diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..0857b88e8947db355faab8cf76c7e1562923924e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,43 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text + +# collector 目录下的大文件(SDK 二进制/模型)走 LFS +collector/**/*.rknn filter=lfs diff=lfs merge=lfs -text +collector/**/*.so filter=lfs diff=lfs merge=lfs -text +collector/**/*.so.* filter=lfs diff=lfs merge=lfs -text +collector/**/*.jpg filter=lfs diff=lfs merge=lfs -text +collector/**/*.png filter=lfs diff=lfs merge=lfs -text +collector/**/*.bmp filter=lfs diff=lfs merge=lfs -text +collector/**/*.task filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d3519fb20b6c4ea4a0e4b0b70f2346e2bcbe7b8c --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +--- +title: DataFlowing +emoji: 🏃 +colorFrom: purple +colorTo: blue +sdk: static +pinned: false +short_description: A data pipeline for robot learning to LeRobot export +--- + +# DataFlowing · 处理端(processor) + +本 Space 存放 DataFlowing 项目的**服务端处理代码**,内容来自 GitHub 仓库 [Stouching-robotics/DataFlowing](https://github.com/Stouching-robotics/DataFlowing) 的 `processor/` 目录。 + +## 目录结构 + +- [`processor/app/`](https://huggingface.co/spaces/Stouching-Robotics/DataFlowing/tree/main/processor/app) — API、存储、工作流、AI 标注、LeRobot/HDF5 导出 +- [`processor/worker/`](https://huggingface.co/spaces/Stouching-Robotics/DataFlowing/tree/main/processor/worker) — 异步处理 worker +- [`processor/web/`](https://huggingface.co/spaces/Stouching-Robotics/DataFlowing/tree/main/processor/web) — 审核 UI 与 Workflow Studio +- [`processor/scripts/`](https://huggingface.co/spaces/Stouching-Robotics/DataFlowing/tree/main/processor/scripts) — 部署、迁移与巡检工具 +- [`processor/tests/`](https://huggingface.co/spaces/Stouching-Robotics/DataFlowing/tree/main/processor/tests) — 测试 +- [`processor/examples/`](https://huggingface.co/spaces/Stouching-Robotics/DataFlowing/tree/main/processor/examples) — 脱敏示例会话元数据(LeRobot 格式;视频文件见 GitHub 仓库) + +## 链接 + +- GitHub 仓库:https://github.com/Stouching-robotics/DataFlowing +- 处理端文档:https://github.com/Stouching-robotics/DataFlowing/tree/main/processor +- 中文说明:https://github.com/Stouching-robotics/DataFlowing/blob/main/README.zh-CN.md + +> 注意:本 Space 为代码镜像,与 GitHub 手动同步。开发协作请以 GitHub 仓库为准。 diff --git a/collector/.gitattributes b/collector/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..4f9194527e5462a027d4d885fef74c03f1bd3b30 --- /dev/null +++ b/collector/.gitattributes @@ -0,0 +1,5 @@ +# 换行符规范化:保证 GitLab 下载后 bat 可直接双击运行 +*.bat text eol=crlf +*.sh text eol=lf +*.py text eol=lf +*.md text eol=lf diff --git a/collector/.gitignore b/collector/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c8adfb61602a6432bcd71425fda2682344fa4ebb --- /dev/null +++ b/collector/.gitignore @@ -0,0 +1,57 @@ +__pycache__/ +*.pyc +*.pyo +*.egg-info/ +dist/ +# 分发包的**构建模板**要入库(构建产物 dist/ 本身仍忽略) +!tools/hand_3d_s80c/dist/ +build/ +data/recordings/ +data/*.db +*.log +.venv/ +venv/ +venv_lite/ +*.fifo +*.h5 +*.mp4 +.DS_Store +*.bak_* +*.corrupted_* + +# 备份包/个人配置/生成数据 +*.tar.gz +*.bak +*.old +*.parquet +.vscode/ +.claude/ +keypoints_output/ +exports/ +tools/weights/ +wheels/ # scripts/pack_wheels.py 生成的离线部署包(不入库,拷给客户用) +imgui.ini +.polyscope.ini +tools/stereo_s80m/offline_slam_output/ +tools/stereo_s80m/hand_benchmark/ +data/*.db-shm +data/*.db-wal +tools/demos/stereo_depth_demo/*.bin +tools/demos/stereo_depth_demo/*.png +tools/demos/stereo_depth_demo/build/ + +# 本地私有配置(模板见 *.example.json) +data/server_config.json +data/device_names.json +data/tasks.json + +# 真机标定(本地提取产物,跑 tools/hand_3d_d435/tools/extract_d435_color_calib.py 再生) +tools/hand_3d_d435/calibration/ +pipeline.db + +# 手套工具包(第三方 SDK 本地参考,永远不上传) +stouch_glove_toolkit-Stouch_Glove_Toolkit-beta/ +lite_package/* +!lite_package/start_lite.bat +!lite_package/start_lite.sh +!lite_package/使用说明_lite.md diff --git a/collector/README.md b/collector/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9d1a99e2d35bfce88392fb852a31fcfed5891888 --- /dev/null +++ b/collector/README.md @@ -0,0 +1,731 @@ +# collector — Multimodal Data Acquisition SDK · 多模态数据采集 SDK + +![Version](https://img.shields.io/badge/version-1.2.0-blue) +![Python](https://img.shields.io/badge/python-3.12-blue) +![License](https://img.shields.io/badge/license-TBD-lightgrey) + + +## 📚 Navigation · 导航 + +| Section · 章节 | English | 中文 | +|---|---|---| +| Features · 功能特性 | [Features](#features) | [功能特性](#功能特性) | +| Quick Start · 快速开始 | [Quick Start](#quick-start) | [快速开始](#快速开始) | +| Supported Hardware · 硬件支持 | [Supported Hardware](#supported-hardware) | [硬件支持](#硬件支持) | +| Data Formats · 数据格式 | [Data Formats](#data-formats) | [数据格式](#数据格式) | +| Black Glove Keypoints · 黑手套解算 | [Black Glove Keypoints](#black-glove-keypoints) | [黑手套解算](#黑手套解算) | +| Environment Variables · 环境变量 | [Environment Variables](#environment-variables) | [环境变量](#环境变量) | +| Directory Structure · 目录结构 | [Directory Structure](#directory-structure) | [目录结构](#目录结构) | +| Tests · 测试 | [Tests](#tests) | [测试](#测试) | +| Documentation · 文档 | [Documentation](#documentation) | [文档](#文档) | +| Privacy & Local Config · 隐私与本地配置 | [Privacy & Local Config](#privacy--local-config) | [隐私与本地配置](#隐私与本地配置) | +| Third-Party Components & Licensing · 第三方组件与许可 | [Third-Party Components & Licensing](#third-party-components--licensing) | [第三方组件与许可](#第三方组件与许可) | +| License · 许可证 | [License](#license) | [许可证](#许可证) | +| Contributing · 贡献 | [Contributing](#contributing) | [贡献](#贡献) | +| Changelog · 更新记录 | [Changelog](#changelog) | [更新记录](#更新记录) | + +--- + +## English + +A PyQt5-based multimodal data acquisition SDK + GUI: synchronized recording, +playback, and HTTP upload across multiple cameras (UVC webcams, Intel +RealSense D435/D405, S80C / S80M stereo) and BLE data gloves, outputting +[EgoData](https://github.com/facebookresearch/egodata) / +[LeRobot v3](https://github.com/huggingface/lerobot) compatible formats for +robot teleoperation datasets. Ships with 3D hand-keypoint processing +pipelines and offline SLAM dataset export. + +**Architecture**: `core/` is the SDK core (capture pipeline, device managers, +recording/upload/playback logic — depends only on PyQt5.QtCore, never imports +ui); `ui/` does widget assembly only; `tools/` is a self-contained toolchain +(never imported by the main program), including standalone demos, model +weights, and tests. + + + +### Features + +- **Multi-camera synchronized recording**: per-stream record control + (normal stop saves / abnormal stop discards) with live recording duration +- **Draggable multi-view grid layout**, adjustable in playback view too +- **Device detection panel**: unified UVC / D435 / S80M enumeration, 2 s + polling, click to display +- **BLE data gloves**: one per hand, tactile data captured in sync with video +- **Recording history & playback**: SQLite persistence, compatible with + EgoData / LeRobot v3 sessions +- **HTTP upload**: post-recording upload to a self-hosted server, with + optional auto-sync/delete of local files +- **Chinese / English UI switching** (i18n) +- **3D hand keypoints**: D435 RGB-D pipeline + ([tools/hand_3d_d435/](tools/hand_3d_d435/)), S80C / S80M stereo + triangulation, MediaPipe bare-hand pipeline, plus a dedicated + black-glove pipeline (YOLO-World boxes + RTMPose keypoints — see + [Black Glove Keypoints](#black-glove-keypoints)) +- **Offline SLAM dataset export** (ORB-SLAM compatible formats, with + validation tooling) +- **12-bit depth video recording**: single-stream gray HEVC MP4 (log depth + codes, reversibly decoded to millimetres), unified JET heatmap display + live and in playback +- **Direct HEVC recording**: low-bitrate HEVC at record time with + multi-encoder fallback; the uploader detects HEVC and skips redundant + re-compression + +### Quick Start + +#### Install dependencies + +```bash +python -m venv venv +venv/bin/pip install -r requirements.txt +``` + +> Optional dependencies such as `pyrealsense2`, `mediapipe`, `torch` are not +> listed in `requirements.txt` (lazily imported; the corresponding feature is +> unavailable if missing — one-click installs via `start.bat extras` below). + +#### Windows one-click deployment (recommended for customers) + +Double-click **`start.bat`** in the repo root: it installs Python 3.12 +(silent download if absent), creates the venv, installs dependencies, and +launches the main program; already-deployed machines start instantly. Common +commands: + +```bat +start.bat deploy and launch (default) +start.bat reinstall delete venv and reinstall (first resort when broken) +start.bat extras additionally install mediapipe / pyrealsense2 +start.bat extras-torch additionally install CPU torch (hand-keypoint RTMPose backend) +start.bat help open the operation guide and troubleshooting doc +``` + +> Full operation guide, error-code reference, and intranet offline delivery +> procedure: [使用说明.md](使用说明.md) / [使用说明_EN.md](使用说明_EN.md) +> (offline wheel bundles are produced by `python scripts/pack_wheels.py`). + +#### Launch the main program + +```bash +./start.sh # Linux one-click deploy (same subcommands: reinstall/extras/...) +./run.sh # launch directly when venv already exists +venv/bin/python main.py # launch directly +run.bat # launch directly when venv already exists (start.bat deploys first) +``` + +No manual config needed on first run: `data/tasks.json` is generated from +built-in seed tasks; other config files are created the first time the +corresponding setting is saved (the repo only ships `*.example.json` +templates). + +#### 3D hand keypoints (D435) + +```bash +./tools/hand_3d_d435/run_live_d435.sh # live demo (direct camera) +./tools/hand_3d_d435/run_live_d435.sh --replay # replay a session +./tools/hand_3d_d435/run_live_d435.sh --glove # black-glove mode (see Black Glove Keypoints) +./tools/hand_3d_d435/run_d435.sh # offline pipeline +``` + +#### Demos + +```bash +./tools/demos/run_stereo_depth_demo.sh # S80M depth-engine demo (SDK required, see below) +venv/bin/python tools/demos/test_stereo_depth_calib.py # stereo depth calibration self-check (SDK required) +venv/bin/python tools/hand_detection/demo_stereo_hands.py # stereo + MediaPipe hand demo +``` + +### Supported Hardware + +| Device | Interface | Notes | +|---|---|---| +| UVC camera | `/dev/videoN` (OpenCV V4L2) | MJPG pixel format; up to 8 cameras | +| Intel RealSense D435 / D405 | `pyrealsense2` | RGB + depth dual slots; depth recorded as 12-bit gray HEVC MP4 (log depth codes) + live JET heatmap; built-in stall/framerate watchdog with auto-reconnect; D405 has a dedicated near-range capture profile | +| S80C / S80M stereo | FaysSense VI Kit SDK (bundled in-repo, incl. FT602 bridge driver) | No SDK install needed; camera profile `STEREO_CAM_FPS` (default 50 fps) decimated to 30 fps recording via wall-clock 1/30 s buckets (burst backfill + empty-bucket watchdog, ~3% empty-bucket rate on healthy recordings); callback frame capture (same as the official GUI); carries hardware nanosecond timestamps and IMU samples; since v1.0.11 the subprocess runs the SDK depth engine → third-tile live depth heatmap + 12-bit gray depth video recording | +| BLE data gloves | `bleak` | one per hand; parquet column names bound (`right_glove` / `left_glove`) | + +### Data Formats + +Recordings live in a **task-level pooled layout** (v1.1.0+, LeRobot v3 +naming): `data/recordings//` — the task name doubles as the upload +"project name", one file group per episode: + +``` +data/recordings// +├── videos/chunk-NNN//episode-NNN.mp4 # one video per stream per episode +│ # RGB = mp4; depth = 12-bit gray mp4 (mkv on fallback) +├── data/chunk-NNN/episode-NNN.parquet # one parquet per episode (zstd, sparse columns) +└── meta/ + ├── info.json # task header; format="pooled_episodes_v1" is the discriminator + ├── stats.json # task-wide stats accumulator (count/mean/std/min/max per column) + ├── tasks.jsonl # task descriptions (single-line JSONL is contractual) + └── episodes/chunk-NNN/episode-NNN.parquet # one row per episode (10 columns) +``` + +- **Numbering**: episodes are numbered globally from N=1 with + `chunk = (N-1) // 1000`, `file = (N-1) % 1000` (`chunks_size=1000`, + declared in info.json); every file of an episode shares the same + `(chunk, file)`. Abnormally-stopped recordings recycle their number; + completed episodes never do (in-app deletion is permanent) +- **Row layout**: each data parquet row = one 30 fps frame with key + columns (`episode_index` / `frame_index` / `timestamp` / `wall_time` / + `hardware_ns`) plus sparse observations (`observation.` per + frame, `observation.imu` variable-length sample lists aligned by + `imu_ts_ns`, `observation.*hand_pose` zero placeholders backfilled by + post-processing). The full interface contract lives in + [docs/file_format.md](docs/file_format.md) +- Device naming follows the EgoData `_` convention, e.g. + `head_left_rgb`, `head_right_rgb`, `head_depth`, `right_glove`, + `right_hand_pose` +- Depth video: single-stream 12-bit gray HEVC MP4 (log depth codes, + reversibly decoded to millimetres; falls back to FFV1 MKV when x265 is + unavailable); playback always renders the unified JET heatmap +- Recording history & upload queue: SQLite (`data/pipeline.db`) +- Offline processing output: `keypoints_output//episode_NNNNNN/` + (mirrors the pooled key, never written back into the recording + directory) + +### Black Glove Keypoints + +Bare-hand MediaPipe detection fails on black gloves (4/68 hands +measured), so gloves are solved with a dedicated YOLO + RTMPose +pipeline (40/40 on black / grey / any-colour gloves): + +1. **Detection box** — open-vocabulary YOLO-World + (`yolov8m-worldv2.pt`, prompts `hand` / `glove`) or the trained + single-class yolo11n detector (`best.pt`), hot-switchable at runtime +2. **Box tracking** — EMA-smoothed track boxes with dual-threshold + new-track gating and churn suppression (HandTracker) +3. **Keypoints** — RTMPose hand5 (21 points, ONNX via onnxruntime CUDA) + cropped-box inference; a MediaPipe cropped-box backend is available + for comparison (hot-switchable at runtime) +4. **Stabilization** — per-point confidence weighting; on low confidence + hold the last output and translate it with the smoothed box motion; + a hold-escape releases after N consecutive low-confidence frames so + real new poses (grip, fist) are never frozen out; degradation freeze + cap and handedness voting +5. **3D lift** — D435 RGB-D depth lift or S80C stereo depth engine. On + S80C the right eye reuses the left eye's smoothed box translated by + disparity (`x_r = x_l − fx·B/z`) and runs the same stateless pose + backend; the 2D display stays decoupled from the 3D slot chain + +Where it runs: + +| Location | Mode | Notes | +|---|---|---| +| Main program post-processing | `HAND_TRACK_MODE=glove` | YOLO box + RTMPose 2D keypoints written back to `keypoints_output/` (92 dim/frame packed); `bare` mode = MediaPipe 2D + 3D world landmarks | +| D435 live demo | `--glove` | realtime 3D on RGB-D | +| S80C live demo | `--glove` | realtime 3D on stereo depth | +| Toolkit | [tools/glove_package/](tools/glove_package/) | annotation, training (`train_detector.py` → `best.pt`), CLIP auto-labeling | + +```bash +./tools/hand_3d_d435/run_live_d435.sh --glove # D435 live glove mode +./tools/hand_3d_s80c/run_live_s80c.sh --glove # S80C live stereo glove mode +``` + +Implementation: detection / pose front-ends in +[tools/hand_detection/](tools/hand_detection/) and +[tools/glove_package/](tools/glove_package/); post-recording processing +in [core/hand_tracking.py](core/hand_tracking.py); live demos in +[tools/hand_3d_d435/](tools/hand_3d_d435/) and +[tools/hand_3d_s80c/](tools/hand_3d_s80c/). + +### Environment Variables + +| Variable | Required | Description | +|---|---|---| +| `FAYSSENSE_SDK_DIR` | S80M demo/diagnostic tools only | Install path of the FaysSense VI Kit SDK (Release directory); those tools exit with an error if unset. The main program's S80C/S80M capture path does not need it (in-repo self-contained libs) | +| `FFMPEG_BIN` | no | ffmpeg executable override (used by render/video-write tooling) | +| `VENV_PY` | no | Python interpreter used by launcher scripts, default `venv/bin/python` | + +### Directory Structure + +``` +collector/ +├── main.py # program entry (qt-material dark theme) +├── start.bat / start.sh # one-click deployment (Windows / Linux) +├── run.bat / run.sh # direct launch once deployed +├── requirements.txt # required main-program dependencies (start.bat/start.sh self-check matches) +├── .gitignore / .gitattributes # repo exclusions / line-ending rules (bat forced CRLF) +├── core/ # ★ SDK core (depends only on PyQt5.QtCore and config, never imports ui; +│ # listed in data-flow order: capture → write → playback/upload) +│ ├── pipeline.py # recording main loop / pipeline state machine (data-flow hub) +│ ├── device_manager.py # unified device worker registry + panel toggle dispatch +│ ├── camera.py # UVC camera capture (CameraWorker) +│ ├── d435_manager.py # RealSense D435/D405 capture (heatmap/EMA/record write) +│ ├── s80m_manager.py # S80C/S80M subprocess capture + 50→30 decimation +│ ├── ble_engine.py # BLE data-glove capture +│ ├── egodata_writer.py # EgoData / LeRobot v3 recording writer (pooled layout) +│ ├── depth_codec.py # 12-bit log depth codec (gray12le HEVC video) +│ ├── encoder_probe.py # HEVC encoder availability probe (nvenc → x265 → x264) +│ ├── session_catalog.py # session scanning / metadata / fps resolution +│ ├── session_loader.py # background playback loader (QtCore signals) +│ ├── session_timeline.py # playback timeline +│ ├── depth_reader.py # depth video reader (gray12le MP4 / FFV1 MKV / legacy PNG16) +│ ├── uploader.py # session upload queue +│ ├── hand_tracking.py # hand-keypoint processing (glove / bare) +│ ├── helpers.py # session path/duration/size utilities +│ └── … # support modules: calibration, exposure, naming, SQLite +│ # history, task polling, rendering (see docs/core.md) +├── ui/ # PyQt5 UI assembly +│ └── main_window.py # main window: slots / record control / panel dispatch (data-flow wiring point) +├── config/ # global config + i18n strings + calibration/sensor JSON +├── scripts/ # offline processing (process_hands.py) + offline packaging (pack_wheels.py) +├── docs/ # per-directory module docs (see below) +├── data/ # local config templates + recordings (both gitignored) +└── tools/ # toolchain (self-contained, never imported by the main program) + ├── gongsitubiao.png # UI logo (ui/main_window.py, ui/task_page.py) + ├── stereo_s80m/ # S80M stereo tools (read_stereo_rgb.py = main-program capture subprocess) + ├── hand_detection/ # YOLO glove detection + MediaPipe bare-hand pipeline + ├── hand_3d_d435/ # D435 RGB-D 3D hand keypoints (standalone module) + ├── hand_3d_s80c/ # S80C stereo realtime bare-hand/glove keypoint demo (with self-contained SDK) + ├── glove_package/ # YOLO-World + RTMPose black-glove toolkit + ├── fayssense_depth_sdk/ # FaysSense VI Kit depth-engine SDK (proprietary) + ├── models/ # model weights (MediaPipe hand_landmarker.task) + ├── weights/ # CLIP and other large weights (gitignored, not distributed) + ├── demos/ # delivery demos and self-check scripts + └── tests/ # regression / smoke tests +``` + +### Tests + +```bash +# hardware-free offline tests (QT_QPA_PLATFORM=offscreen) +venv/bin/python tools/tests/test_playback_multifps.py +venv/bin/python tools/tests/s80m_signal_regression.py +venv/bin/python tools/tests/s80m_50fps_decimation_test.py +venv/bin/python tools/tests/multi_device_registry_test.py +venv/bin/python tools/tests/exposure_control_test.py +venv/bin/python tools/tests/test_meta_devices.py +venv/bin/python tools/tests/test_depth_heatmap.py +venv/bin/python tools/tests/glove_widget_test.py +venv/bin/python tools/tests/grid_drag_fps_test.py +venv/bin/python tools/tests/device_panel_gui_smoke_test.py +venv/bin/python tools/tests/test_device_detector.py +# hardware tests require the corresponding device attached: d405_worker_test, +# d435_e2e_test, d435_gui_smoke_test, mono_regression, d435_playback_test, etc. +``` + +### Documentation + +Per-module details live in [docs/](docs/) (one page per directory: purpose, +file inventory, data flow): + +- [docs/index.md](docs/index.md) — repository overview (entry point of the doc set) +- [docs/core.md](docs/core.md) — SDK core (pipeline, device managers, recording/upload/playback) +- [docs/ui.md](docs/ui.md), [docs/config.md](docs/config.md) — UI, configuration +- [docs/data.md](docs/data.md) — config and data storage layout +- [docs/scripts.md](docs/scripts.md) — offline processing and deployment scripts +- [docs/tools.md](docs/tools.md), [docs/demos.md](docs/demos.md) — 3D tools, delivery demos +- [docs/stereo_s80m.md](docs/stereo_s80m.md), [docs/hand_detection.md](docs/hand_detection.md) — S80M, hand detection +- [docs/file_format.md](docs/file_format.md) — data file interface contract (authoritative definition of the v1.1.x pooled layout) + +### Privacy & Local Config + +Real config files **never enter the repo**: `data/server_config.json` (may +contain server address and login credentials), `data/device_names.json` +(keys contain device serials/MACs), `data/tasks.json`, plus `data/*.db` and +`data/recordings/` are all excluded by `.gitignore`; apart from +`data/device_params.json` (factory-default empty config), the repo only +ships `*.example.json` templates. Do not commit modified real config files. + +### Third-Party Components & Licensing + +- **FaysSense VI Kit SDK**: proprietary software; the main program's + S80C/S80M capture path uses the in-repo `tools/stereo_s80m/lib` and + `tools/hand_3d_s80c/third_party` (incl. the FT602 bridge driver + libft602.so and OpenCV 4.2 dependencies) — a fresh git clone runs with no + SDK install. `tools/fayssense_depth_sdk/` is an intranet-shared copy (used + by the S80C demo) and must be purged from history before any public + open-source release. Standalone demos/diagnostic tools can also point + `FAYSSENSE_SDK_DIR` at a separately installed SDK +- **Model weights**: `tools/models/hand_landmarker.task` (MediaPipe) and + others follow their respective upstream licenses; large weights such as + CLIP live in `tools/weights/` and are not distributed with the repo. + Verify upstream license terms before use/redistribution +- **ffmpeg**: the recorder prefers the static ffmpeg bundled with + `imageio-ffmpeg` + +### License + +The LICENSE of this repository is to be determined (a LICENSE file will be +added before release). Third-party components (SDK, model weights, ffmpeg, +etc.) are governed by their upstream terms. + +### Contributing + +Issues and merge requests are welcome. Development conventions (version +number defined only in `config/__init__.py`, i18n strings via `tr()`, use +`object` for large ints in PyQt5 signal params, core never imports ui, etc.) +are documented in [docs/index.md](docs/index.md#开发约定). + +### Changelog + +- **v1.2.0** — minimal one-click deployment edition (`start_lite.bat/.sh` + + `venv_lite` whitelist env, ~750 MB): connect devices → record → upload + only — no login/playback/task page/skeleton solving. Devices: D435 + (1280×720@30 RGB / 848×480@30 depth), one UVC camera (640×480@30 + capture; 640×360@15 preview that auto-switches to the device you open), + one USB / one BLE glove. Direct x264 (encoder probe skipped). + `scripts/pack_lite.py` collects the release folder; import-isolation + guard + hardware-free smoke tests included +- **v1.1.4** — USB Type-C glove support (STM32 CDC serial engine, 60 fps + IMU + 16×16 tactile); real-time MANO 21-keypoint solving backfills the + `hand_pose` placeholder columns (with skeleton rendering in the main UI); + BLE glove dual-serial config update; single-file PyQt5 viewer demo + (RGB/depth/tactile/skeleton/IMU panels, live playback, draggable progress + bar) with tests +- **v1.1.3** — dual-directory (`videos/` + `data/`) timeline + reliability: the S80C/S80M 50→30 decimation now uses wall-clock + 1/30 s buckets with burst backfill (sensor hw-clock jumps no longer + cause steady frame drops) plus an empty-bucket watchdog (~3% + empty-bucket rate on healthy recordings, down from 8-15% when + recording depth). Depth-slot frame drops root-fixed: keep-latest + depth queue (the old FIFO dropped 35% of engine bursts), x265 + preset=fast, quantization LUT, and alternate-frame engine feed. + Login & window behavior: closing the startup login now exits the app + (no more silent guest mode); the upload/playback dialogs get working + maximize/minimize buttons. Playback: click-on-groove seeking, + play-after-end restarts, speed-button polish +- **v1.1.2** — upload and playback dialogs reorganized into two-level + trees; depth storage switched to 12-bit gray HEVC MP4 (gray12le log + depth codes, same as LeRobot v3; display and storage now share one code + scale — the old heatmap near/far params are deprecated; falls back to FFV1 + MKV when x265 is unavailable; readers keep legacy MKV/PNG16 fallback). + Per-episode meta files renamed `file-` → `episode-` (same numbering; + legacy chunk shards keep the `file-` prefix). In-app deletion now removes + files outright (no more `_trash/` staging area) +- **v1.1.1** — `stats.json` carries its own `count` accumulator per block; + the `.stats_state.json` sidecar is abolished +- **v1.1.0** — task-level pooled storage layout (`videos/` / `data/` / + `meta/` organized as `chunk-NNN/episode-NNN`, one file group per episode); + one-off migration script for legacy per-session directories + +--- + +## 中文 + +基于 PyQt5 的多模态数据采集 SDK + GUI:多路相机(UVC 摄像头、Intel +RealSense D435/D405、S80C / S80M 双目)与 BLE 数据手套的同步录制、回放与 +HTTP 上传,输出 [EgoData](https://github.com/facebookresearch/egodata) / +[LeRobot v3](https://github.com/huggingface/lerobot) 兼容格式,供机器人 +遥操作数据集使用。配套手部 3D 关键点处理链路与离线 SLAM 数据集导出。 + +**架构定位**:`core/` 是 SDK 核心(采集管线、设备管理器、录制/上传/回放 +全部算法口径,只依赖 PyQt5.QtCore,禁止 import ui);`ui/` 只做界面组装; +`tools/` 是自包含工具链(不被主程序 import),含独立 demo、模型权重、测试。 + + + +### 功能特性 + +- **多路相机同步录制**:每路独立的录制控制(正常停止保存 / 异常停止丢弃), + 录制时长实时显示 +- **可拖拽的多画面网格布局**,回放界面同样支持调位与分割条 +- **设备检测面板**:统一枚举 UVC / D435 / S80M 设备,2 秒轮询,点击即显示 +- **BLE 数据手套**:左右手各一只,触觉数据与视频同步采集 +- **录制历史与回放**:SQLite 持久化,兼容 EgoData / LeRobot v3 会话 +- **HTTP 上传**:录制完成后上传至自建服务器,可自动同步/删除本地文件 +- **中英文界面切换**(i18n) +- **手部 3D 关键点**:D435 RGB-D 管线([tools/hand_3d_d435/](tools/hand_3d_d435/))、 + S80C / S80M 双目三角化、MediaPipe 裸手管线,另有黑手套专用管线 + (YOLO-World 检测框 + RTMPose 关键点,见[黑手套解算](#黑手套解算)) +- **离线 SLAM 数据集导出**(ORB-SLAM 等格式,含校验工具) +- **12-bit 深度视频录制**:单流灰度 HEVC MP4(对数深度码、可逆解码回毫米), + 实时与回放统一 JET 热力图显示 +- **录制直出 HEVC**:录制端低码率 HEVC(多编码器自动回退), + 上传端识别 HEVC 后跳过重复压缩 + +### 快速开始 + +#### 安装依赖 + +```bash +python -m venv venv +venv/bin/pip install -r requirements.txt +``` + +> `pyrealsense2`、`mediapipe`、`torch` 等可选依赖未列入 `requirements.txt` +> (代码内惰性导入,缺失时对应功能不可用;一键安装见下方 `start.bat extras`)。 + +#### Windows 一键部署(推荐客户使用) + +双击根目录 **`start.bat`**:自动安装 Python 3.12(无则静默下载安装)、创建 venv、 +安装依赖并启动主程序;已部署过则秒开。常用命令: + +```bat +start.bat 部署并启动(默认) +start.bat reinstall 删除 venv 重装(出问题首选) +start.bat extras 追加安装 mediapipe / pyrealsense2 +start.bat extras-torch 追加安装 CPU 版 torch(手部关键点 RTMPose 后端) +start.bat help 打开操作指引与异常排查文档 +``` + +> 完整操作指引、错误码对照与内网离线交付方式见 [使用说明.md](使用说明.md) / +> [使用说明_EN.md](使用说明_EN.md)(离线安装包由 `python scripts/pack_wheels.py` 生成)。 + +#### 启动主程序 + +```bash +./start.sh # Linux 一键部署(等价命令:reinstall/extras/...) +./run.sh # 已有 venv 时直接启动 +venv/bin/python main.py # 直接启动 +run.bat # 已有 venv 时直接启动(start.bat 会先部署) +``` + +首次运行无需手动建配置:`data/tasks.json` 由内置种子任务生成,其余配置文件 +在首次保存对应设置时自动创建(仓库只提供 `*.example.json` 模板)。 + +#### 手部 3D 关键点(D435) + +```bash +./tools/hand_3d_d435/run_live_d435.sh # 实时 demo(直连相机) +./tools/hand_3d_d435/run_live_d435.sh --replay <会话目录> # 回放会话 +./tools/hand_3d_d435/run_live_d435.sh --glove # 黑手套模式(见「黑手套解算」) +./tools/hand_3d_d435/run_d435.sh <会话目录> # 离线管线 +``` + +#### Demos + +```bash +./tools/demos/run_stereo_depth_demo.sh # S80M 深度引擎 demo(需 SDK,见下) +venv/bin/python tools/demos/test_stereo_depth_calib.py # 双目深度标定自检(需 SDK) +venv/bin/python tools/hand_detection/demo_stereo_hands.py # 双目 + MediaPipe 手部 demo +``` + +### 硬件支持 + +| 设备 | 接入方式 | 说明 | +|---|---|---| +| UVC 相机 | `/dev/videoN`(OpenCV V4L2) | MJPG 像素格式;最多 8 路 | +| Intel RealSense D435 / D405 | `pyrealsense2` | RGB + depth 双路槽位;深度以 12-bit 灰度 HEVC MP4 录制(对数深度码)+ 实时 JET 热力图;内置停滞/帧率看门狗自动重连;D405 有独立近距采集配置 | +| S80C / S80M 双目 | FaysSense VI Kit SDK(仓库自带,含 FT602 桥驱动) | 无需安装 SDK;相机档 `STEREO_CAM_FPS`(默认 50fps)按 wall 时钟 1/30s 桶抽帧录制 30fps(突发补录 + 空桶看门狗,健康录制空桶率 ~3%),回调取帧(官方 GUI 同款);携带硬件纳秒时间戳与 IMU 样本;v1.0.11 起子进程内置 SDK 深度引擎 → 第三格实时深度热力图 + 12-bit 灰度深度视频录制 | +| BLE 数据手套 | `bleak` | 左右手各一只,parquet 列名绑定(`right_glove` / `left_glove`) | + +### 数据格式 + +录制数据采用**任务级池化布局**(v1.1.0 起,LeRobot v3 命名): +`data/recordings/<任务>/`——任务名即上传语义的「项目名」,每段 episode +一组文件: + +``` +data/recordings/<任务>/ +├── videos/chunk-NNN/<槽名>/episode-NNN.mp4 # 每段每流一个视频 +│ # RGB=mp4;深度=12-bit 灰 mp4(回落 mkv) +├── data/chunk-NNN/episode-NNN.parquet # 每段一个 parquet(zstd,稀疏列) +└── meta/ + ├── info.json # 任务级头部;format="pooled_episodes_v1" 为判别键 + ├── stats.json # 全任务统计累加器(每列 count/mean/std/min/max) + ├── tasks.jsonl # 任务描述(单行 JSONL 是格式契约) + └── episodes/chunk-NNN/episode-NNN.parquet # 每段一行元数据(10 列) +``` + +- **编号规则**:episode 全局从 N=1 递增,`chunk = (N-1) // 1000`、 + `file = (N-1) % 1000`(`chunks_size=1000`,由 info.json 声明);同一 + episode 的所有文件共用同一 `(chunk, file)`。异常终止的录制回收其编号 + 复用;已完成的编号永不复用(应用内删除即彻底删除) +- **行布局**:data parquet 一行 = 一个 30fps 帧,键列 + (`episode_index` / `frame_index` / `timestamp` / `wall_time` / + `hardware_ns`)+ 稀疏观测列(`observation.<传感器>` 逐帧、 + `observation.imu` 变长样本列表按 `imu_ts_ns` 对齐、 + `observation.*hand_pose` 恒写占位零由后处理回填)。完整接口契约见 + [docs/file_format.md](docs/file_format.md) +- 设备命名遵循 EgoData 标准 `<位置>_<模态>`:如 `head_left_rgb`、 + `head_right_rgb`、`head_depth`、`right_glove`、`right_hand_pose` +- 深度视频:单流 12-bit 灰度 HEVC MP4(对数深度码,可逆解码回毫米; + x265 不可用时回落 FFV1 MKV),回放显示统一 JET 热力图 +- 录制历史与上传队列:SQLite(`data/pipeline.db`) +- 离线处理输出:`keypoints_output/<任务>/episode_NNNNNN/`(镜像池化 + 编号,不写回录制目录) + +### 黑手套解算 + +MediaPipe 裸手检测在黑手套上失效(实测 4/68 手),因此黑手套改用专用 +的 YOLO + RTMPose 管线解算(黑/灰/任意颜色手套实测 40/40): + +1. **检测框** — 开放词汇 YOLO-World(`yolov8m-worldv2.pt`,提示词 + `hand` / `glove`)或训练的单类 yolo11n 检测器(`best.pt`),运行中 + 可热切换 +2. **框跟踪** — HandTracker:EMA 平滑跟踪框、新 track 双阈值门控、 + 碎片框抑制 +3. **关键点** — RTMPose hand5(21 点,ONNX / onnxruntime CUDA)按框 + 裁剪推理;可切换 MediaPipe 裁剪后端做对比(运行中热切换) +4. **稳定层** — 逐点置信度加权;低置信时持出上次输出并按平滑框位移 + 平移补偿;连续 N 帧低置信后放行本轮骨架(握拳/抓取等真实新姿势 + 不被无限冻结);退化冻结上限与手性票仓防抖 +5. **3D 抬升** — D435 RGB-D 深度抬升或 S80C 双目深度引擎。S80C 上 + 右目共享左目平滑框按视差平移(`x_r = x_l − fx·B/z`)后复用同一 + 无状态 pose 后端;2D 显示与 3D 槽位链解耦 + +运行位置: + +| 位置 | 模式 | 说明 | +|---|---|---| +| 主程序录后处理 | `HAND_TRACK_MODE=glove` | YOLO 框 + RTMPose 2D 关键点写回 `keypoints_output/`(每帧 92 维打包);`bare` 模式 = MediaPipe 2D + 3D world landmarks | +| D435 实时 demo | `--glove` | RGB-D 实时 3D | +| S80C 实时 demo | `--glove` | 双目深度实时 3D | +| 工具包 | [tools/glove_package/](tools/glove_package/) | 标注、训练(`train_detector.py` → `best.pt`)、CLIP 自动标注 | + +```bash +./tools/hand_3d_d435/run_live_d435.sh --glove # D435 实时手套模式 +./tools/hand_3d_s80c/run_live_s80c.sh --glove # S80C 实时双目手套模式 +``` + +实现位置:检测/关键点前端在 [tools/hand_detection/](tools/hand_detection/) +与 [tools/glove_package/](tools/glove_package/);录后处理在 +[core/hand_tracking.py](core/hand_tracking.py);实时 demo 在 +[tools/hand_3d_d435/](tools/hand_3d_d435/) 与 +[tools/hand_3d_s80c/](tools/hand_3d_s80c/)。 + +### 环境变量 + +| 变量 | 必需 | 说明 | +|---|---|---| +| `FAYSSENSE_SDK_DIR` | 仅 S80M demo/诊断工具 | FaysSense VI Kit SDK 安装路径(Release 目录),未设置时相关工具直接报错退出;主程序 S80C/S80M 采集链路不需要(仓库内自包含) | +| `FFMPEG_BIN` | 否 | ffmpeg 可执行文件覆盖(渲染/视频写入工具使用) | +| `VENV_PY` | 否 | launcher 脚本使用的 Python 解释器,默认 `venv/bin/python` | + +### 目录结构 + +``` +collector/ +├── main.py # 程序入口(qt-material 暗色主题) +├── start.bat / start.sh # 一键部署(Windows / Linux) +├── run.bat / run.sh # 已部署时直接启动 +├── requirements.txt # 主程序必需依赖(start.bat/start.sh 依赖自检与之一致) +├── .gitignore / .gitattributes # 仓库排除规则 / 换行符规范(bat 强制 CRLF) +├── core/ # ★ SDK 核心(仅依赖 PyQt5.QtCore 与 config,禁止 import ui; +│ # 下列按数据流排序:采集 → 写入 → 回放/上传) +│ ├── pipeline.py # 录制主循环 / 管线状态机(数据流中枢) +│ ├── device_manager.py # 统一设备 worker 注册表 + 面板开关分派 +│ ├── camera.py # UVC 相机采集(CameraWorker) +│ ├── d435_manager.py # RealSense D435/D405 采集(热力图/EMA/录制写入) +│ ├── s80m_manager.py # S80C/S80M 子进程采集 + 50→30 抽帧 +│ ├── ble_engine.py # BLE 数据手套采集 +│ ├── egodata_writer.py # EgoData / LeRobot v3 录制写入(池化落盘) +│ ├── depth_codec.py # 12-bit 对数深度码编码(gray12le HEVC 视频) +│ ├── encoder_probe.py # HEVC 编码器可用性探测(nvenc → x265 → x264) +│ ├── session_catalog.py # 会话扫描 / 元数据 / 帧率解析 +│ ├── session_loader.py # 回放后台加载器(QtCore 信号) +│ ├── session_timeline.py # 回放时间线 +│ ├── depth_reader.py # 深度视频读取(gray12le MP4 / FFV1 MKV / 旧 PNG16) +│ ├── uploader.py # 会话上传队列 +│ ├── hand_tracking.py # 手部关键点处理(手套 / 裸手) +│ ├── helpers.py # 会话路径/时长/大小等通用工具 +│ └── … # 其余辅助模块:标定、曝光、命名、SQLite 历史、 +│ # 任务轮询、渲染等(详见 docs/core.md) +├── ui/ # PyQt5 界面组装 +│ └── main_window.py # 主窗口:槽位/录制控制/面板分派(数据流接线点) +├── config/ # 全局配置 + i18n 文案 + 标定/传感器 JSON +├── scripts/ # 离线处理(process_hands.py)+ 离线部署打包(pack_wheels.py) +├── docs/ # 模块文档(逐目录说明,见下) +├── data/ # 本地配置模板 + 录制数据(均 gitignore) +└── tools/ # 工具链(自包含,不被主程序 import) + ├── gongsitubiao.png # 界面 logo(ui/main_window.py、ui/task_page.py 引用) + ├── stereo_s80m/ # S80M 双目工具(read_stereo_rgb.py = 主程序采集子进程) + ├── hand_detection/ # YOLO 手套检测 + MediaPipe 裸手管线 + ├── hand_3d_d435/ # D435 RGB-D 3D 手部关键点(独立模块) + ├── hand_3d_s80c/ # S80C 双目实时裸手/手套关键点 demo(含自包含 SDK) + ├── glove_package/ # YOLO-World + RTMPose 黑手套工具箱 + ├── fayssense_depth_sdk/ # FaysSense VI Kit 深度引擎 SDK(专有) + ├── models/ # 模型权重(MediaPipe hand_landmarker.task) + ├── weights/ # CLIP 等大权重(gitignore,不随仓库分发) + ├── demos/ # 交付版 demo 与自检脚本 + └── tests/ # 回归 / 冒烟测试 +``` + +### 测试 + +```bash +# 无真机可跑的离线测试(QT_QPA_PLATFORM=offscreen) +venv/bin/python tools/tests/test_playback_multifps.py +venv/bin/python tools/tests/s80m_signal_regression.py +venv/bin/python tools/tests/s80m_50fps_decimation_test.py +venv/bin/python tools/tests/multi_device_registry_test.py +venv/bin/python tools/tests/exposure_control_test.py +venv/bin/python tools/tests/test_meta_devices.py +venv/bin/python tools/tests/test_depth_heatmap.py +venv/bin/python tools/tests/glove_widget_test.py +venv/bin/python tools/tests/grid_drag_fps_test.py +venv/bin/python tools/tests/device_panel_gui_smoke_test.py +venv/bin/python tools/tests/test_device_detector.py +# 真机相关测试需连接对应设备:d405_worker_test、d435_e2e_test、 +# d435_gui_smoke_test、mono_regression、d435_playback_test 等 +``` + +### 文档 + +各模块细节见 [docs/](docs/)(每个目录一篇说明:定位、文件清单、数据流): + +- [docs/index.md](docs/index.md) — 仓库总览(本文档集的入口) +- [docs/core.md](docs/core.md) — SDK 核心(管线、设备管理器、录制/上传/回放) +- [docs/ui.md](docs/ui.md)、[docs/config.md](docs/config.md) — 界面、配置 +- [docs/data.md](docs/data.md) — 配置与数据存储结构 +- [docs/scripts.md](docs/scripts.md) — 离线处理与部署脚本 +- [docs/tools.md](docs/tools.md)、[docs/demos.md](docs/demos.md) — 3D 工具、交付 demo +- [docs/stereo_s80m.md](docs/stereo_s80m.md)、[docs/hand_detection.md](docs/hand_detection.md) — S80M、手部检测 +- [docs/file_format.md](docs/file_format.md) — 数据文件接口契约(v1.1.x 任务池化布局权威定义) + +### 隐私与本地配置 + +真实配置文件**不进仓库**:`data/server_config.json`(可能含服务器地址与登录凭据)、 +`data/device_names.json`(key 含设备序列号/MAC)、`data/tasks.json` 以及 +`data/*.db`、`data/recordings/` 均被 `.gitignore` 排除;除 +`data/device_params.json`(出厂默认空配置)外,仓库只提供 +`*.example.json` 模板。请勿将修改过的真实配置文件提交。 + +### 第三方组件与许可 + +- **FaysSense VI Kit SDK**:专有软件;主程序 S80C/S80M 采集链路使用仓库自带的 + `tools/stereo_s80m/lib` 与 `tools/hand_3d_s80c/third_party`(含 FT602 桥驱动 + libft602.so 与 OpenCV 4.2 依赖),git 克隆后无需安装 SDK 即可运行; + `tools/fayssense_depth_sdk/` 为内网共享副本(S80C demo 用),对外开源发布前 + 需从历史中移除。独立 demo/诊断工具也可经 `FAYSSENSE_SDK_DIR` 指向自行安装的 SDK +- **模型权重**:`tools/models/hand_landmarker.task`(MediaPipe)等遵循各自上游许可; + CLIP 等大权重位于 `tools/weights/`,不随仓库分发。使用 / 再分发前请核实上游许可条款 +- **ffmpeg**:录制器优先使用 `imageio-ffmpeg` 捆绑的静态 ffmpeg + +### 许可证 + +本仓库 LICENSE 待定(发布前补充 LICENSE 文件)。第三方组件(SDK、模型权重、 +ffmpeg 等)的许可以其上游条款为准。 + +### 贡献 + +欢迎提交 Issue 与 Merge Request。开发约定(版本号唯一定义在 `config/__init__.py`、 +i18n 文案经 `tr()` 翻译、PyQt5 信号参数用 `object` 封送大整数、core 禁止 import ui +等)见 [docs/index.md](docs/index.md#开发约定)。 + +### 更新记录 + +- **v1.2.0** — 新增极简一键部署采集版(`start_lite.bat/.sh` + `venv_lite` + 白名单依赖,约 750MB):只做连接设备→采集→上传,无登录/回放/任务页/ + 骨架解算。设备:D435(1280×720@30 RGB / 848×480@30 深度)、UVC 摄像头 + 1 台(640×480@30 采集;预览 640×360@15,开哪台自动切哪台)、USB/BLE + 手套各 1 台。x264 直录(跳过编码器探针)。`scripts/pack_lite.py` 收集 + 发布目录,含导入隔离断言与无硬件冒烟自检 +- **v1.1.4** — 新增 USB Type-C 手套接入(STM32 CDC 串口引擎,60fps IMU + + 16×16 触觉);录制时实时解算 MANO 21 关键点回填 hand_pose 占位列(含 + 主界面骨架渲染);BLE 手套双序列号配置更新;新增单文件 PyQt5 查看器 + demo(RGB/深度/触觉/骨架/IMU 面板、实时播放与可拖动的进度条)及配套测试 +- **v1.1.3** — 双目录制(`videos/` + `data/` 两树)时间轴可靠性: + S80C/S80M 50→30 抽帧改 wall 时钟 1/30s 桶 + 突发补录(传感器 hw + 时钟跳变不再造成稳定缺帧)+ 空桶看门狗(健康录制空桶率 ~3%,带 + 深度录制从 8-15% 降至 ~3%)。深度槽丢帧根治:keep-latest 深度队列 + (旧 FIFO 在引擎突发期丢 35%)、x265 preset=fast、量化查表、 + worker 隔帧喂深度引擎。登录与窗口行为:启动首屏关闭登录即退出 + 应用(不再静默进游客模式);上传/回放对话框的最大化最小化按钮 + 在 GNOME/Mutter 下真正可用。回放体验:点击滑槽直接跳帧、播完再点 + 播放从头重播、倍速按钮文字不再截断 +- **v1.1.2** — 上传与回放对话框改两级树结构;深度存储改 12-bit 灰度 + HEVC MP4(gray12le 对数深度码,与 + LeRobot v3 同款;显示与存储统一码值,旧 heatmap 近/远参数废弃;x265 + 不可用时回落 FFV1 MKV;读取端保留旧 MKV/PNG16 回退)。每段文件名前缀 + `file-` → `episode-`(编号不变,旧分片保留 `file-` 前缀不再重名)。 + 应用内删除改为直接彻底删除(不再产生 `_trash/` 回收区) +- **v1.1.1** — `stats.json` 自含 `count` 累加器(每块), + `.stats_state.json` 边车废除 +- **v1.1.0** — 任务级池化存储布局(`videos/` / `data/` / `meta/` 按 + `chunk-NNN/episode-NNN` 组织、每段 episode 一组文件);旧会话目录 + 一次性迁移脚本 diff --git a/collector/config/FS-VI80-S80C_3500000262190088_camera_calibration.yaml b/collector/config/FS-VI80-S80C_3500000262190088_camera_calibration.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8a2a9768247c460958d914b309a0075f75e5e2cb --- /dev/null +++ b/collector/config/FS-VI80-S80C_3500000262190088_camera_calibration.yaml @@ -0,0 +1,29 @@ +cam0: + T_cam_imu: + - [-0.999881744384766, 0.004449303261936, -0.014725826680660, 0.005998577456921] + - [-0.005106299184263, -0.998979330062866, 0.044882606714964, 0.004701206926256] + - [-0.014511099085212, 0.044952493160963, 0.998883724212646, -0.016389895230532] + - [0.0, 0.0, 0.0, 1.0] + camera_model: pinhole + distortion_coeffs: [0.062210198491812, 0.012444571591914, -0.003091567661613, -0.000578491541091] + distortion_model: equidistant + intrinsics: [228.609970092773438, 228.666488647460938, 310.380493164062500, 170.066619873046875] + resolution: [640, 400] + timeshift_cam_imu: -0.001947268727235 +cam1: + T_cam_imu: + - [-0.999790549278259, 0.019221400842071, 0.007029340602458, -0.074173934757710] + - [-0.018963092938066, -0.999202847480774, 0.035132162272930, 0.004080146551132] + - [0.007699025794864, 0.034991502761841, 0.999357938766479, -0.015980923548341] + - [0.0, 0.0, 0.0, 1.0] + T_cn_cnm1: + - [0.999654293060303, -0.013781057670712, 0.022393604740500, -0.079738616943359] + - [0.013997744768858, 0.999856710433960, -0.009548537433147, -0.000860852771439] + - [-0.022258799523115, 0.009858686476946, 0.999703586101532, 0.000491287559271] + - [0.0, 0.0, 0.0, 1.0] + camera_model: pinhole + distortion_coeffs: [0.054715570062399, 0.025506600737572, -0.013235029764473, 0.001610828214325] + distortion_model: equidistant + intrinsics: [228.513122558593750, 228.619979858398438, 315.618072509765625, 201.517837524414062] + resolution: [640, 400] + timeshift_cam_imu: -0.001850676140748 diff --git a/collector/config/FS-VI80-S80C_3500000262190088_imu.yaml b/collector/config/FS-VI80-S80C_3500000262190088_imu.yaml new file mode 100644 index 0000000000000000000000000000000000000000..abaa2d2ea0c4872b295ac92f0717d80d94a0888f --- /dev/null +++ b/collector/config/FS-VI80-S80C_3500000262190088_imu.yaml @@ -0,0 +1,19 @@ +%YAML:1.0 +# Generated by dump_fays_imu_calibration.py at 2026-08-26T09:09:04.671171+00:00 +device: + model: FS-VI80-S80C + serial_number: 3500000262190088 + camera_count: 2 +source: + api: FAYS_VIK_GetCalibrationParam + physical_usb_path: 2-3.2 + ft_index: null + stereo_dev_port: /dev/video0 + imu_dev_port: /dev/video2 + usb_speed_mbps: 5000 +imu: + accelerometer_noise_density: 0.00718758347633413 + accelerometer_random_walk: 7.16249485488661e-05 + gyroscope_noise_density: 0.000806373659162483 + gyroscope_random_walk: 8.2719725151112e-06 + update_rate_hz: 1035 diff --git a/collector/config/__init__.py b/collector/config/__init__.py new file mode 100755 index 0000000000000000000000000000000000000000..94bb4dd0a075b3b11aad1269ff2f703ff9839f3b --- /dev/null +++ b/collector/config/__init__.py @@ -0,0 +1,6 @@ +"""config 包 —— 应用配置、国际化与版本号。 + +版本号集中定义于此:settings.APP_VERSION 及其他模块均从这里取值。 +""" + +__version__ = "1.2.1" # 修复大文件上传被 10 秒误杀(urllib3 发送请求体阶段 socket 超时错用连接超时,服务器慢读停顿超 10s 即 Connection aborted,现已改用读超时窗口);上传对话框关闭后任务在后台继续完成(手动上传并入主窗口共享上传队列,重复提交自动跳过)。 \ No newline at end of file diff --git a/collector/config/fays_device.json b/collector/config/fays_device.json new file mode 100644 index 0000000000000000000000000000000000000000..bbaeb95d5b3e27aae238345fbc0dcd2c2c1c672a --- /dev/null +++ b/collector/config/fays_device.json @@ -0,0 +1,13 @@ +{ + "model": "FS-VI80-S80C", + "serial": "3500000262190088", + "firmware": "1.2.5", + "camera_count": 2, + "imu_count": 1, + "sdk_version": "3.9.0", + "stereo_dev_port": "/dev/video0", + "imu_dev_port": "/dev/video2", + "physical_usb_path": "2-3.2", + "usb_speed_mbps": 5000, + "captured_at": "2026-08-26T09:09:04.671267+00:00" +} \ No newline at end of file diff --git a/collector/config/i18n.py b/collector/config/i18n.py new file mode 100755 index 0000000000000000000000000000000000000000..2fb1f74d2ec3eb97259aa2d5c76449ed622539ae --- /dev/null +++ b/collector/config/i18n.py @@ -0,0 +1,536 @@ +""" +国际化(i18n)模块 —— 中英文切换支持。 + +使用方式: + from config.i18n import tr, lang_manager + text = tr("开始录制") # 返回当前语言的翻译 + lang_manager.set_language("en") # 切到英文 + lang_manager.language_changed.connect(my_slot) # 监听语言切换 +""" + +from PyQt5.QtCore import QObject, pyqtSignal + + +# ═══════════════════════════════════════════════════════ +# 翻译字典 { 中文原文: { "en": "English", "zh": "中文" } } +# ═══════════════════════════════════════════════════════ + +_TRANSLATIONS = { + # ── 录制记录 ────────────────────────────────────── + "多路录制": {"en": "Multi-Camera", "zh": "多路录制"}, + + # ── 应用程序 ────────────────────────────────────── + "DAQ 视频管线": {"en": "DAQ Video Pipeline", "zh": "DAQ 视频管线"}, + "多路摄像机实时监控与录制系统": {"en": "Multi-camera Monitoring & Recording System", "zh": "多路摄像机实时监控与录制系统"}, + + # ── 菜单栏 ──────────────────────────────────────── + "文件(&F)": {"en": "&File", "zh": "文件(&F)"}, + "扫描摄像机": {"en": "Scan Cameras", "zh": "扫描摄像机"}, + "添加摄像机…": {"en": "Add Camera…", "zh": "添加摄像机…"}, + "退出(&X)": {"en": "E&xit", "zh": "退出(&X)"}, + "视图(&V)": {"en": "&View", "zh": "视图(&V)"}, + "清空日志": {"en": "Clear Log", "zh": "清空日志"}, + "刷新历史记录": {"en": "Refresh History", "zh": "刷新历史记录"}, + "重置画面大小": {"en": "Reset Camera Sizes", "zh": "重置画面大小"}, + "帮助(&H)": {"en": "&Help", "zh": "帮助(&H)"}, + "关于": {"en": "About", "zh": "关于"}, + "语言(&L)": {"en": "&Language", "zh": "语言(&L)"}, + "中文": {"en": "中文", "zh": "中文"}, + "English": {"en": "English", "zh": "English"}, + + # ── 工具栏 ──────────────────────────────────────── + "🔍 扫描": {"en": "🔍 Scan", "zh": "🔍 扫描"}, + "+ 添加": {"en": "+ Add", "zh": "+ 添加"}, + "⏺ 全部录制": {"en": "⏺ Record All", "zh": "⏺ 全部录制"}, + "⏹ 完成录制": {"en": "⏹ Finish Recording", "zh": "⏹ 完成录制"}, + "⛔ 异常终止": {"en": "⛔ Abort Recording", "zh": "⛔ 异常终止"}, + "✕ 全部移除": {"en": "✕ Remove All", "zh": "✕ 全部移除"}, + "📂 回放": {"en": "📂 Playback", "zh": "📂 回放"}, + "☁ 上传": {"en": "☁ Upload", "zh": "☁ 上传"}, + + # ── 工具栏提示 ──────────────────────────────────── + "任务名称…": {"en": "Task name…", "zh": "任务名称…"}, + "输入任务名称,录制文件夹将包含此标注": {"en": "Enter a task name to label the recording folder", "zh": "输入任务名称,录制文件夹将包含此标注"}, + "停止录制并永久删除本次录制的全部文件": {"en": "Stop recording and permanently delete all files of this session", "zh": "停止录制并永久删除本次录制的全部文件"}, + + # ── 相机控件 ────────────────────────────────────── + "● 开始录制": {"en": "● Start Recording", "zh": "● 开始录制"}, + "■ 完成录制": {"en": "■ Stop Recording", "zh": "■ 完成录制"}, + "✕ 异常停止": {"en": "✕ Abort", "zh": "✕ 异常停止"}, + "无信号": {"en": "No Signal", "zh": "无信号"}, + "已断开": {"en": "Disconnected", "zh": "已断开"}, + "等待中…": {"en": "Waiting…", "zh": "等待中…"}, + "FPS": {"en": "FPS", "zh": "FPS"}, + + # ── 状态栏 ──────────────────────────────────────── + "就绪": {"en": "Ready", "zh": "就绪"}, + "摄像机:": {"en": "Cameras:", "zh": "摄像机:"}, + "录制中:": {"en": "Recording:", "zh": "录制中:"}, + + # ── 日志消息 ────────────────────────────────────── + "DAQ 视频管线已启动。": {"en": "DAQ Video Pipeline started.", "zh": "DAQ 视频管线已启动。"}, + "录制目录:": {"en": "Recording directory:", "zh": "录制目录:"}, + "正在扫描摄像机 (MSMF → DShow → AUTO)…": {"en": "Scanning for cameras (MSMF → DShow → AUTO)…", "zh": "正在扫描摄像机 (MSMF → DShow → AUTO)…"}, + "发现 Camera {},后端: {}": {"en": "Found Camera {} via {}", "zh": "发现 Camera {},后端: {}"}, + "未检测到摄像机。": {"en": "No cameras detected.", "zh": "未检测到摄像机。"}, + "检测到 {} 台摄像机。": {"en": "Detected {} camera(s).", "zh": "检测到 {} 台摄像机。"}, + "摄像机 {} 已添加 ({}):": {"en": "Camera {} added as '{}'.", "zh": "摄像机 {} 已添加 ({}):"}, + "摄像机 '{}' 已移除。": {"en": "Camera '{}' removed.", "zh": "摄像机 '{}' 已移除。"}, + "[{}] 摄像机状态: {}": {"en": "[{}] Camera state: {}", "zh": "[{}] 摄像机状态: {}"}, + "[{}] ▶ 录制开始。": {"en": "[{}] ▶ Recording started.", "zh": "[{}] ▶ 录制开始。"}, + "[{}] ▶ 录制开始 — 编码: {}": {"en": "[{}] ▶ Recording started — codec: {}", "zh": "[{}] ▶ 录制开始 — 编码: {}"}, + " | 任务: {}": {"en": " | Task: {}", "zh": " | 任务: {}"}, + "[{}] ■ 录制完成: {} ({} MB)": {"en": "[{}] ■ Recording completed: {} ({} MB)", "zh": "[{}] ■ 录制完成: {} ({} MB)"}, + "[{}] ✕ 录制已丢弃。": {"en": "[{}] ✕ Recording aborted — file discarded.", "zh": "[{}] ✕ 录制已丢弃。"}, + "[{}] 相机已打开: {}×{} @ {}": {"en": "[{}] Camera opened: {}×{} @ {}", "zh": "[{}] 相机已打开: {}×{} @ {}"}, + + # ── 录制完成消息 ────────────────────────────────── + "[{}] ■ 录制完成: {}": {"en": "[{}] ■ Recording completed: {}", "zh": "[{}] ■ 录制完成: {}"}, + + # ── 双目摄像机 ──────────────────────────────────── + "正在启动双目摄像机 (S80M)…": {"en": "Starting stereo camera (S80M)…", "zh": "正在启动双目摄像机 (S80M)…"}, + "双目管道已连接,等待帧数据…": {"en": "Stereo pipe connected, waiting for frames…", "zh": "双目管道已连接,等待帧数据…"}, + "双目摄像机已启动": {"en": "Stereo camera started", "zh": "双目摄像机已启动"}, + "双目摄像机画面已开始传输": {"en": "Stereo camera streaming started", "zh": "双目摄像机画面已开始传输"}, + "[双目] 管道断开": {"en": "[Stereo] Pipe broken", "zh": "[双目] 管道断开"}, + "[双目错误] 读取帧异常: {}": {"en": "[Stereo Error] Read exception: {}", "zh": "[双目错误] 读取帧异常: {}"}, + "双目摄像机已断开 (共 {} 帧)": {"en": "Stereo camera disconnected ({} frames)", "zh": "双目摄像机已断开 (共 {} 帧)"}, + "[双目] 子进程已退出,退出码: {}": {"en": "[Stereo] Subprocess exited, code: {}", "zh": "[双目] 子进程已退出,退出码: {}"}, + "[双目 stderr] {}": {"en": "[Stereo stderr] {}", "zh": "[双目 stderr] {}"}, + "[错误] 双目 demo 脚本不存在": {"en": "[Error] Stereo demo script not found", "zh": "[错误] 双目 demo 脚本不存在"}, + + # ── 相机模式切换 ────────────────────────────────── + "📷 单目摄像机": {"en": "📷 Mono Camera", "zh": "📷 单目摄像机"}, + "👁 双目摄像机 (S80M)": {"en": "👁 Stereo Camera (S80M)", "zh": "👁 双目摄像机 (S80M)"}, + "切换摄像机类型": {"en": "Switch camera type", "zh": "切换摄像机类型"}, + "已切换到:单目摄像机模式": {"en": "Switched to: Mono camera mode", "zh": "已切换到:单目摄像机模式"}, + "已切换到:双目摄像机模式 (S80M)": {"en": "Switched to: Stereo camera mode (S80M)", "zh": "已切换到:双目摄像机模式 (S80M)"}, + "🔭 深度双目 (RealSense)": {"en": "🔭 Depth Stereo (RealSense)", "zh": "🔭 深度双目 (RealSense)"}, + "已切换到:深度双目模式 (RealSense)": {"en": "Switched to: Depth stereo mode (RealSense)", "zh": "已切换到:深度双目模式 (RealSense)"}, + "正在启动深度双目摄像机 ({})…": {"en": "Starting depth stereo camera ({})…", "zh": "正在启动深度双目摄像机 ({})…"}, + "深度双目摄像机已启动: {}": {"en": "Depth stereo camera started: {}", "zh": "深度双目摄像机已启动: {}"}, + "[错误] 未检测到 RealSense 设备": {"en": "[Error] No RealSense device detected", "zh": "[错误] 未检测到 RealSense 设备"}, + "[RealSense 错误] {}": {"en": "[RealSense error] {}", "zh": "[RealSense 错误] {}"}, + "请选择相机模式(单目/双目),然后点击 [扫描] 按钮。": { + "en": "Please select camera mode (Mono/Stereo), then click [Scan].", + "zh": "请选择相机模式(单目/双目),然后点击 [扫描] 按钮。", + }, + + # ── 错误消息 ────────────────────────────────────── + "[错误]": {"en": "[ERROR]", "zh": "[错误]"}, + "摄像机 {}: 无法打开 (已尝试 MSMF, DShow, AUTO)": {"en": "Camera {}: cannot open (tried MSMF, DShow, AUTO)", "zh": "摄像机 {}: 无法打开 (已尝试 MSMF, DShow, AUTO)"}, + "添加摄像机 {} 失败: {}": {"en": "Failed to add camera {}: {}", "zh": "添加摄像机 {} 失败: {}"}, + "摄像机 {} 读取连续失败 ({} 帧)": {"en": "Camera {}: read failed ({} consecutive)", "zh": "摄像机 {} 读取连续失败 ({} 帧)"}, + + # ── 对话框 ──────────────────────────────────────── + "摄像机检测": {"en": "Camera Detection", "zh": "摄像机检测"}, + "未找到摄像机。\n\n请检查:\n• 摄像机是否已连接且未被其他程序占用\n• 摄像机驱动是否已安装\n• 尝试用索引 0、1、2… 手动添加": { + "en": "No cameras found.\n\nCheck:\n• Camera is connected and not in use\n• Camera driver is installed\n• Try adding manually with index 0, 1, 2…", + "zh": "未找到摄像机。\n\n请检查:\n• 摄像机是否已连接且未被其他程序占用\n• 摄像机驱动是否已安装\n• 尝试用索引 0、1、2… 手动添加", + }, + "警告": {"en": "Warning", "zh": "警告"}, + "摄像机 {} 已存在。": {"en": "Camera {} already added.", "zh": "摄像机 {} 已存在。"}, + "确认": {"en": "Confirm", "zh": "确认"}, + "摄像机 {} 正在录制中,确定要中止并移除?": {"en": "Camera {} is recording. Abort and remove?", "zh": "摄像机 {} 正在录制中,确定要中止并移除?"}, + "移除所有摄像机?": {"en": "Remove all cameras?", "zh": "移除所有摄像机?"}, + "添加摄像机": {"en": "Add Camera", "zh": "添加摄像机"}, + "摄像机索引:": {"en": "Camera index:", "zh": "摄像机索引:"}, + + # ── 面板标题 ────────────────────────────────────── + "日志": {"en": "Log", "zh": "日志"}, + "录制历史": {"en": "Recording History", "zh": "录制历史"}, + "摄像机": {"en": "Camera", "zh": "摄像机"}, + "编码": {"en": "Codec", "zh": "编码"}, + "文件": {"en": "File", "zh": "文件"}, + "时长": {"en": "Duration", "zh": "时长"}, + "大小": {"en": "Size", "zh": "大小"}, + "状态": {"en": "Status", "zh": "状态"}, + "已完成": {"en": "COMPLETED", "zh": "已完成"}, + "已丢弃": {"en": "ABORTED", "zh": "已丢弃"}, + "已上传": {"en": "Uploaded", "zh": "已上传"}, + "已删除(未上传)": {"en": "DELETED (NOT UPLOADED)", "zh": "已删除(未上传)"}, + + # ── 关于对话框 ──────────────────────────────────── + "关于 DAQ 视频管线": {"en": "About DAQ Video Pipeline", "zh": "关于 DAQ 视频管线"}, + "实时摄像机预览": {"en": "Real-time camera preview", "zh": "实时摄像机预览"}, + "可拖拽调整的画面布局": {"en": "Draggable-resizable camera layout", "zh": "可拖拽调整的画面布局"}, + "支持正常完成和异常停止两种录制模式": {"en": "Normal finish and abort recording modes", "zh": "支持正常完成和异常停止两种录制模式"}, + "录制历史记录追踪": {"en": "Recording history tracking", "zh": "录制历史记录追踪"}, + "中英文界面切换": {"en": "Bilingual UI (Chinese / English)", "zh": "中英文界面切换"}, + + # ── 空状态提示 ──────────────────────────────────── + '尚未检测到摄像机。\n请从左侧设备面板勾选要开启的设备。': { + "en": "No cameras detected.\nEnable devices from the device panel on the left.", + 'zh': '尚未检测到摄像机。\n请从左侧设备面板勾选要开启的设备。', + }, + + # ── 传感器面板 ──────────────────────────────────── + "传感器阵列": {"en": "Sensor Array", "zh": "传感器阵列"}, + + # ── 设备检测面板 ────────────────────────────────── + "📷 设备检测": {"en": "📷 Device Detection", "zh": "📷 设备检测"}, + "设备列表": {"en": "Device List", "zh": "设备列表"}, + "点击列表中的设备以显示画面": {"en": "Click a device to show its feed", "zh": "点击列表中的设备以显示画面"}, + "插拔自动刷新": {"en": "Auto-refresh on plug/unplug", "zh": "插拔自动刷新"}, + "未检测到设备": {"en": "No devices detected", "zh": "未检测到设备"}, + "已切换设备: {}": {"en": "Switched device: {}", "zh": "已切换设备: {}"}, + "[设备] 已连接: {}": {"en": "[Device] Connected: {}", "zh": "[设备] 已连接: {}"}, + "[设备] 已断开: {}": {"en": "[Device] Disconnected: {}", "zh": "[设备] 已断开: {}"}, + "[设备] {} 已移除。": {"en": "[Device] {} removed.", "zh": "[设备] {} 已移除。"}, + "录制中切换设备将中止当前录制,确定继续?": { + "en": "Switching device during recording will abort the current recording. Continue?", + "zh": "录制中切换设备将中止当前录制,确定继续?", + }, + "USB 摄像头": {"en": "USB Camera", "zh": "USB 摄像头"}, + "[设备] S80M 与 D435 同时连接,SDK 抢占 video0/video2,双目可能无法打开": { + "en": "[Device] S80M and D435 both connected; SDK takes video0/video2, stereo may fail to open", + "zh": "[设备] S80M 与 D435 同时连接,SDK 抢占 video0/video2,双目可能无法打开", + }, + "[设备] 录制中拔线,不自动移除(重插自动恢复): {}": { + "en": "[Device] Unplugged during recording, not auto-removed (recovers on replug): {}", + "zh": "[设备] 录制中拔线,不自动移除(重插自动恢复): {}", + }, + + # ── 设备统一接入(分组 / 开关 / 命名) ────────────── + "📷 相机": {"en": "📷 Cameras", "zh": "📷 相机"}, + "🧤 手套": {"en": "🧤 Gloves", "zh": "🧤 手套"}, + "🎧 其他蓝牙": {"en": "🎧 Other Bluetooth", "zh": "🎧 其他蓝牙"}, + "🎧 其他蓝牙: {} 台": {"en": "🎧 Other Bluetooth: {} device(s)", "zh": "🎧 其他蓝牙: {} 台"}, + "蓝牙": {"en": "Bluetooth", "zh": "蓝牙"}, + "开关设备以显示画面": {"en": "Toggle a device to show its feed", "zh": "开关设备以显示画面"}, + "双击设备可重命名": {"en": "Double-click a device to rename", "zh": "双击设备可重命名"}, + "重命名设备": {"en": "Rename Device", "zh": "重命名设备"}, + "设备名称:": {"en": "Device name:", "zh": "设备名称:"}, + "录制中不可更改设备": {"en": "Devices cannot be changed while recording", "zh": "录制中不可更改设备"}, + "该设备无可视化数据": {"en": "No visualizable data for this device", "zh": "该设备无可视化数据"}, + "S80M 与 D435 无法同时开启": {"en": "S80M and D435 cannot be enabled at the same time", "zh": "S80M 与 D435 无法同时开启"}, + "S80M 与 D435 抢占视频节点(video0/video2),先开者生效": { + "en": "S80M and D435 conflict on video nodes (video0/video2); the first one opened wins", + "zh": "S80M 与 D435 抢占视频节点(video0/video2),先开者生效", + }, + "[设备] 已开启: {}": {"en": "[Device] Enabled: {}", "zh": "[设备] 已开启: {}"}, + "[设备] 已关闭: {}": {"en": "[Device] Disabled: {}", "zh": "[设备] 已关闭: {}"}, + "[设备] 已重命名: {}": {"en": "[Device] Renamed: {}", "zh": "[设备] 已重命名: {}"}, + "[设备] 开启失败: {}": {"en": "[Device] Failed to enable: {}", "zh": "[设备] 开启失败: {}"}, + + # ── 每设备曝光设置(信息条 ☀ 按钮) ──────────────── + "曝光设置": {"en": "Exposure", "zh": "曝光设置"}, + "自动曝光": {"en": "Auto exposure", "zh": "自动曝光"}, + "拖动滑块即时生效": {"en": "Drag the slider to adjust live", "zh": "拖动滑块即时生效"}, + "恢复默认": {"en": "Reset to default", "zh": "恢复默认"}, + "回到相机最一开始的曝光设置": {"en": "Restore the camera's original exposure settings", "zh": "回到相机最一开始的曝光设置"}, + "录制中不可调整曝光": {"en": "Exposure cannot be adjusted while recording", "zh": "录制中不可调整曝光"}, + "[双目] 曝光下发失败(子进程已退出)": { + "en": "[Stereo] Exposure command failed (subprocess exited)", + "zh": "[双目] 曝光下发失败(子进程已退出)", + }, + + # ── 状态显示 ────────────────────────────────────── + "● 录制中 ({} 台摄像机)…": {"en": "● Recording ({} camera(s))…", "zh": "● 录制中 ({} 台摄像机)…"}, + "DAQ 视频管线已关闭。": {"en": "DAQ Video Pipeline shut down.", "zh": "DAQ 视频管线已关闭。"}, + "正在扫描摄像机…": {"en": "Scanning for cameras…", "zh": "正在扫描摄像机…"}, + "正在扫描设备…": {"en": "Scanning for devices…", "zh": "正在扫描设备…"}, + "⛔ 录制已异常终止,文件已丢弃。": {"en": "⛔ Recording aborted, files discarded.", "zh": "⛔ 录制已异常终止,文件已丢弃。"}, + + # ── 传感器面板 ──────────────────────────────────── + "传感器阵列 (BLE)": {"en": "Sensor Array (BLE)", "zh": "传感器阵列 (BLE)"}, + "传感器 Right": {"en": "Sensor Right", "zh": "传感器 Right"}, + "传感器 Left": {"en": "Sensor Left", "zh": "传感器 Left"}, + "传感器 {} ({})": {"en": "Sensor {} ({})", "zh": "传感器 {} ({})"}, + "🔍 扫描设备": {"en": "🔍 Scan Device", "zh": "🔍 扫描设备"}, + "选择 BLE 设备": {"en": "Select BLE Device", "zh": "选择 BLE 设备"}, + "🔗 连接": {"en": "🔗 Connect", "zh": "🔗 连接"}, + "未连接": {"en": "Not Connected", "zh": "未连接"}, + "模式:": {"en": "Mode:", "zh": "模式:"}, + "🔥 热力图 (Heatmap)": {"en": "🔥 Heatmap", "zh": "🔥 热力图 (Heatmap)"}, + "📝 轨迹 (Trace)": {"en": "📝 Trace", "zh": "📝 轨迹 (Trace)"}, + "📊 网格 (Grid)": {"en": "📊 Grid", "zh": "📊 网格 (Grid)"}, + "🦾 仿生手掌 (Hand)": {"en": "🦾 Bionic Hand", "zh": "🦾 仿生手掌 (Hand)"}, + "🕸 形变网格 (Deform)": {"en": "🕸 Deform Mesh", "zh": "🕸 形变网格 (Deform)"}, + "🖐 3D 手掌 (3D Hand)": {"en": "🖐 3D Hand", "zh": "🖐 3D 手掌 (3D Hand)"}, + "📐 校准": {"en": "📐 Calibrate", "zh": "📐 校准"}, + "⚙ 配置": {"en": "⚙ Config", "zh": "⚙ 配置"}, + "▸ 降噪参数": {"en": "▸ Denoise Params", "zh": "▸ 降噪参数"}, + "噪声门:": {"en": "Noise Gate:", "zh": "噪声门:"}, + "动态比率:": {"en": "Dynamic Ratio:", "zh": "动态比率:"}, + "空间滤波": {"en": "Spatial Filter", "zh": "空间滤波"}, + "正在扫描…": {"en": "Scanning…", "zh": "正在扫描…"}, + "扫描中…": {"en": "Scanning…", "zh": "扫描中…"}, + "未发现设备": {"en": "No devices found", "zh": "未发现设备"}, + "发现 {} 台设备": {"en": "Found {} device(s)", "zh": "发现 {} 台设备"}, + "断开": {"en": "Disconnect", "zh": "断开"}, + "连接中…": {"en": "Connecting…", "zh": "连接中…"}, + "已连接: {}…": {"en": "Connected: {}…", "zh": "已连接: {}…"}, + "已断开": {"en": "Disconnected", "zh": "已断开"}, + "校准完成": {"en": "Calibration complete", "zh": "校准完成"}, + "校准中… {}%": {"en": "Calibrating… {}%", "zh": "校准中… {}%"}, + "校准中…": {"en": "Calibrating…", "zh": "校准中…"}, + "热力图/轨迹配置": {"en": "Heatmap / Trace Config", "zh": "热力图/轨迹配置"}, + "网格配置": {"en": "Grid Config", "zh": "网格配置"}, + "形变网格配置": {"en": "Deform Mesh Config", "zh": "形变网格配置"}, + "[Sensor] {}": {"en": "[Sensor] {}", "zh": "[Sensor] {}"}, + + # ── 回放对话框 ──────────────────────────────────── + "录制回放": {"en": "Recording Playback", "zh": "录制回放"}, + "录制目录:": {"en": "Recording Directory:", "zh": "录制目录:"}, + "刷新": {"en": "Refresh", "zh": "刷新"}, + "录制会话:": {"en": "Recording Sessions:", "zh": "录制会话:"}, + "传感器数据": {"en": "Sensor Data", "zh": "传感器数据"}, + "显示模式:": {"en": "Display Mode:", "zh": "显示模式:"}, + "选择录制目录": {"en": "Select Recording Directory", "zh": "选择录制目录"}, + "提示": {"en": "Notice", "zh": "提示"}, + "请先勾选要删除的会话": {"en": "Please check sessions to delete first", "zh": "请先勾选要删除的会话"}, + "确认删除": {"en": "Confirm Delete", "zh": "确认删除"}, + "完成": {"en": "Done", "zh": "完成"}, + "⬆ 选中已上传": {"en": "⬆ Select Uploaded", "zh": "⬆ 选中已上传"}, + "仅勾选已上传的会话": {"en": "Select only uploaded sessions", "zh": "仅勾选已上传的会话"}, + "⬇ 选中未上传": {"en": "⬇ Select Not Uploaded", "zh": "⬇ 选中未上传"}, + "仅勾选未上传的会话": {"en": "Select only not-uploaded sessions", "zh": "仅勾选未上传的会话"}, + "🗑 删除选中": {"en": "🗑 Delete Selected", "zh": "🗑 删除选中"}, + "将选中的会话移入回收站": {"en": "Move selected sessions to recycle bin", "zh": "将选中的会话移入回收站"}, + "▶ 播放": {"en": "▶ Play", "zh": "▶ 播放"}, + "⏸ 暂停": {"en": "⏸ Pause", "zh": "⏸ 暂停"}, + "没有找到视频文件": {"en": "No video files found", "zh": "没有找到视频文件"}, + "路": {"en": "ch", "zh": "路"}, + "加载失败: {}": {"en": "Load failed: {}", "zh": "加载失败: {}"}, + "确定要将以下会话移入回收站?\n\n{}\n\n此操作可逆(可从回收站恢复)。": { + "en": "Move the following sessions to recycle bin?\n\n{}\n\nThis operation is reversible.", + "zh": "确定要将以下会话移入回收站?\n\n{}\n\n此操作可逆(可从回收站恢复)。", + }, + "已删除 {}/{} 个会话(已移入回收站)。": { + "en": "Deleted {}/{} session(s) (moved to recycle bin).", + "zh": "已删除 {}/{} 个会话(已移入回收站)。", + }, + "传感器 TS: {} Δ={}ms": { + "en": "Sensor TS: {} Δ={}ms", + "zh": "传感器 TS: {} Δ={}ms", + }, + + # ── 上传对话框 ──────────────────────────────────── + "上传录制数据": {"en": "Upload Recording Data", "zh": "上传录制数据"}, + "服务器配置": {"en": "Server Configuration", "zh": "服务器配置"}, + "服务器地址:": {"en": "Server Address:", "zh": "服务器地址:"}, + "测试连接": {"en": "Test Connection", "zh": "测试连接"}, + "选择要上传的会话": {"en": "Select Sessions to Upload", "zh": "选择要上传的会话"}, + "全选": {"en": "Select All", "zh": "全选"}, + "⬆ 一键上传": {"en": "⬆ Upload", "zh": "⬆ 一键上传"}, + "关闭": {"en": "Close", "zh": "关闭"}, + "请先勾选要上传的会话": {"en": "Please select sessions to upload first", "zh": "请先勾选要上传的会话"}, + "请输入服务器地址": {"en": "Please enter server address", "zh": "请输入服务器地址"}, + "成功": {"en": "Success", "zh": "成功"}, + "服务器连接正常 ✅": {"en": "Server connection OK ✅", "zh": "服务器连接正常 ✅"}, + "失败": {"en": "Failed", "zh": "失败"}, + "无法连接到服务器 ❌": {"en": "Cannot connect to server ❌", "zh": "无法连接到服务器 ❌"}, + "已入队 {} 个任务,开始处理…": {"en": "Queued {} task(s), processing…", "zh": "已入队 {} 个任务,开始处理…"}, + "全部完成": {"en": "All complete", "zh": "全部完成"}, + + # ── 上传开关(自动上传 / 上传后自动删除) ───────────── + "☁ 自动上传: {}": {"en": "☁ Auto upload: {}", "zh": "☁ 自动上传: {}"}, + "录制完成后自动上传;关闭后需在 ☁ 上传对话框手动上传": { + "en": "Auto-upload after recording; when off, upload manually from the ☁ Upload dialog", + "zh": "录制完成后自动上传;关闭后需在 ☁ 上传对话框手动上传", + }, + "☁ 自动上传未开启,请手动上传: {}": {"en": "☁ Auto upload is off, upload manually: {}", "zh": "☁ 自动上传未开启,请手动上传: {}"}, + "🗑 上传后自动删除: {}": {"en": "🗑 Auto-delete after upload: {}", "zh": "🗑 上传后自动删除: {}"}, + "开": {"en": "ON", "zh": "开"}, + "关": {"en": "OFF", "zh": "关"}, + "上传成功后自动删除该会话的本地文件": { + "en": "Delete local session files after a successful upload", + "zh": "上传成功后自动删除该会话的本地文件", + }, + "☁ 上传完成,本地文件已删除: {}": {"en": "☁ Upload complete, local files deleted: {}", "zh": "☁ 上传完成,本地文件已删除: {}"}, + "☁ 上传完成(本地保留): {}": {"en": "☁ Upload complete (kept locally): {}", "zh": "☁ 上传完成(本地保留): {}"}, + "❌ 上传失败: {}": {"en": "❌ Upload failed: {}", "zh": "❌ 上传失败: {}"}, + "[错误] 上传后自动删除失败: {}": {"en": "[Error] Auto-delete after upload failed: {}", "zh": "[错误] 上传后自动删除失败: {}"}, + "已上传,本地已删": {"en": "Uploaded, deleted locally", "zh": "已上传,本地已删"}, + + # ── 数据查看器 ──────────────────────────────────── + "📂 浏览录制目录": {"en": "📂 Browse Recordings", "zh": "📂 浏览录制目录"}, + "🔄 刷新": {"en": "🔄 Refresh", "zh": "🔄 刷新"}, + "📋 录制会话:": {"en": "📋 Recording Sessions:", "zh": "📋 录制会话:"}, + "选择会话开始回放": {"en": "Select a session to start playback", "zh": "选择会话开始回放"}, + "📹 视频": {"en": "📹 Video", "zh": "📹 视频"}, + "📊 传感器": {"en": "📊 Sensor", "zh": "📊 传感器"}, + + # ── 任务选择页面 ──────────────────────────────────── + "连接": {"en": "Connect", "zh": "连接"}, + "用户名": {"en": "Username", "zh": "用户名"}, + "密码": {"en": "Password", "zh": "密码"}, + "登陆成功": {"en": "Login OK", "zh": "登陆成功"}, + "登陆失败: {}": {"en": "Login failed: {}", "zh": "登陆失败: {}"}, + "后端已连接": {"en": "Backend Connected", "zh": "后端已连接"}, + "后端未连接": {"en": "Backend Disconnected", "zh": "后端未连接"}, + "已切换服务器: {} (用户: {})": {"en": "Switched server: {} (user: {})", "zh": "已切换服务器: {} (用户: {})"}, + "已切换服务器地址: {} (无认证)": {"en": "Switched server: {} (no auth)", "zh": "已切换服务器地址: {} (无认证)"}, + "刷新中…": {"en": "Refreshing…", "zh": "刷新中…"}, + "可用任务": {"en": "Available Tasks", "zh": "可用任务"}, + "任务详情": {"en": "Task Details", "zh": "任务详情"}, + "← 返回任务选择": {"en": "← Back to Task Selection", "zh": "← 返回任务选择"}, + "← 请从左侧列表中选择一个任务": {"en": "← Select a task from the list", "zh": "← 请从左侧列表中选择一个任务"}, + "→ 进入采集": {"en": "→ Start Collection", "zh": "→ 进入采集"}, + "已选择: {}": {"en": "Selected: {}", "zh": "已选择: {}"}, + "已选择任务: {}": {"en": "Task selected: {}", "zh": "已选择任务: {}"}, + "描述:": {"en": "Description:", "zh": "描述:"}, + "任务ID:": {"en": "Task ID:", "zh": "任务ID:"}, + "创建时间:": {"en": "Created:", "zh": "创建时间:"}, + "状态:": {"en": "Status:", "zh": "状态:"}, + "参数:": {"en": "Parameters:", "zh": "参数:"}, + "返回任务选择": {"en": "Back to Task Selection", "zh": "返回任务选择"}, + "待处理": {"en": "Pending", "zh": "待处理"}, + "进行中": {"en": "In Progress", "zh": "进行中"}, + "已取消": {"en": "Cancelled", "zh": "已取消"}, + "未命名任务": {"en": "Unnamed Task", "zh": "未命名任务"}, + "任务名称": {"en": "Task Name", "zh": "任务名称"}, + "进度": {"en": "Progress", "zh": "进度"}, + "发布时间": {"en": "Published", "zh": "发布时间"}, + "暂无可用任务\n请检查后端连接或点击刷新": { + "en": "No tasks available\nCheck backend connection or click refresh", + "zh": "暂无可用任务\n请检查后端连接或点击刷新", + }, + "录制中,确定要返回任务列表?当前录制将被终止。": { + "en": "Recording in progress. Return to task list? Current recording will be aborted.", + "zh": "录制中,确定要返回任务列表?当前录制将被终止。", + }, + "已返回任务选择页面。": {"en": "Returned to task selection page.", "zh": "已返回任务选择页面。"}, + "该任务采集进度已满": {"en": "Task progress is full", "zh": "该任务采集进度已满"}, + "该任务采集进度已满,无法进入": {"en": "Task progress is full, cannot enter", "zh": "该任务采集进度已满,无法进入"}, + "该任务采集进度已满({}/{}),无法开始新的采集。": { + "en": "Task progress is full ({}/{}), cannot start new collection.", + "zh": "该任务采集进度已满({}/{}),无法开始新的采集。", + }, + "☁ 已自动加入上传队列: {}": {"en": "☁ Auto-queued for upload: {}", "zh": "☁ 已自动加入上传队列: {}"}, + "☁ 上传完成: {}": {"en": "☁ Upload complete: {}", "zh": "☁ 上传完成: {}"}, + "第 {}/{} 条": {"en": "#{}/{}", "zh": "第 {}/{} 条"}, + "✅ 第 {}/{} 条上传完成: {}": {"en": "✅ #{}/{} uploaded: {}", "zh": "✅ 第 {}/{} 条上传完成: {}"}, + "✅ 上传完成: {}": {"en": "✅ Uploaded: {}", "zh": "✅ 上传完成: {}"}, + "[上传失败] {}: {}": {"en": "[Upload failed] {}: {}", "zh": "[上传失败] {}: {}"}, + "发布时间:": {"en": "Published:", "zh": "发布时间:"}, + "请在任务选择页面选择一个任务。": {"en": "Please select a task on the task selection page.", "zh": "请在任务选择页面选择一个任务。"}, + "任务进度已更新: {} ({}/{})": {"en": "Task progress updated: {} ({}/{})", "zh": "任务进度已更新: {} ({}/{})"}, + "提示": {"en": "Notice", "zh": "提示"}, + "🗑 删除": {"en": "🗑 Delete", "zh": "🗑 删除"}, + "确定要删除任务 \"{}\" 吗?\n删除后可在 tasks.json 中恢复。": { + "en": "Delete task \"{}\"?\nIt can be restored in tasks.json.", + "zh": "确定要删除任务 \"{}\" 吗?\n删除后可在 tasks.json 中恢复。", + }, + "🗑 删除任务": {"en": "🗑 Delete Task", "zh": "🗑 删除任务"}, + "待采集": {"en": "Pending", "zh": "待采集"}, + "采集完成": {"en": "Completed", "zh": "采集完成"}, + "采集中": {"en": "In Progress", "zh": "采集中"}, + "该任务已采集完成,请更换其他任务": {"en": "Task collection complete, please switch to another task.", "zh": "该任务已采集完成,请更换其他任务"}, + + # ── 登录对话框 / 身份 ─────────────────────────────── + "用户登录": {"en": "User Login", "zh": "用户登录"}, + "登录": {"en": "Login", "zh": "登录"}, + "记住账号": {"en": "Remember account", "zh": "记住账号"}, + "游客登录": {"en": "Guest Login", "zh": "游客登录"}, + "登录中…": {"en": "Logging in…", "zh": "登录中…"}, + "请输入用户名": {"en": "Please enter username", "zh": "请输入用户名"}, + "输入后端派发的账号登录,或点「游客登录」直接进入(仅可见公共任务)。": { + "en": "Sign in with the account issued by the backend, or click \"Guest Login\" to continue (public tasks only).", + "zh": "输入后端派发的账号登录,或点「游客登录」直接进入(仅可见公共任务)。", + }, + "当前身份:": {"en": "Current identity:", "zh": "当前身份:"}, + "切换账号": {"en": "Switch account", "zh": "切换账号"}, + "游客": {"en": "Guest", "zh": "游客"}, + "已登录: {} ({})": {"en": "Logged in: {} ({})", "zh": "已登录: {} ({})"}, + "已进入游客模式(仅可见公共任务)。": {"en": "Entered guest mode (public tasks only).", "zh": "已进入游客模式(仅可见公共任务)。"}, + "登录已过期,请重新登录。": {"en": "Login expired, please sign in again.", "zh": "登录已过期,请重新登录。"}, + + # ── 使用说明窗口 ──────────────────────────────── + "使用说明": {"en": "Usage Guide", "zh": "使用说明"}, + "使用步骤": {"en": "Usage Steps", "zh": "使用步骤"}, + "下次启动不再自动显示(可随时从 帮助→使用说明 重新打开并取消勾选)": { + "en": "Don't show automatically at startup (reopen anytime via Help → Usage Guide to undo)", + "zh": "下次启动不再自动显示(可随时从 帮助→使用说明 重新打开并取消勾选)", + }, + + # ── 手部关键点追踪 ──────────────────────────────── + "🧤 手套追踪": {"en": "🧤 Glove Tracking", "zh": "🧤 手套追踪"}, + "🖐 裸手追踪": {"en": "🖐 Bare Hand", "zh": "🖐 裸手追踪"}, + "✋ 手部叠加": {"en": "✋ Hand Overlay", "zh": "✋ 手部叠加"}, + "🔄 提取关键点": {"en": "🔄 Extract Keypoints", "zh": "🔄 提取关键点"}, + "✋ 处理手部关键点": {"en": "✋ Process Hand Keypoints", "zh": "✋ 处理手部关键点"}, + "对录制完成的视频后台提取手部关键点": {"en": "Extract hand keypoints from recorded video in background", "zh": "对录制完成的视频后台提取手部关键点"}, + "后台处理当前视频,提取手部关键点": {"en": "Process current video in background, extract hand keypoints", "zh": "后台处理当前视频,提取手部关键点"}, + "手部关键点处理正在进行中,请等待完成。": {"en": "Hand keypoint processing in progress, please wait.", "zh": "手部关键点处理正在进行中,请等待完成。"}, + "该录制已有手部关键点数据,要重新处理吗?": {"en": "This recording already has hand keypoint data. Reprocess?", "zh": "该录制已有手部关键点数据,要重新处理吗?"}, + "[手部关键点] 模块不可用(缺少依赖)。": {"en": "[Hand Kpts] Module unavailable (missing dependencies).", "zh": "[手部关键点] 模块不可用(缺少依赖)。"}, + "[手部关键点] 没有找到可处理的录制。": {"en": "[Hand Kpts] No recordable session found.", "zh": "[手部关键点] 没有找到可处理的录制。"}, + "[手部关键点] 会话目录不存在: {}": {"en": "[Hand Kpts] Session directory not found: {}", "zh": "[手部关键点] 会话目录不存在: {}"}, + "[手部关键点] 开始处理: {}": {"en": "[Hand Kpts] Processing: {}", "zh": "[手部关键点] 开始处理: {}"}, + "[手部关键点] {}": {"en": "[Hand Kpts] {}", "zh": "[手部关键点] {}"}, + "✋ 处理手部关键点: {}/{} ({:.0f}%)": {"en": "✋ Processing hand keypoints: {}/{} ({:.0f}%)", "zh": "✋ 处理手部关键点: {}/{} ({:.0f}%)"}, + "[手部关键点] ❌ 处理失败: {}": {"en": "[Hand Kpts] ❌ Processing failed: {}", "zh": "[手部关键点] ❌ 处理失败: {}"}, + "[手部关键点] ✅ 处理完成: {}": {"en": "[Hand Kpts] ✅ Processing complete: {}", "zh": "[手部关键点] ✅ 处理完成: {}"}, + "手部关键点": {"en": "Hand Keypoints", "zh": "手部关键点"}, + "⏳ 处理中…": {"en": "⏳ Processing…", "zh": "⏳ 处理中…"}, + "⏳ {:.0f}%": {"en": "⏳ {:.0f}%", "zh": "⏳ {:.0f}%"}, + "手部关键点模块不可用。": {"en": "Hand keypoint module unavailable.", "zh": "手部关键点模块不可用。"}, + "选择手部追踪模式:黑色手套 / 裸手": {"en": "Select hand tracking mode: Glove / Bare Hand", "zh": "选择手部追踪模式:黑色手套 / 裸手"}, + "选择手部追踪模式": {"en": "Select hand tracking mode", "zh": "选择手部追踪模式"}, + "📊 自动标注": {"en": "📊 Auto Label", "zh": "📊 自动标注"}, + "基于手部关键点数据自动生成手势标签": {"en": "Auto-generate gesture labels from hand keypoint data", "zh": "基于手部关键点数据自动生成手势标签"}, + "[自动标注] 模块不可用。": {"en": "[Auto Label] Module unavailable.", "zh": "[自动标注] 模块不可用。"}, + "[自动标注] 没有找到可处理的录制。": {"en": "[Auto Label] No recordable session found.", "zh": "[自动标注] 没有找到可处理的录制。"}, + "[自动标注] 会话目录不存在: {}": {"en": "[Auto Label] Session directory not found: {}", "zh": "[自动标注] 会话目录不存在: {}"}, + "[自动标注] 请先提取手部关键点。": {"en": "[Auto Label] Please extract hand keypoints first.", "zh": "[自动标注] 请先提取手部关键点。"}, + "[自动标注] 开始标注: {}": {"en": "[Auto Label] Labeling: {}", "zh": "[自动标注] 开始标注: {}"}, + "📊 自动标注: {}/{} ({:.0f}%)": {"en": "📊 Auto labeling: {}/{} ({:.0f}%)", "zh": "📊 自动标注: {}/{} ({:.0f}%)"}, + "[自动标注] ❌ 标注失败: {}": {"en": "[Auto Label] ❌ Labeling failed: {}", "zh": "[自动标注] ❌ 标注失败: {}"}, + "[自动标注] ✅ 标注完成: {}": {"en": "[Auto Label] ✅ Labeling complete: {}", "zh": "[自动标注] ✅ 标注完成: {}"}, + "⏳ 标注中…": {"en": "⏳ Labeling…", "zh": "⏳ 标注中…"}, +} + + +# ═══════════════════════════════════════════════════════ +# 语言管理器(单例) +# ═══════════════════════════════════════════════════════ + +class LanguageManager(QObject): + """管理当前语言,切换时发射信号通知所有监听者刷新界面文字。""" + + language_changed = pyqtSignal(str) # 参数: "zh" 或 "en" + + def __init__(self): + super().__init__() + self._current = "en" # 默认英文 + + @property + def current(self) -> str: + return self._current + + def set_language(self, lang: str): + """切换到指定语言并通知所有监听者。""" + if lang not in ("zh", "en"): + return + if lang == self._current: + return + self._current = lang + self.language_changed.emit(lang) + + def toggle(self): + """在中英文之间切换。""" + self.set_language("en" if self._current == "zh" else "zh") + + +# 全局单例 +lang_manager = LanguageManager() + + +def tr(text: str, *fmt_args) -> str: + """ + 翻译函数:根据当前语言返回对应文本。 + + 用法: + tr("开始录制") → "开始录制" 或 "Start Recording" + tr("发现 {} 台摄像机。", 2) → "检测到 2 台摄像机。" 或 "Detected 2 camera(s)." + """ + entry = _TRANSLATIONS.get(text) + if entry is None: + result = text + else: + result = entry.get(lang_manager.current, text) + if fmt_args: + result = result.format(*fmt_args) + return result diff --git a/collector/config/s80m_stereo_calibration.json b/collector/config/s80m_stereo_calibration.json new file mode 100644 index 0000000000000000000000000000000000000000..ca1e9204885b54158d952e6536531f23459b95dc --- /dev/null +++ b/collector/config/s80m_stereo_calibration.json @@ -0,0 +1,60 @@ +{ + "type": "stereo_rgbd_camera", + "name": "head_stereo", + "resolution": [ + 1280, + 800 + ], + "fps": 25.0, + "baseline": 0.0797447770264594, + "left_camera": { + "intrinsic": [ + 457.2199401855469, + 457.3329772949219, + 620.760986328125, + 340.13323974609375 + ], + "distortion": [ + 0.062210198491812, + 0.012444571591914, + -0.003091567661613, + -0.000578491541091 + ], + "distortion_model": "equidistant" + }, + "right_camera": { + "intrinsic": [ + 457.0262451171875, + 457.2399597167969, + 631.2361450195312, + 403.0356750488281 + ], + "distortion": [ + 0.054715570062399, + 0.025506600737572, + -0.013235029764473, + 0.001610828214325 + ], + "distortion_model": "equidistant" + }, + "depth_scale": 0.001, + "cam_imu_timeshift": -0.001947268727235, + "rotation": [ + 0.999654293060303, + -0.013781057670712, + 0.0223936047405, + 0.013997744768858, + 0.99985671043396, + -0.009548537433147, + -0.022258799523115, + 0.009858686476946, + 0.999703586101532 + ], + "translation": [ + -0.079738616943359, + -0.000860852771439, + 0.000491287559271 + ], + "source": "fays_sdk_static_calib", + "captured_at": 1786618577.7006745 +} \ No newline at end of file diff --git a/collector/config/sensors/hand_ble_config.json b/collector/config/sensors/hand_ble_config.json new file mode 100755 index 0000000000000000000000000000000000000000..90d13be66151de9424e090ad8b75621e67d0a9f9 --- /dev/null +++ b/collector/config/sensors/hand_ble_config.json @@ -0,0 +1,165 @@ +{ + "thumb_tip": { + "name": "大拇指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "thumb_joint": { + "name": "大拇指-关节", + "rows": [ + 1, + 2, + 3 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "thumb_base": { + "name": "大拇指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "index_tip": { + "name": "食指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "index_joint": { + "name": "食指-关节", + "rows": [ + 4, + 5, + 6 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "index_base": { + "name": "食指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "middle_tip": { + "name": "中指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "middle_joint": { + "name": "中指-关节", + "rows": [ + 7, + 8, + 9 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "middle_base": { + "name": "中指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "ring_tip": { + "name": "无名指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "ring_joint": { + "name": "无名指-关节", + "rows": [ + 10, + 11, + 12 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "ring_base": { + "name": "无名指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "pinky_tip": { + "name": "小拇指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "pinky_joint": { + "name": "小拇指-关节", + "rows": [ + 13, + 14, + 15 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "pinky_base": { + "name": "小拇指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "palm": { + "name": "手掌心", + "rows": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15 + ], + "cols": [ + 10, + 9, + 8, + 6, + 4 + ], + "axis_order": "col_row" + } +} diff --git a/collector/config/sensors/hand_ble_config_left.json b/collector/config/sensors/hand_ble_config_left.json new file mode 100755 index 0000000000000000000000000000000000000000..f9b945b7070917abd8df706954401db177e58ecd --- /dev/null +++ b/collector/config/sensors/hand_ble_config_left.json @@ -0,0 +1,164 @@ +{ + "thumb_tip": { + "name": "大拇指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "thumb_joint": { + "name": "大拇指-关节", + "rows": [ + 15, + 14, + 13 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "thumb_base": { + "name": "大拇指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "index_tip": { + "name": "食指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "index_joint": { + "name": "食指-关节", + "rows": [ + 12, + 11, + 10 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "index_base": { + "name": "食指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "middle_tip": { + "name": "中指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "middle_joint": { + "name": "中指-关节", + "rows": [ + 9, + 8, + 7 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "middle_base": { + "name": "中指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "ring_tip": { + "name": "无名指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "ring_joint": { + "name": "无名指-关节", + "rows": [ + 6, + 5, + 4 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "ring_base": { + "name": "无名指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "pinky_tip": { + "name": "小拇指-指肚", + "rows": [], + "cols": [], + "axis_order": "col_row" + }, + "pinky_joint": { + "name": "小拇指-关节", + "rows": [ + 3, + 2, + 1 + ], + "cols": [ + 14, + 12, + 13, + 15 + ], + "axis_order": "col_row" + }, + "pinky_base": { + "name": "小拇指-指根", + "rows": [], + "cols": [], + "axis_order": "row_col" + }, + "palm": { + "name": "手掌心", + "rows": [ + 15, + 14, + 13, + 12, + 11, + 10, + 9, + 8, + 7, + 6, + 5, + 4, + 3, + 2, + 1 + ], + "cols": [ + 10, + 9, + 8, + 6 + ], + "axis_order": "col_row" + } +} \ No newline at end of file diff --git a/collector/config/settings.py b/collector/config/settings.py new file mode 100755 index 0000000000000000000000000000000000000000..5262e4613a6fd31448153ee6c89e50f3c4534064 --- /dev/null +++ b/collector/config/settings.py @@ -0,0 +1,478 @@ +""" +应用程序全局配置 —— 路径、颜色、相机参数等。 +""" + +import os +import sys + +from config import __version__ as APP_VERSION # 版本号唯一定义在 config/__init__.py + +# ── 路径 ────────────────────────────────────────────── +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +DATA_DIR = os.path.join(BASE_DIR, "data") +RECORDINGS_DIR = os.path.join(DATA_DIR, "recordings") +DB_PATH = os.path.join(DATA_DIR, "pipeline.db") +KEYPOINTS_OUTPUT_DIR = os.path.join(BASE_DIR, "keypoints_output") + +# ── 应用程序 ────────────────────────────────────────── +APP_NAME = "EGO数据管线" +WINDOW_WIDTH = 1600 +WINDOW_HEIGHT = 900 + +# ── 相机默认参数 ────────────────────────────────────── +DEFAULT_FPS = 30 +if sys.platform == "win32": + # Windows:DECXIN 驱动对 1280×960「直连」只暴露 5fps 档(UVC 帧率表 + # 怪癖,设 MJPG 也一样)。请求 1280×720 高会命中 30fps 档,实测驱动 + # 协商回 1280×960@30(读回与真实帧尺寸仍为 960 高),画面分辨率不变。 + DEFAULT_RESOLUTION = (1280, 720) +else: + DEFAULT_RESOLUTION = (1280, 960) # Linux:UVC 满分辨率(DECXIN);须配合 UVC_FOURCC=MJPG 才能 30fps +UVC_FOURCC = "MJPG" # UVC 采集像素格式:YUYV 在 1280×960 硬限 5fps + # 且驱动默认格式就是 YUYV,不显式设 MJPG 会静默掉帧率 +CAMERA_RECONNECT_INTERVAL_MS = 2000 # 断线后重试间隔(毫秒) +MAX_CAMERAS = 8 + +# ── 录制参数 ────────────────────────────────────────── +RECORDING_FPS = 30 # 录制帧率 +RECORDING_DIR = RECORDINGS_DIR # 录制文件输出目录 +DEPTH_ENABLED = False # 遗留开关:旧 S80M 视差录制路径(已被 S80M_DEPTH_ENABLED + # 取代;仅剩 egodata_writer 守卫/测试/文档引用,勿再启用) + +# ── 录制编码(v1.0.9:录制直出 HEVC,上传免预压)───── +RECORD_VIDEO_ENCODER = "auto" # "auto" | "nvenc" | "x265" | "x264" + # auto: hevc_nvenc(可用) → libx265(速度达标) → libx264 + # 显式指定: 跳过速度门槛强制用该编码器;所有候选 + # 二进制都不支持时按 auto 链逐级回退(警告日志) +RECORD_VIDEO_CRF = 30 # HEVC 目标档(nvenc 用 -cq,x265 用 -crf) +RECORD_VIDEO_X264_CRF = 23 # x264 回退档(与 v1.0.8 现状一致) +ENCODER_PROBE_ENABLED = True # 编码器探针开关(离线测试/极低端机可关,关=直接 x264) +ENCODER_PROBE_FRAME_COUNT = 45 # x265 速度探针每流合成帧数 +ENCODER_PROBE_MAX_STREAMS = 4 # x265 探针并行流数封顶 +ENCODER_PROBE_TIMEOUT_S = 15 # 单个探针子进程超时(秒) +ENCODER_X265_MIN_FPS_RATIO = 1.5 # x265 采用门槛:实测 fps ≥ 录制帧率 × 该比值 +IMU_PENDING_MAX_SAMPLES = 18000 # 双目 IMU 防丢缓冲上限(~1 分钟 @300Hz) +DROP_WARN_RATIO = 0.01 # 丢帧提示阈值:丢帧 > 总帧数×该比例 或 +DROP_WARN_MIN_COUNT = 30 # 丢帧 > 该帧数 → 提示换编码器/降分辨率 + +# ── 设备命名规范 (EgoData 标准) ─────────────────────── +# 命名约定: <位置>_<模态> +# 头戴左目: head_left_rgb +# 头戴右目: head_right_rgb +# 头戴深度: head_depth +# 触觉传感器: left_glove / right_glove +# 手部关键点: left_hand_pose / right_hand_pose +# +CAMERA_LEFT = "head_left_rgb" +CAMERA_RIGHT = "head_right_rgb" +CAMERA_DEPTH = "head_depth" + +def _camera_slot_name(index: int) -> str: + """OpenCV 设备索引 → EgoData 槽位名。 + + index 0 → head_left_rgb(主相机 / 单目左目) + index 1 → head_right_rgb(双目右目) + index 2+ → head_right_rgb_2, head_right_rgb_3, … + """ + if index == 0: + return CAMERA_LEFT + if index == 1: + return CAMERA_RIGHT + return f"{CAMERA_RIGHT}_{index}" + +# 兼容旧命名(供读取旧 LeRobot v3 会话使用) +CAMERA_PRIMARY_LEGACY = "head_rgb" +def _camera_slot_name_legacy(index: int) -> str: + if index == 0: + return CAMERA_PRIMARY_LEGACY + return f"{CAMERA_PRIMARY_LEGACY}_{index}" + +# ── EgoData 输出格式 ───────────────────────────────── +EPISODE_PREFIX = "episode" +EPISODE_DIGITS = 6 # episode_000001, episode_000002, … +DEPTH_FORMAT = "depth_mkv" # 双流 MKV:流0=热力图 h264(默认播放画面), + # 流1=FFV1 gray16le 无损 uint16 毫米深度。 + # 旧版 png16(PNG 序列)与 raw16 bin 均已弃用—— + # 后者实测体积 6× 且上传被拒收(v1.0.11 回退), + # 前者 2026-09 被双流 MKV 取代(体积减半+彩色画面) +DEPTH_SCALE = 0.001 # 深度单位: 像素值 × DEPTH_SCALE = 米 + +# ── 双目标定默认值 ─────────────────────────────────── +STEREO_BASELINE = 0.095 # 基线 (米) +STEREO_RESOLUTION = (1280, 800) # 双目默认分辨率 +STEREO_FPS = 30 # 双目默认帧率 +STEREO_CAM_FPS = 50 # S80M/S80C 相机档(50=默认,50→30 桶抽帧才录到 30fps;8/31 撕裂根因已由回调取帧修复——官方 GUI 同款回调+深度组合实测无撕裂。25 档保留为回退:25fps 相机下 30 桶只填到 25 帧) +STEREO_RECORD_FPS = 30 # S80M 录制帧率(相机帧按 wall 时钟 1/30s 桶抽帧,hw 时钟跳变不空桶) +STEREO_RECORD_MIN_INTERVAL_S = 1.0 / STEREO_RECORD_FPS # 抽帧桶长(秒) +STEREO_CB_BRIDGE = True # S80M/S80C 取帧用官方 GUI 同款回调(装配完成才交付;shim 缺失/注册失败自动回退轮询) + +# ── S80M/S80C 深度(SDK 深度引擎,子进程内计算) ───────────── +S80M_DEPTH_ENABLED = True # S80C 深度开关(关闭→子进程不加 --depth-sdk-dir,协议字节不变) +S80M_DEPTH_SLOT = "stereo_depth" # 深度槽位(depth/stereo_depth/…,双流 MKV) +S80M_DEPTH_NEAR_MM = 300 # 热力图固定色标下限 mm(引擎量程 300-10000,中位 ~1.7m) +S80M_DEPTH_FAR_MM = 3000 # 热力图固定色标上限 mm +S80M_DEPTH_SMOOTH_K = 3 # 热力图中值滤波核 + +# ── D435 深度双目配置 ─────────────────────────────────── +D435_SLOT_RGB = "d435_rgb" # RGB 彩色槽位(录制为 videos/d435_rgb/…) +D435_SLOT_DEPTH = "d435_depth" # 深度槽位(depth/d435_depth/…,双流 MKV) +D435_RESOLUTION = (848, 480) # (width, height),Depth Z16 @30;左右红外仅内部启用 +D435_RGB_RESOLUTION = (1280, 720) # (width, height),RGB 彩色流(D435 标准 720p 全视场) +D435_FPS = 30 +D435_DEPTH_NEAR_MM = 300 # 实时显示深度范围过滤(毫米,参考 S80M 深度 demo 0.3m) +D435_DEPTH_FAR_MM = 4000 # 实时显示深度范围过滤(毫米,4.0m) +D435_PNG_COMPRESSION = 1 # 原始深度 PNG 压缩级(1 最快) +D435_STALL_TIMEOUT_S = 5 # 流停滞阈值(秒):连续无帧超过该值触发重连 + # (双 RealSense 第二台开流偶发静默停滞,无此 + # 看门狗会无限空转且无任何报错) +D435_LOW_FPS_WINDOW_S = 10 # 帧率看门狗窗口(秒):窗口内帧数低于期望 + # fps 的 D435_LOW_FPS_FRACTION → 触发重连 + # (半死状态——wait_for_frames 零星出帧不报错 + # 但画面极卡,静默看门狗测不到) +D435_LOW_FPS_FRACTION = 0.5 # 帧率下限比例(0.5 = 期望帧率的一半) + +# ── RealSense D400 系列多型号支持 ────────────────────── +# 同一采集模式(面板按序列号区分具体设备),但不同型号的深度原生 +# 分辨率 / 适用距离不同,按型号给采集配置(resolution 为 (width, height))。 +REALSENSE_PROFILES = { + "D405": { + "depth_resolution": (1280, 720), # D405 原生深度分辨率(短距近景相机) + "rgb_resolution": (1280, 720), # D405 RGB 最高 720p + "fps": 30, + "depth_near_mm": 100, # 显示/热力图固定色标(D405 理想工作距 0.07-0.5m) + "depth_far_mm": 1000, + "heatmap_smooth_k": 3, # 热力图 3×3 中值(单像素椒盐噪点) + "heatmap_temporal_alpha": 0.5, # 热力图时域 EMA 权重(帧间抖动;仅可视化) + }, +} + +def realsense_profile(model_name: str) -> dict: + """按设备型号名返回采集配置;未收录型号回落 D435 默认。""" + for key, prof in REALSENSE_PROFILES.items(): + if key in (model_name or ""): + return prof + return { + "depth_resolution": D435_RESOLUTION, + "rgb_resolution": D435_RGB_RESOLUTION, + "fps": D435_FPS, + "depth_near_mm": D435_DEPTH_NEAR_MM, + "depth_far_mm": D435_DEPTH_FAR_MM, + "heatmap_smooth_k": 0, + "heatmap_temporal_alpha": 0.0, + } + +# ── 设备检测面板 ───────────────────────────────────── +DEVICE_SCAN_MAX_INDEX = 16 # V4L2 sysfs 枚举上限(D435 占 0-5 时 webcam 常落在 6+) +DEVICE_POLL_INTERVAL_MS = 2000 # 设备列表轮询间隔(毫秒,sysfs 只读扫描) +REALSENSE_VID = "8086" # Intel vendor ID(排除 RealSense UVC 节点用) +REALSENSE_PID = "0b07" # D435 的 product ID;其它型号(如 D435i=0b3a)靠驱动 name 含 "RealSense" 兜底 + +# 传感器命名(写入 parquet observation. 列) +SENSOR_NAMES = [ + "right_glove", # 右手手套传感器(16×16 压力矩阵) + "left_glove", # 左手手套传感器 +] + +# 手部关键点命名(每列 21 关节 × 3 坐标 xyz) +HAND_POSE_LEFT = "left_hand_pose" # observation.left_hand_pose +HAND_POSE_RIGHT = "right_hand_pose" # observation.right_hand_pose +HAND_POSE_DIM = 21 * 3 # 63 维 (x,y,z 关节坐标) + +# 传感器数据维度(16×16 触觉矩阵展平) +SENSOR_DIM = 256 + +# ── 显示参数 ────────────────────────────────────────── +CAMERA_MIRROR_HORIZONTAL = True # 单目相机左右镜像翻转(显示 + 录制) +DISPLAY_FPS_LIMIT = 30 # GUI 显示帧率上限 +FEED_MIN_WIDTH = 320 +FEED_MIN_HEIGHT = 240 + +# ── 暗色主题颜色(Qt-Material dark_teal) ───────────── +COLOR_RECORDING = "#EF5350" # 红色 — 录制中 +COLOR_STOPPED = "#66BB6A" # 绿色 — 空闲 +COLOR_ABNORMAL = "#FFA726" # 橙色 — 异常 / 警告 + +# 主背景 +COLOR_BG_MAIN = "#1E1E1E" # 窗口主背景 +COLOR_BG_PANEL = "#252525" # 面板背景 +COLOR_BG_WIDGET = "#2D2D2D" # 控件 / 容器背景 +COLOR_BG_CANVAS = "#1A1A1A" # 画布 / 网格背景 + +# 文字 +COLOR_TEXT_PRIMARY = "#E0E0E0" # 主文字 +COLOR_TEXT_SECONDARY = "#9E9E9E" # 次要文字 +COLOR_TEXT_HINT = "#616161" # 提示文字 + +# 边框与分割线 +COLOR_BORDER = "#424242" +COLOR_BORDER_STRONG = "#616161" + +# 按钮颜色 +COLOR_BTN_START = "#43A047" # 开始录制按钮(绿) +COLOR_BTN_STOP = "#E53935" # 停止录制按钮(红) +COLOR_BTN_ABORT = "#FF8F00" # 异常停止按钮(橙) +COLOR_BTN_DEFAULT_BG = "#424242" # 普通按钮背景 +COLOR_BTN_HOVER = "#555555" # 按钮悬停 +COLOR_BTN_DISABLED_BG = "#333333" # 禁用按钮背景 +COLOR_BTN_DISABLED_TEXT = "#616161" # 禁用按钮文字 + +# ── 服务器上传配置 ──────────────────────────────────── +# 出厂默认占位地址;实际地址由用户在页面中填写并持久化到 server_config.json。 +SERVER_URL = "http://127.0.0.1:8000" +SERVER_CONFIG_FILE = os.path.join(DATA_DIR, "server_config.json") + +def _load_server_config() -> dict: + """读取 server_config.json,返回完整字典。""" + import json + try: + if os.path.isfile(SERVER_CONFIG_FILE): + with open(SERVER_CONFIG_FILE, "r", encoding="utf-8") as f: + return json.load(f) + except (json.JSONDecodeError, OSError): + pass + return {} + +def _save_server_config(data: dict): + """持久化 server_config.json(合并写入,保留未传入的旧字段)。""" + import json + current = _load_server_config() + current.update(data) + os.makedirs(DATA_DIR, exist_ok=True) + with open(SERVER_CONFIG_FILE, "w", encoding="utf-8") as f: + json.dump(current, f, ensure_ascii=False, indent=2) + +def load_server_url() -> str: + """读取用户保存的服务器地址,若无则返回出厂默认值。""" + data = _load_server_config() + url = data.get("server_url", "").strip() + return url if url else SERVER_URL + +def save_server_url(url: str): + """持久化用户输入的服务器地址。""" + _save_server_config({"server_url": url.strip()}) + +def load_credentials() -> tuple[str, str]: + """读取保存的登陆凭据,返回 (username, password)。""" + data = _load_server_config() + return data.get("username", ""), data.get("password", "") + +def save_credentials(username: str, password: str): + """持久化登陆凭据。""" + _save_server_config({"username": username.strip(), "password": password}) + +def load_remembered_username() -> str: + """读取登录对话框「记住账号」保存的用户名(server_config.json)。""" + return str(_load_server_config().get("remembered_username", "") or "").strip() + +def save_remembered_username(username: str): + """持久化「记住账号」的用户名(空串 = 清除)。""" + _save_server_config({"remembered_username": (username or "").strip()}) + +def load_upload_auto_sync() -> bool: + """读取"录制完成后自动上传"开关(server_config.json,默认开=沿用历史行为)。""" + return bool(_load_server_config().get("upload_auto_sync", True)) + +def save_upload_auto_sync(on: bool): + """持久化"录制完成后自动上传"开关。""" + _save_server_config({"upload_auto_sync": bool(on)}) + +def load_upload_delete_after() -> bool: + """读取"上传成功后自动删除本地文件"开关(server_config.json,默认关)。""" + return bool(_load_server_config().get("upload_delete_after", False)) + +def save_upload_delete_after(on: bool): + """持久化"上传成功后自动删除本地文件"开关。""" + _save_server_config({"upload_delete_after": bool(on)}) + +def load_upload_project_id() -> str: + """读取上传目标项目 ID(server_config.json)。 + + 空字符串 = 不指定,由服务器按会话名自动匹配项目 + (服务器上存在多个同名/近似项目时会返回 409 歧义错误)。 + """ + return str(_load_server_config().get("upload_project_id", "") or "").strip() + +def save_upload_project_id(project_id: str): + """持久化上传目标项目 ID(空 = 恢复服务器自动匹配)。""" + _save_server_config({"upload_project_id": (project_id or "").strip()}) +# ── 设备命名持久化 ──────────────────────────────────── +# key = DeviceInfo.stable_key("uvc:{by-id前缀}" / "d435:{serial}" / "ble:{MAC}" 等) +# value = 用户命名字符串;data_ble 设备另带 "sensor" 字段绑定 parquet 列名 +# ("right_glove"/"left_glove",按 MAC 持久化,左右手配置各不同) +DEVICE_NAMES_FILE = os.path.join(DATA_DIR, "device_names.json") + +def load_device_names() -> dict: + """读取设备命名表,异常/不存在返回 {}。""" + try: + if os.path.isfile(DEVICE_NAMES_FILE): + import json + with open(DEVICE_NAMES_FILE, "r", encoding="utf-8") as f: + data = json.load(f) + return data if isinstance(data, dict) else {} + except (json.JSONDecodeError, OSError): + pass + return {} + +def _write_device_names(data: dict): + import json + os.makedirs(DATA_DIR, exist_ok=True) + with open(DEVICE_NAMES_FILE, "w", encoding="utf-8") as f: + json.dump(data, f, ensure_ascii=False, indent=2) + +def save_device_name(key: str, name: str, sensor: str = ""): + """持久化设备命名(merge-write,保留未传入条目)。 + + sensor: 仅 data_ble 用,绑定 parquet 列名("" 表示不动原值)。 + """ + import json + current = load_device_names() + # 条目统一规范为 {"name": str, "sensor"?: str};旧版纯字符串自动升级 + entry = current.get(key, "") + if isinstance(entry, str): + entry = {"name": entry} + entry = dict(entry) if entry else {} + if name: + entry["name"] = name + if sensor: + entry["sensor"] = sensor + if not entry.get("name") and not entry.get("sensor"): + return + current[key] = entry + _write_device_names(current) + +def device_name(key: str) -> str: + """读单个设备命名(兼容 {"name":…} 结构或纯字符串)。""" + entry = load_device_names().get(key, "") + return entry["name"] if isinstance(entry, dict) else (entry or "") + +def device_sensor_role(key: str) -> str: + """读 data_ble 设备绑定的 parquet 列名(无则空串)。""" + entry = load_device_names().get(key, "") + return entry.get("sensor", "") if isinstance(entry, dict) else "" + +def assign_glove_sensor_role(key: str, prefer: str = "") -> str: + """为首次连接的未知手套分配下一个空闲 parquet 列名并持久化。 + + 按 MAC 绑定(重连保持);prefer 为期望列名(广播名 'L' → left_glove、 + 'R' → right_glove),空闲则优先占用,否则按 SENSOR_NAMES 顺序取 + 下一个空余名。无空余名时兜底取最后一个。 + + USB (Type-C) 手套例外:prefer 来自工具包注册表(按序列号权威), + 直接占用该列,并释放其它设备在该列上的陈旧绑定(避免右手套被 + 历史 BLE 绑定挤到 left_glove)。 + """ + role = device_sensor_role(key) + if role: + return role + if prefer and key.startswith("usbglove:"): + # 硬件权威侧别:抢占对应列,清掉其它键的旧绑定 + current = load_device_names() + for k, entry in list(current.items()): + if k != key and isinstance(entry, dict) \ + and entry.get("sensor") == prefer: + entry["sensor"] = "" + _write_device_names(current) + save_device_name(key, device_name(key), sensor=prefer) + return prefer + used = {device_sensor_role(k) for k in load_device_names()} + candidates = [n for n in ([prefer] + SENSOR_NAMES) if n] + for name in dict.fromkeys(candidates): # 去重保持顺序 + if name not in used: + save_device_name(key, device_name(key), sensor=name) + return name + return SENSOR_NAMES[-1] if SENSOR_NAMES else "" + +def remove_device_name(key: str): + """删除设备命名条目。""" + current = load_device_names() + if key in current: + del current[key] + _write_device_names(current) + +# ── 每设备相机参数持久化(曝光) ────────────────────── +# key 与 device_names.json 同为 DeviceInfo.stable_key; +# value = {"exposure": {"auto": bool, "value": float}}(auto=True 时 value 忽略) +DEVICE_PARAMS_FILE = os.path.join(DATA_DIR, "device_params.json") + +def load_device_params() -> dict: + """读取每设备相机参数表,异常/不存在返回 {}。""" + try: + if os.path.isfile(DEVICE_PARAMS_FILE): + import json + with open(DEVICE_PARAMS_FILE, "r", encoding="utf-8") as f: + data = json.load(f) + return data if isinstance(data, dict) else {} + except (json.JSONDecodeError, OSError): + pass + return {} + +def _write_device_params(data: dict): + import json + os.makedirs(DATA_DIR, exist_ok=True) + with open(DEVICE_PARAMS_FILE, "w", encoding="utf-8") as f: + json.dump(data, f, ensure_ascii=False, indent=2) + +def save_device_exposure(key: str, auto: bool, value: float): + """持久化单设备曝光(merge-write,保留其他条目/参数)。""" + current = load_device_params() + entry = dict(current.get(key) or {}) + entry["exposure"] = {"auto": bool(auto), "value": float(value)} + current[key] = entry + _write_device_params(current) + +def device_exposure(key: str) -> dict: + """读单设备曝光设置 {"auto": bool, "value": float},无则 None。""" + entry = load_device_params().get(key) or {} + exp = entry.get("exposure") + if isinstance(exp, dict) and "auto" in exp and "value" in exp: + return {"auto": bool(exp["auto"]), "value": float(exp["value"])} + return None + + +def ensure_device_original(key: str, auto: bool, value: float) -> bool: + """记录设备「最一开始」的曝光基线(首次看到才写,之后永不覆盖)。 + + 恢复默认按钮的基线:无论之后怎么调整,都能回到首次开启设备时 + 读回的原厂曝光状态。返回 True 表示本次为新写入。 + """ + current = load_device_params() + entry = dict(current.get(key) or {}) + if isinstance(entry.get("original"), dict): + return False + entry["original"] = {"auto": bool(auto), "value": float(value)} + current[key] = entry + _write_device_params(current) + return True + + +def device_original(key: str) -> dict: + """读设备原始曝光基线 {"auto": bool, "value": float},无则 None。""" + entry = load_device_params().get(key) or {} + orig = entry.get("original") + if isinstance(orig, dict) and "auto" in orig and "value" in orig: + return {"auto": bool(orig["auto"]), "value": float(orig["value"])} + return None + +UPLOAD_ENABLED = True # 是否启用自动上传 +UPLOAD_MAX_CONCURRENT = 1 # 最大并发上传数:串行=1(并发时预压缩临时文件会互相覆盖致视频损坏,且进度无法区分当前是哪条数据) +UPLOAD_RETRY_MAX = 3 # 最大重试次数 +UPLOAD_AUTO_SYNC = load_upload_auto_sync() # 录制完成后是否自动上传(持久化,启动时从 server_config.json 读取) +UPLOAD_DELETE_AFTER = load_upload_delete_after() # 上传成功后是否删除本地文件(持久化,启动时从 server_config.json 读取) +UPLOAD_PRECOMPRESS_VIDEO = True # 上传前是否把 videos 重编码到低码率。开=HEVC(libx265) CRF 档再压(tools/hevc_test 实测 CRF30 体积约原录制件的 7%、SSIM 0.967;大会话必备)。关=原样上传 CRF23 录制品(无二代有损;60min 双目 ~7.6GB,上传带宽/后端超时需能承受) +UPLOAD_VIDEO_CRF = 30 # HEVC 目标码率档(x265 CRF 越大越小;30 实测体积约 7%;仅 UPLOAD_PRECOMPRESS_VIDEO=True 时生效) + +# ── 任务服务配置 ────────────────────────────────────── +TASK_POLL_INTERVAL_MS = 30000 # 任务轮询间隔(毫秒) +TASK_API_URL = SERVER_URL # 任务 API 地址(复用服务器地址) +DEVICE_NAME = "EGO_001" # 设备认领名(后端任务分配依据) + +# ── 手部关键点追踪配置 ────────────────────────────────── +HAND_TRACK_ENABLED = False # 是否启用录制后手部关键点处理(需 ultralytics) +HAND_DETECTION_DIR = os.path.join(BASE_DIR, "tools", "hand_detection") +HAND_DET_MODEL = os.path.join(HAND_DETECTION_DIR, "best.pt") # YOLO 手套检测模型 +HAND_MEDIAPIPE_MODEL = os.path.join(HAND_DETECTION_DIR, "hand_landmarker.task") # MediaPipe 裸手模型 +HAND_TRACK_MODE = "glove" # 追踪模式: "glove"(黑色手套) / "bare"(裸手) +HAND_DET_DEVICE = "cuda" # 检测器设备 ("cuda" / "cpu") +HAND_POSE_DEVICE = "cuda" # 关键点设备 ("cuda" / "cpu") +HAND_TRACK_MAX_HANDS = 2 # 最多追踪手数 +HAND_DATA_DIM = 21 * 2 * 2 + 4 * 2 + 1 # 展平后数据维度 diff --git a/collector/core/__init__.py b/collector/core/__init__.py new file mode 100755 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/collector/core/api_client.py b/collector/core/api_client.py new file mode 100755 index 0000000000000000000000000000000000000000..c875f64b5c443d6ca9efc2255cea56df10ecff93 --- /dev/null +++ b/collector/core/api_client.py @@ -0,0 +1,249 @@ +""" +HTTP API 客户端 —— 对接 Data Acquisition 服务器。 + +真实 API: + POST /api/v1/session/upload — 上传整个 session 的 zip 包 + GET /api/v1/sessions — 查询 sessions 列表 + GET /api/v1/session/{id} — session 详情 + DELETE /api/v1/session/{id} — 删除 session + GET /api/v1/video/{id}/{cam}/stream — 视频流 + GET /health — 健康检查 +""" + +from __future__ import annotations +import os +import time +from typing import Optional, Callable + +import requests +import urllib3 +from urllib3.util import Timeout as _Urllib3Timeout +from requests.adapters import HTTPAdapter + + +CONNECT_TIMEOUT = 10 +READ_TIMEOUT = 1800 # 大会话(数 GB)上传 + 服务器解包入库可能耗时数分钟,设 30 分钟 + + +class _PatientSendConnection(urllib3.connection.HTTPConnection): + """连接子类:请求体发送阶段用读超时窗口,而不是连接超时。 + + urllib3 的 connectionpool 在发请求体前把 conn.timeout 设为 + connect_timeout(本工程 10s),request() 顶层随即用该值对 socket + 做 settimeout —— 即发送大请求体时 socket 超时实际是"连接超时"。 + 服务器收到大 zip 后一边入库一边慢读(导入队列繁忙时单次 sendall + 可停顿数秒~数分钟),停顿一超 10s 上传就被误杀为 + ConnectionError(('Connection aborted.', TimeoutError('timed out')))。 + 这里把发送阶段的 socket 超时换成读超时窗口,发送完即恢复原值。 + """ + + def request(self, method, url, body=None, headers=None, *args, **kwargs): + saved = self.timeout + # conn.timeout 此时是 urlopen 写入的 connect_timeout(数值)。 + # 非数值(如 Timeout 对象)说明不是这个路径,交给基类处理。 + if saved is not None and not isinstance(saved, _Urllib3Timeout): + self.timeout = READ_TIMEOUT + try: + return super().request(method, url, body=body, headers=headers, + *args, **kwargs) + finally: + self.timeout = saved + + +class _PatientSendHTTPSConnection(_PatientSendConnection, + urllib3.connection.HTTPSConnection): + pass + + +class _PatientSendHTTPConnectionPool(urllib3.HTTPConnectionPool): + ConnectionCls = _PatientSendConnection + + +class _PatientSendHTTPSConnectionPool(urllib3.HTTPSConnectionPool): + ConnectionCls = _PatientSendHTTPSConnection + + +class _PatientSendAdapter(HTTPAdapter): + """把发送超时加长的连接池装入 session。""" + + def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs): + super().init_poolmanager(connections, maxsize, block=block, **pool_kwargs) + # PoolManager 默认指向模块级 dict(多实例共享),须整体替换实例属性 + self.poolmanager.pool_classes_by_scheme = { + "http": _PatientSendHTTPConnectionPool, + "https": _PatientSendHTTPSConnectionPool, + } + + +class APIClient: + """服务器 REST API 客户端。 + + session: 可选复用已有 requests.Session(如 TaskService 的已认证 session)。 + """ + + def __init__(self, base_url: str, session: requests.Session = None): + self.base_url = base_url.rstrip("/") + self._own_session = session is None + self._session = session if session is not None else requests.Session() + self._session.headers.update({"User-Agent": "DAQ-SDK/1.0"}) + # 大请求体上传时发送阶段的 socket 超时改为读超时窗口, + # 否则服务器慢读停顿 >10s 会误杀上传(见 _PatientSendConnection)。 + self._session.mount("http://", _PatientSendAdapter()) + self._session.mount("https://", _PatientSendAdapter()) + + def close(self): + if self._own_session: + self._session.close() + + # ── 健康检查 ────────────────────────────────────── + + def health_check(self) -> bool: + try: + r = self._session.get(f"{self.base_url}/health", + timeout=CONNECT_TIMEOUT) + return r.status_code == 200 + except requests.RequestException: + return False + + # ── 上传 session ────────────────────────────────── + + def upload_session_zip(self, zip_path: str, session_name: str, + progress_cb: Optional[Callable[[int, int], None]] = None, + name: str = "", project_id: str = "", + episode_index: int = 0 + ) -> dict: + """ + 上传一个 session 的 zip 包到服务器。 + + Args: + zip_path: zip 文件路径 + session_name: 会话名称(v1.1.0 池化 = 任务名) + progress_cb: 进度回调 (uploaded_bytes, total_bytes) + name: 上传接口的 name 表单字段(会话名;服务器按它解析目标项目, + 空则回退 session_name) + project_id: 上传接口的 project_id 表单字段(目标项目 ID; + 空 = 服务器按名称自动匹配,服务器上有多个同名/近似项目时 + 会返回 409 "Ambiguous project prefix") + episode_index: v1.1.0 池化表单字段——值为本 episode 的 file 号 + (0 基,与 zip 内 file-NNN 完全一致;真实全局序号 N 在 + parquet 行的 episode_index 列)。旧服务器忽略未知字段, + 不影响既有上传。 + + Returns: + {"ok": True, "session_id": "...", "response": {...}} + 或 {"ok": False, "error": "..."} + """ + url = f"{self.base_url}/api/v1/session/upload" + file_size = os.path.getsize(zip_path) + + # 包装文件对象,在读取时回调进度 + class _ProgressReader: + def __init__(self, path, cb, total): + self._f = open(path, "rb") + self._cb = cb + self._total = total + self._read = 0 + + def read(self, size=-1): + data = self._f.read(size) + if data: + self._read += len(data) + if self._cb: + self._cb(self._read, self._total) + return data + + def close(self): + self._f.close() + + reader = _ProgressReader(zip_path, progress_cb, file_size) + + try: + r = self._session.post( + url, + files={"file": (session_name + ".zip", reader, "application/zip")}, + # 显式传 name/project_id:服务器按 name 解析目标项目, + # 多个同名/近似项目(含 workflow 别名撞名)时按前缀匹配 + # 会 409 歧义,须用 project_id 消歧。 + data={"name": name or session_name, + "project_id": project_id or "", + "episode_index": str(episode_index)}, + timeout=(CONNECT_TIMEOUT, READ_TIMEOUT), + ) + if r.status_code in (200, 201): + data = r.json() + return {"ok": True, + "session_id": data.get("session_id", ""), + "response": data} + if r.status_code == 409: + # 服务器按名称匹配项目时发现歧义(多项目前缀撞名) + try: + detail = r.json().get("detail", "") + except ValueError: + detail = r.text + if "project_id" in str(detail) or "prefix" in str(detail).lower(): + return {"ok": False, + "ambiguous_project": True, + "error": "项目名有歧义:服务器上有多个同名/近似项目。" + "请在 ☁ 上传对话框的『目标项目』中指定项目后重试"} + return {"ok": False, "error": f"HTTP 409: {r.text[:300]}"} + return {"ok": False, + "error": f"HTTP {r.status_code}: {r.text[:300]}"} + except requests.RequestException as e: + return {"ok": False, "error": str(e)[:300]} + finally: + reader.close() + + def get_projects(self, limit: int = 100) -> list[dict]: + """GET /api/v1/projects 项目列表(需已认证 session;失败/未认证返回 [])。 + + 用于上传对话框的「目标项目」下拉框。 + """ + try: + r = self._session.get( + f"{self.base_url}/api/v1/projects", + params={"limit": limit}, + timeout=CONNECT_TIMEOUT, + ) + if r.status_code == 200: + return r.json().get("projects", []) + except requests.RequestException: + pass + return [] + + # ── 查询 ────────────────────────────────────────── + + def get_sessions(self, limit: int = 50) -> list[dict]: + try: + r = self._session.get( + f"{self.base_url}/api/v1/sessions", + params={"limit": limit}, + timeout=CONNECT_TIMEOUT, + ) + if r.status_code == 200: + data = r.json() + return data.get("sessions", []) + except requests.RequestException: + pass + return [] + + def get_session(self, session_id: str) -> Optional[dict]: + try: + r = self._session.get( + f"{self.base_url}/api/v1/session/{session_id}", + timeout=CONNECT_TIMEOUT, + ) + if r.status_code == 200: + return r.json() + except requests.RequestException: + pass + return None + + def delete_session(self, session_id: str) -> bool: + try: + r = self._session.delete( + f"{self.base_url}/api/v1/session/{session_id}", + timeout=CONNECT_TIMEOUT, + ) + return r.status_code == 200 + except requests.RequestException: + return False diff --git a/collector/core/auto_labeler.py b/collector/core/auto_labeler.py new file mode 100755 index 0000000000000000000000000000000000000000..8b0e2a614f03bc95bd58c9b92905484ca70ae1da --- /dev/null +++ b/collector/core/auto_labeler.py @@ -0,0 +1,66 @@ +""" +自动标注器 —— Qt 薄封装,核心逻辑在 core.hand_tracking。 +""" + +from __future__ import annotations +import threading +from typing import Optional + +from PyQt5.QtCore import QObject, pyqtSignal + +from core.hand_tracking import label_session as _ht_label_session + + +class AutoLabeler(QObject): + """基于手部关键点数据的自动标注器。 + + 信号 + ---- + progress(int, int) — (已处理帧数, 总帧数) + finished(str, str) — (session_path, error_msg) + """ + + progress = pyqtSignal(int, int) + finished = pyqtSignal(str, str) + + def __init__(self, parent=None): + super().__init__(parent) + self._running = False + self._thread: Optional[threading.Thread] = None + + def label_session(self, session_path: str): + """启动后台标注一个录制会话。""" + if self._running: + return + + self._running = True + self._thread = threading.Thread( + target=self._run, args=(session_path,), + daemon=True, name="auto-labeler", + ) + self._thread.start() + + def cancel(self): + self._running = False + + def _run(self, session_path: str): + def _progress(cur, total): + self.progress.emit(cur, total) + + def _cancelled(): + return not self._running + + result = _ht_label_session( + session_path=session_path, + progress_cb=_progress, + cancel_check=_cancelled, + ) + + if not self._running: + return + if result.get("success"): + self.finished.emit(session_path, "") + else: + self.finished.emit(session_path, result.get("error", "未知错误")) + + self._running = False diff --git a/collector/core/ble_engine.py b/collector/core/ble_engine.py new file mode 100755 index 0000000000000000000000000000000000000000..36d3af1720723f9e6ae4bae68025baace4b3b92c --- /dev/null +++ b/collector/core/ble_engine.py @@ -0,0 +1,303 @@ +""" +BLE 传感器数据引擎 —— 蓝牙连接、数据接收、解析、降噪。 + +作为 QObject 运行,在独立线程中处理 BLE 异步通信, +通过 Qt 信号将处理后的数据帧发送到 UI 线程。 +""" + +import asyncio +import sys +import time +import threading +import logging +import numpy as np +from PyQt5.QtCore import QObject, pyqtSignal, QMutex, QMutexLocker + +if sys.platform == "win32": + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + +from bleak import BleakClient, BleakScanner + +# ── 配置常量 ────────────────────────────────────────── +TX_CHAR_UUID = "6e400003-b5a3-f393-e0a9-e50e24dcca9e" +MATRIX_ROWS = 16 +MATRIX_COLS = 16 +CALIBRATION_FRAMES = 100 +TARGET_FPS = 100 + +logger = logging.getLogger("SensorBLE") + + +class SensorBLEEngine(QObject): + """ + BLE 传感器数据采集引擎。 + + 信号 + ---- + device_found(str, str, int) — 设备名, 地址, RSSI + scan_complete(list) — 扫描完成,设备列表 + connected(str) — 已连接,设备地址 + disconnected() — 已断开 + data_ready(ndarray) — 处理后的 16×16 数据帧 + fps_updated(float) — 硬件 FPS + error_occurred(str) — 错误消息 + calibration_progress(int) — 校准进度 (0-100) + """ + + device_found = pyqtSignal(str, str, int) + scan_complete = pyqtSignal(list) + connected = pyqtSignal(str) + disconnected = pyqtSignal() + data_ready = pyqtSignal(np.ndarray) + fps_updated = pyqtSignal(float) + error_occurred = pyqtSignal(str) + calibration_progress = pyqtSignal(int) + + def __init__(self): + super().__init__() + self.data_array = np.zeros((MATRIX_ROWS, MATRIX_COLS), dtype=np.float32) + self.data_lock = threading.Lock() + + self.raw_buffer = bytearray() + self.buffer_lock = threading.Lock() + + self._running = False + self._scanning = False + self._mutex = QMutex() + + # 降噪参数 + self.base_noise_gate = 500 + self.dynamic_noise_ratio = 0.0 + self.temporal_smooth = 0.15 + self.spatial_filter_enabled = True + self.history_buffer = None + self.drift_baseline_val = 0 + + # 校准 + self.is_calibrating = True + self.calibration_buffer = [] + self.baseline_map = np.zeros((MATRIX_ROWS, MATRIX_COLS), dtype=np.float32) + + # FPS + self.frame_count = 0 + self.last_fps_time = time.time() + self.hardware_fps = 0.0 + + # 最新传感器数据的采集时间戳(微秒),由解析线程写入,主线程读取 + self.latest_data_ts_us: int = 0 + self._ts_lock = threading.Lock() + + # ── 公开接口 ────────────────────────────────────── + + def start_scan(self): + """开始扫描 BLE 设备。""" + with QMutexLocker(self._mutex): + if self._scanning: + return + self._scanning = True + threading.Thread(target=self._scan_loop, daemon=True).start() + + def connect_device(self, address: str): + """连接到指定地址的 BLE 设备。""" + with QMutexLocker(self._mutex): + self._running = True + self._target_mac = address + threading.Thread(target=self._ble_loop, daemon=True).start() + threading.Thread(target=self._parse_loop, daemon=True).start() + + def disconnect(self): + """断开 BLE 连接。""" + with QMutexLocker(self._mutex): + self._running = False + + def start_calibration(self): + """开始校准。""" + with self.data_lock: + self.is_calibrating = True + self.calibration_buffer = [] + + def set_noise_gate(self, value: int): + self.base_noise_gate = value + + def set_dynamic_ratio(self, value: float): + self.dynamic_noise_ratio = value + + def set_spatial_filter(self, enabled: bool): + self.spatial_filter_enabled = enabled + + def set_temporal_smooth(self, value: float): + self.temporal_smooth = value + + # ── BLE 扫描 ────────────────────────────────────── + + def _scan_loop(self): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + devices = loop.run_until_complete(BleakScanner.discover(timeout=5.0)) + devices.sort( + key=lambda d: ("Matrix" in (d.name or ""), bool((d.name or "").strip()), + getattr(d.details, "rssi", -999)), + reverse=True, + ) + self.scan_complete.emit(devices) + except Exception as e: + self.error_occurred.emit(f"BLE 扫描失败: {e}") + finally: + loop.close() + with QMutexLocker(self._mutex): + self._scanning = False + + # ── BLE 通信 ────────────────────────────────────── + + def _ble_loop(self): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + loop.run_until_complete(self._ble_main_async()) + + async def _ble_main_async(self): + while True: + with QMutexLocker(self._mutex): + if not self._running: + break + try: + async with BleakClient(self._target_mac) as client: + self.connected.emit(self._target_mac) + await client.start_notify(TX_CHAR_UUID, self._ble_notify_callback) + while client.is_connected: + with QMutexLocker(self._mutex): + if not self._running: + break + await asyncio.sleep(1) + except Exception as e: + # 连接/通知失败原因上抛 UI(否则界面停在"连接中"无从排查) + self.error_occurred.emit(f"连接失败: {e}") + self.disconnected.emit() + with QMutexLocker(self._mutex): + if not self._running: + break + await asyncio.sleep(3) + + def _ble_notify_callback(self, sender, data): + with self.buffer_lock: + self.raw_buffer.extend(data) + + # ── 数据解析 ────────────────────────────────────── + + def _parse_loop(self): + frame_header = b"\xAA\x55" + frame_tail = b"\xFB\x03" + data_size = 512 + frame_size = len(frame_header) + data_size + 1 + len(frame_tail) + + while True: + with QMutexLocker(self._mutex): + if not self._running: + break + + with self.buffer_lock: + buffer_len = len(self.raw_buffer) + + if buffer_len < frame_size: + time.sleep(0.001) + continue + + with self.buffer_lock: + h_idx = self.raw_buffer.find(frame_header) + if h_idx == -1: + del self.raw_buffer[:-1] + continue + if h_idx > 0: + del self.raw_buffer[:h_idx] + if len(self.raw_buffer) < frame_size: + continue + + frame = self.raw_buffer[:frame_size] + if frame[-2:] == frame_tail: + d_bytes = frame[2 : 2 + data_size] + chksum = frame[2 + data_size] + calc_chk = 0 + for b in d_bytes: + calc_chk ^= b + if calc_chk == chksum: + new_data = ( + np.frombuffer(d_bytes, dtype=np.uint16) + .reshape((16, 16)) + .astype(np.float32) + ) + with self.data_lock: + self.data_array[:] = new_data + # 记录数据采集时间戳(微秒) + with self._ts_lock: + self.latest_data_ts_us = int(time.time() * 1_000_000) + self.frame_count += 1 + del self.raw_buffer[:frame_size] + else: + del self.raw_buffer[:2] + + curr_time = time.time() + if curr_time - self.last_fps_time >= 1.0: + self.hardware_fps = self.frame_count / ( + curr_time - self.last_fps_time + ) + self.fps_updated.emit(self.hardware_fps) + self.frame_count = 0 + self.last_fps_time = curr_time + + # ── 数据处理 ────────────────────────────────────── + + def process_frame(self) -> tuple: + """ + 处理一帧数据:校准、降噪、滤波。 + 返回 (processed_data, max_signal)。 + """ + with self.data_lock: + raw_data = self.data_array.copy() + + # 校准中 + if self.is_calibrating: + self.calibration_buffer.append(raw_data) + progress = min(100, len(self.calibration_buffer) * 100 // CALIBRATION_FRAMES) + self.calibration_progress.emit(progress) + if len(self.calibration_buffer) >= CALIBRATION_FRAMES: + self.baseline_map = np.max(np.stack(self.calibration_buffer), axis=0) + 10 + self.is_calibrating = False + return None, 0 + + # 时域平滑 + if self.history_buffer is None: + self.history_buffer = raw_data.copy() + self.history_buffer = ( + self.history_buffer * self.temporal_smooth + + raw_data * (1.0 - self.temporal_smooth) + ) + smoothed = self.history_buffer.copy() + + # 去基线 + processed = np.maximum(0, smoothed - self.baseline_map) + + # 漂移补偿 + self.drift_baseline_val = np.percentile(processed, 40) + if self.drift_baseline_val > 100: + processed = np.maximum(0, processed - self.drift_baseline_val * 0.8) + + # 动态噪声门 + current_max = processed.max() + dynamic_gate = min(current_max * self.dynamic_noise_ratio, 250) + final_gate = max(self.base_noise_gate, dynamic_gate) + processed[processed < final_gate] = 0 + + # 空间滤波 + if self.spatial_filter_enabled: + import cv2 + mask = (processed > 0).astype(np.uint8) + kernel = np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]], dtype=np.uint8) + neighbors = cv2.filter2D(mask, -1, kernel, borderType=cv2.BORDER_CONSTANT) + noise_floor = np.maximum(self.baseline_map * 2.5, 180) + isolated_noise = ( + (mask > 0) & (neighbors == 0) & (processed < noise_floor) + ) + processed[isolated_noise] = 0 + + max_signal = processed.max() + return processed, max_signal diff --git a/collector/core/calibration.py b/collector/core/calibration.py new file mode 100644 index 0000000000000000000000000000000000000000..88d9bea2d89235d7389e699463b6911e875a2a6a --- /dev/null +++ b/collector/core/calibration.py @@ -0,0 +1,147 @@ +""" +EgoData 标定数据模型 —— 双目相机内外参 + 深度缩放。 +""" + +from __future__ import annotations +from dataclasses import dataclass, field +from typing import List, Optional +import json +import numpy as np + + +@dataclass +class CameraIntrinsics: + """单目相机内参。""" + intrinsic: List[float] # [fx, fy, cx, cy] + distortion: List[float] = field(default_factory=list) # k1,k2,p1,p2[,k3] + + @classmethod + def from_matrix(cls, K: np.ndarray, dist: np.ndarray = None) -> "CameraIntrinsics": + """从 OpenCV 标定矩阵构建。""" + fx, fy = float(K[0, 0]), float(K[1, 1]) + cx, cy = float(K[0, 2]), float(K[1, 2]) + d = dist.flatten().tolist() if dist is not None and dist.size > 0 else [] + return cls(intrinsic=[fx, fy, cx, cy], distortion=d) + + def to_matrix(self) -> np.ndarray: + """还原为 3×3 相机矩阵。""" + fx, fy, cx, cy = self.intrinsic + return np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]], dtype=np.float64) + + def to_dist_array(self) -> np.ndarray: + """还原为畸变系数数组。""" + return np.array(self.distortion, dtype=np.float64) if self.distortion else np.zeros(4) + + +@dataclass +class StereoCalibration: + """双目 + 深度相机标定(EgoData 标准)。 + + JSON 格式: + { + "type": "stereo_rgbd_camera", + "name": "head_stereo", + "resolution": [1280, 800], + "fps": 25, + "baseline": 0.095, + "left_camera": {"intrinsic": [fx, fy, cx, cy], "distortion": []}, + "right_camera": {"intrinsic": [fx, fy, cx, cy], "distortion": []}, + "depth_scale": 0.001, + "cam_imu_timeshift": -0.0019 + } + """ + type: str = "stereo_rgbd_camera" + name: str = "head_stereo" + resolution: List[int] = field(default_factory=lambda: [1280, 800]) + fps: float = 25.0 + baseline: float = 0.095 # 基线 (米) + left_camera: CameraIntrinsics = field( + default_factory=lambda: CameraIntrinsics(intrinsic=[0, 0, 0, 0])) + right_camera: CameraIntrinsics = field( + default_factory=lambda: CameraIntrinsics(intrinsic=[0, 0, 0, 0])) + depth_scale: float = 0.001 # 像素值 × depth_scale = 米 + cam_imu_timeshift: float = -0.0019 # 相机-IMU 时间偏移 (秒), IMU 比相机早 + # 来源: SDK calib.yaml timeshift_cam_imu + # (cam0=-0.001947, cam1=-0.001851) + depth_camera: Optional[CameraIntrinsics] = None # 深度相机内参(D435 独有;S80M 无此字段) + # 注: rs2 畸变系数为 Inverse Brown Conrady + # 模型,原样存储,消费方需按 rs2 模型处理 + + # ── 序列化 ────────────────────────────────────── + + def to_dict(self) -> dict: + d = { + "type": self.type, + "name": self.name, + "resolution": list(self.resolution), + "fps": self.fps, + "baseline": self.baseline, + "left_camera": { + "intrinsic": list(self.left_camera.intrinsic), + "distortion": list(self.left_camera.distortion), + }, + "right_camera": { + "intrinsic": list(self.right_camera.intrinsic), + "distortion": list(self.right_camera.distortion), + }, + "depth_scale": self.depth_scale, + "cam_imu_timeshift": self.cam_imu_timeshift, + } + if self.depth_camera is not None: + d["depth_camera"] = { + "intrinsic": list(self.depth_camera.intrinsic), + "distortion": list(self.depth_camera.distortion), + } + return d + + @classmethod + def from_dict(cls, d: dict) -> "StereoCalibration": + def _intrinsics(key: str) -> CameraIntrinsics: + cam = d.get(key, {}) + return CameraIntrinsics( + intrinsic=list(cam.get("intrinsic", [0, 0, 0, 0])), + distortion=list(cam.get("distortion", [])), + ) + return cls( + type=d.get("type", "stereo_rgbd_camera"), + name=d.get("name", "head_stereo"), + resolution=list(d.get("resolution", [1280, 800])), + fps=float(d.get("fps", 25.0)), + baseline=float(d.get("baseline", 0.095)), + left_camera=_intrinsics("left_camera"), + right_camera=_intrinsics("right_camera"), + depth_scale=float(d.get("depth_scale", 0.001)), + cam_imu_timeshift=float(d.get("cam_imu_timeshift", -0.0019)), + depth_camera=_intrinsics("depth_camera") if "depth_camera" in d else None, + ) + + def save(self, path: str): + with open(path, "w", encoding="utf-8") as f: + json.dump(self.to_dict(), f, indent=2, ensure_ascii=False) + + @classmethod + def load(cls, path: str) -> "StereoCalibration": + with open(path, "r", encoding="utf-8") as f: + return cls.from_dict(json.load(f)) + + # ── 工厂方法 ──────────────────────────────────── + + @classmethod + def from_opencv(cls, + K_left: np.ndarray, dist_left: np.ndarray, + K_right: np.ndarray, dist_right: np.ndarray, + baseline: float = 0.095, + resolution: tuple = (1280, 800), + fps: float = 25.0, + depth_scale: float = 0.001) -> "StereoCalibration": + """从 OpenCV stereoCalibrate 结果构建。""" + return cls( + type="stereo_rgbd_camera", + name="head_stereo", + resolution=list(resolution), + fps=fps, + baseline=baseline, + left_camera=CameraIntrinsics.from_matrix(K_left, dist_left), + right_camera=CameraIntrinsics.from_matrix(K_right, dist_right), + depth_scale=depth_scale, + ) diff --git a/collector/core/camera.py b/collector/core/camera.py new file mode 100755 index 0000000000000000000000000000000000000000..7c43bd74529acff3bc1e13352a4cf3da6dfca2e0 --- /dev/null +++ b/collector/core/camera.py @@ -0,0 +1,676 @@ +""" +摄像机采集模块 —— 后台线程采集帧,通过 Qt 信号发送到主线程。 +所有 VideoCapture 操作在采集线程内执行,确保线程安全。 +""" + +from __future__ import annotations +import os +import re +import time +import threading +import queue +from typing import Optional, Tuple + +import cv2 +import numpy as np +from PyQt5.QtCore import QObject, pyqtSignal, QMutex, QMutexLocker + +from config import settings + + +class CameraState: + DISCONNECTED = "disconnected" + IDLE = "idle" + RECORDING = "recording" + ERROR = "error" + + +if os.name == "nt": + _BACKENDS = [ + ("DShow", cv2.CAP_DSHOW), + ("MSMF", cv2.CAP_MSMF), + ("ANY", cv2.CAP_ANY), + ] +else: + _BACKENDS = [ + ("V4L2", cv2.CAP_V4L2), + ("FFMPEG", cv2.CAP_FFMPEG), # 兜底:OpenCV 5.0 V4L2 的 obsensor bug 可能导致 UVC 相机无法打开 + ("ANY", cv2.CAP_ANY), + ] + + +class _Quiet: + def __enter__(self): + self._devnull_fd = os.open(os.devnull, os.O_WRONLY) + self._saved_fd = os.dup(2) + os.dup2(self._devnull_fd, 2) + os.close(self._devnull_fd) + return self + def __exit__(self, *_): + os.dup2(self._saved_fd, 2) + os.close(self._saved_fd) + return False + + +def _quiet(): + return _Quiet() + + +def _find_persistent_v4l_path(index: int) -> Optional[str]: + """查找指向 /dev/video{index} 的 by-id 永久路径。 + + 返回 /dev/v4l/by-id/xxx 路径,该路径在设备重新插拔后保持不变, + 即使 /dev/videoN 编号发生变化。 + """ + target = f"../../video{index}" + by_id_dir = "/dev/v4l/by-id" + if not os.path.isdir(by_id_dir): + return None + try: + for entry in os.listdir(by_id_dir): + entry_path = os.path.join(by_id_dir, entry) + try: + if os.readlink(entry_path) == target: + return entry_path + except OSError: + pass + except OSError: + pass + return None + + +def _scan_all_v4l_by_id_paths() -> list: + """扫描 /dev/v4l/by-id/ 下所有设备路径,返回按优先级排列的路径列表。""" + paths = [] + by_id_dir = "/dev/v4l/by-id" + if not os.path.isdir(by_id_dir): + return paths + try: + for entry in sorted(os.listdir(by_id_dir)): + entry_path = os.path.join(by_id_dir, entry) + if os.path.islink(entry_path): + paths.append(entry_path) + except OSError: + pass + return paths + + +def _resolve_v4l_index(index: int) -> list: + """将 /dev/videoN 索引解析为应尝试的设备路径列表。 + + 优先级: + 1. /dev/v4l/by-id/xxx → /dev/video{index} 的永久路径(不随重新插拔改变) + 2. 数字索引 /dev/video{index} + 3. 所有 by-id 路径(仅作为重连兜底:设备可能换了 /dev/videoN 编号) + """ + paths = [] + persistent = _find_persistent_v4l_path(index) + if persistent: + paths.append(persistent) + paths.append(index) + return paths + + +def _try_open_camera(index: int, test_read: bool = False, + fallback_all_by_id: bool = False) -> Tuple[Optional[cv2.VideoCapture], str]: + """尝试打开摄像机。 + + Args: + index: /dev/videoN 数字索引 + test_read: 是否测试读取第一帧 + fallback_all_by_id: 索引失败后是否尝试所有 by-id 路径(用于重连场景) + """ + # 跳过 FTDI 双目相机设备(需专用 SDK,OpenCV 无法正确捕获) + if _is_sdk_device(index): + return None, "" + # 跳过 RealSense D435 的 UVC 节点(深度走 pyrealsense2 专用通道) + if _is_realsense_node(index): + return None, "" + for device in _resolve_v4l_index(index): + for name, backend in _BACKENDS: + try: + cap = cv2.VideoCapture(device, backend) + if cap.isOpened(): + if test_read: + ok, frame = cap.read() + if not (ok and frame is not None and frame.size > 0): + cap.release() + continue + return cap, name + except Exception: + pass + # 重连兜底:扫描所有 by-id 路径(设备可能换了 /dev/videoN 编号) + if fallback_all_by_id: + for p in _scan_all_v4l_by_id_paths(): + # 跳过需专用 SDK / RealSense 的节点,避免 UVC 断线时误开 + try: + target = os.readlink(p) + if target.startswith("../../video"): + n = int(target.split("video")[-1]) + if _is_sdk_device(n) or _is_realsense_node(n): + continue + except (OSError, ValueError): + pass + for name, backend in _BACKENDS: + try: + cap = cv2.VideoCapture(p, backend) + if cap.isOpened(): + if test_read: + ok, frame = cap.read() + if not (ok and frame is not None and frame.size > 0): + cap.release() + continue + return cap, name + except Exception: + pass + return None, "" + + +def _get_usb_camera_indices() -> set: + """用 DirectShow 获取 USB 摄像机的索引集合。""" + usb_indices = set() + try: + from pygrabber.dshow_graph import FilterGraph + devices = FilterGraph().get_input_devices() + for i, name in enumerate(devices): + nl = name.lower() + builtin_kw = ["integrated", "built-in", "builtin", "laptop", + "thinkpad", "ideapad", "hp ", "dell ", "front", + "rear", "depth", "ir camera", "3d", + "user facing", "acer", "lenovo", "asus", "internal"] + is_builtin = any(kw in nl for kw in builtin_kw) + is_usb = "usb" in nl + if is_usb or (not is_builtin): + usb_indices.add(i) + except Exception: + pass + return usb_indices + + +def _is_sdk_device(index: int) -> bool: + """检查 V4L2 设备是否需专用 SDK(FTDI 双目相机),非标准 UVC。""" + name_path = f"/sys/class/video4linux/video{index}/name" + try: + with open(name_path, "r") as f: + return "FTDI" in f.read() + except Exception: + return False + + +def _usb_vid_pid(video_index: int) -> Optional[Tuple[str, str]]: + """沿 /sys/class/video4linux/videoN 设备树向上(≤6 层)查找 idVendor/idProduct。 + + 返回 (vid, pid) 小写十六进制串;找不到返回 None。sysfs 只读,无副作用。 + """ + node = os.path.realpath(f"/sys/class/video4linux/video{video_index}") + for _ in range(6): + try: + with open(os.path.join(node, "idVendor")) as f: + vid = f.read().strip() + with open(os.path.join(node, "idProduct")) as f: + pid = f.read().strip() + if vid and pid: + return vid.lower(), pid.lower() + except OSError: + pass + parent = os.path.dirname(node) + if parent == node: + break + node = parent + return None + + +def _is_realsense_node(index: int) -> bool: + """检查 V4L2 设备是否为 Intel RealSense 的 UVC 节点。 + + RealSense D400 全家族由 pyrealsense2 专用通道输出,其 UVC 节点不能 + 被 OpenCV 当普通相机使用(否则会与 D435 模式重复列出/抢占设备)。 + 识别: vendor 8086 且(PID 命中 D435 的 0b07 或驱动 name 含 + "RealSense")——D435i 是 0b3a、其余型号 PID 各异,用 name 兜底。 + """ + vp = _usb_vid_pid(index) + if vp is None or vp[0] != settings.REALSENSE_VID: + return False + if vp[1] == settings.REALSENSE_PID: + return True + try: + with open(f"/sys/class/video4linux/video{index}/name") as f: + return "realsense" in f.read().lower() + except OSError: + return False + + +def _by_id_device_streams() -> dict: + """解析 /dev/v4l/by-id 下所有条目,返回 {设备前缀: [video_index, ...]}。 + + entry 形如 usb-X_Y_Z-serial-video-index0,去掉末尾 "-video-indexN" + 后作为物理设备前缀,同一物理设备的多个流聚到同一键下。 + """ + device_streams: dict = {} + by_id_dir = "/dev/v4l/by-id" + if not os.path.isdir(by_id_dir): + return device_streams + try: + for entry in os.listdir(by_id_dir): + entry_path = os.path.join(by_id_dir, entry) + try: + target = os.readlink(entry_path) + if target.startswith("../../video"): + idx = int(target.split("video")[-1]) + # 提取 USB 设备前缀,去掉末尾的 "-video-indexN" + parts = entry.rsplit("-video-index", 1) + prefix = parts[0] if len(parts) == 2 else entry + device_streams.setdefault(prefix, []).append(idx) + except (OSError, ValueError): + pass + except OSError: + pass + return device_streams + + +def _discover_indices(max_index: int = 8) -> list: + """发现应尝试打开的设备索引,包含通过 by-id 路径发现的额外索引。 + + 对于同一 USB 物理设备(如 DECXIN 相机的 video0 和 video1 两个流), + 只保留主视频流(-video-index0),过滤掉辅助流(-video-index1+)。 + 避免同一台相机在页面上出现多个窗口。 + """ + # 基础扫描范围:所有 /dev/videoN(0..max_index-1) + all_indices = set(range(max_index)) + + device_streams = _by_id_device_streams() + # 每个物理设备只保留主视频流(-video-index0,即最小索引) + # 但仅当该设备的多个流 BOTH 都在扫描范围内时才排除辅助流 + for prefix, idx_list in device_streams.items(): + idx_list.sort() + primary_idx = idx_list[0] + # 确保主视频流在扫描范围内 + all_indices.add(primary_idx) + # 只在超过 1 个流时排除辅助流 + if len(idx_list) > 1: + for idx in idx_list[1:]: + all_indices.discard(idx) + + return sorted(all_indices) + + +def list_v4l_devices(max_index: int = 16) -> list: + """sysfs 只读枚举 V4L2 设备(不 open、不 test_read,轮询安全)。 + + 以 /dev/v4l/by-id 分组识别物理设备,每个物理设备只保留主视频流 + (最小索引)。返回列表每项: + {video_index, name, serial, by_id_path, vid, pid, is_sdk} + name 从 by-id 前缀解码(去 "usb-" 前缀、字段分隔符转空格); + serial 启发式取前缀最后一段(仅纯字母数字且 ≥8 字符才认作序号)。 + 被占用的设备不会被打开,仍会稳定出现在列表中。 + """ + devices = [] + for prefix, idx_list in sorted(_by_id_device_streams().items()): + idx_list = sorted(idx_list) + idx = idx_list[0] # 主视频流 + if idx >= max_index: + continue + if prefix.startswith("usb-"): + # usb-__ → 分段转空格 + segments = [s for s in re.split(r"[-_]", prefix[len("usb-"):]) if s] + serial = "" + if segments and segments[-1].isalnum() and len(segments[-1]) >= 8: + serial = segments[-1] # 序号单独显示,不进名称 + segments = segments[:-1] + name = " ".join(segments).strip() + else: + name, serial = "", "" + if not name: + # 非 USB 前缀无法解码,回退 sysfs name 文件 + try: + with open(f"/sys/class/video4linux/video{idx}/name") as f: + name = f.read().strip() + except OSError: + name = f"video{idx}" + vp = _usb_vid_pid(idx) + devices.append({ + "video_index": idx, + "name": name, + "serial": serial, + "by_id_path": _find_persistent_v4l_path(idx), + "vid": vp[0] if vp else None, + "pid": vp[1] if vp else None, + "is_sdk": _is_sdk_device(idx), + "is_realsense": _is_realsense_node(idx), + }) + return devices + + +def detect_cameras(max_index: int = 8) -> list: + usb_indices = _get_usb_camera_indices() + with _quiet(): + found = [] + seen_indices = set() + for idx in _discover_indices(max_index): + if idx >= max_index * 2: # 只扩展到合理范围 + continue + if usb_indices and idx not in usb_indices: + continue + if _is_sdk_device(idx): + continue # 跳过 FTDI 双目相机(需专用 SDK) + if _is_realsense_node(idx): + continue # 跳过 RealSense UVC 节点(D435 走 SDK 专用通道) + if idx in seen_indices: + continue + cap, backend = _try_open_camera(idx, test_read=True) + if cap is not None: + cap.release() + found.append((idx, backend)) + seen_indices.add(idx) + return found + + +class CameraWorker(QObject): + frame_ready = pyqtSignal(np.ndarray) + state_changed = pyqtSignal(str) + error_occurred = pyqtSignal(str) + fps_updated = pyqtSignal(float) + camera_opened = pyqtSignal(int, int, str) + + _RECONNECT_BASE_DELAY = 2.0 + _RECONNECT_MAX_DELAY = 30.0 + _READ_FAIL_THRESHOLD = 120 + _INITIAL_FAIL_THRESHOLD = 30 + _INITIAL_GRACE_PERIOD = 90 + + def __init__(self, camera_index: int = 0, resolution: tuple = None, + record_queue: queue.Queue = None, on_queue_full=None): + """Args: + on_queue_full: 录制队列满丢帧回调(无参;v1.0.9 丢帧统计用, + 采集线程内调用,必须轻量线程安全) + """ + super().__init__() + self.camera_index = camera_index + # 默认满分辨率 1280×960@30(需 MJPG,见 _open_camera) + self._requested_res = resolution if resolution is not None else settings.DEFAULT_RESOLUTION + self._cap: Optional[cv2.VideoCapture] = None + self._running = False + self._paused = False + self._mutex = QMutex() + self._fps_counter = _FPSCounter() + self._state = CameraState.DISCONNECTED + self._actual_res: Tuple[int, int] = (0, 0) + self._backend_name = "" + self._thread: Optional[threading.Thread] = None + # 帧采集时间戳(微秒),在 capture_loop 中随帧一起更新 + self._latest_capture_ts_us: int = 0 + self._ts_lock = QMutex() + # 录制帧队列 —— B+ 方案:采集线程直接写入,绕过 Qt 信号/主线程 + self._record_queue = record_queue + self._on_queue_full = on_queue_full # v1.0.9 丢帧统计回调 + # 曝光:UVC 固定自动曝光(正常亮度 + 30fps;实测该相机手动模式 + # 帧率上限 ~26fps)。开启/重连后由采集循环在首帧读出成功后 + # 强制应用(见 _open_camera/_capture_loop) + self._exp_lock = QMutex() + self._exp_pending = False + + @property + def state(self) -> str: + return self._state + @property + def is_connected(self) -> bool: + return self._cap is not None and self._cap.isOpened() + @property + def resolution(self) -> Tuple[int, int]: + return self._actual_res if self._actual_res[0] > 0 else settings.DEFAULT_RESOLUTION + @property + def latest_capture_ts_us(self) -> int: + """最新帧的采集时间戳(Unix 微秒),线程安全。""" + with QMutexLocker(self._ts_lock): + return self._latest_capture_ts_us + + def start(self): + with QMutexLocker(self._mutex): + if self._running: + return + self._running = True + self._paused = False + self._thread = threading.Thread(target=self._capture_loop, daemon=True, name=f"cam-{self.camera_index}") + self._thread.start() + + def stop(self): + with QMutexLocker(self._mutex): + self._running = False + if self._thread is not None and self._thread.is_alive(): + self._thread.join(timeout=5.0) + self._thread = None + self._release_camera() + self._set_state(CameraState.DISCONNECTED) + + def pause(self): self._paused = True + def resume(self): self._paused = False + + def _set_state(self, state: str): + if self._state != state: + self._state = state + self.state_changed.emit(state) + + # ── 曝光(UVC 固定自动曝光:开启/重连后强制应用) ── + + @staticmethod + def _apply_exposure_to(cap, auto: bool, value: float, + backend: str = "") -> tuple: + """把曝光参数写进 VideoCapture。V4L2 下须先切自动/手动再写值, + 否则手动值被自动模式覆盖。返回 (auto 设置成功, 值设置成功)。 + + V4L2 后端(OpenCV 5 起)对 CAP_PROP_AUTO_EXPOSURE 是菜单值直通: + 标准相机 0=自动 1=手动,但部分相机(如 DECXIN)菜单布局不同 + (1=手动、3=光圈优先即自动、无 0)。因此按候选顺序尝试, + 以 set 返回 True 且 get 读回一致为准。Windows 按 OpenCV MSMF + 约定 1=自动/0=手动 写入;DShow/FFMPEG 不实现该属性(写入无副作用)。 + """ + auto_prop = getattr(cv2, "CAP_PROP_AUTO_EXPOSURE", 21) + if backend in ("V4L2", "ANY") and os.name != "nt": + # 自动:0 标准自动 → 3 光圈优先 → 2 快门优先;手动:1 标准手动 → 0 兜底 + candidates = (0, 3, 2) if auto else (1, 0) + ok_auto = False + for cand in candidates: + if cap.set(auto_prop, cand) and cap.get(auto_prop) == cand: + ok_auto = True + break + else: + # Windows:OpenCV MSMF 约定 1=自动 0=手动(写 0 会把相机锁进 + # 手动曝光,亮度不可控);DShow/FFMPEG 不实现该属性,无副作用。 + ok_auto = cap.set(auto_prop, 1 if auto else 0) + if auto: + return ok_auto, True + ok_val = cap.set(cv2.CAP_PROP_EXPOSURE, max(1.0, float(value))) + return ok_auto, ok_val + + def _open_camera(self) -> bool: + self._release_camera() + with _quiet(): + cap, backend = _try_open_camera(self.camera_index, fallback_all_by_id=True) + if cap is None: + self._set_state(CameraState.ERROR) + self.error_occurred.emit(f"Camera {self.camera_index}: cannot open") + return False + self._cap = cap + self._backend_name = backend + # UVC 满分辨率 30fps 必须走 MJPG:YUYV 格式在 1280×960 硬限 5fps, + # 且驱动默认格式就是 YUYV(只设分辨率会静默掉帧率)。读回不一致 + # 说明该相机不支持 MJPG → 继续用默认格式。 + # FFMPEG 兜底后端不识别 FOURCC/FPS 属性(写了也无效),跳过。 + # 设置顺序按后端拆分(两者要求相反): + # - Windows DShow/MSMF:每次 SetFormat 都以引脚当前/首选媒体类型为 + # 基础重建,最后一次设置决定最终格式 → FPS → 分辨率 → FOURCC 收尾, + # 之后不再设任何属性。旧顺序(先 FOURCC 再补 FPS)恰好把 MJPG 打回 + # YUYV(960p 只剩 5fps 档);插上 D435 后驱动协商行为变化才暴露。 + # - Linux V4L2:FOURCC 须在分辨率之前设置,帧率放最后。 + tunable = backend in ("V4L2", "DShow", "MSMF", "ANY") + want_fourcc = (cv2.VideoWriter_fourcc(*settings.UVC_FOURCC) + if settings.UVC_FOURCC else 0) + + def _set_fourcc(quiet: bool = False): + if not (tunable and want_fourcc): + return + try: + self._cap.set(cv2.CAP_PROP_FOURCC, want_fourcc) + if not quiet and int(self._cap.get(cv2.CAP_PROP_FOURCC)) != want_fourcc: + print(f"Camera {self.camera_index}: FOURCC " + f"{settings.UVC_FOURCC} 不支持,回退默认格式", + flush=True) + except Exception: + pass + + # 显式请求采集帧率(V4L2 按离散间隔就近选择;DShow/MSMF 设媒体类型 + # 帧率)。不设时驱动取默认间隔——本相机 MJPG 默认 120fps,会白烧 + # CPU 且录制丢帧。 + def _set_fps(): + if not tunable: + return + try: + self._cap.set(cv2.CAP_PROP_FPS, settings.DEFAULT_FPS) + except Exception: + pass + + def _set_resolution(): + if not self._requested_res: + return + w, h = self._requested_res + self._cap.set(cv2.CAP_PROP_FRAME_WIDTH, w) + self._cap.set(cv2.CAP_PROP_FRAME_HEIGHT, h) + + if backend in ("DShow", "MSMF"): + # Windows:FOURCC 收尾,之后不再设任何属性(见上方注释) + _set_fps() + _set_resolution() + _set_fourcc() + else: + # Linux V4L2 / ANY 兜底:FOURCC 在前,帧率最后(见上方注释) + _set_fourcc() + _set_resolution() + _set_fps() + # UVC 固定自动曝光:开启/重连一律回到自动(正常亮度 + 30fps; + # 实测该相机手动模式帧率上限 ~26fps)。不在此直接写:部分 UVC + # 相机在 STREAMON(首次 read)时重置/忽略 AE 相关控制,开流前的 + # 写入会丢失 → 标记 pending,由采集循环首帧读出成功后下发。 + with QMutexLocker(self._exp_lock): + self._exp_pending = True + actual_w = int(self._cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + actual_h = int(self._cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + if actual_w <= 0 or actual_h <= 0: + actual_w, actual_h = 640, 480 + self._actual_res = (actual_w, actual_h) + # 诊断:打印后端协商结果(Windows 5fps 排查用,控制台可见) + try: + fc = int(self._cap.get(cv2.CAP_PROP_FOURCC)) + fc_disp = "".join(chr(c) if 32 <= c < 127 else "?" + for c in ((fc >> 24) & 0xFF, (fc >> 16) & 0xFF, + (fc >> 8) & 0xFF, fc & 0xFF)) + fps_rb = float(self._cap.get(cv2.CAP_PROP_FPS)) + except Exception: + fc_disp, fps_rb = "?", float("nan") + print(f"Camera {self.camera_index}: backend={backend} " + f"fourcc={fc_disp} res={actual_w}x{actual_h} " + f"fps={fps_rb:.1f}", flush=True) + self._set_state(CameraState.IDLE) + self.camera_opened.emit(actual_w, actual_h, backend) + return True + + def _release_camera(self): + with QMutexLocker(self._mutex): + if self._cap is not None: + try: self._cap.release() + except Exception: pass + self._cap = None + + def _capture_loop(self): + self._open_camera() + display_interval = 1.0 / max(settings.DISPLAY_FPS_LIMIT, 1) + last_emit = 0.0 + consecutive_failures = 0 + consecutive_open_failures = 0 + iteration_count = 0 + while True: + with QMutexLocker(self._mutex): + if not self._running: + break + cap = self._cap # 局部引用,防止 stop() 并发释放 + if cap is None or not cap.isOpened(): + self._set_state(CameraState.ERROR) + delay = self._reconnect_delay(consecutive_open_failures) + time.sleep(delay) + with QMutexLocker(self._mutex): + if not self._running: break + if self._open_camera(): + consecutive_open_failures = 0 + consecutive_failures = 0 + iteration_count = 0 + time.sleep(0.1) + else: + consecutive_open_failures += 1 + continue + iteration_count += 1 + ok, frame = cap.read() + if not ok or frame is None or frame.size == 0: + consecutive_failures += 1 + threshold = self._INITIAL_FAIL_THRESHOLD if iteration_count <= self._INITIAL_GRACE_PERIOD else self._READ_FAIL_THRESHOLD + if consecutive_failures >= threshold: + self._set_state(CameraState.ERROR) + self.error_occurred.emit(f"Camera {self.camera_index}: consecutive read failures, reconnecting") + self._release_camera() + consecutive_failures = 0 + iteration_count = 0 + time.sleep(0.03) + continue + # 强制应用自动曝光。放在首帧读出成功之后:STREAMON 后相机才 + # 可靠接受 AE 控制,开流前的写入会被部分 UVC 相机重置/忽略 + # (重连后画面发暗)。仅在开启/重连后首帧执行一次。 + with QMutexLocker(self._exp_lock): + pending = self._exp_pending + self._exp_pending = False + if pending: + self._apply_exposure_to(cap, True, 0.0, + backend=self._backend_name) + # 帧采集成功,立即记录时间戳(微秒) + capture_ts_us = int(time.time() * 1_000_000) + with QMutexLocker(self._ts_lock): + self._latest_capture_ts_us = capture_ts_us + consecutive_failures = 0 + + # B+ 方案: 将帧副本直接推入录制队列(采集线程 → 写入线程,无需主线程中转) + if self._record_queue is not None: + try: + self._record_queue.put_nowait(frame.copy()) + except queue.Full: + # 写入线程消费不及,丢弃旧帧,队列自然保持最新 + if self._on_queue_full is not None: + try: + self._on_queue_full() + except Exception: + pass # 统计回调失败不影响采集 + + if self._state == CameraState.ERROR: + self._set_state(CameraState.IDLE) + self._fps_counter.tick() + now = time.perf_counter() + # 阈值留 10% 余量:采集帧率≈显示上限(30fps 采集 vs 30fps 上限) + # 时,严格等号比较会因帧间隔抖动系统性跳过约一半帧(实测 + # 满分辨率 30fps 采集下显示仅 ~18fps) + if now - last_emit >= display_interval * 0.9 and not self._paused: + self.frame_ready.emit(frame.copy()) + self.fps_updated.emit(self._fps_counter.fps) + last_emit = now + self._release_camera() + + @staticmethod + def _reconnect_delay(consecutive_failures: int) -> float: + delay = CameraWorker._RECONNECT_BASE_DELAY * (2 ** consecutive_failures) + return min(delay, CameraWorker._RECONNECT_MAX_DELAY) + + +class _FPSCounter: + def __init__(self, window: int = 30): + self._ticks = []; self._window = window; self.fps = 0.0 + def tick(self): + now = time.perf_counter(); self._ticks.append(now) + if len(self._ticks) > self._window: self._ticks.pop(0) + if len(self._ticks) >= 2: + elapsed = self._ticks[-1] - self._ticks[0] + self.fps = (len(self._ticks) - 1) / elapsed if elapsed > 0 else 0.0 diff --git a/collector/core/d435_camera.py b/collector/core/d435_camera.py new file mode 100644 index 0000000000000000000000000000000000000000..16b6f2ddffacd3fd101dc794fd8b87dea608497c --- /dev/null +++ b/collector/core/d435_camera.py @@ -0,0 +1,571 @@ +""" +Intel RealSense D400 系列(D435/D435I/D405…)深度双目采集模块 —— 进程内 QObject worker。 + +D400 系列是稳定 UVC 用户态设备(pyrealsense2 自带 librealsense2 .so + libusb 后端), +无需像 S80M 那样隔离到子进程。后台线程跑 rs2.pipeline,对外输出两路 +(RGB 彩色 / 深度),经 Qt 信号跨线程发回主线程,复用 +MainWindow 双目帧消费模式(显示 + 录制外部源链路)。 +左红外流仅内部启用(时间戳元数据),不对外输出;右红外不再开流 +(基线改从 depth sensor 的 stereo_baseline 选项直读)。 + +多设备支持:worker 按 serial 锁定具体设备(config.enable_device), +面板点击哪台就开哪台;serial 为空时自动取第一台 D400。 + +信号签名与 MainWindow.stereo_frame_ready 一致: + frames_ready(str slot_id, np.ndarray frame, int hardware_ns, list imu_samples) + - "d435_rgb": BGR 三通道彩色图 + - "d435_depth": uint16 毫米深度图(D435/D405 无 IMU,imu_samples 恒为 []) + +左红外流仅内部启用(时间戳元数据),不对外输出、不显示、不落盘; +右红外不再开流——其唯一用途是算基线,现改从 depth sensor 的 +stereo_baseline 选项直读。双 RealSense 同 hub 共享带宽时多一条 +IR2 会让 D405 掉到 ~19fps(实测,与开启顺序无关),去掉后两台满帧。 +深度本身由红外双目内部计算,无需暴露红外画面。 + +用法: + from core.d435_camera import D435Worker, d435_available, list_d400_devices + if d435_available(): + worker = D435Worker(width=848, height=480, fps=30, serial="…") + worker.frames_ready.connect(on_frames) + worker.start() + ... + worker.stop() + +亦可独立运行做无头自检: + python core/d435_camera.py +""" + +from __future__ import annotations +import os +import sys + +# 脚本直跑(如 python core/d435_camera.py)时 sys.path[0] 是 core/, +# 需把项目根插入 sys.path 才能 import config —— 仅在直跑场景生效 +if os.path.dirname(os.path.abspath(__file__)) == sys.path[0]: + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import threading +import time +from collections import deque +from typing import Optional, List + +import cv2 +import numpy as np +from PyQt5.QtCore import QObject, QMutex, QMutexLocker, pyqtSignal + +from config import settings + +# pyrealsense2 延迟失败:未安装时本模块仍可 import(d435_available 返回 False) +try: + import pyrealsense2 as rs +except ImportError: # pragma: no cover + rs = None + + +# d435_available 结果缓存(探测一次,避免重复打开设备上下文) +_d435_avail_cache: Optional[bool] = None + + +def d435_available(force: bool = False) -> bool: + """检测 pyrealsense2 可用且存在 D400 系列设备。结果模块级缓存。 + + force=True 绕过缓存(热插拔后点击路径的活体复查)。 + """ + global _d435_avail_cache + if not force and _d435_avail_cache is not None: + return _d435_avail_cache + _d435_avail_cache = bool(list_d400_devices()) + return _d435_avail_cache + + +def list_d400_devices() -> List[tuple]: + """返回已连接的 D400 系列设备 [(name, serial), …](无设备/未安装 → [])。""" + out: List[tuple] = [] + if rs is None: + return out + try: + ctx = rs.context() + for d in ctx.query_devices(): + try: + if "D400" not in d.get_info(rs.camera_info.product_line): + continue + out.append((d.get_info(rs.camera_info.name), + d.get_info(rs.camera_info.serial_number))) + except Exception: + continue + except Exception: + pass + return out + + +def _frameset_timestamp_us(frames, rs_mod) -> float: + """帧时间戳逐级回退(µs): + 1) 深度帧 frame_timestamp 元数据(D435 老固件行为) + 2) 左红外帧 frame_timestamp 元数据 + 3) 主机时间戳 frames.get_timestamp() × 1000 + + D405 + pyrealsense2 2.58.3 的深度/红外流不支持该元数据 + (supports_frame_metadata=False,无条件读即 RuntimeError → 外层误判 + 设备异常 → 2s 重连死循环)。每级先 supports_frame_metadata 探测再读, + 读失败继续回退;D405 实测走第 3 级——会话内仍单调递增, + hardware_ns 语义不变,精度从设备计数器降为主机时钟。 + """ + for getter in ( + lambda: frames.get_depth_frame(), + lambda: frames.get_infrared_frame(1), + ): + try: + f = getter() + if (f is not None and f.supports_frame_metadata( + rs_mod.frame_metadata_value.frame_timestamp)): + meta = f.get_frame_metadata( + rs_mod.frame_metadata_value.frame_timestamp) + if meta is not None: + return meta + except Exception: + continue + return frames.get_timestamp() * 1000 + + +def _apply_color_exposure(sensor, auto: bool, value: float) -> bool: + """对 color 传感器应用曝光(µs):auto=True 只开自动曝光; + 否则先关自动再写手动值。异常返回 False(不打断采集线程)。""" + try: + sensor.set_option(rs.option.enable_auto_exposure, 1 if auto else 0) + if not auto: + sensor.set_option(rs.option.exposure, float(value)) + return True + except Exception: + return False + + +class D435Worker(QObject): + """D435 采集 worker:后台线程 rs2.pipeline 三路流,信号回主线程。""" + + # (slot_id, frame, hw_ns, imu_samples) + # ★ hw_ns 必须用 object:PyQt5 队列信号把 Python int 按 C++ qint32 + # 封送,超过 2^31(≈2.1s 纳秒)即静默截断为负数(S80M 已有数据受害) + frames_ready = pyqtSignal(str, np.ndarray, object, list) + error_occurred = pyqtSignal(str) # 错误消息 + status_changed = pyqtSignal(str) # "running" / "stopped" + + def __init__(self, width: int = None, height: int = None, + fps: int = None, parent=None, ts_log: str = None, + rgb_width: int = None, rgb_height: int = None, + serial: str = None, model_name: str = None, + rgb_slot: str = None, depth_slot: str = None, + exposure: dict = None): + super().__init__(parent) + self._width = width if width is not None else settings.D435_RESOLUTION[0] + self._height = height if height is not None else settings.D435_RESOLUTION[1] + self._fps = fps if fps is not None else settings.D435_FPS + self._rgb_width = (rgb_width if rgb_width is not None + else settings.D435_RGB_RESOLUTION[0]) + self._rgb_height = (rgb_height if rgb_height is not None + else settings.D435_RGB_RESOLUTION[1]) + self._serial = serial # 目标设备序列号(None → 第一台 D400) + self._model_name = model_name # 仅用于日志/诊断 + # 槽位名(多设备时由 MainWindow 消歧分配;None 回落 settings 常量) + self._rgb_slot = rgb_slot or settings.D435_SLOT_RGB + self._depth_slot = depth_slot or settings.D435_SLOT_DEPTH + self._depth_unit_factor = 1.0 # 设备深度单位 → mm 换算系数(流启动时探测) + self._stop_event = threading.Event() + self._thread: Optional[threading.Thread] = None + self._calibration = None # StereoCalibration,首帧后可用 + self._frame_count = 0 + self._t0_us: Optional[int] = None # 首个帧计数(µs,重连时重置) + self._last_us: int = 0 # 上一帧原始计数(解绕用) + self._wrap_us: int = 0 # 累计回绕补偿(µs) + self._ts_log = ts_log # 诊断 CSV: i,ft_ms,meta_us(仅调试) + self._ts_fh = None # 首启失败时 _run 尾部清理仍需存在 + # 曝光设置(主线程只写 pending;采集线程在流启动后应用, + # 每次重连新建管道须重放最近一次设置) + self._exp_lock = QMutex() + self._exp_auto: Optional[bool] = None + self._exp_value: Optional[float] = None + self._exp_pending = False + self._exp_range: Optional[tuple] = None # (min, max) µs,流启动后缓存 + # 「最一开始」曝光基线(开流时读回硬件,应用任何设置之前) + self._original_exp: Optional[tuple] = None + if exposure: + self._exp_auto = bool(exposure.get("auto", True)) + self._exp_value = float(exposure.get("value", 0.0)) + self._exp_pending = True + + # ── 生命周期 ──────────────────────────────────────── + + def start(self): + """启动后台采集线程(幂等)。""" + if self._thread is not None and self._thread.is_alive(): + return + self._stop_event.clear() + self._thread = threading.Thread(target=self._run, daemon=True, + name="d435-capture") + self._thread.start() + + def stop(self): + """停止采集线程(阻塞至多约 3s;wait_for_frames 1s 超时保证退出)。""" + self._stop_event.set() + if self._thread is not None: + self._thread.join(timeout=3.0) + self._thread = None + self.status_changed.emit("stopped") + + # ── 标定(录制开始时由主线程读取) ──────────────────── + + def get_calibration(self): + """返回首帧后提取的 StereoCalibration;尚未就绪时为 None。""" + return self._calibration + + # ── 曝光调节(主线程只写 pending;采集线程应用并缓存量程) ── + + def set_exposure(self, auto: bool, value: float): + """设置 color 传感器曝光:auto=True 开自动;否则手动值(µs)。""" + with QMutexLocker(self._exp_lock): + self._exp_auto = bool(auto) + self._exp_value = float(value) + self._exp_pending = True + + def exposure_info(self) -> tuple: + """返回 ((min,max)µs 或 None, auto, value);流未启动时量程 None。""" + with QMutexLocker(self._exp_lock): + return (self._exp_range, self._exp_auto, self._exp_value) + + def original_exposure(self) -> tuple: + """「最一开始」曝光基线 (auto, value);未捕获返回 None。""" + with QMutexLocker(self._exp_lock): + return self._original_exp + + # ── 后台线程 ──────────────────────────────────────── + + def _run(self): + if rs is None: + self.error_occurred.emit("pyrealsense2 未安装") + return + + while not self._stop_event.is_set(): + # 每次重连新建管道:复用同一 rs.pipeline 在"流停滞"后 stop→start + # 无法复位 UVC 通道,同一对象会无限循环"无帧→重连"(实测停滞机 + # 新管道立即恢复出帧——新管道等价于新进程打开设备) + pipe = rs.pipeline() + try: + config = rs.config() + # 多设备时按序列号锁定目标设备;不指定则用第一台 D400 + if self._serial: + config.enable_device(self._serial) + # 对外: RGB 彩色 + 深度两路 + config.enable_stream(rs.stream.color, + self._rgb_width, self._rgb_height, + rs.format.rgb8, self._fps) + config.enable_stream(rs.stream.depth, + self._width, self._height, + rs.format.z16, self._fps) + # 内部: 左红外仅用于时间戳元数据,不对外输出。右红外不开流: + # 其唯一用途是算基线,现从 stereo_baseline 选项直读—— + # 双 RealSense 同 hub 时多一条 IR2 会把 D405 挤到 ~19fps + config.enable_stream(rs.stream.infrared, 1, + self._width, self._height, + rs.format.y8, self._fps) + profile = pipe.start(config) + # 设备深度单位探测(D435=1mm,D405=0.1mm)→ mm 换算系数。 + # 帧统一归一化到 mm 输出:全链路(热力图/无损深度流/metadata + # "unit:mm"/depth_scale 0.001)都按 mm 约定。 + try: + dev_unit = float(profile.get_device() + .first_depth_sensor().get_depth_scale()) + except Exception: + dev_unit = float(settings.DEPTH_SCALE) + self._depth_unit_factor = dev_unit / float(settings.DEPTH_SCALE) + # 曝光:流启动后缓存 color 传感器量程并应用最近设置。 + # 重连 = 新管道 = 新传感器句柄,相机端设置会丢,须每次重放; + # 消费 pending 同样在本线程完成(主线程只写 pending)。 + try: + color = profile.get_device().first_color_sensor() + rng = color.get_option_range(rs.option.exposure) + with QMutexLocker(self._exp_lock): + self._exp_range = (float(rng.min), float(rng.max)) + # 「最一开始」曝光基线:应用任何设置前读回硬件 + # 当前值(重连 = 新管道,读的是本次开流的硬件状态) + try: + oa = float(color.get_option( + rs.option.enable_auto_exposure)) + ov = float(color.get_option(rs.option.exposure)) + self._original_exp = (oa > 0.5, ov) + except Exception: + self._original_exp = None + auto, value = self._exp_auto, self._exp_value + self._exp_pending = False + if auto is not None: + _apply_color_exposure(color, auto, + value if value is not None else 0.0) + except Exception: + pass + if self._calibration is None: + self._calibration = _build_calibration( + profile, self._fps, (self._width, self._height)) + # 帧已归一化为 mm,标定里 depth_scale 写输出格式刻度 + # (设备原生单位仅影响内部换算,不进入落盘标定) + self._calibration.depth_scale = float(settings.DEPTH_SCALE) + self._t0_us = None # 设备计数随流启动重置,重连后重新归零 + self._last_us = 0 + self._wrap_us = 0 + self._ts_fh = open(self._ts_log, "w") if self._ts_log else None + if self._ts_fh: + self._ts_fh.write("i,ft_ms,meta_us\n") + self.status_changed.emit("running") + + # 看门狗一: 停滞——连续无帧秒数(双 RealSense 第二台开流偶发 + # 静默停滞——管道已启动但不再出帧,wait_for_frames 持续超时, + # 无异常可捕获;累计超过阈值则抛给外层走重连) + # 看门狗二: 帧率——半死状态(零星出帧不报错但画面极卡), + # 10s 窗口内帧数低于期望一半 → 同样抛给外层走重连 + stall_s = 0 + fps_win: deque = deque() # 帧到达时刻(monotonic 秒) + fps_win_start: Optional[float] = None # 重连后首个帧时刻 + while not self._stop_event.is_set(): + try: + frames = pipe.wait_for_frames(timeout_ms=1000) + except RuntimeError: + # 超时无帧(拔线初期/流停滞) → 计数,超阈值触发重连 + stall_s += 1 + if stall_s >= settings.D435_STALL_TIMEOUT_S: + raise RuntimeError( + f"流停滞({stall_s}s 无帧),触发重连") + continue + stall_s = 0 + # 消费 pending 曝光设置(主线程 set_exposure 下发) + with QMutexLocker(self._exp_lock): + if self._exp_pending and self._exp_auto is not None: + auto, value = self._exp_auto, self._exp_value + self._exp_pending = False + else: + auto = None + if auto is not None: + try: + color = profile.get_device().first_color_sensor() + _apply_color_exposure( + color, auto, value if value is not None else 0.0) + except Exception: + pass + now_s = time.monotonic() + fps_win.append(now_s) + while (fps_win + and now_s - fps_win[0] > settings.D435_LOW_FPS_WINDOW_S): + fps_win.popleft() + if fps_win_start is None: + fps_win_start = now_s + elif (now_s - fps_win_start >= settings.D435_LOW_FPS_WINDOW_S + and len(fps_win) < (settings.D435_LOW_FPS_FRACTION + * self._fps + * settings.D435_LOW_FPS_WINDOW_S)): + raise RuntimeError( + f"帧率过低({len(fps_win)}帧/" + f"{settings.D435_LOW_FPS_WINDOW_S}s,期望≥" + f"{settings.D435_LOW_FPS_FRACTION * self._fps:.0f}fps)," + f"触发重连") + + # 帧时间戳逐级回退(深度→红外→主机时钟,见 + # _frameset_timestamp_us)。设备计数为 32 位 µs 计数器 + # (2^32µs ≈ 71.6min 才回绕),软件解绕 + 首帧归零 → 会话内 + # 单调递增 hardware_ns(与 S80M 会话相对时钟语义一致)。 + # 注: 排查记录里疑似"每 2.1s 回绕"实为 Qt 信号 qint32 + # 截断假象(>2^31ns 翻转,已改用 object 参数修复)。 + meta_us = _frameset_timestamp_us(frames, rs) + raw_us = int(meta_us) + if self._t0_us is None: + self._t0_us = raw_us + self._last_us = raw_us + hw_ns = 0 + else: + # 解绕: 下跌超过半程(2^31µs) → 补一个整程(2^32µs) + if raw_us < self._last_us - (1 << 31): + self._wrap_us += 1 << 32 + self._last_us = raw_us + hw_ns = (raw_us + self._wrap_us - self._t0_us) * 1000 + if self._ts_fh: + self._ts_fh.write( + f"{self._frame_count},{frames.get_timestamp()}," + f"{int(meta_us)}\n") + self._ts_fh.flush() + + # 显式 copy:rs2 帧缓冲由 C++ 持有,frameset 一释放即失效; + # 深度帧经排队信号延迟消费,必须脱离底层缓冲(848×480×2≈0.8MB) + depth = np.asanyarray( + frames.get_depth_frame().get_data()).copy() # 设备原生单位 + if self._depth_unit_factor != 1.0: + # 归一化到 mm(D405 原生 0.1mm/单位;×0.1 不会溢出 uint16) + depth = (depth.astype(np.float32) + * self._depth_unit_factor + 0.5).astype(np.uint16) + + # RGB8 → BGR 三通道(显示 + MP4 录制链路要求 BGR24) + rgb = np.asanyarray(frames.get_color_frame().get_data()) + rgb_bgr = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR) + + self.frames_ready.emit(self._rgb_slot, + rgb_bgr, hw_ns, []) + self.frames_ready.emit(self._depth_slot, + depth, hw_ns, []) + self._frame_count += 1 + + except RuntimeError as e: + # 拔线 / 设备异常 → 每 2s 重连(仿 CameraWorker 重连策略) + if not self._stop_event.is_set(): + self.error_occurred.emit( + f"RealSense {self._model_name or ''} " + f"{self._serial or ''} 设备异常,2s 后重连: {e}".replace(" ", " ")) + self.status_changed.emit("error") + try: + pipe.stop() + except Exception: + pass + self._stop_event.wait(settings.CAMERA_RECONNECT_INTERVAL_MS / 1000.0) + except Exception as e: + if not self._stop_event.is_set(): + self.error_occurred.emit(f"RealSense 采集异常: {e}") + try: + pipe.stop() + except Exception: + pass + self._stop_event.wait(settings.CAMERA_RECONNECT_INTERVAL_MS / 1000.0) + + try: + pipe.stop() + except Exception: + pass + if self._ts_fh: + try: + self._ts_fh.close() + except Exception: + pass + self._ts_fh = None + + +# ── 标定提取 ─────────────────────────────────────────── + +def _build_calibration(profile, fps: int, resolution: tuple): + """从 rs2 pipeline profile 提取左右红外内参/深度内参/基线 → StereoCalibration。""" + from core.calibration import StereoCalibration, CameraIntrinsics + + def _ir_intrinsics(idx: int) -> CameraIntrinsics: + try: + prof = profile.get_stream(rs.stream.infrared, idx) + except RuntimeError: + prof = None # 未启用的流: get_stream 抛异常而非返回 None + if prof is None: + # IR2 已不开流:右目与左目是同一传感器模组、几何一致, + # 内参镜像左目(基线另从 stereo_baseline 选项读取) + return _ir_intrinsics(1) + intr = prof.as_video_stream_profile().get_intrinsics() + return CameraIntrinsics( + intrinsic=[intr.fx, intr.fy, intr.ppx, intr.ppy], + distortion=list(intr.coeffs), # Inverse Brown Conrady 系数,原样存储 + ) + + def _depth_intrinsics() -> CameraIntrinsics: + prof = profile.get_stream(rs.stream.depth) + intr = prof.as_video_stream_profile().get_intrinsics() + return CameraIntrinsics( + intrinsic=[intr.fx, intr.fy, intr.ppx, intr.ppy], + distortion=list(intr.coeffs), + ) + + def _baseline() -> float: + # 直读 depth sensor 的 stereo_baseline 选项(单位 mm→m),无需 IR2 流。 + # 与旧 IR1→IR2 外参算法实测一致(D435 50.15mm / D405 17.98mm) + try: + return float(profile.get_device().first_depth_sensor() + .get_option(rs.option.stereo_baseline)) / 1000.0 + except Exception: + # 无此选项的罕见设备:IR2 若仍在流中则回落外参算法 + # (未启用时 get_stream 抛异常而非返回 None) + try: + ir2 = profile.get_stream(rs.stream.infrared, 2) + except RuntimeError: + ir2 = None + if ir2 is not None: + ir1 = profile.get_stream( + rs.stream.infrared, 1).as_video_stream_profile() + trans = ir1.get_extrinsics_to( + ir2.as_video_stream_profile()).translation + return float(np.linalg.norm(trans)) # D435 约 0.050 m + return float(settings.STEREO_BASELINE) + + def _depth_scale() -> float: + try: + sensor = profile.get_device().first_depth_sensor() + return float(sensor.get_depth_scale()) + except Exception: + return float(settings.DEPTH_SCALE) + + return StereoCalibration( + resolution=[resolution[0], resolution[1]], + fps=float(fps), + baseline=_baseline(), + left_camera=_ir_intrinsics(1), + right_camera=_ir_intrinsics(2), + depth_camera=_depth_intrinsics(), + depth_scale=_depth_scale(), + cam_imu_timeshift=0.0, # D435 无 IMU + ) + + +# ── 无头自检 ─────────────────────────────────────────── + +if __name__ == "__main__": + import sys + import os + # 脚本直跑时把项目根加入 sys.path(config/core 均为包) + sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + from PyQt5.QtCore import QCoreApplication + + app = QCoreApplication(sys.argv) + + if not d435_available(): + print("未检测到 D435 设备(pyrealsense2 或设备缺失)") + sys.exit(1) + + worker = D435Worker() + stats = {"t0": time.time(), "count": 0, "saved": False, + "sample_dir": "/tmp/d435_selftest"} + + def on_frames(slot_id, frame, hw_ns, imu_samples): + stats["count"] += 1 + # 无头自检不弹窗口(cv2.imshow 与 PyQt5 同进程会冲突); + # 各抽一帧存 /tmp 供人工查看 + if not stats["saved"]: + os.makedirs(stats["sample_dir"], exist_ok=True) + if slot_id == settings.D435_SLOT_DEPTH: + cv2.imwrite(os.path.join(stats["sample_dir"], "depth.png"), frame) + else: + cv2.imwrite(os.path.join(stats["sample_dir"], + f"{slot_id}.png"), frame) + if os.path.isfile(os.path.join(stats["sample_dir"], "depth.png")) \ + and os.path.isfile(os.path.join(stats["sample_dir"], + f"{settings.D435_SLOT_RGB}.png")): + stats["saved"] = True + + worker.frames_ready.connect(on_frames) + worker.error_occurred.connect(lambda m: print("[error]", m)) + worker.start() + + print(f"D435 自检: RGB {worker._rgb_width}x{worker._rgb_height} + " + f"深度 {worker._width}x{worker._height}@{worker._fps}, 运行 5s...") + t_end = time.time() + 5.0 + while time.time() < t_end: + app.processEvents() + time.sleep(0.01) + + elapsed = time.time() - stats["t0"] + print(f" 帧率: {stats['count'] / max(elapsed, 1e-6):.1f} 信号/秒") + print(f" 抽样帧: {stats['sample_dir']}/ (depth.png, d435_rgb.png)") + + calib = worker.get_calibration() + if calib is not None: + print("── 标定 ──") + print(f" baseline = {calib.baseline:.6f} m") + print(f" depth_scale = {calib.depth_scale}") + print(f" left IR 内参 = {calib.left_camera.intrinsic}") + print(f" right IR 内参 = {calib.right_camera.intrinsic}") + print(f" depth 内参 = {calib.depth_camera.intrinsic}") + + worker.stop() diff --git a/collector/core/d435_manager.py b/collector/core/d435_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..0fdb20f6e6b69cc0c2281966fca497f037837ef6 --- /dev/null +++ b/collector/core/d435_manager.py @@ -0,0 +1,149 @@ +""" +D435 深度双目设备管理器 —— worker 生命周期与帧处理口径 +(QtCore QObject + 信号,不依赖 QtWidgets)。 + + - D435DeviceManager 每台一个条目:D435Worker 创建/接线/停止 + + 帧处理口径(calib 首帧注入、深度热力图/EMA、 + 录制写入) + - 帧经 frames_ready(slot, ndarray, object, object, str) 交主线程 + +worker 类由调用方传入(离线测试在 ui.main_window 模块 patch D435Worker +替身仍生效);hw_ns 用 object 封装(PyQt5 qint32 封送截断坑,同 +core.s80m_manager 口径)。 +""" + +from __future__ import annotations + +from functools import partial + +import cv2 +import numpy as np + +from PyQt5.QtCore import QObject, pyqtSignal + +from config.i18n import tr +from core.depth_codec import depth_to_heatmap_bgr +from core.stereo_depth import DepthHeatmapSmoother + + +class D435DeviceManager(QObject): + """D435 深度双目采集 worker 管理(每台一个条目)。 + + 信号 + ---- + frames_ready(str, np.ndarray, object, object, str) + — (slot_id, frame, hw_ns, imu_samples, dev_key),采集线程 → 主线程 + log(str) + — 跨线程日志 + """ + + frames_ready = pyqtSignal(str, np.ndarray, object, object, str) + log = pyqtSignal(str) + + def __init__(self, pipeline, parent=None): + super().__init__(parent) + self._pipeline = pipeline + + @staticmethod + def new_entry(label: str, serial: str, rgb_slot: str, depth_slot: str, + near_mm: float, far_mm: float, smooth_k: int, + temporal_alpha: float) -> dict: + """注册表条目骨架(worker 由 spawn 填充,形状与旧主窗口口径一致)。""" + return { + "kind": "d435", + "slots": [rgb_slot, depth_slot], + "label": label, + "serial": serial, + "rgb_slot": rgb_slot, + "depth_slot": depth_slot, + "worker": None, + "calib_sent": False, + "near_mm": near_mm, + "far_mm": far_mm, + "smooth_k": smooth_k, + "temporal_alpha": temporal_alpha, + "heat_smoother": None, + } + + def spawn(self, dev_key: str, entry: dict, model_name: str, + profile: dict, exposure, worker_cls) -> None: + """创建 D435Worker 并接线(帧/错误信号 → manager 信号 → 主窗口)。 + + 进程内采集 worker(无 IMU;深度与左红外同 imager 出厂对齐)。 + 持久化曝光随 worker 启动应用(流启动后由采集线程消费)。 + 信号连接在 worker.start() 之前完成。 + """ + worker = worker_cls( + width=profile["depth_resolution"][0], + height=profile["depth_resolution"][1], + fps=profile["fps"], + rgb_width=profile["rgb_resolution"][0], + rgb_height=profile["rgb_resolution"][1], + serial=entry["serial"], model_name=model_name, + parent=self, + rgb_slot=entry["rgb_slot"], depth_slot=entry["depth_slot"], + exposure=exposure) + worker.frames_ready.connect( + partial(self._relay_frames, dev_key=dev_key)) + worker.error_occurred.connect( + lambda m: self.log.emit(tr("[RealSense 错误] {}", m))) + worker.start() + entry["worker"] = worker + + def _relay_frames(self, slot_id: str, frame, hardware_ns=0, + imu_samples=None, dev_key: str = None): + self.frames_ready.emit(slot_id, frame, hardware_ns, + imu_samples, dev_key) + + def process_frame(self, entry: dict, slot_id: str, frame, + hardware_ns: int = 0, dev_key: str = None) -> tuple: + """D435 帧处理口径 → 返回 (display_frame, is_depth)。 + + calib 首帧注入(录制开始时写 calibration/head_stereo.json); + 深度槽:规范码值 JET(core.depth_codec 量化域色标,与存储 + 12-bit 灰度视频同构——near/far 线性色标已废弃;EMA 按型号 + 配置,仅显示降噪,存储码值不受影响)+ 录制写原始 uint16 + 毫米深度(12-bit 灰度 MP4:gray12le 对数码,管线内量化); + RGB 槽:原帧 + 录制写外部帧源。UI 侧只做 set_frame 与 FPS + 计数。 + """ + # 首帧后把标定送入管线(录制开始时写 calibration/head_stereo.json) + if not entry["calib_sent"]: + calib = entry["worker"].get_calibration() + if calib is not None: + self._pipeline.set_device_calibration(dev_key, calib) + entry["calib_sent"] = True + + if slot_id == entry["depth_slot"]: + # 规范码值 JET(与存储 12-bit 灰度视频同构,见 depth_codec); + # 可选中值预滤(仅显示降噪,不进入存储码值) + disp = frame + if entry["smooth_k"] and entry["smooth_k"] > 1: + disp = cv2.medianBlur(frame, entry["smooth_k"]) + heat = depth_to_heatmap_bgr(disp) + # 时域 EMA(按型号配置;仅可视化,存储码值不受影响) + if entry["temporal_alpha"] > 0: + if entry["heat_smoother"] is None: + entry["heat_smoother"] = DepthHeatmapSmoother( + entry["temporal_alpha"]) + heat = entry["heat_smoother"].update(heat) + # 录制:原始 uint16 毫米深度 → 12-bit 灰度 MP4(gray12le + # 对数码,量化在管线内完成) + if self._pipeline.is_recording: + self._pipeline.write_depth(frame, depth_slot=slot_id) + return heat, True + if self._pipeline.is_recording: + self._pipeline.write_external_frame( + slot_id, frame.copy(), + hardware_ns=hardware_ns, imu_samples=None) + return frame, False + + def close(self, entry: dict): + """停止 D435 worker(信号先断,防迟到信号进槽)。""" + worker = entry["worker"] + try: + worker.frames_ready.disconnect() + except Exception: + pass + worker.stop() + worker.deleteLater() diff --git a/collector/core/database.py b/collector/core/database.py new file mode 100755 index 0000000000000000000000000000000000000000..8a45444187313e614dab3a77d708c3fdb28b252e --- /dev/null +++ b/collector/core/database.py @@ -0,0 +1,94 @@ +""" +SQLite 数据库管理器 —— 线程安全的单例模式,管理录制历史记录表。 +""" + +import sqlite3 +import os +import threading +from config.settings import DB_PATH, DATA_DIR + + +class Database: + """简单的 SQLite 封装,含建表逻辑和线程本地连接。""" + + _local = threading.local() + + def __init__(self, db_path: str = DB_PATH): + self._db_path = db_path + + @property + def conn(self) -> sqlite3.Connection: + """获取当前线程的数据库连接(自动创建)。""" + if not hasattr(self._local, "conn") or self._local.conn is None: + os.makedirs(os.path.dirname(self._db_path), exist_ok=True) + c = sqlite3.connect(self._db_path) + c.row_factory = sqlite3.Row + c.execute("PRAGMA journal_mode=WAL") + c.execute("PRAGMA foreign_keys=ON") + self._local.conn = c + return self._local.conn + + def close(self): + """关闭当前线程的数据库连接。""" + if hasattr(self._local, "conn") and self._local.conn: + self._local.conn.close() + self._local.conn = None + + # ── 建表 SQL ────────────────────────────────────── + + SCHEMA_SQL = """ + CREATE TABLE IF NOT EXISTS recording ( + id TEXT PRIMARY KEY, + camera_index INTEGER NOT NULL, + camera_name TEXT NOT NULL, + file_path TEXT, + episode_index INTEGER DEFAULT 0, -- v1.1.0 池化:任务目录内的全局 episode 序号 + file_size_mb REAL DEFAULT 0, + duration_sec REAL DEFAULT 0, + resolution_w INTEGER DEFAULT 0, + resolution_h INTEGER DEFAULT 0, + status TEXT NOT NULL DEFAULT 'completed', -- completed | uploaded | aborted | deleted | uploaded_deleted + started_at TEXT NOT NULL, + finished_at TEXT NOT NULL + ); + + CREATE INDEX IF NOT EXISTS idx_recording_camera ON recording(camera_index); + CREATE INDEX IF NOT EXISTS idx_recording_date ON recording(started_at); + + CREATE TABLE IF NOT EXISTS upload_task ( + id TEXT PRIMARY KEY, + session_path TEXT NOT NULL, + session_name TEXT NOT NULL, + episode_index INTEGER DEFAULT 0, -- v1.1.0 池化:全局 episode 序号 + status TEXT NOT NULL DEFAULT 'pending', -- pending | uploading | completed | failed | skipped + progress REAL DEFAULT 0.0, + retry_count INTEGER DEFAULT 0, + server_url TEXT NOT NULL, + server_session_id TEXT DEFAULT '', + error_message TEXT DEFAULT '', + created_at TEXT NOT NULL, + updated_at TEXT NOT NULL + ); + + CREATE INDEX IF NOT EXISTS idx_upload_status ON upload_task(status); + CREATE INDEX IF NOT EXISTS idx_upload_session ON upload_task(session_path); + """ + + def init_schema(self): + """执行建表语句,并做既有库的列迁移(向后兼容)。""" + self.conn.executescript(self.SCHEMA_SQL) + # CREATE TABLE IF NOT EXISTS 不给既有表加列,需 ALTER 迁移 + self._ensure_column("recording", "episode_index", "INTEGER DEFAULT 0") + self._ensure_column("upload_task", "episode_index", "INTEGER DEFAULT 0") + self.conn.commit() + + def _ensure_column(self, table: str, column: str, decl: str): + """表缺列时 ALTER TABLE ADD COLUMN(幂等)。""" + cols = {r[1] for r in self.conn.execute(f"PRAGMA table_info({table})")} + if column not in cols: + self.conn.execute( + f"ALTER TABLE {table} ADD COLUMN {column} {decl}") + + +# 模块级单例 +db = Database() diff --git a/collector/core/depth_codec.py b/collector/core/depth_codec.py new file mode 100644 index 0000000000000000000000000000000000000000..f5a562006be1cbbd8fe38362a35a8f73cef2ed1c --- /dev/null +++ b/collector/core/depth_codec.py @@ -0,0 +1,127 @@ +"""深度 12-bit 灰度视频编码(v1.1.2:gray12le HEVC MP4,lerobot v3 同款)。 + +存储格式: 单视频轨 hevc (Rext) gray12le(12-bit 单平面灰度)—— +Y 平面 = 对数深度码,量化域 [DEPTH_MIN_MM, DEPTH_MAX_MM] 对数映射到 +[0, DEPTH_QMAX]。播放器直接打开显示为灰度视频;读取端 gray12le 解码 +后反量化回 uint16 毫米。文件为 .mp4(hvc1 容器标记)。 + +显示对齐: 所有实时/回放深度画面一律走 depth_to_heatmap_bgr() +(毫米 → 码值 → JET),与存储数据同构——颜色与码值一一对应, +不再有 near/far 线性色标(log 域色标对手部近场场景区分度更好)。 + +精度账(实测,848×480 真实深度): + 量化自身: 每 LSB 相对误差 ln(50)/4095 ≈ 0.096%(0.1mm@0.1m, + 1mm@1m),mean≈0.34mm——低于 D435 传感器噪声 ±3-5mm + 编码 qp=6: 码误差 mean≈2.4/4095(近场深度误差 mean≈1.2mm) + 体积: ~42.6KB/帧(vs FFV1 无损 77KB/帧、PNG16 168KB/帧) + 编码速度: x265 preset=fast 实测 44fps@1280×800 纯噪声下界(真实 + 深度更快;medium 仅 35fps,负载下会反压写线程) + +编码注意: + - 必须不带 -profile:v(main12 与 4:0:0 不兼容,去掉后 x265 自动 + 落 hevc Rext 单平面) + - 必须 range=full(缺省有限域换算会把 600→402 之类毁掉码值) + - CRF 模式禁用(x265 感知优化把深度噪声当纹理抹掉,近场误差 + 3-5×);CQP qp=6 近无损 + - nvenc 不支持 12-bit(p016 族是 10-bit 数据装 16-bit 容器) +""" +from __future__ import annotations + +import math + +import cv2 +import numpy as np + +# ── 量化域常量 ───────────────────────────────────────── +DEPTH_MIN_MM = 100.0 # 量化域下限(毫米);低于此值裁剪为码 0。 + # D405 最近工作距 ~70mm,0.1m 覆盖手部工作域 +DEPTH_MAX_MM = 5000.0 # 量化域上限(毫米);D435 有效量程 ~4m 留余量 +DEPTH_QMAX = 4095 # 12-bit 码值上限 +DEPTH_QP = 6 # x265 近无损 CQP 档(CRF 模式禁用,见模块注释) + +_LOG_LO = math.log(DEPTH_MIN_MM) +_LOG_SPAN = math.log(DEPTH_MAX_MM) - _LOG_LO +_LOG_STEP = DEPTH_QMAX / _LOG_SPAN # 每 LSB 的对数步长 + + +_QUANTIZE_LUT: np.ndarray | None = None # 65536 项 mm→码 LUT(惰性构建) + + +def _quantize_lut() -> np.ndarray: + """mm 值 0..65535 → 12-bit 码值查表(与 float64 公式逐位一致)。 + + 写线程每帧 3.0ms 的 np.log(1280×800 float64)降到 ~0.4ms + 查表——2026-09-03 写线程时间轴漂移残余修复(preset fast 已把 + 漂移 1.74s→0.71s,LUT 再省 ~2.6ms/拍)。 + """ + global _QUANTIZE_LUT + if _QUANTIZE_LUT is None: + lut = np.zeros(65536, dtype=" np.ndarray: + """uint16 毫米深度 → 12-bit 对数码(uint16 存储,值域 0..4095)。 + + 无效值(=0)映射为码 0;低于 DEPTH_MIN_MM 裁剪为码 0, + 高于 DEPTH_MAX_MM 饱和为 DEPTH_QMAX。uint16 输入走查表快路径 + (与 float64 公式逐位一致);非 uint16 输入回退原公式。 + """ + mm = np.asarray(depth_mm) + if mm.dtype == np.uint16: + return np.take(_quantize_lut(), mm) + mm = mm.astype(np.float64) + valid = mm > 0 + if not valid.any(): + return np.zeros(mm.shape, dtype=" np.ndarray: + """12-bit 对数码 → uint16 毫米深度(反量化,四舍五入)。""" + c = np.asarray(codes, dtype=np.float64) + return np.rint(np.exp(_LOG_LO + c / _LOG_STEP)).astype(" np.ndarray: + """12-bit 深度码 → BGR 热力图(规范显示口径:码值 → JET)。 + + 所有实时/回放深度画面的统一颜色映射;码 0(无效/低于量化域下限) + 显示为 JET(0) 深蓝,不置黑(与旧 depth_to_heatmap 口径一致)。 + """ + # 注意:codes 是 uint16,直接 *255 会按 u2 回绕(码 >257 全错), + # 必须先升 int32 再乘(实测 1799*255 回绕后 c8 从 112 错成 16)。 + c8 = ((np.clip(codes, 0, DEPTH_QMAX).astype(np.int32) * 255) + // DEPTH_QMAX).astype(np.uint8) + return cv2.applyColorMap(c8, cv2.COLORMAP_JET) + + +def depth_to_heatmap_bgr(depth_mm: np.ndarray) -> np.ndarray: + """uint16 毫米深度 → BGR 热力图(量化 → 规范 JET,与存储同构)。""" + return codes_to_heatmap_bgr(quantize_depth(depth_mm)) + + +def depth_video_encoder_args() -> list: + """深度视频编码参数(不含 -c:v):gray12le → libx265 qp=6 近无损。 + + 必须不带 -profile:v(main12 与 4:0:0 不兼容,去掉后 x265 自动 + 落 hevc Rext 单平面)。range=full 保 12-bit 码值不被有限域换算 + 破坏(实测缺省会把 600→402)。preset=fast:实测 1280×800 纯噪声 + 下界 44fps(medium 仅 35fps),机器全负载(双彩色流+GUI+USB)时 + 编码器不跌破 30fps 反压写线程——2026-09-03 实机写线程时间轴 + 漂移 1.7s/20s 的根因修复;精度代价实测 +0.26 码值(≈0.15mm@600mm), + 可忽略(转码对比见 session 验证)。 + """ + return ["-pix_fmt", "gray12le", "-tag:v", "hvc1", + "-preset", "fast", + "-x265-params", f"qp={DEPTH_QP}:range=full"] diff --git a/collector/core/depth_reader.py b/collector/core/depth_reader.py new file mode 100644 index 0000000000000000000000000000000000000000..bbd3652cbb01db15a9d26c31f8fbe0f4bc53c600 --- /dev/null +++ b/collector/core/depth_reader.py @@ -0,0 +1,353 @@ +"""深度数据读取(v1.1.2 12-bit 灰度 MP4 + 旧 MKV/png16 回退)。 + +新格式 depth//.mp4:单视频轨 hevc (Rext) gray12le —— +12-bit 对数深度码(core.depth_codec 量化域),ffmpeg CLI 解 +gray12le 后反量化回 uint16 毫米。 +旧格式回退: + depth//.mkv v1.0.14 双流(流0 热力图 h264 + 流1 + FFV1 gray16le 无损 uint16 毫米); + 迁移合成件 = 单流 FFV1(流0)。 + depth//*.png v1.0.13 及以前 PNG16 序列。 + +cv2 的 CAP_PROP_STREAM_INDEX 对 ffmpeg 后端不可靠(实测不生效), +数据轨统一走 ffmpeg CLI 解 rawvideo。 +""" + +from __future__ import annotations +import glob +import os +import re +import subprocess +from typing import Iterator, Optional + +import cv2 +import numpy as np + +from core.depth_codec import codes_to_heatmap_bgr, dequantize_depth +from core.encoder_probe import list_working_ffmpegs +from core.helpers import (egodata_depth_path, egodata_depth_video_path, + episode_video_files) + + +def _get_ffmpeg() -> Optional[str]: + bins = list_working_ffmpegs() + return bins[0] if bins else None + + +def has_depth_mkv(episode_dir: str, depth_name: str) -> bool: + """该槽是否有视频深度(12-bit 灰 MP4 / 双流 MKV 任一)。""" + return os.path.isfile(egodata_depth_video_path(episode_dir, depth_name)) + + +def iter_depth_frames(episode_dir: str, depth_name: str) -> Iterator[np.ndarray]: + """顺序产出 uint16 毫米深度帧((H, W) numpy 数组)。 + + 新格式:12-bit 灰度 MP4(gray12le 解码 + 反量化); + 旧格式:双流/单流 FFV1 MKV(uint16 毫米直出); + 更旧:depth//000001.png 序列(v1.0.13 及以前)。 + """ + path = egodata_depth_video_path(episode_dir, depth_name) + if os.path.isfile(path): + if path.lower().endswith(".mp4"): + yield from _iter_mp4_depth_frames_path(path) + else: + yield from _iter_mkv_depth_frames_path(path) + return + yield from _iter_png16_frames(episode_dir, depth_name) + + +def _ffv1_stream_index(ffmpeg: str, mkv_path: str) -> Optional[int]: + """探测 MKV 里 FFV1 无损深度轨的流号(stderr 解析,无则 None)。 + + v1.0.14 双流 = 流0 热力图 h264 + 流1 FFV1;迁移合成件 = 单流 FFV1 + (流0)。解码前探测一次,两种布局都命中。 + """ + try: + r = subprocess.run([ffmpeg, "-hide_banner", "-i", mkv_path], + capture_output=True, timeout=30) + except Exception: + return None + text = (r.stderr or b"").decode("utf-8", "ignore") + for line in text.splitlines(): + m = re.match(r"\s*Stream #0:(\d+)(?:\([^)]*\))?:\s*Video:\s*ffv1", line) + if m: + return int(m.group(1)) + return None + + +def _iter_mkv_depth_frames_path(mkv_path: str) -> Iterator[np.ndarray]: + """ffmpeg 流式解 MKV 的 FFV1 无损轨(gray16le → uint16 毫米帧)。""" + ffmpeg = _get_ffmpeg() + if not ffmpeg: + return + cap = cv2.VideoCapture(mkv_path) + if not cap.isOpened(): + cap.release() + return + w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + cap.release() + if w <= 0 or h <= 0: + return + # FFV1 轨流号探测:双流件(v1.0.14)= 1,迁移单流件 = 0;探测失败 + # 回退 0:1(v1.0.14 双流默认)。 + idx = _ffv1_stream_index(ffmpeg, mkv_path) + stream = f"0:{idx}" if idx is not None else "0:1" + proc = subprocess.Popen( + [ffmpeg, "-hide_banner", "-i", mkv_path, + "-map", stream, "-f", "rawvideo", "-pix_fmt", "gray16le", "-"], + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + frame_bytes = w * h * 2 + buf = b"" + while proc.poll() is None: + chunk = proc.stdout.read(65536) + if not chunk: + break + buf += chunk + while len(buf) >= frame_bytes: + yield np.frombuffer(buf[:frame_bytes], " Iterator[np.ndarray]: + """ffmpeg 流式解 12-bit 灰度 MP4(gray12le → 反量化 → uint16 毫米)。 + + 探测容器内流是否为 gray12le(v1.0.14 合封失败回退产生的 8-bit + 热力图 mp4 无数据轨,产出空帧序列);其余 HEVC 位深不回退( + 写端只有 12-bit 一条路)。 + """ + if not _mp4_is_gray12(mp4_path): + return + ffmpeg = _get_ffmpeg() + if not ffmpeg: + return + cap = cv2.VideoCapture(mp4_path) + if not cap.isOpened(): + cap.release() + return + w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + cap.release() + if w <= 0 or h <= 0: + return + proc = subprocess.Popen( + [ffmpeg, "-hide_banner", "-i", mp4_path, + "-f", "rawvideo", "-pix_fmt", "gray12le", "-"], + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + frame_bytes = w * h * 2 + buf = b"" + while proc.poll() is None: + chunk = proc.stdout.read(65536) + if not chunk: + break + buf += chunk + while len(buf) >= frame_bytes: + codes = np.frombuffer(buf[:frame_bytes], " 0 else 30.0 + self.total = max(1, int(total)) + self._proc: Optional[subprocess.Popen] = None + self._buf = b"" + self._next_idx = 0 + self._frame_bytes = self.width * self.height * 2 + + @classmethod + def from_path(cls, mp4_path: str) -> Optional["Gray12DepthVideo"]: + """gray12le 且可探测尺寸/帧率的返回实例,否则 None。""" + if not _mp4_is_gray12(mp4_path): + return None + w = h = 0 + fps = 0.0 + total = 0 + try: + cap = cv2.VideoCapture(mp4_path) + if cap.isOpened(): + w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + fps = float(cap.get(cv2.CAP_PROP_FPS) or 0) + total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT) or 0) + cap.release() + except Exception: + pass + if w > 0 and h > 0: + return cls(mp4_path, w, h, fps, total) + # cv2 探不开(灰度 12-bit 后端缺省)→ ffmpeg -i stderr 兜底 + ffmpeg = _get_ffmpeg() + if not ffmpeg: + return None + try: + r = subprocess.run([ffmpeg, "-hide_banner", "-i", mp4_path], + capture_output=True, timeout=30) + except Exception: + return None + text = (r.stderr or b"").decode("utf-8", "ignore") + m = re.search(r"gray12le[^\n]*?(\d{3,5})x(\d{3,5})[^\n]*?([\d.]+)\s+fps", + text) + if not m: + return None + w, h = int(m.group(1)), int(m.group(2)) + fps = float(m.group(3)) + dm = re.search(r"Duration:\s*(\d+):(\d+):([\d.]+)", text) + if dm and fps > 0: + total = int((int(dm.group(1)) * 3600 + int(dm.group(2)) * 60 + + float(dm.group(3))) * fps) + return cls(mp4_path, w, h, fps, total) + + def read(self, idx: int) -> Optional[np.ndarray]: + """读取帧 idx(0-based)→ BGR 热力图;越界/EOF 返回 None。""" + if idx >= self.total: + return None + if self._proc is None or self._proc.poll() is not None: + self._open(idx) + while self._next_idx < idx: + if self._pull() is None: + return None + return self._pull() + + def close(self) -> None: + if self._proc is not None: + try: + self._proc.kill() + except Exception: + pass + try: + self._proc.wait(timeout=3) + except Exception: + pass + self._proc = None + self._buf = b"" + + def _open(self, idx: int) -> None: + self.close() + ffmpeg = _get_ffmpeg() + if not ffmpeg: + return + cmd = [ffmpeg, "-hide_banner", "-nostdin"] + if idx > 0: + # -ss 输入快进:从 ss 前最近关键帧解码并丢弃;-0.5/fps 余量 + # 防 PTS 舍入把 idx-1 带出来(均匀 PTS 下首输出即帧 idx) + ss = max(0.0, (idx - 0.5) / self.fps) + cmd += ["-ss", f"{ss:.6f}"] + cmd += ["-i", self.path, "-f", "rawvideo", + "-pix_fmt", "gray12le", "-"] + try: + self._proc = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + except Exception: + self._proc = None + return + self._next_idx = idx + + def _pull(self) -> Optional[np.ndarray]: + if self._proc is None: + return None + try: + while len(self._buf) < self._frame_bytes: + chunk = self._proc.stdout.read(65536) + if not chunk: + return None # EOF(流结束/解码失败) + self._buf += chunk + raw = self._buf[:self._frame_bytes] + self._buf = self._buf[self._frame_bytes:] + self._next_idx += 1 + except Exception: + return None + codes = np.frombuffer(raw, " bool: + """容器内视频流是否为 gray12le(stderr 解析;探测失败保守 False)。""" + ffmpeg = _get_ffmpeg() + if not ffmpeg: + return False + try: + r = subprocess.run([ffmpeg, "-hide_banner", "-i", mp4_path], + capture_output=True, timeout=30) + except Exception: + return False + text = (r.stderr or b"").decode("utf-8", "ignore") + return bool(re.search(r"Video:\s*[^\n]*gray12le", text)) + + +def _iter_png16_frames(episode_dir: str, depth_name: str) -> Iterator[np.ndarray]: + pattern = os.path.join(episode_dir, "depth", depth_name, "*.png") + for path in sorted(glob.glob(pattern)): + yield cv2.imread(path, cv2.IMREAD_UNCHANGED) + + +def read_depth_frame(episode_dir: str, depth_name: str, + frame_index: int) -> Optional[np.ndarray]: + """读取单帧(1-based 序号,与 RGB 帧号对齐);越界/缺失返回 None。 + + 新格式下为 O(N) 顺序解到目标帧(FFV1 无随机访问捷径); + 批量遍历请直接用 iter_depth_frames。 + """ + for i, frame in enumerate(iter_depth_frames(episode_dir, depth_name)): + if i == frame_index - 1: + return frame + return None + + +# ═══════════════════════════════════════════════════════ +# 池化布局(v1.1.0):(task_dir, depth_key, episode_index) 键控 +# ═══════════════════════════════════════════════════════ + +def pooled_depth_mkv_path(task_dir: str, depth_key: str, + episode_index: int) -> Optional[str]: + """episode N 的深度文件路径(videos/chunk-{c}//episode-{f}.{ext})。 + + 新录制 = 12-bit 灰度 mp4(v1.1.2 起);历史 = mkv(v1.0.14 双流 + FFV1 / 迁移合成单流 FFV1)。无视频深度返回 None。 + """ + path = episode_video_files(task_dir, episode_index).get(depth_key) + if path and os.path.splitext(path)[1].lower() in (".mp4", ".mkv"): + return path + return None + + +def iter_pooled_depth_frames(task_dir: str, depth_key: str, + episode_index: int) -> Iterator[np.ndarray]: + """顺序产出 episode N 该深度槽的 uint16 毫米帧;无文件产出空。""" + path = pooled_depth_mkv_path(task_dir, depth_key, episode_index) + if not path: + return + if path.lower().endswith(".mp4"): + yield from _iter_mp4_depth_frames_path(path) + else: + yield from _iter_mkv_depth_frames_path(path) + + +def read_pooled_depth_frame(task_dir: str, depth_key: str, episode_index: int, + frame_index: int) -> Optional[np.ndarray]: + """池化单帧读取(1-based 序号,与 RGB 帧号对齐);越界/缺失返回 None。 + + O(N) 顺序解到目标帧;批量遍历请直接用 iter_pooled_depth_frames。 + """ + for i, frame in enumerate(iter_pooled_depth_frames( + task_dir, depth_key, episode_index)): + if i == frame_index - 1: + return frame + return None diff --git a/collector/core/device_detector.py b/collector/core/device_detector.py new file mode 100644 index 0000000000000000000000000000000000000000..42e1c2ecbdb79ad519d7f6cf8f59832e18786c3d --- /dev/null +++ b/collector/core/device_detector.py @@ -0,0 +1,497 @@ +""" +设备检测模块 —— 统一枚举已连接设备(UVC + RealSense D400 + S80M + 蓝牙)。 + +列表轮询走 sysfs 只读扫描(不 open 设备、不 test_read)——轮询 <5ms、 +录制中安全、被占用的相机不会从列表闪烁消失;open 测试只发生在开关打开后 +(CameraWorker / D435Worker / S80M 子进程 / SensorBLEEngine 各自带重连)。 + +蓝牙两个来源:bluetoothctl 已配对列表(快、只读、每轮可用)+ bleak 主动 +发现(慢 ~5s,节流缓存;手套连接中建议 set_ble_scan_suppressed(True) 抑制 +扫描,避免挤占 BLE 数据吞吐)。 + +用法: + from core.device_detector import DeviceScanner, detect_devices + + scanner = DeviceScanner() + scanner.scan_finished.connect(on_devices) # list[DeviceInfo] + scanner.request_scan() # 后台线程扫描 +""" + +from __future__ import annotations +import os +import re +import subprocess +import threading +import time +from dataclasses import dataclass, field +from typing import Optional, List + +from PyQt5.QtCore import QObject, pyqtSignal + +from config import settings +from core.camera import list_v4l_devices, _is_sdk_device + + +@dataclass +class DeviceInfo: + """已连接设备的一条描述(跨线程经信号传回主线程)。""" + key: str # "uvc:{by-id前缀或索引}" | "d435:{rs serial}" | "s80m:ftdi" | "ble:{MAC}" | "usbglove:{serial}" + kind: str # "uvc" | "d435" | "s80m" | "data_ble" | "ble" | "usb_glove" + display_name: str # 设备内部命名(by-id 解码 / rs 权威名 / 蓝牙广播名 / USB 手套) + serial: str = "" # 设备序号(无则为空串) + video_index: int = -1 # UVC 设备的 /dev/videoN 索引(其它为 -1) + by_id_path: Optional[str] = None # /dev/v4l/by-id 永久路径(有则填) + backend: str = "" # 打开后端(开关打开后由 CameraWorker 决定,枚举时为空) + address: str = "" # BLE MAC 地址 / USB 手套串口路径(非 BLE 为空串) + rssi: int = 0 # BLE 信号强度(排序用) + user_name: str = "" # 用户命名(枚举后由 MainWindow 从 device_names.json 填充) + + @property + def stable_key(self) -> str: + """持久化用 key:跨插拔稳定(=key)。""" + return self.key + + @property + def group(self) -> str: + """面板分组: "camera" | "glove" | "other_ble"。""" + if self.kind in ("data_ble", "usb_glove"): + return "glove" + if self.kind == "ble": + return "other_ble" + return "camera" + + @property + def label(self) -> str: + """列表/画面叠加显示名:用户命名优先,回落内部命名。""" + return self.user_name or self.display_name + + +def _parse_by_id_entry(entry: str) -> Optional[dict]: + """解析 /dev/v4l/by-id 条目名 → {prefix, serial, index}。 + + 形如 usb-X_Y_Z-serial-video-index0;serial 为启发式(最后一段、 + 纯字母数字且 ≥8 字符),无法解析返回 None。 + """ + if not entry: + return None + parts = entry.rsplit("-video-index", 1) + prefix = parts[0] if len(parts) == 2 else entry + index = int(parts[1]) if (len(parts) == 2 and parts[1].isdigit()) else None + serial = "" + if prefix.startswith("usb-"): + segments = [s for s in re.split(r"[-_]", prefix[len("usb-"):]) if s] + if segments and segments[-1].isalnum() and len(segments[-1]) >= 8: + serial = segments[-1] + return {"prefix": prefix, "serial": serial, "index": index} + + +_REALSENSE_NAME_KW = ("realsense",) + + +def _is_realsense_name(name: str) -> bool: + """Windows DShow 设备名命中 RealSense 关键词(D400 全家族走 + pyrealsense2 专用通道,其 UVC 节点不能当普通相机列出)。""" + nl = (name or "").lower() + return any(kw in nl for kw in _REALSENSE_NAME_KW) + + +def _list_uvc_devices_windows(max_index: int) -> List[DeviceInfo]: + """Windows UVC 枚举:pygrabber DirectShow 设备名。 + + 索引与 OpenCV CAP_DSHOW 顺序一致(两者都枚举同一个 DirectShow + 视频输入设备类),面板 video_index 可直接用于开关打开。 + pygrabber 缺失时退化按索引 DShow open 探测(只验证可打开不读帧)。 + 注意:Windows 无 by-id/sysfs,key 用索引(重插拔索引可能变化)。 + """ + infos: List[DeviceInfo] = [] + names = None + try: + from pygrabber.dshow_graph import FilterGraph + names = FilterGraph().get_input_devices() + except Exception: + names = None + if names is not None: + for i, name in enumerate(names): + if i >= max_index: + break + if _is_realsense_name(name): + continue + if not (name or "").strip(): + name = f"USB Camera {i}" + infos.append(DeviceInfo( + key=f"uvc:{i}", + kind="uvc", + display_name=name.strip(), + video_index=i, + )) + return infos + # 兜底:pygrabber 未安装 → DShow 索引探测(只开不读,快速释放) + import cv2 + for i in range(max_index): + try: + cap = cv2.VideoCapture(i, cv2.CAP_DSHOW) + ok = cap.isOpened() + cap.release() + except Exception: + ok = False + if ok: + infos.append(DeviceInfo( + key=f"uvc:{i}", + kind="uvc", + display_name=f"USB Camera {i}", + video_index=i, + )) + return infos + + +def _list_uvc_devices(max_index: int = settings.DEVICE_SCAN_MAX_INDEX) -> List[DeviceInfo]: + """UVC 网络摄像头(排除 RealSense UVC 节点与 FTDI SDK 设备)。 + + Linux: sysfs 只读枚举(/dev/v4l/by-id 分组,轮询安全)。 + Windows: pygrabber DirectShow 枚举(见 _list_uvc_devices_windows)。 + """ + if os.name == "nt": + return _list_uvc_devices_windows(max_index) + infos: List[DeviceInfo] = [] + for d in list_v4l_devices(max_index): + if d.get("is_sdk"): + continue + if d.get("is_realsense"): + continue + # key 用 by-id 前缀(跨插拔稳定);无 by-id 时退化为索引 + prefix = str(d["video_index"]) + if d.get("by_id_path"): + prefix = os.path.basename(d["by_id_path"]).rsplit("-video-index", 1)[0] + infos.append(DeviceInfo( + key=f"uvc:{prefix}", + kind="uvc", + display_name=d["name"] or f"USB Camera {d['video_index']}", + serial=d.get("serial", ""), + video_index=d["video_index"], + by_id_path=d.get("by_id_path"), + )) + return infos + + +def _list_d435_devices() -> List[DeviceInfo]: + """pyrealsense2 权威枚举(名称 + 序列号);无设备/未安装返回 []。""" + try: + import pyrealsense2 as rs + ctx = rs.context() + infos: List[DeviceInfo] = [] + for dev in ctx.query_devices(): + try: + if "D400" not in dev.get_info(rs.camera_info.product_line): + continue + name = dev.get_info(rs.camera_info.name) + serial = dev.get_info(rs.camera_info.serial_number) + infos.append(DeviceInfo( + key=f"d435:{serial}", + kind="d435", + display_name=name or "Intel RealSense D435", + serial=serial, + )) + except Exception: + continue + return infos + except Exception: + return [] + + +def _list_s80m_devices(max_index: int = settings.DEVICE_SCAN_MAX_INDEX) -> List[DeviceInfo]: + """FTDI 命中一次即返回单条 S80M 条目(SDK 配置写死 video0/video2)。 + + 序号尝试从 by-id 条目解析(FT602 通常无序号 → 空串)。 + """ + for i in range(max_index): + if not _is_sdk_device(i): + continue + serial, by_id_path = "", None + by_id_dir = "/dev/v4l/by-id" + if os.path.isdir(by_id_dir): + for entry in sorted(os.listdir(by_id_dir)): + p = os.path.join(by_id_dir, entry) + try: + if os.readlink(p) == f"../../video{i}": + parsed = _parse_by_id_entry(entry) + if parsed: + serial = parsed.get("serial", "") + by_id_path = p + break + except OSError: + continue + return [DeviceInfo( + key="s80m:ftdi", + kind="s80m", + display_name="FaysSense S80M", + serial=serial, + video_index=i, + by_id_path=by_id_path, + )] + return [] + + +# ── 蓝牙枚举 ────────────────────────────────────────── +BLE_DISCOVERY_INTERVAL_S = 20.0 # bleak 主动发现节流间隔 +BLE_DISCOVERY_TIMEOUT_S = 5.0 # 单次 discover 超时 +_ble_discovery_cache = {"ts": 0.0, "devices": []} # [(name, mac, rssi)] +_ble_discovery_lock = threading.Lock() +_ble_scan_suppressed = False # 手套连接中由 MainWindow 置 True + + +def set_ble_scan_suppressed(on: bool): + """抑制 bleak 主动发现(手套连接中防扫描挤占数据吞吐)。 + + 只影响主动发现;bluetoothctl 已配对列表是只读系统调用,不受影响。 + """ + global _ble_scan_suppressed + _ble_scan_suppressed = bool(on) + + +def _mac_norm(mac: str) -> str: + """MAC 归一化:大写、冒号分隔(bluetoothctl 与 bleak 格式统一)。""" + return re.sub(r"[^0-9A-Fa-f]", ":", mac or "").replace("::", ":").strip(":").upper() + + +def _ble_discover() -> List[tuple]: + """bleak 主动发现(节流缓存;线程内调用,5s 阻塞)。""" + now = time.monotonic() + with _ble_discovery_lock: + if now - _ble_discovery_cache["ts"] <= BLE_DISCOVERY_INTERVAL_S: + return list(_ble_discovery_cache["devices"]) + _ble_discovery_cache["ts"] = now + result: List[tuple] = [] + try: + import asyncio + from bleak import BleakScanner + loop = asyncio.new_event_loop() + try: + found = loop.run_until_complete( + BleakScanner.discover(timeout=BLE_DISCOVERY_TIMEOUT_S)) + for d in found: + rssi = None + try: + rssi = d.rssi + except Exception: + rssi = getattr(getattr(d, "details", None), "rssi", None) + result.append((d.name or "", _mac_norm(d.address), + int(rssi) if rssi is not None else -999)) + finally: + loop.close() + except Exception: + result = [] + with _ble_discovery_lock: + _ble_discovery_cache["devices"] = result + return list(result) + + +def _bluetoothctl_paired() -> dict: + """bluetoothctl devices 已配对列表(只读;不可用返回 {})。""" + paired: dict = {} + try: + out = subprocess.run(["bluetoothctl", "devices"], capture_output=True, + text=True, timeout=5) + for line in out.stdout.splitlines(): + m = re.match(r"Device\s+(\S+)\s+(.+)$", line.strip()) + if m: + paired[_mac_norm(m.group(1))] = m.group(2).strip() + except Exception: + pass + return paired + + +_GLOVE_NAMES = {"l", "r", "left", "right", "l_glove", "r_glove", + "left_glove", "right_glove"} + + +def _is_glove_name(name: str) -> bool: + """广播名判手套:历史 "Matrix…" 或单字母 L/R(现役手套固件)。""" + n = (name or "").strip().lower() + return "matrix" in n or n in _GLOVE_NAMES + + +def _list_ble_devices() -> List[DeviceInfo]: + """蓝牙设备:bluetoothctl 已配对 + bleak 主动发现,按 MAC 去重合并。 + + 广播名含 "Matrix"/"L"/"R" 判为手套(data_ble),其余为普通 BLE + (other_ble);device_names.json 里已绑定 sensor 列的 MAC 永远按手套 + 对待(连过一次即持久化,改名/空名不丢)。手套连接中 + (_ble_scan_suppressed)跳过主动发现,防扫描挤占数据吞吐。 + """ + merged: dict = {} + for mac, name in _bluetoothctl_paired().items(): + merged[_mac_norm(mac)] = {"name": name, "rssi": 0} + if not _ble_scan_suppressed: + for name, mac, rssi in _ble_discover(): + mac = _mac_norm(mac) + if mac in merged: + # 配对名优先;无配对名时用广播名 + if not merged[mac]["name"]: + merged[mac]["name"] = name + else: + merged[mac] = {"name": name, "rssi": rssi} + infos: List[DeviceInfo] = [] + for mac, d in merged.items(): + name = d["name"] or "BLE Device" + is_glove = _is_glove_name(name) or bool( + settings.device_sensor_role(f"ble:{mac}")) + infos.append(DeviceInfo( + key=f"ble:{mac}", + kind="data_ble" if is_glove else "ble", + display_name=name, + serial=mac, + address=mac, + rssi=d["rssi"], + )) + return infos + + +def detect_devices(max_index: int = settings.DEVICE_SCAN_MAX_INDEX) -> List[DeviceInfo]: + """五段枚举(UVC + D435 + S80M + BLE + USB 手套),各自容错,整体不崩。""" + devices: List[DeviceInfo] = [] + try: + devices += _list_uvc_devices(max_index) + except Exception: + pass + try: + devices += _list_d435_devices() + except Exception: + pass + try: + devices += _list_s80m_devices(max_index) + except Exception: + pass + try: + devices += _list_ble_devices() + except Exception: + pass + try: + devices += _list_usb_glove_devices() + except Exception: + pass + return devices + + +# ── USB (Type-C) 手套 ────────────────────────────────── + +_GLOVE_USB_VID = 0x0483 +_GLOVE_USB_PID = 0x5740 +_GLOVE_SIDE_NAMES = {"left_glove": "USB 手套·左手", + "right_glove": "USB 手套·右手"} +_glove_side_cache: Optional[dict] = None +_glove_side_cache_time = 0.0 + + +def _glove_side_by_serial() -> dict: + """读工具包 glove_devices.json → {usb_serial小写: "left_glove"/"right_glove"}。 + + 优先项目根下同级的 stouch_glove_toolkit* 目录,其次项目根自身; + 文件缺失/解析失败返回 {}(左右手仍可经首连分配后持久化)。 + 除 left/right 的 usb_serial 外,还合并可选的 extra_usb_serials + 映射({序列号: "left_glove"/"right_glove"})——支持同一手侧多只 + 手套(换机/固件序列号变更后旧号仍能认出来)。 + 结果缓存 10s,避免 2s 轮询反复读盘。 + """ + global _glove_side_cache, _glove_side_cache_time + now = time.monotonic() + if _glove_side_cache is not None and now - _glove_side_cache_time < 10.0: + return _glove_side_cache + result: dict = {} + root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + candidates = [os.path.join(root, "glove_devices.json")] + try: + candidates += sorted( + os.path.join(root, name, "glove_devices.json") + for name in os.listdir(root) + if name.lower().startswith("stouch_glove_toolkit") + ) + except OSError: + pass + import json + for path in candidates: + try: + with open(path, "r", encoding="utf-8") as f: + data = json.load(f) + except (OSError, ValueError): + continue + for side, role in (("left", "left_glove"), ("right", "right_glove")): + serial = (data.get(side) or {}).get("usb_serial", "") + if serial: + result[str(serial).strip().lower()] = role + for serial, role in (data.get("extra_usb_serials") or {}).items(): + if role in ("left_glove", "right_glove") and serial: + result.setdefault(str(serial).strip().lower(), role) + if result: + break + _glove_side_cache = result + _glove_side_cache_time = now + return result + + +def usb_glove_prefer_side(serial: str) -> str: + """USB 手套序列号 → 期望传感器列名(未知返回空串)。""" + return _glove_side_by_serial().get((serial or "").strip().lower(), "") + + +def _list_usb_glove_devices() -> List[DeviceInfo]: + """枚举 STM32 USB CDC 手套(0483:5740,串口工具按 VID/PID 过滤)。""" + try: + import serial.tools.list_ports + except ImportError: + return [] + side_map = _glove_side_by_serial() + infos: List[DeviceInfo] = [] + for port in serial.tools.list_ports.comports(): + if port.vid != _GLOVE_USB_VID or port.pid != _GLOVE_USB_PID: + continue + serial = (port.serial_number or "").strip() + key = f"usbglove:{serial}" if serial else f"usbglove:{port.device}" + side = side_map.get(serial.lower(), "") + infos.append(DeviceInfo( + key=key, + kind="usb_glove", + display_name=_GLOVE_SIDE_NAMES.get(side, "USB 手套"), + serial=serial, + address=port.device, + )) + return infos + + +class DeviceScanner(QObject): + """后台线程扫描设备(sysfs 只读),经排队信号回主线程。 + + 带 _busy 守卫:扫描未完成时 request_scan 直接返回,防止轮询堆积。 + """ + + scan_finished = pyqtSignal(list) # list[DeviceInfo] + + def __init__(self, parent=None, max_index: int = None): + super().__init__(parent) + self._max_index = (max_index if max_index is not None + else settings.DEVICE_SCAN_MAX_INDEX) + self._busy = False + self._busy_lock = threading.Lock() + self._stop = False + + def request_scan(self): + """请求一次扫描;进行中则忽略(防轮询堆积)。""" + with self._busy_lock: + if self._busy or self._stop: + return + self._busy = True + threading.Thread(target=self._run_scan, daemon=True, + name="device-scan").start() + + def _run_scan(self): + try: + devices = detect_devices(self._max_index) + if not self._stop: + self.scan_finished.emit(devices) + finally: + with self._busy_lock: + self._busy = False + + def stop(self): + """停止接受新扫描(在途扫描完成后自然退出)。""" + with self._busy_lock: + self._stop = True diff --git a/collector/core/device_manager.py b/collector/core/device_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..f2e607fc591b6afbd94374aba2523b86f123a9c1 --- /dev/null +++ b/collector/core/device_manager.py @@ -0,0 +1,148 @@ +""" +统一设备 worker 注册表 + 面板开关分派 + 录制元数据口径(纯 Python, +零 Qt 依赖)。 + +具体开启/关闭动作(建槽、弹窗、widget 接线)留在 UI 侧回调,本模块 +只做核心口径: + - DeviceManager 注册表容器:条目骨架构造 + 查询 + 元数据/抽帧状态 + - dispatch_toggle 面板开关分派(录制锁双保险 + kind 路由) + - build_device_meta / reset_s80m_record_state / teardown_all + 注册表级纯口径(离线测试直接注入假条目即可) + +注册表条目形状(与旧主窗口 _workers 口径一致): + kind ∈ {"uvc", "d435", "s80m", "data_ble", "ble"} + d435/s80m 条目由各自 manager 的 new_entry 构造 + (core.d435_manager / core.s80m_manager),uvc/ble/glove 骨架由本类构造。 +""" + +from __future__ import annotations + +from config import settings + + +class DeviceManager: + """统一设备 worker 注册表(多路并发核心)。 + + entries: dev_key → entry dict(主窗口 _workers 直接引用同一 dict, + 离线测试注入假条目沿用同一形状)。UI 侧负责把条目塞进注册表, + 本类只提供骨架构造、查询与录制口径。 + """ + + def __init__(self): + self.entries: dict = {} + + # ── 条目骨架 ── + @staticmethod + def uvc_entry(slots, label) -> dict: + """UVC 条目(无专属字段,槽位即状态)。""" + return {"kind": "uvc", "slots": list(slots), "label": label} + + @staticmethod + def ble_entry(slot: str, label: str) -> dict: + """无数据蓝牙(耳机类)占位条目。""" + return {"kind": "ble", "slots": [slot], "label": label} + + @staticmethod + def glove_entry(slot: str, role: str, glove_widget, label: str) -> dict: + """数据手套条目:传感器列名 + 画面 widget(close 时停 BLE/撤画面)。""" + return {"kind": "data_ble", "slots": [slot], + "sensor_column": role, "glove": glove_widget, + "label": label} + + # ── 查询 ── + def get(self, dev_key: str) -> dict | None: + return self.entries.get(dev_key) + + def has_kind(self, kind: str) -> bool: + return any(e["kind"] == kind for e in self.entries.values()) + + def has_serial(self, kind: str, serial: str) -> bool: + """按 serial 查重(d435 同机重复开关检测)。""" + return any(e["kind"] == kind and e.get("serial") == serial + for e in self.entries.values()) + + # ── 录制口径 ── + def build_device_meta(self) -> list: + """按注册表构建录制设备信息(写入 meta 的 devices 段)。""" + return build_device_meta(self.entries) + + def reset_s80m_record_state(self): + """录制起止时重置 50→30 抽帧状态(桶号 + 待写 IMU 缓冲)。""" + reset_s80m_record_state(self.entries) + + def teardown_all(self, close_fns: dict) -> None: + """关闭全部已开启设备(遍历注册表分类清理,未知 kind 兜底弹出)。""" + teardown_all(self.entries, close_fns) + + +def build_device_meta(entries: dict) -> list: + """按注册表构建录制设备信息(写入 meta 的 devices 段)。 + + 手套:无画面槽位,附 parquet 传感器列名; + 无数据蓝牙(ble)不进 devices 段。 + """ + meta = [] + for key, e in entries.items(): + if e["kind"] == "data_ble": + meta.append({ + "key": key, "kind": e["kind"], + "name": settings.device_name(key) or e.get("label", ""), + "slots": [], + "sensor_column": e.get("sensor_column", "")}) + continue + if e["kind"] not in ("uvc", "d435", "s80m"): + continue + d = {"key": key, "kind": e["kind"], + "name": settings.device_name(key) or e.get("label", ""), + "slots": list(e.get("slots", []))} + if e.get("serial"): + d["serial"] = str(e["serial"]) + meta.append(d) + return meta + + +def reset_s80m_record_state(entries: dict) -> None: + """录制起止时重置 50→30 抽帧状态(桶号 + 待写 IMU 缓冲 + 空桶统计)。""" + for e in entries.values(): + if e["kind"] == "s80m": + e["last_bucket"] = {} + e["pending_imu"] = [] + e["drop_watch"] = {"last_mono_ns": None, "dropped": 0, + "elapsed": 0, "alerted": False} + + +def teardown_all(entries: dict, close_fns: dict) -> None: + """关闭全部已开启设备(遍历注册表分类清理,未知 kind 兜底弹出)。 + + s80m/d435 的关闭回调会自行 unregister(pop),故遍历键副本。 + """ + for key in list(entries): + entry = entries.get(key) + if not entry: + continue + fn = (close_fns or {}).get(entry["kind"]) + if fn: + fn(key) + else: + entries.pop(key, None) + entries.clear() + + +def dispatch_toggle(dev, on: bool, is_recording: bool, + open_fns: dict, close_fns: dict) -> bool: + """面板开关分派口径(录制锁双保险 + kind 路由)。 + + open_fns / close_fns: kind → 可调用(具体动作在 UI 侧, + open 接收 dev 并返回是否成功,close 接收 dev_key)。 + 返回 opened:打开成功 True;录制中/打开失败/缺回调 False + (UI 侧按 on 区分「回退勾选」与「关闭路径」)。 + """ + if on: + if is_recording: + return False # 面板已锁死,双保险:UI 侧回退勾选 + fn = (open_fns or {}).get(dev.kind) + return bool(fn(dev)) if fn else False + fn = (close_fns or {}).get(dev.kind) + if fn: + fn(dev.key) + return False diff --git a/collector/core/device_naming.py b/collector/core/device_naming.py new file mode 100644 index 0000000000000000000000000000000000000000..e9f61c5a489e39ae05ea133750d973d6cd6027cd --- /dev/null +++ b/collector/core/device_naming.py @@ -0,0 +1,68 @@ +""" +设备命名辅助 —— 型号短名、槽名清洗、曝光基线归一化与槽名分配(零 Qt 依赖)。 + +供主窗口设备接入链路(D435 槽名分配 / 曝光对话框基线)与离线测试共用同一套口径: + - realsense_short 型号名 → 短名("RealSense D405" → "D405") + - slot_base 用户命名 → 槽名前缀(文件系统安全 + "depth" 后缀约定不破坏) + - normalize_original 各种来源的「最一开始」曝光基线 → (auto, value) 二元组 + - allocate_slot_names RealSense RGB/深度槽名对分配(同前缀多台编号追加) +""" + +from __future__ import annotations + +import re + + +def realsense_short(model_name: str) -> str: + """型号名 → 短名("RealSense D405" → "D405";无型号段回落 "RealSense")。""" + m = re.search(r"D\d{3}", model_name or "") + return m.group(0) if m else "RealSense" + + +def slot_base(name: str, fallback: str) -> str: + """用户命名 → 槽名前缀(仅保留字母/数字/下划线/中文;空或全非法回落)。 + + GUI 命名可含空格、emoji 等,槽名要作为文件夹名与 info.json 键, + 须保证文件系统安全且不破坏 "depth" 后缀约定。 + """ + clean = re.sub(r"[^0-9A-Za-z_一-鿿]+", "_", + (name or "").strip()).strip("_") + return clean or fallback + + +def normalize_original(orig) -> tuple | None: + """「最一开始」曝光基线归一化为 (auto, value) 元组;无/坏数据返回 None。 + + settings.device_original 返回 dict,worker.original_exposure 返回 + tuple,S80M entry 存 tuple —— 统一在此收口成对话框要的二元组。 + """ + if isinstance(orig, dict) and "auto" in orig and "value" in orig: + return (bool(orig["auto"]), float(orig["value"])) + if (isinstance(orig, (tuple, list)) and len(orig) == 2 + and orig[0] is not None and orig[1] is not None): + return (bool(orig[0]), float(orig[1])) + return None + + +def allocate_slot_names(user_name: str, model_name: str, + occupied_rgb_slots: list[str]) -> tuple[str, str]: + """分配 RealSense RGB/深度槽名对,同前缀多台编号追加。 + + RGB 槽 = 前缀 + "_rgb";深度槽 = 前缀本身若已以 "_depth" 结尾 + (用户命名 "D405_depth" → depth 文件夹恰为用户名原样),否则补 + "_depth"(保持回放/录制链路 "depth" 后缀约定)。同前缀多台编号 + 追加在槽名之后(d435_depth_2 经典式)。首台未命名 D435 仍得 + d435_rgb/d435_depth 经典名。 + + Args: + user_name: GUI 用户命名(device_names.json,可空回落型号) + model_name: RealSense 显示名(如 "RealSense D405") + occupied_rgb_slots: 已占用 RGB 槽名列表(用于同前缀计数编号) + """ + base = slot_base(user_name, realsense_short(model_name).lower()) + n = sum(1 for s in occupied_rgb_slots if s.startswith(f"{base}_rgb")) + rgb_slot = f"{base}_rgb" if n == 0 else f"{base}_rgb_{n + 1}" + depth_slot = base if base.endswith("_depth") else f"{base}_depth" + if n > 0: + depth_slot = f"{depth_slot}_{n + 1}" + return rgb_slot, depth_slot diff --git a/collector/core/egodata_writer.py b/collector/core/egodata_writer.py new file mode 100644 index 0000000000000000000000000000000000000000..ac3f6d92b258e1843a91c68a8cf38e1ab87d4de7 --- /dev/null +++ b/collector/core/egodata_writer.py @@ -0,0 +1,1108 @@ +""" +EgoData 格式录制器 —— 多模态机器人遥操作数据采集。 + +目录布局(v1.1.0 任务级池化,LeRobot v3 命名,见 docs/data.md): + // + ├── videos/chunk-{c:03d}//episode-{f:03d}.{ext} + │ # 每 episode 每流一文件;RGB=mp4;深度=12-bit + │ # 灰度 MP4(hevc Rext gray12le,对数深度码, + │ # 见 core/depth_codec.py;x265 无 12-bit 时 + │ # 回落 FFV1 gray16le 无损 MKV) + ├── data/chunk-{c:03d}/episode-{f:03d}.parquet + │ # 每 episode 一个,zstd,稀疏列(有数据才写) + └── meta/ + ├── info.json # 任务级 schema/fps/版本/路径模板/calibration + ├── stats.json # 任务级全局统计,每块 {count, mean, std, + │ # min, max}——count 可反推 sum/sum_sq, + │ # 文件自身即增量累加器(v1.1.1,无边车) + ├── tasks.jsonl + └── episodes/chunk-{c:03d}/episode-{f:03d}.parquet + # 每 episode 一个文件(单行),与 data/videos + # 同编号;录制结束原子写,重录覆盖 +""" + +from __future__ import annotations +import os +import json +import time +import subprocess +from typing import Optional, Dict, List + +import cv2 +import numpy as np +import pyarrow as pa +import pyarrow.parquet as pq +from PyQt5.QtCore import QObject, pyqtSignal, QMutex, QMutexLocker + +from config import settings +from core.encoder_probe import (select_encoder, list_working_ffmpegs, + find_depth_12bit_ffmpeg) +from core.depth_codec import quantize_depth, depth_video_encoder_args +from core.calibration import StereoCalibration +from core.helpers import ( + task_dir_of, episode_chunk_file, POOLED_CHUNK_SIZE, + pooled_video_path, pooled_video_dir, + pooled_data_parquet_path, pooled_episodes_path, + _legacy_episodes_shard_path, + pooled_info_path, pooled_stats_path, pooled_tasks_jsonl_path, + load_stats_acc, merge_stat_block, acc_to_stats_json, recalc_stats, + list_task_episodes, next_pooled_episode_index, + mark_recycled_episode, clear_recycled_episode, +) + +# 跨进程文件锁(POSIX);Windows 无 fcntl 时退化为无锁(单机假设, +# 多机共享任务目录须为 POSIX,见 docs/data.md 并发说明) +try: + import fcntl as _fcntl +except ImportError: # pragma: no cover + _fcntl = None + + +# ── 全局 ffmpeg ──────────────────────────────────────── + +def _get_ffmpeg() -> Optional[str]: + """解析可用的 ffmpeg 可执行文件(v1.0.9 起委托 core.encoder_probe)。 + + 优先使用 imageio_ffmpeg 自带的静态二进制(无动态库依赖,最可靠); + PATH 中的 ffmpeg(如 conda 版)必须通过 -version 自检才采用 —— + conda 的 ffmpeg 曾因 libopenvino 符号缺失启动即崩,导致视频静默丢失。 + 候选列表进程内缓存(encoder_probe.list_working_ffmpegs)。 + """ + bins = list_working_ffmpegs() + return bins[0] if bins else None + + +# ── Parquet 模式 (LeRobot v3 兼容) ────────────────────── + +# meta/episodes 分片行:既有 5 列 + v1.1.0 新增(JSON 序列化字符串列) +_EPISODE_COLUMNS = [ + ("episode_index", pa.int64(), 0), + ("task_index", pa.int64(), 0), + ("start_frame_index", pa.int64(), 0), + ("end_frame_index", pa.int64(), 0), + ("length", pa.int64(), 0), + ("created_at", pa.float64(), 0.0), + ("duration_sec", pa.float64(), 0.0), + ("drop_stats", pa.string(), "{}"), + ("video_codec", pa.string(), "{}"), + ("calibration", pa.string(), "{}"), +] +_EPISODE_SCHEMA = pa.schema([(n, t) for n, t, _d in _EPISODE_COLUMNS]) + + +def _episode_rows_table(rows: List[dict]) -> pa.Table: + """episode 行列表 → 分片表(缺失键填默认值)。""" + arrs = {} + for name, typ, default in _EPISODE_COLUMNS: + arrs[name] = pa.array([r.get(name, default) for r in rows], type=typ) + return pa.table(arrs, schema=_EPISODE_SCHEMA) + + +def _read_episode_rows(path: str) -> List[dict]: + """读 episodes 文件为行 dict 列表;文件缺失/损坏返回 []。""" + if not os.path.isfile(path) or os.path.getsize(path) == 0: + return [] + try: + return pq.read_table(path).to_pylist() + except Exception: + return [] + + +# ═══════════════════════════════════════════════════════ +# EgoData 录制器 +# ═══════════════════════════════════════════════════════ + +class EgoDataWriter(QObject): + """EgoData 格式录制器 —— 任务级池化布局(v1.1.0)。 + + 用法: + w = EgoDataWriter() + w.start_episode(output_dir, cameras, fps=30, + sensors=["right_glove", "left_glove"], + task_name="grasp_cup") + w.write_video_frame("head_left_rgb", bgr_frame) + w.write_depth_frame(frame_index, depth_uint16) + w.write_frame_row(frame_index, timestamp_s, + sensors={"right_glove": data}) + w.end_episode() + """ + + episode_started = pyqtSignal(str) + episode_finished = pyqtSignal(str) + error_occurred = pyqtSignal(str) + log_occurred = pyqtSignal(str) # 编码器探测等录制期日志(v1.0.9) + + def __init__(self): + super().__init__() + self._task_dir: str = "" + self._episode_index: int = 0 + self._ffmpeg_procs: Dict[str, subprocess.Popen] = {} + self._camera_dims: Dict[str, tuple] = {} + self._camera_fps: Dict[str, float] = {} + self._fps: float = 30.0 + self._frame_count = 0 + self._max_frame_idx = 0 # 单路最大帧号(用于时长计算) + self._episode_start_s: float = 0.0 + self._episode_created_at: float = 0.0 + self._rows: List[dict] = [] + self._mutex = QMutex() + self._sensor_names: List[str] = [] + self._sensor_dim: int = settings.SENSOR_DIM + self._stats: Dict[str, dict] = {} + self._last_task: str = "" + self._device_ids: List[str] = [] + self._devices: List[dict] = [] + self._calibrations: Dict[str, object] = {} + self._calib_dict: dict = {} # 本 episode 标定(info.json/episodes 行) + # 稀疏列跟踪:只落盘本 episode 实际有数据的列 + self._present_sensors: set = set() + self._present_imu: bool = False + self._present_glove_imu: set = set() # USB 手套 IMU 稀疏列(按传感器名) + # 深度多槽位(D435 第 n 台 = d435_depth[_n];S80M 传统路径兜底 + # settings.CAMERA_DEPTH):槽位键 → depth image_key + self._depth_slots: Dict[str, str] = {} + self._depth_dirs: Dict[str, str] = {} # 每槽深度 image_key 目录(惰性创建) + self._depth_final_ext: Dict[str, str] = {} # 每槽最终扩展名(12-bit 灰 mp4;回落 mkv) + self._depth_12bit: Dict[str, bool] = {} # 每槽是否 12-bit 灰度编码(否则 FFV1 无损) + self._depth_proc_started: Dict[str, bool] = {} # 每槽深度 ffmpeg 是否已启动 + self._depth_enabled: bool = False # 业务开关:是否录制深度 + self._encoder_choice = None # 本会话编码器选择(v1.0.9) + self._drop_stats: Dict[str, int] = {} # 丢帧统计(pipeline 注入) + # abort 清理清单:本 episode 落盘的最终文件 + 创建的目录 + self._created_files: List[str] = [] + self._created_dirs: List[str] = [] + + # ── 对外属性 ────────────────────────────────────── + + @property + def task_dir(self) -> str: + """本 episode 归属的任务目录(池化布局根)。""" + return self._task_dir + + @property + def episode_index(self) -> int: + """本 episode 的全局序号(1 起)。""" + return self._episode_index + + # ── Episode ──────────────────────────────────────── + + def start_episode(self, output_dir: str, cameras: Dict[str, tuple], + fps: float = 30, + sensors: Optional[List[str]] = None, + task_name: str = "", + device_ids: Optional[List[str]] = None, + calibration: Optional[StereoCalibration] = None, + camera_fps: Optional[Dict[str, float]] = None, + depth_enabled: Optional[bool] = None, + heatmap_near_mm: float = 0.0, + heatmap_far_mm: float = 0.0, + heatmap_smooth_k: int = 0, + heatmap_temporal_alpha: float = 0.0, + depth_heatmaps: Optional[Dict[str, dict]] = None, + depth_slots: Optional[List[str]] = None, + devices: Optional[List[dict]] = None, + calibrations: Optional[Dict[str, object]] = None, + batch_index: int = 0) -> bool: + """创建池化任务目录并启动 ffmpeg(直接写最终路径)。 + + Args: + output_dir: 录制根目录 + cameras: {camera_name: (height, width)},名称如 head_left_rgb + fps: 默认录制帧率(未在 camera_fps 中指定的摄像机使用) + sensors: 传感器名称列表 + task_name: 任务标注 + device_ids: 设备 ID 列表(用于 status 列) + calibration: 双目标定数据(旧单值路径) + camera_fps: 每路摄像机的独立帧率(用于 ffmpeg -r) + depth_enabled: 深度录制开关;None 时回退 settings.DEPTH_ENABLED + heatmap_near_mm/far_mm: 已废弃(v1.1.2 起显示与存储统一为 + core.depth_codec 规范码值 JET,色标固定对数域),仅保留 + 签名兼容 + depth_heatmaps: 已废弃(同上),仅保留签名兼容 + depth_slots: 显式深度槽位列表(pipeline 中经 set_depth_camera + 注册的真实深度设备)。空/None → S80M 传统路径兜底单槽 + devices: 录制设备信息(写入 info.json 的 devices 段): + [{"key","kind","name","serial","slots"}] + calibrations: device_key → 标定(多路);存 info.json 任务级 + 最新 + episodes 行,不落盘 calibration/ 目录 + batch_index: 任务进度序号(录制完成次数 + 1);>0 时按进度 + 递增(与文件删除无关),0 时退化为目录扫描取最大 + 1 + """ + ffmpeg = _get_ffmpeg() + if not ffmpeg: + self.error_occurred.emit("ffmpeg 未找到"); return False + + self._fps = fps + self._camera_dims = dict(cameras) + self._camera_fps = dict(camera_fps) if camera_fps else {} + self._sensor_names = list(sensors) if sensors else [] + self._sensor_dim = settings.SENSOR_DIM + self._device_ids = list(device_ids) if device_ids else [] + self._calibrations = dict(calibrations) if calibrations else {} + self._devices = list(devices) if devices else [] + self._calib_dict = self._plan_calibration_dict(calibration) + + # 任务目录: //,episode 序号全局递增 + self._task_dir = task_dir_of(output_dir, task_name) + self._episode_index = next_pooled_episode_index(self._task_dir, + batch_index) + cidx, _fidx = episode_chunk_file(self._episode_index) + + # 深度配置:以显式注册的深度设备(pipeline.set_depth_camera → + # depth_slots)为准,不用槽名是否含 "depth" 猜测——D435/D405 等 + # 槽名可被消歧编号(d435_depth_2),型号与槽名都不该决定是否落盘。 + depth_requested = (depth_enabled if depth_enabled is not None + else settings.DEPTH_ENABLED) + if depth_slots: + self._depth_slots = {dn: dn for dn in depth_slots if dn} + else: + self._depth_slots = {settings.CAMERA_DEPTH: settings.CAMERA_DEPTH} + # 显式注册的深度设备打开即录(与旧语义一致:D435/D405 不受 + # settings.DEPTH_ENABLED 门控——该开关只作用于 S80M 视差路径) + self._depth_enabled = depth_requested and bool(depth_slots) + self._depth_proc_started = {} + self._depth_dirs = {} + self._depth_12bit = {} + # 深度存 12-bit 灰度 MP4(heatmap_near_mm/far_mm/depth_heatmaps + # 参数自 v1.1.2 起不再作用于落盘:显示与存储统一为 + # core.depth_codec 的规范码值 JET,色标固定对数域) + self._depth_final_ext = {slot: "mp4" for slot in self._depth_slots} + + # ★ v1.0.9 编码器自动选择:本会话 RGB 流数/最大分辨率驱动探针。 + # 本函数运行在 _start_async 后台线程(写盘线程在其返回后才启动), + # 探针阻塞不占 UI 节拍;结果进程内缓存,同参数不重探。深度热力图 + # 惰性启动时复用同一选择(同编码器同档位)。 + rgb_cams = {n: d for n, d in cameras.items() + if n not in self._depth_slots} + if rgb_cams: + max_h, max_w = max(rgb_cams.values(), + key=lambda hw: hw[0] * hw[1]) + n_streams = len(rgb_cams) + else: + max_h, max_w = (max(cameras.values(), + key=lambda hw: hw[0] * hw[1]) + if cameras else (0, 0)) + n_streams = 1 + if max_w <= 0 or max_h <= 0: + self.error_occurred.emit("无有效视频流,无法启动录制"); return False + prefer = settings.RECORD_VIDEO_ENCODER if settings.ENCODER_PROBE_ENABLED \ + else "x264" + choice = select_encoder(prefer, max_w, max_h, fps, n_streams, + log=self.log_occurred.emit) + if choice is None: + self.error_occurred.emit("未找到可用视频编码器 (ffmpeg -encoders)") + return False + self._encoder_choice = choice + + # 目录:meta/episodes chunk + data chunk + 每路视频 image_key 目录 + # (关键点数据独立存于 keypoints_output/,此处不创建) + self._created_files = [] + self._created_dirs = [] + dirs = [ + os.path.join("meta", "episodes", f"chunk-{cidx:03d}"), + os.path.join("data", f"chunk-{cidx:03d}"), + ] + for cam_name in cameras: + if cam_name in self._depth_slots: + continue + vdir = pooled_video_dir(self._task_dir, cam_name, + self._episode_index) + dirs.append(vdir) + self._created_files.append( + pooled_video_path(self._task_dir, cam_name, + self._episode_index)) + for sub in dirs: + d = os.path.join(self._task_dir, sub) + try: + os.makedirs(d, exist_ok=True) + except OSError as e: + self.error_occurred.emit(str(e)); return False + self._created_dirs.append(d) + + # 启动 ffmpeg(仅 RGB 相机),每路使用独立帧率; + # 编码器取本会话选择(v1.0.9 动态化,见上方 select_encoder) + for cam_name, (h, w) in cameras.items(): + if cam_name in self._depth_slots: + continue # 深度不走 MP4(显式注册驱动,不猜槽名) + cam_r = self._camera_fps.get(cam_name, fps) + video_path = pooled_video_path(self._task_dir, cam_name, + self._episode_index) + cmd = [ + choice.ffmpeg, "-y", "-f", "rawvideo", "-pix_fmt", "bgr24", + "-s", f"{w}x{h}", "-r", str(cam_r), "-i", "-", + "-c:v", choice.encoder, *choice.args, + "-pix_fmt", "yuv420p", "-f", "mp4", video_path, + ] + try: + self._ffmpeg_procs[cam_name] = subprocess.Popen( + cmd, stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + ) + except Exception as e: + self.error_occurred.emit(str(e)); return False + + self._episode_start_s = time.time() + self._episode_created_at = time.time() + self._frame_count = 0 + self._max_frame_idx = 0 + self._rows.clear() + self._present_sensors = set() + self._present_imu = False + self._present_glove_imu = set() + self._reset_stats() + self._last_task = task_name + + self.episode_started.emit(self._task_dir) + return True + + # ── 标定规划 ─────────────────────────────────────── + + def _plan_calibration_dict(self, legacy_calib) -> dict: + """规划标定 dict(存 info.json/episodes 行,不落盘 calibration/)。 + + 顺序由 devices 列表决定(calibrations 按 device_key 取);旧单值 + calibration 参数写 "head_stereo" 键;全都缺时仍写默认 + head_stereo(保持既有行为)。首台双目型设备同时以 "head_stereo" + 键保存(服务器/回放/stereo_triangulate 兼容路径)。 + """ + ordered = [(d.get("key", ""), d) for d in self._devices] + if not ordered or not self._calibrations: + c = legacy_calib if legacy_calib is not None else StereoCalibration() + return {"head_stereo": c.to_dict()} + out: Dict[str, dict] = {} + first_stereo = True + for dev_key, d in ordered: + c = self._calibrations.get(dev_key) + if c is None or not isinstance(c, StereoCalibration): + continue + if first_stereo: + out["head_stereo"] = c.to_dict() + first_stereo = False + else: + out[f"{self._device_slot_prefix(d)}_calibration"] = c.to_dict() + if not out: + out["head_stereo"] = StereoCalibration().to_dict() + return out + + @staticmethod + def _device_slot_prefix(device: dict) -> str: + """设备槽前缀: 首槽去掉 "_N" 消歧编号(d435_rgb_2 → d435_rgb)。""" + slots = device.get("slots") or [] + slot = slots[0] if slots else (device.get("key") or "device") + import re as _re + return _re.sub(r"_\d+$", "", str(slot)) + + def _video_codec_meta(self) -> dict: + """本会话视频编码信息(episodes 行 video_codec 段)。""" + c = self._encoder_choice + if c is None: + meta = {"encoder": "libx264", "codec": "H.264", + "crf": settings.RECORD_VIDEO_X264_CRF, + "selected_by": settings.RECORD_VIDEO_ENCODER} + else: + meta = {"encoder": c.encoder, "codec": c.codec, "crf": c.crf, + "ffmpeg": c.ffmpeg, "selected_by": c.selected_by, + "probe": c.probe} + # 深度槽编码(12-bit 灰度 HEVC 或 FFV1 回落),按槽记录 + depth_meta = {} + for slot in self._depth_slots: + if self._depth_12bit.get(slot): + depth_meta[slot] = {"codec": "HEVC (Rext) gray12le", + "qp": 6, "format": "12bit log codes"} + else: + depth_meta[slot] = {"codec": "FFV1 gray16le", + "format": "uint16 mm"} + if depth_meta: + meta["depth"] = depth_meta + return meta + + # ── 视频帧写入 ───────────────────────────────────── + + def write_video_frame(self, camera_name: str, frame: np.ndarray, + flip_vertical: bool = True): + """写入一帧 BGR 到对应摄像机的 ffmpeg 管道。 + + Args: + camera_name: 摄像机标识 + frame: BGR numpy array + flip_vertical: 是否上下翻转(默认 True,单目 CameraSlot 路径使用; + 双目显示帧路径传入 False,因为已在 _on_stereo_frame 完成翻转) + """ + proc = self._ffmpeg_procs.get(camera_name) + if proc and proc.stdin and not proc.stdin.closed: + try: + if flip_vertical: + frame = cv2.flip(frame, 0) + proc.stdin.write(frame.tobytes()) + except (BrokenPipeError, OSError): + self.error_occurred.emit(f"ffmpeg pipe broken ({camera_name})") + + # ── 深度帧写入 ───────────────────────────────────── + + def _resolve_depth_slot(self, depth_slot: str) -> str: + """把调用方深度槽名映射到本 episode 的落盘槽名。 + + 规则: 槽名精确匹配 → 原样;否则若只有单一深度槽(S80M 传统路径 + 的 "stereo_left" 名义槽)→ 回落到该槽;多槽且无匹配 → 原样返回, + 由调用方发现无 ffmpeg proc 时自然跳过。 + """ + if depth_slot in self._depth_slots: + return depth_slot + if len(self._depth_slots) == 1: + return next(iter(self._depth_slots)) + return depth_slot + + def write_depth_frame(self, frame_index: int, depth_frame: np.ndarray, + depth_slot: str = ""): + """写入一帧深度图 —— 12-bit 灰度 MP4(v1.1.2,lerobot v3 同款)。 + + 单条 ffmpeg 管道:gray12le → libx265 qp=6 近无损(hevc Rext + 单平面,12-bit 对数深度码,见 core/depth_codec.py),直接写 + 最终路径 videos/chunk-NNN//file-NNN.mp4(单流无需合封)。 + x265 无 12-bit 灰度能力时回落 FFV1 gray16le 无损 MKV(旧格式, + uint16 毫米原值)。 + + 帧节拍:调用方(pipeline)按主槽位帧节拍调用本函数,深度源缺帧时 + 重复最近帧——深度帧 i 与 RGB 帧 i 严格对齐。 + + Args: + frame_index: 帧序号(与 RGB 严格对应;仅存档签名,未参与写入) + depth_frame: uint16 numpy array (H, W),单位毫米 + depth_slot: 深度槽名(多深度相机时区分落盘目录; + 空/未注册时按单槽回落,多槽无匹配则跳过) + """ + if not settings.DEPTH_ENABLED and not self._depth_enabled: + return # 深度录制已关闭,直接跳过 + slot = self._resolve_depth_slot(depth_slot) + if slot not in self._depth_slots: + return # 多槽下无匹配(如 stereo_left 名义帧)→ 不落盘 + if not self._depth_proc_started.get(slot): + # 首次调用:创建目录 + 启动单流深度 ffmpeg(12-bit 优先) + self._depth_dirs[slot] = pooled_video_dir( + self._task_dir, slot, self._episode_index) + try: + os.makedirs(self._depth_dirs[slot], exist_ok=True) + except OSError: + pass + self._created_dirs.append(self._depth_dirs[slot]) + + h, w = depth_frame.shape[:2] + ffmpeg = _get_ffmpeg() + if ffmpeg: + depth_r = (self._camera_fps.get(slot) + or self._camera_fps.get("stereo_left", self._fps)) + d12 = find_depth_12bit_ffmpeg() + if d12: + # 12-bit 对数深度码 → gray12le HEVC(直接写最终路径) + final = pooled_video_path(self._task_dir, slot, + self._episode_index, "mp4") + cmd = [ + d12, "-y", "-f", "rawvideo", "-pix_fmt", "gray12le", + "-s", f"{w}x{h}", "-r", str(depth_r), "-i", "-", + "-c:v", "libx265", *depth_video_encoder_args(), final, + ] + self._depth_12bit[slot] = True + else: + # 回落:FFV1 gray16le 无损 uint16 毫米(旧格式 MKV) + final = pooled_video_path(self._task_dir, slot, + self._episode_index, "mkv") + self._depth_final_ext[slot] = "mkv" + cmd = [ + ffmpeg, "-y", "-f", "rawvideo", "-pix_fmt", "gray16le", + "-s", f"{w}x{h}", "-r", str(depth_r), "-i", "-", + "-c:v", "ffv1", "-level", "3", + "-pix_fmt", "gray16le", final, + ] + self._depth_12bit[slot] = False + try: + self._ffmpeg_procs[slot] = subprocess.Popen( + cmd, stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + ) + self._created_files.append(final) + except Exception as e: + self.error_occurred.emit(f"depth ffmpeg failed: {e}") + + self._depth_proc_started[slot] = True + + proc = self._ffmpeg_procs.get(slot) + if not proc or not proc.stdin or proc.stdin.closed: + return + if self._depth_12bit.get(slot): + payload = np.ascontiguousarray( + quantize_depth(depth_frame), dtype=" self._max_frame_idx: + self._max_frame_idx = frame_index + 1 + + # ── 结束 ────────────────────────────────────────── + + def end_episode(self): + """关闭 ffmpeg,写出全部文件(顺序见 docs/data.md 写入流程)。""" + self._close_ffmpeg() + self._write_data_parquet() + self._append_episode_row() + self._write_info_json() + self._merge_stats() + self._write_tasks_jsonl() + clear_recycled_episode(self._task_dir) + self.episode_finished.emit(self._task_dir) + + @property + def encoder_label(self) -> str: + """本会话视频编码的 UI 显示名(pipeline 录制状态栏用)。""" + c = self._encoder_choice + return c.label if c is not None else "H.264/MP4" + + def set_drop_stats(self, stats: Dict[str, int]) -> None: + """注入录制丢帧统计(pipeline 在 end_episode 前调用)。""" + self._drop_stats = dict(stats or {}) + + def abort_episode(self): + """丢弃本 episode 的全部数据(文件级清理)。 + + abort 只发生在录制期(end_episode 之前),本 episode 未写 data + parquet / episodes 行 / stats 合并;只需删除 ffmpeg 已落盘的视频 + 终稿与深度临时件,并回滚空目录。防御性回滚 episodes 行(若存在)。 + + 异常终止不占号:标记本段序号可复用,下次录制优先取回 + (next_pooled_episode_index 读到标记即复用;正常完成时清除)。 + """ + if getattr(self, "_episode_index", 0) > 0 and getattr( + self, "_task_dir", ""): + mark_recycled_episode(self._task_dir, self._episode_index) + self._close_ffmpeg() + for p in list(self._created_files): + try: + if os.path.isfile(p): + os.remove(p) + except OSError: + pass + # 防御性:episodes 行回滚(正常流程不可达) + self._rollback_episode_row() + # 空目录回滚(深到浅,只删空目录;共享目录自然保留) + for d in reversed(sorted(self._created_dirs, key=len)): + try: + os.rmdir(d) + except OSError: + pass + try: + os.rmdir(self._task_dir) + except OSError: + pass + self.episode_finished.emit("") + + def _rollback_episode_row(self): + """移除本 episode 的 episodes 元数据(每段一文件 → os.remove; + 旧分片回退 → 读-改-写删行,保证 episode_row(N) 回退后返回 {})。 + N=1 时分片与每段文件同路径,先按内容判每段文件才删。""" + path = pooled_episodes_path(self._task_dir, self._episode_index) + with self._task_lock(): + removed_path = False + if os.path.isfile(path): + rows = _read_episode_rows(path) + if len(rows) <= 1 and (not rows or rows[0].get( + "episode_index") == self._episode_index): + try: + os.remove(path) + except OSError: + pass + removed_path = True + cidx, _fidx = episode_chunk_file(self._episode_index) + legacy = _legacy_episodes_shard_path(self._task_dir, cidx) + if os.path.isfile(legacy) and not (removed_path + and legacy == path): + rows = _read_episode_rows(legacy) + kept = [r for r in rows + if r.get("episode_index") != self._episode_index] + if len(kept) != len(rows): + if kept: + _atomic_write_parquet(_episode_rows_table(kept), legacy) + else: + try: + os.remove(legacy) + except OSError: + pass + + # ── 内部 ────────────────────────────────────────── + + def _close_ffmpeg(self): + for proc in list(self._ffmpeg_procs.values()): + try: + if proc.stdin: proc.stdin.close() + except Exception: + pass + try: + proc.wait(timeout=5) + except subprocess.TimeoutExpired: + proc.kill(); proc.wait() + self._ffmpeg_procs.clear() + + def _write_data_parquet(self): + """写入本 episode 的 data parquet(单文件,稀疏列,zstd)。 + + 键列恒有(episode_index/frame_index/timestamp/task_index/ + wall_time/hardware_ns/action/手部占位列/status 列);观测列稀疏: + 只写本 episode 实际有数据的传感器与 IMU 列。 + """ + with QMutexLocker(self._mutex): + if not self._rows: + return + rows = self._rows[:] + self._rows.clear() + + cols = { + "episode_index": pa.array([r["episode_index"] for r in rows], + pa.int64()), + "frame_index": pa.array([r["frame_index"] for r in rows], + pa.int64()), + "timestamp": pa.array([r["timestamp"] for r in rows], + pa.float32()), + "task_index": pa.array([r["task_index"] for r in rows], + pa.int64()), + "wall_time": pa.array([r["wall_time"] for r in rows], + pa.float64()), + "hardware_ns": pa.array([r["hardware_ns"] for r in rows], + pa.int64()), + "action": pa.array([r["action"] for r in rows], + pa.list_(pa.float32(), 1)), + } + # 稀疏传感器列(有真实数据的才写) + for sn in sorted(self._present_sensors): + name = f"observation.{sn}" + cols[name] = pa.array( + [r.get(name, [0.0] * self._sensor_dim) for r in rows], + pa.list_(pa.float32(), self._sensor_dim), + ) + # 稀疏 IMU 列 + if self._present_imu: + cols["imu_ts_ns"] = pa.array( + [r.get("imu_ts_ns", []) for r in rows], pa.list_(pa.int64())) + cols["observation.imu"] = pa.array( + [r.get("observation.imu", []) for r in rows], + pa.list_(pa.list_(pa.float32(), 6))) + # 稀疏 USB 手套 IMU 列(四元数 64 维 + 有效掩码 16 维,每传感器一对) + for sn in sorted(self._present_glove_imu): + name_q = f"observation.{sn}_imu_quat" + name_v = f"observation.{sn}_imu_valid" + cols[name_q] = pa.array( + [r.get(name_q, [0.0] * 64) for r in rows], + pa.list_(pa.float32(), 64)) + cols[name_v] = pa.array( + [r.get(name_v, [0.0] * 16) for r in rows], + pa.list_(pa.float32(), 16)) + # 手部关键点占位列(后处理回填,恒写) + for pose_name in [settings.HAND_POSE_LEFT, settings.HAND_POSE_RIGHT]: + name = f"observation.{pose_name}" + cols[name] = pa.array( + [r[name] for r in rows], + pa.list_(pa.float32(), settings.HAND_POSE_DIM), + ) + for did in self._device_ids: + name = f"status.{did}" + cols[name] = pa.array( + [r.get(name, "connected") for r in rows], pa.string()) + + table = pa.table(cols) + path = pooled_data_parquet_path(self._task_dir, self._episode_index) + os.makedirs(os.path.dirname(path), exist_ok=True) + _atomic_write_parquet(table, path) + + def _append_episode_row(self): + """meta/episodes/chunk-NNN/episode-NNN.parquet 每段一个文件、单行原子写。 + + 与 data/videos 同编号(episode-000 = episode 1):每采一条新任务 + 就多一个 episode 文件。重录同 episode_index = 覆盖该文件。旧分片 + (每 chunk 一个多行文件)里的同号行一并删除,避免双份。 + 跨进程安全:fcntl.flock 锁 meta/episodes/.lock(Windows 无 + fcntl 退化为无锁,多机共享须 POSIX);写入走临时文件 + + os.replace 原子替换。 + """ + path = pooled_episodes_path(self._task_dir, self._episode_index) + os.makedirs(os.path.dirname(path), exist_ok=True) + row = { + "episode_index": self._episode_index, + "task_index": 0, + "start_frame_index": 0, + "end_frame_index": max(0, self._max_frame_idx - 1), + "length": self._max_frame_idx, + "created_at": float(self._episode_created_at), + "duration_sec": float(self._max_frame_idx / max(self._fps, 1.0)), + "drop_stats": json.dumps(self._drop_stats or {}, + ensure_ascii=False), + "video_codec": json.dumps(self._video_codec_meta(), + ensure_ascii=False), + "calibration": json.dumps(self._calib_dict, ensure_ascii=False), + } + with self._task_lock(): + _atomic_write_parquet(_episode_rows_table([row]), path) + # 旧分片里若有同号行则删掉(避免 episode_row 回退到旧记录) + cidx, _fidx = episode_chunk_file(self._episode_index) + legacy = _legacy_episodes_shard_path(self._task_dir, cidx) + if legacy != path and os.path.isfile(legacy): + rows = _read_episode_rows(legacy) + kept = [r for r in rows + if r.get("episode_index") != self._episode_index] + if len(kept) != len(rows): + if kept: + _atomic_write_parquet(_episode_rows_table(kept), + legacy) + else: + try: + os.remove(legacy) + except OSError: + pass + + def _task_lock(self): + """任务级跨进程锁(meta/episodes/.lock);上下文管理器。""" + lock_path = os.path.join(self._task_dir, "meta", "episodes", ".lock") + os.makedirs(os.path.dirname(lock_path), exist_ok=True) + fh = open(lock_path, "a+") + if _fcntl is not None: + _fcntl.flock(fh.fileno(), _fcntl.LOCK_EX) + return _LockedFile(fh) + + def _write_info_json(self): + """任务级 meta/info.json 读-改-写。 + + 服务器上传严格依赖既有字段名/类型/结构(features/cameras/ + devices/device_names/sensors/sensor_dim/fps/video/task_name/ + codebase_version/created_at),v1.1.0 新增 format/chunks_size/ + data_path/video_path/episodes_path/video_extensions/calibration/ + total_episodes/app_version。既有键保留合并(其他机器/旧版本写入 + 的不丢);features/cameras/video_extensions 按并集合并(key 一旦 + 存在不因后续 episode 缺席而丢失),值以最新 episode 为准。 + """ + # cameras: 必须是 dict 格式 {key: {height, width, fps}},不能用 list + # 深度槽过滤以显式注册为准,不猜槽名 + cameras_dict = {} + for name, (h, w) in self._camera_dims.items(): + if name in self._depth_slots: + continue + entry = {"height": h, "width": w} + cam_fps = self._camera_fps.get(name, self._fps) + if cam_fps != self._fps: + entry["fps"] = cam_fps + cameras_dict[name] = entry + + # features: shape 必须是 2D [16, 16],不是 1D [256]; + # 只声明本 episode 实际存在的列(稀疏契约) + features = {} + for sn in sorted(self._present_sensors): + features[f"observation.{sn}"] = { + "dtype": "float32", + "shape": [16, 16], + } + # 双目 IMU: 每帧窗口内变长样本序列, 每样本 6 轴 (gx,gy,gz,ax,ay,az) + if self._present_imu: + features["observation.imu"] = {"dtype": "float32", "shape": [6]} + # USB 手套 IMU: 每帧 16×4 XYZW 四元数 + 16 维有效掩码 + for sn in sorted(self._present_glove_imu): + features[f"observation.{sn}_imu_quat"] = { + "dtype": "float32", "shape": [16, 4]} + features[f"observation.{sn}_imu_valid"] = { + "dtype": "float32", "shape": [16]} + # 手部骨架关键点(21×3 米,恒写列;无骨架数据时为全零占位) + features[f"observation.{settings.HAND_POSE_LEFT}"] = { + "dtype": "float32", "shape": [21, 3]} + features[f"observation.{settings.HAND_POSE_RIGHT}"] = { + "dtype": "float32", "shape": [21, 3]} + features["action"] = {"dtype": "float32", "shape": [1]} + + # devices 紧凑段 + device_names(槽位 → 用户命名)——只加字段, + # 既有键名/类型一律不动(服务器严格依赖) + devices_compact = [{ + "key": d.get("key", ""), "kind": d.get("kind", ""), + "name": d.get("name", ""), "slots": list(d.get("slots") or []), + } for d in self._devices] + device_names = {} + for d in self._devices: + if d.get("name"): + for slot in (d.get("slots") or []): + device_names[slot] = d["name"] + + # video_extensions: 每 image_key 的文件扩展名(RGB=mp4;深度=mp4 + # 12-bit 灰度,x265 无能力回落 mkv)。并集合并,key 不丢。 + video_extensions = { + name: "mp4" for name in cameras_dict + } + for slot in self._depth_slots: + video_extensions[slot] = self._depth_final_ext.get(slot, "mp4") + + base = {} + path = pooled_info_path(self._task_dir) + if os.path.isfile(path): + try: + with open(path, "r", encoding="utf-8") as f: + base = json.load(f) + except (OSError, json.JSONDecodeError): + base = {} + if not isinstance(base, dict): + base = {} + + merged_features = dict(base.get("features") or {}) + merged_features.update(features) + merged_cameras = dict(base.get("cameras") or {}) + merged_cameras.update(cameras_dict) + merged_exts = dict(base.get("video_extensions") or {}) + merged_exts.update(video_extensions) + + info = dict(base) + info.update({ + "format": "pooled_episodes_v1", + "chunks_size": POOLED_CHUNK_SIZE, + "data_path": "data/chunk-{c:03d}/episode-{f:03d}.parquet", + "video_path": "videos/chunk-{c:03d}/{image_key}/episode-{f:03d}.{ext}", + "episodes_path": "meta/episodes/chunk-{c:03d}/episode-{f:03d}.parquet", + "codebase_version": "v3.0", + "app_version": settings.APP_VERSION, + "fps": self._fps, + "video": len(cameras_dict) > 0, + "task_name": self._last_task or "", + "features": merged_features, + "cameras": merged_cameras, + "devices": devices_compact, + "device_names": device_names, + "sensors": sorted(self._present_sensors), + "sensor_dim": self._sensor_dim, + "created_at": time.time(), + "calibration": self._calib_dict, # 任务级最新标定 + "total_episodes": len(list_task_episodes(self._task_dir)), + "video_extensions": merged_exts, + }) + self._atomic_write_json(path, info) + + def _merge_stats(self): + """把本 episode 统计合并进任务级 stats.json(v1.1.1 自含累加器)。 + + stats.json 每块 {count, mean, std, min, max}——count 可反推 + sum/sum_sq,因此文件自身就是增量累加器,无需 .stats_state 边车。 + 旧格式(无 count)或损坏 → recalc_stats 全量重扫重建一次。 + 只统计实际存在的列(present 传感器 + present IMU); + action 恒为占位(mean 0/std 1,与旧格式一致)。 + """ + acc, need_recalc = load_stats_acc(self._task_dir) + if need_recalc: + acc = recalc_stats(self._task_dir) + + for sn in sorted(self._present_sensors): + merge_stat_block(acc, f"observation.{sn}", + self._stats.get(sn), dim=self._sensor_dim) + if self._present_imu: + merge_stat_block(acc, "observation.imu", + self._stats.get("imu"), dim=6) + + self._atomic_write_json(pooled_stats_path(self._task_dir), + acc_to_stats_json(acc)) + + def _write_tasks_jsonl(self): + """任务级 meta/tasks.jsonl(不存在才建,服务器依赖此文件识别任务)。""" + path = pooled_tasks_jsonl_path(self._task_dir) + if os.path.isfile(path): + return + with open(path, "w", encoding="utf-8") as f: + json.dump({ + "task_index": 0, + "task": self._last_task or "default recording", + }, f, ensure_ascii=False) + f.write("\n") + + # ── 原子写入工具 ────────────────────────────────── + + def _atomic_write_json(self, path: str, data: dict): + """JSON 原子写:临时文件 + os.replace(同盘保证原子)。""" + os.makedirs(os.path.dirname(path), exist_ok=True) + tmp = os.path.join(os.path.dirname(path), + f".{os.path.basename(path)}.tmp") + with open(tmp, "w", encoding="utf-8") as f: + json.dump(data, f, indent=2, ensure_ascii=False) + os.replace(tmp, path) + + # ── 统计量 ──────────────────────────────────────── + + def _reset_stats(self): + self._stats.clear() + + def _ensure_stats(self, sensor_name: str): + if sensor_name not in self._stats: + self._stats[sensor_name] = { + "sum": np.zeros(self._sensor_dim, dtype=np.float64), + "sum_sq": np.zeros(self._sensor_dim, dtype=np.float64), + "min": np.full(self._sensor_dim, np.inf, dtype=np.float64), + "max": np.full(self._sensor_dim, -np.inf, dtype=np.float64), + "count": 0, + } + + def _update_stats(self, sensor_name: str, arr: np.ndarray): + self._ensure_stats(sensor_name) + st = self._stats[sensor_name] + a = arr.astype(np.float64) + st["sum"] += a + st["sum_sq"] += a * a + st["min"] = np.minimum(st["min"], a) + st["max"] = np.maximum(st["max"], a) + st["count"] += 1 + + # ── IMU 统计(样本级, 6 轴, 区别于传感器的 256 维帧级统计)── + + def _ensure_imu_stats(self): + if "imu" not in self._stats: + self._stats["imu"] = { + "sum": np.zeros(6, dtype=np.float64), + "sum_sq": np.zeros(6, dtype=np.float64), + "min": np.full(6, np.inf, dtype=np.float64), + "max": np.full(6, -np.inf, dtype=np.float64), + "count": 0, + } + + def _update_imu_stats(self, samples: List[List[float]]): + """按 IMU 样本累积 6 轴统计(count = 样本总数)。 + + samples: 本帧窗口的样本列表, 每样本 [gx, gy, gz, ax, ay, az] + """ + if not samples: + return + self._ensure_imu_stats() + st = self._stats["imu"] + a = np.asarray(samples, dtype=np.float64).reshape(-1, 6) + st["sum"] += a.sum(axis=0) + st["sum_sq"] += np.square(a).sum(axis=0) + st["min"] = np.minimum(st["min"], a.min(axis=0)) + st["max"] = np.maximum(st["max"], a.max(axis=0)) + st["count"] += len(samples) + + +# ── 模块级工具 ──────────────────────────────────────── + +class _LockedFile: + """flock 锁句柄上下文(释放锁 + 关闭文件)。""" + + def __init__(self, fh): + self._fh = fh + + def __enter__(self): + return self._fh + + def __exit__(self, *exc): + try: + if _fcntl is not None: + _fcntl.flock(self._fh.fileno(), _fcntl.LOCK_UN) + except Exception: + pass + try: + self._fh.close() + except Exception: + pass + return False + + +def _atomic_write_parquet(table: pa.Table, path: str): + """Parquet 原子写:临时文件 + os.replace(同盘保证原子)。""" + tmp = os.path.join(os.path.dirname(path), + f".{os.path.basename(path)}.tmp") + pq.write_table(table, tmp, compression="zstd") + os.replace(tmp, path) diff --git a/collector/core/encoder_probe.py b/collector/core/encoder_probe.py new file mode 100644 index 0000000000000000000000000000000000000000..6675196950c0ffb289cfd5012d6ffebb4543dda4 --- /dev/null +++ b/collector/core/encoder_probe.py @@ -0,0 +1,345 @@ +""" +编码器探针 —— 录制编码器自动选择(v1.0.9:录制直出 HEVC)。 + +纯函数模块(无 Qt 依赖),供 EgoDataWriter 在录制启动前调用(发生在 +pipeline 的 _start_async 后台线程内,写盘线程在其返回后才启动,探针 +不卡 UI、不影响写入节奏): + - 候选 ffmpeg 二进制枚举(imageio 静态 → PATH,-version 自检) + - 编码器能力探测(-encoders)与速度探针(null muxer 微型编码) + - 编码器选择(auto: hevc_nvenc → libx265 速度达标 → libx264 回退) + 与参数映射 + +选择结果进程内缓存(同一进程内机器不变不重探;负结果也缓存)。探针 +同步执行、最坏 ~10-20s;所有探针异常按「该编码器不可用」降级处理。 +""" +from __future__ import annotations + +import dataclasses +import shutil +import subprocess +import threading +import time +from typing import Callable, Dict, List, Optional + +from config import settings + +# ── 进程内缓存 ──────────────────────────────────────── +_FFMPEG_CACHE: Optional[List[str]] = None +_ENCODER_CACHE: Dict[tuple, bool] = {} +_SELECT_CACHE: Dict[tuple, Optional["EncoderChoice"]] = {} + + +@dataclasses.dataclass +class EncoderChoice: + """一次编码器选择的结果。""" + encoder: str # "hevc_nvenc" | "libx265" | "libx264" + codec: str # "HEVC" | "H.264" + crf: int # 本选择实际用的档位(x264 用回退档) + args: list # ffmpeg 编码参数(不含 -c:v) + ffmpeg: str # 采用的 ffmpeg 二进制 + label: str # UI 显示名,如 "HEVC (hevc_nvenc)" + probe: dict # 探针明细(写 metadata.json) + selected_by: str # settings.RECORD_VIDEO_ENCODER 原值 + + +# ═══════════════════════════════════════════════════════ +# ffmpeg 二进制枚举 / 编码器能力 +# ═══════════════════════════════════════════════════════ + +def list_working_ffmpegs() -> List[str]: + """候选 ffmpeg 二进制(imageio 静态 → PATH),经 -version 自检。 + + 全部自检失败时,仍把 imageio 静态二进制作为最后兜底返回(与旧 + _get_ffmpeg 口径一致:它已在录制段被证明可用)。 + """ + global _FFMPEG_CACHE + if _FFMPEG_CACHE is not None: + return list(_FFMPEG_CACHE) + candidates: List[str] = [] + imageio_exe = None + try: + import imageio_ffmpeg + imageio_exe = imageio_ffmpeg.get_ffmpeg_exe() + candidates.append(imageio_exe) + except Exception: + pass + for name in ("ffmpeg", "ffmpeg.exe"): + p = shutil.which(name) + if p and p not in candidates: + candidates.append(p) + working = [] + for exe in candidates: + try: + r = subprocess.run([exe, "-version"], capture_output=True, + timeout=10) + if r.returncode == 0: + working.append(exe) + except Exception: + continue + if not working and imageio_exe: + working.append(imageio_exe) # 兜底:录段历史证明可用 + _FFMPEG_CACHE = working + return list(working) + + +def ffmpeg_has_encoder(ffmpeg: str, encoder: str) -> bool: + """-encoders 输出里是否含该编码器(结果缓存)。""" + key = (ffmpeg, encoder) + if key in _ENCODER_CACHE: + return _ENCODER_CACHE[key] + found = False + try: + r = subprocess.run([ffmpeg, "-hide_banner", "-encoders"], + capture_output=True, timeout=30) + text = ((r.stdout or b"") + (r.stderr or b"")).decode("utf-8", "ignore") + found = encoder in text.split() + except Exception: + found = False + _ENCODER_CACHE[key] = found + return found + + +# ═══════════════════════════════════════════════════════ +# 参数映射 / 微型探针 +# ═══════════════════════════════════════════════════════ + +def encoder_args(encoder: str, crf: Optional[int] = None) -> List[str]: + """编码器参数映射(HEVC 一律带 hvc1 容器标记)。""" + if crf is None: + crf = settings.RECORD_VIDEO_CRF + table = { + "hevc_nvenc": ["-rc", "vbr", "-cq", str(crf), "-preset", "p4", + "-tag:v", "hvc1"], + "libx265": ["-crf", str(crf), "-preset", "veryfast", "-tag:v", "hvc1"], + "libx264": ["-preset", "ultrafast", + "-crf", str(settings.RECORD_VIDEO_X264_CRF)], + } + return list(table[encoder]) + + +def _kill(p: subprocess.Popen) -> None: + try: + p.kill() + except Exception: + pass + try: + p.wait(timeout=3) + except Exception: + pass + + +def _feed_raw(proc: subprocess.Popen, frame_bytes: bytes, frames: int) -> None: + try: + for _ in range(frames): + proc.stdin.write(frame_bytes) + proc.stdin.flush() + finally: + try: + proc.stdin.close() + except Exception: + pass + + +def probe_nvenc(ffmpeg: str, width: int, height: int, fps: float, + crf: Optional[int] = None, timeout: int = 10) -> bool: + """NVENC 微型探针:~1s 编码(null muxer)确认 GPU 可用。""" + frames = max(3, int(fps)) + cmd = [ffmpeg, "-y", "-f", "rawvideo", "-pix_fmt", "bgr24", + "-s", f"{width}x{height}", "-r", str(fps), "-i", "-", + "-frames:v", str(frames), + "-c:v", "hevc_nvenc", *encoder_args("hevc_nvenc", crf), + "-f", "null", "-"] + try: + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + _feed_raw(p, bytes(width * height * 3), frames) + return p.wait(timeout=timeout) == 0 + except Exception: + return False + + +def probe_x265(ffmpeg: str, width: int, height: int, fps: float, + n_streams: int, frames: Optional[int] = None, + timeout: Optional[int] = None) -> dict: + """x265 速度探针:并行 n 流各编 frames 帧 → null,返回每流实测 fps。 + + n_streams = 本会话视频流数(封顶 ENCODER_PROBE_MAX_STREAMS)。全部 + 流并行跑满同一墙钟,每流 fps = frames / 总耗时 —— 与写盘线程每 tick + 串行写全部槽的背压口径近似一致。合成帧为全零帧(编码最快),1.5× + 门槛余量即为此乐观偏差所设。 + """ + if frames is None: + frames = settings.ENCODER_PROBE_FRAME_COUNT + if timeout is None: + timeout = settings.ENCODER_PROBE_TIMEOUT_S + n = max(1, min(int(n_streams), settings.ENCODER_PROBE_MAX_STREAMS)) + frame_bytes = bytes(width * height * 3) + cmd_base = [ffmpeg, "-y", "-f", "rawvideo", "-pix_fmt", "bgr24", + "-s", f"{width}x{height}", "-r", str(fps), "-i", "-", + "-frames:v", str(frames), + "-c:v", "libx265", *encoder_args("libx265"), + "-f", "null", "-"] + procs: List[subprocess.Popen] = [] + start = time.monotonic() + ok = True + try: + for _ in range(n): + procs.append(subprocess.Popen( + cmd_base, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL)) + feeders = [threading.Thread(target=_feed_raw, args=(p, frame_bytes, frames), + daemon=True) for p in procs] + for t in feeders: + t.start() + for p in procs: + p.wait(timeout=timeout) + except subprocess.TimeoutExpired: + ok = False + for p in procs: + if p.poll() is None: + _kill(p) + ok = False + elif p.returncode != 0: + ok = False + elapsed = time.monotonic() - start + if not ok or elapsed <= 0: + return {"per_stream_fps": [], "min_fps": 0.0, "passed": False, + "streams": n, "frames": frames, "elapsed_s": round(elapsed, 2)} + per = [frames / elapsed] * n + min_fps = min(per) + threshold = fps * settings.ENCODER_X265_MIN_FPS_RATIO + return {"per_stream_fps": [round(x, 1) for x in per], + "min_fps": round(min_fps, 1), "passed": min_fps >= threshold, + "threshold_fps": round(threshold, 1), + "streams": n, "frames": frames, "elapsed_s": round(elapsed, 2)} + + +def probe_depth_12bit(ffmpeg: str, timeout: int = 8) -> bool: + """深度 12-bit 灰度编码能力探针:gray12le → libx265 → null。 + + x265 版本/构建差异下 gray12le(4:0:0,hevc Rext)未必可用; + 单帧微型编码(32×32 → null)确认能力,结果进程内缓存。 + 失败时调用方回落 FFV1 gray16le MKV(无损 16-bit 旧格式)。 + """ + key = (ffmpeg, "depth12") + if key in _ENCODER_CACHE: + return _ENCODER_CACHE[key] + ok = False + try: + p = subprocess.Popen( + [ffmpeg, "-y", "-f", "rawvideo", "-pix_fmt", "gray12le", + "-s", "32x32", "-r", "30", "-i", "-", + "-frames:v", "1", "-c:v", "libx265", + "-x265-params", "qp=6:range=full", "-f", "null", "-"], + stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + _feed_raw(p, bytes(32 * 32 * 2), 1) + ok = p.wait(timeout=timeout) == 0 + except Exception: + ok = False + _ENCODER_CACHE[key] = ok + return ok + + +def find_depth_12bit_ffmpeg() -> Optional[str]: + """候选二进制中第一个支持 gray12le 12-bit 编码的;全不支持返回 None。""" + return next((b for b in list_working_ffmpegs() if probe_depth_12bit(b)), + None) + + +# ═══════════════════════════════════════════════════════ +# 选择入口 +# ═══════════════════════════════════════════════════════ + +def select_encoder(prefer: str, width: int, height: int, fps: float, + n_streams: int, log: Optional[Callable[[str], None]] = None + ) -> Optional[EncoderChoice]: + """选择录制编码器。返回 EncoderChoice,全链失败返回 None。 + + prefer: settings.RECORD_VIDEO_ENCODER("auto"|"nvenc"|"x265"|"x264") + auto 链: hevc_nvenc(探针可用) → libx265(速度达标) → libx264(兜底) + 显式指定: 跳过速度门槛强制用该编码器;二进制不支持/探针失败时按 + auto 链回退并播报原因。 + """ + if log is None: + log = lambda msg: None + cache_key = (prefer, width, height, fps, + min(int(n_streams), settings.ENCODER_PROBE_MAX_STREAMS)) + if cache_key in _SELECT_CACHE: + return _SELECT_CACHE[cache_key] + bins = list_working_ffmpegs() + if not bins: + log("[编码器] 未找到可用 ffmpeg 二进制") + _SELECT_CACHE[cache_key] = None + return None + + def find_with(enc: str) -> Optional[str]: + return next((b for b in bins if ffmpeg_has_encoder(b, enc)), None) + + def make(enc: str, ffmpeg: str, probe: Optional[dict] = None) -> EncoderChoice: + is_hevc = enc != "libx264" + crf = settings.RECORD_VIDEO_CRF if is_hevc else settings.RECORD_VIDEO_X264_CRF + return EncoderChoice( + encoder=enc, + codec="HEVC" if is_hevc else "H.264", + crf=crf, + args=encoder_args(enc), + ffmpeg=ffmpeg, + label=("HEVC (%s)" % enc) if is_hevc else "H.264 (libx264)", + probe=probe or {}, + selected_by=prefer) + + def auto_chain(why: Optional[str] = None) -> Optional[EncoderChoice]: + if why: + log(f"[编码器] {why},按 auto 链回退") + exe = find_with("hevc_nvenc") + if exe and probe_nvenc(exe, width, height, fps, + settings.RECORD_VIDEO_CRF): + log("[编码器] hevc_nvenc 探针通过 → HEVC 硬件编码") + return make("hevc_nvenc", exe, {"kind": "nvenc", "ok": True}) + if exe: + log("[编码器] hevc_nvenc 探针失败(GPU 不可用),跳过") + exe = find_with("libx265") + if exe: + probe = probe_x265(exe, width, height, fps, n_streams) + if probe["passed"]: + log(f"[编码器] libx265 实测 {probe['min_fps']:.0f} fps/流 " + f"(门槛 {probe['threshold_fps']:.0f}) → HEVC 软编") + return make("libx265", exe, probe) + log(f"[编码器] libx265 实测 {probe['min_fps']:.0f} fps/流 " + f"(门槛 {probe['threshold_fps']:.0f}) → 不达标") + exe = find_with("libx264") + if exe: + log(f"[编码器] 回退 H.264 (libx264 ultrafast, " + f"CRF{settings.RECORD_VIDEO_X264_CRF})") + return make("libx264", exe) + return None + + if prefer == "nvenc": + exe = find_with("hevc_nvenc") + if exe and probe_nvenc(exe, width, height, fps, + settings.RECORD_VIDEO_CRF): + log("[编码器] 显式 nvenc:hevc_nvenc 探针通过") + choice = make("hevc_nvenc", exe, {"kind": "nvenc", "ok": True}) + else: + choice = auto_chain("显式 nvenc 但 hevc_nvenc 探针失败") + elif prefer == "x265": + exe = find_with("libx265") + if exe: + log("[编码器] 显式 x265:跳过速度门槛,强制 HEVC 软编") + choice = make("libx265", exe) + else: + choice = auto_chain("显式 x265 但无二进制支持 libx265") + elif prefer == "x264": + exe = find_with("libx264") + if exe: + log("[编码器] 显式 x264:跳过探针,直接 H.264") + choice = make("libx264", exe) + else: + choice = auto_chain("显式 x264 但无二进制支持 libx264") + else: # auto + choice = auto_chain() + + _SELECT_CACHE[cache_key] = choice + return choice diff --git a/collector/core/exposure_controller.py b/collector/core/exposure_controller.py new file mode 100644 index 0000000000000000000000000000000000000000..88627463357b1f7b68f61d76b9fe2b5337c9ecac --- /dev/null +++ b/collector/core/exposure_controller.py @@ -0,0 +1,80 @@ +""" +每设备曝光控制 —— ☀ 对话框参数解析与下发/持久化口径(零 Qt 依赖)。 + +供主窗口曝光对话框入口与离线测试共用同一套口径: + - exposure_dialog_params 按设备类型解析对话框上下文(量程/自动/当前值/ + 恢复默认基线 + 首见基线落盘锁定);UVC 返回 None + - apply_exposure 按设备类型下发并持久化(下次开启自动应用) +""" + +from __future__ import annotations + +from config import settings +from core.device_naming import normalize_original + + +def exposure_dialog_params(kind: str, entry: dict, + dev_key: str) -> dict | None: + """☀ 曝光对话框参数解析(对话框只做 0..1000 刻度映射)。 + + 量程/单位语义: + D435 → µs,流启动后读真实 rs.option.exposure 量程 + S80M → SDK 曝光 1.0~885.0(与 yaml stereo_init_exposure 同单位) + UVC 无曝光入口(固定自动曝光,保证正常亮度 + 30fps)→ 返回 None。 + + 「恢复默认」基线(original):优先持久化的首见基线 + (settings.device_original,首次开启设备时锁定),无则用 + worker 本次开流读回的硬件状态,并在对话框弹出时落盘锁定 + (之后 worker 读回值不再覆盖)。 + """ + if kind == "uvc": + return None + label = entry["label"] + if kind == "d435": + rng, auto, value = entry["worker"].exposure_info() + if rng is None: + rng = (1.0, 66000.0) # 流未启动兜底量程(µs) + if auto is None: + auto = True + if value is None: + value = rng[1] / 2.0 + orig = settings.device_original(dev_key) + if orig is None: + orig = entry["worker"].original_exposure() + decimals = 0 + elif kind == "s80m": + exp = settings.device_exposure(dev_key) + auto = True if exp is None else exp["auto"] + value = 400.0 if exp is None else exp["value"] + orig = settings.device_original(dev_key) + if orig is None: + orig = entry.get("original_exp") + rng = (1.0, 885.0) + decimals = 1 + else: + return None + + orig = normalize_original(orig) + if orig is not None: + settings.ensure_device_original(dev_key, orig[0], orig[1]) + return {"label": label, "rng": rng, "value": float(value), + "auto": bool(auto), "decimals": decimals, "original": orig} + + +def apply_exposure(dev_key: str, entry: dict, auto: bool, value: float, + send_s80m=None) -> None: + """按设备类型下发曝光并持久化(下次开启自动应用)。 + + UVC 无曝光入口(固定自动曝光),不会进入此函数。 + S80M 的 stdin 行协议由 send_s80m(entry, auto, value) 回调提供 + (见 core.s80m_manager.S80MDeviceManager.send_exposure)。 + """ + kind = entry["kind"] + if kind == "d435": + entry["worker"].set_exposure(auto, value) + elif kind == "s80m": + if send_s80m is not None: + send_s80m(entry, auto, value) + else: + return + settings.save_device_exposure(dev_key, auto, value) diff --git a/collector/core/glove_keypoint_solver.py b/collector/core/glove_keypoint_solver.py new file mode 100644 index 0000000000000000000000000000000000000000..4241b629d75102c6842b980ac6bdbb551df321d3 --- /dev/null +++ b/collector/core/glove_keypoint_solver.py @@ -0,0 +1,236 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""手套骨架解算封装:16×BNO055 四元数 → MANO 21 关键点(米)。 + +复用手套工具包(stouch_glove_toolkit*,与 glove_devices.json 同级)的 +HandSolver:运行时懒导入,工具包目录缺失 / 导入或构造失败时 +available()=False,调用方跳过骨架列即可(触觉/IMU 录制不受影响)。 + +present_mask 近似取 valid_mask:本工程传输层不区分"物理在位"位域, +缺失传感器必为无效样本(valid=False),工具链按有效样本求解。 +""" +import json +import os +import sys +import time + +import numpy as np + +# 进程内共享的懒导入结果(首次 import scipy 链需要 1s 左右) +_HAND_SOLVER_CLS = None +_RAW_FRAME_CLS = None +_IMPORT_ERROR = None + +# 工具包标定选择器拒绝的标定类型(与 apps/gui/calibration_selector.py +# 的 discover_calibration_files 过滤口径一致) +_DIRECT_FK_KINEMATICS = {"direct_fk", "fitted_direct_fk"} +_DIRECT_FK_TOOLS = {"direct_fk_calibrate_cli", "hand_fk_fit_cli"} + + +def _calibration_ok(path: str, side: str) -> bool: + """标定文件是否可用于该手侧(载荷解析 + 过滤口径)。""" + try: + with open(path, "r", encoding="utf-8") as f: + payload = json.load(f) + except (OSError, ValueError): + return False + if str(payload.get("side") or "").lower() != side: + return False + if not isinstance(payload.get("param_inst_calib"), dict): + return False + if payload.get("kinematics") in _DIRECT_FK_KINEMATICS: + return False + return str(payload.get("tool") or "") not in _DIRECT_FK_TOOLS + + +def _calibration_ts(path: str) -> float: + """标定生成时间(payload generated_at → epoch;解析失败用文件 mtime)。""" + try: + with open(path, "r", encoding="utf-8") as f: + payload = json.load(f) + ts = payload.get("generated_at") + if ts: + from datetime import datetime + return datetime.fromisoformat(str(ts)).timestamp() + except (OSError, ValueError, TypeError, ImportError): + pass + try: + return os.path.getmtime(path) + except OSError: + return 0.0 + + +def pick_calibration(toolkit_dir: str, side: str) -> str: + """该手侧要用的标定 JSON 路径;全无可用时返回 ""。 + + 优先级(对应「连接手套后先用标定 GUI 做标定」的工作流: + GUI 每次保存带时间戳的新文件 → 该手套最新的标定自动被采用): + 1) calibration/ 下按 generated_at 最新的该侧标定(跳过 + _default 与 2d 标定 —— 口径见 calibration_selector) + 2) calibration/imu_calibration_{side}_default.json(随包默认标定) + + 注意: 标定文件只按手侧区分、不含 USB 序列号 —— 换用新手套后 + 若未重新标定,会沿用旧手套的标定(日志会标明实际采用的文件)。 + """ + cal_dir = os.path.join(toolkit_dir, "calibration") + if not os.path.isdir(cal_dir): + return "" + best, best_ts = "", 0.0 + try: + names = sorted(os.listdir(cal_dir)) + except OSError: + names = [] + for name in names: + if not name.lower().endswith(".json"): + continue + if name == f"imu_calibration_{side}_default.json": + continue + if "2d" in name.lower(): + continue + path = os.path.join(cal_dir, name) + if not _calibration_ok(path, side): + continue + ts = _calibration_ts(path) + if ts > best_ts: + best, best_ts = path, ts + if best: + return best + dflt = os.path.join(cal_dir, f"imu_calibration_{side}_default.json") + return dflt if _calibration_ok(dflt, side) else "" + + +def find_toolkit_dir() -> str: + """项目根同级的 stouch_glove_toolkit* 目录(照 device_detector 的查找模式)。""" + root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + try: + for name in sorted(os.listdir(root)): + if name.lower().startswith("stouch_glove_toolkit"): + path = os.path.join(root, name) + if os.path.isdir(path): + return path + except OSError: + pass + return "" + + +def _ensure_imported() -> str: + """确保 toolkit 模块已导入;返回错误描述(成功返回 "")。""" + global _HAND_SOLVER_CLS, _RAW_FRAME_CLS, _IMPORT_ERROR + if _HAND_SOLVER_CLS is not None: + return "" + if _IMPORT_ERROR is not None: + return _IMPORT_ERROR + toolkit_dir = find_toolkit_dir() + if not toolkit_dir: + _IMPORT_ERROR = "未找到工具包目录(项目根同级 stouch_glove_toolkit*)" + return _IMPORT_ERROR + try: + if toolkit_dir not in sys.path: + sys.path.insert(0, toolkit_dir) + from glove_sdk.interfaces.solver import HandSolver # noqa: F401 + from glove_sdk.types import RawImuFrame # noqa: F401 + _HAND_SOLVER_CLS = HandSolver + _RAW_FRAME_CLS = RawImuFrame + return "" + except Exception as exc: # 缺依赖/版本不兼容等,全部降级 + _IMPORT_ERROR = f"{type(exc).__name__}: {exc}" + return _IMPORT_ERROR + + +class GloveKeypointSolver: + """单只手套的 21 关键点解算器(GloveDataPump 在连接时创建)。 + + Args: + side: "left" / "right"(决定标定文件,见 pick_calibration:优先该 + 手套自己的标定,其次最新标定,最后随包默认标定) + on_error: 工具包不可用/初始化失败时回调一次(接主窗口日志) + on_warmup: 解算 warmup 完成时回调一次(骨架列开始有有效数据) + """ + + def __init__(self, side: str, on_error=None, on_warmup=None): + self.side = side if side in ("left", "right") else "right" + self._on_error = on_error or (lambda msg: None) + self._on_warmup = on_warmup or (lambda: None) + self._solver = None + self._warm = False + self._seq = 0 + self.calibration_name = "" # 实际采用的标定文件名(日志用) + self._load() + + # ── 初始化 ────────────────────────────────────── + + def _load(self): + err = _ensure_imported() + if err: + self._on_error(f"骨架解算不可用: {err}") + return + toolkit_dir = find_toolkit_dir() + calibration = pick_calibration(toolkit_dir, self.side) + if not calibration: + self._on_error(f"骨架解算不可用: 无 {self.side} 手标定文件") + return + self.calibration_name = os.path.basename(calibration) + geometry = os.path.join( + toolkit_dir, "assets", "hand_geometry", + "hand_measured_runtime_v1.json") + try: + self._solver = _HAND_SOLVER_CLS(self.side, calibration, geometry) + except Exception as exc: + self._solver = None + self._on_error(f"骨架解算初始化失败: {type(exc).__name__}: {exc}") + + def available(self) -> bool: + return self._solver is not None + + @property + def warmup_completed(self) -> bool: + return self._warm + + # ── 解算 ──────────────────────────────────────── + + def process(self, quats, valid, device_ts_us: int = 0): + """→ (21,3) float32 关键点(米);未就绪/未 warmup/异常返回 None。 + + Args: + quats: 64×float32 展平的 16×4 XYZW 四元数 + valid: 16×bool/float32 有效掩码(展平) + device_ts_us: 帧的设备时间戳(微秒),0 时用宿主时钟 + """ + if self._solver is None: + return None + try: + q = np.asarray(quats, dtype=np.float64).reshape(16, 4) + v = np.asarray(valid).reshape(16) > 0.5 + except ValueError: + return None + if not np.isfinite(q).all(): + return None + self._seq += 1 + host_us = time.time_ns() // 1_000 + frame = _RAW_FRAME_CLS( + sequence=self._seq, + # 无设备时间戳时用宿主时钟占位(恒等映射,避免时间轴跳变) + device_timestamp_us=int(device_ts_us) if device_ts_us else host_us, + host_timestamp_us=host_us, + quaternions_xyzw=q, + present_mask=v, + valid_mask=v, + ) + try: + kf = self._solver.process(frame) + except Exception as exc: + if self._warm: + return None + self._on_error(f"骨架解算异常: {type(exc).__name__}: {exc}") + return None + if not self._warm: + details = getattr(getattr(kf, "status", None), "details", {}) or {} + self._warm = bool(details.get("warmup_completed", False)) + if self._warm: + self._on_warmup() + if not self._warm: + return None + joints = np.asarray(kf.joints_m, dtype=np.float32) + if joints.shape != (21, 3) or not np.isfinite(joints).all(): + return None + return joints diff --git a/collector/core/glove_usb/__init__.py b/collector/core/glove_usb/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..c61fa39dadfaff608dd9b51d75617124b9e28f37 --- /dev/null +++ b/collector/core/glove_usb/__init__.py @@ -0,0 +1,22 @@ +"""Stouch STM32 手套 USB CDC 协议栈(自工具包移植的明文子集)。 + +只依赖 numpy + pyserial,无 PyArmor/许可证负担。来源: +stouch_glove_toolkit-Stouch_Glove_Toolkit-beta 的 glove_io/ + glove_sdk/ +明文模块(errors/types/usb_protocol/streams/tactile_processing), +导入路径改为 core.glove_usb.*,其余代码与上游保持一致。 +""" + +from core.glove_usb.streams import RawImuStream, SensorStream, TactileStream +from core.glove_usb.tactile_processing import TactilePreprocessor +from core.glove_usb.types import RawImuFrame, TactileFrame +from core.glove_usb.usb_protocol import ( + STM32_USB_PID, + STM32_USB_VID, + find_stm32_cdc_port, +) + +__all__ = [ + "RawImuStream", "SensorStream", "TactileStream", + "TactilePreprocessor", "RawImuFrame", "TactileFrame", + "STM32_USB_PID", "STM32_USB_VID", "find_stm32_cdc_port", +] diff --git a/collector/core/glove_usb/errors.py b/collector/core/glove_usb/errors.py new file mode 100755 index 0000000000000000000000000000000000000000..c86e0369523ed3db55453b5bee9d92a217677e7c --- /dev/null +++ b/collector/core/glove_usb/errors.py @@ -0,0 +1,53 @@ +"""Stable public exception hierarchy for the modular glove SDK.""" + + +class GloveSdkError(RuntimeError): + """Base class for all supported SDK errors.""" + + +class DeviceNotFoundError(GloveSdkError): + pass + + +class DeviceBindingError(GloveSdkError): + pass + + +class DeviceBusyError(GloveSdkError): + pass + + +class StreamError(GloveSdkError): + pass + + +class StreamTimeoutError(StreamError): + pass + + +class StreamClosedError(StreamError): + pass + + +class CalibrationError(GloveSdkError): + pass + + +class CalibrationQualityError(CalibrationError): + pass + + +class CalibrationCompatibilityError(CalibrationError): + pass + + +class RecordingError(GloveSdkError): + pass + + +class ReplayError(GloveSdkError): + pass + + +class UnsupportedPlatformError(GloveSdkError): + pass diff --git a/collector/core/glove_usb/streams.py b/collector/core/glove_usb/streams.py new file mode 100755 index 0000000000000000000000000000000000000000..9129a2ab1d1a258bf877b3f08519c4795cdcb2e2 --- /dev/null +++ b/collector/core/glove_usb/streams.py @@ -0,0 +1,385 @@ +"""Plaintext STM32 USB acquisition used by the public sensor interfaces. + +The transport only validates and decodes the firmware wire format. It does +not remap sensors, correct axes, filter orientations, calibrate a glove, or +solve hand keypoints. Those operations belong to the protected core behind +the public 21-keypoint interface. +""" + +from __future__ import annotations + +from queue import Empty, Full, Queue +import threading +import time +from typing import Callable, Iterator + +import numpy as np + +from core.glove_usb.usb_protocol import ( + STM32_USB_PID, + STM32_USB_VID, + is_supported_version, + USB_TYPE_ADC_MATRIX, + USB_TYPE_IMU_Q14, + USB_TYPE_STATUS, + UsbCdcFrameParser, + decode_adc_matrix_payload, + decode_imu_q14_payload, + find_stm32_cdc_port, + plausible_quaternion_mask, +) +from core.glove_usb.errors import StreamClosedError, StreamTimeoutError +from core.glove_usb.types import RawImuFrame, TactileFrame + + +StatusCallback = Callable[[str], None] + + +def _put_latest(queue: Queue, value) -> None: + """Put a value without allowing a slow consumer to block acquisition.""" + + while True: + try: + queue.put_nowait(value) + return + except Full: + try: + queue.get_nowait() + except Empty: + return + + +def _drain(queue: Queue, maximum: int | None = None) -> list: + values = [] + limit = None if maximum is None else max(0, int(maximum)) + while limit is None or len(values) < limit: + try: + values.append(queue.get_nowait()) + except Empty: + break + return values + + +class _UsbSensorTransport: + """One serial owner that multiplexes raw IMU and tactile frames.""" + + def __init__( + self, + serial_port: str | None, + usb_vid: int, + usb_pid: int, + imu_queue_size: int, + tactile_queue_size: int, + status_callback: StatusCallback | None, + ): + self.requested_port = serial_port + self.usb_vid = int(usb_vid) + self.usb_pid = int(usb_pid) + self.imu_queue: Queue[RawImuFrame] = Queue( + maxsize=max(2, int(imu_queue_size))) + self.tactile_queue: Queue[TactileFrame] = Queue( + maxsize=max(2, int(tactile_queue_size))) + self.status_callback = status_callback + self.stop_event = threading.Event() + self.thread: threading.Thread | None = None + self.active_port: str | None = None + self.connected = False + self.last_error: str | None = None + self.last_status: str = "idle" + self._state_lock = threading.RLock() + + def _set_status(self, value: str, error: str | None = None) -> None: + callback = None + with self._state_lock: + changed = value != self.last_status or error != self.last_error + self.last_status = value + self.last_error = error + if changed: + callback = self.status_callback + if callback is not None: + callback(value) + + def start(self) -> None: + if self.thread is not None and self.thread.is_alive(): + return + self.stop_event.clear() + self.thread = threading.Thread( + target=self._run, + name="stouch-usb-sensor", + daemon=True, + ) + self.thread.start() + + def stop(self, timeout_s: float = 3.0) -> None: + self.stop_event.set() + thread = self.thread + if thread is not None and thread.is_alive(): + thread.join(timeout=max(0.0, float(timeout_s))) + with self._state_lock: + self.connected = False + self._set_status("stopped") + + def _run(self) -> None: + try: + import serial + except ImportError as exc: + self._set_status("error", "pyserial is not installed") + return + + parser = UsbCdcFrameParser() + serial_handle = None + while not self.stop_event.is_set(): + if serial_handle is None: + try: + port = self.requested_port or find_stm32_cdc_port( + self.usb_vid, self.usb_pid) + if not port: + self._set_status( + "waiting", + f"STM32 USB CDC {self.usb_vid:04X}:{self.usb_pid:04X} not found", + ) + self.stop_event.wait(0.5) + continue + serial_handle = serial.Serial( + port, baudrate=115200, timeout=0.2) + parser.reset() + with self._state_lock: + self.active_port = str(port) + self.connected = True + self._set_status("connected", None) + except (OSError, serial.SerialException) as exc: + with self._state_lock: + self.connected = False + self._set_status("waiting", f"cannot open serial port: {exc}") + serial_handle = None + self.stop_event.wait(0.5) + continue + + try: + data = serial_handle.read(4096) + except (OSError, serial.SerialException) as exc: + self._set_status("disconnected", f"serial read failed: {exc}") + with self._state_lock: + self.connected = False + try: + serial_handle.close() + except Exception: + pass + serial_handle = None + self.stop_event.wait(0.2) + continue + + if not data: + continue + for wire_frame in parser.feed(data): + host_timestamp_us = time.time_ns() // 1_000 + if not is_supported_version(wire_frame.version): + self._set_status( + "error", + f"unsupported USB protocol version {wire_frame.version}", + ) + continue + try: + if wire_frame.message_type == USB_TYPE_IMU_Q14: + quaternions = decode_imu_q14_payload(wire_frame.payload) + present = np.asarray([ + bool(wire_frame.flags & (1 << index)) + for index in range(16) + ], dtype=bool) + plausible = plausible_quaternion_mask(quaternions) + _put_latest(self.imu_queue, RawImuFrame( + sequence=int(wire_frame.sequence), + device_timestamp_us=int(wire_frame.timestamp_us), + host_timestamp_us=int(host_timestamp_us), + quaternions_xyzw=quaternions, + present_mask=present, + valid_mask=present & plausible, + )) + elif wire_frame.message_type == USB_TYPE_ADC_MATRIX: + matrix = decode_adc_matrix_payload(wire_frame.payload) + _put_latest(self.tactile_queue, TactileFrame( + sequence=int(matrix.sequence), + timestamp_us=int(matrix.scan_time_us), + samples=matrix.samples, + processed=False, + )) + elif wire_frame.message_type == USB_TYPE_STATUS: + status = wire_frame.payload.decode( + "utf-8", errors="replace").strip() + if status: + self._set_status(f"device: {status}", None) + except ValueError as exc: + self._set_status("error", f"invalid USB payload: {exc}") + + if serial_handle is not None: + try: + serial_handle.close() + except Exception: + pass + with self._state_lock: + self.connected = False + + +class RawImuStream: + """Public physical-channel IMU stream. + + Frames are exactly the decoded Q14 values in STM32 physical channel order. + No sensor mapping, axis conversion, smoothing, calibration, or FK is + applied. Use :class:`glove_sdk.HandSolver.process` for 21-keypoint output. + """ + + def __init__( + self, + serial_port: str | None = None, + *, + usb_vid: int = STM32_USB_VID, + usb_pid: int = STM32_USB_PID, + buffer_size: int = 256, + tactile_buffer_size: int = 2048, + status_callback: StatusCallback | None = None, + _transport: _UsbSensorTransport | None = None, + ): + self._transport = _transport or _UsbSensorTransport( + serial_port, + usb_vid, + usb_pid, + buffer_size, + tactile_buffer_size, + status_callback, + ) + + def start(self) -> "RawImuStream": + self._transport.start() + return self + + def stop(self, timeout_s: float = 3.0) -> None: + self._transport.stop(timeout_s) + + close = stop + + def __enter__(self) -> "RawImuStream": + return self.start() + + def __exit__(self, *exc) -> None: + self.stop() + + @property + def connected(self) -> bool: + return self._transport.connected + + @property + def port(self) -> str | None: + return self._transport.active_port + + @property + def status(self) -> str: + return self._transport.last_status + + @property + def last_error(self) -> str | None: + return self._transport.last_error + + def read(self, timeout: float | None = None) -> RawImuFrame: + self.start() + try: + return self._transport.imu_queue.get(timeout=timeout) + except Empty as exc: + if self._transport.stop_event.is_set(): + raise StreamClosedError("raw IMU stream is closed") from exc + raise StreamTimeoutError("timed out waiting for a raw IMU frame") from exc + + def poll(self, maximum: int | None = None) -> list[RawImuFrame]: + """Return all currently buffered frames without blocking.""" + + return _drain(self._transport.imu_queue, maximum) + + def frames(self, timeout: float = 0.25) -> Iterator[RawImuFrame]: + self.start() + while not self._transport.stop_event.is_set(): + try: + yield self.read(timeout=timeout) + except StreamTimeoutError: + continue + + def tactile_stream(self) -> "TactileStream": + """Return a tactile interface sharing this stream's serial handle.""" + + return TactileStream(imu=self) + + def poll_tactile(self, maximum: int | None = None) -> list[TactileFrame]: + return _drain(self._transport.tactile_queue, maximum) + + +class TactileStream: + """Public raw 16x16 tactile stream. + + Pass ``imu=raw_stream`` to share the same USB connection. A standalone + tactile stream owns its transport and discards unconsumed IMU frames. + """ + + def __init__( + self, + imu: RawImuStream | None = None, + *, + serial_port: str | None = None, + usb_vid: int = STM32_USB_VID, + usb_pid: int = STM32_USB_PID, + buffer_size: int = 2048, + status_callback: StatusCallback | None = None, + ): + self._owner = imu is None + self._imu = imu or RawImuStream( + serial_port, + usb_vid=usb_vid, + usb_pid=usb_pid, + buffer_size=16, + tactile_buffer_size=buffer_size, + status_callback=status_callback, + ) + + def start(self) -> "TactileStream": + self._imu.start() + return self + + def stop(self, timeout_s: float = 3.0) -> None: + if self._owner: + self._imu.stop(timeout_s) + + close = stop + + def __enter__(self) -> "TactileStream": + return self.start() + + def __exit__(self, *exc) -> None: + self.stop() + + @property + def connected(self) -> bool: + return self._imu.connected + + def read(self, timeout: float | None = None) -> TactileFrame: + self.start() + try: + return self._imu._transport.tactile_queue.get(timeout=timeout) + except Empty as exc: + if self._imu._transport.stop_event.is_set(): + raise StreamClosedError("tactile stream is closed") from exc + raise StreamTimeoutError("timed out waiting for a tactile frame") from exc + + def poll(self, maximum: int | None = None) -> list[TactileFrame]: + return self._imu.poll_tactile(maximum) + + def frames(self, timeout: float = 0.25) -> Iterator[TactileFrame]: + self.start() + while not self._imu._transport.stop_event.is_set(): + try: + yield self.read(timeout=timeout) + except StreamTimeoutError: + continue + + +# Explicit name for callers that want one object for both sensor families. +SensorStream = RawImuStream + + +__all__ = ["RawImuStream", "SensorStream", "TactileStream"] diff --git a/collector/core/glove_usb/tactile_processing.py b/collector/core/glove_usb/tactile_processing.py new file mode 100755 index 0000000000000000000000000000000000000000..56f597f1171fe11c55c35f15af6b4b6861e8326e --- /dev/null +++ b/collector/core/glove_usb/tactile_processing.py @@ -0,0 +1,146 @@ +"""Denoising pipeline for raw tactile frames, shared by the demo and hand GUIs. + +This logic originally lived only in pc/tactile_hand_gui.py; the demo had its own +simplified version (a single-frame baseline plus one hard threshold), so the two +behaviors diverged. Extracted into one shared implementation so a change in one +place updates both, and they can no longer drift apart. + +Pipeline order (line-by-line consistent with the hand implementation): + + 1. Temporal smoothing history = history*α + raw*(1-α) removes frame-to-frame jitter + 2. Baseline subtraction max(0, history - baseline_map) per-cell zero level + 3. Drift removal 40th percentile > 100 → subtract 0.8x of it; keeps the noise floor down on global rises + 4. Noise gate zero below max(base_gate, min(peak*ratio, 250)) + 5. Spatial filter zero isolated cells whose 8 neighbors are all 0 and whose value is below noise_floor + +The baseline map is computed as [per-cell max over N frames + 10], which is more +conservative than the mean — the mean would fold occasional noise spikes into the signal. +""" + +import numpy as np + +MATRIX_ROWS = 16 +MATRIX_COLS = 16 + +# Cap on the dynamic gate. When the peak is large, the gate must not rise unboundedly, otherwise light presses get "drowned out" by heavy ones. +DYNAMIC_GATE_CAP = 250.0 +# Lower bound for isolated-cell detection: cells below this are noise; a strong isolated cell is a real signal +ISOLATED_NOISE_FLOOR = 180.0 +ISOLATED_BASELINE_SCALE = 2.5 + + +class TactilePreprocessor: + """Process a raw (16,16) ADC frame into a usable pressure map. + + :param base_gate: fixed noise gate (in ADC counts after baseline subtraction) + :param temporal_smooth: temporal smoothing factor α; larger is smoother but slower to react + :param dynamic_noise_ratio: dynamic gate = current peak × this value, combined with base_gate via max() + :param spatial_filter: whether to remove isolated cells + :param calibration_frames: how many frames to sample during auto zeroing + :param bypass_gates: when True, skip steps 4 and 5 (hand's --debug-view) + """ + + def __init__(self, + base_gate: float = 500.0, + temporal_smooth: float = 0.15, + dynamic_noise_ratio: float = 0.0, + spatial_filter: bool = True, + calibration_frames: int = 30, + bypass_gates: bool = False): + self.base_gate = float(base_gate) + self.temporal_smooth = float(temporal_smooth) + self.dynamic_noise_ratio = float(dynamic_noise_ratio) + self.spatial_filter = bool(spatial_filter) + self.calibration_frames = int(calibration_frames) + self.bypass_gates = bool(bypass_gates) + + self.baseline_map = np.zeros((MATRIX_ROWS, MATRIX_COLS), dtype=np.float32) + self.history_buffer: np.ndarray | None = None + self.drift_baseline_val = 0.0 + self.is_calibrating = True + self._calibration_buffer: list[np.ndarray] = [] + + # ---- Baseline ---- + + def start_calibration(self, frames: int | None = None): + """Restart zeroing. It ends automatically once frames frames have been collected; process() returns None meanwhile.""" + if frames is not None: + self.calibration_frames = int(frames) + self._calibration_buffer.clear() + self.is_calibrating = True + + def set_baseline(self, baseline_map: np.ndarray): + """Load a baseline map directly (e.g. restored from disk), skipping acquisition.""" + self.baseline_map = np.asarray(baseline_map, dtype=np.float32).reshape( + MATRIX_ROWS, MATRIX_COLS).copy() + self.is_calibrating = False + self._calibration_buffer.clear() + + @property + def calibration_progress(self) -> tuple[int, int]: + return len(self._calibration_buffer), self.calibration_frames + + # ---- Main pipeline ---- + + def process(self, raw_data: np.ndarray) -> tuple[np.ndarray | None, float]: + """→ (processed, peak); returns (None, 0.0) while zeroing is in progress.""" + raw_data = np.asarray(raw_data, dtype=np.float32).reshape(MATRIX_ROWS, MATRIX_COLS) + + if self.is_calibrating: + self._calibration_buffer.append(raw_data.copy()) + if len(self._calibration_buffer) >= self.calibration_frames: + # Per-cell max + 10, more conservative than the mean; noise spikes are not counted as signal + self.baseline_map = np.max( + np.stack(self._calibration_buffer), axis=0) + 10 + self.is_calibrating = False + self._calibration_buffer.clear() + return None, 0.0 + + # 1. Temporal smoothing + if self.history_buffer is None: + self.history_buffer = raw_data.copy() + self.history_buffer = (self.history_buffer * self.temporal_smooth + + raw_data * (1.0 - self.temporal_smooth)) + + # 2. Baseline subtraction + processed = np.maximum(0.0, self.history_buffer - self.baseline_map) + + # 3. Drift removal: when the whole frame rises together (temperature/power), the 40th percentile rises too + self.drift_baseline_val = float(np.percentile(processed, 40)) + if self.drift_baseline_val > 100: + processed = np.maximum(0.0, processed - self.drift_baseline_val * 0.8) + + if not self.bypass_gates: + # 4. Noise gate + dynamic_gate = min(processed.max() * self.dynamic_noise_ratio, DYNAMIC_GATE_CAP) + final_gate = max(self.base_gate, dynamic_gate) + processed[processed < final_gate] = 0.0 + + # 5. Isolated-cell removal. All 8 neighbors being 0 means no adjacent cell is + # pressed at the same time; a real finger contact always covers more than one cell. + if self.spatial_filter: + mask = (processed > 0).astype(np.uint8) + neighbors = _count_neighbors(mask) + noise_floor = np.maximum(self.baseline_map * ISOLATED_BASELINE_SCALE, + ISOLATED_NOISE_FLOOR) + isolated = (mask > 0) & (neighbors == 0) & (processed < noise_floor) + processed[isolated] = 0.0 + + return processed, float(processed.max()) + + +def _count_neighbors(mask: np.ndarray) -> np.ndarray: + """Count 8-neighbors, padding the border with 0. + + Equivalent to cv2.filter2D(mask, -1, 8-neighbor kernel, BORDER_CONSTANT), + but without adding an opencv dependency — the demo side (polyscope) doesn't need it. + """ + padded = np.zeros((mask.shape[0] + 2, mask.shape[1] + 2), dtype=np.int32) + padded[1:-1, 1:-1] = mask + out = np.zeros_like(mask, dtype=np.int32) + for dr in (-1, 0, 1): + for dc in (-1, 0, 1): + if dr == 0 and dc == 0: + continue + out += padded[1 + dr:1 + dr + mask.shape[0], 1 + dc:1 + dc + mask.shape[1]] + return out diff --git a/collector/core/glove_usb/types.py b/collector/core/glove_usb/types.py new file mode 100755 index 0000000000000000000000000000000000000000..6f4543f5aae82d1b4b46706c5fe63bdb4155ee65 --- /dev/null +++ b/collector/core/glove_usb/types.py @@ -0,0 +1,349 @@ +"""Versioned public data contracts used by every SDK interface.""" + +from __future__ import annotations + +from dataclasses import dataclass, field +from pathlib import Path +from typing import Any, Literal + +import numpy as np + + +Side = Literal["left", "right"] + + +def _side(value: str) -> Side: + normalized = str(value).strip().lower() + if normalized not in ("left", "right"): + raise ValueError(f"side must be left or right, got {value!r}") + return normalized # type: ignore[return-value] + + +def _array(value, shape, dtype, name): + result = np.asarray(value, dtype=dtype).reshape(shape).copy() + if not np.all(np.isfinite(result)) and result.dtype.kind == "f": + # NaN is meaningful for sensor age/tactile absence, so callers decide + # whether it is acceptable. Shape and ownership are enforced here. + pass + return result + + +@dataclass(frozen=True) +class DeviceInfo: + device: str + serial_number: str + vid: int + pid: int + location: str = "" + bound_side: Side | None = None + + +@dataclass(frozen=True) +class DeviceBindings: + left_serial: str + right_serial: str + left_port: str | None = None + right_port: str | None = None + + +@dataclass(frozen=True) +class GloveConfig: + side: Side + calibration: Path | str + serial_number: str | None = None + registry: Path | str | None = None + sample_rate_hz: int = 80 + include_tactile: bool = True + smoothing_ms: float = 35.0 + recording_root: Path | str | None = None + + def __post_init__(self): + object.__setattr__(self, "side", _side(self.side)) + object.__setattr__(self, "calibration", Path(self.calibration)) + if self.registry is not None: + object.__setattr__(self, "registry", Path(self.registry)) + if self.recording_root is not None: + object.__setattr__(self, "recording_root", Path(self.recording_root)) + if int(self.sample_rate_hz) <= 0: + raise ValueError("sample_rate_hz must be positive") + if float(self.smoothing_ms) < 0.0: + raise ValueError("smoothing_ms must not be negative") + + +@dataclass(frozen=True) +class BimanualConfig: + left: GloveConfig + right: GloveConfig + output_root: Path | str | None = None + display_separation_m: float = 0.30 + + def __post_init__(self): + if self.left.side != "left" or self.right.side != "right": + raise ValueError("BimanualConfig requires left and right GloveConfig objects") + if self.output_root is not None: + object.__setattr__(self, "output_root", Path(self.output_root)) + if float(self.display_separation_m) <= 0.0: + raise ValueError("display_separation_m must be positive") + + +@dataclass(frozen=True) +class DeviceHealth: + connected: bool + ready_imu_count: int + missing_imus: tuple[str, ...] = () + stream_fps: float = 0.0 + message: str = "" + last_error: str | None = None + + +@dataclass(frozen=True) +class BimanualHealth: + left: DeviceHealth + right: DeviceHealth + synchronization_error_ms: float | None = None + + @property + def connected(self) -> bool: + return self.left.connected and self.right.connected + + +@dataclass(frozen=True) +class HandStatus: + safety_intervened: bool = False + active_contact: str | None = None + kinematics: str = "" + details: dict[str, Any] = field(default_factory=dict) + + +@dataclass(frozen=True) +class RawImuFrame: + """One decoded STM32 IMU packet in physical channel order. + + The quaternion order is XYZW. No physical-to-hand remapping, axis + conversion, filtering, calibration, or hand-pose solving has been applied. + """ + + sequence: int + device_timestamp_us: int + host_timestamp_us: int + quaternions_xyzw: np.ndarray + present_mask: np.ndarray + valid_mask: np.ndarray + + def __post_init__(self): + object.__setattr__(self, "quaternions_xyzw", _array( + self.quaternions_xyzw, (16, 4), np.float64, + "quaternions_xyzw")) + object.__setattr__(self, "present_mask", _array( + self.present_mask, (16,), bool, "present_mask")) + object.__setattr__(self, "valid_mask", _array( + self.valid_mask, (16,), bool, "valid_mask")) + + +@dataclass(frozen=True) +class ImuFrame: + sequence: int + timestamp_us: int + quaternions_xyzw: np.ndarray + valid_mask: np.ndarray + sensor_age_s: np.ndarray + rejected_mask: np.ndarray + + def __post_init__(self): + object.__setattr__(self, "quaternions_xyzw", _array( + self.quaternions_xyzw, (16, 4), np.float64, "quaternions_xyzw")) + object.__setattr__(self, "valid_mask", _array( + self.valid_mask, (16,), bool, "valid_mask")) + object.__setattr__(self, "sensor_age_s", _array( + self.sensor_age_s, (16,), np.float32, "sensor_age_s")) + object.__setattr__(self, "rejected_mask", _array( + self.rejected_mask, (16,), bool, "rejected_mask")) + + +@dataclass(frozen=True) +class TactileFrame: + sequence: int + timestamp_us: int + samples: np.ndarray + processed: bool = False + + def __post_init__(self): + object.__setattr__(self, "samples", _array( + self.samples, (16, 16), np.float32, "samples")) + + @property + def scan_time_us(self) -> int: + """Firmware scan-time field retained as a descriptive alias.""" + + return self.timestamp_us + + +@dataclass(frozen=True) +class SolvedHandFrame: + side: Side + joints_m: np.ndarray + status: HandStatus + + def __post_init__(self): + object.__setattr__(self, "side", _side(self.side)) + object.__setattr__(self, "joints_m", _array( + self.joints_m, (21, 3), np.float32, "joints_m")) + + +@dataclass(frozen=True) +class KeypointFrame: + """Versioned output of the protected raw-IMU to 21-keypoint pipeline.""" + + side: Side + sequence: int + timestamp_us: int + joints_m: np.ndarray + imu_xyzw: np.ndarray + valid_mask: np.ndarray + sensor_age_s: np.ndarray + rejected_mask: np.ndarray + status: HandStatus + + def __post_init__(self): + object.__setattr__(self, "side", _side(self.side)) + object.__setattr__(self, "joints_m", _array( + self.joints_m, (21, 3), np.float32, "joints_m")) + object.__setattr__(self, "imu_xyzw", _array( + self.imu_xyzw, (16, 4), np.float64, "imu_xyzw")) + object.__setattr__(self, "valid_mask", _array( + self.valid_mask, (16,), bool, "valid_mask")) + object.__setattr__(self, "sensor_age_s", _array( + self.sensor_age_s, (16,), np.float32, "sensor_age_s")) + object.__setattr__(self, "rejected_mask", _array( + self.rejected_mask, (16,), bool, "rejected_mask")) + + @property + def keypoints_21_m(self) -> np.ndarray: + """Descriptive alias for :attr:`joints_m`.""" + + return self.joints_m.copy() + + +@dataclass(frozen=True) +class HandFrame: + side: Side + sequence: int + timestamp_us: int + imu_xyzw: np.ndarray + imu_valid: np.ndarray + sensor_age_s: np.ndarray + joints_raw_m: np.ndarray + joints_smoothed_m: np.ndarray + tactile: np.ndarray | None + status: HandStatus + raw_imu_xyzw: np.ndarray | None = None + raw_imu_present: np.ndarray | None = None + raw_imu_valid: np.ndarray | None = None + raw_device_timestamp_us: int | None = None + tactile_raw: np.ndarray | None = None + + def __post_init__(self): + object.__setattr__(self, "side", _side(self.side)) + object.__setattr__(self, "imu_xyzw", _array( + self.imu_xyzw, (16, 4), np.float64, "imu_xyzw")) + object.__setattr__(self, "imu_valid", _array( + self.imu_valid, (16,), bool, "imu_valid")) + object.__setattr__(self, "sensor_age_s", _array( + self.sensor_age_s, (16,), np.float32, "sensor_age_s")) + object.__setattr__(self, "joints_raw_m", _array( + self.joints_raw_m, (21, 3), np.float32, "joints_raw_m")) + object.__setattr__(self, "joints_smoothed_m", _array( + self.joints_smoothed_m, (21, 3), np.float32, "joints_smoothed_m")) + if self.tactile is not None: + object.__setattr__(self, "tactile", _array( + self.tactile, (16, 16), np.float32, "tactile")) + if self.raw_imu_xyzw is not None: + object.__setattr__(self, "raw_imu_xyzw", _array( + self.raw_imu_xyzw, (16, 4), np.float64, "raw_imu_xyzw")) + if self.raw_imu_present is not None: + object.__setattr__(self, "raw_imu_present", _array( + self.raw_imu_present, (16,), bool, "raw_imu_present")) + if self.raw_imu_valid is not None: + object.__setattr__(self, "raw_imu_valid", _array( + self.raw_imu_valid, (16,), bool, "raw_imu_valid")) + if self.tactile_raw is not None: + object.__setattr__(self, "tactile_raw", _array( + self.tactile_raw, (16, 16), np.float32, "tactile_raw")) + + +@dataclass(frozen=True) +class BimanualFrame: + sequence: int + timestamp_us: int + left: HandFrame + right: HandFrame + synchronization_error_ms: float + + +@dataclass(frozen=True) +class CalibrationStep: + id: str + title: str + action: Literal["capture", "compute"] + stage: Literal["root", "installation", "contact"] + + +@dataclass(frozen=True) +class CalibrationStepResult: + step_id: str + ok: bool + message: str + + +@dataclass(frozen=True) +class CalibrationProgress: + current_index: int + total_steps: int + completed_step_ids: tuple[str, ...] + complete: bool + + +@dataclass(frozen=True) +class RecordingStatus: + state: Literal["disabled", "idle", "recording", "saved"] + take_index: int + frame_count: int + output_path: Path | None = None + + +@dataclass(frozen=True) +class RecordingResult: + parquet_path: Path | None + session_path: Path | None + take_index: int + frame_count: int + duration_s: float + sample_fps: float + + +@dataclass(frozen=True) +class RecordingInfo: + parquet_path: Path + session_path: Path | None + mode: str + sides: tuple[Side, ...] + frame_count: int + sample_fps: float + has_imu: bool + has_tactile: bool + tactile_valid_frames: int = 0 + tactile_nonzero_samples: int = 0 + has_raw_imu: bool = False + has_raw_tactile: bool = False + + @property + def has_tactile_signal(self) -> bool: + return self.tactile_nonzero_samples > 0 + + +@dataclass(frozen=True) +class ReplayResult: + input_path: Path + output_path: Path + frame_count: int + sample_fps: float diff --git a/collector/core/glove_usb/usb_protocol.py b/collector/core/glove_usb/usb_protocol.py new file mode 100755 index 0000000000000000000000000000000000000000..1a32576093084e749a47cdff6fb8d6ff83e609a0 --- /dev/null +++ b/collector/core/glove_usb/usb_protocol.py @@ -0,0 +1,344 @@ +"""STM32 glove USB CDC framing and IMU payload decoding. + +The firmware multiplexes status, IMU and pressure-matrix messages on one CDC +byte stream. This module deliberately owns only the wire protocol; serial-port +opening and MANO processing remain in :mod:`modules.hand.hand`. +""" + +from __future__ import annotations + +from dataclasses import dataclass +import struct +from typing import Iterable + +import numpy as np + + +STM32_USB_VID = 0x0483 +STM32_USB_PID = 0x5740 + +USB_MAGIC = b"\xA5\x5A" +# Firmware v1.2.2 is the first release described by +# ``流程图与数据帧格式_v1.2.2.pdf``. It changed the header to carry the +# complete ``major.minor.patch`` version and moved the payload length/flags to +# offsets 14/16. Later firmware keeps this wire format, so the comparison is +# deliberately semantic rather than a hard-coded version string. +USB_NEW_FORMAT_FROM = (1, 2, 2) +USB_HEADER_SIZE = 18 +USB_CRC_SIZE = 2 +USB_MAX_PAYLOAD = 1100 + +USB_TYPE_STATUS = 0x01 +USB_TYPE_IMU_Q14 = 0x02 +USB_TYPE_ADC_MATRIX = 0x03 + +TOTAL_IMU_COUNT = 16 +IMU_COMPONENT_COUNT = 4 +IMU_Q14_PAYLOAD_SIZE = TOTAL_IMU_COUNT * IMU_COMPONENT_COUNT * 2 +Q14_SCALE = 1.0 / 16384.0 +ADC_MATRIX_ROWS = 16 +ADC_MATRIX_COLS = 16 +ADC_MATRIX_META_SIZE = 12 +ADC_MATRIX_PAYLOAD_SIZE = ( + ADC_MATRIX_META_SIZE + ADC_MATRIX_ROWS * ADC_MATRIX_COLS * 2) + +def parse_firmware_version(version: str | tuple[int, ...] | list[int]) -> tuple[int, ...] | None: + """Return numeric firmware components, or ``None`` for malformed input.""" + + try: + if isinstance(version, str): + components = tuple(int(part.strip()) for part in version.split(".")) + else: + components = tuple(int(part) for part in version) + except (TypeError, ValueError): + return None + return components if len(components) == 3 and all(value >= 0 for value in components) else None + + +def is_supported_version(version: str | tuple[int, ...] | list[int]) -> bool: + """Return whether ``version`` uses the current 18-byte-header format. + + The PDF documents v1.2.2 itself as the current format. Accepting it as + well as all newer versions is important when a board is flashed with the + documented release; future patch/minor releases remain compatible. + """ + + components = parse_firmware_version(version) + return components is not None and components >= USB_NEW_FORMAT_FROM + + +# The v1.2.2 firmware emits joint order (wrist, thumb, index, middle, ring, +# pinky). Keep the v1.0 physical-channel maps here so old JSON configurations +# continue to work: ``channel_to_hand_for_firmware`` composes them with the +# firmware's output permutation. New configurations use the resulting map +# directly, which is the same for both hand sides. +LEGACY_CHANNEL_TO_HAND_BY_SIDE = { + "left": ( + 14, 13, 8, 15, + 2, 7, 9, 1, + 4, 3, 11, 0, + 5, 12, 10, 6, + ), + "right": ( + 8, 7, 14, 9, + 11, 13, 15, 10, + 4, 12, 2, 0, + 5, 3, 1, 6, + ), +} + +# USB output slot -> pre-v1.2.2 firmware slot. These are the ORDER_L/R +# tables shown in section A.3 of the supplied PDF. +FIRMWARE_OUTPUT_ORDER_BY_SIDE = { + "left": (11, 1, 0, 3, 7, 4, 9, 8, 12, 15, 14, 10, 13, 5, 2, 6), + "right": (11, 5, 2, 6, 14, 10, 13, 8, 12, 15, 7, 4, 9, 1, 0, 3), +} + +NEW_FIRMWARE_CHANNEL_TO_HAND_BY_SIDE = { + side: tuple( + LEGACY_CHANNEL_TO_HAND_BY_SIDE[side][source] + for source in FIRMWARE_OUTPUT_ORDER_BY_SIDE[side] + ) + for side in FIRMWARE_OUTPUT_ORDER_BY_SIDE +} + +DEFAULT_CHANNEL_TO_HAND = NEW_FIRMWARE_CHANNEL_TO_HAND_BY_SIDE["right"] + + +@dataclass(frozen=True) +class UsbCdcFrame: + """One CRC-validated frame extracted from the CDC byte stream.""" + + version: str + message_type: int + sequence: int + timestamp_us: int + flags: int + payload: bytes + + @property + def firmware_version(self) -> str: + """Compatibility alias used by older SDK callers.""" + + return self.version + + +@dataclass(frozen=True) +class UsbAdcMatrixFrame: + """Decoded STM32 16x16 tactile matrix payload.""" + + sequence: int + scan_time_us: int + samples: np.ndarray + + +def crc16_ccitt_false(data: bytes | bytearray | memoryview) -> int: + """Return CRC16-CCITT-FALSE (poly 0x1021, init 0xFFFF).""" + + crc = 0xFFFF + for value in data: + crc ^= int(value) << 8 + for _ in range(8): + if crc & 0x8000: + crc = ((crc << 1) ^ 0x1021) & 0xFFFF + else: + crc = (crc << 1) & 0xFFFF + return crc + + +class UsbCdcFrameParser: + """Incrementally recover framed messages from arbitrary serial chunks.""" + + def __init__(self): + self.buffer = bytearray() + self.discarded_bytes = 0 + self.crc_errors = 0 + self.length_errors = 0 + + def reset(self) -> None: + self.buffer.clear() + + def feed(self, data: bytes | bytearray | memoryview) -> list[UsbCdcFrame]: + if data: + self.buffer.extend(data) + + frames: list[UsbCdcFrame] = [] + while True: + magic_index = self.buffer.find(USB_MAGIC) + if magic_index < 0: + # Keep a trailing 0xA5 because it may be the first byte of a + # magic sequence split across two serial reads. + keep = 1 if self.buffer.endswith(USB_MAGIC[:1]) else 0 + discard = len(self.buffer) - keep + if discard > 0: + del self.buffer[:discard] + self.discarded_bytes += discard + break + + if magic_index > 0: + del self.buffer[:magic_index] + self.discarded_bytes += magic_index + + if len(self.buffer) < USB_HEADER_SIZE: + break + + payload_length = int.from_bytes(self.buffer[14:16], "little") + if payload_length > USB_MAX_PAYLOAD: + del self.buffer[0] + self.discarded_bytes += 1 + self.length_errors += 1 + continue + + total_length = USB_HEADER_SIZE + payload_length + USB_CRC_SIZE + if len(self.buffer) < total_length: + break + + crc_offset = USB_HEADER_SIZE + payload_length + expected_crc = int.from_bytes( + self.buffer[crc_offset:crc_offset + USB_CRC_SIZE], "little") + actual_crc = crc16_ccitt_false(self.buffer[:crc_offset]) + if actual_crc != expected_crc: + del self.buffer[0] + self.discarded_bytes += 1 + self.crc_errors += 1 + continue + + frames.append(UsbCdcFrame( + version=".".join( + str(value) for value in self.buffer[2:5]), + message_type=int(self.buffer[5]), + sequence=int.from_bytes(self.buffer[6:10], "little"), + timestamp_us=int.from_bytes(self.buffer[10:14], "little"), + flags=int.from_bytes(self.buffer[16:18], "little"), + payload=bytes(self.buffer[USB_HEADER_SIZE:crc_offset]), + )) + del self.buffer[:total_length] + + return frames + + +def validate_channel_to_hand(mapping: Iterable[int]) -> tuple[int, ...]: + """Validate and freeze a physical-channel to MANO-joint permutation.""" + + result = tuple(int(value) for value in mapping) + if len(result) != TOTAL_IMU_COUNT: + raise ValueError("channel_to_hand must contain exactly 16 entries") + if sorted(result) != list(range(TOTAL_IMU_COUNT)): + raise ValueError("channel_to_hand must be a permutation of 0..15") + return result + + +def channel_to_hand_for_firmware(mapping: Iterable[int]) -> tuple[int, ...]: + """Convert a persisted v1.0 map to the v1.2.2 joint-order map. + + A map already written for the new payload is returned unchanged. This + lets users upgrade the SDK without invalidating existing calibration JSON. + """ + + normalized = validate_channel_to_hand(mapping) + for side, legacy_mapping in LEGACY_CHANNEL_TO_HAND_BY_SIDE.items(): + if normalized == legacy_mapping: + return NEW_FIRMWARE_CHANNEL_TO_HAND_BY_SIDE[side] + return normalized + + +def decode_imu_q14_payload(payload: bytes) -> np.ndarray: + """Decode the fixed 128-byte payload into SciPy-order XYZW quaternions.""" + + if len(payload) != IMU_Q14_PAYLOAD_SIZE: + raise ValueError( + f"STM32 IMU payload must be {IMU_Q14_PAYLOAD_SIZE} bytes, " + f"got {len(payload)}") + + raw = np.asarray( + struct.unpack("<64h", payload), dtype=np.float64 + ).reshape(TOTAL_IMU_COUNT, IMU_COMPONENT_COUNT) + wxyz = raw * Q14_SCALE + return wxyz[:, [1, 2, 3, 0]] + + +def decode_adc_matrix_payload(payload: bytes) -> UsbAdcMatrixFrame: + """Decode the STM32 12-byte metadata plus 256 little-endian ADC values.""" + + if len(payload) != ADC_MATRIX_PAYLOAD_SIZE: + raise ValueError( + f"STM32 ADC matrix payload must be {ADC_MATRIX_PAYLOAD_SIZE} bytes, " + f"got {len(payload)}") + rows, cols, adc_bits, order = payload[:4] + if (rows, cols, adc_bits, order) != ( + ADC_MATRIX_ROWS, ADC_MATRIX_COLS, 12, 0): + raise ValueError( + "unsupported STM32 ADC matrix metadata: " + f"rows={rows}, cols={cols}, bits={adc_bits}, order={order}") + sequence = int.from_bytes(payload[4:8], "little") + scan_time_us = int.from_bytes(payload[8:12], "little") + samples = np.frombuffer( + payload, dtype=" np.ndarray: + """Apply the same broad norm gate used by the ESP runtime.""" + + quaternions = np.asarray(quaternions_xyzw, dtype=float) + if quaternions.shape != (TOTAL_IMU_COUNT, IMU_COMPONENT_COUNT): + raise ValueError("quaternions must have shape (16, 4)") + norm_squared = np.sum(quaternions * quaternions, axis=1) + return ( + np.all(np.isfinite(quaternions), axis=1) + & (norm_squared > 0.25) + & (norm_squared < 2.25) + ) + + +def remap_physical_to_hand( + quaternions_xyzw: np.ndarray, + physical_valid_mask: int, + channel_to_hand: Iterable[int] = DEFAULT_CHANNEL_TO_HAND, +) -> tuple[np.ndarray, np.ndarray]: + """Reorder firmware joint-order slots and valid bits into MANO joint order.""" + + quaternions = np.asarray(quaternions_xyzw, dtype=float) + if quaternions.shape != (TOTAL_IMU_COUNT, IMU_COMPONENT_COUNT): + raise ValueError("quaternions must have shape (16, 4)") + mapping = channel_to_hand_for_firmware(channel_to_hand) + + mano_quaternions = np.tile( + np.array([0.0, 0.0, 0.0, 1.0]), (TOTAL_IMU_COUNT, 1)) + mano_valid = np.zeros(TOTAL_IMU_COUNT, dtype=bool) + plausible = plausible_quaternion_mask(quaternions) + + for physical_channel, mano_joint in enumerate(mapping): + mano_quaternions[mano_joint] = quaternions[physical_channel] + mano_valid[mano_joint] = bool( + physical_valid_mask & (1 << physical_channel)) and plausible[physical_channel] + + return mano_quaternions, mano_valid + + +def find_stm32_cdc_port(vid: int = STM32_USB_VID, pid: int = STM32_USB_PID) -> str | None: + """Return the first matching STM32 CDC port, or ``None`` when absent.""" + + import serial.tools.list_ports + + for port in serial.tools.list_ports.comports(): + if port.vid == int(vid) and port.pid == int(pid): + return port.device + return None + + +def list_serial_ports() -> list[tuple[str, str, int | None, int | None]]: + """Return serial-port details for CLI diagnostics.""" + + import serial.tools.list_ports + + return [ + (port.device, port.description, port.vid, port.pid) + for port in serial.tools.list_ports.comports() + ] diff --git a/collector/core/hand_processor.py b/collector/core/hand_processor.py new file mode 100755 index 0000000000000000000000000000000000000000..209c707aee3bae6c6ddecca6e35125ef8fc26958 --- /dev/null +++ b/collector/core/hand_processor.py @@ -0,0 +1,87 @@ +""" +录制会话手部关键点后处理 —— Qt 薄封装,核心逻辑在 core.hand_tracking。 +""" + +from __future__ import annotations +import threading +from typing import Optional + +from PyQt5.QtCore import QObject, pyqtSignal + +from core.hand_tracking import process_session as _ht_process_session + + +class SessionHandProcessor(QObject): + """对已录制的会话视频逐帧跑手部关键点推理,结果写入 parquet。 + + 信号 + ---- + progress(int, int) — (当前帧, 总帧数) + finished(str, str) — (session_path, error_msg) + error_msg 为空表示成功 + status_changed(str) — 状态变化通知 + """ + + progress = pyqtSignal(int, int) + finished = pyqtSignal(str, str) + status_changed = pyqtSignal(str) + + def __init__(self, parent=None): + super().__init__(parent) + self._running = False + self._thread: Optional[threading.Thread] = None + + def process_session(self, session_path: str, detector: str = "", + det_device: str = "cuda", pose_device: str = "cuda", + mode: str = ""): + """启动后台处理一个录制会话。""" + if self._running: + return + + self._track_mode = mode + det_path = detector + self._det_device = det_device + self._pose_device = pose_device + + self._running = True + self._thread = threading.Thread( + target=self._process, args=(session_path, det_path), + daemon=True, name="hand-processor", + ) + self._thread.start() + + def cancel(self): + """取消当前处理任务。""" + self._running = False + + # ── 后台 ────────────────────────────────────────── + + def _process(self, session_path: str, det_path: str): + def _progress(cur, total): + self.progress.emit(cur, total) + + def _status(msg): + self.status_changed.emit(msg) + + def _cancelled(): + return not self._running + + result = _ht_process_session( + session_path=session_path, + mode=getattr(self, '_track_mode', ''), + detector=det_path or '', + det_device=getattr(self, '_det_device', 'cuda'), + pose_device=getattr(self, '_pose_device', 'cuda'), + progress_cb=_progress, + status_cb=_status, + cancel_check=_cancelled, + ) + + if not self._running: + self.status_changed.emit("cancelled") + elif result.get("success"): + self.finished.emit(session_path, "") + else: + self.finished.emit(session_path, result.get("error", "未知错误")) + + self._running = False diff --git a/collector/core/hand_tracking.py b/collector/core/hand_tracking.py new file mode 100644 index 0000000000000000000000000000000000000000..0bd6989efc6723d51923f650f0e9ef77c8f6afec --- /dev/null +++ b/collector/core/hand_tracking.py @@ -0,0 +1,807 @@ +""" +手部关键点后处理独立模块 —— 零 Qt 依赖,纯函数式 API。 + +支持两种追踪模式: + - "glove": YOLO 检测黑色手套 + RTMPose 关键点 (仅 2D) + - "bare": MediaPipe 裸手追踪 (2D + 3D world_landmarks) + +bare 模式下额外保存 3D 世界坐标到 keypoints/hand_pose_3d/, +供下游 3D 可视化与数据集导出使用。 + +用法: + from core.hand_tracking import process_session, load_hand_kpts, draw_kpts_overlay + + result = process_session("/path/to/session", mode="bare") + kpts = load_hand_kpts("/path/to/session") +""" + +from __future__ import annotations +import os +import sys +import json +import time +from typing import Optional, Callable + +import numpy as np +import cv2 +import pyarrow as pa +import pyarrow.parquet as pq + +from config import settings +from core.helpers import ( + hand_kpts_parquet_path, hand_3d_parquet_path, auto_labels_parquet_path, + data_parquet_path, video_mp4_path, detect_session_format, + egodata_video_path, egodata_metadata_path, + _session_kpts_hand_kpts_path, _session_kpts_hand_3d_path, + _session_kpts_auto_labels_path, + _legacy_hand_kpts_path, _legacy_hand_3d_path, _legacy_auto_labels_path, +) + +# ── 将本地 tools/hand_detection 目录加入 sys.path ──────────── +_HAND_DET_DIR = os.path.normpath( + os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + "tools", "hand_detection")) +_HAND_DET_DIR = os.path.abspath(_HAND_DET_DIR) +if _HAND_DET_DIR not in sys.path and os.path.isdir(_HAND_DET_DIR): + sys.path.insert(0, _HAND_DET_DIR) + +# ── 常量 ──────────────────────────────────────────────── + +PER_HAND_DIM = 21 * 2 + 4 # 46: 21点×2坐标 + 4框坐标 +MAX_HANDS = 2 +TOTAL_DIM = PER_HAND_DIM * MAX_HANDS # 92 + +PER_HAND_3D_DIM = 21 * 3 # 63: xyz per landmark + +# ── Parquet Schema ────────────────────────────────────── + +_HAND_KPTS_SCHEMA = pa.schema([ + ("frame_index", pa.int32()), + ("num_hands", pa.int32()), + ("hand_data", pa.list_(pa.float32(), TOTAL_DIM)), + ("track_ids", pa.list_(pa.int32(), MAX_HANDS)), +]) + +_HAND_3D_SCHEMA = pa.schema([ + ("frame_index", pa.int32()), + ("hand_0_present", pa.bool_()), + ("hand_0_landmarks_3d", pa.list_(pa.float32(), PER_HAND_3D_DIM)), + ("hand_0_label", pa.string()), + ("hand_1_present", pa.bool_()), + ("hand_1_landmarks_3d", pa.list_(pa.float32(), PER_HAND_3D_DIM)), + ("hand_1_label", pa.string()), +]) + +_AUTO_LABELS_SCHEMA = pa.schema([ + ("frame_index", pa.int32()), + ("hand_0_gesture", pa.string()), + ("hand_0_extended", pa.list_(pa.string())), + ("hand_0_extended_count", pa.int32()), + ("hand_0_fist", pa.bool_()), + ("hand_0_pinch", pa.bool_()), + ("hand_0_center_x", pa.float32()), + ("hand_0_center_y", pa.float32()), + ("hand_0_motion", pa.float32()), + ("hand_1_gesture", pa.string()), + ("hand_1_extended", pa.list_(pa.string())), + ("hand_1_extended_count", pa.int32()), + ("hand_1_fist", pa.bool_()), + ("hand_1_pinch", pa.bool_()), + ("hand_1_motion", pa.float32()), + ("two_hand_distance", pa.float32()), + ("contact", pa.string()), +]) + +# ── 延迟导入(重型依赖仅处理时加载) ─────────────────── + +_HandPipeline = None +_hand_common = None + + +def _lazy_import_pipeline(): + """导入 HandPipeline(含 ultralytics/torch/CUDA)。""" + global _HandPipeline + if _HandPipeline is None: + try: + from hand_pipeline import HandPipeline as _HP + _HandPipeline = _HP + except ImportError as e: + raise ImportError( + f"无法导入 glove 模式依赖 (hand_pipeline): {e}\n" + "请确保已安装: pip install ultralytics torch rtmlib" + ) from e + return _HandPipeline + + +def _lazy_import_common(): + """导入 hand_common(纯 numpy/cv2)。""" + global _hand_common + if _hand_common is None: + try: + from hand_common import draw_hand, compute_joint_angles, count_extended_fingers, FINGERS + _hand_common = { + "draw_hand": draw_hand, + "compute_joint_angles": compute_joint_angles, + "count_extended_fingers": count_extended_fingers, + "FINGERS": FINGERS, + } + except ImportError as e: + raise ImportError( + f"无法导入 hand_common: {e}\n" + "请确保 tools/hand_detection/ 目录存在且包含 hand_common.py" + ) from e + return _hand_common + + +# ═══════════════════════════════════════════════════════════ +# 数据打包 +# ═══════════════════════════════════════════════════════════ + +def _pack_hand_data(boxes, kpts, track_ids) -> np.ndarray: + """将一帧手部结果打包为固定长度 float32 数组 (TOTAL_DIM,)。""" + arr = np.zeros(TOTAL_DIM, dtype=np.float32) + num = min(len(boxes), MAX_HANDS) + for h in range(num): + off = h * PER_HAND_DIM + pts = kpts[h] if kpts is not None and h < len(kpts) else np.zeros((21, 2)) + for j in range(min(21, len(pts))): + arr[off + j * 2] = float(pts[j][0]) + arr[off + j * 2 + 1] = float(pts[j][1]) + box = boxes[h] if h < len(boxes) else [0, 0, 0, 0] + for j in range(4): + arr[off + 42 + j] = float(box[j]) + return arr + + +def _unpack_hand_data(arr: np.ndarray) -> tuple: + """从打包数组恢复 (boxes, kpts, num_hands)。""" + num = 0; boxes = []; kpts = [] + for h in range(MAX_HANDS): + off = h * PER_HAND_DIM + box = [float(arr[off + 42 + j]) for j in range(4)] + if box[2] > 1 and box[3] > 1: + pts = np.array([[float(arr[off + j * 2]), + float(arr[off + j * 2 + 1])] for j in range(21)], + dtype=np.float32) + boxes.append(box); kpts.append(pts); num += 1 + return boxes, kpts, num + + +def _pack_hand_3d_data(world_landmarks_list) -> np.ndarray: + """将单帧 3D 数据打包为 (PER_HAND_3D_DIM,) float32。""" + arr = np.zeros(PER_HAND_3D_DIM, dtype=np.float32) + wl = world_landmarks_list[0] if world_landmarks_list else None + if wl is not None: + flat = np.array(wl, dtype=np.float32).ravel()[:PER_HAND_3D_DIM] + arr[:len(flat)] = flat + return arr + + +# ═══════════════════════════════════════════════════════════ +# 关键点叠加绘制 +# ═══════════════════════════════════════════════════════════ + +def draw_kpts_overlay(frame: np.ndarray, data: np.ndarray, + track_ids: list = None) -> np.ndarray: + """在 BGR 帧上叠加手部关键点。""" + hc = _lazy_import_common() + overlay = frame.copy() + boxes, kpts, num = _unpack_hand_data(data) + if num == 0: + return overlay + for i, (box, pts) in enumerate(zip(boxes, kpts)): + x1, y1, x2, y2 = [int(v) for v in box] + cv2.rectangle(overlay, (x1, y1), (x2, y2), (0, 220, 220), 2, cv2.LINE_AA) + tid = track_ids[i] if track_ids and i < len(track_ids) else i + label = f"Hand #{tid}" + (tw, th), _ = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 2) + cv2.rectangle(overlay, (x1, y1 - th - 6), (x1 + tw + 6, y1), (0, 200, 200), -1) + cv2.putText(overlay, label, (x1 + 3, y1 - 3), + cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 2, cv2.LINE_AA) + hc["draw_hand"](overlay, pts, angles=None, show_angles=False, + kpt_scores=None, thr=0.0) + try: + angles = hc["compute_joint_angles"](pts) + extended = hc["count_extended_fingers"](angles) + ext_text = "open: " + ",".join(extended) if extended else "fist" + cv2.putText(overlay, ext_text, (x1, y2 + 18), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 255, 120), 1, cv2.LINE_AA) + except Exception: + pass + return overlay + + +# ═══════════════════════════════════════════════════════════ +# 手势分类 +# ═══════════════════════════════════════════════════════════ + +PINCH_THRESH = 30.0 +TWO_HAND_TOUCH_THRESH = 80.0 + + +def classify_gesture(extended: list, thumb_tip_pt: np.ndarray, + index_tip_pt: np.ndarray) -> dict: + """根据伸直手指 + 指尖距离分类手势。""" + n = len(extended) + pinch = (np.linalg.norm(thumb_tip_pt - index_tip_pt) < PINCH_THRESH) + if n == 0: + gesture, fist = "fist", True + elif n >= 4: + gesture, fist = ("open" if not pinch else "ok"), False + elif n == 1: + if "Index" in extended: gesture, fist = "point", False + elif "Thumb" in extended: gesture, fist = "hook", False + else: gesture, fist = "unknown", False + elif pinch and n == 3: + gesture, fist = "ok", False + elif pinch: + gesture, fist = "pinch", False + elif n in (2, 3): + gesture, fist = "grab", False + else: + gesture, fist = "unknown", False + return {"gesture": gesture, "pinch": bool(pinch), "fist": fist, + "extended_count": n} + + +def _thumb_tip(kpts: np.ndarray) -> np.ndarray: + return kpts[4] if len(kpts) > 4 else np.zeros(2) + + +def _index_tip(kpts: np.ndarray) -> np.ndarray: + return kpts[8] if len(kpts) > 8 else np.zeros(2) + + +def _hand_center(kpts: np.ndarray) -> np.ndarray: + wrist = kpts[0] if len(kpts) > 0 else np.zeros(2) + middle_mcp = kpts[9] if len(kpts) > 9 else np.zeros(2) + return (wrist + middle_mcp) / 2.0 + + +def _compute_contact(motion_0: float, motion_1: float, + sensors: Optional[dict]) -> str: + max_p = 0.0 + if sensors: + for arr in sensors.values(): + if arr is not None and len(arr) > 0: + max_p = max(max_p, float(arr.max())) + motion = max(motion_0, motion_1) if motion_0 >= 0 else motion_0 + if max_p > 500 and motion > 15: + return "grasping" + elif max_p > 500: + return "holding" + elif motion > 10: + return "reaching" + elif max_p > 0: + return "resting" + return "none" + + +# ═══════════════════════════════════════════════════════════ +# 主入口: 批量处理一个会话 +# ═══════════════════════════════════════════════════════════ + +def process_session(session_path: str, + mode: str = "", + detector: str = "", + det_device: str = "cuda", + pose_device: str = "cuda", + progress_cb: Optional[Callable[[int, int], None]] = None, + status_cb: Optional[Callable[[str], None]] = None, + cancel_check: Optional[Callable[[], bool]] = None, + ) -> dict: + """对已录制会话逐帧提取手部关键点,写入 parquet。 + + bare 模式额外保存 3D world_landmarks 到独立 parquet。 + + Returns: + {"success": True, "frames": N, "elapsed": s, "fps": float, + "mode": str, "session_path": str} + 或 {"success": False, "error": msg} + """ + if not os.path.isdir(session_path): + return {"success": False, "error": f"会话目录不存在: {session_path}"} + + mode = mode or settings.HAND_TRACK_MODE + det_path = detector or settings.HAND_DET_MODEL + det_device = det_device or settings.HAND_DET_DEVICE + pose_device = pose_device or settings.HAND_POSE_DEVICE + + out_path = hand_kpts_parquet_path(session_path) + out_3d_path = hand_3d_parquet_path(session_path) + t_start = time.perf_counter() + + try: + # ── 加载管线 ────────────────────────────────── + _is_mediapipe = False + if mode == "bare": + if status_cb: status_cb("loading (MediaPipe bare hand)") + _mp_model_src = settings.HAND_MEDIAPIPE_MODEL + _mp_cache = os.path.join(os.path.expanduser("~"), ".cache", + "hand_landmarker.task") + if not os.path.isfile(_mp_cache) or \ + os.path.getsize(_mp_cache) != os.path.getsize(_mp_model_src): + os.makedirs(os.path.dirname(_mp_cache), exist_ok=True) + import shutil + shutil.copy2(_mp_model_src, _mp_cache) + from hand_pipeline_mediapipe import MediaPipeHandPipeline + pipeline = MediaPipeHandPipeline( + model_path=_mp_cache, num_hands=MAX_HANDS, mirror=False) + _is_mediapipe = True + else: + _lazy_import_pipeline() + try: + import torch + if not torch.cuda.is_available(): + if det_device == "cuda": det_device = "cpu" + if pose_device == "cuda": pose_device = "cpu" + except Exception: + det_device = "cpu"; pose_device = "cpu" + pipeline = _HandPipeline( + detector=det_path, det_device=det_device, + pose_device=pose_device, max_hands=MAX_HANDS) + _is_mediapipe = False + + if status_cb: status_cb("processing") + + # ── 找视频 ──────────────────────────────────── + fmt = detect_session_format(session_path) + cameras = {} + if fmt == "egodata": + meta_path = egodata_metadata_path(session_path) + else: + meta_path = os.path.join(session_path, "meta", "info.json") + if os.path.isfile(meta_path): + with open(meta_path, "r", encoding="utf-8") as f: + cameras = json.load(f).get("cameras", {}) + + # 为 EgoData 格式构造视频路径(cameras 元数据不含 "video" 键) + if fmt == "egodata" and cameras: + for cam_name in list(cameras.keys()): + # 优先 EgoData 标准路径, 回退 flat videos/.mp4 + for vp in [egodata_video_path(session_path, cam_name), + os.path.join(session_path, "videos", f"{cam_name}.mp4")]: + if os.path.isfile(vp): + cameras[cam_name]["video"] = vp + break + + if not cameras: + vdir = os.path.join(session_path, "videos") + if os.path.isdir(vdir): + for cam_name in sorted(os.listdir(vdir)): + if fmt == "egodata": + mp4 = egodata_video_path(session_path, cam_name) + flat = os.path.join(session_path, "videos", f"{cam_name}.mp4") + if os.path.isfile(mp4): + cameras[cam_name] = {"video": mp4} + elif cam_name.endswith(".mp4") and os.path.isfile(flat): + base = cam_name[:-4] + cameras[base] = {"video": flat} + else: + mp4 = video_mp4_path(session_path, cam_name) + if os.path.isfile(mp4): + cameras[cam_name] = {"video": mp4} + else: + old = os.path.join(vdir, cam_name, "chunk_000000.mp4") + if os.path.isfile(old): + cameras[cam_name] = {"video": old} + + if not cameras: + return {"success": False, "error": "未找到视频文件"} + + # 只保留有视频文件的 RGB 摄像机(排除 depth) + _rgb_cameras = {} + for cam_id, cam_info in cameras.items(): + if isinstance(cam_info, dict) and cam_info.get("type") == "depth": + continue + if cam_id.lower().endswith("_depth"): + continue + vp = cam_info.get("video", "") + if os.path.isfile(vp): + _rgb_cameras[cam_id] = cam_info + cameras = _rgb_cameras + + if not cameras: + return {"success": False, "error": "未找到可播放的视频文件"} + + first_cam = list(cameras.keys())[0] + video_path = cameras[first_cam].get("video", "") + + cap = cv2.VideoCapture(video_path) + if not cap.isOpened(): + return {"success": False, "error": f"无法打开视频: {video_path}"} + + total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) + if total_frames <= 0: + total_frames = 1 + + # ── 逐帧处理 ────────────────────────────────── + rows = [] + rows_3d = [] + frame_idx = 0 + + while True: + if cancel_check and cancel_check(): + cap.release() + return {"success": False, "error": "cancelled"} + + ok, frame = cap.read() + if not ok: + break + + if _is_mediapipe: + result = pipeline.process(frame) + boxes, kpts_list, tids_raw = [], [], [] + world_3d_per_hand = [] + handedness = [] + for i, hand in enumerate(result.hands): + lms = hand.landmarks # (21, 2) + x1, y1 = lms.min(axis=0); x2, y2 = lms.max(axis=0) + boxes.append([float(x1), float(y1), float(x2), float(y2)]) + kpts_list.append(lms) + tids_raw.append(i) + wl = getattr(hand, "world_landmarks", None) + world_3d_per_hand.append(wl) + hlabel = getattr(hand, "label", None) or getattr(hand, "handedness", "Unknown") + handedness.append(str(hlabel)) + kpts = np.array(kpts_list, dtype=np.float32) if kpts_list \ + else np.zeros((0, 21, 2), dtype=np.float32) + track_ids = tids_raw + else: + boxes, kpts, scores, track_ids = pipeline.process(frame) + if kpts is None: kpts = np.zeros((0, 21, 2), dtype=np.float32) + world_3d_per_hand = [None] * len(boxes) + handedness = ["Unknown"] * len(boxes) + + # 2D 打包 + packed = _pack_hand_data(boxes, kpts, track_ids) + num = min(len(boxes), MAX_HANDS) + tids = list(track_ids[:MAX_HANDS]) if track_ids else [] + tids += [0] * (MAX_HANDS - len(tids)) + rows.append({ + "frame_index": frame_idx, + "num_hands": num, + "hand_data": packed.tolist(), + "track_ids": tids, + }) + + # 3D 打包 (bare 模式) + if _is_mediapipe: + hl = handedness if handedness else [] + wl = world_3d_per_hand if world_3d_per_hand else [] + row_3d = { + "frame_index": frame_idx, + "hand_0_present": len(boxes) >= 1, + "hand_0_landmarks_3d": _pack_hand_3d_data(wl[0:1]).tolist(), + "hand_0_label": hl[0] if hl else "Unknown", + "hand_1_present": len(boxes) >= 2, + "hand_1_landmarks_3d": _pack_hand_3d_data(wl[1:2]).tolist(), + "hand_1_label": hl[1] if len(hl) >= 2 else "Unknown", + } + rows_3d.append(row_3d) + + frame_idx += 1 + if progress_cb and frame_idx % 10 == 0: + progress_cb(frame_idx, total_frames) + + cap.release() + + if cancel_check and cancel_check(): + return {"success": False, "error": "cancelled"} + + # ── 写入 2D parquet ─────────────────────────── + if rows: + table = pa.table({ + "frame_index": pa.array([r["frame_index"] for r in rows], pa.int32()), + "num_hands": pa.array([r["num_hands"] for r in rows], pa.int32()), + "hand_data": pa.array([r["hand_data"] for r in rows], + pa.list_(pa.float32(), TOTAL_DIM)), + "track_ids": pa.array([r["track_ids"] for r in rows], + pa.list_(pa.int32(), MAX_HANDS)), + }, schema=_HAND_KPTS_SCHEMA) + os.makedirs(os.path.dirname(out_path), exist_ok=True) + pq.write_table(table, out_path, compression="zstd") + + # ── 写入 3D parquet (bare 模式) ─────────────── + if rows_3d: + table_3d = pa.table({ + "frame_index": pa.array([r["frame_index"] for r in rows_3d], pa.int32()), + "hand_0_present": pa.array([r["hand_0_present"] for r in rows_3d], pa.bool_()), + "hand_0_landmarks_3d": pa.array([r["hand_0_landmarks_3d"] for r in rows_3d], + pa.list_(pa.float32(), PER_HAND_3D_DIM)), + "hand_0_label": pa.array([r["hand_0_label"] for r in rows_3d], pa.string()), + "hand_1_present": pa.array([r["hand_1_present"] for r in rows_3d], pa.bool_()), + "hand_1_landmarks_3d": pa.array([r["hand_1_landmarks_3d"] for r in rows_3d], + pa.list_(pa.float32(), PER_HAND_3D_DIM)), + "hand_1_label": pa.array([r["hand_1_label"] for r in rows_3d], pa.string()), + }, schema=_HAND_3D_SCHEMA) + os.makedirs(os.path.dirname(out_3d_path), exist_ok=True) + pq.write_table(table_3d, out_3d_path, compression="zstd") + + elapsed = time.perf_counter() - t_start + result = { + "success": True, "frames": frame_idx, "elapsed": elapsed, + "fps": frame_idx / elapsed if elapsed > 0 else 0, + "mode": mode, "session_path": session_path, + } + if status_cb: + status_cb(f"done ({frame_idx} frames in {elapsed:.1f}s, " + f"{frame_idx/elapsed:.1f} fps)") + if progress_cb: + progress_cb(frame_idx, total_frames) + return result + + except Exception as e: + import traceback + traceback.print_exc() + return {"success": False, "error": str(e)} + + +# ═══════════════════════════════════════════════════════════ +# 自动标注 +# ═══════════════════════════════════════════════════════════ + +MIN_SEGMENT_FRAMES = 10 + + +def label_session(session_path: str, + progress_cb: Optional[Callable[[int, int], None]] = None, + cancel_check: Optional[Callable[[], bool]] = None, + ) -> dict: + """对手部关键点数据逐帧计算手势标签,写入 auto_labels.parquet + auto_actions.jsonl。 + + Returns: + {"success": True/False, "frames": N, "error": ""} + """ + t_start = time.perf_counter() + + try: + # 1. 加载手部关键点 + hand_kpts = load_hand_kpts(session_path) + if not hand_kpts: + return {"success": False, "error": "手部关键点数据不存在,请先提取关键点"} + + # 2. 加载传感器数据 + sensor_data = None + sensor_path = data_parquet_path(session_path) + if os.path.isfile(sensor_path): + try: + sensor_rows = pq.read_table(sensor_path).to_pylist() + sensor_data = {} + for sn in settings.SENSOR_NAMES: + sensor_data[sn] = {} + for r in sensor_rows: + fi = r["frame_index"] + for sn in settings.SENSOR_NAMES: + col = f"observation.{sn}" + val = r.get(col) + if val is not None: + sensor_data[sn][fi] = np.array(val, dtype=np.float32) + except Exception: + sensor_data = None + + # 3. 逐帧标注 + _lazy_import_common() + frame_indices = sorted(hand_kpts.keys()) + total = len(frame_indices) + rows = [] + prev_centers = [None, None] + + for idx, fi in enumerate(frame_indices): + if cancel_check and cancel_check(): + return {"success": False, "error": "cancelled"} + + kpt = hand_kpts[fi] + boxes, kpts_list, num = _unpack_hand_data(kpt["hand_data"]) + row = {"frame_index": fi} + + for h in range(2): + prefix = f"hand_{h}" + if h < num and h < len(kpts_list): + pts = kpts_list[h] + tt = _thumb_tip(pts) + it = _index_tip(pts) + hc_ = _lazy_import_common() + angles = hc_["compute_joint_angles"](pts) + extended = hc_["count_extended_fingers"](angles) + result = classify_gesture(extended, tt, it) + + center = _hand_center(pts) + motion = 0.0 + if prev_centers[h] is not None: + motion = float(np.linalg.norm(center - prev_centers[h])) + prev_centers[h] = center + + row[f"{prefix}_gesture"] = result["gesture"] + row[f"{prefix}_extended"] = extended + row[f"{prefix}_extended_count"] = result["extended_count"] + row[f"{prefix}_fist"] = result["fist"] + row[f"{prefix}_pinch"] = result["pinch"] + row[f"{prefix}_center_x"] = float(center[0]) + row[f"{prefix}_center_y"] = float(center[1]) + row[f"{prefix}_motion"] = motion + else: + for key in ["gesture", "extended", "extended_count", + "fist", "pinch", "center_x", "center_y", "motion"]: + row[f"{prefix}_{key}"] = { + "gesture": "none", "extended": [], "extended_count": 0, + "fist": False, "pinch": False, + "center_x": -1.0, "center_y": -1.0, "motion": -1.0, + }[key] + + # 两手距离 + if num >= 2: + c0 = _hand_center(kpts_list[0]) + c1 = _hand_center(kpts_list[1]) + row["two_hand_distance"] = float(np.linalg.norm(c0 - c1)) + else: + row["two_hand_distance"] = -1.0 + + # 接触状态 + cur_sensors = None + if sensor_data is not None: + cur_sensors = {} + for sn in settings.SENSOR_NAMES: + arr = sensor_data[sn].get(fi) + if arr is not None: + cur_sensors[sn] = arr + row["contact"] = _compute_contact( + row["hand_0_motion"], row["hand_1_motion"], cur_sensors) + + rows.append(row) + + if progress_cb and idx % 100 == 0: + progress_cb(idx, total) + + if cancel_check and cancel_check(): + return {"success": False, "error": "cancelled"} + + # 4. 写入 parquet + if rows: + table = pa.Table.from_pylist(rows, schema=_AUTO_LABELS_SCHEMA) + out_path = auto_labels_parquet_path(session_path) + os.makedirs(os.path.dirname(out_path), exist_ok=True) + pq.write_table(table, out_path, compression="zstd") + + # 5. 时序分割 → jsonl + from core.helpers import _keypoints_session_dir + actions_path = os.path.join(_keypoints_session_dir(session_path), + "auto_actions.jsonl") + os.makedirs(os.path.dirname(actions_path), exist_ok=True) + with open(actions_path, "w", encoding="utf-8") as f: + for action in _segment_actions(rows): + f.write(json.dumps(action, ensure_ascii=False) + "\n") + + elapsed = time.perf_counter() - t_start + if progress_cb: + progress_cb(total, total) + return {"success": True, "frames": total, "elapsed": elapsed} + + except Exception as e: + import traceback + traceback.print_exc() + return {"success": False, "error": str(e)} + + +def _segment_actions(rows: list) -> list: + """帧级标签 → 动作片段列表。""" + if not rows: + return [] + segments = [] + cur_label = rows[0]["hand_0_gesture"] + cur_start = 0 + for i in range(1, len(rows)): + label = rows[i]["hand_0_gesture"] + if label != cur_label: + segments.append({"start": cur_start, "end": i - 1, "label": cur_label}) + cur_label = label + cur_start = i + segments.append({"start": cur_start, "end": len(rows) - 1, "label": cur_label}) + + for seg in segments: + seg["length"] = seg["end"] - seg["start"] + 1 + + merged = [] + i = 0 + while i < len(segments): + seg = segments[i] + if seg["length"] < MIN_SEGMENT_FRAMES and len(merged) > 0: + merged[-1]["end"] = seg["end"] + merged[-1]["length"] = merged[-1]["end"] - merged[-1]["start"] + 1 + else: + merged.append(dict(seg)) + i += 1 + + actions = [] + for seg in merged: + seg_rows = rows[seg["start"]:seg["end"] + 1] + known = sum(1 for r in seg_rows + if r.get("hand_0_gesture", "unknown") != "unknown") + conf = known / max(len(seg_rows), 1) + actions.append({ + "start_frame": seg["start"], + "end_frame": seg["end"], + "label": seg["label"], + "dominant_hand": 0, + "confidence": round(conf, 3), + }) + return actions + + +# ═══════════════════════════════════════════════════════════ +# 加载函数 +# ═══════════════════════════════════════════════════════════ + +def load_hand_kpts(session_path: str) -> Optional[dict]: + """加载 2D 手部关键点,返回 {frame_index: {hand_data, num_hands, track_ids}}。 + + 读取顺序: keypoints_output/ → session/keypoints/ → session/annotations/ + """ + for path_fn in [hand_kpts_parquet_path, _session_kpts_hand_kpts_path, + _legacy_hand_kpts_path]: + kpts_path = path_fn(session_path) + if os.path.isfile(kpts_path): + break + else: + return None + table = pq.read_table(kpts_path) + rows = table.to_pylist() + return {r["frame_index"]: { + "hand_data": np.array(r["hand_data"], dtype=np.float32), + "num_hands": r["num_hands"], + "track_ids": r["track_ids"], + } for r in rows} + + +def load_hand_kpts_pooled(task_dir: str, episode_index: int) -> Optional[dict]: + """池化布局加载 2D 手部关键点(v1.1.0)。 + + 镜像目录 keypoints_output//episode_{N:06d}/hand_pose/chunk-000.parquet; + 返回结构与 load_hand_kpts 相同:{frame_index: {hand_data, num_hands, + track_ids}};无数据返回 None。 + """ + from core.helpers import episode_hand_kpts_parquet_path + kpts_path = episode_hand_kpts_parquet_path(task_dir, episode_index) + if not os.path.isfile(kpts_path): + return None + table = pq.read_table(kpts_path) + rows = table.to_pylist() + return {r["frame_index"]: { + "hand_data": np.array(r["hand_data"], dtype=np.float32), + "num_hands": r["num_hands"], + "track_ids": r["track_ids"], + } for r in rows} + + +def load_hand_3d(session_path: str) -> Optional[dict]: + """加载 3D 手部 landmarks,返回 {frame_index: {...}}。 + + 读取顺序: keypoints_output/ → session/keypoints/ → session/annotations/ + """ + for path_fn in [hand_3d_parquet_path, _session_kpts_hand_3d_path, + _legacy_hand_3d_path]: + path = path_fn(session_path) + if os.path.isfile(path): + break + else: + return None + table = pq.read_table(path) + rows = table.to_pylist() + return {r["frame_index"]: r for r in rows} + + +def load_auto_labels(session_path: str) -> Optional[dict]: + """加载自动标注,返回 {frame_index: row}。 + + 读取顺序: keypoints_output/ → session/keypoints/ → session/annotations/ + """ + for path_fn in [auto_labels_parquet_path, _session_kpts_auto_labels_path, + _legacy_auto_labels_path]: + path = path_fn(session_path) + if os.path.isfile(path): + break + else: + return None + table = pq.read_table(path) + rows = table.to_pylist() + return {r["frame_index"]: r for r in rows} diff --git a/collector/core/helpers.py b/collector/core/helpers.py new file mode 100755 index 0000000000000000000000000000000000000000..82284db46f0d374c30110d40a81d932ddcf0c9a5 --- /dev/null +++ b/collector/core/helpers.py @@ -0,0 +1,1281 @@ +""" +通用工具函数 —— ID 生成、时间戳、时长格式化。 +""" + +import os +import json +import re +import uuid +import ctypes +from datetime import datetime + + +def new_id() -> str: + """生成一个 12 位十六进制短 ID。""" + return uuid.uuid4().hex[:12] + + +def utcnow() -> str: + """返回 ISO-8601 格式的 UTC 时间戳字符串。""" + return datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") + + +def send_to_recycle_bin(path: str) -> bool: + """将文件或文件夹移入回收站。 + + Windows: SHFileOperationW (FOF_ALLOWUNDO → 回收站) + Linux: gio trash(GNOME/GLib 自带);无 gio 时手动移入 + ~/.local/share/Trash(GNOME 标准回收站)。 + + 返回 True 表示成功,False 表示失败。 + """ + if not os.path.exists(path): + return False + + # ── Linux: gio trash(GNOME 桌面自带,移入桌面回收站)── + if os.name != "nt": + import shutil + import subprocess + gio = shutil.which("gio") + if gio: + try: + ret = subprocess.run([gio, "trash", path], + capture_output=True, timeout=30) + if ret.returncode == 0: + return True + except Exception: + pass + # fallback: 手动移入 GNOME 回收站目录(记录原始路径以便恢复) + trash_dir = os.path.expanduser("~/.local/share/Trash") + try: + files_dir = os.path.join(trash_dir, "files") + info_dir = os.path.join(trash_dir, "info") + os.makedirs(files_dir, exist_ok=True) + os.makedirs(info_dir, exist_ok=True) + base = os.path.basename(path.rstrip("/")) or "item" + dest = os.path.join(files_dir, base) + if os.path.exists(dest): # 重名时加后缀 + stem, ext = os.path.splitext(base) + i = 1 + while os.path.exists(dest): + dest = os.path.join(files_dir, f"{stem}_{i}{ext}") + i += 1 + os.rename(path, dest) + import time + with open(os.path.join(info_dir, os.path.basename(dest) + ".trashinfo"), "w") as f: + f.write("[Trash Info]\n") + f.write(f"Path={path}\n") + f.write(f"DeletionDate={time.strftime('%Y-%m-%dT%H:%M:%S')}\n") + return True + except Exception: + return False + + # ── Windows: SHFileOperationW ── + try: + # SHFileOperationW 需要双 null 结尾的宽字符串 + from ctypes import wintypes + SHF = ctypes.windll.shell32.SHFileOperationW + + class SHFILEOPSTRUCTW(ctypes.Structure): + _fields_ = [ + ("hwnd", wintypes.HWND), + ("wFunc", wintypes.UINT), + ("pFrom", wintypes.LPCWSTR), + ("pTo", wintypes.LPCWSTR), + ("fFlags", wintypes.WORD), + ("fAnyOperationsAborted", wintypes.BOOL), + ("hNameMappings", wintypes.LPVOID), + ("lpszProgressTitle", wintypes.LPCWSTR), + ] + + FO_DELETE = 3 + FOF_ALLOWUNDO = 0x40 + FOF_NOCONFIRMATION = 0x10 + FOF_SILENT = 0x04 + + fileop = SHFILEOPSTRUCTW() + fileop.wFunc = FO_DELETE + fileop.pFrom = path + "\0" # null 结尾(ctypes 自动处理宽字符) + fileop.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION + + result = SHF(ctypes.byref(fileop)) + return result == 0 + except Exception: + return False + + +def format_duration(seconds: float) -> str: + """将秒数格式化为 HH:MM:SS 字符串。""" + h = int(seconds // 3600) + m = int((seconds % 3600) // 60) + s = int(seconds % 60) + return f"{h:02d}:{m:02d}:{s:02d}" + + +# ── EgoData 会话摘要 ────────────────────────────── + +def session_size_mb(session_dir: str) -> float: + """遍历会话目录累加所有文件大小,返回 MB。目录不存在/出错返回 0。""" + if not session_dir or not os.path.isdir(session_dir): + return 0.0 + total = 0 + try: + for root, _dirs, files in os.walk(session_dir): + for fn in files: + try: + total += os.path.getsize(os.path.join(root, fn)) + except OSError: + pass + except OSError: + return 0.0 + return total / (1024.0 * 1024.0) + + +def read_metadata(session_dir: str) -> dict: + """读 EgoData metadata.json,任何失败返回 {}。""" + try: + p = egodata_metadata_path(session_dir) + if os.path.isfile(p): + with open(p, "r", encoding="utf-8") as f: + return json.load(f) + except (OSError, json.JSONDecodeError): + pass + return {} + + +def _slot_base(name: str, all_names) -> str: + """流名 → 设备基名(legacy 会话无 devices 段时的启发式)。 + + 兼容三种命名惯例: + xxx_rgb → xxx + xxx_depth → xxx(同组存在 xxx_rgb 时) + xxx_depth → xxx_depth(同组存在 xxx_depth_rgb,即设备本身被命名为 + xxx_depth,如 D435_depth) + 同前缀多台设备的 _N 编号后缀(settings 自动追加)保留在基名上: + d435_rgb_2 / d435_depth_2 → d435_2 + 其余原样返回(stereo_left/stereo_right 等)。 + """ + m = re.match(r"^(.*)_(\d+)$", name) + core, num = (m.group(1), m.group(2)) if m else (name, "") + if core.endswith("_rgb"): + base = core[:-4] + elif core.endswith("_depth"): + if core + "_rgb" in all_names: + base = core + elif core[:-6] + "_rgb" in all_names: + base = core[:-6] + else: + base = core + else: + base = core + return base + ("_" + num if num else "") + + +def _sub_name(slot: str, dev_name: str, slots: list) -> str: + """槽名 → 子画面名:优先去设备名前缀,其次去槽名公共前缀。 + + slot == dev_name 的惯例是深度槽以设备本身命名(如 D435_depth), + 子画面名即 "depth"。 + """ + if slot == dev_name: + return "depth" + if dev_name and slot.startswith(dev_name + "_"): + return slot[len(dev_name) + 1:] + if len(slots) > 1: + prefix = os.path.commonprefix(slots) + if prefix: + return slot[len(prefix):].lstrip("_") + return slot + + +def _device_display_names(meta: dict) -> list: + """录制历史"摄像机"列文本:按设备聚合,不把子画面平铺当相机。 + + D435 一台设备出 rgb+depth 两路流 → "D435_depth (rgb, depth)"; + 双目 S80M → "FaysSense S80M (left, right)";单流设备只显示设备名。 + 有 devices 段按设备条目聚合(跳过 data_ble 手套/无槽设备); + legacy 会话无 devices 段时按 _slot_base 对 cameras 键分组。 + """ + devices = meta.get("devices") or [] + groups = [] # [(设备名, [槽名...])] + if devices: + for d in devices: + slots = list(d.get("slots") or []) + if not slots or d.get("kind") == "data_ble": + continue + name = d.get("name") or "" + if not name: + if len(slots) > 1: + prefix = os.path.commonprefix(slots).rstrip("_") + name = prefix or _slot_base(slots[0], set(slots)) + else: + name = _slot_base(slots[0], set(slots)) + groups.append((name, slots)) + else: + cam_names = list((meta.get("cameras") or {}).keys()) + by_base = {} + for n in cam_names: + by_base.setdefault(_slot_base(n, set(cam_names)), []).append(n) + groups = list(by_base.items()) + disp = [] + for name, slots in groups: + subs = [s for s in (_sub_name(s, name, slots) for s in slots) if s] + if len(subs) >= 2: + disp.append(f"{name} ({', '.join(subs)})") + else: + disp.append(name) + return disp + + +def session_summary(session_dir: str, + frames_by_cam: dict, + episode_index: int = 0) -> tuple: + """会话展示摘要。返回 (camera_list, duration_sec, size_mb)。 + + episode_index > 0 且目录为池化布局时走任务级口径: + - camera_list: info.json devices 段按设备聚合 + - duration_sec: episodes 每段文件行 duration_sec + - size_mb: episode_size_mb(task_dir, N)(只统计本 episode 文件组) + 否则走旧会话目录口径(历史自愈/未迁移残留): + - camera_list: 按设备聚合的显示名(D435 一台设备出 rgb+depth 两路 + 子画面 → "D435_depth (rgb, depth)",见 _device_display_names); + metadata 缺失时用 frames_by_cam 中有帧的键(sorted); + 两者皆空返回 ""(调用方兜底) + - duration_sec: max(每相机 帧数/fps);每相机 fps 优先 + cameras[cam].fps(egodata_writer 只在异于全局时写入),缺省 + metadata["fps"],再缺省 settings.RECORDING_FPS;帧数为 0 的相机 + 贡献 0;帧数全部缺失(旧记录自愈)时降级 timestamps.json 最后一 + 帧相对时间,再降级 total_frames / 最小 fps(近似) + - size_mb: session_size_mb(session_dir) + """ + if episode_index and detect_session_format(session_dir) == "pooled": + info = {} + try: + with open(pooled_info_path(session_dir), "r", + encoding="utf-8") as f: + info = json.load(f) + except (OSError, json.JSONDecodeError): + info = {} + row = episode_row(session_dir, episode_index) + duration = float(row.get("duration_sec") or 0.0) + display = ", ".join(_device_display_names(info)) if info else "" + if not display: + # 无 devices 段兜底:本 episode 实际存在的视频 key + display = ", ".join( + sorted(episode_video_files(session_dir, episode_index))) + return display, duration, episode_size_mb(session_dir, episode_index) + + meta = read_metadata(session_dir) + cam_names = list((meta.get("cameras") or {}).keys()) + if not cam_names: + cam_names = sorted(k for k, v in (frames_by_cam or {}).items() if v > 0) + fps_list = [] + for cam in cam_names: + info = (meta.get("cameras") or {}).get(cam) or {} + fps = float(info.get("fps") or meta.get("fps") or _settings.RECORDING_FPS) + frames = float((frames_by_cam or {}).get(cam, 0)) + if frames > 0: + fps_list.append(frames / max(fps, 1.0)) + duration = max(fps_list) if fps_list else 0.0 + if duration == 0.0 and cam_names: + duration = _timestamps_duration(session_dir, meta, cam_names) + display = ", ".join(_device_display_names(meta)) if meta else "" + if not display: + display = ", ".join(cam_names) # 无 cameras 元数据 → 旧行为 + return display, duration, session_size_mb(session_dir) + + +def _timestamps_duration(session_dir: str, meta: dict, cam_names: list) -> float: + """timestamps.json 降级补算时长:最后一条相对时间(精确), + 再降级 total_frames / 最小 fps(近似,同 playback 的 _get_effective_fps 思路)。""" + try: + p = egodata_timestamps_path(session_dir) + if not os.path.isfile(p): + return 0.0 + with open(p, "r", encoding="utf-8") as f: + data = json.load(f) + ts_list = data.get("timestamps") or [] + if ts_list and isinstance(ts_list[-1], dict): + last_ts = ts_list[-1].get("timestamp") + if isinstance(last_ts, (int, float)) and last_ts > 0: + return float(last_ts) + total = data.get("total_frames") + if isinstance(total, (int, float)) and total > 0: + fps_values = [] + for name in cam_names: + info = (meta.get("cameras") or {}).get(name) or {} + fps_values.append(float(info.get("fps") or meta.get("fps") + or _settings.RECORDING_FPS)) + fps = min(fps_values) if fps_values else float(_settings.RECORDING_FPS) + return float(total) / max(fps, 1.0) + except (OSError, ValueError, TypeError, json.JSONDecodeError): + pass + return 0.0 + + +def format_size_mb(mb: float) -> str: + """大小列文本: >0 显示 "12.3 MB",0/缺失显示 "-"。""" + if not mb or mb <= 0: + return "-" + return f"{mb:.1f} MB" + + +def timestamp_filename(prefix: str = "rec", ext: str = ".avi") -> str: + """生成带时间戳的文件名,例如 rec_20260804_143052.avi""" + stamp = datetime.now().strftime("%Y%m%d_%H%M%S") + return f"{prefix}_{stamp}{ext}" + + +def _sanitize_tag(raw: str) -> str: + """清洗标签名,保留字母数字、中文和下划线。""" + tag = raw.strip() if raw else "session" + return "".join(c if c.isalnum() or c in "_一-鿿" else "_" for c in tag) + + +def task_tag(task_name: str = "") -> str: + """生成任务分类标签(用于子文件夹名)。 + + Args: + task_name: 任务标注(如 "grasp_cup"),为空时返回 "session" + + Returns: + 清洗后的标签名,例如 "grasp_cup"、"test00"、"session" + """ + return _sanitize_tag(task_name) + + +def session_dirname(task_name: str = "", batch_index: int = 0) -> str: + """生成会话目录名。 + + Args: + task_name: 任务标注(如 "grasp_cup"),为空时默认用 "session" + + Returns: + 目录名字符串,例如 "grasp_cup_20260805_195046" 或 "session_20260805_195046" + """ + tag = _sanitize_tag(task_name) + stamp = datetime.now().strftime("%Y%m%d_%H%M%S") + if batch_index > 0: + return f"{tag}_{batch_index:04d}_{stamp}" + return f"{tag}_{stamp}" + + +# ═══════════════════════════════════════════════════════════ +# LeRobot v3 分块存储路径工具 +# ═══════════════════════════════════════════════════════════ + +def chunk_dir(chunk_index: int = 0) -> str: + """chunk 目录名: chunk-000""" + return f"chunk-{chunk_index:03d}" + + +def chunk_file(chunk_index: int = 0, name: str = "file") -> str: + """chunk 内文件名: file-000.parquet / file-000.mp4""" + return f"{name}-{chunk_index:03d}" + + +def data_parquet_path(session_dir: str, chunk_index: int = 0) -> str: + """data/chunk-000/file-000.parquet""" + return os.path.join(session_dir, "data", chunk_dir(chunk_index), + chunk_file(chunk_index) + ".parquet") + + +def episode_parquet_path(session_dir: str, chunk_index: int = 0) -> str: + """meta/episodes/chunk-000/file-000.parquet""" + return os.path.join(session_dir, "meta", "episodes", chunk_dir(chunk_index), + chunk_file(chunk_index) + ".parquet") + + +def video_mp4_path(session_dir: str, camera_key: str, chunk_index: int = 0) -> str: + """videos//chunk-000.mp4""" + return os.path.join(session_dir, "videos", camera_key, + f"{chunk_dir(chunk_index)}.mp4") + + +def tasks_jsonl_path(session_dir: str) -> str: + """meta/tasks.jsonl""" + return os.path.join(session_dir, "meta", "tasks.jsonl") + + +# ═══════════════════════════════════════════════════════════ +# 池化任务布局路径工具(v1.1.0) +# ═══════════════════════════════════════════════════════════ + +POOLED_CHUNK_SIZE = 1000 + + +def episode_chunk_file(episode_index: int) -> tuple: + """全局 episode 序号 N(1 起)→ (chunk_index, file_index)。 + + 每 chunk 1000 个 episode,episode 文件号三位零起: + N=1 → (0, 0) chunk-000/episode-000 + N=1000 → (0, 999) + N=1001 → (1, 0) chunk-001/episode-000 + """ + n = max(int(episode_index) - 1, 0) + return n // POOLED_CHUNK_SIZE, n % POOLED_CHUNK_SIZE + + +def pooled_file_stem(file_index: int, ext: str = "") -> str: + """chunk 内文件名: episode-000.parquet / episode-000.mp4(v1.1.2 起)""" + return f"episode-{file_index:03d}{ext}" + + +def episode_file_suffix(episode_index: int) -> int: + """episode N 的 episode 文件号(0 基):episode-000 = 第 1 段(= 本地文件后缀)。 + + 上传/回放界面的任务名后缀与上传表单 episode_index 均用此值, + 与本地 episode-NNN 完全对齐;真实全局序号 N 始终在 parquet 行内。 + """ + return episode_chunk_file(episode_index)[1] + + +def task_dir_of(base_dir: str, task_name: str) -> str: + """池化任务目录: /(目录名与旧任务目录一致)。""" + return os.path.join(base_dir, task_tag(task_name)) + + +def pooled_video_path(task_dir: str, image_key: str, episode_index: int, + ext: str = "mp4") -> str: + """videos/chunk-NNN//episode-NNN.(每 episode 每流一文件)""" + c, f = episode_chunk_file(episode_index) + return os.path.join(task_dir, "videos", chunk_dir(c), image_key, + pooled_file_stem(f, f".{ext}")) + + +def pooled_video_dir(task_dir: str, image_key: str, episode_index: int) -> str: + """videos/chunk-NNN// 目录路径""" + c, _ = episode_chunk_file(episode_index) + return os.path.join(task_dir, "videos", chunk_dir(c), image_key) + + +def pooled_data_parquet_path(task_dir: str, episode_index: int) -> str: + """data/chunk-NNN/episode-NNN.parquet(每 episode 一个,稀疏列)""" + c, f = episode_chunk_file(episode_index) + return os.path.join(task_dir, "data", chunk_dir(c), + pooled_file_stem(f, ".parquet")) + + +def pooled_episodes_path(task_dir: str, episode_index: int) -> str: + """meta/episodes/chunk-NNN/episode-NNN.parquet(每 episode 一个文件, + 与 data/videos 同编号:episode-000 = episode 1;单行 10 列)。""" + c, f = episode_chunk_file(episode_index) + return os.path.join(task_dir, "meta", "episodes", chunk_dir(c), + pooled_file_stem(f, ".parquet")) + + +def _legacy_episodes_shard_path(task_dir: str, chunk_index: int) -> str: + """v1.1.0 旧布局的 episodes 分片路径(每 chunk 一个 ≤1000 行文件, + 文件名 = chunk 号,即 file-{chunk:03d}.parquet——v1.1.2 每段文件改 + episode- 前缀后两者不再重名)。仅作旧数据回退读取/删行用。""" + return os.path.join(task_dir, "meta", "episodes", chunk_dir(chunk_index), + chunk_file(chunk_index) + ".parquet") + + +def pooled_info_path(task_dir: str) -> str: + """meta/info.json(任务级)""" + return os.path.join(task_dir, "meta", "info.json") + + +def pooled_stats_path(task_dir: str) -> str: + """meta/stats.json(任务级全局统计,块含 count/mean/std/min/max)。 + + v1.1.1 起 stats.json 自身即增量累加器(count 可反推 sum/sum_sq), + 不再有 .stats_state.json 边车。 + """ + return os.path.join(task_dir, "meta", "stats.json") + + +def pooled_tasks_jsonl_path(task_dir: str) -> str: + """meta/tasks.jsonl(任务级)""" + return os.path.join(task_dir, "meta", "tasks.jsonl") + + +def list_task_episodes(task_dir: str) -> list: + """扫描池化任务目录,返回已存在的全局 episode 序号列表(升序)。 + + 依据 data/ 与 videos/ 下的 episode-NNN 文件组(episodes 行可能因 + abort 回滚而缺失,数据文件才是权威)。任务目录不存在返回 []。 + """ + if not os.path.isdir(task_dir): + return [] + ns = set() + for sub in ("data", "videos"): + root = os.path.join(task_dir, sub) + if not os.path.isdir(root): + continue + for cname in os.listdir(root): + m = re.match(r"^chunk-(\d+)$", cname) + if not m: + continue + cdir = os.path.join(root, cname) + if not os.path.isdir(cdir): + continue + chunk = int(m.group(1)) + for entry in os.listdir(cdir): + p = os.path.join(cdir, entry) + if os.path.isdir(p): # videos: image_key 目录 + for fn in os.listdir(p): + fm = re.match(r"^episode-(\d+)\.", fn) + if fm: + ns.add(chunk * POOLED_CHUNK_SIZE + + int(fm.group(1)) + 1) + else: # data: 直接 episode-NNN.parquet + fm = re.match(r"^episode-(\d+)\.parquet$", entry) + if fm: + ns.add(chunk * POOLED_CHUNK_SIZE + + int(fm.group(1)) + 1) + return sorted(ns) + + +def recycled_episode_path(task_dir: str) -> str: + """异常终止回退标记文件路径(meta/recycled_episode.json)。""" + return os.path.join(task_dir, "meta", "recycled_episode.json") + + +def read_recycled_episode(task_dir: str) -> int: + """读取上次异常终止释放的 episode 序号;无标记/损坏返回 0。""" + try: + with open(recycled_episode_path(task_dir), "r", + encoding="utf-8") as f: + data = json.load(f) + n = int(data.get("episode_index", 0) or 0) + return n if n > 0 else 0 + except (OSError, ValueError, TypeError): + return 0 + + +def mark_recycled_episode(task_dir: str, episode_index: int) -> None: + """异常终止后标记该序号可复用(下次录制优先取回——不占号语义)。 + + 原子写(临时件 + os.replace);episode_index <= 0 视为清除。 + 标记由本段正常完成(writer.end_episode)时清除。 + """ + path = recycled_episode_path(task_dir) + if episode_index <= 0: + clear_recycled_episode(task_dir) + return + try: + os.makedirs(os.path.dirname(path), exist_ok=True) + tmp = f"{path}.tmp{os.getpid()}" + with open(tmp, "w", encoding="utf-8") as f: + json.dump({"episode_index": int(episode_index), + "freed_at": utcnow()}, f) + os.replace(tmp, path) + except OSError: + pass + + +def clear_recycled_episode(task_dir: str) -> None: + """录制正常完成后清除回退标记(该号已被本段重新占住)。""" + try: + os.remove(recycled_episode_path(task_dir)) + except OSError: + pass + + +def next_pooled_episode_index(task_dir: str, batch_index: int = 0) -> int: + """返回任务的下一个全局 episode 序号。 + + 权威 = 任务进度序号 batch_index(录制完成次数 + 1,与本地文件删除 + 无关——上传后自动删除不会让序号回退)与目录扫描 max + 1 取大 + (防与现存文件组重名)。batch_index <= 0 退化为纯目录扫描。 + + 异常终止回退(不占号):上次中止写下的 recycled 标记若其号未被 + 文件组占用,优先复用该号——batch_index 水位跑在前面也 + 不跳号;号已被占(跨机共享目录/遗留)时自动放弃标记并走常规取号。 + """ + existing = list_task_episodes(task_dir) + recycled = read_recycled_episode(task_dir) + if recycled: + if recycled not in existing: + return recycled + clear_recycled_episode(task_dir) + scan_next = (existing[-1] + 1) if existing else 1 + if batch_index > 0: + return max(batch_index, scan_next) + return scan_next + + +def episode_video_files(task_dir: str, episode_index: int) -> dict: + """episode N 的视频文件组 {image_key: 文件路径}。 + + key 可跨 episode 改名(同一物理相机不同会话槽名不同),以本 episode + 实际存在的文件为准,不按任务级 video_extensions 推断。 + """ + c, f = episode_chunk_file(episode_index) + stem = pooled_file_stem(f, "") + out = {} + vroot = os.path.join(task_dir, "videos", chunk_dir(c)) + if os.path.isdir(vroot): + for key in sorted(os.listdir(vroot)): + kd = os.path.join(vroot, key) + if not os.path.isdir(kd): + continue + for fn in sorted(os.listdir(kd)): + if fn.startswith(stem + "."): + out[key] = os.path.join(kd, fn) + return out + + +def episode_size_mb(task_dir: str, episode_index: int) -> float: + """episode N 的文件组总大小(MB;视频 + data parquet)。""" + total = 0 + for p in episode_video_files(task_dir, episode_index).values(): + try: + total += os.path.getsize(p) + except OSError: + pass + dp = pooled_data_parquet_path(task_dir, episode_index) + if os.path.isfile(dp): + try: + total += os.path.getsize(dp) + except OSError: + pass + return total / (1024.0 * 1024.0) + + +def episode_row(task_dir: str, episode_index: int) -> dict: + """episode N 的元数据行;不存在返回 {}。 + + 新布局:每段一个文件(pooled_episodes_path 直读)。 + 旧布局回退:v1.1.0 分片(每 chunk 一个 ≤1000 行文件,文件名 = + chunk 号)里按 episode_index 列过滤。 + """ + import pyarrow.parquet as pq + p = pooled_episodes_path(task_dir, episode_index) + if os.path.isfile(p): + try: + for r in pq.read_table(p).to_pylist(): + if r.get("episode_index") == episode_index: + return r + except Exception: + pass + # 旧分片回退(分片名 = chunk 号 file-{c:03d},v1.1.2 起与每段文件 + # episode-{f:03d} 不再重名) + c, _ = episode_chunk_file(episode_index) + legacy = _legacy_episodes_shard_path(task_dir, c) + if legacy != p and os.path.isfile(legacy): + try: + for r in pq.read_table(legacy).to_pylist(): + if r.get("episode_index") == episode_index: + return r + except Exception: + pass + return {} + + +def episode_refs(base_dir: str) -> list: + """扫描全部池化任务的 episode 列表(读侧唯一枚举入口)。 + + Returns: + [{"task", "task_dir", "episode_index", "name"}, ...] + name 后缀 = episode 文件号(0 基,与本地 episode-NNN 对齐);按名称倒序 + (最新任务/最新序号在前)。旧格式会话目录不再列出 + (v1.1.0 读侧只认池化布局)。 + """ + out = [] + if not os.path.isdir(base_dir): + return out + for task in sorted(os.listdir(base_dir)): + task_dir = os.path.join(base_dir, task) + if not os.path.isdir(task_dir) or task.startswith((".", "_")): + continue + if detect_session_format(task_dir) != "pooled": + continue + for n in list_task_episodes(task_dir): + out.append({"task": task, "task_dir": task_dir, + "episode_index": n, + "name": f"{task}_ep{episode_file_suffix(n):06d}"}) + return sorted(out, key=lambda s: s["name"], reverse=True) + + +# ═══════════════════════════════════════════════════════ +# 任务级统计(v1.1.1:stats.json 自含累加器,无 .stats_state 边车) +# ═══════════════════════════════════════════════════════ + +def stat_block_to_sum(blk: dict) -> dict: + """统计块归一为 sum-form {count, sum, sum_sq, min, max}。 + + 兼容两种入参:writer/迁移产出的 sum-form;stats.json 的 json-form + {count, mean, std, min, max}(按 mean/std/count 反推 sum/sum_sq—— + 这是 stats.json 能当累加器的基础)。 + """ + import numpy as np + n = int(blk.get("count", 0) or 0) + if "sum" in blk: + s = np.asarray(blk.get("sum", []), dtype=np.float64) + sq = np.asarray(blk.get("sum_sq", []), dtype=np.float64) + dim = len(s) + elif "mean" in blk: + m = np.asarray(blk.get("mean", []), dtype=np.float64) + sd = np.asarray(blk.get("std", []), dtype=np.float64) + dim = len(m) + s = m * n + sq = (sd * sd + m * m) * n + else: + return {"count": 0, "sum": [], "sum_sq": [], "min": [], "max": []} + mn = blk.get("min") + mx = blk.get("max") + if mn is None or len(mn) != dim: + mn = [float("inf")] * dim + if mx is None or len(mx) != dim: + mx = [float("-inf")] * dim + return {"count": n, "sum": s.tolist(), "sum_sq": sq.tolist(), + "min": [float(v) for v in mn], "max": [float(v) for v in mx]} + + +def merge_stat_block(acc: dict, key: str, blk: dict, dim: int) -> None: + """把新统计块合并进累加器(sum-form;count<=0 跳过)。 + + blk 可为 sum-form(writer 的 np 数组块/迁移块)或 json-form; + acc 中旧块按 sum-form 读取,无则从零起。 + """ + if not blk or int(blk.get("count", 0) or 0) <= 0: + return + import numpy as np + new = stat_block_to_sum(blk) + n1 = int(new["count"]) + old = acc.get(key) + if isinstance(old, dict) and int(old.get("count", 0) or 0) > 0: + old = stat_block_to_sum(old) + n0 = int(old["count"]) + s = (np.asarray(old["sum"], dtype=np.float64) + + np.asarray(new["sum"], dtype=np.float64)) + sq = (np.asarray(old["sum_sq"], dtype=np.float64) + + np.asarray(new["sum_sq"], dtype=np.float64)) + mn = np.minimum(np.asarray(old["min"], dtype=np.float64), + np.asarray(new["min"], dtype=np.float64)) + mx = np.maximum(np.asarray(old["max"], dtype=np.float64), + np.asarray(new["max"], dtype=np.float64)) + else: + n0 = 0 + s = np.asarray(new["sum"], dtype=np.float64) + sq = np.asarray(new["sum_sq"], dtype=np.float64) + mn = np.asarray(new["min"], dtype=np.float64) + mx = np.asarray(new["max"], dtype=np.float64) + acc[key] = {"count": n0 + n1, "sum": s.tolist(), "sum_sq": sq.tolist(), + "min": mn.tolist(), "max": mx.tolist()} + + +def acc_to_stats_json(acc: dict) -> dict: + """sum-form 累加器 → stats.json 内容:每块 {count, mean, std, min, max}。 + + count=0 的块写占位(mean 0/std 1,与旧格式空块语义一致); + action 恒为占位块(count 0,对外只表示列形状,不参与统计)。 + """ + import numpy as np + stats: dict = {} + for key, blk in acc.items(): + if not isinstance(blk, dict): + continue + sblk = stat_block_to_sum(blk) + n = int(sblk["count"]) + dim = len(sblk["sum"]) + if n <= 0 or dim == 0: + stats[key] = {"count": 0, "mean": [0.0] * dim, "std": [1.0] * dim, + "min": [0.0] * dim, "max": [0.0] * dim} + continue + s = np.asarray(sblk["sum"], dtype=np.float64) + sq = np.asarray(sblk["sum_sq"], dtype=np.float64) + mean = s / n + var = np.maximum(sq / n - mean * mean, 0.0) + stats[key] = {"count": n, "mean": mean.tolist(), + "std": np.sqrt(var).tolist(), + "min": sblk["min"], "max": sblk["max"]} + stats["action"] = {"count": 0, "mean": [0.0], "std": [1.0], + "min": [0.0], "max": [0.0]} + return stats + + +def load_stats_acc(task_dir: str) -> tuple: + """读任务 stats.json 归一为 sum-form 累加器。 + + 返回 (acc, need_recalc):文件缺失/损坏 → ({}, False);任一块缺 count + (旧格式,无法增量合并)→ ({}, True),调用方应 recalc_stats 重建。 + """ + path = pooled_stats_path(task_dir) + if not os.path.isfile(path): + return {}, False + try: + with open(path, "r", encoding="utf-8") as f: + raw = json.load(f) + except (OSError, json.JSONDecodeError): + return {}, False + if not isinstance(raw, dict): + return {}, False + acc = {} + for key, blk in raw.items(): + if not isinstance(blk, dict): + continue + if "count" not in blk: + return {}, True # 旧格式(无 count)→ 全量重算一次 + acc[key] = stat_block_to_sum(blk) + return acc, False + + +def recalc_stats(task_dir: str) -> dict: + """全量重扫任务 data parquet,重建 stats.json(自含 count),返回 sum-form acc。 + + 只统计实际存在的观测列:observation.*(帧级,逐行计数,与写入器同口径) + 与 observation.imu(样本级 6 轴);observation.*hand_pose 为恒写占位 + 零列(后处理回填),跳过不计(与写入器增量口径一致,且避免 std=0 + 块毒化归一化)。旧格式 stats.json 迁移、删边车后的重建兜底都用它。 + 无数据列时产出仅含 action 占位块。 + """ + import numpy as np + import pyarrow.parquet as pq + acc: dict = {} + for ep in list_task_episodes(task_dir): + p = pooled_data_parquet_path(task_dir, ep) + if not os.path.isfile(p): + continue + try: + tbl = pq.read_table(p) + except Exception: + continue + for col in tbl.column_names: + if not col.startswith("observation."): + continue + if col.endswith("hand_pose"): + continue # 恒写占位零列,后处理回填,不计统计 + try: + if col == "observation.imu": + samples = [np.asarray(v, dtype=np.float64) + for v in tbl.column(col).to_pylist() if v] + if not samples: + continue + arr = np.concatenate([a.reshape(-1, 6) for a in samples]) + else: + vals = [np.asarray(v, dtype=np.float64) + for v in tbl.column(col).to_pylist() + if v is not None] + if not vals: + continue + arr = np.stack(vals) + except (TypeError, ValueError): + continue + merge_stat_block(acc, col, { + "count": int(arr.shape[0]), + "sum": arr.sum(axis=0).tolist(), + "sum_sq": (arr * arr).sum(axis=0).tolist(), + "min": arr.min(axis=0).tolist(), + "max": arr.max(axis=0).tolist(), + }, arr.shape[1]) + # 原子写(indent=2:stats.json 是给人读的契约文件) + path = pooled_stats_path(task_dir) + os.makedirs(os.path.dirname(path), exist_ok=True) + tmp = path + ".tmp" + with open(tmp, "w", encoding="utf-8") as f: + json.dump(acc_to_stats_json(acc), f, indent=2, ensure_ascii=False) + os.replace(tmp, path) + return acc + + +def _rmdir_empty(path: str) -> bool: + """删除空目录(自底向上连带空父目录);非空/不存在返回 False。""" + if not os.path.isdir(path): + return False + try: + os.rmdir(path) + return True + except OSError: + return False + + +def delete_pooled_episode(task_dir: str, episode_index: int) -> bool: + """彻底删除 episode N 的文件组(用户裁决:GUI 删除不走回收区)。 + + - videos//episode-{f}.{ext} 各流文件 + - data/chunk-{c}/episode-{f}.parquet + - episodes 每段文件直接删;旧分片回退=flock 读-改-写删行(与 writer + 同口径) + 统计不回退(stats/total_episodes 保持,与进度语义一致)。 + + 幂等:文件组已不存在也返回 True(视为已删)。 + """ + files = episode_video_files(task_dir, episode_index) + for key, src in files.items(): + try: + os.remove(src) + except OSError: + pass + _rmdir_empty(os.path.dirname(src)) + dp = pooled_data_parquet_path(task_dir, episode_index) + if os.path.isfile(dp): + try: + os.remove(dp) + except OSError: + pass + _rmdir_empty(os.path.dirname(dp)) + + # episodes 元数据:新布局=每段一个文件 → 直接删;旧分片回退=删行 + from core.egodata_writer import (_read_episode_rows, _episode_rows_table, + _atomic_write_parquet) + cidx, fidx = episode_chunk_file(episode_index) + ep_file = pooled_episodes_path(task_dir, episode_index) + handled = False + if os.path.isfile(ep_file): + try: + rows = _read_episode_rows(ep_file) + except Exception: + rows = [] + if len(rows) == 1 and rows[0].get("episode_index") == episode_index: + # 单行且正是 N → 直接删(含旧分片只剩该行的退化情形) + try: + os.remove(ep_file) + handled = True + except OSError: + pass + _rmdir_empty(os.path.dirname(ep_file)) + if not handled: + # 旧分片(每 chunk 一个多行文件)→ flock 读-改-写删行 + legacy = _legacy_episodes_shard_path(task_dir, cidx) + if os.path.isfile(legacy): + try: + import fcntl as _fcntl + except ImportError: + _fcntl = None + lock_dir = os.path.join(task_dir, "meta", "episodes") + os.makedirs(lock_dir, exist_ok=True) + fh = open(os.path.join(lock_dir, ".lock"), "a+") + try: + if _fcntl is not None: + _fcntl.flock(fh.fileno(), _fcntl.LOCK_EX) + rows = [r for r in _read_episode_rows(legacy) + if r.get("episode_index") != episode_index] + _atomic_write_parquet(_episode_rows_table(rows), legacy) + finally: + if _fcntl is not None: + _fcntl.flock(fh.fileno(), _fcntl.LOCK_UN) + fh.close() + return True + + +# ═══════════════════════════════════════════════════════════ +# 关键点数据路径 —— 独立输出到 keypoints_output/,与 data/ 镜像结构 +# ═══════════════════════════════════════════════════════════ + +from config import settings as _settings + + +def _keypoints_session_dir(session_dir: str) -> str: + """将录制 session 路径映射到 keypoints_output 下的镜像目录。 + + data/recordings/Test005/Test005_000024 + → keypoints_output/Test005/Test005_000024 + """ + recordings_root = os.path.normpath(_settings.RECORDING_DIR) + sd = os.path.normpath(session_dir) + if sd.startswith(recordings_root + os.sep): + rel = os.path.relpath(sd, recordings_root) + else: + parts = sd.replace(os.sep, "/").rstrip("/").split("/") + rel = os.path.join(parts[-2], parts[-1]) if len(parts) >= 2 else parts[-1] + return os.path.join(_settings.KEYPOINTS_OUTPUT_DIR, rel) + + +def episode_keypoints_dir(task_dir: str, episode_index: int) -> str: + """池化 episode 的 keypoints 镜像目录。 + + data/recordings/ + N → keypoints_output//episode_{N:06d} + """ + task = os.path.basename(os.path.normpath(task_dir)) + return os.path.join(_settings.KEYPOINTS_OUTPUT_DIR, task, + f"episode_{episode_index:06d}") + + +def episode_keypoints_video_dir(task_dir: str, episode_index: int) -> str: + """keypoints_output//episode_{N:06d}/videos/""" + return os.path.join(episode_keypoints_dir(task_dir, episode_index), "videos") + + +def episode_hand_kpts_parquet_path(task_dir: str, episode_index: int) -> str: + """keypoints_output//episode_{N:06d}/hand_pose/chunk-000.parquet""" + return os.path.join(episode_keypoints_dir(task_dir, episode_index), + "hand_pose", f"{chunk_dir(0)}.parquet") + + +def episode_auto_labels_parquet_path(task_dir: str, episode_index: int) -> str: + """keypoints_output//episode_{N:06d}/auto_labels/auto_labels.parquet""" + return os.path.join(episode_keypoints_dir(task_dir, episode_index), + "auto_labels", "auto_labels.parquet") + + +def episode_hand_3d_parquet_path(task_dir: str, episode_index: int) -> str: + """keypoints_output//episode_{N:06d}/hand_pose_3d/chunk-000.parquet""" + return os.path.join(episode_keypoints_dir(task_dir, episode_index), + "hand_pose_3d", f"{chunk_dir(0)}.parquet") + + +def keypoints_video_dir(session_dir: str) -> str: + """keypoints_output///videos/""" + return os.path.join(_keypoints_session_dir(session_dir), "videos") + + +def hand_kpts_parquet_path(session_dir: str) -> str: + """keypoints_output///hand_pose/chunk-000.parquet""" + return os.path.join(_keypoints_session_dir(session_dir), "hand_pose", + f"{chunk_dir(0)}.parquet") + + +def auto_labels_parquet_path(session_dir: str) -> str: + """keypoints_output///auto_labels/auto_labels.parquet""" + return os.path.join(_keypoints_session_dir(session_dir), "auto_labels", + "auto_labels.parquet") + + +def hand_3d_parquet_path(session_dir: str) -> str: + """keypoints_output///hand_pose_3d/chunk-000.parquet""" + return os.path.join(_keypoints_session_dir(session_dir), "hand_pose_3d", + f"{chunk_dir(0)}.parquet") + + +# ── 回退路径 1: session 目录内的 keypoints/ ────────────── + +def _session_kpts_hand_kpts_path(session_dir: str) -> str: + return os.path.join(session_dir, "keypoints", "hand_pose", + f"{chunk_dir(0)}.parquet") + +def _session_kpts_hand_3d_path(session_dir: str) -> str: + return os.path.join(session_dir, "keypoints", "hand_pose_3d", + f"{chunk_dir(0)}.parquet") + +def _session_kpts_auto_labels_path(session_dir: str) -> str: + return os.path.join(session_dir, "keypoints", "auto_labels", + "auto_labels.parquet") + +# ── 回退路径 2: session 目录内的 annotations/(最旧版兼容)── + +def _legacy_hand_kpts_path(session_dir: str) -> str: + return os.path.join(session_dir, "annotations", "hand_pose", + f"{chunk_dir(0)}.parquet") + +def _legacy_hand_3d_path(session_dir: str) -> str: + return os.path.join(session_dir, "annotations", "hand_pose_3d", + f"{chunk_dir(0)}.parquet") + +def _legacy_auto_labels_path(session_dir: str) -> str: + return os.path.join(session_dir, "annotations", "mmpose", "auto_labels.parquet") + + +def list_all_sessions(base_dir: str) -> list: + """扫描录制根目录,返回全部池化 episode(v1.1.0 读侧唯一枚举入口)。 + + base_dir 是录制根目录(如 RECORDING_DIR)。 + 旧格式会话目录不再列出——迁移后只认任务级池化布局。 + + 返回: [(task_dir, episode_index, display_name), ...] 按名称倒序, + display_name 后缀 = episode 文件号(0 基,与本地 episode-NNN 对齐)。 + """ + return [(r["task_dir"], r["episode_index"], r["name"]) + for r in episode_refs(base_dir)] + + +# ═══════════════════════════════════════════════════════════ +# EgoData 格式路径工具 +# ═══════════════════════════════════════════════════════════ + +def episode_dirname(episode_index: int = 1, task_name: str = "", + digits: int = 6) -> str: + """EgoData episode 目录名。 + + 有 task_name 时: Chew_gum_000001 + 无 task_name 时: episode_000001(兼容旧命名) + """ + from config import settings + d = digits if digits else settings.EPISODE_DIGITS + if task_name: + prefix = _sanitize_tag(task_name) + else: + prefix = settings.EPISODE_PREFIX + return f"{prefix}_{episode_index:0{d}d}" + + +def next_episode_index(base_dir: str, task_name: str = "", + batch_index: int = 0) -> int: + """返回下一个 episode 索引。 + + 优先取任务进度序号 batch_index(录制完成次数 + 1,与本地文件是否 + 删除无关——上传后自动删除不会让序号回退);同时至少大于目录扫描出 + 的最大索引,防止与现存目录重名(删除失败/人工留存等场景)。 + batch_index <= 0 时退化为纯目录扫描(旧行为)。 + + 兼容新命名 (_NNNNNN) 和旧命名 (episode_NNNNNN)。 + """ + import re + from config import settings + + tag = task_tag(task_name) if task_name else "" + + # 构建匹配模式:新格式 (task_tag_NNN) + 旧格式 (episode_NNN) 兼容 + patterns = [] + if tag: + patterns.append(re.compile(rf"^{re.escape(tag)}_(\d+)$")) + patterns.append(re.compile(rf"^{settings.EPISODE_PREFIX}_(\d+)$")) + + max_idx = 0 + search_dirs = [] + if tag: + tagged = os.path.join(base_dir, tag) + if os.path.isdir(tagged): + search_dirs.append(tagged) + search_dirs.append(base_dir) + + for sd in search_dirs: + if not os.path.isdir(sd): + continue + for entry in os.listdir(sd): + for pat in patterns: + m = pat.match(entry) + if m and os.path.isdir(os.path.join(sd, entry)): + idx = int(m.group(1)) + if idx > max_idx: + max_idx = idx + scan_next = max_idx + 1 + if batch_index > 0: + return max(batch_index, scan_next) + return scan_next + + +# ── EgoData 目录内路径 ────────────────────────────── + +def egodata_video_path(episode_dir: str, camera_name: str) -> str: + """videos//chunk-0000/.mp4 + + _aux 后缀的摄像头归入其主摄像头文件夹: + stereo_left_aux → videos/stereo_left/chunk-0000/stereo_left_aux.mp4 + """ + base_cam = camera_name[:-4] if camera_name.endswith("_aux") else camera_name + return os.path.join(episode_dir, "videos", base_cam, "chunk-0000", + f"{camera_name}.mp4") + + +def egodata_video_dir(episode_dir: str, camera_name: str) -> str: + """videos//chunk-0000/ 目录路径。""" + base_cam = camera_name[:-4] if camera_name.endswith("_aux") else camera_name + return os.path.join(episode_dir, "videos", base_cam, "chunk-0000") + + +def egodata_depth_path(episode_dir: str, depth_name: str, frame_index: int) -> str: + """episode_dir/depth/head_depth/000001.png(PNG 16-bit grayscale,uint16 毫米) + + 旧版 png16 格式(v1.0.13 及以前),保留给历史会话读取回退。 + """ + return os.path.join(episode_dir, "depth", depth_name, + f"{frame_index:06d}.png") + + +def egodata_depth_video_path(episode_dir: str, depth_name: str) -> str: + """episode_dir/depth//.mp4(12-bit 灰度 HEVC,v1.1.2 起) + + 单视频轨 hevc (Rext) gray12le,12-bit 对数深度码(见 + core/depth_codec.py)。旧格式回退 .mkv(v1.0.14 双流 + FFV1);哪个存在返回哪个,都无则按 mp4 返回。 + """ + base = os.path.join(episode_dir, "depth", depth_name, depth_name) + for ext in (".mp4", ".mkv"): + path = base + ext + if os.path.isfile(path): + return path + return base + ".mp4" + + +def egodata_image_path(episode_dir: str, camera_name: str, frame_index: int) -> str: + """episode_dir/images/head_left_rgb/000001.jpg""" + return os.path.join(episode_dir, "images", camera_name, + f"{frame_index:06d}.jpg") + + +def egodata_calibration_path(episode_dir: str, + calib_name: str = "head_stereo") -> str: + """episode_dir/calibration/head_stereo.json""" + return os.path.join(episode_dir, "calibration", f"{calib_name}.json") + + +def egodata_metadata_path(episode_dir: str) -> str: + """episode_dir/metadata.json""" + return os.path.join(episode_dir, "metadata.json") + + +def egodata_timestamps_path(episode_dir: str) -> str: + """episode_dir/timestamps.json""" + return os.path.join(episode_dir, "timestamps.json") + + +def egodata_sensor_data_dir(episode_dir: str, sensor_name: str) -> str: + """data//chunk-0000/ 目录路径。""" + return os.path.join(episode_dir, "data", sensor_name, "chunk-0000") + + +def egodata_sensor_parquet_path(episode_dir: str, sensor_name: str) -> str: + """data//chunk-0000/chunk_000000.parquet""" + return os.path.join(episode_dir, "data", sensor_name, "chunk-0000", + "chunk_000000.parquet") + + +# ── 格式检测 ──────────────────────────────────────── + +def detect_session_format(session_dir: str) -> str: + """检测会话目录格式。 + + Returns: + "pooled" — v1.1.0 任务池化布局(meta/info.json format 字段) + "egodata" — 有 metadata.json + "lerobot_v3" — 有 meta/info.json(旧 LeRobot v3 会话目录) + "unknown" — 无法识别 + """ + info_path = os.path.join(session_dir, "meta", "info.json") + if os.path.isfile(info_path): + try: + with open(info_path, "r", encoding="utf-8") as f: + info = json.load(f) + if isinstance(info, dict) and \ + info.get("format") == "pooled_episodes_v1": + return "pooled" + except (OSError, json.JSONDecodeError): + pass + return "lerobot_v3" + if os.path.isfile(os.path.join(session_dir, "metadata.json")): + return "egodata" + return "unknown" + + +# ── 扩展 list_all_sessions 兼容 EgoData ────────────── + +def list_all_egodata_sessions(base_dir: str) -> list: + """扫描全部 EgoData episode 目录。 + + 目录结构: base_dir//episode_000001/ + + Returns: [(ep_path, ep_name, tag_name), ...] 按名称倒序 + """ + import re + from config import settings + + sessions = [] + if not os.path.isdir(base_dir): + return sessions + + d = settings.EPISODE_DIGITS + # 匹配: 任意前缀_NNNNNN (新任务命名) 或 episode_NNNNNN (旧兼容) + pattern = re.compile(rf"^(\w+)_(\d{{{d}}})$") + + for entry in sorted(os.listdir(base_dir)): + entry_path = os.path.join(base_dir, entry) + if not os.path.isdir(entry_path): + continue + + # EgoData: 本身是 episode 目录(有 metadata.json) + if pattern.match(entry) and os.path.isfile( + os.path.join(entry_path, "metadata.json")): + sessions.append((entry_path, entry, entry.split("_")[0])) + else: + # 任务子文件夹 + for sub in sorted(os.listdir(entry_path)): + sub_path = os.path.join(entry_path, sub) + if pattern.match(sub) and os.path.isfile( + os.path.join(sub_path, "metadata.json")): + sessions.append((sub_path, sub, entry)) + + return sorted(sessions, key=lambda s: s[1], reverse=True) diff --git a/collector/core/pipeline.py b/collector/core/pipeline.py new file mode 100755 index 0000000000000000000000000000000000000000..bf53f928b8772314ea19d4f1421ea6e7d4c9b248 --- /dev/null +++ b/collector/core/pipeline.py @@ -0,0 +1,866 @@ +""" +摄像机管线 —— 管理多路摄像机和共享录制会话。 +所有摄像机录制到同一个 episode(v1.1.0 任务池化布局:每路一个 +videos/chunk-NNN//file-NNN 视频 + 一个 data parquet)。 +""" + +from __future__ import annotations +import time +import threading +import queue +from typing import Callable, Dict, List, Optional + +import numpy as np +from PyQt5.QtCore import QObject, pyqtSignal, QTimer + +from config import settings +from core.camera import CameraWorker, CameraState +from core.egodata_writer import EgoDataWriter + + +class DropStats: + """录制丢帧统计(v1.0.9:编码背压可见化)。 + + 线程安全计数器 + 快照。计数路径:采集线程/主线程的 put_nowait 满 + 分支(写入线程只读快照)。 + """ + + def __init__(self): + self._lock = threading.Lock() + self._counts: Dict[str, int] = {} + + def inc(self, key: str, n: int = 1): + with self._lock: + self._counts[key] = self._counts.get(key, 0) + n + + def clear(self): + with self._lock: + self._counts.clear() + + def snapshot(self) -> Dict[str, int]: + with self._lock: + return dict(self._counts) + + +class CameraSlot(QObject): + """ + 一个摄像机槽位 —— 相机采集 + 帧缓冲。 + + 信号 + ---- + frame_ready(str, ndarray) — slot_id, BGR帧(用于 UI 显示) + state_changed(str, str) — slot_id, 新状态 + error_occurred(str, str) — slot_id, 错误消息 + """ + + frame_ready = pyqtSignal(str, object) + state_changed = pyqtSignal(str, str) + error_occurred = pyqtSignal(str, str) + + def __init__(self, slot_id: str, camera_index: int, + on_queue_full: Optional[Callable[[], None]] = None): + super().__init__() + self.slot_id = slot_id + self.camera_index = camera_index + self.camera_name = f"Camera {camera_index}" + + # B+ 方案: 帧队列,采集线程直接写入,录制线程消费 + # maxsize=3 保证队列里始终是最新的帧,避免积压 + self.frame_queue = queue.Queue(maxsize=3) + self.camera = CameraWorker(camera_index, record_queue=self.frame_queue, + on_queue_full=on_queue_full) + + self.camera.frame_ready.connect(self._on_frame) + self.camera.state_changed.connect(self._on_camera_state) + self.camera.error_occurred.connect( + lambda msg: self.error_occurred.emit(self.slot_id, msg) + ) + + def start_camera(self): + self.camera.start() + + def stop_camera(self): + self.camera.stop() + + @property + def camera_state(self) -> str: + return self.camera.state + + def _on_frame(self, frame): + # 转发给 UI 显示(录制帧由 frame_queue 独立传递,不受此信号影响) + self.frame_ready.emit(self.slot_id, frame) + + def _on_camera_state(self, state: str): + self.state_changed.emit(self.slot_id, state) + + +class CameraPipeline(QObject): + """ + 管理一组 CameraSlot + 共享 LeRobot 录制会话。 + + 所有摄像机录制到同一个会话目录,保证 MP4 和 Parquet 完整。 + """ + + slot_added = pyqtSignal(str) + slot_removed = pyqtSignal(str) + session_changed = pyqtSignal(object) # VideoRecorder | None + recording_started = pyqtSignal(str) # slot_id + recording_finished = pyqtSignal(str, str) # slot_id, task_dir(v1.1.0 池化) + recording_aborted = pyqtSignal(str) # slot_id + duration_changed = pyqtSignal(str, float) + error_occurred = pyqtSignal(str, str) + state_changed = pyqtSignal(str, str) + recording_log = pyqtSignal(str) # v1.0.9 编码器探测等录制期日志 + + def __init__(self, output_dir: str = None): + super().__init__() + self._output_dir = output_dir or settings.RECORDING_DIR + self._slots: Dict[str, CameraSlot] = {} + + # 共享录制状态 + self._writer: Optional[EgoDataWriter] = None + self._recording = False + self._frame_count = 0 # 全局帧序号(跨摄像机递增) + self._per_cam_frame: Dict[str, int] = {} # 每路摄像机的独立帧序号 + self._last_recording_frames: Dict[str, int] = {} # 上一轮录制的每相机帧数快照 + self._start_time: float = 0.0 + self._episode_start_s: float = 0.0 # episode 起始 Unix 秒(用于相对时间戳) + self._timer_running = False + self._codec_name = "" + self._session_path: Optional[str] = None + self._last_episode_index: int = 0 # v1.1.0:上一轮录制的全局 episode 序号 + self._recording_slot: Optional[str] = None + + # v1.0.9 丢帧统计与 IMU 防丢 + self._drop_stats = DropStats() + self._last_drop_stats: Dict[str, int] = {} + self._pending_imu: Dict[str, list] = {} # slot → 队列满暂存的 IMU 样本 + self._pending_imu_lock = threading.Lock() + self._imu_overflow_count = 0 # 防丢缓冲超限次数(每 episode 告警一次) + + # 已注册的传感器名称列表(决定 parquet 中 observation. 列) + self._sensor_names: List[str] = [] + self._device_meta: List[dict] = [] # start_recording(device_meta=…) 透传 + + # B+ 方案: 传感器数据通过队列传递(主线程 → 写入线程),线程安全 + # 队列元素: (sensor_name, data_array) 元组 + self._sensor_queue: queue.Queue = queue.Queue(maxsize=10) + + # USB 手套 IMU 四元数:sensor_name → (quats 64×f32, valid 16×f32) + # 最新值覆盖式快照,写入线程每帧取走后清空(与传感器队列同节奏) + self._glove_imu: Dict[str, tuple] = {} + self._glove_imu_lock = threading.Lock() + # USB 手套骨架关键点:sensor_name → 63×f32(21×3 米),同节奏快照 + self._glove_kpts: Dict[str, np.ndarray] = {} + self._glove_kpts_lock = threading.Lock() + + # 外部帧源(如双目子进程),不经过 CameraWorker + # 帧通过队列传入写入线程,以固定帧率均匀消费,避免 GIL 导致的写入抖动 + # _external_queues[slot_id] = queue.Queue(maxsize=2) + # _external_dims[slot_id] = (height, width) + # _external_fps[slot_id] = fps + self._external_queues: Dict[str, queue.Queue] = {} + self._external_dims: Dict[str, tuple] = {} + self._external_fps: Dict[str, float] = {} + + # B+ 方案: 独立写入线程,用 time.perf_counter() 精确控制 30fps + self._write_thread: Optional[threading.Thread] = None + + # 录制时长更新定时器(主线程,仅用于 UI 显示) + self._duration_timer = QTimer(self) + self._duration_timer.timeout.connect(self._tick_duration) + self._duration_timer.setInterval(250) + + # 深度帧队列(双目深度计算 → 写入线程);按深度槽位名分列 + # (S80M 传统路径用 "stereo_left" 作为默认键) + self._depth_queues: Dict[str, queue.Queue] = {} + self._depth_frame_idx: Dict[str, int] = {} + + # 深度伪相机元数据(D435 等原生深度相机,多路并存): + # _depth_cameras[depth槽名] = {"resolution": (h,w), "fps": f, + # "master_slot": 主槽位, + # "heatmap_near_mm"/"heatmap_far_mm"/"heatmap_smooth_k"/ + # "heatmap_temporal_alpha": …} + # 名字含 "depth" → EgoDataWriter 自动标 type:depth 并跳过视频目录创建 + self._depth_cameras: Dict[str, dict] = {} + # 最近深度帧(深度源低于录制帧率时补拍节拍:重复写双流使 + # 深度 MKV 帧 i 与 RGB 帧 i 对齐;FFV1 对重复帧增量≈0) + self._last_depth_frames: Dict[str, np.ndarray] = {} + # 深度帧随哪路主槽位同步落盘(S80M 默认 stereo_left,D435 为 d435_rgb) + self._depth_master_slot: str = "stereo_left" + # 外部帧源标定(D435 运行时从 SDK 提取,录制开始时写入 calibration/) + self._external_calibration = None + self._external_calibrations: dict = {} # device_key → 标定(多路) + + # 录制事件日志(连接/断开标记) + self._device_status: Dict[str, str] = {} + + def record_event(self, device: str, event_type: str, message: str = ""): + """记录一个带时间戳的设备事件并更新连接状态。 + + CameraPipeline 写入线程会在每帧 parquet 数据中写入 status. 列。 + + Args: + device: 设备标识(如 cam_001, sensors_right) + event_type: 事件类型(connected, disconnected) + message: 附加描述 + """ + status = "connected" if event_type == "connected" else "disconnected" + self._device_status[device] = status + + # ── 槽位管理 ────────────────────────────────────── + + def add_camera(self, slot_id: str, camera_index: int) -> CameraSlot: + if slot_id in self._slots: + raise ValueError(f"槽位 {slot_id} 已存在") + slot = CameraSlot(slot_id, camera_index, + on_queue_full=lambda: self._drop_stats.inc( + f"uvc:{slot_id}")) + self._slots[slot_id] = slot + slot.start_camera() + self.slot_added.emit(slot_id) + return slot + + def remove_camera(self, slot_id: str): + slot = self._slots.pop(slot_id, None) + if slot: + if self._recording: + self.abort_recording(slot_id) + slot.stop_camera() + slot.blockSignals(True) + slot.deleteLater() + self.slot_removed.emit(slot_id) + + def get_slot(self, slot_id: str) -> Optional[CameraSlot]: + return self._slots.get(slot_id) + + def slot_ids(self): + return list(self._slots.keys()) + + def slot_count(self) -> int: + return len(self._slots) + + def remove_all(self): + for sid in list(self._slots.keys()): + self.remove_camera(sid) + + @property + def is_recording(self) -> bool: + return self._recording + + # ── 外部帧源(双目子进程等) ────────────────────── + + def register_external_source(self, slot_id: str, resolution: tuple, + fps: float = 25.0): + """注册一个外部帧源(不创建 CameraWorker)。 + + 外部帧源通过队列将帧传入写入线程,以固定帧率均匀消费。 + 每路外部源可使用独立 fps,ffmpeg 用该值设置输出帧率。 + + Args: + slot_id: 槽位标识(如 "stereo_left") + resolution: (height, width) + fps: 该摄像机的原生帧率(用于 ffmpeg -r 参数) + """ + # 深缓冲(≈1s):写线程/编码器子进程启动、系统卡顿期间吸收 + # 抽帧后的积压帧,避免 put_nowait 丢帧;写线程按 30fps 均匀 + # 消费,缓冲只延后写入不丢内容(峰值内存 ~90MB/槽,可控) + self._external_queues[slot_id] = queue.Queue(maxsize=30) + self._external_dims[slot_id] = resolution + self._external_fps[slot_id] = fps + + def unregister_external_source(self, slot_id: str): + """移除外部帧源。""" + self._external_queues.pop(slot_id, None) + self._external_dims.pop(slot_id, None) + self._external_fps.pop(slot_id, None) + + def write_external_frame(self, slot_id: str, frame: np.ndarray, + hardware_ns: int = 0, + imu_samples: Optional[List] = None): + """将外部帧推入录制队列(线程安全,非阻塞)。 + + 帧由写入线程以固定帧率均匀消费,保证输出视频无抖动。 + + Args: + hardware_ns: 帧的 SDK 硬件纳秒时间戳(双目相机,与 IMU 同源) + imu_samples: 本帧窗口内的 IMU 样本 [(ts_ns, gx,gy,gz, ax,ay,az), ...] + """ + q = self._external_queues.get(slot_id) + if q is not None and self._recording: + try: + q.put_nowait((frame, hardware_ns, imu_samples)) + except queue.Full: + # ★ v1.0.9 丢帧保 IMU:帧+hardware_ns 成对丢弃(视频帧与 + # parquet 行同步少一行,序号对齐不受影响),但 stereo_left + # 的 IMU 批次转入防丢缓冲,随后续帧按时间戳挂靠落盘 —— + # 丢帧只损失视频帧,不损失 IMU 样本 + self._drop_stats.inc(f"ext:{slot_id}") + if slot_id == "stereo_left" and imu_samples: + with self._pending_imu_lock: + buf = self._pending_imu.setdefault(slot_id, []) + buf.extend(imu_samples) + overflow = (len(buf) + - settings.IMU_PENDING_MAX_SAMPLES) + if overflow > 0: + del buf[:overflow] + self._imu_overflow_count += 1 + if self._imu_overflow_count == 1: + self.recording_log.emit( + "[警告] IMU 防丢缓冲超限,最旧样本被丢弃") + + def write_depth(self, depth_frame: np.ndarray, + depth_slot: str = "stereo_left"): + """将深度帧推入录制队列(线程安全,非阻塞,keep-latest)。 + + 深度图(S80M 视差 / D435 原生毫米深度,均为 uint16)通过此方法传入, + 写入线程在消费该路深度主槽位帧时同步写入。深度帧语义是 + "每帧 RGB 配最新深度":入队前清掉未消费旧帧——旧 FIFO 丢新帧 + 口径在实测 ~27fps 突发产出下丢 35%(突发期队列必然溢出), + 被覆盖的旧帧下游本来就不消费,最新帧覆盖无损失。 + + Args: + depth_frame: uint16 numpy array (H, W),视差图(值×16)或毫米深度图 + depth_slot: 深度槽位名(默认 "stereo_left" 兼容 S80M 传统路径) + """ + if not self._recording: + return + # 兼容旧单深度调用(如 d435_e2e_test 的 write_depth(frame)): + # 名义槽未注册而恰好只声明了一路深度相机时,自动落到该路 + if depth_slot not in self._depth_cameras \ + and len(self._depth_cameras) == 1: + depth_slot = next(iter(self._depth_cameras)) + q = self._depth_queues.setdefault(depth_slot, + queue.Queue(maxsize=3)) + # keep-latest:深度引擎实测 ~27fps 突发产出(burst 期可达 ~50fps), + # 与写线程 30fps 消费名义相等——FIFO+丢新帧必然溢出(实机 165/478 + # = 35%);最新帧覆盖旧帧后突发期无丢帧、每拍都配到最新深度, + # 引擎停顿期的补拍(重复最近帧)路径不受影响 + try: + while True: + q.get_nowait() + except queue.Empty: + pass + q.put_nowait(depth_frame) + + # ── 深度伪相机(D435 等原生深度设备) ────────────── + + def set_depth_camera(self, name: str, resolution: tuple, + fps: float, master_slot: str, + heatmap_near_mm: float = 0.0, + heatmap_far_mm: float = 0.0, + heatmap_smooth_k: int = 0, + heatmap_temporal_alpha: float = 0.0): + """声明一个元数据深度相机(不注册外部队列、不建视频目录;多路并存)。 + + 名字含 "depth" 的相机会被 EgoDataWriter 自动跳过视频创建, + 但进入 metadata.json(type:depth/unit:mm)并启用 write_depth + 12-bit 灰度 MP4 落盘(gray12le 对数码,编码器不支持时回落 + FFV1 灰度 MKV 无损 uint16 毫米)。 + + Args: + name: 深度槽位名(如 "d435_depth") + resolution: (height, width) + fps: 深度帧率 + master_slot: 深度帧随哪路主槽位同步落盘(如 "d435_rgb") + heatmap_near_mm: 热力图色标下限(毫米);0 表示帧内自适应 + heatmap_far_mm: 热力图色标上限(毫米);0 表示帧内自适应 + near/far 同给时是**真固定色标**(线性映射,帧间颜色 + 完全一致),无效值/近端→JET(0) 深蓝、超远→红饱和 + (demo 口径,不置黑);否则每帧重配(会闪) + heatmap_smooth_k: 热力图中值滤波核(奇数,0 关闭) + heatmap_temporal_alpha: 热力图时域 EMA 权重(0 关闭; + 仅影响可视化热力图流,无损深度流不受影响) + """ + self._depth_cameras[name] = { + "resolution": resolution, + "fps": fps, + "master_slot": master_slot, + "heatmap_near_mm": heatmap_near_mm, + "heatmap_far_mm": heatmap_far_mm, + "heatmap_smooth_k": int(heatmap_smooth_k), + "heatmap_temporal_alpha": float(heatmap_temporal_alpha), + } + self._depth_master_slot = master_slot + + def clear_depth_camera(self, name: str = None): + """清除深度伪相机(name=None 清全部),S80M 默认主槽位兜底。""" + if name is None: + self._depth_cameras.clear() + else: + self._depth_cameras.pop(name, None) + self._depth_master_slot = "stereo_left" + + def set_external_calibration(self, calib): + """兼容旧调用:设置外部帧源标定(单设备场景 → head_stereo.json)。""" + self._external_calibration = calib + self._external_calibrations["_default"] = calib + + def set_device_calibration(self, device_key: str, calib): + """按设备注册标定(多路场景)。录制开始时: + 首台双目型设备 → calibration/head_stereo.json(服务器/回放依赖), + 其余 → calibration/{slot前缀}_calibration.json。 + """ + self._external_calibrations[device_key] = calib + + def clear_device_calibration(self, device_key: str): + """设备关闭时清除其标定,避免下个会话串台。""" + self._external_calibrations.pop(device_key, None) + + # ── 设备注册 ────────────────────────────────────── + + def register_sensors(self, sensor_names: List[str]): + """注册传感器设备名称。 + + 必须在 start_recording 之前调用。传感器名称决定 parquet 中 + observation. 列名,如 "right_glove", "left_glove"。 + """ + self._sensor_names = list(sensor_names) + + def register_sensor(self, sensor_name: str): + """增量注册单个传感器(手套开关 ON 时实时调用,下次录制生效)。""" + if sensor_name not in self._sensor_names: + self._sensor_names.append(sensor_name) + + def unregister_sensor(self, sensor_name: str): + """注销单个传感器(手套开关 OFF)。""" + if sensor_name in self._sensor_names: + self._sensor_names.remove(sensor_name) + + # ── 录制控制 ────────────────────────────────────── + + def start_recording(self, slot_id: str, task_name: str = "", + batch_index: int = 0, + device_meta: Optional[List[dict]] = None): + """全部摄像机开始录制到同一个 LeRobot 会话。 + + Args: + slot_id: 触发录制的摄像机槽位 ID + task_name: 任务标注(如 "grasp_cup"),会嵌入目录名 + batch_index: 任务进度序号(录制完成次数 + 1),用于 episode + 目录序号命名(与本地文件删除无关) + device_meta: 录制设备信息列表(写入 metadata.json / info.json + devices 段): [{"key","kind","name","serial","slots"}] + """ + if self._recording or (not self._slots and not self._external_queues): + return + # 先设标志防重复触发,再后台初始化 + self._recording_slot = slot_id + self._recording = True + self._device_status.clear() # 清空上一轮的状态 + self._start_time = time.monotonic() + self._timer_running = True + self._duration_timer.start() + self._task_name = task_name + self._batch_index = batch_index + self._device_meta = list(device_meta) if device_meta else [] + threading.Thread(target=self._start_async, daemon=True).start() + + def _start_async(self): + """后台线程:创建 EgoData episode 并启动独立写入线程。""" + # 收集所有摄像机尺寸(含外部帧源如双目) + cameras = {} + camera_fps = {} # per-camera FPS(外部源用原生帧率,其余用录制帧率) + default_fps = float(settings.RECORDING_FPS) + for sid, sl in self._slots.items(): + w, h = sl.camera.resolution # resolution = (width, height) + cameras[sid] = (h, w) # EgoData: (height, width) + camera_fps[sid] = default_fps + for sid, (h, w) in self._external_dims.items(): + cameras[sid] = (h, w) + camera_fps[sid] = self._external_fps.get(sid, default_fps) + # 深度伪相机(D435 等):只进 metadata,不建视频目录/MP4;多路并存 + for dname, dconf in self._depth_cameras.items(): + dh, dw = dconf["resolution"] + cameras[dname] = (dh, dw) + camera_fps[dname] = dconf["fps"] + + w = EgoDataWriter() + # 探针日志在 start_episode 内 emit → connect 必须在调用之前 + w.log_occurred.connect(self.recording_log) + all_device_ids = list(self._slots.keys()) + list(self._sensor_names) + # 设备标定(多路):set_device_calibration 注册的按 key 传入; + # 旧 set_external_calibration 单值路径存 "_default" 键 + calibrations = dict(self._external_calibrations) + legacy_calib = self._external_calibration if calibrations else None + ok = w.start_episode(self._output_dir, cameras, default_fps, + sensors=self._sensor_names, + task_name=getattr(self, '_task_name', ''), + device_ids=all_device_ids, + calibration=legacy_calib, + camera_fps=camera_fps, + devices=getattr(self, '_device_meta', []), + calibrations=calibrations, + # 任务进度序号:按录制完成次数命名(与文件 + # 删除无关);0 时 writer 退化为目录扫描 + batch_index=getattr(self, '_batch_index', 0), + # 与旧语义一致:显式注册的深度设备(如 D435/D405) + # 打开即录深度;settings.DEPTH_ENABLED 只门控 + # S80M 视差路径(无注册槽的兜底单槽) + depth_enabled=bool(self._depth_cameras), + depth_heatmaps={ + dn: {"near_mm": dc["heatmap_near_mm"], + "far_mm": dc["heatmap_far_mm"], + "smooth_k": dc["heatmap_smooth_k"], + "temporal_alpha": dc["heatmap_temporal_alpha"]} + for dn, dc in self._depth_cameras.items()}, + # 深度槽以显式注册为准(set_depth_camera), + # 不由槽名是否含 "depth" 猜测 + depth_slots=list(self._depth_cameras.keys())) + if not ok: + self._recording = False + self._timer_running = False + self.error_occurred.emit("", "ffmpeg 启动失败") + return + + self._writer = w + self._session_path = w.task_dir # v1.1.0:任务目录(池化布局根) + self._last_episode_index = w.episode_index + # v1.0.9 编码器名动态化(如 "HEVC (libx265)") + self._codec_name = f"{w.encoder_label} | EgoData + LeRobot v3 Parquet" + # 丢帧统计/IMU 防丢:每 episode 重置 + self._drop_stats.clear() + self._pending_imu.clear() + with self._glove_imu_lock: + self._glove_imu.clear() + with self._glove_kpts_lock: + self._glove_kpts.clear() + self._imu_overflow_count = 0 + self._frame_count = 0 + self._per_cam_frame = {sid: 0 for sid in self._slots} + self._depth_frame_idx = {} + self._last_depth_frames = {} + self._episode_start_s = time.time() + + # 清空录制前残留的旧帧和传感器数据 + for sid, sl in self._slots.items(): + while not sl.frame_queue.empty(): + try: sl.frame_queue.get_nowait() + except queue.Empty: break + while not self._sensor_queue.empty(): + try: self._sensor_queue.get_nowait() + except queue.Empty: break + + # B+ 方案: 启动独立写入线程(精确 30fps,完全不受主线程 UI 影响) + self._write_thread = threading.Thread( + target=self._write_loop, daemon=True, name="frame-writer" + ) + self._write_thread.start() + + self.recording_started.emit(self._recording_slot) + self.session_changed.emit(self) + + def _write_loop(self): + """独立写入线程 —— 用 time.perf_counter() 精确按 30fps 写入帧。""" + frame_interval = 1.0 / settings.RECORDING_FPS # ~0.0333s + next_write = time.perf_counter() + + while self._recording and self._writer is not None: + now = time.perf_counter() + + # 精确等待到下一帧时刻 + sleep_for = next_write - now + if sleep_for > 0.001: + # sleep 到目标时间前 ~1ms,然后用 busy-wait 补齐精度 + time.sleep(sleep_for - 0.001) + while time.perf_counter() < next_write: + pass + elif sleep_for < -frame_interval: + # 落后超过一帧(系统卡顿),重置时钟防止帧爆发 + next_write = now + frame_interval + + # 推进到下一帧时刻(用 += 防止累积误差) + next_write += frame_interval + + try: + # 每帧先排空传感器队列,取最新数据(所有相机共享) + sensor_data: Dict[str, np.ndarray] = {} + while True: + try: + s_name, s_data = self._sensor_queue.get_nowait() + sensor_data[s_name] = s_data + except queue.Empty: + break + # 手套 IMU/骨架快照随本帧行写入(USB 手套;空 dict 无影响) + glove_imu = self._pop_glove_imu() + glove_kpts = self._pop_glove_keypoints() + + # 处理 CameraSlot 队列(排空取最新帧) + for sid, sl in self._slots.items(): + try: + frame = sl.frame_queue.get_nowait() + except queue.Empty: + continue + while True: + try: + frame = sl.frame_queue.get_nowait() + except queue.Empty: + break + + # 单目相机左右镜像翻转(录制时写入 MP4) + if getattr(settings, 'CAMERA_MIRROR_HORIZONTAL', False): + frame = np.flip(frame, axis=1) + + self._write_one_frame(sid, frame, sensor_data, + glove_imu=glove_imu, + glove_kpts=glove_kpts) + + # 处理外部帧源队列(取一帧不排空,保证输出均匀无抖动) + # 双目帧已在 _on_stereo_frame 完成垂直翻转,此处不再重复翻转 + for sid, q in self._external_queues.items(): + try: + item = q.get_nowait() + except queue.Empty: + continue + if isinstance(item, tuple) and len(item) == 3: + frame, hw_ns, imu_s = item + else: # 兼容旧格式(仅帧) + frame, hw_ns, imu_s = item, 0, None + # IMU 样本只随 stereo_left 写入(左右目共享同一份, + # 避免 data/imu/ 出现重复行) + if sid != "stereo_left": + imu_s = None + else: + # v1.0.9:队列满时暂存的 IMU 批次随后续帧挂靠。 + # 被丢帧的 IMU 晚于队内旧帧,只挂靠 ts ≤ 本帧 hw_ns + # 的样本(旧样本在前,跨行时序单调),其余留在缓冲 + # 等更晚的帧;hw_ns=0 无时序信息则全量挂靠。 + with self._pending_imu_lock: + pending = self._pending_imu.pop(sid, None) + if pending: + if hw_ns and hw_ns > 0: + due = [s for s in pending if s[0] <= hw_ns] + rest = [s for s in pending if s[0] > hw_ns] + if rest: + with self._pending_imu_lock: + self._pending_imu.setdefault( + sid, []).extend(rest) + pending = due + if pending: + imu_s = list(pending) + list(imu_s or []) + self._write_one_frame(sid, frame, sensor_data, + flip_vertical=False, + hardware_ns=hw_ns, + imu_samples=imu_s, + glove_imu=glove_imu, + glove_kpts=glove_kpts) + + except Exception: + pass + + def _write_one_frame(self, sid: str, frame: np.ndarray, + sensor_data: Dict[str, np.ndarray], + flip_vertical: bool = True, + hardware_ns: int = 0, + imu_samples: Optional[List] = None, + glove_imu: Optional[Dict[str, tuple]] = None, + glove_kpts: Optional[Dict[str, np.ndarray]] = None): + """写入单帧到 MP4 + Parquet。 + + Args: + flip_vertical: 是否在 write_video_frame 中上下翻转。 + 单目 CameraSlot 路径为 True(默认); + 双目外部帧路径为 False(已在 _on_stereo_frame 完成翻转)。 + hardware_ns: SDK 硬件纳秒时间戳(双目相机帧) + imu_samples: 本帧窗口的 IMU 样本列表(双目,随 stereo_left 携带) + glove_imu: {传感器名: (quats 64×f32, valid 16×f32)} USB 手套 IMU 快照 + glove_kpts: {传感器名: 63×f32 骨架关键点} USB 手套骨架快照 + """ + cam_frame_idx = self._per_cam_frame.get(sid, 0) + rel_ts = time.time() - self._episode_start_s + self._writer.write_video_frame(sid, frame, flip_vertical=flip_vertical) + self._writer.write_frame_row( + cam_frame_idx, rel_ts, + sensors=sensor_data if sensor_data else None, + connection_status=self._device_status, + hardware_ns=hardware_ns, + imu_samples=imu_samples, + glove_imu=glove_imu, + glove_kpts=glove_kpts, + ) + self._per_cam_frame[sid] = cam_frame_idx + 1 + self._frame_count += 1 + + # 深度帧:每路深度相机随自己的主槽位同步写入 + # (S80M: stereo_left;D435 第 n 台: d435_rgb[_n]) + depth_targets = dict(self._depth_cameras) + if not depth_targets: + # S80M 传统路径:无深度伪相机注册,默认随 stereo_left 落盘 + depth_targets = {"stereo_left": { + "master_slot": "stereo_left"}} + for dname, dconf in depth_targets.items(): + if sid != dconf["master_slot"]: + continue + try: + depth_frame = self._depth_queues.get(dname, + queue.Queue()).get_nowait() + fresh = True + except queue.Empty: + # 深度引擎停顿期队列空(实测产出 ~27fps 突发,低于录制 + # 帧率,见 write_depth keep-latest):重复最近帧补满节拍, + # 深度视频帧 i 与 RGB 帧 i 严格对齐(12-bit MP4 与 FFV1 + # 回退同口径);编码器对重复帧增量≈0 + depth_frame = self._last_depth_frames.get(dname) + if depth_frame is None: + continue + fresh = False + if fresh: + idx = self._depth_frame_idx.get(dname, 0) + self._last_depth_frames[dname] = depth_frame + self._depth_frame_idx[dname] = idx + 1 + else: + idx = 0 + self._writer.write_depth_frame(idx, depth_frame, depth_slot=dname) + + def write_sensor(self, data, capture_ts_us: int = 0, + sensor_name: str = ""): + """将传感器数据通过队列传给写入线程(线程安全)。 + + Args: + data: 16×16 float32 压力矩阵 + capture_ts_us: 保留参数(兼容),当前不使用 + sensor_name: 传感器设备名(如 "sensors_right"), + 为空时默认用 _sensor_names 的第一个 + """ + if self._writer is not None and self._recording: + if not sensor_name and self._sensor_names: + sensor_name = self._sensor_names[0] + if not sensor_name: + return + try: + self._sensor_queue.put_nowait( + (sensor_name, data.astype(np.float32).ravel()) + ) + except queue.Full: + self._drop_stats.inc("sensor_queue") # 消费不及,丢弃旧数据 + + def write_glove_imu(self, sensor_name: str, quats, valid): + """USB 手套 IMU 四元数快照(主线程 → 写入线程,最新值覆盖)。 + + Args: + sensor_name: 传感器列名(如 "right_glove") + quats: 16×4 XYZW 四元数(64×float32 展平) + valid: 16×bool 有效掩码(展平) + """ + if self._writer is None or not self._recording or not sensor_name: + return + q = np.asarray(quats, dtype=np.float32).ravel()[:64] + v = np.asarray(valid, dtype=np.float32).ravel()[:16] + if q.size != 64 or v.size != 16: + return + with self._glove_imu_lock: + self._glove_imu[sensor_name] = (q, v) + + def _pop_glove_imu(self) -> Dict[str, tuple]: + """取走并清空本帧窗口内的手套 IMU 快照(写入线程调用)。""" + with self._glove_imu_lock: + snapshot = dict(self._glove_imu) + self._glove_imu.clear() + return snapshot + + def write_glove_keypoints(self, sensor_name: str, kpts): + """USB 手套骨架关键点快照(主线程 → 写入线程,最新值覆盖)。 + + Args: + sensor_name: 传感器列名(如 "left_glove") + kpts: 21×3 关节坐标(米,float32,展平 63 维) + """ + if self._writer is None or not self._recording or not sensor_name: + return + k = np.asarray(kpts, dtype=np.float32).ravel()[:63] + if k.size != 63 or not np.isfinite(k).all(): + return + with self._glove_kpts_lock: + self._glove_kpts[sensor_name] = k + + def _pop_glove_keypoints(self) -> Dict[str, np.ndarray]: + """取走并清空本帧窗口内的手套骨架快照(写入线程调用)。""" + with self._glove_kpts_lock: + snapshot = dict(self._glove_kpts) + self._glove_kpts.clear() + return snapshot + + @property + def last_recording_frames(self) -> Dict[str, int]: + """上一轮录制的每相机帧数(快照副本,用于录制完成回调的统计)。""" + return dict(self._last_recording_frames) + + @property + def last_drop_stats(self) -> Dict[str, int]: + """上一轮录制的丢帧统计(快照副本;含 imu_overflow 键)。""" + return dict(self._last_drop_stats) + + @property + def last_episode_index(self) -> int: + """上一轮录制的全局 episode 序号(v1.1.0 池化布局;1 起)。""" + return self._last_episode_index + + def finish_recording(self, slot_id: str): + """正常停止——最终化共享会话。""" + if not self._recording: + return + self._recording = False + self._timer_running = False + self._duration_timer.stop() + + # 等待写入线程退出 + if self._write_thread is not None and self._write_thread.is_alive(): + self._write_thread.join(timeout=3.0) + self._write_thread = None + + # 快照每相机帧数:_finish_async 在后台线程 emit 回调, + # 用户可能抢在回调前开始新一轮录制重置 _per_cam_frame + self._last_recording_frames = dict(self._per_cam_frame) + + # v1.0.9 丢帧统计快照(含 IMU 溢出次数):供录制完成回调提示与 + # writer 元数据回写;在 _finish_async(end_episode)之前注入 + self._last_drop_stats = self._drop_stats.snapshot() + self._last_drop_stats["imu_overflow"] = self._imu_overflow_count + if self._writer is not None: + self._writer.set_drop_stats(self._last_drop_stats) + + path = self._session_path + threading.Thread(target=self._finish_async, args=(path,), daemon=True).start() + + def _finish_async(self, path: str): + if self._writer: + self._writer.end_episode() + self._writer = None + self._session_path = None + self.session_changed.emit(None) + if path: + self.recording_finished.emit(self._recording_slot or "", path) + + def abort_recording(self, slot_id: str): + """异常停止——丢弃共享会话。""" + if not self._recording: + return + self._recording = False + self._timer_running = False + self._duration_timer.stop() + + # 等待写入线程退出 + if self._write_thread is not None and self._write_thread.is_alive(): + self._write_thread.join(timeout=3.0) + self._write_thread = None + + threading.Thread(target=self._abort_async, daemon=True).start() + + def _abort_async(self): + if self._writer: + self._writer.abort_episode() + self._writer = None + self._session_path = None + self.session_changed.emit(None) + self.recording_aborted.emit(self._recording_slot or "") + + @property + def elapsed(self) -> float: + if not self._recording: + return 0.0 + return time.monotonic() - self._start_time + + def _tick_duration(self): + """QTimer 回调 —— 主线程执行,无跨线程问题。""" + if self._recording: + self.duration_changed.emit(self._recording_slot or "", self.elapsed) diff --git a/collector/core/recording_record.py b/collector/core/recording_record.py new file mode 100755 index 0000000000000000000000000000000000000000..33f13169345a8e55fdc9188930340b4d3b0def1d --- /dev/null +++ b/collector/core/recording_record.py @@ -0,0 +1,30 @@ +""" +数据模型 —— 录制记录的数据类定义。 +""" + +from __future__ import annotations +from dataclasses import dataclass, field +from core.helpers import new_id, utcnow + + +@dataclass +class RecordingRecord: + """录制历史表中的一条记录。""" + + id: str = field(default_factory=new_id) + camera_index: int = 0 + camera_name: str = "" + file_path: str = "" # v1.1.0 池化:任务目录(一行 = 一个 episode) + episode_index: int = 0 # v1.1.0 池化:全局 episode 序号(1 起) + file_size_mb: float = 0.0 # 文件大小(MB) + duration_sec: float = 0.0 # 录制时长(秒) + resolution_w: int = 0 + resolution_h: int = 0 + status: str = "completed" # "completed"(已完成)| "aborted"(已丢弃)| "uploaded_deleted"(已上传,本地已删)| "deleted"(已删除,未上传) + started_at: str = field(default_factory=utcnow) + finished_at: str = field(default_factory=utcnow) + + @classmethod + def from_row(cls, row) -> RecordingRecord: + """从 sqlite3.Row 构造实例。""" + return cls(**dict(row)) diff --git a/collector/core/recording_repository.py b/collector/core/recording_repository.py new file mode 100755 index 0000000000000000000000000000000000000000..2fe9d5ef8085371119a623059fac3f17f08330f3 --- /dev/null +++ b/collector/core/recording_repository.py @@ -0,0 +1,94 @@ +""" +数据仓库层 —— 录制记录的增删改查操作。 +""" + +from typing import List, Optional +from core.database import db +from core.recording_record import RecordingRecord + + +class RecordingRepo: + """录制记录的 CRUD 仓库。""" + + @staticmethod + def save(r: RecordingRecord): + """保存(插入或替换)一条录制记录。""" + db.conn.execute( + """INSERT OR REPLACE INTO recording + (id, camera_index, camera_name, file_path, episode_index, + file_size_mb, duration_sec, resolution_w, resolution_h, + status, started_at, finished_at) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?)""", + (r.id, r.camera_index, r.camera_name, r.file_path, + r.episode_index, r.file_size_mb, r.duration_sec, + r.resolution_w, r.resolution_h, r.status, + r.started_at, r.finished_at), + ) + db.conn.commit() + + @staticmethod + def list_all(limit: int = 100) -> List[RecordingRecord]: + """按时间倒序返回最近 N 条录制记录。""" + rows = db.conn.execute( + "SELECT * FROM recording ORDER BY started_at DESC LIMIT ?", (limit,) + ).fetchall() + return [RecordingRecord.from_row(r) for r in rows] + + @staticmethod + def list_by_camera(camera_index: int, limit: int = 50) -> List[RecordingRecord]: + """按摄像机索引筛选录制记录。""" + rows = db.conn.execute( + "SELECT * FROM recording WHERE camera_index=? ORDER BY started_at DESC LIMIT ?", + (camera_index, limit), + ).fetchall() + return [RecordingRecord.from_row(r) for r in rows] + + @staticmethod + def delete(record_id: str): + """删除指定记录。""" + db.conn.execute("DELETE FROM recording WHERE id=?", (record_id,)) + db.conn.commit() + + @staticmethod + def _where(file_path: str, episode_index): + """匹配条件:v1.1.0 起按 (file_path, episode_index) 定位一个 episode; + episode_index 为 None 时退回旧路径匹配(历史行/旧调用方兼容)。""" + if episode_index is None: + return "file_path=?", (file_path,) + return "file_path=? AND episode_index=?", (file_path, episode_index) + + @staticmethod + def mark_uploaded(file_path: str, episode_index=None) -> int: + """把指定 episode 的录制行状态改为 uploaded(上传成功、本地保留)。 + + 行保留(历史可查"已上传"),返回受影响行数。 + """ + cond, args = RecordingRepo._where(file_path, episode_index) + cur = db.conn.execute( + f"UPDATE recording SET status='uploaded' WHERE {cond}", args) + db.conn.commit() + return cur.rowcount + + @staticmethod + def mark_uploaded_deleted(file_path: str, episode_index=None) -> int: + """把指定 episode 的录制行状态改为 uploaded_deleted(上传成功后本地已删)。 + + 行保留(用户要求历史可查"已上传,本地已删"),返回受影响行数。 + """ + cond, args = RecordingRepo._where(file_path, episode_index) + cur = db.conn.execute( + f"UPDATE recording SET status='uploaded_deleted' WHERE {cond}", args) + db.conn.commit() + return cur.rowcount + + @staticmethod + def mark_deleted(file_path: str, episode_index=None) -> int: + """把指定 episode 的录制行状态改为 deleted(本地已删、未上传)。 + + 行保留(历史可查"已删除,未上传"),返回受影响行数。 + """ + cond, args = RecordingRepo._where(file_path, episode_index) + cur = db.conn.execute( + f"UPDATE recording SET status='deleted' WHERE {cond}", args) + db.conn.commit() + return cur.rowcount diff --git a/collector/core/render_engine.py b/collector/core/render_engine.py new file mode 100755 index 0000000000000000000000000000000000000000..e7f8143a7d4ac5c9b02fec7ddda4e9f3c0840df8 --- /dev/null +++ b/collector/core/render_engine.py @@ -0,0 +1,768 @@ +""" +传感器数据渲染引擎 —— 5 种可视化模式。 + +所有渲染函数接收 (processed_data, max_signal, config, window_size) +返回 BGR 格式的 numpy 帧数组,由 UI 层转为 QPixmap 显示。 +""" + +import json +import os +import numpy as np +import cv2 + +from config import settings + +# ── 常量 ────────────────────────────────────────────── +MATRIX_ROWS = 16 +MATRIX_COLS = 16 +VIRIDIS_LUT: np.ndarray = None + +# ── 配置路径 ────────────────────────────────────────── +# 仿生手掌(左/右手)映射配置。原定义在 sensors.sensor_panel, +# 迁到这里:glove_widget / playback_dialog 需要路径但不应引入 bleak。 +CONFIG_DIR = os.path.join(settings.BASE_DIR, "config", "sensors") +CONFIG_FILE = os.path.join(CONFIG_DIR, "hand_ble_config.json") +CONFIG_FILE_LEFT = os.path.join(CONFIG_DIR, "hand_ble_config_left.json") + + +def _get_viridis_lut() -> np.ndarray: + """延迟初始化 Viridis 颜色查找表。""" + global VIRIDIS_LUT + if VIRIDIS_LUT is None: + lut = np.zeros((256, 1, 3), dtype=np.uint8) + for i in range(256): + lut[i, 0, 0] = i + VIRIDIS_LUT = cv2.applyColorMap(lut, cv2.COLORMAP_VIRIDIS) + return VIRIDIS_LUT + + +# ── HUD 绘制 ────────────────────────────────────────── + +def _draw_hud(frame: np.ndarray, lines: list, color=(255, 255, 255)): + """在帧左上角绘制半透明 HUD 信息栏。""" + font, scale, thick, lh, pad = cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1, 22, 10 + max_w = ( + max(cv2.getTextSize(l, font, scale, thick)[0][0] for l in lines) + if lines else 0 + ) + overlay = frame.copy() + cv2.rectangle( + overlay, (0, 0), (max_w + pad * 2, len(lines) * lh + pad * 2), + (0, 0, 0), -1, + ) + cv2.addWeighted(overlay, 0.5, frame, 0.5, 0, frame) + for i, line in enumerate(lines): + cv2.putText( + frame, line, (pad, pad + lh - 5 + i * lh), + font, scale, color, thick, cv2.LINE_AA, + ) + + +# ── 配置加载 ────────────────────────────────────────── + +def _load_json(path, default): + if os.path.exists(path): + try: + with open(path, "r", encoding="utf-8") as f: + loaded = json.load(f) + if isinstance(default, dict): + default.update(loaded) + return default + return loaded + except Exception: + pass + return default + + +# ═══════════════════════════════════════════════════════ +# 模式 1: 热力图 +# ═══════════════════════════════════════════════════════ + +def render_heatmap( + processed: np.ndarray, + max_signal: float, + config: dict, + window_size: tuple, + current_vmax: float, + fps: float, + noise_gate: int, + dyn_ratio: float, + spatial_on: bool, +) -> tuple: + """返回 (frame, new_vmax)。""" + ww, wh = window_size + rows = config.get("rows", list(range(16))) + cols = config.get("cols", list(range(16))) + order = config.get("axis_order", "row_col") + + # 增强参数(来自 config,向后兼容) + subpixel = config.get("subpixel", True) + gamma = config.get("gamma", 1.0) + blur_ksize = config.get("blur", 5) + + nr, nc = len(rows), len(cols) + if nr == 0 or nc == 0: + frame = np.zeros((wh, ww, 3), dtype=np.uint8) + _draw_hud(frame, ["Press [M] to select Heatmap Rows/Cols!"], (0, 0, 255)) + return frame, current_vmax + + # 提取子矩阵 + sub = processed[np.ix_(rows, cols)] + if order != "row_col": + sub = sub.T + + # ── Subpixel 超分 ────────────────────────────── + if subpixel and sub.shape[0] >= 2 and sub.shape[1] >= 2: + H0, W0 = sub.shape + shrink = 1.5 + padded = np.pad(sub, 1, mode='constant') + top = padded[0:H0, 1:W0 + 1] + bottom = padded[2:H0 + 2, 1:W0 + 1] + left = padded[1:H0 + 1, 0:W0] + right = padded[1:H0 + 1, 2:W0 + 2] + sum_x = left + right + sub + 1e-6 + sum_y = top + bottom + sub + 1e-6 + dx = np.clip((right - left) / sum_x * shrink, -1, 1) + dy = np.clip((bottom - top) / sum_y * shrink, -1, 1) + super_res = np.zeros((H0 * 2, W0 * 2), dtype=np.float32) + super_res[0::2, 0::2] = sub * np.maximum(0, 1.0 - dx - dy) + super_res[0::2, 1::2] = sub * np.maximum(0, 1.0 + dx - dy) + super_res[1::2, 0::2] = sub * np.maximum(0, 1.0 - dx + dy) + super_res[1::2, 1::2] = sub * np.maximum(0, 1.0 + dx + dy) + sub = super_res + + H, W = sub.shape + scale_w = (ww - 200) / W + scale_h = (wh - 120) / H + scale = min(scale_w, scale_h) + target_w = int(W * scale) + target_h = int(H * scale) + + resized = cv2.resize(sub, (target_w, target_h), interpolation=cv2.INTER_CUBIC) + if blur_ksize > 0: + k = blur_ksize if blur_ksize % 2 == 1 else blur_ksize + 1 + resized = cv2.GaussianBlur(resized, (k, k), 0) + + # 平滑 vmax + vmax_cand = max(5000, np.percentile(resized, 99.7)) + new_vmax = current_vmax * 0.95 + vmax_cand * 0.05 if vmax_cand > current_vmax else vmax_cand + + # ── Gamma 校正 ──────────────────────────────── + norm = np.clip(resized / new_vmax, 0, 1) if new_vmax > 0 else resized + if gamma != 1.0: + norm = np.power(norm, gamma) + img_8u = (norm * 255).astype(np.uint8) + color = cv2.applyColorMap(img_8u, cv2.COLORMAP_VIRIDIS) + + frame = np.zeros((wh, ww, 3), dtype=np.uint8) + sx = (ww - target_w) // 2 + sy = (wh - target_h) // 2 + 20 + frame[sy:sy + target_h, sx:sx + target_w] = color + + _draw_hud(frame, [ + f"Heatmap | FPS:{fps:.1f} | Max:{int(max_signal)}", + f"Gate:{noise_gate} | Dyn:{dyn_ratio:.2f} | Filter:{'ON' if spatial_on else 'OFF'}", + f"SP:{'ON' if subpixel else 'OFF'} G:{gamma:.1f} B:{blur_ksize} | [M] Config", + ]) + return frame, new_vmax + + +# ═══════════════════════════════════════════════════════ +# 模式 2: 轨迹模式 +# ═══════════════════════════════════════════════════════ + +_trace_canvas = None + +def render_trace( + processed: np.ndarray, + max_signal: float, + config: dict, + window_size: tuple, + current_vmax: float, + fps: float, + noise_gate: int, + dyn_ratio: float, + spatial_on: bool, +) -> tuple: + """轨迹模式:叠加历史数据。""" + global _trace_canvas + ww, wh = window_size + rows = config.get("rows", list(range(16))) + cols = config.get("cols", list(range(16))) + order = config.get("axis_order", "row_col") + + # 增强参数 + subpixel = config.get("subpixel", True) + gamma = config.get("gamma", 1.0) + blur_ksize = config.get("blur", 5) + + nr, nc = len(rows), len(cols) + if nr == 0 or nc == 0: + frame = np.zeros((wh, ww, 3), dtype=np.uint8) + _draw_hud(frame, ["Press hotkey to config"], (0, 0, 255)) + return frame, current_vmax, False + + sub = processed[np.ix_(rows, cols)] + if order != "row_col": + sub = sub.T + + # ── Subpixel 超分 ────────────────────────────── + if subpixel and sub.shape[0] >= 2 and sub.shape[1] >= 2: + H0, W0 = sub.shape + shrink = 1.5 + padded = np.pad(sub, 1, mode='constant') + top = padded[0:H0, 1:W0 + 1] + bottom = padded[2:H0 + 2, 1:W0 + 1] + left = padded[1:H0 + 1, 0:W0] + right = padded[1:H0 + 1, 2:W0 + 2] + sum_x = left + right + sub + 1e-6 + sum_y = top + bottom + sub + 1e-6 + dx = np.clip((right - left) / sum_x * shrink, -1, 1) + dy = np.clip((bottom - top) / sum_y * shrink, -1, 1) + super_res = np.zeros((H0 * 2, W0 * 2), dtype=np.float32) + super_res[0::2, 0::2] = sub * np.maximum(0, 1.0 - dx - dy) + super_res[0::2, 1::2] = sub * np.maximum(0, 1.0 + dx - dy) + super_res[1::2, 0::2] = sub * np.maximum(0, 1.0 - dx + dy) + super_res[1::2, 1::2] = sub * np.maximum(0, 1.0 + dx + dy) + sub = super_res + + if _trace_canvas is None or _trace_canvas.shape != sub.shape: + _trace_canvas = np.zeros_like(sub) + _trace_canvas = np.maximum(_trace_canvas, sub) + display = _trace_canvas + + H, W = display.shape + scale_w = (ww - 200) / W + scale_h = (wh - 120) / H + scale = min(scale_w, scale_h) + tw, th = int(W * scale), int(H * scale) + + resized = cv2.resize(display, (tw, th), interpolation=cv2.INTER_CUBIC) + if blur_ksize > 0: + k = blur_ksize if blur_ksize % 2 == 1 else blur_ksize + 1 + resized = cv2.GaussianBlur(resized, (k, k), 0) + + vmax_cand = max(5000, np.percentile(resized, 99.7)) + new_vmax = current_vmax * 0.95 + vmax_cand * 0.05 if vmax_cand > current_vmax else vmax_cand + + norm = np.clip(resized / new_vmax, 0, 1) if new_vmax > 0 else resized + if gamma != 1.0: + norm = np.power(norm, gamma) + img_8u = (norm * 255).astype(np.uint8) + color = cv2.applyColorMap(img_8u, cv2.COLORMAP_VIRIDIS) + + frame = np.zeros((wh, ww, 3), dtype=np.uint8) + sx, sy = (ww - tw) // 2, (wh - th) // 2 + 20 + frame[sy:sy + th, sx:sx + tw] = color + + _draw_hud(frame, [ + f"Trace | FPS:{fps:.1f} | Max:{int(max_signal)}", + f"Gate:{noise_gate} | Dyn:{dyn_ratio:.2f} | Filter:{'ON' if spatial_on else 'OFF'}", + f"SP:{'ON' if subpixel else 'OFF'} G:{gamma:.1f} B:{blur_ksize} | [X] Clear | [M] Config", + ]) + return frame, new_vmax, True + +def clear_trace_canvas(): + global _trace_canvas + _trace_canvas = None + + +# ═══════════════════════════════════════════════════════ +# 模式 3: 网格数据 +# ═══════════════════════════════════════════════════════ + +def render_grid( + processed: np.ndarray, + max_signal: float, + config: dict, + window_size: tuple, + fps: float, +) -> np.ndarray: + """网格模式:每个单元格显示数值。""" + ww, wh = window_size + rows = config.get("rows", list(range(16))) + cols = config.get("cols", list(range(16))) + order = config.get("axis_order", "row_col") + + nr, nc = len(rows), len(cols) + visual_rows = nr if order == "row_col" else nc + visual_cols = nc if order == "row_col" else nr + + if nr == 0 or nc == 0: + frame = np.zeros((wh, ww, 3), dtype=np.uint8) + _draw_hud(frame, ["Press hotkey to config"], (0, 0, 255)) + return frame + + cell_size = min((ww - 100) / max(1, visual_cols), (wh - 120) / max(1, visual_rows)) + cell_size = max(5.0, min(80.0, cell_size)) + + grid_w = int(visual_cols * cell_size) + grid_h = int(visual_rows * cell_size) + sx = (ww - grid_w) // 2 + sy = (wh - grid_h) // 2 + 30 + + frame = np.zeros((wh, ww, 3), dtype=np.uint8) + grid_vmax = max(5000.0, max_signal) + + for vi in range(visual_rows): + for vj in range(visual_cols): + if order == "row_col": + r_idx, c_idx = rows[vi], cols[vj] + else: + r_idx, c_idx = rows[vj], cols[vi] + if r_idx >= MATRIX_ROWS or c_idx >= MATRIX_COLS: + continue + + val = int(processed[r_idx, c_idx]) + x1 = int(sx + vj * cell_size) + y1 = int(sy + vi * cell_size) + x2 = int(sx + (vj + 1) * cell_size) + y2 = int(sy + (vi + 1) * cell_size) + + if val > 0: + blue = min(255, int((val / grid_vmax) * 255)) + cv2.rectangle(frame, (x1, y1), (x2, y2), (blue, 0, 0), -1) + cv2.rectangle(frame, (x1, y1), (x2, y2), (50, 50, 50), 1) + + if val > 0 and cell_size > 15: + fs = max(0.3, cell_size / 60.0) + text = str(val) + (tw, th), _ = cv2.getTextSize(text, cv2.FONT_HERSHEY_PLAIN, fs, 1) + if tw > cell_size * 0.9: + fs *= (cell_size * 0.9 / tw) + (tw, th), _ = cv2.getTextSize(text, cv2.FONT_HERSHEY_PLAIN, fs, 1) + cv2.putText( + frame, text, + (x1 + (int(cell_size) - tw) // 2, y1 + (int(cell_size) + th) // 2), + cv2.FONT_HERSHEY_PLAIN, fs, (255, 255, 255), 1, cv2.LINE_AA, + ) + + _draw_hud(frame, [ + f"Grid | FPS:{fps:.1f} | Max:{int(max_signal)}", + "[M] Config Matrix", + ]) + return frame + + +# ═══════════════════════════════════════════════════════ +# 模式 4: 仿生手掌 +# ═══════════════════════════════════════════════════════ + +# 手部锚点坐标(相对于窗口) +HAND_ANCHORS = { + "thumb_tip": (350, 280), "thumb_joint": (420, 360), "thumb_base": (480, 420), + "index_tip": (510, 120), "index_joint": (540, 240), "index_base": (560, 340), + "middle_tip": (640, 80), "middle_joint": (640, 200), "middle_base": (640, 320), + "ring_tip": (770, 120), "ring_joint": (740, 240), "ring_base": (720, 340), + "pinky_tip": (930, 280), "pinky_joint": (860, 360), "pinky_base": (800, 420), + "palm": (640, 480), +} +WRIST_ANCHOR = (640, 600) + +# 默认手部配置(16×16 传感器映射到手指区域) +# 右手实测(2026-09-04 录制逐格核对):行 = 手指,拇指 1-3 … 小指 +# 13-15(行 0 为空),即旧配置 [0-2…12-14] 整体偏高一行的修正; +# 列 12-15 = 指骨 [14,12,13,15] 根→尖;掌心行 1-15 x 传感列 [10,9,8,6,4]。 +DEFAULT_HAND = { + "thumb_joint": {"rows": [1, 2, 3], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "index_joint": {"rows": [4, 5, 6], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "middle_joint": {"rows": [7, 8, 9], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "ring_joint": {"rows": [10, 11, 12], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "pinky_joint": {"rows": [13, 14, 15], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "palm": {"rows": list(range(1, 16)), "cols": [10, 9, 8, 6, 4], "axis_order": "col_row"}, +} +for k in DEFAULT_HAND: + if k != "palm": + DEFAULT_HAND[k]["name"] = k + + +def _scale_point(x: float, y: float, sx: float, sy: float) -> tuple: + """按缩放因子缩放坐标点。""" + return (int(x * sx), int(y * sy)) + + +def render_hand( + processed: np.ndarray, + max_signal: float, + config: dict, + window_size: tuple, + current_vmax: float, + fps: float, + noise_gate: int, + dyn_ratio: float, + spatial_on: bool, + drift: float, +) -> tuple: + """仿生手掌映射模式。 + + 硬编码锚点坐标基于 1280×720 画布设计,运行时根据实际 window_size + 等比缩放,适配任意尺寸(如回放面板的 640×400)。 + """ + ww, wh = window_size + + # ── 计算缩放因子(锚点基于 1280×720 设计) ────────── + NOM_W, NOM_H = 1280.0, 720.0 + sx = ww / NOM_W + sy = wh / NOM_H + + frame = np.full((wh, ww, 3), 15, dtype=np.uint8) + lut = _get_viridis_lut() + + # ── 缩放后的锚点 ──────────────────────────────────── + def _sp(x, y): + return _scale_point(x, y, sx, sy) + + wrist = _sp(*WRIST_ANCHOR) + scaled_anchors = {k: _sp(*v) for k, v in HAND_ANCHORS.items()} + + # ── 缩放线宽和圆半径 ────────────────────────────── + lw_scale = min(sx, sy) + _lw = lambda v: max(1, int(v * lw_scale)) + _cr = lambda v: max(1, int(v * lw_scale)) + + # 画骨骼框架 + line_c, joint_c = (60, 60, 60), (80, 80, 80) + cv2.line(frame, wrist, scaled_anchors["palm"], line_c, _lw(6), cv2.LINE_AA) + for fg in ["thumb", "index", "middle", "ring", "pinky"]: + b = scaled_anchors[f"{fg}_base"] + j = scaled_anchors[f"{fg}_joint"] + t = scaled_anchors[f"{fg}_tip"] + cv2.line(frame, scaled_anchors["palm"], b, line_c, _lw(5), cv2.LINE_AA) + cv2.line(frame, b, j, line_c, _lw(4), cv2.LINE_AA) + cv2.line(frame, j, t, line_c, _lw(3), cv2.LINE_AA) + cv2.circle(frame, b, _cr(10), joint_c, -1, cv2.LINE_AA) + cv2.circle(frame, j, _cr(8), joint_c, -1, cv2.LINE_AA) + cv2.circle(frame, t, _cr(6), joint_c, -1, cv2.LINE_AA) + cv2.circle(frame, scaled_anchors["palm"], _cr(16), joint_c, -1, cv2.LINE_AA) + + # 平滑 vmax + vmax = max(max_signal, 5000) + new_vmax = current_vmax * 0.95 + vmax * 0.05 if vmax < current_vmax else vmax + + CELL = max(1, int(14 * min(sx, sy))) + for part_key, cfg in config.items(): + if part_key not in scaled_anchors: + continue + ax, ay = scaled_anchors[part_key] + rows = cfg.get("rows", []) + cols = cfg.get("cols", []) + order = cfg.get("axis_order", "row_col") + if not rows or not cols: + continue + + nrr, ncc = len(rows), len(cols) + w = ncc * CELL if order == "row_col" else nrr * CELL + h = nrr * CELL if order == "row_col" else ncc * CELL + cx, cy = ax - w // 2, ay - h // 2 + + for i, r in enumerate(rows): + for j, c in enumerate(cols): + if r >= MATRIX_ROWS or c >= MATRIX_COLS: + continue + val = processed[r, c] + x1 = cx + (j if order == "row_col" else i) * CELL + y1 = cy + (i if order == "row_col" else j) * CELL + x2, y2 = x1 + CELL, y1 + CELL + + if val > 0: + idx = int(min(255, (val / new_vmax) * 255)) + b, g, rr = lut[idx, 0] + cv2.rectangle(frame, (x1, y1), (x2, y2), (int(b), int(g), int(rr)), -1) + # 单元格内显示数据值 + if CELL > 14: + vtext = str(int(val)) + fs = 0.4 + (tw, th), _ = cv2.getTextSize(vtext, cv2.FONT_HERSHEY_PLAIN, fs, 1) + tc = (0, 0, 0) if (0.299 * rr + 0.587 * g + 0.114 * b) > 140 else (255, 255, 255) + cv2.putText(frame, vtext, + (x1 + (CELL - tw) // 2, y1 + (CELL + th) // 2), + cv2.FONT_HERSHEY_PLAIN, fs, tc, 1, cv2.LINE_AA) + cv2.rectangle(frame, (x1, y1), (x2, y2), (100, 100, 100), 1) + + _draw_hud(frame, [ + f"Bionic Hand | FPS:{fps:.1f} | Max:{int(max_signal)} | Drift:{int(drift)}", + f"Gate:{noise_gate} | Dyn:{dyn_ratio:.2f} | Filter:{'ON' if spatial_on else 'OFF'}", + "[M] Config | [C] Calibrate", + ]) + return frame, new_vmax + + +# ═══════════════════════════════════════════════════════ +# 模式 5: 拓扑形变 +# ═══════════════════════════════════════════════════════ + +class DeformMeshState: + """模式5 的交互状态。""" + + def __init__(self): + self.holes = [] + self.flip_x = False + self.flip_y = False + self.deform_strength = 1.0 + self.cached_x = None + self.cached_y = None + self.cache_valid = False + # 绘制中 + self.drawing = False + self.draw_start = (0, 0) + self.draw_end = (0, 0) + + +def _update_mesh_cache(state: DeformMeshState, rows, cols, order, ww, wh): + """更新形变网格缓存。""" + nr, nc = len(rows), len(cols) + if nr == 0 or nc == 0: + state.cached_x = state.cached_y = None + return + + CELL = 26 + tw = nc * CELL if order == "row_col" else nr * CELL + th = nr * CELL if order == "row_col" else nc * CELL + sx = (ww - tw) // 2 + sy = (wh - th) // 2 + 30 + + jj, ii = np.meshgrid(np.arange(nc), np.arange(nr)) + if order == "row_col": + mx = sx + jj * CELL + my = sy + ii * CELL + else: + mx = sx + ii * CELL + my = sy + jj * CELL + + if state.flip_x: + mx, my = np.fliplr(mx), np.fliplr(my) + if state.flip_y: + mx, my = np.flipud(mx), np.flipud(my) + + # 应用孔洞形变 + holes = list(state.holes) + if state.drawing: + cx1, cy1 = state.draw_start + cx2, cy2 = state.draw_end + rx, ry = max(1, abs(cx2 - cx1)), max(1, abs(cy2 - cy1)) + if rx > 5 and ry > 5: + holes.append({"cx": cx1, "cy": cy1, "rx": rx, "ry": ry}) + + for h in holes: + cx, cy, rx, ry = h["cx"], h["cy"], h["rx"], h["ry"] + vx, vy = mx - cx, my - cy + d = np.sqrt((vx / rx) ** 2 + (vy / ry) ** 2) + 1e-6 + target_d = d + state.deform_strength * np.exp(-d * 1.5) + scale = target_d / d + mx = cx + vx * scale + my = cy + vy * scale + + state.cached_x, state.cached_y = mx, my + state.cache_valid = True + + +def render_deform_mesh( + processed: np.ndarray, + max_signal: float, + config: dict, + window_size: tuple, + current_vmax: float, + fps: float, + state: DeformMeshState, +) -> tuple: + """拓扑形变模式。""" + ww, wh = window_size + frame = np.full((wh, ww, 3), 15, dtype=np.uint8) + lut = _get_viridis_lut() + + vmax = max(5000, max_signal) + new_vmax = current_vmax * 0.95 + vmax * 0.05 if vmax < current_vmax else vmax + + rows = config.get("rows", list(range(16))) + cols = config.get("cols", list(range(16))) + order = config.get("axis_order", "row_col") + + if not state.cache_valid: + _update_mesh_cache(state, rows, cols, order, ww, wh) + + mx, my = state.cached_x, state.cached_y + if mx is None: + _draw_hud(frame, ["Press [M] to select Matrix Rows/Cols!"], (0, 0, 255)) + return frame, new_vmax + + nr, nc = len(rows), len(cols) + + # 画网格线 + pts = np.stack([mx, my], axis=-1).astype(np.int32) + cv2.polylines(frame, pts, False, (60, 60, 60), 1, cv2.LINE_AA) + pts_t = np.ascontiguousarray(np.transpose(pts, (1, 0, 2))) + cv2.polylines(frame, pts_t, False, (60, 60, 60), 1, cv2.LINE_AA) + + # 画孔洞 + holes = list(state.holes) + if state.drawing: + cx1, cy1 = state.draw_start + cx2, cy2 = state.draw_end + rx, ry = max(1, abs(cx2 - cx1)), max(1, abs(cy2 - cy1)) + if rx > 5 and ry > 5: + holes.append({"cx": cx1, "cy": cy1, "rx": rx, "ry": ry}) + for h in holes: + cv2.ellipse(frame, (h["cx"], h["cy"]), (h["rx"], h["ry"]), + 0, 0, 360, (90, 90, 90), 2, cv2.LINE_AA) + + # 画数据点 + for i in range(nr): + for j in range(nc): + ri, cj = rows[i], cols[j] + if ri >= MATRIX_ROWS or cj >= MATRIX_COLS: + continue + val = processed[ri, cj] + px, py = int(mx[i, j]), int(my[i, j]) + if val > 0: + idx = int(min(255, (val / new_vmax) * 255)) + b, g, rr = lut[idx, 0] + cv2.circle(frame, (px, py), 10, (int(b), int(g), int(rr)), -1, cv2.LINE_AA) + else: + cv2.circle(frame, (px, py), 3, (80, 80, 80), -1, cv2.LINE_AA) + + s = state.deform_strength + _draw_hud(frame, [ + f"Deform Mesh | FPS:{fps:.1f} | Max:{int(max_signal)} | Strength:{s:.1f}", + f"Flip X:{state.flip_x} | Flip Y:{state.flip_y}", + "[Drag] Draw Hole | [R] Clear | [U/I] Flip | [O/P] Strength | [M] Config", + ]) + return frame, new_vmax + + +# ═══════════════════════════════════════════════════════ +# 手部骨架渲染(MANO 21 关键点 → 3/4 视角透视画面) +# +# 移植自手套工具包 apps/rendering/replay.py 的 Camera/_grid/ +# _draw_hand(画布尺寸参数化)。tools/demos/pooled_viewer_demo +# 另有同口径自包含副本(demo 不导入 core,两边保持同步即可)。 +# ═══════════════════════════════════════════════════════ + +# MANO 21 关键点骨骼连接 + 分组: 0 拇指 1 食指 2 中指 3 无名指 4 小指 5 掌骨 +SKELETON_BONES = [ + (0, 1, 0), (1, 2, 0), (2, 3, 0), (3, 4, 0), # thumb + (0, 5, 1), (5, 6, 1), (6, 7, 1), (7, 8, 1), # index + (0, 9, 2), (9, 10, 2), (10, 11, 2), (11, 12, 2), # middle + (0, 13, 3), (13, 14, 3), (14, 15, 3), (15, 16, 3), # ring + (0, 17, 4), (17, 18, 4), (18, 19, 4), (19, 20, 4), # pinky + (5, 9, 5), (9, 13, 5), (13, 17, 5), # metacarpal +] +# 每根手指分组颜色(BGR) +SKELETON_FINGER_BGR = [ + (60, 80, 255), # 0 拇指 红 + (60, 255, 255), # 1 食指 黄 + (60, 220, 60), # 2 中指 绿 + (255, 210, 60), # 3 无名指 青 + (255, 120, 255), # 4 小指 紫 + (210, 210, 210), # 5 掌骨 白 +] + +_SKELETON_FOV_DEG = 50.0 + + +class SkeletonCamera: + """球坐标相机 + 透视投影(照工具包 replay.py 的 Camera,画布尺寸参数化)。""" + + def __init__(self, yaw_deg, elev_deg, dist, img_w, img_h, roll_deg=0.0): + yaw, elev = np.deg2rad(yaw_deg), np.deg2rad(elev_deg) + roll = np.deg2rad(roll_deg) + cp = np.array([dist * np.cos(elev) * np.sin(yaw), + dist * np.sin(elev), + dist * np.cos(elev) * np.cos(yaw)]) + self.pos = cp + self.fwd = -cp / np.linalg.norm(cp) + self.right = np.cross(self.fwd, [0, 1, 0]) + self.right /= np.linalg.norm(self.right) + self.up = np.cross(self.right, self.fwd) + cos_r, sin_r = np.cos(roll), np.sin(roll) + r0, u0 = self.right, self.up + self.right = r0 * cos_r + u0 * sin_r + self.up = -r0 * sin_r + u0 * cos_r + self.w, self.h = img_w, img_h + self.f = (self.h / 2) / np.tan(np.deg2rad(_SKELETON_FOV_DEG) / 2) + + def project(self, pts3d): + """(N,3) → (N,2) 图像坐标 + (N,) 深度(相机前方为正)。""" + v = pts3d - self.pos + z = v @ self.fwd + x = v @ self.right + y = v @ self.up + u = self.f * x / z + self.w / 2 + vv = self.h / 2 - self.f * y / z + return np.stack([u, vv], -1), z + + +def fit_skeleton_dist(kpts): + """按手部空间尺度定相机距离(照工具包 replay.py)。""" + v = kpts[np.isfinite(kpts).all(axis=-1)] + if len(v) == 0: + return 0.5 + r = float(np.abs(v).max()) + return max(0.25, r * 2.6 + 0.1) + + +def _skeleton_bg(w, h): + img = np.full((h, w, 3), 12, np.uint8) + for y in range(h): + img[y] = np.full(3, 10 + int(10 * y / h), np.uint8) + return img + + +def _skeleton_grid(img, cam, r): + """z=0 平面网格 + 三色坐标轴(照工具包 replay.py 的 _grid)。""" + x = [(i / 6) * r for i in range(-6, 7)] + lines = ([([v, -r, 0.0], [v, r, 0.0]) for v in x] + + [([-r, v, 0.0], [r, v, 0.0]) for v in x]) + for p0, p1 in lines: + pts, z = cam.project(np.array([p0, p1], np.float32)) + if (z > 0).all(): + cv2.line(img, tuple(pts[0].astype(int)), tuple(pts[1].astype(int)), + (40, 44, 52), 1, cv2.LINE_AA) + origin = np.zeros((3,), np.float32) + for axis, col in [(np.array([r, 0.0, 0.0]), (40, 60, 255)), # X 红 + (np.array([0.0, r, 0.0]), (40, 255, 60)), # Y 绿 + (np.array([0.0, 0.0, r]), (255, 60, 40))]: # Z 蓝 + pts, z = cam.project(np.stack([origin, axis])) + if (z > 0).all(): + cv2.line(img, tuple(pts[0].astype(int)), tuple(pts[1].astype(int)), + col, 2, cv2.LINE_AA) + + +def _draw_skeleton_hand(img, cam, kpts): + """深度着色的骨骼连线 + 白色关节点(照工具包 replay.py 的 _draw_hand)。""" + pts, z = cam.project(kpts) + vis = np.isfinite(kpts).all(axis=1) & (z > 0) + # 近亮远暗的深度着色;手指比掌骨略亮 + zmin, zmax = 0.05, 0.6 + lum = np.clip((zmax - z) / (zmax - zmin), 0.35, 1.0) + for a, b, g in SKELETON_BONES: + if vis[a] and vis[b]: + k = 0.5 * (lum[a] + lum[b]) + col = tuple(int(c * k) for c in SKELETON_FINGER_BGR[g]) + cv2.line(img, tuple(pts[a].astype(int)), tuple(pts[b].astype(int)), + col, 3, cv2.LINE_AA) + for p, ok in zip(pts, vis): + if ok: + cv2.circle(img, tuple(p.astype(int)), 2, (255, 255, 255), -1, + cv2.LINE_AA) + + +def render_skeleton(kpts, w=640, h=420, dist=None, label=""): + """单手骨架面板(固定 3/4 视角;dist 传入为帧间防抖后的距离)。 + + Args: + kpts: (21,3) float 关键点(米) + dist: 相机距离(None → 按当前帧 fit_skeleton_dist) + Returns: + BGR 画布 + """ + if dist is None: + dist = fit_skeleton_dist(kpts) + img = _skeleton_bg(w, h) + cam = SkeletonCamera(yaw_deg=-25.0, elev_deg=15.0, dist=dist, + img_w=w, img_h=h) + _skeleton_grid(img, cam, fit_skeleton_dist(kpts) * 0.5) + _draw_skeleton_hand(img, cam, kpts) + if label: + cv2.putText(img, label, (12, 24), cv2.FONT_HERSHEY_SIMPLEX, 0.7, + (240, 240, 240), 2, cv2.LINE_AA) + return img diff --git a/collector/core/s80m_manager.py b/collector/core/s80m_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..5f1c0c81b948796c7f1a0addd12a76a480d52efd --- /dev/null +++ b/collector/core/s80m_manager.py @@ -0,0 +1,560 @@ +""" +S80M 双目设备管理器 —— 子进程生命周期、stdout 帧管道读取、曝光协议与 +50→30 抽帧口径(QtCore QObject + 信号,不依赖 QtWidgets)。 + +自包含双目模块:tools/stereo_s80m/ 内含 read_stereo_rgb.py + +libfays_vikit.so (3.9.0) + fays_vikit.yaml,与外部 SDK 目录完全独立—— +外部目录 git 更新、跑官方 demo 均不影响 DAQ 程序。 + + - S80MDeviceManager 每台一个条目:Popen 子进程 / stdin 曝光通道 / + watchdog / stdout 帧读取线程 / 临时 50fps yaml + - frame_record_decision 录制 50→30 抽帧纯口径(wall 时钟每 1/30s 桶保留首帧,突发补录) + - s80m_drop_watch 录制期空桶统计纯口径(wall 时钟,超阈值由 UI 告警) + - load_default_exposure 「恢复默认」基线(yaml stereo_init_exposure) + +帧信号 frame_ready(str, ndarray, object, list) 与深度信号 +depth_ready(str, ndarray, object) 的 hw_ns 必须用 object 封装:PyQt5 +队列信号把 Python int 按 C++ qint32 封送,超过 2^31 (≈2.1s 纳秒) +即静默截断为负数,录制数据受害。 +""" + +from __future__ import annotations + +import os +import sys +import struct +import shutil +import tempfile +import threading +import subprocess + +import numpy as np +import cv2 + +from PyQt5.QtCore import QObject, pyqtSignal, QTimer + +from config import settings +from config.i18n import tr + +# ★ 自包含双目模块:tools/stereo_s80m/(路径锚定仓库根,不随 cwd 漂移) +SDK_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + "tools", "stereo_s80m") +STEREO_DEMO = os.path.join(SDK_ROOT, "read_stereo_rgb.py") +STEREO_AVAILABLE = os.path.isfile(STEREO_DEMO) +STEREO_CFG_25 = os.path.join(SDK_ROOT, "config", "fays_vikit.yaml") +STEREO_CFG_50 = os.path.join(SDK_ROOT, "config", "fays_vikit_50fps.yaml") +# 相机档(settings.STEREO_CAM_FPS):50=默认,50→30 桶抽帧才有真 30fps +# 录制(回调取帧已根治 SDK 交付撕裂,官方 GUI 同款组合);25=回退档 +#(25fps 相机下 30 桶只填到 25 帧,录制内容等效 25fps) +STEREO_CFG = STEREO_CFG_50 if settings.STEREO_CAM_FPS >= 50 else STEREO_CFG_25 + +# S80C 深度:SDK 深度引擎自包含包(third_party/ 内 vikit 3.9.0 + +# 深度库 + OpenCV 4.2 + 深度配置/model,与 hand_3d_s80c 共用) +DEPTH_SDK_ROOT = os.path.join(os.path.dirname(os.path.dirname( + os.path.abspath(__file__))), "tools", "hand_3d_s80c", "third_party") + +# 回调取帧桥接(官方 GUI 同款消费方案;shim 在 S80C 自包含包内)。 +# 轮询 GetStereoFrames + 深度引擎绑定叠加会在交付帧内留下水平错位带 +#(8/31 主程序录制回归:25fps 档降缝率但不根治)——回调在 SDK 装配 +# 完成后才触发、帧必完整。settings.STEREO_CB_BRIDGE 关掉即回轮询; +# shim 缺失/注册失败子进程也自动回退(协议不变)。 +CB_BRIDGE_LIB = os.path.join(DEPTH_SDK_ROOT, "cb_bridge", + "libfays_cb_bridge.so") + + +def s80m_depth_available() -> bool: + """S80C 深度可用性:开关开 + 深度包关键文件齐备。 + + 关闭(settings.S80M_DEPTH_ENABLED=False)→ spawn 不传 --depth-sdk-dir, + 子进程协议无深度块、零深度 CPU 开销(与旧版逐字节一致)。 + """ + if not settings.S80M_DEPTH_ENABLED: + return False + return all(os.path.isfile(p) for p in ( + os.path.join(DEPTH_SDK_ROOT, "lib", "libfays_vikit.so"), + os.path.join(DEPTH_SDK_ROOT, "lib", "libfayssense_aikit_depth.so"), + os.path.join(DEPTH_SDK_ROOT, "config", "stereo_depth.yaml"), + os.path.join(DEPTH_SDK_ROOT, "config", "models", + "rk3588", "stereo_s_general.rknn"), + )) and os.path.isdir(os.path.join(DEPTH_SDK_ROOT, "opencv4.2", "lib406")) + + +def load_default_exposure() -> tuple: + """「恢复默认」基线:SDK 无曝光读回接口,出厂值即 yaml + stereo_init_exposure(-1 = 自动曝光,1.0~885.0 = 手动)。""" + try: + import yaml as _yaml + with open(STEREO_CFG, encoding="utf-8") as _f: + _si = float(_yaml.safe_load(_f).get( + "stereo_init_exposure", 400.0)) + return (_si < 0, 400.0 if _si < 0 else _si) + except Exception: + return (False, 400.0) + + +def frame_record_decision(entry: dict | None, slot_id: str, + hardware_ns: int, mono_ns: int, + imu_samples: list) -> tuple: + """相机帧 / 30fps 采集抽帧:wall 时钟每 1/30s 桶保留首帧,突发补录。 + + 正常节奏(帧距 20ms)按 wall 桶取每桶首帧:桶号用调用方到达时刻 + mono_ns(time.monotonic_ns,与视频 PTS 同源)而非 hardware_ns—— + 传感器 hw 时钟会跳变(实测 400ms),按 hw 桶会把跳变区间整段判成 + 空桶 → 30fps 抽帧每次稳定缺帧;wall 口径下 hw 跳变不影响抽帧率。 + + 突发补录:主进程卡顿(编码器子进程启动/GIL 争抢)期间帧堆积在 + 队列里,恢复后集中处理时 mono 间隔 <10ms 且落在同一 wall 桶—— + 这些帧的真实时间差在 hw 上仍逐桶推进,按 hw 桶号 ≥1 补录;正常 + 20ms 节奏的同桶第二帧 mono 间隔 ≥10ms,不受影响,输出恒 30fps。 + 补录帧由写线程 30fps 均匀消费(配合深外部队列),视频时间轴延后 + 但不出空洞。 + + 左右目同 ts 天然同步;hw_ns==0 兜底全录(无时间戳可依)。被抽掉帧 + 携带的 IMU 块累积到下一帧(stereo_left 主槽),不丢样本。entry 至少 + 带 last_bucket / pending_imu 键(由 S80MDeviceManager.new_entry 初始化, + 离线测试假条目同款形状)。返回 (record, imu_batch)。 + """ + record = True + imu_batch = imu_samples + if entry is not None and hardware_ns > 0: + interval_ns = int(settings.STEREO_RECORD_MIN_INTERVAL_S * 1e9) + wall_b = mono_ns // interval_ns + hw_b = hardware_ns // interval_ns + prev = entry["last_bucket"].get(slot_id) + if prev is not None: + if wall_b == prev["wall"]: + # 同 wall 桶:突发补录(mono 间隔 <10ms = 队列积压集中 + # 处理,帧真实间隔看 hw 桶推进);正常节奏同桶第二帧 + # (mono 间隔 ≈20ms)跳过 + record = (mono_ns - prev["mono"] < _BURST_MONO_GAP_NS + and hw_b >= prev["hw"] + 1) + else: + record = True + if record: + entry["last_bucket"][slot_id] = { + "wall": wall_b, "hw": hw_b, "mono": mono_ns} + if slot_id == "stereo_left": + if record: + if entry["pending_imu"]: + imu_batch = entry["pending_imu"] + (imu_samples or []) + entry["pending_imu"] = [] + else: + entry["pending_imu"].extend(imu_samples or []) + return record, imu_batch + + +# 突发补录判定:同 wall 桶内 mono 间隔低于此值视为队列积压集中处理 +# (正常 50fps 节奏帧距 20ms;Qt 队列事件连续处理间隔亚毫秒级) +_BURST_MONO_GAP_NS = 10_000_000 + +# 空桶告警阈值:录制期空桶率超过此值弹一次告警(8/28 健康录制 ~2%; +# 9/2 三槽齐录实测 ~15%,视频 PTS 与数据时间轴错位 ~1.2s) +STEREO_DROP_ALERT_RATE = 0.10 + + +def s80m_drop_watch(entry: dict | None, mono_ns: int, + interval_ns: int) -> tuple: + """录制期空桶统计(stereo_left 主槽口径,纯函数可离线测)。 + + 用 wall 时钟(time.monotonic_ns,与 data 帧时间戳同源)而非 + hardware_ns:传感器时钟跳变(实测 400ms)按 hw 桶统计会误计 + 为丢桶,wall 口径与"视频 PTS 均匀 30fps、数据时间轴被拉长" + 的错位症状一致。每帧推进:跨过的桶数 elapsed=⌊gap/interval⌋, + 跨 k≥2 桶即计 k-1 个空桶;间隔 20ms 的同桶弃帧自然不误计。 + hw_ns==0 兜底全录时帧距 20ms 跨 0 桶,统计恒 0 不告警。 + + entry 需带 drop_watch 键(new_entry 初始化、录制起止由 + device_manager.reset_s80m_record_state 重置)。返回 + (本帧新增空桶, 累计空桶, 累计桶数);entry 为 None 返回 (0, 0, 0)。 + """ + if entry is None: + return (0, 0, 0) + w = entry["drop_watch"] + last = w["last_mono_ns"] + new_drops = 0 + if last is not None and mono_ns > last: + elapsed = (mono_ns - last) // interval_ns + if elapsed >= 2: + new_drops = elapsed - 1 + w["dropped"] += new_drops + w["elapsed"] += elapsed + w["last_mono_ns"] = mono_ns + return (new_drops, w["dropped"], w["elapsed"]) + + +class S80MDeviceManager(QObject): + """S80M 双目子进程生命周期管理(每台一个条目)。 + + 信号 + ---- + frame_ready(str, np.ndarray, object, list) + — (slot_id, frame, hw_ns, imu_samples),reader 线程 → 主线程 + depth_ready(str, np.ndarray, object) + — (depth_slot, depth_uint16_mm, hw_ns),子进程 SDK 深度引擎输出 + (--depth-sdk-dir 模式;hw_ns 同帧 SDK 硬件纳秒时钟) + device_closed(str) + — dev_key,进程/文件/线程清理完毕;UI 侧注销管线源、拆槽、 + 清标定由调用方槽执行(顺序与原 _close_s80m 一致) + log(str) + — 跨线程日志 + + reader 线程与 watchdog 不触碰 UI;主线程创建、QObject 亲和性在主线程。 + """ + + frame_ready = pyqtSignal(str, np.ndarray, object, list) + depth_ready = pyqtSignal(str, np.ndarray, object) + device_closed = pyqtSignal(str) + log = pyqtSignal(str) + + def __init__(self, pipeline, parent=None): + super().__init__(parent) + self._pipeline = pipeline + self._entries: dict = {} # dev_key → 注册表条目(与主窗口共享同一 dict) + self.shutting_down = False + + @staticmethod + def new_entry(label: str) -> dict: + """注册表条目骨架(kind/slots/label 由主窗口注册,进程字段由 spawn 填充)。""" + return { + "kind": "s80m", + # 深度可用时设备 meta 多记录一路深度槽(spawn 后真实生效) + "slots": ["stereo_left", "stereo_right"] + + (["stereo_depth"] if s80m_depth_available() else []), + "label": label, + "proc": None, + "stdin": None, # 曝光命令通道(close 时关闭) + "stderr_file": None, + "config_file": None, + "original_exp": None, # 恢复默认基线(yaml 出厂值) + "watchdog": None, + "reader_thread": None, + "depth_active": False, # spawn 后填充:子进程协议带深度块 + "last_bucket": {}, # 50→30 抽帧:每槽最近保留帧 {wall,hw,mono}(突发补录口径) + "pending_imu": [], # 被抽掉帧的 IMU 块缓冲(随下一帧落盘) + "drop_watch": { # 录制期空桶统计(wall 时钟,UI 告警用) + "last_mono_ns": None, + "dropped": 0, # 累计空桶数 + "elapsed": 0, # 累计跨过的桶数(= 已填桶 + 空桶) + "alerted": False, # 本段已弹过一次告警 + }, + } + + def spawn(self, dev_key: str, entry: dict) -> bool: + """启动子进程 + watchdog + reader 线程,填充 entry 进程字段。 + + 用户已在 video 组,无需 sudo(sudo 在 no-new-privileges 环境下会 + 直接失败)。stdout 管道传帧数据(--pipe -),避免 FIFO 文件权限 + 问题(AppArmor)。 + """ + if not STEREO_AVAILABLE: + return False + + # ★ 相机档 / 30fps 采集:SDK 跑 STEREO_CAM_FPS 档 yaml 副本(tempfile + # 拷贝,仓库内原文件不动,关闭时清理),录制按 wall 时钟 1/30s 桶抽帧 + cfg_tmp = None + cfg_args = [] + if os.path.isfile(STEREO_CFG): + cfg_tmp = tempfile.mktemp(suffix="_s80m_cam.yaml") + shutil.copyfile(STEREO_CFG, cfg_tmp) + cfg_args = ["--config", cfg_tmp] + entry["original_exp"] = load_default_exposure() + + stereo_stderr = tempfile.mktemp(suffix="_s80m_stderr.log") + # 深度模式:cmd 追加 --depth-sdk-dir + env 注入 lib406 + # (深度库依赖链用裸 SONAME 必须靠动态链接器搜索路径解析; + # venv cv2 走自身 rpath 绑自家 OpenCV,不受影响) + depth_args = [] + spawn_env = None + if s80m_depth_available(): + depth_args = ["--depth-sdk-dir", DEPTH_SDK_ROOT] + _lib406 = os.path.join(DEPTH_SDK_ROOT, "opencv4.2", "lib406") + spawn_env = dict(os.environ) + spawn_env["LD_LIBRARY_PATH"] = _lib406 + ":" + \ + spawn_env.get("LD_LIBRARY_PATH", "") + entry["depth_active"] = bool(depth_args) + # 回调取帧(官方 GUI 同款;开关/shim 齐备才传,子进程另有回退) + cb_args = (["--cb-bridge"] + if settings.STEREO_CB_BRIDGE and os.path.isfile(CB_BRIDGE_LIB) + else []) + # stdin 管道 = 曝光控制通道(行协议 "SET_EXPOSURE ", + # SDK 运行时生效无需重启;子进程句柄创建完成前命令先积在管道缓冲) + proc = subprocess.Popen( + [sys.executable, STEREO_DEMO, "--pipe", "-"] + cfg_args + + depth_args + cb_args, + cwd=SDK_ROOT, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=open(stereo_stderr, "w"), + env=spawn_env, + ) + entry.update(proc=proc, stdin=proc.stdin, + stderr_file=stereo_stderr, config_file=cfg_tmp) + self._entries[dev_key] = entry + + # 监控子进程退出(定时检查) + watchdog = QTimer(self) + watchdog.setInterval(1000) + watchdog.timeout.connect( + lambda key=dev_key: self.check_alive(key)) + watchdog.start() + entry["watchdog"] = watchdog + + # 启动帧读取线程 + reader = threading.Thread( + target=self.read_pipe, args=(dev_key,), daemon=True) + entry["reader_thread"] = reader + reader.start() + return True + + def read_pipe(self, dev_key: str): + """从子进程 stdout 管道读取双目帧,经 frame_ready 信号发主线程。""" + entry = self._entries.get(dev_key) + if not entry or entry["kind"] != "s80m": + return + fifo = entry["proc"].stdout # subprocess.PIPE 的读端 + self.log.emit(tr("双目管道已连接,等待帧数据…")) + + frame_count = 0 + while entry["proc"] and entry["proc"].poll() is None: + if self.shutting_down: + break + try: + # 帧格式: + # [4B left_len][8B left_ts_ns][left_jpg] + # [4B right_len][8B right_ts_ns][right_jpg] + # [4B imu_count][imu_count × (8B ts_ns + 8B×6 gyro/acc)] + # [4B depth_len] ← 仅 depth_active + # >0: [8B depth_ts][4B w][4B h][w*h*2 字节 uint16 毫米] + # 时间戳均为 SDK 硬件纳秒时钟(帧/IMU 同源,SLAM 对齐用) + header = fifo.read(4) + if len(header) < 4: + break + left_len = struct.unpack(">I", header)[0] + # 帧头自检:0 或超 8MB 均属管道流错位(如子进程打印进入 + # 管道),防巨额分配/空帧 imdecode 抛异常;正常 1280×800 + # JPEG 远小于 8MB + if not (0 < left_len <= 8 * 1024 * 1024): + self.log.emit(tr( + "[双目错误] 帧头异常 left_len={},管道流错位", left_len)) + break + ts_raw = fifo.read(8) + if len(ts_raw) < 8: + break + left_ts = struct.unpack(">Q", ts_raw)[0] + left_data = fifo.read(left_len) + if len(left_data) < left_len: + break + + header = fifo.read(4) + if len(header) < 4: + break + right_len = struct.unpack(">I", header)[0] + if not (0 < right_len <= 8 * 1024 * 1024): + self.log.emit(tr( + "[双目错误] 帧头异常 right_len={},管道流错位", right_len)) + break + ts_raw = fifo.read(8) + if len(ts_raw) < 8: + break + right_ts = struct.unpack(">Q", ts_raw)[0] + right_data = fifo.read(right_len) + if len(right_data) < right_len: + break + + # IMU 样本块 + hdr = fifo.read(4) + if len(hdr) < 4: + break + imu_count = struct.unpack(">I", hdr)[0] + imu_samples = [] + for _ in range(imu_count): + rec = fifo.read(56) + if len(rec) < 56: + break + imu_samples.append(struct.unpack(">Q6d", rec)) + if len(imu_samples) < imu_count: + break + + # 深度块(子进程 SDK 深度引擎输出;每帧必写保证解析确定性。 + # 尺寸校验防协议错位;校验失败仍已消费 payload 保持同步) + if entry.get("depth_active"): + hdr = fifo.read(4) + if len(hdr) < 4: + break + depth_len = struct.unpack(">I", hdr)[0] + if depth_len > 0: + if depth_len > 64 * 1024 * 1024: # 防坏流巨额分配 + break + dh = fifo.read(16) # >QII = 8+4+4 + if len(dh) < 16: + break + # unpack_from(而非 unpack(dh):本机 Python 严格版 + # 要求 buffer 恰好 == calcsize,16=16 亦可,但 + # unpack_from 语义更稳)。注意此处必须 16 字节: + # 写端 struct.pack(">QII")=16;多读 4 字节会把 + # 下一帧帧头吃进本块(实测全流错位→0 帧断连) + depth_ts, dw, dh2 = struct.unpack_from(">QII", dh) + payload = fifo.read(depth_len) + if len(payload) < depth_len: + break + if depth_len == dw * dh2 * 2 \ + and 0 < dw <= 4096 and 0 < dh2 <= 4096: + depth = np.frombuffer(payload, np.uint16) \ + .reshape(dh2, dw) + self.depth_ready.emit( + settings.S80M_DEPTH_SLOT, depth, depth_ts) + else: + self.log.emit(tr( + "[双目] 深度块尺寸不符 w={} h={} len={},跳过", + dw, dh2, depth_len)) + + # JPEG 解码(cv2 5.0.0 起空/坏缓冲直接抛 cv2.error 而非 + # 返回 None;异常按流损坏处理,交由下方异常出口收尾) + try: + left = cv2.imdecode(np.frombuffer(left_data, np.uint8), + cv2.IMREAD_COLOR) + right = cv2.imdecode(np.frombuffer(right_data, np.uint8), + cv2.IMREAD_COLOR) + except cv2.error as e: + self.log.emit(tr("[双目错误] JPEG 解码失败: {}", e)) + break + if left is None or right is None: + continue + + # ★ S80M 子进程直接输出左右两个完整单目画面 (1280×800) + # ★ 镜头方向已由 SDK config (left_cam_rotate_180 / + # right_cam_rotate_180 / stereo_swap_lr) 处理,此处不再翻转 + # ★ 显示翻转由主线程 _on_stereo_frame 统一执行(与单目一致) + self.frame_ready.emit("stereo_left", left, left_ts, imu_samples) + self.frame_ready.emit("stereo_right", right, right_ts, imu_samples) + + frame_count += 1 + if frame_count == 1: + self.log.emit(tr("双目摄像机画面已开始传输")) + + except BrokenPipeError: + if not self.shutting_down: + self.log.emit(tr("[双目] 管道断开")) + break + except Exception as e: + if not self.shutting_down: + self.log.emit(tr("[双目错误] 读取帧异常: {}", e)) + break + + if not self.shutting_down: + # 异常退出(流错位/解码失败/EOF)时确保子进程终止:SIGTERM + # 走脚本内优雅退出(finally → _fn_destroy 释放 SDK),避免 + # 半死子进程占着相机不死。正常 close() 路径已 terminate, + # poll() 非 None 不会误杀。 + proc = entry.get("proc") + if proc and proc.poll() is None: + try: + proc.terminate() + proc.wait(timeout=3) + except Exception: + try: + proc.kill() + except Exception: + pass + self.log.emit(tr("双目摄像机已断开 (共 {} 帧)", frame_count)) + + def check_alive(self, dev_key: str): + """定时检查双目子进程是否仍在运行(watchdog 槽)。""" + entry = self._entries.get(dev_key) + if not entry or entry["kind"] != "s80m": + return + ret = entry["proc"].poll() + if ret is not None: + entry["watchdog"].stop() + self.log.emit(tr("[双目] 子进程已退出,退出码: {}", ret)) + # 读取 stderr 末尾(最后 500 字符) + err_file = entry["stderr_file"] + if err_file and os.path.isfile(err_file): + try: + with open(err_file, "r") as f: + f.seek(0, os.SEEK_END) + size = f.tell() + f.seek(max(0, size - 500)) + tail = f.read() + if tail.strip(): + self.log.emit(tr("[双目 stderr] {}", tail.strip())) + except Exception: + pass + + def close(self, dev_key: str): + """停止 S80M 子进程并清理进程侧资源,完毕 emit device_closed。 + + (主窗口注册表条目由调用方弹出;管线注销/拆槽/清标定在 + device_closed 槽中执行,整体顺序与原 _close_s80m 一致。) + """ + entry = self._entries.pop(dev_key, None) + if not entry or entry["kind"] != "s80m": + return + # 1. 停止 watchdog 定时器 + wd = entry.get("watchdog") + if wd: + wd.stop() + wd.deleteLater() + + # 2. 先关曝光命令通道(子进程 stdin 线程随 EOF 退出),再终止子进程 + stdin = entry.get("stdin") + if stdin: + try: + stdin.close() + except Exception: + pass + proc = entry["proc"] + try: + proc.terminate() + proc.wait(timeout=3) + except Exception: + try: + proc.kill() + proc.wait(timeout=2) + except Exception: + pass + # 关闭 stdout 管道 → 唤醒 reader 线程的阻塞 read() + if proc.stdout: + try: + proc.stdout.close() + except Exception: + pass + + # 3. 等待 reader 线程退出(管道已关闭,不再阻塞) + reader = entry.get("reader_thread") + if reader and reader.is_alive(): + reader.join(timeout=3.0) + + # 4. 清理 stderr 日志文件 + 50fps yaml 临时副本 + err_file = entry.get("stderr_file") + if err_file and os.path.isfile(err_file): + try: + os.unlink(err_file) + except Exception: + pass + cfg_tmp = entry.get("config_file") + if cfg_tmp and os.path.isfile(cfg_tmp): + try: + os.unlink(cfg_tmp) + except Exception: + pass + + self.device_closed.emit(dev_key) + + def send_exposure(self, entry: dict, auto: bool, value: float): + """向 S80M 子进程下发曝光(stdin 行协议;-1.0 = 自动曝光)。 + + entry 由调用方按注册表取到(主窗口注册表与离线测试假条目同款 + 形状),行协议口径集中于此。 + """ + if not entry: + return + stdin = entry.get("stdin") + if stdin is None: + return + v = -1.0 if auto else float(value) + try: + stdin.write(f"SET_EXPOSURE {v}\n".encode()) + stdin.flush() + except (BrokenPipeError, OSError): + self.log.emit(tr("[双目] 曝光下发失败(子进程已退出)")) diff --git a/collector/core/sensor_config_dialogs.py b/collector/core/sensor_config_dialogs.py new file mode 100755 index 0000000000000000000000000000000000000000..f32b4f90293488e5eaeccee42bf6cae95856ab02 --- /dev/null +++ b/collector/core/sensor_config_dialogs.py @@ -0,0 +1,238 @@ +""" +传感器配置对话框 —— PyQt5 实现的矩阵选择和手掌配置界面。 +""" + +import json +import os +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import ( + QDialog, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, + QGroupBox, QRadioButton, QScrollArea, QWidget, QButtonGroup, + QDialogButtonBox, QGridLayout, +) + + +# ═══════════════════════════════════════════════════════ +# 通用矩阵行列选择对话框 +# ═══════════════════════════════════════════════════════ + +class MatrixConfigDialog(QDialog): + """通用矩阵行列配置 —— 按钮点击选择行/列序列。""" + + def __init__(self, parent, title: str, config: dict): + super().__init__(parent) + self.setWindowTitle(title) + self.setMinimumSize(600, 480) + + self._rows = list(config.get("rows", [])) + self._cols = list(config.get("cols", [])) + self._order = config.get("axis_order", "row_col") + + self._setup_ui() + + def _setup_ui(self): + layout = QVBoxLayout(self) + + # 映射方向 + order_group = QGroupBox("映射渲染方向 (Axis Mapping)") + order_layout = QHBoxLayout(order_group) + bg = QButtonGroup(self) + self._rb_rowcol = QRadioButton("先行后列 (横向列, 纵向行)") + self._rb_colrow = QRadioButton("先列后行 (横向行, 纵向列)") + bg.addButton(self._rb_rowcol) + bg.addButton(self._rb_colrow) + if self._order == "row_col": + self._rb_rowcol.setChecked(True) + else: + self._rb_colrow.setChecked(True) + order_layout.addWidget(self._rb_rowcol) + order_layout.addWidget(self._rb_colrow) + layout.addWidget(order_group) + + # 行列选择 + lists_layout = QHBoxLayout() + + # 行选择 + row_group = QGroupBox("行 (Rows 00-15)") + row_vbox = QVBoxLayout(row_group) + self._row_label = QLabel() + self._row_label.setStyleSheet("color:#1565C0; font-weight:bold;") + self._row_label.setWordWrap(True) + row_vbox.addWidget(self._row_label) + + row_grid = QGridLayout() + for i in range(16): + btn = QPushButton(f"{i:02d}") + btn.setFixedSize(36, 28) + btn.clicked.connect(lambda checked, x=i: self._add_row(x)) + row_grid.addWidget(btn, i // 4, i % 4) + row_vbox.addLayout(row_grid) + + row_btn_layout = QHBoxLayout() + row_btn_layout.addWidget(QPushButton("撤销", clicked=self._undo_row)) + row_btn_layout.addWidget(QPushButton("清空", clicked=self._clear_row)) + row_vbox.addLayout(row_btn_layout) + lists_layout.addWidget(row_group) + + # 列选择 + col_group = QGroupBox("列 (Cols 00-15)") + col_vbox = QVBoxLayout(col_group) + self._col_label = QLabel() + self._col_label.setStyleSheet("color:#1565C0; font-weight:bold;") + self._col_label.setWordWrap(True) + col_vbox.addWidget(self._col_label) + + col_grid = QGridLayout() + for i in range(16): + btn = QPushButton(f"{i:02d}") + btn.setFixedSize(36, 28) + btn.clicked.connect(lambda checked, x=i: self._add_col(x)) + col_grid.addWidget(btn, i // 4, i % 4) + col_vbox.addLayout(col_grid) + + col_btn_layout = QHBoxLayout() + col_btn_layout.addWidget(QPushButton("撤销", clicked=self._undo_col)) + col_btn_layout.addWidget(QPushButton("清空", clicked=self._clear_col)) + col_vbox.addLayout(col_btn_layout) + lists_layout.addWidget(col_group) + + layout.addLayout(lists_layout) + + # 确认按钮 + btns = QDialogButtonBox( + QDialogButtonBox.Ok | QDialogButtonBox.Cancel + ) + btns.accepted.connect(self.accept) + btns.rejected.connect(self.reject) + layout.addWidget(btns) + + self._update_labels() + + def _add_row(self, val): + if val not in self._rows: + self._rows.append(val) + self._update_labels() + + def _undo_row(self): + if self._rows: + self._rows.pop() + self._update_labels() + + def _clear_row(self): + self._rows.clear() + self._update_labels() + + def _add_col(self, val): + if val not in self._cols: + self._cols.append(val) + self._update_labels() + + def _undo_col(self): + if self._cols: + self._cols.pop() + self._update_labels() + + def _clear_col(self): + self._cols.clear() + self._update_labels() + + def _update_labels(self): + r_str = " → ".join(map(str, self._rows)) if self._rows else "(无)" + c_str = " → ".join(map(str, self._cols)) if self._cols else "(无)" + self._row_label.setText(f"已选行:\n{r_str}") + self._col_label.setText(f"已选列:\n{c_str}") + + def get_config(self) -> dict: + order = "row_col" if self._rb_rowcol.isChecked() else "col_row" + return { + "rows": list(self._rows), + "cols": list(self._cols), + "axis_order": order, + } + + +# ═══════════════════════════════════════════════════════ +# 仿生手掌配置对话框 +# ═══════════════════════════════════════════════════════ + +class HandConfigDialog(QDialog): + """仿生手掌 —— 各手指区域的矩阵配置。""" + + def __init__(self, parent, config: dict): + super().__init__(parent) + self.setWindowTitle("仿生手掌映射配置") + self.setMinimumSize(650, 600) + self._config = {k: dict(v) for k, v in config.items()} + self._labels = {} + self._setup_ui() + + def _setup_ui(self): + layout = QVBoxLayout(self) + layout.addWidget(QLabel("🦾 仿生手掌模式 - 矩阵配置")) + layout.addWidget(QLabel('点击"选择"为每个部位配置传感器行列映射')) + + scroll = QScrollArea() + scroll.setWidgetResizable(True) + container = QWidget() + container_layout = QVBoxLayout(container) + + for key, item in self._config.items(): + name = item.get("name", key) + row_widget = QWidget() + row_layout = QHBoxLayout(row_widget) + row_layout.setContentsMargins(0, 2, 0, 2) + + row_layout.addWidget(QLabel(name)) + + label = QLabel(self._format_cfg(item)) + label.setStyleSheet("color:#1565C0;") + label.setMinimumWidth(300) + self._labels[key] = label + row_layout.addWidget(label, 1) + + btn = QPushButton("选择") + btn.clicked.connect( + lambda checked, k=key: self._open_sub_config(k) + ) + row_layout.addWidget(btn) + + container_layout.addWidget(row_widget) + + scroll.setWidget(container) + layout.addWidget(scroll, 1) + + btns = QDialogButtonBox( + QDialogButtonBox.Ok | QDialogButtonBox.Cancel + ) + btns.accepted.connect(self.accept) + btns.rejected.connect(self.reject) + layout.addWidget(btns) + + def _format_cfg(self, item): + rows = item.get("rows", []) + cols = item.get("cols", []) + order = item.get("axis_order", "row_col") + r_str = ",".join(map(str, rows)) if rows else "无" + c_str = ",".join(map(str, cols)) if cols else "无" + dir_str = "先行后列" if order == "row_col" else "先列后行" + return f"[{dir_str}] 行:[{r_str}] 列:[{c_str}]" + + def _open_sub_config(self, key): + item = self._config[key] + sub_cfg = { + "rows": list(item.get("rows", [])), + "cols": list(item.get("cols", [])), + "axis_order": item.get("axis_order", "row_col"), + } + dlg = MatrixConfigDialog( + self, f"配置 - {item.get('name', key)}", sub_cfg + ) + if dlg.exec_() == dlg.Accepted: + new_cfg = dlg.get_config() + item["rows"] = new_cfg["rows"] + item["cols"] = new_cfg["cols"] + item["axis_order"] = new_cfg["axis_order"] + self._labels[key].setText(self._format_cfg(item)) + + def get_config(self) -> dict: + return self._config diff --git a/collector/core/sensor_hand_config.py b/collector/core/sensor_hand_config.py new file mode 100644 index 0000000000000000000000000000000000000000..6227e48692692bdde543613476f453f7a4952908 --- /dev/null +++ b/collector/core/sensor_hand_config.py @@ -0,0 +1,44 @@ +""" +传感器(BLE 手套)仿生手掌配置与有效性过滤 —— 零 Qt 依赖,纯函数。 + +供回放对话框与手套面板共用同一套口径: + - load_sensor_hand_config 按传感器角色加载仿生手掌映射(左/右手套不同) + - valid_sensor_names 只保留时间线中确实存在 16×16 压力矩阵的传感器列 +""" + +from __future__ import annotations + +from core.render_engine import ( + DEFAULT_HAND, _load_json, CONFIG_FILE, CONFIG_FILE_LEFT, +) + + +def load_sensor_hand_config(sensor_name: str) -> dict: + """按传感器角色加载仿生手掌映射配置(左/右手套不同)。""" + config_file = (CONFIG_FILE_LEFT + if sensor_name == "left_glove" else CONFIG_FILE) + cfg = {k: dict(v) for k, v in DEFAULT_HAND.items()} + for k, v in _load_json(config_file, {}).items(): + if k in cfg: + cfg[k].update(v) + else: + cfg[k] = v # 左传感器配置文件有 DEFAULT_HAND 之外的部位 + return cfg + + +def valid_sensor_names(timeline, names: list) -> list: + """只保留时间线中确实存在 16×16 压力矩阵(256 宽)的传感器列。 + + 无 sensors 键的会话会从 features 推断(observation.imu 等 + 非手套特征会被误判成传感器),按实际列宽过滤掉,避免出现 + 永远"无信号"的幽灵传感器格。 + """ + if timeline is None: + return [] + out = [] + for n in names: + data = timeline.obs.get(f"observation.{n}") + if (data is not None and getattr(data, "ndim", 0) == 2 + and data.shape[1] == 256): + out.append(n) + return out diff --git a/collector/core/session_catalog.py b/collector/core/session_catalog.py new file mode 100644 index 0000000000000000000000000000000000000000..b38a693650a92de563449a6ede807c6f7ff26ac0 --- /dev/null +++ b/collector/core/session_catalog.py @@ -0,0 +1,127 @@ +""" +录制数据目录 —— 扫描、元数据读取与主时钟帧率解析(零 Qt 依赖,纯函数)。 + +供回放对话框与录制历史刷新共用: + - get_effective_fps 任务元数据 → 回放主时钟帧率 + - list_sessions 扫描录制根目录,返回全部 episode(池化布局) + - load_session_meta 任务元数据读取(格式探测 / info / fps / 传感器列名) + +v1.1.0 起读侧只认任务级池化布局(meta/info.json format=="pooled_episodes_v1"), +键为 (task_dir, episode_index);旧格式会话目录不再列出。 +""" + +from __future__ import annotations + +import os +import json + +from config import settings +from core.helpers import ( + episode_refs, detect_session_format, + pooled_info_path, episode_row, episode_video_files, +) + + +def get_effective_fps(info: dict) -> float: + """从任务元数据中提取回放主时钟帧率(每路摄像机帧率的最大值)。 + + 主时钟取最高帧率保证播放平滑;低帧率路按 _cam_fps 逐路独立 + seek 按比例抽帧。兼容旧数据:无 per-camera fps 时通过摄像机 + 命名检测双目模式。 + """ + cameras = info.get("cameras", {}) + cam_fps_vals = [] + for cam_name, cam_info in cameras.items(): + if isinstance(cam_info, dict): + f = cam_info.get("fps") + if f and f > 0: + cam_fps_vals.append(float(f)) + + if cam_fps_vals: + # 有 per-camera fps:取最大值作为主时钟 + return max(cam_fps_vals) + + # 兼容旧数据:无 per-camera fps 时,按摄像机名称推断 + cam_names = [k.lower() for k in cameras.keys()] + is_stereo = any("stereo" in cn for cn in cam_names) + if is_stereo: + return float(settings.STEREO_FPS) + + global_fps = info.get("fps", 30) + return float(global_fps) if global_fps > 0 else 30.0 + + +def load_session_meta(task_dir: str, episode_index: int = 0) -> dict: + """同步读取任务元数据(极快,主线程安全)。 + + 返回 {"fmt", "info", "fps", "sensor_names", "episode_index"}: + - fmt "pooled"(池化布局)或旧格式名 + - episode_index 传入的 episode 序号(0 表示未指定,仅任务级元数据) + - sensor_names 从 info["sensors"] 读;旧格式从 features 推断; + 最旧格式回退 ["state"] + """ + fmt = detect_session_format(task_dir) + + if fmt == "pooled": + mp = pooled_info_path(task_dir) + else: + mp = os.path.join(task_dir, "meta", "info.json") + info = {} + if os.path.isfile(mp): + with open(mp, "r", encoding="utf-8") as f: + info = json.load(f) + + sensor_names = info.get("sensors", []) + if not sensor_names: + # 兼容旧格式:尝试从 features 键推断 + features = info.get("features", {}) + sensor_names = [ + k.replace("observation.", "") for k in features + if k.startswith("observation.") + ] + if not sensor_names: + sensor_names = ["state"] # 最旧格式回退 + + return { + "fmt": fmt, + "info": info, + "fps": get_effective_fps(info), + "sensor_names": sensor_names, + "episode_index": episode_index, + } + + +def list_sessions(directory: str) -> list: + """扫描录制根目录,返回全部 episode(按名称倒序)。 + + 每项 {"name", "path", "tag", "episode_index", "info", "duration", "fps"}: + - path = 任务目录(task_dir) + - episode_index = episode 序号(池化文件组的 N) + - duration = episodes 行的 duration_sec(秒) + """ + sessions = [] + for ref in episode_refs(directory): + task_dir = ref["task_dir"] + episode_index = ref["episode_index"] + meta = load_session_meta(task_dir, episode_index) + row = episode_row(task_dir, episode_index) + sessions.append({ + "name": ref["name"], "path": task_dir, "tag": ref["task"], + "episode_index": episode_index, + "info": meta["info"], + "duration": row.get("duration_sec", 0) or 0, + "fps": meta["fps"], + "cams": len(episode_video_files(task_dir, episode_index)), + }) + return sessions + + +def list_recordings(base_dir: str) -> list[dict]: + """扫描录制根目录,返回全部 episode(上传对话框口径)。 + + 每项 {"name", "path", "tag", "episode_index"}(轻量版 list_sessions, + 不读元数据)。 + """ + return [{"name": r["name"], "path": r["task_dir"], "tag": r["task"], + "episode_index": r["episode_index"]} + for r in episode_refs(base_dir)] diff --git a/collector/core/session_loader.py b/collector/core/session_loader.py new file mode 100644 index 0000000000000000000000000000000000000000..f1142c259cadfe7c0e82cb238dee07d596682051 --- /dev/null +++ b/collector/core/session_loader.py @@ -0,0 +1,112 @@ +""" +会话后台加载器 —— 会话时间线与手部关键点的 parquet 读取全部在 worker 线程。 + +与 UI 无关(QtCore QObject + 信号,不依赖 QtWidgets): + - SessionLoader 后台加载(gen 防过期协议由调用方维护) + - 可选手部关键点经 core.hand_tracking 惰性导入 +""" + +from __future__ import annotations + +import threading + +from PyQt5.QtCore import QObject, pyqtSignal + +from core.session_timeline import load_timeline, SensorTimeline + +# 手部关键点(可选模块;core.hand_tracking 引入 ultralytics/torch 等重依赖) +try: + from core.hand_tracking import load_hand_kpts as _load_hand_kpts + from core.hand_tracking import load_hand_kpts_pooled as _load_hand_kpts_pooled + _HAND_KPTS_AVAILABLE = True +except ImportError: + _load_hand_kpts = None + _load_hand_kpts_pooled = None + _HAND_KPTS_AVAILABLE = False + + +class SessionLoader(QObject): + """后台加载会话时间线与手部关键点(parquet 读取全部在 worker 线程)。 + + 信号 + ---- + finished(int, object) — (gen, {"timeline": SensorTimeline, "hand_kpts": dict}) + payload 按引用传递,worker emit 后不再触碰 + failed(int, str) — (gen, error) + + VideoCapture 不在 worker 中创建/读取(OpenCV FFmpeg 后端不承诺跨线程 + 安全),视频打开与播放全部留在调用方主线程。 + """ + + finished = pyqtSignal(int, object) + failed = pyqtSignal(int, str) + + def __init__(self, parent=None): + super().__init__(parent) + self._running = False + self._pending = None # 排队的下一次加载请求(最新覆盖旧的) + self._lock = threading.Lock() + self._thread: threading.Thread = None + + def start(self, gen: int, session_dir: str, sensor_names: list[str], + load_kpts: bool = False, load_timeline: bool = True, + episode_index: int = 0): + """启动后台加载。 + + 已有加载在跑时把请求排队(新请求覆盖旧请求——过期结果本就会被 + gen 丢弃,只跑最新一次即可)。 + + load_timeline=False → kpts-only 模式(手部处理完成后重载关键点)。 + episode_index > 0 时按池化布局读本 episode 的文件组。 + """ + with self._lock: + if self._running: + self._pending = (gen, session_dir, sensor_names, + load_kpts, load_timeline, episode_index) + return + self._running = True + self._spawn(gen, session_dir, sensor_names, load_kpts, load_timeline, + episode_index) + + def is_running(self) -> bool: + return self._running + + def _spawn(self, gen, session_dir, sensor_names, load_kpts, load_timeline, + episode_index): + self._thread = threading.Thread( + target=self._run, + args=(gen, session_dir, sensor_names, load_kpts, load_timeline, + episode_index), + daemon=True, name="session-loader", + ) + self._thread.start() + + # ── 后台 ────────────────────────────────────────── + + def _run(self, gen: int, session_dir: str, sensor_names: list[str], + load_kpts: bool, want_timeline: bool, episode_index: int): + try: + timeline = None + if want_timeline: + timeline = load_timeline(session_dir, sensor_names, + episode_index) + hand_kpts = {} + if load_kpts and _HAND_KPTS_AVAILABLE: + if episode_index > 0 and _load_hand_kpts_pooled: + # 池化布局:镜像目录 keypoints_output//episode_NNNNNN/ + hand_kpts = (_load_hand_kpts_pooled( + session_dir, episode_index) or {}) + elif _load_hand_kpts: + hand_kpts = _load_hand_kpts(session_dir) or {} + self.finished.emit(gen, {"timeline": timeline, "hand_kpts": hand_kpts}) + except Exception as e: + self.failed.emit(gen, str(e)[:300]) + finally: + with self._lock: + self._running = False + pending = self._pending + self._pending = None + if pending is not None: + self._running = True + if pending is not None: + self._spawn(*pending) diff --git a/collector/core/session_timeline.py b/collector/core/session_timeline.py new file mode 100644 index 0000000000000000000000000000000000000000..3a97fdacf496368e78f2bd2366233ab7ed799817 --- /dev/null +++ b/collector/core/session_timeline.py @@ -0,0 +1,281 @@ +""" +录制会话传感器时间线 —— 向量化合并 per-sensor parquet + 帧号二分查询。 + +替代 ui/playback_dialog.py 中逐行 dict 合并(60 分钟会话 179464 行实测 +32.5s → 本实现约 1s),并提供 O(log n) 的帧号→传感器行查询。 + +纯 numpy/pyarrow 实现,无 Qt 依赖,可在后台线程运行。 +""" +from __future__ import annotations + +import os +from typing import Optional + +import numpy as np +import pyarrow as pa +import pyarrow.parquet as pq + +# 合并键列(旧格式单表可能缺 episode_index,缺失时填 0) +_KEY_COLS = ("episode_index", "frame_index", "timestamp") + + +# ═══════════════════════════════════════════════════════ +# parquet 文件定位 +# ═══════════════════════════════════════════════════════ + +def _find_sensor_parquet(session_dir: str) -> str: + """查找新结构下的传感器 parquet 文件路径。 + + 新结构: data//chunk-0000/chunk_000000.parquet + 返回第一个找到的路径,无则返回空串。 + """ + data_dir = os.path.join(session_dir, "data") + if os.path.isdir(data_dir): + for entry in sorted(os.listdir(data_dir)): + parquet = os.path.join(data_dir, entry, "chunk-0000", "chunk_000000.parquet") + if os.path.isfile(parquet): + return parquet + return "" + + +def _find_all_sensor_parquets(session_dir: str) -> list[str]: + """查找新结构下所有 per-sensor parquet 文件路径。 + + 新结构: data//chunk-0000/chunk_000000.parquet + 每个传感器独立一个 parquet,只含自己的 observation. 列。 + 返回所有找到的路径列表(按字母排序)。 + """ + data_dir = os.path.join(session_dir, "data") + paths = [] + if os.path.isdir(data_dir): + for entry in sorted(os.listdir(data_dir)): + parquet = os.path.join(data_dir, entry, "chunk-0000", "chunk_000000.parquet") + if os.path.isfile(parquet): + paths.append(parquet) + return paths + + +def _column_to_matrix(col, n_rows: int) -> Optional[np.ndarray]: + """pyarrow 列 → (n_rows, D) float32 矩阵(缺值 NaN)。 + + fixed_size_list / 标量数组均展平为二维;转换失败(如变长 list)返回 None。 + """ + try: + arr = col.combine_chunks() + if pa.types.is_fixed_size_list(arr.type): + child = arr.values.to_numpy(zero_copy_only=False) + else: + child = arr.to_numpy(zero_copy_only=False) + m = np.asarray(child) + if m.ndim == 1: + m = m.reshape(n_rows, -1) + return m.astype(np.float32, copy=False) + except Exception: + return None + + +# ═══════════════════════════════════════════════════════ +# 时间线 +# ═══════════════════════════════════════════════════════ + +class SensorTimeline: + """合并后的统一时间线(按 (episode_index, frame_index) 排序)。 + + Attributes: + frame_indices : (N,) int64 每行对应的视频帧号(非降,可二分) + timestamps : (N,) float64 每行时间戳(秒,不保证严格单调—— + 录制暂停点存在负跳变,查询请用帧号) + obs : {col: (N,D) float32} 观测列矩阵(缺值 NaN) + signal_mask : (N,) bool 该行任一观测列有非零信号 + signal_count : int 有信号行总数 + """ + + def __init__(self, frame_indices, timestamps, obs, signal_mask): + self.frame_indices = np.asarray(frame_indices, dtype=np.int64) + self.timestamps = np.asarray(timestamps, dtype=np.float64) + self.obs = obs + self.signal_mask = np.asarray(signal_mask, dtype=bool) + self.signal_count = int(self.signal_mask.sum()) + # 每列非空行的 (fi 子数组, 行号子数组) —— nearest_for_column 二分用 + self._col_index = {} + for col, V in obs.items(): + valid = ~np.isnan(V).all(axis=1) + rows = np.flatnonzero(valid) + if rows.size: + self._col_index[col] = (self.frame_indices[rows], rows) + + def __bool__(self) -> bool: + return len(self.frame_indices) > 0 + + def __len__(self) -> int: + return len(self.frame_indices) + + def nearest_for_column(self, col: str, frame_idx: int + ) -> tuple[Optional[int], Optional[int]]: + """返回该列中 frame_index 最接近 frame_idx 的 (行号, |Δ帧|)。 + + 列不存在或无有效行时返回 (None, None)。O(log n) 二分。 + 假设:传感器 frame_index 与视频帧号同源同帧率空间 + (加载时已按 fi 排序保证非降;若未来出现不同源数据, + 在 load_timeline 处回退为 fi→ts 区间线性扫描)。 + """ + sub = self._col_index.get(col) + if sub is None: + return None, None + fi_sub, rows_sub = sub + i = int(np.searchsorted(fi_sub, frame_idx, side="left")) + cands = [] + if i > 0: + cands.append(i - 1) + if i < len(fi_sub): + cands.append(i) + if not cands: + return None, None + best = min(cands, key=lambda k: abs(int(fi_sub[k]) - int(frame_idx))) + return int(rows_sub[best]), int(abs(int(fi_sub[best]) - int(frame_idx))) + + def nearest_for_column_time(self, col: str, t_s: float + ) -> tuple[Optional[int], Optional[float]]: + """返回该列中 timestamp 最接近 t_s(秒)的 (行号, |Δt|秒)。 + + 列不存在或无有效行时返回 (None, None)。 + 时间戳单调(无暂停)时 O(log n) 二分;含暂停负跳变时退化为 + 向量化 argmin(该列有效行上的最小 |Δt|)。 + + 多帧率回放用:主时钟时间 → 传感器时间线(传感器行按录制 + 30fps 循环时间戳,与视频主时钟帧率可能不同源)。 + """ + sub = self._col_index.get(col) + if sub is None: + return None, None + _, rows_sub = sub + ts_sub = self.timestamps[rows_sub] + if ts_sub.size == 0: + return None, None + if bool(np.all(np.diff(ts_sub) >= 0)): + i = int(np.searchsorted(ts_sub, t_s, side="left")) + cands = [] + if i > 0: + cands.append(i - 1) + if i < len(ts_sub): + cands.append(i) + if not cands: + return None, None + best = min(cands, key=lambda k: abs(float(ts_sub[k]) - t_s)) + else: + best = int(np.argmin(np.abs(ts_sub - t_s))) + return int(rows_sub[best]), float(abs(float(ts_sub[best]) - t_s)) + + +# ═══════════════════════════════════════════════════════ +# 加载与合并 +# ═══════════════════════════════════════════════════════ + +def load_timeline(session_dir: str, sensor_names: list[str], + episode_index: int = 0) -> SensorTimeline: + """加载会话传感器时间线。 + + episode_index > 0(池化布局)→ 直接读本 episode 的单个 data parquet + (data/chunk-{c:03d}/episode-{f:03d}.parquet); + episode_index == 0 → 旧格式双路径(per-sensor 多文件或单表回退)。 + """ + if episode_index > 0: + from core.helpers import pooled_data_parquet_path + tp = pooled_data_parquet_path(session_dir, episode_index) + paths = [tp] if os.path.isfile(tp) else [] + else: + paths = _find_all_sensor_parquets(session_dir) + if not paths: + # 旧格式回退:单个 data parquet + from core.helpers import data_parquet_path + tp = data_parquet_path(session_dir) + if not os.path.isfile(tp): + tp = os.path.join(session_dir, "data", "chunk_000000.parquet") + if os.path.isfile(tp): + paths = [tp] + if not paths: + return SensorTimeline([], [], {}, []) + return _merge_per_sensor_parquets(paths, sensor_names) + + +def _merge_per_sensor_parquets(paths: list[str], + sensor_names: list[str]) -> SensorTimeline: + """向量化合并多个 per-sensor parquet 为统一时间线。 + + 语义与旧逐行 dict 合并一致(已对真实会话逐项验证): + - 按 (episode_index, frame_index, round6(timestamp)) 分组合并 + - 每组输出首行的键值;观测列取组内最后一个非空值 + - 信号掩码 = 任一观测列该行 |值|.sum > 0 + """ + obs_cols = [f"observation.{sn}" for sn in sensor_names] + + ei_parts, fi_parts, ts_parts = [], [], [] + ranges = [] # 每文件在全量行空间中的 (start, end) + col_blocks = {c: [] for c in obs_cols} # col → [(start, matrix)] + + pos = 0 + for p in paths: + schema = pq.read_schema(p) + keys = [c for c in _KEY_COLS if schema.get_field_index(c) >= 0] + if "frame_index" not in keys: + raise ValueError(f"parquet 缺少 frame_index 列: {p}") + have_obs = [c for c in obs_cols if schema.get_field_index(c) >= 0] + tbl = pq.read_table(p, columns=keys + have_obs) + n = len(tbl) + + ei = (tbl.column("episode_index").to_numpy(zero_copy_only=False) + if "episode_index" in keys else np.zeros(n, np.int64)) + fi = tbl.column("frame_index").to_numpy(zero_copy_only=False) + ts = (tbl.column("timestamp").to_numpy(zero_copy_only=False) + if "timestamp" in keys else np.zeros(n, np.float64)) + ei_parts.append(np.asarray(ei, np.int64)) + fi_parts.append(np.asarray(fi, np.int64)) + ts_parts.append(np.asarray(ts, np.float64)) + + for c in have_obs: + m = _column_to_matrix(tbl.column(c), n) + if m is not None: + col_blocks[c].append((pos, m)) + ranges.append((pos, pos + n)) + pos += n + + N = pos + ei = np.concatenate(ei_parts) + fi = np.concatenate(fi_parts) + ts = np.concatenate(ts_parts) + + # 分组排序(ts6 只作组键,输出时间戳保留原始值) + ts6 = np.round(ts, 6) + order = np.lexsort((ts6, fi, ei)) + ei_s, fi_s, ts6_s = ei[order], fi[order], ts6[order] + + new = np.empty(N, dtype=bool) + new[0] = True + if N > 1: + np.not_equal(ei_s[1:], ei_s[:-1], out=new[1:]) + new[1:] |= (fi_s[1:] != fi_s[:-1]) | (ts6_s[1:] != ts6_s[:-1]) + gstart = np.flatnonzero(new) + gcount = len(gstart) + + obs = {} + signal_mask = np.zeros(gcount, dtype=bool) + for c in obs_cols: + blocks = col_blocks.get(c) + if not blocks: + continue + D = blocks[0][1].shape[1] + V = np.full((N, D), np.nan, dtype=np.float32) + for start, m in blocks: + V[start:start + m.shape[0]] = m + V = V[order] + + # 组内最后一个非空值(组内全缺值时置 NaN,不能取 V[-1]) + valid = ~np.isnan(V).all(axis=1) + last_valid = np.maximum.reduceat( + np.where(valid, np.arange(N, dtype=np.int64), -1), gstart) + idx = np.maximum(last_valid, 0) + col_mat = np.where(last_valid[:, None] >= 0, V[idx], np.nan) + obs[c] = col_mat + signal_mask |= (np.abs(col_mat).sum(axis=1) > 0) + + return SensorTimeline(fi_s[gstart], ts[order][gstart], obs, signal_mask) diff --git a/collector/core/stereo_depth.py b/collector/core/stereo_depth.py new file mode 100644 index 0000000000000000000000000000000000000000..632f9237df5406d55ed39066c80dbff0a0117848 --- /dev/null +++ b/collector/core/stereo_depth.py @@ -0,0 +1,201 @@ +""" +双目深度计算模块 —— 基于 OpenCV StereoSGBM 从左右目图像生成视差/深度图。 + +输出 uint16 PNG,像素值 = 视差 × 16(OpenCV 标准亚像素格式), +单位可通过标定参数 (baseline × fx / disparity) 换算为毫米。 + +用法: + from core.stereo_depth import StereoDepthComputer + + computer = StereoDepthComputer() + disparity = computer.compute(left_frame, right_frame) # uint16 (H, W) +""" + +from __future__ import annotations +from typing import Optional + +import cv2 +import numpy as np + +from config import settings + + +def depth_to_heatmap(depth_uint16: np.ndarray, + near_mm: float = 0.0, + far_mm: float = 0.0, + colormap: int = cv2.COLORMAP_JET, + smooth_k: int = 0) -> np.ndarray: + """uint16 深度图(毫米)→ BGR 热力图。 + + near_mm/far_mm 均 >0 时用**真固定色标**(与 hand_3d_d435 demo + 同口径):整幅按 (depth-near)/(far-near)*255 做 0..255 裁剪—— + 无效值 =0 与近于 near 的像素落入 JET(0) 深蓝,远于 far 的饱和为 + JET(255) 红,不置黑;帧间颜色完全一致,不随画面内容漂移。 + 否则按帧内有效值 min/max 自适应归一化(S80M 传统行为),无效值 + 同样显示为 JET(0) 深蓝而非黑。仅一侧给定时按窗口过滤 + 自适应。 + + smooth_k>0 时先做 k×k 中值滤波(单像素椒盐噪点,仅可视化用)。 + + Args: + depth_uint16: uint16 深度图 (H, W),单位毫米 + near_mm: 显示范围下限(毫米);与 far_mm 同给 → 固定色标 + far_mm: 显示范围上限(毫米) + colormap: OpenCV colormap 常量 + smooth_k: 中值滤波核(奇数,0/1 关闭) + + Returns: + BGR 热力图 (H, W, 3) uint8 + """ + if smooth_k and smooth_k > 1: + depth_uint16 = cv2.medianBlur(depth_uint16, smooth_k) + + fixed = near_mm > 0 and far_mm > 0 + if fixed: + # 整幅 clip(demo 口径):无效值(0) 与近于 near 的像素经负数 + # 裁剪落到 JET(0) 深蓝,远于 far 的饱和为 JET(255) 红——不置黑 + normed = np.clip((depth_uint16.astype(np.float32) - near_mm) + / (far_mm - near_mm) * 255.0, + 0.0, 255.0).astype(np.uint8) + return cv2.applyColorMap(normed, colormap) + + valid = depth_uint16 > 0 + if near_mm > 0 or far_mm > 0: + lo = near_mm if near_mm > 0 else 0.0 + hi = far_mm if far_mm > 0 else float("inf") + valid = valid & (depth_uint16 >= lo) & (depth_uint16 <= hi) + + normed = np.zeros_like(depth_uint16, dtype=np.uint8) + if valid.any(): + vmin = depth_uint16[valid].min() + vmax = depth_uint16[valid].max() + if vmax > vmin: + # 线性映射 vmin..vmax → 1..255(0 保留给无效值) + normed[valid] = ((depth_uint16[valid].astype(np.float32) - vmin) + / (vmax - vmin) * 254 + 1).astype(np.uint8) + else: + normed[valid] = 128 + # 无效值保持 0 → JET(0) 深蓝(demo 口径,不再置黑) + return cv2.applyColorMap(normed, colormap) + + +class DepthHeatmapSmoother: + """深度热力图时域 EMA 平滑(仅可视化通道;无损深度流不受影响)。 + + 对 BGR 热力图做指数滑动平均,抑制帧间抖动噪点;无效区(JET(0) + 深蓝)随 EMA 自然淡入淡出,不会留下永久残影。 + """ + + def __init__(self, alpha: float = 0.5): + self._alpha = float(alpha) # 上一帧权重(越大越平滑、拖影越重) + self._prev: np.ndarray = None + + def update(self, bgr: np.ndarray) -> np.ndarray: + if self._prev is None or self._prev.shape != bgr.shape: + self._prev = bgr.copy() + return bgr + out = cv2.addWeighted(self._prev, self._alpha, bgr, + 1.0 - self._alpha, 0) + self._prev = out + return out + + def reset(self): + self._prev = None + + +class StereoDepthComputer: + """基于 StereoSGBM 的双目深度计算器。 + + 为 S80M 双目摄像机 (800×640) 调优的默认参数。 + 输出 uint16 视差图:像素值 = 视差 × 16(DISPVIS_MULT=16 时实际值需 /16)。 + """ + + def __init__(self, + resolution: tuple = (800, 640), + num_disparities: int = 128, + block_size: int = 11): + """ + Args: + resolution: (width, height) of each camera frame + num_disparities: 视差搜索范围,必须是 16 的倍数 + block_size: SAD 窗口大小,奇数,越大越平滑但丢失细节 + """ + self._width, self._height = resolution + + # StereoSGBM 参数 + self._num_disparities = max(16, num_disparities // 16 * 16) # 强制 16 倍数 + self._block_size = max(5, block_size // 2 * 2 + 1) # 强制奇数 + + self._stereo: Optional[cv2.StereoSGBM] = None + self._right_matcher: Optional[cv2.ximgproc.DisparityWLSFilter] = None + self._wls_filter: Optional[cv2.ximgproc.DisparityWLSFilter] = None + + self._init_matchers() + + def _init_matchers(self): + """初始化 StereoSGBM 匹配器 + WLS 滤波器(WLS 需要 opencv-contrib)。""" + # 左目 → 右目 匹配 + self._left_matcher = cv2.StereoSGBM_create( + minDisparity=0, + numDisparities=self._num_disparities, + blockSize=self._block_size, + P1=8 * 3 * self._block_size ** 2, + P2=32 * 3 * self._block_size ** 2, + disp12MaxDiff=1, + preFilterCap=63, + uniquenessRatio=10, + speckleWindowSize=100, + speckleRange=32, + mode=cv2.STEREO_SGBM_MODE_SGBM_3WAY, + ) + + # 右目 → 左目 匹配(用于 WLS 左右一致性检查) + self._right_matcher = cv2.ximgproc.createRightMatcher(self._left_matcher) + + # WLS 滤波器 —— 平滑视差图同时保留边缘 + self._wls_filter = cv2.ximgproc.createDisparityWLSFilter(self._left_matcher) + self._wls_filter.setLambda(8000.0) + self._wls_filter.setSigmaColor(1.5) + + # ── 公开接口 ────────────────────────────────────────── + + def compute(self, left: np.ndarray, right: np.ndarray) -> np.ndarray: + """从左右目 BGR 帧计算视差图。 + + Args: + left: 左目 BGR 帧 (H, W, 3) + right: 右目 BGR 帧 (H, W, 3) + + Returns: + uint16 视差图 (H, W),像素值 = 视差 × 16 + (eg. value=256 → disparity=16 pixels) + """ + # 转灰度 + gray_l = cv2.cvtColor(left, cv2.COLOR_BGR2GRAY) + gray_r = cv2.cvtColor(right, cv2.COLOR_BGR2GRAY) + + # 直方图均衡化 —— 改善纹理较弱区域的匹配 + gray_l = cv2.equalizeHist(gray_l) + gray_r = cv2.equalizeHist(gray_r) + + # 计算左右视差 + disp_l = self._left_matcher.compute(gray_l, gray_r) # int16 + disp_r = self._right_matcher.compute(gray_r, gray_l) # int16 + + # WLS 滤波(亚像素精度 float32) + disp_filtered = self._wls_filter.filter( + disp_l, gray_l, disparity_map_right=disp_r + ) # float32 + + # 转为 uint16,×16 缩放(OpenCV 标准格式) + disp_filtered = np.maximum(disp_filtered, 0.0) + disp_uint16 = (disp_filtered * 16.0).astype(np.uint16) + + return disp_uint16 + + @property + def num_disparities(self) -> int: + return self._num_disparities + + @property + def block_size(self) -> int: + return self._block_size diff --git a/collector/core/task_record.py b/collector/core/task_record.py new file mode 100755 index 0000000000000000000000000000000000000000..6506b2229dd45e2603ea6122bb0cbaa081615d1b --- /dev/null +++ b/collector/core/task_record.py @@ -0,0 +1,461 @@ +""" +Task record persistence — data/tasks.json is the single source of truth. + +- 进度分账(多电脑协同,后端聚合口径): + local_count 本机累计完成段数(increment_task_completed 加它) + synced_count 后端已确认的本机段数(水位,只前进不后退) + backend_count 最近一次已知后端全局数(merge/flush 用后端值无条件替换) + completed_count = backend_count + (local_count - synced_count) + —— 派生显示值,字段名保留使 UI 零改动,所有写路径经 _recount() 重算。 +- 迁移回填:旧数据没有上述字段时,local/synced/backend 一次性回填为 + 旧 completed_count(目录扫描兜底)——历史不补报、显示连续; + 此后以持久化值为准,上传后删本地文件也不影响进度。 +- Task metadata (id, name, description, total_required, etc.) is persisted. +- Backend tasks are merged into the local record, keeping local-only tasks. +""" + +from __future__ import annotations +import json +import os +import threading +from datetime import datetime + +from config import settings + +_TASKS_FILE = os.path.join(settings.DATA_DIR, "tasks.json") +_lock = threading.RLock() # reentrant — merge_backend_tasks calls save_tasks/load_tasks + +_SEED_TASKS = [ + { + "id": "task_001", + "name": "cylinder_grasping", + "description": "Grasp cylinder parts with right hand, record 16x16 tactile sensor data.", + "status": "pending", + "total_required": 1000, + "assigned_at": "2026-08-07T09:00:00Z", + "params": {"object": "cylinder", "hand": "right"}, + }, + { + "id": "task_002", + "name": "cube_placement", + "description": "Place cube objects from point A to point B using both hands.", + "status": "pending", + "total_required": 500, + "assigned_at": "2026-08-06T14:30:00Z", + "params": {"object": "cube", "hand": "both"}, + }, + { + "id": "task_003", + "name": "valve_rotation", + "description": "Rotate circular valve 90 degrees with single hand, record torque and tactile feedback.", + "status": "pending", + "total_required": 800, + "assigned_at": "2026-08-05T11:00:00Z", + "params": {"object": "valve", "hand": "right", "angle": 90}, + }, +] + + +# ═══════════════════════════════════════════════════════════ +# Public API +# ═══════════════════════════════════════════════════════════ + +def load_tasks(identity: str | None = None) -> list[dict]: + """Load all tasks. Filters out hidden tasks. + + completed_count 以持久化值为准(increment_task_completed 累计); + 文件中缺该字段(旧版本数据)时一次性按目录扫描回填并写回, + 此后删会话文件不再影响进度。 + + Status is auto-computed: pending(0%), in_progress(>0%), completed(100%). + + 排序: 按 assigned_at 从新到旧;null/空/解析失败排最后。 + + identity(新增,默认 None 兼容旧调用): + None → 返回全部可见任务(现状行为) + "guest" → 仅公共任务(无 assigned_user 字段) + 用户名 → 公共任务 + assigned_user == 该用户的任务 + + 注意: 除迁移回填外不写回 tasks.json —— hidden 任务必须保留在文件中, + 否则后端再次推送时无法识别为已删除,任务会死而复生。 + """ + with _lock: + tasks = _read_raw() + need_backfill = False + for t in tasks: + if _ensure_sync_fields(t): + need_backfill = True + _recount(t) + t["status"] = _compute_status(t) + if need_backfill: + with _lock: + _write({"tasks": tasks, "updated_at": datetime.now().isoformat()}) + visible = [t for t in tasks if not t.get("hidden")] + visible = filter_by_identity(visible, identity) + visible.sort(key=_assigned_at_key, reverse=True) # 新→旧;null/空/非法排最后 + return visible + + +def filter_by_identity(tasks: list[dict], identity: str | None = None) -> list[dict]: + """按身份过滤任务列表(纯函数,供 UI 对已有列表即时过滤)。 + + identity 语义与 load_tasks 相同;返回新列表,不修改原列表。 + """ + if identity is None: + return list(tasks) + if identity == "guest": + return [t for t in tasks if not _assigned_user(t)] + return [t for t in tasks + if not _assigned_user(t) or _assigned_user(t) == identity] + + +def save_tasks(tasks: list[dict]): + """Persist task metadata,含 completed_count(录制完成次数持久化权威值)。""" + clean = [dict(t) for t in tasks] + with _lock: + _write({"tasks": clean, "updated_at": datetime.now().isoformat()}) + + +def merge_backend_tasks(backend_tasks: list[dict], view_scope: str | None = None) -> list[dict]: + """Merge backend tasks into local record. Returns merged list. + + - Backend tasks update existing entries by id, new ones are added. + - Local-only tasks are preserved. + - Invalid/incomplete tasks are filtered out. + - 同名去重: 同一 (name, assigned_user) 组出现多个可见任务时,只保留 + assigned_at 最新的一个(后端推送的优先胜出——"根据后台指令更新任务细节"), + 其余标 hidden。公共任务(均无 assigned_user)分组结果与旧版等价。 + - view_scope(新增): 当前会话身份。"guest"/None 不触发撤销清除; + 用户名时,本地 assigned_user == 该用户名、且本轮后端未返回的任务 + (已被后端撤销)从本地清除。游客轮询绝不触发撤销清除——防止把 + 他人指派任务误删。 + """ + with _lock: + local = _read_raw() + + backend_ids = {_tid(t) for t in backend_tasks} + + # ── 阶段 0: 撤销清除(仅账号轮询;游客/无身份完全跳过)── + if view_scope not in (None, "guest"): + local = [ + lt for lt in local + if not (_assigned_user(lt) == view_scope and _tid(lt) not in backend_ids) + ] + + candidates: list[dict] = [] + + # ── 阶段 1: 后端任务(按 id 合并,逻辑与现状一致)── + for bt in backend_tasks: + if not _is_valid(bt): + continue + bid = _tid(bt) + local_match = _find(local, bid) + backend_global = max(0, int(bt.get("completed_count") or 0)) + if local_match: + # 保留本地覆盖字段 + for key in ("total_required", "params", "assigned_user"): + if key in local_match and key not in bt: + bt[key] = local_match[key] + # 进度分账:后端全局数权威;本机完成数/已同步水位沿用本地 + _ensure_sync_fields(local_match) + bt["local_count"] = local_match["local_count"] + bt["synced_count"] = local_match["synced_count"] + bt["backend_count"] = backend_global + # 保留删除标记:用户删过的任务不能被后端推送复活 + if local_match.get("hidden"): + bt["hidden"] = True + else: + # 新任务:本机 0 段全同步;backend_count 取后端全局数 + # (保留 current_count 作新任务初值的旧语义) + bt["local_count"] = 0 + bt["synced_count"] = 0 + bt["backend_count"] = backend_global + candidates.append(bt) + + # ── 阶段 2: 本地独有任务 ── + for lt in local: + if not _is_valid(lt): + continue + if _tid(lt) not in backend_ids: + candidates.append(dict(lt)) + + # ── 阶段 3: 同名去重((name, assigned_user) 墓碑)── + groups: dict[tuple, list[dict]] = {} + for c in candidates: + groups.setdefault((c["name"], _assigned_user(c)), []).append(c) + for group in groups.values(): + visible = [g for g in group if not g.get("hidden")] + if len(visible) <= 1: + continue # 无碰撞(含整组已 hidden)→ 不动 + backend_visible = [v for v in visible if _tid(v) in backend_ids] + pool = backend_visible if backend_visible else visible + winner = max(pool, key=_assigned_at_key) + for g in visible: + if g is not winner: + g["hidden"] = True # 持久化墓碑,防止复活 + + for t in candidates: + _ensure_sync_fields(t) + _recount(t) + t["status"] = _compute_status(t) + save_tasks(candidates) + return load_tasks() + + +def mark_hidden(task_id: str): + """Mark a task as hidden so it no longer appears in the UI.""" + with _lock: + tasks = _read_raw() + for t in tasks: + if _tid(t) == task_id: + t["hidden"] = True + break + _write({"tasks": tasks, "updated_at": datetime.now().isoformat()}) + + +def refresh_progress() -> list[dict]: + """Reload task list with persisted completion counts.""" + return load_tasks() + + +def increment_task_completed(task_name: str, task_id: str | None = None, + assigned_user: str | None = None) -> dict | None: + """一次录制完成:把对应任务的录制完成次数持久化 +1,返回更新后的任务。 + + 匹配优先级: + 1) task_id 提供时按 id 精确匹配(须 name 一致) + 2) (name, assigned_user) 精确匹配(assigned_user 为 None 时匹配公共任务) + 3) 同名条目唯一时回退唯一匹配(兼容旧数据/手动临时任务名) + 4) 多名同名且身份不匹配 → 返回 None 不计数(跨身份串扰防护) + task_id/assigned_user 由调用方从所选任务(_current_task)提供, + 而非会话身份——避免"登录用户录制公共任务却按用户名匹配"的错配。 + 任务不在 tasks.json(手动临时任务名)时不计数,返回 None。 + 会话目录随后被删除也不影响该计数——进度以持久化值为准。 + """ + if not task_name: + return None + with _lock: + tasks = _read_raw() + target = None + if task_id: + for t in tasks: + if _tid(t) == task_id and t.get("name") == task_name: + target = t + break + if target is None: + for t in tasks: + if (t.get("name") == task_name + and _assigned_user(t) == (assigned_user or None)): + target = t + break + if target is None: + matches = [t for t in tasks if t.get("name") == task_name] + if len(matches) == 1: + target = matches[0] + if target is None: + return None + _ensure_sync_fields(target) + target["local_count"] = int(target.get("local_count", 0) or 0) + 1 + _recount(target) + target["status"] = _compute_status(target) + _write({"tasks": tasks, "updated_at": datetime.now().isoformat()}) + return dict(target) + + +def pending_sync_tasks() -> list[dict]: + """所有 local_count > synced_count 的任务快照(含 hidden,不按身份过滤—— + 身份不符由服务端 401/403 处理,跳过本轮即可)。 + + 纯读路径:直接 _read_raw(),跳过未迁移记录(无 local_count), + 绝不触发迁移写盘(flush 只上报,不改变本地计数语义)。 + """ + with _lock: + tasks = _read_raw() + out = [] + for t in tasks: + local = t.get("local_count") + if not isinstance(local, int): + continue + synced = int(t.get("synced_count", 0) or 0) + tid = _tid(t) + if local > synced and tid: + out.append({"id": tid, "name": t.get("name", ""), + "local_count": local, "synced_count": synced}) + return out + + +def mark_synced(task_id: str, synced_count: int, backend_count: int) -> dict | None: + """flush 成功后回写同步状态。 + + synced_count 必须是「快照水位 + 本次增量」(不是当前 local_count—— + 快照与响应之间 UI 线程可能又录了一段);水位只前进不后退; + backend_count 用响应值无条件替换(服务端权威,迁移基线可能高于真实 + 全局数,不能 max-前向)。返回更新后的任务。 + """ + with _lock: + tasks = _read_raw() + target = _find(tasks, task_id) + if target is None or not isinstance(target.get("local_count"), int): + return None + if synced_count > (int(target.get("synced_count", 0) or 0)): + target["synced_count"] = synced_count + target["backend_count"] = max(0, int(backend_count or 0)) + _recount(target) + target["status"] = _compute_status(target) + _write({"tasks": tasks, "updated_at": datetime.now().isoformat()}) + return dict(target) + + +def task_by_id(task_id: str) -> dict | None: + tasks = load_tasks() + return _find(tasks, task_id) + + +# ═══════════════════════════════════════════════════════════ +# Internal +# ═══════════════════════════════════════════════════════════ + +def _read_raw() -> list[dict]: + if not os.path.isfile(_TASKS_FILE): + _init_seed() + try: + with open(_TASKS_FILE, "r", encoding="utf-8") as f: + data = json.load(f) + return data.get("tasks", []) + except (json.JSONDecodeError, OSError): + _init_seed() + return [dict(t) for t in _SEED_TASKS] + + +def _write(data: dict): + os.makedirs(os.path.dirname(_TASKS_FILE), exist_ok=True) + tmp = _TASKS_FILE + ".tmp" + with open(tmp, "w", encoding="utf-8") as f: + json.dump(data, f, ensure_ascii=False, indent=2) + os.replace(tmp, _TASKS_FILE) + + +def _init_seed(): + _write({"tasks": [dict(t) for t in _SEED_TASKS], "updated_at": datetime.now().isoformat()}) + + +def _tid(task: dict) -> str: + return task.get("id", task.get("task_id", "")) + + +def _assigned_user(task: dict): + """任务的指派用户;null/空串/缺失统一归一化为 None(= 公共任务)。""" + return task.get("assigned_user") or None + + +def _assigned_at_key(task: dict) -> tuple: + """排序键: 带有效时间的排前,null/空/解析失败排后。 + (0, raw) 与 (1, ts) 首元素不同,跨类不会比较第二元素。""" + raw = task.get("assigned_at") or "" + if not raw: + return (0, "") + try: + dt = datetime.fromisoformat(raw.replace("Z", "+00:00")) + return (1, dt.timestamp()) + except ValueError: + return (0, raw) # 解析失败: 排最后,按原始字符串保序 + + +def _find(tasks: list[dict], task_id: str) -> dict | None: + for t in tasks: + if _tid(t) == task_id: + return t + return None + + +def _is_valid(task: dict) -> bool: + name = task.get("name", task.get("task_name", "")) + tid = task.get("id", task.get("task_id", "")) + return bool(name and name.strip()) and bool(tid and tid.strip()) and task.get("total_required", 0) > 0 + + +def _compute_status(task: dict) -> str: + total = task.get("total_required", 0) + completed = task.get("completed_count", 0) + if total <= 0: + return "pending" + if completed >= total: + return "completed" + if completed > 0: + return "in_progress" + return "pending" + + +def _count_with_fallback(task: dict) -> int: + """任务的录制完成次数:优先持久化值,缺字段(旧版本数据)回退目录扫描。""" + cur = task.get("completed_count") + if isinstance(cur, int) and cur >= 0: + return cur + return _count_sessions(task.get("name", "")) + + +def _count_sessions(task_name: str) -> int: + """扫描录制目录统计 episode 数 —— 仅用于旧数据迁移回填初值,非进度权威来源。 + + v1.1.0 池化布局:list_task_episodes(videos/data 文件组扫描,与 + episodes 每段文件一致——删除时两者同步移除);旧格式任务目录 + 回退按会话子目录计数。 + """ + if not task_name: + return 0 + task_dir = os.path.join(settings.RECORDING_DIR, task_name) + if not os.path.isdir(task_dir): + return 0 + try: + from core.helpers import detect_session_format, list_task_episodes + if detect_session_format(task_dir) == "pooled": + return len(list_task_episodes(task_dir)) + except ImportError: + pass + count = 0 + try: + for entry in os.listdir(task_dir): + ses_dir = os.path.join(task_dir, entry) + if not os.path.isdir(ses_dir): + continue + if os.path.isfile(os.path.join(ses_dir, "meta", "info.json")): + count += 1 + except OSError: + pass + return count + + +def _ensure_sync_fields(task: dict) -> bool: + """补全 local/synced/backend 三字段(迁移);返回是否发生迁移(需写回)。 + + 迁移(幂等,字段存在且为合法 int 即跳过): + local_count = 旧 completed_count(目录扫描兜底) + synced_count = local_count(历史不补报,避免重复计数) + backend_count = local_count(历史基线保显示连续;首次 merge/flush + 用真实全局数无条件替换) + """ + changed = False + local = task.get("local_count") + if not isinstance(local, int) or local < 0: + task["local_count"] = _count_with_fallback(task) + changed = True + synced = task.get("synced_count") + if not isinstance(synced, int) or synced < 0: + task["synced_count"] = task["local_count"] + changed = True + backend = task.get("backend_count") + if not isinstance(backend, int) or backend < 0: + task["backend_count"] = task["local_count"] + changed = True + return changed + + +def _recount(task: dict) -> int: + """显示值 = backend_count + (local_count - synced_count),写回 completed_count。 + + 防御:synced 不超 local(异常水位按已同步处理,宁可少显示不可多显示)。 + """ + local = int(task.get("local_count", 0) or 0) + synced = min(int(task.get("synced_count", 0) or 0), local) + task["completed_count"] = int(task.get("backend_count", 0) or 0) + (local - synced) + return task["completed_count"] diff --git a/collector/core/task_service.py b/collector/core/task_service.py new file mode 100755 index 0000000000000000000000000000000000000000..e89efaac0d86c3e1d8acd61af13d1556eb51d587 --- /dev/null +++ b/collector/core/task_service.py @@ -0,0 +1,405 @@ +""" +后台任务轮询服务 —— 定时从后端拉取可用任务列表,通过 Qt 信号通知 UI 更新。 + +设计模式参照 SyncService:QTimer 定时触发 + 后台 threading.Thread 执行 HTTP 请求。 + +信号: + tasks_updated(list) — 任务列表已刷新 + connection_status(bool) — 后端连接状态 (True=已连接) + error_occurred(str) — 轮询出错 +""" + +from __future__ import annotations +import threading + +import requests +from PyQt5.QtCore import QObject, pyqtSignal, QTimer + +from config import settings +from core import task_record + +CONNECT_TIMEOUT = 10 # HTTP 请求超时(秒) + + +def _normalize_tasks(raw: list[dict]) -> list[dict]: + """Map backend fields to internal field names. + + Backend → Internal: + current_count → completed_count + status "active" → "in_progress" + assigned_user 透传(null/空串/缺失统一归一化为 None = 公共任务) + """ + tasks = [] + for t in raw: + status = t.get("status", "active") + if status == "active": + status = "in_progress" + tasks.append({ + "id": t.get("id", ""), + "name": t.get("name", ""), + "description": t.get("description", ""), + "status": status, + "total_required": t.get("total_required", 0), + "completed_count": t.get("current_count", 0), + "assigned_at": t.get("assigned_at", ""), + "assigned_user": t.get("assigned_user") or None, + "params": t.get("params"), + }) + return tasks + + +class TaskService(QObject): + """后台任务轮询服务。 + + 定时向服务器请求任务列表,通过 Qt 信号通知 UI 刷新。 + 轮询在后台线程执行,不阻塞 UI。 + 支持 Cookie-based JWT 认证:先 POST /api/v1/auth/login,再用 Session 轮询。 + + 身份三态(_identity): None=未决(启动未选身份)/ "guest"=游客 / 用户名=已登录。 + 身份切换经 adopt_login()/set_guest() 完成,_epoch 代次守卫丢弃 + 后台线程中过期身份的响应。 + """ + + tasks_updated = pyqtSignal(list) # list[dict] — 任务列表 + connection_status = pyqtSignal(bool) # True=已连接, False=断开 + error_occurred = pyqtSignal(str) # 错误描述 + login_result = pyqtSignal(bool, str) # True=登陆成功, 附带消息 + identity_changed = pyqtSignal(str) # 身份确定/切换后发: "guest" 或用户名 + identity_expired = pyqtSignal() # 登录态轮询遇 401/403 —— 会话过期 + progress_synced = pyqtSignal() # 进度增量上报成功后本地计数已更新 + + LOGIN_TIMEOUT = 8 # 登录对话框同步校验超时(秒) + + def __init__(self, server_url: str = "", parent=None): + super().__init__(parent) + self._url = (server_url or settings.SERVER_URL).rstrip("/") + self._username = "" + self._password = "" + self._running = False + self._interval_ms = getattr(settings, 'TASK_POLL_INTERVAL_MS', 5000) + + self._timer = QTimer(self) + self._timer.timeout.connect(self._trigger_poll) + self._timer.setInterval(self._interval_ms) + + # HTTP Session 维持 auth cookie + self._session = requests.Session() + self._session.headers.update({"User-Agent": "DAQ-SDK/1.0"}) + + # 缓存最近一次成功拉取的任务列表 + self._cached_tasks: list[dict] = [] + self._logged_in = False + + # 身份状态机 + self._identity: str | None = None # None / "guest" / 用户名 + self._epoch = 0 # 身份代次:每次身份变化 +1 + + # 进度增量上报(多电脑协同聚合) + self._progress_supported = True # 后端 404 → False 静默降级本地口径 + self._flush_fail: dict[str, int] = {} # task_id → 连续失败次数(防日志刷屏) + self._flush_lock = threading.Lock() # 防 flush_now 与轮询 tick 并发重复 POST + self._poll_fail = 0 # 轮询连续失败次数(防日志刷屏) + + # ── 公开接口 ────────────────────────────────────── + + def start(self): + """启动定时轮询(身份由 adopt_login/set_guest 确定后调用)。""" + if self._running: + return + self._running = True + self._timer.start() + + def stop(self): + """停止定时轮询。""" + self._running = False + self._timer.stop() + + def poll_now(self): + """手动触发一次拉取(不改变定时器状态)。""" + self._trigger_login_and_poll() + + @staticmethod + def verify_credentials(url: str, username: str, password: str): + """独立 Session 同步校验登录凭据(供登录对话框使用,不触碰实例状态)。 + + 返回 (ok: bool, msg: str, cookies: RequestsCookieJar)。 + 成功时 cookies 含 auth cookie,由 adopt_login() 接管。 + """ + session = requests.Session() + session.headers.update({"User-Agent": "DAQ-SDK/1.0"}) + try: + r = session.post( + f"{url.rstrip('/')}/api/v1/auth/login", + json={ + "username": username, + "password": password, + "remember_me": True, + }, + timeout=TaskService.LOGIN_TIMEOUT, + ) + if r.status_code == 200: + data = r.json() + return True, str(data.get("message", "Login successful")), session.cookies + try: + detail = r.json().get("detail", f"HTTP {r.status_code}") + except Exception: + detail = f"HTTP {r.status_code}" + return False, str(detail), session.cookies + except requests.RequestException as e: + return False, str(e)[:200], session.cookies + + def adopt_login(self, url: str, username: str, cookies) -> None: + """采纳已验证的登录:cookie 拷入实例 Session,切换为账号身份并立即轮询。 + + 登录对话框已用 verify_credentials 校验过凭据,此处免二次 login。 + """ + self._url = (url or self._url).rstrip("/") + self._session.cookies.clear() + self._session.cookies.update(cookies) + self._username = username + self._password = "" + self._logged_in = True + self._identity = username + self._epoch += 1 + self.identity_changed.emit(username) + self._trigger_poll() + + def set_guest(self, url: str | None = None) -> None: + """切换为游客身份:清 cookie,立即轮询(只应拉到公共任务)。""" + if url: + self._url = url.rstrip("/") + self._session.cookies.clear() + self._username = "" + self._password = "" + self._logged_in = False + self._identity = "guest" + self._epoch += 1 + self.identity_changed.emit("guest") + self._trigger_poll() + + def current_identity(self) -> str | None: + """当前身份:None(未决)/ "guest" / 用户名。""" + return self._identity + + def set_server_url(self, url: str): + """动态修改服务器地址并立即重新轮询。""" + self._url = url.rstrip("/") + self._session.cookies.clear() + self._logged_in = False + self._progress_supported = True # 新后端可能已实现进度端点 + self._trigger_login_and_poll() + + def set_credentials(self, username: str, password: str): + """更新登陆凭据。""" + self._username = username + self._password = password + + def set_server_and_credentials(self, url: str, username: str, password: str): + """同时更新服务器地址和登陆凭据。""" + self._url = url.rstrip("/") + self._username = username + self._password = password + self._session.cookies.clear() + self._logged_in = False + self._trigger_login_and_poll() + + def set_interval(self, ms: int): + """动态修改轮询间隔(毫秒)。""" + self._interval_ms = ms + self._timer.setInterval(ms) + + def cached_tasks(self) -> list[dict]: + """返回缓存的任务列表(不发起网络请求)。""" + return list(self._cached_tasks) + + def flush_now(self): + """录制完成后的即时进度上报(后台线程,不阻塞 UI)。 + + 本机显示不依赖它(increment 已本地重算),只为其他机器秒级传播; + 正确性由轮询 tick 兜底。 + """ + threading.Thread(target=self._flush_progress, daemon=True).start() + + # ── 内部 ────────────────────────────────────────── + + def _post_progress(self, task_id: str, session_id: str, increment: int, + device: str): + """POST /api/v1/device/tasks/progress(幂等:后端按 session_id 去重)。 + + 返回 (新全局数 | None, 错误码);错误码: "" 成功 / "404" / "auth"(401/403) + / "net" / "http"。 + """ + try: + r = self._session.post( + f"{self._url}/api/v1/device/tasks/progress", + json={"task_id": task_id, "session_id": session_id, + "increment": increment, "device_name": device}, + timeout=CONNECT_TIMEOUT, + ) + if r.status_code == 200: + data = r.json() + if isinstance(data, dict) and isinstance(data.get("completed_count"), int): + return data["completed_count"], "" + return None, "http" + if r.status_code == 404: + return None, "404" + if r.status_code in (401, 403): + return None, "auth" + return None, "http" + except requests.RequestException: + return None, "net" + + def _note_fail(self, tid: str): + """进度上报失败计数:首次与每 10 次记一条日志,避免刷屏。""" + n = self._flush_fail.get(tid, 0) + 1 + self._flush_fail[tid] = n + if n == 1 or n % 10 == 0: + self.error_occurred.emit(f"任务进度上报失败(连续{n}次): {tid[:8]}") + + def _flush_progress(self): + """水位合并上报:每任务一次 POST increment = local - synced。 + + 幂等键含设备名与水位(重试不重复计数);崩溃安全由 tasks.json 落盘 + 保证;401/403 跳过本轮不标记死(重新登录后自然恢复)。 + """ + if not self._progress_supported: + return + if not self._flush_lock.acquire(blocking=False): + return # 已有一次 flush 在途(tick 或 flush_now),让给先到者 + try: + device = getattr(settings, 'DEVICE_NAME', 'EGO_001') + changed = False + for p in task_record.pending_sync_tasks(): + tid = p["id"] + inc = p["local_count"] - p["synced_count"] + session_id = f"{device}:{tid}:{p['synced_count']}" + new_backend, err = self._post_progress(tid, session_id, inc, device) + if err == "404": + self._progress_supported = False # 后端未升级 → 静默降级本地口径 + return + if new_backend is None: + self._note_fail(tid) # auth/net/http:跳过本轮,下个 tick 重试 + continue + self._flush_fail.pop(tid, None) + task_record.mark_synced(tid, p["synced_count"] + inc, new_backend) + changed = True + if changed: + self.progress_synced.emit() + finally: + self._flush_lock.release() + + def _trigger_poll(self): + """在后台线程执行一次 HTTP 轮询(仅拉取任务,不登陆)。""" + threading.Thread(target=self._poll, daemon=True).start() + + def _trigger_login_and_poll(self): + """在后台线程执行:先登陆再拉取任务。""" + threading.Thread(target=self._login_and_poll, daemon=True).start() + + def _login_and_poll(self): + """登陆 → 拉取任务列表。 + + 连接状态一律以实际响应为准(_do_login 失败置灰、_poll 成功置绿), + 不在此处凭「无需认证」提前置绿 —— 否则地址填错/后端宕机时, + 一次刷新也会让界面谎报「后端已连接」。 + """ + if self._username and self._password: + ok = self._do_login() + if not ok: + self.connection_status.emit(False) + return + self._poll() + + def _do_login(self) -> bool: + """POST /api/v1/auth/login 获取 auth_token cookie。返回是否成功。""" + try: + r = self._session.post( + f"{self._url}/api/v1/auth/login", + json={ + "username": self._username, + "password": self._password, + "remember_me": True, + }, + timeout=CONNECT_TIMEOUT, + ) + if r.status_code == 200: + self._logged_in = True + self._identity = self._username + self._epoch += 1 + data = r.json() + msg = data.get("message", "Login successful") + self.login_result.emit(True, msg) + self.identity_changed.emit(self._username) + return True + else: + self._logged_in = False + try: + detail = r.json().get("detail", f"HTTP {r.status_code}") + except Exception: + detail = f"HTTP {r.status_code}" + self.login_result.emit(False, str(detail)) + self.error_occurred.emit(f"登陆失败: {detail}") + return False + except requests.RequestException as e: + self._logged_in = False + self.login_result.emit(False, str(e)[:200]) + self.error_occurred.emit(f"登陆失败: {e}") + return False + + def _poll(self): + """Poll GET /api/v1/device/tasks?device_name=xxx and emit task list.""" + epoch = self._epoch + try: + device = getattr(settings, 'DEVICE_NAME', 'EGO_001') + r = self._session.get( + f"{self._url}/api/v1/device/tasks", + params={"device_name": device}, + timeout=CONNECT_TIMEOUT, + ) + if epoch != self._epoch: + return # 身份已切换,丢弃过期响应 + if r.status_code == 200: + data = r.json() + raw = data.get("tasks", []) if isinstance(data, dict) else [] + if self._identity == "guest": + # 游客态防御性兜底:契约上服务端只回公共任务, + # 万一返回指派任务也一律丢弃 + raw = [t for t in raw if not (t.get("assigned_user") or None)] + tasks = _normalize_tasks(raw) + self._cached_tasks = tasks + self.tasks_updated.emit(tasks) + self.connection_status.emit(True) + self._poll_fail = 0 # 成功即清零连续失败计数 + if epoch == self._epoch: + # GET 成功才 flush —— 断网时 POST 必然失败,不浪费请求; + # 恢复后下一个成功 tick 内收敛 + self._flush_progress() + elif r.status_code in (401, 403): + if self._identity == "guest": + # 游客态 401:旧后端未遵循契约(匿名应 200)——只报错不断身份, + # 本地公共任务照常显示,可随时账号登录 + self.connection_status.emit(False) + self.error_occurred.emit( + f"游客访问被服务器拒绝 (HTTP {r.status_code}),请尝试账号登录") + elif self._identity is not None: + # 登录态认证失效 → 身份置空,通知 UI 重登/降级游客 + self._logged_in = False + self._identity = None + self._epoch += 1 + self.connection_status.emit(False) + self.error_occurred.emit(f"认证失效 HTTP {r.status_code}") + self.identity_expired.emit() + else: + # 服务器错误(如 500)不改变连接状态,只记录错误 + self.error_occurred.emit(f"HTTP {r.status_code}") + except requests.RequestException as e: + if epoch != self._epoch: + return + # 请求都发不出去 = 后端不可达:如实置灰「后端未连接」, + # 恢复后下个成功 tick 再置绿(5s 内自愈)。连续失败只记 + # 首条与每 10 条(服务器卡死时 5s 一条会刷屏) + self.connection_status.emit(False) + self._poll_fail += 1 + if self._poll_fail == 1 or self._poll_fail % 10 == 0: + self.error_occurred.emit( + f"{str(e)[:180]}(连续{self._poll_fail}次)") diff --git a/collector/core/uploader.py b/collector/core/uploader.py new file mode 100755 index 0000000000000000000000000000000000000000..9a5fb189ab3d0561d135d7c0ec8a69b8f1db13a2 --- /dev/null +++ b/collector/core/uploader.py @@ -0,0 +1,749 @@ +""" +上传队列管理器 —— 自动打包 session 为 zip → 上传到服务器。 + +上传流程: + 1. 用 zipfile 将 session 目录打包(保留 LeRobot v3 内部结构) + 2. 通过 APIClient 将 zip 上传到 POST /api/v1/session/upload + 3. 清理临时 zip 文件 + 4. 通过 Qt 信号通知 UI 进度 +""" + +from __future__ import annotations +import os +import re +import subprocess +import time +import zipfile +import threading +import tempfile +from datetime import datetime +from typing import Optional + +from PyQt5.QtCore import QObject, pyqtSignal, QMutex, QMutexLocker + +from config import settings +from core.database import db +from core.api_client import APIClient +from core.helpers import episode_file_suffix + + +# ═══════════════════════════════════════════════════════ +# 上传任务 +# ═══════════════════════════════════════════════════════ + +class UploadTask: + """单个上传任务的数据对象。""" + + __slots__ = ("id", "session_path", "session_name", "episode_index", + "status", "progress", "retry_count", "server_url", + "server_session_id", "error_message", "created_at", "updated_at") + + def __init__(self, session_path: str, server_url: str, episode_index: int = 0): + import uuid + self.id = uuid.uuid4().hex[:12] + self.session_path = session_path + # v1.1.0 池化:session_path = 任务目录,session_name 即任务名 + self.session_name = os.path.basename(session_path) + self.episode_index = episode_index + self.status = "pending" + self.progress = 0.0 + self.retry_count = 0 + self.server_url = server_url + self.server_session_id = "" + self.error_message = "" + now = datetime.now().isoformat() + self.created_at = now + self.updated_at = now + + def to_dict(self) -> dict: + return {k: getattr(self, k, "") for k in self.__slots__} + + @staticmethod + def from_row(row: dict) -> "UploadTask": + t = UploadTask.__new__(UploadTask) + for k in UploadTask.__slots__: + setattr(t, k, row.get(k, "")) + return t + + +# ═══════════════════════════════════════════════════════ +# 上传管理器 +# ═══════════════════════════════════════════════════════ + +class UploadManager(QObject): + """ + 上传队列管理器 — 自动打包 + 上传。 + + 信号: + task_added(str) — 任务入队 + task_started(str) — 任务开始 + task_status(str, str) — 状态文字更新 (task_id, msg) + task_progress(str, float) — 进度 (task_id, 0.0~1.0) + task_completed(str) — 任务完成 + task_failed(str, str) — 任务失败 (task_id, error) + all_completed() — 全部任务完成 + """ + + task_added = pyqtSignal(str) + task_started = pyqtSignal(str) + task_status = pyqtSignal(str, str) + task_progress = pyqtSignal(str, float) + task_completed = pyqtSignal(str) + task_failed = pyqtSignal(str, str) + all_completed = pyqtSignal() + + def __init__(self, server_url: str = "", session=None): + super().__init__() + self._server_url = server_url or settings.SERVER_URL + self._retry_max = settings.UPLOAD_RETRY_MAX + self._max_concurrent = settings.UPLOAD_MAX_CONCURRENT + self._shared_session = session # 复用已认证的 requests.Session + self._project_id = settings.load_upload_project_id() # 目标项目 ID(空=服务器自动匹配) + + self._queue: list[UploadTask] = [] + self._active: dict[str, threading.Thread] = {} + self._active_tasks: dict[str, UploadTask] = {} # task_id → 任务对象(防重查询用) + self._mutex = QMutex() + self._running = False + self._worker_thread: Optional[threading.Thread] = None + + # ── 公开接口 ────────────────────────────────────── + + @property + def server_url(self) -> str: + return self._server_url + + @server_url.setter + def server_url(self, value: str): + self._server_url = value + + @property + def project_id(self) -> str: + """上传时携带的目标项目 ID(空 = 服务器按名称自动匹配)。""" + return self._project_id + + @project_id.setter + def project_id(self, value: str): + self._project_id = (value or "").strip() + + def add_task(self, session_path: str, episode_index: int = 0) -> str: + """添加一个上传任务,返回 task_id。 + + v1.1.0 池化:防重键 (task_dir, episode_index)——同一 episode 已在队列/ + 执行中时返回既有任务 id,不重复入队(自动上传与手动上传互防)。 + """ + with QMutexLocker(self._mutex): + for t in self._queue + list(self._active_tasks.values()): + if (t.session_path == session_path + and t.episode_index == episode_index): + return t.id + task = UploadTask(session_path, self._server_url, episode_index) + self._save_to_db(task) + with QMutexLocker(self._mutex): + self._queue.append(task) + self.task_added.emit(task.id) + return task.id + + def add_tasks(self, items: list) -> list[str]: + """批量入队。items 元素为路径字符串或 (path, episode_index) 元组。""" + out = [] + for it in items: + if isinstance(it, (tuple, list)): + p, n = it[0], it[1] + else: + p, n = it, 0 + if os.path.isdir(p): + out.append(self.add_task(p, n)) + return out + + def has_task(self, session_path: str, episode_index: int = 0) -> bool: + """(task_dir, episode_index) 是否已在队列/执行中。 + + 上传对话框复用主窗口共享管理器后,跨对话框会话防重靠此判断: + 上次提交仍在后台进行时,重新打开对话框不会再重复入队。 + """ + with QMutexLocker(self._mutex): + for t in self._queue + list(self._active_tasks.values()): + if (t.session_path == session_path + and t.episode_index == episode_index): + return True + return False + + def start(self): + if self._running: + return + self._running = True + self._worker_thread = threading.Thread( + target=self._worker_loop, daemon=True, name="upload-worker" + ) + self._worker_thread.start() + + def stop(self): + self._running = False + if self._worker_thread and self._worker_thread.is_alive(): + self._worker_thread.join(timeout=10) + + def pending_count(self) -> int: + with QMutexLocker(self._mutex): + return len(self._queue) + + def active_count(self) -> int: + with QMutexLocker(self._mutex): + return len(self._active) + + def all_done(self) -> bool: + return self.pending_count() == 0 and self.active_count() == 0 + + # ── 工作循环 ────────────────────────────────────── + + def _worker_loop(self): + while self._running: + task = None + with QMutexLocker(self._mutex): + if len(self._active) < self._max_concurrent and self._queue: + task = self._queue.pop(0) + self._active[task.id] = None + + if task: + t = threading.Thread( + target=self._upload_one, args=(task,), + daemon=True, name=f"upload-{task.id[:8]}" + ) + with QMutexLocker(self._mutex): + self._active[task.id] = t + self._active_tasks[task.id] = task + t.start() + else: + time.sleep(0.5) + + def _upload_one(self, task: UploadTask): + """执行单个任务的完整上传流程。""" + task_id = task.id + self.task_started.emit(task_id) + + client = APIClient(self._server_url, session=self._shared_session) + zip_path = None + precomp = {} + + try: + # ── 步骤 1: 视频预压缩(大会话必备)── + if settings.UPLOAD_PRECOMPRESS_VIDEO: + precomp = self._precompress_videos( + task.session_path, task_id, task.episode_index) + + # ── 步骤 2: 打包为 zip(池化 = 单 episode 切片)── + self.task_status.emit(task_id, "正在打包…") + if task.episode_index > 0: + zip_path = self._zip_episode( + task.session_path, task.session_name, task.episode_index, + task_id, precomp) + else: + zip_path = self._zip_session( + task.session_path, task.session_name, task_id, precomp) + + if not zip_path: + raise RuntimeError("打包失败") + + zip_size = os.path.getsize(zip_path) + self.task_status.emit(task_id, + f"打包完成 ({zip_size / 1024 / 1024:.1f} MB),正在上传…") + + # ── 步骤 3: 上传 zip ── + last_ratio = [0.0] + + def _progress(uploaded: int, total: int): + ratio = uploaded / max(total, 1) + if ratio - last_ratio[0] >= 0.02 or ratio >= 1.0: + last_ratio[0] = ratio + # 0.12~1.0:预压缩 0~0.08、打包 0.08~0.12、上传 0.12~1.0 + self.task_progress.emit(task_id, 0.12 + 0.88 * ratio) + mb_up = uploaded / 1024 / 1024 + mb_total = total / 1024 / 1024 + self.task_status.emit(task_id, + f"上传中 {mb_up:.1f}/{mb_total:.1f} MB") + + # 目标项目:优先用户显式配置;未配置时按会话名精确匹配服务器 + # 项目名自动消歧(防 409 "Ambiguous project prefix"), + # 匹配不到则留空由服务器按名称自动匹配/自动创建。 + project_id = self._project_id or self._resolve_project_by_name( + client, task.session_name) + if project_id and not self._project_id: + self.task_status.emit(task_id, f"已匹配目标项目 {project_id[:8]}…") + + result = client.upload_session_zip( + zip_path, task.session_name, progress_cb=_progress, + name=task.session_name, project_id=project_id, + # 表单值 = file 号(0 基,与本地 file-NNN 对齐;真实全局 + # 序号 N 在包内 parquet 行的 episode_index 列) + episode_index=episode_file_suffix(task.episode_index), + ) + + if not result.get("ok"): + raise RuntimeError(result.get("error", "上传失败")) + + # ── 完成 ── + task.status = "completed" + task.progress = 1.0 + task.server_session_id = result.get("session_id", "") + task.error_message = "" # 清掉此前重试残留的错误文本 + task.retry_count = 0 + task.updated_at = datetime.now().isoformat() + self._save_to_db(task) + self.task_progress.emit(task_id, 1.0) + self.task_status.emit(task_id, "上传完成 ✅") + self.task_completed.emit(task_id) + + except Exception as e: + task.error_message = str(e)[:500] + task.retry_count += 1 + task.updated_at = datetime.now().isoformat() + + if task.retry_count < self._retry_max: + task.status = "pending" + self._save_to_db(task) + with QMutexLocker(self._mutex): + self._queue.append(task) + self.task_status.emit(task_id, + f"重试 {task.retry_count}/{self._retry_max}…") + self.task_added.emit(task_id) + else: + task.status = "failed" + self._save_to_db(task) + self.task_status.emit(task_id, f"失败: {task.error_message[:80]}") + self.task_failed.emit(task_id, task.error_message) + + finally: + client.close() + # 清理临时 zip、预压缩临时视频与 episodes 单行切片 + slice_tmp = os.path.join( + os.path.dirname(task.session_path), + f"_episodes_{task_id}_{task.episode_index}.parquet") + for p in [zip_path, slice_tmp] + list(precomp.values()): + if p and os.path.isfile(p): + try: + os.remove(p) + except OSError: + pass + + with QMutexLocker(self._mutex): + self._active.pop(task_id, None) + self._active_tasks.pop(task_id, None) + + if self.all_done(): + self.all_completed.emit() + + # ── 项目消歧 ────────────────────────────────────── + + @staticmethod + def _strip_episode_suffix(session_name: str) -> str: + """去掉会话名末尾的 episode 序号(_000001)得到任务/项目名。""" + import re + m = re.match(r"^(.*)_(\d{6,})$", session_name) + return m.group(1) if m else session_name + + @staticmethod + def _resolve_project_by_name(client: "APIClient", + session_name: str) -> str: + """按会话名匹配服务器项目,唯一命中时返回 project_id,否则空。 + + 优先项目名精确相等(服务器为任务名自动创建的项目即此形式); + 其次 workflow 名相等且唯一(不唯一说明撞名,宁可让用户手动选)。 + """ + stripped = UploadManager._strip_episode_suffix(session_name) + projects = client.get_projects() + exact = [p for p in projects if p.get("name") == stripped] + if len(exact) == 1: + return exact[0].get("id", "") + if not exact: + wf = [p for p in projects + if stripped in (p.get("workflow_names") or [])] + if len(wf) == 1: + return wf[0].get("id", "") + return "" + + # ── 打包 ────────────────────────────────────────── + + def _zip_session(self, session_dir: str, session_name: str, + task_id: str = "", precomp: Optional[dict] = None + ) -> Optional[str]: + """ + 将 session 目录打包为 zip(LeRobot v3 兼容路径)。 + + EgoData 视频路径转换为 LeRobot v3 格式: + 旧结构: videos/stereo_left.mp4 → videos/stereo_left/chunk_000000.mp4 + 新结构: videos/stereo_left/chunk-0000/stereo_left.mp4 → videos/stereo_left/chunk_000000.mp4 + + precomp: 预压缩映射 {原视频路径: 临时压缩视频路径},打包时用它顶替原视频 + (视频已是压缩格式,zip 用 ZIP_STORED 免二次压缩)。 + + Returns: + 临时 zip 文件路径,失败返回 None + """ + try: + # 在 recordings 目录下创建临时 zip(同盘避免跨盘拷贝); + # 文件名带 task_id——同进程内并发任务不会互相覆盖 + parent_dir = os.path.dirname(session_dir) + tmp_path = os.path.join(parent_dir, + f"_{session_name}_upload_{task_id}.zip") + + file_list = [] + for root, dirs, files in os.walk(session_dir): + for f in files: + fp = os.path.join(root, f) + arcname = os.path.relpath(fp, session_dir) + + # EgoData 路径 → LeRobot v3 兼容路径 + if "chunk-0000" in arcname: + parts = arcname.replace("\\", "/").split("/") + if parts[0] == "videos" and len(parts) >= 4: + # 用目录名作为 camera key,_aux 文件归入主摄像头目录 + # videos/stereo_left/chunk-0000/stereo_left_aux.mp4 + # → videos/stereo_left/chunk_0000/stereo_left_aux.mp4 + cam_name = parts[1] + file_name = parts[-1] + arcname = f"videos/{cam_name}/chunk_0000/{file_name}" + elif parts[0] == "data" and len(parts) >= 4: + # data//chunk-0000/.parquet → data//chunk_0000/.parquet + sensor_name = parts[1] + file_name = parts[-1] + arcname = f"data/{sensor_name}/chunk_0000/{file_name}" + else: + # 其它含 chunk-0000 的路径:只把 chunk-0000 替换为 chunk_0000 + arcname = arcname.replace("chunk-0000", "chunk_0000") + # 旧结构兼容: videos/.mp4 (flat) → videos//chunk_0000/file-0000.mp4 + elif arcname.startswith("videos/") and arcname.count("/") == 1: + cam_name = os.path.splitext(f)[0] + arcname = f"videos/{cam_name}/chunk_0000/file-0000.mp4" + + file_list.append((fp, arcname)) + + total = len(file_list) + with zipfile.ZipFile(tmp_path, "w", zipfile.ZIP_STORED) as zf: + for i, (fp, arcname) in enumerate(file_list): + zf.write(precomp.get(fp, fp), arcname) + ratio = (i + 1) / total + # 打包占进度 0.08~0.12(预压缩 0~0.08,上传 0.12~1.0) + self.task_progress.emit(task_id, 0.08 + 0.04 * ratio) + + return tmp_path + except Exception as e: + self.task_status.emit(task_id, f"打包出错: {e}") + return None + + # ── 打包(v1.1.0 池化:单 episode 切片)──────────── + + def _zip_episode(self, task_dir: str, session_name: str, + episode_index: int, task_id: str = "", + precomp: Optional[dict] = None) -> Optional[str]: + """ + 将池化任务里的单个 episode 打包为 zip(上传契约): + + videos/chunk-{c:03d}/{image_key}/episode-{f:03d}.{ext} 本 episode 各 key 视频 + data/chunk-{c:03d}/episode-{f:03d}.parquet 本 episode 数据 + meta/info.json / stats.json 快照 / tasks.jsonl 任务级元数据 + meta/episodes/chunk-{c:03d}/episode-{f:03d}.parquet 本 episode 元数据(每段一文件) + + zip 内相对路径与原池化目录一致,服务器导入器凭 + info.json.format=="pooled_episodes_v1" 识别。 + precomp: 预压缩映射 {原视频路径: 临时压缩视频路径}(ZIP_STORED 顶替)。 + """ + from core.helpers import ( + episode_chunk_file, chunk_dir, episode_video_files, + pooled_data_parquet_path, pooled_episodes_path, + pooled_info_path, pooled_stats_path, pooled_tasks_jsonl_path, + ) + precomp = precomp or {} + try: + parent_dir = os.path.dirname(task_dir) + tmp_path = os.path.join( + parent_dir, + f"_{session_name}_ep" + f"{episode_file_suffix(episode_index):06d}_upload_" + f"{task_id}.zip") + + c, f = episode_chunk_file(episode_index) + file_list = [] + + # 本 episode 各 key 视频(深度视频——12-bit 灰 mp4 / 旧双流 + # mkv——一并打包,不预压缩) + for key, vp in sorted(episode_video_files(task_dir, episode_index).items()): + if not os.path.isfile(vp): + continue + ext = os.path.splitext(vp)[1] + arcname = f"videos/{chunk_dir(c)}/{key}/episode-{f:03d}{ext}" + file_list.append((vp, arcname)) + + # 本 episode 数据 parquet + data_pq = pooled_data_parquet_path(task_dir, episode_index) + if os.path.isfile(data_pq): + file_list.append((data_pq, os.path.relpath(data_pq, task_dir))) + + # episodes 每段文件直传;旧分片回退=单行切片(临时文件,打完包即删) + slice_file, slice_arc = self._episode_slice_parquet( + task_dir, episode_index, parent_dir, task_id) + if slice_file: + file_list.append((slice_file, slice_arc)) + + # 任务级元数据(stats.json 为 v1.1.1 自含累加器格式) + for mp in (pooled_info_path(task_dir), pooled_stats_path(task_dir), + pooled_tasks_jsonl_path(task_dir)): + if os.path.isfile(mp): + file_list.append((mp, os.path.relpath(mp, task_dir))) + + total = len(file_list) + with zipfile.ZipFile(tmp_path, "w", zipfile.ZIP_STORED) as zf: + for i, (fp, arcname) in enumerate(file_list): + zf.write(precomp.get(fp, fp), arcname) + # 打包占进度 0.08~0.12(预压缩 0~0.08,上传 0.12~1.0) + self.task_progress.emit(task_id, 0.08 + 0.04 * (i + 1) / total) + + return tmp_path + except Exception as e: + self.task_status.emit(task_id, f"打包出错: {e}") + return None + + def _episode_slice_parquet(self, task_dir: str, episode_index: int, + tmp_dir: str, task_id: str): + """episodes 元数据文件(zip 内 arcname 与新布局同编号)。 + + 新布局=每段一个文件:返回原文件直传(不做切片)。 + 旧分片回退(每 chunk 一个多行文件):取本 episode 那一行写成 + 临时单行 parquet。返回 (源文件路径, zip 内 arcname); + 文件缺失/行不存在返回 (None, "")。 + """ + from core.helpers import (episode_chunk_file, pooled_episodes_path, + _legacy_episodes_shard_path) + c, _ = episode_chunk_file(episode_index) + ep_file = pooled_episodes_path(task_dir, episode_index) + arcname = os.path.relpath(ep_file, task_dir) + if os.path.isfile(ep_file): + try: + import pyarrow.parquet as pq + rows = pq.read_table(ep_file).to_pylist() + except Exception: + rows = None + # 单行且正是 N → 直传(旧分片只剩该行的退化情形同样安全) + if rows is not None and len(rows) == 1 and \ + rows[0].get("episode_index") == episode_index: + return ep_file, arcname + # 旧分片回退(分片名 = chunk 号 file-{c:03d},v1.1.2 起与每段文件 + # episode-{f:03d} 不再重名) + legacy = _legacy_episodes_shard_path(task_dir, c) + if not os.path.isfile(legacy): + return None, "" + try: + import pyarrow as pa + import pyarrow.parquet as pq + tbl = pq.read_table(legacy) + mask = pa.array( + [v == episode_index + for v in tbl.column("episode_index").to_pylist()]) + sub = tbl.filter(mask) + if sub.num_rows == 0: + return None, "" + tmp = os.path.join( + tmp_dir, f"_episodes_{task_id}_{episode_index}.parquet") + pq.write_table(sub, tmp) + return tmp, arcname + except Exception: + return None, "" + + # ── 视频预压缩 ──────────────────────────────────── + + def _find_working_ffmpeg(self) -> Optional[str]: + """探测可用的 ffmpeg。 + + conda base 的 ffmpeg 因 openvino/tbb 库冲突无法运行, + 优先用 lerobot 环境的独立 ffmpeg,再退回系统 PATH。 + """ + candidates = [ + os.path.expanduser("~/miniconda3/envs/lerobot/bin/ffmpeg"), + os.path.expanduser("~/anaconda3/envs/lerobot/bin/ffmpeg"), + "ffmpeg", + ] + for c in candidates: + try: + r = subprocess.run([c, "-version"], capture_output=True, + timeout=10) + if r.returncode == 0: + return c + except Exception: + continue + return None + + @staticmethod + def _parse_video_codec(stderr_text: str) -> Optional[str]: + """解析 ffmpeg -i stderr 的 Video 流编码名(小写),失败返回 None。""" + m = re.search(r"Stream #[^\n]*?Video:\s*([a-zA-Z0-9_]+)", stderr_text) + return m.group(1).lower() if m else None + + def _probe_video_text(self, ffmpeg: str, path: str) -> Optional[str]: + """ffmpeg -i 的 stderr 文本(其 rc 恒非 0,不看 rc); + 异常/超时 → None。""" + try: + r = subprocess.run([ffmpeg, "-hide_banner", "-i", path], + capture_output=True, timeout=30) + except Exception: + return None + return (r.stderr or b"").decode("utf-8", "ignore") + + def _is_hevc(self, ffmpeg: str, path: str) -> Optional[bool]: + """码流探测:视频是否已是 HEVC。True=是 / False=否 / None=未知。 + + 探测失败 → None(=未知,调用方照旧压缩,安全方向)。 + """ + text = self._probe_video_text(ffmpeg, path) + codec = self._parse_video_codec(text or "") + if codec is None: + return None + if codec in ("hevc", "h265"): + return True + return False + + def _is_gray12le(self, ffmpeg: str, path: str) -> bool: + """码流探测:是否 gray12le 12-bit 灰度(v1.1.2 深度数据轨)。 + + 深度轨转 8-bit 预压即毁码值——HEVC 探测失败(None)时此检查 + 兜底。探测失败保守 False:此时 ffmpeg 不可用,转码同样会失败, + 原文件原样进包,数据不损。 + """ + text = self._probe_video_text(ffmpeg, path) + return bool(text and "gray12le" in text) + + def _precompress_videos(self, session_dir: str, + task_id: str = "", + episode_index: int = 0) -> dict: + """把 session 内 videos 下的视频重编码到低码率(HEVC CRF 档见 settings)。 + + 保持分辨率/帧率 → 帧数不变,与 parquet/时间戳的帧级对齐不受影响。 + 已是 HEVC 的视频(v1.0.9 录制直出)跳过预压 —— 再压一遍纯属浪费。 + v1.1.0 池化:episode_index > 0 时只压本 episode 的视频;深度视频 + 有专门的 12-bit 灰度检测跳过预压缩(再编码会破坏对数深度码)。 + 重编码产物放在 recordings 同盘临时文件,返回 {原路径: 临时路径}; + 找不到 ffmpeg 或没视频时返回 {}(调用方直接跳过)。 + """ + ffmpeg = self._find_working_ffmpeg() + if not ffmpeg: + self.task_status.emit(task_id, "未找到 ffmpeg,跳过视频压缩") + return {} + + targets = [] + if episode_index > 0: + from core.helpers import episode_video_files + targets = [ + vp for vp in sorted(episode_video_files(session_dir, + episode_index).values()) + if vp.lower().endswith((".mp4", ".avi", ".mov")) + and os.path.isfile(vp) + ] + else: + for root, dirs, files in os.walk(os.path.join(session_dir, "videos")): + for f in files: + if f.lower().endswith((".mp4", ".avi", ".mov")): + targets.append(os.path.join(root, f)) + if not targets: + return {} + + crf = getattr(settings, "UPLOAD_VIDEO_CRF", 30) + parent_dir = os.path.dirname(session_dir) + mapping = {} + for i, src in enumerate(targets): + # ★ v1.0.9:已是 HEVC 的录制件跳过预压(录制端直出目标档; + # 探测失败按"未知"照旧压缩——安全方向,旧 h264 会话行为不变) + if self._is_hevc(ffmpeg, src) is True: + self.task_status.emit( + task_id, f"{os.path.basename(src)} 已是 HEVC,跳过预压缩") + continue + # ★ v1.1.2:深度 12-bit 灰度视频是数据轨不是画面,转 8-bit + # 预压即毁码值(HEVC 探测失败时此检查兜底) + if self._is_gray12le(ffmpeg, src): + self.task_status.emit( + task_id, f"{os.path.basename(src)} 是 12-bit 灰度深度视频,跳过预压缩") + continue + # 临时文件名带 task_id:并发任务各自的压缩产物互不覆盖 + # (旧写法按进程号+序号命名,同进程两条任务的同名视频 + # 会写同一文件,ffmpeg 互踩 → 打进 zip 的视频损坏) + dst = os.path.join( + parent_dir, + f"_precomp_{task_id}_{i}_{os.path.basename(src)}") + self.task_status.emit( + task_id, + f"压缩视频 {i + 1}/{len(targets)}: {os.path.basename(src)} " + f"(HEVC CRF {crf})…") + try: + r = subprocess.run( + [ffmpeg, "-y", "-i", src, "-c:v", "libx265", + "-crf", str(crf), "-preset", "veryfast", + "-tag:v", "hvc1", "-pix_fmt", "yuv420p", dst], + capture_output=True, timeout=3600) + if r.returncode == 0 and os.path.isfile(dst): + mapping[src] = dst + src_mb = os.path.getsize(src) / 1048576 + dst_mb = os.path.getsize(dst) / 1048576 + self.task_status.emit( + task_id, + f"压缩 {os.path.basename(src)}: " + f"{src_mb:.0f}MB → {dst_mb:.0f}MB") + elif os.path.isfile(dst): + try: + os.remove(dst) + except OSError: + pass + except Exception: + if os.path.isfile(dst): + try: + os.remove(dst) + except OSError: + pass + return mapping + + # ── 数据库 ──────────────────────────────────────── + + def _save_to_db(self, task: UploadTask): + d = task.to_dict() + db.conn.execute(""" + INSERT OR REPLACE INTO upload_task + (id, session_path, session_name, episode_index, status, progress, + retry_count, server_url, server_session_id, + error_message, created_at, updated_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, (d["id"], d["session_path"], d["session_name"], + d["episode_index"], d["status"], d["progress"], + d["retry_count"], d["server_url"], + d["server_session_id"], d["error_message"], + d["created_at"], d["updated_at"])) + db.conn.commit() + + @staticmethod + def get_upload_status(session_path: str, episode_index: int = 0) -> str: + """(task_dir, episode_index) 键查询最近一次上传状态(v1.1.0 池化)。""" + row = db.conn.execute( + "SELECT status FROM upload_task WHERE session_path = ? " + "AND episode_index = ? " + "ORDER BY created_at DESC LIMIT 1", (session_path, episode_index) + ).fetchone() + return row["status"] if row else "pending" + + @staticmethod + def list_tasks(session_path: str = "", + episode_index: int | None = None) -> list[dict]: + """episode_index 为 None 时跨 episode 查(旧语义);int 时精确匹配。""" + cond, args = "", [] + if session_path: + cond += "session_path = ?" + args.append(session_path) + if episode_index is not None: + if cond: + cond += " AND " + cond += "episode_index = ?" + args.append(episode_index) + if cond: + rows = db.conn.execute( + f"SELECT * FROM upload_task WHERE {cond} " + "ORDER BY created_at DESC", args + ).fetchall() + else: + rows = db.conn.execute( + "SELECT * FROM upload_task ORDER BY created_at DESC" + ).fetchall() + return [dict(r) for r in rows] diff --git a/collector/core/usb_glove_engine.py b/collector/core/usb_glove_engine.py new file mode 100644 index 0000000000000000000000000000000000000000..41a8cc8e4a0c7c967a2710b83a205b0bcf7cece3 --- /dev/null +++ b/collector/core/usb_glove_engine.py @@ -0,0 +1,228 @@ +"""USB (Type-C) 手套数据引擎 —— STM32 CDC 串口,IMU 四元数 + 16×16 触觉。 + +复用 core.glove_usb 明文协议栈:RawImuStream 自带 daemon 串口线程 +(自动重连、CRC 校验、队列限长),本引擎在其上再起 IMU / 触觉两个消费 +线程;对外信号与属性口径与 SensorBLEEngine 完全对齐,GloveWidget 通过 +engine= 参数注入即可无缝切换两种手套。 +""" + +from __future__ import annotations + +import threading +import time + +import numpy as np +from PyQt5.QtCore import QObject, pyqtSignal + +from core.glove_usb import RawImuStream, TactilePreprocessor +from core.glove_usb.errors import StreamClosedError, StreamTimeoutError + +MATRIX_ROWS = 16 +MATRIX_COLS = 16 +IMU_COUNT = 16 +QUAT_COMPONENTS = 4 +TARGET_FPS = 80 # 手套 IMU 额定帧率(触觉与 IMU 复用同一串口流) + + +class UsbGloveEngine(QObject): + """STM32 USB 手套采集引擎(信号口径 = SensorBLEEngine)。 + + 信号 + ---- + connected(str) — 串口已打开,设备地址(端口路径) + disconnected() — 串口已断开 + fps_updated(float) — IMU 实测帧率 + error_occurred(str) — 错误消息 + calibration_progress(int) — 触觉基线校准进度 (0-100) + """ + + connected = pyqtSignal(str) + disconnected = pyqtSignal() + fps_updated = pyqtSignal(float) + error_occurred = pyqtSignal(str) + calibration_progress = pyqtSignal(int) + + def __init__(self, serial_port: str = ""): + super().__init__() + self.serial_port = serial_port + + # ── 触觉(16×16 float32 ADC,口径同 ble_engine.data_array)── + self.data_array = np.zeros((MATRIX_ROWS, MATRIX_COLS), + dtype=np.float32) + self.data_lock = threading.Lock() + self.latest_data_ts_us = 0 # 宿主收帧时刻(μs,帧龄显示用) + + # ── IMU(16×4 XYZW 四元数 + 有效性掩码)── + self.imu_array = np.zeros((IMU_COUNT, QUAT_COMPONENTS), dtype=np.float64) + self.imu_valid = np.zeros(IMU_COUNT, dtype=bool) + self.imu_lock = threading.Lock() + self.latest_imu_ts_us = 0 # 设备时钟 μs(信息用) + self.imu_present_count = 0 # 有效 IMU 传感器数(覆盖条显示) + + # ── 帧率(1s 滑动窗)── + self.hardware_fps = 0.0 # IMU fps(主显示) + self.tactile_fps = 0.0 + + # ── 触觉降噪管线(工具包 TactilePreprocessor,含自动基线校准)── + self._preprocessor = TactilePreprocessor() + self.is_calibrating = True + self.drift_baseline_val = 0.0 + # 覆盖条渲染参数(GloveWidget 直接读,口径同 ble_engine) + self.base_noise_gate = self._preprocessor.base_gate + self.dynamic_noise_ratio = self._preprocessor.dynamic_noise_ratio + self.spatial_filter_enabled = self._preprocessor.spatial_filter + + # ── 运行状态 ── + self._running = False + self._was_connected = False + self._stream: RawImuStream | None = None + self._threads: list[threading.Thread] = [] + + # ── 连接控制 ────────────────────────────────────── + + def connect_device(self, port: str = ""): + """打开串口并启动消费线程(幂等:重复调用只更新端口)。""" + if port: + self.serial_port = port + if self._running: + return + self._running = True + self._was_connected = False + self._stream = RawImuStream( + serial_port=self.serial_port or None, + status_callback=self._on_status, + ) + self._threads = [ + threading.Thread(target=self._imu_loop, + name="usb-glove-imu", daemon=True), + threading.Thread(target=self._tactile_loop, + name="usb-glove-tactile", daemon=True), + ] + for t in self._threads: + t.start() + + def disconnect(self): + """停止串口与消费线程(线程随 frames() 生成器退出,join 收尾)。""" + self._running = False + stream = self._stream + self._stream = None + if stream is not None: + stream.stop(timeout_s=1.0) + for t in self._threads: + if t is not threading.current_thread() and t.is_alive(): + t.join(timeout=1.5) + self._threads.clear() + + # ── 状态回调(串口线程 → Qt 信号,自动排队)── + + def _on_status(self, status: str): + """RawImuStream status_callback:connected/waiting/error/… 转 Qt 信号。""" + if status == "connected" and not self._was_connected: + self._was_connected = True + port = self._stream.port if self._stream else self.serial_port + self.connected.emit(str(port or "")) + elif status in ("disconnected", "stopped"): + if self._was_connected: + self._was_connected = False + self.disconnected.emit() + elif status.startswith("error"): + detail = self._stream.last_error if self._stream else "" + self.error_occurred.emit(detail or status) + elif status.startswith("waiting") and self._was_connected: + # 已连后读失败回落为 waiting:视为掉线(串口线程会重连) + self._was_connected = False + self.disconnected.emit() + elif status.startswith("waiting"): + # 从未连上:每 0.5s 报一次(面板可见"未找到设备"原因) + detail = self._stream.last_error if self._stream else "" + self.error_occurred.emit(detail or status) + + # ── 消费线程 ────────────────────────────────────── + + def _imu_loop(self): + """IMU 帧消费:最新四元数 + 1s 滑动窗帧率。""" + stream = self._stream + if stream is None: + return + count, window_start = 0, time.monotonic() + try: + for frame in stream.frames(): + if not self._running: + break + with self.imu_lock: + self.imu_array = np.asarray(frame.quaternions_xyzw, + dtype=np.float64) + self.imu_valid = np.asarray(frame.valid_mask, dtype=bool) + self.latest_imu_ts_us = int(frame.device_timestamp_us) + self.imu_present_count = int(np.count_nonzero( + self.imu_valid)) + count += 1 + now = time.monotonic() + if now - window_start >= 1.0: + self.hardware_fps = count / (now - window_start) + self.fps_updated.emit(self.hardware_fps) + count, window_start = 0, now + except StreamClosedError: + pass + except Exception as exc: # 串口级异常已在 transport 内处理,兜底 + if self._running: + self.error_occurred.emit(f"IMU 线程异常: {exc}") + + def _tactile_loop(self): + """触觉帧消费:最新 16×16 原始 ADC + 宿主时间戳 + 帧率。""" + stream = self._stream + if stream is None: + return + tactile = stream.tactile_stream() + count, window_start = 0, time.monotonic() + try: + for frame in tactile.frames(): + if not self._running: + break + host_us = time.time_ns() // 1_000 + with self.data_lock: + self.data_array = np.asarray(frame.samples, + dtype=np.float32).copy() + self.latest_data_ts_us = host_us + count += 1 + now = time.monotonic() + if now - window_start >= 1.0: + self.tactile_fps = count / (now - window_start) + count, window_start = 0, now + except StreamClosedError: + pass + except Exception as exc: + if self._running: + self.error_occurred.emit(f"触觉线程异常: {exc}") + + # ── 数据拉取(UI 线程 30ms 轮询,口径同 ble_engine)── + + def process_frame(self): + """→ (processed 16×16, peak);校准期间返回 (None, 0.0)。""" + with self.data_lock: + raw = self.data_array.copy() + processed, peak = self._preprocessor.process(raw) + if processed is None: + if self._preprocessor.is_calibrating: + done, total = self._preprocessor.calibration_progress + pct = min(100, done * 100 // max(total, 1)) + self.calibration_progress.emit(pct) + else: + if self.is_calibrating: + self.is_calibrating = False + self.calibration_progress.emit(100) + self.drift_baseline_val = self._preprocessor.drift_baseline_val + return processed, peak + + def latest_imu(self): + """→ (quats 64×float32, valid 16×float32, device_ts_us);从未收帧返回 None。 + + device_ts_us 为帧的设备时间戳(微秒),骨架解算的时间轴对齐用。 + """ + with self.imu_lock: + if not np.any(self.imu_valid): + return None + quats = np.asarray(self.imu_array, dtype=np.float32).ravel().copy() + valid = np.asarray(self.imu_valid, dtype=np.float32).ravel().copy() + ts_us = int(getattr(self, "latest_imu_ts_us", 0) or 0) + return quats, valid, ts_us diff --git a/collector/data/device_names.example.json b/collector/data/device_names.example.json new file mode 100644 index 0000000000000000000000000000000000000000..0967ef424bce6791893e9a57bb952f80fd536e93 --- /dev/null +++ b/collector/data/device_names.example.json @@ -0,0 +1 @@ +{} diff --git a/collector/data/device_params.json b/collector/data/device_params.json new file mode 100644 index 0000000000000000000000000000000000000000..2c63c0851048d8f7bff41ecf0f8cee05f52fd120 --- /dev/null +++ b/collector/data/device_params.json @@ -0,0 +1,2 @@ +{ +} diff --git a/collector/data/server_config.example.json b/collector/data/server_config.example.json new file mode 100644 index 0000000000000000000000000000000000000000..0afb390a653a65e3b74dbd2731066dae1c5990b4 --- /dev/null +++ b/collector/data/server_config.example.json @@ -0,0 +1,7 @@ +{ + "server_url": "", + "username": "", + "password": "", + "upload_delete_after": false, + "upload_auto_sync": false +} diff --git a/collector/data/tasks.example.json b/collector/data/tasks.example.json new file mode 100644 index 0000000000000000000000000000000000000000..cb3335edf05f0d90f7c87b96e8adfd8e0d124489 --- /dev/null +++ b/collector/data/tasks.example.json @@ -0,0 +1 @@ +{"tasks": []} diff --git a/collector/docs/config.md b/collector/docs/config.md new file mode 100644 index 0000000000000000000000000000000000000000..319319435d5fea707647aa83c1be831d0f8c7bb4 --- /dev/null +++ b/collector/docs/config.md @@ -0,0 +1,142 @@ +# config/ + +## 定位 + +config/ 是应用全局配置、国际化与版本号所在的配置包。版本号唯一来源是 `config/__init__.py` 中的 `__version__ = "1.0.3"`,`config/settings.py` 以 `from config import __version__ as APP_VERSION` 从此取值,保证全系统版本号单一出处。 + +被几乎所有子系统 import:`core/pipeline.py`、`core/camera.py`、`core/hand_tracking.py`、`core/egodata_writer.py`、`core/render_engine.py`、`ui/main_window.py` 等均 `from config import settings`;`ui/camera_widget.py`、`ui/device_panel.py`、`ui/camera_grid.py`、`ui/glove_widget.py`、`ui/playback_dialog.py`、`ui/upload_dialog.py`、`ui/exposure_dialog.py`、`ui/task_page.py` 等 import `settings` 与 i18n 的 `tr`/`lang_manager`;`core/database.py` 直接 `from config.settings import DB_PATH, DATA_DIR`;`ui/device_panel.py` 直接 import `save_device_name`。 + +## 文件清单 + +| 文件 | 一句话作用 | +| --- | --- | +| `config/__init__.py` | 包入口,只定义版本号 `__version__`(全系统唯一来源) | +| `config/settings.py` | 全部全局配置常量,及 server_config / device_names / device_params 三类 JSON 持久化的读写函数 | +| `config/i18n.py` | 中英文翻译字典、`LanguageManager` 单例与翻译函数 `tr()` | +| `config/s80m_stereo_calibration.json` | S80M 双目标定参数副本(JSON 数据文件,非代码;由 `ui/main_window.py`(`_open_s80m`)拼接路径读取,供双目采集/显示使用) | +| `config/sensors/` | 手套仿生手掌映射配置(`hand_ble_config.json` 右手 / `hand_ble_config_left.json` 左手,各 16 部位;由 `core/render_engine.py` 常量指路,`core/sensor_hand_config.py` 加载) | + +## 各文件详解 + +### config/__init__.py + +**作用**:config 包的入口文件。仅一行真实代码 `__version__ = "1.0.3"`,是版本号的唯一定义点;`settings.py` 的 `APP_VERSION` 及其他模块均从这里取值(文件 docstring 明确说明"版本号集中定义于此")。 + +**类/函数**:无。 + +**关键数据**: + +| 名称 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| `__version__` | str | `"1.0.3"` | 版本号唯一来源 | + +**调用关系**:被 `config/settings.py` import(`APP_VERSION`);间接被所有 `from config import settings` 的模块触发。 + +### config/settings.py + +**作用**:应用程序全局配置中心。集中定义路径、窗口尺寸、相机采集、录制、双目、D435/RealSense、设备检测、上传、任务服务、手部关键点与暗色主题颜色等全部常量;同时提供 `server_config.json`、`device_names.json`、`device_params.json` 三类配置文件的读写函数(均为 merge-write,保留未传入的旧字段)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_camera_slot_name` | `(index: int) -> str` | OpenCV 设备索引 → EgoData 槽位名 | 0→`head_left_rgb`,1→`head_right_rgb`,2+→`head_right_rgb_N` | +| `_camera_slot_name_legacy` | `(index: int) -> str` | 旧 LeRobot v3 会话命名兼容 | 0→`head_rgb`,其余→`head_rgb_N` | +| `realsense_profile` | `(model_name: str) -> dict` | 按型号名(子串匹配)查 `REALSENSE_PROFILES` | 返回该型号配置;未收录回落 D435 默认配置 | +| `_load_server_config` / `_save_server_config` | `() -> dict` / `(data: dict)` | 读 / merge-write `server_config.json` | 异常或不存在返回 `{}`;写盘保留旧字段 | +| `load_server_url` / `save_server_url` | `() -> str` / `(url: str)` | 读 / 存用户服务器地址 | 无保存值或空串时返回出厂默认 `SERVER_URL` | +| `load_credentials` / `save_credentials` | `() -> tuple[str, str]` / `(username, password)` | 读 / 存登录凭据 | 返回 `(username, password)` | +| `load_upload_auto_sync` / `save_upload_auto_sync` | `() -> bool` / `(on: bool)` | 读 / 存"录制完成后自动上传"开关 | 缺省默认 `True`(沿用历史行为) | +| `load_upload_delete_after` / `save_upload_delete_after` | `() -> bool` / `(on: bool)` | 读 / 存"上传成功后自动删除本地文件"开关 | 缺省默认 `False` | +| `load_device_names` / `save_device_name` / `remove_device_name` | `() -> dict` / `(key, name, sensor="")` / `(key)` | 设备命名表读 / merge-write / 删除 | `sensor` 仅 `data_ble` 用,绑定 parquet 列名;`""` 表示不动原值 | +| `device_name` / `device_sensor_role` | `(key: str) -> str` | 读单个设备名 / 读绑定列名 | 兼容 `{"name": …}` 结构与旧版纯字符串;无则空串 | +| `assign_glove_sensor_role` | `(key: str, prefer: str = "") -> str` | 为首次连接的手套分配空闲 parquet 列名并按 MAC 键持久化 | 返回 `left_glove`/`right_glove` 等;优先占 `prefer`,否则按 `SENSOR_NAMES` 顺序取空余名,无空余名兜底最后一个 | +| `load_device_params` / `save_device_exposure` | `() -> dict` / `(key, auto, value)` | 每设备参数表读 / 写曝光 | merge-write 保留其他条目与参数 | +| `device_exposure` | `(key: str) -> dict` | 读单设备曝光 | `{"auto": bool, "value": float}`,无则 `None` | +| `ensure_device_original` | `(key, auto, value) -> bool` | 记录设备"最一开始"的曝光基线(首次才写,之后永不覆盖) | 返回 `True` 表示本次为新写入 | +| `device_original` | `(key: str) -> dict` | 读原始曝光基线 | 结构同 `device_exposure`,无则 `None` | + +**关键数据**(均为模块级常量,代码中真实存在): + +| 分组 | 常量 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | +| 路径 | `BASE_DIR` / `DATA_DIR` / `RECORDINGS_DIR` / `DB_PATH` / `KEYPOINTS_OUTPUT_DIR` | str | 仓库根 / `data` / `data/recordings` / `data/pipeline.db` / 根下 `keypoints_output` | 由 `os.path` 拼接 | +| 应用 | `APP_NAME` | str | `"EGO数据管线"` | 窗口标题等 | +| 应用 | `APP_VERSION` | str | 来自 `config/__init__.py` | 版本号唯一来源在此 | +| 应用 | `WINDOW_WIDTH` / `WINDOW_HEIGHT` | int | 1600 / 900 | 主窗口尺寸 | +| 相机 | `DEFAULT_FPS` / `DEFAULT_RESOLUTION` / `UVC_FOURCC` | int / tuple / str | 30 / `(1280, 960)` / `"MJPG"` | UVC 满分辨率须配合 MJPG 才能 30fps | +| 相机 | `CAMERA_RECONNECT_INTERVAL_MS` / `MAX_CAMERAS` | int | 2000 / 8 | 断线重试间隔 / 最大相机数 | +| 录制 | `RECORDING_FPS` / `RECORDING_DIR` / `DEPTH_ENABLED` | int / str / bool | 30 / `RECORDINGS_DIR` / `False` | `DEPTH_ENABLED` 为遗留开关(旧 S80M 视差录制路径,已被 `S80M_DEPTH_ENABLED` 取代,保持 `False` 勿启用) | +| 设备命名 | `CAMERA_LEFT` / `CAMERA_RIGHT` / `CAMERA_DEPTH` | str | `"head_left_rgb"` / `"head_right_rgb"` / `"head_depth"` | EgoData 命名约定 `<位置>_<模态>` | +| 设备命名 | `CAMERA_PRIMARY_LEGACY` | str | `"head_rgb"` | 旧 LeRobot v3 会话兼容 | +| EgoData 输出 | `EPISODE_PREFIX` / `EPISODE_DIGITS` / `DEPTH_FORMAT` / `DEPTH_SCALE` | str / int / str / float | `"episode"` / 6 / `"png16"` / 0.001 | 深度存 16-bit PNG(像素值 × `DEPTH_SCALE` = 米;v1.0.11 曾试 raw16 裸 bin,体积过大/上传失败后 v1.0.12 回退) | +| 双目标定 | `STEREO_BASELINE` / `STEREO_RESOLUTION` / `STEREO_FPS` | float / tuple / int | 0.095 / `(1280, 800)` / 30 | 基线(米)等 | +| 双目 | `STEREO_CAM_FPS` / `STEREO_RECORD_FPS` / `STEREO_RECORD_MIN_INTERVAL_S` | int / int / float | 50 / 30 / 1.0/30 | S80M 相机档 50fps(50→30 桶抽帧才有真 30fps;回调取帧=官方 GUI 同款组合,8/31 撕裂已根治;25 档保留为回退)、录制按 1/30s 桶抽帧 | +| 双目 | `STEREO_CB_BRIDGE` | bool | True | 取帧用官方 GUI 同款回调(SDK 装配完成才交付、帧必完整;shim 缺失/注册失败自动回退轮询) | +| S80C 深度 | `S80M_DEPTH_ENABLED` | bool | `True` | S80C 深度开关(关闭→子进程不加 `--depth-sdk-dir`,管道协议字节不变、零 CPU 开销) | +| S80C 深度 | `S80M_DEPTH_SLOT` | str | `"stereo_depth"` | 深度槽位(录制为 `depth/stereo_depth/…`) | +| S80C 深度 | `S80M_DEPTH_NEAR_MM` / `S80M_DEPTH_FAR_MM` / `S80M_DEPTH_SMOOTH_K` | int / int / int | 300 / 3000 / 3 | 热力图固定色标下限 / 上限(毫米)/ 中值滤波核 | +| D435 | `D435_SLOT_RGB` / `D435_SLOT_DEPTH` | str | `"d435_rgb"` / `"d435_depth"` | 录制槽位名 | +| D435 | `D435_RESOLUTION` / `D435_RGB_RESOLUTION` / `D435_FPS` | tuple / tuple / int | `(848, 480)` / `(1280, 720)` / 30 | 深度 / RGB 流配置 | +| D435 | `D435_DEPTH_NEAR_MM` / `D435_DEPTH_FAR_MM` | int | 300 / 4000 | 实时显示深度范围过滤(毫米) | +| D435 | `D435_PNG_COMPRESSION` / `D435_STALL_TIMEOUT_S` | int | 1 / 5 | [DEPRECATED v1.0.11] 深度已改存原始 uint16 二进制,压缩级不再生效 / 流停滞看门狗阈值(秒) | +| D435 | `D435_LOW_FPS_WINDOW_S` / `D435_LOW_FPS_FRACTION` | int / float | 10 / 0.5 | 帧率看门狗窗口与下限比例 | +| RealSense | `REALSENSE_PROFILES` | dict | 见下 | 按型号给采集配置 | +| RealSense | `REALSENSE_PROFILES["D405"]` | dict | `depth_resolution`/`rgb_resolution` `(1280,720)`、`fps` 30、`depth_near_mm` 100、`depth_far_mm` 1000、`heatmap_smooth_k` 3、`heatmap_temporal_alpha` 0.5 | D405 短距近景配置 | +| 设备检测 | `DEVICE_SCAN_MAX_INDEX` / `DEVICE_POLL_INTERVAL_MS` | int | 16 / 2000 | V4L2 枚举上限 / 轮询间隔(毫秒) | +| 设备检测 | `REALSENSE_VID` / `REALSENSE_PID` | str | `"8086"` / `"0b07"` | Intel vendor ID / D435 product ID(其他型号靠驱动 name 兜底) | +| 传感器 | `SENSOR_NAMES` | list | `["right_glove", "left_glove"]` | 写入 parquet observation 列名 | +| 手部 | `HAND_POSE_LEFT` / `HAND_POSE_RIGHT` / `HAND_POSE_DIM` / `SENSOR_DIM` | str / str / int / int | `"left_hand_pose"` / `"right_hand_pose"` / 63(21×3)/ 256 | 手部 63 维、触觉 16×16 展平 | +| 显示 | `CAMERA_MIRROR_HORIZONTAL` / `DISPLAY_FPS_LIMIT` / `FEED_MIN_WIDTH` / `FEED_MIN_HEIGHT` | bool / int / int / int | `True` / 30 / 320 / 240 | 镜像翻转(显示+录制)、GUI 帧率上限、最小画面 | +| 颜色 | `COLOR_RECORDING` / `COLOR_STOPPED` / `COLOR_ABNORMAL` | str | `"#EF5350"` / `"#66BB6A"` / `"#FFA726"` | 红=录制中 / 绿=空闲 / 橙=异常 | +| 颜色 | `COLOR_BG_MAIN` / `COLOR_BG_PANEL` / `COLOR_BG_WIDGET` / `COLOR_BG_CANVAS` | str | `"#1E1E1E"` / `"#252525"` / `"#2D2D2D"` / `"#1A1A1A"` | 暗色主题背景四层 | +| 颜色 | `COLOR_TEXT_PRIMARY` / `COLOR_TEXT_SECONDARY` / `COLOR_TEXT_HINT` | str | `"#E0E0E0"` / `"#9E9E9E"` / `"#616161"` | 文字三档 | +| 颜色 | `COLOR_BORDER` / `COLOR_BORDER_STRONG` | str | `"#424242"` / `"#616161"` | 边框与分割线 | +| 颜色 | `COLOR_BTN_START` / `COLOR_BTN_STOP` / `COLOR_BTN_ABORT` | str | `"#43A047"` / `"#E53935"` / `"#FF8F00"` | 开始 / 停止 / 异常停止按钮 | +| 颜色 | `COLOR_BTN_DEFAULT_BG` / `COLOR_BTN_HOVER` / `COLOR_BTN_DISABLED_BG` / `COLOR_BTN_DISABLED_TEXT` | str | `"#424242"` / `"#555555"` / `"#333333"` / `"#616161"` | 按钮常规四态 | +| 上传 | `SERVER_URL` | str | `"http://127.0.0.1:8000"` | 出厂默认占位地址;实际地址由用户在页面填写并持久化到 `server_config.json` | +| 上传 | `SERVER_CONFIG_FILE` / `DEVICE_NAMES_FILE` / `DEVICE_PARAMS_FILE` | str | `data/server_config.json` / `data/device_names.json` / `data/device_params.json` | 三个持久化文件路径 | +| 上传 | `UPLOAD_ENABLED` / `UPLOAD_MAX_CONCURRENT` / `UPLOAD_RETRY_MAX` | bool / int / int | `True` / 1 / 3 | 串行=1(并发时预压缩临时文件会互相覆盖致视频损坏) | +| 上传 | `UPLOAD_AUTO_SYNC` / `UPLOAD_DELETE_AFTER` | bool | 启动时从 `server_config.json` 读取(默认 `True` / `False`) | 录制后自动上传 / 上传后删本地 | +| 上传 | `UPLOAD_PRECOMPRESS_VIDEO` / `UPLOAD_VIDEO_CRF` | bool / int | `True` / 30 | 上传前视频重编码低码率 / CRF 档(v1.0.9 起 HEVC 录制件自动跳过) | +| 录制编码 | `RECORD_VIDEO_ENCODER` | str | `"auto"` | 录制编码器:`"auto"` 自动探测(nvenc→x265→x264)/ `"nvenc"` / `"x265"` / `"x264"` 显式指定 | +| 录制编码 | `RECORD_VIDEO_CRF` / `RECORD_VIDEO_X264_CRF` | int / int | 30 / 23 | HEVC 直出 CRF 档 / x264 回退 CRF 档(与 v1.0.8 现状一致) | +| 录制编码 | `ENCODER_PROBE_ENABLED` / `ENCODER_PROBE_FRAME_COUNT` / `ENCODER_PROBE_MAX_STREAMS` / `ENCODER_PROBE_TIMEOUT_S` | bool / int / int / int | `True` / 45 / 4 / 15 | 录前编码器速度探针开关 / 每探针合成帧数 / 并行流上限 / 单进程超时秒 | +| 录制编码 | `ENCODER_X265_MIN_FPS_RATIO` | float | 1.5 | x265 达标门槛 = 录制帧率 × 该比值(不达标回退 x264) | +| 录制编码 | `IMU_PENDING_MAX_SAMPLES` | int | 18000 | 双目 IMU 防丢缓冲上限(约 1 分钟 @300Hz;队列满时丢帧保 IMU) | +| 录制编码 | `DROP_WARN_RATIO` / `DROP_WARN_MIN_COUNT` | float / int | 0.01 / 30 | 录制结束丢帧告警阈值(占比 1% 或 30 帧) | +| 任务服务 | `TASK_POLL_INTERVAL_MS` / `TASK_API_URL` / `DEVICE_NAME` | int / str / str | 30000 / `SERVER_URL` / `"EGO_001"` | 轮询间隔 / API 地址 / 设备认领名 | +| 手部追踪 | `HAND_TRACK_ENABLED` / `HAND_TRACK_MODE` | bool / str | `False` / `"glove"` | 需 ultralytics;`"glove"` 黑色手套 / `"bare"` 裸手 | +| 手部追踪 | `HAND_DETECTION_DIR` / `HAND_DET_MODEL` / `HAND_MEDIAPIPE_MODEL` | str | 根下 `tools/hand_detection` / 其内 `best.pt` / `hand_landmarker.task` | YOLO 手套模型 / MediaPipe 裸手模型 | +| 手部追踪 | `HAND_DET_DEVICE` / `HAND_POSE_DEVICE` / `HAND_TRACK_MAX_HANDS` / `HAND_DATA_DIM` | str / str / int / int | `"cuda"` / `"cuda"` / 2 / 21×2×2+4×2+1(=93) | 设备、最多手数、展平维度 | + +**JSON 字段约定**(由本模块的读写函数定义): + +- `data/server_config.json`:`server_url`(str)、`username`(str)、`password`(str)、`upload_auto_sync`(bool,缺省 `True`)、`upload_delete_after`(bool,缺省 `False`)。 +- `data/device_names.json`:key = `DeviceInfo.stable_key`(形如 `"uvc:{by-id前缀}"` / `"d435:{serial}"` / `"ble:{MAC}"` 等),value = `{"name": str, "sensor"?: str}`(`sensor` 仅 `data_ble` 设备用,绑定 parquet 列名 `right_glove`/`left_glove`,按 MAC 持久化);旧版纯字符串自动升级为 `{"name": …}`。 +- `data/device_params.json`:key 同 `stable_key`,value = `{"exposure": {"auto": bool, "value": float}, "original": {同结构}}`;`auto=True` 时 `value` 忽略;`original` 首次看到才写入、之后永不覆盖,供"恢复默认"回到开机原厂曝光。 + +**调用关系**:被 `core/`(`pipeline.py`、`camera.py`、`hand_tracking.py`、`stereo_depth.py`、`device_detector.py`、`d435_camera.py`、`egodata_writer.py`、`task_record.py`、`render_engine.py`、`helpers.py`(`as _settings`)等)、`ui/`(`main_window.py`、`camera_widget.py`、`device_panel.py`、`playback_dialog.py`、`upload_dialog.py`、`task_page.py`)以及 `tools/tests/` 多个用例 import。自身仅依赖 `os` 与 `config.__version__`。 + +### config/i18n.py + +**作用**:国际化模块,支持中英文界面切换。维护一张以中文原文为键的翻译字典 `_TRANSLATIONS`,通过模块级单例 `lang_manager` 记录当前语言,切换时发射 Qt 信号通知所有监听者刷新界面文字;`tr()` 负责查表翻译。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `LanguageManager` | `(QObject)` | 管理当前语言,切换时发信号 | 信号 `language_changed(str)`,参数 `"zh"` 或 `"en"` | +| `LanguageManager.current` | property | 当前语言 | 默认 `"en"` | +| `LanguageManager.set_language` | `(lang: str)` | 切换语言并通知监听者 | 非法值或相同语言时不动作 | +| `LanguageManager.toggle` | `()` | 中英文之间切换 | — | +| `lang_manager` | 全局单例 | 全应用共享的语言管理器 | 默认英文 | +| `tr` | `(text: str, *fmt_args) -> str` | 翻译函数 | 未收录条目原样返回;有 `fmt_args` 时 `str.format` 填充 | + +**关键数据**: + +| 名称 | 类型 | 说明 | +| --- | --- | --- | +| `_TRANSLATIONS` | dict | 键为中文原文,值为 `{"en": …, "zh": …}`;覆盖录制记录、菜单栏、工具栏、相机控件、状态栏、日志消息、双目 S80M、相机模式切换、RealSense、错误消息、对话框、面板标题、关于、空状态、传感器面板、设备检测、设备统一接入、每设备曝光、状态显示、回放、上传、上传开关、数据查看器、任务选择页面、手部关键点、自动标注等全部界面文案 | + +**调用关系**:被 `ui/main_window.py`、`ui/camera_widget.py`、`ui/device_panel.py`、`ui/camera_grid.py`、`ui/glove_widget.py`、`ui/playback_dialog.py`、`ui/upload_dialog.py`、`ui/exposure_dialog.py`、`ui/task_page.py`、`tools/tests/device_panel_gui_smoke_test.py`、`tools/tests/glove_widget_test.py`、`tools/tests/exposure_control_test.py`、`tools/tests/test_playback_multifps.py` 等 import。依赖 `PyQt5.QtCore`(`QObject`、`pyqtSignal`)。 diff --git a/collector/docs/core.md b/collector/docs/core.md new file mode 100644 index 0000000000000000000000000000000000000000..a5258a618a1ed52f0e6ed58c101999ed2d95b11f --- /dev/null +++ b/collector/docs/core.md @@ -0,0 +1,962 @@ +# core/ — SDK 核心 + +## 定位 + +`core/` 是 collector 的 SDK 核心:相机采集、设备管理器、录制落盘、SQLite +持久化、上传/后端通信、回放会话、手部关键点、BLE 手套传感与通用工具全部 +平铺于此(v1.0.3 架构重组后由原 `core/` + `storage/` + `network/` + `utils/` ++ `tools/sensors/` 合并而成)。 + +**分层规则**(SDK 化后确立): + +- core 只依赖 PyQt5.**QtCore**(QObject/pyqtSignal/QTimer)与 `config/`, + **禁止 import ui**;唯一例外 `core/sensor_config_dialogs.py`(传感器 + 配置对话框继承 `QDialog`,需 `PyQt5.QtWidgets`); +- 算法口径全部在 core(纯函数优先),ui 槽只做 widget 操作; +- 跨线程一律语义信号(帧/日志/关闭完成),主线程创建 QObject; +- 可能超过 32 位的信号参数(纳秒时间戳)用 `object` 封装 + (PyQt5 int 参数按 qint32 封送,>2^31 静默翻负)。 + +## 文件清单 + +| 文件 | 一句话作用 | +|---|---| +| `core/camera.py` | UVC 相机采集:V4L2 sysfs 枚举 + `CameraWorker` 后台线程采集(重连/曝光/FOURCC) | +| `core/d435_camera.py` | RealSense D400 系列采集:`D435Worker` 进程内 rs2.pipeline 双路输出 + 运行时标定提取 | +| `core/device_detector.py` | 统一设备枚举(UVC + D435 + S80M + BLE),`DeviceScanner` 后台扫描 | +| `core/pipeline.py` | `CameraPipeline`:多路相机 + 共享 EgoData 录制会话,独立写入线程 | +| `core/s80m_manager.py` | S80M 双目子进程生命周期:Popen/stdin 曝光通道/watchdog/帧管道读取 + 50→30 抽帧口径 | +| `core/d435_manager.py` | D435 worker 生命周期 + 帧处理口径(calib 首帧注入/热力图 EMA/录制写入) | +| `core/device_manager.py` | 统一设备 worker 注册表 + 面板开关分派口径 + 录制设备元数据 | +| `core/device_naming.py` | 槽名清洗/分配(`allocate_slot_names`)+ 曝光基线归一化(纯函数,零 Qt) | +| `core/exposure_controller.py` | 每设备曝光:对话框参数解析 + 下发/持久化口径(零 Qt) | +| `core/egodata_writer.py` | EgoData / LeRobot v3 格式录制器:MP4/深度/Parquet/元数据多模态落盘 | +| `core/calibration.py` | 标定数据模型:双目内外参 + 深度缩放的 dataclass 与 JSON 序列化 | +| `core/database.py` | 线程安全 SQLite 单例(`recording` 与 `upload_task` 两表 + 建表 SQL) | +| `core/recording_record.py` | `RecordingRecord` dataclass:录制历史一行记录的字段定义(原 storage/models) | +| `core/recording_repository.py` | `RecordingRepo`:录制记录 CRUD 仓库(原 storage/repository) | +| `core/task_record.py` | 任务进度持久化(`data/tasks.json` 唯一权威源,缺文件自动播种) | +| `core/api_client.py` | 后端 HTTP REST 客户端(健康检查、上传、查询、删除) | +| `core/task_service.py` | 后台任务轮询服务(QTimer + 后台线程,Cookie JWT 登录) | +| `core/uploader.py` | 上传队列管理器(视频预压缩 → 打包 zip → 上传 → SQLite 状态持久化) | +| `core/session_timeline.py` | 会话传感器时间线:向量化合并 per-sensor parquet + 帧号二分查询 | +| `core/session_catalog.py` | 会话扫描/元数据/帧率解析/录制列表(纯函数,零 Qt) | +| `core/session_loader.py` | 回放后台加载器(parquet 合并 + 关键点,gen 防过期协议) | +| `core/stereo_depth.py` | 手写 StereoSGBM + WLS 视差计算,深度热力图与 EMA 平滑 | +| `core/hand_tracking.py` | 手部关键点后处理纯函数 API(glove/bare 双模式、自动标注、parquet 读写) | +| `core/hand_processor.py` | `SessionHandProcessor`:`hand_tracking.process_session` 的 Qt 薄封装 | +| `core/auto_labeler.py` | `AutoLabeler`:`hand_tracking.label_session` 的 Qt 薄封装 | +| `core/ble_engine.py` | BLE 传感器引擎:扫描/连接/通知订阅/帧解析/降噪,QObject + Qt 信号 | +| `core/render_engine.py` | 五种触觉渲染模式 + 仿生手掌配置路径常量(config/sensors/) | +| `core/sensor_config_dialogs.py` | PyQt5 传感器配置对话框(矩阵行列 / 仿生手掌逐部位) | +| `core/sensor_hand_config.py` | 仿生手掌配置加载/传感器列有效性过滤(纯函数,零 Qt) | +| `core/helpers.py` | 通用工具函数(约 47 个:ID/时间/格式化/路径/会话扫描) | + +(`core/__init__.py` 为空包标记。) + +## 采集与设备 + +### core/camera.py + +**作用**:UVC 摄像机采集模块。模块级函数负责只读 sysfs 枚举与打开 +(`list_v4l_devices` 不 open 设备、轮询安全;`_try_open_camera` 支持 +`/dev/v4l/by-id` 永久路径与重连兜底;跳过 FTDI SDK 设备与 RealSense UVC +节点)。`CameraWorker` 在后台线程采集帧、经 Qt 信号发主线程,含指数退避 +重连、UVC 固定自动曝光(首帧读出成功后强制应用)、MJPG FOURCC 设置与 +读回校验、录制帧队列直推。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `CameraState` | 类常量 | 状态枚举 | `DISCONNECTED/IDLE/RECORDING/ERROR` | +| `list_v4l_devices` | `(max_index=16)` | sysfs 只读枚举 V4L2 设备,by-id 分组、每物理设备只留主视频流 | 每项 `{video_index, name, serial, by_id_path, vid, pid, is_sdk, is_realsense}` | +| `detect_cameras` | `(max_index=8)` | 打开测试(test_read)枚举可用相机 | `[(idx, backend), ...]` | +| `_try_open_camera`(内部) | `(index, test_read=False, fallback_all_by_id=False)` | 按后端列表(Linux: V4L2/FFMPEG/ANY;Windows: DShow/MSMF/ANY)尝试打开 | `(VideoCapture, backend名)` 或 `(None, "")` | +| `_is_sdk_device` / `_is_realsense_node`(内部) | `(index)` | sysfs name/VID:PID 判 FTDI SDK 设备与 RealSense 节点 | `bool` | +| `_usb_vid_pid`(内部) | `(video_index)` | 沿 sysfs 设备树向上(≤6 层)找 `idVendor`/`idProduct` | `(vid, pid)` 小写十六进制或 `None` | +| `CameraWorker` | `(camera_index=0, resolution=None, record_queue=None)` | UVC 采集 worker;默认分辨率 `settings.DEFAULT_RESOLUTION`(1280×960@30,MJPG) | 信号:`frame_ready(ndarray)`、`state_changed(str)`、`error_occurred(str)`、`fps_updated(float)`、`camera_opened(int,int,str)` | +| `CameraWorker.start` / `stop` / `pause` / `resume` | 无参 | 生命周期控制(stop join ≤5s) | 无 | +| `CameraWorker.state` / `is_connected` / `resolution` / `latest_capture_ts_us` | property | 状态、连接、实际分辨率、最新帧采集时间戳(Unix 微秒,线程安全) | 对应值 | +| `CameraWorker._apply_exposure_to`(内部,static) | `(cap, auto, value, backend="")` | V4L2 按候选菜单顺序(自动 0→3→2;手动 1→0)写自动曝光,以 set 返回 True 且 get 读回一致为准 | `(auto成功, 值成功)` | +| `_FPSCounter` | `(window=30)` | 滑动窗口帧率计数 | `tick()` 更新 `.fps` | + +**关键数据**:重连参数 `_RECONNECT_BASE_DELAY=2.0s`、`_RECONNECT_MAX_DELAY=30.0s`、`_READ_FAIL_THRESHOLD=120`、`_INITIAL_FAIL_THRESHOLD=30`、`_INITIAL_GRACE_PERIOD=90`(迭代数);曝光为"开启/重连后首帧读出成功后强制回自动"策略(注释:UVC 手动模式实测帧率上限 ~26fps);录制帧队列 `queue.Queue(maxsize=3)`,满则丢旧帧保持最新。 + +**调用关系**:被 `core/pipeline.py`(`CameraWorker`/`CameraState`)、`core/device_detector.py`(`list_v4l_devices`/`_is_sdk_device`)、`ui/main_window.py`(`_add_camera_slot`)、`tools/tests/exposure_control_test.py`、`tools/tests/test_device_detector.py`、`tools/tests/mono_regression.py` 引用。 + +### core/d435_camera.py + +**作用**:Intel RealSense D400 系列(D435/D435I/D405 等)深度双目采集。D400 +是稳定 UVC 用户态设备(pyrealsense2 自带 librealsense2 + libusb),无需像 +S80M 那样隔离到子进程;`D435Worker` 后台线程跑 `rs2.pipeline`,对外输出 +RGB(BGR 三通道)+ 深度(uint16,归一化毫米)两路信号。左红外流仅内部 +启用(时间戳元数据),不对外输出;右红外不开流(基线改从 depth sensor 的 +`stereo_baseline` 选项直读,双 RealSense 同 hub 时多一条 IR2 会把 D405 挤到 +~19fps)。带停滞/低帧率双看门狗,重连每次新建管道。`frames_ready` 信号的 +`hardware_ns` 用 `object` 参数(PyQt5 队列信号把 int 按 qint32 封送,>2^31 +纳秒会静默翻负)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `d435_available` | `(force=False)` | pyrealsense2 可用且存在 D400;结果模块级缓存,`force=True` 绕过(热插拔后活体复查) | `bool` | +| `list_d400_devices` | 无参 | 枚举 D400 设备(product_line 含 "D400") | `[(name, serial), ...]`,无则 `[]` | +| `_apply_color_exposure`(模块级) | `(sensor, auto, value)` | 对 color 传感器应用曝光(µs) | `bool`,异常返回 False | +| `D435Worker` | `(width, height, fps, parent, ts_log, rgb_width, rgb_height, serial, model_name, rgb_slot, depth_slot, exposure)` | 采集 worker;分辨率默认 `settings.D435_RESOLUTION`/`D435_RGB_RESOLUTION`,`serial` 锁定设备(None→第一台 D400),槽名默认 `settings.D435_SLOT_RGB`/`D435_SLOT_DEPTH` | 信号:`frames_ready(str, np.ndarray, object, list)`(slot_id, frame, hw_ns, imu_samples;D435/D405 无 IMU,恒 `[]`)、`error_occurred(str)`、`status_changed(str)` | +| `D435Worker.start` / `stop` | 无参 | 启动/停止后台线程(stop 阻塞 ≤3s) | 无 | +| `D435Worker.get_calibration` | 无参 | 首帧后提取的标定 | `StereoCalibration` 或 `None` | +| `D435Worker.set_exposure` | `(auto, value)` | 主线程只写 pending;采集线程在流启动后应用,重连重放最近设置 | 无 | +| `D435Worker.exposure_info` | 无参 | 返回量程/auto/value | `((min,max)µs 或 None, auto, value)` | +| `D435Worker.original_exposure` | 无参 | 开流时读回的"最一开始"曝光基线 | `(auto, value)` 或 `None` | +| `_build_calibration`(模块级) | `(profile, fps, resolution)` | 从 rs2 profile 提取左右红外内参/深度内参/基线 | `StereoCalibration`(right IR2 未开流时内参镜像左目) | + +**关键数据**:输出深度统一归一化到毫米(`_depth_unit_factor = 设备深度单位 / settings.DEPTH_SCALE`,D405 原生 0.1mm/单位);帧时间戳用左红外帧 `frame_timestamp` 元数据(32 位 µs 计数,软件解绕 + 首帧归零 → 会话内单调 `hardware_ns`,与 S80M 语义一致);流组合 color(rgb8) + depth(z16) + infrared#1(y8,仅内部);标定 `cam_imu_timeshift=0.0`(D435 无 IMU)。`__main__` 为无头自检(运行 5s、抽帧存 `/tmp/d435_selftest`、打印标定)。 + +**调用关系**:被 `ui/main_window.py`(`_open_d435`,worker 类经 `D435DeviceManager.spawn` 传入)、`tools/tests/d405_worker_test.py`、`tools/tests/d435_e2e_test.py`、`tools/tests/d435_gui_smoke_test.py`、`tools/tests/exposure_control_test.py` 引用;函数内延迟导入 `core/calibration.py`。 + +### core/device_detector.py + +**作用**:统一枚举已连接设备(UVC + RealSense D400 + S80M + 蓝牙)。列表轮询 +走 sysfs 只读扫描(不 open、不 test_read),轮询 <5ms、录制中安全;open 测试 +只发生在开关打开后(各 worker 自带重连)。蓝牙两个来源:`bluetoothctl` +已配对列表(快、只读)+ bleak 主动发现(慢 ~5s,节流缓存 20s;手套连接中 +可 `set_ble_scan_suppressed(True)` 抑制)。`DeviceScanner` 在后台线程扫描, +经排队信号回主线程。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `DeviceInfo` | dataclass | 单条设备描述 | 字段:`key/kind/display_name/serial/video_index/by_id_path/backend/address/rssi/user_name`;property `stable_key`、`group`(`camera|glove|other_ble`)、`label`(用户命名优先) | +| `detect_devices` | `(max_index=settings.DEVICE_SCAN_MAX_INDEX)` | 四段枚举(UVC+D435+S80M+BLE),各自容错整体不崩 | `List[DeviceInfo]` | +| `DeviceScanner` | `(parent=None, max_index=None)` | 后台线程扫描,`_busy` 守卫防轮询堆积 | 信号 `scan_finished(list)`;`request_scan()`/`stop()` | +| `set_ble_scan_suppressed` | `(on: bool)` | 抑制 bleak 主动发现(手套连接中防扫描挤占吞吐),不影响 bluetoothctl 列表 | 无 | +| `_list_uvc_devices` / `_list_d435_devices` / `_list_s80m_devices` / `_list_ble_devices`(内部) | 各自 max_index | 分段枚举 | `List[DeviceInfo]` | +| `_is_glove_name`(内部) | `(name)` | 广播名判手套:含 "matrix" 或单字母 `l/r/left/right/l_glove/r_glove/left_glove/right_glove` | `bool` | + +**关键数据**:`DeviceInfo.key` 格式约定:`"uvc:{by-id前缀或索引}"`、`"d435:{serial}"`、`"s80m:ftdi"`、`"ble:{MAC}"`;`kind` 取值 `uvc | d435 | s80m | data_ble | ble`(`data_ble`=手套)。BLE 常量 `BLE_DISCOVERY_INTERVAL_S=20.0`、`BLE_DISCOVERY_TIMEOUT_S=5.0`。S80M:FTDI 命中一次即返回单条(SDK 配置写死 video0/video2)。RealSense UVC 节点判定:vendor 8086 且 PID 0b07(D435)或驱动 name 含 "RealSense"(D435i 为 0b3a、其余型号 PID 各异,name 兜底)。 + +**调用关系**:被 `ui/main_window.py`(`DeviceScanner`)、`ui/device_panel.py`、`tools/tests/device_panel_gui_smoke_test.py`(`DeviceInfo`/`detect_devices`)、`tools/tests/glove_widget_test.py`、`tools/tests/multi_device_registry_test.py` 引用;调用了 `core/camera.py`。 + +### core/pipeline.py + +**作用**:摄像机管线——管理多路相机槽位与一个共享 EgoData 录制会话。 +`CameraSlot` 封装单路 `CameraWorker` + 帧缓冲队列(maxsize=3,采集线程直写, +绕过 Qt 信号/主线程)。`CameraPipeline` 录制时创建 `EgoDataWriter`,独立写入 +线程以 `settings.RECORDING_FPS`(30fps)精确节拍把各槽位帧、传感器数据、 +外部帧源(双目子进程等)、深度帧统一写入同一会话(MP4 + Parquet)。深度 +"伪相机"经 `set_depth_camera` 显式注册(D435 原生深度与 S80C 子进程深度 +引擎多路并存,S80C 用槽 `settings.S80M_DEPTH_SLOT`;无注册槽时随 +`stereo_left` 兜底落盘)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `CameraSlot` | `(slot_id, camera_index)` | 单相机槽位 | 信号 `frame_ready(str, object)`、`state_changed(str, str)`、`error_occurred(str, str)`;`start_camera()`/`stop_camera()`/`camera_state` | +| `CameraPipeline` | `(output_dir=None)`(默认 `settings.RECORDING_DIR`) | 多路管线 | 信号:`slot_added`、`slot_removed`、`session_changed(object)`、`recording_started(str)`、`recording_finished(str, str)`、`recording_aborted(str)`、`duration_changed(str, float)`、`error_occurred(str, str)`、`state_changed(str, str)` | +| `CameraPipeline.add_camera` / `remove_camera` / `get_slot` / `slot_ids` / `slot_count` / `remove_all` | `(slot_id, camera_index)` | 槽位管理(录制中移除会先 `abort_recording`) | 对应值/无 | +| `CameraPipeline.register_external_source` / `unregister_external_source` | `(slot_id, resolution, fps=25.0)` | 外部帧源注册(队列 maxsize=2,不建 CameraWorker) | 无 | +| `CameraPipeline.write_external_frame` | `(slot_id, frame, hardware_ns=0, imu_samples=None)` | 外部帧入录制队列(非阻塞,满则丢) | 无 | +| `CameraPipeline.write_depth` | `(depth_frame, depth_slot="stereo_left")` | 深度帧入录制队列(uint16 毫米:S80C SDK 深度引擎 / D435 原生,同口径);单深度相机时自动回落 | 无 | +| `CameraPipeline.set_depth_camera` / `clear_depth_camera` | `(name, resolution, fps, master_slot, heatmap_near_mm, heatmap_far_mm, heatmap_smooth_k, heatmap_temporal_alpha, raw_depth)` | 声明/清除深度伪相机(多路并存,只进 metadata 不建 MP4;`raw_depth=True` 时原始 uint16 bin 随热力图 MP4 落盘) | 无 | +| `CameraPipeline.set_external_calibration` / `set_device_calibration` / `clear_device_calibration` | `(calib)` / `(device_key, calib)` / `(device_key)` | 注册外部帧源标定(单值路径存 `"_default"` 键 → `calibration/head_stereo.json`) | 无 | +| `CameraPipeline.register_sensors` / `register_sensor` / `unregister_sensor` | `(sensor_names)` / `(sensor_name)` / `(sensor_name)` | 传感器名称注册(决定 parquet `observation.` 列),须在 `start_recording` 前调用 | 无 | +| `CameraPipeline.start_recording` | `(slot_id, task_name="", batch_index=0, device_meta=None)` | 全部相机开始录制同一会话(后台线程初始化) | 信号 `recording_started` | +| `CameraPipeline.finish_recording` / `abort_recording` | `(slot_id)` | 正常停止(`end_episode` 最终化)/ 异常停止(`abort_episode` 删目录) | 信号 `recording_finished`/`recording_aborted` | +| `CameraPipeline.write_sensor` | `(data, capture_ts_us=0, sensor_name="")` | 传感器数据入队列(16×16 float32 压力矩阵 ravel) | 无 | +| `CameraPipeline.record_event` | `(device, event_type, message="")` | 记录设备连接/断开事件 → 写入线程每帧写 `status.` 列 | 无 | +| `CameraPipeline.is_recording` / `elapsed` / `last_recording_frames` | property | 录制状态/已录时长/上一轮每相机帧数快照 | 对应值 | + +**关键数据**:写入线程节拍 `frame_interval = 1.0 / settings.RECORDING_FPS`(30fps),sleep 到目标前 ~1ms 后 busy-wait 补齐;每帧先排空传感器队列取最新数据,CameraSlot 队列"排空取最新帧"、外部帧源队列"取一帧不排空"(输出均匀无抖动);单目路径写 MP4 时上下翻转、外部双目帧路径已在 `ui/main_window._on_stereo_frame` 翻转故 `flip_vertical=False`;IMU 样本只随 `stereo_left` 写入(左右目共享一份,避免 `data/imu/` 重复行);可选 `settings.CAMERA_MIRROR_HORIZONTAL` 水平镜像。**深度 MP4 补拍**(v1.0.11):`_write_one_frame` 每个 master 槽节拍至多消费一帧深度——队列有新帧则写热力图 MP4 +(raw_depth 时)PNG16 并缓存于 `_last_depth_frames`;队列空(S80C 深度引擎 ~20fps 低于录制 30fps)则重写缓存帧到热力图 MP4(不落 PNG、不推进序号),保证深度 MP4 时长与 RGB 对齐。 + +**调用关系**:被 `ui/main_window.py`(主程序)、`tools/tests/d435_e2e_test.py`、`tools/tests/device_panel_gui_smoke_test.py`、`tools/tests/exposure_control_test.py` 引用;调用了 `core/camera.py` 与 `core/egodata_writer.py`。 + +## 设备管理器与口径(v1.0.3 从 ui 抽出) + +### core/s80m_manager.py + +**作用**:S80M 双目子进程生命周期管理(每台一个条目)。自包含双目模块 +`tools/stereo_s80m/` 内含 `read_stereo_rgb.py` + +`lib/fays_atrak/x86_64/Release/libfays_vikit.so`(SDK 动态库,注释标 3.9.0)+ +`config/fays_vikit.yaml`,与外部 SDK 目录完全独立——外部目录 git 更新、跑官方 +demo 均不影响 DAQ 程序。Popen 子进程 stdout 管道传帧(`--pipe -`,避免 FIFO +权限问题),stdin 管道是曝光控制通道(行协议 `"SET_EXPOSURE "`, +-1.0=自动),watchdog 定时检查进程存活并回读 stderr 末尾,reader 线程按 +`[4B len][8B ts_ns][jpg]` 帧格式解析左右目 JPEG 与 IMU 样本块(56B/样本)。 + +**管道协议扩展(v1.0.11)**:`s80m_depth_available()`(`settings.S80M_DEPTH_ENABLED` 且 `tools/hand_3d_s80c/third_party` 深度库/模型/OpenCV4.2 齐全)时 spawn 给子进程追加 `--depth-sdk-dir`,每帧 IMU 块之后、flush 之前必写深度块(引擎失败期恒写 0 长度,保证解析确定性): +``` +[>I depth_len] ← 0 = 本帧无新深度 +if depth_len>0: [>Q depth_ts][>I w][>I h][w*h*2 字节 uint16 毫米 LE] +``` +reader 校验 `depth_len == w*h*2` 且尺寸合法后 `depth_ready.emit(slot, uint16, ts)`;子进程内移植自 `tools/hand_3d_s80c/s80c_depth_worker.py` 的 SDK 深度引擎(~20fps @ 相机 50fps,~220MB 缓冲)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `SDK_ROOT` / `STEREO_DEMO` / `STEREO_AVAILABLE` / `STEREO_CFG_50` | 模块常量 | 锚定 `tools/stereo_s80m/` 路径(不随 cwd 漂移) | — | +| `load_default_exposure` | 无参(模块级) | 「恢复默认」基线:yaml `stereo_init_exposure`(<0=自动) | `(auto, value)`,兜底 `(False, 400.0)` | +| `frame_record_decision` | `(entry, slot_id, hardware_ns, imu_samples)`(模块级) | 50→30 抽帧纯口径:每 1/30s 桶保留首帧;被抽帧的 IMU 块累积到下一帧;hw_ns==0 兜底全录 | `(record, imu_batch)` | +| `S80MDeviceManager` | `(pipeline, parent=None)` | 子进程生命周期管理 | 信号:`frame_ready(str, np.ndarray, object, list)`、`depth_ready(str, np.ndarray, object)`、`device_closed(str)`、`log(str)` | +| `S80MDeviceManager.new_entry` | `(label)` staticmethod | 注册表条目骨架(kind/slots/label + 进程字段占位;深度可用时 slots 含 `settings.S80M_DEPTH_SLOT`) | `dict` | +| `S80MDeviceManager.spawn` | `(dev_key, entry)` | 临时 50fps yaml 副本 + Popen + watchdog + reader 线程;深度可用时追加 `--depth-sdk-dir` 并注入 `LD_LIBRARY_PATH` | `bool` | +| `S80MDeviceManager.read_pipe` | `(dev_key)` | reader 线程:解析双目帧 → `frame_ready` ×2 + 深度块 → `depth_ready` | 无 | +| `S80MDeviceManager.check_alive` | `(dev_key)` | watchdog 槽:进程退出时停表 + 回读 stderr 末尾 500 字符 | 无 | +| `S80MDeviceManager.close` | `(dev_key)` | 停 watchdog → 关 stdin → terminate/kill → 关 stdout → join reader → 清理临时文件 → `device_closed` | 无 | +| `S80MDeviceManager.send_exposure` | `(entry, auto, value)` | stdin 行协议下发曝光(-1.0=自动) | 无 | +| `S80MDeviceManager.shutting_down` | 属性 | 窗口关闭标记(read_pipe 主循环退出条件) | — | + +**关键数据**:`settings.STEREO_RECORD_MIN_INTERVAL_S`(1/30s)为抽帧桶宽; +帧时间戳为 SDK 硬件纳秒时钟(帧/IMU 同源,SLAM 对齐用);镜头方向已由 SDK +config(`left_cam_rotate_180`/`right_cam_rotate_180`/`stereo_swap_lr`)处理, +reader 不再翻转;深度由子进程 SDK 深度引擎计算(进程常驻 ~1 核 + ~220MB, +`S80M_DEPTH_ENABLED=False` 一键回退纯 RGB);`depth_ready` 的 hw_ns 用 +`object` 类型信号参数(PyQt5 qint32 封送会截断 >2^31 纳秒)。 + +**调用关系**:被 `ui/main_window.py`(`_open_s80m`/`_on_stereo_frame`/ +`_on_s80m_depth`/`_close_s80m`/`_s80m_set_exposure`)实例化;`frame_record_decision` 经 +MainWindow 集成路径被 `tools/tests/s80m_50fps_decimation_test.py` 覆盖 +(测试构造假 50fps 帧流走 `_on_stereo_frame` 接线,不直接 import 该函数)。 + +### core/d435_manager.py + +**作用**:D435 深度双目设备管理器(每台一个条目):worker 生命周期 +(创建/信号接线/停止)与帧处理口径(calib 首帧注入、深度热力图/EMA、 +录制写入)。`spawn` 接收 worker 类参数(离线测试在 `ui.main_window` 模块 +patch `D435Worker` 替身仍生效);信号连接在 `worker.start()` 之前完成。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `D435DeviceManager` | `(pipeline, parent=None)` | worker 生命周期 + 帧口径 | 信号:`frames_ready(str, np.ndarray, object, object, str)`(slot, frame, hw_ns, imu, dev_key)、`log(str)` | +| `D435DeviceManager.new_entry` | `(label, serial, rgb_slot, depth_slot, near_mm, far_mm, smooth_k, temporal_alpha)` staticmethod | 注册表条目骨架(worker 占位 None) | `dict` | +| `D435DeviceManager.spawn` | `(dev_key, entry, model_name, profile, exposure, worker_cls)` | 创建 worker(分辨率/fps 取 profile)、连接 `frames_ready`→`_relay_frames`、start | 无 | +| `D435DeviceManager.process_frame` | `(entry, slot_id, frame, hardware_ns=0, dev_key=None)` | 帧处理口径 → `(display_frame, is_depth)`;深度槽:热力图 + EMA + `pipeline.write_depth`;RGB 槽:原帧 + `write_external_frame` | `tuple` | +| `D435DeviceManager.close` | `(entry)` | 断开信号 → stop → deleteLater | 无 | + +**关键数据**:calib 首帧注入只发生一次(`entry["calib_sent"]`),标定写 +`calibration/head_stereo.json`;热力图 EMA 仅可视化(录制原始 PNG16 不受 +影响);`hw_ns` 用 object 封装(同 S80M 口径)。 + +**调用关系**:被 `ui/main_window.py`(`_open_d435`/`_on_d435_frames`/ +`_close_d435`)实例化;调用了 `core/stereo_depth.py`。 + +### core/device_manager.py + +**作用**:统一设备 worker 注册表 + 面板开关分派 + 录制元数据口径(纯 +Python,零 Qt)。具体开启/关闭动作(建槽、弹窗、widget 接线)留在 UI 侧 +回调,core 只做注册表与分派口径——录制锁双保险、kind 路由、失败语义统一 +于此。主窗口 `_workers` 直接引用 `DeviceManager.entries`(同一 dict,离线 +测试注入假条目沿用同一形状)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `DeviceManager` | 无参 | 注册表容器 | 属性 `entries`(dev_key → entry dict) | +| `DeviceManager.uvc_entry` / `ble_entry` / `glove_entry` | `(slots, label)` / `(slot, label)` / `(slot, role, glove_widget, label)` staticmethod | uvc/占位蓝牙/手套条目骨架 | `dict` | +| `DeviceManager.get` / `has_kind` / `has_serial` | `(dev_key)` / `(kind)` / `(kind, serial)` | 注册表查询(serial 查重用于 d435 同机重复开关检测) | 对应值 | +| `DeviceManager.build_device_meta` / `reset_s80m_record_state` / `teardown_all` | `()` / `()` / `(close_fns)` | 录制设备元数据 / 抽帧状态重置 / 全部关闭 | `list` / 无 / 无 | +| `build_device_meta` | `(entries)`(模块级) | 注册表 → meta devices 段(手套附 `sensor_column`,无数据蓝牙不进) | `list` | +| `reset_s80m_record_state` | `(entries)`(模块级) | 录制起止重置 50→30 抽帧状态(桶号 + IMU 缓冲) | 无 | +| `teardown_all` | `(entries, close_fns)`(模块级) | 遍历注册表分类清理(未知 kind 兜底弹出) | 无 | +| `dispatch_toggle` | `(dev, on, is_recording, open_fns, close_fns)`(模块级) | 面板开关分派:录制锁双保险 + kind 路由 → open/close 回调 | `opened: bool` | + +**调用关系**:被 `ui/main_window.py`(`_on_device_toggled`/ +`_teardown_all_workers`/`_build_device_meta`/`_reset_s80m_record_state`/ +`_open_uvc`/`_open_glove`/`_open_ble_placeholder` + 冲突检测)使用。 + +### core/device_naming.py + +**作用**:槽名清洗/分配与曝光基线归一化(纯函数,零 Qt 依赖)。从 +`ui/main_window.py` 抽出的命名口径,供主窗口与离线测试共用。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `realsense_short` | `(model_name)` | 型号名 → 短名(如 "Intel RealSense D405" → "D405") | `str` | +| `slot_base` | `(name, fallback)` | 槽名清洗:非 `[0-9A-Za-z_一-鿿]` 字符 → `_` | `str` | +| `normalize_original` | `(orig)` | 曝光基线归一化 → `(auto, value)` 或 `None` | `tuple | None` | +| `allocate_slot_names` | `(user_name, model_name, occupied_rgb_slots)` | 槽名分配:用户命名优先 → 型号名回落(d435_rgb/d435_depth 经典名);同前缀多台编号追加(`_2`…) | `(rgb_slot, depth_slot)` | + +**调用关系**:被 `ui/main_window.py`(`_open_d435`)与 `core/exposure_controller.py` 使用。 + +### core/exposure_controller.py + +**作用**:每设备曝光控制——对话框参数解析与下发/持久化口径(零 Qt 依赖)。 +UVC 无曝光入口(固定自动曝光,返回 None)。「恢复默认」基线(original): +优先持久化的首见基线(`settings.device_original`),无则用 worker 本次开流 +读回的硬件状态,并在对话框弹出时落盘锁定。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `exposure_dialog_params` | `(kind, entry, dev_key)` | 按设备类型解析对话框上下文(量程/自动/当前值/基线 + 首见基线落盘);D435 → µs(流启动后读真实量程,兜底 1~66000);S80M → 1.0~885.0 | `dict | None` | +| `apply_exposure` | `(dev_key, entry, auto, value, send_s80m=None)` | 按类型下发(d435 → worker.set_exposure;s80m → send_s80m 回调)+ `settings.save_device_exposure` 持久化 | 无 | + +**调用关系**:被 `ui/main_window.py`(`_open_exposure_dialog`/`_apply_exposure`)使用;`tools/tests/exposure_control_test.py` 经 MainWindow `_apply_exposure` 接线与 `CameraWorker._apply_exposure_to` 间接覆盖(测试不直接 import 本模块)。 + +## 录制落盘与持久化(原 storage/) + +### core/egodata_writer.py + +**作用**:EgoData 格式录制器,多模态机器人遥操作数据采集的落盘核心 +(`QObject`,带 Qt 信号)。一个 episode 对应一个会话目录:RGB 视频经 ffmpeg +管道写成 MP4,深度写热力图 MP4 和/或原始 uint16 PNG(png16),触觉传感器/IMU/手部 +姿态写 LeRobot v3 兼容 Parquet,同时生成 `metadata.json`、`timestamps.json`、 +`meta/info.json`、`meta/tasks.jsonl`、`meta/stats.json`、`meta/episodes/` 等 +元数据。`meta/info.json` 是服务器上传契约(字段名、类型、结构不可动); +`_write_metadata()` 写的 `metadata.json` 含 `devices` 段(设备分组权威信息)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `_get_ffmpeg` | 无参(模块级) | v1.0.9 起薄封装 `core/encoder_probe.list_working_ffmpegs()`(imageio 静态二进制 → PATH,须 `-version` 自检) | 可执行文件路径或 `None` | +| `_build_data_schema` | `(sensor_names, sensor_dim=256, device_ids=None)`(模块级) | 构建 data parquet 的 schema | `pa.Schema` | +| `EgoDataWriter.start_episode` | `(output_dir, cameras, fps=30, sensors, task_name, device_ids, calibration, camera_fps, depth_enabled, raw_depth, heatmap_near_mm, heatmap_far_mm, heatmap_smooth_k, heatmap_temporal_alpha, depth_heatmaps, depth_slots, raw_depth_slots, devices, calibrations, batch_index=0)` | 建 episode 目录结构、写标定与 metadata.json、启动各路 ffmpeg | `bool`;发 `episode_started(str)` | +| `EgoDataWriter.write_video_frame` | `(camera_name, frame, flip_vertical=True)` | 一帧 BGR 写入对应 ffmpeg 管道 | 无;管道断裂发 `error_occurred` | +| `EgoDataWriter.write_depth_frame` | `(frame_index, depth_frame, depth_slot="")` | uint16 深度 → 热力图 → 深度 MP4(首帧惰性建目录/启动 ffmpeg) | 无;`settings.DEPTH_ENABLED` 关闭且无显式深度槽时跳过 | +| `EgoDataWriter.write_raw_depth_frame` | `(frame_index, depth_frame, depth_slot="")` | 原始 uint16 深度写 `depth//<1-based 序号>.png`(16-bit grayscale,毫米,压缩级 `D435_PNG_COMPRESSION`;D435/D405/S80C 统一 png16) | 写 PNG16 | +| `EgoDataWriter.write_frame_row` | `(frame_index, timestamp_s, sensors, connection_status, hardware_ns=0, imu_samples)` | 追加一行到 data parquet 缓冲 + 记录 timestamps 条目 | 内存缓冲;`hardware_ns` 仅双目帧非零,`imu_samples` 仅随 `stereo_left` 携带 | +| `EgoDataWriter.end_episode` | 无参 | 关 ffmpeg,写 timestamps/data/episode/info/tasks/stats/compat 全部文件 | 发 `episode_finished(episode_dir)` | +| `EgoDataWriter.abort_episode` | 无参 | 关 ffmpeg 并整目录 `shutil.rmtree` 丢弃 | 发 `episode_finished("")` | +| `_write_metadata` | `(cameras, fps, sensors, task_name)`(内部) | 写根级 `metadata.json`(含 `devices` 段) | 写文件 | +| `_write_info_json`(内部) | 无参 | 写 LeRobot v3 精确兼容 `meta/info.json`(服务器上传契约,结构不可动) | 写文件 | +| `_write_tasks_jsonl`(内部) | 无参 | 写 `meta/tasks.jsonl`(服务器上传依赖其识别任务) | 写文件 | +| `_write_episode_parquet` / `_write_compat_parquet`(内部) | 无参 | 写 `meta/episodes/chunk-000/file-000.parquet` 并复制到兼容旧路径 `chunk_000000.parquet` | 写文件 | +| `_write_timestamps`(内部) | 无参 | 写 `timestamps.json`;含 `hardware_ns` 的行按 hw 稳定排序保证时间线单调 | 写文件 | +| `_write_data_parquet`(内部) | 无参 | 按传感器分别写 `data//chunk-0000/chunk_000000.parquet` + `data/imu/...`(zstd) | 写文件 | +| `_write_stats_json`(内部) | 无参 | 写 `meta/stats.json`(均值/标准差/极值,imu 为 6 轴样本级统计) | 写文件 | +| `_plan_calibration_files` / `_device_slot_prefix`(内部) | `(legacy_calib)` | 规划标定文件布局:首台双目型写 `calibration/head_stereo.json`(服务器/回放依赖),其余写 `calibration/{slot前缀}_calibration.json` | `{相对路径: StereoCalibration}` | + +**关键数据**: +- 目录布局(docstring 即约定):`//_000001/` 下 `videos//chunk-0000/.mp4`、`depth//.mp4`(热力图)或 `depth//000001.png`(png16 uint16 毫米)、`calibration/head_stereo.json`、`metadata.json`、`timestamps.json`、`data//chunk-0000/chunk_000000.parquet`、`meta/episodes/chunk-000/file-000.parquet`。 +- 编码器选择(v1.0.9):`start_episode` 内(启动 ffmpeg 之前)按本会话 RGB 流数/最大分辨率调 `core/encoder_probe.select_encoder`(auto:nvenc 探针 → x265 速度门槛 → x264 兜底;显式指定失败按 auto 链回退),结果进程内缓存并写 `metadata.video_codec`;RGB 与深度热力图 ffmpeg 命令共用该选择(`choice.encoder + choice.args`)。 +- Parquet schema(代码中的 `pa.schema` 真实定义):`_EPISODE_SCHEMA` = `episode_index/task_index/start_frame_index/end_frame_index/length` 均 int64;`_IMU_SCHEMA` = `episode_index, frame_index, timestamp(float32), task_index, hardware_ns(int64), imu_ts_ns(list), observation.imu(list>)`,IMU 样本 6 轴 = `[gx, gy, gz, ax, ay, az]`;`_build_data_schema` 在传感器列 `observation.`(list)之外固定加 `observation.`/`observation.`(list,值全 0 占位)、`action`(list,恒 `[0.0]`)、每设备 `status.`(string,默认 `"connected"`)。 +- `metadata.json` 顶层键:`format="egodata"`、`format_version="1.0"`、`episode_index`、`fps`、`task_name`、`cameras`(每相机 `{height, width, type: rgb|depth, unit:"mm", format:"png16", fps?, device_key?, device?}`)、`devices`(每设备 `{key, kind, name, slots, serial?, sensor_column?, resolution, fps, calibration}`)、`sensors`、`sensor_dim`、`created_at`、`codebase_version`(`settings.APP_VERSION`)、`video_codec`(v1.0.9 编码器选择 `{encoder, codec, crf, ffmpeg, selected_by, probe}`)、`drop_stats`(v1.0.9 丢帧统计,`end_episode` 回写)。 +- `meta/info.json` 顶层键:`codebase_version="v3.0"`、`fps`、`video`、`task_name`、`features`(`observation.: {dtype:"float32", shape:[16,16]}`、`observation.imu: {dtype:"float32", shape:[6]}`、`action: {shape:[1]}`)、`cameras`(dict,非 list——注释强调)、`devices`(紧凑段)、`device_names`(槽位→用户命名)、`sensors`、`sensor_dim`、`created_at`。 +- `meta/tasks.jsonl` 行:`{"task_index": 0, "task": task_name or "default recording"}`。 +- `meta/stats.json`:`observation.` 与 `observation.imu` 各含 `mean/std/min/max`(list),另有 `action` 恒值段。 +- `timestamps.json`:`{"timestamps": [{frame_index, timestamp, wall_time, hardware_ns?}], "total_frames"}`。 +- 深度槽位:显式 `depth_slots` 注册驱动落盘(不用槽名是否含 "depth" 猜测,D435/D405 槽名可被消歧编号如 `d435_depth_2`;S80C 用 `settings.S80M_DEPTH_SLOT`=`"stereo_depth"`);未注册时回退 S80M 传统单槽 `settings.CAMERA_DEPTH`(`"head_depth"`)。 + +**调用关系**:被 `core/pipeline.py`(录制主链路)、`tools/tests/test_meta_devices.py`、`tools/tests/multi_device_registry_test.py` 引用;调用了 `core/stereo_depth.py`(`depth_to_heatmap`/`DepthHeatmapSmoother`)、`core/calibration.py`、`core/helpers.py` 的路径函数。 + +### core/calibration.py + +**作用**:定义 EgoData 标准的标定数据模型。`CameraIntrinsics` 表达单目内参 +(OpenCV 3×3 矩阵 + 畸变系数),`StereoCalibration` 表达双目 + 深度相机完整 +标定(含基线、depth_scale、相机-IMU 时间偏移),并提供 OpenCV 结果互转与 +JSON 读写。docstring 写明其 JSON 布局即为 `calibration/head_stereo.json` 的 +落盘格式。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `CameraIntrinsics` | `intrinsic: [fx, fy, cx, cy]`;`distortion` 默认 `[]` | 单目内参 dataclass | 无 | +| `CameraIntrinsics.from_matrix` | `(K: 3×3, dist=None)` | 从 OpenCV 标定矩阵构建 | `CameraIntrinsics` | +| `CameraIntrinsics.to_matrix` | 无参 | 还原 3×3 相机矩阵 | `np.ndarray (3,3)` | +| `CameraIntrinsics.to_dist_array` | 无参 | 还原畸变系数 | `np.ndarray`(空时返回 `zeros(4)`) | +| `StereoCalibration` | 字段见下表 | 双目 + 深度标定 dataclass | 无 | +| `StereoCalibration.to_dict` | 无参 | 序列化为 dict(`depth_camera` 非空才输出该键) | `dict` | +| `StereoCalibration.from_dict` | `(d: dict)` | 从 dict 反序列化(缺键用默认值) | `StereoCalibration` | +| `StereoCalibration.save` | `(path)` | 写 JSON 文件 | 磁盘文件 | +| `StereoCalibration.load` | `(path)` | 读 JSON 文件 | `StereoCalibration` | +| `StereoCalibration.from_opencv` | `(K_left, dist_left, K_right, dist_right, baseline=0.095, resolution=(1280,800), fps=25.0, depth_scale=0.001)` | 从 `cv2.stereoCalibrate` 结果构建 | `StereoCalibration` | + +**关键数据**:`StereoCalibration` 字段与 JSON 键一一对应:`type`(默认 `"stereo_rgbd_camera"`)、`name`(默认 `"head_stereo"`)、`resolution`(默认 `[1280, 800]`)、`fps`(默认 `25.0`)、`baseline`(默认 `0.095`,米)、`left_camera`/`right_camera`(各含 `intrinsic` 与 `distortion`)、`depth_scale`(默认 `0.001`,像素值 × depth_scale = 米)、`cam_imu_timeshift`(默认 `-0.0019` 秒,来源注释注明 SDK calib.yaml 的 timeshift_cam_imu)、可选 `depth_camera`(D435 独有;注释注明 rs2 畸变系数为 Inverse Brown Conrady 模型,原样存储)。 + +**调用关系**:被 `core/egodata_writer.py`(写入 `calibration/head_stereo.json`)、`core/d435_camera.py`(D435 运行时从 rs2 profile 提取标定)、`ui/main_window.py`(`_open_s80m` 静态标定注入)、`tools/tests/test_meta_devices.py` 引用。 + +### core/database.py + +**作用**:SQLite 数据库管理器。`Database` 类用 `threading.local` 为每线程维护 +独立连接(线程安全),建库时开启 WAL 模式与外键约束;`SCHEMA_SQL` 定义 +`recording`(录制历史)与 `upload_task`(上传任务)两张表及索引。模块底部 +创建模块级单例 `db = Database()`,全项目共享。路径取自 +`config.settings.DB_PATH`(`config/settings.py`:`data/pipeline.db`)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `Database.__init__` | `(db_path=DB_PATH)` | 保存路径 | 无 | +| `Database.conn`(property) | 无参 | 取当前线程连接,自动创建目录/连接、设 row_factory=Row、WAL、外键 | `sqlite3.Connection` | +| `Database.close` | 无参 | 关闭当前线程连接 | 无 | +| `Database.init_schema` | 无参 | 执行 `SCHEMA_SQL`(IF NOT EXISTS) | 建表并 commit | +| `db` | 模块级单例 | 全局共享实例 | `Database` 实例 | + +**关键数据**(SQLite 表,`config.settings.DB_PATH` = `data/pipeline.db`): +- `recording`:`id TEXT PK`、`camera_index INTEGER NOT NULL`、`camera_name TEXT NOT NULL`、`file_path TEXT`、`file_size_mb REAL`、`duration_sec REAL`、`resolution_w INTEGER`、`resolution_h INTEGER`、`status TEXT`(`completed | uploaded | aborted | deleted | uploaded_deleted`)、`started_at TEXT NOT NULL`、`finished_at TEXT NOT NULL`;索引 `idx_recording_camera(camera_index)`、`idx_recording_date(started_at)`。 +- `upload_task`:`id TEXT PK`、`session_path TEXT`、`session_name TEXT`、`status TEXT`(`pending | uploading | completed | failed | skipped`)、`progress REAL`、`retry_count INTEGER`、`server_url TEXT`、`server_session_id TEXT`、`error_message TEXT`、`created_at TEXT`、`updated_at TEXT`;索引 `idx_upload_status(status)`、`idx_upload_session(session_path)`。 + +**调用关系**:被 `core/recording_repository.py`、`core/uploader.py`、`ui/main_window.py` 引用。 + +### core/recording_record.py + +**作用**:定义录制历史记录的 dataclass `RecordingRecord`,字段与 `recording` +表列一一对应,`id`/`started_at`/`finished_at` 默认用 `core.helpers` 的 +`new_id`/`utcnow` 生成。(原名 storage/models.py,v1.0.3 改名避免与 +`tools/models/` 混淆。) + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `RecordingRecord` | 字段见下 | 一条录制记录 | 无 | +| `RecordingRecord.from_row` | `(row)` classmethod | 从 `sqlite3.Row` 构造 | `RecordingRecord` | + +**关键数据**:字段 `id: str`、`camera_index: int = 0`、`camera_name: str = ""`、`file_path: str = ""`、`file_size_mb: float = 0.0`、`duration_sec: float = 0.0`、`resolution_w: int = 0`、`resolution_h: int = 0`、`status: str = "completed"`(`completed | uploaded | aborted | deleted | uploaded_deleted`)、`started_at: str`、`finished_at: str`。 + +**调用关系**:被 `core/recording_repository.py`、`ui/main_window.py` 引用。 + +### core/recording_repository.py + +**作用**:录制记录的数据仓库层,`RecordingRepo` 全部为静态方法,直接操作 +`core.database` 的单例 `db`。其中 `mark_uploaded` 支持"上传成功、本地保留" +的语义(行保留、状态改为 `uploaded`),`mark_uploaded_deleted` 支持"上传 +成功、本地已删"(状态 `uploaded_deleted`),两者都保证历史可查。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `RecordingRepo.save` | `(r: RecordingRecord)` | INSERT OR REPLACE 一条记录 | 写入并 commit | +| `RecordingRepo.list_all` | `(limit=100)` | 按 `started_at` 倒序取最近 N 条 | `List[RecordingRecord]` | +| `RecordingRepo.list_by_camera` | `(camera_index, limit=50)` | 按摄像机索引筛选 | `List[RecordingRecord]` | +| `RecordingRepo.delete` | `(record_id)` | 按 id 删除 | 删除并 commit | +| `RecordingRepo.mark_uploaded` | `(file_path)` | 按路径把状态改为 `uploaded`(已上传、本地保留) | 受影响行数 `int` | +| `RecordingRepo.mark_uploaded_deleted` | `(file_path)` | 按路径把状态改为 `uploaded_deleted` | 受影响行数 `int` | + +**调用关系**:被 `ui/upload_dialog.py`、`ui/main_window.py` 引用;调用了 `core/database.py` 与 `core/recording_record.py`。 + +### core/task_record.py + +**作用**:任务记录持久化。`data/tasks.json` 是唯一权威源(`_TASKS_FILE = +settings.DATA_DIR/tasks.json`)。核心设计:进度按**分账模型**持久化—— +`local_count`(本机累计完成段数,`increment_task_completed()` +1)、 +`synced_count`(后端已确认的本机段数,水位只前进不后退)、`backend_count` +(最近一次已知后端全局数),派生显示值 `completed_count = backend_count + +(local_count - synced_count)` 由 `_recount()` 统一重算(字段名保留,UI 零 +改动);上传成功后本地文件被删也不影响进度。旧数据缺新字段时一次性迁移 +回填(`local/synced/backend` 均取旧 `completed_count`,目录扫描兜底, +历史不补报、显示连续)。`_read_raw()` 在文件缺失或 JSON 解析失败时自动 +播种内置 `_SEED_TASKS`(3 个默认任务)。`merge_backend_tasks()` 把后端 +推送的任务按 id 合并进本地记录(本地独有任务保留、(name, assigned_user) +同名去重、被删任务以 `hidden` 墓碑防止复活、账号身份轮询下的撤销清除; +后端全局数权威,本机水位沿用)。多用户语义:任务可带 `assigned_user` +(null/缺失 = 公共任务),`load_tasks(identity)` 与 `filter_by_identity()` +按身份过滤可见范围(None=全部、`"guest"`=仅公共、用户名=公共+指派给该 +用户)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `load_tasks` | `(identity: str \| None = None)` | 加载任务,过滤 `hidden`,自动计算 `status`,按 `assigned_at` 新→旧排序;`identity` 过滤可见范围(None=全部/`"guest"`=仅公共/用户名=公共+指派) | `list[dict]`;旧数据缺同步字段时迁移回填并写回文件 | +| `filter_by_identity` | `(tasks, identity: str \| None = None)` | 纯函数:按身份过滤任务列表(不修改原列表,供 UI 对已有列表即时过滤) | 新列表 | +| `save_tasks` | `(tasks)` | 持久化任务元数据(含分账字段) | 写文件(哑写,不迁移不重算) | +| `merge_backend_tasks` | `(backend_tasks, view_scope: str \| None = None)` | 后端任务合并进本地记录(id 合并/本地保留/(name, assigned_user) 同名去重墓碑/账号身份撤销清除/后端全局数权威+本机水位沿用) | 合并后列表(内部调用 `save_tasks` + `load_tasks`) | +| `mark_hidden` | `(task_id)` | 标记任务隐藏(UI 不再显示) | 写文件 | +| `refresh_progress` | 无参 | 用持久化计数重载任务列表 | `list[dict]` | +| `increment_task_completed` | `(task_name, task_id: str \| None = None, assigned_user: str \| None = None)` | 一次录制完成:匹配优先级 id → (name, assigned_user) → 唯一同名回退;`local_count` +1 并重算显示值 | 更新后的任务 dict,无匹配返回 `None`;写文件 | +| `pending_sync_tasks` | 无参 | 所有 `local_count > synced_count` 的任务快照(含 hidden,不按身份过滤);纯读路径不触发迁移 | `list[dict]`(id/name/local_count/synced_count) | +| `mark_synced` | `(task_id, synced_count, backend_count)` | flush 成功后回写:水位只前进不后退,`backend_count` 用响应值无条件替换 | 更新后的任务 dict 或 `None`;写文件 | +| `task_by_id` | `(task_id)` | 按 id 查单个任务 | `dict` 或 `None` | +| `_read_raw` | 无参(内部) | 读 `tasks.json`;缺文件/解析失败时播种 | `list[dict]` | +| `_write` | `(data)`(内部) | 原子写(`.tmp` + `os.replace`) | 写文件 | + +**关键数据**(`data/tasks.json` 结构):顶层 `{"tasks": [...], "updated_at": iso字符串}`。任务条目字段:`id`、`name`、`description`、`status`(`load_tasks` 自动计算:`pending`(0%) / `in_progress`(>0%) / `completed`(100%))、`total_required`、`assigned_at`(ISO 时间)、`assigned_user`(指派用户;null/空/缺失归一化为 None = 公共任务)、`params`(dict)、`completed_count`(派生显示值 = `backend_count + (local_count - synced_count)`)、`local_count`/`synced_count`/`backend_count`(进度分账三字段)、`hidden`(bool 墓碑)。内置播种任务:`task_001`(`cylinder_grasping`)、`task_002`(`cube_placement`)、`task_003`(`valve_rotation`)。`_count_sessions()` 按 `settings.RECORDING_DIR//<会话>/meta/info.json` 存在与否统计会话数,仅用于旧数据迁移回填。 + +**调用关系**:被 `ui/main_window.py`(`load_tasks`、`increment_task_completed`)、`ui/task_page.py`(`load_tasks`、`filter_by_identity`、`merge_backend_tasks`、`refresh_progress`、`mark_hidden`)引用。 + +## 上传与后端通信(原 network/) + +### core/api_client.py + +**作用**:对接 Data Acquisition 服务器的 HTTP REST 客户端。基于 `requests`, +支持复用外部已认证的 `requests.Session`(如 `TaskService` 的登录会话); +上传接口用包装文件对象在读取时回调进度,避免把数 GB 的 zip 一次性读入 +内存。所有网络异常均被吞掉并转为布尔/空值/错误字典返回,不会向上抛出。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `APIClient` | `(base_url: str, session: requests.Session = None)` | REST 客户端;`session` 缺省时自建并设置 `User-Agent: DAQ-SDK/1.0` | — | +| `APIClient.close` | `()` | 仅关闭自建 session | 复用外部 session 时不关闭 | +| `APIClient.health_check` | `() -> bool` | GET `/health` 健康检查(UI「测试连接」用) | 200 为 `True`,异常/非 200 为 `False` | +| `APIClient.upload_session_zip` | `(zip_path, session_name, progress_cb: Optional[Callable[[int, int], None]] = None, name: str = "", project_id: str = "") -> dict` | POST `/api/v1/session/upload` 上传 zip(`progress_cb` 收 `(uploaded_bytes, total_bytes)`);`name`/`project_id` 为服务器目标项目表单字段(同名项目前缀歧义时服务器返回 409,须用 `project_id` 消歧) | `{"ok": True, "session_id": …, "response": …}` 或 `{"ok": False, "error": …, "ambiguous_project": True}`(409 项目歧义时置 `ambiguous_project`;错误文本截断 300 字符) | +| `APIClient.get_projects` | `(limit: int = 100) -> list[dict]` | GET `/api/v1/projects` 项目列表(UI 下拉框用) | 异常返回 `[]` | +| `APIClient.get_sessions` | `(limit: int = 50) -> list[dict]` | GET `/api/v1/sessions` 查询列表 | `data["sessions"]`;异常返回 `[]` | +| `APIClient.get_session` | `(session_id: str) -> Optional[dict]` | GET `/api/v1/session/{id}` 详情 | 异常返回 `None` | +| `APIClient.delete_session` | `(session_id: str) -> bool` | DELETE `/api/v1/session/{id}` | 200 为 `True` | +| `_ProgressReader` | 内部类(文件包装) | 上传读取时回调进度 | 用完 `close()` | + +**关键数据**: + +| 名称 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| `CONNECT_TIMEOUT` | int | 10 | 连接超时(秒) | +| `READ_TIMEOUT` | int | 1800 | 读超时(秒);大会话上传+服务器解包入库可能耗时数分钟,设 30 分钟 | +| `User-Agent` | str | `"DAQ-SDK/1.0"` | 自建 session 时写入请求头 | +| API 端点 | — | `POST /api/v1/session/upload`、`GET /api/v1/sessions`、`GET /api/v1/session/{id}`、`DELETE /api/v1/session/{id}`、`GET /api/v1/video/{id}/{cam}/stream`、`GET /health` | 模块 docstring 中的真实 API 清单 | + +**调用关系**:被 `core/uploader.py`、`ui/upload_dialog.py`(懒加载用于测试连接与项目列表)import。依赖 `requests`。 + +### core/task_service.py + +**作用**:后台任务轮询服务。`QTimer` 定时触发,每次轮询在 `threading.Thread` +后台线程执行 HTTP 请求,不阻塞 UI;通过 Qt 信号把任务列表与连接状态通知 +UI。支持 Cookie-based JWT 认证:先 POST `/api/v1/auth/login` +(`remember_me=True`),复用带 cookie 的 `requests.Session` 轮询 +GET `/api/v1/device/tasks?device_name=…`。设计模式参照已移除的 `SyncService`。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_normalize_tasks` | `(raw: list[dict]) -> list[dict]`(模块级函数) | 后端字段 → 内部字段名映射 | `current_count`→`completed_count`,状态 `"active"`→`"in_progress"`;输出含 `id/name/description/status/total_required/completed_count/assigned_at/assigned_user(null/空→None)/params` | +| `TaskService` | `(server_url: str = "", parent=None)` | 任务轮询服务;URL 缺省取 `settings.SERVER_URL`,轮询间隔取 `settings.TASK_POLL_INTERVAL_MS`(缺省 30000) | 自建带 cookie 的 `requests.Session`,缓存最近一次任务列表;身份三态 `_identity`:None=未决 / `"guest"` / 用户名,`_epoch` 代次守卫丢弃过期身份响应 | +| `TaskService.verify_credentials` | `(url, username, password)`(staticmethod) | 独立 Session 同步校验登录凭据(供登录对话框用,不触碰实例状态) | `(ok: bool, msg: str, cookies)`,成功时 cookies 由 `adopt_login` 接管 | +| `TaskService.adopt_login` | `(url, username, cookies)` | 采纳已验证登录:cookie 拷入实例 Session,切换账号身份并立即轮询 | `identity_changed` 信号 | +| `TaskService.set_guest` | `(url: str \| None = None)` | 切换游客身份:清 cookie 并立即轮询(只应拉到公共任务) | `identity_changed` 信号 | +| `TaskService.current_identity` | `() -> str \| None` | 当前身份:None / `"guest"` / 用户名 | — | +| `TaskService.start` / `stop` | `()` | 启动 / 停止定时轮询 | `start` 只启动 QTimer 不触发拉取——首次拉取由身份确定路径(`adopt_login`/`set_guest`)触发,UI 在身份确定后才 `start()` | +| `TaskService.poll_now` | `()` | 手动触发一次拉取 | 不改变定时器状态 | +| `TaskService.set_server_url` | `(url: str)` | 修改服务器地址并立即重新轮询 | 清 cookie、置未登录 | +| `TaskService.set_credentials` | `(username, password)` | 更新登录凭据 | — | +| `TaskService.set_server_and_credentials` | `(url, username, password)` | 同时更新地址与凭据 | 清 cookie、置未登录并重新轮询 | +| `TaskService.set_interval` | `(ms: int)` | 动态修改轮询间隔 | — | +| `TaskService.cached_tasks` | `() -> list[dict]` | 返回缓存任务列表 | 不发网络请求 | +| `TaskService.flush_now` | `()` | 录制完成后的即时进度上报(后台线程) | 本机显示不依赖它,仅为其他机器秒级传播;轮询 tick 兜底 | +| 信号 | `tasks_updated(list)` / `connection_status(bool)` / `error_occurred(str)` / `login_result(bool, str)` / `identity_changed(str)` / `identity_expired()` / `progress_synced()` | 任务刷新 / 连接状态 / 出错 / 登录结果 / 身份确定或切换(`"guest"` 或用户名)/ 登录态轮询遇 401/403(会话过期,UI 重登或降级游客)/ 进度增量上报成功后本地计数已更新 | 登录态 401/403 → 身份置空 + `identity_expired`;游客态 401 只报错不断身份;网络错误与 5xx 只记错误、不改连接状态 | +| 内部 | `_trigger_poll` / `_trigger_login_and_poll` / `_login_and_poll` / `_do_login` / `_poll` / `_post_progress` / `_note_fail` / `_flush_progress` | 后台线程调度、登录、拉取、进度水位合并上报 | daemon 线程执行;`_flush_progress` 仅在 GET 200 后调用,`_flush_lock` 防并发重复 POST | + +**关键数据**: + +| 名称 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| `CONNECT_TIMEOUT` | int | 10 | HTTP 请求超时(秒) | +| 轮询间隔 | int | `settings.TASK_POLL_INTERVAL_MS`(默认 30000) | 读不到时 `getattr` 兜底 5000 毫秒(代码兜底值,非配置默认) | +| 设备认领名 | str | `settings.DEVICE_NAME` | 读不到时回退 `"EGO_001"`;作为 `device_name` 查询参数 | +| API 端点 | — | `POST /api/v1/auth/login`、`GET /api/v1/device/tasks`、`POST /api/v1/device/tasks/progress` | 登录 body 含 `username/password/remember_me`;进度上报 body 含 `task_id/session_id/increment/device_name`,`session_id = "{device}:{task_id}:{水位}"` 幂等(后端按 `(device_name, session_id)` 去重,重复请求返回当前全局数不重复加;游客上报公共任务应放行);404 → `_progress_supported=False` 静默降级本地口径 | +| `User-Agent` | str | `"DAQ-SDK/1.0"` | — | + +**调用关系**:被 `ui/main_window.py` 实例化。依赖 `requests` 与 `PyQt5.QtCore`。 + +### core/uploader.py + +**作用**:上传队列管理器。工作流:①(可选)用 ffmpeg 把 session 内 videos +重编码到低码率(保持分辨率/帧率不变,帧级对齐不受影响);②用 `zipfile` +打包 session 目录为 zip(`ZIP_STORED` 免二次压缩,EgoData 路径转 LeRobot v3 +兼容路径);③经 `APIClient` 上传;④状态持久化到 SQLite 表 `upload_task`, +全程通过 Qt 信号通知 UI。失败自动重试(最多 `settings.UPLOAD_RETRY_MAX` +次),临时 zip 与预压缩产物用完即删。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `UploadTask` | `(session_path: str, server_url: str)` | 单个上传任务数据对象(`__slots__` 11 字段) | 状态初值 `pending`,进度 0.0 | +| `UploadTask.to_dict` / `UploadTask.from_row` | `() -> dict` / `(row: dict)`(staticmethod) | 序列化 / 从数据库行还原 | — | +| `UploadManager` | `(server_url: str = "", session=None)` | 上传队列管理器;URL 缺省 `settings.SERVER_URL`,重试/并发取 `settings.UPLOAD_RETRY_MAX` / `settings.UPLOAD_MAX_CONCURRENT`;`session` 可复用已认证 `requests.Session` | 队列与活跃任务表由 `QMutex` 保护 | +| `UploadManager.server_url` | property(可写) | 当前服务器地址 | — | +| `UploadManager.add_task` | `(session_path: str) -> str` | 入队一个任务(先写库再入队) | 返回 `task_id` | +| `UploadManager.add_tasks` | `(session_paths: list[str]) -> list[str]` | 批量入队 | 只收存在的目录 | +| `UploadManager.start` / `stop` | `()` | 启动 / 停止 worker 线程 | `stop` 等线程最多 10 秒 | +| `UploadManager.pending_count` / `active_count` / `all_done` | `() -> int` / `() -> int` / `() -> bool` | 队列计数查询 | — | +| 信号 | `task_added(str)` / `task_started(str)` / `task_status(str, str)` / `task_progress(str, float)` / `task_completed(str)` / `task_failed(str, str)` / `all_completed()` | 入队 / 开始 / 状态文字 / 进度 0~1 / 完成 / 失败 / 全部完成 | — | +| `UploadManager.get_upload_status` | `(session_path: str) -> str`(staticmethod) | 查某会话最近一条上传状态 | 无记录返回 `"pending"` | +| `UploadManager.list_tasks` | `(session_path: str = "") -> list[dict]`(staticmethod) | 查上传记录(可按会话过滤) | 按 `created_at` 倒序 | +| 内部 | `_worker_loop` / `_upload_one` / `_zip_session` / `_find_working_ffmpeg` / `_precompress_videos` / `_save_to_db` | 并发调度、单任务全流程、打包、ffmpeg 探测、视频预压缩、写库 | 打包与预压缩的临时文件名均带 `task_id`,避免同进程并发任务互相覆盖 | + +**关键数据**: + +| 名称 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| 并发 / 重试 / CRF | 常量 | 取自 `settings.UPLOAD_MAX_CONCURRENT`(默认 1)、`settings.UPLOAD_RETRY_MAX`(默认 3)、`settings.UPLOAD_VIDEO_CRF`(默认 30) | 串行=1 的原因:并发时预压缩临时文件互相覆盖致视频损坏 | +| 上传状态值 | str | `"pending"` / `"completed"` / `"failed"` | 重试期间回 `pending` 重新入队 | +| `upload_task` 表字段 | — | `id, session_path, session_name, status, progress, retry_count, server_url, server_session_id, error_message, created_at, updated_at` | `INSERT OR REPLACE` 写 `core/database.py` 的 `db` | +| 进度区间约定 | — | 预压缩 0~0.08,打包 0.08~0.12,上传 0.12~1.0 | `task_progress` 的 0~1 映射 | +| 路径转换 | — | EgoData `chunk-0000` → LeRobot v3 `chunk_0000`;`videos/stereo_left/chunk-0000/stereo_left_aux.mp4` → `videos/stereo_left/chunk_0000/stereo_left_aux.mp4`;旧扁平结构 `videos/.mp4` → `videos//chunk_0000/file-0000.mp4` | 打包时改写 arcname | +| ffmpeg 候选 | str 列表 | `~/miniconda3/envs/lerobot/bin/ffmpeg`、`~/anaconda3/envs/lerobot/bin/ffmpeg`、PATH 上的 `"ffmpeg"` | conda base 的 ffmpeg 因 openvino/tbb 库冲突不可用,故优先 lerobot 环境的独立 ffmpeg;找不到则跳过压缩 | +| 预压缩参数 | — | `libx265`、`-crf UPLOAD_VIDEO_CRF`(默认 30)、`-preset veryfast`、`-tag:v hvc1`、`-pix_fmt yuv420p`、单文件超时 3600 秒 | 仅处理 `videos/` 下 `.mp4/.avi/.mov`;v1.0.9 起先 `ffmpeg -i` 探测源编码,已是 HEVC(录制直出)的跳过预压,探测失败按未知照旧压缩 | + +**调用关系**:被 `ui/main_window.py`、`ui/upload_dialog.py`、`ui/playback_dialog.py`(懒加载)import。自身调用:`config.settings`、`core.database.db`、`core.api_client.APIClient`。依赖 `PyQt5.QtCore`(`QObject`、`pyqtSignal`、`QMutex`、`QMutexLocker`)。 + +## 回放与会话 + +### core/session_timeline.py + +**作用**:录制会话传感器时间线——向量化合并 per-sensor parquet + 帧号二分 +查询。替代 `ui/playback_dialog.py` 中逐行 dict 合并(docstring 实测:60 分钟 +会话 179464 行,32.5s → 约 1s),提供 O(log n) 的帧号→传感器行查询。纯 +numpy/pyarrow 实现,无 Qt 依赖,可在后台线程运行。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `SensorTimeline` | `(frame_indices, timestamps, obs, signal_mask)` | 统一时间线(按 `(episode_index, frame_index)` 排序) | 属性:`frame_indices (N,) int64`、`timestamps (N,) float64`、`obs {col: (N,D) float32}`(缺值 NaN)、`signal_mask (N,) bool`、`signal_count int`;支持 `bool()`/`len()` | +| `SensorTimeline.nearest_for_column` | `(col, frame_idx)` | 该列中 `frame_index` 最接近的行 | `(行号, |Δ帧|)` 或 `(None, None)`,二分 | +| `SensorTimeline.nearest_for_column_time` | `(col, t_s)` | 该列中 `timestamp` 最接近 `t_s`(秒)的行;含暂停负跳变时退化为向量化 argmin | `(行号, |Δt|秒)` 或 `(None, None)` | +| `load_timeline` | `(session_dir, sensor_names)` | 加载会话传感器时间线(per-sensor 多文件或旧格式单表双路径) | `SensorTimeline` | +| `_merge_per_sensor_parquets`(内部) | `(paths, sensor_names)` | 向量化合并:按 `(episode_index, frame_index, round6(timestamp))` 分组,组内取最后一个非空观测值 | `SensorTimeline` | +| `_find_sensor_parquet` / `_find_all_sensor_parquets`(内部) | `(session_dir)` | 定位 `data//chunk-0000/chunk_000000.parquet` | 路径或 `[]` | +| `_column_to_matrix`(内部) | `(col, n_rows)` | pyarrow 列 → `(n_rows, D)` float32 矩阵(fixed_size_list 展平,失败返回 None) | `np.ndarray` 或 `None` | + +**关键数据**:合并键列 `_KEY_COLS = ("episode_index", "frame_index", "timestamp")`(旧格式单表缺 `episode_index` 时填 0);信号掩码语义 = 任一观测列该行 `|值|.sum > 0`;时间戳不保证严格单调(录制暂停点存在负跳变,查询用帧号)。 + +**调用关系**:被 `ui/playback_dialog.py`(`load_timeline`/`SensorTimeline`)、`tools/tests/test_playback_multifps.py` 引用。 + +### core/session_catalog.py + +**作用**:录制会话目录——扫描、元数据读取与主时钟帧率解析(零 Qt 依赖, +纯函数)。供回放对话框、录制历史刷新与上传对话框共用。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `get_effective_fps` | `(info)` | 回放主时钟帧率:每路相机 fps 最大值;旧数据无 per-camera fps 时按双目命名回退 `settings.STEREO_FPS` | `float` | +| `list_sessions` | `(directory)` | 扫描全部会话(含元数据/时长/fps) | `[{name, path, tag, info, duration, fps}]` | +| `list_recordings` | `(base_dir)` | 轻量扫描全部完整 session(上传对话框口径) | `[{name, path, tag}]` | +| `load_session_meta` | `(session_dir)` | 同步读单会话元数据(格式探测 / info / fps / 传感器列名) | `{"fmt", "info", "fps", "sensor_names"}` | + +**调用关系**:被 `ui/playback_dialog.py`、`ui/upload_dialog.py`(`list_recordings`)使用;调用了 `core/helpers.py`。 + +### core/session_loader.py + +**作用**:回放后台加载器——把时间线与手部关键点加载放进后台线程,经 +`finished(int, object)` / `failed(int, str)` 信号回主线程(payload 为 +`{"timeline": SensorTimeline, "hand_kpts": dict}`,按引用传递);`gen` 防过期 +协议由调用方(`ui/playback_dialog.py`)维护——收到 gen 不一致的迟到结果即 +丢弃。加载期间新请求排队(最新覆盖旧的,过期结果本就会被 gen 丢弃)。 +VideoCapture 不在 worker 中创建/读取(OpenCV FFmpeg 后端不承诺跨线程安全), +视频打开与播放留在调用方主线程。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `SessionLoader` | `(parent=None)` | 后台加载器 | 信号 `finished(int, object)`(gen, payload)、`failed(int, str)`(gen, error) | +| `SessionLoader.start` | `(gen, session_dir, sensor_names, load_kpts=False, load_timeline=True)` | 后台线程加载;已有加载在跑时把请求排队(新覆盖旧) | 无 | +| `SessionLoader.is_running` | `()` | 是否有加载在跑 | `bool` | + +**调用关系**:被 `ui/playback_dialog.py`(`.finished` 接线 + `.start(...)` 调用)使用;调用了 `core/session_timeline.py`(`load_timeline`)与 `core/hand_tracking.py`(`load_hand_kpts`,惰性导入,缺失时降级为不加载关键点)。 + +## 手部关键点 + +### core/hand_tracking.py + +**作用**:手部关键点后处理独立模块,零 Qt 依赖纯函数式 API。两种追踪模式: +`"glove"`(YOLO 检测黑色手套 + RTMPose 关键点,仅 2D)与 `"bare"`(MediaPipe +裸手追踪,2D + 3D world_landmarks,供下游 3D 可视化与数据集导出使用)。 +支持对已录制会话逐帧提取关键点写 parquet、手势自动标注 +(`auto_labels.parquet` + `auto_actions.jsonl`)、以及关键点/标注的读取 +(三层路径回退:`keypoints_output/` → `session/keypoints/` → +`session/annotations/`)。重型依赖(ultralytics/torch/rtmlib 与 +`hand_pipeline`、`hand_pipeline_mediapipe`、`hand_common`)全部延迟导入。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `process_session` | `(session_path, mode="", detector="", det_device="cuda", pose_device="cuda", progress_cb, status_cb, cancel_check)` | 逐帧提取手部关键点写 parquet;bare 模式额外写 3D parquet;glove 模式无 CUDA 时设备自动降级 cpu | `{"success", "frames", "elapsed", "fps", "mode", "session_path"}` 或 `{"success": False, "error"}` | +| `label_session` | `(session_path, progress_cb, cancel_check)` | 基于手部关键点 + 传感器数据逐帧手势标注,写 `auto_labels.parquet` 与 `auto_actions.jsonl` | `{"success", "frames", "elapsed"}` 或错误 | +| `load_hand_kpts` | `(session_path)` | 读 2D 关键点 | `{frame_index: {hand_data, num_hands, track_ids}}` 或 `None` | +| `load_hand_3d` | `(session_path)` | 读 3D landmarks | `{frame_index: row}` 或 `None` | +| `load_auto_labels` | `(session_path)` | 读自动标注 | `{frame_index: row}` 或 `None` | +| `draw_kpts_overlay` | `(frame, data, track_ids=None)` | BGR 帧上叠加关键点 + 手 #id + 手势文本 | 叠加后帧 | +| `classify_gesture` | `(extended, thumb_tip_pt, index_tip_pt)` | 按伸直手指数 + 拇指-食指距离分类 | `{"gesture", "pinch", "fist", "extended_count"}` | +| `_pack_hand_data` / `_unpack_hand_data` / `_pack_hand_3d_data`(内部) | 见下 | 固定长度打包/解包 | `np.ndarray` / tuple | +| `_compute_contact`(内部) | `(motion_0, motion_1, sensors)` | 由手部运动 + 传感器峰值推接触状态 | `"grasping/holding/reaching/resting/none"` | +| `_segment_actions`(内部) | `(rows)` | 帧级手势 → 动作片段(<10 帧合并入前段) | `[{start_frame, end_frame, label, dominant_hand, confidence}]` | + +**关键数据**:常量 `PER_HAND_DIM = 21*2 + 4 = 46`(21 点×2 坐标 + 4 框坐标)、`MAX_HANDS = 2`、`TOTAL_DIM = 92`、`PER_HAND_3D_DIM = 21*3 = 63`。Parquet schema(真实定义): +- `_HAND_KPTS_SCHEMA`:`frame_index(int32)`、`num_hands(int32)`、`hand_data(list)`、`track_ids(list)`。 +- `_HAND_3D_SCHEMA`:`frame_index(int32)`、`hand_0_present(bool)`、`hand_0_landmarks_3d(list)`、`hand_0_label(string)`、`hand_1_*` 同构。 +- `_AUTO_LABELS_SCHEMA`:`frame_index(int32)`、每手 `hand_N_gesture(string)/hand_N_extended(list)/hand_N_extended_count(int32)/hand_N_fist(bool)/hand_N_pinch(bool)/hand_N_center_x(float32)/hand_N_center_y(float32)/hand_N_motion(float32)`、`two_hand_distance(float32)`、`contact(string)`。 +- 手势分类阈值:`PINCH_THRESH = 30.0`(像素)、`TWO_HAND_TOUCH_THRESH = 80.0`;`MIN_SEGMENT_FRAMES = 10`。 +- MediaPipe 模型缓存 `~/.cache/hand_landmarker.task`(从 `settings.HAND_MEDIAPIPE_MODEL` 复制,大小不一致时更新)。 + +**调用关系**:被 `ui/playback_dialog.py`、`scripts/process_hands.py`、`tools/demos/demo_glove_kpts/demo_glove_video.py`、`core/hand_processor.py`、`core/auto_labeler.py` 引用。 + +### core/hand_processor.py + +**作用**:`SessionHandProcessor`——对已录制会话逐帧跑手部关键点推理的 Qt 薄 +封装,核心逻辑全在 `core.hand_tracking.process_session`。后台线程执行,经 +Qt 信号回主线程。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `SessionHandProcessor` | `(parent=None)` | 后台处理器 | 信号 `progress(int, int)`、`finished(str, str)`(session_path, error_msg,空=成功)、`status_changed(str)` | +| `SessionHandProcessor.process_session` | `(session_path, detector="", det_device="cuda", pose_device="cuda", mode="")` | 启动后台处理(运行中再调被忽略) | 无 | +| `SessionHandProcessor.cancel` | 无参 | 取消当前任务 | 无 | + +**调用关系**:被 `ui/main_window.py`、`ui/playback_dialog.py` 引用;调用了 `core/hand_tracking.py`。 + +### core/auto_labeler.py + +**作用**:`AutoLabeler`——基于手部关键点数据的自动标注器, +`core.hand_tracking.label_session` 的 Qt 薄封装。后台线程执行,信号回主线程。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `AutoLabeler` | `(parent=None)` | 后台标注器 | 信号 `progress(int, int)`(已处理帧, 总帧数)、`finished(str, str)`(session_path, error_msg) | +| `AutoLabeler.label_session` | `(session_path)` | 启动后台标注(运行中再调被忽略) | 无 | +| `AutoLabeler.cancel` | 无参 | 取消(`_cancelled` 检查 `_running`) | 无 | + +**调用关系**:被 `ui/main_window.py` 引用;调用了 `core/hand_tracking.py`。 + +## 手套传感(原 tools/sensors/) + +### core/ble_engine.py + +**作用**:BLE 传感器数据采集引擎。作为 `QObject` 运行,在独立线程中处理 +BLE 异步通信(基于 `bleak`),通过 Qt 信号把连接状态、FPS、校准进度与错误 +发送到 UI 线程。数据链路:`BleakClient` 订阅 TX 特征通知 → 原始字节缓冲 → +`_parse_loop` 按帧头/帧尾/校验和解析成 16×16 压力矩阵 → `process_frame()` +做校准、时域平滑、去基线、漂移补偿、动态噪声门与空间滤波,返回处理后的 +矩阵供 UI 渲染(UI 侧是轮询式取帧,而非信号推帧)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `SensorBLEEngine` | `__init__(self)` | 初始化 16×16 数据数组、降噪参数(`base_noise_gate=500` 等)、校准状态与线程锁 | 无 | +| `start_scan` | `start_scan(self)` | 启动 daemon 线程执行 5 秒 BLE 扫描(`BleakScanner.discover`),按名称含 `"Matrix"`、非空名称、RSSI 排序 | 完成后发 `scan_complete`;失败发 `error_occurred` | +| `connect_device` | `connect_device(self, address: str)` | 记录目标地址,启动 `_ble_loop`(连接 + 订阅通知 + 断线重连)与 `_parse_loop`(帧解析)两个 daemon 线程 | 连接成功发 `connected`;失败发 `error_occurred` 与 `disconnected` | +| `disconnect` | `disconnect(self)` | 置 `_running=False`,结束通信与解析循环 | 循环退出时发 `disconnected` | +| `start_calibration` | `start_calibration(self)` | 清空校准缓冲并进入校准态 | 校准期间 `process_frame` 返回 `(None, 0)` 并逐帧发 `calibration_progress` | +| `set_noise_gate` | `set_noise_gate(self, value: int)` | 设置基础噪声门 | 无返回 | +| `set_dynamic_ratio` | `set_dynamic_ratio(self, value: float)` | 设置动态噪声门比例 | 无返回 | +| `set_spatial_filter` | `set_spatial_filter(self, enabled: bool)` | 开关空间滤波 | 无返回 | +| `set_temporal_smooth` | `set_temporal_smooth(self, value: float)` | 设置时域平滑系数 | 无返回 | +| `process_frame` | `process_frame(self) -> tuple` | 一帧完整处理:校准 → 时域平滑 → 去基线 → 漂移补偿 → 动态噪声门 → 空间滤波 | 返回 `(processed_data, max_signal)`;校准期间返回 `(None, 0)` | +| 信号 | `device_found(str, str, int)` / `scan_complete(list)` / `connected(str)` / `disconnected()` / `data_ready(ndarray)` / `fps_updated(float)` / `error_occurred(str)` / `calibration_progress(int)` | Qt 信号定义,UI 侧连接使用 | `device_found` 与 `data_ready` 在本文件内定义但未 emit;UI 实际通过轮询 `process_frame()` 取帧 | + +**关键数据**: + +- 传感器矩阵:`MATRIX_ROWS = 16`、`MATRIX_COLS = 16`,数据以 `np.uint16` 解析后转 `float32`。 +- 帧协议:帧头 `b"\xAA\x55"` + 512 字节数据 + 1 字节 XOR 校验和 + 帧尾 `b"\xFB\x03"`;校验和不通过则整帧丢弃。512 字节 = 256 个 uint16 → reshape 为 16×16。 +- BLE 特征:`TX_CHAR_UUID = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"`(Nordic UART 服务 TX 特征),通知回调只做字节缓冲。 +- 校准:`CALIBRATION_FRAMES = 100`,`baseline_map` = 校准帧逐格最大值 + 10;`TARGET_FPS = 100` 为常量定义。 +- 降噪默认参数:`base_noise_gate=500`、`dynamic_noise_ratio=0.0`、`temporal_smooth=0.15`、`spatial_filter_enabled=True`。 +- 漂移补偿:`processed` 的 40 分位数 > 100 时,减去其 0.8 倍(`drift_baseline_val` 同时供 UI 显示)。 +- 动态噪声门:`min(current_max * dynamic_noise_ratio, 250)`,与基础门取较大者;低于门限的格点清零。 +- 空间滤波:孤立点判据——邻域(3×3 无中心核)全空且值低于 `max(baseline_map * 2.5, 180)` 的格点清零。 +- 时间戳:`latest_data_ts_us`(微秒)由解析线程写入、UI 线程读取,用于数据年龄判断。 + +**调用关系**:被 `ui/glove_widget.py` 导入并实例化(连接信号后调用 `connect_device` / `disconnect`,每帧轮询 `process_frame()` 与公开属性如 `is_calibrating`、`latest_data_ts_us`、`hardware_fps`);被 `tools/tests/glove_widget_test.py` mock 替换。依赖 `bleak`、`PyQt5`、`numpy`(空间滤波分支依赖 `cv2`)。 + +### core/render_engine.py + +**作用**:传感器数据渲染引擎,实现五种可视化模式:热力图(`render_heatmap`)、 +轨迹(`render_trace`)、网格数值(`render_grid`)、仿生手掌(`render_hand`)、 +拓扑形变(`render_deform_mesh`)。所有渲染函数接收处理后的 16×16 数据与 +配置,返回 BGR 格式的 numpy 帧,由 UI 层转为 `QPixmap` 显示。本文件同时 +集中定义仿生手掌映射配置路径常量(左右手各一套 JSON,位于 `config/sensors/`), +供 `ui/glove_widget.py` 与 `ui/playback_dialog.py` 复用——代码注释说明这些 +常量原先定义在 `sensors.sensor_panel`(已删除),迁到 core 是为了让 UI 取 +路径时不必引入 `bleak`。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `CONFIG_DIR` / `CONFIG_FILE` / `CONFIG_FILE_LEFT` | 模块常量 | 指向 `config/sensors/hand_ble_config.json` 与 `hand_ble_config_left.json`(基于 `settings.BASE_DIR`) | — | +| `_get_viridis_lut` | `_get_viridis_lut() -> np.ndarray` | 延迟初始化 256 级 Viridis 颜色查找表(`VIRIDIS_LUT`,首次调用构建) | 返回 `(256, 1, 3)` uint8 LUT | +| `_draw_hud` | `_draw_hud(frame, lines, color=(255,255,255))` | 帧左上角绘制半透明 HUD 信息栏 | 原地修改 `frame` | +| `_load_json` | `_load_json(path, default)` | 读取 JSON;`default` 为 dict 时浅合并(默认值兜底),异常静默回退 | 返回配置 dict | +| `render_heatmap` | `(processed, max_signal, config, window_size, current_vmax, fps, noise_gate, dyn_ratio, spatial_on)` | 模式 1:子矩阵提取 → subpixel 2× 超分 → 缩放/高斯模糊 → Viridis 伪彩 | 返回 `(frame, new_vmax)` | +| `render_trace` | `(processed, max_signal, config, window_size, current_vmax, fps, noise_gate, dyn_ratio, spatial_on)` | 模式 2:历史数据叠加显示(`_trace_canvas` 取逐格最大值),支持 `clear_trace_canvas` 清空 | 返回 `(frame, new_vmax, changed)` | +| `clear_trace_canvas` | `clear_trace_canvas()` | 清空轨迹画布 | 全局 `_trace_canvas` 置 `None` | +| `render_grid` | `(processed, max_signal, config, window_size, fps)` | 模式 3:每格显示数值,蓝色强度映射幅值 | 返回 `frame` | +| `render_hand` | `(processed, max_signal, config, window_size, current_vmax, fps, noise_gate, dyn_ratio, spatial_on, drift)` | 模式 4:仿生手掌映射——骨骼框架 + 各手指区域传感器格点上色 | 返回 `(frame, new_vmax)` | +| `DeformMeshState` | `__init__(self)` | 模式 5 交互状态:`holes` / `flip_x` / `flip_y` / `deform_strength` / 网格缓存 / 拖拽绘制状态 | 无 | +| `render_deform_mesh` | `(processed, max_signal, config, window_size, current_vmax, fps, state: DeformMeshState)` | 模式 5:网格 + 孔洞形变 + 数据点圆 | 返回 `(frame, new_vmax)` | + +**关键数据**: + +- `HAND_ANCHORS`:16 个手部锚点坐标(`thumb/index/middle/ring/pinky` 各自的 `tip/joint/base` + `palm`),基于 1280×720 画布设计,运行时按实际 `window_size` 等比缩放;`WRIST_ANCHOR = (640, 600)`。 +- `DEFAULT_HAND`:默认 16×16 传感器到手部区域的映射,如 `thumb_joint: rows [0,1,2] cols [14,12,13,15]`、`palm: rows 0-14 cols [10,9,8,6,4]`,各手指关节区域共享 `axis_order: "col_row"`。 +- 配置 JSON 字段(`config/sensors/hand_ble_config.json` 与 `hand_ble_config_left.json`):16 个部位键(`thumb_tip` … `palm`),每项含 `name`(中文部位名,如 "大拇指-指肚")、`rows`、`cols`、`axis_order`(`"row_col"` 或 `"col_row"`)。左右两文件键同值异(左手套关节锚点不同)。 +- 热力图/轨迹增强参数:`subpixel`(默认 True,梯度 2× 超分)、`gamma`(默认 1.0)、`blur`(默认 5,奇数化)。 +- vmax 自适应(热力图/轨迹模式):候选值 `max(5000, p99.7)`,上浮时按 `current_vmax*0.95 + vmax_cand*0.05` 平滑;仿生手掌/形变模式改用 `max(max_signal, 5000)`。 +- 形变网格:`CELL = 26`(形变模式)/ `CELL = int(14 * min(sx, sy))`(仿生手掌模式)。 + +**调用关系**:被 `ui/glove_widget.py`(`render_hand`、`DEFAULT_HAND`、`_load_json`、`CONFIG_FILE`、`CONFIG_FILE_LEFT`)与 `ui/playback_dialog.py`(五种模式、`DeformMeshState`、`clear_trace_canvas`)调用。依赖 `config.settings`(`BASE_DIR`)、`numpy`、`cv2`。 + +### core/sensor_config_dialogs.py + +**作用**:PyQt5 配置对话框。`MatrixConfigDialog` 是通用 16×16 矩阵行列选择 +界面(按钮点击选行/列,可撤销/清空,可选映射方向);`HandConfigDialog` 是 +仿生手掌模式配置界面,为每个手部部位(指尖/关节/指根/手掌)列出当前 +rows/cols 映射,点击"选择"弹出子级 `MatrixConfigDialog` 逐部位编辑。两者 +操作的数据结构与 `render_engine.py` 的配置 JSON 字段一致(`rows` / `cols` / +`axis_order`)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `MatrixConfigDialog` | `__init__(self, parent, title: str, config: dict)` | 构建行列选择对话框(16 个行按钮 + 16 个列按钮 + 映射方向单选) | 修改内部 `_rows/_cols/_order` | +| `_add_row` / `_undo_row` / `_clear_row` | `_add_row(self, val)` 等 | 行选择序列的追加/撤销/清空 | 更新标签显示 | +| `_add_col` / `_undo_col` / `_clear_col` | `_add_col(self, val)` 等 | 列选择序列的追加/撤销/清空 | 更新标签显示 | +| `get_config` | `get_config(self) -> dict` | 输出当前选择 | 返回 `{"rows", "cols", "axis_order"}` | +| `HandConfigDialog` | `__init__(self, parent, config: dict)` | 深拷贝配置并构建逐部位配置列表 | 无 | +| `_format_cfg` | `_format_cfg(self, item)` | 把部位配置格式化为单行摘要文本 | 返回字符串 | +| `_open_sub_config` | `_open_sub_config(self, key)` | 弹出 `MatrixConfigDialog` 编辑某部位 | 确认后写回 `item["rows"/"cols"/"axis_order"]` 并刷新标签 | +| `get_config` | `get_config(self) -> dict` | 输出全部部位配置 | 返回完整配置 dict | + +**关键数据**:配置结构为 `{部位键: {"rows": [...], "cols": [...], "axis_order": "row_col"|"col_row", 可选 "name"}}`;`MatrixConfigDialog` 固定显示 16 行(00-15)与 16 列(00-15)按钮。 + +**调用关系**:`HandConfigDialog` 内部调用 `MatrixConfigDialog`(子对话框),与 `render_engine.py` 的配置口径保持一致。 + +### core/sensor_hand_config.py + +**作用**:传感器(BLE 手套)仿生手掌配置与有效性过滤(零 Qt 依赖,纯函数)。 +供 `ui/glove_widget.py` 与 `ui/playback_dialog.py` 共用同一套口径。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `load_sensor_hand_config` | `(sensor_name)` | 按传感器角色加载仿生手掌映射(左/右手套不同配置文件,`DEFAULT_HAND` 之外部位并入) | `dict` | +| `valid_sensor_names` | `(timeline, names)` | 只保留时间线中确实存在 16×16 压力矩阵(256 宽)的传感器列(防幽灵传感器格) | `list` | + +**调用关系**:被 `ui/glove_widget.py`(hand_config 加载)、`ui/playback_dialog.py` 使用;调用了 `core/render_engine.py`。 + +## 通用工具 + +### core/helpers.py + +**作用**:通用工具函数集合(原 utils/helpers.py),按主题分五块:①基础工具 +(ID/时间/回收站/格式化);②会话摘要(供录制历史面板"摄像机/时长/大小" +三列使用);③命名与 LeRobot v3 分块路径;④关键点数据路径 +(`keypoints_output/` 镜像结构 + 两级回退路径);⑤EgoData 格式路径、会话 +枚举与格式检测。无类,全部为模块级函数。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `new_id` | `() -> str` | 生成短 ID | 12 位十六进制(`uuid4().hex[:12]`) | +| `utcnow` | `() -> str` | UTC 时间戳 | ISO-8601 字符串 `YYYY-MM-DDTHH:MM:SSZ` | +| `send_to_recycle_bin` | `(path: str) -> bool` | 将文件/文件夹移入回收站 | Windows 走 `SHFileOperationW`(FOF_ALLOWUNDO);Linux 优先 `gio trash`,无 gio 时手动移入 `~/.local/share/Trash`(写 `.trashinfo` 记录原路径);成功 `True` | +| `format_duration` | `(seconds: float) -> str` | 秒数格式化 | `HH:MM:SS` 字符串 | +| `session_size_mb` | `(session_dir: str) -> float` | 累加会话目录全部文件大小 | MB;目录不存在/出错返回 0.0 | +| `read_metadata` | `(session_dir: str) -> dict` | 读会话 `metadata.json` | 任何失败返回 `{}` | +| `session_summary` | `(session_dir: str, frames_by_cam: dict) -> tuple` | 会话展示摘要(录制历史面板三列数据源) | 返回 `(camera_list, duration_sec, size_mb)`;时长=各相机 帧数/fps 的最大值,帧数全缺时降级 `timestamps.json` 最后一条相对时间,再降级 `total_frames / 最小 fps` | +| `format_size_mb` | `(mb: float) -> str` | 大小列文本 | `"12.3 MB"`;0/缺失显示 `"-"` | +| `timestamp_filename` | `(prefix: str = "rec", ext: str = ".avi") -> str` | 带时间戳文件名 | 如 `rec_20260804_143052.avi` | +| `task_tag` | `(task_name: str = "") -> str` | 任务分类标签(子文件夹名) | 清洗后标签,如 `"grasp_cup"`;空输入返回 `"session"` | +| `session_dirname` | `(task_name: str = "", batch_index: int = 0) -> str` | 会话目录名 | 如 `grasp_cup_20260805_195046`;`batch_index>0` 时插入 4 位批次号 | +| `chunk_dir` / `chunk_file` | `(chunk_index: int = 0) -> str` / `(chunk_index: int = 0, name: str = "file") -> str` | LeRobot v3 分块目录/文件名 | `"chunk-000"` / `"file-000"` | +| `data_parquet_path` | `(session_dir, chunk_index=0) -> str` | 数据 parquet 路径 | `data/chunk-000/file-000.parquet` | +| `episode_parquet_path` | `(session_dir, chunk_index=0) -> str` | episode 元数据路径 | `meta/episodes/chunk-000/file-000.parquet` | +| `video_mp4_path` | `(session_dir, camera_key, chunk_index=0) -> str` | 视频路径 | `videos//chunk-000.mp4` | +| `tasks_jsonl_path` | `(session_dir) -> str` | 任务记录路径 | `meta/tasks.jsonl` | +| `keypoints_video_dir` | `(session_dir) -> str` | 关键点视频目录 | `keypoints_output/<项目>/<会话>/videos/` | +| `hand_kpts_parquet_path` | `(session_dir) -> str` | 手部 2D 关键点路径 | `keypoints_output/…/hand_pose/chunk-000.parquet` | +| `auto_labels_parquet_path` | `(session_dir) -> str` | 自动标注路径 | `keypoints_output/…/auto_labels/auto_labels.parquet` | +| `hand_3d_parquet_path` | `(session_dir) -> str` | 手部 3D 关键点路径 | `keypoints_output/…/hand_pose_3d/chunk-000.parquet` | +| `list_all_sessions` | `(base_dir: str) -> list` | 扫描全部会话目录(兼容 EgoData 与 LeRobot v3) | `[(ses_path, ses_name, tag_name), …]`,按名称倒序 | +| `episode_dirname` | `(episode_index: int = 1, task_name: str = "", digits: int = 6) -> str` | EgoData episode 目录名 | 有任务名 `Chew_gum_000001`,否则 `episode_000001` | +| `next_episode_index` | `(base_dir, task_name="", batch_index=0) -> int` | 下一个 episode 索引 | `max(batch_index, 目录扫描最大值+1)`;`batch_index<=0` 时纯目录扫描 | +| `egodata_video_path` / `egodata_video_dir` | `(episode_dir, camera_name) -> str` | 视频文件 / 目录路径 | `videos//chunk-0000/.mp4`;`_aux` 后缀摄像头归入主摄像头目录 | +| `egodata_depth_path` | `(episode_dir, depth_name, frame_index) -> str` | 深度帧路径 | `depth/head_depth/000001.png`(6 位序号,png16) | +| `egodata_image_path` | `(episode_dir, camera_name, frame_index) -> str` | 图像帧路径 | `images/head_left_rgb/000001.jpg` | +| `egodata_calibration_path` | `(episode_dir, calib_name: str = "head_stereo") -> str` | 标定文件路径 | `calibration/head_stereo.json` | +| `egodata_metadata_path` | `(episode_dir) -> str` | 元数据路径 | `episode_dir/metadata.json` | +| `egodata_timestamps_path` | `(episode_dir) -> str` | 时间戳路径 | `episode_dir/timestamps.json` | +| `egodata_sensor_data_dir` / `egodata_sensor_parquet_path` | `(episode_dir, sensor_name) -> str` | 传感器数据目录 / parquet | `data//chunk-0000/` 与 `…/chunk_000000.parquet` | +| `detect_session_format` | `(session_dir: str) -> str` | 会话格式检测 | `"egodata"`(有 `metadata.json`)/ `"lerobot_v3"`(有 `meta/info.json`)/ `"unknown"` | +| `list_all_egodata_sessions` | `(base_dir: str) -> list` | 扫描全部 EgoData episode | `[(ep_path, ep_name, tag_name), …]`,按名称倒序 | +| 内部函数 | `_slot_base` / `_sub_name` / `_device_display_names` / `_timestamps_duration` / `_sanitize_tag` / `_keypoints_session_dir` | 流名→设备基名、槽名→子画面名、录制历史"摄像机"列文本、降级补算时长、标签清洗、session→镜像目录映射 | 供公开函数内部使用(见下方"会话摘要"说明) | +| 内部函数 | `_session_kpts_hand_kpts_path` / `_session_kpts_hand_3d_path` / `_session_kpts_auto_labels_path` / `_legacy_hand_kpts_path` / `_legacy_hand_3d_path` / `_legacy_auto_labels_path` | 回退路径 1:会话内 `keypoints/`;回退路径 2:最旧版 `annotations/` | 历史数据兼容定位 | + +**关键数据**(路径/命名约定,均为代码中真实存在的硬编码结构): + +- 会话识别标志:EgoData 会话 = 目录内含 `metadata.json`;LeRobot v3 会话 = 目录内含 `meta/info.json`。 +- 关键点输出镜像:`data/recordings/<项目>/<会话>` → `keypoints_output/<项目>/<会话>`(`_keypoints_session_dir` 基于 `settings.RECORDING_DIR` 与 `settings.KEYPOINTS_OUTPUT_DIR` 映射)。 +- 关键点回退查找顺序:`keypoints_output/` 镜像 → 会话内 `keypoints/` → 会话内 `annotations/`(最旧版,自动标注为 `annotations/mmpose/auto_labels.parquet`)。 +- 会话摘要约定(`session_summary`):每相机 fps 优先取 `cameras[cam].fps`,缺省 `metadata["fps"]`,再缺省 `settings.RECORDING_FPS`;`camera_list` 由 `_device_display_names` 按设备聚合——D435 一台设备出 rgb+depth 两路子画面显示为 `"D435_depth (rgb, depth)"`,双目 S80M 显示为 `"FaysSense S80M (left, right)"`,单流设备只显示设备名;`devices` 段缺失(legacy 会话)时按 `_slot_base` 对 `cameras` 键分组。 +- 命名清洗规则(`_sanitize_tag`):保留字母、数字、下划线与中文(Unicode `一-鿿`),其余字符替换为 `_`。 +- episode 索引兼容:新命名 `_NNNNNN` 与旧命名 `episode_NNNNNN`(位数取 `settings.EPISODE_DIGITS`)。 + +**调用关系**:被 `core/`(`recording_record.py`、`egodata_writer.py`、`hand_tracking.py`、`session_timeline.py`、`session_catalog.py`)、`ui/`(`main_window.py`、`camera_widget.py`、`playback_dialog.py`、`upload_dialog.py`)、`scripts/process_hands.py`、`tools/tests/` 各 import 点引用;其中 `session_summary` 供录制历史面板生成"摄像机"列摘要,`send_to_recycle_bin` 供回放对话框删除会话。自身 `from config import settings`。 + +### core/stereo_depth.py + +**作用**:双目深度计算模块。`StereoDepthComputer` 基于手写 OpenCV +`StereoSGBM`(未用 SDK 深度引擎)+ `DisparityWLSFilter`(opencv-contrib), +从左右目 BGR 帧算视差图,输出 uint16(像素值 = 视差 × 16,OpenCV 标准亚 +像素格式),单位可经标定参数(baseline × fx / disparity)换算为毫米。 +`depth_to_heatmap` 与 `DepthHeatmapSmoother` 是深度可视化的共享工具(实时 +显示与 `core/egodata_writer.py` 落盘热力图共用)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `depth_to_heatmap` | `(depth_uint16, near_mm=0.0, far_mm=0.0, colormap=cv2.COLORMAP_JET, smooth_k=0)` | uint16 毫米深度 → BGR 热力图;near/far 同给为真固定色标(整幅 clip 0..255,demo 口径:无效值/近端→JET(0) 深蓝、超远→红饱和,不置黑),否则帧内自适应(min/max→1..255,无效→JET(0) 深蓝);`smooth_k>0` 先 k×k 中值滤波 | `np.ndarray (H, W, 3) uint8` | +| `DepthHeatmapSmoother` | `(alpha=0.5)` | 热力图时域 EMA(仅可视化通道,原始 PNG16 不受影响) | `update(bgr)` 返回平滑帧;`reset()` | +| `StereoDepthComputer` | `(resolution=(800, 640), num_disparities=128, block_size=11)` | S80M 双目调优的 SGBM 计算器;`num_disparities` 强制 16 倍数、`block_size` 强制奇数 | 无 | +| `StereoDepthComputer.compute` | `(left, right)`(BGR (H,W,3)) | 灰度化 + 直方图均衡 → 左/右视差 → WLS 滤波 → ×16 转 uint16 | `np.ndarray (H, W) uint16` | +| `StereoDepthComputer.num_disparities` / `block_size` | property | 参数查询 | `int` | + +**关键数据**:SGBM 参数(代码硬编码):`minDisparity=0`、`P1=8*3*block²`、`P2=32*3*block²`、`disp12MaxDiff=1`、`preFilterCap=63`、`uniquenessRatio=10`、`speckleWindowSize=100`、`speckleRange=32`、`mode=STEREO_SGBM_MODE_SGBM_3WAY`;WLS `lambda=8000.0`、`sigmaColor=1.5`。输出视差缩放:value=256 → 视差 16 像素。 + +**调用关系**:被 `ui/main_window.py`(`_on_s80m_depth` 用 `depth_to_heatmap` 渲染 S80C 深度格)、`core/d435_manager.py:24` 与 `core/egodata_writer.py:41`(`depth_to_heatmap`/`DepthHeatmapSmoother` 热力图生成/落盘)、`tools/tests/test_depth_heatmap.py:20` 引用。`StereoDepthComputer`(旧 S80M 视差路径)自 v1.0.11 起无调用方,仅为 demo 保留。 + +## 数据流 + +**采集链路**:`ui/main_window.py` 经 `core/device_detector.py`(复用 +`core/camera.py` 的 sysfs 枚举)获得统一设备列表;面板开关经 +`core/device_manager.dispatch_toggle` 分派到 `_open_*`。UVC 走 +`core/camera.py` 的 `CameraWorker`;S80M 走 `core/s80m_manager.py` 的子进程 +管道(帧 → `frame_ready` 信号 → `_on_stereo_frame` 抽帧口径);D435 走 +`core/d435_manager.py` + `core/d435_camera.py`。所有帧汇入 +`core/pipeline.py` 的 `CameraPipeline` → 独立写入线程按 30fps 节拍调 +`core/egodata_writer.py` 落盘(MP4 + Parquet + 深度热力图/PNG16 + 元数据)。 +手套数据经 `core/ble_engine.py` 采集 → `pipeline.write_sensor` 入队。 + +**持久化链路**:会话结束后 `ui/main_window.py` 经 +`core/recording_repository.py`(→ `core/database.py` 单例 `db`)把录制摘要写 +进 `data/pipeline.db` 的 `recording` 表,上传任务另记 `upload_task` 表 +(`core/uploader.py` 全程状态持久化);任务进度独立走 +`core/task_record.py` 的 `data/tasks.json`(录制完成 → +`increment_task_completed` 本机 `local_count` +1 → 显示值重算,与本地会话 +文件是否被删无关),随后 `TaskService._flush_progress` 把本机未上报增量 +以水位合并方式 POST `/api/v1/device/tasks/progress`(幂等键 +`{device}:{task_id}:{水位}`,断网/失败由下个轮询 tick 兜底重试)。 + +**上传链路**:`ui/upload_dialog.py` 经 `core/uploader.py` +(`UploadManager`:ffmpeg 预压缩 → zip 打包 → `core/api_client.py` 上传 → +SQLite 状态)→ `POST /api/v1/session/upload`;`meta/info.json` 的结构即上传 +服务器所依赖的契约。 + +**回放链路**:`ui/playback_dialog.py` 经 `core/session_catalog.py` 扫描/读 +元数据,经 `core/session_loader.py` 后台加载(`core/session_timeline.py` +向量化合并 + `core/hand_tracking.py` 关键点),主线程只做 widget 操作。 + +**后处理链路**:已录制会话的手部关键点由 `core/hand_tracking.py` +(`scripts/process_hands.py` 或 UI 经 `core/hand_processor.py`/ +`core/auto_labeler.py`)提取为 2D/3D parquet,供下游 3D 可视化与数据集导出 +使用。 diff --git a/collector/docs/data.md b/collector/docs/data.md new file mode 100644 index 0000000000000000000000000000000000000000..c6973aa774096f047789365eade163eb3686454d --- /dev/null +++ b/collector/docs/data.md @@ -0,0 +1,326 @@ +# data/ —— 配置文件与数据存储结构 + +本文档描述 `data/` 目录下的配置文件格式、SQLite 表结构与录制数据的目录布局。 +所有结构均从代码(`config/settings.py`、`core/task_record.py`、 +`core/egodata_writer.py`、`core/database.py`、`core/recording_record.py`、 +`core/helpers.py`)与仓库内模板文件归纳得出。 + +## 1. 总览:仓库提供什么,本地生成什么 + +| 文件/目录 | 归属 | 说明 | +|---|---|---| +| `server_config.example.json` | 仓库模板 | 服务器连接配置模板;本地真实配置写在 `server_config.json`(gitignore) | +| `device_names.example.json` | 仓库模板 | 设备命名表模板(空 `{}`);本地真实配置写在 `device_names.json`(gitignore) | +| `tasks.example.json` | 仓库模板 | 任务列表模板(`{"tasks": []}`);本地真实数据写在 `tasks.json`(gitignore) | +| `device_params.json` | 仓库内默认文件 | 每设备相机参数(曝光),出厂为空对象 `{}`;key 用设备稳定标识,增长后可能含设备标识,勿提交本地改动 | +| `recordings/` | 本地生成(gitignore) | 录制会话输出根目录 | +| `app.db`、`pipeline.db` | 本地生成(gitignore) | SQLite 数据库;当前代码使用 `pipeline.db`(`settings.DB_PATH`),`app.db` 未被现有代码引用,属历史遗留 | + +本地真实文件可能包含服务器地址、凭据、MAC 等敏感信息,**永不提交**; +新环境首次运行由程序按需创建,结构见下文。 + +## 2. 配置文件 + +### 2.1 `server_config.json`(模板 `server_config.example.json`) + +服务器连接与上传行为配置。字段由 `config/settings.py` 中的读写函数定义: + +| 键 | 类型 | 含义 | 默认/回退 | +|---|---|---|---| +| `server_url` | string | 服务器地址;为空时回退出厂默认 `http://127.0.0.1:8000`(`settings.SERVER_URL`) | 空 | +| `username` | string | 上传登录用户名 | 空 | +| `password` | string | 上传登录密码 | 空 | +| `upload_auto_sync` | bool | 录制完成后是否自动上传 | `true` | +| `upload_delete_after` | bool | 上传成功后是否自动删除本地文件 | `false` | + +写入采用合并式(merge-write):`_save_server_config` 只更新传入键,保留其余字段。 + +### 2.2 `device_names.json`(模板 `device_names.example.json`) + +设备命名表。顶层为 JSON 对象: + +```json +{ + "": { "name": "<用户命名>", "sensor": "" } +} +``` + +- **key**:设备稳定标识 `DeviceInfo.stable_key`,形式如 `uvc:{by-id 前缀}`、 + `d435:{serial}`、`ble:{MAC}` 等(含设备序列号/MAC,属本地敏感信息,不入库)。 +- **value**:规范形式为 `{"name": str, "sensor"?: str}`;旧版本可能是纯字符串, + 读取时自动兼容升级。 + - `name`:用户在界面中给设备的命名(槽名随 GUI 用户命名)。 + - `sensor`:仅 BLE 数据手套使用,把设备绑定到 parquet 列名 + (`right_glove` / `left_glove`)。按 MAC 持久化,重连保持;首次连接的未知手套 + 由 `assign_glove_sensor_role` 按广播名偏好(`L` → `left_glove`、 + `R` → `right_glove`)自动分配一个空闲列名并写回。 + +### 2.3 `tasks.json`(模板 `tasks.example.json`) + +采集任务列表,是任务进度的事实来源(single source of truth)。顶层结构: + +```json +{ + "tasks": [ { <任务条目> }, ... ], + "updated_at": "" +} +``` + +任务条目字段(由 `core/task_record.py` 归纳): + +| 键 | 类型 | 含义 | +|---|---|---| +| `id` | string | 任务唯一 ID(读取时也兼容 `task_id` 键名) | +| `name` | string | 任务名;录制时输入的 `task_name` 按 `name` 精确匹配来累计进度,同时是录制目录名的来源 | +| `description` | string | 任务描述 | +| `total_required` | int | 要求完成的录制总次数(`>0` 才视为有效任务) | +| `assigned_at` | string | 任务分配时间(ISO 8601,用于列表排序,新→旧;空/非法排最后) | +| `params` | object | 任务自定义参数(如对象、用手等) | +| `completed_count` | int | 录制完成次数(持久化权威值,每次录制完成 +1,与本地文件是否被删除无关) | +| `status` | string | `pending` / `in_progress` / `completed`,每次加载时由 `completed_count` 与 `total_required` 重新推算 | +| `hidden` | bool | 删除墓碑:用户删除过的任务标 `true`,防止后端再次推送时“复活” | + +行为要点(均来自代码): + +- 首次运行若文件缺失或解析失败,写入内置示例种子任务(`task_001` 起 3 条)后重读。 +- `load_tasks` 除旧数据回填外不写回文件;后端推送经 `merge_backend_tasks` + 按 `id` 合并,本地保留 `total_required`/`params` 覆盖字段与 + `completed_count` 权威值;同名多可见任务只保留 `assigned_at` 最新的一条, + 其余标 `hidden`。 +- 旧数据缺少 `completed_count` 时,一次性按 `data/recordings//` 下含 + `meta/info.json` 的会话目录数回填初值并写回,此后以持久化值为准。 + +### 2.4 `device_params.json` + +每设备相机参数(当前为曝光设置)持久化。顶层为 JSON 对象,key 与 +`device_names.json` 同为 `DeviceInfo.stable_key`: + +```json +{ + "": { + "exposure": { "auto": true, "value": 0.0 }, + "original": { "auto": true, "value": 0.0 } + } +} +``` + +- `exposure`:当前曝光(`auto=true` 时 `value` 被忽略)。 +- `original`:设备首次开启时读回的原厂曝光基线,只写一次、永不覆盖, + 供“恢复默认”按钮使用。 + +仓库内默认文件为空对象 `{}`,随使用增长。注意:key 与 `device_names.json` 同为 +`DeviceInfo.stable_key`,增长后可能含设备序列号/MAC 等标识,本地修改过的文件请勿提交。 + +## 3. SQLite 数据库(`data/pipeline.db`) + +`core/database.py` 定义建表 SQL(`CREATE TABLE IF NOT EXISTS`), +连接为线程本地单例,启用 `journal_mode=WAL` 与 `foreign_keys=ON`。 + +### 表 `recording` —— 录制历史记录 + +| 列 | 类型 | 含义 | +|---|---|---| +| `id` | TEXT PK | 记录 ID | +| `camera_index` | INTEGER | 触发录制的摄像机槽位索引 | +| `camera_name` | TEXT | 摄像机名 | +| `file_path` | TEXT | 会话目录路径 | +| `file_size_mb` | REAL | 文件大小(MB) | +| `duration_sec` | REAL | 录制时长(秒) | +| `resolution_w` / `resolution_h` | INTEGER | 分辨率 | +| `status` | TEXT | `completed` / `uploaded`(已上传、本地保留)/ `aborted` / `deleted` / `uploaded_deleted`(已上传、本地已删,行保留供历史可查) | +| `started_at` / `finished_at` | TEXT | 起止时间 | + +索引:`idx_recording_camera(camera_index)`、`idx_recording_date(started_at)`。 +读写封装在 `core/recording_repository.py`(`RecordingRepo`)、数据类在 +`core/recording_record.py`(`RecordingRecord`)。 + +### 表 `upload_task` —— 上传任务记录 + +| 列 | 类型 | 含义 | +|---|---|---| +| `id` | TEXT PK | 上传任务 ID | +| `session_path` | TEXT | 会话目录路径 | +| `session_name` | TEXT | 会话名 | +| `status` | TEXT | `pending` / `uploading` / `completed` / `failed` / `skipped` | +| `progress` | REAL | 进度(0.0–1.0) | +| `retry_count` | INTEGER | 重试次数 | +| `server_url` | TEXT | 目标服务器 | +| `server_session_id` | TEXT | 服务器返回的会话 ID | +| `error_message` | TEXT | 错误信息 | +| `created_at` / `updated_at` | TEXT | 创建/更新时间 | + +索引:`idx_upload_status(status)`、`idx_upload_session(session_path)`。 + +## 4. 录制目录结构(`data/recordings/`) + +录制由 `core/pipeline.py` 驱动 `core/egodata_writer.py`(`EgoDataWriter`) +写入。目录布局为 EgoData 标准,并兼容 LeRobot v3 格式消费方。 + +### 4.1 目录树 + +``` +data/recordings/ # 录制根目录(settings.RECORDING_DIR) +└── / # 任务目录:清洗后的任务名(task_name 为空时叫 "session") + └── _000001/ # 会话(episode)目录:任务名 + 6 位序号 + # 旧格式兼容:episode_000001/ + ├── metadata.json # EgoData 根级元数据(见 4.3) + ├── timestamps.json # 逐帧时间戳(见 4.4) + ├── videos/ # RGB 视频(每台相机一路 MP4) + │ └── / # 槽名,如 head_left_rgb;_aux 后缀相机归入主相机目录 + │ └── chunk-0000/ + │ └── .mp4 # 编码自适应(v1.0.9:HEVC CRF30 直出,性能不足回退 H.264 CRF23;实际见 metadata.video_codec) + ├── depth/ # 深度(仅启用深度时创建) + │ └── <深度槽名>/ # 如 head_depth(S80M 兜底)/ d435_depth(D435)/ stereo_depth(S80C) + │ ├── <深度槽名>.mp4 # 深度热力图视频(JET 伪彩,可视化用途) + │ └── 000001.png … # 原始 uint16 毫米 PNG(16-bit grayscale, + │ # raw_depth 槽位;v1.0.11 曾改 raw16 bin, + │ # 体积过大且上传失败,v1.0.12 回退 PNG16) + ├── calibration/ # 标定(StereoCalibration) + │ ├── head_stereo.json # 首台双目型设备标定(服务器/回放/三角化依赖此路径) + │ └── <槽名前缀>_calibration.json # 其余设备的标定(槽名前缀去掉 "_N" 消歧编号) + ├── data/ # 传感器数据(LeRobot v3 兼容 Parquet) + │ ├── / # 每传感器一个目录,如 right_glove / left_glove + │ │ └── chunk-0000/ + │ │ └── chunk_000000.parquet # zstd 压缩,schema 见 4.5 + │ └── imu/ # 双目 IMU(仅双目会话,每帧一行) + │ └── chunk-0000/ + │ └── chunk_000000.parquet + └── meta/ # LeRobot v3 兼容元数据 + ├── info.json # 上传服务器严格依赖的字段(见 4.6) + ├── stats.json # 各特征 mean/std/min/max(归一化统计) + ├── tasks.jsonl # {"task_index": 0, "task": "<任务名,空时 'default recording'>"},单行 JSON + └── episodes/ + ├── chunk-000/ + │ └── file-000.parquet # 每会话一行的 episode 表 + └── chunk_000000.parquet # 前者的兼容旧路径副本 +``` + +要点: + +- **序号**:episode 序号 = `max(任务进度 batch_index, 目录扫描最大序号 + 1)`; + `batch_index` 是“录制完成次数 + 1”(`core/task_record.py` 持久化), + 上传后自动删除本地文件也不会使序号回退。 +- **视频/深度/标定**:深度槽位(`depth_slots`)不建视频目录也不走 MP4 合成; + `start_episode` 中 `_aux` 后缀摄像头归入主摄像头目录。 +- **旧格式兼容**:会话目录也可能以 `_YYYYMMDD_HHMMSS`(`session_dirname`) + 命名且内含 `meta/info.json`(LeRobot v3 旧会话);`core/helpers.py` 的 + `list_all_sessions` / `detect_session_format` 通过 `metadata.json`(egodata) + 或 `meta/info.json`(lerobot_v3)识别会话,回放支持两种格式。 +- **中止录制**:`abort_episode` 直接 `rmtree` 丢弃整个会话目录。 +- **关键点数据不写在本目录**:手部关键点输出镜像到仓库根的 + `keypoints_output///`(见第 5 节)。 + +### 4.2 深度通道说明 + +- **S80M 传统路径**(无显式注册深度槽):单槽兜底 `head_depth`, + 由 `write_depth_frame` 惰性创建目录并合成热力图 MP4,受 + `settings.DEPTH_ENABLED` 门控(默认关闭,遗留开关勿启用)。 +- **D435/D405**(`core/pipeline.py` 经 `set_depth_camera` 显式注册槽位): + 打开即录深度;槽位配置了 `raw_depth=True` 时额外写原始 uint16 PNG16 + (`egodata_depth_path`:`depth/<槽名>/000001.png`,文件名从 1 起 6 位, + 压缩级 `settings.D435_PNG_COMPRESSION`)。 + 热力图支持固定色标(`near_mm`/`far_mm`)、3×3 中值与 EMA 时域平滑 + (仅作用于可视化通道,原始 PNG16 不经过)。 +- **S80C**(v1.0.11):`set_depth_camera(settings.S80M_DEPTH_SLOT, + raw_depth=True)` 显式注册槽位 `stereo_depth`,深度由 `read_stereo_rgb.py` + 子进程内 SDK 深度引擎计算(~20fps),经管道深度块 → `depth_ready` 信号 + 回主程序;录制时热力图 MP4 + PNG16 与 D435 同口径落盘。深度源低于 + 录制帧率时热力图 MP4 重复最近帧补拍(时长与 RGB 对齐),PNG16 仅 + 记新帧不重复。 +- **读取**:PNG16 直接 `cv2.imread(path, cv2.IMREAD_UNCHANGED)`; + v1.0.11 窗口会话存的是 raw16 bin(`np.fromfile(dtype=np.uint16) + .reshape(h, w)`,`(h, w)` 取 `metadata.json` `cameras.<槽名>.height/width`), + 读取方已做扩展名回退兼容(`depth_align.load_depth_frame`)。 + +### 4.3 `metadata.json` 字段概览(EgoData 根级元数据) + +| 键 | 含义 | +|---|---| +| `format` / `format_version` | 固定 `"egodata"` / `"1.0"` | +| `episode_index` | episode 序号 | +| `fps` | 默认录制帧率 | +| `task_name` | 任务名(可为空) | +| `cameras` | `{槽名: {height, width, ...}}`;深度槽带 `type:"depth"`、`unit:"mm"`、`format:"png16"`(v1.0.11 窗口会话为 `"raw16"`);RGB 槽带独立帧率 `fps`(与默认不同时);挂设备归属时带 `device_key`/`device` | +| `devices` | 设备段数组:`{key, kind, name, slots, serial?, sensor_column?, resolution, fps, calibration}`;`serial` 仅在设备提供时写入 | +| `sensors` | 传感器名列表(如 `["right_glove", "left_glove"]`) | +| `sensor_dim` | 传感器维度(256 = 16×16 触觉矩阵展平) | +| `created_at` | 创建时间(Unix 时间) | +| `codebase_version` | 程序版本(`config.__version__`) | +| `video_codec` | v1.0.9:本会话视频编码信息 `{encoder, codec, crf, ffmpeg, selected_by, probe}`;`selected_by` = `"auto"` 或显式指定名,`probe` = 录前速度探针结果(x265 路径) | +| `drop_stats` | v1.0.9:录制丢帧统计 `{队列键: 丢弃帧数}` + `imu_overflow`(IMU 防丢缓冲溢出次数);无丢帧时全为 0 | + +### 4.4 `timestamps.json` + +```json +{ + "timestamps": [ { "frame_index": 0, "timestamp": 0.0, "wall_time": 1.7e9 }, ... ], + "total_frames": 1234 +} +``` + +- `timestamp`:会话相对时间(秒,与 parquet 的 `timestamp` 列同源);`wall_time`:写入时刻的墙上时间。 +- `hardware_ns`:仅双目相机帧携带(SDK 硬件纳秒时钟,与 IMU 同源);含硬件 + 时间戳的行在写出时按 `hardware_ns` 稳定排序,保证时间线单调。 + +### 4.5 Parquet schema(`data/` 与 `meta/episodes/`) + +- `data//chunk-0000/chunk_000000.parquet`(每帧一行,zstd 压缩): + + | 列 | 类型 | 含义 | + |---|---|---| + | `episode_index` | int64 | episode 序号 | + | `frame_index` | int64 | 帧序号 | + | `timestamp` | float32 | 会话时间(秒) | + | `task_index` | int64 | 任务序号(当前固定 0) | + | `observation.` | list | 传感器读数(16×16 展平;缺帧补零) | + | `observation.left_hand_pose` / `observation.right_hand_pose` | list | 手部关键点(21 关节 × xyz;录制时占位为零,后处理回填) | + | `action` | list | 动作(当前固定 `[0.0]`) | + | `status.` | string | 该设备在本帧的连接状态(默认 `"connected"`) | + +- `data/imu/chunk-0000/chunk_000000.parquet`(双目 IMU,每帧一行): + + | 列 | 类型 | 含义 | + |---|---|---| + | `episode_index` / `frame_index` / `timestamp` / `task_index` | 同上 | 同上 | + | `hardware_ns` | int64 | 帧的 SDK 硬件纳秒时间戳 | + | `imu_ts_ns` | list | 本帧窗口内 IMU 样本时间戳,与样本一一对应 | + | `observation.imu` | list> | 样本序列,每样本 `[gx, gy, gz, ax, ay, az]` | + +- `meta/episodes/chunk-000/file-000.parquet`(每会话一行): + `episode_index`、`task_index`、`start_frame_index`、`end_frame_index`、 + `length`(均为 int64)。 + +### 4.6 `meta/info.json` 字段概览(LeRobot v3 兼容,上传服务器严格依赖) + +| 键 | 含义 | +|---|---| +| `codebase_version` | 固定字符串 `"v3.0"` | +| `fps` | 默认录制帧率 | +| `video` | bool:是否有视频 | +| `task_name` | 任务名(空时 `""`) | +| `features` | `{observation.: {dtype:"float32", shape:[16,16]}, observation.imu: {dtype:"float32", shape:[6]}, action: {dtype:"float32", shape:[1]}}`;shape 必须是 2D `[16,16]` 而非 1D `[256]` | +| `cameras` | dict 格式 `{槽名: {height, width, fps?}}`(深度槽不在此列) | +| `devices` | 紧凑设备段:`[{key, kind, name, slots}]`(无 serial 等敏感字段) | +| `device_names` | 槽位 → 用户命名映射 | +| `sensors` | 传感器名列表 | +| `sensor_dim` | 传感器维度 | +| `created_at` | 创建时间(Unix 时间) | + +`stats.json` 对应 `features` 各键给出 `mean`/`std`/`min`/`max`(IMU 为 6 轴 +样本级统计,`action` 为占位值),供归一化使用。 + +## 5. 相邻输出目录 `keypoints_output/`(不在 `data/` 下) + +录制后的手部关键点处理结果**不写回** `data/recordings/`,而是镜像输出到 +仓库根的 `keypoints_output/`(`settings.KEYPOINTS_OUTPUT_DIR`,gitignore): + +``` +keypoints_output/// +├── videos/ # 关键点可视化视频 +├── hand_pose/chunk-000.parquet # 2D 手部关键点 +├── hand_pose_3d/chunk-000.parquet # 3D 手部关键点 +└── auto_labels/auto_labels.parquet # 自动标注 +``` + +读取时有三级回退路径(`core/helpers.py`):先查 `keypoints_output/` 镜像, +再查会话目录内 `keypoints/`,最后查旧版 `annotations/`(含 `annotations/mmpose/`)。 diff --git a/collector/docs/demos.md b/collector/docs/demos.md new file mode 100644 index 0000000000000000000000000000000000000000..c9f5a39d5487ee8facdc98a4ff350d1e10854b5f --- /dev/null +++ b/collector/docs/demos.md @@ -0,0 +1,194 @@ +# tools/demos/ + +## 定位 + +`tools/demos/` 汇集面向客户交付与开发者自检的演示程序:HDF5 录制回放查看器、UVC 相机 HSV/触觉可视化工具、双目 2D 手部关键点 demo、黑手套检测对比工具,以及 S80M 双目深度 demo(Python 与 C++ 两版)。 + +本目录独立于主程序运行。全库检索(排除 `tools/demos/` 自身与 `docs/`)仅 `tools/hand_3d_s80c/s80c_depth_worker.py:118` 注释引用 `tools/demos/run_stereo_depth_demo.sh`;主程序中的「双目 demo」字样(`ui/main_window.py:703,711,759`、`config/i18n.py:100`)实际指自包含模块 `tools/stereo_s80m/read_stereo_rgb.py`(路径常量 `STEREO_DEMO` 在 `core/s80m_manager.py:40`),与 `tools/demos/` 无关;`config/settings.py:86` 的深度显示下限注释(0.3m)参考的是本目录 S80M 深度 demo 的口径。其中 `tools/demos/demo_glove_kpts/` 反向复用了主程序的 `core/hand_tracking.py` 代码路径。 + +## 文件清单 + +| 文件/子目录 | 一句话作用 | 运行方式 | +|---|---|---| +| `tools/demos/demo_glove_kpts/compare_detectors.py` | 黑手套检测器 A/B 对比(对照检测器 vs 新训练模型),输出对比视频与指标 CSV | `python tools/demos/demo_glove_kpts/compare_detectors.py [--old world\|.pt] [--new .pt]` | +| `tools/demos/demo_glove_kpts/demo_glove_video.py` | 单视频黑手套关键点识别 + 渲染(复用主程序 core/ 代码路径) | `python tools/demos/demo_glove_kpts/demo_glove_video.py [--video PATH]` | +| `tools/demos/demo_glove_kpts/D435_depth_rgb_kpts.mp4` | 示例渲染输出视频(运行 `demo_glove_video.py` 后生成,约 10 MB;当前仓库内未保留) | — | +| `tools/demos/hdf5_demo_v1.4/hdf5_demo.py` | HDF5 录制四宫格回放查看器(双目视频/渲染视频/仿生手掌/触觉热力图/IMU,单文件自包含) | `python tools/demos/hdf5_demo_v1.4/hdf5_demo.py [data.h5]` | +| `tools/demos/hdf5_demo_v1.4/README.md`、`HELP.md` | 英文 / 中文使用说明 | — | +| `tools/demos/hdf5_demo_v1.4/requirements.txt` | 依赖:`numpy`、`h5py`、`PyQt5`、`opencv-python` | `pip install -r tools/demos/hdf5_demo_v1.4/requirements.txt` | +| `tools/demos/HSV_Visualizer_V4.4.1.py` | UVC 相机 HSV/RGB 通道可视化 + ROI 统计 + RGB/Hue 时序曲线 + 平面触觉热力图链路复刻 | `python tools/demos/HSV_Visualizer_V4.4.1.py` | +| `tools/demos/stereo_2d_demo/stereo_2d_demo.py` | 双目/单目视频 2D 手部关键点检测 + 渲染(单文件自包含) | `python tools/demos/stereo_2d_demo/stereo_2d_demo.py left.mp4 right.mp4 -o out.mp4` | +| `tools/demos/stereo_2d_demo/hand_landmarker.task` | MediaPipe 手部关键点模型权重(约 7.5 MB,须与脚本同目录) | `--model` 可改路径 | +| `tools/demos/stereo_2d_demo/run.sh`、`requirements.txt`、`README.md` | 一键运行脚本(自动检测本地 venv)/ 依赖 / 中文说明 | `tools/demos/stereo_2d_demo/run.sh left.mp4 right.mp4` | +| `tools/demos/test_stereo_depth_calib.py` | S80M 双目深度 demo(Python ctypes 调用 FaysSense SDK 深度引擎) | 必须经启动器:`./tools/demos/run_stereo_depth_demo.sh` | +| `tools/demos/run_stereo_depth_demo.sh` | 深度 demo 启动器(设置 `LD_LIBRARY_PATH` 绑定 SDK 自带 OpenCV 4.2) | `FAYSSENSE_SDK_DIR= ./tools/demos/run_stereo_depth_demo.sh` | +| `tools/demos/stereo_depth_640x400.yaml` | 640×400 分辨率的双目深度引擎配置样例 | 参考用;运行时读取 SDK 目录内配置 | +| `tools/demos/stereo_depth_demo/` | C++ 版 S80M 双目深度 demo(`main.cpp` + `CMakeLists.txt` + `build.sh` + `run.sh`) | 目录内 `./build.sh && ./run.sh`(需 SDK) | + +## 各文件详解 + +### `tools/demos/demo_glove_kpts/demo_glove_video.py` + +**作用**:对单个视频逐帧跑黑手套检测管线(YOLO 检测黑手套 + RTMPose 21 点关键点),叠加框/Hand #ID/分色骨架/伸指信息后写输出视频,可选实时显示窗口。完全复用主程序两条现成代码路径:`core/hand_processor.py` 内部 `process_session()` 的 glove 分支与 `core/hand_tracking.draw_kpts_overlay()` 渲染,行为与 GUI 会话后处理一致。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `_find_ffmpeg` | `() -> str` | 按优先级找可用 ffmpeg(lerobot 环境 → PATH → miniconda base) | 返回路径,找不到返回 `""` | +| `build_pipeline` | `(det_device, pose_device, detector="")` | 构造 `HandPipeline`;CUDA 不可用时自动回退 CPU | 返回 `HandPipeline` 实例 | +| `main` | — | 解析参数、逐帧推理渲染、写临时 mpeg4 后用 ffmpeg 转 H.264 | 返回退出码;输出 `<源文件名>_kpts.mp4` | + +**关键数据**: +- 输入:任意视频;默认 `data/recordings/Project_Test10/Project_Test10_000003/videos/D435_depth_rgb/chunk-0000/D435_depth_rgb.mp4`。 +- 默认检测器权重:`tools/hand_detection/best.pt`(`--detector` 可改)。 +- 命令行参数:`--video`(默认上述路径)、`--out`(默认写入本 demo 目录 `<源文件名>_kpts.mp4`)、`--detector`、`--start 0`、`--frames 0`(0=到结尾)、`--det-device cuda`、`--pose-device cuda`、`--no-display`、`--no-transcode`(跳过转码,直接输出 cv2 的 mpeg4)。 +- 输出:cv2 先写 `.mpeg4.tmp.mp4`(mp4v 编码),结束用 ffmpeg 转 `libx264 -crf 20 yuv420p +faststart`;无 ffmpeg 时保留 mpeg4。 +- 显示窗口按键:`q`/`Esc` 退出,空格 暂停/继续;按源帧率限速。 + +**调用关系**:不被主程序调用(无外部引用);导入 `core/hand_tracking`(`_lazy_import_pipeline`、`_pack_hand_data`、`draw_kpts_overlay`,`core/hand_tracking.py` 经 `core/hand_processor.py` 间接与主程序共用)。被同目录 `compare_detectors.py` 导入复用。 + +### `tools/demos/demo_glove_kpts/compare_detectors.py` + +**作用**:黑手套检测器 A/B 对比工具。两个参数完全相同的 `HandPipeline`(仅检测器不同,`det_imgsz`/conf/追踪/姿态门/渲染链与主程序部署口径一致)对同一段视频逐帧各跑一遍,输出各自渲染视频、左右并排对比视频和指标 CSV。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `ModelStats` | `__init__(label, weights)`;`add(boxes, kpts, scores, track_ids)`;`summary()` | 单模型逐帧指标收集(基于 `process()` 门后输出,即用户实际看到的渲染结果) | `summary()` 返回指标 dict | +| `_as_pt` | `(path, out_dir)` | ultralytics 只认 `.pt` 后缀;非 `.pt` 权重复制成临时 `.pt` | 返回可用路径 | +| `_transcode` | `(tmp, out, ffmpeg)` | mpeg4 临时文件 → H.264(与 `demo_glove_video.py` 相同配方,`crf 20`) | 返回是否转码成功;无 ffmpeg 时原样改名 | +| `main` | — | 建两条管线、逐帧推理 + 并排渲染、转码、打印并写指标表 | 输出 `old.mp4`/`new.mp4`/`side_by_side.mp4`/`compare_report.csv` | + +**关键数据**: +- `--old` 默认 `"world"`:内置 YOLO-World 零样本(prompt `["hand","glove"]`,imgsz 320,权重 `yolov8m-worldv2.pt`);也可传 `.pt` 路径对比旧训练模型。 +- `--new` 默认 `tools/glove_package/runs/hand_det/weights/best.pt`。 +- `--out-dir` 默认 `keypoints_output/ab_compare`;`--video` 默认同 `demo_glove_video.py` 的 `DEFAULT_VIDEO`。 +- 其余参数:`--start 0`、`--frames 0`、`--det-device cuda`、`--pose-device cuda`、`--display`(弹出实时窗口,`q` 退出)、`--no-transcode`。 +- 并排视频:顶部 30px 标签条(`LABEL_H`,按偶数对齐保证 yuv420p),左对照右新,下方帧号。 +- 指标口径(`compare_report.csv`):检出帧率(boxes 非空帧占比)、单手率、kpt 均值中位数(被渲染手部 21 点置信度均值的中位数)、腕点(点 0)抖动 p50/p95/max(px)、ID 切换次数、平均 track 寿命(帧)。 + +**调用关系**:不被主程序调用;从同目录 `demo_glove_video` 导入 `build_pipeline`、`draw_kpts_overlay`、`_pack_hand_data`、`_find_ffmpeg`、`DEFAULT_VIDEO`;间接依赖 `core/hand_tracking` 与 `tools/glove_package` 训练产物。 + +### `tools/demos/hdf5_demo_v1.4/hdf5_demo.py` + +**作用**:单文件自包含的 HDF5 数据四宫格演示播放器(可直接发给客户)。一个窗口同时显示:左上双目原始视频(可同时拼单目)、右上 h5 内已渲染好的视频、左下仿生手掌(16×16 触觉矩阵按部位映射)、右下触觉热力图、底部 IMU 加速度/角速度波形。触觉与 IMU 面板只在文件里确有该数据时显示。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `render_bionic_hand` | `(mat, window_size=(640,400), vmax=None)` | 2D 手掌骨架 + 16×16 触觉矩阵按部位映射 viridis 色块(锚点基于 1280×720 等比缩放) | 返回 BGR 画布 | +| `make_heatmap` | `(mat, size=300, cmap=COLORMAP_JET, vmax=None)` | 16×16 压力矩阵 → 带网格线的热力图 | 返回热力图 BGR | +| `put_label` | `(img, text, pos, color)` | 叠加带黑底标签文字;无效输入直接忽略 | 就地修改 | +| `render_imu` | `(seq, counts, idx, window=240, w=880, h=185)` | IMU 6 通道折线(上 acc/下 gyr)+ 当前帧竖线 + 右侧数值 | 返回 IMU 波形画布 | +| `RenderedVideo` | `__init__(ds)`、`__len__()`、`__getitem__(i)`、`close()` | h5 内 `videos/hand_skeleton` 的 MP4 原始字节 → 临时文件 + `cv2.VideoCapture` 按帧解码;顺序播放走顺序 read,跳转才 seek 且只缓存跳转帧(`_CACHE_MAX=30`) | 帧 BGR 数组或 `None` | +| `H5Data` | `__init__(path)`、`_find_rendered()`、`close()` | 惰性读取 hdf5,探测双目/单目视频、渲染视频、触觉、IMU、播放帧率 | 属性:`imgs`、`rendered`、`tactile`、`fps`、`capture_fps`、`tactile_vmax`、`imu_seq`/`imu_counts` | +| `DemoWindow` | `__init__(h5_path=None)`、`load(path)`、`open_file_dialog()`、`toggle_play()`、`next_frame()`、`seek(i)`、`render_frame(idx)`、`_show_image(label, bgr)`(静态) | PyQt5 主窗口:四宫格 + 控制条(Open h5/Play/Pause/单帧步进/滑块),`QTimer` 40ms(25fps),渲染慢于时钟时自动降速 | 渲染各面板像素图 | +| `main` | `h5` 为可选位置参数 | 启动 QApplication | — | + +**关键数据**(读取的数据集,均在 `episode_*` 组内): +- `observation/images/stereo_left`、`stereo_right`:`(N, 800, 1280, 3)` uint8 RGB(必需,缺失报错)。 +- 单目数据集名探测(可与双目并存):`left`/`mono`/`monocular`/`rgb`/`color`/`cam0`/`camera`/`image`/`frame`/`left_camera`/`camera_left`/`head_left_rgb`/`head_rgb`/`front_rgb`/`front`。 +- `videos/hand_skeleton`:MP4 字节(优先作为渲染视频源);兜底探测 `images` 组内名称含 `RENDERED_KEYWORDS`(`preview`/`keypoint`/`annot`/`render`/`overlay`/`visual`/`vis`/`kp`/`skeleton`/`slam`)的帧数组。 +- `observation/tactile/left`、`right`:`(N, 16, 16)` float(全零视为无数据,面板隐藏)。 +- `observation/imu`:`(M, 6)` float(acc xyz + gyr xyz);`observation/imu_frame_index`:`(M,)` int 对应帧号;查看器自动按帧重新聚合(每帧取第一个样本作图 + 统计样本数)。 +- 播放帧率:`meta/info` attrs `capture_fps` 优先,其次 `fps`,再其次数据集 attrs `fps`,默认 25。 +- 运行:`python tools/demos/hdf5_demo_v1.4/hdf5_demo.py [data.h5]`,不带参数启动后点 Open h5 选择。 + +**调用关系**:不被任何其他代码调用(独立 GUI 单文件);仅依赖 `numpy`/`h5py`/`cv2`/`PyQt5`。`HELP.md` 含详细使用说明与 FAQ。 + +### `tools/demos/HSV_Visualizer_V4.4.1.py` + +**作用**:UVC 相机实时可视化工具。同一窗口 3 行拼接显示原图/H/S/V/R/G/B 七个通道与平面触觉热力图,底部 RGB+Hue 时序曲线;支持双 ROI 均值/方差统计、相机参数实时调节(滑块直写 `cv2.VideoCapture`)、传感器 ROI 裁切、热力图链路参数设置(复刻 `touch_sensor.py` 的 H 基线差分 → mask → 阈值 → 力标定链路)、断线自动重连。无命令行参数,全部经 GUI 操作。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `open_camera` | `(port)` | 打开摄像头;Linux 固定 V4L2 + MJPG 640×480@30fps,Windows DirectShow | 返回 `cv2.VideoCapture` | +| `ROIDialog` | `create_slider_with_label(...)`、`update_params()`、`reset_to_defaults()` | ROI 1(绿)/ROI 2(红)的 x/y/w/h 滑块弹窗,默认 r1=(275,320,50,55)、r2=(275,120,50,55) | 回写 `parent.roi_params` | +| `CameraParamsDialog` | `_on_slider`/`_on_spin`/`_write_camera(prop_id, value)`、`_on_auto_exp_toggled`、`_on_auto_wb_toggled`、`_reset_defaults` | 9 项相机参数滑块 + 自动曝光/白平衡复选框,拖动即时写入相机;Linux 曝光值 log2 秒 ↔ V4L2 100µs 互转,自动曝光极性 V4L2 与 Windows 相反 | 实时修改相机参数 | +| `HeatmapSettingsDialog` | `_on_scale_slider`/`_on_scale_spin`/`_reset_defaults`/`_confirm` | 热力图缩放/Mask B/Mask R/Hue 阈值/标定系数设置,默认 `scale=10.0`、`mask_b=50`、`mask_r=130`、`hue_threshold=5.0`、`fz_p1=1.0` | `_confirm` 回写主窗口 | +| `MainWindow` | `calibrate_baseline(num_frames=5)`、`compute_fz_matrix(frame)`、`update_frame()`、`draw_heatmap(fz_matrix, cell_w, cell_h)`、`draw_rgb_curve(cell_w, cell_h)`、`change_port()`、`reconnect_camera()`、`_do_retry_reconnect()`、`_setup_camera_defaults()`、`keyPressEvent(event)`、鼠标事件、`closeEvent(event)` | 主窗口:30ms 定时刷新;`compute_fz_matrix` 复刻 H 提取→基线差分→mask→阈值过滤→`×fz_p1` 链路;自动重连阈值 30 连败帧,重试间隔 67 帧(约 2s);右键拖拽可在任一子图内画 ROI2 | 更新 UI;`R` 键触发重连 | + +**关键数据**: +- 相机参数列表(`CAM_PARAMS`):亮度 0-255、对比度 0-255、色调 0-180、饱和度 0-255、锐度 0-255、伽马 1-500、增益 16-248、曝光 -13 ~ -1、白平衡 2800-6500K。 +- 主窗口默认 `roi_params`:`r1=(150,200,50,55)`、`r2=(275,120,200,200)`;`sensor_roi` 默认全帧 `(0,640,0,480)`。 +- 打开相机后自动关闭自动曝光/自动白平衡并校准 H 基线;统计值每 10 帧(约每秒 3 次)刷新一次;R/G/B/H 均值历史最近 500 帧。 +- 输出:无文件输出,纯实时显示。 + +**调用关系**:不被其他代码调用(独立 GUI);依赖 `numpy`/`cv2`/`PyQt5`。文件内注释多处标注其热力图链路「复刻 `touch_sensor.py:516` / `touch_sensor.py:702`」及 `sightac_sdk` 逻辑——该模块属于外部 sightac SDK,本仓库内不存在同名文件,仅作为算法口径参考。 + +### `tools/demos/stereo_2d_demo/stereo_2d_demo.py` + +**作用**:双目(或单目)视频 2D 手部关键点检测 + 渲染演示。自包含单文件:不依赖仓库任何其他模块,MediaPipe 检测、One-Euro 平滑、五指分色绘制、手势识别、视频合成与 H.264 转码全部在本文件内。模型文件 `hand_landmarker.task` 须与本文件同目录(缺失时报错并给出官方下载地址)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `_angle_between` | `(p_prev, p_vertex, p_next)` | 顶点处两骨段夹角(度,180°=伸直) | 返回角度 | +| `_compute_joint_angles` | `(pts)` | 21 点 `(21,2)` → 每关节角度 | 返回 `{(finger, joint): 度}` | +| `_count_extended_fingers` | `(angles)` | 角度 → 伸直手指名列表(空=握拳) | 返回手指名列表 | +| `_OneEuroFilter` | `__init__(freq_min=5.0, beta=0.05, dcutoff=1.0)`、`__call__(x, ts_ms)` | 单值 One-Euro 自适应低通 | 返回滤波值 | +| `_OneEuroFilter2D` | `__init__(freq_min=5.0, beta=0.05, dcutoff=1.0)`、`__call__(x, y, ts_ms)` | x/y 分量独立滤波 | 返回 `(x_hat, y_hat)` | +| `HandDetector` | `__init__(model_path=MODEL_PATH, num_hands=2, mirror=False, smooth=True, freq_min=15.0, beta=0.6, dcutoff=1.0)`;`process(frame_bgr)`;`close()` | MediaPipe Tasks API VIDEO 模式手部检测,置信度门限均为 0.5,可选 One-Euro 平滑 | `process` 返回 `[[(x,y)×21], ...]` 像素关键点 | +| `_draw_hand` | `(frame, pts)` | 五指分色骨架:掌心灰连接、腕白圆、指尖 7px/关节 5px + 深色描边 | 就地绘制 | +| `_draw_kpts_overlay` | `(frame, hands, cam_label="", frame_idx=0, total=0)` | 包围框 + 底衬标签 + 分色骨架 + 手势文本(`open: 手指名`/`fist`) | 返回叠加后的帧 | +| `_create_writer` | `(out_path, fps, width, height)` | 创建 mp4v 临时写器 | 返回 `(writer, tmp_path)` | +| `_find_working_ffmpeg` | `()` | 探测可运行 ffmpeg(存在但损坏的候选会被跳过) | 返回路径或 `None` | +| `_finalize` | `(writer, tmp_path, out_path)` | 释放写器后用 ffmpeg 转 `libx264 -crf 23 yuv420p`;无 ffmpeg 则 mp4v 原样交付 | 返回最终输出路径 | +| `process_video` | `(streams, output, detector, cam_labels)` | 多流逐帧检测 + 并排渲染(`hconcat`) | 写输出视频 | +| `main` | 位置参数 `videos`(1 或 2 个) | 解析参数、建检测器、跑 `process_video` | 退出码 | + +**关键数据**: +- 输入:1 个视频=单目;2 个视频=左右目并排输出(最多 2 个,超出报错)。帧数取各流最小值。 +- 输出:默认 `stereo_2d_output.mp4`;帧叠加:青绿包围框 + `Hand #0/#1` 标签 + 五指分色(拇指橙、食指绿、中指黄、无名指紫、小指蓝)+ 手势文本。 +- 命令行参数:`-o/--output`(默认 `stereo_2d_output.mp4`)、`--model`(默认同目录 `hand_landmarker.task`)、`--freq-min 15.0`(越大越跟手越抖)、`--beta 0.6`(快速运动滞后就调大)、`--no-smooth`(关闭平滑)。 +- 依赖:`mediapipe>=0.10`、`opencv-python>=4.5`、`numpy>=1.21`(`requirements.txt`)。 +- `run.sh`:一键运行(自动检测本目录 `venv/bin/python`,否则系统 `python3`,要求 Python 3.9+)。 + +**调用关系**:不被其他代码调用(自包含单文件,`README.md` 明确「不依赖仓库里任何其他模块或目录」,面向解压即用的客户交付)。 + +### `tools/demos/test_stereo_depth_calib.py` + +**作用**:S80M 双目深度 demo(Python 版)。用 `ctypes` 直接调用 FaysSense VI Kit SDK 官方深度引擎:`FAYS_VIK_CreateHandleWithConfig` 打开相机 → `FAYS_ATRAK_D_CreateHandleWithConfig` 创建深度引擎(`stereo_depth.yaml`,`depth_mode=1` CPU)→ `FAYS_ATRAK_D_BindViKit` 绑定(在线模式,标定由相机提供)→ 循环 `GetStereoFrames` / `FeedStereoImage` / `GetDepthImage` / `GetRectifiedImage`,三窗口实时显示深度热力图、原始/矫正双目、视差图;`P` 键导出点云 PLY。文件为顶层执行脚本(无 `main()`),并注意 S80M 固件的两个怪癖:实际拼接为 上=右目/下=左目(已由官方配置 `stereo_swap_lr: 1` 在传感器层解决,脚本默认不交换)、实际输出 RGB 通道序与头文件声称的 BGR 相反(`SWAP_RGB=True` 转回 BGR)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `_preload_opencv_dir` | `(libdir)` | `ctypes.CDLL(RTLD_GLOBAL)` 预载 OpenCV 4.2 模块及外部依赖(libwebp/libtiff/libtbb/dc1394/av* 等) | 加载动态库 | +| `img_to_numpy` | `(img: AtrakImage)` | uint8 `AtrakImage` → numpy(按 `step` 处理行填充,`as_strided`) | 返回副本数组 | +| `depth_to_numpy` | `(img: AtrakDepthImage)` | float32 深度/视差 → numpy 2D | 返回数组 | +| `save_pointcloud_ply` | `(path, pos, rgb)` | `pos: (N,3)` float32 + `rgb: (N,)` uint32 ARGB8 → 二进制 PLY(`binary_little_endian 1.0`) | 写文件 | + +结构体(对应 SDK 头文件 `fays_atrak_types.h`):`AtrakImage`、`AtrakDepthImage`(data 为 float,深度单位米)、`AtrakRectifyInfo`(矫正矩阵 R0/R1/P0/P1)、`AtrakMap`(点云 pos N×3 float、rgb N×1 ARGB8)、`AtrakIntrinsics`、`AtrakExtrinsics`、`AtrakCamParam`、`AtrakCamChainParam`、`AtrakImuParam`、`AtrakCalibrationParam`。 + +**关键数据**: +- 环境变量 `FAYSSENSE_SDK_DIR` 必需;未设置直接 `SystemExit` 报错退出。由此拼出库与配置路径:`lib/fays_atrak/x86_64/Release/libfays_vikit.so`、`libfayssense_aikit_depth.so`、`config/fays_vikit.yaml`、`config/perception/stereo_depth/stereo_depth.yaml`。 +- OpenCV:优先预载 SDK 自带 4.2(`thirdparty/opencv-4.2.0-linux-x86_64/lib406`,深度引擎按其编译,系统 OpenCV 4.6/4.13 不兼容);找不到才回退系统 4.6(引擎在其下会崩)。 +- 输出缓冲必须按 SDK 头文件宏上限分配(如 `FAYS_ATRAK_IMG_MAX_BYTES = 3840*2160*3`、`FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM = 262144`),偏小会越界写堆导致随机段错误。 +- 运行时打印标定摘要(双 Cam fx/fy/分辨率、Baseline mm)与矫正后 `fx'`/`baseline'`。 +- 深度显示范围 `D_NEAR=0.3`、`D_FAR=4.0` m;按键:`Q`/`Esc` 退出、`S` 截图(`depth_heat_.png`、`disparity_.png`、`stereo_rectified_.png`、`depth_.raw` float32 米)、`P` 导出 `pointcloud_.ply`、`L` 切换左右顺序验证、`1`-`4` 调深度范围;每秒打印一次有效深度占比/中位/范围统计。 + +**调用关系**:必须经 `tools/demos/run_stereo_depth_demo.sh` 启动(见下),不可直接 `python` 运行(深度库加载失败时会提示用启动器)。不被主程序调用;与 C++ 版 `tools/demos/stereo_depth_demo/main.cpp` 管线一致、缓冲区口径一致。注:`tools/demos/stereo_depth_640x400.yaml` 文件头注明 "generated by test_stereo_depth_calib.py",但当前脚本运行时读取的是 SDK 目录内的 `stereo_depth.yaml`(`DEPTH_CONFIG`),该 yaml 是 640×400 分辨率的配置样例(`depth_mode: 1`、`wls_filter: true`、`farthest_dist: 10.0`、`cloest_dist: 0.3`)。 + +### `tools/demos/run_stereo_depth_demo.sh` + +**作用**:Python 深度 demo 启动器。深度引擎 `libfayssense_aikit_depth.so` 按 SDK 自带 OpenCV 4.2.0 编译,系统 OpenCV 4.6/4.13 不兼容(`cv::Exception: Unknown/unsupported array type`),启动器通过 `LD_LIBRARY_PATH` 让 SDK 库绑定自带 4.2(`lib406` 目录),然后 `exec python3 -u test_stereo_depth_calib.py "$@"`。SDK 目录由 `SDK_DIR` 或 `FAYSSENSE_SDK_DIR` 环境变量提供,未设置报错退出;`lib406` 目录缺失也会报错退出。 + +### `tools/demos/stereo_depth_demo/`(C++ 版深度 demo) + +**作用**:S80M 双目深度 demo 的 C++ 版,严格按 FaysSense VI Kit SDK 官方实现编写(图像读取参考 SDK `example/fays_vikit_example.cpp`,深度引擎参考 `stereo_depth_gui/core/depth_engine.cpp`),管线与 Python 版一致(打开相机 → 创建深度引擎 → 绑定 → 取帧/深度/矫正 → 导出点云 PLY)。此处仅说明存在与用途,不展开 C++ 内部实现。 + +**构成与运行**: +- `main.cpp`:主程序(含 SDK 同款直方图均衡 + JET 深度着色)。 +- `CMakeLists.txt`:CMake ≥ 3.12;`SDK_DIR` 未定义时默认 `/home/REDACTED/FaysSense_VI_Kit_Release`(占位符,实际构建由 `build.sh` 传 `-DSDK_DIR` 覆盖);必须用 SDK 自带 OpenCV 4.2(`find_package(OpenCV)` 经 `-DOpenCV_DIR` 指向 SDK 目录);链接顺序注释明确:SDK 库在前、OpenCV 4.2 模块其次、`lib406` 外部依赖 shim 最后。 +- `build.sh`:自动检测 SDK(`SDK_DIR` 或 `FAYSSENSE_SDK_DIR`,未设置报错退出),校验 SDK 头文件与自带 OpenCV 4.2 的 cmake 配置存在,`cmake -DCMAKE_BUILD_TYPE=Release` + `make`,产物 `build/stereo_depth_demo`。 +- `run.sh`:设置 `LD_LIBRARY_PATH`(SDK 自带 OpenCV 4.2 的 `lib406` 目录 + SDK 库目录)后运行 `build/stereo_depth_demo [viKitConfig] [depthConfig]`。 +- 目录内 `depth_*.bin`、`depth_*_rect.png`、`depth_*_depth.png` 等为运行/调试时导出的示例产物(当前仓库内未保留),非源码。 + +**调用关系**:不被仓库其他代码调用;依赖外部 FaysSense VI Kit SDK(需 `FAYSSENSE_SDK_DIR` 指向 SDK Release 目录)。 diff --git a/collector/docs/file_format.html b/collector/docs/file_format.html new file mode 100644 index 0000000000000000000000000000000000000000..5a313d0c18358e67409457b00c947e130e1733ce --- /dev/null +++ b/collector/docs/file_format.html @@ -0,0 +1,471 @@ +数据文件接口契约 + + + +
+
+
录制数据落盘规范 · v1.1.2
+

数据文件接口契约

+

本文是录制数据落盘格式的规范性契约,供一切读写该数据的程序严格对齐:服务器导入器、离线处理工具、第三方数据读取器。标注 MUST 的条目写入方必须产出、读取方必须容忍;SHOULD 为建议。歧义以 core/helpers.py 与 core/egodata_writer.py 的实现为准。

+
+ format = "pooled_episodes_v1" + chunks_size = 1000 + v1.1.0 起任务级池化 + v1.1.1 stats 自含 count + v1.1.2 episode- 前缀命名 +
+
+
+ +
+
data/recordings/<task>/                          # <task> = 任务清洗名(可含中文)
+├── videos/
+│   └── chunk-{c:03d}/<image_key>/episode-{f:03d}.{ext}
+├── data/
+│   └── chunk-{c:03d}/episode-{f:03d}.parquet
+└── meta/
+    ├── info.json
+    ├── stats.json
+    ├── tasks.jsonl
+    ├── recycled_episode.json               # 异常终止回退标记,见 §7.5
+    └── episodes/
+        ├── .lock                            # 运行时锁锚点(旧分片回退路径),见 §7.4
+        └── chunk-{c:03d}/episode-{f:03d}.parquet   # 每 episode 一个文件(单行)
+
+ N = 1 → chunk-000 / episode-000 + N = 1000 → chunk-000 / episode-999 + N = 1001 → chunk-001 / episode-000 + chunk = (N−1) // 1000 · fnum = (N−1) % 1000 +
+
+ +
+ + +
+
+
§1

顶层布局与格式判别

+
    +
  • 格式判别MUST:读 meta/info.json 的 format 字段,"pooled_episodes_v1" 即本契约;format 缺失且存在 <task>_NNNNNN 子目录者为 v1.0 旧格式。
  • +
  • 任务目录内MUST NOT存在 calibration/、metadata.json、timestamps.json、每会话子目录(v1.0 遗留物)。
  • +
  • <task> 即任务名;上传/项目语义中「会话名」概念废除,任务名即项目名。
  • +
+
+ +
+
§2

编号规则

+

全局 episode 序号 N 从 1 起递增(跨该任务全部 episode;权威 = data/videos 文件组扫描与 tasks.json 进度水位取 max):

+
chunk = (N - 1) // 1000     # chunk-000 装 N=1..1000
+fnum  = (N - 1) % 1000      # 三位零起:episode-000 .. episode-999
+
    +
  • chunks_size = 1000(info.json 声明,服务器/工具按此计算,勿写死)。
  • +
  • 同一 episode 的MUST所有文件共用同一个 (chunk, fnum):视频各流、data parquet、episodes 每段文件(episode-005 = 第 6 个 episode,全部同名)。
  • +
  • 界面/上传的任务名后缀 = episode 文件号(0 基):第 N 段显示 _ep{(N-1)%1000:06d}(即 _ep000011 = 本地 episode-011)。回放/上传界面显示名、zip 内 arcname、上传表单 episode_index 值MUST三处同一号码(= 本地文件后缀);真实全局序号 N 只出现在 parquet 的 episode_index 列,不靠界面名反推。
  • +
  • 异常终止不占号:GUI「异常终止」丢弃的录制不消耗序号——中止时写下 meta/recycled_episode.json 标记(§7.5),下一次录制优先复用该号(即使进度水位已跑在前面也不跳号);正常完成即清标记。删除(含上传后自动删除)不回退:已完成的 episode 序号永不复用(服务器已持有该号)。
  • +
+
旧分片命名残留(读侧 MUST 容忍)
+ v1.1.0 早期曾用「每 chunk 一个分片」,分片文件名 = chunk 自身编号(chunk-000 → file-000.parquet,一个文件装该 chunk 内最多 1000 个 episode 的行)。该布局已废除,新写入一律每段一文件;读侧工具对旧分片按 episode_index 列过滤做回退,不靠文件名。v1.1.2 起每段文件前缀 episode-、分片保留 file- 前缀,两者路径不再重名。scripts/migrate_pooled_storage.py --split-episodes 可把旧分片原地拆成每段文件(幂等)。
+
+ +
+
§3

meta/info.json(任务级)

+

单 JSON 对象(可读缩进,无单行约束)。字段:

+
+ + + + + + + + + + + + + + + + + + + + + +
字段类型说明
formatstr"pooled_episodes_v1"(格式判别键)
chunks_sizeint1000
data_pathstr模板 data/chunk-{c:03d}/episode-{f:03d}.parquet
video_pathstr模板 videos/chunk-{c:03d}/{image_key}/episode-{f:03d}.{ext}
episodes_pathstr模板 meta/episodes/chunk-{c:03d}/episode-{f:03d}.parquet
codebase_versionstr数据代码基准版本(如 "v3.0",沿用服务器侧语义)
app_versionstr主程序版本(如 "1.1.0")
fpsfloat录制帧率(如 30.0)
videobool是否含视频
task_namestr任务名(= 目录名)
featuresobj只声明实际存在的列:action 恒在;observation.<sn> 每传感器一列;有 IMU 才有 observation.imu。形如 {"action": {"dtype": "float32", "shape": [1]}, "observation.right_glove": {"dtype": "float32", "shape": [256]}}
camerasobjRGB 相机键 → {height, width}(深度槽不入 cameras,见 video_extensions)
deviceslist设备紧凑注册:{key, kind, name, slots}(kind: d435/s80m/uvc…;slots 为该设备的 image_key 列表)
device_namesobjimage_key → 设备显示名
sensorslist任务级出现过的传感器名
sensor_dimint传感器观测维度(如 256)
created_atfloat任务创建时间(Unix 秒)
calibrationobj任务级最新标定(每设备一键,如 head_stereo,内容为 StereoCalibration.to_dict() 规范化结构:type/name/resolution/fps/baseline/left_camera/right_camera/depth_scale/cam_imu_timeshift,相机内参为 {intrinsic: [fx,fy,cx,cy], distortion: [...]})。多设备时以设备名/前缀消歧编号(d435_rgb_calibration 等)
total_episodesint当前 episode 数(上传删除不回退,见 §6)
video_extensionsobj每个 image_key → 扩展名(RGB=mp4,深度=mkv);深度是 mkv 不是 mp4,读侧MUST按此判文件,勿按 .mp4 硬猜
+
+ +
+
§4

meta/stats.json(任务级全局统计)

+

单 JSON 对象。每块 {count, mean, std, min, max},列表维度 = 列维度:

+
{
+  "observation.right_glove": {"count": 1196, "mean": [...256], "std": [...],
+                              "min": [...], "max": [...]},
+  "observation.imu":         {"count": 9922, "mean": [...6], "std": [...],
+                              "min": [...], "max": [...]},
+  "action": {"count": 0, "mean": [0.0], "std": [1.0], "min": [0.0], "max": [0.0]}
+}
+
    +
  • count 是累加器契约MUST:sum = mean × count、sum_sq = (std² + mean²) × count。写入方在每个 episode 结束后读入现有 stats.json、按公式合并本 episode 统计、原子写回;文件自身即持久累加器,不存在任何边车(.stats_state.json 已废除,读到即旧版残留,忽略即可)。
  • +
  • MUSTcount 恒存在。无 count 的块 = v1.1.0 旧格式,写入方须全量重扫 data/ 重建一次再增量合并(参考 core.helpers.recalc_stats)。
  • +
  • action 恒为占位块(count:0,仅声明列形状,不参与统计)。
  • +
  • 只统计实际存在的列:帧级 observation.<sn>(逐行计数,含全零行)、样本级 observation.imu(按样本计数);observation.*hand_pose 为恒写占位零列(后处理回填),不入统计。
  • +
  • 语义:删除 episode 不回退 stats(与任务进度水位一致);stats.json 是全任务聚合快照,不是逐 episode 重建值。
  • +
+
+ +
+
§5

meta/tasks.jsonl(单行 JSONL 是格式契约)

+
{"task_index": 0, "task": "D435-裸手_3D手部关键点识别_AI标注"}
+
    +
  • MUST每行一个完整 JSON 对象、且当前实现为单行;读取方必须 json.loads(f.readline()) 逐行解析。禁止美化/多行重排——多行会静默破坏首行读取器(task_index 变 0)。写入方只在文件不存在时创建。
  • +
+
+ +
+
§6

meta/episodes/(每段一个文件)

+

6.1 文件与原子性

+
    +
  • 每 episode 一个文件 chunk-{c:03d}/episode-{f:03d}.parquet(与 data/videos 同编号:episode-000 = episode 1),恒 1 行(10 列,见 §6.2)。
  • +
  • episode 结束时单行原子写:临时文件 + os.replace 原子替换;同号重录 = 覆盖该文件。读取方MUST容忍文件在任意时刻被原子替换(每次打开重新读取,勿缓存 fd)。
  • +
  • 新布局写入MUST NOT依赖 flock(单文件原子替换即完整);flock 锚点 .lock 仅剩旧分片回退的读-改-写路径使用(见 §7.4)。
  • +
  • 旧分片回退(读侧MUST容忍):v1.1.0 早期目录可能存在「每 chunk 一个分片」(文件名 = chunk 编号,≤1000 行,行序按 episode_index 升序)。读侧定位行必须按 episode_index 列过滤、不靠文件名(v1.1.2 起分片保留 file- 前缀、每段文件改 episode- 前缀,路径不再重名)。迁移工具 --split-episodes 可原地拆分(幂等)。
  • +
+

6.2 列(10 列)

+
+ + + + + + + + + + + +
列类型说明
episode_indexint64全局序号 N(1 起)
task_indexint64任务序号(现恒 0)
start_frame_indexint64首帧 frame_index
end_frame_indexint64末帧 frame_index
lengthint64帧数 = data parquet 行数
created_atfloat64episode 开始时间(Unix 秒)
duration_secfloat64时长(秒)
drop_statsstrJSON 字符串(如 {"imu_overflow": 0}),读取方须 json.loads
video_codecstrJSON 字符串:本机原始编码信息(encoder/codec/crf/ffmpeg 路径/probe);上传 zip 中的 mp4 可能已被再编码,见 §8
calibrationstrJSON 字符串:本 episode 标定(结构与 info.json 的 calibration 同型),保每 episode 标定保真
+
+ +
+
§7

data/(每 episode 一个 parquet)

+

data/chunk-{c:03d}/episode-{f:03d}.parquet,zstd 压缩,稀疏列(有数据才写该列)。

+

7.1 键列(恒有)

+
+ + + + + + + +
列类型说明
episode_indexint64= N
frame_indexint64帧内序号,0 起递增,无空洞(abort 不落盘)
timestampfloat32墙钟相对秒(episode 内相对,f32 精度够)
task_indexint64现恒 0
wall_timefloat64绝对 Unix 秒(宿主时钟锚)
hardware_nsint64设备时钟硬件时间戳(ns,可绕回);IMU 挂靠基准
+

7.2 观测列(稀疏)

+
+ + + + + + + + +
列类型说明
observation.<sn>list<float32, 256>每帧一个传感器读数(维度 = info.json sensor_dim)
imu_ts_nslist<int64>与 observation.imu 一一对应的样本时间戳
observation.imulist<list<float32, 6>>挂在帧行上的变长样本列表(1000Hz/400Hz 只是 list 长短变化)
observation.left_hand_poselist<float32, 63>恒写占位零,后处理回填(裸手 63 维 world landmarks)
observation.right_hand_poselist<float32, 63>同上
actionlist<float32, 1>恒写(现为 0)
status.<did>str稀疏设备状态列("connected"/"disconnected" 等)
+

7.3 时间对齐模型

+

表为帧行为主:一行 = 一个 30fps 帧;视频帧/传感器读数/帧行共用同一 frame_index(写入线程同拍产出)。IMU 为变长 list 列挂在帧行上,录制时按 hardware_ns 设备时钟窗口挂靠。读取零重采样;宿主时间锚定靠 timestamp + wall_time。客户 9 列平表由导出工具展开插值合成,非本契约内容。

+

7.4 meta/episodes/.lock(运行时辅助文件,非数据)

+

meta/episodes/.lock 是空文件,flock 锁锚点——旧分片回退的读-改-写用 os.replace 原子替换(inode 变化),锁必须挂在路径不变的锚文件上,故锚点为空文件、锁在 fd 上而非文件内容。新布局的每段文件写入是单文件原子替换,不走该锁。其他程序MUST忽略该文件(不解析、不打包、不告警);上传 zip 不含它(dotfiles 一律不进包)。

+

7.5 meta/recycled_episode.json(异常终止回退标记,非数据)

+

内容为单 JSON 对象 {"episode_index": <int>, "freed_at": "<ISO>"}。录制被「异常终止」时由写入器原子写入(临时件 + os.replace),标记该序号可复用;下一次录制取号时若该号未被文件组占用则优先复用;录制正常完成时清除,号已被占(跨机共享目录/遗留)时自动放弃。删除即彻底删除(v1.1.2 起无 _trash/ 回收区)。删除(含上传后自动删除)不写该标记——已完成的序号永不复用(见 §2)。其他程序MUST忽略该文件(不解析、不打包、不告警);上传 zip 不含它。

+
+ +
+
§8

videos/(每 episode 每流一文件)

+
    +
  • 路径 videos/chunk-{c:03d}/<image_key>/episode-{f:03d}.{ext},<image_key> 为槽名。同任务内不同 episode 之间允许槽改名(如 ep1 用 D435_depth_rgb、ep2 用 D435_head_rgb)——读侧MUST按 episodes 行的 image_key 枚举,勿假设任务级固定集合。
  • +
  • 扩展名以 info.json video_extensions 为准:RGB=mp4(HEVC/h264),深度=mkv。
  • +
  • 深度 MKV 两种布局(读侧MUST都支持,用 ffprobe/ffmpeg 的 stderr 探测 FFV1 流号): +
      +
    • 双流(v1.0.14+ 录制直出):流0 = 热力图 H.264(默认播放画面),流1 = FFV1 gray16le 无损 uint16 毫米深度;
    • +
    • 单流(迁移合成):仅一个 FFV1 gray16le 流。
    • +
    +
  • +
  • RGB 的 _aux 类辅助流归主 key 同一目录,非主键可忽略。
  • +
+
上传预压缩
zip 内 mp4 可能已被再编码为 HEVC(hvc1, CRF30)以缩小体积,与 episodes 行 video_codec(描述本机原始编码)不必一致;mkv 深度永不再编码。
+
+ +
+
§9

上传 zip 契约(给服务器导入器)

+

POST /api/v1/session/upload,端点不变。name 语义 = 任务名,form 字段 episode_index(字符串化的 episode 文件号——0 基,与本 episode 的 episode-{f:03d} 完全一致,见 §2「任务名后缀」;真实全局序号 N 以包内 parquet 的 episode_index 列为准;旧服务器忽略未知字段)。

+

zip = 单 episode 切片,包内 arcname 与原池化目录完全一致(相对任务目录):

+
videos/chunk-{c:03d}/<key>/episode-{f:03d}.{ext}    # 仅本 episode 的各流文件
+data/chunk-{c:03d}/episode-{f:03d}.parquet          # 本 episode 数据
+meta/episodes/chunk-{c:03d}/episode-{f:03d}.parquet # 本 episode 单行文件直传
+meta/info.json                                    # 任务级快照
+meta/stats.json                                   # 任务级快照(v1.1.1 含 count)
+meta/tasks.jsonl                                  # 任务级
+
    +
  • MUSTdotfiles(.lock、临时件)不进包;episodes 直传本 episode 的单行文件(旧分片回退时打成单行切片,arcname 同为新命名)。
  • +
  • 导入器以 info.json.format == "pooled_episodes_v1" 识别新格式。
  • +
  • 上传删除 = 删该 episode 文件组(videos/data 各 key 本 episode 文件),episodes 行、stats、total_episodes 不回退。
  • +
+
+ +
+
§10

关键点镜像布局(keypoints_output/)

+

后处理产物(手部关键点)按同一池化键镜像存放,与录制目录解耦:

+
keypoints_output/<task>/episode_{N:06d}/
+├── hand_pose/chunk-000.parquet        # 2D 关键点(MediaPipe 后端)
+├── auto_labels/auto_labels.parquet    # 自动标注
+└── hand_pose_3d/chunk-000.parquet     # 3D 关键点(bare 63 维 world landmarks,
+                                       #   回填 data parquet 两列的来源)
+

镜像目录内文件名不含 episode 号(父目录已键控),按帧 frame_index 与 data parquet 对齐。

+
+ +
+
§11

不属于架构的文件(忽略/不得依赖)

+
+ + + + + + + + +
文件/目录说明
meta/episodes/.lock运行时 flock 锚点,恒空
meta/recycled_episode.json异常终止回退标记(§7.5),完成即删
meta/.stats_state.jsonv1.1.0 边车残留,已废除,见即删
_trash/v1.1.1 及更早应用内删除的回收区残留;v1.1.2 起删除即彻底删除,不再产生
.{name}.tmp原子写临时件(os.replace 前身)
_episodes_{task_id}_{N}.parquet上传打包临时切片(仅旧分片回退路径产生),打完即删
_migrate_backup_*一次性迁移备份目录
+
+ +
+
§12

对齐检查清单(新程序接入逐项验证)

+
    +
  1. 读 info.json 判 format=="pooled_episodes_v1",未知 format 报错不猜。
  2. +
  3. 路径全部经模板 + (N→chunk,file) 计算,勿扫描拼接;chunks_size 读 info.json。
  4. +
  5. episodes 每段一个文件(file 编号 = data/videos 同编号);旧目录的多行分片按 episode_index 列过滤回退,勿按文件名对齐。
  6. +
  7. stats.json 每块必有 count;无 count 的旧块触发全量重算或忽略并告警。
  8. +
  9. tasks.jsonl 逐行 json.loads,写回保持单行。
  10. +
  11. 深度文件按 video_extensions 判 mkv,FFV1 流号探测,双流/单流都支持。
  12. +
  13. 视频槽名按 episodes 行枚举,容忍跨 episode 槽改名。
  14. +
  15. dotfiles 与临时件一律忽略;上传 zip arcname 与池化目录一致、episodes 带本 episode 单行文件、name=任务名 + form episode_index。
  16. +
  17. IMU 是变长 list 列,读取端展开时按 imu_ts_ns 对齐,勿假设固定采样率行宽。
  18. +
  19. 新布局 episodes 写入 = 单文件临时件 + os.replace 原子替换(无需 flock);旧分片回退的读-改-写必须走 flock(POSIX)+ 临时文件 + os.replace。
  20. +
+
+ +
+ 数据文件接口契约 v1.1.2 · 基准实现 core/helpers.py / core/egodata_writer.py · 仓库版 docs/file_format.md +
+
+
diff --git a/collector/docs/file_format.md b/collector/docs/file_format.md new file mode 100644 index 0000000000000000000000000000000000000000..4c16aa40f6f9dbb1ccf0ae28ae769b0bc1d7113c --- /dev/null +++ b/collector/docs/file_format.md @@ -0,0 +1,315 @@ +# 数据文件架构接口契约(v1.1.2) + +> 本文是录制数据落盘格式的**规范性契约**,供一切读写该数据的程序严格对齐: +> 服务器导入器、离线处理工具、第三方数据读取器。凡本文标注 **MUST** 的条目, +> 写入方必须产出、读取方必须容忍;标注 SHOULD 为建议。歧义以 `core/helpers.py` +> 与 `core/egodata_writer.py` 的实现为准。 + +v1.1.0 起录制数据从「每会话一个子目录」改为**任务级池化布局**(LeRobot v3 +命名)。v1.1.1 起 `stats.json` 自含累加器(每块加 `count`),`.stats_state.json` +边车已废除。**v1.1.2 起每段文件名前缀 `file-` 改为 `episode-`**(编号不变: +`file-011` → `episode-011`),应用内删除改为直接彻底删除(不再产生 `_trash/`); +**v1.1.2 起深度存储改单流 12-bit 灰度 HEVC MP4**(gray12le 对数深度码; +x265 无 12-bit 灰度能力时回落 FFV1 gray16le MKV;旧双流 MKV / PNG16 仅 +读侧容忍,见 §8)。 +旧格式(v1.0 每会话目录)仅存在于历史数据,读侧工具内部处理, +**本契约只定义新格式**。 + +--- + +## 1. 顶层布局与格式判别 + +``` +data/recordings// # = 任务清洗名(可含中文) +├── videos/ +│ └── chunk-{c:03d}//episode-{f:03d}.{ext} +├── data/ +│ └── chunk-{c:03d}/episode-{f:03d}.parquet +└── meta/ + ├── info.json + ├── stats.json + ├── tasks.jsonl + ├── recycled_episode.json # 异常终止回退标记,见 §7.5 + └── episodes/ + ├── .lock # 运行时锁锚点,见 §7.4 + └── chunk-{c:03d}/episode-{f:03d}.parquet # 每 episode 一个文件(单行) +``` + +- **格式判别**:读 `meta/info.json` 的 `format` 字段,`"pooled_episodes_v1"` + 即本契约;`format` 缺失且存在 `_NNNNNN` 子目录者为 v1.0 旧格式。 +- 任务目录内**没有** `calibration/`、`metadata.json`、`timestamps.json`、 + 每会话子目录(v1.0 遗留物)。 +- `` 即任务名;上传/项目语义中「会话名」概念废除,任务名即项目名。 + +## 2. 编号规则(MUST) + +全局 episode 序号 **N 从 1 起递增**(跨该任务全部 episode;权威 = data/ +videos 文件组扫描与 `tasks.json` 进度水位取 max): + +``` +chunk = (N - 1) // 1000 # chunk-000 装 N=1..1000 +fnum = (N - 1) % 1000 # 三位零起:episode-000 .. episode-999 +``` + +- `chunks_size = 1000`(info.json 声明,服务器/工具按此计算,勿写死)。 +- 同一 episode 的**所有文件共用同一个 (chunk, fnum)**:视频各流、data + parquet、episodes 每段文件(episode-005 = 第 6 个 episode,全部同名)。 +- **界面/上传的任务名后缀 = episode 文件号(0 基)**:第 N 段显示 + `_ep{(N-1)%1000:06d}`(即 `_ep000011` = 本地 `episode-011`)。回放/上传 + 界面显示名、zip 内 arcname、上传表单 `episode_index` 值**三处同一号码** + (= 本地文件后缀);真实全局序号 N 只出现在 parquet 的 + `episode_index` 列,不靠界面名反推。 +- **异常终止不占号**:GUI「异常终止」丢弃的录制**不消耗序号**——中止时 + 写下 `meta/recycled_episode.json` 标记(§7.5),下一次录制优先复用该号 + (即使进度水位已跑在前面也不跳号);正常完成即清标记。**删除(含上传后 + 自动删除)不回退**:已完成的 episode 序号永不复用(服务器已持有该号)。 + 删除即彻底删除(v1.1.2 起无 `_trash/` 回收区)。 +- **旧分片命名残留(读侧 MUST 容忍)**:v1.1.0 早期曾用「每 chunk 一个 + 分片」,分片文件名 = chunk 自身编号(chunk-000 → file-000.parquet, + 一个文件装该 chunk 内最多 1000 个 episode 的行)。该布局已废除,新写入 + 一律每段一文件;读侧工具(`episode_row`/上传/迁移)对旧分片按 + `episode_index` 列过滤做回退,**不靠文件名**。v1.1.2 起每段文件前缀 + `episode-`、分片保留 `file-` 前缀,两者路径不再重名。 + +## 3. meta/info.json(任务级,MUST 字段) + +单 JSON 对象(可读缩进,无单行约束): + +| 字段 | 类型 | 说明 | +|---|---|---| +| `format` | str | `"pooled_episodes_v1"`(格式判别键) | +| `chunks_size` | int | `1000` | +| `data_path` | str | 模板 `data/chunk-{c:03d}/episode-{f:03d}.parquet` | +| `video_path` | str | 模板 `videos/chunk-{c:03d}/{image_key}/episode-{f:03d}.{ext}` | +| `episodes_path` | str | 模板 `meta/episodes/chunk-{c:03d}/episode-{f:03d}.parquet` | +| `codebase_version` | str | 数据代码基准版本(如 `"v3.0"`,沿用服务器侧语义) | +| `app_version` | str | 主程序版本(如 `"1.1.0"`) | +| `fps` | float | 录制帧率(如 `30.0`) | +| `video` | bool | 是否含视频 | +| `task_name` | str | 任务名(= 目录名) | +| `features` | obj | **只声明实际存在的列**:`action` 恒在;`observation.` 每传感器一列;有 IMU 才有 `observation.imu`。形如 `{"action": {"dtype": "float32", "shape": [1]}, "observation.imu": {"dtype": "float32", "shape": [6]}, "observation.right_glove": {"dtype": "float32", "shape": [256]}}` | +| `cameras` | obj | RGB 相机键 → `{height, width}`(深度槽不入 cameras,见 `video_extensions`) | +| `devices` | list | 设备紧凑注册:`{key, kind, name, slots}`(kind: d435/s80m/uvc…;slots 为该设备的 image_key 列表) | +| `device_names` | obj | image_key → 设备显示名 | +| `sensors` | list | 任务级出现过的传感器名 | +| `sensor_dim` | int | 传感器观测维度(如 `256`) | +| `created_at` | float | 任务创建时间(Unix 秒) | +| `calibration` | obj | **任务级最新标定**(每设备一键:如 `head_stereo`,内容为 `StereoCalibration.to_dict()` 规范化结构:`type/name/resolution/fps/baseline/left_camera/right_camera/depth_scale/cam_imu_timeshift`,相机内参为 `{intrinsic: [fx,fy,cx,cy], distortion: [...]}`)。多设备时以设备名/前缀消歧编号(`d435_rgb_calibration` 等) | +| `total_episodes` | int | 当前 episode 数(上传删除不回退,见 §6) | +| `video_extensions` | obj | **每个 image_key** → 扩展名(RGB=`mp4`;深度=`mp4`=12-bit 灰度 HEVC、`mkv`=FFV1 回落);读侧必须按此判文件,勿按扩展名硬猜格式 | + +## 4. meta/stats.json(任务级全局统计,v1.1.1 契约) + +单 JSON 对象。**每块 {count, mean, std, min, max},列表维度 = 列维度**: + +```json +{ + "observation.right_glove": {"count": 1196, "mean": [...256 个], "std": [...], + "min": [...], "max": [...]}, + "observation.imu": {"count": 9922, "mean": [...6 个], "std": [...], + "min": [...], "max": [...]}, + "action": {"count": 0, "mean": [0.0], "std": [1.0], "min": [0.0], "max": [0.0]} +} +``` + +- **`count` 是累加器契约**:`sum = mean * count`、`sum_sq = (std² + mean²) * count`。 + 写入方在每个 episode 结束后**读入现有 stats.json、按公式合并本 episode 统计、 + 原子写回**;文件自身即持久累加器,**不存在任何边车**(`.stats_state.json` + 已废除,读到即旧版残留,忽略即可)。 +- **MUST**:`count` 恒存在。无 `count` 的块 = v1.1.0 旧格式,写入方须全量重扫 + `data/` 重建一次再增量合并(参考 `core.helpers.recalc_stats`)。 +- `action` 恒为占位块(`count:0`,仅声明列形状,不参与统计)。 +- 只统计实际存在的列:帧级 `observation.`(逐行计数,含全零行)、样本级 + `observation.imu`(按样本计数);`observation.*hand_pose` 为恒写占位零列 + (后处理回填),**不入统计**。 +- 语义:删除 episode 不回退 stats(与任务进度水位一致);stats.json 是全任务 + 聚合快照,不是逐 episode 重建值。 + +## 5. meta/tasks.jsonl(任务级,单行 JSONL 是格式契约) + +```jsonl +{"task_index": 0, "task": "D435-裸手_3D手部关键点识别_AI标注"} +``` + +- **MUST 每行一个完整 JSON 对象、且当前实现为单行**;读取方必须 + `json.loads(f.readline())` 逐行解析。**禁止美化/多行重排**——多行会静默破坏 + 首行读取器(task_index 变 0)。写入方只在文件不存在时创建。 + +## 6. meta/episodes/(episode 元数据,每段一个文件) + +### 6.1 文件与原子性 + +- **每 episode 一个文件** `chunk-{c:03d}/episode-{f:03d}.parquet`(与 data/videos + 同编号:episode-000 = episode 1),**恒 1 行**(10 列,见 §6.2)。 +- episode 结束时**单行原子写**:临时文件 + `os.replace` 原子替换;同号重录 = + 覆盖该文件。读取方 MUST 容忍文件在任意时刻被原子替换(每次打开重新 + 读取,勿缓存 fd)。 +- 新布局写入**不需要 flock**(单文件原子替换即完整);flock 锚点 `.lock` + 仅剩旧分片回退的读-改-写路径使用(见 §7.4)。 +- **旧分片回退(读侧 MUST 容忍)**:v1.1.0 早期目录可能存在「每 chunk 一个 + 分片」(文件名 = chunk 编号的 file-{c:03d}.parquet,≤1000 行,行序按 + `episode_index` 升序)。读侧定位行必须按 `episode_index` 列过滤、 + **不靠文件名**(v1.1.2 起分片保留 file- 前缀、每段文件改 episode- + 前缀,路径不再重名)。 + `scripts/migrate_pooled_storage.py --split-episodes` 可把旧分片原地拆成 + 每段文件(幂等)。 + +### 6.2 列(10 列,MUST) + +| 列 | 类型 | 说明 | +|---|---|---| +| `episode_index` | int64 | 全局序号 N(1 起) | +| `task_index` | int64 | 任务序号(现恒 0) | +| `start_frame_index` | int64 | 首帧 frame_index | +| `end_frame_index` | int64 | 末帧 frame_index | +| `length` | int64 | 帧数 = data parquet 行数 | +| `created_at` | float64 | episode 开始时间(Unix 秒) | +| `duration_sec` | float64 | 时长(秒) | +| `drop_stats` | str | **JSON 字符串**(如 `{"imu_overflow": 0}`),读取方须 `json.loads` | +| `video_codec` | str | **JSON 字符串**:本机原始编码信息(encoder/codec/crf/ffmpeg 路径/probe);上传 zip 中的 mp4 可能已被再编码,见 §8 | +| `calibration` | str | **JSON 字符串**:本 episode 标定(结构与 info.json 的 calibration 同型),保每 episode 标定保真 | + +## 7. data/(每 episode 一个 parquet) + +`data/chunk-{c:03d}/episode-{f:03d}.parquet`,zstd 压缩,**稀疏列**(有数据才写该列)。 + +### 7.1 键列(恒有) + +| 列 | 类型 | 说明 | +|---|---|---| +| `episode_index` | int64 | = N | +| `frame_index` | int64 | 帧内序号,0 起递增,无空洞(abort 不落盘) | +| `timestamp` | float32 | **墙钟相对秒**(episode 内相对,f32 精度够) | +| `task_index` | int64 | 现恒 0 | +| `wall_time` | float64 | **绝对 Unix 秒**(宿主时钟锚) | +| `hardware_ns` | int64 | 设备时钟硬件时间戳(ns,可绕回);IMU 挂靠基准 | + +### 7.2 观测列(稀疏) + +| 列 | 类型 | 说明 | +|---|---|---| +| `observation.` | list | 每帧一个传感器读数(维度 = info.json `sensor_dim`) | +| `imu_ts_ns` | list | 与 `observation.imu` **一一对应**的样本时间戳 | +| `observation.imu` | list> | 挂在帧行上的**变长样本列表**(1000Hz/400Hz 只是 list 长短变化) | +| `observation.left_hand_pose` | list | **恒写占位零**,后处理回填(裸手 63 维 world landmarks) | +| `observation.right_hand_pose` | list | 同上 | +| `action` | list | 恒写(现为 0) | +| `status.` | str | 稀疏设备状态列(`"connected"`/`"disconnected"` 等) | + +### 7.3 时间对齐模型(MUST 理解) + +**表为帧行为主**:一行 = 一个 30fps 帧;视频帧/传感器读数/帧行共用同一 +`frame_index`(写入线程同拍产出)。IMU 为变长 list 列挂在帧行上,录制时按 +`hardware_ns` 设备时钟窗口挂靠。读取零重采样;宿主时间锚定靠 `timestamp` + +`wall_time`。客户 9 列平表由导出工具展开插值合成,非本契约内容。 + +### 7.4 meta/episodes/.lock(运行时辅助文件,非数据) + +`meta/episodes/.lock` 是**空文件**,flock 锁锚点——旧分片回退的读-改-写用 +`os.replace` 原子替换(inode 变化),锁必须挂在**路径不变的锚文件**上,故锚点 +为空文件、锁在 fd 上而非文件内容。新布局的每段文件写入是单文件原子替换, +不走该锁。**其他程序 MUST 忽略该文件**(不解析、不打包、不告警);上传 zip +不含它(dotfiles 一律不进包)。 + +### 7.5 meta/recycled_episode.json(异常终止回退标记,非数据) + +内容为单 JSON 对象 `{"episode_index": , "freed_at": ""}`。录制被 +「异常终止」时由写入器**原子写入**(临时件 + `os.replace`),标记该序号 +可复用;下一次录制取号时若该号未被文件组占用则**优先复用**; +录制正常完成时清除,号已被占(跨机共享目录/遗留)时自动放弃。删除 +(含上传后自动删除)**不写**该标记——已完成的序号永不复用(见 §2)。 +**其他程序 MUST 忽略该文件**(不解析、不打包、不告警);上传 zip 不含它。 + +## 8. videos/(每 episode 每流一文件) + +- 路径 `videos/chunk-{c:03d}//episode-{f:03d}.{ext}`,`` 为 + 槽名(同任务内不同 episode 之间**允许槽改名**,如 ep1 用 `D435_depth_rgb`、 + ep2 用 `D435_head_rgb`——读侧必须按 episodes 行的 image_key 枚举,勿假设 + 任务级固定集合)。 +- 扩展名以 info.json `video_extensions` 为准:RGB=`mp4`(HEVC/h264), + 深度=`mp4`(12-bit 灰度 HEVC)或 `mkv`(FFV1 回落,仅 x265 无 12-bit + 灰度能力时产生)。 +- **深度视频(v1.1.2 起,MUST)**:单流 12-bit 灰度 HEVC MP4——hevc Rext + `gray12le` 单平面(对数深度码,qp=6、range=full、不带 profile;hvc1 + 容器标记),解码后按对数码反量化回 uint16 毫米(实现口径在 + `core/depth_codec.py` / `core/depth_reader.py`)。读侧注意:cv2 直读 + gray12le 的 8-bit 转换不可靠,像素一律走 ffmpeg CLI 解 gray12le。 +- **FFV1 回落(读侧 MUST 支持)**:x265 不可用时写 FFV1 `gray16le` 无损 + MKV(uint16 毫米原值),`video_extensions` 记 `mkv`。 +- **旧深度布局(读侧 MUST 容忍,仅历史数据)**: + - v1.0.14 双流 MKV:流0 = 热力图 H.264(默认播放画面),流1 = FFV1 + `gray16le` 无损 uint16 毫米深度(用 ffprobe/ffmpeg 的 stderr 探测 + FFV1 流号);v1.0.14 迁移合成的单流 MKV 同款; + - PNG16:v1.0.12 及更早的单帧 PNG 序列。 +- RGB 的 `_aux` 类辅助流归主 key 同一目录,非主键可忽略。 + +## 9. 上传 zip 契约(给服务器导入器,端点不变) + +`POST /api/v1/session/upload`,`name` 语义 = **任务名**,form 字段 +`episode_index`(字符串化的 **episode 文件号**——0 基,与本 episode 的 +`episode-{f:03d}` 完全一致,见 §2「任务名后缀」;真实全局序号 N 以包内 +parquet 的 `episode_index` 列为准;旧服务器忽略未知字段)。 + +zip = **单 episode 切片**,包内 arcname 与原池化目录完全一致(相对任务目录): + +``` +videos/chunk-{c:03d}//episode-{f:03d}.{ext} # 仅本 episode 的各流文件 +data/chunk-{c:03d}/episode-{f:03d}.parquet # 本 episode 数据 +meta/episodes/chunk-{c:03d}/episode-{f:03d}.parquet# 本 episode 单行文件直传 +meta/info.json # 任务级快照 +meta/stats.json # 任务级快照(v1.1.1 含 count) +meta/tasks.jsonl # 任务级 +``` + +- **MUST**:dotfiles(`.lock`、临时件)不进包;episodes 直传本 episode 的单行 + 文件(旧分片回退时打成单行切片,arcname 同为新命名)。 +- 导入器以 `info.json.format == "pooled_episodes_v1"` 识别新格式。 +- **HEVC 预压缩**:zip 内 mp4 可能已被再编码为 HEVC(hvc1, CRF30)以缩小体积, + 与 episodes 行 `video_codec`(描述本机原始编码)**不必一致**;mkv 深度永不再编码。 +- 上传删除 = 删该 episode 文件组(videos/data 各 key 本 episode 文件), + episodes 行、stats、total_episodes **不回退**。 + +## 10. 关键点镜像布局(keypoints_output/) + +后处理产物(手部关键点)按同一池化键镜像存放,与录制目录解耦: + +``` +keypoints_output//episode_{N:06d}/ +├── hand_pose/chunk-000.parquet # 2D 关键点(MediaPipe 后端) +├── auto_labels/auto_labels.parquet # 自动标注 +└── hand_pose_3d/chunk-000.parquet # 3D 关键点(bare 63 维 world landmarks, + # 回填 data parquet 两列的来源) +``` + +镜像目录内文件名不含 episode 号(父目录已键控),按帧 `frame_index` 与 +data parquet 对齐。 + +## 11. 不属于架构的文件(其他程序须忽略/不得依赖) + +| 文件/目录 | 说明 | +|---|---| +| `meta/episodes/.lock` | 运行时 flock 锚点,恒空 | +| `meta/recycled_episode.json` | 异常终止回退标记(§7.5),完成即删 | +| `meta/.stats_state.json` | v1.1.0 边车残留,**已废除**,见即删 | +| `_trash/` | v1.1.1 及更早应用内删除的回收区残留;v1.1.2 起删除即彻底删除,不再产生 | +| `.{name}.tmp` | 原子写临时件(`os.replace` 前身) | +| `_episodes_{task_id}_{N}.parquet` | 上传打包临时切片(仅旧分片回退路径产生),打完即删 | +| `_migrate_backup_*` | 一次性迁移备份目录 | + +## 12. 对齐检查清单(新程序接入逐项验证) + +1. 读 `info.json` 判 `format=="pooled_episodes_v1"`,未知 format 报错不猜。 +2. 路径全部经模板 + (N→chunk,file) 计算,勿扫描拼接;`chunks_size` 读 info.json。 +3. episodes 每段一个文件(episode- 编号 = data/videos 同编号);旧目录的多行 + 分片(file- 前缀)按 `episode_index` 列过滤回退,勿按文件名对齐。 +4. stats.json 每块必有 `count`;无 count 的旧块触发全量重算或忽略并告警。 +5. tasks.jsonl 逐行 `json.loads`,写回保持单行。 +6. 深度文件按 `video_extensions` 判扩展名;12-bit 灰度 MP4 走 ffmpeg + gray12le 解码 + 对数码反量化,FFV1 MKV 做流号探测(双流/单流都 + 支持),旧 PNG16 按历史回退读取。 +7. 视频槽名按 episodes 行枚举,容忍跨 episode 槽改名。 +8. dotfiles 与临时件一律忽略;上传 zip arcname 与池化目录一致、episodes 带 + 本 episode 单行文件、`name`=任务名 + form `episode_index`。 +9. IMU 是变长 list 列,读取端展开时按 `imu_ts_ns` 对齐,勿假设固定采样率行宽。 +10. 新布局 episodes 写入 = 单文件临时件 + os.replace 原子替换(无需 flock); + 旧分片回退的读-改-写必须走 flock(POSIX)+ 临时文件 + os.replace。 diff --git a/collector/docs/hand_detection.md b/collector/docs/hand_detection.md new file mode 100644 index 0000000000000000000000000000000000000000..a92546057daacaddcf35817b66af39416591a42b --- /dev/null +++ b/collector/docs/hand_detection.md @@ -0,0 +1,208 @@ +# tools/hand_detection/ + +## 定位 + +手部 2D 关键点检测共享库,向仓库内多套上层管线提供统一的手部检测能力。核心是两条路径:裸手路径 `MediaPipeHandPipeline`(MediaPipe HandLandmarker Tasks API,`hand_pipeline_mediapipe.py`),黑手套路径 `HandPipeline`(YOLO-World 检测 + RTMPose 关键点 + IoU 追踪,`hand_pipeline.py`)。目录无 `__init__.py`,以 Python 隐式命名空间包形式被导入;存在两种导入风格: + +- 包限定导入 `from hand_detection.xxx import ...`(依赖仓库根在 `sys.path`),如 `tools/stereo_s80m/hand_3d/detector.py:28`、`tools/hand_3d_d435/live_demo.py:73`、`tools/hand_3d_d435/render_overlay.py:24`。 +- 顶层导入 `import hand_common` / `from hand_pipeline import HandPipeline`(调用方先把本目录插入 `sys.path`),如 `core/hand_tracking.py:45-46,106,121,327`(主程序手部追踪模块)、`tools/stereo_s80m/render_stereo.py:57-62`(sys.path shim + `from hand_common import ...`,缺失回退内置简单画法)、`tools/hand_3d_d435/glove_detector.py:85-86`(sys.path shim 见 :66-74,顶层 `from glove_package.hand_tracker import HandTracker` / `from world_detector import ...`)。 + +被 import 的完整清单(package 限定):`tools/stereo_s80m/hand_3d/detector.py:28`、`tools/stereo_s80m/hand_3d/mp_gpu.py:34`、`tools/stereo_s80m/hand_3d/probes/probe_jitter.py:34`、`tools/stereo_s80m/hand_3d/renderer_3d.py:27`、`tools/stereo_s80m/hand_3d/run_pipeline.py:61`、`tools/stereo_s80m/hand_3d/smoother.py:26`、`tools/stereo_s80m/hand_benchmark.py:44`、`tools/stereo_s80m/hand_triangulate.py:67`、`tools/stereo_s80m/render_stereo.py:346`、`tools/hand_3d_d435/glove_detector.py:84`、`tools/hand_3d_d435/live_demo.py:73`、`tools/hand_3d_d435/render_overlay.py:24`。注意:`tools/glove_package/` 内含 `hand_common.py`、`hand_tracker.py`、`world_detector.py` 的同源副本(该包自包含);`tools/hand_3d_d435/glove_detector.py` 的 `hand_tracker` 为显式命名空间导入 `from glove_package.hand_tracker import HandTracker`(`hand_detection/` 下同源旧副本 sys.path 排前,裸导入会解析错、双阈值等新参数失效),`world_detector` 为顶层导入 `from world_detector import ...`(按 sys.path 顺序解析到本目录副本,见 :80-84 注释)。 + +MediaPipe 手部模型为仓库根 `tools/models/hand_landmarker.task`(HandLandmarker Tasks 模型);`tools/hand_detection/` 内也有一份内容相同的副本(`tools/hand_detection/hand_landmarker.task`,md5 一致),`config/settings.py:423` 的 `HAND_MEDIAPIPE_MODEL` 指向目录内副本。 + +## 文件清单 + +| 文件 | 一句话作用 | +| --- | --- | +| `tools/hand_detection/hand_pipeline_mediapipe.py` | MediaPipe 裸手 21 关键点管线 + One-Euro 滤波(`OneEuroFilter`/`OneEuroFilter2D`/`OneEuroFilter3D`)。 | +| `tools/hand_detection/hand_pipeline.py` | 黑手套模式统一入口:YOLO-World 检测 + RTMPose 关键点 + 追踪 + 冻结/遮挡。 | +| `tools/hand_detection/hand_tracker.py` | 基于 IoU 的跨帧手部身份追踪(`HandTrack` / `HandTracker`)。 | +| `tools/hand_detection/world_detector.py` | YOLO-World 开放词汇检测器(提示词 `hand`/`glove`)+ 两级 NMS 后处理。 | +| `tools/hand_detection/hand_common.py` | RTMPose 方案共用的 21 点定义、关节角度与绘制工具(不依赖 mediapipe)。 | +| `tools/hand_detection/demo_stereo_hands.py` | 双目视频手部关键点演示(左右目各自独立管线,输出 `keypoints_output/`)。 | +| `tools/hand_detection/test_smoothing.py` | One-Euro 平滑效果对比脚本(左原始 / 右平滑,并排输出视频)。 | + +附:目录内的非 `.py` 文件——`yolov8m-worldv2.pt` 是指向 `../glove_package/yolov8m-worldv2.pt` 的符号链接(YOLO-World 权重);`best.pt` 是自训 YOLO 回退权重(`config/settings.py:422` 的 `HAND_DET_MODEL` 指向它);`hand_landmarker.task` 为 MediaPipe 手部模型副本;`hand_pipeline_mediapipe.py.bak` 为旧版备份(非 `.py`,不参与导入)。 + +## 各文件详解 + +### tools/hand_detection/hand_pipeline_mediapipe.py + +**作用**:基于 MediaPipe HandLandmarker(Tasks API)的裸手关键点检测管线,是外部程序调用的统一入口。输出每只手 21 个关键点的像素坐标、归一化坐标、3D 世界坐标、左右手判定(`Left`/`Right`)、关节角度与伸直手指列表;内置 One-Euro 自适应低通滤波对像素坐标与世界坐标做抖动平滑。默认模型路径 `tools/models/hand_landmarker.task`(仓库根),模型缺失时抛 `FileNotFoundError` 并附下载 URL。管线运行在 `RunningMode.VIDEO` 模式下,内部持有跨帧追踪先验——左右目须各自独立实例,共享实例交替喂帧会污染追踪状态(`demo_stereo_hands.py:144-145` 注释:双手检出率 99.7% → ~50%)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `LANDMARK_NAMES` | 模块常量 | 21 点名称(`WRIST`、`THUMB_CMC`…`PINKY_TIP`) | — | +| `FINGERS` | 模块常量 | 五指 → (关键点下标 1-20, BGR 颜色),如 `Thumb: [1,2,3,4]` | — | +| `JOINT_SPECS` | 由 `_joint_specs()` 生成 | 15 个关节三元组 `(手指, 关节名, 顶点, 前点, 后点, 颜色)` | — | +| `OneEuroFilter` | `__init__(freq_min=1.0, beta=0.007, dcutoff=1.0)` | 单值 One-Euro 自适应低通滤波 | `__call__(x, ts_ms) -> float` | +| `OneEuroFilter2D` | 同上参数 | 对 `(x, y)` 分量独立滤波 | `__call__(x, y, ts_ms) -> (float, float)` | +| `OneEuroFilter3D` | 同上参数 | 对 `(x, y, z)` 分量独立滤波 | `__call__(x, y, z, ts_ms) -> (float, float, float)` | +| `_Preprocessor` | `__init__(gamma=0.4, clahe_clip=3.0, clahe_grid=8)` | 可选预处理(灰化/伽马/CLAHE),帮助深色手套场景 | `apply(bgr, mode)` 返回 RGB | +| `HandResult` | `__init__(index: int)` | 单只手结果容器 | 字段见"关键数据" | +| `FrameResult` | `__init__()` | 一帧完整结果容器 | `hands` / `raw_landmarks` / `raw_world` / `raw_handedness` | +| `MediaPipeHandPipeline` | `__init__(model_path="tools/models/hand_landmarker.task", num_hands=2, det_conf=0.5, track_conf=0.5, preprocess_mode="none", mirror=True, smooth=True, freq_min=5.0, beta=0.05, dcutoff=1.0)` | 构建 HandLandmarker 与滤波器状态 | 无 | +| `process` | `process(self, frame: np.ndarray) -> FrameResult` | 镜像 → 预处理 → 推理 → 组装/平滑 | 返回 `FrameResult` | +| `reset` | `reset(self) -> None` | 关闭 landmarker、清空滤波器状态(切换视频源时调用) | 重建 `_landmarker` | +| `close` | `close(self) -> None` | 释放 MediaPipe 资源 | 关闭 `_landmarker` | + +**关键数据**: + +- 关键点维度:每只手 21 点;`landmarks` 为 `(21, 2)` float32 像素坐标,`norm_landmarks` 为 21 个归一化 `(x, y)`(0-1),`world_landmarks` 为 21 个 3D 世界坐标 `(x, y, z)`。 +- `HandResult` 字段:`index`(结果序号)、`label`(`Left`/`Right`)、`score`、`landmarks`、`norm_landmarks`、`world_landmarks`、`angles`(`{(手指, 关节): 度数}`,基于 3D 世界坐标计算)、`extended`(伸直手指名列表)。 +- 伸直判定阈值:拇指 `MCP > 145` 且 `IP > 150`;其余四指 `PIP > 150` 且 `DIP > 140`。 +- 滤波默认参数:管线层 `freq_min=5.0`、`beta=0.05`、`dcutoff=1.0`(归一化空间速度量纲下 `beta` 需较大才有明显效果);`OneEuroFilter` 类本身默认 `freq_min=1.0`、`beta=0.007`、`dcutoff=1.0`。滤波状态按 `(手序号, 关键点序号)` 键惰性创建。 +- 镜像:`mirror=True` 时先 `cv2.flip(frame, 1)`,且左右手 label 在镜像后翻转。 +- 固定项:`min_hand_presence_confidence=0.5`;时间戳 `ts_ms` 以构造时刻为 0 的 `perf_counter` 毫秒。 + +**调用关系**:被上文"定位"列出的 14 处 import;主要使用方为 `tools/stereo_s80m/hand_3d/`(双目 3D 三角化链)、`tools/hand_3d_d435/`(D435 单目 3D 链)、`core/hand_tracking.py:327`(主程序裸手模式,顶层导入)、`tools/hand_detection/demo_stereo_hands.py:25`、`tools/hand_detection/test_smoothing.py:21`。依赖 `mediapipe`、`opencv-python`、`numpy`。 + +### tools/hand_detection/hand_pipeline.py + +**作用**:黑手套模式的手部检测 + 关键点推理统一入口 `HandPipeline`。流程:检测(`detector="world"` 走 `world_detector.WorldDetector`,否则用 `_YOLOWrapper` 加载自训 `.pt`)→ `HandTracker` 跨帧追踪 → 仅对需要推理的框跑 RTMPose 21 点 → `pose_is_glove` 无手套误检抑制 → 逐点置信度冻结 + 遮挡判断。默认检测器权重为 `MODEL_PATH = tools/hand_detection/yolov8m-worldv2.pt`(符号链接)。`det_imgsz` 默认 1280——注释说明 `best.pt` 对 640 缩放过敏感(同框 conf 掉到 0.4-0.65、位置漂移幻觉),1280 原生推理才能还原训练尺度下的检测质量。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `HandPipeline` | `__init__(detector="world", det_device="cpu", pose_device="cpu", max_hands=2, conf=0.05, det_imgsz=1280)` | 组装检测器(`WorldDetector` 或 `_YOLOWrapper`)、RTMPose 模型与 `HandTracker` | 无 | +| `process` | `process(frame: np.ndarray, apply_freeze: bool = True)` | 检测 → 追踪 → 关键点 → 误检抑制 → 冻结/遮挡 | 返回 `(boxes, kpts, scores, track_ids)`,`kpts` 为 `(N,21,2)` 或 `None` | +| `reset` | `reset(self) -> None` | 清空追踪状态(切换视频源时调用) | `_tracker.clear()` | +| `detector_name` | 属性 | 当前检测器名称(`WorldDetector` / `YOLO (best.pt)`) | 返回 str | +| `_apply_freeze` | `_apply_freeze(kpts, scores)` | 遮挡判定(低置信点占比 ≥ 阈值则整手冻结)+ 按手指粒度逐点冻结 | 原地修改 `kpts` | +| `_YOLOWrapper` | `__init__(weights, device, imgsz=1280)` | ultralytics YOLO 包装(回退权重路径) | `__call__(frame, conf)` 返回 `[[x1,y1,x2,y2,conf], ...]` | + +**关键数据**: + +- 检测参数:`conf=0.05`(world 后端)、`det_imgsz=1280`(YOLO 后端)、`max_hands=2`。 +- 追踪参数(传给 `HandTracker`):`iou_match_thr=0.3`、`lost_timeout=3`、`movement_thresh=3`、`skip_timeout=10`、`box_smooth_alpha=0.7`。 +- 冻结/遮挡:`kpt_freeze_thr=0.2`(逐点低置信阈值)、`occlusion_ratio=0.9`(低置信点占比 ≥ 0.9 判整手遮挡)。 +- 无手套误检抑制:`hc.pose_is_glove`(阈值见 `hand_common.py`),不通过则整帧清空输出。 + +**调用关系**:被 `core/hand_tracking.py:106` 以顶层 `from hand_pipeline import HandPipeline` 延迟导入(该文件已把 `tools/hand_detection/` 插入 `sys.path`;依赖 ultralytics/torch/rtmlib,缺失时抛带提示的 `ImportError`);`tools/demos/demo_glove_kpts/demo_glove_video.py` 与 `compare_detectors.py` 使用本管线。内部:`import hand_common as hc`、`import world_detector as wd`、`from hand_tracker import HandTracker`(文件开头把自身目录插入 `sys.path`)。 + +### tools/hand_detection/hand_tracker.py + +**作用**:手部身份追踪模块。用贪心 IoU 匹配做跨帧框关联,给每只手分配稳定 ID;每只手独立维护 `kpts`/`scores`/`last_good_kpts`/`skip_counter`/`lost_counter`,EMA 平滑检测框,短期记忆(连续丢失 ≤ `lost_timeout` 帧的 track 保持活跃但不跑推理)。设计动机(文件 docstring):框按置信度排序会导致帧间交换、按数组下标操作冻结缓存会错乱、检测丢失一帧就清空状态会导致 ID 跳变——本模块按 track 对象而非数组下标管理状态,避免上述问题。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `HandTrack` | dataclass | 一只手跨帧状态 | 字段:`id`/`box`/`raw_box`/`prev_center`/`kpts`/`scores`/`last_good_kpts`/`skip_counter`/`lost_counter`/`active` | +| `HandTracker` | `__init__(max_hands=2, iou_match_thr=0.3, lost_timeout=3, movement_thresh=3.0, skip_timeout=10, box_smooth_alpha=0.7)` | 初始化 track 列表与 ID 计数器 | 无 | +| `update_detections` | `update_detections(boxes: List[List[float]]) -> None` | 每帧必须调用:贪心 IoU 匹配 → 创建/更新 track → 老化丢失 track → EMA 平滑 → 限制活跃数 ≤ `max_hands` | 修改内部 tracks | +| `get_boxes_for_pose` | `get_boxes_for_pose()` | 挑出需要跑关键点推理的框(新 track / 移动超阈值 / skip 超时;丢失中的不跑) | 返回 `(boxes, indices)` | +| `update_pose_results` | `update_pose_results(indices, new_kpts, new_scores)` | 把 RTMPose 结果写入对应 track,记录框中心、清零 `skip_counter` | 无返回 | +| `get_results` | `get_results()` | 取活跃 track 的框/关键点/置信度/ID(无关键点的补零矩阵) | 返回 `(boxes, kpts, scores, track_ids)` | +| `update_last_good` | `update_last_good(track_index, point_index, value)` | 更新某 track 某关键点的冻结缓存 | 惰性创建 `last_good_kpts` | +| `get_last_good` | `get_last_good(track_index, point_index)` | 读冻结缓存 | 返回 `np.ndarray` 或 `None` | +| `clear` | `clear()` | 重置所有 track | 清空 `tracks`、`_next_id=0` | +| `hand_count` | 属性 | 当前活跃手数 | 返回 int | +| `_needs_pose` | `_needs_pose(track, movement_thresh, skip_timeout)` | 判断是否需要推理(无数据/超时/位移超阈值) | 返回 bool | +| `_smooth_box` | `_smooth_box(old, new, alpha)` | EMA 平滑框(alpha=0 不平滑,1 完全不动) | 返回列表 | +| `_greedy_match` | `_greedy_match(prev_boxes, curr_boxes, iou_thr)` | 按 IoU 降序贪心配对(`max_hands≤2` 时等价匈牙利算法,不依赖 scipy) | 返回 `(matches, unmatched_curr, unmatched_prev)` | + +**关键数据**:`kpts`/`scores` 维度 `(21, 2)` / `(21,)`;`last_good_kpts` 为逐点冻结缓存 `(21, 2)`。 + +**调用关系**:`from world_detector import iou`(顶层导入,依赖本目录在 `sys.path`)。被 `tools/hand_detection/hand_pipeline.py:35` 使用;`tools/glove_package/` 有同源副本(`tools/glove_package/hand_tracker.py`),`tools/hand_3d_d435/glove_detector.py:85` 为显式命名空间导入 `from glove_package.hand_tracker import HandTracker`(hand_detection 旧副本 sys.path 排前,裸导入会解析错)。 + +### tools/hand_detection/world_detector.py + +**作用**:YOLO-World 开放词汇手部检测器,提示词驱动免训练,是 `tools/glove_package/auto_label.py` 与 `infer.py` 的唯一真值来源(原先两处各写一份配置导致标注框与推理框不一致,统一收敛到本文件)。默认 `yolov8m-worldv2.pt` @ `imgsz=320`——docstring 记录了 40 张真实手套数据的实测:`yolov8m-worldv2@320` 召回 40/40、平均 IoU 0.780、22.6ms,优于 640 与 `yolov8x-worldv2`。提示词 `["hand", "glove"]` 会让同一只手被检出两次,因此后处理带两级 NMS(区分"同手重复检出"与"两手靠近")。`__call__` 接受 BGR numpy 帧,统一返回 `(boxes_xyxy [N,4], confs [N,])`。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| 常量 | `DEFAULT_MODEL="yolov8m-worldv2.pt"` / `DEFAULT_PROMPT=["hand","glove"]` / `DEFAULT_IMGSZ=320` / `DEFAULT_CONF=0.05` / `DEFAULT_NMS_IOU=0.6` | 检测器默认参数(标注与推理共用) | — | +| `WorldDetector` | `__init__(model=DEFAULT_MODEL, prompt=None, imgsz=DEFAULT_IMGSZ, device="cpu", nms_iou=DEFAULT_NMS_IOU, use_onnx=False)` | 按权重后缀选后端:`.pt` 走 `YOLOWorld`(GPU ~12ms/CPU ~85ms),`.onnx` 走 ultralytics YOLO ONNX(强制 CPU) | 无 | +| `__call__` | `__call__(src, conf=DEFAULT_CONF, max_boxes=1, wh=None, reuse_boxes=False)` | 推理 + 后处理;`reuse_boxes=True` 时复用上一帧结果(帧跳过) | 返回 `(boxes [N,4], confs [N,])` | +| `postprocess` | `postprocess(boxes, confs, w, h, max_boxes, nms_iou=DEFAULT_NMS_IOU)` 静态方法 | 裁入画面、丢弃 <8px 非法框、按置信度排序(不按面积)、两级 NMS、Top-N | 返回 `(boxes, confs)` | +| `postprocess_legacy` | `postprocess_legacy(...)` 静态方法 | 旧版纯 IoU 阈值 NMS,保留给兼容性测试 | 返回 `(boxes, confs)` | +| `iou` | `iou(a, b)` | 两框 IoU | 返回 float | +| `_center_close` | `_center_close(a, b, ratio=0.15)` | 中心距是否 < 较小框宽度的 15% | 返回 bool | +| `add_args` | `add_args(ap, max_boxes_default=1)` | 向 argparse 挂检测器公共参数(`--weights/--prompt/--imgsz/--conf/--max-boxes/--det-skip`) | 修改 `ap` | +| `from_args` | `from_args(args, device)` | 由解析结果构建 `WorldDetector` | 返回实例 | + +**关键数据**: + +- 两级 NMS 判据:中心距 < 框宽 15% 且 `IoU >= nms_iou`(0.6) → 视为同手重复,抑制;中心有偏移 → 视为两手靠近,仅 `IoU > 0.85` 才抑制。 +- 后处理过滤:框宽/高 ≥ 8px、坐标非有限值剔除。 +- 帧跳过缓存:`_last_boxes`,供 `reuse_boxes=True` 复用。 + +**调用关系**:被 `tools/hand_detection/hand_pipeline.py:34` 顶层导入;`tools/glove_package/auto_label.py:38`、`infer.py:29`、`hand_demo_mmpose.py:39` 顶层导入(`glove_package` 内自带副本 `world_detector.py`);`tools/hand_3d_d435/glove_detector.py:86` 顶层导入(`from world_detector import WorldDetector, iou`,按 sys.path 顺序解析到本目录副本)。依赖 `ultralytics`(`YOLOWorld`)、`numpy`。 + +### tools/hand_detection/hand_common.py + +**作用**:RTMPose 方案共用的手部关键点定义与绘制工具。关键点约定与 MediaPipe 完全一致(21 点同序:0 腕、1-4 拇指、5-8 食指、9-12 中指、13-16 无名指、17-20 小指),刻意不 import 父目录、不依赖 mediapipe(仅 cv2/numpy),使 `rtmpose`/glove 相关脚本可自包含运行。提供 2D 关节角度计算(图像平面,注意手指正对相机透视缩短时角度偏小,区别于 MediaPipe 管线的 3D 世界坐标角度)、五指分色绘制、RTMPose hand5 模型构建与"真手套"误检判定。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `FINGERS` | 模块常量 | 五指 → (下标, BGR 颜色),与 MediaPipe 同序 | — | +| `PALM_CONNECTIONS` | 模块常量 | 掌心连接 `(0,1),(0,5),(5,9),(9,13),(13,17),(0,17)` | — | +| `JOINT_SPECS` | 由 `joint_specs()` 生成 | 15 个关节三元组 | — | +| `angle_between` | `angle_between(p_prev, p_vertex, p_next)` | 顶点处两条骨段夹角(度,180° = 伸直) | 返回 float | +| `compute_joint_angles` | `compute_joint_angles(pts)` | 由 21 点 2D 坐标算全部关节角度 | 返回 `{(手指, 关节): 度}` | +| `count_extended_fingers` | `count_extended_fingers(angles)` | 伸直手指判定(阈值同 MediaPipe 管线:拇指 MCP>145/IP>150,其余 PIP>150/DIP>140) | 返回手指名列表 | +| `draw_hand` | `draw_hand(frame, pts, angles=None, show_angles=True, kpt_scores=None, thr=0.3)` | 绘制 21 点骨架(掌心灰线 + 五指分色 + 腕部白圆 + 角度标注);`kpt_scores` 低于 `thr` 的点画空心 | 原地修改 `frame` | +| `draw_panel` | `draw_panel(frame, x, y, lines, width=340)` | 半透明信息面板 | 原地修改 `frame` | +| `build_pose` | `build_pose(device="cpu")` | 构建 RTMPose hand5(21 点与 MediaPipe 同序,首次运行自动下载 ~56MB) | 返回 `RTMPose` 实例 | +| `auto_device` | `auto_device()` | 自动选择推理设备:CUDA > MPS > CPU | 返回 str | +| `pose_is_glove` | `pose_is_glove(kpts, scores, box, mean_thr=0.45, n_ok_thr=15, ok_thr=0.3, span_thr=0.3)` | 误检抑制:均值/高置信点数/点团 span 三条全过才判"真手套" | 返回 bool | + +**关键数据**: + +- `pose_is_glove` 三条判据(docstring 实测 2026-08-20):误检框关键点均值 0.20-0.31、≥0.3 高置信点 ≤10、点团 span ≤0.23×框对角线;真手套 0.64-0.81、21/21 高置信、span 0.55-0.79。 +- RTMPose 模型:`rtmpose-m_simcc-hand5_pt-aic-coco_210e-256x256-74fb594_20230320.zip`(OpenMMLab onnx SDK,输入 256×256,onnxruntime 后端)。 + +**调用关系**:被 `tools/hand_detection/hand_pipeline.py:33`(`import hand_common as hc`)、`tools/hand_detection/demo_stereo_hands.py:26`、`tools/hand_detection/test_smoothing.py:26`(包限定导入 `draw_hand`)、`core/hand_tracking.py:121`(顶层导入,主程序绘制复用)、`tools/stereo_s80m/render_stereo.py:59`(顶层导入,失败时回退本文件内置简单画法)。`tools/glove_package/hand_common.py` 为同源副本(`infer.py`、`verify_pose.py` 等顶层导入的是该副本)。 + +### tools/hand_detection/demo_stereo_hands.py + +**作用**:双目手部关键点演示脚本。同时打开左右目视频,分别用两个独立的 `MediaPipeHandPipeline` 实例逐帧检测(`mirror=False`,头戴式双目相机无需镜像),`draw_hand` 绘制关键点与角度,左右并排合成输出 mp4,最后用 ffmpeg 转 H.264(libx264 crf 23)便于播放。左右目各自独立实例的原因见注释:共享实例交替喂帧会污染 VIDEO 模式追踪先验,双手检出率从 99.7% 塌陷到 ~50%。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `draw_header` | `draw_header(frame, text, color=(255,255,255))` | 顶部半透明标题栏(LEFT/RIGHT CAMERA) | 原地修改 `frame` | +| `draw_info_overlay` | `draw_info_overlay(frame, hand_results, fps_val)` | 底部叠加 FPS、每只手 label/score/伸直手指 | 原地修改 `frame` | +| `process_and_draw` | `process_and_draw(pipe, frame)` | 单目检测 + 绘制 | 返回 `(标注帧, hands)` | +| `main` | `main()` | 打开视频 → 双管线循环 → 写临时 mp4 → ffmpeg 转码 | 输出 `keypoints_output/stereo_hands.mp4` | + +**关键数据**: + +- 默认输入:`data/recordings/Test1/Test1_000020/videos/stereo_left/chunk-0000/stereo_left.mp4` 与同路径 `stereo_right.mp4`(示例会话不在仓库内,需自备或用 `--left`/`--right` 覆盖)。 +- 输出:`keypoints_output/stereo_hands.mp4`(临时文件 `stereo_hands_tmp.mp4`,转码成功即删除);`VIEW_WIDTH = 640`(每目宽度)。 +- 管线参数:`num_hands=2`、`det_conf=0.5`、`track_conf=0.5`、`preprocess_mode="none"`、`mirror=False`、`smooth=True`、`freq_min=5.0`、`beta=0.05`;模型 `tools/models/hand_landmarker.task`(仓库根)。 +- ffmpeg 候选:`FFMPEG_CANDIDATES` 依次尝试 `shutil.which("ffmpeg")`、`/usr/bin/ffmpeg`、环境变量 `FFMPEG_BIN` 指定的路径、`~/miniconda3/envs/lerobot/bin/ffmpeg`(注释说明 conda base 的 ffmpeg 因 openvino/tbb 符号错误不可用);全部失败则保留原始 mp4v 临时文件。 + +**调用关系**:`from hand_detection.hand_pipeline_mediapipe import MediaPipeHandPipeline`(:25)、`from hand_detection.hand_common import draw_hand`(:26)。独立运行入口(`python tools/hand_detection/demo_stereo_hands.py`)。 + +### tools/hand_detection/test_smoothing.py + +**作用**:One-Euro 平滑效果对比测试脚本。对同一段视频用单个 `MediaPipeHandPipeline`(`smooth=True`)处理,输出左右并排视频:左侧画原始关键点(取自 `FrameResult.raw_landmarks`,未滤波),右侧画平滑后的关键点 + 关节角度,直观对比滤波去抖效果。末尾用 ffmpeg 转 H.264。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `draw_landmarks_simple` | `draw_landmarks_simple(frame, pts, color=(0,255,0), label="")` | 简化画法:21 点 + 五指连线(无角度) | 原地修改 `frame` | +| `draw_info_bar` | `draw_info_bar(frame, frame_idx, total, fps, hand_count)` | 顶部信息栏(帧号/FPS/手数/左右说明) | 原地修改 `frame` | +| `raw_pixel_coords` | `raw_pixel_coords(lms, w, h)` | MediaPipe 原始归一化 landmark 转像素坐标(无滤波) | 返回 `(21, 2)` float32 | +| `main` | `main()` | 读视频 → 管线循环 → 并排合成 → 转码 | 输出 `keypoints_output/smoothing_comparison.mp4` | + +**关键数据**: + +- 默认输入:`data/recordings/Project_812/Project_812_000005/videos/head_left_rgb/chunk-0000/head_left_rgb.mp4`(示例会话不在仓库内,需自备或改 `main()` 中的路径)。 +- 输出:`keypoints_output/smoothing_comparison.mp4`(临时 `smoothing_comparison_tmp.mp4`);输出宽度 = 输入 2 倍(左右并排)。 +- 管线参数与 `demo_stereo_hands.py` 一致:`num_hands=2`、`det_conf=0.5`、`track_conf=0.5`、`mirror=False`、`smooth=True`、`freq_min=5.0`、`beta=0.05`、`dcutoff=1.0`;模型 `tools/models/hand_landmarker.task`。 +- ffmpeg:直接调用 `"ffmpeg"` 命令(libx264 crf 23),失败时保留 mp4v 临时文件并打印 stderr 尾部(本脚本未使用 `demo_stereo_hands.py` 的 `FFMPEG_BIN` 候选逻辑)。 + +**调用关系**:`from hand_detection.hand_pipeline_mediapipe import (MediaPipeHandPipeline, FINGERS, JOINT_SPECS)`(:21-25)、`from hand_detection.hand_common import draw_hand`(:26)。独立运行入口。 diff --git a/collector/docs/images/fig-1-1.png b/collector/docs/images/fig-1-1.png new file mode 100644 index 0000000000000000000000000000000000000000..450bdc6f80c8ccb0cd5cdee54df85d7961667c82 --- /dev/null +++ b/collector/docs/images/fig-1-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0380b1e650cfb4b1d0ba290ed8239497b9d107f35a32460f1fd133210acb1e2c +size 62347 diff --git a/collector/docs/images/fig-2-1.png b/collector/docs/images/fig-2-1.png new file mode 100644 index 0000000000000000000000000000000000000000..bbdb600301fe02840385f32d6b00b250a4f9eea6 --- /dev/null +++ b/collector/docs/images/fig-2-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cec06fa3117e48b6e12bccebacbf2aece33c01609812f23a166c99286b7f80c8 +size 28517 diff --git a/collector/docs/images/fig-2-2.png b/collector/docs/images/fig-2-2.png new file mode 100644 index 0000000000000000000000000000000000000000..03f60cf3de153f518720e507244a3e4eadd9f9e9 --- /dev/null +++ b/collector/docs/images/fig-2-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d2b1e9af4798d5e532ffabd5b529be2a437cb044d072ca71852186ed595c712 +size 32231 diff --git a/collector/docs/images/fig-3-1.png b/collector/docs/images/fig-3-1.png new file mode 100644 index 0000000000000000000000000000000000000000..36a8e6fb748988f7c4431b4c63a17c5454058e12 --- /dev/null +++ b/collector/docs/images/fig-3-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:af070f6433dd56f86ddbdd53473ee0295788490b0b04615a3d4b23e9f0c8c06c +size 22328 diff --git a/collector/docs/images/fig-3-2.png b/collector/docs/images/fig-3-2.png new file mode 100644 index 0000000000000000000000000000000000000000..851066b2604892da9c4c2a5759236e2505e37d7a --- /dev/null +++ b/collector/docs/images/fig-3-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c8465b949d62890c68935418b3f21747226d9f066d6b7c2f396a61fb9dacbdf +size 143257 diff --git a/collector/docs/images/fig-3-3.png b/collector/docs/images/fig-3-3.png new file mode 100644 index 0000000000000000000000000000000000000000..dd8d7e19841754ccbeba7fafe9b117f480b12a87 --- /dev/null +++ b/collector/docs/images/fig-3-3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:721113355baced5e679902079e117efb25d1de9c2a3de8a683ee860222a1e255 +size 2135277 diff --git a/collector/docs/images/fig-3-4.png b/collector/docs/images/fig-3-4.png new file mode 100644 index 0000000000000000000000000000000000000000..fc3aeb91e6a89ffed0559dbf7a28a85ecb110682 --- /dev/null +++ b/collector/docs/images/fig-3-4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37e8027327ae6581d6e95168c161659e88384badc7b09b6a149051d5860b4b83 +size 65863 diff --git a/collector/docs/images/fig-3-5.png b/collector/docs/images/fig-3-5.png new file mode 100644 index 0000000000000000000000000000000000000000..012c1e97846a448f2dfa10148f85e9f750e69217 --- /dev/null +++ b/collector/docs/images/fig-3-5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed7904887ccfb0fdd6c7c2bddb34f17a2f85a6b8456642be6231c90ce89f08b2 +size 24346 diff --git a/collector/docs/images/fig-3-6.png b/collector/docs/images/fig-3-6.png new file mode 100644 index 0000000000000000000000000000000000000000..6a1981d5fce3fd1e5af9270ecc0e99243c6d213a --- /dev/null +++ b/collector/docs/images/fig-3-6.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d50900b6dc48124d52f7bf9665ffe99a4a09e890b48b1a94be91f005fc301eb3 +size 110559 diff --git a/collector/docs/images/fig-3-7.png b/collector/docs/images/fig-3-7.png new file mode 100644 index 0000000000000000000000000000000000000000..b952e930e573298b46176f942b9aceb537306d4a --- /dev/null +++ b/collector/docs/images/fig-3-7.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0f3aff1bc7e08d9b838cd412a70885386fa3d8610715e750047a5e40aa91cde +size 483580 diff --git a/collector/docs/images/fig-4-1.png b/collector/docs/images/fig-4-1.png new file mode 100644 index 0000000000000000000000000000000000000000..81db7eceb81f9ef7f269df1c9d12db40ae2f547d --- /dev/null +++ b/collector/docs/images/fig-4-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d80464bd86194854de7f8670bf10daf1c3f9790e620f2b9b5de6ea5c5724582c +size 9525 diff --git a/collector/docs/images/fig-5-1.png b/collector/docs/images/fig-5-1.png new file mode 100644 index 0000000000000000000000000000000000000000..d8233451943e44e4f95443cee8d4ef088af540c5 --- /dev/null +++ b/collector/docs/images/fig-5-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16318f0f8020916d9fbc7f73d12a7a49c23dada7ff72411b1c8e51fb1e42627b +size 5947 diff --git a/collector/docs/images/fig-5-2.png b/collector/docs/images/fig-5-2.png new file mode 100644 index 0000000000000000000000000000000000000000..8f90d1419e884cfb5b40c00a3510dfcdc11ea2cf --- /dev/null +++ b/collector/docs/images/fig-5-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c57a85fd6aa1c6e3736d88dc688c59b4d6d2847a447cc0190127fb30bd945c0 +size 79281 diff --git a/collector/docs/images/fig-6-1.png b/collector/docs/images/fig-6-1.png new file mode 100644 index 0000000000000000000000000000000000000000..6b264d2183e1d16a6742719cb95093f86f56d6b4 --- /dev/null +++ b/collector/docs/images/fig-6-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d57088ae5f89e9f89b874f96910f1c8826bb1b4193ce0b79817841db2db62dc +size 45965 diff --git a/collector/docs/images/fig-6-2.png b/collector/docs/images/fig-6-2.png new file mode 100644 index 0000000000000000000000000000000000000000..330e517a871f92b738943c1e29b195a347bfc131 --- /dev/null +++ b/collector/docs/images/fig-6-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3612acb79877a334414a80373eb3b1021f56ca2a51b94b906de21b65016996ea +size 175218 diff --git a/collector/docs/images/fig-6-3.png b/collector/docs/images/fig-6-3.png new file mode 100644 index 0000000000000000000000000000000000000000..eae4959fd5559bf6c868d985d560eb0df735e249 --- /dev/null +++ b/collector/docs/images/fig-6-3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fd6887094d573c0144dbd8c9ae7d68fefcc9a9bf8d63cdac5e7a7890f4c83a8 +size 922408 diff --git a/collector/docs/images/fig-6-4.png b/collector/docs/images/fig-6-4.png new file mode 100644 index 0000000000000000000000000000000000000000..eaa020600fdba8802a42e3171e799a65c6f783e0 --- /dev/null +++ b/collector/docs/images/fig-6-4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20e609a270acd0acb8a2249ceca8b6f85d8b2e945547f835febe9bbd0963933a +size 858340 diff --git a/collector/docs/images/fig-6-6.png b/collector/docs/images/fig-6-6.png new file mode 100644 index 0000000000000000000000000000000000000000..6117b398da63a21df605556b9c1f82253990340a --- /dev/null +++ b/collector/docs/images/fig-6-6.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1efab42be006d30f6d3caa3957e7ec2c567b8796bdb452b2774ef0ab95feb432 +size 16552 diff --git a/collector/docs/images/fig-7-1.png b/collector/docs/images/fig-7-1.png new file mode 100644 index 0000000000000000000000000000000000000000..d1a2a5074126d10df2f89cc46f62d3e684bc221a --- /dev/null +++ b/collector/docs/images/fig-7-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:949f223f248fe629229680f747f7d94bbd013bfd6cea35aa51b92bf6e126a7d4 +size 487823 diff --git a/collector/docs/images/fig-7-2.png b/collector/docs/images/fig-7-2.png new file mode 100644 index 0000000000000000000000000000000000000000..6747761c71386af0b49d8ba43129fe57130335d2 --- /dev/null +++ b/collector/docs/images/fig-7-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8b6bb2b2dba7228e60a0d6cd006c47da13c7f813a406b953866aa31b832db39 +size 41742 diff --git a/collector/docs/images/fig-7-3.png b/collector/docs/images/fig-7-3.png new file mode 100644 index 0000000000000000000000000000000000000000..cf50b7cb5bcaa3348afde2edd75205d9f15c2043 --- /dev/null +++ b/collector/docs/images/fig-7-3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64a6f181b359f3d762b4c432576cc55657366bda7afa610d0976b1ba67a1afb6 +size 64656 diff --git a/collector/docs/images/fig-7-4.png b/collector/docs/images/fig-7-4.png new file mode 100644 index 0000000000000000000000000000000000000000..d3535cdc8d7b32d63a5f5720ba8c2ab9ae04f045 --- /dev/null +++ b/collector/docs/images/fig-7-4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:21d9075b2f2023836cd5c0b26806bd347d6c4aac524149fa5a867eee06299eb3 +size 448338 diff --git a/collector/docs/images/fig-8-1.png b/collector/docs/images/fig-8-1.png new file mode 100644 index 0000000000000000000000000000000000000000..a525749e095e35745b60fde61e5ddcd4184ddb18 --- /dev/null +++ b/collector/docs/images/fig-8-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5a1731fbd2943ad8868957b8e0579180b406e7dc0276749d4b8757af5c54fcb +size 318684 diff --git a/collector/docs/images/fig-8-3.png b/collector/docs/images/fig-8-3.png new file mode 100644 index 0000000000000000000000000000000000000000..1ef7a340f29b99c2a9f718facd3d7309651729cb --- /dev/null +++ b/collector/docs/images/fig-8-3.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3982239b8371ff81b5c1642fb98871c52df53a76ba719c2e33b043ad8f18fd82 +size 44717 diff --git a/collector/docs/images/fig-8-4.png b/collector/docs/images/fig-8-4.png new file mode 100644 index 0000000000000000000000000000000000000000..a99b959c14653bd7b0b6eecc386b6eba4b125fd0 --- /dev/null +++ b/collector/docs/images/fig-8-4.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a50abdd290571098e77a703bf46b297b8dcffd5d64a23977a5472d125e31f38 +size 50312 diff --git a/collector/docs/images/fig-8-5.png b/collector/docs/images/fig-8-5.png new file mode 100644 index 0000000000000000000000000000000000000000..6d490314aa529567b541ef969db6066ade485948 --- /dev/null +++ b/collector/docs/images/fig-8-5.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4849f07c84f21cc986fa65ae954415e6e1db32dd357c556ee8d0cdbaf6e9ff4 +size 91692 diff --git a/collector/docs/images/fig-8-6.png b/collector/docs/images/fig-8-6.png new file mode 100644 index 0000000000000000000000000000000000000000..e222f92bd7a77013bdd30e381204ab5cd97e0b7b --- /dev/null +++ b/collector/docs/images/fig-8-6.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfdc9b55bff1bdd044d85c3d2434d0df7f91afedc5ea66061271348a7f533ad6 +size 55144 diff --git a/collector/docs/images/fig-9-1.png b/collector/docs/images/fig-9-1.png new file mode 100644 index 0000000000000000000000000000000000000000..e9042474c431f7f2b474a707ea72e9e87c50b360 --- /dev/null +++ b/collector/docs/images/fig-9-1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1640ffd016ed3fea62769bddf0fcc6c8f99aa9dfc0457267c1d961595d60f4b +size 42711 diff --git a/collector/docs/images/fig-9-2.png b/collector/docs/images/fig-9-2.png new file mode 100644 index 0000000000000000000000000000000000000000..faaf1f73f2059968615fd694306d4b10f7206b14 --- /dev/null +++ b/collector/docs/images/fig-9-2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58954f7b1d4018a22ac7c5379a7262ca167acfc2efd880b0d093b178dd887ab0 +size 663632 diff --git a/collector/docs/index.md b/collector/docs/index.md new file mode 100644 index 0000000000000000000000000000000000000000..d835a8767bb3a68b39069225a341ad3cb800123a --- /dev/null +++ b/collector/docs/index.md @@ -0,0 +1,233 @@ +# collector 仓库总览 + +collector 是一个基于 PyQt5 的数据采集 GUI 系统:多相机(UVC 摄像头、Intel +RealSense D435/D405、S80M 双目)与 BLE 数据手套的同步录制、回放与 HTTP 上传; +配套手部 3D 关键点处理链路(`tools/hand_detection/`、`tools/hand_3d_d435/`、 +`tools/stereo_s80m/`)与离线 SLAM 数据集导出。采集输出为 EgoData / LeRobot v3 +兼容格式,供机器人遥操作数据集使用。 + +## 快速开始 + +### 主程序 + +仓库自带虚拟环境 `venv/`(含 PyQt5、OpenCV、pyarrow、pyrealsense2 等), +依赖清单见 `requirements.txt`。 + +```bash +./run.sh # 等价于 venv/bin/python main.py +venv/bin/python main.py # 直接启动 +``` + +Windows 下用 `run.bat`(自动设置 Qt 平台插件路径后运行 `main.py`)。 +若本机没有 `venv/`,先创建: + +```bash +python -m venv venv && venv/bin/pip install -r requirements.txt +``` + +说明:`pyrealsense2`、`opencv-python`、`torch` 等未列入 `requirements.txt` +(按需在 venv 内安装;`main.py` 对 torch 做可选导入,缺失时自动跳过)。 + +首次运行无需手动建配置:`data/tasks.json` 在首次读取时由程序写入内置种子 +任务;`data/server_config.json`、`data/device_names.json`、 +`data/device_params.json` 在首次保存对应设置时自动创建(模板文件仅作结构 +参考,不会自动复制为真实配置)。`data/pipeline.db` 在首次启动时建表。 + +### 主程序界面 + +`main.py` 启动的 `MainWindow`(`ui/main_window.py`)提供: + +- 可拖拽调整大小的多画面网格布局(回放界面同样支持视频拖拽调位、分割条调大小); +- 每路摄像机独立的录制控制——正常停止保存,异常停止丢弃(`abort_episode` 直接删除会话目录); +- 录制历史记录追踪(SQLite)与回放(`ui/playback_dialog.py`); +- 设备检测面板(统一枚举 UVC/D435/S80M 设备,2 秒轮询)、任务页、上传页; +- 中英文界面切换(`config/i18n.py`,`tr()` 翻译 + `lang_manager`)。 + +### 手部 3D 关键点(D435) + +```bash +./tools/hand_3d_d435/run_live_d435.sh # 实时 demo(直连相机) +./tools/hand_3d_d435/run_live_d435.sh --replay <会话目录> # 回放会话 +./tools/hand_3d_d435/run_d435.sh <会话目录> # 离线管线 +``` + +两个 launcher 均通过 `VENV_PY` 环境变量选择解释器(默认仓库 `venv/bin/python`)。 + +### Demos + +```bash +./tools/demos/run_stereo_depth_demo.sh # S80M 深度引擎 demo(需 SDK,见下) +venv/bin/python tools/demos/test_stereo_depth_calib.py # 双目深度标定自检(需 SDK) +venv/bin/python tools/hand_detection/demo_stereo_hands.py # 双目 + MediaPipe 手部 demo +``` + +`tools/demos/stereo_2d_demo/` 是自带 README/requirements/run.sh 的独立小包; +`tools/demos/` 下另有 `demo_glove_kpts/`、`hdf5_demo_v1.4/`、`HSV_Visualizer_V4.4.1.py`。 + +### 测试 + +```bash +venv/bin/python tools/tests/test_device_detector.py # 设备枚举 +venv/bin/python tools/tests/test_depth_heatmap.py # 深度热力图 +# 真机相关测试需连接对应设备:d435_*、s80m_*、device_panel_gui_smoke_test 等 +``` + +`tools/tests/` 内 `d405_worker_test.py`、`d435_e2e_test.py`、`s80m_50fps_decimation_test.py` +等覆盖 D405/D435 采集与 S80M 抽帧逻辑,`mono_regression.py`、 +`s80m_signal_regression.py` 为回归测试。 + +## 环境变量约定 + +### `FAYSSENSE_SDK_DIR`(仅独立 S80M 工具必需) + +FaysSense VI Kit SDK 的安装路径(Release 目录)。以下工具依赖它, +**未设置时直接报错退出**: + +- `tools/demos/run_stereo_depth_demo.sh`(也接受 `SDK_DIR`;且要求 SDK 内已构建 + `thirdparty/opencv-4.2.0-linux-x86_64/lib406`) +- `tools/demos/stereo_depth_demo/run.sh`、`tools/demos/stereo_depth_demo/build.sh` +- `tools/demos/test_stereo_depth_calib.py` +- `tools/stereo_s80m/capture_calibration.py` +- `tools/diag_color.py`、`tools/diag_frame_layout.py` + +示例:`export FAYSSENSE_SDK_DIR=/path/to/VIKitRelease` + +主程序 S80C/S80M 采集链路不使用此变量——仓库自带 SDK 副本与全部依赖 +(见下方硬件支持表),git 克隆后无需安装 SDK 即可运行。 + +### `FFMPEG_BIN`(可选) + +ffmpeg 可执行文件覆盖。默认兜底 +`~/miniconda3/envs/lerobot/bin/ffmpeg`(`~` 自动展开),候选列表逐个自检、 +第一个可用者胜出。使用处: + +- `tools/stereo_s80m/render_stereo.py`:候选顺序 `which ffmpeg` → `/usr/bin/ffmpeg` + → `$FFMPEG_BIN`(未设则 lerobot 路径) +- `tools/stereo_s80m/hand_3d/video_writer.py`:`$FFMPEG_BIN`(未设则 lerobot 路径) + 优先,再 `which ffmpeg` / `/usr/bin/ffmpeg` 兜底 +- `tools/hand_detection/demo_stereo_hands.py`:与 `render_stereo.py` 相同候选顺序 + +注意:录制器 `core/egodata_writer.py` 不走 `FFMPEG_BIN`——它优先使用 +`imageio_ffmpeg` 自带的静态 ffmpeg,其次取 PATH 中通过 `-version` 自检的 +`ffmpeg`(conda 版曾因 openvino/tbb 符号错误启动即崩,自检不通过即弃用)。 + +### `VENV_PY`(可选) + +launcher 脚本使用的 Python 解释器,默认 `$REPO_ROOT/venv/bin/python`: + +```bash +VENV_PY=/path/to/python ./tools/hand_3d_d435/run_live_d435.sh +``` + +使用处:`tools/hand_3d_d435/run_live_d435.sh`、`tools/hand_3d_d435/run_d435.sh`。 + +## 目录总览 + +| 目录 | 作用 | 文档 | +|---|---|---| +| `config/` | 全局配置:路径/相机/录制/上传常量(`settings.py`)、中英文文案(`i18n.py`)、S80M 标定副本与 `config/sensors/` 手套仿生手掌映射 | `docs/config.md` | +| `core/` | ★ SDK 核心(平铺,30 个模块):采集管线(`pipeline.py`/`camera.py`/`d435_camera.py`/`device_detector.py`)、设备管理器(`device_manager.py`/`s80m_manager.py`/`d435_manager.py`/`device_naming.py`/`exposure_controller.py`)、录制落盘(`egodata_writer.py`/`calibration.py`/`database.py`/`recording_record.py`/`recording_repository.py`/`task_record.py`)、上传后端(`api_client.py`/`task_service.py`/`uploader.py`)、回放会话(`session_timeline.py`/`session_catalog.py`/`session_loader.py`)、手部(`hand_tracking.py`/`hand_processor.py`/`auto_labeler.py`)、手套传感(`ble_engine.py`/`render_engine.py`/`sensor_config_dialogs.py`/`sensor_hand_config.py`)、通用(`helpers.py`/`stereo_depth.py`) | `docs/core.md` | +| `data/` | 本地配置(仓库提供 `*.example.json` 模板与出厂默认 `device_params.json`;其余配置、录制数据、SQLite 均 gitignore) | `docs/data.md`(本文档集) | +| `tools/demos/` | 交付版 demo:S80M 深度引擎 demo、双目 2D demo、手套关键点 demo、hdf5 演示、标定自检脚本 | `docs/demos.md` | +| `tools/hand_detection/` | 手部检测:YOLO 手套检测(`best.pt`、`world_detector.py`)、MediaPipe 裸手管线、`demo_stereo_hands.py` | `docs/hand_detection.md` | +| `scripts/` | 录制后离线处理:手部关键点提取/标注/可视化导出(`process_hands.py`) | `docs/scripts.md` | +| `tools/stereo_s80m/` | S80M 双目工具:`read_stereo_rgb.py`、`stereo_triangulate.py`、`render_stereo.py`、`hand_3d/`、离线 SLAM 导出(`export_offline_slam_dataset.py`、`validate_offline_dataset.py`) | `docs/stereo_s80m.md` | +| `tools/` | 诊断与手部 3D 工具:`diag_*.py`、`hand_3d_d435/`(独立 D435 3D 手部管线模块)、`hand_3d_s80c/`(S80C 双目实时裸手/手套关键点 demo,含自包含 SDK)、`fayssense_depth_sdk/`(FaysSense VI Kit 深度引擎 SDK,专有)、`glove_package/`、`tests/`(回归/冒烟测试)、`weights/`(大权重)、`models/`(模型权重) | `docs/tools.md` | +| `ui/` | PyQt5 界面:`main_window.py`、`camera_grid.py`、`playback_dialog.py`(回放)、`upload_dialog.py`、`task_page.py`、`device_panel.py`(设备检测面板)等 | `docs/ui.md` | +| `tools/models/` | 模型权重:`hand_landmarker.task`(MediaPipe 裸手关键点,供 `tools/hand_detection/demo_stereo_hands.py` 等使用) | — | +| `keypoints_output/` | 录制后手部关键点输出(镜像录制目录结构,gitignore) | — | +| `dist/` | 自包含 demo 发布包(gitignore) | — | +| `venv/`、`tools/weights/` | 虚拟环境、CLIP 等大权重(均 gitignore) | — | +| `docs/` | 本文档目录 | — | + +### 根目录文件 + +| 文件 | 说明 | +|---|---| +| `main.py` | 主入口:qt-material `dark_teal` 暗色主题;先做 torch 可选导入(避免 DLL 冲突),并修复 cv2 覆盖 `QT_QPA_PLATFORM_PLUGIN_PATH` 导致的 Qt 平台插件加载问题,然后启动 `ui.main_window.MainWindow` | +| `start.bat` / `start.sh` | Windows / Linux 一键部署:无 Python 时自动安装、建 venv、装依赖并启动主程序;子命令 `reinstall` / `extras` / `extras-torch` / `help` | +| `.gitattributes` | 换行符规范化:`*.bat` 强制 CRLF,保证客户从 GitLab 下载后双击可用 | +| `requirements.txt` | 核心依赖:PyQt5、numpy(<2)、pyarrow、imageio-ffmpeg、bleak、qt-material、h5py、requests、pygrabber、comtypes、pyvista、pyvistaqt | +| `.gitignore` | 排除录制数据(`data/recordings/`、`data/*.db`)、真实配置文件、venv、keypoints_output、大权重等 | +| `run.sh` / `run.bat` | Linux / Windows 启动脚本(使用 venv 解释器运行 `main.py`) | +| `README.md` | 仓库说明(开发者向,中英双语合并版:英文在前、中文在后,顶部章节导航表) | +| `使用说明.md` / `使用说明_EN.md` | 客户操作指引与错误码 A–G 排查(中英两版;`start.bat help` 与启动弹窗引用) | +| `tools/gongsitubiao.png` | 界面 logo(`ui/main_window.py`、`ui/task_page.py` 引用) | + +## 数据链路速览 + +``` +录制 ──► core/pipeline.py(相机帧 + BLE 手套数据汇聚) + └─► core/egodata_writer.py(EgoDataWriter) + └─► data/recordings/<任务>/<任务>_NNNNNN/(MP4 + Parquet + 元数据) + │ + ├─► 回放:ui/playback_dialog.py(兼容 EgoData / LeRobot v3 会话) + ├─► 上传:core/uploader.py → POST /api/v1/session/upload + │ (服务器地址见 data/server_config.json,可自动同步/删本地) + └─► 离线处理: + tools/stereo_s80m/(三角化 stereo_triangulate.py、 + 渲染 render_stereo.py、离线 SLAM 数据集导出) + tools/hand_3d_d435/(D435 RGB-D 3D 手部关键点) + tools/hand_detection/ + scripts/(手套/裸手关键点) + └─► 输出到 keypoints_output/<任务>/<会话>/(不写回录制目录) +``` + +- 任务进度:`data/tasks.json` 由 `core/task_record.py` 维护,进度按分账模型 + 持久化(`local_count` 本机完成数 / `synced_count` 已确认水位 / + `backend_count` 后端全局数,显示值 `completed_count = backend_count + + (local_count - synced_count)`),与本地文件是否被删除无关;多电脑协同 + 采集时经 `POST /api/v1/device/tasks/progress` 水位合并上报,后端聚合全局数。 +- 录制历史与上传队列:`data/pipeline.db`(表 `recording`、`upload_task`)。 +- 目录结构与各元数据字段详见 `docs/data.md`。 + +## 开发约定 + +- **版本号**:唯一定义在 `config/__init__.py`(`__version__`),各模块经 + `config.settings.APP_VERSION` 引用,录制元数据写入 `codebase_version`。 +- **设备命名**:EgoData 标准 `<位置>_<模态>`,如 `head_left_rgb` / + `head_right_rgb` / `head_depth`;触觉传感器 `right_glove` / `left_glove`; + 手部关键点 `right_hand_pose` / `left_hand_pose`(见 `config/settings.py`)。 + UVC 槽位按索引映射:0 → `head_left_rgb`、1 → `head_right_rgb`、 + 2+ → `head_right_rgb_N`。 +- **PyQt5 信号参数**:可能超过 32 位整数范围的参数(如纳秒时间戳)一律用 + `object` 类型声明(`pyqtSignal(object)`)——`int` 参数会按 qint32 封送, + 超过 2^31 静默翻负。 +- **SQLite**:`core/database.py` 线程本地连接 + WAL 模式; + 上传后删除本地文件的录制行保留为 `uploaded_deleted`、上传成功但本地保留 + 标为 `uploaded`,均供历史可查。 +- **任务进度**:`completed_count` 是持久化权威值,不依赖扫描录制目录 + (上传后自动删本地也不会回退);`hidden` 是删除墓碑,防后端推送复活。 +- **i18n**:界面文案经 `config/i18n.py` 的 `tr()` 翻译,勿在 UI 代码中硬编码 + 中英文混用文案。 + +## 硬件支持 + +| 设备 | 接入方式 | 说明 | +|---|---|---| +| UVC 相机 | `/dev/videoN`(OpenCV V4L2) | MJPG 像素格式(`settings.UVC_FOURCC`);单目镜像显示;最多 8 路 | +| Intel RealSense D435 / D405 | `pyrealsense2` | RGB + depth 双路槽位(如 `d435_rgb` / `d435_depth`);深度原始 uint16 PNG16(毫米)+ 热力图 MP4;内置停滞/帧率看门狗自动重连;D405 有独立采集配置(近距) | +| S80M 双目 | FaysSense VI Kit SDK(仓库自带,含 FT602 桥驱动) | 无需安装 SDK / 设置 `FAYSSENSE_SDK_DIR`;深度引擎依赖仓库自带 OpenCV 4.2(`lib406` 目录);相机档 `STEREO_CAM_FPS`(默认 50fps)+ 回调取帧(官方 GUI 同款)按 1/30s 桶抽帧录制 30fps;携带硬件纳秒时间戳与 IMU 样本;v1.0.11 起子进程内置 SDK 深度引擎(`tools/hand_3d_s80c/third_party`,~20fps)→ 第三格实时深度热力图 + 录制 raw16/热力图 MP4(`S80M_DEPTH_ENABLED=False` 关闭) | +| BLE 数据手套 | `bleak`(core/ble_engine.py) | 左右手各一只;parquet 列名绑定(`right_glove` / `left_glove`)按设备 MAC 持久化在 `data/device_names.json` 中 | + +## 隐私与本地配置 + +- 真实配置文件**不进仓库**:`data/server_config.json`、`data/device_names.json`、 + `data/tasks.json` 以及 `data/*.db`、`data/recordings/` 均被 `.gitignore` + 排除;仓库只提供模板 `server_config.example.json`、 + `device_names.example.json`、`tasks.example.json`(结构见 `docs/data.md`)。 +- `server_config.json` 可能包含服务器地址与登录凭据,`device_names.json` + 的 key 含设备序列号/MAC——这些文件务必保持本地私有。 +- `SERVER_URL` 出厂默认值为 `http://127.0.0.1:8000`(`config/settings.py`), + 用户可在界面填写实际服务器地址并持久化。 +- `data/device_params.json`(曝光设置)出厂为空对象 `{}`,仓库内默认文件 + 本身不含敏感信息;但其 key 与 `device_names.json` 同为设备稳定标识, + 本地增长后可能含序列号/MAC,修改过的文件请勿提交。 + +## 相关文档 + +各模块细节见 `docs/` 下的分文档: + +- `docs/data.md` — `data/` 配置与数据存储结构(本文档集) +- `docs/config.md`、`docs/core.md` — 配置、SDK 核心(采集/设备管理器/录制落盘/上传/回放/手套传感) +- `docs/ui.md`、`docs/scripts.md` — 界面、离线脚本 +- `docs/demos.md`、`docs/stereo_s80m.md`、`docs/tools.md`、`docs/hand_detection.md` — demo、S80M、工具与手部检测 diff --git a/collector/docs/scripts.md b/collector/docs/scripts.md new file mode 100644 index 0000000000000000000000000000000000000000..c9d05c107bf0641f5da95cbcdb328c6890b847bf --- /dev/null +++ b/collector/docs/scripts.md @@ -0,0 +1,65 @@ +# scripts/ + +## 定位 + +`scripts/` 提供两类离线 CLI:对已录制会话的离线批处理(手部关键点提取与手势标注、可视化渲染导出),以及 Windows 离线部署包打包。`process_hands.py` 在开头把仓库根目录插入 `sys.path`,从任意位置以 `python scripts/xxx.py ...` 运行即可(`pack_wheels.py` 只依赖标准库,无此 shim)。 + +主程序不调用这些脚本(全库检索 `scripts/` 除 `scripts/` 自身外无任何引用)。`process_hands.py` 反向依赖 `core/`(`core.hand_tracking` 与 `core.helpers`);`pack_wheels.py` 零 core 依赖。 + +## 文件清单 + +| 文件 | 一句话作用 | 运行方式 | +|---|---|---| +| `scripts/process_hands.py` | 手部关键点提取(2D+可选 3D)、手势自动标注、可视化渲染,子命令 `kpts/label/all/show/render` | `python scripts/process_hands.py kpts --mode bare` | +| `scripts/pack_wheels.py` | 生成 Windows 3.12 离线部署包(`wheels/`:依赖轮子 + Python 安装包),供客户无外网一键安装 | `python scripts/pack_wheels.py [--extras|--torch|--out]` | + +## 各文件详解 + +### `scripts/process_hands.py` + +**作用**:手部关键点提取 CLI,对已录制会话离线处理。`kpts` 子命令调 `core/hand_tracking.process_session()` 提取关键点(`glove`/`bare` 双模式);`label` 子命令做手势自动标注;`render` 子命令把已有 2D 关键点叠加回视频导出可视化;`show` 查看已有数据摘要。它是整条离线后处理链的入口。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `_progress_bar` | `(cur, total, width=40)` | 写 stderr 的进度条 | — | +| `cmd_kpts` | `(args)` | 调 `process_session()` 提取关键点 | 成功打印帧数/耗时/fps,失败 `sys.exit(1)` | +| `cmd_label` | `(args)` | 调 `label_session()` 手势自动标注 | 同上 | +| `cmd_all` | `(args)` | 先 `cmd_kpts` 再 `cmd_label` | — | +| `cmd_show` | `(args)` | 调 `load_hand_kpts()` 打印数据摘要(帧数/维度/最多手数) | — | +| `_find_video` | `(session_path)` | 在 session 目录找第一个非 depth 的 RGB 视频(egodata 格式先查 metadata 相机列表,再扫 `videos/` 与 `chunk-0000/`) | 返回视频路径或 `""` | +| `cmd_render` | `(args)` | 关键点叠加到视频导出:ffmpeg 子进程(`libx264 -crf 23`)优先,`avc1`/`mp4v` 的 `cv2.VideoWriter` 回退 | 写 `_hand_kpts.mp4` | +| `main` | 子命令解析 | — | — | + +**关键数据**: +- 子命令与参数: + - `kpts [--mode glove|bare] [--device cuda]`(默认 `glove`、`cuda`) + - `label ` + - `all [--mode] [--device]` + - `show ` + - `render `(无附加参数) +- 输入:会话目录(如 `data/recordings/Test005/episode_000001`);egodata 格式视频路径经 `core.helpers.egodata_video_path` 解析。 +- 输出:关键点 parquet 落盘由 `core/hand_tracking` 负责(路径口径 `core.helpers.hand_kpts_parquet_path`);`render` 输出到 `keypoints_video_dir(session)/<相机名>_hand_kpts.mp4`。 + +**调用关系**:导入 `core.hand_tracking`(`process_session`、`label_session`、`load_hand_kpts`、`draw_kpts_overlay`);`cmd_render` 内部使用 `core.helpers`(`detect_session_format`、`egodata_video_path`、`egodata_metadata_path`、`keypoints_video_dir`)。不被主程序调用。 + +### `scripts/pack_wheels.py` + +**作用**:生成 Windows 离线部署包(`wheels/` 目录),供 `start.bat`/`start.sh` 在无外网环境一键安装。在任意有网机器(Linux 开发机即可,跨平台拉取 Windows 轮子)上运行,把产出的 `wheels/` 整个目录拷到客户项目根目录后,启动脚本检测到 `wheels/*.whl` 自动改走纯离线安装。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +|---|---|---|---| +| `parse_requirements` | `(path)` | `requirements.txt` → 包规格列表(去注释/空行) | list[str] | +| `download_closure` | `(specs, out, ...)` | 拉取依赖闭包:优先 `uv pip compile --python-platform windows` 跨平台解析(正确剔除 Linux-only 依赖如 bleak 的 dbus-fast),无 uv 回退 `pip download` | 写 `/*.whl` | +| `download_python_installer` | `(out)` | 下载 `python-3.12.10-amd64.exe`(阿里云/npmmirror/华为云镜像回退) | 写 `/python-3.12.10-amd64.exe` | +| `main` | 参数解析 | — | — | + +**关键数据**: +- 参数:`--extras`(+ mediapipe / pyrealsense2)、`--torch`(+ CPU 版 torch,走阿里云/官方 CPU 索引)、`--out `(默认 `wheels/`)、`--no-python-installer` +- 镜像链:阿里云 → 清华 → 官方源(与 start.bat 安装顺序一致) +- 产物:`/*.whl`(Windows 3.12 依赖闭包)+ `/python-3.12.10-amd64.exe` + +**调用关系**:不 import 仓库任何模块(纯标准库);产物被 `start.bat`/`start.sh` 的离线安装逻辑消费。 diff --git a/collector/docs/stereo_s80m.md b/collector/docs/stereo_s80m.md new file mode 100644 index 0000000000000000000000000000000000000000..f40b3b07bd7583393b8eac66122482d0324b8b04 --- /dev/null +++ b/collector/docs/stereo_s80m.md @@ -0,0 +1,556 @@ +# tools/stereo_s80m/ + +## 定位 + +`tools/stereo_s80m/` 是 S80M 双目相机(FaysSense VI Kit)的**全部处理代码**,自包含独立模块:只读复用 `tools/hand_detection/`(MediaPipe 检测管线),不修改主程序(`ui/`、`core/`)。覆盖完整链路:出厂标定捕获/导出 → 双目三角化 → 3D 手部两阶段管线(`hand_3d/` 子包)→ 骨架渲染 → 离线 ORB-SLAM 数据集导出与本地校验 → 相机 RGB 读取(`read_stereo_rgb.py`,含 `/dev/videoN` 端口自动解析)。 + +被哪些模块使用(引用证据): + +- 主程序以**子进程**方式运行 `tools/stereo_s80m/read_stereo_rgb.py`,帧经 stdout 管道传回:`core/s80m_manager.py:6`(模块注释注明目录内含 `libfays_vikit.so` (3.9.0) + `fays_vikit.yaml`)、`core/s80m_manager.py:37-42`(`STEREO_DEMO`/`STEREO_AVAILABLE` 路径常量,锚定仓库根不随 cwd 漂移)、`ui/main_window.py:703`(`_open_s80m`,面板开关启动子进程)。 +- D435 工具包大量复用 `hand_3d/` 子包: + - `tools/hand_3d_d435/live_demo.py:65-71`(`MediaPipeDetector`、`HandednessVoter`、`HandSlotTracker`、`Hand3DSmoother`、`RotatingSkeletonRenderer`、`create_video_sink`、`io`) + - `tools/hand_3d_d435/run_pipeline_d435.py:37-43`(同上全套) + - `tools/hand_3d_d435/mono_assign.py:34`、`fill_track.py:32`(`HandSlotTracker`) + - `tools/hand_3d_d435/glove_detector.py:76`(`DetectedHand`) + - `tools/hand_3d_d435/tools/render_keypoints_parquet.py:46-47`(`RotatingSkeletonRenderer`、`create_video_sink`) + - `tools/hand_3d_d435/probes/probe_live_consistency.py:39-42`、`probe_align_overlay.py:57-58` +- 包内自用:`hand_3d/` 依赖本目录的 `stereo_triangulate.py`(三角化几何)与 `render_stereo.py`(叠加渲染);`render_stereo.py:50`、`hand_benchmark.py:45`、`hand_triangulate.py:73` 等。 + +目录内另有非 Python 数据:`tools/stereo_s80m/lib/fays_atrak/x86_64/Release/libfays_vikit.so`(FaysSense SDK 动态库)与 `tools/stereo_s80m/config/fays_vikit.yaml`、`fays_vikit_50fps.yaml`(SDK 配置,`--config` 可切换 50fps 副本)。`tools/stereo_s80m/dist/` 为交付目录;`tools/stereo_s80m/offline_slam_output/` 为产物目录(首次运行 `export_offline_slam_dataset.py` 后生成,仓库内不保留),见文末说明。 + +## 文件清单 + +| 文件 | 一句话作用 | +| --- | --- | +| `tools/stereo_s80m/capture_calibration.py` | 从 SDK 出厂标定静态 yaml(`FAYSSENSE_SDK_DIR` 环境变量定位)生成设备级 `config/s80m_stereo_calibration.json`,可选 `--live` 连相机校验 | +| `tools/stereo_s80m/export_calibration.py` | 通过 ctypes 从设备 ROM 读取标定,写会话级 `calibration/head_stereo.json` + 设备级 JSON + DumpCalib yaml 备份 | +| `tools/stereo_s80m/read_stereo_rgb.py` | S80M 双目 RGB 读取:ctypes 调 SDK 取左右目帧/IMU,`--pipe` 二进制管道或窗口预览,含设备端口自动解析与曝光控制 | +| `tools/stereo_s80m/stereo_triangulate.py` | 双目三角化几何核心:标定加载、fisheye/radtan 双路径矫正、三角化、跨目手匹配、自检 | +| `tools/stereo_s80m/render_stereo.py` | 骨架叠加渲染模块:3D/2D 单帧叠加、视频写器与 H.264 转码、parquet 纯渲染重放 | +| `tools/stereo_s80m/hand_triangulate.py` | 单阶段后处理脚本:左右目视频跑 MediaPipe → 三角化 → LeRobot 风格 parquet + 可视化视频 | +| `tools/stereo_s80m/hand_benchmark.py` | 手势检测参数基准:分辨率 × 帧率 × 颜色 × 单双目扫描,输出稳定性指标 CSV | +| `tools/stereo_s80m/export_offline_slam_dataset.py` | EgoData 会话 → 离线双目惯性 SLAM 数据集(ORB-SLAM3 格式,矫正灰度 PNG + CSV + orb_calibration.yaml) | +| `tools/stereo_s80m/validate_offline_dataset.py` | 离线 SLAM 数据集本地验收:复刻客户侧 FileStorage 格式检查与官方 rectify 一致性校验 | +| `tools/stereo_s80m/hand_3d/__init__.py` | 子包入口:从 `run_pipeline` 导入 `main` 供包外引用(无 `__main__` 执行块,管线入口仍是 `run_pipeline.py`) | +| `tools/stereo_s80m/hand_3d/detector.py` | 2D 检测抽象层:`KeypointDetector` 接口 + `MediaPipeDetector`(float 亚像素,CPU/GPU 双后端) | +| `tools/stereo_s80m/hand_3d/identity.py` | 手性投票 `HandednessVoter`:轨迹票仓多数表决,压掉 MediaPipe handedness 逐帧闪烁 | +| `tools/stereo_s80m/hand_3d/track3d.py` | 槽位跟踪 + 遮挡传播:`HandSlotTracker` αβ 滤波预测 3D,`make_pseudo_pair` 生成伪 pair 救援 | +| `tools/stereo_s80m/hand_3d/smoother.py` | 3D 域因果时序平滑:`Hand3DSmoother` 逐点 One-Euro,防跨手状态污染 | +| `tools/stereo_s80m/hand_3d/perspective_crop.py` | 两阶段透视裁剪精修(Hur et al. 2025):3D 投影取 ROI → 裁剪图重检测 → 二次三角化 | +| `tools/stereo_s80m/hand_3d/mp_gpu.py` | MediaPipe GPU delegate 直连封装 `FastHandLandmarker` + 子进程冒烟测试 | +| `tools/stereo_s80m/hand_3d/postprocess.py` | 离线后处理:`fill_gaps` 间隙插值 + `offline_smooth` 零相位速度自适应平滑 | +| `tools/stereo_s80m/hand_3d/renderer_3d.py` | 3D 旋转视角骨架渲染器 `RotatingSkeletonRenderer`(numpy+cv2 透视投影,零额外依赖) | +| `tools/stereo_s80m/hand_3d/io.py` | 数据 IO:会话元数据读取 + LeRobot 风格 parquet 打包/落盘 + meta 合并 | +| `tools/stereo_s80m/hand_3d/video_writer.py` | 管道视频写器:ffmpeg 子进程单段直出 H.264(nvenc → libx264 → mp4v 逐级回退) | +| `tools/stereo_s80m/hand_3d/run_pipeline.py` | 两阶段管线主流程 + CLI:检测 → 配对 → 三角化 → 精修 → 平滑 → 渲染 → parquet | +| `tools/stereo_s80m/hand_3d/probes/probe_compare3.py` | 探针:单阶段 vs 两阶段双配置硬对比(指标 CSV + 并排视频 montage) | +| `tools/stereo_s80m/hand_3d/probes/probe_jitter.py` | 探针:P5 抖动验收——三列 jitter 对比 + 快段保真 + 长缺口不幻觉检查 + 合成静止手测试 | +| `tools/stereo_s80m/hand_3d/probes/probe_mp_gpu.py` | 探针:GPU delegate 冒烟 + 单目计时 + CPU/GPU 关键点差值 | +| `tools/stereo_s80m/hand_3d/probes/probe_nvenc.py` | 探针:管道写器冒烟(各编码器直出 + BrokenPipe latch + 可解码性) | +| `tools/stereo_s80m/dist/s80m_stereo_camera/*.py` | 客服交付版自包含副本(3 个 .py,非本目录源码,见文末) | + +## 各文件详解 + +### capture_calibration.py + +**作用**:离线生成设备级标定。解析 FaysSense VI Kit SDK 发布目录下的出厂标定静态文件 `config/calib/calib.yaml`(默认路径由环境变量 `FAYS_CALIB_YAML` 或 `FAYSSENSE_SDK_DIR` 定位),提取左右目内参/畸变/外参 `T_cn_cnm1`,把内参从 SDK 原生 640×400 **等比缩放到录制分辨率 1280×800**,写入 `config/s80m_stereo_calibration.json`。`--live` 可选路径通过 ctypes 加载 `libfays_vikit.so` 只调 `CreateHandleWithConfig`/`GetCalibrationParam`/`DestroyHandle` 与静态文件对比基线/内参——注释明确**绝不调用 `GetStereoFrames`**(SDK 3.9.1 在 RGB 失败后有段错误风险)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `load_calib_yaml` | `(path)` | PyYAML 解析 SDK 标定 yaml,校验 `cam0`/`cam1` 存在 | dict | +| `_intrinsics_from_cam` | `(cam)` | 从 yaml 相机条目提取 K(3×3)、dist、模型、分辨率 | 4 元组 | +| `_T_cn_cnm1_from_cam` | `(cam)` | 从 cam1 的 `T_cn_cnm1` 4×4 齐次矩阵提取 R/t | (R 3×3, t 3×1) | +| `build_calibration` | `(yaml_path, target_resolution)` | 构建设备级标定 dict,内参按宽度比例缩放 | dict(写文件由 main 完成) | +| `verify_with_sdk` | `(calib, vikit_lib, config_path)` | 连相机读 ROM 标定对比:基线偏差 >2mm、fx 偏差 >1% 告警 | 打印对比结果 | +| `main` | `--calib-yaml / --output / --live` | CLI:构建 → 写 JSON → 打印摘要(含 R 正交性 det 检查)→ 可选在线校验 | 退出码 | + +**关键数据**:输出 JSON 含平台字段(`type: "stereo_rgbd_camera"`、`name: "head_stereo"`、`resolution: [1280, 800]`、`fps: 25.0`、`baseline`(米,`t` 的模)、`left_camera`/`right_camera`(`intrinsic` 为 `[fx, fy, cx, cy]`、`distortion`、`distortion_model`)、`depth_scale: 0.001`、`cam_imu_timeshift`)+ **三角化扩展字段** `rotation`(行主序 9 元)、`translation`(3 元,米)、`distortion_model`(决定三角化走 fisheye 还是普通路径)。 + +**调用关系**:独立 CLI(无包内调用方);其输出 JSON 被 `stereo_triangulate.load_stereo_calibration` 的查找链第 3 级消费。 + +### export_calibration.py + +**作用**:采集端职责——从设备 ROM 读取出厂标定(后端二进制符号走查确认 `FAYS_VIK_GetCalibrationParam`/`FAYS_VIK_DumpCalib` 存在),补齐 SDK 示例没导出标定的链路。写 `/calibration/head_stereo.json`(平台格式)+ `calibration/s80m_dump_calib.yaml`(DumpCalib 原始备份)+ `config/s80m_stereo_calibration.json`(设备级默认,三角化回退链用)。同样只调 Create/GetCalibrationParam/DumpCalib/Destroy,不碰 `GetStereoFrames`。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `AtrakIntrinsics` / `AtrakExtrinsics` / `AtrakCamParam` / `AtrakCamChainParam` / `AtrakImuParam` / `AtrakCalibrationParam` | ctypes `Structure` | 对应 `fays_atrak_types.h` 的 SDK 结构体 | — | +| `DISTORTION_MODEL_NAMES` | dict | SDK 畸变枚举(0-4)→ 字符串:`none`/`equidistant`(KB4)/`radtan`/`brown_conrady`/`cvbasic` | — | +| `_load_sdk` | — | 校验库/配置存在,预加载 OpenCV(4.2 或 4.6),绑定 mangled 符号 | 函数句柄组 | +| `calibration_to_dict` | `(cal: AtrakCalibrationParam)` | SDK 结构体 → 平台 JSON(含 `imu` 噪声参数与三角化扩展字段),内参 640×400→1280×800 缩放 | dict | +| `is_usable` | `(calib)` | 与 `stereo_triangulate.is_usable` 同逻辑(不依赖 cv2 的自包含版) | bool | +| `export` | `(calib_path, yaml_path, device_output)` | 完整导出流程,finally 中 `DestroyHandle` | (calib dict, yaml 路径) | +| `main` | `--session / --output` | CLI | 退出码 | + +**关键数据**:JSON 与 `capture_calibration.py` 同 schema,另加 `"source": "fays_sdk_device_rom"` 与 `imu` 子对象(`accelerometer_noise_density`、`accelerometer_random_walk`、`gyroscope_noise_density`、`gyroscope_random_walk`、`update_rate`)。 + +**调用关系**:独立 CLI;输出被 `stereo_triangulate.py`、`export_offline_slam_dataset.py`(交叉校验源)消费。 + +### read_stereo_rgb.py + +**作用**:S80M 双目 RGB 读取脚本,ctypes 调 `libfays_vikit.so`(mangled 符号 `FAYS_VIK_CreateHandleWithConfig`/`GetStereoFrames`/`GetImuData`/`GetVersion`)。两种模式:`--pipe ` 以 JPEG 二进制协议把左右目帧 + IMU 样本写到管道(主程序经此收帧);无 `--pipe` 时窗口实时预览(Q/Esc 退出、S 截图、R 切 180° 旋转)。启动时**按设备名(`FTDI Superspeed Video Bridge`)与 USB 接口号重写临时 yaml**:接口 `1.0` = 双目对、`1.2` = IMU/中置 RGB、`rgb_dev_port` 一律置 `NULL`——绕开 `/dev/videoN` 端口漂移(代码注释原文:DECXIN/RealSense 先枚举时,S80C 的 FTDI 桥被挤到 `video2+`,SDK 会拿别的相机当双目,现象 `RgbInit failed` + 主程序永远等不到帧)。解析失败保持原 yaml 不动。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `AtrakImage` / `AtrakIMU` | ctypes `Structure` | SDK 图像(`device_id/seq/timestamp/width/height/channel/encoding/step/bytes/data`)与 IMU 样本(纳秒时间戳 + gyro×3 + acc×3) | — | +| `_graceful_exit` | `(sig, frame)` | SIGTERM/SIGINT → `SystemExit`,走 finally 释放 SDK,避免 FT602 设备留坏状态 | 进程退出 | +| `_stdin_control` | — | 后台线程读 stdin:`SET_EXPOSURE ` 行协议(`-1.0`=自动,`1.0~885.0`=手动;符号缺失时静默降级) | 调用 `FAYS_VIK_SetStereoExposure` | +| `_imu_collector` / `_drain_imu` | — | IMU 高频轮询线程(`IMU_HZ` 环境变量,默认 200;轮询率 = 2.5× 采样率)+ 线程安全取走缓冲 | 列表 | +| 主循环 | — | `GetStereoFrames` → 上下拼接图切分(**上=左目、下=右目**)→ 通道序修正 → JPEG 编码写管道 | 帧/IMU 字节流 | + +**关键数据**: + +- 管道协议(大端):`[4B left_len][8B left_ts_ns][left_jpg]` + `[4B right_len][8B right_ts_ns][right_jpg]` + `[4B imu_count][imu_count × (8B ts + 8B×3 gyro + 8B×3 acc)]`;时间戳为 SDK 硬件纳秒时钟(帧/IMU 同源)。 +- JPEG 质量 85;预分配缓冲 `MAX_BYTES = 1280*800*2*3`。 +- SDK 帧 `encoding` 声称 BGR8 但通道序实为 RGB → 统一 `cv2.cvtColor(..., cv2.COLOR_BGR2RGB)` 修正。 +- `IMU_HZ` 环境变量(默认 200,0=关);注释记录教训:2kHz 轮询每秒 ~2000 次 GIL 抢占把 Stereo FPS 从 25 拖到 6。 +- 环境修复:设置 `QT_QPA_PLATFORM_PLUGIN_PATH`/`QT_QPA_PLATFORM=xcb` 指向 cv2 5.0.0 wheel 自带 Qt 插件。 + +**调用关系**:被 `ui/main_window.py:703`(`_open_s80m`)以子进程启动;`--pipe -` 时 fd 1 被重定向到 stderr 以拦截 C++ SDK 的 printf/cout。 + +### stereo_triangulate.py + +**作用**:双目三角化几何核心,独立子模块不依赖主程序。从标定 dict 构建 `StereoTriangulator`:`distortion_model == "equidistant"` 走 `cv2.fisheye.stereoRectify` + `fisheye.undistortPoints`,其他模型走 `cv2.stereoRectify` + `cv2.undistortPoints`。三角化输出的 3D 点在**左目(cam0)相机光学系**下(米制):原点 = cam0 光心,+X 右、+Y 下、+Z 前(OpenCV 约定)。还提供左右目手列表的跨目匹配(几何主判据)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `K_from_intrinsic` | `(intr)` | `[fx, fy, cx, cy]` → 3×3 相机矩阵 | np.ndarray | +| `is_usable` | `(calib)` | 左右内参非零 + R(9)/t(3) 齐全且有限 + 基线非零 | bool | +| `load_stereo_calibration` | `(session_path=None, calib_path=None)` | 查找链:`--calib` 显式路径 → `/calibration/head_stereo.json` → `config/s80m_stereo_calibration.json`;显式指定不可用时**报错而非静默回退** | dict 或 None | +| `TriangulationResult` | `(points_3d, reproj_error)` | 结果容器:`points_3d` (N,3) 无效点 NaN、`reproj_error` (N,) 无效 inf、`valid`/`valid_count`/`mean_error`、`z` 属性 | — | +| `HandPair` | `(l_idx, r_idx, left_label, result)` | 左右目匹配出的同一只手 | — | +| `StereoTriangulator` | `(calib, image_size=None, swap_cams=False)` | 三角化器:内参按目标分辨率缩放、SDK 8 系数只取 fisheye 前 4 个(k1..k4)、矫正映射表、`swap_cams` 处理左右文件与 cam0/cam1 错位 | — | +| `StereoTriangulator.rectify_points` | `(pts, side)` | 原始图像素 (N,2) → 矫正图像素 (N,2) | np.ndarray | +| `StereoTriangulator.rectified_image` | `(frame, side)` | 原始帧 → 矫正帧(可视化用) | np.ndarray | +| `StereoTriangulator.project` | `(xyz, side)` | 左目相机系 3D → 矫正图像素(重投影验证/可视化) | (N,2) | +| `StereoTriangulator.triangulate` | `(pts_l, pts_r, max_err=None, max_depth=None)` | 原始像素关键点 (N,2) → 3D (N,3);逐点过滤重投影误差 ≤ max_err、`min_depth < z ≤ max_depth`、有限 | `TriangulationResult` | +| `StereoTriangulator.summarize` | — | 单行摘要:模型/fx_rect/baseline_rect/分辨率 | str | +| `match_hands` | `(left_hands, right_hands, tri, max_err, max_depth, min_valid)` | ≤2×2 穷举 + 贪心去重;评分 = `有效点数×10 − 平均重投影误差 + (label 一致 +5)`;按物理左右排序(左目 label "Left" 在前) | `HandPair` 列表 | +| `_self_test` | — | 3D → 双图投影(+0.5px 噪声)→ 逆变换回原始像素 → 三角化往返误差测试 | 退出码 | + +**关键数据**:阈值常量 `DEFAULT_MAX_REPROJ_ERR = 8.0` px、`DEFAULT_MAX_DEPTH = 3.0` m、`DEFAULT_MIN_DEPTH = 0.05` m、`MIN_VALID_POINTS = 8`。实例属性 `fx_rect`(矫正焦距,取自 P1)、`baseline_rect`(矫正基线)。`swap_cams=True` 时左右内参互换且外参取逆(`R^T`, `−R·t`)。自检允许 3D 误差 < 80mm、重投影 < 2.0px(注释:基线 8cm 双目 1px 视差噪声在 1.5m 处 ≈ 80mm 深度误差)。 + +**调用关系**:被 `render_stereo.py:50`、`hand_triangulate.py:73`、`hand_benchmark.py:45`、`hand_3d/run_pipeline.py:63`、`hand_3d/perspective_crop.py:37`、`hand_3d/track3d.py:34` 及 `tools/hand_3d_d435/*` 广泛复用。 + +### render_stereo.py + +**作用**:独立于检测/三角化的可视化组件。两种模式:`3d`(默认)把三角化 3D 骨架(`observation.keypoints.hand_3d` 列)投影叠加到左右目**矫正图**;`2d` 把 MediaPipe 原始 2D 关键点(`stereo_left`/`stereo_right` 列,84 维)叠加到**原图**。既作为库被 `hand_triangulate.py` 逐帧调用,也可作为独立 CLI 从已落盘 parquet 纯渲染重放(不重新检测)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `HAND_EDGES` | 常量 | MediaPipe 21 点骨架连接拓扑(0-17 腕等 21 条边) | — | +| `draw_skeleton` | `(img, pts, color, radius, thickness)` | 按 `HAND_EDGES` 画单色骨架,非有限点跳过 | 原地画 | +| `_draw_hand_styled` | `(img, pts, label, box_color, pts_angle)` | demo 风格单手叠加:teal 边框 + 底衬标签 + 五指分色(复用 `tools/hand_detection/hand_common.draw_hand`)+ 手势文本;有效点 <8 整手跳过 | 原地画 | +| `overlay_view` | `(img, pairs, tri, side, frame_idx, total)` | 一张矫正图上叠加 3D 骨架(`HandPair` 列表投影回该视角) | 原地画 | +| `overlay_view_2d` | `(img, kpts, side, frame_idx, total)` | 原图上叠加 (2,21,2) 原始 2D 关键点,全零手跳过 | 原地画 | +| `create_video_writer` | `(out_path, fps, width, height)` | mp4v 临时写器(`*_tmp.avi`) | (writer, tmp_path) | +| `finalize_video` | `(writer, tmp_path, out_path)` | 释放写器并转码 H.264(libx264 crf 23);无可用 ffmpeg 时保留 mp4v | 最终路径 str | +| `render_session_from_parquet` | `(session_dir, parquet_path, calib_path, out_dir, mode)` | 纯渲染重放:3d 消费 `hand_3d`(126=2×21×3)+ present/label/err 列;2d 消费 `stereo_left/right`(84)列 | 视频路径 | +| `render_video_2d` | `(session_dir, out_dir, scale, smooth)` | 直接从视频跑 2D 检测 + 渲染(左右目各自独立 MediaPipe 实例,共享会污染 VIDEO 模式追踪先验);`scale<1` 在缩放图上检测 | 视频路径 | +| `main` | `session_dir [--parquet --calib --out --mode --detect --scale]` | CLI | 退出码 | + +**关键数据**:骨架色——品红 = 三角化 3D 投影、青 = 原始 2D 关键点。ffmpeg 候选链:`shutil.which("ffmpeg")` → `/usr/bin/ffmpeg` → 环境变量 `FFMPEG_BIN`(默认兜底 `~/miniconda3/envs/lerobot/bin/ffmpeg`);注释说明 conda base 的 ffmpeg 因 openvino/tbb 符号错误不可用(2026-08 实测)。 + +**调用关系**:被 `hand_triangulate.py:66`、`hand_3d/run_pipeline.py:59`、`hand_3d/video_writer.py:129`(旧两段式回退路径)调用。 + +### hand_triangulate.py + +**作用**:单阶段(无裁剪精修)双目手部关键点后处理脚本。左右目视频各自跑 `MediaPipeHandPipeline`(独立实例)→ 方向自检 → `match_hands` 跨目配对 → 三角化 → 物理 3D 关键点按 LeRobot 风格并入 episode parquet;同时产出并排矫正图可视化视频。**只新增** `data/keypoints/` 与 meta 追加,不修改现有文件内容。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_find_video` | `(session_path, cam)` | 定位 `videos//chunk-0000/.mp4`,回退 `videos/.mp4` | 路径或 None | +| `_load_episode_meta` | `(session_path)` | 读 `meta/episodes/*.parquet` 与 `meta/tasks.jsonl` | (episode_index, task_index) | +| `_load_timestamps` | `(session_path)` | `timestamps.json` → {frame_index: timestamp},同帧多条取第一条 | dict | +| `_pack_2d` / `_pack_3d` / `_pack_errors` | `(hands)` / `(pairs)` / `(pairs)` | 打包 84 维 2D(缺手全零)/ 126 维 3D(无效 NaN)/ 每手平均重投影误差 | list | +| `_detect_orientation` | `(pipe_l, pipe_r, vc_l, vc_r, tri_normal, tri_swapped)` | 前 10 帧两种配对各三角化比平均重投影误差(小者几何自洽),True=需 swap | bool | +| `_merge_info_json` / `_merge_stats_json` | `(session_path)` / `(session_path, rows)` | 纯追加 `meta/info.json` features 与 `meta/stats.json` 统计(mean/std/min/max,NaN 忽略) | 写文件 | +| `main` | `session_dir [--calib --max-err --max-depth --every --no-video --freq-min --beta --no-smooth]` | 主循环 + parquet 落盘 + 副本拆分 + 视频转码 + 汇总 | 退出码 | + +**关键数据**: + +- parquet 列:`episode_index`/`frame_index`/`timestamp`/`task_index` + `observation.keypoints.stereo_left`(float32 list 84 = 2手×21点×(x,y))、`stereo_right`(84)、`hand_3d`(126 = 2手×21点×(x,y,z),米)、`reprojection_error`(2)、`hand_0/1_present`(bool)、`hand_0/1_label`(string)、`action`(占位 `[0.0]`)。`hand_3d` 无效点 NaN,2D 缺手全零。 +- 输出:`/data/keypoints/chunk-0000/chunk_000000.parquet`(zstd);镜像目录 `keypoints_output///` 下 `stereo_triangulate.mp4` + `hand_3d/chunk-000.parquet` + `hand_2d/chunk-000.parquet`(2D 副本为列子集)。 +- One-Euro 平滑参数由 CLI 控制(`--freq-min` 默认 5.0、`--beta` 默认 0.05、`--no-smooth` 全关)。 + +**调用关系**:调用 `hand_detection.hand_pipeline_mediapipe`、`stereo_s80m.render_stereo`、`stereo_s80m.stereo_triangulate`;独立 CLI。 + +### hand_benchmark.py + +**作用**:S80M 手势检测参数基准测试。对会话视频离线扫参数组合(4 分辨率 × 4 帧率隔帧 × rgb/gray × mono/stereo),`ProcessPoolExecutor` 多进程并行,输出稳定性指标矩阵 CSV + 终端表格。指标(smooth 关闭,测管线原始稳定性):`det_rate`、`det2_rate`、`mean_score`、`max_miss`(最大连续未检出段)、`disp`(帧间关键点位移中位)、`jitter`(位移一阶差分中位)、`tri_rate`、`tri_err`、`ms_frame`。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `run_group` | `(session, calib_path, swap, (w,h), (fps,step), color, mode)` | worker 进程内跑一组参数(左右目独立 MediaPipe 实例),统计全指标 | dict | +| `_detect_swap` | `(session, calib_path, size)` | ORB 极线误差法自检:两种配对各自 |y差| 中位数(0.75 ratio 过滤),小者正确 | bool | +| `main` | `--session --calib --workers --out --modes` | 组装 4×4×2×2 组合 → 并行跑 → CSV + 结果矩阵表 | 退出码 | + +**关键数据**:`RESOLUTIONS = [(1280,800), (960,600), (640,400), (480,300)]`;`FPS_STEPS = [(25,1), (12,2), (6,4), (3,8)]`(fps, 隔帧数);灰度 = `GRAY2BGR` 三通道复制(信息等价);双目三角化用 `image_size=(w,h)` 且 `swap_cams=swap`。CSV 默认落 `<脚本目录>/hand_benchmark/benchmark_.csv`(`os.makedirs` 按需创建;`--modes` 非 `all` 时文件名追加 `_` 后缀)。 + +**调用关系**:调用 `hand_detection.hand_pipeline_mediapipe` 与 `stereo_s80m.stereo_triangulate`;独立 CLI。 + +### export_offline_slam_dataset.py + +**作用**:EgoData 录制会话 → 离线双目惯性 SLAM 数据集(ORB-SLAM3 输入格式;格式规范 `OFFLINE_DATA_FORMAT.md` / `OFFLINE_DATA_RECORDING.md` 为客户侧 offline_slam/ 交付文档,不在本仓库)。转换要点:1280×800 彩色视频 → 灰度 → 缩放标定原生 640×400 → 用工厂标定(equidistant/fisheye)双目矫正 → PNG;相机硬件 32 位纳秒计数器(每 2^32 ns ≈ 4.295s 回卷)逐帧回卷修正并对齐 IMU 时基、按规范应用一次 `timeshift_cam_imu`;IMU 从 parquet 逐帧批次展开为逐样本行,列序 `[gx,gy,gz,ax,ay,az] → [ax,ay,az,gx,gy,gz]`;两个 CSV 时间戳严格递增、IMU 覆盖完整相机时间范围。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `parse_calib_yaml` | `(path)` | 手写递归解析工厂 `calib.yaml`(避免 PyYAML 依赖,支持内联/块序列两种列表风格) | dict | +| `load_session` | `(session_dir)` | 读 `timestamps.json` + IMU parquet(`observation.imu`/`imu_ts_ns` 列展开)+ `metadata.json` | dict | +| `unwrap_camera_clock` | `(frames, imu_ref_ns, period_ns=40_000_000)` | 32 位回卷修正:用首条 IMU 样本推断回卷次数 k,逐帧增量累加,陈旧读帧放回标称网格保证严格递增 | 绝对时钟列表 | +| `build_rect_maps` | `(cal, size=(640,400))` | 工厂标定 → 双目矫正映射表(内参按分辨率比例缩放,与 ROM 原生 640×400 标定一致) | dict(map0/map1/P0/P1/R0/R1) | +| `check_orientation` | `(video_dir, cal, size, n_frames=6)` | ORB 极线对齐自检(注释:本会话实测 3px vs 57px),True=需交换左右 | bool | +| `extract_frames` | `(video_dir, ts_list, maps, out_dir, size)` | 左右视频 → 灰度 → 缩放 → 矫正 → PNG(PNG_COMPRESSION 6);帧数必须等于时间戳数 | 每目写盘统计 | +| `write_csvs` | `(out_dir, ts_aligned, ts_raw, imu_rows, timeshift)` | 写 `images.csv` / `camera_timestamps.csv` / `imu.csv` | 写文件 | +| `_opencv_matrix` | `(name, rows, cols, dt, data)` | OpenCV FileStorage 矩阵块(数据单行,`dt` 显式指定) | str | +| `write_orb_calibration` | `(out_dir, cal, P0, P1, serial, imu_rate)` | 生成 `orb_calibration.yaml`(ORB-SLAM3 FileStorage 配置,六项修复 + 必需键清单) | 写文件 | +| `write_runtime_calibration` | `(out_dir, cal, serial, size)` | 生成 `s80m_runtime_calibration.yaml`(K1/D1/K2/D2/R/T/T_b_c1 + serial/image size/timeshift),供官方采集器一致性验收 | 写文件 | +| `verify_against_device_json` | `(cal, tol=1e-3)` | 工厂 yaml 与设备 ROM dump(`config/s80m_stereo_calibration.json`)交叉校验,防 yaml 过期/错设备 | 问题列表 | +| `write_metadata_yaml` | `(out_dir, session, stats, n_imu, imu_rate)` | 交付说明 `metadata.yaml` | 写文件 | +| `validate` | `(ts_aligned, imu_rows)` | 校验时间戳严格递增 + IMU 覆盖 | 问题列表 | +| `main` | `--session --out --calib --serial` | 全流程:校验 → 时钟对齐 → 方向自检 → 帧提取 → 写 CSV/标定 → 校验 → tar.gz 打包 | 退出码 | + +**关键数据**: + +- 输出目录 `session_YYYYMMDD_HHMMSS/`:`orb_calibration.yaml`、`images.csv`(`timestamp_ns,left_image,right_image`)、`imu.csv`、`camera_timestamps.csv`(审计:原始/对齐后/偏移)、`metadata.yaml`、`cam0/data/.png`、`cam1/data/.png`(已矫正 640×400 8-bit 灰度);同名目录已存在时加 `_v2/_v3` 后缀,绝不覆盖。默认输出根 `tools/stereo_s80m/offline_slam_output/`(首次运行后生成,仓库内不保留)。 +- `orb_calibration.yaml` 关键点(注释明确六项修复):`%YAML:1.0` 必须首行;`Camera.width/height`(非 rows/cols);`IMU.Frequency`(大写 F);实数值必须带小数点(否则解析成 INT 被 `isReal()` 拒绝);`Stereo.ThDepth` + 全部 10 个 `Viewer.*`;`IMU.GyroWalk/AccWalk` 非零(0 会导致预积分协方差退化 → Sophus 崩溃);`IMU.T_b_c1` 必须 `dt: f`(32F,ORB-SLAM3 的 `toMatrix3d` 用 `.at()` 读,写成 `dt: d` 会按 double 重解释 float → Sophus 崩溃)。IMU 噪声常量:`NoiseGyro 1.9e-05`、`NoiseAcc 1.22e-04`、`GyroWalk 0.0002`、`AccWalk 0.00086`;`Camera.bf = baseline × fx`。 +- `_TIMESHIFT_APPLIED = True`:时间偏移已应用一次,回放时 `--camera-time-shift-s` 必须为 0(写进 yaml 注释与 metadata)。 +- 方向约定(SDK `fays_atrak_types.h`:"T_cn_imu // Bring points in {imu} frame to {camera n} frame"):工厂 `T_cam_imu` = IMU系→左目系,即 ORB-SLAM3 的 `IMU.T_b_c1`,直接写入。 +- `--serial`:设备序列号(用于元数据与校验;默认值写死在 argparse 中,本仓库文档不抄录序列号)。 + +**调用关系**:独立 CLI;与 `validate_offline_dataset.py` 配套(导出产物由其本地验收)。 + +### validate_offline_dataset.py + +**作用**:离线 SLAM 数据集本地验收——**复刻客户侧两份检查**:① `cv::FileStorage` 格式检查(`离线ORB-SLAM报错修复记录.md` 六项修复 + 必需键);② 官方采集器 `prepare_rectification_and_validate_settings` 复刻(`offline_slam/fayssense_offline_dataset_recorder.cc`):用 `s80m_runtime_calibration.yaml` 的 K/D/R/T 在 640×400 重算 `cv2.fisheye.stereoRectify`,校验 orb yaml 一致性;③ 数据完整性(时间戳严格递增、IMU 覆盖、帧数、图像属性)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `REQUIRED_KEYS` / `REAL_KEYS` | 常量 | 必需键清单(`Camera.*`/`Camera1.*`/`Stereo.*`/`IMU.*`/`Viewer.*`)与必须是 REAL 节点的实数值键清单 | — | +| `check_orb_yaml` | `(session)` | `orb_calibration.yaml` 格式检查:首行 `%YAML:1.0`、键齐全、REAL 节点类型、`IMU.T_b_c1` 必须 32F 且 4×4 | 问题列表 | +| `check_runtime_consistency` | `(session, size=(640,400))` | 复刻官方验收:`Camera.type=="Rectified"`、`Camera1.fx/fy/cx/cy` 与重算 P1 差 ≤1e-4、`Stereo.b` 与 `P2[0,3]/P2[0,0]` 差 ≤1e-4、`IMU.T_b_c1` 与 runtime 差(Inf-norm)≤1e-5、fps/IMU 频率 >0 | 问题列表 | +| `check_data` | `(session)` | images.csv/imu.csv 时间戳严格递增、IMU 覆盖相机时间范围、抽 1 张图验证 640×400 8bit 灰度 | (issues, info) | +| `main` | `session_dir`(sys.argv) | 顺序跑三组检查,任一失败退出码 1 | 退出码 | + +**调用关系**:独立 CLI,输入是 `export_offline_slam_dataset.py` 的产物目录。 + +### hand_3d/__init__.py + +**作用**:子包入口。把仓库根插入 `sys.path` 后 `from stereo_s80m.hand_3d.run_pipeline import main`,`__all__ = ["main"]`——`python -m stereo_s80m.hand_3d` 只完成导入不执行管线;入口仍是 `python tools/stereo_s80m/hand_3d/run_pipeline.py `(与模块 docstring 用法一致)。 + +### hand_3d/detector.py + +**作用**:2D 关键点检测抽象层——几何层唯一依赖的接口。`KeypointDetector.detect()` 返回 21 点像素关键点(MediaPipe 拓扑序),三角化、精修、渲染全部只依赖该接口,因此 GPU 神经检测器可作为可替换后端接入。`MediaPipeDetector` 关键改进:用 `norm_landmarks × 帧尺寸` 重算 **float 亚像素坐标**(现有管线 landmarks 是 int 截断,0.5px 量化对 ~3.8px 级重投影误差是可见噪声源,对裁剪图放大精修尤其重要)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `DetectedHand` | dataclass:`landmarks (21,2)`、`label`、`score`、`index`、`conf (21,)` | 单只手的 2D 检测结果(几何层消费的最小结构) | — | +| `DetectedHand.from_hand_result` | `(hr, frame_w, frame_h, index=0)` | MediaPipe `HandResult` → 亚像素像素坐标 | `DetectedHand` | +| `KeypointDetector` | ABC | 抽象接口:`detect(frame_bgr)` / `reset()` / `close()` | — | +| `MediaPipeDetector` | `(model_path, num_hands=2, mirror, smooth, freq_min=5.0, beta=0.05, dcutoff=1.0, det_conf=0.5, track_conf=0.5, delegate="cpu")` | 包装 `MediaPipeHandPipeline`(CPU)或惰性接入 `hand_3d.mp_gpu.FastHandLandmarker`(GPU,3.0ms/帧 vs CPU 7.8ms;GPU 时两目必须同线程顺序,输出有 ~2.8px 级 fp16 数值漂移) | — | + +**调用关系**:被 `run_pipeline.py:70`、`tools/hand_3d_d435/live_demo.py:65`、`run_pipeline_d435.py:37`、`glove_detector.py:76`(只用 `DetectedHand`)等使用;`mp_gpu.py:35` 反向 import `DetectedHand`。 + +### hand_3d/identity.py + +**作用**:手性投票——修复 MediaPipe handedness 逐帧独立分类在遮挡/快动/对称手势下闪烁,导致 `match_hands` 槽位排序不稳、tracker 换手误重置、骨架身份对穿。每目一个 `HandednessVoter`:维护 ≤2 条手轨迹(质心最近贪心关联,ByteTrack 式),每条轨迹带 7 帧 label 票仓,当前帧 = 轨迹票 + 原始票**严格多数表决**。注释记录两代教训:v1 单次投票平票保原始 → 闪烁穿透;v2 双手交叠时贪心关联交叉 → 票仓自锁错 label → 增加**重叠守卫**(两质心 < `OVERLAP_PX` 时不表决,原始 label 直通并把轨迹票仓重播种;实际实现为交叠期 label 冻结为交叠前稳定值、位置不更新)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `HandednessVoter` | `(window=7, min_score=0.7)` | 单目实例;轨迹 = {pos, votes(deque), last, idle},空帧全清、未分配轨迹冻结、超限替换最旧 | — | +| `HandednessVoter.update` | `(hands, frame_w=1280, frame_h=800, frame=None, cam="?")` | 贪心分配 → 重叠守卫 → 逐手表决(严格多数,平票沿用轨迹稳定 label)→ 轨迹更新 | 原地覆盖每只手 `label` | +| `_dump_debug` | — | `HAND3D_IDENTITY_DEBUG` 环境变量指向文件时,atexit 写 `frame,cam;pre,post,score,cx,cy` 调试行 | 写文件 | + +**关键数据**:`VOTE_WINDOW=7`、`MIN_VOTE_SCORE=0.7`(低于此的原始检测不计票)、`ASSOC_GATE=0.12`(×max(宽,高),1280×800 下 ≈154px)、`OVERLAP_PX=0.05`(≈64px)、`MAX_TRACKS=2`。 + +**调用关系**:被 `run_pipeline.py:74`(每目一个实例,在 `match_hands` 之前原地覆盖 label)、`tools/hand_3d_d435/live_demo.py:66` 等使用。 + +### hand_3d/track3d.py + +**作用**:遮挡传播(两件套):`HandSlotTracker` 为每个槽位(hand_0/hand_1,`match_hands` 已按 left_label 排序:Left 前)维护 αβ 滤波的 3D 位置/速度,缺手帧生成预测 3D;`PseudoHandPair` 把预测 3D 包成伪 pair(`l_idx/r_idx=-1`、`valid_count=0`、err=inf)并入同一次 refine 批处理——预测 3D → `tri.project` → crop 的现成路径做救援重检。幻觉防护:`max_lost` 硬顶(默认 15,长缺口保持 absent 不得幻觉)、`propagated` 列可过滤、`--propagate-max 0` 全关。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `PseudoHandPair` | dataclass:`result`、`left_label`、`l_idx=-1`、`r_idx=-1` | 丢失槽位的传播重检载体(接口与 `HandPair` 平替) | — | +| `HandSlotTracker` | `(max_lost=15, alpha=0.5, beta=0.1, debug_log=None)` | 两槽位 αβ 跟踪器;槽位 label 变化 → 槽位重置(换手防旧状态污染) | — | +| `HandSlotTracker.observe_slot` | `(slot, label, pts3d, t)` | 真实检测回写:label 变化重置;首见初始化;`dt > max_lost` 重初始化直接采信本次观测(防陈旧速度外推冲掉新鲜观测);否则 αβ 预测-修正(NaN 点保持纯预测) | 更新槽位状态 | +| `HandSlotTracker.mark_lost` | `(slot, t)` | 救援失败计数丢失 | 递增 lost | +| `HandSlotTracker.predict` | `(slot, t)` | 恒速外推 `x + v·(t − last_t)`;从未见过或丢失超限 → None | np.ndarray 或 None | +| `HandSlotTracker.slot_label` / `debug` / `close` | — | 查询当前槽 label / 写事件日志 / 关闭 | — | +| `make_pseudo_pair` | `(pred, label)` | 预测 3D → `PseudoHandPair`(err 全 inf 使 `_adopt` 判据退化) | `PseudoHandPair` | + +**关键数据**:槽位状态含 `label/x/v/last_t/lost`;debug CSV 头 `frame,slot,event,label,lost`。注释:基线会话 `222_000008` hand_1 检出 57%、5 段 ≤3 帧短缺口;长缺口 45/89 帧保持 absent。 + +**调用关系**:被 `run_pipeline.py:73`、`tools/hand_3d_d435/live_demo.py:67`、`mono_assign.py:34`、`fill_track.py:32` 使用。`track3d.py` 依赖 `stereo_triangulate.TriangulationResult`。 + +### hand_3d/smoother.py + +**作用**:3D 域因果时序平滑——三角化之后的最终抖动抑制。对 (2,21,3) 左目相机系 3D 关键点逐点跑 One-Euro 自适应低通(复用 `hand_detection.hand_pipeline_mediapipe.OneEuroFilter3D`)。平滑放在三角化之后的米制 3D 域而非 2D:精修 2D 与粗 2D 来源不同,在最终 3D 上统一平滑才能消除两种来源切换时的跳变。防污染:槽位 label 变化或"空→有"跳变时重置该槽全部滤波器。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `Hand3DSmoother` | `(freq_min=3.0, beta=0.3, dcutoff=1.0)` | 每 (slot, kpt) 一个 `OneEuroFilter3D`,时间基准 perf_counter 毫秒 | — | +| `Hand3DSmoother.update` | `(hands3d, labels, valids=None)` | 一帧平滑:`valids`(每槽有效点数 ≥8 视为有手);无效点保持 NaN 不喂滤波器(数据诚实,渲染层自行处理) | (2,21,3) float32 | + +**调用关系**:被 `run_pipeline.py:72`(主循环因果平滑,渲染用)与 `tools/hand_3d_d435/live_demo.py:68`、`probe_live_consistency.py:42` 使用。 + +### hand_3d/perspective_crop.py + +**作用**:两阶段透视裁剪精修——Hur et al. 2025(Eurographics)"Perspective Crop Based Egocentric Hand Pose Estimation via Fisheye Stereo Vision" 的落地实现。原理:鱼眼边缘手形畸变是 MediaPipe 全图检测误差主要来源;粗三角化给出 3D 位置后按 3D 投影在每只眼取手部 ROI,放大成 256² 裁剪图(默认取自矫正图 = 已去鱼眼畸变),裁剪图重检测 21 点(手更大、畸变更小 → 更准),再逆变换回原始图像素二次三角化。采纳判据:精修结果有效点数 ≥ 粗结果且平均重投影误差 < 粗结果,否则保留粗结果(**精修永不回退精度**)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_centroid3` | `(points)` | 3D 质心(≥ `MIN_VALID_POINTS` 个有效点的中位数) | np.ndarray 或 None | +| `_rescue_near` | `(res, coarse)` | 伪救援位置门限:精修 3D 质心须在预测质心 `RESCUE_MAX_DIST` 内 | bool | +| `RefinedPair` | dataclass:`pair`、`kpts_l_raw/kpts_r_raw`、`result`、`used`、`reason`、`conf_l/conf_r` | 一只手的粗匹配 + 精修结果;`left_label` 属性兼容 `overlay_view` 的 `HandPair` 接口 | — | +| `CropRefiner` | `(tri, crop_size=256, pad_ratio=0.5, crop_source="rect", max_err, max_depth, refine_det_l, refine_det_r, epi_y_align=False, kpt_soft_thr=0.15)` | 精修器;`refine_det_l/r` 为每目独立裁剪图检测器(num_hands=1, smooth=False,与全图管线隔离防追踪先验串扰) | — | +| `CropRefiner.rect_to_raw` | `(px_rect, tri, side)` | 矫正图像素 → 原始(畸变)图像素(inv(K_rect) → R^T → 加畸变,与 `_self_test` 同算法) | (N,2) | +| `CropRefiner._make_crop` | `(img, proj_pts)` | 按投影点取 ROI → pad 0.5 → 正方形原生分辨率 crop;有效点 <4 / 边长 < `MIN_CROP_BOX` 放弃 | (crop, x1, y1) 或 None | +| `CropRefiner._refine_side` | `(img, proj_pts, det, side, to_raw=True)` | 单侧裁剪检测(空检测重试一次)→ 关键点回全图像素(to_raw=False 返回矫正图像素供对极对齐) | (21,2) 或 None | +| `CropRefiner._adopt` | `(pair, kpts_raw, conf_raw, coarse_l, coarse_r)` | 候选(精修/置信度加权 blend)重三角化 → 真 pair 严格优于粗结果才采纳;伪 pair 走绝对质量门槛(≥8 点且 err ≤ `RESCUE_MAX_ERR` 且位置近)防重复救援;失败返回粗结果(伪 pair 标记 `propagated`) | `RefinedPair` | +| `CropRefiner._blend_w` | `(conf)` | 逐点 blend 权重 `w = 0.25 + 0.5·c ∈ [0.25, 0.75]`;无置信度标量 0.5;conf < `kpt_soft_thr` 的点 w=0(完全回退粗检) | 权重 | +| `CropRefiner.refine` | `(pair, rect_l, rect_r, raw_l, raw_r, coarse_l, coarse_r)` | 整手精修(MediaPipe 逐 crop 路径):投影 → 裁剪 → 检测 → (可选对极 y 对齐)→ 转 raw → `_adopt` | `RefinedPair` | +| `CropRefiner.refine_batch` | `(pairs, rect_l, rect_r, raw_l, raw_r, coarse_l_src, coarse_r_src)` | 整帧批量精修:crop 收集 → 单次 `detect_batch` → 分发(为 `batch_capable` 检测器保留,当前无启用后端;检测器无 `detect_batch` 时逐手回退 `refine()`) | `RefinedPair` 列表 | + +**关键数据**: + +- 常量:`MIN_CROP_BOX=20`、`RESCUE_MAX_ERR=3.0`(px,伪救援采纳的绝对误差上限)、`RESCUE_MAX_DIST=0.15`(m,伪救援位置门限)。 +- 对极 y 对齐(`epi_y_align`,构造默认关、`run_pipeline` MP 路径已接线开):矫正后左右目同名关键点必共行,实测存在 ~+3px 系统性竖直视差——在 rect 空间强制 `y=(y_l+y_r)/2` 再转 raw。 +- 检测分辨率 = 裁剪原生边长(256~512 之间,`detect_size = min(max(s, crop_size), crop_size*2)`),保留全部像素信息。 +- `RefinedPair.reason` 取值:`ok` / `ok-refined` / `ok-blend` / `no-crop-det` / `not-better` / `coarse-invalid` / `propagated`。 + +**调用关系**:被 `run_pipeline.py:71`(构造 `CropRefiner`)使用;依赖 `stereo_s80m.stereo_triangulate`(`StereoTriangulator` 及默认阈值、`MIN_VALID_POINTS`)。 + +### hand_3d/mp_gpu.py + +**作用**:MediaPipe GPU delegate 直连封装——stage-1 检测提速。`hand_detection.hand_pipeline_mediapipe` 写死 CPU delegate(共享模块不改),本模块自建 `vision.HandLandmarker` 支持 `BaseOptions.Delegate.GPU`,输出 `DetectedHand` 结构与 `MediaPipeDetector` 完全一致(几何层零改动)。GPU delegate 可能 SIGSEGV(进程内 try/except 拦不住)→ `smoke_test_gpu()` 用子进程冒烟,通过才切 GPU。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `smoke_test_gpu` | `(model_path, timeout=90.0)` | 子进程跑"GPU delegate 创建 + 3 帧推理",stdout 含 `GPU_SMOKE_OK` 才算通过 | bool | +| `FastHandLandmarker` | `(model_path, num_hands=2, det_conf=0.5, track_conf=0.5, delegate="cpu", smooth=True, freq_min=5.0, beta=0.05, dcutoff=1.0)` | `RunningMode.VIDEO` + 自增帧号时间戳(1.0.1 要求单调);2D One-Euro 平滑逻辑与共享管线一致(归一化坐标域,按 (手序号, 点序号) 维护滤波器) | — | +| `FastHandLandmarker.detect` | `(frame_bgr)` | BGR → SRGB mp.Image → `detect_for_video` → 亚像素 `DetectedHand` 列表(label 取 `handedness[0].category_name`) | list | +| `FastHandLandmarker.reset` / `close` | — | 清滤波器/时间戳;释放 landmarker | — | + +**关键数据**(代码注释实测,2026-08-17,RTX 5090 + mediapipe 1.0.1):GPU delegate 3.0ms/帧 vs CPU 7.8ms/帧(单目),创建 ~1.1s 一次性成本;GPU delegate 双线程反而慢(GL 上下文竞争 0.84×)→ GPU 时两目必须顺序;与 CPU 结果关键点最大差 2.77px(fp16 数值差异,已知漂移)。 + +**调用关系**:被 `detector.py:86`(`delegate="gpu"` 惰性 import)、`run_pipeline.py:389`(`--mp-delegate auto` 冒烟)、`tools/hand_3d_d435/live_demo.py:419` 使用;探针 `probe_mp_gpu.py:24` 直接测。 + +### hand_3d/postprocess.py + +**作用**:离线后处理——间隙插值 + 零相位速度自适应平滑("平衡"档)。两阶段都在主循环之后、parquet 落盘之前,只在 `--video-smooth offline` 跑:① `fill_gaps` 对 ≤max_gap 的缺手短间隙逐点逐轴插值(优先三次,上下文不足退二次/线性),**覆盖**传播外推值并置 `propagated=True`;长缺口不动(不幻觉)。② `offline_smooth` 逐槽位逐点逐轴按连续有效段 savgol(7,3) 零相位平滑 + 速度自适应混合。平滑结果写入**新列** `observation.keypoints.hand_3d_smoothed`(float32 [2,21,3]),`hand_3d` 列保持原始精修值语义不变。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `ReplayPair` | `(label, points_3d, mean_error, valid_count)` | 渲染用伪 pair(把 parquet 行还原成 `overlay_view` 可消费结构,同 `render_stereo._ReplayPair`) | — | +| `_runs` | `(mask)` | bool mask 的连续 False 段 → [(a,b)] 闭区间 | list | +| `fill_gaps` | `(rows, max_gap=15)` | 间隙插值:锚点 = 间隙两侧真实检测帧(present 且非 propagated),优先左右各 2 帧三次插值(<4 退线性);回写 `hand_3d`/`present=True`/`propagated=True`/label 沿用 | 填充帧-槽数(原地改 rows) | +| `offline_smooth` | `(rows, sg_window=7, sg_poly=3, v0=0.08, fps=25.0, still_window=21)` | 逐槽逐点逐轴:连续有效段 savgol 零相位 + 速度自适应混合 `w=exp(-(v/v0)²)`(速度从 savgol 去噪输出测量);静止 v_sg<20mm/s 用长窗 21、20-80mm/s 线性混入、>80mm/s 基准窗;跳变阻尼(帧间位移 >`JUMP_THR` 的突变点 ±still_window/2 内保 raw) | (N,2,21,3) float32 | +| `pairs_from_row` | `(row, key="observation.keypoints.hand_3d_smoothed", min_points=4)` | parquet 行 → `ReplayPair` 列表(第二遍渲染 pass 用):按"有效点数 ≥ min_points"纳入渲染,保证间隙期骨架连续 | list | + +**关键数据**:`JUMP_THR = 0.010`(m/帧 = 10mm/帧;注释:噪声 σ=1.2mm 下帧差 ~1.7mm,10mm≈6σ 不误触发)。注释记录跳变阻尼效果:长窗零相位对阶跃有预振铃(合成测试静止段边界 105-115 帧 wobble 3.11mm、峰值 68mm),阻尼后边界无预振铃、内部(30-100 帧)wobble 1.19→0.37mm。 + +**调用关系**:被 `run_pipeline.py:75`(`fill_gaps` + `offline_smooth`)、`tools/hand_3d_d435/run_pipeline_d435.py:40`、`tools/hand_3d_d435/tools/render_keypoints_parquet.py:173` 使用;`run_pipeline.py:291` 二次 import `pairs_from_row`。 + +### hand_3d/renderer_3d.py + +**作用**:3D 旋转视角骨架渲染器——numpy + cv2 自写透视投影(零额外依赖)。虚拟相机绕双手质心匀速旋转(默认整段视频转 2 圈,仰角 25°),五指分色骨架(与 2D demo 同一套 `FINGERS` 色表)+ 掌心灰连接 + 腕部白圆 + 地面网格 + 腕部深度标注 + 相机系坐标轴 + HUD。对比 matplotlib 3D:本渲染器 2-5ms/帧(matplotlib 60-150ms/帧)、视角完全确定、原生 BGR 直进 VideoWriter。坐标系:左目相机系(OpenCV 约定,+X 右/+Y 下/+Z 前,米)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `PALM_CONNECTIONS` / `FINGER_CHAINS` | 常量 | 掌心连接(0-1/0-5/5-9/9-13/13-17/0-17);每指画法链(拇指 1→2→3→4,其余 0→掌根→MCP→PIP→DIP→指尖) | — | +| `RotatingSkeletonRenderer` | `(width=1280, height=720, fov_deg=45.0, revolutions=2.0, elevation_deg=25.0, ground_grid=True, depth_labels=True, bg_color, text_color)` | 渲染器;焦距 `f = (h/2)/tan(fov/2)` | — | +| `RotatingSkeletonRenderer._look_at` | `(eye, target)` | 虚拟相机基 (right, up, fwd);左目相机系 Y 向下 → 世界"上" = −Y | 基向量 | +| `RotatingSkeletonRenderer._project` | `(pts3d, right, up, fwd, eye)` | (N,3) → ((N,2) 像素, (N,) 视线深度) | 投影 | +| `RotatingSkeletonRenderer._draw_hand` | `(img, proj, fin, label, err)` | 五指分色 + 掌心 + 腕部白圆(指尖 7px/关节 5px/腕 9px + 深色描边,与 `draw_hand` 同风格) | 原地画 | +| `RotatingSkeletonRenderer._draw_grid` / `_draw_axes` | — | 地面网格(最下手部点下方 0.05m 平面,0.05m 间距)/ 相机系原点坐标轴(0.1m 长) | 原地画 | +| `RotatingSkeletonRenderer.render` | `(hands3d, labels=("",""), errs=(nan,nan), frame_idx=0, total=1, title=...)` | 整帧渲染:质心/跨度 → 相机距离 `clip(2.2·half/tan(fov/2), 0.2, 1.5)` → 旋转角 `2π·revolutions·frame/total` → painter 算法(远手先画)→ HUD | (H,W,3) BGR 帧 | + +**关键数据**:默认画布 `RENDER_SIZE=(1280, 720)`(`run_pipeline.py:81` 定义);腕部深度标注 `"Left/Right z=0.XXm err=0.0px"`;无有效点帧显示 "no valid 3D hand keypoints"。 + +**调用关系**:被 `run_pipeline.py:76`、`tools/hand_3d_d435/live_demo.py:69`、`run_pipeline_d435.py:41`、`tools/render_keypoints_parquet.py:46` 使用;复用 `hand_detection.hand_pipeline_mediapipe.FINGERS`。 + +### hand_3d/io.py + +**作用**:数据 IO——会话元数据读取 + LeRobot 风格 parquet 打包/落盘。schema 与 `hand_triangulate.py` 完全一致(保证 `render_stereo` 重放路径兼容),新增三列:`observation.keypoints.stage2`(每手 bool,精修是否被采纳)、`observation.keypoints.propagated`(每手 bool,传播/插值标记)、`observation.keypoints.hand_3d_smoothed`(离线平滑结果)。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `find_video` | `(session_path, cam)` | 同 `hand_triangulate._find_video`(chunk-0000 → 根目录回退) | 路径或 None | +| `load_episode_meta` | `(session_path)` | 读 `meta/episodes/*.parquet` + `meta/tasks.jsonl`,异常时默认 0 | (episode_index, task_index) | +| `load_timestamps` | `(session_path)` | `timestamps.json` → {frame_index: timestamp} | dict | +| `pack_2d` / `pack_3d` / `pack_errors` | `(hands)` / `(pairs)` / `(pairs)` | 84 维 2D(缺手全零)/ 126 维 3D(无效 NaN)/ 每手平均误差(`valid_count` 为 0 时 NaN) | list | +| `pack_stage2` | `(pairs)` | 每手精修是否被采纳(`p.used`)→ bool list [2] | list | +| `write_parquet` | `(rows, path, drop_keys=())` | dict 列表 → parquet(zstd);`drop_keys` 跳过不存在的列(如 causal 模式不写 `hand_3d_smoothed`) | 写入路径 | +| `merge_info_json` | `(session_path, drop_keys=())` | 纯追加 `meta/info.json` features(含移除上次写入的 drop_keys) | 写文件 | +| `merge_stats_json` | `(session_path, rows)` | 纯追加 `meta/stats.json` 的 mean/std/min/max 统计 | 写文件 | + +**关键数据**:`FEATURES_ADD` 注册 11 个 feature 键(dtype/shape 与 parquet 列一致,含 `stage2`、`propagated`、`hand_3d_smoothed` 三个扩展);`DIM_2D=84`、`DIM_3D=126`;`action` 列仍为占位 `[0.0]`。 + +**调用关系**:被 `run_pipeline.py:78`、`tools/hand_3d_d435/live_demo.py:71`、`run_pipeline_d435.py:43`、`probe_align_overlay.py:57` 使用。 + +### hand_3d/video_writer.py + +**作用**:管道视频写器——渲染段提速。旧路径(`render_stereo.create_video_writer/finalize_video`)两段式:cv2 mp4v 写临时 avi(CPU 编码 ~15ms/帧)+ 事后 libx264 转码(再花一遍全片时间)。本模块用 ffmpeg 管道单段直出:rawvideo bgr24 → stdin → H.264 → mp4,编码移出主线程(ffmpeg 子进程),主循环只剩帧拷贝。编码器逐级回退:nvenc(lerobot ffmpeg 带 `h264_nvenc`)→ libx264(管道)→ 旧两段式 mp4v。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `find_ffmpeg` | — | 找一个能跑起来的 ffmpeg(`-version` 退出码探测,结果缓存):`FFMPEG_BIN`(默认 `~/miniconda3/envs/lerobot/bin/ffmpeg`)→ `shutil.which("ffmpeg")` → `/usr/bin/ffmpeg` | 路径或 None | +| `has_nvenc` | `(ffmpeg=None)` | 该 ffmpeg 是否带 `h264_nvenc`(`-encoders` 探测,结果缓存) | bool | +| `PipeVideoWriter` | `(out_path, fps, width, height, codec, codec_args)` | ffmpeg 管道写器:`-f rawvideo -pix_fmt bgr24 -i - ... -c:v codec ... -movflags +faststart` | — | +| `PipeVideoWriter.write` | `(frame_bgr)` | 写一帧;BrokenPipeError → latch 失败(调用方可忽略,parquet 数据不受影响) | bool | +| `PipeVideoWriter.close` | — | 关 stdin 等 ffmpeg 退出(60s 超时);失败删半成品 mp4 | 最终路径或 None | +| `Mp4vWriter` | `(out_path, fps, width, height)` | 旧两段式路径包装(惰性 import `render_stereo`),统一 `.write/.close` 接口 | — | +| `create_video_sink` | `(out_path, fps, width, height, encoder="auto")` | 按 encoder 创建写器:auto=nvenc→libx264→mp4v 逐级回退;nvenc 参数 `-rc vbr -cq 23 -b:v 0`,libx264 参数 `-crf 23 -preset veryfast` | sink 对象 | + +**调用关系**:被 `run_pipeline.py:77`、`tools/hand_3d_d435/*`、探针 `probe_nvenc.py:18`、`probe_compare3.py:30` 使用。 + +### hand_3d/run_pipeline.py + +**作用**:两阶段管线主流程 + CLI,`tools/stereo_s80m/hand_3d/` 的入口。流程(Hur et al. 2025 落地):左右目视频 → 每目独立 MediaPipe 2D 检测(stage-1,float 亚像素)→ 手性投票 → `match_hands` 跨目配对 → 鱼眼双目三角化(粗 3D)→ 透视裁剪精修(stage-2:3D 投影 → 手 ROI 256² 裁剪图 → 重检测 → 二次三角化)→ 3D 域平滑(默认离线零相位 + 第二遍渲染,`--video-smooth causal` 为因果 One-Euro)→ 3D 旋转视角渲染 + 矫正图并排叠加 → H.264 视频 + hand_3d parquet。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_detect_orientation` | `(det_l, det_r, vc_l, vc_r, tri_normal, tri_swapped)` | 方向自检(同 `hand_triangulate` 的重投影误差法),True=需 swap | bool | +| `_rescue_too_close` | `(pred, pairs, thresh)` | 伪 pair 救援互斥:预测 3D 与任一真实 pair 有效点质心距离 < thresh 则跳过救援(防"一只手进两个槽";`--rescue-min-dist` 默认 0.10m,0=关) | bool | +| `_slot_debug` | `(line)` | `HAND3D_SLOT_DEBUG` 环境变量指向文件时写槽位规划事实(诊断用) | 追加写文件 | +| `_best_slot_for` | `(pair, tracker, n, exclude=None, bias=None)` | 真 pair 槽位归属:几何(粗 3D 质心按槽位粗→精偏移校正进精空间,与 tracker 预测比距离,≤`_UNRELIABLE_GATE` 达标;两槽相差 ≤`_AMBIGUITY_MARGIN` 时标签优先)→ 标签复活(死亡槽唯一匹配)→ 冷启动 Left→0/Right→1 → 全无返回 -1(丢给双槽伪救援) | 槽位号或 -1 | +| `_DispTracker` | — | 按槽位记录相邻帧 3D 位移中位与一阶差分(抖动,≥8 共同有效点才计) | — | +| `_render_offline_pass` | `(vp_l, vp_r, rows, tri, renderer, out_dir, out_names, fps, w, h, args)` | 第二遍渲染 pass:重读视频逐帧渲染平滑后数据(rot + rect + 可选 2d 三个视频 sink) | 视频路径 dict | +| `run_session` | `(session_dir, args)` | 主流程(详见下文"数据流"节):检测器/投票器/方向自检/精修器/平滑器/tracker 装配 → 主循环 → 离线后处理 → parquet → 视频 | stats dict | +| `_summarize` | `(stats)` | 汇总打印:匹配帧/双手帧/stage-2 采纳率/reason 分布/精修前后重投影误差/三档抖动/各阶段耗时/深度范围 | 打印 | +| `_write_metrics_csv` | `(stats, path)` | 逐帧指标 CSV(与已落盘基线 parquet 对比):`frame_index,n_pairs,err_ours,valid_ours,stage2,err_base,valid_base` | 写文件 | +| `main` | `session_dir [--calib --max-err --max-depth --no-refine --propagate-max --rescue-min-dist --track-debug --crop-size --crop-pad --crop-source --no-smooth3d --freq-min --beta --every --no-video --render-2d --no-parquet --write-episode --compare --out-dir --det-parallel --mp-delegate --det-conf --track-conf --video-encoder --video-smooth --sg-window --sg-v0 --write-smoothed]` | CLI,全参数见 `--help`;`--write-episode` 才写 `/data/keypoints/` 并追加 meta(默认只写 `keypoints_output/`,不动会话目录) | 退出码 | + +**关键数据**: + +- 阈值:`_UNRELIABLE_GATE = 0.15`(m,粗 3D 与活轨迹预测最小距离 >150mm → pair 不可靠)、`_AMBIGUITY_MARGIN = 0.04`(m,两槽距离差 ≤40mm 视为平手 → 标签裁决);`--max-err` 默认 8px、`--max-depth` 默认 3m;`--propagate-max` 默认 15;`--crop-size` 256、`--crop-pad` 0.5、`--crop-source rect`;3D One-Euro `--freq-min` 3.0、`--beta` 0.3;离线平滑 `--sg-window` 7、`--sg-v0` 0.08(m/s)。 +- 输出(默认 `keypoints_output///`):`hand_3d_refined/chunk-000.parquet`(zstd)、`hand_3d_rotating.mp4`(1280×720)、`stereo_triangulate_refined.mp4`(矫正图并排)、可选 `stereo_2d_refined.mp4`(原图 2D 叠加)、`track_events.csv`(`--track-debug`)、`metrics.csv`(`--compare`)。parquet 先于视频写盘:视频渲染失败不影响数据。 +- stage-1 双线程(仅 CPU delegate,MediaPipe 推理释放 GIL 实测 ~1.9×;GPU 双线程 0.84× → gpu 顺序,`--det-parallel auto`)。 +- 槽位规划修复注释:pair 不再按列表顺序占槽(双手同 label 或单 pair 时列表顺序会串槽)。 + +**调用关系**:调用本子包除 `mp_gpu`(经 `detector` 间接)外的全部模块 + `stereo_s80m.render_stereo`/`stereo_triangulate` + `hand_detection.hand_pipeline_mediapipe`;被 `hand_3d/__init__.py:25` 导出为 `main`。 + +### hand_3d/probes/probe_compare3.py + +**作用**:探针——双配置硬对比(纯 MP 单阶段 vs 纯 MP 两阶段)。读两个 run 目录(同一会话、同默认后处理,仅 stage-2 不同)的 parquet + 视频:① 指标表(打印 + `compare_report.csv`):err mean/p95、双手帧、propagated 数、label 翻转次数、raw/offline 抖动中位;② 三个并排视频(`montage/`):`rect_side_by_side.mp4`(0.5×)、`rect_zoom4x.mp4`(跟随 B 手部 ROI 4× 放大,亚像素精度差在此可见)、`rot_side_by_side.mp4`。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_jitter` | `(h3)` | 与 `_DispTracker` 同口径的抖动中位(帧间共同有效点位移中位的一阶差分中位,mm) | float | +| `compute_metrics` | `(run_dir)` | 读 `hand_3d_refined/chunk-000.parquet` 计算全指标(含 hand_0/hand_1 label 翻转次数) | dict | +| `_montage_rect` / `_montage_zoom` / `_montage_rot` | — | 并排视频生成;zoom 版 ROI 中心 = B 每帧 hand_0 的 stage-1 左目 2D 点中位(5 帧滑动中值防跳变;注释:3D 质心会被深度离群点拉偏,实测中心 vs 2D 质心 p90 差 179px) | 视频文件 | +| `main` | `--a --b [--montage ]` | 指标对比 + montage 视频 | 退出码 | + +**关键数据**:帧率栏来自 run 日志硬编码(`fps_log = {"a": "101.4", "b": "26.6"}`);指标表会话为 222_000008。**调用关系**:使用 `hand_3d/video_writer.create_video_sink`;独立 CLI。 + +### hand_3d/probes/probe_jitter.py + +**作用**:探针——P5 抖动验收:对 offline 模式跑出的 parquet(`hand_3d`=原始精修值、`hand_3d_smoothed`=离线零相位平滑值)复现因果 One-Euro(与主循环 `Hand3DSmoother` 同参数 freq_min=3.0/beta=0.3,ts 用标称 25fps 帧间隔)作第三列对比。指标与 `_DispTracker` 同口径:`disp(t)` = 相邻帧共同有效点位移中位、`jitter(t) = |disp(t) − disp(t−1)|`。速度分带(25fps):低速 disp<2mm(<50mm/s)、中速 2-6mm、快段 >6mm(>150mm/s)。验收线:低速段 smoothed jitter 中位 <1.0mm;快段 |smoothed−raw| 中位 <1.5mm;长缺口(>15 帧)smoothed 保持 NaN 不幻觉。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_load` | `(path)` | 读 parquet → raw/smoothed/propagated 三维数组 | 三元组 | +| `_causal` | `(raw, labels)` | 复现主循环因果 One-Euro(label 变化重置滤波器) | (N,2,21,3) | +| `_band_stats` | `(name, col, mask, raw, disp)` | 速度分带统计:jitter 中位/p90 + 对 raw 的保真中位 | 打印 | +| `main` | `parquet`(argv) | 三列分带对比 + 传播/长缺口检查 | 退出码 | +| `synth_still` | `(n=200, sigma_mm=1.2, seed=7)` | 合成静止手测试:噪声模型来自 P2 实测(GPU delegate 2D 抖动中位 0.72px(1280×800,fx_rect=362)→ z=0.5m 处 3D σ ≈ 0.72px×0.5m/362px×1.48 ≈ 1.2mm);含快段台阶(帧 120-160 匀速 40mm/帧平移)验证零相位无滞后 | 退出码 | + +**调用关系**:复用 `hand_detection.hand_pipeline_mediapipe.OneEuroFilter3D`;独立 CLI(`--synth` 走合成测试)。 + +### hand_3d/probes/probe_mp_gpu.py + +**作用**:探针——GPU delegate 冒烟 + 单目计时 + CPU/GPU 关键点差值。只读不落盘。用法:`python probes/probe_mp_gpu.py [video_path]`(默认 `data/recordings/222/222_000008/videos/stereo_left/chunk-0000/stereo_left.mp4`)。 + +**类/函数**:脚本式(无函数导出)。流程:`smoke_test_gpu(MODEL)` → 读 20 帧 → CPU/GPU 各预热 3 帧 + 计时(ms/帧)→ 逐帧同 label 手对算关键点 `max|Δ|`(打印中位/p90/max)。 + +**调用关系**:使用 `hand_3d/mp_gpu.FastHandLandmarker` 与 `smoke_test_gpu`;独立 CLI。 + +### hand_3d/probes/probe_nvenc.py + +**作用**:探针——管道写器冒烟:nvenc/libx264 直出 + BrokenPipe latch + 可解码性。只写 `/tmp`,不落仓库。用法:`python probes/probe_nvenc.py`。 + +**类/函数**:脚本式。流程:打印 `find_ffmpeg()`/`has_nvenc()` → 对 4 种 encoder(`auto/nvenc/libx264/mp4v`)各写 30 帧随机帧并回读验证可解码性与首帧均差 → BrokenPipe 测试(非法编码器 `h264_bogus_codec` 让 ffmpeg 启动即退出,断言 `latch=True, final=None`)。 + +**调用关系**:使用 `hand_3d/video_writer`(`create_video_sink`、`find_ffmpeg`、`has_nvenc`、`PipeVideoWriter`);独立 CLI。 + +## 数据流 + +完整链路(标定 → 2D → 三角化 → 槽位跟踪 → 平滑 → 渲染/parquet): + +**0. 标定准备(采集前)** + +- `capture_calibration.py`:SDK 出厂标定静态 yaml(`FAYSSENSE_SDK_DIR` 环境变量定位 `config/calib/calib.yaml`)→ 内参缩放到 1280×800 → `config/s80m_stereo_calibration.json`。 +- `export_calibration.py`(可选,连相机):设备 ROM `FAYS_VIK_GetCalibrationParam` → 会话级 `calibration/head_stereo.json` + 设备级 JSON + DumpCalib yaml 备份。 +- 标定查找链(`stereo_triangulate.load_stereo_calibration`):显式 `--calib` → episode `calibration/head_stereo.json` → 设备级 `config/s80m_stereo_calibration.json`。 + +**1. 采集**:主程序 `ui/main_window.py:703` 子进程运行 `read_stereo_rgb.py --pipe -`(启动时按 FTDI 设备名+USB 接口号自动解析端口重写临时 yaml),左右目 JPEG + IMU 二进制流经管道传回录制为 `videos/stereo_left|right/` + IMU parquet + `timestamps.json`。 + +**2. 离线 3D 手部管线**(`hand_3d/run_pipeline.py`,核心链路): + +1. **stage-1 检测**:每目独立 `MediaPipeDetector`(`--mp-delegate auto`:GPU 子进程冒烟通过才切,失败回退 CPU;CPU 时两目双线程并行)→ 左右各 ≤2 只 `DetectedHand`(float 亚像素 21 点)。 +2. **手性投票**:每目一个 `HandednessVoter.update` 原地覆盖 label(7 帧票仓严格多数 + 交叠守卫)。 +3. **跨目配对 + 粗三角化**:`match_hands`(几何主判据,≤2×2 穷举)→ `StereoTriangulator.triangulate` 粗 3D(左目相机系,米);先做左右方向自检(两种配对比平均重投影误差决定 `swap_cams`)。 +4. **槽位规划 + 遮挡传播**:真 pair 经 `_best_slot_for` 按轨迹归属槽位(几何 + 标签裁决);缺手槽位 `HandSlotTracker.predict` 生成预测 3D → `make_pseudo_pair` 伪 pair(`max_lost=15` 幻觉硬顶,`--propagate-max 0` 全关)。 +5. **stage-2 透视裁剪精修**:`CropRefiner.refine`——3D 投影 → 矫正图手 ROI 256² 裁剪图(`crop_source="rect"`)→ 每目独立 num_hands=1 检测器重检测 → 对极 y 对齐(左右 y 取平均)→ `rect_to_raw` 回原始像素 → 二次三角化;采纳判据"严格优于粗结果"(伪 pair 走绝对质量门槛)。 +6. **tracker 回写**:真 pair / 救援成功 → `observe_slot`(αβ 更新,label 变化重置);失败 → `mark_lost`。粗→精偏移对(`slot_bias`)持续维护供槽位几何校正。 +7. **因果平滑(渲染用)**:`Hand3DSmoother.update` 对 (2,21,3) 逐点 One-Euro;parquet 存精修原始值。 +8. **parquet 落盘**:`io.write_parquet` → `keypoints_output///hand_3d_refined/chunk-000.parquet`(LeRobot 风格列 + `stage2`/`propagated`/`hand_3d_smoothed`)。 +9. **离线后处理**(`--video-smooth offline`,默认):`fill_gaps`(≤15 帧短间隙插值,覆盖传播值)→ `offline_smooth`(savgol 零相位 + 速度自适应混合 + 跳变阻尼)→ 写入 `hand_3d_smoothed` 新列。 +10. **第二遍渲染 pass**:重读视频,`RotatingSkeletonRenderer.render`(3D 旋转视角)+ `overlay_view`(矫正图骨架叠加)+ 可选 `overlay_view_2d` → `create_video_sink`(nvenc→libx264→mp4v 回退)→ `hand_3d_rotating.mp4`、`stereo_triangulate_refined.mp4`、`stereo_2d_refined.mp4`。 + +**3. 旁路/下游**: + +- **单阶段后处理**(旧路径,无裁剪精修):`hand_triangulate.py` 直接写 episode `data/keypoints/` parquet;`hand_benchmark.py` 做参数扫描基准。 +- **纯渲染重放**(不重新检测):`render_stereo.render_session_from_parquet` 从已落盘 parquet 出视频。 +- **离线 SLAM 数据集**:`export_offline_slam_dataset.py` 会话 → 矫正灰度 PNG + images/imu CSV + `orb_calibration.yaml`(ORB-SLAM3 FileStorage 格式)→ `validate_offline_dataset.py` 本地复刻客户侧验收(格式键 + rectify 一致性 + 数据完整性)。 +- **D435 复用**:`tools/hand_3d_d435/` 复用本模块的 `detector`/`identity`/`track3d`/`smoother`/`renderer_3d`/`video_writer`/`io`(仅替换数据源与部分几何),与 S80M 管线共享全部跟踪/平滑/渲染逻辑。 + +## 产物与交付目录(非源码) + +- `tools/stereo_s80m/offline_slam_output/`:`export_offline_slam_dataset.py` 的默认输出根(`session_*` 数据集目录与 `.tar.gz` 包),首次运行后生成、仓库内不保留,产物不参与代码。 +- `tools/stereo_s80m/dist/s80m_stereo_camera/`:客服交付版自包含副本(`read_stereo_rgb.py` + `export_calibration.py` + `pipe_consumer.py` 管道协议消费示例),与仓库侧同名脚本同源,改本目录脚本时需同步更新交付版。 diff --git a/collector/docs/tools.md b/collector/docs/tools.md new file mode 100644 index 0000000000000000000000000000000000000000..f3ecaa3b6ef649e931184bf9f7abe2d9b56472e0 --- /dev/null +++ b/collector/docs/tools.md @@ -0,0 +1,339 @@ +# tools/ + +## 定位 + +`tools/` 是独立工具包集合,与主程序(`ui/`、`core/`)完全解耦:仓库其余代码不 import 它(全仓 grep `import tools`/`from tools` 无命中),它只单向复用 `tools/stereo_s80m/hand_3d/` 与 `tools/hand_detection/` 的既有组件(只读,不改任何现有文件),输出统一落在 `keypoints_output/` 下。 + +每个入口脚本自带 `sys.path` shim——把仓库根与 `tools/` 插入 `sys.path`,从而能直接 `from hand_3d_d435.*`、`from stereo_s80m.hand_3d.*` 自导入,**无需安装、无需改环境变量**(唯一例外:`tools/glove_package/` 内脚本要求 cwd 在包目录内,见下)。 + +## 目录总览 + +| 子目录/文件 | 一句话作用 | +| --- | --- | +| `tools/diag_color.py` | S80M 子进程 pipe 输出一帧的颜色通道诊断(需 `FAYSSENSE_SDK_DIR`) | +| `tools/diag_frame_layout.py` | ctypes 直连 FaysSense SDK 打印标定/帧布局/双目相关性(需 `FAYSSENSE_SDK_DIR`) | +| `tools/hand_3d_d435/` | D435 RGB-D 单目 3D 手部关键点独立模块(实时 demo + 离线批处理 + 验收探针) | +| `tools/hand_3d_d435/probes/` | 6 个离线验收探针(对齐/一致性/完整性/标签/传播/骨长) | +| `tools/hand_3d_d435/tools/` | 3 个配套小工具(parquet 渲染、交付版 demo 导出、标定提取) | +| `tools/hand_3d_d435/run_live_d435.sh` | 实时 demo 启动器(venv 选择 + 参数透传) | +| `tools/hand_3d_d435/run_d435.sh` | 离线批处理启动器(venv 选择 + 参数透传) | +| `tools/hand_3d_d435/calibration/` | 固化标定 JSON(`.gitignore` 第 48 行忽略,需先跑提取脚本生成) | +| `tools/hand_3d_d435/新手套接入.md` | 新手套(不同纹路/图案)接入验证说明 | +| `tools/glove_package/` | YOLO-World + RTMPose 手套识别/标注/训练自包含工具包(11 个 .py) | +| `tools/glove_package/使用说明.md` | 工具包安装与用法总说明 | +| `tools/glove_package/yolov8m-worldv2.pt` | YOLO-World 检测器权重(默认,被 `hand_3d_d435` 复用) | +| `tools/glove_package/yolo11n.pt` | 检测器训练基座权重(`train_detector.py` 默认 `--model`) | +| `tools/demos/` | 交付版 demo 与自检脚本(S80M 深度引擎、双目 2D、手套关键点、hdf5) | `docs/demos.md` | +| `tools/hand_detection/` | 手部检测:YOLO 手套检测(`best.pt`、`world_detector.py`)+ MediaPipe 裸手管线 | `docs/hand_detection.md` | +| `tools/stereo_s80m/` | S80M 双目工具:标定/三角化/渲染/离线 SLAM 导出(主程序子进程) | `docs/stereo_s80m.md` | +| `tools/hand_3d_s80c/` | S80C 双目实时裸手/手套关键点 demo(含自包含 SDK `third_party/`、`build_dist.sh` 分发包) | 包内 `README.md` | +| `tools/fayssense_depth_sdk/` | FaysSense VI Kit 深度引擎 SDK(C++,专有;S80C demo 自包含用副本) | 包内 `README.md` | +| `tools/models/` | 模型权重:`hand_landmarker.task`(MediaPipe 裸手关键点) | — | +| `tools/tests/` | 16 个回归/冒烟测试(11 离线 + 5 真机,见文末) | `README.md` 测试节 | +| `tools/weights/clip/` | CLIP ViT-B-32 大权重(gitignore,不随仓库分发) | — | + +本文档详解覆盖 33 个 `.py` 文件(2 诊断 + 11 手套包 + 11 D435 模块 + 6 探针 + 3 小工具);`demos/`、`hand_detection/`、`stereo_s80m/`、`hand_3d_s80c/`、`tests/` 等目录的脚本见各自文档。 + +## hand_3d_d435 模块 + +D435 RGB-D 单目 3D 手部关键点独立模块(与主程序解耦)。链路两版同源: + +- **离线**(`run_pipeline_d435.py`):RGB(1280×720) MediaPipe 2D(+ 手性投票)→ 原生深度(848×480 mm PNG) 前向对齐抬升 3D(彩色相机系,米)→ 单目槽位分配 → `HandSlotTracker` 遮挡传播 → tracker 前向+后向填充 + `offline_smooth` → 旋转渲染 + RGB 叠显 + parquet。 +- **实时**(`live_demo.py`):同上,仅把批处理段换成 αβ + OneEuro 在线平滑链,并加 M1/M3/M5/M6 展示路径稳定性修正(见下)。 + +### 子模块文件详解 + +#### `__init__.py` + +**作用**:包说明文档串,无代码。声明模块只复用 `tools/stereo_s80m/hand_3d/` 组件(detector/identity/track3d/postprocess/renderer_3d/video_writer/io),不改任何现有文件,输出落在 `keypoints_output/`。 + +#### `depth_align.py` + +**作用**:深度→彩色离线前向对齐 + 关键点深度采样。采集链路(`core/d435_camera.py`)不做 `rs2.align`,本模块逐深度像素投影:`P_d = ray·Z_d` → `P_c = R·P_d + t` → 彩色投影,z-buffer 保最近(0=无效哨兵),再空穴回填(848×480→1280×720 是 ~2.12× 上采样,rint 跳列跳行留 ~50% 空穴,3×3 min 邻域 3 轮回填,只写空穴不腐蚀有效值)。 + +公开接口: + +| 接口 | 说明 | +| --- | --- | +| `load_session_depth_intr(session_dir)` | 读录制期 `calibration/head_stereo.json` → 深度内参 dict(fx/fy/cx/cy/width/height),失败返回 None | +| `load_calib(calib_path=None)` | 读固化标定 JSON(默认 `tools/hand_3d_d435/calibration/d435_color_calib.json`),缺失抛 `FileNotFoundError` 并提示先跑提取脚本 | +| `DepthAligner(color_intr, depth_to_color, depth_intr)` | 构造时预计算深度侧单位射线与 R/t(t 米→毫米) | +| `DepthAligner.align_depth_to_color(depth_mm)` | (dh,dw) uint16 毫米深度 → (ch,cw) float32 aligned 深度(0=无效) | +| `DepthAligner.sample_points(aligned, uv, band=None)` | (N,2) 像素坐标 → (N,) 深度 mm;3×3 窗口取中位(有效 ≥2 才出数),`band=(z_lo,z_hi)` 时先按深度带过滤(手缘点抗背景混入) | + +**关键数据**:`_MAX_DEPTH_MM = 8000.0`(远背景离群上限)、`_FX_REL_TOL = 0.01`(深度内参交叉核对容差)。`python depth_align.py` 可直接跑合成自测(恒等外参逐点精确、t_x=25mm 平移、中位抗离群、回填不腐蚀)。 + +**调用关系**:被 `lift3d.py`、`replay_compat.py`、`run_pipeline_d435.py`、`live_demo.py`、`probe_align_overlay.py`、`probe_live_consistency.py` 导入。 + +#### `lift3d.py` + +**作用**:2D `DetectedHand` + aligned 深度 → 彩色相机系 3D(米)。`LiftResult`/`D435Pair` 两个 dataclass mimic 双目管线的 `RefinedPair` 接口,使 `io.pack_3d`/`pack_errors`/`pack_stage2` 零改动可消费。`mean_error` 恒 NaN(单目无重投影概念),真实质量信号走旁挂 metrics。 + +| 接口 | 说明 | +| --- | --- | +| `LiftResult` | `points_3d`(21,3 米,NaN=无效)、`mean_error`(恒 NaN)、`valid_count`(实测有效点数) | +| `D435Pair` | `result`、`left_label`、`used`、`hand2d`(21,2)、`n_valid`、`det`、`measured`(21, bool:z 来自实测,False=补点) | +| `lift_hand(hand, aligner, aligned, band=True, complete=True)` | 深度采样抬升;`band`=两遍带约束采样(手深中位 zc ± 0.12m 带内取中位);`complete`=缺失点补到 zc、x,y 按 2D 反投影("保持 z、调 x,y") | +| `apply_slot_zc(pair, zc, aligner)` | M5:补点深度锚定到槽级稳定 zc,只动 `measured=False` 的补点,实测点不动 | +| `gate_observations(pts, pred, gate=0.15, wholesale_frac=0.6)` | 时序一致性门:|观测−预测| > 0.15m 的点置 NaN(tracker 对 NaN 走纯预测);可疑点 ≥60% 时返回 `(原样, True)` 触发槽位重置 | + +**关键数据**:`BAND_HALF_M = 0.12`、`BAND_MIN_VALID = 4`(第一遍有效点不足退无约束)、`GATE_M = 0.15`。 + +**调用关系**:被 `fill_track.py`(`gate_observations`)、`mono_assign.py`(自测)、`run_pipeline_d435.py`、`live_demo.py`、`probe_live_consistency.py` 导入。 + +#### `mono_assign.py` + +**作用**:单目双手槽位分配(`hand_0`/`hand_1` 连续身份),仿双目 `_best_slot_for` 的决策层级: + +1. 冷启动:标签惯例 Left→slot0 / Right→slot1,无标签按检测序号; +2. 标签唯一命中存活槽 + 几何门(≤0.15m); +2b. 标签唯一命中困境槽(上帧无真手)→ 不设几何门(恒速外推会漂移,label 是唯一可靠信号); +3. 贪心几何:剩余手入最近未占用存活槽(质心 ≥4 有效点,不足退 2D 判据;label 冲突守卫); +4. 互斥守卫:双真实且腕距 <0.10m → 两种排列取总 cost 更小者(须严格优于 ≥5mm 防抖动); +5. 未见槽冷启(label 惯例/无标签单死槽兜底); +6. 兜底丢弃。 + +| 接口 | 说明 | +| --- | --- | +| `assign_mono_slots(pairs, tracker, n, color_intr, lost_counts=(0,0), debug=False)` | `list[D435Pair]`(≤2) → `[slot0_pair|None, slot1_pair|None]`;`lost_counts` 供 2b 规则用 | +| `_cost(pair, slot_pred, color_intr)` | 3D 质心距槽预测(米);质心不可靠退 2D 判据(预测投影 vs 2D 质心,像素距 ×Z/fx) | +| `_dbg(n, labels, pred, out, evt)` | `HAND3D_SLOT_DEBUG` 环境变量指向文件时追加决策日志(`atexit` 落盘) | + +**关键数据**:`UNRELIABLE_GATE = 0.15`、`WRIST_MUTEX = 0.10`、`SWAP_MARGIN = 0.005`、`MIN_VALID_PTS = 4`。`python tools/hand_3d_d435/mono_assign.py` 可跑 7 项构造轨迹自测。 + +**调用关系**:import `stereo_s80m.hand_3d.track3d.HandSlotTracker`;被 `run_pipeline_d435.py`、`live_demo.py`、`probe_live_consistency.py` 调用。 + +#### `fill_track.py` + +**作用**:离线缺失帧槽的 tracker 前向+后向填充(替代 `fill_gaps` 短桥接)。用与实时版同源的 `HandSlotTracker`(αβ、逐点 NaN 保持纯预测)沿时间轴前向跑一遍(真实观测 observe、缺失帧 predict),再反向跑一遍补首观测前的头部段;合并时真实观测优先、前向预测次之、后向兜底。轨迹是恒速外推,比线性插值更物理;门控与实时版一致(`gate_observations`)。`fill_gaps` 语义保留:被填帧 `present=True`、`propagated=True`、label 取最近 present 帧;从未见过的槽不幻觉 present。 + +| 接口 | 说明 | +| --- | --- | +| `tracker_fill(rows, max_lost=15)` | 原地修改 rows(parquet 行字典列表),返回填充帧-槽数 | +| `_forward_pass(h3, present, prop, labels, max_lost)` | 单方向 tracker 填充 → (N,2,21,3) 状态轨迹 | + +**调用关系**:被 `run_pipeline_d435.py` 调用(`--propagate-max` 透传 max_lost);自测在 `__main__`。 + +#### `render_overlay.py` + +**作用**:D435 RGB 单视叠加渲染:2D 骨架(分色,复用 `tools/hand_detection` 的 `FINGERS` 色表 + 自含 `PALM_CONNECTIONS`)+ 逐关键点平滑深度 mm 标注 + 槽位 label/propagated HUD;另含伪彩深度叠层。 + +| 接口 | 说明 | +| --- | --- | +| `draw_overlay(rgb, hands2d, hands3d, labels, propagated, presents, frame_idx, total, title=...)` | 返回叠加帧(拷贝,不改原图);absent 槽不画 | +| `blend_depth(rgb, aligned_mm, alpha=0.4)` | 伪彩深度叠层:300-1200mm 归一 JET(无效=不叠),α 混合回 BGR | +| `PALM_CONNECTIONS` / `FINGER_CHAINS` | 掌心连接(腕-掌子集)与每指画法链(拇指 1→2→3→4,其余 0→MCP→…→指尖) | + +**调用关系**:被 `run_pipeline_d435.py`、`live_demo.py`、`probe_align_overlay.py` 导入。 + +#### `replay_compat.py` + +**作用**:录制会话布局/标定兼容层(`live_demo --replay` 用)。自动探测三类会话:新会话(槽名随 GUI 用户命名 → `videos/D435_depth_rgb/`、`depth/D435_depth/`,`head_stereo.json` 可能是 D405 内参)、旧会话(`videos/d435_rgb` + `depth/d435_depth` + `head_stereo.json` 即 D435 内参)、双 RealSense 并存会话。 + +| 接口 | 说明 | +| --- | --- | +| `find_video_any(session)` | 依次尝试小写/大写槽名的 RGB 视频(兼容 `chunk-0000/` 布局) | +| `find_depth_dir(session)` | 依次尝试小写/大写槽名的深度 PNG 目录 | +| `load_session_depth_intr_any(session)` | head_stereo 深度内参;两文件并存且 fx 差 >1% 时改读 `D435_depth_rgb_calibration.json`(head_stereo 记录的"最后写入"设备不可靠) | + +#### `glove_detector.py` + +**作用**:黑手套检测器(YOLO-World 手套框 + RTMPose hand5 21 点 + 帧间稳定层)。检测契约对齐 `DetectedHand`(landmarks (21,2)、MediaPipe 拓扑 0=腕、label、score=框 conf),下游 voter/抬升/槽位/平滑/渲染零改动。 + +| 接口 | 说明 | +| --- | --- | +| `GloveDetector(weights=None, det_conf=None, ...)` | 权重默认 `tools/glove_package/yolov8m-worldv2.pt`;文件名含 "world" 走 world 后端(conf 0.05),否则普通 YOLO(`best.pt` 回退开关,conf 0.3);惰性加载(ultralytics/torch/rtmlib 首次构造才 import,裸手启动零开销) | +| `detect(frame_bgr)` | → `list[DetectedHand]`,按 track_id 稳定序输出 | +| `reset()` / `close()` | 清空全部帧间状态 / 释放模型 | + +**关键数据(帧间稳定层)**:`HandTracker` 贪心 IoU 匹配 + 框 EMA(α=0.7) + 运动门控 3px(静止帧免 RTMPose 推理、0.33s 强制刷新)+ 丢框持 3 帧;逐点 `OneEuroFilter2D`(freq_min=5.0/beta=0.05/dcutoff=1.0,归一化坐标域,键 (track_id, 点序号));退化族过滤(框外点 ≥16 / 唯一点 <15 / span <0.2×框对角线);per-track 手性锁存(连续 3 票相同锁死;双手框中心距 <0.05×max(w,h) 冻结,镜像 voter latch);`pose_conf_thr`(默认 0.3)持出低置信骨架;复活继承 `_REVIVE_MAX=90` 帧 / `_REVIVE_DIST=0.3×max(w,h)`(死亡 track 的 OneEuro/锁存/冻结缓冲 re-key 给新 track,消重捕捉闪烁)。 + +**调用关系**:只读复用 `stereo_s80m.hand_3d.detector.DetectedHand`、`hand_detection.hand_pipeline_mediapipe.OneEuroFilter2D`、`glove_package` 的 `world_detector` 与 `hand_tracker`(shim 把 tools/、glove_package、tools/hand_detection 三目录都插入 sys.path);被 `live_demo.py` 调用(按 g 键热切换)。 + +#### `pose_backends.py` + +**作用**:姿态关键点后端(黑手套链),把 RTMPose / MediaPipe 两个后端统一到同一契约,`GloveDetector` 只依赖契约、后端可热切换。契约:`backend(frame_bgr, bboxes=None) -> (kpts, scores)`——`kpts` (M,21,2) 全图像素坐标(21 点 MediaPipe 拓扑 0=腕,与 RTMPose hand5 同序,手性几何判据直接可用),全局失败返回 None;`scores` (M,21) 或 None(RTMPose=SimCC 逐点响应、MediaPipe=逐点 visibility,下游只取每手均值对照 pose_conf 门);`backend.close()` 释放(重建前必调,幂等);`backend.device` 实际推理设备。 + +| 接口 | 说明 | +| --- | --- | +| `RtmposePoseBackend(device)` | RTMPose hand5(onnxruntime,SIMCC 256×256);首次构造模型未缓存时自动从 openmmlab 下载;CUDA EP 初始化失败自动回退 CPU | +| `MediaPipePoseBackend(model_path=None, device)` | HandLandmarker Tasks API(venv mediapipe 1.0.0 无 legacy `mp.solutions`,必须 `from mediapipe.tasks import python`);默认模型 `tools/models/hand_landmarker.task`;IMAGE 模式整图 `num_hands=2` 检测 + 质心就近关联到入参 bboxes——实测(000005)框外扩 1.25 裁剪喂入 0/5 检出、整图 5/5 检出,输出仍按入参框顺序每框一行,未关联框吐零行 | + +**关键数据**:`_MP_PAD = 1.25`(裁剪外扩,与 RTMPose bbox padding 同口径)、`_MP_MIN_CONF = 0.3`(检测/存在阈值放宽,由下游退化过滤 + pose_conf 门兜底保召回)。 + +**调用关系**:被 `glove_detector.py` 使用(后端热切换);MediaPipe 后端对黑手套检出率低(整图 5/60 帧 vs world 每帧出框),主要供裸手/效果对比。 + +#### `run_pipeline_d435.py` + +**作用**:离线批处理入口。用法 `./tools/hand_3d_d435/run_d435.sh [选项]`;产物(`keypoints_output///`):`d435_hand_3d_rotating.mp4`、`d435_rgb_overlay.mp4`、`hand_3d_refined/chunk-000.parquet`、`d435_metrics.csv`(`--track-debug` 追加 `track_events.csv`)。 + +参数:`--out-dir`、`--calib`、`--mp-delegate`(cpu/gpu,默认 cpu)、`--det-conf`(0.5)、`--track-conf`(0.5)、`--propagate-max`(15,槽位丢失硬顶)、`--depth-overlay`(overlay 视频叠伪彩深度)、`--video-encoder`、`--no-video`、`--no-parquet`、`--track-debug`。 + +**关键流程**:空帧不喂 voter(identity.py 空帧会清轨迹 → 重建期同 label 闪烁);`gate_observations` wholesale 时借 `"\x00reset"` 标签触发槽位重置;收尾 `tracker_fill` + `offline_smooth(sg_window=7, sg_poly=3, v0=0.08, fps, still_window=21)`;parquet 列 schema 与双目管线同构(`pack_3d`/`pack_errors`/`pack_stage2`)。汇总打印每槽 present/propagated 比例、label 翻转数、腕位移 p50/p95、腕→中指 MCP 骨长。 + +内部函数:`_load_episode_task`(pyarrow 直读 episodes parquet + tasks.jsonl)、`_pack_2d_slots`、`_render_videos`、`_summarize`、`_write_metrics`、`_nan_pair`/`_pred_pair` 占位构造。 + +**调用关系**:import `stereo_s80m.hand_3d` 的 detector/identity/track3d/postprocess/renderer_3d/video_writer/io + 本模块其余全部子模块。 + +#### `live_demo.py` + +**作用**:实时 demo 入口(模块内 1415 行的主体)。三窗口:`D435 live: RGB overlay`(骨架+深度标注+HUD)、`D435 live: 3D view`(3D 骨架,左键拖拽环绕/俯仰、`r` 复位;输入平移到首帧锁定的世界锚点,不拖拽时视角/网格/缩放完全静止)、`D435 live: depth`(aligned 深度 0.3-1.5m 伪彩)。按键:`q`/ESC 退出、`s` 截图(`keypoints_output/live_d435/`,三窗口各一张)、`d` 深度伪彩叠层切换、`g` 裸手/黑手套热切换(切回裸手重建 MediaPipeDetector 实例——`det.reset()` 只 close landmarker 不重建,实机踩过)、`r` 复位视角。 + +输入源三类:`LiveD435Source`(pyrealsense2 直开,rgb8 1280×720@30 + z16 848×480@30;流组合失败自动回退 1280×720 双流、848×480@60 双流——D405 深度/彩色须同分辨率;对齐用**本机实时内参/外参**,换设备自洽;设备独占,主程序预览开启时 EBUSY)、`ReplaySource`(`--replay `,按录制 fps 步调回放,经 `replay_compat` 兼容新旧布局)、`UvcSource`(`--uvc`:设备号/路径/URL,无深度 → 2D-only 单窗口模式,只产 2D 关键点渲染)。 + +主要参数:`--replay` / `--replay-pace`(30)、`--uvc`、`--calib`、`--delegate`(auto=GPU 子进程冒烟成功则 GPU)、`--fill`(默认 1 轮填洞:覆盖 91.6% vs 3 轮 94.0%,省 20ms/帧)、`--propagate-max`(15)、`--det-conf`/`--track-conf`(0.4)、`--glove` 及 `--glove-weights/-det-conf/-pose-conf/-nms-iou/-lost-timeout/-box-alpha/-freeze-max`、`--rs-serial`、`--exposure`(0=自动,运动模糊丢手时试 4000-10000µs)、`--stats`、`--depth-overlay`、`--no-window`、`--export`。`--export` 落盘四件套:`keypoints_2d.parquet`(xy 定长 float32[42],像素)、`keypoints_3d.parquet`(xyz float32[63],质心锚定 3D 米)、`render.mp4`、`rgb_overlay.mp4`(H.264+faststart,venv cv2 只能写 mp4v 故走共享 sink)。 + +展示路径稳定性修正(不回灌 tracker):**M5** 补点深度锚定槽级 zc EMA(换手/首帧取实测,否则 0.5 混合,`apply_slot_zc`);**M3①** `_SoftSmoother` 包装 `Hand3DSmoother`(label 变化/空→有重建且几何近 <0.1m 时 0.5 混合软衔接防 snap);**M3②** wholesale 两帧确认(`_ws_agree` tol=0.30,或连续 ≥3 帧强制采信,单帧跳变只走预测显示);**M1** `_CentroidAnchor` 质心锚定(每槽有效点中位质心走强 OneEuroFilter3D(3.0, 0.3, 0.3),输出=输入+(ĉ−c),共模平移在质心层吸收,手内形状原样保留);**M6** 门控锁死豁免(逐点连续被门控 ≥5 帧且观测恢复有限 → 采信观测,防"预测外推越走越远永不恢复")。 + +其他守卫:空帧不喂 voter;两手同 label(voter 重建期)先清空 label 走几何分配;手套模式整体跳过 voter(identity.py 新轨迹同帧双分配缺陷,实测同 label 锁死),身份由 `GloveDetector` per-track 锁存承担。 + +内部类/函数:`LiveAligner`、`LiveD435Source`、`ReplaySource`、`UvcSource`、`_OrbitControl`、`_SoftSmoother`、`_CentroidAnchor`、`_run_uvc_2d`、`_run_3d_chain`、`_ws_agree`、`_resolve_delegate`、`_write_export`/`_write_export_2d`、`_exp_meta`。 + +#### `tools/` 子目录(parquet 渲染 / 交付版导出 / 标定提取) + +- `tools/hand_3d_d435/tools/render_keypoints_parquet.py`:任意 21 点 3D 关键点 parquet(列名同 `io.pack_3d`:`observation.keypoints.hand_3d`/`hand_3d_smoothed`)→ 3D 视角渲染视频。零相机依赖(不 import pyrealsense2/mediapipe,仅 numpy+cv2+pyarrow,`--smooth` 才需 scipy)。选项:`--col`(hand_3d/hand_3d_smoothed)、`--view`(rotating/static)、`--revolutions`、`--yaw`/`--elev`、`--smooth`(渲染前跑 `offline_smooth` 压抖)、`--scale`/`--shift`(尺度修正/平移)、`--frame N`(单帧 PNG 预览)、`--fps`、`--encoder`;支持多文件通配拼接、(N,2,21,3) 与 (N,21,3) 两种展平、`frame_index` 乱序保险;启动时打印数据体检(腕位移/骨长,骨长明显偏小提示 `--scale`)。 +- `tools/hand_3d_d435/tools/demo_export_parquet.py`:跑交付版 `dist/d435_hands_demo_v1.1/d435_hands_demo.py` 并以**钩子**方式抓取每帧数据落 parquet(不复制管线代码、不改交付目录):`install_hooks` 在 `_SoftSmoother.update`(抓槽位原始 3D/平滑 3D)与 `draw_overlay`(抓 2D/labels/present,`frame_idx-1` 收口成行)上挂钩;`Collector` 攒行,schema 复用 `tools/stereo_s80m/hand_3d/io.py` 的 `write_parquet`,与 `run_pipeline_d435.py` 产物同构、现有 probes 可直接读。用法:`venv/bin/python tools/hand_3d_d435/tools/demo_export_parquet.py <会话目录> --out-dir `;输出 demo 原三路视频 + `hand_3d_refined/chunk-000.parquet`。 +- `tools/hand_3d_d435/tools/extract_d435_color_calib.py`:从真机 D435 提取彩色内参 + 深度内参 + depth→color 外参,固化到 `tools/hand_3d_d435/calibration/d435_color_calib.json`(模块离线对齐的唯一标定来源;外参语义 `P_color = R·P_depth + t`,t 单位米,D435 典型 |t|≈25mm)。必须用 venv python(pyrealsense2 只装在 venv);`--session` 时与录制 `head_stereo.json` 深度内参交叉核对(差 >1% 告警"可能不是同一台设备录制");自带防呆(t 范数不在 [10,60]mm 告警、设备被主程序独占时报 busy)。产物含 serial/firmware 字段(运行时值,文档不转载)。 + +### probes/ 探针(合表) + +全部用 venv python 运行,输入 parquet 的用 `run_pipeline_d435.py` 产物。 + +| 文件名 | 用途 | 输入 | 输出 | +| --- | --- | --- | --- | +| `probe_align_overlay.py` | 深度↔RGB 对齐验收:覆盖率 + 手部深度一致性 A/B(正确 vs 反号外参)+ 边缘距离(仅信息,实测噪声底之上不作判据) | `--session` 会话目录(+ `--calib`、`--frames` 抽样帧号) | `probe_align/` 下 `frame_XXX_align.png`(伪彩叠层)/`frame_XXX_edges.png`(深度边叠层)+ 覆盖率中位 ≥60% 与 手散布 ≤200mm 且 ≤0.8×反号 的 PASS/FAIL | +| `probe_live_consistency.py` | 重跑 live_demo 在线链(1 轮填洞 + αβ + Hand3DSmoother)与离线 parquet 逐帧比对 | `--session`(离线产物需先存在) | 两者都有限的腕点(点 0)深度差:中位 <10mm、p95 <30mm 判 PASS/FAIL | +| `probe_3d_completeness.py` | 3D 输出完整性与翻面事件(旋转渲染质量直接判据) | `--parquet`(读 `hand_3d_smoothed`) | 整手 21 点全有限帧率 ≥50%、翻面事件(相邻帧 z 跳 >300mm)≤2 起判 PASS/FAIL;另报有效点中位、腕点有限率 | +| `probe_label_stability.py` | 逐槽 label 翻转计数 | `--parquet` | 全片 0 次翻转(连续 present 帧间 Left↔Right)判 PASS/FAIL;退出码 0/1 | +| `probe_propagation.py` | propagated 比例 + absent 缺口直方图 | `--parquet` | 每槽 propagated <15%、absent 缺口全 ≤15 帧判 PASS/FAIL;另报硬 absent(3D 全 NaN 未幻觉)帧数;退出码 0/1 | +| `probe_bone_lengths.py` | 腕→中指 MCP 骨长自检(标定无关硬判据,剔除 propagated 帧) | `--parquet`(读 `hand_3d` 原始值) | 每槽中位 ∈[72,95]mm、IQR<25mm、<5% 帧出 [55,115]mm、两槽中位差 <10mm 判 PASS/FAIL;退出码 0/1 | + +### launcher 脚本说明 + +- `tools/hand_3d_d435/run_live_d435.sh`:实时 demo 启动器。`VENV_PY` 环境变量可覆盖解释器(默认 `$REPO_ROOT/venv/bin/python`,即 collector/venv,含 pyrealsense2 2.58.3);脚本自动 `cd` 回仓库根后 `exec "$VENV_PY" tools/hand_3d_d435/live_demo.py "$@"`——全部参数原样透传给 `live_demo.py`。例:`./tools/hand_3d_d435/run_live_d435.sh`(直连相机)、`... --replay data/recordings/222/222_000011`(回放)。 +- `tools/hand_3d_d435/run_d435.sh`:离线批处理启动器,同款 `VENV_PY`/`cd` 逻辑,`exec` 到 `run_pipeline_d435.py`。用法 `./tools/hand_3d_d435/run_d435.sh [选项...]`。 + +## glove_package 工具包 + +YOLO-World 检测 + RTMPose 姿态的自包含工具箱(11 个 .py),专为戴手套场景优化(MediaPipe 在手套上完全失效,本方案实测检出 40/40)。**独立运行特性**: + +- **cwd 必须在包目录内**:包内脚本用顶层裸导入(`import hand_common` / `import world_detector` / `from world_detector import iou`)互引,不挂 sys.path shim;默认模型路径 `MODEL_PATH` 以包目录 `_HERE` 锚定(`yolov8m-worldv2.pt`)。从包外 `python tools/glove_package/xxx.py` 会 ImportError——需 `cd tools/glove_package` 后再运行(`hand_3d_d435/glove_detector.py` 则不受此限:它自己把 `glove_package` 插进 sys.path)。 +- **自包含**:不依赖 mediapipe(`hand_common` 刻意不 import 父目录);依赖见 `requirements.txt`(torch/torchvision 由 `setup.bat` 装 CUDA 版,numpy、opencv-python、onnxruntime、rtmlib、ultralytics、openai-clip);首次运行联网下载模型约 450MB(YOLO-World 权重 ~55MB + RTMPose hand5 ~56MB 缓存到 `~/.cache/rtmlib/` + CLIP 文本编码权重约 338MB)。 +- **训练产物在包内 `runs/`**:`train_detector.py` 把相对 `--project` 锚定到包目录(ultralytics 会把相对路径解析到全局 settings 的 runs_dir,产物会落到包外),产出 `runs/hand_det/weights/best.pt`。`dataset/`、`captures1/`、`to_label/`、`verify_pose_out/` 等数据目录也在包内。 + +### 各文件 + +#### `world_detector.py` + +**作用**:YOLO-World 开放词汇检测器——`auto_label.py` 和 `infer.py` 的唯一真值来源(标注框与推理框同一套配置)。 + +| 接口 | 说明 | +| --- | --- | +| `WorldDetector(model, prompt, imgsz, device, nms_iou, use_onnx)` | `.pt` 走 `YOLOWorld` + `set_classes(prompt)`;`.onnx` 走 `YOLO`(ONNX GPU 不可用——缺系统 CUDA Toolkit,强制 CPU) | +| `WorldDetector.__call__(src, conf, max_boxes, wh, reuse_boxes)` | BGR 帧 → `(boxes_xyxy [N,4], confs [N,])`,已过滤 + 两级 NMS + Top-N;`reuse_boxes` 帧跳过缓存 | +| `WorldDetector.postprocess(boxes, confs, w, h, max_boxes, nms_iou)` | 裁画面 + 丢非法/过小框(8px)+ 两级 NMS(中心距 <框宽 15% 且 IoU>nms_iou 判同一只手;中心有偏移只用 >0.85 极高阈值——解决"两只手靠近误删一只")+ 按置信度 Top-N | +| `iou(a, b)` / `_center_close(a, b)` | 框 IoU / 中心距离判据(被 `hand_tracker.py`、`glove_detector.py` 复用) | +| `add_args(ap, max_boxes_default)` / `from_args(args, device)` | 给 argparse 挂公共参数(`--weights/--prompt/--imgsz/--conf/--max-boxes/--det-skip`),保证各脚本命令行一致 | + +**关键数据(默认值)**:`DEFAULT_MODEL = "yolov8m-worldv2.pt"`、`DEFAULT_PROMPT = ["hand","glove"]`、`DEFAULT_IMGSZ = 320`(手占比大时比 640 更准更快)、`DEFAULT_CONF = 0.05`、`DEFAULT_NMS_IOU = 0.6`。 + +#### `hand_tracker.py` + +**作用**:手部身份追踪——贪心 IoU 跨帧框匹配 + 稳定 track_id,解决"框按置信度排序帧间交换 → 关键点粘连"、"丢一帧就清状态 → ID 跳变"。`HandTrack` dataclass 记录框(EMA 平滑)、`last_good_kpts` 逐点冻结缓存、skip/lost 计数。 + +| 接口 | 说明 | +| --- | --- | +| `HandTracker(max_hands=2, iou_match_thr=0.3, lost_timeout=3, movement_thresh=3.0, skip_timeout=10, box_smooth_alpha=0.7)` | 每帧先 `update_detections`(贪心匹配 + 老化 + 清理超时 track + 限活跃数) | +| `get_boxes_for_pose()` | 只在运动超阈值/新 track/skip 超时(静止 10 帧强制刷新)时返回需要推理的框 | +| `update_pose_results(indices, kpts, scores)` | RTMPose 结果写回对应 track,记推理时框中心 | +| `get_results()` | → (boxes, kpts, scores, track_ids);未出过 pose 的 track 吐 (21,2) 零数组(下游注意:`hand_3d_d435/glove_detector.py` 因此额外维护 `_posed` 集合过滤占位) | +| `update_last_good(track_index, point_index, value)` / `get_last_good(...)` | 逐点冻结缓存读写;**注意 `track_index` 是活跃列表下标**(与 `get_boxes_for_pose` 返回的 `self.tracks` 下标不一致,`glove_detector.py` 因此直接改 `track.last_good_kpts` 绕开) | +| `clear()` / `hand_count` | 重置 / 活跃手数 | + +#### `hand_common.py` + +**作用**:RTMPose 方案共用的关键点定义与绘制(21 点与 MediaPipe 同序:0=腕、1-4 拇指、5-8 食指、9-12 中指、13-16 无名指、17-20 小指)。 + +| 接口 | 说明 | +| --- | --- | +| `FINGERS` / `PALM_CONNECTIONS` / `JOINT_SPECS` | 五指 id 与 BGR 色表 / 掌心连接 / 关节表(拇指 CMC/MCP/IP,其余 MCP/PIP/DIP) | +| `angle_between()` / `compute_joint_angles(pts)` | 关节角(度,图像平面算——手指透视缩短时偏小) | +| `count_extended_fingers(angles)` | 伸直判定:拇指 MCP>145° 且 IP>150°;其余 PIP>150° 且 DIP>140° | +| `draw_hand(frame, pts, angles, kpt_scores, thr)` | 骨架+关节角绘制,低于 `thr` 的点画空心 | +| `draw_panel(frame, x, y, lines, width)` | 半透明信息面板 | +| `build_pose(device)` | RTMPose hand5(onnxruntime,首次自动下载 ~56MB) | +| `auto_device()` | CUDA > MPS > CPU | +| `RSCapture(serial, width, height)` | pyrealsense2 颜色流包装,接口对齐 `cv2.VideoCapture`(懒加载) | +| `pose_is_glove(kpts, scores, box, ...)` | 误检抑制:kpt 均值 ≥0.45、≥0.3 的高置信点 ≥15、点团 span ≥0.3×框对角线,三条全过才算真手套 | + +#### `hand_demo_mmpose.py` + +**作用**:摄像头实时手指/关节识别完整 demo(YOLO-World + RTMPose + HandTracker + 逐点冻结 + 数据采集)。快捷键:`q`/ESC 退出、`a` 关节角度、`s` 骨架、`b` 检测框、`h` 帮助、`i` UI 面板、空格暂停、`c` 抓拍、`r` 连续采集、`m` 只存漏检帧(最需要的难样本)。采集目录 `captures1/<时间戳>/`(`session.json` + `frames/000001.jpg` + `labels.jsonl` 预标注——存的是镜像后未画骨架的干净原图)。UVC 源做左右镜像 + 上下翻转(倒装校正),`--realsense` 不翻。遮挡处理:低置信点占比 ≥90% 整手冻结,否则按手指粒度冻结(伸直指/腕/高置信点才更新 `last_good`,阈值 0.2)。检测器可选自训权重(`YOLOWrapper`);`wd.add_args` 挂载 `--weights`(默认锚定包目录)/`--prompt`/`--imgsz`/`--conf`/`--max-boxes`/`--det-skip`。另有 `--output` 出视频、`--data-out` 出逐帧检测 JSONL。 + +#### `infer.py` + +**作用**:RTMPose 实时推理精简版。`--source` 支持摄像头序号/图片目录/视频文件,`--realsense` 走 D435 颜色流;`--detector` 可选 `world`(默认)/`rtmdet`(官方 RTMDet-nano,黑手套上失效,仅基线对照)/自训 `.pt` 路径。含 `--det-skip` 帧跳过(复用上一帧框,CPU 加速)。同一套误检抑制(`pose_is_glove` 连续 2 帧确认)+ 遮挡/逐点冻结(阈值 0.3)。快捷键同 demo 子集:`q`/ESC、`a`、`s`、`b`、`h`、空格。 + +#### `annotate.py` + +**作用**:极简手部框人工标注工具(不用装任何标注软件)。`--dir`(默认 `to_label`)下 `images/` → 同级 `labels/`,保持子目录结构,输出 YOLO 格式(单类别 class id=0)。操作:左键拖拽画框、`u` 撤销、`c` 清空、`d`/空格/→ 下一张、`a`/← 上一张、`g` 跳到第一张未标注的、`q`/ESC 退出(自动保存)。**无框也写空文件**——标记"这张我看过了",`prepare_dataset.py --merge` 会跳过空文件,无手图不会被当负样本混进训练集。`--max-width` 限制显示宽度(超宽图缩放显示、坐标仍按原图写)。标注要点(文件头):框住整只手(指尖到手腕含袖口),偏大 10~30% 没问题。 + +#### `auto_label.py` + +**作用**:手部框自动标注(零样本 / 自举双模式)。零样本=YOLO-World 文本提示直接检(默认),自举=`--model best.pt` 用已训检测器标新数据。**每张图只取置信最高的 N 个框**(`--max-boxes`,默认 1)是过滤误检的关键(原始输出 2.6 框/图)。`--eval` 模式不写标注,拿现有 `labels/` 当 ground truth 打分(IoU≥0.5 命中率 + 匹配框平均 IoU + 最差几张),对比图到 `viz_eval/`(文件名以 IoU 开头,最差排前);`--overwrite` 才覆盖已标注。自动标注完输出核对图 `viz_auto/`,并提示用 `annotate.py` 人工复核。首次运行联网下载 YOLO-World + CLIP 权重(约 400MB)。注意默认 `--device mps`(此文件与其他文件的 auto_device 不一致,非 Apple 机器需显式传)。 + +#### `prepare_dataset.py` + +**作用**:采集数据 → YOLO 检测数据集(单类别 hand)。两阶段: + +1. `--captures ` 扫 `labels.jsonl` 采集会话:有检测结果的帧从 21 点直接算 bbox(白捡的标注,`--pad` 外扩 0.12 与人工框风格对齐);漏检帧导出到 `--to-label` 供人工标(**空标签绝不进训练集**——YOLO 空标签表示"无目标",会把戴手套的手教成背景)。切分按 session(避免相邻帧泄漏进验证集),只有一个 session 时按时间顺序取末尾做验证集。 +2. `--merge ` 把人工标好的合并进 `--out` 数据集(跳过空文件),固定种子随机切 val。 + +产物 `dataset/`:`images/{train,val}` + `labels/{train,val}` + `data.yaml` + `viz/` 核对图(从写入的 .txt 反解坐标画框——画的就是模型真正读到的框)。 + +#### `train_detector.py` + +**作用**:训练单类别手部检测器(替换在黑手套上输出 0 框的 RTMDet)。只训检测不训关键点(实测 RTMPose 给定正确框误差 3.9px,瓶颈只在"找不到手")。默认 `yolo11n.pt`、100 轮、imgsz 640、batch 16;`--project`(默认 `runs`)**锚定到包目录**、`--name`(默认 `hand_det`)→ 最佳权重 `runs/hand_det/weights/best.pt`;`--resume` 从 last.pt 续训;`--no-augment-hsv` 关色相/饱和度增强(黑手套没色彩信息,算力让给几何增强,保留 hsv_v=0.4)。训练完提示 `python infer.py --detector `。要求先跑 `prepare_dataset.py` 生成 `dataset/data.yaml`。 + +#### `verify_pose.py` + +**作用**:拿人工标好的框检验 RTMPose 关键点模型在目标手套上到底行不行——**大批量标注前先跑**(整套"只标框不标点"方案的前提验证)。标 10~20 张即可:`--dir`(含 `images/`+`labels/`)→ 逐张画骨架到 `verify_pose_out/`(`--out`),打印关键点置信均值。结论判定**必须逐张打开图看骨架是否贴合手指**(置信度在空白背景上反而更高);贴合 → 只标框方案成立,不贴合 → 需改方案(标关键点微调或换模型)。 + +#### `fix_clip.py` + +**作用**:修复 openai-clip 在 Python 3.12+ 的兼容问题(`clip.py` 的 `from pkg_resources import packaging` 在新 setuptools 中已移除 → 替换为 `import packaging.version`)。`find_clip()` 在 site-packages 定位 `clip/clip.py`,幂等(已打过补丁或不需要时跳过)。`setup.bat` 装完依赖后自动运行。 + +## 诊断工具 + +两个 FaysSense SDK(S80M 双目)诊断脚本,都从 `FAYSSENSE_SDK_DIR` 环境变量定位 SDK(``),未设置直接报错退出。 + +#### `diag_color.py` + +**作用**:验证 S80M 子进程 pipe 输出一帧的颜色通道是否正确。以子进程跑 SDK 的 `read_stereo_rgb.py --pipe -`(cwd 设为 SDK 目录),按 4 字节大端长度前缀协议逐帧解析左右目 JPEG,`cv2.imdecode` 后按上下半分割(与 GUI 一致,竖图上下半各一目),同时存两份 PNG:`/tmp/s80m_left_BGR.png`(OpenCV 原样 BGR 布局)与 `/tmp/s80m_left_RGB.png`(BGR→RGB 转换)——用图片查看器看哪张颜色正常(如红色物体显示为红色)。**须在 DAQ venv 下运行**(`VENV_PY = sys.executable` 直取当前解释器)。 + +#### `diag_frame_layout.py` + +**作用**:ctypes 直连 SDK 动态库,验证帧布局 + 打印标定数据。加载 `$FAYSSENSE_SDK_DIR/lib/fays_atrak/x86_64/Release/libfays_vikit.so`,按 C++ 符号名(`_Z31FAYS_VIK_CreateHandleWithConfigPPvPKc` 等)声明 5 个接口:创建句柄(配置文件 `config/fays_vikit.yaml`)、取版本、取一帧、取标定参数。输出:每个相机的内参/畸变/外参 `T_cn_cnm1` 与基线(mm);抓一帧后按 2 列×4 行(每行 400 高)统计 8 个子区 mean/std、左右半帧互相关、行 0-1 vs 行 2-3 差异,保存 `/tmp/diag_full_frame.png` 与 `/tmp/diag_grid.png`。启动时预加载 OpenCV `.so.406`/`.so.4.2` 共享库(`RTLD_GLOBAL`)并设置 `QT_QPA_PLATFORM_PLUGIN_PATH` 指向 cv2 自带的 qt plugins,规避 SDK 自带 OpenCV 与本环境 cv2 的冲突。 + +## tests/ 测试 + +16 个测试脚本(11 离线 + 5 真机),离线测试加 `QT_QPA_PLATFORM=offscreen` 无需任何硬件;真机测试需对应设备在线。运行命令见 `README.md` 测试节。 + +| 文件 | 类型 | 一句话 | +| --- | --- | --- | +| `test_playback_multifps.py` | 离线 | 多帧率会话回放 | +| `s80m_signal_regression.py` | 离线 | S80M 信号回归(object 参数大整数时间戳) | +| `s80m_50fps_decimation_test.py` | 离线 | S80M 50→30 抽帧录制决策 | +| `multi_device_registry_test.py` | 离线 | 多设备 worker 注册表 | +| `exposure_control_test.py` | 离线 | 曝光控制解析/下发 | +| `test_meta_devices.py` | 离线 | 会话元数据设备行 | +| `test_depth_heatmap.py` | 离线 | 深度热力图生成 | +| `glove_widget_test.py` | 离线 | 手套控件配置路由 | +| `grid_drag_fps_test.py` | 离线 | 网格拖拽/分割条 | +| `device_panel_gui_smoke_test.py` | 离线 | 设备面板 GUI 冒烟 | +| `test_device_detector.py` | 离线 | 设备枚举 | +| `d405_worker_test.py` | 真机 | D405 采集 worker | +| `d435_e2e_test.py` | 真机 | D435 端到端 | +| `d435_gui_smoke_test.py` | 真机 | D435 GUI 冒烟 | +| `d435_playback_test.py` | 真机 | D435 回放 | +| `mono_regression.py` | 真机 | 单目回归 | diff --git a/collector/docs/ui.md b/collector/docs/ui.md new file mode 100644 index 0000000000000000000000000000000000000000..08d9e3faf8b37e41ebc702afca2dbd033271082e --- /dev/null +++ b/collector/docs/ui.md @@ -0,0 +1,478 @@ +# ui/ + +## 定位 + +`ui/` 是 DAQ 桌面主程序的 PyQt5 界面层:主窗口把设备枚举面板、多画面网格、录制控制、录制历史、任务选择、上传与回放全部串成图形界面,后台数据链路(管线、数据库、网络服务)均由本层发起的对象持有并注入。界面层本身不写数据文件,持久化一律经 `config.settings` 与 `core.*` 完成。 + +被以下模块引用(证据): + +- `main.py` `from ui.main_window import MainWindow` —— 主入口(Qt-Material 暗色主题),构造并 `show()`。 +- `tools/tests/` 多个回归/冒烟测试直接构造界面类:`exposure_control_test.py`、`device_panel_gui_smoke_test.py`、`grid_drag_fps_test.py`、`test_playback_multifps.py`(还 import `_get_effective_fps`)、`d435_playback_test.py`、`glove_widget_test.py` 等。 +- 包内互引:`ui/main_window.py`(CameraGrid/DevicePanel/ExposureDialog/LoginDialog/GuideDialog/PlaybackDialog/UploadDialog/TaskSelectionPage)、`ui/playback_dialog.py`(ZoomableVideoWidget、CameraGrid 及两个分割条常量)、`ui/camera_grid.py` 与 `ui/glove_widget.py`(CameraWidget)、`ui/login_dialog.py`(复用 `ui/guide_dialog.py` 的 `VisibleCheckBox`)。 + +注:磁盘上存在 `ui/hand_model/` 目录,但其中只剩未跟踪的 `__pycache__/`(已删除 `__init__.py`、`state.py` 的编译残留),无任何源码 `.py`,故不列入文件清单(其源码已在开源准备提交 8ea2f44 的死代码清理中移除)。 + +## 文件清单 + +| 文件 | 一句话作用 | +| --- | --- | +| `ui/main_window.py` | 主窗口:任务/采集双页面栈、设备面板路由(UVC/D435/S80M/蓝牙统一开关)、录制控制、录制历史表、上传与回放入口 | +| `ui/camera_grid.py` | 嵌套 QSplitter 多画面网格容器:画面拖拽调位、分割条调大小、空状态提示 | +| `ui/camera_widget.py` | 单路画面控件:`ZoomableVideoWidget`(滚轮缩放/拖拽平移/双击还原)+ `CameraWidget`(信息条、FPS、状态灯、☀ 曝光按钮) | +| `ui/device_panel.py` | 左侧设备检测面板:已连接设备统一分组列表(UVC/D435/S80M/手套/其他蓝牙),勾选开关、双击命名 | +| `ui/exposure_dialog.py` | 每设备曝光设置对话框(自动曝光开关 + 滑块,量程/单位语义由调用方注入) | +| `ui/glove_widget.py` | BLE 手套仿生手掌画面控件,直接嵌入主网格,录制数据经 `pipeline.write_sensor` 落盘 | +| `ui/login_dialog.py` | 启动/切换账号登录对话框:账号登录(对话框内同步校验)或游客登录,关闭窗口等价游客;结果经 `choice()/server_url()/username()/cookies()` 等访问器读取 | +| `ui/guide_dialog.py` | 使用说明窗口(首次启动自动弹出、帮助菜单重开;中英 HTML 模板;「不再显示」持久化到 QSettings)+ `VisibleCheckBox` 复选组件 | +| `ui/playback_dialog.py` | 录制回放对话框:统一网格同步播放全部视频 + 传感器渲染,深度槽识别、手部关键点叠加、批量删除 | +| `ui/task_page.py` | 启动时的任务选择页:任务表、服务器地址/凭据输入、连接状态、进入采集 | +| `ui/upload_dialog.py` | 录制会话一键打包上传对话框 | +| `ui/__init__.py` | 空包标记(0 行) | + +## 各文件详解 + +### ui/main_window.py + +**作用**:应用程序主窗口,界面层中枢。组合页面栈(任务选择页 + 数据采集页)、`CameraGrid` 主网格、左侧 `DevicePanel` 设备面板、底部日志 dock、右侧录制历史 dock、工具栏与菜单;启动时经 `_show_login_flow` 弹 `LoginDialog` 确定账号/游客身份,首次启动经 `_show_guide` 弹 `GuideDialog` 使用说明;持有 `CameraPipeline`、`DeviceScanner`、`TaskService`、`UploadManager` 与 `core.device_manager.DeviceManager` 注册表(`_workers` 为其 `entries` 别名)等核心对象并负责信号接线。所有设备的开启/关闭都经左侧面板开关按 `core.device_manager.dispatch_toggle` 分派到 `_open_*`/`_close_*` 系列方法:S80M 双目子进程 + 管道解析在 `core.s80m_manager.S80MDeviceManager`,D435 worker 生命周期与帧口径在 `core.d435_manager.D435DeviceManager`,手套以 BLE 引擎 + 渲染定时器运行。 + +**模块级辅助与常量**(v1.0.3 后多为 core 模块的兼容 re-export,离线测试直接 patch 这些名字): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_realsense_short` / `_slot_base` / `_normalize_original` | — | `core.device_naming` 的 `realsense_short`/`slot_base`/`normalize_original` 旧名兼容别名 | 同 core 定义 | +| `_LEGACY_CAM_NAMES` | 常量 | 旧录制记录的退化相机名(`"多路录制"`/`"Multi-Camera"`/`""`),历史表自愈判据 | — | +| `_STEREO_AVAILABLE` | 常量 | `core.s80m_manager.STEREO_AVAILABLE` 别名(自包含双目模块 `tools/stereo_s80m/read_stereo_rgb.py`,内含 libfays_vikit.so 3.9.0 与 yaml,与外部 SDK 目录独立) | — | +| `_D435_AVAILABLE` / `D435Worker` / `list_d400_devices` | 常量 | 导入 `core.d435_camera` 并缓存 `d435_available()`;导入失败全置 None/False(模块全局保留供离线测试 patch) | — | +| `_HAND_PROC_AVAILABLE` | 常量 | `core.hand_processor.SessionHandProcessor` + `core.auto_labeler.AutoLabeler` 可选导入结果 | — | +| `_GLOVE_AVAILABLE` | 常量 | `ui.glove_widget.GloveWidget` 可选导入结果(依赖 bleak 子系统) | — | + +**类/信号**(`class MainWindow(QMainWindow)`): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `stereo_frame_ready` | `pyqtSignal(str, np.ndarray, object, list)` | 双目帧信号(FIFO 读取线程 → 主线程),参数 `slot_id, frame, hardware_ns, imu_samples` | 连接到 `_on_stereo_frame`。★ 封送坑:`hardware_ns` 必须用 `object`——PyQt5 队列信号把 Python int 按 C++ `qint32` 封送,超过 2^31(约 2.1s 纳秒)会静默截断为负数,录制数据受害 | +| `log_message` | `pyqtSignal(str)` | 跨线程日志信号(后台线程 → 主线程 `QTextEdit.append`) | `_log()` 在非主线程时经此投递 | +| `_upload_session_deleted` | `pyqtSignal(str, str)` | 上传后自动删除线程 → 主线程,参数 `(session_path, error_msg)` | 连接到 `_on_upload_session_deleted` | + +**相机管理**(设备开启/关闭全在此区): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_auto_detect_cameras` | `()` | 工具栏「🔍 扫描」:立即请求一次设备扫描(接入统一走面板开关,不自动打开画面) | 记日志;`DeviceScanner.request_scan()` | +| `_teardown_all_workers` | `()` | 委托 `core.device_manager.DeviceManager.teardown_all(close_fns)` 按 kind 分类关闭全部已开启设备 | 清空注册表 | +| `_open_uvc` / `_close_uvc` | `(dev) -> bool` / `(dev_key)` | UVC 面板开关:增量建槽(`settings._camera_slot_name(dev.video_index)`)/ 按注册表拆槽;条目经 `DeviceManager.uvc_entry` 创建 | bool 成功与否 | +| `_open_s80m` | `(dev) -> bool` | 面板开关打开 S80M 双目:先注入静态标定(`config/s80m_stereo_calibration.json` → `StereoCalibration.load`),创建 `stereo_left`/`stereo_right` 两槽并注册外部帧源(fps=`settings.STEREO_RECORD_FPS`=30);`s80m_depth_available()` 时追加第三格 `stereo_depth`(`set_depth_camera`,PNG16,v1.0.11),随后子进程/Popen/管道/watchdog/读线程全部交 `core.s80m_manager.S80MDeviceManager.spawn` | bool;与 D435 互斥(共用 video0/video2,后开者弹窗拒绝) | +| `_on_stereo_frame` | `(slot_id, frame, hardware_ns=0, imu_samples=None)` | 主线程槽(`S80MDeviceManager.frame_ready` 转投):显示帧直推画面;录制时按 `core.s80m_manager.frame_record_decision`(1/30s 桶)抽帧;IMU 仅随 `stereo_left` 落盘 | `pipeline.write_external_frame(...)` | +| `_on_s80m_depth` | `(slot_id, depth, hardware_ns=0)` | `S80MDeviceManager.depth_ready` 槽:`depth_to_heatmap`(固定色标 + 中值滤波)→ 深度格显示;录制中 `pipeline.write_depth` | — | +| `_close_s80m` | `(dev_key)` | 委托 `S80MDeviceManager.close`(停 watchdog → 关 stdin → terminate/kill → join 读线程 → 清理临时文件),再注销两路外部帧源、`clear_depth_camera(stereo_depth)`、移除 UI 控件、清除本设备标定 | — | +| `_open_d435` | `(dev) -> bool` | 面板开关打开 RealSense:按 serial 活体复查 `list_d400_devices()`(不信任导入期缓存)、按 serial 查重、与 S80M 反向冲突检查;槽名 = `core.device_naming.allocate_slot_names` 派生 `{base}_rgb` + `{base}_depth`,RGB 注册外部帧源、深度注册深度伪相机(`set_depth_camera`,热力图 MP4 + PNG16 双通道,`raw_depth=True`);worker 创建/信号接线/启动交 `core.d435_manager.D435DeviceManager.spawn` | bool;S80M 已开时弹窗拒绝 | +| `_on_d435_frames` | `(slot_id, frame, hardware_ns=0, imu_samples=None, dev_key=None)` | 委托 `core.d435_manager.D435DeviceManager.process_frame`(深度槽 → 热力图显示 + `write_depth`;RGB 槽 → 显示 + `write_external_frame`;首帧后标定送进管线 `calibration/head_stereo.json`) | 已关闭设备的迟到信号直接丢弃 | +| `_close_d435` | `(dev_key)` | 委托 `D435DeviceManager.close`(断信号 → stop → deleteLater)→ 注销外部帧源 + 清除深度伪相机 + 清除标定 → 移除双槽 | — | +| `_add_camera_slot` | `(slot_id, camera_index, backend="", label="")` | UVC 建槽:管线 `add_camera` + 网格 `add_camera` + `_connect_slot_signals` | 失败仅记日志 | +| `_connect_slot_signals` | `(slot_id)` | 单个 `CameraSlot` 信号 → UI 回调:`frame_ready`/`state_changed`/`error_occurred`/`camera_opened`/`fps_updated`,以及 widget 的 `remove_requested`/`exposure_clicked` | — | +| `_remove_camera` / `_remove_camera_slot_no_confirm` | `(slot_id)` | 移除单槽(录制中先弹确认)/ 不确认版;若槽属于某面板开启设备则整机关闭(d435 移除双槽之一即整机关)并取消勾选 | 同步面板勾选与高亮 | +| `_remove_all_cameras` | `()` | 工具栏「✕ 全部移除」:确认后先 `_teardown_all_workers()` 再逐槽移除 | 清面板勾选/高亮集合 | + +**设备面板路由与曝光**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_device_label` | `(dev)` staticmethod | `DeviceInfo` → 日志显示标签(用户命名优先,有 serial 时附 `— serial`) | str | +| `_on_devices_scanned` | `(devices)` | 扫描结果(每 2s 轮询,`settings.DEVICE_POLL_INTERVAL_MS`=2000):填用户命名 → `DevicePanel.set_devices` + 恢复勾选/高亮 → 插拔 diff 日志(只记变化)→ 录制中拔线暂存 `_lost_device_keys` 重插恢复勾选 → 已开启但已消失的设备逐个 `_handle_active_device_lost` | — | +| `_handle_active_device_lost` | `(key)` | 已开启设备被拔出:录制中不自动移除(重插恢复),否则按 kind 关设备 | — | +| `_on_device_toggled` | `(dev, on)` | 面板 `device_toggled` 路由:委托 `core.device_manager.dispatch_toggle`(录制锁双保险 + kind 路由到 `_open_*`/`_close_*` 回调,多路并发,互不拆台);打开失败回退勾选 | 维护 `_active_device_keys` | +| `_on_device_renamed` | `(dev, name)` | 面板双击命名后:刷新插拔标签缓存与 worker 注册表标签 | 持久化已在面板完成 | +| `_show_exposure_button` | `(slot_id)` | 在设备的「主槽位」(S80M 左目、D435 的 RGB 槽)信息条显示 ☀ 按钮 | — | +| `_open_exposure_dialog` | `(slot_id)` | ☀ 入口:对话框参数口径在 `core.exposure_controller.exposure_dialog_params`(D435:worker 读回 µs 量程;S80M:1.0~885.0,`decimals=1`;UVC 无曝光入口固定自动曝光);按类型弹 `ExposureDialog` | 模态 `exec_()` | +| `_apply_exposure` | `(dev_key, entry, auto, value)` | 委托 `core.exposure_controller.apply_exposure`(d435 → `worker.set_exposure`;s80m → `_s80m_set_exposure` 回调)并持久化(下次开启自动应用) | — | +| `_s80m_set_exposure` | `(dev_key, auto, value)` | 委托 `S80MDeviceManager.send_exposure`(stdin 行协议 `"SET_EXPOSURE "`,`-1.0`=自动曝光),SDK 运行时生效无需重启 | BrokenPipe 时记日志 | +| `_set_exposure_buttons_enabled` | `(enabled)` | 录制锁:所有已显示的 ☀ 按钮随录制状态禁用/恢复 | 用 `isHidden()` 判断(窗口未 show 时 `isVisible` 恒 False) | +| `_open_glove` / `_close_glove` | `(dev) -> bool` / `(dev_key)` | 手套开关:广播名 `L`/`R` → `settings.assign_glove_sensor_role` 优先绑左右手;创建 `GloveWidget`(slot=`sensor:{key}`)注入管线并 `start(address)`,`pipeline.register_sensor(role)`;关闭时停 BLE、撤画面、注销传感器列 | bool | +| `_open_ble_placeholder` / `_close_ble_placeholder` | `(dev) -> bool` / `(dev_key)` | 无数据蓝牙(耳机类):主网格显示「该设备无可视化数据」占位画面 | bool | + +**录制**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_reset_s80m_record_state` | `()` | 委托 `DeviceManager.reset_s80m_record_state`:录制起止时重置 S80M 50→30 抽帧状态(`last_bucket` 桶号 + `pending_imu` 缓冲) | — | +| `_build_device_meta` | `() -> list` | 委托 `DeviceManager.build_device_meta`:手套无画面槽附 `sensor_column`;uvc/d435/s80m 附 `slots`(及 `serial`);无数据蓝牙不进 devices 段 | list[dict] | +| `_record_all` | `()` | 工具栏「⏺ 全部录制」:任务名取自所选任务;所选任务进度已满(`completed_count >= total_required`,本地 `load_tasks()` 计数)时弹窗阻止;否则 `pipeline.start_recording(首个槽, task_name=..., batch_index=已完成数+1, device_meta=...)` | — | +| `_stop_all` | `()` | 「⏹ 完成录制」:`pipeline.finish_recording("")` + 重置抽帧状态 | — | +| `_abort_recording` | `()` | 「⛔ 异常终止」:`pipeline.abort_recording("")`(永久删除本次文件) | 记日志、刷新状态栏 | + +**信号处理器(管线 → 控件)**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_on_slot_added` / `_on_slot_removed` | `(_slot_id)` | 空实现(控件已在 `_add_camera_slot` 中创建/移除) | — | +| `_on_frame` | `(slot_id, frame)` | UVC 帧 → 画面(`settings.CAMERA_MIRROR_HORIZONTAL` 时先水平镜像) | `w.update_frame` | +| `_on_camera_state` | `(slot_id, state)` | 状态 → 指示灯 + 日志;`CameraState.DISCONNECTED` 时 `pipeline.record_event(slot_id, "disconnected")`,否则记 `"connected"` | — | +| `_on_camera_fps` | `(slot_id, fps)` | UVC 由 `CameraWorker` 自带的 fps 信号 → 标签 | — | +| `_note_frame_arrival` | `(slot_id)` | 记录一帧到达时刻(D435/S80M 无 CameraWorker,主窗口统一计 FPS) | 写入 `_fps_ring` | +| `_update_fps_labels` | `()` | 每秒刷新非 UVC 槽的 FPS(过去 1 秒到达帧数) | — | +| `_on_recording_started` | `(slot_id)` | 录制开始:锁死设备面板开关 + 禁用曝光按钮 + 日志(含编码与任务名) | — | +| `_on_recording_finished` | `(slot_id, session_path)` | 录制完成:解锁面板/曝光;`core.helpers.session_summary(session_path, pipeline.last_recording_frames)` 算摄像机列/时长/大小 → `RecordingRecord` 存库 → 刷新历史;`increment_task_completed(实际任务名)` 更新任务进度;自动上传入队(开关开启且该会话尚未 `completed` 时 `_upload_manager.add_task`);`HAND_TRACK_ENABLED` 时延迟 500ms 自动处理手部关键点(silent) | — | +| `_on_recording_aborted` | `(slot_id)` | 异常停止:解锁面板/曝光,取消手部后处理与标注 | — | +| `_on_duration` | `(_slot_id, seconds)` | 录制时长 → 状态栏 | — | + +**录制历史**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_refresh_history` | `()` | `RecordingRepo.list_all(limit=100)` → 表格 5 列:摄像机/文件/时长/大小/状态;旧记录自愈:退化值(无大小、`_LEGACY_CAM_NAMES` 相机名、无时长)实时从磁盘 `session_summary` 补算并回写 DB;状态列按 `completed`/`uploaded`/`uploaded_deleted` 绿色(`uploaded` 含自愈兜底:`completed` 且目录仍在、上传任务表记为 `completed` 的旧行也显示「已上传」)、其余(已丢弃)异常色 | 启动时即加载 | + +**上传 / 回放入口**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_open_playback` | `()` | 「📂 回放」:`PlaybackDialog(self, settings.RECORDING_DIR)` 模态打开 | — | +| `_open_upload` | `()` | 「☁ 上传」:`UploadDialog(self, settings.RECORDING_DIR, session=TaskService._session)` 模态打开 | — | +| `_on_upload_task_done` | `(task_id)` | 自动上传完成:记日志;`UPLOAD_DELETE_AFTER` 开启时后台线程删本地目录,否则 `RecordingRepo.mark_uploaded` 标「已上传(本地保留)」并刷新历史 | — | +| `_delete_session_after_upload` | `(session_path)` | 后台线程 `shutil.rmtree`(防大目录阻塞 UI),结果经 `_upload_session_deleted` 回主线程 | — | +| `_on_upload_session_deleted` | `(session_path, err)` | 删除收尾:失败记日志;成功 `RecordingRepo.mark_uploaded_deleted` 保留历史行(状态「已上传,本地已删」)并刷新 | — | +| `_on_upload_task_failed` | `(task_id, error)` | 自动上传失败(重试 3 次后仍失败才触发)→ 日志 | — | +| `_on_upload_auto_toggled` / `_on_upload_delete_toggled` | `(on)` | 两个工具栏开关:`settings.save_upload_auto_sync` / `save_upload_delete_after` 持久化 + 运行时立即生效 + 按钮文字/样式刷新 | — | +| `_style_toolbar_toggle` | `(action)` | 开关类 QAction 按钮高亮样式(开启绿底白字加粗) | — | + +**任务服务与页面切换**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_connect_task_service` | `()` | `TaskService` 信号 ↔ `TaskSelectionPage`:tasks_updated/connection_status/login_result/identity_changed/identity_expired;任务页 refresh_requested→`poll_now`、switch_account_requested→`_on_switch_account`;错误首次出现只记一次(`_last_task_error` 判重) | 轮询在身份确定后(`_show_login_flow` 末尾)才 `start()` | +| `maybe_show_login` / `_show_login_flow` | `()` | 启动入口(main.py 调用)→ 登录流程:`LoginDialog` exec 后 `save_server_url`;账号登录成功经 `TaskService.adopt_login` 接管 cookie(`save_remembered_username`),否则 `set_guest`;同步 `_upload_manager.server_url` 与任务页 `set_server_display` 后 `task_service.start()` | — | +| `_on_switch_account` | `()` | 任务页「切换账号」按钮 → 重开登录对话框 | — | +| `_on_identity_expired` | `()` | 登录态轮询遇 401/403 → 提示重登;关闭对话框(Esc)自动降级游客 | — | +| `_on_task_confirmed` | `(task)` | 选中任务进入采集页(index 1),更新窗口标题;不自动扫描,提示先选模式再点扫描 | — | +| `_on_page_changed` | `(index)` | 页面切换控制工具栏/dock 可见性;任务页停设备轮询,采集页立即扫描 + 启动 `_device_timer`(2s 轮询) | — | +| `_go_back_to_task_selection` | `()` | 返回任务选择:录制中先确认(同意则 abort);取消手部后处理/标注;`_teardown_all_workers` + 清网格 + 清面板状态;切回 index 0 并 `poll_now()` 刷新任务列表 | — | + +**其余(语言/视图/手部后处理/日志/退出)**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_on_language_changed` | `(lang)` | 中英文切换:菜单/工具栏/dock 标题/历史表头/手部模式下拉全部 `tr()` 重刷,并调 `_task_page._on_language_changed` | — | +| `_reset_camera_sizes` | `()` | 视图菜单「重置画面大小」:`grid._rebuild_layout()` 等分 | — | +| `_update_status` | `()` | 状态栏:摄像机数(排除 `sensor:`/`ble:` 占位槽)+ 录制中标记与颜色 | — | +| `_process_hand_keypoints` | `(session_path="", silent=False)` | 后台提取手部关键点(`SessionHandProcessor.process_session`,mode 由手套/裸手下拉决定);已有结果时弹确认(silent 模式跳过);无路径用最近一条录制 | — | +| `_on_hand_proc_progress` / `_on_hand_proc_finished` | `(current, total)` / `(session_path, error)` | 进度 → 状态栏+按钮;完成后 300ms 自动触发 `_auto_label`(silent) | — | +| `_auto_label` / `_on_auto_label_finished` | `(session_path="", silent=False)` / `(session_path, error)` | 基于关键点 parquet 自动生成手势标签(`AutoLabeler.label_session`) | — | +| `_log` | `(msg)` | 时间戳日志:主线程直接 `append`,后台线程经 `log_message` 信号安全投递 | — | +| `_show_about` | `()` | 关于对话框(应用名/版本/功能简介) | — | +| `closeEvent` | `(event)` | 安全退出:置 `_shutting_down` → 停轮询/扫描器 → 录制中 abort → 拆全部 worker → 移除全部槽 → 取消手部后处理 → 停 TaskService/UploadManager | accept | + +**关键数据**: + +- `_workers` 设备注册表:`DeviceManager.entries` 的别名,`key → {"kind": "uvc"|"d435"|"s80m"|"data_ble"|"ble", "slots": [网格槽位], "label": 日志标签}`,另含 kind 专属字段(d435:`worker`/`rgb_slot`/`depth_slot`/`near_mm`/`far_mm`/`smooth_k`/`temporal_alpha`/`heat_smoother`/`calib_sent`/`serial`;s80m:`proc`/`stdin`/`watchdog`/`reader_thread`/`stderr_file`/`config_file`/`original_exp`/`entry_depth`/`last_bucket`/`pending_imu`;data_ble:`sensor_column`/`glove`)。 +- 设备面板状态:`_active_device_keys`(勾选集合=UI 状态源)、`_lost_device_keys`(录制中拔线暂存)、`_last_device_keys`(key→标签,插拔 diff 日志)。 +- FPS:`_fps_ring`(slot_id → 到达时刻 deque),1s 定时刷新。 +- 历史表列名:`摄像机 / 文件 / 时长 / 大小 / 状态`。 +- S80M 管道帧格式与曝光行协议见 `core/s80m_manager.py`,50→30 抽帧桶长 `settings.STEREO_RECORD_MIN_INTERVAL_S`。 +- D435 槽名约定:RGB 槽 = 前缀 + `_rgb`,深度槽 = 前缀本身若以 `_depth` 结尾否则补 `_depth`;`depth` 后缀仅用于回放过滤,是否落盘由显式注册决定。 +- meta 写入点:`_build_device_meta()` 产出 `devices` 段(`key`/`kind`/`name`/`slots`/`serial`/`sensor_column`)。 + +**调用关系**:被 `main.py` 构造。创建并持有:`core.pipeline.CameraPipeline`、`core.device_detector.DeviceScanner`、`core.device_manager.DeviceManager`、`core.s80m_manager.S80MDeviceManager`、`core.d435_manager.D435DeviceManager`、`core.task_service.TaskService`、`core.uploader.UploadManager`、`core.recording_repository.RecordingRepo`(静态调用)、`ui` 内全部其余组件。调用 `core.d435_camera.D435Worker`、`core.stereo_depth.StereoDepthComputer/depth_to_heatmap/DepthHeatmapSmoother`、`core.calibration.StereoCalibration`、`core.task_record.load_tasks/increment_task_completed`、`core.helpers.session_summary/format_duration/format_size_mb/hand_kpts_parquet_path`、`core.device_naming`/`core.exposure_controller` 口径;可选手部子系统 `core.hand_processor.SessionHandProcessor`、`core.auto_labeler.AutoLabeler`。 + +### ui/camera_grid.py + +**作用**:多画面网格容器 `CameraGrid`(继承 `QScrollArea`),把每路画面排进嵌套 `QSplitter` 布局;所有画面(相机 `CameraWidget`、回放传感器格、手套仿生手掌、占位画面)同格共存。提供两种交互:按住画面顶部信息条拖到另一画面上松手即互换位置(事件过滤器 + 鼠标抓取);画面间的分割条加宽(8px)并带悬停/按住高亮,可拖动调大小。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `add_camera` | `(slot_id: str, camera_name: str = "")` | 添加一个 `CameraWidget` 到网格 | 返回 `CameraWidget` | +| `add_widget` | `(slot_id: str, widget: QWidget)` | 添加任意控件(手套仿生手掌/传感器格/占位等);重复 slot_id 直接返回已有控件 | 返回 QWidget;触发重建布局 | +| `remove_camera` | `(slot_id: str)` | 移除指定控件:先 `_end_drag()` 复位拖拽状态(防抓取/光标残留),再 `deleteLater()` | 触发重建布局 | +| `camera_widget` | `(slot_id: str)` | 按 slot_id 取控件 | `Optional[CameraWidget]` | +| `clear` | `()` | 移除所有画面 | — | +| `widget_count` | `() -> int` | 当前画面数量 | int | +| `slot_ids` | `() -> List[str]` | 全部 slot_id 列表(字典顺序即布局顺序) | list | +| `eventFilter` | `(obj, ev)` | 拖拽手柄事件:顶部 `DRAG_STRIP_H`(32px)内按下左键→`grabMouse` 抓取 + 闭合手掌光标;移动→悬停目标高亮(`DRAG_TARGET_BORDER`);松开→`_swap_widgets` 互换位置;双击信息条不触发缩放还原;带 `_no_drag` 属性的控件(曝光按钮、模式下拉等)直接放行 | 消费事件时返回 True | +| `_rebuild_layout` | `()` | 按画面数重建布局:0 路=空提示文案(默认 i18n「尚未检测到摄像机…」,可 `empty_text` 覆盖);1 路=填满;2 路=[A\|B];3 路=[A\|B]/[C];4 路=2×2;5+ 路按 `ceil(sqrt(n))` 行列嵌套分割;初始等分 | — | +| `_install_drag_filter` / `_remove_drag_filter` | `(w)` | 给画面控件及其全部子控件装/卸事件过滤器(子控件才真正接收鼠标事件) | — | +| `_root_widget` / `_in_drag_strip` / `_widget_at_global` | 辅助 | 事件来源控件沿父链找所属画面 / 判断全局坐标是否落在信息条内 / 命中画面 | QWidget 或 None | +| `_set_drag_hover` / `_swap_widgets` / `_end_drag` | 辅助 | 高亮悬停目标(恢复旧样式)/ 互换字典顺序并重建 / 释放抓取、还原光标与高亮 | — | + +**关键数据**: + +| 名称 | 值 | 说明 | +| --- | --- | --- | +| `DRAG_STRIP_H` | 32 | 每画面顶部拖拽手柄信息条高度(像素) | +| `SPLITTER_HANDLE_WIDTH` | 8 | 分割条宽度(被 `ui/playback_dialog.py:29` 复用) | +| `SPLITTER_HANDLE_QSS` | 灰条 + 悬停/按住高亮 | 暗色主题下分割条可见性(被 `ui/playback_dialog.py:29` 复用) | +| `DRAG_TARGET_BORDER` | `border:2px solid #4FC3F7` | 拖拽悬停目标边框高亮 | + +**调用关系**:被 `ui/main_window.py`(主网格)、`ui/playback_dialog.py`(回放统一网格)使用;`tools/tests/exposure_control_test.py`、`tools/tests/grid_drag_fps_test.py` 直接构造。依赖 `ui/camera_widget.py` 的 `CameraWidget` 与 `config.i18n.tr`(空提示文案)。 + +### ui/camera_widget.py + +**作用**:单路画面的两个控件。`ZoomableVideoWidget` 是纯视频显示画布:接收 BGR `np.ndarray` 帧,内部 BGR→RGB 转 `QImage.Format_RGB888`(Qt x86 上 `Format_BGR888` 会红蓝互换),支持滚轮缩放(以鼠标位置为基准)、左键拖拽平移、双击还原、缩放百分比提示。`CameraWidget` 把视频画布 + 顶部覆盖条(名称、☀ 曝光按钮、FPS 标签、状态灯)组合成一路「画面」,供主网格与回放共用。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `ZoomableVideoWidget.reset_view` | `()` | 还原缩放(1.0)与平移(0,0) | 重绘 | +| `ZoomableVideoWidget.set_frame` | `(bgr_frame: np.ndarray, flip_vertical: bool = False)` | 传入 BGR 帧:可选上下翻转(摄像机视频需要,传感器渲染不需要),BGR→RGB 后存为 `QPixmap` | 触发重绘 | +| `ZoomableVideoWidget.set_status_text` | `(text: str)` | 设置无画面时居中显示的文字(如「无信号」「已断开」) | 清空画面 | +| `ZoomableVideoWidget.wheelEvent` | `(event)` | 滚轮缩放:1.08×/级,范围 0.25×~8.0×,以鼠标位置为基准调偏移,右下角短暂显示百分比 | 重绘 | +| `ZoomableVideoWidget.mousePressEvent` / `mouseMoveEvent` / `mouseReleaseEvent` / `mouseDoubleClickEvent` | `(event)` | 左键拖拽平移(闭合手掌光标);双击 `reset_view` | — | +| `CameraWidget`(信号) | `remove_requested(str)` / `exposure_clicked(str)` | 请求移除此摄像机 / 点击 ☀(主窗口按槽位所属设备弹曝光对话框) | 由 `MainWindow._connect_slot_signals` 连接 | +| `CameraWidget.update_frame` | `(bgr_frame)` | 相机采集帧更新显示(`flip_vertical=True` 适配安装方向) | — | +| `CameraWidget.update_fps` | `(fps: float)` | 更新 `FPS: n` 标签 | — | +| `CameraWidget.set_frame_number` | `(n: int)` | 回放用:信息条右侧显示当前帧号 `#n`(复用 FPS 标签位) | — | +| `CameraWidget.set_camera_state` | `(state: str)` | `recording`/`error`/`disconnected`/`idle` → 状态灯颜色与「已断开/等待中…」文字 | — | +| `CameraWidget.set_exposure_button_visible` / `set_exposure_enabled` | `(visible: bool)` / `(enabled: bool)` | 显示/隐藏 ☀(只对设备主槽位);启用/禁用(录制中禁用,tooltip 随之切换) | — | +| `CameraWidget._refresh_texts` | `(_lang="")` | 语言切换刷新文案 | 连接 `lang_manager.language_changed` | +| `CameraWidget.resizeEvent` | `(event)` | 调整覆盖条宽度与位置 | — | + +**关键数据**: + +- `ZOOM_MIN = 0.25`、`ZOOM_MAX = 8.0`、`ZOOM_STEP = 1.08`。 +- 覆盖条:固定高 28px、初始宽 260px(随 resize 收缩到 ≤300px),位于画面左上角;刻意不设 `WA_TransparentForMouseEvents`(会连 ☀ 按钮一起屏蔽),画面信息条拖拽由 `CameraGrid` 事件过滤器统一拦截。 +- ☀ 按钮带 `_no_drag` 属性标记,`CameraGrid.eventFilter` 对按下直接放行(不触发拖拽/双击还原)。 +- 注意:`reset_view` 在文件中定义了两次(第 74-78 行与第 109-113 行),后者覆盖前者,行为一致。 + +**调用关系**:被 `ui/camera_grid.py`、`ui/glove_widget.py`(`GloveWidget` 继承 `CameraWidget`)、`ui/playback_dialog.py`(`ZoomableVideoWidget`)使用。依赖 `config.settings`(`FEED_MIN_WIDTH` 等尺寸与颜色常量)、`config.i18n.tr/lang_manager`、`core.helpers.format_duration`(导入存在,当前代码未直接调用)。 + +### ui/device_panel.py + +**作用**:左侧停靠的设备检测面板。`DeviceScanner`(`core/device_detector`)每 2s 扫描的结果由 `MainWindow._on_devices_scanned` 调 `set_devices` 重建列表;三组展示(📷 相机 / 🧤 手套 / 🎧 其他蓝牙),「其他蓝牙」默认折叠、空组隐藏;每台设备带独立 `QCheckBox`,勾选发射 `device_toggled(DeviceInfo, bool)` 由主窗口路由到主网格显示;双击条目弹命名框并持久化到 `device_names.json`(此后每次连接显示用户命名)。 + +**类/函数**(`class DevicePanel(QWidget)`): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `device_toggled` / `device_renamed`(信号) | `pyqtSignal(object, bool)` / `pyqtSignal(object, str)` | 勾选变化(DeviceInfo, checked)/ 双击命名完成(DeviceInfo, new_name) | 由 `MainWindow` 连接 | +| `set_devices` | `(devices: list)` | blockSignals 下清空重建分组树;勾选状态由随后的 `set_checked_keys` 恢复;组展开状态跨重建保留 | 空列表显示「未检测到设备」占位 | +| `set_checked_keys` | `(keys: set)` | 按 key 集合静默勾选(不发信号) | — | +| `set_checked` | `(key: str, on: bool)` | 程序化勾选单个(不发信号,供失败回退) | — | +| `checked_keys` | `() -> set` | 当前勾选的设备 key 集合 | set(开关状态=UI 状态源) | +| `set_active_keys` | `(keys: set)` | 高亮正在显示中的设备(绿色前景),其余还原;空集合全还原 | — | +| `set_active_key` | `(key)` | 兼容旧调用:单 key 高亮(None 全还原) | — | +| `set_locked` | `(on: bool)` | 录制中锁死全部开关(去 `Qt.ItemIsEnabled`,命名同步禁用) | — | +| `key_for_kind` | `(kind: str)` | 列表中第一个 kind 匹配的设备 key | str 或 None | +| `device_for_key` | `(key: str)` | key → `DeviceInfo`(存在 `Qt.UserRole`) | DeviceInfo 或 None | +| `key_for_serial` | `(serial: str)` | 按序列号找 key(多台 RealSense 时精确高亮) | str 或 None | +| `key_for_video_index` | `(video_index: int)` | 第一个 `video_index` 匹配的设备 key | str 或 None | +| `refresh_texts` | `()` | 语言切换刷新提示文字、组标题与占位项 | — | +| `_row_text` | `(dev) -> str` | 行文本 = 图标 + `label`(+ `— serial`) | — | +| `_on_item_changed` | `(item, column)` | 勾选状态真正变化(用 `_last_check` 挡文字类变化与组标题)才发射 `device_toggled` | — | +| `_on_item_double_clicked` | `(item, _column)` | 双击 → `QInputDialog` 命名 → `settings.save_device_name(dev.stable_key, name)` 持久化 → 更新行文本 + `device_renamed`;对话框打开期间列表可能已被 2s 轮询重建,必须用当前列表里的条目更新 | — | + +**关键数据**: + +- `_ICON = {"uvc": "📹", "d435": "🔭", "s80m": "👁", "data_ble": "🧤", "ble": "🎧"}`;`_GROUP_ORDER = ["camera", "glove", "other_ble"]`;`_GROUP_TITLE` 对应中文组标题。 +- `_items`:device key → `QTreeWidgetItem`;`_last_check`:key → 上次勾选状态(防 `itemChanged` 误触发);`_group_expanded`:组展开状态(初始 camera/glove 展开、other_ble 折叠)。 +- 命名持久化:`config.settings.save_device_name`(device_names.json)。 + +**调用关系**:由 `ui/main_window.py` 构造并连接 `device_toggled`/`device_renamed`;`tools/tests/device_panel_gui_smoke_test.py` 直接构造。依赖 `config.settings.save_device_name`、`config.i18n.tr`。 + +### ui/exposure_dialog.py + +**作用**:每设备曝光设置模态对话框:自动曝光开关 + 曝光值滑块(内部统一 0..1000 刻度映射),拖动即时下发 `apply_requested(auto, value)`,勾选自动曝光立即生效。范围/值语义由调用方(`MainWindow`)按设备类型注入:UVC 是 V4L2 原始曝光值、D435/D405 是 µs(流启动后读 `rs.option.exposure` 量程)、S80M 是 SDK 曝光值 1.0~885.0(与 yaml `stereo_init_exposure` 同单位)。对话框只发参数不改持久化(持久化由主窗口统一处理)。 + +**类/函数**(`class ExposureDialog(QDialog)`): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `apply_requested`(信号) | `pyqtSignal(bool, float)` | 参数变化:`apply(auto, value)`(`auto=True` 时 value 忽略) | 由 `MainWindow._open_exposure_dialog` 连接到 `_apply_exposure` | +| `__init__` | `(parent, title, vmin, vmax, value, auto, decimals=0, original=None)` | 构造:自动曝光勾选框 + 0..1000 滑块 + 数值标签 + 「恢复默认」按钮(仅传入 `original` 时显示)+ 关闭 | 模态 | +| `_to_ticks` / `_from_ticks` | `(value) -> int` / `(ticks) -> float` | 曝光值 ↔ 0..1000 刻度线性映射 | — | +| `_fmt` | `(value) -> str` | 按 `decimals` 格式化数值标签 | — | +| `_on_auto_toggled` | `(checked)` | 自动曝光开关:禁用/启用滑块并立即 `apply_requested.emit(checked, 当前值)` | — | +| `_on_moved` / `_on_released` | `(ticks)` / `()` | 拖动中/松手时更新值并下发(`auto` 时忽略) | — | +| `_on_reset` | `()` | 「恢复默认」:控件静默(blockSignals)回到「最一开始」曝光基线 `(auto, value)` 并下发一次 | — | + +**关键数据**:`_original` = 设备首次开启、应用任何设置之前读回的 `(auto, value)` 基线(来源为 `settings.device_original` 或 worker 读回值,经 `core.device_naming.normalize_original` 归一化)。 + +**调用关系**:由 `ui/main_window.py`(`_open_exposure_dialog`)按设备类型构造并 `exec_()`;`tools/tests/exposure_control_test.py` 直接构造。依赖 `config.i18n.tr`。 + +### ui/glove_widget.py + +**作用**:BLE 手套仿生手掌画面控件(继承 `CameraWidget`,复用其覆盖条),直接嵌入主网格,替代旧的底部传感器 dock。面板开关打开手套后由主窗口创建;内部持有 `core.ble_engine.SensorBLEEngine`,30ms 渲染定时器处理一帧数据并用 `core.render_engine.render_hand` 画成 BGR 帧显示;录制中数据经 `pipeline.write_sensor` 写入 parquet 对应传感器列。 + +**类/函数**(`class GloveWidget(CameraWidget)`): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `__init__` | `(slot_id, address, sensor_column, label="", parent=None)` | 固定 `_RENDER_W=1280`×`_RENDER_H=720` 画布;左/右手套配置由 `core.sensor_hand_config.load_sensor_hand_config(sensor_column)` 加载(左/右不同配置文件);启动 30ms 渲染定时器 | — | +| `start` | `(address: str = "")` | 连接 BLE 设备(懒创建引擎并连接 `connected`/`disconnected`/`fps_updated`/`calibration_progress`/`error_occurred` 信号) | 画面显示「连接中…」 | +| `stop` | `()` | 断开连接、停止渲染 | 画面显示「已断开」 | +| `set_pipeline` | `(pipeline)` | 主窗口注入/清除当前录制管线引用 | — | +| `_on_connected` / `_on_disconnected` | `(addr)` / `()` | 连接状态 → 画面文字 + `pipeline.record_event(sensor_column, "connected"/"disconnected")` | — | +| `_on_error` | `(msg)` | 引擎错误显示到画面状态栏(失败原因不再只有控制台可见) | — | +| `_on_fps` | `(fps)` | 硬件 FPS 显示到信息条(`HW: n`) | — | +| `_on_calib_progress` | `(progress)` | 校准进度显示(`校准中… n%` / `校准完成`) | — | +| `_render_tick` | `()` | 定时器触发:`engine.process_frame()` 拿一帧;录制中 `pipeline.write_sensor(processed, capture_ts, sensor_name=sensor_column)`;`render_hand(...)` 渲染并传给画面(逻辑平移自旧 `SensorPanel`) | — | +| `_display_frame` | `(frame)` | 渲染帧叠加传感器名 + 硬件 FPS + 数据帧龄(`Age: n ms`,按 <100/<300ms 绿/黄/红) | — | + +**关键数据**: + +- 渲染配置常量 `CONFIG_FILE`/`CONFIG_FILE_LEFT` 定义在 `core.render_engine`(指向 `config/sensors/hand_ble_config.json` 与 `hand_ble_config_left.json`);加载与合并口径在 `core.sensor_hand_config.load_sensor_hand_config`。 +- `_current_vmax` 初始 5000.0,跨帧回传保持色标稳定。 + +**调用关系**:由 `ui/main_window.py`(try/except 可选导入)在 `_open_glove` 中创建。依赖 `core.ble_engine.SensorBLEEngine`、`core.render_engine`、`core.sensor_hand_config`、`ui.camera_widget.CameraWidget`;`tools/tests/glove_widget_test.py` import 本模块做自检。 + +### ui/login_dialog.py + +**作用**:登录对话框——启动时(或任务页点「切换账号」)弹出,确定会话身份。账号登录在对话框内同步校验(`TaskService.verify_credentials`,独立 `requests.Session`,≤8s),失败就地提示可重试,成功后携带 auth cookie 返回;游客登录直接进入(仅见公共任务);关闭窗口(Esc/X)等价游客——后端不可达时不把用户锁死在启动页。 + +**类/函数**(`class LoginDialog(QDialog)`): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `choice` | `() -> str` | 结果:"login"(点登录且校验成功)或 "guest"(游客/关闭窗口) | str | +| `server_url` | `() -> str` | 地址输入框内容;空则回退 `settings.SERVER_URL` | str | +| `username` / `password` | `() -> str` | 账号/密码输入框内容 | str | +| `remember_checked` | `() -> bool` | 「记住账号」勾选状态 | bool | +| `cookies` | `()` | 登录成功后的 auth cookie(失败/游客为 None) | cookie 或 None | +| `_on_login_clicked` | `()` | 空用户名就地提示;同步校验(按钮置「登录中…」防误以为卡死),成功记 cookie 并 accept,失败 `_show_error` | — | +| `_on_guest_clicked` | `()` | choice="guest" 并 accept | — | + +**关键数据**:表单回填——服务器地址(与出厂默认相同则不回填、以 placeholder 显示)、用户名(`settings.load_remembered_username`);错误提示仅登录失败时显示。 + +**调用关系**:由 `ui/main_window.py`(`_show_login_flow`)构造。依赖 `config.settings`、`config.i18n.tr`、`core.task_service.TaskService.verify_credentials`、`ui.guide_dialog.VisibleCheckBox`。 + +### ui/guide_dialog.py + +**作用**:使用说明窗口——首次启动自动弹出(`guide/shown_once` 未置位,或环境变量 `DAQ_SHOW_GUIDE=1` 强制),也可从菜单 帮助 → 使用说明 随时重开;「下次启动不再自动显示」勾选持久化到 QSettings(`guide/dont_show`,取消勾选即恢复自动弹出;每次关闭按当前勾选落盘并 `sync()` 立即写盘)。正文为整段 HTML 使用步骤(登录 → 设备 → 录制 → 回放 → 上传),按当前界面语言选择 `GUIDE_HTML_ZH`/`GUIDE_HTML_EN` 模板,与根目录 `使用说明.md` 内容一致。 + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `guide_html` | `() -> str` | 按 `lang_manager.current` 返回当前语言的 HTML 正文 | str | +| `VisibleCheckBox` | `(QCheckBox)` | 暗色主题下勾选指示不明显:指示框加显式描边/填充,勾选时自绘白色 ✓(`login_dialog.py` 复用) | — | +| `GuideDialog` | `(parent=None)` | 760×640 对话框:标题(APP_NAME + 版本)、`QTextBrowser` 渲染 HTML、底部 VisibleCheckBox + 「关闭」 | — | +| `dont_show_checked` | `() -> bool` | 供调用方持久化「下次不再显示」 | bool | + +**调用关系**:由 `ui/main_window.py`(`_show_guide`,惰性 import)构造;`VisibleCheckBox` 被 `ui/login_dialog.py` 复用。依赖 `config.settings`、`config.i18n`。 + +### ui/playback_dialog.py + +**作用**:本地录制回放对话框。左侧会话列表(多选、按上传状态筛选、批量移入回收站),右侧复用 `CameraGrid` 的统一网格:摄像机格与传感器格同格共存,可拖拽调位、分割条调大小;底部播放控制(播放/暂停、逐帧、进度条、倍速 0.25~4×、手部关键点叠加开关、追踪模式、提取关键点)。时间戳对齐经 Parquet 统一时间线(`frame_idx` 与 `timestamp_us`);会话加载(parquet 合并 + 手部关键点)全部放后台线程,视频打开与播放留在主线程(OpenCV FFmpeg 后端不承诺跨线程安全)。 + +**模块级**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_get_effective_fps` | `(info: dict) -> float` | `core.session_catalog.get_effective_fps` 的兼容别名(离线测试仍按旧名 import) | float | + +**类/函数**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `SessionLoader` | `(parent=None)` QObject | `core.session_loader.SessionLoader` re-export:后台加载器,parquet 读取全在 worker 线程,`loaded(str, object, int)` 携带 `{"timeline": SensorTimeline, "hand_kpts": dict}`;`load(session_dir, gen)` 已有加载在跑时排队(新请求覆盖旧请求,过期结果被 gen 丢弃);`cancel()` 取消 | 信号 `loaded`/`failed(int, str)` | +| `PlaybackSensorWidget` | `(sensor_name, title="", parent=None)` QFrame | 单路传感器回放格:标题 + 模式下拉(🔥 热力图/📝 轨迹/📊 网格/🦾 仿生手掌/🕸 形变网格,默认仿生手掌)+ `ZoomableVideoWidget` + TS 标签;头部行 ≈32px 与网格拖拽手柄区对齐,`mode_combo`/`ts_label` 标 `_no_drag` 放行点击 | — | +| `PlaybackDialog._toggle_fullscreen` | `()` | F11 切换全屏(`QShortcut` WindowShortcut 上下文,任意子控件聚焦时可用) | — | +| `PlaybackDialog._rebuild_grid` | `()` | 按当前会话重建统一网格:先摄像机格(双目四路 `stereo_left/right` + `_aux` 保持 2×2 特殊排列),后传感器格(slot_id=`sensor:{name}`,与主窗口手套格约定一致);摄像机格隐藏状态灯 | — | +| `_browse_dir` / `_refresh_list` | `()` | 选择录制目录 / 重建会话列表(`core.session_catalog.list_sessions`;每项含上传状态图标 ✅/❌/⬜、路数、FPS、时长、任务 tag) | — | +| `_on_session_clicked` | `(item)` | 点击会话 → `_load_session(path)` | — | +| `_filter_by_upload` | `(uploaded: bool)` | 「⬆ 选中已上传」/「⬇ 选中未上传」:按 `UploadManager.get_upload_status` 勾选 | — | +| `_delete_selected` | `()` | 勾选会话移入回收站:先停播并释放全部 `cv2.VideoCapture` 句柄(否则 Windows 阻止删除)+ 强制 GC;`core.helpers.send_to_recycle_bin` 逐个移入 | 可逆 | +| `_load_session` | `(session_dir)` | 加载会话:主线程同步读元数据(`core.session_catalog.load_session_meta`:格式探测 → EgoData `metadata.json` 或 `meta/info.json`;传感器列表读 `info["sensors"]`,无则从 `info["features"]` 的 `observation.*` 键推断,最旧格式回退 `["state"]`);parquet 合并 + 关键点交 `SessionLoader` 后台加载 | — | +| `_on_session_loaded` | `(gen, payload)` | 主线程槽:过期 gen 丢弃;过滤幽灵传感器列(时间线中确有 16×16=256 宽压力矩阵的才留,防 `observation.imu` 等非手套特征被误判);打开每路 MP4(深度槽取 `depth//.mp4`);用户命名叠加(`device_names` + `devices` 段 slots/sensor_column → name);算主时钟(info fps → 视频实际 fps → 全局兜底)、每路总帧数;重建网格、`_seek(0)` | — | +| `_on_session_load_failed` | `(gen, error)` | 后台加载失败 → 信息标签 | — | +| `_toggle_play` / `_stop` | `()` | 播放/暂停切换;`_stop` 也用于切会话前收尾 | — | +| `_tick` | `()` | 定时器推进:按真实流逝时间补帧追赶(主线程被 seek/渲染拖慢时保持原速);到末尾自动停 | — | +| `_prev_frame` / `_next_frame` | `()` | 逐帧进退 | — | +| `_seek` | `(idx: int)` | 主时钟帧号 → 每路帧号(`t_s × fps_i` 四舍五入,低帧率路按比例抽帧);小步前进(≤5 帧,定时器抖动/追赶所致)顺序 `read()` 到底(每帧 1-2ms),随机大跳(拖进度条)才 `set+read` seek(43-89ms/路)——小步也 seek 会因 seek 耗时把追赶 steps 推大形成死亡螺旋(HEVC B 帧 seek 更贵);随后 `_update_sensor` + 时间标签 | — | +| `_on_slider_pressed` / `_on_slider_moved` / `_on_slider_released` | `(value)` | 拖动中不 seek(每秒数十个 move 事件 × 单次 90-180ms 会卡死),松手单次 seek;点击滑槽未拖动也跳到点击处;原在播则恢复播放 | — | +| `_set_video_frame` | `(slot_id, frame, frame_num)` | 一帧显示到摄像机格 + 帧号 `#n`;可选手部关键点叠加(`draw_kpts_overlay`);MP4 帧录制时已 `np.flip(axis=0)` 过,回放不再翻转 | — | +| `_on_sensor_mode_changed` | `(sensor_idx, mode_idx)` | 切换传感器可视化模式(heatmap/trace/grid/hand/deform),trace 时 `clear_trace_canvas()`,vmax 重置 5000.0 | — | +| `_update_sensor` | `(frame_idx, t_s=0.0)` | 渲染全部传感器:多帧率混合会话按主时钟时间二分(`nearest_for_column_time`),帧率一致会话走帧号二分(`nearest_for_column`,时间戳含暂停负跳变时更稳);16×16 矩阵按模式调 `render_heatmap/trace/grid/hand/deform_mesh`;TS 标签显示传感器时间戳与 Δ(ms/帧) | — | +| `_cycle_speed` | `()` | 倍速循环 0.25/0.5/1/2/4×,播放中即时改定时器间隔 | — | +| `_toggle_hand_overlay` | `(checked)` | 手部关键点叠加开关 → 重刷当前帧 | — | +| `_process_current_kpts` / `_on_hand_proc_finished` | `()` / `(session_path, error)` | 对当前会话后台提取手部关键点(主线程延迟创建 `SessionHandProcessor` 保证信号正常);完成后 kpts-only 重载(`load_timeline=False`) | — | +| `closeEvent` | `(event)` | 置 `_closing`(迟到 loader 回调丢弃)、取消手部处理、停播、释放全部 VideoCapture | — | + +**关键数据**: + +- 深度槽判定(`_on_session_loaded`):`cameras[slot]` 的 `type == "depth"` 或槽名以 `_depth` 结尾(槽名约定与主窗口 `_open_d435` 一致);深度槽仅当其热力图 MP4(`depth//.mp4`)存在时加入回放列表。 +- 双目四路特殊排序:`_STEREO_IDS = {"stereo_left", "stereo_right", "stereo_left_aux", "stereo_right_aux"}` 四路齐备时按固定顺序排列。 +- 传感器状态列表:`_sensor_modes`/`_sensor_vmax_list`/`_sensor_mesh_states`/`_sensor_widgets`/`_sensor_ts_labels`/`_sensor_hand_configs`/`_sensor_cells` 按 `info["sensors"]` 动态创建。 +- meta 字段读取点:`cameras[].fps`、`cameras[].type`、`sensors`、`features`、`device_names`、`devices[].slots/sensor_column/name/kind`、`task_name`、`fps`(`info["fps"]` 兜底);EgoData 会话的 devices 全量段在 `metadata.json`、device_names 在 `meta/info.json`,两处合并读。 +- 会话列表项把上传状态存在 `Qt.UserRole + 1`。 + +**调用关系**:由 `ui/main_window.py`(`_open_playback`)构造;`tools/tests/test_playback_multifps.py`、`tools/tests/d435_playback_test.py` 直接构造。依赖 `core.session_timeline.load_timeline/SensorTimeline`、`core.session_catalog`(fps/扫描/元数据)、`core.session_loader.SessionLoader`、`core.render_engine` 五种渲染器与 `CONFIG_FILE`/`CONFIG_FILE_LEFT`、`core.sensor_hand_config`、`core.helpers` 路径与扫描函数、`core.uploader.UploadManager.get_upload_status`;可选手部叠加来自 `core.hand_tracking`。 + +### ui/task_page.py + +**作用**:启动时显示的任务选择页(页面栈 index 0)。顶栏只读显示服务器地址(`set_server_display`)与当前身份,附「切换账号」按钮(发射 `switch_account_requested`);中部任务表(4 列),底部「→ 进入采集」与「🗑 删除」。任务数据来自 `data/tasks.json`(`core.task_record.load_tasks`),后端任务经 `merge_backend_tasks` 合并,并 `set_identity` 按身份过滤(游客仅见公共任务);用户选中任务点「进入采集」发射 `task_selected(dict)`,主窗口切换到数据采集页。 + +**模块级**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_compute_status` | `(task: dict) -> str` | 按 `total_required`/`completed_count` 算状态:`pending`/`in_progress`/`completed` | str | +| `_tid` | `(task: dict) -> str` | 取任务 id(`id` 或 `task_id`) | str | +| `_format_date` | `(iso_str: str) -> str` | 日期截取前 10 字符 | str | + +**类/函数**(`class TaskSelectionPage(QWidget)`): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `task_selected` / `refresh_requested` / `switch_account_requested`(信号) | `pyqtSignal(dict)` / `pyqtSignal()` / `pyqtSignal()` | 点击「进入采集」/ 点击「🔄 刷新」/ 点击「切换账号」 | 由 `MainWindow._connect_task_service` 连接 | +| `update_tasks` | `(tasks: list[dict])` | 后端任务列表到达:`merge_backend_tasks` 合并(空则回退本地 `load_tasks`)→ 重算状态 → 重建表 | — | +| `update_task_progress` | `(task_id: str, completed_count: int)` | 录制完成回写进度:`refresh_progress()` 后按 `_tid` 找行刷新 | — | +| `set_connection_status` | `(connected: bool)` | 更新连接圆点与「后端已连接/未连接」文案 | — | +| `on_login_result` | `(ok: bool, msg: str)` | 登录结果反馈(`登陆成功` / `登陆失败: msg[:30]`) | — | +| `set_identity` | `(identity: str \| None)` | 更新当前身份("guest" 或用户名)并即时按新身份重滤任务表 | — | +| `set_server_display` | `(url)` | 更新顶栏服务器地址显示与 tooltip(登录对话框改地址后由主窗口调用) | — | +| `current_task` | `() -> dict \| None` | 当前选中行任务 | dict 或 None | +| `_on_cell_changed` | `(row, _col, _pr, _pc)` | 选行联动:completed 任务禁用「进入采集」(tooltip 提示换任务) | — | +| `_on_double_clicked` / `_on_enter_clicked` | `()` | 双击行=快捷进入;进入前 completed 任务弹警告 | 发射 `task_selected` | +| `_do_delete_task` | `()` | 删除任务(按钮与右键菜单共用):确认后 `mark_hidden`(可在 tasks.json 中恢复)→ 重载列表 | — | +| `_on_context_menu` | `(pos)` | 右键菜单「🗑 删除任务」 | — | +| `_on_refresh_clicked` | `()` | 发射 `refresh_requested`,按钮 1.5s 内显示「刷新中…」禁用 | — | +| `_on_language_changed` | `(lang)` | 表头/占位符/按钮文字刷新并重建表 | — | + +**关键数据**: + +- 表格 4 列:`任务名称 / 状态 / 进度 / 发布时间`(`_COL_NAME=0` … `_COL_DATE=3`);状态列用彩色方块+文字的 badge(`_STATUS_CONFIG`:pending 灰 `#757575`、in_progress 蓝 `#42A5F5`、completed 绿 `#66BB6A`);进度列 `completed/total` 右对齐。 +- 身份与地址:服务器地址/记住账号由 `LoginDialog` 校验后经 `MainWindow._show_login_flow` 写入(`settings.save_server_url` / `save_remembered_username`);登录态 cookie 由 `TaskService.adopt_login` 接管;身份过滤 scope 经 `_identity_scope()` 传给 `core.task_record`。 + +**调用关系**:由 `ui/main_window.py` 构造;任务服务信号在 `_connect_task_service` 中双向接线。依赖 `core.task_record`(`load_tasks`/`merge_backend_tasks`/`refresh_progress`/`mark_hidden`)、`config.settings`、`config.i18n`。 + +### ui/upload_dialog.py + +**作用**:录制数据一键上传对话框:顶部服务器地址 + 「测试连接」(`core.api_client.APIClient.health_check`),中部会话列表(多选、全选、按上传状态筛选),底部进度条与状态栏。「⬆ 一键上传」把勾选会话入队 `UploadManager`(复用已认证的 `requests.Session`);每项成功后遵循「上传后自动删除」开关:开启时后台线程删本地目录并把 `recording` 记录标记为 `uploaded_deleted`,否则标 `uploaded`(本地保留);成功/失败结果均经 `_parent_log` 写进主窗口日志面板(与自动上传同一口径)。 + +**模块级**: + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| (无) | — | 会话扫描用 `core.session_catalog.list_recordings`(轻量版,不读元数据) | 按名称倒序 | + +**类/函数**(`class UploadDialog(QDialog)`): + +| 名称 | 签名要点 | 作用 | 返回/副作用 | +| --- | --- | --- | --- | +| `_session_deleted`(信号) | `pyqtSignal(str, str)` | 后台删除线程 → 主线程:`(session_path, error)` | 连接 `_on_session_deleted` | +| `__init__` | `(parent=None, data_dir="", session=None)` | `session` 为复用已认证的 `requests.Session`;`QTimer.singleShot(50, _init_manager)` 延迟建 `UploadManager`(读 `_url_edit` 当前值) | — | +| `_refresh_list` | `()` | 重建会话列表:每项图标按 `UploadManager.get_upload_status`(✅ completed / ❌ failed / ⬜ pending),默认勾选未完成项;「全选」用 blockSignals 复位防 `_toggle_all` 连锁 | — | +| `_on_item_clicked` | `(item)` | 点击整行切换勾选(不必精确点复选框) | — | +| `_toggle_all` | `(checked)` | 全选/全不选 | — | +| `_filter_uploaded` | `(uploaded)` | 「⬆ 选中已上传」/「⬇ 选中未上传」 | — | +| `_test_connection` | `()` | `APIClient(url).health_check()` 弹结果框 | — | +| `_start_upload` | `()` | 勾选会话(过滤不存在的目录)`_manager.add_tasks(valid)` 入队并 `start()`;`_task_path_map` 记 task_id → session_path;禁用上传按钮 | — | +| `_on_status` | `(task_id, msg)` | 串行处理时状态栏显示「第 x/y 条 [会话名] 当前动作」 | — | +| `_on_progress` | `(task_id, ratio)` | 总进度 =(已完成数 + 当前比例)/ 总数 | 进度条 | +| `_on_task_done` | `(task_id)` | 单条完成:刷新列表;`UPLOAD_DELETE_AFTER` 开启时 `_delete_after_upload`(与主窗口自动上传同规则),否则 `RecordingRepo.mark_uploaded` + 主窗口日志「☁ 上传完成(本地保留)」 | — | +| `_delete_after_upload` | `(session_path)` | 后台线程 `shutil.rmtree`,结果经 `_session_deleted` 回主线程 | — | +| `_on_session_deleted` | `(session_path, err)` | 删除收尾:失败仅提示;成功 `RecordingRepo.mark_uploaded_deleted` + 刷新列表 + 主窗口日志「☁ 上传完成,本地文件已删除」 | — | +| `_on_task_failed` / `_on_all_done` | `(task_id, error)` / `()` | 失败:状态栏「❌ 上传失败」+ 主窗口日志 + 刷新列表 / 全部完成:恢复按钮、进度条 100、状态「全部完成」 | — | +| `closeEvent` | `(event)` | 停止 `_manager` | — | + +**关键数据**: + +- 上传状态来源 `UploadManager.get_upload_status(path)`:`completed`/`failed`/`pending`。 +- `_task_path_map`:task_id → session_path(删除与状态显示用)。 +- 「上传后自动删除」开关 `settings.UPLOAD_DELETE_AFTER` 对自动与手动上传统一生效。 + +**调用关系**:由 `ui/main_window.py`(`_open_upload`)构造。依赖 `core.uploader.UploadManager`、`core.api_client.APIClient`(测试连接)、`core.recording_repository.RecordingRepo`、`core.session_catalog.list_recordings`、`config.settings`、`config.i18n.tr`。 + +### ui/__init__.py + +**作用**:ui 包的空标记文件(0 行),仅使目录成为可导入包。无类、无函数、无数据。 diff --git a/collector/glove_devices.json b/collector/glove_devices.json new file mode 100644 index 0000000000000000000000000000000000000000..6c9ef5889ad580751cd879e8adbcd444a4264136 --- /dev/null +++ b/collector/glove_devices.json @@ -0,0 +1,12 @@ +{ + "schema_version": 1, + "left": { + "usb_serial": "2067376F3032" + }, + "right": { + "usb_serial": "2095376E3032" + }, + "extra_usb_serials": { + "2096376E3032": "right_glove" + } +} diff --git a/collector/lite_package/start_lite.bat b/collector/lite_package/start_lite.bat new file mode 100644 index 0000000000000000000000000000000000000000..51844f7a5458f810bc7e4f6004ec30619f7a8ae2 --- /dev/null +++ b/collector/lite_package/start_lite.bat @@ -0,0 +1,259 @@ +@echo off +rem ============================================================ +rem !!! ±àÂ뾯¸æ: ±¾Îļþ±ØÐ뱣³Ö GBK(ANSI) ±àÂë + CRLF ÐÐβ !!! +rem ÓüÇʱ¾ / VSCode Áí´棨ĬÈϴæ UTF-8 »áÂÒÂ뵼Ö cmd ½âÎö +rem ¾²Ĭʧ°ܣ©£¬ÈçËð»µÇë´Ó GitLab ÖØÐÂÏÂÔØԭÎļþ¡£ +rem ============================================================ +rem ============================================================ +rem DAQ ¼«¼ò²ɼ¯°æ ¡ª¡ª Windows һ¼ü²¿Êð½ű¾ +rem +rem Ó÷¨: +rem start_lite.bat ²¿Êð(°´Ðè) + Æô¶¯¼«¼ò²ɼ¯ +rem start_lite.bat reinstall ɾ³ý venv_lite ǿÖÆÖØװ£¨³öÎÊÌâÊ×ѡ£© +rem start_lite.bat help ´ò¿ª ʹÓÃ˵Ã÷_lite.md +rem +rem ֻ°²װ requirements-lite.txt °×Ãûµ¥ÒÀÀµ£¨¶ÀÁ¢ venv_lite/£¬ +rem ÓëÖ÷³ÌÐò venv/ »¥²»ӰÏ죩£»wheels/ Óë data/ Á½°汾¹²Óᣠ+rem ÒÀÀµ°²װ˳Ðò: wheels\ ÀëÏ߰ü ¡ú °¢ÀïÔƾµÏñ ¡ú Ç廪¾µÏñ ¡ú ¹ٷ½Դ +rem ´íÎóÂë A-G ¶ÔӦ ʹÓÃ˵Ã÷_lite.md£¨Ò쳣´¦ÀíÕ½ڣ© +rem ============================================================ +setlocal enabledelayedexpansion +cd /d "%~dp0" + +set "FORCE=0" +if /i "%~1"=="reinstall" set "FORCE=1" +if /i "%~1"=="help" goto :show_help + +echo. +echo ============================================================ +echo DAQ ¼«¼ò²ɼ¯°æ ¡ª¡ª һ¼ü²¿Êð +echo ============================================================ +echo. + +rem ©¤©¤ [G] ½âѹ²ã´Î×Լì ©¤©¤ +if not exist "main_lite.py" goto :errG +if not exist "requirements-lite.txt" goto :errG + +rem ©¤©¤ [1/6] ¶¨λ Python£¨°汾 >= 3.10£¬ÍƼö 3.12£©©¤©¤ +set "PY=" +set "VPY=venv_lite\Scripts\python.exe" +if exist "%VPY%" (set "PY=%VPY%" & goto :have_python) +echo [1/6] ²éÕÒ Python »·¾³ ... +call :try_py py -3.12 +if defined PY goto :have_python +call :try_py py -3 +if defined PY goto :have_python +call :try_py python +if defined PY goto :have_python +echo [1/6] δ¼ì²⵽ Python£¬×Զ¯ÏÂÔذ²װ Python 3.12£¨Լ 25MB£©... +set "PY_VER=3.12.10" +set "PY_EXE=%TEMP%\python-%PY_VER%-amd64.exe" +set "PY_URL=https://mirrors.aliyun.com/python-release/windows/python-%PY_VER%-amd64.exe" +set "PY_URL2=https://registry.npmmirror.com/-/binary/python/%PY_VER%/python-%PY_VER%-amd64.exe" +set "PY_URL3=https://mirrors.huaweicloud.com/python/%PY_VER%/python-%PY_VER%-amd64.exe" +if exist "wheels\python-%PY_VER%-amd64.exe" goto :py_copy_local +curl -L -o "%PY_EXE%" "%PY_URL%" --connect-timeout 20 --retry 2 --silent --show-error +if exist "%PY_EXE%" goto :py_run_installer +curl -L -o "%PY_EXE%" "%PY_URL2%" --connect-timeout 20 --retry 2 --silent --show-error +if exist "%PY_EXE%" goto :py_run_installer +curl -L -o "%PY_EXE%" "%PY_URL3%" --connect-timeout 20 --retry 2 --silent --show-error +if exist "%PY_EXE%" goto :py_run_installer +goto :errA +:py_copy_local +echo [1/6] ʹÓà wheels\ Ŀ¼ÄڵÄ Python °²װ°ü ... +copy /y "wheels\python-%PY_VER%-amd64.exe" "%PY_EXE%" >nul +:py_run_installer +echo [1/6] ¾²Ĭ°²װ Python ÖУ¨Ç벻Ҫ¹رմ°¿ڣ¬Լ 1 ·ÖÖӣ©... +"%PY_EXE%" /quiet InstallAllUsers=0 PrependPath=1 Include_pip=1 Include_test=0 Include_launcher=1 +del "%PY_EXE%" >nul 2>&1 +call :try_py py -3.12 +if defined PY goto :have_python +goto :errA + +:have_python +echo [1/6] ʹÓà Python: %PY% + +rem ©¤©¤ [2/6] ÐéÄ⻷¾³ venv_lite ©¤©¤ +if exist "%VPY%" if "%FORCE%"=="1" ( + echo [2/6] reinstall: ɾ³ý¾É venv_lite ... + rmdir /s /q "venv_lite" 2>nul + if exist "%VPY%" goto :errC2 +) +if exist "%VPY%" goto :deps_check +echo [2/6] ´´½¨ÐéÄ⻷¾³ venv_lite£¨Ê״ÎԼ 1 ·ÖÖӣ©... +rem עÒâ: PY ¿ÉÄÜÊǴø¿ոñµÄÃüÁpy -3.12 / python£©£¬²»ÄܼÓÒýºÅ +%PY% -m venv "venv_lite" +if not exist "%VPY%" goto :errC + +rem ©¤©¤ [3/6] °²װÒÀÀµ£¨requirements-lite.txt Óб仯»òÊ״Îʱ£©©¤©¤ +:deps_check +rem Óà requirements-lite.txt µÄ Ð޸Äʱ¼ä|´óС ×öǩÃû£¨ÄÚÈݱäÁ˲ÅÖØװ£© +for %%I in (requirements-lite.txt) do set "SIG=%%~tI;%%~zI" +if "%FORCE%"=="1" goto :install_deps +if not exist "venv_lite\.deps-lite-ok" goto :install_deps +set /p STAMP=<"venv_lite\.deps-lite-ok" +if "%STAMP%"=="%SIG%" goto :after_deps + +:install_deps +echo [3/6] °²װÒÀÀµ£¨Ê״ÎԼ 3-8 ·ÖÖӣ¬֮ºóÆô¶¯Ã뿪£©... +"%VPY%" -m pip install --upgrade pip >nul 2>&1 +call :pip_install_req +if errorlevel 1 goto :errD +> "venv_lite\.deps-lite-ok" echo %SIG% + +rem ©¤©¤ [4/6] ÒÀÀµðÑÌ×Լ죨ÄÜ import ¼´ͨ¹ý£©©¤©¤ +:after_deps +echo [4/6] ÒÀÀµ×Լì ... +"%VPY%" -c "import main_lite" >nul 2>&1 +if errorlevel 1 goto :errE +echo [4/6] ÒÀÀµ×Լìͨ¹ý + +rem ©¤©¤ [5/6] Æô¶¯ ©¤©¤ +echo [5/6] Æô¶¯¼«¼ò²ɼ¯ ... +echo. +echo ¡¾²Ù×÷ָÒý¡¿ +echo ¡¤ É豸: ²åÈëºóԼ 2 Ãë×Զ¯³öÏÖÔÚÁбí£¬ѡÖкóµã ¿ªÆô +echo ¡¤ ¼ÖÆ: Ïȿª D435£¬Ôٵã ¿ªʼ/ֹͣ£¨Õý³£ֹͣ=±£´棬X ¶ªÆú=×÷·ϣ© +echo ¡¤ Éϴ«: ¼ÖÆÍê³ɺó×Զ¯Éϴ«£¬»òÔÚÏ·½ÁбíÊֶ¯Éϴ« +echo ¡¤ ˵Ã÷: ˫»÷ start_lite.bat help ´ò¿ª ʹÓÃ˵Ã÷_lite.md +echo. +set "QT_QPA_PLATFORM_PLUGIN_PATH=%~dp0venv_lite\Lib\site-packages\PyQt5\Qt5\plugins\platforms" +"%VPY%" main_lite.py +set "EXITCODE=%errorlevel%" +if "%EXITCODE%"=="0" exit /b 0 +goto :errF + +rem ¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T +rem ×ӳÌÐò: УÑ鲢¼Ç¼¿ÉÓà Python ½âÊÍÆ÷ +rem ¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T +:try_py +%* -c "import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)" >nul 2>&1 +if errorlevel 1 exit /b 1 +set "PY=%*" +exit /b 0 + +rem ©¤©¤ ¼ì²é wheels\ Ŀ¼ÏÂÊǷñÓÐ .whl Îļþ ©¤©¤ +:wheels_exists +dir /b "wheels\*.whl" >nul 2>&1 +exit /b %errorlevel% + +rem ©¤©¤ °²װ requirements-lite.txt£¨ÀëÏ߰ü ¡ú °¢ÀïÔÆ ¡ú Ç廪 ¡ú ¹ٷ½Դ£©©¤©¤ +:pip_install_req +call :wheels_exists +if errorlevel 1 goto :req_online +echo [3/6] ¼ì²⵽ wheels\ ÀëÏ߰ü£¬ÓÅÏÈÀëÏ߰²װ ... +"%VPY%" -m pip install --no-index --find-links "wheels" -r requirements-lite.txt +if not errorlevel 1 exit /b 0 +echo [3/6] ÀëÏ߰ü°²װʧ°ܣ¬תÔÚÏ߰²װ ... +:req_online +"%VPY%" -m pip install -r requirements-lite.txt -i https://mirrors.aliyun.com/pypi/simple/ +if not errorlevel 1 exit /b 0 +"%VPY%" -m pip install -r requirements-lite.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +if not errorlevel 1 exit /b 0 +"%VPY%" -m pip install -r requirements-lite.txt +exit /b %errorlevel% + +rem ¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T +rem °ïÖú / ʹÓÃ˵Ã÷ +rem ¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T +:show_help +echo. +echo ¡¾³£ÓÃÃüÁ +echo start_lite.bat ²¿Êð²¢Æô¶¯£¨ĬÈϣ© +echo start_lite.bat reinstall ɾ³ý venv_lite ǿÖÆÖØװ +echo start_lite.bat help ´򿪱¾Îĵµ +echo. +if exist "ʹÓÃ˵Ã÷_lite.md" start "" "ʹÓÃ˵Ã÷_lite.md" +if not exist "ʹÓÃ˵Ã÷_lite.md" echo [¾¯¸æ] δÕҵ½ ʹÓÃ˵Ã÷_lite.md£¬Çë´Ó GitLab ÖØÐÂÏÂÔØÍêÕûÎļþ +pause +exit /b 0 + +rem ¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T +rem Ò쳣´¦Àí£¨´íÎóÂë A-G£¬Ïê¼û ʹÓÃ˵Ã÷_lite.md£© +rem ¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T +:errA +echo. +echo [´íÎó A] δÕҵ½ÇÒ×Զ¯°²װ Python 3.12 ʧ°Ü +echo ------------------------------------------------------------ +echo 0. Ðè Python 3.10 ÒÔÉϰ汾£¬ÍƼöÊֶ¯°²װ 3.12 +echo 1. ÀëÏ߻·¾³: °Ñ python-3.12.10-amd64.exe ·ÅÈ뱾Ŀ¼ wheels\ ºóÖØÊÔ +echo £¨ÓɹÜÀíԱÓà scripts\pack_wheels.py --lite Éú³ɣ© +echo 2. Êֶ¯°²װ: ä¯ÀÀÆ÷´򿪹ÙÍøÏÂÔØ Python 3.12.x 64 λ +echo °²װʱÎñ±ع´ѡ "Add python.exe to PATH" +echo 3. ÒѰ²װµ«û·´Ӧ: жÔØ Microsoft Store µÄ Python ÌæÉíºóÖØװ +echo. +start https://www.python.org/downloads/ +pause +exit /b 1 + +:errC +echo. +echo [´íÎó C] ÐéÄ⻷¾³´´½¨ʧ°Ü +echo ------------------------------------------------------------ +echo 1. ´ÅÅ̿ռ䲻×ã: ÇåÀí´ÅÅ̺óÖØÊԣ¬ÐèҪԼ 2GB ¿ռä +echo 2. ɱ¶¾Èí¼þÀ¹½Ø: °ѱ¾Ŀ¼¼ÓÈë°×Ãûµ¥ºó ˫»÷ start_lite.bat reinstall +echo 3. ·¾¶ÎÊÌâ: °ÑÏîĿÎļþ¼ÐÒƵ½·¾¶½϶̵ÄλÖã¨Èç C:\DAQ_lite£© +echo 4. ·¾¶º¬ÌØÊâ×ַû: »»һ¸ö´¿ӢÎÄ/Êý×ֵÄĿ¼ÔÙÊÔ +echo. +pause +exit /b 1 + +:errC2 +echo. +echo [´íÎó C2] ¾É venv_lite ɾ³ýʧ°ܣ¨Îļþ±»ռÓã© +echo ------------------------------------------------------------ +echo ÏȹرÕËùÓд򿪵IJɼ¯´°¿ڣ¬ÔÙ˫»÷ start_lite.bat reinstall +echo. +pause +exit /b 1 + +:errD +echo. +echo [´íÎó D] ÒÀÀµÏÂÔØ/°²װʧ°Ü +echo ------------------------------------------------------------ +echo 1. ¼ì²éÍøÂç: ÉԺó˫»÷ start_lite.bat ÖØÊԣ¨ÒÑÏÂÔز¿·ֻỺ´棩 +echo 2. ¹«˾ÄÚÍø/·À»ðǽ: ÇëÁªϵ¹ÜÀíԱ¿ªͨ pypi ¾µÏ񣬻òʹÓÃÀëÏ߰ü +echo ¹ÜÀíԱÓà scripts\pack_wheels.py --lite Éú³É wheels\ Ŀ¼ +echo 3. ɱ¶¾Èí¼þ/·À»ðǽÀ¹½Ø pip: ¼ÓÈë°×Ãûµ¥ºóÖØÊÔ +echo 4. ÖØװ: ˫»÷ start_lite.bat reinstall +echo. +pause +exit /b 1 + +:errE +echo. +echo [´íÎó E] ÒÀÀµ×Լìʧ°ܣ¨ÒÀÀµÒѰ²װµ«³ÌÐòÎ޷¨µ¼È룩 +echo ------------------------------------------------------------ +echo 1. ɱ¶¾Èí¼þÆƻµÁË venv_lite Îļþ: ¼Ӱ×Ãûµ¥ºóÖØװ +echo 2. ÒÀÀµ°汾³åͻ: ˫»÷ start_lite.bat reinstall ÖØװ +echo 3. ²鿴¾ßÌåԭÒò: ÔÚ cmd ÀïִÐÐ +echo venv_lite\Scripts\python.exe -c "import main_lite" +echo. +pause +exit /b 1 + +:errF +echo. +echo [´íÎó F] ³ÌÐòÆô¶¯ºóÒ쳣Í˳ö +echo ------------------------------------------------------------ +echo 1. ÏԿ¨Çý¶¯¹ý¾É: ¸üÐÂÏԿ¨Çý¶¯ºóÖØÊÔ +echo 2. Զ³Ì×ÀÃæ/ÐéÄâ»ú: ÇëÔڱ¾»úʵÌ廷¾³ÔËÐÐ +echo 3. Qt ƽ̨²å¼þËð»µ: ˫»÷ start_lite.bat reinstall ÖØװ +echo 4. ÉãÏñͷÒþ˽ȨÏÞ: Windows ÉèÖà - Òþ˽ºͰ²ȫÐÔ - Ïà»ú +echo ÔÊÐíӦÓ÷ÃÎÊÉãÏñͷ +echo 5. ²鿴´íÎóÐÅϢ: ÔÚ cmd ÀïִÐÐ +echo venv_lite\Scripts\python.exe main_lite.py +echo. +pause +exit /b 1 + +:errG +echo. +echo [´íÎó G] δÕҵ½ main_lite.py ¡ª¡ª ½âѹ²ã´β»¶Ô +echo ------------------------------------------------------------ +echo Ç뱣³ÖÎļþ¼нṹÍêÕû: start_lite.bat Óë main_lite.py ±ØÐëÔÚͬһĿ¼¡£ +echo ²»Ҫֻ¿½±´ start_lite.bat£¬Ðè½âѹÍêÕûÏîĿ£»ѹËõ°üÈô´øÍâ²ãÎļþ¼У¬ +echo Çë½øÈëÄڲãĿ¼ÔÙ˫»÷ start_lite.bat¡£ +echo. +pause +exit /b 1 diff --git a/collector/lite_package/start_lite.sh b/collector/lite_package/start_lite.sh new file mode 100755 index 0000000000000000000000000000000000000000..30afe52bc2133f157f3cd59f26dba3a4dbc6af0f --- /dev/null +++ b/collector/lite_package/start_lite.sh @@ -0,0 +1,118 @@ +#!/usr/bin/env bash +# ============================================================ +# DAQ 极简采集版 —— Linux 一键部署脚本(与 Windows start_lite.bat 行为一致) +# +# 用法: +# ./start_lite.sh 部署(按需) + 启动极简采集 +# ./start_lite.sh reinstall 删除 venv_lite 强制重装(出问题首选) +# ./start_lite.sh help 打开 使用说明_lite.md +# +# 只安装 requirements-lite.txt 白名单依赖(独立 venv_lite/, +# 与主程序 venv/ 互不影响);wheels/ 与 data/ 两版本共用。 +# 依赖安装顺序: 离线 wheels/ 包 → 阿里云镜像 → 清华镜像 → 官方源 +# ============================================================ +set -euo pipefail +cd "$(dirname "$0")" + +FORCE=0 +case "${1:-}" in + reinstall) FORCE=1 ;; + help|guide) MODE=help ;; +esac + +if [ "${MODE:-run}" = help ]; then + [ -f "使用说明_lite.md" ] && xdg-open "使用说明_lite.md" 2>/dev/null || true + echo "常用命令: ./start_lite.sh [reinstall|help]" + exit 0 +fi + +# ── [G] 解压层次自检 ── +if [ ! -f main_lite.py ] || [ ! -f requirements-lite.txt ]; then + echo "[错误 G] 未找到 main_lite.py —— 目录层次不对。start_lite.sh 与 main_lite.py 必须在同一目录。" + exit 1 +fi + +# ── [1/6] 定位 Python(>= 3.10,推荐 3.12)── +PY="" +find_python() { + for c in python3.12 python3.11 python3.10 python3; do + if command -v "$c" >/dev/null 2>&1 && "$c" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; then + PY="$(command -v "$c")" + return 0 + fi + done + return 1 +} +if [ -x venv_lite/bin/python ]; then + PY="venv_lite/bin/python" +elif ! find_python; then + echo "[错误 A] 未找到 Python >= 3.10。请先安装:" + echo " Ubuntu/Debian: sudo apt install python3.12 python3.12-venv" + echo " CentOS/RHEL: sudo dnf install python3.12" + echo " conda: conda create -n daq_lite python=3.12" + exit 1 +fi +echo "[1/6] 使用 Python: $PY" + +# ── [2/6] venv_lite ── +if [ -x venv_lite/bin/python ] && [ "$FORCE" = 1 ]; then + echo "[2/6] reinstall: 删除旧 venv_lite ..." + rm -rf venv_lite +fi +if [ ! -x venv_lite/bin/python ]; then + echo "[2/6] 创建虚拟环境 venv_lite(首次约 1 分钟)..." + "$PY" -m venv venv_lite +fi +VPY="venv_lite/bin/python" + +# ── [3/6] 依赖(requirements-lite.txt 的 mtime+size 签名驱动)── +HASH="$(md5sum requirements-lite.txt | cut -d' ' -f1)" +NEED_INSTALL=0 +if [ "$FORCE" = 1 ]; then + NEED_INSTALL=1 +elif [ ! -f venv_lite/.deps-lite-ok ] || [ "$(cat venv_lite/.deps-lite-ok)" != "$HASH" ]; then + NEED_INSTALL=1 +fi + +install_req() { + local req="$1" + if [ -d wheels ] && ls wheels/*.whl >/dev/null 2>&1; then + echo "[3/6] 检测到 wheels/ 离线包,优先离线安装 ..." + "$VPY" -m pip install --no-index --find-links wheels -r "$req" && return 0 + echo "[3/6] 离线包安装失败,转在线安装 ..." + fi + "$VPY" -m pip install -r "$req" -i https://mirrors.aliyun.com/pypi/simple/ && return 0 + "$VPY" -m pip install -r "$req" -i https://pypi.tuna.tsinghua.edu.cn/simple && return 0 + "$VPY" -m pip install -r "$req" +} + +if [ "$NEED_INSTALL" = 1 ]; then + echo "[3/6] 安装依赖(首次约 3-8 分钟,之后启动秒开)..." + "$VPY" -m pip install --upgrade pip >/dev/null 2>&1 || true + if ! install_req requirements-lite.txt; then + echo "[错误 D] 依赖下载/安装失败: 检查网络;内网环境请用 scripts/pack_wheels.py --lite 生成 wheels/ 离线包。" + exit 1 + fi + echo "$HASH" > venv_lite/.deps-lite-ok +fi + +# ── [4/6] 冒烟自检 ── +echo "[4/6] 依赖自检 ..." +if ! "$VPY" -c "import main_lite" >/dev/null 2>&1; then + echo "[错误 E] 依赖自检失败。查看具体原因:" + echo " venv_lite/bin/python -c \"import main_lite\"" + echo "重装: ./start_lite.sh reinstall" + exit 1 +fi +echo "[4/6] 依赖自检通过" + +# ── [5/6] 启动 ── +echo "[5/6] 启动极简采集 ..." +echo +echo "【操作指引】" +echo " · 设备: 插入后约 2 秒自动出现在列表,选中后点 开启" +echo " · 录制: 先开 D435,再点 开始/停止(正常停止=保存,⛔ 丢弃=作废)" +echo " · 上传: 录制完成后自动上传,或在下方列表手动上传" +echo " · 说明: ./start_lite.sh help 打开 使用说明_lite.md" +echo +exec "$VPY" main_lite.py diff --git "a/collector/lite_package/\344\275\277\347\224\250\350\257\264\346\230\216_lite.md" "b/collector/lite_package/\344\275\277\347\224\250\350\257\264\346\230\216_lite.md" new file mode 100644 index 0000000000000000000000000000000000000000..a44a37377c7d4f3b86300dce07cced64d40b3b3e --- /dev/null +++ "b/collector/lite_package/\344\275\277\347\224\250\350\257\264\346\230\216_lite.md" @@ -0,0 +1,84 @@ +# DAQ 极简采集版 · 使用说明 + +只做三件事:**连接设备 → 采集数据 → 上传**。无登录、无回放、无任务页、无骨架解算。 +体积小(无 torch/scipy/mediapipe/pyvista)、CPU 要求低(录制直接 x264、预览 15fps)。 + +> 与主程序共用 `data/`(录制目录、`pipeline.db`、`server_config.json`、手套序列号绑定), +> 两版可交替使用、数据互通;但虚拟环境独立(`venv_lite/`,与主程序 `venv/` 互不影响)。 + +--- + +## 一、启动(Windows 客户机) + +``` +双击 start_lite.bat +``` + +首次运行会自动:找 Python(没有就静默下载安装 3.12)→ 建 `venv_lite` → 装依赖 +(优先 `wheels\` 离线包 → 阿里云 → 清华 → 官方源)→ 依赖自检 → 启动。之后秒开。 + +| 命令 | 作用 | +|---|---| +| `start_lite.bat` | 部署(按需)+ 启动 | +| `start_lite.bat reinstall` | 删除 `venv_lite` 强制重装(出问题首选) | +| `start_lite.bat help` | 打开本文档 | + +**错误码**:`[错误 A]` 无 Python 且自动安装失败 → 手动装 3.12 并勾选 "Add python.exe to PATH"; +`[错误 C]` 建 venv 失败 → 磁盘空间/杀毒软件/中文路径;`[错误 D]` 依赖安装失败 → 网络或让管理员 +生成离线包;`[错误 E]` 自检失败 → 杀毒软件或 `reinstall`;`[错误 F]` 启动即退 → 显卡驱动/远程桌面; +`[错误 G]` 解压层次不对 → 保持文件夹完整、不要只拷 bat。 + +**无外网环境**:管理员在有网机器上运行 `python scripts/pack_wheels.py --lite` 生成 +`wheels\` 目录(约几百 MB),连同 `python-3.12.10-amd64.exe` 一起拷到客户项目根目录, +`start_lite.bat` 自动改走纯离线安装。 + +**Linux**:`./start_lite.sh`(`reinstall` / `help` 子命令同上)。 + +--- + +## 二、日常操作流程 + +1. **插设备**:D435(USB3)、UVC 摄像头、USB-C 手套、BLE 手套(已配对)。约 2 秒后出现在左侧对应列表。 +2. **开启**:左侧设备组选中设备 → 点「开启」;中上方出现预览(RGB / 深度热力图 / UVC 可切换, + 开启设备后预览源会自动切到新开的设备)。 + - 录制必须有视频源:**先开 D435 或 UVC 摄像头**(只开 UVC 时以其为主视频源,无深度图)。 + - 手套左右手按序列号/广播名 L/R 自动绑定传感器列,与主程序共用绑定记忆。 +3. **录制**:填任务名(可选)→「▶ 开始」→「■ 停止」保存(「X 丢弃」作废)。 + 保存后按「自动上传」开关决定是否自动入队上传。 +4. **上传**:顶部填服务器地址 →「测试连接」→ 下方列表「上传全部未上传」; + 勾「上传后删除」则上传成功后自动删除本地文件。 + +录制数据落在 `data/recordings/`(与主程序同目录结构),在主程序的 ☁ 上传对话框同样可见。 + +--- + +## 三、与主程序的差异(本版没有的东西) + +- 无登录/任务页/回放/查看器/使用向导;无骨架关键点解算(parquet 的 hand_pose 列为全零占位,合法)。 +- 无 S80M/S80C;每类设备(D435 / UVC / USB 手套 / BLE 手套)只支持 1 台。 +- UVC 摄像头采集固定 640×480、30fps(预览刷新仍限 15fps;无深度图); + Windows 枚举无需额外依赖(pygrabber+comtypes 可选,装了仅提升枚举质量)。 +- 预览固定 640×360、15fps;编码器固定 x264(跳过 x265 速度探针,低端机友好)。 +- 依赖只有 9 个包(`requirements-lite.txt`);`imageio-ffmpeg`(77MB)提供内置 ffmpeg, + 装有系统 ffmpeg 的机器可删除该行再重装以省体积。 + +## 四、手工验收清单(真实设备) + +- [ ] D435 出现在列表 → 开启 → RGB/深度预览切换正常 → 录 30s → 停止 → `data/recordings/<任务>/` + 出现 `videos/chunk-000/d435_rgb/`、`depth/`、`data/chunk-000/*.parquet`、`meta/info.json` +- [ ] UVC 摄像头出现在列表 → 开启(不开 D435)→ 预览切到 UVC 有画面 → 录 10s → 停止 → + `videos/chunk-000/uvc_rgb/` 有视频,parquet 无深度相关列 +- [ ] 主程序 ☁ 上传对话框能看到刚才的会话(共用 `pipeline.db`) +- [ ] USB 手套开启 → parquet 含 `observation.<列>_imu_quat/_imu_valid`,hand_pose 列全零 +- [ ] BLE 手套广播名 L/R 绑定左右列正确 +- [ ] 服务器地址保存后重启仍在(与主程序共用 `server_config.json`,不互相覆盖) +- [ ] 勾「自动上传」→ 录制完成后自动上传 → 服务器可见 session +- [ ] 无 Python 的 Windows 真机跑 `start_lite.bat` 全流程(含 `wheels\` 离线安装) + +## 五、常见问题 + +- **预览显示「无信号」**:开启设备后预览会自动切到新开设备的画面;若仍无信号, + 看窗口下方日志 —— 出现「无法打开…可能被其他程序占用」说明摄像头正被别的程序 + 使用(主程序 / 浏览器 / 另一个极简版窗口),关掉它们后点「关闭」再重新「开启」。 +- **录不了**:录制必须有视频源 —— 先开 D435 或 UVC 摄像头。 +- **改了代码不生效**:`start_lite.sh reinstall` 重装依赖,或先关闭所有旧窗口再重开。 diff --git a/collector/main.py b/collector/main.py new file mode 100755 index 0000000000000000000000000000000000000000..7b6254c13ec0b82f53f74f4d3637cc8dfc70ce58 --- /dev/null +++ b/collector/main.py @@ -0,0 +1,77 @@ +""" +DAQ 视频管线 — 程序入口。 + +多路摄像机实时监控与录制系统: + - 可拖拽调整大小的多画面网格布局 + - 每路摄像机独立的录制控制(正常停止保存 / 异常停止丢弃) + - 录制时长实时显示在开始按钮上方 + - 录制历史记录追踪 + - 中英文界面切换 + +用法: + python main.py +""" + +import sys +import os + +_base = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, _base) + +# 先导入 torch,再导入 PyQt5(避免 DLL 加载冲突;torch 不可用时跳过) +try: + import torch # noqa: F401 +except ImportError: + pass + +from PyQt5.QtWidgets import QApplication, QDesktopWidget +from PyQt5.QtCore import Qt +from PyQt5.QtGui import QFontDatabase # noqa: F401 — qt-material 需要 +from qt_material import apply_stylesheet + +from ui.main_window import MainWindow + +# ── Qt 平台插件路径修复 ─────────────────────────────── +# cv2(opencv-python 预编译轮子)在首次 import 时会把 +# QT_QPA_PLATFORM_PLUGIN_PATH 覆盖成它自带的 qt/plugins 目录 +# (见 venv/.../cv2/config-3.py),其 xcb 插件与 PyQt5 的 Qt 库 +# 不兼容 → QApplication 创建即崩溃("Could not load the Qt +# platform plugin xcb")。必须在所有 import 之后、QApplication +# 创建之前把路径抢回 PyQt5 自带插件目录(cv2 只写一次,不会再覆盖)。 +import PyQt5 +_qt_platforms = os.path.join( + os.path.dirname(os.path.abspath(PyQt5.__file__)), + "Qt5", "plugins", "platforms") +if os.path.isdir(_qt_platforms): + os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = _qt_platforms + + +def main(): + QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) + QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) + + app = QApplication(sys.argv) + app.setApplicationName("DAQ 视频管线") + + # ── Qt-Material 暗色主题 ────────────────────────── + apply_stylesheet(app, theme='dark_teal.xml') + + window = MainWindow() + # 先确定会话身份(账号登录/游客登录,身份决定任务页可见内容), + # 确认前不显示主窗口(登录框弹在主窗口之前,不露出任务页), + # 之后才是首次启动或经 start.bat/start.sh 启动(DAQ_SHOW_GUIDE=1)时的使用步骤窗口 + if not window.maybe_show_login(): + # 启动首屏关闭登录窗口 = 直接退出(不再静默进游客模式) + window.close() # 触发 closeEvent 释放已初始化的资源 + sys.exit(0) + window.show() + # 主窗口在登录框之后才 show,WM 不再把它当首窗居中(常落左上角)→ 显式居中 + geo = window.frameGeometry() + geo.moveCenter(QDesktopWidget().availableGeometry().center()) + window.move(geo.topLeft()) + window.maybe_show_guide() + sys.exit(app.exec_()) + + +if __name__ == "__main__": + main() diff --git a/collector/main_lite.py b/collector/main_lite.py new file mode 100644 index 0000000000000000000000000000000000000000..286becbd7d382b51ea0a34d51664b0bd27d9e137 --- /dev/null +++ b/collector/main_lite.py @@ -0,0 +1,61 @@ +""" +DAQ 极简采集 —— 程序入口(lite 版)。 + +只保留: 连接设备 → 采集(parquet+MP4) → 上传。 +无登录 / 任务页 / 回放 / 骨架解算 / qt-material 主题 / torch。 +依赖白名单见 requirements-lite.txt;部署入口见 start_lite.bat / start_lite.sh。 + +用法: + python main_lite.py +""" + +import sys +import os + +_base = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, _base) + +from PyQt5.QtWidgets import QApplication, QDesktopWidget +from PyQt5.QtCore import Qt + +from config import settings + +# 低端机优化:跳过 10-20s 的 x265 速度探针,录制直接走 x264 +# (egodata_writer 依据此开关在 start_episode 里选编码器) +settings.ENCODER_PROBE_ENABLED = False + +from ui.lite_window import LiteWindow, LITE_QSS + +# ── Qt 平台插件路径修复 ─────────────────────────────── +# cv2(opencv-python 预编译轮子)首次 import 时会把 +# QT_QPA_PLATFORM_PLUGIN_PATH 覆盖成它自带的 qt/plugins 目录, +# 其 xcb 插件与 PyQt5 的 Qt 库不兼容 → QApplication 创建即崩溃。 +# 必须在所有 import 之后、QApplication 创建之前把路径抢回 +# PyQt5 自带插件目录(与 main.py 同口径)。 +import PyQt5 +_qt_platforms = os.path.join( + os.path.dirname(os.path.abspath(PyQt5.__file__)), + "Qt5", "plugins", "platforms") +if os.path.isdir(_qt_platforms): + os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = _qt_platforms + + +def main(): + QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) + QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True) + + app = QApplication(sys.argv) + app.setApplicationName("DAQ 极简采集") + app.setStyleSheet(LITE_QSS) + + window = LiteWindow() + window.show() + # 居中(与 main.py 同口径,WM 可能把首窗丢左上角) + geo = window.frameGeometry() + geo.moveCenter(QDesktopWidget().availableGeometry().center()) + window.move(geo.topLeft()) + sys.exit(app.exec_()) + + +if __name__ == "__main__": + main() diff --git a/collector/requirements-lite.txt b/collector/requirements-lite.txt new file mode 100644 index 0000000000000000000000000000000000000000..f1ea5313cdb7e2949792bb5bbb112663ad6bcbb3 --- /dev/null +++ b/collector/requirements-lite.txt @@ -0,0 +1,16 @@ +# 极简采集版依赖白名单(start_lite.bat / start_lite.sh 使用) +# 只保留: 连接设备 → 采集(parquet+MP4) → 上传。 +# 不含回放/登录/任务页/骨架解算(toolkit/scipy/loguru/pydantic)/pyvista 等重型依赖。 +# 注意: imageio-ffmpeg(约 77MB) 提供静态 ffmpeg 二进制(含 x264), +# 客户机无 PATH ffmpeg 时录制链必需;装有系统 ffmpeg 的机器可删掉本行。 +# UVC 摄像头零新增依赖: Linux 走 sysfs 枚举;Windows 无 pygrabber 时 +# 自动退化 DShow 索引探测(装了 pygrabber+comtypes 仅提升枚举质量)。 +PyQt5>=5.15.0 +numpy>=1.24 +opencv-python>=4.10 +pyarrow>=14.0.0 +imageio-ffmpeg>=0.5.0 +bleak>=0.20.0 +requests>=2.28 +pyserial>=3.5 +pyrealsense2 diff --git a/collector/requirements.txt b/collector/requirements.txt new file mode 100755 index 0000000000000000000000000000000000000000..6858c5559734c8e3d0013bbbdc6356d65177a3d7 --- /dev/null +++ b/collector/requirements.txt @@ -0,0 +1,21 @@ +# ── 主程序 GUI 必需依赖(start.bat / start.sh 一键部署与本清单一致)── +PyQt5>=5.15.0 +numpy>=1.24 +opencv-python>=4.10 # cv2 在 ui/core 顶层 import,主程序启动必需 +pyarrow>=14.0.0 +imageio-ffmpeg>=0.5.0 +bleak>=0.20.0 +qt-material>=2.14 +h5py>=3.10 +requests>=2.28 +pygrabber>=0.2 # Windows UVC 设备枚举 +comtypes>=1.4 # pygrabber 依赖 +pyvista>=0.42 +pyvistaqt>=0.11 +pyserial>=3.5 # USB (Type-C) STM32 手套 CDC 串口 + +# ── 可选依赖(代码内惰性导入,缺失时对应功能不可用)── +# 一键安装: start.bat extras / start.bat extras-torch +# pyrealsense2 # Intel D435/D405 深度相机 +# mediapipe # 裸手 3D 关键点(bare 模式) +# torch # 手部关键点 RTMPose 后端(CPU 版安装见 `start.bat extras-torch`) diff --git a/collector/run.bat b/collector/run.bat new file mode 100755 index 0000000000000000000000000000000000000000..b030bf478edcd94b53060e3829086864da9d57bc --- /dev/null +++ b/collector/run.bat @@ -0,0 +1,5 @@ +@echo off +cd /d "%~dp0" +set QT_QPA_PLATFORM_PLUGIN_PATH=%~dp0venv\Lib\site-packages\PyQt5\Qt5\plugins\platforms +venv\Scripts\python.exe main.py +pause diff --git a/collector/run.sh b/collector/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..eee48358ddfd7b22ae982628eef879753001755f --- /dev/null +++ b/collector/run.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# DAQ 程序启动脚本 —— 使用项目自带 venv 运行 +# 用法: ./run.sh +cd "$(dirname "$0")" + +if [ ! -x venv/bin/python ]; then + echo "[错误] 未找到 venv,请先创建虚拟环境:" + echo " python -m venv venv && venv/bin/pip install -r requirements.txt" + exit 1 +fi + +exec venv/bin/python main.py "$@" diff --git a/collector/scripts/migrate_pooled_storage.py b/collector/scripts/migrate_pooled_storage.py new file mode 100644 index 0000000000000000000000000000000000000000..e8bfa0b8a9f87c7082d48e83888ea6b01dc705a6 --- /dev/null +++ b/collector/scripts/migrate_pooled_storage.py @@ -0,0 +1,1360 @@ +#!/usr/bin/env python +"""一次性迁移脚本:旧「每会话一个子目录」布局 → v1.1.0 任务级池化布局。 + +旧布局(egodata v1.0,每会话一个子目录): + /_NNNNNN/ + ├── metadata.json / timestamps.json / calibration/*.json + ├── videos//chunk-0000/.mp4 + ├── data//chunk-0000/chunk_000000.parquet(每传感器一文件) + ├── depth//.mkv | NNNNNN.png | NNNNNN.bin + └── meta/{info.json, stats.json, tasks.jsonl, + episodes/{chunk_000000.parquet, chunk-000/file-000.parquet}} + +新布局(v1.1.0 任务级池化;v1.1.2 起文件前缀 file- → episode-): + / + ├── videos/chunk-NNN//episode-NNN.ext # 每 episode 一文件 + ├── data/chunk-NNN/episode-NNN.parquet # 单文件稀疏列 + └── meta/{info.json, stats.json, tasks.jsonl, + episodes/chunk-NNN/episode-NNN.parquet} + +迁移内容(每会话): + 1. 按旧 metadata.json episode_index/created_at 排序定新全局序号 N( + 已存在池化 episode 之后续排) + 2. 视频 move: videos//chunk-0000/.mp4 → 池化路径 + 3. 深度: mkv 直接 move;png16/bin 序列经 numpy+ffmpeg 无损合成 + 单流 FFV1 gray16le mkv(数据无损;显示层热力图由读取端按需生成) + 4. data parquet 列合并: timestamps.json 为骨架(含 wall_time/ + hardware_ns)+ 各传感器/IMU 按 frame_index 对齐(同帧多槽行取首行) + + action/手部占位零 + 旧 status. 列(如有) + 5. episodes 分片 append 一行(created_at/video_codec/drop_stats 取自 + metadata.json,calibration 取 calibration/*.json 原文) + 6. 任务级 info.json(并集合并)/ tasks.jsonl / stats.json(v1.1.1 + 自含 count 累加器,无 .stats_state 边车) + 7. pipeline.db 改写(recording.file_path → 任务目录 + episode_index; + upload_task.session_path 同);改前自动备份 + 8. keypoints_output//<旧会话名>/ → /episode_{N:06d}/ + 9. 旧会话目录先**全量快照复制**到 data/recordings/_migrate_backup_/ + 再移动媒体(快照在前是 restore 无损的前提),迁移完成删除残壳 + (--no-backup 跳过快照=显式破坏性模式;manifest 记录全部映射) + +用法: + venv/bin/python scripts/migrate_pooled_storage.py --dry-run + venv/bin/python scripts/migrate_pooled_storage.py [--backup] [--task 名称] + venv/bin/python scripts/migrate_pooled_storage.py --validate + venv/bin/python scripts/migrate_pooled_storage.py --restore [--task 名称] + +限制(一次性工具,已知可接受): + - stats 为累加器语义:--restore 不回退 stats 数值(若任务无剩余 + episode 则删除 stats 文件;有剩余则保留并含已迁移数值) + - 旧格式行无视频帧-传感器一一对应元信息:传感器/IMU 按 frame_index + 挂到同帧首行(旧读取端同口径) + - 深度合成单流 FFV1(非双流),显示端按需热力图 + - 无 ffmpeg 时跳过 png16/bin 深度会话并警告(视频/数据仍迁移) + - 快照复制需要 2× 磁盘临时余量;确认备份无误后再删除备份区 +""" +import argparse +import json +import os +import re +import shutil +import sqlite3 +import subprocess +import sys +import time + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import numpy as np + +from config import settings +from core.helpers import (episode_chunk_file, POOLED_CHUNK_SIZE, + pooled_video_path, + pooled_data_parquet_path, pooled_episodes_path, + _legacy_episodes_shard_path, + pooled_info_path, pooled_stats_path, + pooled_tasks_jsonl_path, + load_stats_acc, merge_stat_block, + acc_to_stats_json, recalc_stats, + list_task_episodes) +from core.egodata_writer import (_episode_rows_table, _read_episode_rows, + _atomic_write_parquet, _LockedFile) + +try: + import fcntl as _fcntl +except ImportError: + _fcntl = None + +try: + import cv2 # png16 解码 +except ImportError: + cv2 = None + +MANIFEST_VERSION = 1 +MANIFEST_NAME = ".migrate_manifest.json" + +RECORDINGS_DIR = os.path.join(settings.DATA_DIR, "recordings") +DB_PATH = os.path.join(settings.DATA_DIR, "pipeline.db") + +DEFAULT_SENSOR_DIM = 256 + + +# ── 日志 / 报告 ────────────────────────────────────────────── + +class Report: + """迁移执行报告(dry-run 只打印,实跑落到 backup 根目录)。""" + + def __init__(self): + self.sessions = [] + self.warnings = [] + + def add(self, task, session, n, kind, detail, created, db_rows, warns): + self.sessions.append({ + "task": task, "session": session, "N": n, "kind": kind, + "detail": detail, "created": created, "db_rows": db_rows, + }) + self.warnings.extend(warns) + + def print(self, label): + print(f"\n===== 迁移报告 [{label}] =====") + for s in self.sessions: + print(f" [{s['kind']}] {s['task']} :: {s['session']} → " + f"episode {s['N']} ({s['detail']})") + for f in s["created"]: + print(f" + {f}") + for d in s["db_rows"]: + print(f" db {d['table']} id={d['id']}") + if self.warnings: + print(" ⚠ 警告:") + for w in self.warnings: + print(f" - {w}") + if not self.sessions: + print(" (无可迁移/已回滚的会话)") + + +# ── 会话发现 ──────────────────────────────────────────────── + +def task_dirs(root, task_filter): + out = [] + for name in sorted(os.listdir(root)): + if name.startswith("_") or name.startswith("."): + continue + d = os.path.join(root, name) + if not os.path.isdir(d): + continue + if task_filter and name not in task_filter: + continue + out.append((name, d)) + return out + + +def legacy_sessions(task_dir, task): + """任务目录下的旧会话子目录(有 metadata.json 且非池化结构目录)。""" + out = [] + try: + children = os.listdir(task_dir) + except OSError: + return out + for name in children: + d = os.path.join(task_dir, name) + if not os.path.isdir(d): + continue + if name in ("videos", "data", "meta", "depth", "calibration") \ + or name.startswith("chunk-") or name.startswith("_"): + continue + if os.path.isfile(os.path.join(d, "metadata.json")): + out.append(d) + out.sort(key=lambda d: _session_sort_key(d, task)) + return out + + +def _session_sort_key(session_dir, task): + """排序键:旧 metadata.json 的 episode_index,回退 created_at/名字。""" + try: + with open(os.path.join(session_dir, "metadata.json"), + "r", encoding="utf-8") as f: + m = json.load(f) + except (OSError, json.JSONDecodeError): + m = {} + return (int(m.get("episode_index", 0) or 0), + float(m.get("created_at", 0) or 0), + os.path.basename(session_dir)) + + +def load_json(path, default=None): + try: + with open(path, "r", encoding="utf-8") as f: + return json.load(f) + except (OSError, json.JSONDecodeError): + return default + + +# ── 旧数据读取 ────────────────────────────────────────────── + +def read_ts_rows(session_dir): + """timestamps.json → ([{frame_index, timestamp, wall_time, hardware_ns}], + total_frames);缺失返回 (None, None)。""" + ts = load_json(os.path.join(session_dir, "timestamps.json")) + if not ts or not isinstance(ts.get("timestamps"), list): + return None, None + return ts["timestamps"], int(ts.get("total_frames") or 0) + + +def read_sensor_parquet(session_dir, sensor): + """data//chunk-0000/chunk_000000.parquet → {frame_index: row}""" + for rel in (f"data/{sensor}/chunk-0000/chunk_000000.parquet", + f"data/{sensor}/chunk_000000.parquet", + f"data/{sensor}/chunk-000/file-000.parquet"): + p = os.path.join(session_dir, rel) + if os.path.isfile(p): + import pyarrow.parquet as pq + t = pq.read_table(p) + idx = {} + for r in t.to_pylist(): + fi = int(r.get("frame_index", 0)) + if fi not in idx: # 同帧多槽行取首行 + idx[fi] = r + return idx + return None + + +def find_legacy_media(session_dir, metadata): + """定位旧视频/深度文件。 + + 返回 ({cam: (src, kind)}, {depth_slot: (src, kind)}) + kind ∈ {move, png16, bin} + """ + vids, depths = {}, {} + for cam, info in (metadata.get("cameras") or {}).items(): + if not isinstance(info, dict): + continue + ctype = info.get("type", "rgb") + if ctype == "depth": + src = _find_depth_source(session_dir, cam) + if src: + depths[cam] = src + continue + # rgb: videos//chunk-0000/.mp4(兼容无 chunk 层) + for rel in (f"videos/{cam}/chunk-0000/{cam}.mp4", + f"videos/{cam}/{cam}.mp4"): + p = os.path.join(session_dir, rel) + if os.path.isfile(p): + vids[cam] = (p, "move") + break + if cam not in vids: + # 兜底:videos/ 下任意 mp4(槽名可能与 metadata 名不同) + d = os.path.join(session_dir, "videos", cam) + if os.path.isdir(d): + for root, _dirs, files in os.walk(d): + for fn in sorted(files): + if fn.endswith(".mp4"): + vids[cam] = (os.path.join(root, fn), "move") + break + if cam in vids: + break + return vids, depths + + +def _find_depth_source(session_dir, slot): + mkv = os.path.join(session_dir, "depth", slot, f"{slot}.mkv") + if os.path.isfile(mkv): + return (mkv, "move") + d = os.path.join(session_dir, "depth", slot) + if not os.path.isdir(d): + return None + pngs = sorted(f for f in os.listdir(d) + if f.endswith(".png") and f.split(".")[0].isdigit()) + if pngs: + return (os.path.join(d, pngs[0]), "png16") + bins = sorted(f for f in os.listdir(d) + if f.endswith(".bin") and f.split(".")[0].isdigit()) + if bins: + return (os.path.join(d, bins[0]), "bin") + return None + + +def depth_frame_files(session_dir, slot): + """深度帧文件按数字文件名升序 → [(abs_path, frame_no)]""" + d = os.path.join(session_dir, "depth", slot) + if not os.path.isdir(d): + return [] + out = [] + for fn in os.listdir(d): + stem = fn.rsplit(".", 1)[0] + if stem.isdigit() and fn.rsplit(".", 1)[1] in ("png", "bin"): + out.append((os.path.join(d, fn), int(stem))) + out.sort(key=lambda x: x[1]) + return out + + +# ── 深度合成(png16 / bin → 单流 FFV1 gray16le mkv) ───────── + +def find_ffmpeg(metadata): + """ffmpeg 二进制:metadata 记录的 imageio_ffmpeg 路径 → PATH → None。""" + vc = metadata.get("video_codec") or {} + p = vc.get("ffmpeg") + if p and os.path.isfile(p): + return p + try: + import imageio_ffmpeg + exe = imageio_ffmpeg.get_ffmpeg_exe() + if exe and os.path.isfile(exe): + return exe + except Exception: + pass + return shutil.which("ffmpeg") + + +def synthesize_depth_mkv(task_dir, session_dir, slot, metadata, out_path, + warn): + """png16/bin 序列 → 无损单流 FFV1 gray16le mkv(out_path)。""" + frames = depth_frame_files(session_dir, slot) + if not frames: + warn(f"{slot}: 深度帧目录为空,跳过") + return False + ffmpeg = find_ffmpeg(metadata) + if not ffmpeg: + warn(f"{slot}: 无 ffmpeg,跳过深度合成({len(frames)} 帧未迁移)") + return False + cam = (metadata.get("cameras") or {}).get(slot) or {} + fps = float(metadata.get("fps") or cam.get("fps") or 30.0) + width = int(cam.get("width") or 0) + height = int(cam.get("height") or 0) + + tmp_raw = os.path.join(task_dir, f".migrate_tmp_{slot}_N{int(time.time()*1000)%100000}.raw") + try: + # 逐帧解码/读入 memmap,避免整段驻留内存 + first = None + count = 0 + ext = os.path.splitext(frames[0][0])[1].lower() + if ext == ".png": + if cv2 is None: + warn(f"{slot}: 无 cv2(OpenCV),跳过 png16 深度合成") + return False + for path, _no in frames: + img = cv2.imread(path, cv2.IMREAD_UNCHANGED) + if img is None: + continue + if img.ndim == 3: + img = img[..., 0] + if img.dtype != np.uint16: + warn(f"{slot}: png 非 uint16({img.dtype}),跳过深度合成") + return False + if first is None: + first = img + width, height = img.shape[1], img.shape[0] + count += 1 + else: # bin: raw uint16 + if width <= 0 or height <= 0: + warn(f"{slot}: bin 序列缺分辨率(metadata 无 width/height)," + "跳过深度合成") + return False + first = np.zeros((height, width), dtype=np.uint16) + count = len(frames) + if first is None or count == 0: + return False + + npx = width * height + mm = np.memmap(tmp_raw, dtype=np.uint16, mode="w+", + shape=(count * npx,)) + i = 0 + if ext == ".png": + for path, _no in frames: + img = cv2.imread(path, cv2.IMREAD_UNCHANGED) + if img is None or img.ndim == 3: + img = img[..., 0] if img is not None and img.ndim == 3 \ + else np.zeros((height, width), np.uint16) + mm[i * npx:(i + 1) * npx] = img.reshape(-1)[:npx] + i += 1 + else: + for path, _no in frames: + raw = np.fromfile(path, dtype=np.uint16) + mm[i * npx:(i + 1) * npx] = raw[:npx] + i += 1 + mm.flush() + del mm + + os.makedirs(os.path.dirname(out_path), exist_ok=True) + cmd = [ffmpeg, "-y", "-loglevel", "error", + "-f", "rawvideo", "-pix_fmt", "gray16le", + "-s", f"{width}x{height}", "-framerate", f"{fps}", + "-i", tmp_raw, + "-c:v", "ffv1", "-pix_fmt", "gray16le", out_path] + r = subprocess.run(cmd, capture_output=True, text=True) + if r.returncode != 0: + warn(f"{slot}: ffmpeg 合成失败: {r.stderr.strip()[:300]}") + return False + return True + finally: + try: + os.remove(tmp_raw) + except OSError: + pass + + +# ── data parquet 列合并 ───────────────────────────────────── + +def build_merged_table(meta, ts_rows, sensor_idx, imu_idx): + """按新格式契约构建本 episode 的 data 表。 + + ts_rows 为骨架(一行一帧槽位行);sensor_idx/imu_idx 为 + {frame_index: 旧行}(同帧多槽行取首行)。 + """ + import pyarrow as pa + n_ep = int(meta.get("episode_index", 0)) # 由调用方覆盖为新 N + sensor_dim = int((meta.get("sensor_dim") or DEFAULT_SENSOR_DIM) + or DEFAULT_SENSOR_DIM) + hand_dim = int(settings.HAND_POSE_DIM or 63) + + sensors = sorted(sensor_idx.keys()) + cols = {} + cols["episode_index"] = pa.array([n_ep] * len(ts_rows), pa.int64()) + cols["frame_index"] = pa.array([int(r.get("frame_index", 0)) + for r in ts_rows], pa.int64()) + cols["timestamp"] = pa.array([float(r.get("timestamp", 0.0)) + for r in ts_rows], pa.float32()) + cols["task_index"] = pa.array([0] * len(ts_rows), pa.int64()) + cols["wall_time"] = pa.array([float(r.get("wall_time", 0.0)) + for r in ts_rows], pa.float64()) + cols["hardware_ns"] = pa.array([int(r.get("hardware_ns", 0) or 0) + for r in ts_rows], pa.int64()) + cols["action"] = pa.array([[0.0]] * len(ts_rows), + pa.list_(pa.float32(), 1)) + + for sn in sensors: + idx = sensor_idx[sn] + vals = [] + for r in ts_rows: + fi = int(r.get("frame_index", 0)) + row = idx.get(fi) + v = (row or {}).get(f"observation.{sn}") + if v is None: + v = [0.0] * sensor_dim + v = [float(x) for x in v] + if len(v) < sensor_dim: + v = v + [0.0] * (sensor_dim - len(v)) + vals.append(v[:sensor_dim]) + cols[f"observation.{sn}"] = pa.array( + vals, pa.list_(pa.float32(), sensor_dim)) + + if imu_idx is not None: + # IMU 只挂在每帧首行(旧格式=stereo_left 行,左右目共享样本) + ts_list, imu_list = [], [] + seen = set() + for r in ts_rows: + fi = int(r.get("frame_index", 0)) + row = imu_idx.get(fi) + if fi in seen or row is None: + ts_list.append([]) + imu_list.append([]) + continue + seen.add(fi) + ts_list.append([int(x) for x in (row.get("imu_ts_ns") or [])]) + imu_list.append([[float(x) for x in s] + for s in (row.get("observation.imu") or [])]) + cols["imu_ts_ns"] = pa.array(ts_list, pa.list_(pa.int64())) + cols["observation.imu"] = pa.array( + imu_list, pa.list_(pa.list_(pa.float32(), 6))) + + for pose in (settings.HAND_POSE_LEFT, settings.HAND_POSE_RIGHT): + cols[f"observation.{pose}"] = pa.array( + [[0.0] * hand_dim] * len(ts_rows), + pa.list_(pa.float32(), hand_dim)) + + # status.:旧 parquet 携带过设备状态列则保留(同帧取首行) + dids = set() + for idx in sensor_idx.values(): + for row in (idx or {}).values(): + for key in (row or {}).keys(): + if isinstance(key, str) and key.startswith("status."): + dids.add(key[len("status."):]) + for did in sorted(dids): + vals = [] + for r in ts_rows: + fi = int(r.get("frame_index", 0)) + row = next((idx.get(fi) for idx in sensor_idx.values() + if f"status.{did}" in (idx.get(fi) or {})), None) + vals.append(str((row or {}).get(f"status.{did}", "connected"))) + cols[f"status.{did}"] = pa.array(vals, pa.string()) + + return pa.table(cols), sensors + + +# ── 统计(stats.json 自含累加器,v1.1.1) ────────────────── + +def episode_stat_blocks(table, sensors, has_imu): + """本 episode 各列的统计块 {key: {count,sum,sum_sq,min,max}}。""" + blocks = {} + cols = {c: table.column(c).to_pylist() for c in table.column_names} + for sn in sensors: + name = f"observation.{sn}" + vals = [np.asarray(v, dtype=np.float64) for v in cols[name] + if v and any(x != 0 for x in v)] + if not vals: + continue + arr = np.stack(vals) + blocks[name] = { + "count": int(arr.shape[0]), + "sum": arr.sum(axis=0).tolist(), + "sum_sq": (arr * arr).sum(axis=0).tolist(), + "min": arr.min(axis=0).tolist(), + "max": arr.max(axis=0).tolist(), + } + if has_imu: + samples = [np.asarray(s, dtype=np.float64) + for v in cols["observation.imu"] for s in v] + if samples: + arr = np.stack(samples) + blocks["observation.imu"] = { + "count": int(arr.shape[0]), + "sum": arr.sum(axis=0).tolist(), + "sum_sq": (arr * arr).sum(axis=0).tolist(), + "min": arr.min(axis=0).tolist(), + "max": arr.max(axis=0).tolist(), + } + return blocks + + +def merge_state_and_write(task_dir, blocks): + """把各 episode 统计块合并进 stats.json(v1.1.1 自含累加器,同写入器)。""" + acc, need_recalc = load_stats_acc(task_dir) + if need_recalc: + acc = recalc_stats(task_dir) + for key, blk in blocks.items(): + dim = len(blk["sum"]) + merge_stat_block(acc, key, blk, dim) + _atomic_write_json(pooled_stats_path(task_dir), acc_to_stats_json(acc)) + + +def _atomic_write_json(path, obj): + os.makedirs(os.path.dirname(path), exist_ok=True) + tmp = path + ".tmp" + with open(tmp, "w", encoding="utf-8") as f: + json.dump(obj, f, indent=2, ensure_ascii=False) + os.replace(tmp, path) + + +# ── info.json 合成(任务级并集合并,同写入器语义) ────────── + +def build_info(task_dir, task, sessions_meta): + """sessions_meta: [(metadata, sensors, has_imu, calib_dict)] 按 N 升序。""" + path = pooled_info_path(task_dir) + base = load_json(path, {}) + if not isinstance(base, dict): + base = {} + + merged_features = dict(base.get("features") or {}) + merged_cameras = dict(base.get("cameras") or {}) + merged_exts = dict(base.get("video_extensions") or {}) + merged_calib = dict(base.get("calibration") or {}) + sensors_union, has_imu_any = set(), False + + last = None + for meta, sensors, has_imu, calib in sessions_meta: + last = meta + sensors_union |= set(sensors) + has_imu_any = has_imu_any or has_imu + for sn in sorted(sensors): + merged_features[f"observation.{sn}"] = { + "dtype": "float32", "shape": [16, 16]} + if has_imu: + merged_features["observation.imu"] = { + "dtype": "float32", "shape": [6]} + merged_features["action"] = {"dtype": "float32", "shape": [1]} + for cam, info in (meta.get("cameras") or {}).items(): + if not isinstance(info, dict): + continue + if info.get("type") == "depth": + merged_exts[cam] = "mkv" + continue + entry = {"height": int(info.get("height", 0)), + "width": int(info.get("width", 0))} + cam_fps = float(info.get("fps") or meta.get("fps") or 0.0) + if cam_fps and cam_fps != float(meta.get("fps") or 0.0): + entry["fps"] = cam_fps + merged_cameras[cam] = entry + merged_exts.update({cam: "mp4" for cam in merged_cameras}) + merged_calib.update(calib or {}) + + devices, device_names = [], {} + if last: + devices = [{"key": d.get("key", ""), "kind": d.get("kind", ""), + "name": d.get("name", ""), + "slots": list(d.get("slots") or [])} + for d in (last.get("devices") or [])] + for d in (last.get("devices") or []): + if d.get("name"): + for slot in (d.get("slots") or []): + device_names[slot] = d["name"] + + info = dict(base) + info.update({ + "format": "pooled_episodes_v1", + "chunks_size": POOLED_CHUNK_SIZE, + "data_path": "data/chunk-{c:03d}/episode-{f:03d}.parquet", + "video_path": "videos/chunk-{c:03d}/{image_key}/episode-{f:03d}.{ext}", + "episodes_path": "meta/episodes/chunk-{c:03d}/episode-{f:03d}.parquet", + "codebase_version": (last or {}).get("codebase_version", "v3.0"), + "app_version": f"{settings.APP_VERSION}-migrated", + "fps": float((last or {}).get("fps") or 30.0), + "video": len(merged_cameras) > 0, + "task_name": task, + "features": merged_features, + "cameras": merged_cameras, + "devices": devices, + "device_names": device_names, + "sensors": sorted(sensors_union), + "sensor_dim": int((last or {}).get("sensor_dim") + or DEFAULT_SENSOR_DIM), + "created_at": max([float((m or {}).get("created_at") or 0.0) + for m, *_ in sessions_meta] or [time.time()]), + "calibration": merged_calib, + "total_episodes": len(list_task_episodes(task_dir)), + "video_extensions": merged_exts, + }) + return info + + +# ── episodes 分片 append ─────────────────────────────────── + +def _task_lock(task_dir): + lock_path = os.path.join(task_dir, "meta", "episodes", ".lock") + os.makedirs(os.path.dirname(lock_path), exist_ok=True) + fh = open(lock_path, "a+") + if _fcntl is not None: + _fcntl.flock(fh.fileno(), _fcntl.LOCK_EX) + return _LockedFile(fh) + + +def append_episode_row(task_dir, n, row): + """每段一个文件、单行原子写(与 data/videos 同编号);旧分片里 + 的同号行一并删除,避免双份。""" + path = pooled_episodes_path(task_dir, n) + os.makedirs(os.path.dirname(path), exist_ok=True) + with _task_lock(task_dir): + _atomic_write_parquet(_episode_rows_table([row]), path) + cidx, _ = episode_chunk_file(n) + legacy = _legacy_episodes_shard_path(task_dir, cidx) + if legacy != path and os.path.isfile(legacy): + rows = _read_episode_rows(legacy) + kept = [r for r in rows if int(r.get("episode_index", 0)) != n] + if len(kept) != len(rows): + if kept: + _atomic_write_parquet(_episode_rows_table(kept), legacy) + else: + os.remove(legacy) + + +def remove_episode_row(task_dir, n): + """移除 episode N 的 episodes 元数据(每段文件 → os.remove; + 旧分片回退 → 读-改-写删行)。N=1 时分片与每段文件同路径, + 先按内容判每段文件才删,避免误删整个旧分片。""" + path = pooled_episodes_path(task_dir, n) + cidx, _ = episode_chunk_file(n) + legacy = _legacy_episodes_shard_path(task_dir, cidx) + with _task_lock(task_dir): + removed_path = False + if os.path.isfile(path): + rows = _read_episode_rows(path) + if len(rows) <= 1 and (not rows or + int(rows[0].get("episode_index", 0)) == n): + os.remove(path) # 每段文件(或旧分片只剩该行) + removed_path = True + if os.path.isfile(legacy) and not (removed_path and legacy == path): + rows = _read_episode_rows(legacy) + kept = [r for r in rows if int(r.get("episode_index", 0)) != n] + if len(kept) != len(rows): + if kept: + _atomic_write_parquet(_episode_rows_table(kept), legacy) + else: + os.remove(legacy) # 分片空 → 删除文件本身 + + +# ── DB 改写 ──────────────────────────────────────────────── + +def db_rows_for_path(db_path, col, old_path): + """返回 {table: [(id, 现值)]}——只匹配旧会话目录绝对路径。""" + if not os.path.isfile(db_path): + return [], [] + con = sqlite3.connect(db_path) + try: + rec = con.execute( + "SELECT id, file_path FROM recording " + "WHERE file_path=? AND episode_index=0", (old_path,)).fetchall() + up = con.execute( + "SELECT id, session_path FROM upload_task " + "WHERE session_path=?", (old_path,)).fetchall() + except sqlite3.OperationalError: + rec, up = [], [] + finally: + con.close() + return [{"id": r[0], "table": "recording", "old": r[1]} + for r in rec], [{"id": r[0], "table": "upload_task", "old": r[1]} + for r in up] + + +def db_update_episode(db_path, rows, task_dir, n, task): + con = sqlite3.connect(db_path) + try: + for r in rows: + if r["table"] == "recording": + con.execute("UPDATE recording SET file_path=?, " + "episode_index=? WHERE id=?", + (task_dir, n, r["id"])) + else: + con.execute("UPDATE upload_task SET session_path=?, " + "session_name=?, episode_index=? WHERE id=?", + (task_dir, task, n, r["id"])) + con.commit() + finally: + con.close() + + +def db_restore_episode(db_path, rows): + con = sqlite3.connect(db_path) + try: + for r in rows: + if r["table"] == "recording": + con.execute("UPDATE recording SET file_path=?, " + "episode_index=0 WHERE id=?", + (r["old"], r["id"])) + else: + con.execute("UPDATE upload_task SET session_path=?, " + "episode_index=0 WHERE id=?", + (r["old"], r["id"])) + con.commit() + finally: + con.close() + + +# ── 单个会话迁移 ─────────────────────────────────────────── + +def migrate_session(task_dir, task, session_dir, n, backup_root, report, + dry_run, backup, db_path): + warns = [] + meta = load_json(os.path.join(session_dir, "metadata.json"), {}) + if not meta: + return "skip", warns + ts_rows, total_frames = read_ts_rows(session_dir) + if ts_rows is None or not ts_rows: + # 无 timestamps.json:从传感器 parquet 并集重建骨架(wall_time 近似) + import pyarrow.parquet as pq + skeleton = {} + for sub in os.listdir(os.path.join(session_dir, "data")): + idx = read_sensor_parquet(session_dir, sub) + for fi, r in (idx or {}).items(): + skeleton.setdefault(fi, { + "frame_index": fi, + "timestamp": float(r.get("timestamp", 0.0)), + "wall_time": float(meta.get("created_at", time.time())) + + float(r.get("timestamp", 0.0)), + "hardware_ns": int(r.get("hardware_ns", 0) or 0), + }) + ts_rows = [skeleton[k] for k in sorted(skeleton)] + warns.append("无 timestamps.json,骨架由 data parquet 重建" + "(wall_time 近似)") + if not ts_rows: + return "skip", ["无 timestamps.json 且无 data parquet,跳过"] + + vids, depths = find_legacy_media(session_dir, meta) + + # 防撞护栏:任何计划目标已存在 → 整会话跳过,绝不覆盖池化已有文件 + # (部分迁移/并发重跑时 N 可能撞号,文件级检查是最强不变量) + existing = [] + for cam in sorted(vids): + if os.path.exists(pooled_video_path(task_dir, cam, n, ext="mp4")): + existing.append(os.path.relpath( + pooled_video_path(task_dir, cam, n, ext="mp4"), task_dir)) + for slot in sorted(depths): + if os.path.exists(pooled_video_path(task_dir, slot, n, ext="mkv")): + existing.append(os.path.relpath( + pooled_video_path(task_dir, slot, n, ext="mkv"), task_dir)) + if os.path.exists(pooled_data_parquet_path(task_dir, n)): + existing.append(os.path.relpath( + pooled_data_parquet_path(task_dir, n), task_dir)) + # episodes 行撞号(restore 半途失败残留行 → 追加会造重复行; + # list_task_episodes 只扫 data/videos 文件,看不到 episodes 行) + # 每段文件与旧分片两条路径都要查(N=1 时两者同路径,set 去重) + import pyarrow.parquet as pq + cidx, _ = episode_chunk_file(n) + for cand in {pooled_episodes_path(task_dir, n), + _legacy_episodes_shard_path(task_dir, cidx)}: + if os.path.isfile(cand): + try: + if any(r["episode_index"] == n for r in pq.read_table( + cand, columns=["episode_index"]).to_pylist()): + existing.append(f"meta/episodes 行 {n}") + except Exception: + pass + if existing: + return "skip", [f"防撞护栏:池化目标已存在,跳过本会话绝不覆盖:" + f"{existing[:4]}"] + + # ① 完整快照先行(媒体 move 出目录之前),否则 restore 会丢数据 + backup_path = os.path.join(backup_root, task, + os.path.basename(session_dir)) + if not dry_run and backup: + os.makedirs(os.path.dirname(backup_path), exist_ok=True) + try: + shutil.copytree(session_dir, backup_path) + except OSError as e: + return "skip", [f"快照失败({e}),本会话不动"] + if not os.path.isfile(os.path.join(backup_path, "metadata.json")): + shutil.rmtree(backup_path, ignore_errors=True) + return "skip", ["快照缺 metadata.json(校验失败),本会话不动"] + sensors_found = {} + imu_idx = None + data_dir = os.path.join(session_dir, "data") + if os.path.isdir(data_dir): + for sub in sorted(os.listdir(data_dir)): + if sub == "imu": + imu_idx = read_sensor_parquet(session_dir, "imu") + continue + idx = read_sensor_parquet(session_dir, sub) + if idx: + # 全零传感器视为从未出现(旧格式零填充=缺席) + present = False + for r in idx.values(): + v = r.get(f"observation.{sub}") + if v and any(float(x) != 0 for x in v): + present = True + break + if present: + sensors_found[sub] = idx + else: + warns.append(f"传感器 {sub} 全零,视为缺席不写列") + + created = [] + + def plan_create(rel): + return os.path.join(task_dir, rel) + + # 视频 move + for cam, (src, kind) in sorted(vids.items()): + dst = pooled_video_path(task_dir, cam, n, ext="mp4") + created.append(dst) + if not dry_run: + os.makedirs(os.path.dirname(dst), exist_ok=True) + _move_file(src, dst) + for cam, info in (meta.get("cameras") or {}).items(): + if (isinstance(info, dict) + and info.get("type", "rgb") != "depth" + and cam not in vids): + warns.append(f"摄像头 {cam} 无视频文件(旧目录缺 mp4)") + + # 深度 move / 合成 + depth_done = {} + for slot, (src, kind) in sorted(depths.items()): + dst = pooled_video_path(task_dir, slot, n, ext="mkv") + created.append(dst) + if kind == "move": + if not dry_run: + os.makedirs(os.path.dirname(dst), exist_ok=True) + _move_file(src, dst) + depth_done[slot] = "mkv" + else: # png16 / bin + if dry_run: + depth_done[slot] = f"{kind}→mkv" + continue + ok = synthesize_depth_mkv(task_dir, session_dir, slot, meta, + dst, warns.append) + depth_done[slot] = "mkv" if ok else "skipped" + + # data parquet + import pyarrow as pa + table, sensors = build_merged_table(meta, ts_rows, sensors_found, + imu_idx) + table = table.set_column( + 0, "episode_index", + pa.array([n] * table.num_rows, pa.int64())) + data_path = pooled_data_parquet_path(task_dir, n) + created.append(data_path) + if not dry_run: + os.makedirs(os.path.dirname(data_path), exist_ok=True) + _atomic_write_parquet(table, data_path) + + # episodes 行 + calib = {} + cal_dir = os.path.join(session_dir, "calibration") + if os.path.isdir(cal_dir): + for fn in sorted(os.listdir(cal_dir)): + if fn.endswith(".json"): + c = load_json(os.path.join(cal_dir, fn)) + if isinstance(c, dict): + calib[fn[:-5]] = c + video_codec = dict(meta.get("video_codec") or {}) + video_codec.pop("ffmpeg", None) # 机器相关绝对路径不入库 + fps = float(meta.get("fps") or 30.0) + ts_vals = [float(r.get("timestamp", 0.0)) for r in ts_rows] + ep_row = { + "episode_index": n, + "task_index": 0, + "start_frame_index": int(min(r["frame_index"] for r in ts_rows)), + "end_frame_index": int(max(r["frame_index"] for r in ts_rows)), + "length": int(total_frames + or len({int(r["frame_index"]) for r in ts_rows})), + "created_at": float(meta.get("created_at") or time.time()), + # 真实墙钟时长(多槽行共享时间轴,不随行数翻倍) + "duration_sec": float(max(0.0, max(ts_vals) - min(ts_vals)) + + 1.0 / fps), + "drop_stats": json.dumps(meta.get("drop_stats") or {}, + ensure_ascii=False), + "video_codec": json.dumps(video_codec, ensure_ascii=False), + "calibration": json.dumps(calib, ensure_ascii=False), + } + if not dry_run: + append_episode_row(task_dir, n, ep_row) + + # DB 改写(先于目录移动,崩溃后重跑可从 manifest 续) + db_rec, db_up = db_rows_for_path(db_path, "file_path", session_dir) + if not dry_run and (db_rec or db_up): + db_update_episode(db_path, db_rec + db_up, task_dir, n, task) + + # keypoints_output 重键 + kp_moves = [] + kp_base = os.path.join(settings.DATA_DIR, "keypoints_output", task) + kp_old = os.path.join(kp_base, os.path.basename(session_dir)) + kp_new = os.path.join(kp_base, f"episode_{n:06d}") + if os.path.isdir(kp_old): + kp_moves.append((kp_old, kp_new)) + if not dry_run: + os.makedirs(os.path.dirname(kp_new), exist_ok=True) + _move_file(kp_old, kp_new) + + # ② 媒体已 move 入池化(快照在前,--no-backup 时无快照);删除残壳 + # 防重跑重复发现(--no-backup 属显式破坏性模式) + if not dry_run: + shutil.rmtree(session_dir, ignore_errors=True) + + report.add(task, os.path.basename(session_dir), n, + "migrated" if not dry_run else "planned", + f"视频 {len(vids)} 路 / 深度 {list(depth_done.values())} / " + f"数据 {table.num_rows} 行 x {len(sensors)} 传感器", + created, db_rec + db_up, warns) + return { + "session": os.path.basename(session_dir), + "N": n, + "backup_path": backup_path, + "created_files": created, + "db_rows": db_rec + db_up, + "keypoints": [{"from": a, "to": b} for a, b in kp_moves], + "metadata": meta, + "sensors": sensors, + "has_imu": imu_idx is not None + and any((r.get("observation.imu") or []) for r in imu_idx.values()), + "calib": calib, + "warnings": warns, + }, warns + + +def _move_file(src, dst): + try: + os.rename(src, dst) + except OSError: + shutil.move(src, dst) + + +# ── 任务级收尾 ───────────────────────────────────────────── + +def finalize_task(task_dir, task, session_entries, dry_run): + """info.json / tasks.jsonl / stats 合成(实跑时)。""" + metas = [(e["metadata"], e["sensors"], e["has_imu"], e["calib"]) + for e in session_entries if e.get("metadata")] + info = build_info(task_dir, task, metas) + blocks = {} + if not dry_run: + for e in session_entries: + import pyarrow.parquet as pq + p = pooled_data_parquet_path(task_dir, e["N"]) + if os.path.isfile(p): + t = pq.read_table(p) + blocks.update(episode_stat_blocks( + t, e["sensors"], e["has_imu"])) + _atomic_write_json(pooled_info_path(task_dir), info) + if not os.path.isfile(pooled_tasks_jsonl_path(task_dir)): + with open(pooled_tasks_jsonl_path(task_dir), "w", + encoding="utf-8") as f: + json.dump({"task_index": 0, "task": task}, f, + ensure_ascii=False) + f.write("\n") + merge_state_and_write(task_dir, blocks) + return info + + +# ── manifest ─────────────────────────────────────────────── + +def manifest_path(task_dir): + return os.path.join(task_dir, "meta", MANIFEST_NAME) + + +def load_manifest(task_dir): + m = load_json(manifest_path(task_dir), {}) + if not isinstance(m, dict): + m = {} + return m + + +def save_manifest(task_dir, manifest): + _atomic_write_json(manifest_path(task_dir), manifest) + + +# ── 回滚 ─────────────────────────────────────────────────── + +def restore_task(task_dir, task, manifest, dry_run, report): + """按 manifest 回滚一个任务的全部迁移。""" + entries = manifest.get("sessions") or [] + for e in reversed(entries): + n = int(e["N"]) + for f in e.get("created_files") or []: + if os.path.isfile(f): + if not dry_run: + os.remove(f) + remove_episode_row(task_dir, n) if not dry_run else None + if not dry_run and (e.get("db_rows")): + db_restore_episode(DB_PATH, e["db_rows"]) + for kp in e.get("keypoints") or []: + if os.path.isdir(kp["to"]): + if not dry_run: + os.makedirs(os.path.dirname(kp["from"]), + exist_ok=True) + _move_file(kp["to"], kp["from"]) + bp = e.get("backup_path") + if bp and os.path.isdir(bp): + if not dry_run: + os.makedirs(task_dir, exist_ok=True) + _move_file(bp, os.path.join( + task_dir, os.path.basename(bp))) + report.add(task, e.get("session", "?"), n, + "restored" if not dry_run else "planned-restore", + f"backup={bp}", [], [], e.get("warnings") or []) + # 备份根目录若已清空则一并回收 + if not dry_run: + for entry in entries: + bp = entry.get("backup_path") + if bp: + root = os.path.dirname(os.path.dirname(bp)) + if os.path.isdir(root) and not os.listdir(root): + _rmdir_empty(root) + # 任务清空则回收 info/stats/tasks;有剩余 episode 则保留(stats 不回退) + if not dry_run and not list_task_episodes(task_dir): + for p in (pooled_info_path(task_dir), pooled_stats_path(task_dir), + pooled_tasks_jsonl_path(task_dir)): + try: + os.remove(p) + except OSError: + pass + # 池化结构空目录自底向上回收(不动已恢复的旧会话目录) + if not dry_run: + for sub in ("videos", "data"): + for root, dirs, _files in os.walk( + os.path.join(task_dir, sub), topdown=False): + _rmdir_empty(root) + ep_dir = os.path.join(task_dir, "meta", "episodes") + for root, _dirs, _files in os.walk(ep_dir, topdown=False): + # 注意:不能用 walk 的 dirs 判断——那是下探时快照, + # 子目录在自底向上过程中已被删,快照仍非空会挡住清理 + leftovers = [e for e in os.listdir(root) if e != ".lock"] + if not leftovers: + try: + os.remove(os.path.join(root, ".lock")) + except OSError: + pass + _rmdir_empty(root) + _rmdir_empty(os.path.join(task_dir, "meta")) + if not dry_run: + try: + os.remove(manifest_path(task_dir)) + except OSError: + pass + _rmdir_empty(os.path.join(task_dir, "meta")) + + +def _rmdir_empty(path): + try: + os.rmdir(path) + except OSError: + pass + + +# ── 校验 ─────────────────────────────────────────────────── + +def _episode_video_files(task_dir, n): + """episode N 的全部视频文件路径列表(任意 key/扩展名)。""" + _, fidx = episode_chunk_file(n) + out = [] + vroot = os.path.join(task_dir, "videos") + if os.path.isdir(vroot): + for cname in os.listdir(vroot): + cdir = os.path.join(vroot, cname) + if not os.path.isdir(cdir): + continue + for key in os.listdir(cdir): + kd = os.path.join(cdir, key) + if not os.path.isdir(kd): + continue + for fn in os.listdir(kd): + # v1.1.2 起 episode- 前缀;file- 前缀为更早数据(容忍) + if (fn.startswith(f"episode-{fidx:03d}.") + or fn.startswith(f"file-{fidx:03d}.")): + out.append(os.path.join(kd, fn)) + return out + + +def validate_task(task_dir, task): + """读取端自检:episodes 行 ↔ data parquet ↔ 视频文件组 ↔ info.json。""" + print(f"── 校验 {task} ──") + import pyarrow.parquet as pq + ok = True + info = load_json(pooled_info_path(task_dir), {}) + if info.get("format") != "pooled_episodes_v1": + print(" ✗ info.json 缺失或非池化格式") + return False + episodes = [] + dupes = set() + ep_dir = os.path.join(task_dir, "meta", "episodes") + if not os.path.isdir(ep_dir): + print(" ✗ meta/episodes 缺失") + return False + for c in sorted(os.listdir(ep_dir)): + if not c.startswith("chunk-"): + continue + d = os.path.join(ep_dir, c) + for f in sorted(os.listdir(d)): + if not f.endswith(".parquet"): + continue + p = os.path.join(d, f) + rows = pq.read_table(p).to_pylist() + # 每段文件不变量:单行且 episode-{f}(旧数据 file-{f})与 + # episode_index 同编号 + if len(rows) == 1: + n = int(rows[0]["episode_index"]) + fm = re.match(r"^(?:episode|file)-(\d+)\.parquet$", f) + fidx = int(fm.group(1)) if fm else -1 + if fidx != (n - 1) % POOLED_CHUNK_SIZE: + print(f" ✗ {os.path.relpath(p, task_dir)}: " + f"episode-{fidx:03d} 与 episode {n} 编号不符") + ok = False + for r in rows: + n = int(r["episode_index"]) + if any(int(x["episode_index"]) == n for x in episodes): + dupes.add(n) + episodes.append(r) + if dupes: + print(f" ✗ episode 行重复(新旧布局并存): {sorted(dupes)}") + ok = False + print(f" episodes 行: {len(episodes)}") + for r in episodes: + n = int(r["episode_index"]) + data = pooled_data_parquet_path(task_dir, n) + if not os.path.isfile(data): + print(f" ✗ episode {n}: 缺 data parquet") + ok = False + continue + t = pq.read_table(data) + cols = set(t.column_names) + need = {"episode_index", "frame_index", "timestamp", "task_index", + "wall_time", "hardware_ns", "action"} + miss = need - cols + if miss: + print(f" ✗ episode {n}: 缺列 {sorted(miss)}") + ok = False + else: + print(f" ✓ episode {n}: {t.num_rows} 行, 列 " + f"{sorted(c for c in cols if c.startswith('observation') or c.startswith('status'))}") + # 视频:episode 自己的文件组(key 可跨会话改名,不能要求 + # 每个 key 每个 episode 都有文件) + if not _episode_video_files(task_dir, n): + print(f" ✗ episode {n}: 无任何视频文件") + ok = False + # 每个声明的 key 至少在某个 episode 有文件(任务级并集口径) + for key, ext in (info.get("video_extensions") or {}).items(): + if not any(os.path.isfile(pooled_video_path( + task_dir, key, int(r["episode_index"]), ext=ext)) + for r in episodes): + print(f" ✗ 视频 key {key} ({ext}) 全任务无文件") + ok = False + if os.path.isfile(pooled_stats_path(task_dir)): + print(f" ✓ stats.json 存在: {sorted(load_json(pooled_stats_path(task_dir), {}))}") + return ok + + +def split_episodes(task_dir, task, dry_run): + """旧分片(每 chunk 一个多行文件)→ 每段一个文件;幂等。 + + - 多行文件按 episode_index 拆成每段单行文件(每段文件已存在 + 则跳过,不覆盖——每段文件为准)。 + - v1.1.2 起每段文件前缀 episode-,与旧分片名 file-{chunk} 不再 + 重名(v1.1.1 及更早两者同路径,写回源路径特判已无必要但保留)。 + - 拆完删除旧分片;单行文件不动。 + - 拆分过则刷新 info.json episodes_path 模板(旧任务写的是旧模板)。 + """ + ep_dir = os.path.join(task_dir, "meta", "episodes") + if not os.path.isdir(ep_dir): + print(f" {task}: 无 meta/episodes,跳过") + return + changed = False + for c in sorted(os.listdir(ep_dir)): + if not c.startswith("chunk-"): + continue + d = os.path.join(ep_dir, c) + for fn in sorted(os.listdir(d)): + if not fn.endswith(".parquet"): + continue + p = os.path.join(d, fn) + rows = _read_episode_rows(p) + if len(rows) <= 1: + continue # 每段新布局或只剩一行,不动 + dests = {} + for r in rows: + n = int(r.get("episode_index", 0)) + if n: + dests[pooled_episodes_path(task_dir, n)] = r + wrote = 0 + for dst, r in dests.items(): + if dst == p: + continue # 源路径自身最后写 + if os.path.isfile(dst): + continue # 每段文件已存在(幂等,不覆盖) + if dry_run: + wrote += 1 + continue + os.makedirs(os.path.dirname(dst), exist_ok=True) + _atomic_write_parquet(_episode_rows_table([r]), dst) + wrote += 1 + if dry_run: + print(f" [plan] {task}: {os.path.relpath(p, task_dir)} " + f"{len(rows)} 行 → {len(dests)} 个每段文件") + continue + if p in dests: + # chunk-0:N=1 的行写回源路径(分片变成每段文件) + _atomic_write_parquet(_episode_rows_table([dests[p]]), p) + else: + os.remove(p) + changed = True + print(f" {task}: {os.path.relpath(p, task_dir)} {len(rows)} 行 " + f"→ {len(dests)} 个每段文件") + if changed and not dry_run: + info_path = pooled_info_path(task_dir) + info = load_json(info_path, {}) + if isinstance(info, dict): + info["episodes_path"] = ("meta/episodes/chunk-{c:03d}/" + "episode-{f:03d}.parquet") + _atomic_write_json(info_path, info) + if dry_run: + print(f" [plan] {task}: 以上为计划,未落盘") + + +# ── 主流程 ───────────────────────────────────────────────── + +def main(): + ap = argparse.ArgumentParser(description="旧会话 → v1.1.0 任务池化布局") + ap.add_argument("--task", action="append", default=[], + help="只处理指定任务目录名(可多次)") + ap.add_argument("--dry-run", action="store_true", + help="只打印迁移计划,不落盘") + ap.add_argument("--backup", action="store_true", default=True, + help="旧会话目录移入备份区(默认开)") + ap.add_argument("--no-backup", dest="backup", action="store_false", + help="旧会话目录不备份(不推荐)") + ap.add_argument("--force", action="store_true", + help="任务已有 manifest 时仍处理剩余旧会话") + ap.add_argument("--restore", action="store_true", + help="按 manifest 回滚迁移") + ap.add_argument("--validate", action="store_true", + help="读取端自检(迁移后校验报告)") + ap.add_argument("--split-episodes", action="store_true", + help="旧 episodes 分片(每 chunk 多行)拆成每段一文件(幂等)") + ap.add_argument("--recordings-root", default=None, + help="测试用:覆盖录制根目录(默认 data/recordings)") + ap.add_argument("--db-path", default=None, + help="测试用:覆盖 pipeline.db 路径") + args = ap.parse_args() + global RECORDINGS_DIR, DB_PATH + if args.recordings_root: + RECORDINGS_DIR = args.recordings_root + if args.db_path: + DB_PATH = args.db_path + + report = Report() + run_ts = time.strftime("%Y%m%d_%H%M%S") + backup_root = os.path.join(RECORDINGS_DIR, + f"_migrate_backup_{run_ts}") + db_backup_path = os.path.join( + settings.DATA_DIR, f"pipeline.db.migrate_backup_{run_ts}") + db_needs_backup = False + + if args.restore: + for task, task_dir in task_dirs(RECORDINGS_DIR, args.task): + manifest = load_manifest(task_dir) + if manifest.get("sessions"): + restore_task(task_dir, task, manifest, args.dry_run, report) + report.print("restore") + return 0 + + if args.validate: + all_ok = True + for task, task_dir in task_dirs(RECORDINGS_DIR, args.task): + if os.path.isdir(os.path.join(task_dir, "meta", "episodes")): + all_ok = validate_task(task_dir, task) and all_ok + print() + print("PASS: 校验全部通过" if all_ok + else "FAIL: 存在校验失败项") + return 0 if all_ok else 1 + + if args.split_episodes: + for task, task_dir in task_dirs(RECORDINGS_DIR, args.task): + split_episodes(task_dir, task, args.dry_run) + print() + print("PASS: 旧分片拆分完成(幂等,可重复跑)") + return 0 + + for task, task_dir in task_dirs(RECORDINGS_DIR, args.task): + sessions = legacy_sessions(task_dir, task) + if not sessions: + continue + manifest = load_manifest(task_dir) + if manifest.get("sessions") and not args.force: + report.warnings.append( + f"{task}: 已有 manifest(迁移过),--force 才会重扫") + continue + done = {os.path.basename(e["backup_path"]) + for e in (manifest.get("sessions") or []) + if e.get("backup_path")} + todo = [s for s in sessions + if os.path.basename(s) not in done] + if not todo: + continue + + n_next = max(list_task_episodes(task_dir) or [0]) + 1 + entries = manifest.get("sessions") or [] + for session_dir in todo: + db_rec, db_up = db_rows_for_path( + DB_PATH, "file_path", session_dir) + if db_rec or db_up: + db_needs_backup = True + if not args.dry_run and not os.path.isfile(db_backup_path): + shutil.copy2(DB_PATH, db_backup_path) + print(f"pipeline.db 已备份: {db_backup_path}") + entry, warns = migrate_session( + task_dir, task, session_dir, n_next, backup_root, report, + args.dry_run, args.backup, DB_PATH) + if entry == "skip": + report.warnings.extend(warns) + continue + entries.append(entry) + n_next += 1 + finalize_task(task_dir, task, entries, args.dry_run) + manifest = { + "version": MANIFEST_VERSION, + "run_ts": run_ts, + "db_backup": db_backup_path if db_needs_backup else None, + "sessions": entries, + } + if not args.dry_run: + save_manifest(task_dir, manifest) + + report.print("dry-run" if args.dry_run else "migrate") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/collector/scripts/pack_lite.py b/collector/scripts/pack_lite.py new file mode 100644 index 0000000000000000000000000000000000000000..745c20af9b396b264b4aa18d1986149fce137d38 --- /dev/null +++ b/collector/scripts/pack_lite.py @@ -0,0 +1,176 @@ +"""极简采集版发布包收集脚本 —— 把 lite 运行时闭包收集到一个目录。 + +只收集 start_lite.bat 真正需要的最小集合(约 1.5 MB 代码), +不拷贝 venv/venv_lite/data/wheels(--with-wheels 除外)、tools 下的 +demo/其它测试、stouch_glove_toolkit-*/ 等与 lite 无关的内容。 + +代码文件以仓库根为源;start_lite.bat/.sh 与 使用说明_lite.md 是分发壳, +只住在 lite_package/(主目录不放),收集时从那里原样复制。 + +--force 只重建代码部分(main_lite/requirements-lite/config/core/ui/tools), +venv_lite/、wheels/、data/ 与分发壳原样保留 —— lite_package 可同时当 +"发布模板"和"本机测试部署目录"用(在包内跑过 start_lite.sh 装的环境 +不会被冲掉)。 + +收集完成后自动做导入自检:在目标目录内 `import main_lite`, +缺任何被闭包引用的模块都会当场报错(与 start_lite.bat 的错误 E 同口径)。 + +闭包清单与 tools/tests/lite_import_guard_test.py 的 WHITELIST 一致, +外加 egodata_writer/d435_camera 实际 import 的 core.calibration。 + +用法: + python scripts/pack_lite.py 收集到 lite_package/ + python scripts/pack_lite.py --out D:/lite 指定目录 + python scripts/pack_lite.py --with-wheels 连同 wheels/ 离线依赖包一起 + python scripts/pack_lite.py --force 重建代码部分(保留环境) +""" +import argparse +import os +import shutil +import subprocess +import sys + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# 分发壳的常驻目录(start_lite.bat/.sh、使用说明_lite.md 只住在这里) +DIST_SOURCE = os.path.join(ROOT, "lite_package") + +# 代码文件(仓库根为源,收集时拷入包目录) +CODE_FILES = [ + "main_lite.py", + "requirements-lite.txt", +] + +# 分发壳文件(从 DIST_SOURCE 原样复制,主目录不放) +DIST_FILES = [ + "start_lite.bat", + "start_lite.sh", + "使用说明_lite.md", +] + +# 整目录拷贝(core.glove_usb 是包,内部有 __init__.py 与互引模块) +WHOLE_DIRS = [ + "core/glove_usb", +] + +# 单文件拷贝:目录 → 文件列表(只收 lite 闭包,主程序 UI/重依赖模块不带) +MODULE_FILES = { + "ui": ["__init__.py", "lite_window.py"], + "config": ["__init__.py", "settings.py", "i18n.py"], + "core": [ + "__init__.py", + "pipeline.py", "egodata_writer.py", "encoder_probe.py", + "depth_codec.py", "d435_manager.py", "stereo_depth.py", + "d435_camera.py", "camera.py", "device_detector.py", + "ble_engine.py", "usb_glove_engine.py", "uploader.py", + "api_client.py", "database.py", "helpers.py", + # egodata_writer.py:41 / d435_camera.py:447 实际 import + "calibration.py", + ], +} + +# 自检测试(客户机可选跑:无硬件验证导入隔离与采集链) +SELFTEST_FILES = [ + "tools/tests/lite_import_guard_test.py", + "tools/tests/lite_smoke_test.py", +] + + +def collect(out_dir: str, with_wheels: bool, force: bool) -> None: + out_dir = os.path.abspath(out_dir) + if force: + # 只重建代码路径;venv_lite/wheels/data 与分发壳原样保留 + for rel in (CODE_FILES + ["config", "core", "ui", "tools"]): + p = os.path.join(out_dir, rel) + if os.path.isdir(p): + shutil.rmtree(p, ignore_errors=True) + elif os.path.isfile(p): + os.remove(p) + elif os.path.isfile(os.path.join(out_dir, "main_lite.py")): + print(f"[跳过] 目标目录已存在: {out_dir}") + print(" --force 只重建代码部分,venv_lite/wheels/data 会保留") + sys.exit(0) + + copied = [] + for rel in CODE_FILES + SELFTEST_FILES: + src = os.path.join(ROOT, rel) + if not os.path.isfile(src): + print(f"[警告] 缺文件: {rel}") + continue + dst = os.path.join(out_dir, rel) + os.makedirs(os.path.dirname(dst), exist_ok=True) + shutil.copy2(src, dst) + copied.append(rel) + + for rel in DIST_FILES: + src = os.path.join(DIST_SOURCE, rel) + dst = os.path.join(out_dir, rel) + if os.path.abspath(src) == os.path.abspath(dst): + copied.append(rel) # 源即目标(lite_package 自身) + continue + if not os.path.isfile(src): + print(f"[警告] 缺分发文件: {rel}(应在 lite_package/ 下)") + continue + shutil.copy2(src, dst) + copied.append(rel) + + for rel in WHOLE_DIRS: + src = os.path.join(ROOT, rel) + dst = os.path.join(out_dir, rel) + shutil.copytree(src, dst, ignore=shutil.ignore_patterns("__pycache__")) + copied.append(rel + "/") + + for sub, files in MODULE_FILES.items(): + for name in files: + rel = os.path.join(sub, name) + src = os.path.join(ROOT, rel) + if not os.path.isfile(src): + print(f"[警告] 缺文件: {rel}") + continue + dst = os.path.join(out_dir, rel) + os.makedirs(os.path.dirname(dst), exist_ok=True) + shutil.copy2(src, dst) + copied.append(rel) + + if with_wheels: + src = os.path.join(ROOT, "wheels") + if os.path.isdir(src): + shutil.copytree(src, os.path.join(out_dir, "wheels")) + copied.append("wheels/") + else: + print("[提示] --with-wheels 但仓库没有 wheels/ 目录,跳过") + + # 自检:在目标目录内 import main_lite(与 start_lite.bat 错误 E 同口径) + env = dict(os.environ, PYTHONPATH=out_dir, + QT_QPA_PLATFORM=os.environ.get("QT_QPA_PLATFORM", "offscreen")) + proc = subprocess.run( + [sys.executable, "-c", "import main_lite"], + cwd=out_dir, env=env, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if proc.returncode != 0: + print("[失败] 目标目录内 import main_lite 自检未通过:") + print(proc.stderr.decode("utf-8", "replace")) + sys.exit(1) + + total = sum(os.path.getsize(os.path.join(out_dir, r)) + for r in copied if os.path.isfile(os.path.join(out_dir, r))) + print(f"[完成] 收集 {len(copied)} 个文件到 {out_dir}/," + f"代码共 {total / 1024:.0f} KB,import main_lite 自检通过") + print(" 客户机落盘 = 本目录 + venv_lite(自动安装, ~750MB)" + + (" + wheels/" if with_wheels else "")) + + +def main() -> None: + parser = argparse.ArgumentParser(description="收集极简采集版发布包") + parser.add_argument("--out", default=os.path.join(ROOT, "lite_package"), + help="输出目录(默认仓库根 lite_package/)") + parser.add_argument("--with-wheels", action="store_true", + help="连同 wheels/ 离线依赖包一起收集") + parser.add_argument("--force", action="store_true", + help="重建代码部分(保留 venv_lite/wheels/data)") + args = parser.parse_args() + collect(os.path.abspath(args.out), args.with_wheels, args.force) + + +if __name__ == "__main__": + main() diff --git a/collector/scripts/pack_wheels.py b/collector/scripts/pack_wheels.py new file mode 100644 index 0000000000000000000000000000000000000000..12b6dff74a1c56d5e995939345825397cecab5db --- /dev/null +++ b/collector/scripts/pack_wheels.py @@ -0,0 +1,217 @@ +#!/usr/bin/env python3 +"""生成 Windows 离线部署包(wheels/ 目录),供 start.bat 在无外网环境一键安装。 + +在任意**有网**的机器上运行(Linux 开发机即可,跨平台拉取 Windows 轮子), +把产出的 wheels/ 整个目录拷到客户项目根目录: +start.bat / start.sh 检测到 wheels\\*.whl 后自动改走纯离线安装。 + +跨平台解析用 uv(uv pip compile --python-platform windows,能正确按目标平台 +评估环境标记,剔除 Linux-only 依赖如 bleak 的 dbus-fast);无 uv 时回退纯 +pip download(此时建议直接在一台 Windows 机器上运行本脚本)。 + +用法: + python scripts/pack_wheels.py # 仅主程序必需依赖 + python scripts/pack_wheels.py --lite # 仅极简采集版依赖(requirements-lite.txt) + python scripts/pack_wheels.py --extras # + mediapipe / pyrealsense2 + python scripts/pack_wheels.py --torch # + CPU 版 torch(较大) + python scripts/pack_wheels.py --out /tmp/wheels # 自定义输出目录 + +产物: + /*.whl Windows 3.12 依赖轮子(含依赖闭包) + /python-3.12.10-amd64.exe Python 安装包(客户机器无 Python 时用) +""" + +from __future__ import annotations + +import argparse +import shutil +import subprocess +import sys +import urllib.request +from pathlib import Path + +PY_VERSION = "3.12" +PY_INSTALLER = "python-3.12.10-amd64.exe" +PY_INSTALLER_URLS = [ + f"https://mirrors.aliyun.com/python-release/windows/{PY_INSTALLER}", + f"https://registry.npmmirror.com/-/binary/python/3.12.10/{PY_INSTALLER}", + f"https://mirrors.huaweicloud.com/python/3.12.10/{PY_INSTALLER}", +] +ALIYUN = "https://mirrors.aliyun.com/pypi/simple/" +TUNA = "https://pypi.tuna.tsinghua.edu.cn/simple" +PYPI = "https://pypi.org/simple" +MIRRORS = [ALIYUN, TUNA, PYPI] +EXTRAS = ["mediapipe", "pyrealsense2"] +TORCH_INDEXES = [ + ("https://mirrors.aliyun.com/pytorch-wheels/cpu/", ALIYUN), + ("https://download.pytorch.org/whl/cpu", PYPI), +] +UV = shutil.which("uv") + + +def parse_requirements(path: Path) -> list[str]: + """requirements.txt → 包规格列表(去注释、去空行)。""" + specs = [] + for line in path.read_text(encoding="utf-8").splitlines(): + line = line.split("#", 1)[0].strip() + if line: + specs.append(line) + return specs + + +def _run(cmd: list[str]) -> None: + subprocess.run(cmd, check=True) + + +def _pip_download(lock: Path, out: Path, mirror: str) -> None: + """按锁定文件抓取 Windows 轮子(--no-deps:锁定已含全部闭包,无需再解析)。""" + _run([sys.executable, "-m", "pip", "download", "--no-deps", + "-r", str(lock), "-d", str(out), + "--platform", "win_amd64", "--python-version", PY_VERSION, + "--only-binary=:all:", "-i", mirror]) + + +def download_closure(specs: list[str], out: Path, + index: str | None = None, + extra_index: str | None = None, + lock_name: str = "requirements-win.txt") -> Path: + """uv compile(目标 Windows)→ pip download 抓轮子。无 uv 时直接 pip download。""" + lock = out / lock_name + if UV is None: + # 回退:在 Windows 机器上运行时 pip 会按本机平台评估标记,结果正确 + req = out / ".pack_wheels_req.tmp" + req.write_text("\n".join(specs), encoding="utf-8") + _run([sys.executable, "-m", "pip", "download", "-d", str(out), + "-r", str(req), "--platform", "win_amd64", + "--python-version", PY_VERSION, "--only-binary=:all:", + "-i", index or MIRRORS[0]]) + req.unlink() + return lock + + cmd = [UV, "pip", "compile", "--python-platform", "windows", + "--python-version", PY_VERSION, "--output-file", str(lock)] + if index: + cmd += ["--index-url", index] + if extra_index: + cmd += ["--extra-index-url", extra_index] + req = out / ".pack_wheels_req.tmp" + req.write_text("\n".join(specs), encoding="utf-8") + cmd.append(str(req)) + _run(cmd) + req.unlink() + # 按锁抓轮子(锁内索引头由 pip 原样生效;传同一镜像兜底非锁内包的查找) + _pip_download(lock, out, index or MIRRORS[0]) + return lock + + +def download_python_installer(out: Path) -> None: + target = out / PY_INSTALLER + if target.exists() and target.stat().st_size > 10_000_000: + print(f" 已存在: {target.name},跳过下载") + return + last_err: Exception | None = None + for url in PY_INSTALLER_URLS: + try: + print(f" 下载 Python 安装包: {url}") + with urllib.request.urlopen(url, timeout=120) as r: + target.write_bytes(r.read()) + print(f" 完成: {target.name} ({target.stat().st_size / 1e6:.1f} MB)") + return + except Exception as e: # noqa: BLE001 — 逐源回退 + last_err = e + raise RuntimeError(f"Python 安装包下载失败: {last_err}") + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--lite", action="store_true", + help="仅打包极简采集版依赖(requirements-lite.txt)") + parser.add_argument("--extras", action="store_true", + help="额外打包 mediapipe / pyrealsense2") + parser.add_argument("--torch", action="store_true", + help="额外打包 CPU 版 torch(体积较大)") + parser.add_argument("--out", type=Path, + default=Path(__file__).resolve().parent.parent / "wheels", + help="输出目录(默认仓库根目录 wheels/)") + parser.add_argument("--no-python-installer", action="store_true", + help="跳过 Python 安装包下载") + args = parser.parse_args() + + if args.lite and (args.extras or args.torch): + parser.error("--lite 与 --extras/--torch 互斥(极简版不装可选功能)") + + out = args.out + out.mkdir(parents=True, exist_ok=True) + + repo_root = Path(__file__).resolve().parent.parent + req_file = "requirements-lite.txt" if args.lite else "requirements.txt" + specs = parse_requirements(repo_root / req_file) + if not specs: + print(f"[错误] {req_file} 为空或不存在", file=sys.stderr) + return 1 + if args.extras: + specs = specs + EXTRAS + + print(f"[1/3] 解析 {len(specs)} 个包的 Windows {PY_VERSION} 依赖闭包 -> {out}/ ...") + if UV is None: + print(" [提示] 未检测到 uv,回退纯 pip 解析(建议在一台 Windows 机器上运行," + "或 pip install uv 后重试)") + + last_err: Exception | None = None + for mirror in MIRRORS: + try: + download_closure(specs, out, index=mirror) + break + except subprocess.CalledProcessError as e: + last_err = e + print(f" 源 {mirror} 失败,尝试下一个 ...") + else: + print(f"[错误] 依赖下载失败: {last_err}", file=sys.stderr) + if UV is None: + print(" 提示: 本机无 uv,且 pip 跨平台解析可能因 Linux-only 依赖失败;" + "请 pip install uv 后重试,或直接在一台 Windows 机器上运行本脚本。", + file=sys.stderr) + return 1 + + if args.torch: + print("[2/3] 解析 CPU 版 torch(Windows)...") + torch_done = False + for index, extra in TORCH_INDEXES: + try: + download_closure(["torch"], out, index=index, extra_index=extra, + lock_name="torch-win.txt") + torch_done = True + break + except subprocess.CalledProcessError as e: + last_err = e + print(f" 源 {index} 失败,尝试下一个 ...") + if not torch_done: + print(f"[错误] torch 下载失败: {last_err}", file=sys.stderr) + return 1 + print("[2/3] torch 完成") + else: + print("[2/3] 跳过 torch(--torch 可打包 CPU 版)") + + if not args.no_python_installer: + print("[3/3] 拉取 Python 安装包(客户机器无 Python 时 start.bat 会用)...") + try: + download_python_installer(out) + except RuntimeError as e: + print(f"[警告] {e};不影响 wheels 使用,手动放入同名文件即可", + file=sys.stderr) + else: + print("[3/3] 跳过 Python 安装包(--no-python-installer)") + + whls = sorted(out.glob("*.whl")) + total = sum(w.stat().st_size for w in whls) / 1e6 + print() + print("=" * 60) + print(f"打包完成: {len(whls)} 个 wheel,共 {total:.0f} MB -> {out}/") + print("交付方式: 把整个 wheels/ 目录拷到客户项目根目录,") + print(" start.bat / start.sh 会自动改走纯离线安装。") + print("=" * 60) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/collector/scripts/process_hands.py b/collector/scripts/process_hands.py new file mode 100644 index 0000000000000000000000000000000000000000..5105d294a61d9359586ad1b8d1311c26456ef05d --- /dev/null +++ b/collector/scripts/process_hands.py @@ -0,0 +1,284 @@ +#!/usr/bin/env python3 +""" +手部关键点提取 CLI —— 对已录制会话离线处理。 + +用法: + python scripts/process_hands.py kpts /path/to/session --mode bare + python scripts/process_hands.py label /path/to/session + python scripts/process_hands.py all /path/to/session --mode bare +""" + +import argparse +import os +import sys +import subprocess +import shutil + +import numpy as np +import cv2 + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from core.hand_tracking import process_session, label_session, load_hand_kpts, draw_kpts_overlay + + +def _progress_bar(cur: int, total: int, width: int = 40): + ratio = min(cur / max(total, 1), 1.0) + filled = int(width * ratio) + bar = "█" * filled + "░" * (width - filled) + sys.stderr.write(f"\r [{bar}] {cur}/{total} ({ratio*100:.0f}%)") + sys.stderr.flush() + + +def cmd_kpts(args): + """提取手部关键点(2D + 可选 3D)。""" + print(f"提取手部关键点: {args.session}") + print(f" 模式: {args.mode}, 设备: {args.device}") + + sys.stderr.write("\n") + result = process_session( + session_path=args.session, + mode=args.mode, + det_device=args.device, + pose_device=args.device, + progress_cb=_progress_bar, + status_cb=lambda msg: print(f" [{msg}]"), + ) + + sys.stderr.write("\n") + if result["success"]: + print(f"✅ 完成: {result['frames']} 帧, " + f"{result['elapsed']:.1f}s, {result['fps']:.1f} fps") + else: + print(f"❌ 失败: {result['error']}") + sys.exit(1) + + +def cmd_label(args): + """手势自动标注。""" + print(f"手势标注: {args.session}") + + result = label_session( + session_path=args.session, + progress_cb=_progress_bar, + ) + + sys.stderr.write("\n") + if result["success"]: + print(f"✅ 完成: {result['frames']} 帧, {result['elapsed']:.1f}s") + else: + print(f"❌ 失败: {result['error']}") + sys.exit(1) + + +def cmd_all(args): + """先提取关键点,再标注。""" + cmd_kpts(args) + print() + cmd_label(args) + + +def cmd_show(args): + """显示已有关键点信息。""" + kpts = load_hand_kpts(args.session) + if kpts: + n = len(kpts) + sample = kpts[min(kpts.keys())] + print(f"手部关键点数据: {n} 帧") + print(f" 维度: {len(sample['hand_data'])}") + print(f" 最多手数: {sample['num_hands']}") + else: + print("❌ 未找到手部关键点数据") + sys.exit(1) + + +def _find_video(session_path: str) -> str: + """在 session 目录下找第一个可用的 RGB 视频文件。""" + from core.helpers import detect_session_format, egodata_video_path, egodata_metadata_path + import json + + vdir = os.path.join(session_path, "videos") + if not os.path.isdir(vdir): + return "" + + fmt = detect_session_format(session_path) + # 先尝试从 metadata 获取相机列表 + if fmt == "egodata": + meta_path = egodata_metadata_path(session_path) + if os.path.isfile(meta_path): + with open(meta_path) as f: + cameras = json.load(f).get("cameras", {}) + for cam_name in cameras: + if cameras[cam_name].get("type") == "depth": + continue + for vp in [egodata_video_path(session_path, cam_name), + os.path.join(vdir, f"{cam_name}.mp4")]: + if os.path.isfile(vp): + return vp + + # 直接扫描 videos/ 目录 + for entry in sorted(os.listdir(vdir)): + if "depth" in entry.lower(): + continue + full = os.path.join(vdir, entry) + if os.path.isfile(full) and entry.endswith(".mp4"): + return full + # 子目录结构 + sub_dir = os.path.join(full, "chunk-0000") + if os.path.isdir(sub_dir): + for fname in os.listdir(sub_dir): + if fname.endswith(".mp4"): + return os.path.join(sub_dir, fname) + return "" + + +def cmd_render(args): + """将手部关键点叠加到视频上,导出可视化视频。""" + import time + from core.helpers import keypoints_video_dir + + session_path = args.session + kpts = load_hand_kpts(session_path) + if not kpts: + print("❌ 未找到手部关键点数据,请先运行 kpts 命令") + sys.exit(1) + + video_path = _find_video(session_path) + if not video_path: + print("❌ 未找到可播放的视频文件") + sys.exit(1) + + cam_name = os.path.splitext(os.path.basename(video_path))[0] + out_dir = keypoints_video_dir(session_path) + os.makedirs(out_dir, exist_ok=True) + out_path = os.path.join(out_dir, f"{cam_name}_hand_kpts.mp4") + + cap = cv2.VideoCapture(video_path) + total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) + fps = cap.get(cv2.CAP_PROP_FPS) + if fps <= 0: + fps = 30.0 + ret, first = cap.read() + if not ret: + print("❌ 无法读取视频帧") + sys.exit(1) + h, w = first.shape[:2] + cap.set(cv2.CAP_PROP_POS_FRAMES, 0) + + # ffmpeg 优先,cv2 回退 + writer = None + ffmpeg_proc = None + if shutil.which("ffmpeg"): + ffmpeg_cmd = [ + "ffmpeg", "-y", "-f", "rawvideo", "-vcodec", "rawvideo", + "-s", f"{w}x{h}", "-pix_fmt", "bgr24", "-r", str(fps), + "-i", "-", "-c:v", "libx264", "-preset", "fast", "-crf", "23", + "-pix_fmt", "yuv420p", out_path, + ] + try: + ffmpeg_proc = subprocess.Popen( + ffmpeg_cmd, stdin=subprocess.PIPE, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + except Exception: + ffmpeg_proc = None + + if not ffmpeg_proc: + for codec in ["avc1", "mp4v"]: + fourcc = cv2.VideoWriter_fourcc(*codec) + writer = cv2.VideoWriter(out_path, fourcc, fps, (w, h)) + if writer.isOpened(): + break + + print(f"输入视频: {video_path} ({total} 帧, {fps} fps)") + print(f"手部关键点: {len(kpts)} 帧") + print(f"输出: {out_path}") + t0 = time.perf_counter() + fi = 0 + + while True: + ret, frame = cap.read() + if not ret: + break + kpt = kpts.get(fi) + if kpt is not None and np.any(kpt["hand_data"] > 0): + frame = draw_kpts_overlay(frame, kpt["hand_data"], kpt["track_ids"]) + if ffmpeg_proc: + try: + ffmpeg_proc.stdin.write(frame.tobytes()) + except BrokenPipeError: + break + else: + writer.write(frame) + fi += 1 + if fi % 50 == 0: + _progress_bar(fi, total) + + cap.release() + if ffmpeg_proc: + ffmpeg_proc.stdin.close() + ffmpeg_proc.wait() + else: + writer.release() + + elapsed = time.perf_counter() - t0 + _progress_bar(total, total) + sys.stderr.write("\n") + size_mb = os.path.getsize(out_path) / (1024 * 1024) + print(f"✅ 完成: {out_path}") + print(f" {fi} 帧, {elapsed:.1f}s ({fi / elapsed:.1f} fps), {size_mb:.1f} MB") + + +def main(): + parser = argparse.ArgumentParser( + description="手部关键点提取与标注", + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=""" +示例: + python scripts/process_hands.py kpts data/recordings/Test005/episode_000001 --mode bare + python scripts/process_hands.py render data/recordings/Test005/episode_000001 + python scripts/process_hands.py all data/recordings/Test005/episode_000001 --mode bare + python scripts/process_hands.py show data/recordings/Test005/episode_000001 + """, + ) + sub = parser.add_subparsers(dest="command", help="子命令") + + p_kpts = sub.add_parser("kpts", help="提取手部关键点") + p_kpts.add_argument("session", help="会话目录路径") + p_kpts.add_argument("--mode", default="glove", + choices=["glove", "bare"], help="追踪模式") + p_kpts.add_argument("--device", default="cuda", help="推理设备") + + p_label = sub.add_parser("label", help="手势自动标注") + p_label.add_argument("session", help="会话目录路径") + + p_all = sub.add_parser("all", help="提取 + 标注") + p_all.add_argument("session", help="会话目录路径") + p_all.add_argument("--mode", default="glove", + choices=["glove", "bare"], help="追踪模式") + p_all.add_argument("--device", default="cuda", help="推理设备") + + p_show = sub.add_parser("show", help="查看已有数据") + p_show.add_argument("session", help="会话目录路径") + + p_render = sub.add_parser("render", help="导出关键点可视化视频") + p_render.add_argument("session", help="会话目录路径") + + args = parser.parse_args() + + if args.command == "kpts": + cmd_kpts(args) + elif args.command == "label": + cmd_label(args) + elif args.command == "all": + cmd_all(args) + elif args.command == "show": + cmd_show(args) + elif args.command == "render": + cmd_render(args) + else: + parser.print_help() + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/collector/start.bat b/collector/start.bat new file mode 100644 index 0000000000000000000000000000000000000000..62dae0489f8ea1f7e43ff6baa4641ad2300fdeb5 --- /dev/null +++ b/collector/start.bat @@ -0,0 +1,363 @@ +@echo off +rem ============================================================ +rem !!! ±àÂ뾯¸æ: ±¾Îļþ±ØÐ뱣³Ö GBK(ANSI) ±àÂë + CRLF ÐÐβ !!! +rem ÎðÓüÇʱ¾ / VSCode Áí´棨ĬÈϴæ³É UTF-8 »áÈà cmd ÂÒÂ벢 +rem ¾²Ĭʧ°ܣ©£»ÂÒÂëºóÇë´Ó GitLab ÖØÐÂÏÂÔØԭÎļþ¡£ +rem ============================================================ +rem ============================================================ +rem DAQ Êý¾ݲɼ¯ϵͳ ¡ª¡ª Windows һ¼ü²¿Êð½ű¾ +rem +rem Ó÷¨: +rem start.bat ²¿Êð(°´Ðè) + Æô¶¯Ö÷³ÌÐò +rem start.bat reinstall ɾ³ý venv ǿÖÆÖØװ£¨³öÎÊÌâÊ×ѡ£© +rem start.bat extras ׷¼Ӱ²װ mediapipe / pyrealsense2 +rem start.bat extras-torch ׷¼Ӱ²װ CPU °æ torch +rem start.bat help ´ò¿ª ʹÓÃ˵Ã÷.md +rem +rem ÒÀÀµ°²װ˳Ðò: ÀëÏß wheels\ °ü ¡ú °¢ÀïÔƾµÏñ ¡ú Ç廪¾µÏñ ¡ú ¹ٷ½Դ +rem ´íÎóÂë A-G ¶ÔӦ ʹÓÃ˵Ã÷.md¡¸³£¼ûÒ쳣Óë½â¾ö·½°¸¡¹Õ½Ú +rem ============================================================ +setlocal enabledelayedexpansion +cd /d "%~dp0" + +set "MODE=run" +set "FORCE=0" +set "MAIN_ARGS=" +if /i "%~1"=="reinstall" goto :sub_reinstall +if /i "%~1"=="extras" goto :sub_extras +if /i "%~1"=="extras-torch" goto :sub_extras_torch +if /i "%~1"=="help" goto :show_help +if /i "%~1"=="guide" goto :show_help +set "MAIN_ARGS=%*" +goto :banner + +:sub_reinstall +set "FORCE=1" +goto :banner +:sub_extras +set "MODE=extras" +goto :banner +:sub_extras_torch +set "MODE=extras-torch" +goto :banner + +:banner +echo. +echo ============================================================ +echo DAQ Êý¾ݲɼ¯ϵͳ ¡ª¡ª һ¼ü²¿Êð +echo ============================================================ +echo. + +rem ©¤©¤ ´íÎó G: ½âѹ²ã´Î×Լì ©¤©¤ +if not exist "main.py" goto :errG +if not exist "requirements.txt" goto :errG + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem [1/6] ¶¨λ Python£¨°汾Ðè >= 3.10£¬ÍƼö 3.12£© +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +set "PY=" +set "VPY=venv\Scripts\python.exe" +if not exist "%VPY%" goto :find_py +set "PY=%VPY%" +goto :have_python + +:find_py +echo [1/6] ¼ì²é Python »·¾³ ... +call :try_py py -3.12 +if defined PY goto :have_python +call :try_py py -3 +if defined PY goto :have_python +call :try_py python +if defined PY goto :have_python + +rem ©¤©¤ δ¼ì²⵽ ¡ú ×Զ¯ÏÂÔز¢¾²Ĭ°²װ Python 3.12 ©¤©¤ +echo [1/6] δ¼ì²⵽ Python£¬×Զ¯ÏÂÔذ²װ Python 3.12£¨Լ 25MB£©... +set "PY_VER=3.12.10" +set "PY_EXE=%TEMP%\python-%PY_VER%-amd64.exe" +set "PY_URL=https://mirrors.aliyun.com/python-release/windows/python-%PY_VER%-amd64.exe" +set "PY_URL2=https://registry.npmmirror.com/-/binary/python/%PY_VER%/python-%PY_VER%-amd64.exe" +set "PY_URL3=https://mirrors.huaweicloud.com/python/%PY_VER%/python-%PY_VER%-amd64.exe" +if exist "wheels\python-%PY_VER%-amd64.exe" goto :py_copy_local +curl -L -o "%PY_EXE%" "%PY_URL%" --connect-timeout 20 --retry 2 --silent --show-error +if exist "%PY_EXE%" goto :py_run_installer +curl -L -o "%PY_EXE%" "%PY_URL2%" --connect-timeout 20 --retry 2 --silent --show-error +if exist "%PY_EXE%" goto :py_run_installer +curl -L -o "%PY_EXE%" "%PY_URL3%" --connect-timeout 20 --retry 2 --silent --show-error +if exist "%PY_EXE%" goto :py_run_installer +goto :errA +:py_copy_local +echo [1/6] ʹÓà wheels\ Ŀ¼ÄڵÄ Python °²װ°ü ... +copy /y "wheels\python-%PY_VER%-amd64.exe" "%PY_EXE%" >nul +:py_run_installer +echo [1/6] ¾²Ĭ°²װ Python ÖУ¨ÇëÎð¹رմ°¿ڣ¬Լ 1 ·ÖÖӣ©... +"%PY_EXE%" /quiet InstallAllUsers=0 PrependPath=1 Include_pip=1 Include_test=0 Include_launcher=1 +del "%PY_EXE%" >nul 2>&1 +call :try_py py -3.12 +if defined PY goto :have_python +goto :errA + +:have_python +echo [1/6] ʹÓà Python: %PY% + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem [2/6] ÐéÄ⻷¾³ venv +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +if not exist "%VPY%" goto :make_venv +if not "%FORCE%"=="1" goto :deps_check +echo [2/6] reinstall: ɾ³ý¾É venv ... +rmdir /s /q "venv" 2>nul +if exist "%VPY%" goto :errC2 +:make_venv +echo [2/6] ´´½¨ÐéÄ⻷¾³ venv£¨Ê״ÎԼ 1 ·ÖÖӣ©... +rem עÒâ: PY ÊÇÃüÁpy -3.12 / python£©£¬²»ÄܼÓÒýºÅ +%PY% -m venv "venv" +if not exist "%VPY%" goto :errC + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem [3/6] °²װÒÀÀµ£¨requirements.txt Óб仯»òÊ״ÎÔËÐÐʱ£© +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +:deps_check +rem Óà requirements.txt µÄ Ð޸Äʱ¼ä|´óС ×öǩÃû£¨ÄÚÈݱäÁ˲ÅÖØװ£© +for %%I in (requirements.txt) do set "SIG=%%~tI;%%~zI" +if "%FORCE%"=="1" goto :install_deps +if not exist "venv\.deps-ok" goto :install_deps +set /p STAMP=<"venv\.deps-ok" +if "%STAMP%"=="%SIG%" goto :after_deps + +:install_deps +echo [3/6] °²װÒÀÀµ£¨Ê״ÎԼ 3-10 ·ÖÖӣ¬֮ºóÆô¶¯Ã뿪£©... +"%VPY%" -m pip install --upgrade pip >nul 2>&1 +call :pip_install_req +if errorlevel 1 goto :errD +> "venv\.deps-ok" echo %SIG% + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem [4/6] ÒÀÀµðÑÌ×Լ죨µ¼ÈëÍêÕûÖ÷³ÌÐòÁ´£© +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +:after_deps +echo [4/6] ÒÀÀµ×Լì ... +"%VPY%" -c "import main" >nul 2>&1 +if errorlevel 1 goto :errE +echo [4/6] ÒÀÀµ×Լìͨ¹ý + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem [5/6] ¿Éѡ¹¦Äܣ¨extras / extras-torch ×ÓÃüÁ +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +if "%MODE%"=="extras" goto :install_extras +if "%MODE%"=="extras-torch" goto :install_torch +goto :launch + +:install_extras +if exist "venv\.extras-ok" goto :extras_done +echo [5/6] °²װ¿Éѡ¹¦ÄÜ: mediapipe(ÂãÊÖ3D¹ؼüµã) + pyrealsense2(D435/D405) ... +call :pip_pkg "mediapipe" +if errorlevel 1 echo [¾¯¸æ] mediapipe °²װʧ°ܣ¨Ö÷³ÌÐò²»ÊÜӰÏ죬Ïê¼ûʹÓÃ˵Ã÷.md£© +call :pip_pkg "pyrealsense2" +if errorlevel 1 echo [¾¯¸æ] pyrealsense2 °²װʧ°ܣ¨Ö÷³ÌÐò²»ÊÜӰÏ죬Ïê¼ûʹÓÃ˵Ã÷.md£© +> "venv\.extras-ok" echo done +:extras_done +echo [5/6] ¿Éѡ¹¦Äܰ²װÍê³ɡ£˫»÷ start.bat Æô¶¯Ö÷³ÌÐò¡£ +pause +exit /b 0 + +:install_torch +if exist "venv\.torch-ok" goto :torch_done +echo [5/6] °²װ¿Éѡ¹¦ÄÜ: torch CPU °棨Êֲ¿¹ؼüµã RTMPose Óã©... +call :pip_torch +if errorlevel 1 echo [¾¯¸æ] torch °²װʧ°ܣ¨Ö÷³ÌÐò²»ÊÜӰÏ죬GPU °氲װ¼ûʹÓÃ˵Ã÷.md£© +> "venv\.torch-ok" echo done +:torch_done +echo [5/6] ¿Éѡ¹¦Äܰ²װÍê³ɡ£˫»÷ start.bat Æô¶¯Ö÷³ÌÐò¡£ +pause +exit /b 0 + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem [6/6] Æô¶¯Ö÷³ÌÐò +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +:launch +echo [6/6] Æô¶¯Ö÷³ÌÐò ... +echo. +echo ¡¾²Ù×÷ָÒý¡¿ +echo ¡¤ É豸Ãæ°å: Ïà»ú²åÈëºóԼ 2 Ãë×Զ¯³öÏ֣¬µã»÷¼´¿ÉԤÀÀ +echo ¡¤ Íø¸񲼾Ö: Í϶¯·ָîÌõµ÷Õû»­Ãæ´óСÓëλÖà +echo ¡¤ ¼ÖÆ: ÿ·Ïà»ú¶ÀÁ¢µÄ ¿ªʼ/ֹͣ °´ť£»Õý³£ֹͣ=±£´棬Ò쳣ֹͣ=¶ªÆú +echo ¡¤ ÈÎÎñ: ѡÔñÈÎÎñºó¿ªʼ¼Öƣ»×ó²à¿ɲ鿴¼ÖÆÀúʷÓë»طÅ +echo ¡¤ Éϴ«: ¼ÖÆÍê³ɺó¿ÉÉϴ«·þÎñÆ÷£¨ÅäÖüû data\server_config.example.json£© +echo ¡¤ ÓïÑÔ: ÉèÖÃҳ¿ÉÇл»ÖÐӢÎĽçÃæ +echo ¡¤ ÍêÕû˵Ã÷: ˫»÷ start.bat help »ò²鿴 ʹÓÃ˵Ã÷.md +echo. +set "QT_QPA_PLATFORM_PLUGIN_PATH=%~dp0venv\Lib\site-packages\PyQt5\Qt5\plugins\platforms" +rem ±ê¼DZ¾´ÎΪ start.bat Æô¶¯ ¡ú Ö÷³ÌÐ򵯳öʹÓò½Ö贰¿ڣ¨¿ɹ´ѡ²»ÔÙÏÔʾ£© +set "DAQ_SHOW_GUIDE=1" +"%VPY%" main.py %MAIN_ARGS% +set "EXITCODE=%errorlevel%" +if "%EXITCODE%"=="0" exit /b 0 +goto :errF + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem ×ӳÌÐò: УÑ鲢¼Ç¼¿ÉÓà Python ½âÊÍÆ÷ +rem ²ÎÊý: ½âÊÍÆ÷ÃüÁÈç "py -3.12" / "python"£© +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +:try_py +%* -c "import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)" >nul 2>&1 +if errorlevel 1 exit /b 1 +set "PY=%*" +exit /b 0 + +rem ©¤©¤ wheels\ Ŀ¼ÄÚÊǷñÓÐ .whl Îļþ ©¤©¤ +:wheels_exists +dir /b "wheels\*.whl" >nul 2>&1 +exit /b %errorlevel% + +rem ©¤©¤ °²װ requirements.txt£¨ÀëÏßÓÅÏÈ ¡ú °¢ÀïÔÆ ¡ú Ç廪 ¡ú ¹ٷ½£©©¤©¤ +:pip_install_req +call :wheels_exists +if errorlevel 1 goto :req_online +echo [3/6] ¼ì²⵽ wheels\ ÀëÏ߰ü£¬ÓÅÏÈÀëÏ߰²װ ... +"%VPY%" -m pip install --no-index --find-links "wheels" -r requirements.txt +if not errorlevel 1 exit /b 0 +echo [3/6] ÀëÏ߰ü°²װʧ°ܣ¬תÔÚÏ߰²װ ... +:req_online +"%VPY%" -m pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ +if not errorlevel 1 exit /b 0 +"%VPY%" -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple +if not errorlevel 1 exit /b 0 +"%VPY%" -m pip install -r requirements.txt +exit /b %errorlevel% + +rem ©¤©¤ °²װµ¥¸ö°ü£¨ÀëÏßÓÅÏÈ ¡ú °¢ÀïÔÆ ¡ú Ç廪 ¡ú ¹ٷ½£©©¤©¤ +:pip_pkg +call :wheels_exists +if errorlevel 1 goto :pkg_online +"%VPY%" -m pip install --no-index --find-links "wheels" "%~1" +if not errorlevel 1 exit /b 0 +echo [5/6] ÀëÏ߰üȱʧ»òʧ°ܣ¬תÔÚÏ߰²װ ... +:pkg_online +"%VPY%" -m pip install "%~1" -i https://mirrors.aliyun.com/pypi/simple/ +if not errorlevel 1 exit /b 0 +"%VPY%" -m pip install "%~1" -i https://pypi.tuna.tsinghua.edu.cn/simple +if not errorlevel 1 exit /b 0 +"%VPY%" -m pip install "%~1" +exit /b %errorlevel% + +rem ©¤©¤ °²װ CPU °æ torch£¨ÀëÏßÓÅÏÈ ¡ú °¢ÀïÔÆ CPU Դ ¡ú ¹ٷ½ CPU Դ£©©¤©¤ +:pip_torch +call :wheels_exists +if errorlevel 1 goto :torch_online +"%VPY%" -m pip install --no-index --find-links "wheels" torch +if not errorlevel 1 exit /b 0 +echo [5/6] ÀëÏ߰üȱʧ»òʧ°ܣ¬תÔÚÏ߰²װ ... +:torch_online +"%VPY%" -m pip install torch --index-url https://mirrors.aliyun.com/pytorch-wheels/cpu/ +if not errorlevel 1 exit /b 0 +"%VPY%" -m pip install torch --index-url https://download.pytorch.org/whl/cpu +exit /b %errorlevel% + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem °ïÖú / ʹÓÃ˵Ã÷ +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +:show_help +echo. +echo ¡¾³£ÓÃÃüÁ +echo start.bat ²¿Êð²¢Æô¶¯£¨ĬÈϣ© +echo start.bat reinstall ɾ³ý venv ÖØװ£¨³öÎÊÌâÊ×ѡ£© +echo start.bat extras ׷¼Ӱ²װ mediapipe / pyrealsense2 +echo start.bat extras-torch ׷¼Ӱ²װ CPU °æ torch +echo start.bat help ´򿪱¾Îĵµ +echo. +echo English guide: ʹÓÃ˵Ã÷_EN.md +echo. +if exist "ʹÓÃ˵Ã÷.md" start "" "ʹÓÃ˵Ã÷.md" +if not exist "ʹÓÃ˵Ã÷.md" echo [¾¯¸æ] δÕҵ½ ʹÓÃ˵Ã÷.md£¬Çë´Ó GitLab ÖØÐÂÏÂÔØÍêÕû´úÂë +pause +exit /b 0 + +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +rem Ò쳣´¦Àí£¨´íÎóÂë A-G£¬Óë ʹÓÃ˵Ã÷.md ¶ÔӦ£© +rem ©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤ +:errA +echo. +echo [´íÎó A] δÄÜÕҵ½»ò×Զ¯°²װ Python 3.12 +echo ------------------------------------------------------------ +echo 0. ÒÑÓÐ Python µ«°汾µÍÓÚ 3.10£¿°´ÏÂÃ沽Ö谲װ 3.12 ¼´¿É +echo 1. ÀëÏ߻·¾³: ½« python-3.12.10-amd64.exe ·ÅÈ뱾Ŀ¼ wheels\ ºóÖØÊÔ +echo £¨ÓɹÜÀíԱÓà scripts\pack_wheels.py Éú³ɣ¬¼ûʹÓÃ˵Ã÷.md£© +echo 2. Êֶ¯°²װ: ¼´½«´򿪹ÙÍøÏÂÔØҳ£¬ÇëÏÂÔØ Python 3.12.x 64 λ +echo °²װʱÎñ±ع´ѡ "Add python.exe to PATH" +echo 3. ÒѰ²װÈԱ¨´í: µçÄԿÉÄÜװÓÐ Microsoft Store °æ Python ¸ÉÈţ¬ +echo ÇëÔÚ ÉèÖÃ-ӦÓà ÖÐжÔغó°²װ¹ÙÍø°æ +echo. +start https://www.python.org/downloads/ +pause +exit /b 1 + +:errC +echo. +echo [´íÎó C] ÐéÄ⻷¾³´´½¨ʧ°Ü +echo ------------------------------------------------------------ +echo 1. ´ÅÅ̿ռ䲻×ã: ÇåÀí´ÅÅ̺óÖØÊԣ¨ÐèҪԼ 2GB ¿ÕÏУ© +echo 2. ɱ¶¾Èí¼þÀ¹½Ø: ½«±¾Ŀ¼¼ÓÈë°×Ãûµ¥ºó˫»÷ start.bat reinstall +echo 3. ·¾¶¹ý³¤: °ÑÕû¸öÏîĿÎļþ¼ÐÒƵ½¶Ì·¾¶£¨Èç C:\DAQ_sdk£©ºóÖØÊÔ +echo 4. ·¾¶º¬ÌØÊâ×ַû: »»һ¸ö´¿ӢÎÄ/Êý×ֵÄĿ¼ÖØÊÔ +echo. +pause +exit /b 1 + +:errC2 +echo. +echo [´íÎó C2] ¾É venv ɾ³ýʧ°ܣ¨Îļþ±»ռÓã© +echo ------------------------------------------------------------ +echo ÇëÏȹرÕÕýÔÚÔËÐеÄÖ÷³ÌÐ򴰿ڣ¬ÔÙ˫»÷ start.bat reinstall +echo. +pause +exit /b 1 + +:errD +echo. +echo [´íÎó D] ÒÀÀµÏÂÔØ/°²װʧ°Ü +echo ------------------------------------------------------------ +echo 1. ÍøÂçÎÊÌâ: ¼ì²éÍøÂçºóÖØÐÂ˫»÷ start.bat£¨ÒÑÏÂÔز¿·ֻỺ´棬²»Öظ´ÏÂÔأ© +echo 2. ¹«˾ÍøÂçÏÞÖÆ/´úÀí: Çë¹ÜÀíԱ·ÅÐÐ pypi ¾µÏ񣬻ò¸ÄÓÃÀëÏ߰ü½»¸¶ +echo £¨¹ÜÀíԱÔËÐÐ scripts\pack_wheels.py Éú³É wheels\£¬¼ûʹÓÃ˵Ã÷.md£© +echo 3. ɱ¶¾Èí¼þ/·À»ðǽÀ¹½Ø pip: ¼ÓÈë°×Ãûµ¥ºóÖØÊÔ +echo 4. ¶à´Îʧ°Ü: ˫»÷ start.bat reinstall ÖØװ +echo. +pause +exit /b 1 + +:errE +echo. +echo [´íÎó E] ÒÀÀµ×Լìʧ°ܣ¨ÒÀÀµÒѰ²װµ«³ÌÐòÎ޷¨µ¼È룩 +echo ------------------------------------------------------------ +echo 1. ɱ¶¾Èí¼þ¸ôÀëÁË venv Îļþ: ´ӸôÀëÇø»ָ´²¢¼ÓÈë°×Ãûµ¥ +echo 2. ÒÀÀµ°汾³åͻ: ˫»÷ start.bat reinstall ÖØװ +echo 3. ²鿴¾ßÌåԭÒò: ÔÚ cmd ÖÐÔËÐÐ +echo venv\Scripts\python.exe -c "import main" +echo. +pause +exit /b 1 + +:errF +echo. +echo [´íÎó F] Ö÷³ÌÐòÆô¶¯ºóÒ쳣Í˳ö +echo ------------------------------------------------------------ +echo 1. ÏԿ¨Çý¶¯¹ý¾É: ¸üÐÂÏԿ¨Çý¶¯ºóÖØÊÔ +echo 2. Զ³Ì×ÀÃæ/ÐéÄâ»ú»·¾³: ÇëÔڱ¾µØʵ»úÔËÐÐ +echo 3. Qt ƽ̨²å¼þ´íÎó: ˫»÷ start.bat reinstall ÖØװ +echo 4. ÉãÏñͷÎ޻­Ãæ: Windows ÉèÖà - Òþ˽ºͰ²ȫÐÔ - Ïà»ú£¬ +echo ÔÊÐíӦÓ÷ÃÎÊÏà»úºóÖØÆôÖ÷³ÌÐò +echo 5. ²鿴¾ßÌå´íÎó: ÔÚ cmd ÖÐÔËÐÐ +echo venv\Scripts\python.exe main.py +echo. +pause +exit /b 1 + +:errG +echo. +echo [´íÎó G] δÕҵ½ main.py ¡ª¡ª ½âѹ²ã´β»¶Ô +echo ------------------------------------------------------------ +echo Ç뱣³ÖÎļþ¼нṹÍêÕû: start.bat Óë main.py ±ØÐëÔÚͬһĿ¼¡£ +echo ²¿·ֽâѹ¹¤¾߻á¶àÌ×һ²ãÎļþ¼У¬Çë½øÈëÄڲãĿ¼ÔÙ˫»÷ start.bat¡£ +echo. +pause +exit /b 1 diff --git a/collector/start.sh b/collector/start.sh new file mode 100755 index 0000000000000000000000000000000000000000..052df9914ca0dd1778ac9fe4eb18abfa6bdd7b13 --- /dev/null +++ b/collector/start.sh @@ -0,0 +1,160 @@ +#!/usr/bin/env bash +# ============================================================ +# DAQ 数据采集系统 —— Linux 一键部署脚本(与 Windows start.bat 行为一致) +# +# 用法: +# ./start.sh 部署(按需) + 启动主程序 +# ./start.sh reinstall 删除 venv 强制重装(出问题首选) +# ./start.sh extras 追加安装 mediapipe / pyrealsense2 +# ./start.sh extras-torch 追加安装 CPU 版 torch +# ./start.sh help 打开 使用说明.md +# +# 依赖安装顺序: 离线 wheels/ 包 → 阿里云镜像 → 清华镜像 → 官方源 +# ============================================================ +set -euo pipefail +cd "$(dirname "$0")" + +MODE=run +FORCE=0 +case "${1:-}" in + reinstall) FORCE=1 ;; + extras) MODE=extras ;; + extras-torch) MODE=extras-torch ;; + help|guide) MODE=help ;; +esac +# 非子命令参数原样透传给 main.py + +if [ "$MODE" = help ]; then + [ -f "使用说明.md" ] && xdg-open "使用说明.md" 2>/dev/null || true + echo "常用命令: ./start.sh [reinstall|extras|extras-torch|help]" + echo "English guide: 使用说明_EN.md" + exit 0 +fi + +# ── [G] 解压层次自检 ── +if [ ! -f main.py ] || [ ! -f requirements.txt ]; then + echo "[错误 G] 未找到 main.py —— 目录层次不对。start.sh 与 main.py 必须在同一目录。" + exit 1 +fi + +# ── [1/6] 定位 Python(>= 3.10,推荐 3.12)── +PY="" +find_python() { + for c in python3.12 python3.11 python3.10 python3; do + if command -v "$c" >/dev/null 2>&1 && "$c" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; then + PY="$(command -v "$c")" + return 0 + fi + done + return 1 +} +if [ -x venv/bin/python ]; then + PY="venv/bin/python" +elif ! find_python; then + echo "[错误 A] 未找到 Python >= 3.10。请先安装:" + echo " Ubuntu/Debian: sudo apt install python3.12 python3.12-venv" + echo " CentOS/RHEL: sudo dnf install python3.12" + echo " conda: conda create -n daq python=3.12" + exit 1 +fi +echo "[1/6] 使用 Python: $PY" + +# ── [2/6] venv ── +if [ -x venv/bin/python ] && [ "$FORCE" = 1 ]; then + echo "[2/6] reinstall: 删除旧 venv ..." + rm -rf venv +fi +if [ ! -x venv/bin/python ]; then + echo "[2/6] 创建虚拟环境 venv(首次约 1 分钟)..." + "$PY" -m venv venv +fi +VPY="venv/bin/python" + +# ── [3/6] 依赖 ── +HASH="$(md5sum requirements.txt | cut -d' ' -f1)" +NEED_INSTALL=0 +if [ "$FORCE" = 1 ]; then + NEED_INSTALL=1 +elif [ ! -f venv/.deps-ok ] || [ "$(cat venv/.deps-ok)" != "$HASH" ]; then + NEED_INSTALL=1 +fi + +install_req() { + local req="$1" + if [ -d wheels ] && ls wheels/*.whl >/dev/null 2>&1; then + echo "[3/6] 检测到 wheels/ 离线包,优先离线安装 ..." + "$VPY" -m pip install --no-index --find-links wheels -r "$req" && return 0 + echo "[3/6] 离线包安装失败,转在线安装 ..." + fi + "$VPY" -m pip install -r "$req" -i https://mirrors.aliyun.com/pypi/simple/ && return 0 + "$VPY" -m pip install -r "$req" -i https://pypi.tuna.tsinghua.edu.cn/simple && return 0 + "$VPY" -m pip install -r "$req" +} + +if [ "$NEED_INSTALL" = 1 ]; then + echo "[3/6] 安装依赖(首次约 3-10 分钟,之后启动秒开)..." + "$VPY" -m pip install --upgrade pip >/dev/null 2>&1 || true + if ! install_req requirements.txt; then + echo "[错误 D] 依赖下载/安装失败: 检查网络;内网环境请用 scripts/pack_wheels.py 生成 wheels/ 离线包。" + exit 1 + fi + echo "$HASH" > venv/.deps-ok +fi + +# ── [4/6] 冒烟自检 ── +echo "[4/6] 依赖自检 ..." +if ! "$VPY" -c "import main" >/dev/null 2>&1; then + echo "[错误 E] 依赖自检失败。查看具体原因:" + echo " venv/bin/python -c \"import main\"" + echo "重装: ./start.sh reinstall" + exit 1 +fi +echo "[4/6] 依赖自检通过" + +# ── [5/6] 可选功能 ── +install_pkg() { + if [ -d wheels ] && ls wheels/*.whl >/dev/null 2>&1; then + "$VPY" -m pip install --no-index --find-links wheels "$1" && return 0 + fi + "$VPY" -m pip install "$1" -i https://mirrors.aliyun.com/pypi/simple/ && return 0 + "$VPY" -m pip install "$1" -i https://pypi.tuna.tsinghua.edu.cn/simple && return 0 + "$VPY" -m pip install "$1" +} + +case "$MODE" in + extras) + [ -f venv/.extras-ok ] || { + echo "[5/6] 安装可选功能: mediapipe + pyrealsense2 ..." + install_pkg mediapipe || echo " [警告] mediapipe 安装失败(主程序不受影响)" + install_pkg pyrealsense2 || echo " [警告] pyrealsense2 安装失败(主程序不受影响)" + echo done > venv/.extras-ok + } + echo "[5/6] 可选功能安装完成。运行 ./start.sh 启动主程序。" + exit 0 ;; + extras-torch) + [ -f venv/.torch-ok ] || { + echo "[5/6] 安装可选功能: torch CPU 版 ..." + install_torch() { + if [ -d wheels ] && ls wheels/*.whl >/dev/null 2>&1; then + "$VPY" -m pip install --no-index --find-links wheels torch && return 0 + fi + "$VPY" -m pip install torch --index-url https://mirrors.aliyun.com/pytorch-wheels/cpu/ && return 0 + "$VPY" -m pip install torch --index-url https://download.pytorch.org/whl/cpu + } + install_torch || echo " [警告] torch 安装失败(主程序不受影响)" + echo done > venv/.torch-ok + } + echo "[5/6] 可选功能安装完成。运行 ./start.sh 启动主程序。" + exit 0 ;; +esac + +# ── [6/6] 启动 ── +echo "[6/6] 启动主程序 ..." +echo +echo "【操作指引】" +echo " · 设备面板: 相机插入后约 2 秒自动出现,点击即可预览" +echo " · 录制: 每路相机独立的 开始/停止;正常停止=保存,异常停止=丢弃" +echo " · 任务/回放/上传: 见主界面与 使用说明.md" +echo +# 标记本次为 start.sh 启动 → 主程序弹出使用步骤窗口(可勾选不再显示) +DAQ_SHOW_GUIDE=1 exec "$VPY" main.py "$@" diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/analyze_episode_crf.py" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/analyze_episode_crf.py" new file mode 100644 index 0000000000000000000000000000000000000000..a19f98853d4e19c4b2d4ade878725093d8ea5d5e --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/analyze_episode_crf.py" @@ -0,0 +1,693 @@ +#!/usr/bin/env python3 +""" +Episode SLAM 轨迹对比分析器 (多档压缩 / 多 episode 两两对比)。 + +用于把多份来自**同一段录制、不同处理参数**(如不同视频 CRF)的 SLAM 轨迹 +放在一起对比,量化轨迹间差异。参考 analyze_test.py 的 RPE / ATE / 逐帧 +偏差方法,但对比对象从"SLAM vs 机械臂FK"换成"N 个 episode 目录互相对比"。 + +核心前提(已验证): + - 每份 episode 的 results/trajectory/trajectory_online_style.txt 采用 + 相同的坐标修正(rotation_correction + 原点平移),起点时间与起始四元数 + 完全一致 → 无需手眼标定,可直接在同一时间轴上逐帧比较。 + - 时间轴 = 相对时间(第1列, 从 0 起),三档起点相同。 + +用法: + # 两个及以上 episode 目录, 两两对比: + python analyze_episode_crf.py /path/episode_00009.zip.new \ + /path/episode_00009_crf30.zip.new \ + /path/episode_00009_crf37.zip.new --plot + # 指定基准(否则两两): + python analyze_episode_crf.py A B C --ref A --plot + # 切换轨迹文件 / 报告输出: + python analyze_episode_crf.py A B C --traj tum --outdir reports --plot + +输出: + 每次运行在 --outdir 下新建独立时间戳子目录 run_<时间戳>/, 历史结果互不覆盖: + - report_<时间戳>.txt + summary.txt: 每档质量表 + 逐对 RPE/ATE/最大偏差 + [总结] + - --plot 时: traj_3d/traj_xy/traj_xz/traj_yz/pos_vs_time/dev_vs_time/rpe_bar/tracking_ok.png +""" + +import sys, os, math, time, argparse +import numpy as np + + +# --------------------------------------------------------------------------- +# 基础 SE3 / 四元数工具 (与 analyze_test.py 一致) +# --------------------------------------------------------------------------- + +def quat_to_rot(q_xyzw): + """[qx,qy,qz,qw] → 3×3""" + x, y, z, w = float(q_xyzw[0]), float(q_xyzw[1]), float(q_xyzw[2]), float(q_xyzw[3]) + return np.array([ + [1 - 2 * y * y - 2 * z * z, 2 * x * y - 2 * w * z, 2 * x * z + 2 * w * y], + [2 * x * y + 2 * w * z, 1 - 2 * x * x - 2 * z * z, 2 * y * z - 2 * w * x], + [2 * x * z - 2 * w * y, 2 * y * z + 2 * w * x, 1 - 2 * x * x - 2 * y * y], + ]) + + +def rot_to_axis_angle(R): + """3×3 → axis*angle 向量, ||v|| = angle(rad)""" + theta = math.acos(max(-1.0, min(1.0, (np.trace(R) - 1) / 2))) + if theta < 1e-10: + return np.zeros(3) + rx = R[2, 1] - R[1, 2] + ry = R[0, 2] - R[2, 0] + rz = R[1, 0] - R[0, 1] + s = math.sqrt(rx * rx + ry * ry + rz * rz) + if s < 1e-10: + return np.zeros(3) + axis = np.array([rx, ry, rz]) / s + return axis * theta + + +def make_T(xyz, q_xyzw): + """→ 4×4 SE3, 输入四元数顺序为 [x,y,z,w]。""" + T = np.eye(4) + T[0:3, 0:3] = quat_to_rot(q_xyzw) + T[0:3, 3] = xyz + return T + + +def normalize_quat(q_xyzw): + n = np.linalg.norm(q_xyzw) + return q_xyzw / n if n > 1e-15 else np.array([0.0, 0.0, 0.0, 1.0]) + + +def quat_rot_error(qa, qb): + """两姿态间相对旋转角(rad), 输入 [x,y,z,w]""" + Ra, Rb = quat_to_rot(qa), quat_to_rot(qb) + E = Ra.T @ Rb + return np.linalg.norm(rot_to_axis_angle(E)) + + +def umeyama(src_pts, dst_pts): + """src → dst 的刚体变换估计 (Umeyama, 无缩放)。返回 (R, t)。""" + c_s = src_pts.mean(axis=0) + c_d = dst_pts.mean(axis=0) + sc = src_pts - c_s + dc = dst_pts - c_d + H = (sc.T @ dc) / len(sc) + U, _, Vt = np.linalg.svd(H) + R = Vt.T @ U.T + if np.linalg.det(R) < 0: + Vt[-1, :] *= -1 + R = Vt.T @ U.T + t = c_d - R @ c_s + return R, t + + +# --------------------------------------------------------------------------- +# 数据加载 +# --------------------------------------------------------------------------- + +def resolve_episode_root(path): + """给定 episode 目录(可能是 zip 名目录或 episode_XXXX 子目录) → episode 根。 + + 根目录特征: 存在 results/ 子目录。若传入的是父目录, 自动找唯一/第一个 + episode_* 子目录。 + """ + if os.path.isdir(os.path.join(path, "results")): + return path + cands = sorted( + d for d in os.listdir(path) + if d.startswith("episode") and os.path.isdir(os.path.join(path, d)) + ) + if not cands: + raise ValueError(f"无法从 {path} 定位 episode 根目录(找不到 results/ 或 episode_* 子目录)") + return os.path.join(path, cands[0]) + + +def load_trajectory(episode_root, traj_kind="online"): + """读取 SLAM 轨迹。 + + traj_kind: + online (默认) -> results/trajectory/trajectory_online_style.txt + 9列: t_rel x y z qx qy qz qw abs_sensor_s + tum -> results/trajectory/camera_trajectory_tum.txt + (严格 TUM: ts_s x y z qx qy qz qw, ts为秒) + body -> results/trajectory/body_trajectory_euroc.txt + (EuRoC: ts_ns px py pz vx vy vz qx qy qz qw bg ba) + """ + traj_dir = os.path.join(episode_root, "results", "trajectory") + if traj_kind == "online": + p = os.path.join(traj_dir, "trajectory_online_style.txt") + arr = np.loadtxt(p) + if arr.ndim == 1 or arr.shape[1] < 8: + raise ValueError(f"{p} 列数不足") + ts = arr[:, 0].copy() + xyz = arr[:, 1:4].copy() + q = arr[:, 4:8].copy() + abs_s = arr[:, 8].copy() if arr.shape[1] >= 9 else np.full(len(ts), np.nan) + elif traj_kind == "tum": + p = os.path.join(traj_dir, "camera_trajectory_tum.txt") + arr = np.loadtxt(p) + ts = arr[:, 0].copy() - arr[0, 0] # 相对秒 + xyz = arr[:, 1:4].copy() + q = arr[:, 4:8].copy() + abs_s = arr[:, 0].copy() + elif traj_kind == "body": + p = os.path.join(traj_dir, "body_trajectory_euroc.txt") + arr = np.loadtxt(p) + # EuRoC: 列0为纳秒时间戳; 位姿平移在第1:4列; 四元数第7:11列 + ts = (arr[:, 0] - arr[0, 0]) * 1e-9 # 纳秒→相对秒 + xyz = arr[:, 1:4].copy() + q = arr[:, 7:11].copy() + abs_s = arr[:, 0] * 1e-9 + else: + raise ValueError(f"未知轨迹类型: {traj_kind}") + + # 恢复单位四元数, 避免微小范数误差放大为旋转误差 + norms = np.linalg.norm(q, axis=1, keepdims=True) + q = q / np.maximum(norms, 1e-15) + + # 相对时间起点归零, 且严格递增 + ts = ts - ts[0] + order = np.argsort(ts) + ts, xyz, q, abs_s = ts[order], xyz[order], q[order], abs_s[order] + + # 四元数符号连续性解卷: q 与 -q 表示同一旋转, ORB 输出符号可能跳变。 + # 若不统一, 跨符号跳变做分量插值会在中点得到近零向量 → 虚假旋转误差。 + for i in range(1, len(q)): + if np.dot(q[i], q[i - 1]) < 0: + q[i] = -q[i] + + # 命名用外层变体目录(如 episode_00009_crf30.zip.new), 而非 episode_0000 + base = os.path.basename(episode_root) + if base.startswith("episode"): + name = os.path.basename(os.path.dirname(episode_root)) + else: + name = base + + T_list = [make_T(xyz[i], q[i]) for i in range(len(ts))] + return {"name": name, "root": episode_root, "path": p, + "ts": ts, "xyz": xyz, "q": q, "abs_s": abs_s, "T": T_list} + + +def load_run_report(episode_root): + """读取 results/trajectory/run_report.yaml 关键字段。""" + meta = {} + p = os.path.join(episode_root, "results", "trajectory", "run_report.yaml") + if os.path.exists(p): + with open(p) as f: + for line in f: + line = line.strip() + if ":" in line and not line.startswith("#"): + k, v = line.split(":", 1) + k, v = k.strip(), v.strip() + try: + meta[k] = float(v) + except ValueError: + meta[k] = v + return meta + + +def load_tracking_states(episode_root): + """读取 results/trajectory/tracking.csv → (aligned_ts_s, tracking_state)。 + + tracking_state 约定(与离线工具一致): 2 = 跟踪OK, 其余为未就绪/丢失。 + """ + p = os.path.join(episode_root, "results", "trajectory", "tracking.csv") + if not os.path.exists(p): + return None, None + rows = [] + with open(p) as f: + header = None + for line in f: + line = line.strip() + if not line: + continue + if header is None: + header = line.split(",") + continue + parts = line.split(",") + if len(parts) < 4: + continue + try: + rows.append((float(parts[2]), int(parts[3]))) + except ValueError: + continue + if not rows: + return None, None + ts = np.array([r[0] for r in rows]) + states = np.array([r[1] for r in rows]) + ts = ts - ts[0] + return ts, states + + +# --------------------------------------------------------------------------- +# 公共时间轴插值 (位置逐轴线性, 四元数分量插值后归一化) +# --------------------------------------------------------------------------- + +def interpolate_pose(trajectory, grid): + """把轨迹插值到公共时间轴 grid → (xyz_g, q_g)。grid 需在轨迹时间范围内。""" + ts, xyz, q = trajectory["ts"], trajectory["xyz"], trajectory["q"] + xyz_g = np.column_stack([np.interp(grid, ts, xyz[:, k]) for k in range(3)]) + q_g = np.column_stack([np.interp(grid, ts, q[:, k]) for k in range(4)]) + q_g = q_g / np.maximum(np.linalg.norm(q_g, axis=1, keepdims=True), 1e-15) + return xyz_g, q_g + + +def valid_mask(ts, grid, gap_thresh=0.3): + """公共时间轴上"该轨迹有有效位姿"的掩码。 + + 若 grid 点落在这条轨迹的某个大于 gap_thresh 的样本间隙内部 + (离最近样本超过 gap_thresh/2), 说明该处 SLAM 没有估计值, + 插值得到的姿态无意义 → 标记为无效, 避免跨跟丢间隙的虚假大偏差。 + """ + idx = np.searchsorted(ts, grid) + left = np.clip(idx - 1, 0, len(ts) - 1) + right = np.clip(idx, 0, len(ts) - 1) + d = np.minimum(np.abs(ts[left] - grid), np.abs(ts[right] - grid)) + return (d <= gap_thresh / 2) & (grid >= ts[0]) & (grid <= ts[-1]) + + +# --------------------------------------------------------------------------- +# 对比指标 +# --------------------------------------------------------------------------- + +def compute_deviation(ta, tb, grid, valid): + """同一公共时间轴上的逐帧偏差: 位置(米) + 旋转(度)。无效点置 NaN。""" + xa, qa = interpolate_pose(ta, grid) + xb, qb = interpolate_pose(tb, grid) + pos_dev = np.full(len(grid), np.nan) + rot_dev = np.full(len(grid), np.nan) + pos_dev[valid] = np.linalg.norm(xa[valid] - xb[valid], axis=1) + rot_dev[valid] = np.array([ + math.degrees(quat_rot_error(qa[i], qb[i])) for i in np.flatnonzero(valid) + ]) + return pos_dev, rot_dev + + +def compute_rpe_time(ta, tb, grid, delta_s, valid): + """时间增量 RPE: 每隔 delta_s 比较两轨迹的帧间相对运动。 + + E = inv(ΔB) @ ΔA, ΔX = inv(T_X(t)) @ T_X(t+delta) + RPE_trans = |trans(E)|, RPE_rot = |axisangle(rot(E))| (度)。 + 只比较运动大小, 不需要坐标系对齐。仅统计两端都有效的点。 + """ + xa, qa = interpolate_pose(ta, grid) + xb, qb = interpolate_pose(tb, grid) + trans_errs, rot_errs = [], [] + n = len(grid) + for i in range(n): + if not valid[i]: + continue + j = np.searchsorted(grid, grid[i] + delta_s) + if j >= n or not valid[j]: + continue + dA = np.linalg.inv(make_T(xa[i], qa[i])) @ make_T(xa[j], qa[j]) + dB = np.linalg.inv(make_T(xb[i], qb[i])) @ make_T(xb[j], qb[j]) + E = np.linalg.inv(dA) @ dB + trans_errs.append(np.linalg.norm(E[0:3, 3])) + rot_errs.append(math.degrees(np.linalg.norm(rot_to_axis_angle(E[0:3, 0:3])))) + return np.array(trans_errs), np.array(rot_errs) + + +def compute_ate(ta, tb, grid, valid): + """ATE: Umeyama 对齐 B→A 后的平移残差 (米)。仅统计有效点。""" + xa, _ = interpolate_pose(ta, grid) + xb, _ = interpolate_pose(tb, grid) + R, t = umeyama(xb[valid], xa[valid]) + aligned = (R @ xb.T).T + t + errs = np.full(len(grid), np.nan) + errs[valid] = np.linalg.norm(aligned[valid] - xa[valid], axis=1) + return errs + + +def trajectory_quality(tr, report, states): + """每档单条轨迹的质量指标。""" + xyz = tr["xyz"] + path_len = np.sum(np.linalg.norm(np.diff(xyz, axis=0), axis=1)) + max_disp = np.linalg.norm(xyz - xyz[0], axis=1).max() + ok = report.get("tracking_ok_frames", None) + total = report.get("input_frames", None) + if states is not None: + ok_cnt = int(np.sum(states == 2)) + if total is None: + total = len(states) + ok = ok_cnt + ok_ratio = (ok / total * 100) if (ok is not None and total) else float("nan") + return { + "frames": len(tr["ts"]), + "duration_s": float(tr["ts"][-1] - tr["ts"][0]), + "path_len_m": path_len, + "max_disp_m": max_disp, + "tracking_ok": ok, + "input_frames": total, + "ok_ratio_pct": ok_ratio, + "max_gap_s": float(np.max(np.diff(tr["ts"]))) if len(tr["ts"]) > 1 else 0.0, + } + + +# --------------------------------------------------------------------------- +# 报告 & 绘图 +# --------------------------------------------------------------------------- + +def build_report(episodes, trajs, ref_name, out_lines): + qualities = [] + for tr in trajs: + name = tr["name"] + report = load_run_report(tr["root"]) + states_ts, states = load_tracking_states(tr["root"]) + q = trajectory_quality(tr, report, states) + q["name"] = name + qualities.append(q) + out_lines.append( + f" {name:<28s} 帧数 {q['frames']:>4d} 时长 {q['duration_s']:>6.2f}s " + f"路径 {q['path_len_m']:>5.2f}m 最大位移 {q['max_disp_m']:>5.2f}m " + f"跟踪 {q['tracking_ok']}/{q['input_frames']} ({q['ok_ratio_pct']:.0f}%) " + f"最大间隙 {q['max_gap_s']:.1f}s" + ) + out_lines.append("") + return qualities + + +def build_summary(qualities, names, metrics_map, ref_name, delta, out_lines): + """生成 [总结] 摘要段: 跟踪完整度排序 + 与基准差异最小的档位 + 结论。""" + out_lines.append("") + out_lines.append("=" * 72) + out_lines.append(" [总结]") + out_lines.append("=" * 72) + if ref_name: + out_lines.append(f" 对比基准: {ref_name}") + else: + out_lines.append(" 对比模式: 两两对比 (无预设基准)") + out_lines.append(f" 对比对象: {len(qualities)} 档 → {', '.join(q['name'] for q in qualities)}") + + # 跟踪完整度排序 (从高到低) + by_ok = sorted(qualities, key=lambda q: q["ok_ratio_pct"], reverse=True) + out_lines.append("") + out_lines.append(f" 跟踪完整度排序 (输入 {by_ok[0]['input_frames']} 帧):") + for k, q in enumerate(by_ok, 1): + out_lines.append( + f" {k}. {q['name']:<28s} {q['ok_ratio_pct']:>5.1f}% " + f"({q['tracking_ok']}/{q['input_frames']}) 最大间隙 {q['max_gap_s']:.1f}s") + + if metrics_map: + # RPE 平移排序 (低 = 差异更小 / 更接近基准) + rpe_key = f"rpe_t_{delta}s_mean_mm" + ranked = sorted(metrics_map.items(), key=lambda kv: kv[1][2][rpe_key]) + sort_note = "更接近基准" if ref_name else "差异更小" + out_lines.append("") + out_lines.append(f" 轨迹差异 (以 RPE@{delta}s 平移排序, 低 = {sort_note}):") + for key, (i, j, res) in ranked: + out_lines.append( + f" {key:<52s} RPE {res[rpe_key]:>6.1f}mm / {res[f'rpe_r_{delta}s_mean_deg']:>5.2f}° " + f"ATE {res['ate_rmse_m']*1000:>6.1f}mm") + if ref_name: + worst = ranked[-1] + out_lines.append("") + out_lines.append( + f" → 与基准差异最小: {ranked[0][0]} " + f"(RPE@{delta}s {ranked[0][1][2][rpe_key]:.1f}mm, ATE {ranked[0][1][2]['ate_rmse_m']*1000:.1f}mm)") + out_lines.append( + f" → 与基准差异最大: {worst[0]} " + f"(RPE@{delta}s {worst[1][2][rpe_key]:.1f}mm, ATE {worst[1][2]['ate_rmse_m']*1000:.1f}mm)") + + # 结论建议: 点名完整度最差/最好档位 + ok_min = min(q["ok_ratio_pct"] for q in qualities) + worst = min(qualities, key=lambda q: q["ok_ratio_pct"]) + best = max(qualities, key=lambda q: q["ok_ratio_pct"]) + out_lines.append("") + if ok_min < 70: + out_lines.append( + f" 结论: {worst['name']} 跟踪完整度仅 {worst['ok_ratio_pct']:.0f}%" + f"(最大间隙 {worst['max_gap_s']:.1f}s), 压缩过大导致轨迹不可信, 不建议使用。") + out_lines.append( + f" 可用档位: {best['name']} 完整度最高 ({best['ok_ratio_pct']:.0f}%), 建议采用。") + elif ok_min < 90: + out_lines.append( + f" 结论: 各档位跟踪完整度基本可用 (最低 {worst['name']} {worst['ok_ratio_pct']:.0f}%), " + "存在轻微跟踪损失, 建议在可接受误差内选择压缩率更高的一档。") + else: + out_lines.append( + f" 结论: 各档位跟踪完整度良好 (最低 {worst['name']} {worst['ok_ratio_pct']:.0f}%), " + "压缩对 SLAM 影响有限。") + out_lines.append("") + + +def pairwise_metrics(ta, tb, deltas): + """ta 为基准(参考), tb 为被测。返回汇总 dict。 + + 只在两侧都有有效位姿的时间点上统计(屏蔽跟踪间隙, 见 valid_mask)。 + """ + end = min(ta["ts"][-1], tb["ts"][-1]) + grid = np.arange(0.0, end, 0.02) + valid = valid_mask(ta["ts"], grid) & valid_mask(tb["ts"], grid) + pos_dev, rot_dev = compute_deviation(ta, tb, grid, valid) + ate = compute_ate(ta, tb, grid, valid) + res = { + "pos_dev_mean_mm": float(np.nanmean(pos_dev) * 1000), + "pos_dev_max_m": float(np.nanmax(pos_dev)), + "rot_dev_mean_deg": float(np.nanmean(rot_dev)), + "rot_dev_max_deg": float(np.nanmax(rot_dev)), + "ate_rmse_m": float(np.sqrt(np.nanmean(ate ** 2))), + "ate_mean_m": float(np.nanmean(ate)), + "ate_max_m": float(np.nanmax(ate)), + } + for d in deltas: + t_err, r_err = compute_rpe_time(ta, tb, grid, d, valid) + res[f"rpe_t_{d}s_mean_mm"] = float(np.mean(t_err) * 1000) + res[f"rpe_t_{d}s_max_mm"] = float(np.max(t_err) * 1000) + res[f"rpe_r_{d}s_mean_deg"] = float(np.mean(r_err)) + res[f"rpe_r_{d}s_max_deg"] = float(np.max(r_err)) + res["_grid"] = grid + res["_valid"] = valid + res["_pos_dev"] = pos_dev + res["_rot_dev"] = rot_dev + res["_ate"] = ate + return res + + +def main(): + p = argparse.ArgumentParser( + description="多档 episode SLAM 轨迹对比 (RPE/ATE/逐帧偏差)") + p.add_argument("episodes", nargs="+", + help="episode 目录(1 个以上); 每目录下需含 results/trajectory/") + p.add_argument("--ref", default=None, + help="基准 episode 目录; 不指定则两两对比") + p.add_argument("--traj", choices=["online", "tum", "body"], default="online", + help="对比用的轨迹文件 (默认 online = trajectory_online_style.txt)") + p.add_argument("--deltas", type=float, nargs="+", default=[0.5, 1.0, 2.0], + help="RPE 时间增量(秒), 默认 0.5 1.0 2.0") + p.add_argument("--outdir", default="", + help="输出根目录(每次运行在其下新建 run_<时间戳>/ 子目录; 默认 crf_report)") + p.add_argument("--plot", action="store_true", help="生成可视化图") + p.add_argument("--title", default="Episode SLAM 对比 (视频压缩档)", + help="图标题前缀") + args = p.parse_args() + + # ── 解析 episode 根 ── + roots = [] + for ep in args.episodes: + root = resolve_episode_root(os.path.abspath(ep)) + if root not in roots: + roots.append(root) + if len(roots) < 1: + sys.exit("至少需要 1 个 episode 目录") + if args.ref is not None: + ref_root = resolve_episode_root(os.path.abspath(args.ref)) + + # ── 加载轨迹 ── + trajs = [load_trajectory(r, args.traj) for r in roots] + names = [tr["name"] for tr in trajs] + + # ── 确定对比对 ── + pairs = [] + if args.ref is not None: + if ref_root not in roots: + roots = [ref_root] + roots + trajs = [load_trajectory(ref_root, args.traj)] + trajs + names = [trajs[0]["name"]] + names + idx_ref = roots.index(ref_root) + pairs = [(idx_ref, k) for k in range(len(roots)) if k != idx_ref] + ref_name = names[idx_ref] + else: + pairs = [(i, j) for i in range(len(roots)) for j in range(i + 1, len(roots))] + ref_name = None + + if not pairs: + print("仅一个目录, 跳过对比; 输出单档质量。") + + # ── 输出目录: 每次运行独立时间戳子目录, 历史结果不被覆盖 ── + run_ts = time.strftime("%Y%m%d_%H%M%S") + base_out = args.outdir or "crf_report" + outdir = os.path.join(base_out, f"run_{run_ts}") + k = 1 + while os.path.exists(outdir): # 同秒内连跑时追加序号 + k += 1 + outdir = os.path.join(base_out, f"run_{run_ts}_{k}") + os.makedirs(outdir, exist_ok=True) + report_path = os.path.join(outdir, f"report_{run_ts}.txt") + + lines = [] + lines.append("=" * 72) + lines.append(f" {args.title}") + lines.append(f" 轨迹文件: {args.traj} ({trajs[0]['path']})") + lines.append(f" 对比模式: {'以 ' + ref_name + ' 为基准' if ref_name else '两两对比'}") + lines.append("=" * 72) + lines.append("") + lines.append("[各档质量]") + qualities = build_report(episodes=roots, trajs=trajs, ref_name=ref_name, out_lines=lines) + lines.append("") + + metrics_map = {} + if pairs: + lines.append("[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °)") + lines.append(f" {'基准 → 被测':<42s} {'Δ=0.5s':>10s} {'Δ=1.0s':>10s} {'Δ=2.0s':>10s} {'ATE RMSE':>10s}") + for i, j in pairs: + res = pairwise_metrics(trajs[i], trajs[j], args.deltas) + key = f"{names[i]} → {names[j]}" + metrics_map[key] = (i, j, res) + rpe_line = " ".join( + f"t {res[f'rpe_t_{d}s_mean_mm']:>4.1f}mm/r {res[f'rpe_r_{d}s_mean_deg']:>4.2f}°" + for d in args.deltas + ) + lines.append(f" {key:<42s} {rpe_line} {res['ate_rmse_m']*1000:>6.1f}mm") + lines.append("") + lines.append(" 最大偏差(公共时间轴上, 未对齐):") + for key, (i, j, res) in metrics_map.items(): + lines.append( + f" {key:<42s} 位置 {res['pos_dev_mean_mm']:>6.1f}mm(均) / " + f"{res['pos_dev_max_m']*1000:>6.0f}mm(峰) | 旋转 " + f"{res['rot_dev_mean_deg']:>5.2f}°(均) / {res['rot_dev_max_deg']:>5.1f}°(峰)") + + # ── [总结] 摘要段 ── + summary_delta = args.deltas[0] + build_summary(qualities, names, metrics_map, ref_name, summary_delta, lines) + + text = "\n".join(lines) + "\n" + print(text) + with open(report_path, "w") as f: + f.write(text) + print(f"报告: {report_path}") + + # 另存一份固定名 summary.txt, 便于直接打开看结论(位于本次运行的 run_<时间戳>/ 内) + summary_path = os.path.join(outdir, "summary.txt") + with open(summary_path, "w") as f: + f.write(text) + print(f"摘要: {summary_path}") + print(f"本次运行输出目录: {outdir}") + + # ── 绘图 ── + if args.plot: + import matplotlib + matplotlib.use("Agg") + import matplotlib.font_manager as _fm + import matplotlib.pyplot as plt + # 中文字体: 优先 Noto Sans CJK, 找不到则退回 DejaVu (中文显示为方框) + _available = {f.name for f in _fm.fontManager.ttflist} + _cjk = next((n for n in [ + "Noto Sans CJK SC", "Noto Sans CJK JP", "WenQuanYi Micro Hei", + "AR PL UMing CN", "AR PL UKai CN", + ] if n in _available), None) + if _cjk: + plt.rcParams["font.sans-serif"] = [_cjk, "DejaVu Sans"] + plt.rcParams["axes.unicode_minus"] = False + else: + print("[WARN] 未找到 CJK 字体, 图中中文将显示为方框") + colors = ["#d62728", "#1f77b4", "#2ca02c", "#ff7f0e", "#9467bd", "#8c564b"] + c = {n: colors[k % len(colors)] for k, n in enumerate(names)} + + grid_common = None + if pairs: + i0, j0, res0 = next(iter(metrics_map.values())) + grid_common = res0["_grid"] + + # 1) 3D 叠加 + fig = plt.figure(figsize=(10, 8)) + ax = fig.add_subplot(111, projection="3d") + for tr in trajs: + xyz = tr["xyz"] + ax.plot(xyz[:, 0], xyz[:, 1], xyz[:, 2], lw=1.2, + color=c[tr["name"]], label=tr["name"]) + ax.set_xlabel("X(m)"); ax.set_ylabel("Y(m)"); ax.set_zlabel("Z(m)") + ax.legend(fontsize=8) + ax.set_title(f"{args.title} — 3D 轨迹叠加") + fig.tight_layout() + fig.savefig(os.path.join(outdir, "traj_3d.png"), dpi=150) + + # 2) 俯视 / 侧视 + for view, (u, v) in {"XY": (0, 1), "XZ": (0, 2), "YZ": (1, 2)}.items(): + fig, ax = plt.subplots(figsize=(9, 6)) + for tr in trajs: + xyz = tr["xyz"] + ax.plot(xyz[:, u], xyz[:, v], lw=1.2, color=c[tr["name"]], + label=tr["name"]) + ax.set_xlabel(f"{'XYZ'[u]}(m)"); ax.set_ylabel(f"{'XYZ'[v]}(m)") + ax.set_aspect("equal", adjustable="datalim") + ax.legend(fontsize=8); ax.grid(True) + ax.set_title(f"{args.title} — {view} 俯视/侧视") + fig.tight_layout() + fig.savefig(os.path.join(outdir, f"traj_{view.lower()}.png"), dpi=150) + + # 3) XYZ vs 时间 + fig, axes = plt.subplots(3, 1, figsize=(12, 9), sharex=True) + for tr in trajs: + xyz0 = tr["xyz"][0] + for k, ax in enumerate(axes): + ax.plot(tr["ts"], tr["xyz"][:, k] - xyz0[k], lw=0.8, + color=c[tr["name"]], label=tr["name"]) + ax.set_ylabel(["X(m)", "Y(m)", "Z(m)"][k]); ax.grid(True) + axes[0].legend(fontsize=8) + axes[-1].set_xlabel("t(s)") + fig.suptitle(f"{args.title} — 位姿分量 vs 时间 (相对各自起点)") + fig.tight_layout() + fig.savefig(os.path.join(outdir, "pos_vs_time.png"), dpi=150) + + # 4) 逐帧偏差 vs 时间 + if pairs: + fig, axes = plt.subplots(2, 1, figsize=(12, 7), sharex=True) + for key, (i, j, res) in metrics_map.items(): + g = res["_grid"] + axes[0].plot(g, res["_pos_dev"] * 1000, lw=0.8, color=c[names[j]], + label=key) + axes[1].plot(g, res["_rot_dev"], lw=0.8, color=c[names[j]], + label=key) + axes[0].set_ylabel("位置偏差(mm)"); axes[0].grid(True); axes[0].legend(fontsize=8) + axes[1].set_ylabel("旋转偏差(°)"); axes[1].grid(True); axes[1].legend(fontsize=8) + axes[1].set_xlabel("t(s)") + fig.suptitle(f"{args.title} — 公共时间轴逐帧偏差") + fig.tight_layout() + fig.savefig(os.path.join(outdir, "dev_vs_time.png"), dpi=150) + + # 5) RPE 柱状图 (取最接近 1.0s 的增量) + bar_delta = min(args.deltas, key=lambda d: abs(d - 1.0)) + fig, axes = plt.subplots(1, 2, figsize=(11, 5)) + keys = list(metrics_map.keys()) + t_means = [metrics_map[k][2][f"rpe_t_{bar_delta}s_mean_mm"] for k in keys] + r_means = [metrics_map[k][2][f"rpe_r_{bar_delta}s_mean_deg"] for k in keys] + axes[0].bar(range(len(keys)), t_means, color="#1f77b4") + axes[0].set_xticks(range(len(keys))); axes[0].set_xticklabels(keys, rotation=25, ha="right", fontsize=7) + axes[0].set_ylabel(f"RPE 平移(mm) @Δ={bar_delta}s"); axes[0].grid(True, axis="y") + axes[1].bar(range(len(keys)), r_means, color="#d62728") + axes[1].set_xticks(range(len(keys))); axes[1].set_xticklabels(keys, rotation=25, ha="right", fontsize=7) + axes[1].set_ylabel(f"RPE 旋转(°) @Δ={bar_delta}s"); axes[1].grid(True, axis="y") + fig.suptitle(f"{args.title} — 平均 RPE (Δ={bar_delta}s)") + fig.tight_layout() + fig.savefig(os.path.join(outdir, "rpe_bar.png"), dpi=150) + + # 6) 跟踪完整度 + fig, ax = plt.subplots(figsize=(10, 4.5)) + ok_ratios = [] + for tr in trajs: + report = load_run_report(tr["root"]) + states_ts, states = load_tracking_states(tr["root"]) + q = trajectory_quality(tr, report, states) + ok_ratios.append(q["ok_ratio_pct"]) + ax.bar(range(len(names)), ok_ratios, color=[c[n] for n in names]) + ax.set_xticks(range(len(names))); ax.set_xticklabels(names, rotation=15, ha="right", fontsize=8) + ax.set_ylabel("跟踪完整度(%)"); ax.set_ylim(0, 105) + ax.grid(True, axis="y") + for k, v in enumerate(ok_ratios): + ax.text(k, v + 1, f"{v:.0f}%", ha="center", fontsize=9) + ax.set_title(f"{args.title} — 跟踪完整度") + fig.tight_layout() + fig.savefig(os.path.join(outdir, "tracking_ok.png"), dpi=150) + + print(f"图已保存到: {outdir}/ (traj_3d/traj_xy/traj_xz/pos_vs_time/dev_vs_time/rpe_bar/tracking_ok)") + + +if __name__ == "__main__": + main() diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/dev_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/dev_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..d95223e3ef2fddaeca7f4ae8d59c410a660a9061 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/dev_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7426e2074cb9d47347c72e597261ccf933fd6bbdc5890231a8fc23bcd5d4323e +size 182873 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/pos_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/pos_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..e7bf96d0b56b707a7c0a381f5086763ec7d2e840 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/pos_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10637aecf3e1185173c565701f1d915775139c0f91269a43bfbeb88f6a1cfc19 +size 233696 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/report_20260827_154925.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/report_20260827_154925.txt" new file mode 100644 index 0000000000000000000000000000000000000000..b6ccb0835dbfe2040dedeb2e567f255a6411b269 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/report_20260827_154925.txt" @@ -0,0 +1,33 @@ +======================================================================== + Episode SLAM 对比 (视频压缩档) + 轨迹文件: online (/home/stouch/episode_00009.zip.new/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 两两对比 +======================================================================== + +[各档质量] + episode_00009.zip.new 帧数 337 时长 12.50s 路径 4.24m 最大位移 0.52m 跟踪 337/419.0 (80%) 最大间隙 0.1s + episode_00009_crf30.zip.new 帧数 333 时长 12.48s 路径 4.71m 最大位移 0.49m 跟踪 333/419.0 (79%) 最大间隙 0.2s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + episode_00009.zip.new → episode_00009_crf30.zip.new t 24.5mm/r 2.49° t 28.7mm/r 2.81° t 35.6mm/r 3.55° 27.7mm + + 最大偏差(公共时间轴上, 未对齐): + episode_00009.zip.new → episode_00009_crf30.zip.new 位置 23.1mm(均) / 161mm(峰) | 旋转 2.39°(均) / 18.6°(峰) + +======================================================================== + [总结] +======================================================================== + 对比模式: 两两对比 (无预设基准) + 对比对象: 2 档 → episode_00009.zip.new, episode_00009_crf30.zip.new + + 跟踪完整度排序 (输入 419.0 帧): + 1. episode_00009.zip.new 80.4% (337/419.0) 最大间隙 0.1s + 2. episode_00009_crf30.zip.new 79.5% (333/419.0) 最大间隙 0.2s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 差异更小): + episode_00009.zip.new → episode_00009_crf30.zip.new RPE 24.5mm / 2.49° ATE 27.7mm + + 结论: 各档位跟踪完整度基本可用 (最低 episode_00009_crf30.zip.new 79%), 存在轻微跟踪损失, 建议在可接受误差内选择压缩率更高的一档。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/rpe_bar.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/rpe_bar.png" new file mode 100644 index 0000000000000000000000000000000000000000..fafb5763c74bd61e2ae6a31ec66e2bae107ce40e --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/rpe_bar.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d6adda11fb49be5f8f534b3ccdc34aace2c80c1c0b64b983efbe024c46ce9ac5 +size 66936 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/summary.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/summary.txt" new file mode 100644 index 0000000000000000000000000000000000000000..b6ccb0835dbfe2040dedeb2e567f255a6411b269 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/summary.txt" @@ -0,0 +1,33 @@ +======================================================================== + Episode SLAM 对比 (视频压缩档) + 轨迹文件: online (/home/stouch/episode_00009.zip.new/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 两两对比 +======================================================================== + +[各档质量] + episode_00009.zip.new 帧数 337 时长 12.50s 路径 4.24m 最大位移 0.52m 跟踪 337/419.0 (80%) 最大间隙 0.1s + episode_00009_crf30.zip.new 帧数 333 时长 12.48s 路径 4.71m 最大位移 0.49m 跟踪 333/419.0 (79%) 最大间隙 0.2s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + episode_00009.zip.new → episode_00009_crf30.zip.new t 24.5mm/r 2.49° t 28.7mm/r 2.81° t 35.6mm/r 3.55° 27.7mm + + 最大偏差(公共时间轴上, 未对齐): + episode_00009.zip.new → episode_00009_crf30.zip.new 位置 23.1mm(均) / 161mm(峰) | 旋转 2.39°(均) / 18.6°(峰) + +======================================================================== + [总结] +======================================================================== + 对比模式: 两两对比 (无预设基准) + 对比对象: 2 档 → episode_00009.zip.new, episode_00009_crf30.zip.new + + 跟踪完整度排序 (输入 419.0 帧): + 1. episode_00009.zip.new 80.4% (337/419.0) 最大间隙 0.1s + 2. episode_00009_crf30.zip.new 79.5% (333/419.0) 最大间隙 0.2s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 差异更小): + episode_00009.zip.new → episode_00009_crf30.zip.new RPE 24.5mm / 2.49° ATE 27.7mm + + 结论: 各档位跟踪完整度基本可用 (最低 episode_00009_crf30.zip.new 79%), 存在轻微跟踪损失, 建议在可接受误差内选择压缩率更高的一档。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/tracking_ok.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/tracking_ok.png" new file mode 100644 index 0000000000000000000000000000000000000000..680b65d014c612430d146d03d21fbbb518a0b795 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/tracking_ok.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f145594beb5cec91482d18354cae1d95cee5554fa7b153cf3ffa36daedb14981 +size 47638 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_3d.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_3d.png" new file mode 100644 index 0000000000000000000000000000000000000000..fa2d299cbd714ecd4357e5e0135b8531e6e6de96 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_3d.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6c5edc7f74dda866f0f234cd8023125a62fcb7ae52ed1e5af3c26659ae05632 +size 374486 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_xy.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_xy.png" new file mode 100644 index 0000000000000000000000000000000000000000..330d8e4973b54687e7fbd882e2609e8c393c7e82 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_xy.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63985d30f6d560d8f6ad56f8aff8aaf4856a4a7940c36eb699999f3f667a177d +size 92095 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_xz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_xz.png" new file mode 100644 index 0000000000000000000000000000000000000000..4d8deae6faf2fbf6c4870f0845431845e806c75f --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_xz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee4cd068990adcb0b719658fb91ec3d235870255127daa95359c6a9f0a19d85a +size 128945 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_yz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_yz.png" new file mode 100644 index 0000000000000000000000000000000000000000..c8a161e21d0b33021d56d64dbf42467f18ab0329 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_154925/traj_yz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:976b6575d0c9c6883c55ba5fe927f2aaac91cd59b87b5022dd085ad231c184f9 +size 114476 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/dev_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/dev_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..289bcd3fdf4d49a8744b1e76bed07bd38a99bb61 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/dev_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ea6af2e778e5ff78fed96daf13c66463a62184922bca9a5ec054f9a170a00b7 +size 181351 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/pos_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/pos_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..f5eda53aeaede09a340bd875d53c6046c0e65e68 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/pos_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:547ca98a9999299e7f96633efb41f4147281e8733e30550e6a4047a429aa4aca +size 225813 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/report_20260827_171729.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/report_20260827_171729.txt" new file mode 100644 index 0000000000000000000000000000000000000000..978398125968a129e1cffc77e061dda0a62db71f --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/report_20260827_171729.txt" @@ -0,0 +1,33 @@ +======================================================================== + Episode SLAM 对比 (视频压缩档) + 轨迹文件: online (/tmp/epcmp_00009_orig/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 两两对比 +======================================================================== + +[各档质量] + epcmp_00009_orig 帧数 337 时长 12.50s 路径 4.24m 最大位移 0.52m 跟踪 337/419.0 (80%) 最大间隙 0.1s + epcmp_00009_crf28 帧数 331 时长 12.48s 路径 4.46m 最大位移 0.50m 跟踪 331/419.0 (79%) 最大间隙 0.2s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + epcmp_00009_orig → epcmp_00009_crf28 t 25.6mm/r 2.76° t 31.4mm/r 3.40° t 33.8mm/r 3.92° 27.9mm + + 最大偏差(公共时间轴上, 未对齐): + epcmp_00009_orig → epcmp_00009_crf28 位置 19.5mm(均) / 155mm(峰) | 旋转 2.21°(均) / 14.4°(峰) + +======================================================================== + [总结] +======================================================================== + 对比模式: 两两对比 (无预设基准) + 对比对象: 2 档 → epcmp_00009_orig, epcmp_00009_crf28 + + 跟踪完整度排序 (输入 419.0 帧): + 1. epcmp_00009_orig 80.4% (337/419.0) 最大间隙 0.1s + 2. epcmp_00009_crf28 79.0% (331/419.0) 最大间隙 0.2s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 差异更小): + epcmp_00009_orig → epcmp_00009_crf28 RPE 25.6mm / 2.76° ATE 27.9mm + + 结论: 各档位跟踪完整度基本可用 (最低 epcmp_00009_crf28 79%), 存在轻微跟踪损失, 建议在可接受误差内选择压缩率更高的一档。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/rpe_bar.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/rpe_bar.png" new file mode 100644 index 0000000000000000000000000000000000000000..e15ee36519f0c4ec2c3d93ff8015d63e7527971d --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/rpe_bar.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5699668a64c0ee008292375eec180cccf31eefb966f8bbd7e4058c18421c289 +size 64083 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/summary.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/summary.txt" new file mode 100644 index 0000000000000000000000000000000000000000..978398125968a129e1cffc77e061dda0a62db71f --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/summary.txt" @@ -0,0 +1,33 @@ +======================================================================== + Episode SLAM 对比 (视频压缩档) + 轨迹文件: online (/tmp/epcmp_00009_orig/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 两两对比 +======================================================================== + +[各档质量] + epcmp_00009_orig 帧数 337 时长 12.50s 路径 4.24m 最大位移 0.52m 跟踪 337/419.0 (80%) 最大间隙 0.1s + epcmp_00009_crf28 帧数 331 时长 12.48s 路径 4.46m 最大位移 0.50m 跟踪 331/419.0 (79%) 最大间隙 0.2s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + epcmp_00009_orig → epcmp_00009_crf28 t 25.6mm/r 2.76° t 31.4mm/r 3.40° t 33.8mm/r 3.92° 27.9mm + + 最大偏差(公共时间轴上, 未对齐): + epcmp_00009_orig → epcmp_00009_crf28 位置 19.5mm(均) / 155mm(峰) | 旋转 2.21°(均) / 14.4°(峰) + +======================================================================== + [总结] +======================================================================== + 对比模式: 两两对比 (无预设基准) + 对比对象: 2 档 → epcmp_00009_orig, epcmp_00009_crf28 + + 跟踪完整度排序 (输入 419.0 帧): + 1. epcmp_00009_orig 80.4% (337/419.0) 最大间隙 0.1s + 2. epcmp_00009_crf28 79.0% (331/419.0) 最大间隙 0.2s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 差异更小): + epcmp_00009_orig → epcmp_00009_crf28 RPE 25.6mm / 2.76° ATE 27.9mm + + 结论: 各档位跟踪完整度基本可用 (最低 epcmp_00009_crf28 79%), 存在轻微跟踪损失, 建议在可接受误差内选择压缩率更高的一档。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/tracking_ok.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/tracking_ok.png" new file mode 100644 index 0000000000000000000000000000000000000000..063afc0ac9513ef4661192c095c23b5ababbf7a1 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/tracking_ok.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a265be28af2a4472bef93a3fa6c802c1333d0eae2c04d76f59f7480d1ee8e9c +size 44812 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_3d.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_3d.png" new file mode 100644 index 0000000000000000000000000000000000000000..cc124179257ca9535eee6ae3cf3b083fceafd311 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_3d.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0c0ceab28f701e4ce38ca8e4e814d64706ce023a89d854a1d40276a7153430f8 +size 371060 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_xy.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_xy.png" new file mode 100644 index 0000000000000000000000000000000000000000..e8c62cf9855a49a76a32eea9d87e041903acf6f5 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_xy.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71715b066fc52d478dcd2d8319aeaa49b89789c818c658739fc23372ab8514d1 +size 90232 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_xz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_xz.png" new file mode 100644 index 0000000000000000000000000000000000000000..4733049a1d77c47bfcea7c5de09f652e9f500e11 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_xz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47fd3ed7423e767a26a731ad407042e3efc210262b71fa5218715b3e732a8b6f +size 122201 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_yz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_yz.png" new file mode 100644 index 0000000000000000000000000000000000000000..67bb19b47a5061caaee038814ab5b94f09c465f7 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_171729/traj_yz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:070f02d720b178f39d0dd1625fc54920069be43283369651f447fc605f283613 +size 115884 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/_template.html" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/_template.html" new file mode 100644 index 0000000000000000000000000000000000000000..32991d788d9f6feefe2079ab722792f304039774 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/_template.html" @@ -0,0 +1,304 @@ +episode_9 · CRF 五档对比 + + + + + +
+
EPISODE SLAM · CRF 轨迹对比
+
+ EPISODE_912.5 s419 输入帧2026-08-27 +
+
+ +
+ +
+
同一段录制 · 四档视频压缩 + 原档 · 离线 SLAM 轨迹逐帧对比
+

CRF 28/30 轨迹几乎无损,CRF 34/37 已崩坏

+

同一段 12.5 秒录制,视频分别以 CRF 28/30/34/37 压缩后跑离线 SLAM, + 轨迹与基准(原档)在同一时间轴上逐帧对比。压缩越重,视频越小 —— 但轨迹代价在 30 与 34 之间陡然跳变。

+
+ +
+
+
17.7 mm
+
与基准最接近 · CRF30
+
ATE 17.7mm · RPE@0.5s 10.1mm(CRF28 同水平,ATE 17.6mm)
+
+
+
339.9 mm
+
与基准偏离最大 · CRF34
+
ATE 339.9mm · 峰偏 1080mm —— 比 CRF37(176mm)反而更差
+
+
+
35.3 %
+
基准本身跟踪率
+
148/419 帧 · 中段存在 5.2s 跟丢段 —— 本段录制本身质量偏低
+
+
+ +
+
+ 01

各档质量

+ trajectory_online_style.txt · tracking.csv +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
档位轨迹帧数时长 (s)路径 (m)最大位移 (m)跟踪 OK完整度最大间隙 (s)
原档(基准)14812.541.410.49148/41935.3%5.2
CRF 2814011.281.270.29140/41933.4%5.2
CRF 301048.801.060.33104/41924.8%5.1
CRF 341119.802.291.01111/41926.5%5.1
CRF 371098.942.751.46109/41926.0%5.1
+
+ +
+
+ 02

与基准差异

+ RPE 位移 mm · 旋转 ° · ATE Umeyama 对齐后残差 +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
基准 → 被测RPE@0.5sRPE@1.0sRPE@2.0sATE RMSE (mm)峰偏 (mm)判定
原档 → CRF 2811.1 / 0.70°15.5 / 0.85°26.8 / 1.01°17.6116良好
原档 → CRF 3010.1 / 0.78°14.3 / 1.10°18.3 / 0.76°17.7139良好
原档 → CRF 3492.8 / 0.81°263.1 / 1.07°46.1 / 0.91°339.91080严重劣化
原档 → CRF 3757.4 / 1.43°87.9 / 1.85°22.2 / 0.60°176.01371严重劣化
+ +
+
观察 · 非单调
+

压缩档的劣化不是单调的:CRF 34(ATE 340mm)反而比 CRF 37(176mm)更差。 + 基准本身只有 35.3% 跟踪率、中段有 5.2s 跟丢段,各档在该段的重建行为各不相同(SLAM 对压缩伪影的敏感度有随机性)。 + 可靠结论:28/30 与原档重合良好(ATE ≈ 18mm),34/37 不可用。另:本段录制整体跟踪质量偏低(35%), + 若用于正式交付,建议重录或仅截取跟踪良好的区间。

+
+
+ +
+
+ 03

图表

+ matplotlib · 图例颜色与上文档位色一致 +
+
+
+
五档 SLAM 轨迹三维叠加
+
FIG.01三维轨迹叠加 —— 34/37 在跟丢段后漂出,28/30 与基准贴合
+
+
+
俯视 XY 轨迹
+
FIG.02俯视 XY
+
+
+
侧视 XZ 轨迹
+
FIG.03侧视 XZ
+
+
+
侧视 YZ 轨迹
+
FIG.04侧视 YZ
+
+
+
平均 RPE 柱状图
+
FIG.05平均 RPE(Δ=1.0s)
+
+
+
跟踪完整度柱状图
+
FIG.06跟踪完整度
+
+
+
逐帧偏差时间曲线
+
FIG.07公共时间轴逐帧偏差(上:位置 mm,下:旋转 °)
+
+
+
位姿分量时间曲线
+
FIG.08XYZ 分量 vs 时间(相对各自起点)
+
+
+
+ +
+ 工具 analyze_episode_crf.py(RPE / ATE / 逐帧偏差) + 数据 /tmp/ep9cmp · trajectory_online_style.txt + 输出 crf_report/run_20260827_193248 +
+ +
diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/comparison.html" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/comparison.html" new file mode 100644 index 0000000000000000000000000000000000000000..d8119da807dbac39f1b432690574c33a6feadb1a --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/comparison.html" @@ -0,0 +1,304 @@ +episode_9 · CRF 五档对比 + + + + + +
+
EPISODE SLAM · CRF 轨迹对比
+
+ EPISODE_912.5 s419 输入帧2026-08-27 +
+
+ +
+ +
+
同一段录制 · 四档视频压缩 + 原档 · 离线 SLAM 轨迹逐帧对比
+

CRF 28/30 轨迹几乎无损,CRF 34/37 已崩坏

+

同一段 12.5 秒录制,视频分别以 CRF 28/30/34/37 压缩后跑离线 SLAM, + 轨迹与基准(原档)在同一时间轴上逐帧对比。压缩越重,视频越小 —— 但轨迹代价在 30 与 34 之间陡然跳变。

+
+ +
+
+
17.7 mm
+
与基准最接近 · CRF30
+
ATE 17.7mm · RPE@0.5s 10.1mm(CRF28 同水平,ATE 17.6mm)
+
+
+
339.9 mm
+
与基准偏离最大 · CRF34
+
ATE 339.9mm · 峰偏 1080mm —— 比 CRF37(176mm)反而更差
+
+
+
35.3 %
+
基准本身跟踪率
+
148/419 帧 · 中段存在 5.2s 跟丢段 —— 本段录制本身质量偏低
+
+
+ +
+
+ 01

各档质量

+ trajectory_online_style.txt · tracking.csv +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
档位轨迹帧数时长 (s)路径 (m)最大位移 (m)跟踪 OK完整度最大间隙 (s)
原档(基准)14812.541.410.49148/41935.3%5.2
CRF 2814011.281.270.29140/41933.4%5.2
CRF 301048.801.060.33104/41924.8%5.1
CRF 341119.802.291.01111/41926.5%5.1
CRF 371098.942.751.46109/41926.0%5.1
+
+ +
+
+ 02

与基准差异

+ RPE 位移 mm · 旋转 ° · ATE Umeyama 对齐后残差 +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
基准 → 被测RPE@0.5sRPE@1.0sRPE@2.0sATE RMSE (mm)峰偏 (mm)判定
原档 → CRF 2811.1 / 0.70°15.5 / 0.85°26.8 / 1.01°17.6116良好
原档 → CRF 3010.1 / 0.78°14.3 / 1.10°18.3 / 0.76°17.7139良好
原档 → CRF 3492.8 / 0.81°263.1 / 1.07°46.1 / 0.91°339.91080严重劣化
原档 → CRF 3757.4 / 1.43°87.9 / 1.85°22.2 / 0.60°176.01371严重劣化
+ +
+
观察 · 非单调
+

压缩档的劣化不是单调的:CRF 34(ATE 340mm)反而比 CRF 37(176mm)更差。 + 基准本身只有 35.3% 跟踪率、中段有 5.2s 跟丢段,各档在该段的重建行为各不相同(SLAM 对压缩伪影的敏感度有随机性)。 + 可靠结论:28/30 与原档重合良好(ATE ≈ 18mm),34/37 不可用。另:本段录制整体跟踪质量偏低(35%), + 若用于正式交付,建议重录或仅截取跟踪良好的区间。

+
+
+ +
+
+ 03

图表

+ matplotlib · 图例颜色与上文档位色一致 +
+
+
+
五档 SLAM 轨迹三维叠加
+
FIG.01三维轨迹叠加 —— 34/37 在跟丢段后漂出,28/30 与基准贴合
+
+
+
俯视 XY 轨迹
+
FIG.02俯视 XY
+
+
+
侧视 XZ 轨迹
+
FIG.03侧视 XZ
+
+
+
侧视 YZ 轨迹
+
FIG.04侧视 YZ
+
+
+
平均 RPE 柱状图
+
FIG.05平均 RPE(Δ=1.0s)
+
+
+
跟踪完整度柱状图
+
FIG.06跟踪完整度
+
+
+
逐帧偏差时间曲线
+
FIG.07公共时间轴逐帧偏差(上:位置 mm,下:旋转 °)
+
+
+
位姿分量时间曲线
+
FIG.08XYZ 分量 vs 时间(相对各自起点)
+
+
+
+ +
+ 工具 analyze_episode_crf.py(RPE / ATE / 逐帧偏差) + 数据 /tmp/ep9cmp · trajectory_online_style.txt + 输出 crf_report/run_20260827_193248 +
+ +
diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/dev_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/dev_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..4ec52f99e7641f8253f4695701e2dd0c4fdceb94 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/dev_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:057df91525e1c3cb3e58ea1406a1de0831a53490ac1643e19cb10561fba90a41 +size 161463 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/pos_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/pos_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..f9910b60a5969127b3631941b46f1b683b590654 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/pos_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:09ffe7f305e2f6b7ec925361fb1f633ebe74815a8bb2d54d0e9a1f09869f8ae2 +size 168728 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/report_20260827_193248.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/report_20260827_193248.txt" new file mode 100644 index 0000000000000000000000000000000000000000..5a5854d6ec51e8113c7022ff691ba5b74c119808 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/report_20260827_193248.txt" @@ -0,0 +1,52 @@ +======================================================================== + Episode SLAM 对比 (视频压缩档) + 轨迹文件: online (/tmp/ep9cmp/episode_9.zip.new/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 以 episode_9.zip.new 为基准 +======================================================================== + +[各档质量] + episode_9.zip.new 帧数 148 时长 12.54s 路径 1.41m 最大位移 0.49m 跟踪 148/419.0 (35%) 最大间隙 5.2s + episode_9_crf28.zip.new 帧数 140 时长 11.28s 路径 1.27m 最大位移 0.29m 跟踪 140/419.0 (33%) 最大间隙 5.2s + episode_9_crf30.zip.new 帧数 104 时长 8.80s 路径 1.06m 最大位移 0.33m 跟踪 104/419.0 (25%) 最大间隙 5.1s + episode_9_crf34.zip.new 帧数 111 时长 9.80s 路径 2.29m 最大位移 1.01m 跟踪 111/419.0 (26%) 最大间隙 5.1s + episode_9_crf37.zip.new 帧数 109 时长 8.94s 路径 2.75m 最大位移 1.46m 跟踪 109/419.0 (26%) 最大间隙 5.1s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + episode_9.zip.new → episode_9_crf28.zip.new t 11.1mm/r 0.70° t 15.5mm/r 0.85° t 26.8mm/r 1.01° 17.6mm + episode_9.zip.new → episode_9_crf30.zip.new t 10.1mm/r 0.78° t 14.3mm/r 1.10° t 18.3mm/r 0.76° 17.7mm + episode_9.zip.new → episode_9_crf34.zip.new t 92.8mm/r 0.81° t 263.1mm/r 1.07° t 46.1mm/r 0.91° 339.9mm + episode_9.zip.new → episode_9_crf37.zip.new t 57.4mm/r 1.43° t 87.9mm/r 1.85° t 22.2mm/r 0.60° 176.0mm + + 最大偏差(公共时间轴上, 未对齐): + episode_9.zip.new → episode_9_crf28.zip.new 位置 9.8mm(均) / 116mm(峰) | 旋转 0.51°(均) / 3.4°(峰) + episode_9.zip.new → episode_9_crf30.zip.new 位置 6.5mm(均) / 139mm(峰) | 旋转 0.48°(均) / 5.5°(峰) + episode_9.zip.new → episode_9_crf34.zip.new 位置 144.7mm(均) / 1080mm(峰) | 旋转 0.65°(均) / 4.5°(峰) + episode_9.zip.new → episode_9_crf37.zip.new 位置 41.8mm(均) / 1371mm(峰) | 旋转 0.97°(均) / 13.0°(峰) + +======================================================================== + [总结] +======================================================================== + 对比基准: episode_9.zip.new + 对比对象: 5 档 → episode_9.zip.new, episode_9_crf28.zip.new, episode_9_crf30.zip.new, episode_9_crf34.zip.new, episode_9_crf37.zip.new + + 跟踪完整度排序 (输入 419.0 帧): + 1. episode_9.zip.new 35.3% (148/419.0) 最大间隙 5.2s + 2. episode_9_crf28.zip.new 33.4% (140/419.0) 最大间隙 5.2s + 3. episode_9_crf34.zip.new 26.5% (111/419.0) 最大间隙 5.1s + 4. episode_9_crf37.zip.new 26.0% (109/419.0) 最大间隙 5.1s + 5. episode_9_crf30.zip.new 24.8% (104/419.0) 最大间隙 5.1s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 更接近基准): + episode_9.zip.new → episode_9_crf30.zip.new RPE 10.1mm / 0.78° ATE 17.7mm + episode_9.zip.new → episode_9_crf28.zip.new RPE 11.1mm / 0.70° ATE 17.6mm + episode_9.zip.new → episode_9_crf37.zip.new RPE 57.4mm / 1.43° ATE 176.0mm + episode_9.zip.new → episode_9_crf34.zip.new RPE 92.8mm / 0.81° ATE 339.9mm + + → 与基准差异最小: episode_9.zip.new → episode_9_crf30.zip.new (RPE@0.5s 10.1mm, ATE 17.7mm) + → 与基准差异最大: episode_9.zip.new → episode_9_crf34.zip.new (RPE@0.5s 92.8mm, ATE 339.9mm) + + 结论: episode_9_crf30.zip.new 跟踪完整度仅 25%(最大间隙 5.1s), 压缩过大导致轨迹不可信, 不建议使用。 + 可用档位: episode_9.zip.new 完整度最高 (35%), 建议采用。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/rpe_bar.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/rpe_bar.png" new file mode 100644 index 0000000000000000000000000000000000000000..c06739441edbad0fd10234eaa8b0880748f3f219 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/rpe_bar.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d3cef9ab2cb06f7dd1baee87c384107d5d885d023818cd093db81e142447a62 +size 109996 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/summary.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/summary.txt" new file mode 100644 index 0000000000000000000000000000000000000000..5a5854d6ec51e8113c7022ff691ba5b74c119808 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/summary.txt" @@ -0,0 +1,52 @@ +======================================================================== + Episode SLAM 对比 (视频压缩档) + 轨迹文件: online (/tmp/ep9cmp/episode_9.zip.new/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 以 episode_9.zip.new 为基准 +======================================================================== + +[各档质量] + episode_9.zip.new 帧数 148 时长 12.54s 路径 1.41m 最大位移 0.49m 跟踪 148/419.0 (35%) 最大间隙 5.2s + episode_9_crf28.zip.new 帧数 140 时长 11.28s 路径 1.27m 最大位移 0.29m 跟踪 140/419.0 (33%) 最大间隙 5.2s + episode_9_crf30.zip.new 帧数 104 时长 8.80s 路径 1.06m 最大位移 0.33m 跟踪 104/419.0 (25%) 最大间隙 5.1s + episode_9_crf34.zip.new 帧数 111 时长 9.80s 路径 2.29m 最大位移 1.01m 跟踪 111/419.0 (26%) 最大间隙 5.1s + episode_9_crf37.zip.new 帧数 109 时长 8.94s 路径 2.75m 最大位移 1.46m 跟踪 109/419.0 (26%) 最大间隙 5.1s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + episode_9.zip.new → episode_9_crf28.zip.new t 11.1mm/r 0.70° t 15.5mm/r 0.85° t 26.8mm/r 1.01° 17.6mm + episode_9.zip.new → episode_9_crf30.zip.new t 10.1mm/r 0.78° t 14.3mm/r 1.10° t 18.3mm/r 0.76° 17.7mm + episode_9.zip.new → episode_9_crf34.zip.new t 92.8mm/r 0.81° t 263.1mm/r 1.07° t 46.1mm/r 0.91° 339.9mm + episode_9.zip.new → episode_9_crf37.zip.new t 57.4mm/r 1.43° t 87.9mm/r 1.85° t 22.2mm/r 0.60° 176.0mm + + 最大偏差(公共时间轴上, 未对齐): + episode_9.zip.new → episode_9_crf28.zip.new 位置 9.8mm(均) / 116mm(峰) | 旋转 0.51°(均) / 3.4°(峰) + episode_9.zip.new → episode_9_crf30.zip.new 位置 6.5mm(均) / 139mm(峰) | 旋转 0.48°(均) / 5.5°(峰) + episode_9.zip.new → episode_9_crf34.zip.new 位置 144.7mm(均) / 1080mm(峰) | 旋转 0.65°(均) / 4.5°(峰) + episode_9.zip.new → episode_9_crf37.zip.new 位置 41.8mm(均) / 1371mm(峰) | 旋转 0.97°(均) / 13.0°(峰) + +======================================================================== + [总结] +======================================================================== + 对比基准: episode_9.zip.new + 对比对象: 5 档 → episode_9.zip.new, episode_9_crf28.zip.new, episode_9_crf30.zip.new, episode_9_crf34.zip.new, episode_9_crf37.zip.new + + 跟踪完整度排序 (输入 419.0 帧): + 1. episode_9.zip.new 35.3% (148/419.0) 最大间隙 5.2s + 2. episode_9_crf28.zip.new 33.4% (140/419.0) 最大间隙 5.2s + 3. episode_9_crf34.zip.new 26.5% (111/419.0) 最大间隙 5.1s + 4. episode_9_crf37.zip.new 26.0% (109/419.0) 最大间隙 5.1s + 5. episode_9_crf30.zip.new 24.8% (104/419.0) 最大间隙 5.1s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 更接近基准): + episode_9.zip.new → episode_9_crf30.zip.new RPE 10.1mm / 0.78° ATE 17.7mm + episode_9.zip.new → episode_9_crf28.zip.new RPE 11.1mm / 0.70° ATE 17.6mm + episode_9.zip.new → episode_9_crf37.zip.new RPE 57.4mm / 1.43° ATE 176.0mm + episode_9.zip.new → episode_9_crf34.zip.new RPE 92.8mm / 0.81° ATE 339.9mm + + → 与基准差异最小: episode_9.zip.new → episode_9_crf30.zip.new (RPE@0.5s 10.1mm, ATE 17.7mm) + → 与基准差异最大: episode_9.zip.new → episode_9_crf34.zip.new (RPE@0.5s 92.8mm, ATE 339.9mm) + + 结论: episode_9_crf30.zip.new 跟踪完整度仅 25%(最大间隙 5.1s), 压缩过大导致轨迹不可信, 不建议使用。 + 可用档位: episode_9.zip.new 完整度最高 (35%), 建议采用。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/tracking_ok.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/tracking_ok.png" new file mode 100644 index 0000000000000000000000000000000000000000..e7272f2c06b46b299b24798116534bbd25ead9a1 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/tracking_ok.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ce556daca85e2cd0eb72695ffba3d3d09913fc792ba826986c7a45a7736eaee +size 62187 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_3d.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_3d.png" new file mode 100644 index 0000000000000000000000000000000000000000..b90dd2e5a0ec6399469dd97cd8b85d8634063450 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_3d.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0cf175b510b26a1b034ee255c712469a9c5548a5c1f4bdd1c5cdcc278003c4ba +size 309438 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_xy.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_xy.png" new file mode 100644 index 0000000000000000000000000000000000000000..efd10c07fcb7151e74f664d2dabfd34b1665d2fd --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_xy.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5a972321301f41cb71ff989a8ba44d44b5dc3ba5138cb25e26614c8ec53106c +size 114876 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_xz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_xz.png" new file mode 100644 index 0000000000000000000000000000000000000000..9ad09f4bbbd1d299708c14dbd8e649181ae2d35c --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_xz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88216b1414d768476b1bd316d3577282822e4d867bd1ce549b3562f38c569e01 +size 81667 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_yz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_yz.png" new file mode 100644 index 0000000000000000000000000000000000000000..e2db12dfcf6b0b980c81e48d8488cb2a5f3b457c --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260827_193248/traj_yz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d3bbc5d107ca632fcf258a6a3f702b0583796e671b3dd73ce736474659fbb4d +size 81176 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/_template.html" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/_template.html" new file mode 100644 index 0000000000000000000000000000000000000000..e364d38ba8e566645ab807b7f4d0c37d12248b3c --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/_template.html" @@ -0,0 +1,306 @@ +episode_9 · CRF 五档对比 + + + + + +
+
EPISODE SLAM · CRF 轨迹对比
+
+ EPISODE_913.8 s419 输入帧2026-08-28 更新数据 +
+
+ +
+ +
+
同一段录制 · 四档视频压缩 + 原档 · 离线 SLAM 轨迹逐帧对比
+

全档跟踪 ≥77%,CRF 28 与原档几乎重合,CRF 34 依然最差

+

更新后的数据:同一段 13.8 秒录制,视频分别以 CRF 28/30/34/37 压缩后跑离线 SLAM, + 轨迹与基准(原档)在同一时间轴上逐帧对比。跟踪完整度全面回到正常水平(77%–88%), + 但压缩档的轨迹劣化仍非单调——CRF 34 的 ATE 比 CRF 37 还差 5 倍。

+
+ +
+
+
29.2 mm
+
与基准最接近 · CRF28
+
ATE 29.2mm · RPE@0.5s 25.0mm · 跟踪 88.3%(略高于原档的 87.1%)
+
+
+
234.6 mm
+
与基准偏离最大 · CRF34
+
ATE 234.6mm · 峰偏 569mm —— 比 CRF37(42.1mm)反而差 5.6 倍
+
+
+
87.1 %
+
基准本身跟踪率
+
365/419 帧 · 最大间隙仅 0.7s —— 更新后数据跟踪质量正常
+
+
+ +
+
+ 01

各档质量

+ trajectory_online_style.txt · tracking.csv +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
档位轨迹帧数时长 (s)路径 (m)最大位移 (m)跟踪 OK完整度最大间隙 (s)
原档(基准)36513.845.090.42365/41987.1%0.7
CRF 2837013.844.220.46370/41988.3%0.6
CRF 3032413.843.680.48324/41977.3%0.7
CRF 3435313.842.240.49353/41984.2%1.2
CRF 3736713.844.340.46367/41987.6%0.6
+
+ +
+
+ 02

与基准差异

+ RPE 位移 mm · 旋转 ° · ATE Umeyama 对齐后残差 +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
基准 → 被测RPE@0.5sRPE@1.0sRPE@2.0sATE RMSE (mm)峰偏 (mm)判定
原档 → CRF 2825.0 / 2.67°27.8 / 2.90°31.9 / 3.72°29.2128良好
原档 → CRF 3033.6 / 2.64°48.1 / 3.84°46.0 / 4.90°57.5319可用
原档 → CRF 3449.6 / 4.12°70.2 / 5.34°107.0 / 7.21°234.6569明显劣化
原档 → CRF 3733.0 / 3.00°37.1 / 3.33°41.1 / 4.32°42.1195可用
+ +
+
观察 · 非单调 · 与旧数据一致
+

压缩档的劣化不是单调的:CRF 34(ATE 234.6mm)比 CRF 37(42.1mm)差 5 倍以上, + 这一点与上一批数据(CRF 34 同样垫底)吻合——CRF 34 这一档对 SLAM 的破坏有可复现性,不是随机扰动。 + 轨迹帧数方面 CRF 30 只有 324/419(77%),是跟踪损失最大的一档。 + 实用结论:CRF 28 与原档几乎无差别(ATE ≈ 29mm),可直接替代原档;CRF 37 亦可接受; + CRF 30/34 应避免。压缩率与轨迹代价之间不存在单调关系,选档必须逐档实测。

+
+
+ +
+
+ 03

图表

+ matplotlib · 图例颜色与上文档位色一致 +
+
+
+
五档 SLAM 轨迹三维叠加
+
FIG.01三维轨迹叠加 —— 34 在尾段漂出,28/37 与基准贴合
+
+
+
俯视 XY 轨迹
+
FIG.02俯视 XY
+
+
+
侧视 XZ 轨迹
+
FIG.03侧视 XZ
+
+
+
侧视 YZ 轨迹
+
FIG.04侧视 YZ
+
+
+
平均 RPE 柱状图
+
FIG.05平均 RPE(Δ=1.0s)
+
+
+
跟踪完整度柱状图
+
FIG.06跟踪完整度
+
+
+
逐帧偏差时间曲线
+
FIG.07公共时间轴逐帧偏差(上:位置 mm,下:旋转 °)
+
+
+
位姿分量时间曲线
+
FIG.08XYZ 分量 vs 时间(相对各自起点)
+
+
+
+ +
+ 工具 analyze_episode_crf.py(RPE / ATE / 逐帧偏差) + 数据 2026-08-28 更新 · trajectory_online_style.txt + 输出 crf_report/run_20260828_1026 +
+ +
diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/comparison.html" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/comparison.html" new file mode 100644 index 0000000000000000000000000000000000000000..a260a84a5e5f40636c369ecfa2bcff22fa6dcd6f --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/comparison.html" @@ -0,0 +1,306 @@ +episode_9 · CRF 五档对比 + + + + + +
+
EPISODE SLAM · CRF 轨迹对比
+
+ EPISODE_913.8 s419 输入帧2026-08-28 更新数据 +
+
+ +
+ +
+
同一段录制 · 四档视频压缩 + 原档 · 离线 SLAM 轨迹逐帧对比
+

全档跟踪 ≥77%,CRF 28 与原档几乎重合,CRF 34 依然最差

+

更新后的数据:同一段 13.8 秒录制,视频分别以 CRF 28/30/34/37 压缩后跑离线 SLAM, + 轨迹与基准(原档)在同一时间轴上逐帧对比。跟踪完整度全面回到正常水平(77%–88%), + 但压缩档的轨迹劣化仍非单调——CRF 34 的 ATE 比 CRF 37 还差 5 倍。

+
+ +
+
+
29.2 mm
+
与基准最接近 · CRF28
+
ATE 29.2mm · RPE@0.5s 25.0mm · 跟踪 88.3%(略高于原档的 87.1%)
+
+
+
234.6 mm
+
与基准偏离最大 · CRF34
+
ATE 234.6mm · 峰偏 569mm —— 比 CRF37(42.1mm)反而差 5.6 倍
+
+
+
87.1 %
+
基准本身跟踪率
+
365/419 帧 · 最大间隙仅 0.7s —— 更新后数据跟踪质量正常
+
+
+ +
+
+ 01

各档质量

+ trajectory_online_style.txt · tracking.csv +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
档位轨迹帧数时长 (s)路径 (m)最大位移 (m)跟踪 OK完整度最大间隙 (s)
原档(基准)36513.845.090.42365/41987.1%0.7
CRF 2837013.844.220.46370/41988.3%0.6
CRF 3032413.843.680.48324/41977.3%0.7
CRF 3435313.842.240.49353/41984.2%1.2
CRF 3736713.844.340.46367/41987.6%0.6
+
+ +
+
+ 02

与基准差异

+ RPE 位移 mm · 旋转 ° · ATE Umeyama 对齐后残差 +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
基准 → 被测RPE@0.5sRPE@1.0sRPE@2.0sATE RMSE (mm)峰偏 (mm)判定
原档 → CRF 2825.0 / 2.67°27.8 / 2.90°31.9 / 3.72°29.2128良好
原档 → CRF 3033.6 / 2.64°48.1 / 3.84°46.0 / 4.90°57.5319可用
原档 → CRF 3449.6 / 4.12°70.2 / 5.34°107.0 / 7.21°234.6569明显劣化
原档 → CRF 3733.0 / 3.00°37.1 / 3.33°41.1 / 4.32°42.1195可用
+ +
+
观察 · 非单调 · 与旧数据一致
+

压缩档的劣化不是单调的:CRF 34(ATE 234.6mm)比 CRF 37(42.1mm)差 5 倍以上, + 这一点与上一批数据(CRF 34 同样垫底)吻合——CRF 34 这一档对 SLAM 的破坏有可复现性,不是随机扰动。 + 轨迹帧数方面 CRF 30 只有 324/419(77%),是跟踪损失最大的一档。 + 实用结论:CRF 28 与原档几乎无差别(ATE ≈ 29mm),可直接替代原档;CRF 37 亦可接受; + CRF 30/34 应避免。压缩率与轨迹代价之间不存在单调关系,选档必须逐档实测。

+
+
+ +
+
+ 03

图表

+ matplotlib · 图例颜色与上文档位色一致 +
+
+
+
五档 SLAM 轨迹三维叠加
+
FIG.01三维轨迹叠加 —— 34 在尾段漂出,28/37 与基准贴合
+
+
+
俯视 XY 轨迹
+
FIG.02俯视 XY
+
+
+
侧视 XZ 轨迹
+
FIG.03侧视 XZ
+
+
+
侧视 YZ 轨迹
+
FIG.04侧视 YZ
+
+
+
平均 RPE 柱状图
+
FIG.05平均 RPE(Δ=1.0s)
+
+
+
跟踪完整度柱状图
+
FIG.06跟踪完整度
+
+
+
逐帧偏差时间曲线
+
FIG.07公共时间轴逐帧偏差(上:位置 mm,下:旋转 °)
+
+
+
位姿分量时间曲线
+
FIG.08XYZ 分量 vs 时间(相对各自起点)
+
+
+
+ +
+ 工具 analyze_episode_crf.py(RPE / ATE / 逐帧偏差) + 数据 2026-08-28 更新 · trajectory_online_style.txt + 输出 crf_report/run_20260828_1026 +
+ +
diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/dev_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/dev_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..528a3e1dbf83d15891fbece6e339cd06aa1d8996 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/dev_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55838ebd50b02599aa29fd25f871c6c66f72d889c482fb9b47aecd80408f0484 +size 244540 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/pos_vs_time.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/pos_vs_time.png" new file mode 100644 index 0000000000000000000000000000000000000000..91037360304de400b1ab7fe7a2488fabe8ab3dd5 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/pos_vs_time.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e517dd2c0333748f5b58081816076099ac47ae9b147c9cd267a67cd5bc9dbab3 +size 303722 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/report_20260828_102634.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/report_20260828_102634.txt" new file mode 100644 index 0000000000000000000000000000000000000000..1107fe45281fb48d7924757001741000e53c018e --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/report_20260828_102634.txt" @@ -0,0 +1,51 @@ +======================================================================== + Episode 9 SLAM 对比 (更新数据 2026-08-28) + 轨迹文件: online (/tmp/ep9cmp2/episode_9/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 以 episode_9 为基准 +======================================================================== + +[各档质量] + episode_9 帧数 365 时长 13.84s 路径 5.09m 最大位移 0.42m 跟踪 365/419.0 (87%) 最大间隙 0.7s + episode_9_crf28 帧数 370 时长 13.84s 路径 4.22m 最大位移 0.46m 跟踪 370/419.0 (88%) 最大间隙 0.6s + episode_9_crf30 帧数 324 时长 13.84s 路径 3.68m 最大位移 0.48m 跟踪 324/419.0 (77%) 最大间隙 0.7s + episode_9_crf34 帧数 353 时长 13.84s 路径 2.24m 最大位移 0.49m 跟踪 353/419.0 (84%) 最大间隙 1.2s + episode_9_crf37 帧数 367 时长 13.84s 路径 4.34m 最大位移 0.46m 跟踪 367/419.0 (88%) 最大间隙 0.6s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + episode_9 → episode_9_crf28 t 25.0mm/r 2.67° t 27.8mm/r 2.90° t 31.9mm/r 3.72° 29.2mm + episode_9 → episode_9_crf30 t 33.6mm/r 2.64° t 48.1mm/r 3.84° t 46.0mm/r 4.90° 57.5mm + episode_9 → episode_9_crf34 t 49.6mm/r 4.12° t 70.2mm/r 5.34° t 107.0mm/r 7.21° 234.6mm + episode_9 → episode_9_crf37 t 33.0mm/r 3.00° t 37.1mm/r 3.33° t 41.1mm/r 4.32° 42.1mm + + 最大偏差(公共时间轴上, 未对齐): + episode_9 → episode_9_crf28 位置 17.6mm(均) / 128mm(峰) | 旋转 1.97°(均) / 20.3°(峰) + episode_9 → episode_9_crf30 位置 25.5mm(均) / 319mm(峰) | 旋转 2.58°(均) / 33.3°(峰) + episode_9 → episode_9_crf34 位置 223.9mm(均) / 569mm(峰) | 旋转 18.03°(均) / 43.7°(峰) + episode_9 → episode_9_crf37 位置 23.3mm(均) / 195mm(峰) | 旋转 2.52°(均) / 26.9°(峰) + +======================================================================== + [总结] +======================================================================== + 对比基准: episode_9 + 对比对象: 5 档 → episode_9, episode_9_crf28, episode_9_crf30, episode_9_crf34, episode_9_crf37 + + 跟踪完整度排序 (输入 419.0 帧): + 1. episode_9_crf28 88.3% (370/419.0) 最大间隙 0.6s + 2. episode_9_crf37 87.6% (367/419.0) 最大间隙 0.6s + 3. episode_9 87.1% (365/419.0) 最大间隙 0.7s + 4. episode_9_crf34 84.2% (353/419.0) 最大间隙 1.2s + 5. episode_9_crf30 77.3% (324/419.0) 最大间隙 0.7s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 更接近基准): + episode_9 → episode_9_crf28 RPE 25.0mm / 2.67° ATE 29.2mm + episode_9 → episode_9_crf37 RPE 33.0mm / 3.00° ATE 42.1mm + episode_9 → episode_9_crf30 RPE 33.6mm / 2.64° ATE 57.5mm + episode_9 → episode_9_crf34 RPE 49.6mm / 4.12° ATE 234.6mm + + → 与基准差异最小: episode_9 → episode_9_crf28 (RPE@0.5s 25.0mm, ATE 29.2mm) + → 与基准差异最大: episode_9 → episode_9_crf34 (RPE@0.5s 49.6mm, ATE 234.6mm) + + 结论: 各档位跟踪完整度基本可用 (最低 episode_9_crf30 77%), 存在轻微跟踪损失, 建议在可接受误差内选择压缩率更高的一档。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/rpe_bar.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/rpe_bar.png" new file mode 100644 index 0000000000000000000000000000000000000000..b00edce6098ad73aa2b4951837666b23a30563f2 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/rpe_bar.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef4661fbf3406cc1a00469ab99c94789243e7275e6ebd263d0d52c5c38f25f1e +size 85722 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/summary.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/summary.txt" new file mode 100644 index 0000000000000000000000000000000000000000..1107fe45281fb48d7924757001741000e53c018e --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/summary.txt" @@ -0,0 +1,51 @@ +======================================================================== + Episode 9 SLAM 对比 (更新数据 2026-08-28) + 轨迹文件: online (/tmp/ep9cmp2/episode_9/episode_0000/results/trajectory/trajectory_online_style.txt) + 对比模式: 以 episode_9 为基准 +======================================================================== + +[各档质量] + episode_9 帧数 365 时长 13.84s 路径 5.09m 最大位移 0.42m 跟踪 365/419.0 (87%) 最大间隙 0.7s + episode_9_crf28 帧数 370 时长 13.84s 路径 4.22m 最大位移 0.46m 跟踪 370/419.0 (88%) 最大间隙 0.6s + episode_9_crf30 帧数 324 时长 13.84s 路径 3.68m 最大位移 0.48m 跟踪 324/419.0 (77%) 最大间隙 0.7s + episode_9_crf34 帧数 353 时长 13.84s 路径 2.24m 最大位移 0.49m 跟踪 353/419.0 (84%) 最大间隙 1.2s + episode_9_crf37 帧数 367 时长 13.84s 路径 4.34m 最大位移 0.46m 跟踪 367/419.0 (88%) 最大间隙 0.6s + + +[轨迹对比] (基准 → 被测; 位移 RPE 单位 mm, 旋转 RPE 单位 °) + 基准 → 被测 Δ=0.5s Δ=1.0s Δ=2.0s ATE RMSE + episode_9 → episode_9_crf28 t 25.0mm/r 2.67° t 27.8mm/r 2.90° t 31.9mm/r 3.72° 29.2mm + episode_9 → episode_9_crf30 t 33.6mm/r 2.64° t 48.1mm/r 3.84° t 46.0mm/r 4.90° 57.5mm + episode_9 → episode_9_crf34 t 49.6mm/r 4.12° t 70.2mm/r 5.34° t 107.0mm/r 7.21° 234.6mm + episode_9 → episode_9_crf37 t 33.0mm/r 3.00° t 37.1mm/r 3.33° t 41.1mm/r 4.32° 42.1mm + + 最大偏差(公共时间轴上, 未对齐): + episode_9 → episode_9_crf28 位置 17.6mm(均) / 128mm(峰) | 旋转 1.97°(均) / 20.3°(峰) + episode_9 → episode_9_crf30 位置 25.5mm(均) / 319mm(峰) | 旋转 2.58°(均) / 33.3°(峰) + episode_9 → episode_9_crf34 位置 223.9mm(均) / 569mm(峰) | 旋转 18.03°(均) / 43.7°(峰) + episode_9 → episode_9_crf37 位置 23.3mm(均) / 195mm(峰) | 旋转 2.52°(均) / 26.9°(峰) + +======================================================================== + [总结] +======================================================================== + 对比基准: episode_9 + 对比对象: 5 档 → episode_9, episode_9_crf28, episode_9_crf30, episode_9_crf34, episode_9_crf37 + + 跟踪完整度排序 (输入 419.0 帧): + 1. episode_9_crf28 88.3% (370/419.0) 最大间隙 0.6s + 2. episode_9_crf37 87.6% (367/419.0) 最大间隙 0.6s + 3. episode_9 87.1% (365/419.0) 最大间隙 0.7s + 4. episode_9_crf34 84.2% (353/419.0) 最大间隙 1.2s + 5. episode_9_crf30 77.3% (324/419.0) 最大间隙 0.7s + + 轨迹差异 (以 RPE@0.5s 平移排序, 低 = 更接近基准): + episode_9 → episode_9_crf28 RPE 25.0mm / 2.67° ATE 29.2mm + episode_9 → episode_9_crf37 RPE 33.0mm / 3.00° ATE 42.1mm + episode_9 → episode_9_crf30 RPE 33.6mm / 2.64° ATE 57.5mm + episode_9 → episode_9_crf34 RPE 49.6mm / 4.12° ATE 234.6mm + + → 与基准差异最小: episode_9 → episode_9_crf28 (RPE@0.5s 25.0mm, ATE 29.2mm) + → 与基准差异最大: episode_9 → episode_9_crf34 (RPE@0.5s 49.6mm, ATE 234.6mm) + + 结论: 各档位跟踪完整度基本可用 (最低 episode_9_crf30 77%), 存在轻微跟踪损失, 建议在可接受误差内选择压缩率更高的一档。 + diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/tracking_ok.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/tracking_ok.png" new file mode 100644 index 0000000000000000000000000000000000000000..1615441530d6bef06ae454c6dcb9c78a63be7b92 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/tracking_ok.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df93e5b89bd6ff349b839c77c2177ca6b495c3e1a713a94f32063dd5b35b85f8 +size 57123 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_3d.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_3d.png" new file mode 100644 index 0000000000000000000000000000000000000000..0219dd5d955a7603095ddb4b2ded5ceb20f8971d --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_3d.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18ba4d60a7d81c21636a65ed1e27b49d3d0bd60aa91728b1d1bc01d62097b682 +size 396256 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_xy.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_xy.png" new file mode 100644 index 0000000000000000000000000000000000000000..c7d256851ea4669770b4d723c273d8517541bf99 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_xy.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1425572bad578000398527a03309bf3ffa0263a56e1f3600b7b16d14feec75c5 +size 126419 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_xz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_xz.png" new file mode 100644 index 0000000000000000000000000000000000000000..c7f4a7e7ec399c4528cfd7e050d677d1cf8e0846 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_xz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9b5cd8291adbf61626c2895bfa5628f9a4e9b63f2e4587d0f0f3bf521368859 +size 235524 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_yz.png" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_yz.png" new file mode 100644 index 0000000000000000000000000000000000000000..2f071e4c06b11abb0ee59f87e9eb4d1fdf7e7e47 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/crf_report/run_20260828_1026/run_20260828_102634/traj_yz.png" @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc7e16e89efdf9bb36ae8dc2590ab59093144f1bbbbdc5ba9c44db3fe94a58d5 +size 165946 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/requirements.txt" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/requirements.txt" new file mode 100644 index 0000000000000000000000000000000000000000..167fddae18922da3015c76b3018836df35dcccf3 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/requirements.txt" @@ -0,0 +1,2 @@ +numpy>=1.20 +matplotlib>=3.3 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/run.sh" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/run.sh" new file mode 100755 index 0000000000000000000000000000000000000000..c693a4449a073c8af60faa758a0766feca5e5c6b --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/run.sh" @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# ============================================================ +# Episode SLAM 轨迹对比分析 - 一键运行脚本 (Linux / macOS) +# 首次运行自动创建 .venv 并安装依赖, 之后直接可用。 +# ============================================================ +set -e +cd "$(dirname "$0")" + +PY=python3 +VENV=.venv + +if [ ! -d "$VENV" ]; then + echo "[init] 创建虚拟环境 $VENV ..." + $PY -m venv "$VENV" + "$VENV/bin/pip" install --upgrade pip -q + "$VENV/bin/pip" install -r requirements.txt -q + echo "[init] 依赖安装完成" +fi + +if [ $# -lt 1 ]; then + echo "用法: ./run.sh [ ...] [选项]" + echo + echo "示例:" + echo " ./run.sh /data/episode_00009.zip.new /data/episode_00009_crf30.zip.new --plot" + echo " ./run.sh A B C --ref A --plot # 指定基准" + echo " ./run.sh A B --outdir 输出报告 --plot # 自定义输出目录" + echo + echo "全部选项见 使用说明.md" + exit 1 +fi + +"$VENV/bin/python" analyze_episode_crf.py "$@" diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/\344\275\277\347\224\250\350\257\264\346\230\216.md" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/\344\275\277\347\224\250\350\257\264\346\230\216.md" new file mode 100644 index 0000000000000000000000000000000000000000..61fa3cd069c1c064df0975c50e4e47780da4cbe2 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/\344\275\277\347\224\250\350\257\264\346\230\216.md" @@ -0,0 +1,100 @@ +# Episode SLAM 轨迹对比分析工具 + +对比**同一段录制、不同处理参数**(如不同视频压缩 CRF)得到的 SLAM 轨迹, +量化轨迹间差异:RPE / ATE / 逐帧偏差 / 跟踪完整度。 + +## 目录内容 +| 文件 | 作用 | +|---|---| +| `analyze_episode_crf.py` | 分析主程序(纯 Python, 单文件) | +| `run.sh` | Linux / macOS 一键运行脚本(自动装依赖) | +| `运行(Windows).bat` | Windows 一键运行脚本 | +| `requirements.txt` | 依赖清单 | +| `使用说明.md` | 本文件 | + +## 环境要求 +- Python 3.8+ +- 依赖: `numpy`、`matplotlib`(首次运行会自动安装) + +## 快速开始 + +**Linux / macOS** +```bash +./run.sh /路径/episode_00009.zip.new /路径/episode_00009_crf30.zip.new --plot +``` +首次运行会在本目录创建 `.venv` 虚拟环境并自动安装依赖,之后每次直接运行。 + +**Windows** +双击 `运行(Windows).bat`,按提示输入 episode 目录; +或把 episode 目录直接拖到 `运行(Windows).bat` 上。 +也可手动: +```bat +python analyze_episode_crf.py D:\data\episode_00009.zip.new D:\data\episode_00009_crf30.zip.new --plot +``` + +## 用法 + +``` +python analyze_episode_crf.py [ ...] [选项] +``` + +- 需要 **1 个以上** episode 目录;目录内须含 `results/trajectory/` + (传 `episode_XXXX` 或其父目录均可,自动定位)。 +- 典型的三档对比: + ``` + ./run.sh /data/episode_00009.zip.new /data/episode_00009_crf30.zip.new /data/episode_00009_crf37.zip.new --plot + ``` + +## 选项 + +| 选项 | 说明 | +|---|---| +| `--ref <目录>` | 指定基准目录;不指定则**两两对比**(无预设基准) | +| `--traj online\|tum\|body` | 轨迹文件类型,默认 `online` | +| `--deltas 0.5 1.0 2.0` | RPE 时间增量(秒),默认 `0.5 1.0 2.0` | +| `--outdir <目录>` | 输出根目录,默认 `crf_report` | +| `--plot` | 生成可视化图 | +| `--title "文本"` | 图标题前缀 | + +**示例** +```bash +# 指定基准 +./run.sh /data/A /data/B /data/C --ref /data/A --plot +# 只出文字报告, 不用图 +./run.sh /data/A /data/B +# 自定义输出目录 +./run.sh /data/A /data/B --outdir 输出报告 --plot +``` + +## 输出 + +**每次运行自动新建独立子目录 `run_<时间戳>/`,历史结果不会被覆盖**,可随时回看。 + +``` +输出根目录/ +└── run_20260827_154805/ + ├── report_20260827_154805.txt # 完整文字报告(各档质量 + 逐对对比 + [总结]结论) + ├── summary.txt # 与报告内容相同,方便直接打开 + ├── traj_3d.png # 3D 轨迹叠加 + ├── traj_xy.png / traj_xz.png / traj_yz.png + ├── pos_vs_time.png # XYZ 分量随时间变化 + ├── dev_vs_time.png # 逐帧偏差时间曲线 + ├── rpe_bar.png # RPE 柱状图 + └── tracking_ok.png # 跟踪完整度柱状图 +``` + +## 指标说明 +- **RPE**(相对位姿误差):每隔 `Δ` 秒比较两条轨迹的帧间相对运动一致程度。平移单位 mm、旋转单位 °。衡量"两条轨迹的运动是否一致",无需坐标系对齐。 +- **ATE**(绝对轨迹误差):Umeyama 刚体对齐后的平移残差(mm),衡量整条轨迹的贴合程度。 +- **跟踪完整度**:SLAM 成功跟踪的帧占比(2 = 跟踪OK / 输入帧数)。 +- **最大间隙**:轨迹中相邻样本的最大时间间隔(s),即跟丢时长。 + +## 常见问题 +**Q: 图中文字显示为方框?** +A: 系统缺少中文字体。安装 Noto Sans CJK(如 `sudo apt install fonts-noto-cjk`)即可,不影响数值。 + +**Q: 报错找不到 `results/trajectory/`?** +A: 传入的目录必须是 episode 目录,或包含 `episode_*` 子目录的父目录。 + +**Q: 想换输出目录但不想每次删旧文件?** +A: 不需要删。每次运行都是新的 `run_<时间戳>/`,旧结果自动保留。 diff --git "a/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/\350\277\220\350\241\214(Windows).bat" "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/\350\277\220\350\241\214(Windows).bat" new file mode 100644 index 0000000000000000000000000000000000000000..31af6ed6cb8281f7b7c371105f3db9ec549ddc12 --- /dev/null +++ "b/collector/tools/Episode_SLAM\345\257\271\346\257\224\345\210\206\346\236\220/\350\277\220\350\241\214(Windows).bat" @@ -0,0 +1,36 @@ +@echo off +rem ============================================================ +rem Episode SLAM 轨迹对比分析 - 一键运行脚本 (Windows) +rem 需要已安装 Python 3; 首次运行自动安装 numpy/matplotlib。 +rem 用法: 双击后输入 episode 目录, 或拖拽目录到本文件上。 +rem ============================================================ +cd /d "%~dp0" + +where python >nul 2>nul +if errorlevel 1 ( + echo [错误] 未找到 python, 请先安装 Python 3 并勾选 Add to PATH + pause + exit /b 1 +) + +echo [init] 检查/安装依赖 ... +python -m pip install -r requirements.txt --quiet +if errorlevel 1 ( + echo [错误] 依赖安装失败, 请检查网络 + pause + exit /b 1 +) + +if "%~1"=="" ( + echo 用法: python analyze_episode_crf.py ^ [^ ...] [选项] + echo 示例: python analyze_episode_crf.py D:\data\episode_00009.zip.new D:\data\episode_00009_crf30.zip.new --plot + echo. + echo 直接输入要对比的 episode 目录(用空格隔开), 或拖拽目录到本 bat 上: + set /p ARGS=episode 目录: +) else ( + set ARGS=%* +) + +python analyze_episode_crf.py %ARGS% +echo. +pause diff --git a/collector/tools/demos/HSV_Visualizer_V4.4.1.py b/collector/tools/demos/HSV_Visualizer_V4.4.1.py new file mode 100755 index 0000000000000000000000000000000000000000..a611be0f9f93cf2e10e6fbb8a0c1a9b895f2c6b0 --- /dev/null +++ b/collector/tools/demos/HSV_Visualizer_V4.4.1.py @@ -0,0 +1,1189 @@ +import sys +import platform +import cv2 +import numpy as np +from collections import deque +from PyQt5.QtWidgets import (QApplication, QWidget, QLabel, QPushButton, + QVBoxLayout, QHBoxLayout, QInputDialog, QMessageBox, + QDialog, QSlider, QFormLayout, QGroupBox, QSizePolicy) +from PyQt5.QtCore import QTimer, Qt +from PyQt5.QtGui import QImage, QPixmap +from PyQt5.QtWidgets import QCheckBox, QSpinBox, QDoubleSpinBox + +# HSV_Visualizer_V4.4.1 //复刻 sightac 热力图完整链路 + Hue曲线 + 传感器ROI裁切 + +# ================= 平台检测 ================= +# Windows=DirectShow, Linux=V4L2, 其他(macOS等)=自动选择 +IS_WINDOWS = platform.system() == 'Windows' +IS_LINUX = platform.system() == 'Linux' +if IS_WINDOWS: + CAP_BACKEND = cv2.CAP_DSHOW +elif IS_LINUX: + CAP_BACKEND = cv2.CAP_V4L2 +else: + CAP_BACKEND = cv2.CAP_ANY # macOS 等使用默认后端 + + +def open_camera(port): + """打开摄像头;Linux 下固定使用 V4L2 + MJPG 640x480@30fps。""" + backend = cv2.CAP_V4L2 if IS_LINUX else CAP_BACKEND + cap = cv2.VideoCapture(port, backend) + + if IS_LINUX and cap.isOpened(): + cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*"MJPG")) + cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) + cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) + cap.set(cv2.CAP_PROP_FPS, 30) + + return cap +# ================= 相机参数定义 ================= +# OpenCV CAP_PROP 映射 + 滑块范围 +CAM_PARAMS = [ + ("亮度 (Brightness)", cv2.CAP_PROP_BRIGHTNESS, 0, 255, 10), + ("对比度 (Contrast)", cv2.CAP_PROP_CONTRAST, 0, 255, 10), + ("色调 (Hue)", cv2.CAP_PROP_HUE, 0, 180, 0), + ("饱和度 (Saturation)", cv2.CAP_PROP_SATURATION, 0, 255, 64), + ("锐度 (Sharpness)", cv2.CAP_PROP_SHARPNESS, 0, 255, 0), + ("伽马 (Gamma)", cv2.CAP_PROP_GAMMA, 1, 500, 100), + ("增益 (Gain)", cv2.CAP_PROP_GAIN, 16, 248, 16), + ("曝光 (Exposure)", cv2.CAP_PROP_EXPOSURE, -13, -1, -5), + ("白平衡 (WB Temp)", cv2.CAP_PROP_WB_TEMPERATURE, 2800, 6500, 4600), +] + +# 自动重连参数 +AUTO_RECONNECT_THRESHOLD = 30 # 连续失败30帧(~1秒)触发自动重连 +RETRY_INTERVAL_FRAMES = 67 # 重连失败后每~2秒重试一次(67帧×30ms) + +# ================= 独立的 ROI 设置弹窗 ================= +class ROIDialog(QDialog): + def __init__(self, parent=None): + super().__init__(parent) + self.setWindowTitle("ROI 详细设置") + self.setFixedSize(350, 480) + self.parent = parent + + # 保存一份默认参数,用于重置功能 + self.default_params = { + 'r1_x': 275, 'r1_y': 320, 'r1_w': 50, 'r1_h': 55, + 'r2_x': 275, 'r2_y': 120, 'r2_w': 50, 'r2_h': 55 + } + + layout = QVBoxLayout() + + # --- 分组 1: 绿色 ROI 1 --- + group1 = QGroupBox("ROI 1 (绿色区域)") + form1 = QFormLayout() + self.r1_x, self.lbl_1x, lay1_x = self.create_slider_with_label(0, 640, parent.roi_params['r1_x']) + self.r1_y, self.lbl_1y, lay1_y = self.create_slider_with_label(0, 480, parent.roi_params['r1_y']) + self.r1_w, self.lbl_1w, lay1_w = self.create_slider_with_label(1, 320, parent.roi_params['r1_w']) + self.r1_h, self.lbl_1h, lay1_h = self.create_slider_with_label(1, 240, parent.roi_params['r1_h']) + form1.addRow("X 坐标:", lay1_x) + form1.addRow("Y 坐标:", lay1_y) + form1.addRow("宽度:", lay1_w) + form1.addRow("高度:", lay1_h) + group1.setLayout(form1) + + # --- 分组 2: 红色 ROI 2 --- + group2 = QGroupBox("ROI 2 (红色区域)") + form2 = QFormLayout() + self.r2_x, self.lbl_2x, lay2_x = self.create_slider_with_label(0, 640, parent.roi_params['r2_x']) + self.r2_y, self.lbl_2y, lay2_y = self.create_slider_with_label(0, 480, parent.roi_params['r2_y']) + self.r2_w, self.lbl_2w, lay2_w = self.create_slider_with_label(1, 640, parent.roi_params['r2_w']) + self.r2_h, self.lbl_2h, lay2_h = self.create_slider_with_label(1, 480, parent.roi_params['r2_h']) + form2.addRow("X 坐标:", lay2_x) + form2.addRow("Y 坐标:", lay2_y) + form2.addRow("宽度:", lay2_w) + form2.addRow("高度:", lay2_h) + group2.setLayout(form2) + + layout.addWidget(group1) + layout.addWidget(group2) + + # --- 重置按钮 --- + self.btn_reset = QPushButton("重置为默认参数") + self.btn_reset.clicked.connect(self.reset_to_defaults) + layout.addWidget(self.btn_reset) + + self.setLayout(layout) + + def create_slider_with_label(self, min_val, max_val, default_val): + container = QWidget() + h_layout = QHBoxLayout(container) + h_layout.setContentsMargins(0, 0, 0, 0) + + slider = QSlider(Qt.Horizontal) + slider.setMinimum(min_val) + slider.setMaximum(max_val) + slider.setValue(default_val) + + label = QLabel(str(default_val)) + label.setFixedWidth(35) + label.setAlignment(Qt.AlignRight | Qt.AlignVCenter) + + h_layout.addWidget(slider) + h_layout.addWidget(label) + + slider.valueChanged.connect(lambda val, l=label: self.on_slider_changed(val, l)) + return slider, label, container + + def on_slider_changed(self, val, label): + label.setText(str(val)) + self.update_params() + + def update_params(self): + self.parent.roi_params = { + 'r1_x': self.r1_x.value(), 'r1_y': self.r1_y.value(), + 'r1_w': self.r1_w.value(), 'r1_h': self.r1_h.value(), + 'r2_x': self.r2_x.value(), 'r2_y': self.r2_y.value(), + 'r2_w': self.r2_w.value(), 'r2_h': self.r2_h.value() + } + + def reset_to_defaults(self): + self.r1_x.setValue(self.default_params['r1_x']) + self.r1_y.setValue(self.default_params['r1_y']) + self.r1_w.setValue(self.default_params['r1_w']) + self.r1_h.setValue(self.default_params['r1_h']) + + self.r2_x.setValue(self.default_params['r2_x']) + self.r2_y.setValue(self.default_params['r2_y']) + self.r2_w.setValue(self.default_params['r2_w']) + self.r2_h.setValue(self.default_params['r2_h']) + + +# ================= 相机参数设置弹窗 ================= +class CameraParamsDialog(QDialog): + """弹窗式相机参数调节,滑块拖动实时写入 cv2.VideoCapture""" + def __init__(self, parent=None): + super().__init__(parent) + self.setWindowTitle("相机参数设置") + self.setFixedSize(550, 450) + self.parent = parent + + layout = QVBoxLayout() + + grp = QGroupBox("实时参数调节(拖动滑块即时生效)") + form = QFormLayout() + + self._sliders = {} + self._spinboxes = {} + self._updating = False # 防循环 + + for label, prop_id, lo, hi, default in CAM_PARAMS: + # 读取相机当前值(Linux V4L2 和 Windows DirectShow 范围不同) + try: + cur_val = int(parent.cap.get(prop_id)) if parent.cap.isOpened() else default + except Exception: + cur_val = default + + if IS_LINUX: + if prop_id == cv2.CAP_PROP_EXPOSURE and cur_val > 0: + # V4L2 100µs → log2 秒(与 Windows 显示一致) + cur_val = int(round(np.log2(cur_val * 0.0001))) + cur_val = max(lo, min(hi, cur_val)) + actual_lo, actual_hi = lo, hi + else: + # 其他参数:动态扩展范围以适应 V4L2 实际值 + actual_lo = min(lo, cur_val) + actual_hi = max(hi, cur_val) + else: + # Windows: -1 表示不支持,fallback 到默认值 + if cur_val == -1: + cur_val = default + cur_val = max(lo, min(hi, cur_val)) + actual_lo, actual_hi = lo, hi + + row = QWidget() + h = QHBoxLayout(row) + h.setContentsMargins(0, 0, 0, 0) + + slider = QSlider(Qt.Horizontal) + slider.setRange(actual_lo, actual_hi) + slider.setValue(cur_val) + slider.setToolTip(f"{actual_lo} ~ {actual_hi}") + + spin = QSpinBox() + spin.setRange(actual_lo, actual_hi) + spin.setValue(cur_val) + spin.setFixedWidth(65) + + slider.valueChanged.connect(lambda v, p=prop_id, s=spin: self._on_slider(p, v, s)) + spin.valueChanged.connect(lambda v, p=prop_id, sl=slider: self._on_spin(p, v, sl)) + + h.addWidget(slider, stretch=1) + h.addWidget(spin) + + self._sliders[prop_id] = slider + self._spinboxes[prop_id] = spin + form.addRow(label, row) + + grp.setLayout(form) + layout.addWidget(grp) + + # --- 自动曝光 / 自动白平衡 复选框 --- + grp_auto = QGroupBox("自动控制") + auto_layout = QHBoxLayout() + + self._chk_auto_exp = QCheckBox("自动曝光") + self._chk_auto_wb = QCheckBox("自动白平衡") + + # Linux V4L2: AUTO_EXPOSURE 0=自动 1=手动(与Windows相反) + # Windows DShow: AUTO_EXPOSURE 0=手动 1=自动 + # 读取相机当前状态来设置复选框初始值(不写入) + self._chk_auto_exp.setChecked(False) + self._chk_auto_wb.setChecked(False) + if parent.cap.isOpened(): + try: + auto_exp_val = parent.cap.get(cv2.CAP_PROP_AUTO_EXPOSURE) + if IS_LINUX: + # V4L2: 0=自动模式 → 勾选;1=手动模式 → 不勾选 + self._chk_auto_exp.setChecked(auto_exp_val == 0) + else: + # Windows: >0 表示自动模式开启 + self._chk_auto_exp.setChecked(auto_exp_val > 0) + except Exception: + pass + try: + auto_wb_val = parent.cap.get(cv2.CAP_PROP_AUTO_WB) + self._chk_auto_wb.setChecked(auto_wb_val > 0) + except Exception: + pass + + self._chk_auto_exp.toggled.connect(self._on_auto_exp_toggled) + self._chk_auto_wb.toggled.connect(self._on_auto_wb_toggled) + + auto_layout.addWidget(self._chk_auto_exp) + auto_layout.addWidget(self._chk_auto_wb) + grp_auto.setLayout(auto_layout) + layout.addWidget(grp_auto) + + # --- 重置按钮 --- + btn_reset = QPushButton("重置为默认值") + btn_reset.clicked.connect(self._reset_defaults) + layout.addWidget(btn_reset) + + self.setLayout(layout) + + def _on_slider(self, prop_id, value, spin): + if self._updating: + return + self._updating = True + spin.setValue(value) + self._updating = False + self._write_camera(prop_id, value) + + def _on_spin(self, prop_id, value, slider): + if self._updating: + return + self._updating = True + slider.setValue(value) + self._updating = False + self._write_camera(prop_id, value) + + def _write_camera(self, prop_id, value): + """实时写入相机(Linux V4L2 曝光值需从 log2 转回 100µs 单位)""" + if self.parent.cap.isOpened(): + try: + if IS_LINUX and prop_id == cv2.CAP_PROP_EXPOSURE: + # log2 秒 → V4L2 100µs 单位 + value = max(1, int(round((2 ** value) * 10000))) + self.parent.cap.set(prop_id, value) + except Exception: + pass # V4L2 驱动可能不支持某些属性 + + def _on_auto_exp_toggled(self, checked): + if IS_LINUX: + # V4L2: 0=自动 1=手动(与Windows相反) + self._write_camera(cv2.CAP_PROP_AUTO_EXPOSURE, 0 if checked else 1) + else: + self._write_camera(cv2.CAP_PROP_AUTO_EXPOSURE, 1 if checked else 0) + + def _on_auto_wb_toggled(self, checked): + self._write_camera(cv2.CAP_PROP_AUTO_WB, 1 if checked else 0) + + def _reset_defaults(self): + # 先关闭自动曝光/白平衡,再写入参数值,否则自动算法会覆盖写入 + self._chk_auto_exp.setChecked(False) + self._chk_auto_wb.setChecked(False) + for label, prop_id, lo, hi, default in CAM_PARAMS: + self._updating = True + self._sliders[prop_id].setValue(default) + self._spinboxes[prop_id].setValue(default) + self._updating = False + self._write_camera(prop_id, default) + + +# ================= 🆕 V4.4.1: 热力图参数设置弹窗 ================= +class HeatmapSettingsDialog(QDialog): + def __init__(self, parent=None): + super().__init__(parent) + self.setWindowTitle("热力图参数设置") + self.setFixedSize(380, 310) + self.parent = parent + + self.default_params = {'scale': 10.0, 'mask_b': 50, 'mask_r': 130, + 'hue_threshold': 5.0, 'fz_p1': 1.0} + + layout = QVBoxLayout() + + grp = QGroupBox("热力图链路参数") + form = QFormLayout() + + # --- 热力图缩放 (1.0 ~ 500.0,滑块+输入框双向同步) --- + scale_row = QWidget() + scale_h = QHBoxLayout(scale_row) + scale_h.setContentsMargins(0, 0, 0, 0) + self._scale_sync = False # 防循环标志 + self.scale_slider = QSlider(Qt.Horizontal) + self.scale_slider.setRange(10, 5000) + self.scale_slider.setValue(int(parent.heatmap_scale * 10)) + self.scale_spin = QDoubleSpinBox() + self.scale_spin.setRange(1.0, 500.0) + self.scale_spin.setDecimals(1) + self.scale_spin.setValue(parent.heatmap_scale) + self.scale_spin.setFixedWidth(75) + self.scale_slider.valueChanged.connect(self._on_scale_slider) + self.scale_spin.valueChanged.connect(self._on_scale_spin) + scale_h.addWidget(self.scale_slider) + scale_h.addWidget(self.scale_spin) + form.addRow("热力图缩放:", scale_row) + + # --- Mask B阈值 --- + self.mask_b_spin = QSpinBox() + self.mask_b_spin.setRange(0, 255) + self.mask_b_spin.setValue(parent.mask_b_threshold) + form.addRow("Mask B阈值:", self.mask_b_spin) + + # --- Mask R阈值 --- + self.mask_r_spin = QSpinBox() + self.mask_r_spin.setRange(0, 255) + self.mask_r_spin.setValue(parent.mask_r_threshold) + form.addRow("Mask R阈值:", self.mask_r_spin) + + # --- Hue 阈值 --- + self.hue_thresh_spin = QDoubleSpinBox() + self.hue_thresh_spin.setRange(0.0, 180.0) + self.hue_thresh_spin.setDecimals(1) + self.hue_thresh_spin.setValue(parent.hue_threshold) + form.addRow("Hue 阈值:", self.hue_thresh_spin) + + # --- 标定系数 --- + self.fz_p1_spin = QDoubleSpinBox() + self.fz_p1_spin.setRange(0.01, 100.0) + self.fz_p1_spin.setDecimals(2) + self.fz_p1_spin.setValue(parent.fz_p1) + form.addRow("标定系数 fz_p1:", self.fz_p1_spin) + + grp.setLayout(form) + layout.addWidget(grp) + + # --- 按钮行: 重置 | 确认 --- + btn_row = QWidget() + btn_h = QHBoxLayout(btn_row) + btn_h.setContentsMargins(0, 0, 0, 0) + btn_reset = QPushButton("重置为默认值") + btn_reset.setAutoDefault(False) + btn_reset.clicked.connect(self._reset_defaults) + btn_confirm = QPushButton("确认修改") + btn_confirm.setDefault(True) + btn_confirm.setStyleSheet("background-color: #4CAF50; color: white; font-weight: bold;") + btn_confirm.clicked.connect(self._confirm) + btn_h.addWidget(btn_reset) + btn_h.addWidget(btn_confirm) + layout.addWidget(btn_row) + + self.setLayout(layout) + + def _on_scale_slider(self, v): + if self._scale_sync: return + self._scale_sync = True + self.scale_spin.setValue(v / 10.0) + self._scale_sync = False + + def _on_scale_spin(self, v): + if self._scale_sync: return + self._scale_sync = True + self.scale_slider.setValue(int(v * 10)) + self._scale_sync = False + + def _reset_defaults(self): + self.scale_slider.setValue(int(self.default_params['scale'] * 10)) + self.mask_b_spin.setValue(self.default_params['mask_b']) + self.mask_r_spin.setValue(self.default_params['mask_r']) + self.hue_thresh_spin.setValue(self.default_params['hue_threshold']) + self.fz_p1_spin.setValue(self.default_params['fz_p1']) + + def _confirm(self): + p = self.parent + p.heatmap_scale = self.scale_spin.value() + p.mask_b_threshold = self.mask_b_spin.value() + p.mask_r_threshold = self.mask_r_spin.value() + p.hue_threshold = self.hue_thresh_spin.value() + p.fz_p1 = self.fz_p1_spin.value() + self.accept() + + +# ================= 主界面窗口 ================= +class MainWindow(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("HSV_Visualizer_V4.4.1") + + # 初始窗口大小匹配 16:9 宽高比(2560×1440 → 1280×720 图区 + 按钮栏 ~50px) + self.resize(1280, 770) + + # --- 初始化变量 --- + self.cam_port = 0 + # 默认使用 DirectShow 后端 + self.cap = open_camera(self.cam_port) + self._setup_camera_defaults() + + # 🆕 V4.4: 传感器 ROI 裁切(复刻 touch_sensor.py:702,不翻转) + self.sensor_roi = (0, 640, 0, 480) # (x1, x2, y1, y2) 默认全帧 + + # 🆕 V4.4: 热力图链路参数(复刻 touch_sensor.py 对应逻辑) + self.fz_p1 = 1.0 # 力标定系数(应填入传感器出厂值) + self.hue_threshold = 5.0 # Hue差分阈值(平面款默认5.0) + self.hue_baseline = None # H通道基准 + self._fz_matrix = None # 热力图数据源 (float32) + self.mask_b_threshold = 50 # Mask B阈值 + self.mask_r_threshold = 130 # Mask R阈值 + + # 相机打开后自动校准基线 + if self.cap.isOpened(): + self.calibrate_baseline() + + self.roi_params = { + 'r1_x': 150, 'r1_y': 200, 'r1_w': 50, 'r1_h': 55, + 'r2_x': 275, 'r2_y': 120, 'r2_w': 200, 'r2_h': 200 + } + + self.roi_dialog = None + self.cam_params_dialog = None + + # 用于控制统计值刷新频率(每秒3次) + self.frame_count = 0 + self.stats_h = [0, 0] # [mean, var] 红色ROI + self.stats_s = [0, 0] + self.stats_v = [0, 0] + self.stats_r = [0, 0] + self.stats_g = [0, 0] + self.stats_b = [0, 0] + self.stats_gray = [0, 0] + self.stats_green = [0, 0, 0] # [avg_h1, avg_s1, avg_v1] 绿色ROI + + # 🆕 V4.2: 红色ROI的R/G/B均值历史(最近500帧) + self.rgb_history = { + 'r': deque(maxlen=500), + 'g': deque(maxlen=500), + 'b': deque(maxlen=500) + } + + # 🆕 V4.4: H/S/V均值历史 + self.hsv_history = { + 'h': deque(maxlen=500), + 's': deque(maxlen=500), + 'v': deque(maxlen=500) + } + + # 🆕 V4.4: 平面热力图(照搬 sightac_sdk 热力图逻辑) + self.heatmap_scale = 10.0 + + # 鼠标拖拽绘制ROI相关 + self.dragging = False + self.drag_start = None + self.drag_current = None + + # --- 🆕 V4: 自动重连状态 --- + self._fail_count = 0 # 连续读取失败帧数 + self._reconnecting = False # 是否正在重连中 + self._retry_countdown = 0 # 重试间隔倒计时(帧) + self._camera_connected = self.cap.isOpened() # 当前连接状态 + + # --- 构建 UI 布局 --- + self.image_label = QLabel(self) + self.image_label.setMinimumSize(400, 300) + # 允许标签在水平和垂直方向上自由伸展 + self.image_label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + self.image_label.setStyleSheet("background-color: black;") + self.image_label.setAlignment(Qt.AlignCenter) + self.image_label.setMouseTracking(True) + # 🆕 V4: 让 image_label 能接收键盘事件 + self.image_label.setFocusPolicy(Qt.StrongFocus) + + self.btn_port = QPushButton("设置相机端口") + self.btn_roi = QPushButton("设置 ROI 参数") + self.btn_cam = QPushButton("相机参数修改") + # 🆕 V4: 重新连接按钮 + self.btn_reconnect = QPushButton("重新连接") + self.btn_reconnect.setToolTip("重新连接摄像头(快捷键: R)") + self._update_reconnect_button_style() + + self.btn_port.clicked.connect(self.change_port) + self.btn_roi.clicked.connect(self.open_roi_dialog) + self.btn_cam.clicked.connect(self.open_cam_params_dialog) + self.btn_reconnect.clicked.connect(self.reconnect_camera) + + # 🆕 V4.4: 校准基线 + 热力图设置按钮 + self.btn_calibrate = QPushButton("校准基线") + self.btn_calibrate.setToolTip("重新校准H通道基线(请确保传感器无触摸)") + self.btn_calibrate.clicked.connect(lambda: self.calibrate_baseline()) + + self.btn_heatmap_settings = QPushButton("热力图设置") + self.btn_heatmap_settings.setToolTip("设置热力图缩放/Mask/Hue阈值/标定系数") + self.btn_heatmap_settings.clicked.connect(self.open_heatmap_settings) + + btn_layout = QHBoxLayout() + btn_layout.addWidget(self.btn_port) + btn_layout.addWidget(self.btn_roi) + btn_layout.addWidget(self.btn_cam) + btn_layout.addWidget(self.btn_reconnect) + btn_layout.addSpacing(15) + btn_layout.addWidget(self.btn_calibrate) + btn_layout.addWidget(self.btn_heatmap_settings) + + main_layout = QVBoxLayout() + main_layout.addWidget(self.image_label) + main_layout.addLayout(btn_layout) + self.setLayout(main_layout) + + # --- 设置定时器刷新画面 --- + self.timer = QTimer(self) + self.timer.timeout.connect(self.update_frame) + self.timer.start(30) + + # ========== 🆕 V4: 摄像头重连 ========== + + def _setup_camera_defaults(self): + """摄像头打开后默认关闭自动曝光和自动白平衡,保持手动控制""" + if self.cap is not None and self.cap.isOpened(): + try: + if IS_LINUX: + # V4L2: AUTO_EXPOSURE 0=自动 1=手动(与Windows相反) + self.cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1) + else: + self.cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0) + # 关闭 AWB 之前先保存当前色温值,避免被相机固件复位覆盖 + saved_wb = self.cap.get(cv2.CAP_PROP_WB_TEMPERATURE) + self.cap.set(cv2.CAP_PROP_AUTO_WB, 0) + # 部分摄像头关闭 AWB 后需锁定色温才生效,用之前保存的值恢复 + if saved_wb > 0: + self.cap.set(cv2.CAP_PROP_WB_TEMPERATURE, saved_wb) + except Exception: + pass # 部分驱动不支持这些属性,忽略即可 + + def reconnect_camera(self): + """释放当前摄像头并重新连接,可手动/自动/快捷键触发""" + # 避免重复重连 + self._reconnecting = True + self._fail_count = 0 + self._retry_countdown = 0 + + print(f"[V4] 正在重连摄像头端口 {self.cam_port} ...") + + # 释放旧的 + if self.cap is not None: + self.cap.release() + + # 尝试重新打开 + self.cap = open_camera(self.cam_port) + if self.cap.isOpened(): + self._camera_connected = True + self._reconnecting = False + self._setup_camera_defaults() + print(f"[V4] ✅ 重连成功!摄像头端口 {self.cam_port} 已恢复。") + else: + self._camera_connected = False + self._reconnecting = True + self._retry_countdown = RETRY_INTERVAL_FRAMES + print(f"[V4] ❌ 重连失败,将在 ~2 秒后自动重试...") + + self._update_reconnect_button_style() + + def _update_reconnect_button_style(self): + """根据连接状态更新按钮样式和文字""" + if self._reconnecting: + self.btn_reconnect.setText("重连中...") + self.btn_reconnect.setStyleSheet( + "background-color: #ff9800; color: white; font-weight: bold;" + ) + self.btn_reconnect.setEnabled(False) + elif self._camera_connected: + self.btn_reconnect.setText("重新连接") + self.btn_reconnect.setStyleSheet("") + self.btn_reconnect.setEnabled(True) + else: + self.btn_reconnect.setText("重新连接 ⚠") + self.btn_reconnect.setStyleSheet( + "background-color: #f44336; color: white; font-weight: bold;" + ) + self.btn_reconnect.setEnabled(True) + + def keyPressEvent(self, event): + """🆕 V4: 按 R 键触发重连""" + if event.key() == Qt.Key_R: + # 不区分大小写 + self.reconnect_camera() + super().keyPressEvent(event) + + # ========== 🆕 V4.4.1: 复刻 sightac 热力图链路 ========== + + def calibrate_baseline(self, num_frames=5): + """复刻 touch_sensor.py:516 — 连拍 num_frames 帧取H通道均值作基线""" + if not self.cap.isOpened(): + print("[V4.4.1] 相机未打开,无法校准基线") + return + print(f"[V4.4.1] 正在校准H通道基线(连拍{num_frames}帧,请确保传感器无触摸)...") + base_sum = None + count = 0 + for _ in range(num_frames): + ret, frame = self.cap.read() + if not ret or frame is None: + continue + rx1, rx2, ry1, ry2 = self.sensor_roi + frame = frame[ry1:ry2, rx1:rx2] + frame = cv2.resize(frame, (640, 480)) + hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) + h_channel = hsv[:, :, 0].astype(np.float32) + if base_sum is None: + base_sum = np.zeros_like(h_channel) + base_sum += h_channel + count += 1 + if count > 0: + self.hue_baseline = base_sum / count + print(f"[V4.4.1] ✅ 基线校准完成 ({count}帧),尺寸={self.hue_baseline.shape}") + else: + print("[V4.4.1] ❌ 基线校准失败:无有效帧") + + def compute_fz_matrix(self, frame): + """复刻 touch_sensor.py 完整链路: + H提取 → 差分 → mask → 阈值过滤 → 力标定 → 返回 fz_matrix""" + if self.hue_baseline is None: + return None + hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) + h_channel = hsv[:, :, 0].astype(np.float32) + if h_channel.shape != self.hue_baseline.shape: + h_channel = cv2.resize(h_channel, + (self.hue_baseline.shape[1], self.hue_baseline.shape[0])) + hue_matrix = h_channel - self.hue_baseline + mask2 = (frame[:, :, 0] > self.mask_b_threshold) & (frame[:, :, 2] > self.mask_r_threshold) + if mask2.shape != hue_matrix.shape: + mask2 = cv2.resize(mask2.astype(np.uint8), + (hue_matrix.shape[1], hue_matrix.shape[0])).astype(bool) + hue_matrix[mask2] = 0.0 + filtered = hue_matrix.astype(np.float32, copy=True) + filtered[np.abs(filtered) < self.hue_threshold] = 0.0 + return filtered * self.fz_p1 + + # ========== 原有功能 ========== + + def change_port(self): + port, ok = QInputDialog.getInt(self, "设置相机", f"当前端口为 {self.cam_port}\n请输入新的相机端口号:", self.cam_port, 0, 10, 1) + if ok: + print(f"[*] 尝试连接新端口: {port} ...") + temp_cap = open_camera(port) + if temp_cap.isOpened(): + self.cap.release() + self.cap = temp_cap + self.cam_port = port + self._camera_connected = True + self._setup_camera_defaults() + self._fail_count = 0 + self._reconnecting = False + self._update_reconnect_button_style() + QMessageBox.information(self, "成功", f"成功切换到相机端口 {port}!") + else: + temp_cap.release() + QMessageBox.critical(self, "错误", f"无法打开端口 {port}!\n原相机画面继续保留。") + + def open_roi_dialog(self): + if self.roi_dialog is None: + self.roi_dialog = ROIDialog(self) + self.roi_dialog.show() + + def open_cam_params_dialog(self): + if self.cam_params_dialog is None: + self.cam_params_dialog = CameraParamsDialog(self) + self.cam_params_dialog.show() + + def open_heatmap_settings(self): + """打开热力图参数设置弹窗""" + dialog = HeatmapSettingsDialog(self) + dialog.exec_() + + def update_frame(self): + # --- 🆕 V4: 自动重连逻辑 --- + if self._reconnecting: + # 倒计时中,等待下一次重试 + if self._retry_countdown > 0: + self._retry_countdown -= 1 + else: + # 倒计时到,尝试重连 + self._do_retry_reconnect() + + # 🆕 V4.4: 动态 cell 尺寸 — 计算格子像素 + label_w = self.image_label.width() + label_h = self.image_label.height() + if label_w > 0 and label_h > 0: + cell_w, cell_h = label_w // 4, label_h // 3 + else: + cell_w, cell_h = 640, 480 # fallback + + # 读取帧 + ret = False + frame = None + if not self._reconnecting and self.cap.isOpened(): + ret, frame = self.cap.read() + + if not ret: + # 🆕 V4: 累计失败帧数,达到阈值触发自动重连 + self._fail_count += 1 + if self._fail_count >= AUTO_RECONNECT_THRESHOLD and not self._reconnecting: + print(f"[V4] 连续 {self._fail_count} 帧读取失败,触发自动重连...") + self.reconnect_camera() + # reconnect_camera 可能立即成功或进入重试模式 + + # 显示状态提示 + frame = np.zeros((480, 640, 3), dtype=np.uint8) + if self._reconnecting: + msg = "Reconnecting..." + color = (0, 200, 255) + elif self._camera_connected: + msg = "Loading..." + color = (0, 165, 255) + else: + msg = "Camera Disconnected\nPress R or click button to reconnect" + color = (0, 0, 255) + # 多行文字分行绘制 + lines = msg.split('\n') + y_start = 200 + for i, line in enumerate(lines): + text_size = cv2.getTextSize(line, cv2.FONT_HERSHEY_SIMPLEX, 1, 2)[0] + x_pos = (640 - text_size[0]) // 2 + cv2.putText(frame, line, (x_pos, y_start + i * 40), + cv2.FONT_HERSHEY_SIMPLEX, 1, color, 2) + else: + # 读取成功,重置失败计数 + self._fail_count = 0 + # 🆕 V4.4: 裁切传感器ROI(复刻 touch_sensor.py:702,不翻转) + rx1, rx2, ry1, ry2 = self.sensor_roi + frame = frame[ry1:ry2, rx1:rx2] + frame = cv2.resize(frame, (640, 480)) + # 🆕 V4.4: 热力图数据源 — 复刻 sightac 完整链路 + self._fz_matrix = self.compute_fz_matrix(frame) + + p = self.roi_params + x1 = max(0, min(p['r1_x'], 639)) + y1 = max(0, min(p['r1_y'], 479)) + x2 = max(x1 + 1, min(x1 + p['r1_w'], 640)) + y2 = max(y1 + 1, min(y1 + p['r1_h'], 480)) + + x1_2 = max(0, min(p['r2_x'], 639)) + y1_2 = max(0, min(p['r2_y'], 479)) + x2_2 = max(x1_2 + 1, min(x1_2 + p['r2_w'], 640)) + y2_2 = max(y1_2 + 1, min(y1_2 + p['r2_h'], 480)) + + hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) + h, s, v = cv2.split(hsv) + + roi_h1, roi_s1, roi_v1 = h[y1:y2, x1:x2], s[y1:y2, x1:x2], v[y1:y2, x1:x2] + avg_h1 = np.mean(roi_h1) if roi_h1.size > 0 else 0 + avg_s1 = np.mean(roi_s1) if roi_s1.size > 0 else 0 + avg_v1 = np.mean(roi_v1) if roi_v1.size > 0 else 0 + + roi_h2, roi_s2, roi_v2 = h[y1_2:y2_2, x1_2:x2_2], s[y1_2:y2_2, x1_2:x2_2], v[y1_2:y2_2, x1_2:x2_2] + avg_h2 = np.mean(roi_h2) if roi_h2.size > 0 else 0 + avg_s2 = np.mean(roi_s2) if roi_s2.size > 0 else 0 + avg_v2 = np.mean(roi_v2) if roi_v2.size > 0 else 0 + + h_show = cv2.cvtColor(h, cv2.COLOR_GRAY2BGR) + s_show = cv2.cvtColor(s, cv2.COLOR_GRAY2BGR) + v_show = cv2.cvtColor(v, cv2.COLOR_GRAY2BGR) + + # --- 分离 BGR 通道 --- + b_ch, g_ch, r_ch = cv2.split(frame) + r_show = cv2.cvtColor(r_ch, cv2.COLOR_GRAY2BGR) + g_show_c = cv2.cvtColor(g_ch, cv2.COLOR_GRAY2BGR) + b_show = cv2.cvtColor(b_ch, cv2.COLOR_GRAY2BGR) + + # 红色ROI区域 — R/G/B 通道 + roi_r2 = r_ch[y1_2:y2_2, x1_2:x2_2] + roi_g2 = g_ch[y1_2:y2_2, x1_2:x2_2] + roi_b2 = b_ch[y1_2:y2_2, x1_2:x2_2] + roi_bgr2 = frame[y1_2:y2_2, x1_2:x2_2] + + # 🆕 V4.2: 记录红色ROI的R/G/B均值到历史缓冲区(最近500帧) + avg_r2 = np.mean(roi_r2) if roi_r2.size > 0 else 0 + avg_g2 = np.mean(roi_g2) if roi_g2.size > 0 else 0 + avg_b2 = np.mean(roi_b2) if roi_b2.size > 0 else 0 + self.rgb_history['r'].append(avg_r2) + self.rgb_history['g'].append(avg_g2) + self.rgb_history['b'].append(avg_b2) + + # 🆕 V4.4: 记录H/S/V均值到历史缓冲区 + self.hsv_history['h'].append(avg_h2) + self.hsv_history['s'].append(avg_s2) + self.hsv_history['v'].append(avg_v2) + + # 每约333ms(10帧)更新一次统计值(每秒3次) + self.frame_count += 1 + if self.frame_count >= 10: + self.frame_count = 0 + self.stats_h = [np.mean(roi_h2) if roi_h2.size > 0 else 0, np.var(roi_h2) if roi_h2.size > 0 else 0] + self.stats_s = [np.mean(roi_s2) if roi_s2.size > 0 else 0, np.var(roi_s2) if roi_s2.size > 0 else 0] + self.stats_v = [np.mean(roi_v2) if roi_v2.size > 0 else 0, np.var(roi_v2) if roi_v2.size > 0 else 0] + self.stats_green = [np.mean(roi_h1) if roi_h1.size > 0 else 0, + np.mean(roi_s1) if roi_s1.size > 0 else 0, + np.mean(roi_v1) if roi_v1.size > 0 else 0] + self.stats_r = [np.mean(roi_r2) if roi_r2.size > 0 else 0, np.var(roi_r2) if roi_r2.size > 0 else 0] + self.stats_g = [np.mean(roi_g2) if roi_g2.size > 0 else 0, np.var(roi_g2) if roi_g2.size > 0 else 0] + self.stats_b = [np.mean(roi_b2) if roi_b2.size > 0 else 0, np.var(roi_b2) if roi_b2.size > 0 else 0] + + # 🆕 V4.4: 缩放7个子图到 cell 尺寸,再画 overlay(字/框直接渲染不缩放) + S = min(cell_w / 640, cell_h / 480) # 缩放因子 + SZ = (cell_w, cell_h) + images_cell = [ + cv2.resize(frame, SZ, interpolation=cv2.INTER_LANCZOS4), + cv2.resize(h_show, SZ, interpolation=cv2.INTER_LANCZOS4), + cv2.resize(s_show, SZ, interpolation=cv2.INTER_LANCZOS4), + cv2.resize(v_show, SZ, interpolation=cv2.INTER_LANCZOS4), + cv2.resize(r_show, SZ, interpolation=cv2.INTER_LANCZOS4), + cv2.resize(g_show_c, SZ, interpolation=cv2.INTER_LANCZOS4), + cv2.resize(b_show, SZ, interpolation=cv2.INTER_LANCZOS4), + ] + # 名字对应: 0=原图, 1=H, 2=S, 3=V, 4=R, 5=G, 6=B + titles = ["Original", "Hue (H)", "Saturation (S)", "Value (V)", + "Red (R)", "Green (G)", "Blue (B)"] + roi2_label_indices = [1, 2, 3] # H/S/V 显示 ROI1 标签 + + # 比例化 ROI 坐标 + def _sx(v): return int(v * cell_w / 640) + def _sy(v): return int(v * cell_h / 480) + cx1, cy1, cx2, cy2 = _sx(x1), _sy(y1), _sx(x2), _sy(y2) + cx1_2, cy1_2, cx2_2, cy2_2 = _sx(x1_2), _sy(y1_2), _sx(x2_2), _sy(y2_2) + + # 比例化字体 + font_title = max(0.5, 1.2 * S) + font_info = max(0.4, 0.7 * S) + font_small = max(0.35, 0.6 * S) + thick = max(1, int(1.5 * S)) + thick_roi = max(1, int(2 * S)) + + text_color = (0, 255, 255) + red_color = (0, 0, 255) + c_roi1, c_roi2 = (0, 255, 0), (0, 0, 255) + + font = cv2.FONT_HERSHEY_SIMPLEX + + for i, img in enumerate(images_cell): + # ROI 框 + cv2.rectangle(img, (cx1, cy1), (cx2, cy2), c_roi1, thick_roi) + cv2.rectangle(img, (cx1_2, cy1_2), (cx2_2, cy2_2), c_roi2, thick_roi) + # 标题 + cv2.putText(img, titles[i], (_sx(20), _sy(40)), font, font_title, + text_color, thick, cv2.LINE_AA) + # ROI1 标签 (仅 H/S/V) + if i in roi2_label_indices: + gi = i - 1 # green stats index + cv2.putText(img, f"Avg {titles[i][0]}: {self.stats_green[gi]:.1f}", + (cx1, max(_sy(15), cy1 - _sy(10))), + font, font_small, c_roi1, thick, cv2.LINE_AA) + # ROI2 均值+方差 (仅 H/S/V/R/G/B, i>=1) + if i >= 1: + si = i - 1 # stats index + st = [self.stats_h, self.stats_s, self.stats_v, + self.stats_r, self.stats_g, self.stats_b][si] + cv2.putText(img, f"Mean: {st[0]:.1f}", (_sx(20), _sy(75)), + font, font_info, red_color, thick, cv2.LINE_AA) + cv2.putText(img, f"Var: {st[1]:.1f}", (_sx(20), _sy(100)), + font, font_info, red_color, thick, cv2.LINE_AA) + + # 原图(索引0)额外显示 ROI1 数值 + cv2.putText(images_cell[0], + f"R1: {self.stats_green[0]:.0f},{self.stats_green[1]:.0f},{self.stats_green[2]:.0f}", + (cx1, max(_sy(15), cy1 - _sy(10))), + font, font_small, c_roi1, thick, cv2.LINE_AA) + + # 右键拖拽预览矩形(cell 空间) + if self.dragging and self.drag_start and self.drag_current: + dx1, dy1, idx = self.drag_start + dx2, dy2, _ = self.drag_current + rx1, ry1 = _sx(min(dx1, dx2)), _sy(min(dy1, dy2)) + rx2, ry2 = _sx(max(dx1, dx2)), _sy(max(dy1, dy2)) + if 0 <= idx <= 6 and rx2 > rx1 and ry2 > ry1: + cv2.rectangle(images_cell[idx], (rx1, ry1), (rx2, ry2), + (0, 255, 255), thick_roi) + + # 组装 + frame_d, h_show_d, s_show_d, v_show_d, r_show_d, g_show_d, b_show_d = images_cell + heatmap_cell = self.draw_heatmap(self._fz_matrix, cell_w, cell_h) + # 🆕 V4.4: 热力图ROI框用动态反色 — 每框独立采样背景,确保JET色图全区域可见 + hm_roi1_color = self._get_contrast_color(heatmap_cell, cx1, cy1, cx2, cy2) + hm_roi2_color = self._get_contrast_color(heatmap_cell, cx1_2, cy1_2, cx2_2, cy2_2) + cv2.rectangle(heatmap_cell, (cx1, cy1), (cx2, cy2), hm_roi1_color, thick_roi) + cv2.rectangle(heatmap_cell, (cx1_2, cy1_2), (cx2_2, cy2_2), hm_roi2_color, thick_roi) + top_row = np.hstack((frame_d, h_show_d, s_show_d, v_show_d)) + bottom_row = np.hstack((r_show_d, g_show_d, b_show_d, heatmap_cell)) + rgb_curve = self.draw_rgb_curve(cell_w, cell_h) + + # 曲线文字 overlay + curve_th = max(1, int(1.5 * S)) + cv2.putText(rgb_curve, "RGB + Hue Time Curve", + (_sx(20), _sy(40)), font, font_title, + text_color, curve_th, cv2.LINE_AA) + cv2.putText(rgb_curve, + f"R:{self.stats_r[0]:.1f} G:{self.stats_g[0]:.1f} B:{self.stats_b[0]:.1f} H:{self.stats_h[0]:.1f}", + (_sx(20), _sy(75)), font, font_info, + red_color, curve_th, cv2.LINE_AA) + + combined_img = np.vstack((top_row, bottom_row, rgb_curve)) + rgb_img = cv2.cvtColor(combined_img, cv2.COLOR_BGR2RGB) + h, w, ch = rgb_img.shape + q_img = QImage(rgb_img.data, w, h, w * ch, QImage.Format_RGB888) + self.image_label.setPixmap(QPixmap.fromImage(q_img)) + + def _do_retry_reconnect(self): + """🆕 V4: 重连重试(由 update_frame 中的倒计时触发)""" + print(f"[V4] 重试连接摄像头端口 {self.cam_port} ...") + if self.cap is not None: + self.cap.release() + + self.cap = open_camera(self.cam_port) + if self.cap.isOpened(): + self._camera_connected = True + self._reconnecting = False + self._setup_camera_defaults() + self._fail_count = 0 + self._retry_countdown = 0 + print(f"[V4] ✅ 重连成功!摄像头端口 {self.cam_port} 已恢复。") + else: + # 失败,设定下一次重试倒计时 + self._retry_countdown = RETRY_INTERVAL_FRAMES + print(f"[V4] ❌ 重连失败,将在 ~2 秒后再次重试...") + + self._update_reconnect_button_style() + + def draw_rgb_curve(self, cell_w, cell_h): + """🆕 V4.4: 动态 cell 尺寸 — 比例化坐标""" + CW = cell_w * 4 # 通栏宽 + CH = cell_h + S = min(cell_w / 640, cell_h / 480) # 缩放因子 + + canvas = np.zeros((CH, CW, 3), dtype=np.uint8) + axis_color = (200, 200, 200) + + # 比例坐标 + margin_l = int(55 * S) + margin_r = int(40 * S) + margin_t = int(20 * S) + margin_b = int(40 * S) + legend_x = CW - margin_r + plt_x0, plt_y0 = margin_l, CH - margin_b + plt_w = CW - margin_l - int(60 * S) + plt_h = CH - margin_t - margin_b + + # Y轴 + cv2.line(canvas, (plt_x0, plt_y0), (plt_x0, margin_t), axis_color, max(1, int(2 * S))) + cv2.line(canvas, (plt_x0, plt_y0), (CW, plt_y0), axis_color, max(1, int(2 * S))) + + for val_255, y_abs in [(0, plt_y0), (128, plt_y0 - int(128 * plt_h / 255)), (255, margin_t)]: + fs = max(0.4, 0.8 * S) + cv2.putText(canvas, str(val_255), (int(3 * S), y_abs + int(8 * S)), + cv2.FONT_HERSHEY_SIMPLEX, fs, axis_color, max(1, int(2 * S)), cv2.LINE_AA) + tick_x = plt_x0 - int(5 * S) + cv2.line(canvas, (tick_x, y_abs), (plt_x0, y_abs), axis_color, max(1, int(2 * S))) + + n = len(self.rgb_history['r']) + text_th = max(1, int(1.5 * S)) # 文字厚度随 cell 缩放 + if n < 2: + cv2.putText(canvas, "Collecting...", (int(20 * S), int(40 * S)), + cv2.FONT_HERSHEY_SIMPLEX, 1.0 * S, (200, 200, 200), text_th) + return canvas + + # B/G/R 曲线 + colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] + for key, color in zip(['b', 'g', 'r'], colors): + mean_vals = self.rgb_history[key] + pts = [] + for i, val in enumerate(mean_vals): + x = plt_x0 + int(i * plt_w / max(n - 1, 1)) + y = plt_y0 - int(val * plt_h / 255) + pts.append([x, y]) + pts = np.array(pts, np.int32).reshape((-1, 1, 2)) + cv2.polylines(canvas, [pts], False, color, max(1, int(3 * S))) + + # H 曲线 + mean_vals_h = self.hsv_history['h'] + pts_h = [] + for i, val in enumerate(mean_vals_h): + x = plt_x0 + int(i * plt_w / max(n - 1, 1)) + y = plt_y0 - int(val * plt_h / 255) + pts_h.append([x, y]) + pts_h = np.array(pts_h, np.int32).reshape((-1, 1, 2)) + cv2.polylines(canvas, [pts_h], False, (200, 200, 200), max(1, int(3 * S))) + + # 图例 + fs_l = max(0.4, 0.9 * S) + for i, (label, color) in enumerate([("B", (255, 0, 0)), ("G", (0, 255, 0)), + ("R", (0, 0, 255)), ("H", (200, 200, 200))]): + cv2.putText(canvas, label, (legend_x, int((40 + 30 * i) * S)), + cv2.FONT_HERSHEY_SIMPLEX, fs_l, color, text_th) + + return canvas + + def _get_contrast_color(self, img, x1, y1, x2, y2): + """采样ROI边框路径上的背景像素均值,返回高对比度反色。 + 性能:每框采样 ~2*(w+h) 像素做 np.mean,微秒级,不影响30fps。""" + h, w = img.shape[:2] + x1, y1 = max(0, x1), max(0, y1) + x2, y2 = min(w, x2), min(h, y2) + if x2 <= x1 or y2 <= y1: + return (0, 255, 0) # fallback + # 采样四条边(取2px宽度的边框区域,容错性好) + top = img[y1:y1+2, x1:x2] + bottom = img[y2-2:y2, x1:x2] + left = img[y1:y2, x1:x1+2] + right = img[y1:y2, x2-2:x2] + border = np.concatenate([top.reshape(-1, 3), bottom.reshape(-1, 3), + left.reshape(-1, 3), right.reshape(-1, 3)], axis=0) + if border.size == 0: + return (0, 255, 0) + mean_bgr = np.mean(border, axis=0) + # 反色 = 高对比度 + return (255 - int(mean_bgr[0]), 255 - int(mean_bgr[1]), 255 - int(mean_bgr[2])) + + def draw_heatmap(self, fz_matrix, cell_w, cell_h): + """🆕 V4.4.1: 平面热力图 — sightac 核心逻辑 + cell 尺寸""" + if fz_matrix is None or fz_matrix.size == 0: + return np.zeros((cell_h, cell_w, 3), dtype=np.uint8) + + preview_gray = np.clip(fz_matrix * self.heatmap_scale, 0, 255).astype(np.uint8) + heatmap = cv2.applyColorMap(preview_gray, cv2.COLORMAP_JET) + heatmap = cv2.resize(heatmap, (cell_w, cell_h), interpolation=cv2.INTER_LANCZOS4) + + S = min(cell_w / 640, cell_h / 480) + fs = max(0.4, 0.7 * S) + cv2.putText(heatmap, "Planar Heatmap (JET)", (int(15 * S), int(30 * S)), + cv2.FONT_HERSHEY_SIMPLEX, fs, (255, 255, 255), max(1, int(2 * S)), cv2.LINE_AA) + cv2.putText(heatmap, f"Scale: {self.heatmap_scale:.1f}", (int(15 * S), int(60 * S)), + cv2.FONT_HERSHEY_SIMPLEX, fs * 0.8, (200, 200, 200), max(1, int(1 * S)), cv2.LINE_AA) + + return heatmap + + def get_sub_image_coords(self, pos, label_rect): + """将鼠标位置映射到对应子图的坐标和子图索引(适配动态 cell 尺寸) + 返回坐标归一化到 640×480 空间,与 ROI 参数一致。""" + lw, lh = label_rect.width(), label_rect.height() + cell_w, cell_h = lw // 4, lh // 3 + + # 鼠标在合并图像中的像素坐标 + img_x = int(pos.x() * lw / max(lw, 1)) + img_y = int(pos.y() * lh / max(lh, 1)) + + col = min(img_x // max(cell_w, 1), 3) + row = min(img_y // max(cell_h, 1), 2) + + sub_x_in_cell = img_x - col * cell_w + sub_y_in_cell = img_y - row * cell_h + + # 转回 640×480 空间(ROI 参数使用的坐标系) + sub_x = int(sub_x_in_cell * 640 / max(cell_w, 1)) + sub_y = int(sub_y_in_cell * 480 / max(cell_h, 1)) + + idx_map = [[0, 1, 2, 3], [4, 5, 6, 8], [7, 7, 7, 7]] + return sub_x, sub_y, idx_map[row][col] + + def mousePressEvent(self, event): + # 只处理右键点击 + if event.button() == Qt.RightButton: + # 获取点击位置相对于 image_label 的坐标 + pos = self.image_label.mapFrom(self, event.pos()) + label_rect = self.image_label.rect() + + # 检查是否在 image_label 内 + if not label_rect.contains(pos): + return + + # 获取子图坐标和索引 + sub_x, sub_y, sub_idx = self.get_sub_image_coords(pos, label_rect) + + # 空白占位格(-1)和通栏曲线(7)不是图像空间,禁止拖拽画 ROI + if sub_idx < 0 or sub_idx == 7: + return + + self.dragging = True + self.drag_start = (sub_x, sub_y, sub_idx) + self.drag_current = (sub_x, sub_y, sub_idx) + + super().mousePressEvent(event) + + def mouseMoveEvent(self, event): + if self.dragging: + pos = self.image_label.mapFrom(self, event.pos()) + label_rect = self.image_label.rect() + + # 获取子图坐标和索引 + sub_x, sub_y, sub_idx = self.get_sub_image_coords(pos, label_rect) + + # 确保在同一个子图内拖拽 + if sub_idx == self.drag_start[2]: + # 限制在子图范围内 (640x480) + sub_x = max(0, min(sub_x, 639)) + sub_y = max(0, min(sub_y, 479)) + self.drag_current = (sub_x, sub_y, sub_idx) + + super().mouseMoveEvent(event) + + def mouseReleaseEvent(self, event): + if event.button() == Qt.RightButton and self.dragging: + self.dragging = False + + if self.drag_start and self.drag_current: + x1, y1, idx1 = self.drag_start + x2, y2, idx2 = self.drag_current + + # 确保在同一个子图内 + if idx1 == idx2: + # 计算矩形(确保 x1 < x2, y1 < y2) + roi_x = min(x1, x2) + roi_y = min(y1, y2) + roi_w = abs(x2 - x1) + roi_h = abs(y2 - y1) + + # 矩形需大于5x5像素 + if roi_w > 5 and roi_h > 5: + # 限制在640x480范围内 + roi_x = max(0, min(roi_x, 639)) + roi_y = max(0, min(roi_y, 479)) + max_x = min(roi_x + roi_w, 640) + max_y = min(roi_y + roi_h, 480) + roi_w = max_x - roi_x + roi_h = max_y - roi_y + + # 更新红色ROI参数 + self.roi_params['r2_x'] = roi_x + self.roi_params['r2_y'] = roi_y + self.roi_params['r2_w'] = roi_w + self.roi_params['r2_h'] = roi_h + + # 同步更新ROI对话框中的滑块 + if self.roi_dialog is not None: + self.roi_dialog.r2_x.setValue(roi_x) + self.roi_dialog.r2_y.setValue(roi_y) + self.roi_dialog.r2_w.setValue(roi_w) + self.roi_dialog.r2_h.setValue(roi_h) + + self.drag_start = None + self.drag_current = None + + super().mouseReleaseEvent(event) + + def closeEvent(self, event): + if self.cap is not None: + self.cap.release() + event.accept() + +if __name__ == '__main__': + app = QApplication(sys.argv) + window = MainWindow() + window.show() + sys.exit(app.exec_()) diff --git a/collector/tools/demos/demo_glove_kpts/compare_detectors.py b/collector/tools/demos/demo_glove_kpts/compare_detectors.py new file mode 100644 index 0000000000000000000000000000000000000000..13235f97964ddbe3952f73927acc480d9173053b --- /dev/null +++ b/collector/tools/demos/demo_glove_kpts/compare_detectors.py @@ -0,0 +1,308 @@ +""" +黑手套检测器 A/B 对比 —— 对照检测器 vs 新训练模型,同一段视频逐帧同条件渲染。 + +两个 HandPipeline(仅检测器不同,其余 det_imgsz/conf/追踪/姿态门/渲染链完全 +一致,即主程序部署口径)对同一帧各跑一遍,输出: + - /old.mp4 / new.mp4 各自完整渲染视频 + - /side_by_side.mp4 左对照右新并排对比视频(带标签条) + - /compare_report.csv 指标表(检出率/关键点置信度/抖动/跟踪) + +--old 默认 "world":内置 YOLO-World 零样本(prompt ["hand","glove"], +imgsz 320——即代码里自带的黑手套检测方案);也可传 .pt 路径对比旧训练模型。 + +指标口径(全部基于 process() 门后输出,即用户实际看到的渲染结果): + - 检出帧率 boxes 非空帧占比(姿态门已滤掉无手套误检框) + - kpt均值中位数 所有被渲染手部 21 点置信度均值的中位数 + - 腕点抖动 p50/p95/max 同一 track 相邻帧腕点(点0)位移 px(渲染骨架跳动的直接度量) + - ID 切换次数 新 track 出现而旧 track 仍活跃的次数 + - 平均 track 寿命 每个 track 被渲染的帧数均值 + +用法: + python tools/demos/demo_glove_kpts/compare_detectors.py + python tools/demos/demo_glove_kpts/compare_detectors.py --old <旧权重.pt|world> --new <新权重.pt> + [--start N] [--frames N] + [--display] [--no-transcode] +""" + +from __future__ import annotations + +import argparse +import csv +import os +import shutil +import subprocess +import sys +import time + +import cv2 +import numpy as np + +# 复用 demo_glove_video 的管线构造 / 打包 / 渲染 / ffmpeg 查找 +from demo_glove_video import ( # noqa: E402 + build_pipeline, + draw_kpts_overlay, + _pack_hand_data, + _find_ffmpeg, + DEFAULT_VIDEO, +) + +_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +if _REPO_ROOT not in sys.path: + sys.path.insert(0, _REPO_ROOT) + +OLD_DEFAULT = "world" # 内置 YOLO-World 零样本(也可传 .pt 路径对比旧训练模型) +NEW_DEFAULT = os.path.join(_REPO_ROOT, "tools", "glove_package", "runs", + "hand_det", "weights", "best.pt") +OUT_DEFAULT = os.path.join(_REPO_ROOT, "keypoints_output", "ab_compare") + +LABEL_H = 30 # 并排视频顶部标签条高度(偶数,保证 yuv420p 可用) + + +class ModelStats: + """单模型逐帧指标收集器。""" + + def __init__(self, label: str, weights: str): + self.label = label + self.weights = weights + self.n_frames = 0 + self.det_frames = 0 + self.hand_counts = [] # 每帧渲染手数 + self.kpt_means = [] # 每手 21 点置信度均值 + self.jitter = [] # 同 track 相邻帧腕点位移 px + self.track_frames = {} # track_id -> 被渲染帧数 + self.prev_wrist = {} # track_id -> 上帧腕点 (x, y) + self.prev_active = set() # 上帧活跃 track(门后) + self.id_switches = 0 + + def add(self, boxes, kpts, scores, track_ids): + self.n_frames += 1 + n = len(boxes) + if n: + self.det_frames += 1 + self.hand_counts.append(n) + + active = set(track_ids) if track_ids else set() + if active and self.prev_active: + new_ids = active - self.prev_active + if new_ids: + self.id_switches += len(new_ids) + if active: + self.prev_active = active + + if kpts is not None: + for i, tid in enumerate(track_ids): + self.kpt_means.append(float(scores[i][:21].mean())) + self.track_frames[tid] = self.track_frames.get(tid, 0) + 1 + wrist = kpts[i][0] + if tid in self.prev_wrist: + self.jitter.append( + float(np.hypot(*(wrist - self.prev_wrist[tid])))) + self.prev_wrist[tid] = wrist.copy() + + def summary(self) -> dict: + j = np.asarray(self.jitter) if self.jitter else np.zeros(1) + km = np.asarray(self.kpt_means) if self.kpt_means else np.zeros(1) + det = max(1, self.det_frames) + return { + "model": self.label, + "weights": os.path.basename(self.weights), + "frames": self.n_frames, + "det_frames": f"{self.det_frames}/{self.n_frames}", + "det_rate": round(self.det_frames / max(1, self.n_frames), 4), + "avg_hands": round(float(np.mean(self.hand_counts)), 3), + "single_hand_rate": round( + sum(1 for c in self.hand_counts if c == 1) / det, 4), + "kpt_mean_med": round(float(np.median(km)), 3), + "jitter_p50_px": round(float(np.percentile(j, 50)), 2), + "jitter_p95_px": round(float(np.percentile(j, 95)), 2), + "jitter_max_px": round(float(j.max()), 2), + "jitter_n": len(self.jitter), + "avg_track_len": round( + float(np.mean(list(self.track_frames.values()))), 1) + if self.track_frames else 0, + "id_switches": self.id_switches, + } + + +def _as_pt(path: str, out_dir: str) -> str: + """ultralytics 只认 .pt 后缀;非 .pt 权重复制成临时 .pt 再加载。""" + if path.lower().endswith(".pt"): + return path + dst = os.path.join(out_dir, os.path.basename(path) + ".pt") + if not os.path.isfile(dst): + shutil.copyfile(path, dst) + return dst + + +def _transcode(tmp: str, out: str, ffmpeg: str) -> bool: + """mpeg4 临时文件 → H.264(与 demo_glove_video 相同配方)。""" + if not ffmpeg: + shutil.move(tmp, out) + return False + cmd = [ffmpeg, "-y", "-hide_banner", "-loglevel", "error", + "-i", tmp, + "-c:v", "libx264", "-preset", "fast", "-crf", "20", + "-pix_fmt", "yuv420p", "-movflags", "+faststart", + out] + ok = subprocess.run(cmd, capture_output=True, text=True).returncode == 0 + if ok: + os.remove(tmp) + else: + shutil.move(tmp, out) + return ok + + +def main(): + ap = argparse.ArgumentParser(description="黑手套检测器 A/B 渲染对比") + ap.add_argument("--video", default=DEFAULT_VIDEO) + ap.add_argument("--old", default=OLD_DEFAULT, + help="对照检测器:'world' 用内置 YOLO-World 零样本(默认)," + "或传 .pt 路径") + ap.add_argument("--new", default=NEW_DEFAULT, help="新模型权重路径") + ap.add_argument("--out-dir", default=OUT_DEFAULT) + ap.add_argument("--start", type=int, default=0) + ap.add_argument("--frames", type=int, default=0) + ap.add_argument("--det-device", default="cuda") + ap.add_argument("--pose-device", default="cuda") + ap.add_argument("--display", action="store_true", help="弹出实时显示窗口") + ap.add_argument("--no-transcode", action="store_true", + help="跳过 ffmpeg 转码,直接输出 mpeg4") + args = ap.parse_args() + + for path, tag in [(args.video, "video"), (args.new, "new")]: + if not os.path.isfile(path): + print(f"[error] {tag} 不存在: {path}") + return 1 + if args.old != "world" and not os.path.isfile(args.old): + print(f"[error] old 不存在: {args.old}") + return 1 + os.makedirs(args.out_dir, exist_ok=True) + + cap = cv2.VideoCapture(args.video) + if not cap.isOpened(): + print(f"[error] 无法打开视频: {args.video}") + return 1 + src_fps = cap.get(cv2.CAP_PROP_FPS) or 30.0 + width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) + if args.start > 0: + cap.set(cv2.CAP_PROP_POS_FRAMES, args.start) + max_frames = args.frames if args.frames > 0 else (total - args.start) + + # 标签条高度按偶数对齐(yuv420p 需要偶数尺寸) + lab_h = LABEL_H if (height + LABEL_H) % 2 == 0 else LABEL_H + 1 + + print(f"[input ] {args.video}") + print(f"[input ] {width}x{height} @ {src_fps:.0f}fps, 处理 {max_frames} 帧") + print(f"[out ] {args.out_dir}") + + # ── 两条同参数管线,只差检测器 ──────────────────────── + old_arg = args.old if args.old == "world" else _as_pt(args.old, args.out_dir) + new_pt = _as_pt(args.new, args.out_dir) + t0 = time.perf_counter() + pipe_old = build_pipeline(args.det_device, args.pose_device, old_arg) + pipe_new = build_pipeline(args.det_device, args.pose_device, new_pt) + print(f"[model ] OLD {pipe_old.detector_name} | NEW {pipe_new.detector_name}") + print(f"[model ] 加载 {time.perf_counter() - t0:.1f}s") + + old_label = "WORLD" if args.old == "world" else "OLD" + stats_old = ModelStats( + old_label, + "yolov8m-worldv2.pt" if args.old == "world" else args.old) + stats_new = ModelStats("NEW", args.new) + + old_name = ("YOLO-World built-in" if args.old == "world" + else os.path.basename(args.old)) + new_name = os.path.basename(args.new) + + def _writer(name): + tmp = os.path.join(args.out_dir, name + ".mpeg4.tmp.mp4") + return cv2.VideoWriter(tmp, cv2.VideoWriter_fourcc(*"mp4v"), + src_fps, (width, height)), tmp + w_old, tmp_old = _writer("old") + w_new, tmp_new = _writer("new") + sb_tmp = os.path.join(args.out_dir, "side_by_side.mpeg4.tmp.mp4") + w_sb = cv2.VideoWriter(sb_tmp, cv2.VideoWriter_fourcc(*"mp4v"), + src_fps, (width * 2, height + lab_h)) + + n = 0 + t0 = time.perf_counter() + try: + while True: + ok, frame = cap.read() + if not ok or (max_frames and n >= max_frames): + break + + # 同帧、同管线参数,只差检测器权重 + b_o, k_o, s_o, t_o = pipe_old.process(frame) + b_n, k_n, s_n, t_n = pipe_new.process(frame) + stats_old.add(b_o, k_o, s_o, t_o) + stats_new.add(b_n, k_n, s_n, t_n) + + out_o = draw_kpts_overlay(frame, _pack_hand_data(b_o, k_o, t_o), t_o) + out_n = draw_kpts_overlay(frame, _pack_hand_data(b_n, k_n, t_n), t_n) + w_old.write(out_o) + w_new.write(out_n) + + # 并排: 顶部标签条 + hconcat + strip = np.full((lab_h, width * 2, 3), 20, np.uint8) + cv2.putText(strip, old_name, (10, lab_h - 8), + cv2.FONT_HERSHEY_SIMPLEX, 0.55, (90, 90, 255), 2, cv2.LINE_AA) + cv2.putText(strip, new_name, (width + 10, lab_h - 8), + cv2.FONT_HERSHEY_SIMPLEX, 0.55, (90, 255, 90), 2, cv2.LINE_AA) + cv2.putText(strip, f"frame {n + 1}/{max_frames}", + (width - 110, lab_h - 8), + cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 200), 1, cv2.LINE_AA) + side = np.vstack([strip, np.hstack([out_o, out_n])]) + w_sb.write(side) + n += 1 + + if n % 30 == 0: + fps = n / (time.perf_counter() - t0) + print(f"[proc ] {n}/{max_frames} 帧 {fps:5.1f} fps " + f"OLD检出 {stats_old.det_frames} | NEW检出 {stats_new.det_frames}") + if args.display: + small = cv2.resize(side, (width, (height + lab_h) // 2)) + cv2.imshow("A/B compare - q:quit", small) + if cv2.waitKey(1) & 0xFF in (ord("q"), 27): + break + finally: + cap.release() + for w in (w_old, w_new, w_sb): + w.release() + cv2.destroyAllWindows() + + ffmpeg = "" if args.no_transcode else _find_ffmpeg() + if ffmpeg: + print(f"[ffmpeg] {ffmpeg}") + names = [("old", tmp_old), ("new", tmp_new), + ("side_by_side", sb_tmp)] + for name, tmp in names: + out = os.path.join(args.out_dir, name + ".mp4") + _transcode(tmp, out, ffmpeg) + print(f"[out ] {out}") + + # ── 指标表 ────────────────────────────────────────── + rows = [stats_old.summary(), stats_new.summary()] + keys = list(rows[0].keys()) + print("\n" + "=" * 64) + for k in keys: + print(f"{k:<18} {rows[0][k]:<16} {rows[1][k]}") + print("=" * 64) + + csv_path = os.path.join(args.out_dir, "compare_report.csv") + with open(csv_path, "w", newline="") as f: + wcsv = csv.writer(f) + wcsv.writerow(keys) + for r in rows: + wcsv.writerow([r[k] for k in keys]) + print(f"[csv ] {csv_path}") + + elapsed = time.perf_counter() - t0 + print(f"[done ] 处理 {n} 帧, 用时 {elapsed:.1f}s, 平均 {n / elapsed:.1f} fps") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/collector/tools/demos/demo_glove_kpts/demo_glove_video.py b/collector/tools/demos/demo_glove_kpts/demo_glove_video.py new file mode 100644 index 0000000000000000000000000000000000000000..e289efb1260961ffea690d33e6fada24ba7ac606 --- /dev/null +++ b/collector/tools/demos/demo_glove_kpts/demo_glove_video.py @@ -0,0 +1,227 @@ +""" +黑手套关键点识别 + 渲染 Demo —— 对单个视频逐帧跑手套管线并叠加关键点。 + +完全复用主程序两条现成代码路径(行为与 GUI 会话后处理一致): + - core/hand_processor.py 内部调用 core.hand_tracking.process_session() 的 + glove 分支 → HandPipeline (YOLO best.pt 检测黑色手套 + RTMPose 21 关键点) + - core.hand_tracking.draw_kpts_overlay() → hand_common.draw_hand 渲染 + +用法: + python tools/demos/demo_glove_kpts/demo_glove_video.py + python tools/demos/demo_glove_kpts/demo_glove_video.py --video <路径> [--out <路径>] + [--detector <权重.pt>] + [--start N] [--frames N] + [--det-device cuda] [--pose-device cuda] + [--no-display] + +按键(显示窗口内): q/Esc 退出, 空格 暂停/继续 + +输出视频默认写入本 demo 目录: <源文件名>_kpts.mp4 +""" + +from __future__ import annotations + +import argparse +import os +import shutil +import subprocess +import sys +import time + +_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +if _REPO_ROOT not in sys.path: + sys.path.insert(0, _REPO_ROOT) + +import cv2 +import numpy as np + +from core.hand_tracking import ( # noqa: E402 + _lazy_import_pipeline, + _pack_hand_data, + draw_kpts_overlay, +) + +DEMO_DIR = os.path.dirname(os.path.abspath(__file__)) + +DEFAULT_VIDEO = os.path.join( + _REPO_ROOT, "data", "recordings", "Project_Test10", + "Project_Test10_000003", "videos", "D435_depth_rgb", + "chunk-0000", "D435_depth_rgb.mp4") + + +def _find_ffmpeg() -> str: + """找可用的 ffmpeg。优先 lerobot 环境(conda base 的 ffmpeg 因 openvino/tbb 失效)。""" + for cand in [os.path.expanduser("~/miniconda3/envs/lerobot312/bin/ffmpeg"), + os.path.expanduser("~/miniconda3/envs/lerobot/bin/ffmpeg"), + shutil.which("ffmpeg") or "", + os.path.expanduser("~/miniconda3/bin/ffmpeg")]: + if cand and os.path.isfile(cand): + return cand + return "" + + +def build_pipeline(det_device: str, pose_device: str, detector: str = ""): + """与 core/hand_processor.py → process_session() 的 glove 分支同一套逻辑。""" + try: + import torch + if not torch.cuda.is_available(): + if det_device == "cuda": + det_device = "cpu" + if pose_device == "cuda": + pose_device = "cpu" + except Exception: + det_device = "cpu" + pose_device = "cpu" + + HP = _lazy_import_pipeline() + det_path = detector or os.path.join(_REPO_ROOT, "tools", "hand_detection", "best.pt") + return HP(detector=det_path, det_device=det_device, + pose_device=pose_device, max_hands=2) + + +def main(): + ap = argparse.ArgumentParser(description="黑手套视频关键点识别 + 渲染 Demo") + ap.add_argument("--video", default=DEFAULT_VIDEO, + help="输入视频路径 (默认 Project_Test10_000003 D435 RGB)") + ap.add_argument("--out", default="", + help="输出视频路径 (默认写入本 demo 目录: <源文件名>_kpts.mp4)") + ap.add_argument("--detector", default="", + help="检测器权重路径 (默认 tools/hand_detection/best.pt)") + ap.add_argument("--start", type=int, default=0, help="起始帧 (默认 0)") + ap.add_argument("--frames", type=int, default=0, + help="处理帧数 (默认 0 = 到结尾)") + ap.add_argument("--det-device", default="cuda", help="检测器设备 cuda/cpu") + ap.add_argument("--pose-device", default="cuda", help="关键点设备 cuda/cpu") + ap.add_argument("--no-display", action="store_true", + help="不弹显示窗口,只写输出视频") + ap.add_argument("--no-transcode", action="store_true", + help="跳过 ffmpeg 转码,直接输出 cv2 的 mpeg4(部分播放器打不开)") + args = ap.parse_args() + + if not os.path.isfile(args.video): + print(f"[error] 视频不存在: {args.video}") + return 1 + + # ── 输出路径: 默认放本 demo 目录 ───────────────────── + if args.out: + out_path = args.out + else: + stem = os.path.splitext(os.path.basename(args.video))[0] + out_path = os.path.join(DEMO_DIR, f"{stem}_kpts.mp4") + os.makedirs(os.path.dirname(os.path.abspath(out_path)), exist_ok=True) + + # ── 打开视频 ──────────────────────────────────────── + cap = cv2.VideoCapture(args.video) + if not cap.isOpened(): + print(f"[error] 无法打开视频: {args.video}") + return 1 + src_fps = cap.get(cv2.CAP_PROP_FPS) or 30.0 + width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) + if args.start > 0: + cap.set(cv2.CAP_PROP_POS_FRAMES, args.start) + max_frames = args.frames if args.frames > 0 else (total - args.start) + + print(f"[input ] {args.video}") + print(f"[input ] {width}x{height} @ {src_fps:.0f}fps, " + f"总帧 {total}, 从第 {args.start} 帧起处理 {max_frames} 帧") + print(f"[output] {out_path}") + + # ── 加载管线(首帧含模型加载,较慢) ──────────────── + t_load = time.perf_counter() + pipeline = build_pipeline(args.det_device, args.pose_device, args.detector) + print(f"[model ] {pipeline.detector_name} | det={args.det_device} " + f"pose={args.pose_device} | 加载 {time.perf_counter() - t_load:.1f}s") + + # cv2 的 FFmpeg 后端只支持 mpeg4 编码,播放器兼容性差 → 先写临时文件, + # 结束后用 ffmpeg 转 H.264(libx264 + faststart,通用播放器都能开) + tmp_path = out_path + ".mpeg4.tmp.mp4" + writer = cv2.VideoWriter(tmp_path, cv2.VideoWriter_fourcc(*"mp4v"), + src_fps, (width, height)) + display = not args.no_display + paused = False + n = 0 + t0 = time.perf_counter() + n_hands_frames = 0 + + try: + while True: + # ── 空格暂停时仍刷新窗口,但不读帧 ────────── + if not paused: + ok, frame = cap.read() + if not ok or (max_frames and n >= max_frames): + break + + # 与 process_session() 相同的逐帧推理 + boxes, kpts, scores, track_ids = pipeline.process(frame) + + # 与主程序相同的打包 + 渲染(框 / Hand #ID / 骨骼 / 伸指) + packed = _pack_hand_data(boxes, kpts, track_ids) + out = draw_kpts_overlay(frame, packed, track_ids) + + if boxes: + n_hands_frames += 1 + writer.write(out) + n += 1 + + if n % 30 == 0: + fps = n / (time.perf_counter() - t0) + print(f"[proc ] {n}/{max_frames} 帧 " + f"{fps:5.1f} fps 检出 {n_hands_frames} 帧") + + # ── 显示窗口(帧率限速在下方 waitKey 里做) ── + if display: + cv2.imshow("glove kpts demo - q:quit space:pause", out) + elapsed = time.perf_counter() - t0 + # 按源帧率限速 + wait_ms = max(1, int(1000.0 / src_fps * n - elapsed * 1000)) + else: + wait_ms = 1 + else: + wait_ms = 1 + + if display: + key = cv2.waitKey(wait_ms) & 0xFF + if key in (ord("q"), 27): # q / Esc + print("[demo ] 用户退出") + break + elif key == ord(" "): # 空格 暂停/继续 + paused = not paused + print(f"[demo ] {'暂停' if paused else '继续'}") + finally: + cap.release() + writer.release() + if display: + cv2.destroyAllWindows() + + # ── 转码 H.264(cv2 只能写 mpeg4,部分播放器打不开) ── + if n > 0: + ffmpeg = "" if args.no_transcode else _find_ffmpeg() + if ffmpeg: + print(f"[ffmpeg] {ffmpeg}") + cmd = [ffmpeg, "-y", "-hide_banner", "-loglevel", "error", + "-i", tmp_path, + "-c:v", "libx264", "-preset", "fast", "-crf", "20", + "-pix_fmt", "yuv420p", "-movflags", "+faststart", + out_path] + if subprocess.run(cmd, capture_output=True, text=True).returncode == 0: + os.remove(tmp_path) + else: + print("[ffmpeg] 转码失败,保留 mpeg4 原始输出") + shutil.move(tmp_path, out_path) + else: + if not args.no_transcode: + print("[ffmpeg] 未找到可用 ffmpeg,输出为 mpeg4 " + "(部分播放器可能打不开)") + shutil.move(tmp_path, out_path) + + elapsed = time.perf_counter() - t0 + print(f"[done ] 处理 {n} 帧, 用时 {elapsed:.1f}s, " + f"平均 {n / elapsed:.1f} fps, 检出帧 {n_hands_frames}/{n}") + print(f"[done ] 输出: {out_path}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/collector/tools/demos/hdf5_demo_v1.4/HELP.md b/collector/tools/demos/hdf5_demo_v1.4/HELP.md new file mode 100644 index 0000000000000000000000000000000000000000..0d8660ac2a7292c56983d5f94e3309702dab71ba --- /dev/null +++ b/collector/tools/demos/hdf5_demo_v1.4/HELP.md @@ -0,0 +1,123 @@ +# HDF5 Data Viewer — 使用说明 + +单文件 hdf5 回放查看器。一个窗口同时显示: + +``` +┌─────────────────────┬─────────────────────┐ +│ 左上 │ 右上 │ +│ 相机视频 │ 渲染好的视频 │ +│ (左 | 右) │ (h5 内已渲染) │ +├─────────────────────┼─────────────────────┤ +│ 左下 │ 右下 │ +│ 仿生手掌 │ 触觉热力图 │ +│ (触觉矩阵映射) │ (16x16 矩阵) │ +├─────────────────────┴─────────────────────┤ +│ 底部: IMU 波形 (加速度 | 角速度) │ +└───────────────────────────────────────────┘ +``` + +**传感器自适应布局**:触觉面板(仿生手掌 / 热力图)和 IMU 面板**只有当文件里 +确实含有该传感器数据时才显示**(见下方"传感器检测")。没有数据的面板会被 +隐藏,其余面板自动扩大填满窗口——中间不会空出一块。 + +--- + +## 1. 打开 hdf5 文件 + +### 方式 A. 命令行(推荐) + +```bash +python hdf5_demo.py /your/path/data_001.h5 +``` + +### 方式 B. Open h5 按钮 + +不带参数启动后,点击左下角的 **Open h5** 按钮,在对话框中选择文件。 + +### 方式 C. 播放控制 + +使用底部控制栏: + +- **Play / Pause** 播放 / 暂停 +- **|< / >|** 单帧步进(上一帧 / 下一帧) +- **滑块** 拖动跳转到任意帧 + +--- + +## 2. 数据格式 + +数据从 `episode_*` 组中读取(`*` 可以是任意名称): + +``` +/observation/images/stereo_left (N, 800, 1280, 3) uint8 RGB [必需] +/observation/images/stereo_right (N, 800, 1280, 3) uint8 RGB [必需] +/observation/tactile/left (N, 16, 16) float [可选] +/observation/tactile/right (N, 16, 16) float [可选] +/observation/imu (M, 6) float [可选] + 列: [acc_x acc_y acc_z gyr_x gyr_y gyr_z] +/observation/imu_frame_index (M,) int32 每条 imu 数据对应的帧号 [可选] +``` + +- **双目视频为必需**——缺失时打开会报错 +- 帧数 N 可以为任意值;查看器以视频帧为准对齐其他数据 +- `videos/hand_skeleton` 数据集(MP4 字节)用于右上角渲染视频面板——见第 4 节 + +## 3. 传感器检测 + +查看器根据 h5 文件里实际包含的数据决定显示什么: + +| 文件中的数据 | 仿生手掌 + 热力图 | IMU 面板 | +|---|---|---| +| tactile 存在且有非零样本 | 显示 | - | +| tactile 缺失,或全零(传感器从未被接触) | 隐藏 | - | +| imu + imu_frame_index 存在 | - | 显示 | +| imu 缺失 | - | 隐藏 | + +触觉数据全零(例如录制过程中没有任何东西触碰传感器)会被当作"无数据": +面板隐藏而不是显示空白。某面板被隐藏后,其余面板会扩大使用空出的空间。 + +## 4. 渲染视频(右上角) + +右上角面板播放 **h5 文件里已经渲染好的视频**——查看器本身不做渲染。 +探测顺序: + +1. **优先**:`/videos/hand_skeleton` —— 以原始 MP4 字节存储的 + 手部骨架渲染视频(attr `format=mp4`),自动解码播放 +2. **兜底**:`images` 组内名称包含以下任一关键字的帧数组数据集: + ``` + preview keypoint annot render overlay visual vis kp skeleton slam + ``` + +- 找到 → 视频在右上角面板播放 +- 找不到 → 显示 "No rendered video found",其余功能不受影响 +- 如果你的渲染视频用了其他名字,把名字加到 `hdf5_demo.py` 顶部的 + `RENDERED_KEYWORDS` 元组里,重新运行即可 + +## 5. IMU 波形 + +底部面板绘制 IMU 六个通道(每帧一个点,取该帧的第一个 imu 样本): + +- **上半部分**:加速度 acc_x / acc_y / acc_z +- **下半部分**:角速度 gyr_x / gyr_y / gyr_z +- **白色竖线**:当前视频帧的位置 +- **右侧数值**:当前帧号、该帧内的 imu 样本数(imu 采样率高于视频, + 约 19 个样本/帧),以及各通道的实时数值 + +IMU 以平铺样本数组存储,通过 `imu_frame_index` 把每个样本对应到视频帧; +查看器会自动重新聚合。 + +## 6. 常见问题 + +| 现象 | 处理方式 | +|---|---| +| 打开报错: "no stereo_left/stereo_right" | 文件没有双目视频数据集,检查数据格式 | +| 打开报错: "no episode_* group" | 文件结构不匹配,见第 2 节 | +| 右上角显示 "No rendered video found" | 正常——该 h5 里没有渲染视频,可忽略或见第 4 节 | +| 仿生手掌 / 热力图 / IMU 面板缺失 | 正常——文件里没有(非零的)对应传感器数据 | +| 播放卡顿 | 降低播放速率:把 `hdf5_demo.py` 里的 `timer.setInterval(40)` 改大(例如 80) | + +## 7. 运行环境 + +- Python 3.8 或更高版本 +- 安装依赖:`pip install -r requirements.txt` +- Linux:需要桌面环境(X11/Wayland);Windows:直接运行 diff --git a/collector/tools/demos/hdf5_demo_v1.4/README.md b/collector/tools/demos/hdf5_demo_v1.4/README.md new file mode 100644 index 0000000000000000000000000000000000000000..07160d0847f99e768a012454fa2e088aca257c89 --- /dev/null +++ b/collector/tools/demos/hdf5_demo_v1.4/README.md @@ -0,0 +1,69 @@ +# HDF5 Data Viewer (hdf5_demo) + +Self-contained single-file viewer for hdf5 recordings. All UI text is +English. Shows **stereo video / rendered video / bionic hand / tactile +heatmap / IMU waveform** in one window, with sensor panes appearing only +when the file actually contains that data. + +## Install + +```bash +pip install -r requirements.txt +``` + +Requires Python 3.8+. On Linux a desktop environment (X11/Wayland) is needed. + +## Run + +```bash +python hdf5_demo.py your_data.h5 +``` + +Without an argument, click "Open h5" after startup to pick a file. + +## Layout + +| Position | Content | +|---|---| +| Top-left | Stereo camera video (left \| right side by side) | +| Top-right | Pre-rendered video from the h5 (videos/hand_skeleton MP4, or auto-detected by keywords) | +| Bottom-left | Bionic hand: 16x16 tactile matrix mapped onto a hand figure (L \| R) | +| Bottom-right | Tactile heatmap (16x16 pressure matrix, L \| R) | +| Bottom | IMU waveform: accel X/Y/Z (top) and gyro X/Y/Z (bottom), current frame marked by a white line | + +Controls: Play/Pause, \|< and >| single-frame step, slider to seek. + +## Sensor detection + +- Tactile panes are shown only when the tactile datasets exist **and** + contain non-zero samples (all-zero = sensor never touched = hidden) +- The IMU pane is shown only when `observation/imu` exists +- Hidden panes are removed from the layout (no blank gap); the remaining + panes expand to fill the window + +## Rendered video auto-detection + +The top-right pane plays a video **already rendered inside the h5** - no +rendering is done by the viewer. Priority: + +1. `/videos/hand_skeleton` - MP4 bytes, decoded via a temporary + file + cv2.VideoCapture (sequential read on playback, seek + cache on jumps) +2. Any dataset in `images` whose name contains: `preview, keypoint, annot, + render, overlay, visual, vis, kp, skeleton, slam` + +Extend `RENDERED_KEYWORDS` at the top of the script for other names. + +## Datasets read (inside an episode_* group) + +``` +/observation/images/stereo_left (N,800,1280,3) uint8 RGB [required] +/observation/images/stereo_right (N,800,1280,3) uint8 RGB [required] +/observation/tactile/left (N,16,16) float [optional] +/observation/tactile/right (N,16,16) float [optional] +/observation/imu (M,6) float [acc xyz, gyr xyz] [optional] +/observation/imu_frame_index (M,) int32 [optional] +``` + +Missing optional datasets are tolerated: the corresponding pane is hidden +and the rest keeps playing. Playback rate follows `meta/info` attrs +(`capture_fps` preferred, else file `fps`), defaulting to 25 fps. diff --git a/collector/tools/demos/hdf5_demo_v1.4/hdf5_demo.py b/collector/tools/demos/hdf5_demo_v1.4/hdf5_demo.py new file mode 100644 index 0000000000000000000000000000000000000000..19580dbce7e15752d78b7b9417a48a77225fcb10 --- /dev/null +++ b/collector/tools/demos/hdf5_demo_v1.4/hdf5_demo.py @@ -0,0 +1,741 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +HDF5 数据四宫格演示播放器(单文件自包含,可直接发给客户) + +用法: + python hdf5_demo.py [data.h5] + 不带参数则启动后点"打开文件"选择 + +界面四宫格 + 底部 IMU: + 左上 相机原始视频: 双目并排 (stereo_left | stereo_right), + 单目单图, 或双目+单目同时显示(单目拼在下排) + 右上 渲染好的视频 (videos/hand_skeleton MP4 字节 或 images 内 + preview/keypoint/render/... 帧数组, 自动探测) + 左下 仿生手掌 (16x16 触觉矩阵按部位映射到手掌图形) + 右下 触觉传感器热力图 (16x16 压力矩阵, 左 | 右) + 底部 IMU 加速度/角速度波形 (observation/imu + imu_frame_index) + +依赖 (见 requirements.txt): + numpy, h5py, PyQt5, opencv-python + +hdf5 数据格式 (本 demo 读取的数据集): + /observation/images/stereo_left (N, 800, 1280, 3) uint8 (RGB) + /observation/images/stereo_right (N, 800, 1280, 3) uint8 (RGB) + /observation/images/<单目数据集> (N, H, W, 3) uint8 (RGB) + 单目名: left/mono/monocular/rgb/color/cam0/camera/image/frame/ + left_camera/camera_left/head_left_rgb/head_rgb/front_rgb/front + (与双目独立探测, 可同时存在) + /videos/hand_skeleton (nbytes,) uint8 · MP4 字节 (自动探测) + /observation/images/<渲染视频> (N, H, W, 3) uint8 (自动探测) + /observation/tactile/left (N, 16, 16) float 触觉矩阵 + /observation/tactile/right (N, 16, 16) float + /observation/imu (M, 6) float 变长聚合 (可选) + /observation/imu_frame_index (M,) int IMU 对应帧号 (可选) +""" + +import sys +import os +import time +import argparse + +import numpy as np +import h5py +import cv2 + +from PyQt5.QtCore import Qt, QTimer +from PyQt5.QtGui import QImage, QPixmap +from PyQt5.QtWidgets import ( + QApplication, QMainWindow, QWidget, QLabel, QSlider, QPushButton, + QHBoxLayout, QVBoxLayout, QGridLayout, QFileDialog, QSizePolicy, +) + + +# ══════════════════════════════════════════════════════════════════ +# 1. 仿生手掌 —— 手掌图形锚点 (基于 1280x720 设计, 运行时等比缩放) +# 16x16 触觉矩阵按部位映射到手指关节/掌心 +# ══════════════════════════════════════════════════════════════════ +HAND_ANCHORS = { + "thumb_tip": (350, 280), "thumb_joint": (420, 360), "thumb_base": (480, 420), + "index_tip": (510, 120), "index_joint": (540, 240), "index_base": (560, 340), + "middle_tip": (640, 80), "middle_joint": (640, 200), "middle_base": (640, 320), + "ring_tip": (770, 120), "ring_joint": (740, 240), "ring_base": (720, 340), + "pinky_tip": (930, 280), "pinky_joint": (860, 360), "pinky_base": (800, 420), + "palm": (640, 480), +} +WRIST_ANCHOR = (640, 600) + +# 16×16 传感器矩阵 → 手掌部位映射(行列号) +HAND_PART_CONFIG = { + "thumb_joint": {"rows": [0, 1, 2], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "index_joint": {"rows": [3, 4, 5], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "middle_joint": {"rows": [6, 7, 8], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "ring_joint": {"rows": [9, 10, 11], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "pinky_joint": {"rows": [12, 13, 14], "cols": [14, 12, 13, 15], "axis_order": "col_row"}, + "palm": {"rows": list(range(15)), "cols": [10, 9, 8, 6, 4], "axis_order": "col_row"}, +} + +# Viridis 色表 (cv2 内置, 一次生成缓存) +_VIRIDIS_LUT = cv2.applyColorMap( + np.arange(256, dtype=np.uint8).reshape(256, 1), cv2.COLORMAP_VIRIDIS)[:, 0] + + +def render_bionic_hand(mat, window_size=(640, 400), vmax=None): + """仿生手掌: 2D 手掌骨架 + 触觉矩阵按部位映射 viridis 色块。 + + Args: + mat: 16×16 触觉矩阵 + window_size: 输出画布 (w, h) + vmax: 色块归一化基准 (None = 用本帧最大值) + """ + ww, wh = window_size + sx, sy = ww / 1280.0, wh / 720.0 + frame = np.full((wh, ww, 3), 15, dtype=np.uint8) + + m = np.asarray(mat, dtype=np.float32) + if m.ndim != 2: + m = np.zeros((16, 16), np.float32) + m = np.nan_to_num(m, nan=0.0, posinf=0.0, neginf=0.0) + if vmax is None or vmax <= 0: + vmax = float(m.max()) if m.max() > 0 else 1.0 + + def _sp(x, y): + return (int(x * sx), int(y * sy)) + + wrist = _sp(*WRIST_ANCHOR) + anchors = {k: _sp(*v) for k, v in HAND_ANCHORS.items()} + _lw = lambda v: max(1, int(v * min(sx, sy))) + + # ── 手掌骨骼框架 ── + line_c, joint_c = (60, 60, 60), (80, 80, 80) + cv2.line(frame, wrist, anchors["palm"], line_c, _lw(6), cv2.LINE_AA) + for fg in ("thumb", "index", "middle", "ring", "pinky"): + b, j, t = anchors[f"{fg}_base"], anchors[f"{fg}_joint"], anchors[f"{fg}_tip"] + cv2.line(frame, anchors["palm"], b, line_c, _lw(5), cv2.LINE_AA) + cv2.line(frame, b, j, line_c, _lw(4), cv2.LINE_AA) + cv2.line(frame, j, t, line_c, _lw(3), cv2.LINE_AA) + for p, r in ((b, 10), (j, 8), (t, 6)): + cv2.circle(frame, p, _lw(r), joint_c, -1, cv2.LINE_AA) + cv2.circle(frame, anchors["palm"], _lw(16), joint_c, -1, cv2.LINE_AA) + + # ── 触觉色块映射 ── + CELL = max(1, int(14 * min(sx, sy))) + for part, cfg in HAND_PART_CONFIG.items(): + ax, ay = anchors[part] + rows, cols = cfg["rows"], cfg["cols"] + order = cfg.get("axis_order", "row_col") + nrr, ncc = len(rows), len(cols) + w = ncc * CELL if order == "row_col" else nrr * CELL + h = nrr * CELL if order == "row_col" else ncc * CELL + cx, cy = ax - w // 2, ay - h // 2 + for i, r in enumerate(rows): + for j, c in enumerate(cols): + if r >= 16 or c >= 16: + continue + val = m[r, c] + x1 = cx + (j if order == "row_col" else i) * CELL + y1 = cy + (i if order == "row_col" else j) * CELL + if val > 0: + idx = int(min(255, (val / vmax) * 255)) + b, g, rr = _VIRIDIS_LUT[idx] + cv2.rectangle(frame, (x1, y1), (x1 + CELL, y1 + CELL), + (int(b), int(g), int(rr)), -1) + cv2.rectangle(frame, (x1, y1), (x1 + CELL, y1 + CELL), + (100, 100, 100), 1) + return frame + + +# ══════════════════════════════════════════════════════════════════ +# 2. 工具 +# ══════════════════════════════════════════════════════════════════ +def make_heatmap(mat, size=300, cmap=cv2.COLORMAP_JET, vmax=None): + """16x16 压力矩阵 → 热力图 BGR 图像 (size x size)。""" + m = np.asarray(mat, dtype=np.float32) + if m.ndim != 2: + m = np.zeros((16, 16), np.float32) + m = np.nan_to_num(m, nan=0.0, posinf=0.0, neginf=0.0) + if vmax is None or vmax <= 0: + vmax = float(m.max()) if m.max() > 0 else 1.0 + norm = np.clip(m / vmax, 0.0, 1.0) + big = cv2.resize(norm, (size, size), interpolation=cv2.INTER_NEAREST) + heat = cv2.applyColorMap((big * 255).astype(np.uint8), cmap) + n = m.shape[0] + step = size // n + for i in range(1, n): + cv2.line(heat, (i * step, 0), (i * step, size), (60, 60, 60), 1) + cv2.line(heat, (0, i * step), (size, i * step), (60, 60, 60), 1) + return heat + + +def put_label(img, text, pos, color=(255, 255, 255)): + """叠加标签文字(带黑底)。无效输入(object/空/非3通道)直接忽略。""" + if (not isinstance(img, np.ndarray) or img.dtype == np.object_ + or img.size == 0 or img.ndim != 3 or img.shape[2] != 3): + return + (tw, th), _ = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2) + x, y = pos + cv2.rectangle(img, (x - 4, y - th - 6), (x + tw + 4, y + 4), (0, 0, 0), -1) + cv2.putText(img, text, (x, y), cv2.FONT_HERSHEY_SIMPLEX, + 0.7, color, 2, cv2.LINE_AA) + + +# ══════════════════════════════════════════════════════════════════ +# 2.5 IMU 可视化 (observation/imu 变长聚合: 平铺样本 + imu_frame_index) +# ══════════════════════════════════════════════════════════════════ +_IMU_COLORS = [(255, 90, 90), (90, 255, 90), (90, 170, 255), + (255, 210, 90), (255, 110, 255), (90, 255, 255)] +_IMU_LABELS = ("acc_x", "acc_y", "acc_z", "gyr_x", "gyr_y", "gyr_z") + + +def render_imu(seq, counts, idx, window=240, w=880, h=185): + """IMU 6 通道折线(acc 3 轴 / gyr 3 轴)+ 当前帧竖线 + 数值文本。 + + Args: + seq: (T, 6) 每帧首个 IMU 样本 + counts: (T,) 每帧 IMU 样本数 + idx: 当前视频帧号 + Returns: + BGR 画布(顶部标题区, 右侧数值区, 左侧波形区) + """ + canvas = np.full((h, w, 3), 18, np.uint8) + n = len(seq) + start = max(0, idx - window + 1) + x0, x1 = 14, w - 128 # 波形区 | 右侧文本区 + y0, mid, y1 = 30, h // 2 + 2, h - 8 + + cv2.putText(canvas, "IMU (Accel / Gyro)", (8, 20), + cv2.FONT_HERSHEY_SIMPLEX, 0.55, (220, 220, 220), 1, cv2.LINE_AA) + + # 分上下两图: 上 = acc(0..2), 下 = gyr(3..5) + for part, (ya, yb) in enumerate(((y0, mid - 4), (mid + 4, y1))): + cols = list(range(3 * part, 3 * part + 3)) + vals = seq[start:idx + 1, cols] + if vals.size: + lo, hi = float(np.nanmin(vals)), float(np.nanmax(vals)) + else: + lo, hi = -1.0, 1.0 + if hi - lo < 1e-6: + hi = lo + 1.0 + cv2.putText(canvas, "acc" if part == 0 else "gyr", + (x0 + 2, (ya + yb) // 2 + 5), cv2.FONT_HERSHEY_SIMPLEX, + 0.5, (180, 180, 180), 1, cv2.LINE_AA) + t_start = x0 + 34 + for c in cols: + pts = [] + for t in range(start, idx + 1): + v = seq[t, c] + if v != v: # NaN(该帧无样本) + continue + px = t_start + (t - start) / max(1, window - 1) * (x1 - t_start - 10) + py = ya + (yb - ya) * (1 - (v - lo) / (hi - lo)) + pts.append((int(px), int(py))) + if len(pts) > 1: + cv2.polylines(canvas, [np.array(pts, np.int32)], False, + _IMU_COLORS[c], 1, cv2.LINE_AA) + # 当前帧竖线 + if start <= idx: + px = t_start + (idx - start) / max(1, window - 1) * (x1 - t_start - 10) + cv2.line(canvas, (int(px), ya), (int(px), yb), (255, 255, 255), 1) + + # 右侧: 当前帧数值 + tx = x1 + 8 + cv2.putText(canvas, f"frame {idx}", (tx, y0 + 14), + cv2.FONT_HERSHEY_SIMPLEX, 0.55, (255, 255, 255), 1, cv2.LINE_AA) + ns = int(counts[idx]) if idx < len(counts) else 0 + cv2.putText(canvas, f"samples {ns}", (tx, y0 + 32), + cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 200), 1, cv2.LINE_AA) + for c in range(6): + v = seq[idx, c] if idx < len(seq) else float("nan") + cv2.putText(canvas, f"{_IMU_LABELS[c]} {v:+.2f}", (tx, y0 + 54 + c * 15), + cv2.FONT_HERSHEY_SIMPLEX, 0.42, _IMU_COLORS[c], 1, cv2.LINE_AA) + return canvas + + +# ══════════════════════════════════════════════════════════════════ +# 3. HDF5 数据加载 +# ══════════════════════════════════════════════════════════════════ +# 渲染视频数据集名匹配关键字(自动探测 h5 中已渲染好的视频) +RENDERED_KEYWORDS = ("preview", "keypoint", "annot", "render", "overlay", + "visual", "vis", "kp", "skeleton", "slam") + + +class RenderedVideo: + """h5 内 /videos/hand_skeleton 的 MP4 原始字节 → 按帧解码。 + + 手部骨骼渲染视频以 MP4 字节存于 videos/ 组(attrs 标 format=mp4), + 用临时文件 + cv2.VideoCapture 解码,支持 __len__/__getitem__, + 与 images 组帧数组用法一致。 + + 性能: 逐帧 seek(CAP_PROP_POS_FRAMES)对 h264 要回关键帧重解, 2560×800 + 大帧实测 ~70ms/帧 → 播放会掉帧成慢动作。因此连续访问(播放)走顺序 + read(~5ms/帧), 只有跳转(拖进度条/单帧步进)才 seek, 且跳转帧才缓存 + (缓存上限 _CACHE_MAX, 防 2560×800 帧撑爆内存)。 + """ + _CACHE_MAX = 30 + + def __init__(self, ds): + import tempfile + data = ds[...].tobytes() + self._tmp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) + self._tmp.write(data) + self._tmp.close() + self.cap = cv2.VideoCapture(self._tmp.name) + # 打不开/损坏的 mp4 会返回负帧数, 规整为 0 (len() 必须 >= 0) + self.n = max(0, int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))) + self._cache = {} + self._seq_next = 0 # 顺序读指针(播放加速用) + + def __len__(self): + return self.n + + def __getitem__(self, i): + i = int(i) + if i in self._cache: + # 缓存命中必须同时同步解码器指针: 只更新 _seq_next 会让 cap + # 停在旧位置, 回卷后从 EOF 顺序读返回 None(右上角窗口失效), + # 播放中拖到已缓存帧则会读到错帧。set+read 把 cap 定位到 i+1。 + self.cap.set(cv2.CAP_PROP_POS_FRAMES, i) + self.cap.read() + self._seq_next = i + 1 + return self._cache[i] + if i == self._seq_next: + ok, frame = self.cap.read() # 顺序播放: 直接读, 快 + else: + self.cap.set(cv2.CAP_PROP_POS_FRAMES, i) # 跳转: seek + ok, frame = self.cap.read() + if ok: + self._cache[i] = frame # 只缓存跳转帧 + if len(self._cache) > self._CACHE_MAX: + self._cache.pop(next(iter(self._cache))) + self._seq_next = i + 1 + return frame if ok else None + + def close(self): + try: + self.cap.release() + except Exception: + pass + try: + os.unlink(self._tmp.name) + except OSError: + pass + self._cache.clear() + + +class H5Data: + """读取 hdf5 中的数据(惰性访问,按帧索引取)。""" + + def __init__(self, path): + self.path = path + self.f = h5py.File(path, "r") + ep_groups = [k for k in self.f.keys() if str(k).startswith("episode")] + if not ep_groups: + raise ValueError(f"no episode_* group in hdf5: {list(self.f.keys())}") + self.ep = str(ep_groups[0]) + obs = self.f[f"{self.ep}/observation"] + if "images" not in obs: + raise ValueError("missing observation/images") + + # 视频: 双目与单目独立探测、不互斥 —— 同一个 h5 里混有 + # 双目(S80M)和单目(头戴相机)时, 两组都读进来同时显示; + # 都找不到则报错并列出 images 组内容便于排查 + self.imgs = {} + for side in ("stereo_left", "stereo_right"): + key = f"{self.ep}/observation/images/{side}" + if key in self.f: + self.imgs[side] = self.f[key] + # 单目: 常见数据集名逐个尝试 (与双目同时存在也读) + for name in ("left", "mono", "monocular", "rgb", "color", "cam0", + "camera", "image", "frame", "left_camera", "camera_left", + "head_left_rgb", "head_rgb", "front_rgb", "front"): + if name in self.imgs: + continue + key = f"{self.ep}/observation/images/{name}" + if key in self.f: + self.imgs["mono"] = self.f[key] + break + if not self.imgs: + grp = self.f[f"{self.ep}/observation/images"] + raise ValueError( + "no stereo_left/stereo_right or mono video dataset; " + f"images group contains: {list(grp.keys())}") + self.n = len(next(iter(self.imgs.values()))) + + # 渲染好的视频(自动探测) + self.rendered = self._find_rendered() + + # 触觉矩阵 + self.tactile = {} + for side in ("left", "right"): + key = f"{self.ep}/observation/tactile/{side}" + self.tactile[side] = self.f[key] if key in self.f else None + + # 播放帧率: 优先 meta/info attrs["capture_fps"](可选采集速度标记), + # 无标记 → 按文件 fps 原样播放。 + # 说明: 视频文件本身按录制节奏编码(实测 25fps,墙钟时间戳验证 + # 播放时长≈真实录制时长), 因此文件 fps 即真实速度, 直接按它播 + # 即为实时。capture_fps 仅为将来"采集节拍与文件 fps 不一致"的 + # 批次预留的可选标记, 本批数据无此问题。 + self.fps = 25.0 + self.capture_fps = None + info = self.f.get("meta/info") + if info is not None: + cf = info.attrs.get("capture_fps") + if cf: + try: + self.capture_fps = float(cf) + except (TypeError, ValueError): + pass + f_ = info.attrs.get("fps") + if f_: + try: + self.fps = float(f_) + except (TypeError, ValueError): + pass + if self.capture_fps is None: + f_ = next(iter(self.imgs.values())).attrs.get("fps") + if f_: + try: + self.fps = float(f_) + except (TypeError, ValueError): + pass + + # 预扫触觉全局最大值(热力图/手掌归一化基准) + self.tactile_vmax = 0.0 + for ds in self.tactile.values(): + if ds is not None and len(ds): + try: + self.tactile_vmax = max(self.tactile_vmax, + float(np.nanmax(ds[:]))) + except Exception: + pass + + # IMU(变长聚合:平铺样本 + imu_frame_index 帧号列) + self.imu_seq = None + self.imu_counts = None + imu_key = f"{self.ep}/observation/imu" + if imu_key in self.f: + imu = np.asarray(self.f[imu_key][:], dtype=np.float32) + fidx_key = f"{self.ep}/observation/imu_frame_index" + if fidx_key in self.f: + fidx = np.asarray(self.f[fidx_key][:], dtype=np.int64) + # 按帧号排序后, 取每帧第一个样本作图 + 统计每帧样本数 + order = np.argsort(fidx) + sfidx = fidx[order] + simu = imu[order] + first = np.searchsorted(sfidx, np.arange(self.n), side="left") + counts = np.bincount(sfidx, minlength=self.n) + seq = np.full((self.n, 6), np.nan, dtype=np.float32) + valid = first < len(simu) + seq[valid] = simu[first[valid]] + self.imu_seq, self.imu_counts = seq, counts + + def _find_rendered(self): + """渲染视频自动探测:优先 videos/hand_skeleton(MP4 字节), + 再回退 images 组内名称含渲染关键字的帧数组。""" + vkey = f"{self.ep}/videos/hand_skeleton" + if vkey in self.f: + try: + return RenderedVideo(self.f[vkey]) + except Exception: + pass + grp = self.f[f"{self.ep}/observation/images"] + for name in grp: + if name in ("stereo_left", "stereo_right"): + continue + low = name.lower() + if any(k in low for k in RENDERED_KEYWORDS): + return grp[name] + return None + + def close(self): + if self.rendered is not None and hasattr(self.rendered, "close"): + try: + self.rendered.close() + except Exception: + pass + try: + self.f.close() + except Exception: + pass + + +# ══════════════════════════════════════════════════════════════════ +# 4. 主窗口 +# ══════════════════════════════════════════════════════════════════ +class DemoWindow(QMainWindow): + def __init__(self, h5_path=None): + super().__init__() + self.setWindowTitle("HDF5 Data Viewer") + self.resize(1440, 900) + self.data = None + self.idx = 0 + self.playing = False + + central = QWidget() + self.setCentralWidget(central) + root = QVBoxLayout(central) + + self.lbl_top_left = QLabel("Top-left: Stereo Cameras (L | R)") + self.lbl_top_right = QLabel("Top-right: Rendered Video") + self.lbl_hand = QLabel("Bottom-left: Bionic Hand (L | R)") + self.lbl_heat = QLabel("Bottom-right: Tactile Heatmap (L | R)") + self.lbl_imu = QLabel("Bottom: IMU (Accel / Gyro)") + for lb in (self.lbl_top_left, self.lbl_top_right, + self.lbl_hand, self.lbl_heat, self.lbl_imu): + lb.setAlignment(Qt.AlignCenter) + lb.setMinimumSize(1, 1) + lb.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + lb.setStyleSheet("background:#111; color:#888; font-size:14px;") + + grid = QGridLayout() + grid.addWidget(self.lbl_top_left, 0, 0) + grid.addWidget(self.lbl_top_right, 0, 1) + grid.addWidget(self.lbl_hand, 1, 0) + grid.addWidget(self.lbl_heat, 1, 1) + grid.addWidget(self.lbl_imu, 2, 0, 1, 2) # IMU 横跨底部 + # 行权重: 视频行(0)与手掌行(1)平分剩余空间; IMU 行(2)固定高度。 + # 检测到无传感器时对应行 stretch 归零(load 时), 不会在中间留空。 + grid.setRowStretch(0, 1) + grid.setRowStretch(1, 1) + grid.setRowStretch(2, 0) + grid.setColumnStretch(0, 1); grid.setColumnStretch(1, 1) + root.addLayout(grid, 1) + self.grid = grid + self.lbl_imu.setFixedHeight(240) + + # 控制条 + bar = QHBoxLayout() + self.btn_open = QPushButton("Open h5") + self.btn_play = QPushButton("Play") + self.btn_play.setEnabled(False) + self.slider = QSlider(Qt.Horizontal) + self.slider.setEnabled(False) + self.lbl_frame = QLabel("- / -") + self.btn_prev = QPushButton("|<") # ASCII only, safe on Windows fonts + self.btn_next = QPushButton(">|") + for b in (self.btn_prev, self.btn_next): + b.setEnabled(False) + bar.addWidget(self.btn_open) + bar.addWidget(self.btn_play) + bar.addWidget(self.btn_prev) + bar.addWidget(self.slider, 1) + bar.addWidget(self.btn_next) + bar.addWidget(self.lbl_frame) + root.addLayout(bar) + + self.btn_open.clicked.connect(self.open_file_dialog) + self.btn_play.clicked.connect(self.toggle_play) + self.btn_prev.clicked.connect(lambda: self.seek(self.idx - 1)) + self.btn_next.clicked.connect(lambda: self.seek(self.idx + 1)) + self.slider.sliderMoved.connect(self.seek) + + self.timer = QTimer(self) + self.timer.setInterval(40) # 25fps + self.timer.timeout.connect(self.next_frame) + + if h5_path: + self.load(h5_path) + + # ── 文件 ── + def open_file_dialog(self): + path, _ = QFileDialog.getOpenFileName( + self, "Select HDF5 data file", "", + "HDF5 (*.h5 *.hdf5);;All files (*)") + if path: + self.load(path) + + def load(self, path): + try: + if self.data: + self.data.close() + self.data = H5Data(path) + except Exception as e: + self.statusBar().showMessage(f"Failed to open: {e}", 8000) + return + self.n = self.data.n + self.idx = 0 + # Sensor detection: tactile panes are shown only when the tactile + # datasets exist AND contain non-zero samples (tactile_vmax > 0; + # all-zero data means the sensor was never touched during recording); + # the IMU pane is shown only when imu data exists + self.has_tactile = self.data.tactile_vmax > 0 + self.has_imu = self.data.imu_seq is not None + self.lbl_hand.setVisible(self.has_tactile) + self.lbl_heat.setVisible(self.has_tactile) + self.lbl_imu.setVisible(self.has_imu) + # 无传感器时该行不参与空间分配(否则隐藏行仍按 stretch 分到高度, + # 导致视频与 IMU 之间留一块空) + self.grid.setRowStretch(1, 1 if self.has_tactile else 0) + # 播放时钟按帧率设置: capture_fps 优先(恢复采集实时速度), + # 否则按文件 fps(原速还原) + self.play_fps = self.data.capture_fps or self.data.fps + self.timer.setInterval(max(1, int(round(1000 / self.play_fps)))) + self.slider.setRange(0, max(0, self.n - 1)) + self.slider.setEnabled(True) + self.btn_play.setEnabled(True) + self.btn_prev.setEnabled(True) + self.btn_next.setEnabled(True) + self.setWindowTitle( + f"HDF5 Data Viewer - {os.path.basename(path)} ({self.n} frames @ {self.play_fps:g}fps)") + self.render_frame(0) + rn = "yes" if self.data.rendered is not None else "no" + speed_note = (f"capture speed {self.play_fps:g}fps" if self.data.capture_fps + else f"file speed {self.play_fps:g}fps") + self.statusBar().showMessage( + f"Loaded {os.path.basename(path)}: {self.n} frames | {speed_note} | " + f"rendered video: {rn}", 6000) + + # ── 播放 ── + def toggle_play(self): + self.playing = not self.playing + self.btn_play.setText("Pause" if self.playing else "Play") + if self.playing: + self.timer.start() + else: + self.timer.stop() + + def next_frame(self): + if self.data is None: + return + self.idx = 0 if self.idx + 1 >= self.n else self.idx + 1 + t0 = time.perf_counter() + self.render_frame(self.idx) + # 自调节: 渲染慢于播放时钟时自动降到渲染速率(稳定不掉帧), + # 渲染快时保持时钟速度(30fps → 33ms) + elapsed_ms = (time.perf_counter() - t0) * 1000 + self.timer.setInterval( + max(int(round(1000 / self.play_fps)), int(elapsed_ms))) + + def seek(self, i): + if self.data is None: + return + self.idx = max(0, min(self.n - 1, int(i))) + self.render_frame(self.idx) + + # ── 渲染 ── + def render_frame(self, idx): + self.slider.setValue(idx) + self.lbl_frame.setText(f"{idx + 1} / {self.n}") + + # 左上: 双目并排 + 单目; 无立体对时单目单图 + # 注意: h5 内视频帧以 RGB 存储(导出时 BGR→RGB 写入), + # 这里转回 BGR 给 _show_image(cv2 惯例是 BGR)。 + imgs = self.data.imgs + l_key = "stereo_left" if "stereo_left" in imgs else "mono" + l = cv2.cvtColor(np.asarray(imgs[l_key][idx]), cv2.COLOR_RGB2BGR) + if "stereo_right" in imgs: + r = cv2.cvtColor(np.asarray(imgs["stereo_right"][idx]), + cv2.COLOR_RGB2BGR) + top = np.hstack([l, r]) + cam_label = "Stereo Cameras (L | R)" + elif "stereo_left" in imgs: + top = l + cam_label = "Camera" + else: + top = l + cam_label = "Mono Camera" + put_label(top, cam_label, (12, 26), (0, 255, 255)) + # 单目与双目同时存在: 单目等宽缩放后拼在下方, 两组都可见 + mono_ds = imgs.get("mono") + if mono_ds is not None and "stereo_left" in imgs: + m = cv2.cvtColor(np.asarray(mono_ds[idx]), cv2.COLOR_RGB2BGR) + h, w = top.shape[:2] + mh = max(1, int(round(m.shape[0] * w / m.shape[1]))) + m = cv2.resize(m, (w, mh), interpolation=cv2.INTER_AREA) + put_label(m, "Mono Camera", (12, 26), (255, 255, 0)) + top = np.vstack([top, m]) + self._show_image(self.lbl_top_left, top) + + # 右上: 渲染好的视频(h5 内已有, 不自行渲染) + if self.data.rendered is not None: + n = len(self.data.rendered) + if idx < n: + rv = self.data.rendered[idx] + # 解码失败(RenderedVideo read 返回 None)或数据集为 object + # dtype 时 rv 会是 object 数组, cv2 无法处理 → 提示而非崩溃 + ok_frame = (isinstance(rv, np.ndarray) + and rv.dtype != np.object_ + and rv.size > 0) + if ok_frame: + rv = np.asarray(rv) + # RenderedVideo 解码出 BGR 直接用; images 组帧数组是 RGB 需转 + if not isinstance(self.data.rendered, RenderedVideo): + rv = cv2.cvtColor(rv, cv2.COLOR_RGB2BGR) + put_label(rv, "Rendered Video", (12, 26), (0, 255, 255)) + self._show_image(self.lbl_top_right, rv) + else: + self.lbl_top_right.setText( + "Rendered video: frame decode failed") + else: + self.lbl_top_right.setText( + f"Rendered video too short ({n} < {idx + 1})") + else: + self.lbl_top_right.setText( + "No rendered video found in h5\n" + "(auto-detect: videos/hand_skeleton\n" + "or images with preview/keypoint/render/...)") + + # 左下: 仿生手掌(触觉矩阵映射)— hidden when no tactile data + if self.has_tactile: + mats = [] + for side in ("left", "right"): + ds = self.data.tactile[side] + mats.append(np.asarray(ds[idx], np.float32) + if ds is not None + else np.zeros((16, 16), np.float32)) + w = self.lbl_hand.width() or 620 + h = self.lbl_hand.height() or 400 + bh = render_bionic_hand(mats[0], (w, h), self.data.tactile_vmax) + br = render_bionic_hand(mats[1], (w, h), self.data.tactile_vmax) + pad = np.full((h, 16, 3), 15, np.uint8) + bhv = np.hstack([bh, pad, br]) + put_label(bhv, "Bionic Hand (L | R)", (12, 26), (0, 255, 255)) + self._show_image(self.lbl_hand, bhv) + + # 右下: 触觉热力图 + hm = [make_heatmap(m, size=280, vmax=self.data.tactile_vmax) + for m in mats] + pad2 = np.full((280, 24, 3), 20, np.uint8) + out = np.hstack([hm[0], pad2, hm[1]]) + put_label(out, "Tactile Heatmap (L | R)", (12, 26), (0, 255, 255)) + self._show_image(self.lbl_heat, out) + + # 底部: IMU 波形(最近 window 帧, 当前帧竖线 + 数值)— hidden when no imu + if self.has_imu: + w = self.lbl_imu.width() or 880 + h = self.lbl_imu.height() or 185 + imu = render_imu(self.data.imu_seq, self.data.imu_counts, idx, + window=240, w=max(w, 400), h=max(h, 120)) + self._show_image(self.lbl_imu, imu) + + @staticmethod + def _show_image(label, bgr): + if (not isinstance(bgr, np.ndarray) or bgr.dtype == np.object_ + or bgr.size == 0 or bgr.ndim != 3 or bgr.shape[2] != 3): + return + h, w = bgr.shape[:2] + rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB) + qimg = QImage(rgb.data, w, h, 3 * w, QImage.Format_RGB888) + pix = QPixmap.fromImage(qimg) + label.setPixmap(pix.scaled( + label.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)) + + +# ══════════════════════════════════════════════════════════════════ +# 5. 入口 +# ══════════════════════════════════════════════════════════════════ +def main(): + ap = argparse.ArgumentParser(description="HDF5 data viewer (stereo video / " + "rendered video / tactile / imu)") + ap.add_argument("h5", nargs="?", help="hdf5 file path (optional, use the UI)") + args = ap.parse_args() + + app = QApplication(sys.argv) + win = DemoWindow(args.h5) + win.show() + sys.exit(app.exec_()) + + +if __name__ == "__main__": + main() diff --git a/collector/tools/demos/hdf5_demo_v1.4/requirements.txt b/collector/tools/demos/hdf5_demo_v1.4/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..e888a4d16262a631aa3529f373c11bdfabcd6ee1 --- /dev/null +++ b/collector/tools/demos/hdf5_demo_v1.4/requirements.txt @@ -0,0 +1,5 @@ +# HDF5 演示播放器依赖 (python3 -m pip install -r requirements.txt) +numpy +h5py +PyQt5 +opencv-python diff --git a/collector/tools/demos/pooled_viewer_demo/PooledViewer.spec b/collector/tools/demos/pooled_viewer_demo/PooledViewer.spec new file mode 100644 index 0000000000000000000000000000000000000000..c492b43fbfb5d0918588318564449e68a8d3d3c3 --- /dev/null +++ b/collector/tools/demos/pooled_viewer_demo/PooledViewer.spec @@ -0,0 +1,38 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['pooled_viewer_demo.py'], + pathex=[], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name='PooledViewer', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) diff --git a/collector/tools/demos/pooled_viewer_demo/README.md b/collector/tools/demos/pooled_viewer_demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..da4d33b47247c151bf22705d497ad1ca0e2efb69 --- /dev/null +++ b/collector/tools/demos/pooled_viewer_demo/README.md @@ -0,0 +1,39 @@ +# Pooled Viewer Demo —— 池化录制查看器 + +单文件自包含的查看器 demo:选中主程序池化录制的 `episode-NNN.parquet` 即可播放 +D435 相机视频 + 手套触觉(工具包 tactile.py 同款手掌面板 / 16x16 矩阵网格)+ +手套 IMU 四元数姿态面板。手套可视化沿用手套工具包 +`apps/rendering/tactile.py` 的实现(左右手手指带/掌心布局 2026-08-29 与实机 +逐格核对版本),主程序 GUI 不再显示手套画面。 + +## 用法 + +```bash +# 项目 venv(与主程序同一环境) +venv/bin/python tools/demos/pooled_viewer_demo/pooled_viewer_demo.py [episode-NNN.parquet] + +# 不带参数启动后点"打开 Parquet"选择文件 +``` + +快捷键:空格 播放/暂停,←/→ 上一帧/下一帧,拖动进度条跳帧。 + +## 读取的布局(v1.1.2+ 池化,与主程序 core/helpers.py 约定一致) + +``` +/meta/info.json # fps / features / cameras +/data/chunk-NNN/episode-FFF.parquet # 主时钟 = 行序(30fps 写入节拍) +/videos/chunk-NNN//episode-FFF.mp4 # 每路视频一个文件 +``` + +- 触觉列:`observation.` fixed_size_list\(16×16 摊平); + 传感器名含 left/right 时手掌面板自动按对应手布局渲染 +- IMU 列:`observation._imu_quat`(16×4 XYZW 摊平为 64)+ + `observation._imu_valid`(16 个掩码) +- 帧对齐:视频与传感器行按写入帧号一一对应;播放时视频顺序读、 + 跳帧 seek,视频帧数不足保持最后一帧 +- 深度流(`*_depth` / `.mkv`,12-bit 灰度 HEVC)本 demo 跳过, + 完整回放见主程序回放对话框(Gray12DepthVideo 解码) + +## 依赖 + +numpy / pyarrow / opencv-python / PyQt5 —— 见 requirements.txt。 diff --git a/collector/tools/demos/pooled_viewer_demo/pooled_viewer_demo.py b/collector/tools/demos/pooled_viewer_demo/pooled_viewer_demo.py new file mode 100644 index 0000000000000000000000000000000000000000..8ff8e1b3b654a6d5b42f21dc9e6c993661ece72d --- /dev/null +++ b/collector/tools/demos/pooled_viewer_demo/pooled_viewer_demo.py @@ -0,0 +1,1539 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +池化存储查看器演示(单文件自包含,可直接发给客户) + +用法: + python pooled_viewer_demo.py [episode-NNN.parquet] + 不带参数则启动后点"打开文件"选择数据 parquet + +读取主程序 v1.1.2+ 池化录制布局(与 core/helpers.py 路径约定一致): + /meta/info.json # fps / features / cameras + /data/chunk-NNN/episode-FFF.parquet # 每行 = 一个 30fps 写入帧 + /videos/chunk-NNN//episode-FFF.mp4 # 每路视频一个文件 + +画面(自上而下): + 1) D435 等相机 RGB 视频与深度伪彩视频左右并排(RGB 多路竖排拼接, + 帧号对齐逐帧播放;深度 12-bit 灰度 HEVC MP4 / FFV1 MKV → + 反量化毫米 → 码值 → JET 热力图,与主程序显示口径一致; + 无深度流时 RGB 占满整行) + 2) 手套触觉面板(厂商 Glove-test V1.4 glove_qt_visualizer.py 的 + PressureMatrixCanvas 的 OpenCV 移植:只留 16x16 分区网格, + 手形热图 PressureHandCanvas 移植已按用户要求移除;单面板优先 + 显示左手,会话无左手数据时回退显示右手;可选"触觉基线校正" + (每传感器中位基线,默认开)。与骨架面板在同一行左右并排 + (触觉左、骨架右)) + 3) 手部骨架面板(工具包 apps/rendering/replay.py 的 MANO 21 关键点 + 骨骼渲染,observation.{left,right}_hand_pose,左 | 右; + 视角 = 标定预览初始视角(calibration_pose_preview 的 + _PREVIEW_*:yaw=186.8°/elev=-44.3°/roll=1.5°),每侧绕腕显示 + 旋转烘焙进本文件,手背面向观众(右手拇指在画面右侧、左手拇指 + 在画面左侧);相机距离与居中点按整段数据一次计算,播放中 + 相机完全不动) + 4) 手套 IMU 面板(16 个 BNO055 的四元数姿态,每格画旋转后的 XYZ 轴; + 有骨架数据时默认隐藏,"显示 IMU 四元数"勾选可切出) + +parquet 稀疏列约定(与 core/egodata_writer 一致): + observation. fixed_size_list 16x16 触觉 + observation._imu_quat fixed_size_list 16x4 四元数 XYZW + observation._imu_valid fixed_size_list 有效掩码 + observation._hand_pose fixed_size_list 21x3 骨架(米, + 恒写列;全零 = 无骨架数据) +时间对齐: 主时钟 = parquet 行序(录制时视频与传感器同 30fps 写入节拍)。 +行序 i 对应时刻 t=i/fps,各路视频按各自帧时钟取 round(t×fps) 帧 +(帧率一致即按帧号读;不一致时按比例映射,保证两路画面时间一致)。 +RGB 顺序读/跳转 seek、帧数不足保持尾帧;深度小步前进顺序解、后退/ +大跳 -ss 重建流(帧精确);拖动进度条节流渲染、松手落定。 + +依赖 (见 requirements.txt): + numpy, pyarrow, opencv-python, PyQt5 +""" + +import sys +import os +import re +import math +import time +import shutil +import argparse +import json +import subprocess + +import numpy as np +import pyarrow as pa +import pyarrow.parquet as pq +import cv2 + +from PyQt5.QtCore import Qt, QTimer, QLibraryInfo +from PyQt5.QtGui import QColor, QImage, QPixmap +from PyQt5.QtWidgets import ( + QApplication, QMainWindow, QWidget, QLabel, QSlider, QPushButton, + QHBoxLayout, QVBoxLayout, QGridLayout, QFileDialog, QSizePolicy, + QCheckBox, +) + +# opencv-python 打包了自家 Qt 插件并在 import cv2 时写入 QT_QPA_PLATFORM_PLUGIN_PATH, +# 会让 PyQt5 去加载 ABI 不匹配的 xcb 插件而崩溃 —— 在这里指回 PyQt5 自带的插件目录 +os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = QLibraryInfo.location( + QLibraryInfo.PluginsPath) + +CHUNK_SIZE = 1000 # 每 chunk 1000 个 episode(与主程序一致) + + +# ══════════════════════════════════════════════════════════════════ +# 1. 池化会话数据层 +# ══════════════════════════════════════════════════════════════════ + +_EPISODE_RE = re.compile(r"^(?:episode|file)-(\d{3,})\.parquet$") +_CHUNK_RE = re.compile(r"^chunk-(\d{3,})$") +_DEPTH_KEY_RE = re.compile(r"(^|_)depth$") # d435_depth / head_depth 等深度流 + + +class Mp4Stream: + """单路 MP4 视频按帧访问(顺序读快、跳转 seek + 跳转帧缓存)。 + + 与 hdf5_demo 的 RenderedVideo 相同策略:连续播放走顺序 read + (~5ms/帧),拖进度条才 seek;解码失败/越界返回最后一帧。 + """ + + _CACHE_MAX = 30 + + def __init__(self, path): + self.path = path + self.name = os.path.splitext(os.path.basename( + os.path.dirname(path)))[0] + self.cap = cv2.VideoCapture(path) + if not self.cap.isOpened(): + raise ValueError(f"cannot open video: {path}") + self.n = max(0, int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))) + self.fps = float(self.cap.get(cv2.CAP_PROP_FPS)) or 0.0 + self._cache = {} + self._seq_next = 0 + self._last = None + + def __len__(self): + return self.n + + def __getitem__(self, i): + i = int(i) + if i in self._cache: + self.cap.set(cv2.CAP_PROP_POS_FRAMES, i) + self.cap.read() + self._seq_next = i + 1 + return self._cache[i] + if i == self._seq_next: + ok, frame = self.cap.read() + else: + self.cap.set(cv2.CAP_PROP_POS_FRAMES, i) + ok, frame = self.cap.read() + if ok: + self._cache[i] = frame + if len(self._cache) > self._CACHE_MAX: + self._cache.pop(next(iter(self._cache))) + self._seq_next = i + 1 + if ok and frame is not None: + self._last = frame + return frame + return self._last + + def close(self): + try: + self.cap.release() + except Exception: + pass + + +# ══════════════════════════════════════════════════════════════════ +# 1.5 深度流读取(主程序 core/depth_codec + depth_reader 的轻量移植) +# ══════════════════════════════════════════════════════════════════ +# 深度视频为 12-bit 对数深度码(gray12le HEVC MP4,lerobot v3 同款)或 +# 旧 FFV1 gray16le MKV(uint16 毫米)。cv2 直读 gray12le 的 8-bit 转换 +# 不可靠,统一走 ffmpeg CLI 解 rawvideo;显示口径 = 码值 → JET(与 +# 实时显示同构:mm → log 码 → JET,near/far 线性色标已废弃)。 + +_DEPTH_MIN_MM = 100.0 +_DEPTH_MAX_MM = 5000.0 +_DEPTH_QMAX = 4095 +_DEPTH_LOG_LO = math.log(_DEPTH_MIN_MM) +_DEPTH_LOG_STEP = _DEPTH_QMAX / (math.log(_DEPTH_MAX_MM) - _DEPTH_LOG_LO) + + +def _find_ffmpeg(): + """可用的 ffmpeg 二进制(imageio 静态 → PATH),找不到返回 None。""" + try: + import imageio_ffmpeg + exe = imageio_ffmpeg.get_ffmpeg_exe() + if exe and os.path.isfile(exe): + return exe + except Exception: + pass + p = shutil.which("ffmpeg") + return p if p else None + + +def _depth_to_heatmap_bgr(mm_or_codes, is_mm): + """毫米/码值 → BGR JET 热力图(统一显示口径)。""" + if is_mm: + mm = np.asarray(mm_or_codes) + valid = mm > 0 + codes = np.zeros(mm.shape, dtype=" 0 else 30.0 + if total <= 0: + text = self._probe_text + dm = re.search(r"Duration:\s*(\d+):(\d+):([\d.]+)", text) + if dm and self.fps > 0: + total = int((int(dm.group(1)) * 3600 + int(dm.group(2)) * 60 + + float(dm.group(3))) * self.fps) + self.total = max(1, int(total)) + self._proc = None + self._buf = b"" + self._next_idx = 0 + self._frame_bytes = self.width * self.height * 2 + + @property + def _probe_text(self): + if not hasattr(self, "_probe_text_cache"): + try: + r = subprocess.run( + [self._ffmpeg, "-hide_banner", "-i", self.path], + capture_output=True, timeout=30) + self._probe_text_cache = (r.stderr or b"").decode( + "utf-8", "ignore") + except Exception: + self._probe_text_cache = "" + return self._probe_text_cache + + def _probe_kind(self, path): + text = self._probe_text + if not text: + return None, None + if re.search(r"Video:\s*[^\n]*gray12le", text): + return "mp4", None # 12-bit 对数深度码(hevc Rext) + if re.search(r"Video:\s*ffv1", text): + # 双流件(v1.0.14)= 流0 热力图 h264 + 流1 FFV1;迁移单流件 = 流0 + idx = None + for line in text.splitlines(): + m = re.match(r"\s*Stream #0:(\d+)(?:\([^)]*\))?:\s*Video:\s*ffv1", + line) + if m: + idx = int(m.group(1)) + break + return "mkv", (idx if idx is not None else 0) + return None, None + + def __len__(self): + return self.total + + # 顺序拉帧上限:实测 848x480 HEVC 顺序 ~2ms/帧、-ss 重建 ~21-57ms, + # 30 帧附近两者打平;超过或后退一律 -ss 重建(帧精确、O(1)) + _PULL_FWD_MAX = 30 + + def read(self, idx): + """读取帧 idx(0-based)→ BGR JET 热力图;越界/EOF 返回 None。 + + 访问策略: 小步前进(≤_PULL_FWD_MAX)顺序 pull;后退/大跳 -ss + 重建流。旧实现只在进程死亡时重建——后退时顺序流已越过目标帧 + 无法回卷,直接 _pull() 返回错帧(拖进度条后退时深度面板不动、 + 与其它面板错帧的根因),前进大跳则逐帧解出数千帧(一次 11s+ + 的卡死,进度条拖不动的根因)。 + """ + if idx >= self.total: + return None + if (self._proc is None or self._proc.poll() is not None + or idx < self._next_idx + or idx > self._next_idx + self._PULL_FWD_MAX): + self._open(idx) + while self._next_idx < idx: + if self._pull() is None: + return None + return self._pull() + + def close(self): + if self._proc is not None: + try: + self._proc.kill() + except Exception: + pass + try: + self._proc.wait(timeout=3) + except Exception: + pass + self._proc = None + self._buf = b"" + + def _open(self, idx): + self.close() + if not self._ffmpeg: + return + cmd = [self._ffmpeg, "-hide_banner", "-nostdin"] + if idx > 0: + ss = max(0.0, (idx - 0.5) / self.fps) + cmd += ["-ss", f"{ss:.6f}"] + if self._kind == "mp4": + pix_fmt = "gray12le" + cmd += ["-i", self.path, "-f", "rawvideo", "-pix_fmt", pix_fmt, "-"] + else: + cmd += ["-i", self.path, "-map", f"0:{self._stream}", + "-f", "rawvideo", "-pix_fmt", "gray16le", "-"] + try: + self._proc = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) + except Exception: + self._proc = None + return + self._next_idx = idx + + def _pull(self): + if self._proc is None: + return None + try: + while len(self._buf) < self._frame_bytes: + chunk = self._proc.stdout.read(65536) + if not chunk: + return None + self._buf += chunk + raw = self._buf[:self._frame_bytes] + self._buf = self._buf[self._frame_bytes:] + self._next_idx += 1 + except Exception: + return None + codes = np.frombuffer(raw, " 0: + self.fps = float(self.info["fps"]) + except (TypeError, ValueError): + pass + + # ── data parquet ── + tbl = pq.read_table(self.parquet_path) + self.n = len(tbl) + if self.n == 0: + raise ValueError("parquet 为空: " + self.parquet_path) + schema = tbl.schema + self.frame_indices = ( + tbl.column("frame_index").to_numpy(zero_copy_only=False).astype(np.int64) + if schema.get_field_index("frame_index") >= 0 + else np.arange(self.n, dtype=np.int64)) + self.timestamps = ( + tbl.column("timestamp").to_numpy(zero_copy_only=False).astype(np.float64) + if schema.get_field_index("timestamp") >= 0 + else np.zeros(self.n, np.float64)) + + self.tactile, self.imu_quats, self.imu_valid = {}, {}, {} + self.keypoints = {} + for field in schema: + name = field.name + if not name.startswith("observation."): + continue + sensor = name[len("observation."):] + mat = _col_to_matrix(tbl.column(name), self.n) + if mat is None or mat.shape[1] == 0: + continue + if name.endswith("_imu_quat"): + if mat.shape[1] == 64: + self.imu_quats[sensor[:-len("_imu_quat")]] = mat + elif name.endswith("_imu_valid"): + if mat.shape[1] == 16: + self.imu_valid[sensor[:-len("_imu_valid")]] = mat + elif name.endswith("_hand_pose"): + # 恒写占位列:全零 = 无骨架数据(旧录制/未 warmup),过滤掉 + if (mat.shape[1] == 63 and self.n + and float(np.nanmax(np.abs(mat))) > 1e-6): + self.keypoints[sensor[:-len("_hand_pose")]] = mat + elif mat.shape[1] == 256: + self.tactile[sensor] = mat + # 触觉全局最大值(热力图/手掌归一化基准,全零传感器视为未触碰) + self.tactile_vmax = {} + for sensor, mat in self.tactile.items(): + v = float(np.nanmax(mat)) if self.n else 0.0 + self.tactile_vmax[sensor] = v if v > 0 else 0.0 + # 触觉中位基线(每传感器 16x16 逐格中位数,厂商 Glove-test 工具的 + # 基线校正等价物;"触觉基线校正"勾选时网格显示 值-基线) + self.tactile_baselines = {} + for sensor, mat in self.tactile.items(): + self.tactile_baselines[sensor] = np.median( + mat.reshape(self.n, 16, 16), axis=0).astype(np.float32) + + # ── 视频 ── + self.videos, self.depth_videos, self.skipped_depth = [], [], [] + vroot = os.path.join(self.task_dir, "videos", f"chunk-{chunk_index:03d}") + if os.path.isdir(vroot): + for key in sorted(os.listdir(vroot)): + kd = os.path.join(vroot, key) + if not os.path.isdir(kd): + continue + for fn in sorted(os.listdir(kd)): + if not fn.startswith(self.stem + "."): + continue + ext = os.path.splitext(fn)[1].lower() + if ext not in (".mp4", ".mkv", ".avi"): + continue + if _DEPTH_KEY_RE.search(key) or ext == ".mkv": + # 深度流:12-bit gray12le HEVC MP4 / 旧 FFV1 gray16le + # MKV → DepthVideo(ffmpeg 解码 → 伪彩热力图) + try: + self.depth_videos.append( + DepthVideo(os.path.join(kd, fn))) + except ValueError: + self.skipped_depth.append(key) + continue + try: + self.videos.append(Mp4Stream(os.path.join(kd, fn))) + except ValueError: + pass + # fps 兜底:视频实际帧率优先于 info.json 缺失值 + for v in self.videos: + if v.fps > 0: + self.fps = v.fps + break + + def has_tactile(self): + return any(v > 0 for v in self.tactile_vmax.values()) + + def has_depth(self): + return bool(self.depth_videos) + + def has_imu(self): + return bool(self.imu_quats) + + def has_keypoints(self): + return bool(self.keypoints) + + def keypoints_frame(self, side, idx): + return self.keypoints[side][idx].reshape(21, 3) + + def tactile_frame(self, sensor, idx): + return self.tactile[sensor][idx].reshape(16, 16) + + def imu_frame(self, sensor, idx): + quats = self.imu_quats[sensor][idx].reshape(16, 4).copy() + valid = (self.imu_valid[sensor][idx].reshape(16) > 0.5 + if sensor in self.imu_valid + else np.ones(16, dtype=bool)) + return quats, valid + + def close(self): + for v in self.videos: + v.close() + self.videos = [] + for dv in self.depth_videos: + dv.close() + self.depth_videos = [] + + +# ══════════════════════════════════════════════════════════════════ +# 2. 渲染工具(手套触觉面板 / IMU 姿态面板) +# ══════════════════════════════════════════════════════════════════ +# 手套触觉可视化移植自厂商 Glove-test V1.4 工具 +# glove_qt_visualizer.py 的 PressureMatrixCanvas +# (QPainter → OpenCV,QColor → BGR,中文字串 → 英文,布局/配色照搬): +# render_tactile_grid —— 16x16 分区网格(手指区 y=12…15 / 手掌区 y=3…11 / +# 空值区 y≤2,左右手行翻转;行列号 + 逐格数值 + 图例) +# (2026-09-04 起按用户要求移除手形热图 PressureHandCanvas 移植,只留矩阵) +# 触觉矩阵映射(2026-09-04 与实机录制数据逐格核对): +# 行 = 手指(右手 拇指 1-3/食指 4-6/中指 7-9/无名 10-12/小指 13-15; +# 左手镜像 拇指 15-13 … 小指 3-1),行 0 为空; +# 列 12-15 = 指骨,列序 [14,12,13,15] = 根→尖;列 3-11 = 掌心 +# (右手传感列 [10,9,8,6,4] / 左手 [10,9,8,6]),列 0-2 为空。 +# 面板内拇指统一朝左:网格 x 轴 = 矩阵行,左手翻转、右手不翻 +# (与厂商网格恰好对调,因左手行序与厂商 README 假定相反)。 + +_TACTILE_FINGER_NAMES = ("Thumb", "Index", "Middle", "Ring", "Pinky") +# 手指区分区框颜色(厂商 _FINGER_COLORS,BGR) +_TACTILE_FINGER_BGR = ((68, 68, 239), (11, 158, 245), (94, 197, 34), + (246, 130, 59), (247, 85, 168)) +# 压力色带(厂商 PRESSURE_COLOR_BANDS_CORRECTED / _RAW,BGR) +_TACTILE_BANDS_CORRECTED = ((333, (95, 58, 30)), (666, (199, 134, 22)), + (999, (94, 197, 34)), (1333, (21, 204, 250)), + (1666, (22, 115, 249)), (float("inf"), (68, 68, 239))) +_TACTILE_BANDS_RAW = ((2000, (95, 58, 30)), (2400, (199, 134, 22)), + (2800, (94, 197, 34)), (3200, (21, 204, 250)), + (3600, (22, 115, 249)), (float("inf"), (68, 68, 239))) +_TACTILE_BG = (25, 16, 8) # #081019 +_TACTILE_CELL_IDLE = (49, 33, 18) # #122131(无数据格底色) +_TACTILE_EMPTY_OVERLAY = (48, 38, 30) # (30,38,48) 斜线覆盖 +_TACTILE_GRID_BORDER = (239, 225, 210) # (210,225,239,105) 简化实线 +_TACTILE_TEXT = (245, 232, 220) # #dce8f5 +_TACTILE_TEXT_DIM = (210, 189, 169) # #a9bdd2 +_TACTILE_TEXT_FAINT = (185, 148, 148) # #94a3b8 +_TACTILE_EMPTY_LINE = (184, 163, 148) # #94a3b8 +_TACTILE_SPARE_LINE = (219, 213, 209) # #d1d5db +_TACTILE_PALM_BLUE = (248, 189, 56) # #38bdf8 +_TACTILE_WHITE = (252, 250, 248) # #f8fafc + + +def glove_side_of(sensor: str) -> str: + """传感器列名 → 左右手(默认右手)。""" + low = (sensor or "").lower() + return "left" if "left" in low else "right" + + +def _tactile_heat_color(value, use_baseline): + bands = _TACTILE_BANDS_CORRECTED if use_baseline else _TACTILE_BANDS_RAW + for upper, bgr in bands: + if value <= upper: + return bgr + return bands[-1][1] + + +def render_tactile_grid(matrix, side="right", baseline=None, + use_baseline=True, w=780, h=560): + """16x16 压力矩阵 → 分区确认网格(厂商 PressureMatrixCanvas 移植)。 + + 网格行 = 矩阵列(y=15 在顶 = 指尖),网格列 = 矩阵行(拇指朝左: + 左手翻转、右手不翻);baseline 为 16x16 中位基线(可 None)。 + """ + m = np.asarray(matrix, np.float32).reshape(16, 16) + # 网格 (x, y) = (矩阵行, 矩阵列) —— 厂商网格即直接读 m[x, y],不转置 + img = np.full((h, w, 3), _TACTILE_BG, np.uint8) + left_margin, top_margin, bottom_margin = 54.0, 54.0, 22.0 + legend_width = 250.0 + flip = (side == "left") # 左手行序反转 → 网格 x 翻转 + cell = max(10.0, min((w - left_margin - legend_width) / 16.0, + (h - top_margin - bottom_margin) / 16.0)) + grid_left, grid_top = left_margin, top_margin + if baseline is not None: + base = np.asarray(baseline, np.float32).reshape(16, 16) + + def display_value(x, y): + value = float(m[x, y]) + if use_baseline and baseline is not None: + value = max(0.0, value - float(base[x, y])) + return int(round(value)) + + cv2.putText(img, "X -> 0..15" if not flip else "X -> 15..0", + (int(grid_left) + 16 * int(cell) // 2 - 70, 16), + cv2.FONT_HERSHEY_SIMPLEX, 0.55, _TACTILE_TEXT_DIM, + 1, cv2.LINE_AA) + for display_x in range(16): + x = display_x if not flip else 15 - display_x + cv2.putText(img, str(x), + (int(grid_left + display_x * cell) + int(cell) // 2 - 5, + int(grid_top) - 26), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_TEXT_DIM, + 1, cv2.LINE_AA) + for display_row in range(16): + y = 15 - display_row + row_top = grid_top + display_row * cell + cv2.putText(img, f"y={y}", + (6, int(row_top + cell / 2 + 4)), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_TEXT_DIM, + 1, cv2.LINE_AA) + for display_x in range(16): + x = display_x if not flip else 15 - display_x + value = display_value(x, y) + x0 = int(grid_left + display_x * cell) + y0 = int(row_top) + x1 = int(grid_left + (display_x + 1) * cell) + y1 = int(row_top + cell) + fill = _tactile_heat_color(value, use_baseline) + cv2.rectangle(img, (x0, y0), (x1, y1), fill, -1) + is_empty = y <= 2 + is_spare = y >= 3 and x == 0 + if is_empty or is_spare: + cv2.rectangle(img, (x0, y0), (x1, y1), + _TACTILE_EMPTY_OVERLAY, -1) + cv2.line(img, (x0, y0), (x1, y1), _TACTILE_EMPTY_LINE, 1) + cv2.line(img, (x1, y0), (x0, y1), _TACTILE_EMPTY_LINE, 1) + cv2.rectangle(img, (x0, y0), (x1, y1), _TACTILE_GRID_BORDER, 1) + lum = (0.299 * fill[2] + 0.587 * fill[1] + 0.114 * fill[0]) + text_color = (7, 16, 25) if lum > 145 else (255, 246, 238) + if cell >= 11: + cv2.putText(img, str(value), (x0 + 2, y0 + int(cell) - 4), + cv2.FONT_HERSHEY_SIMPLEX, 0.28, text_color, + 1, cv2.LINE_AA) + + finger_height = 4.0 * cell + for group in range(5): + start_x = 1 + group * 3 + display_start_x = start_x if not flip else 16 - (start_x + 3) + x0 = int(grid_left + display_start_x * cell) + y0 = int(grid_top) + cv2.rectangle(img, (x0 + 2, y0 + 2), + (x0 + int(3 * cell) - 2, y0 + int(finger_height) - 2), + _TACTILE_FINGER_BGR[group], 2) + spare_x = 0 if not flip else 15 + x0 = int(grid_left + spare_x * cell) + cv2.rectangle(img, (x0 + 1, int(grid_top) + 1), + (x0 + int(cell) - 1, int(grid_top + finger_height) - 1), + _TACTILE_SPARE_LINE, 1) + palm_left = grid_left + (cell if not flip else 0.0) + x0 = int(palm_left) + y0 = int(grid_top + 4.0 * cell) + cv2.rectangle(img, (x0 + 2, y0 + 2), + (x0 + int(15 * cell) - 2, y0 + int(9 * cell) - 2), + _TACTILE_PALM_BLUE, 2) + cv2.line(img, (x0, y0), (x0 + int(15 * cell), y0), _TACTILE_WHITE, 2) + + legend_left = int(grid_left + 16 * cell + 18.0) + if legend_left < w - 10: + cv2.putText(img, "Fingers y=12..15", (legend_left, int(grid_top) + 14), + cv2.FONT_HERSHEY_SIMPLEX, 0.45, _TACTILE_TEXT, 1, cv2.LINE_AA) + for group in range(5): + top = int(grid_top + 28.0 + group * 24.0) + cv2.rectangle(img, (legend_left, top), + (legend_left + 15, top + 15), + _TACTILE_FINGER_BGR[group], -1) + cv2.putText(img, f"{_TACTILE_FINGER_NAMES[group]}: x={1+group*3}..{3+group*3}", + (legend_left + 23, top + 13), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_TEXT, 1, cv2.LINE_AA) + cv2.putText(img, "Spare col: x=0, y=3..15", + (legend_left, int(grid_top + 166.0)), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_TEXT_FAINT, + 1, cv2.LINE_AA) + cv2.putText(img, "Palm x=1..15, y=3..11", + (legend_left, int(grid_top + 208.0)), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_PALM_BLUE, + 1, cv2.LINE_AA) + cv2.putText(img, "Empty zone: y=0..2", + (legend_left, int(grid_top + 232.0)), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_TEXT, 1, cv2.LINE_AA) + cv2.putText(img, "Top of view = y=15..0", + (legend_left, int(grid_top + 258.0)), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_TEXT_FAINT, + 1, cv2.LINE_AA) + cv2.putText(img, "fingers point upward", + (legend_left, int(grid_top + 280.0)), + cv2.FONT_HERSHEY_SIMPLEX, 0.4, _TACTILE_TEXT_FAINT, + 1, cv2.LINE_AA) + return img + + +def put_label(img, text, pos, color=(255, 255, 255)): + """叠加标签文字(带黑底)。""" + if (not isinstance(img, np.ndarray) or img.dtype == np.object_ + or img.size == 0 or img.ndim != 3 or img.shape[2] != 3): + return + (tw, th), _ = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.7, 2) + x, y = pos + cv2.rectangle(img, (x - 4, y - th - 6), (x + tw + 4, y + 4), (0, 0, 0), -1) + cv2.putText(img, text, (x, y), cv2.FONT_HERSHEY_SIMPLEX, + 0.7, color, 2, cv2.LINE_AA) + + +# ── IMU 四元数姿态面板 ────────────────────────────────── + +_VIEW_DIR = np.array([0.6, -0.7, 1.0], dtype=np.float64) +_VIEW_DIR /= np.linalg.norm(_VIEW_DIR) +_WORLD_UP = np.array([0.0, 1.0, 0.0], dtype=np.float64) +_E1 = np.cross(_VIEW_DIR, _WORLD_UP) +_E1 /= np.linalg.norm(_E1) +_E2 = np.cross(_VIEW_DIR, _E1) # 屏幕 x = dot(p, e1), 屏幕 y = dot(p, e2) +_AXIS_BGR = ((60, 60, 255), # X 红 + (60, 220, 60), # Y 绿 + (255, 120, 40)) # Z 蓝 +_AXIS_NAMES = ("X", "Y", "Z") + + +def _quat_to_rotmat(q): + """四元数 XYZW → 3x3 旋转矩阵。""" + x, y, z, w = (float(v) for v in q) + xx, yy, zz = x * x, y * y, z * z + xy, xz, yz = x * y, x * z, y * z + wx, wy, wz = w * x, w * y, w * z + return np.array([ + [1 - 2 * (yy + zz), 2 * (xy - wz), 2 * (xz + wy)], + [2 * (xy + wz), 1 - 2 * (xx + zz), 2 * (yz - wx)], + [2 * (xz - wy), 2 * (yz + wx), 1 - 2 * (xx + yy)], + ], dtype=np.float64) + + +def _project(p3): + """3D 点 → 2D 屏幕坐标(斜视正交投影)。""" + return float(np.dot(p3, _E1)), float(np.dot(p3, _E2)) + + +def _arrow(img, p0, p1, color, thick=2): + """带箭头的线段(p0→p1,三角箭头)。""" + cv2.line(img, tuple(p0), tuple(p1), color, thick, cv2.LINE_AA) + d = np.array(p1, np.float64) - np.array(p0, np.float64) + n = np.linalg.norm(d) + if n < 1e-6: + return + t = d / n + nrm = np.array([-t[1], t[0]]) + tip = np.array(p1, np.float64) + cv2.fillConvexPoly(img, np.array([ + tip + t * 5, + tip - t * 3 + nrm * 4, + tip - t * 3 - nrm * 4, + ], np.int32), color, cv2.LINE_AA) + + +def render_imu_panel(quats, valid, w=880, h=240): + """手套 IMU 姿态面板:16 个 BNO055 各画一格,格内为旋转后的 XYZ 轴。 + + Args: + quats: (16,4) float XYZW + valid: (16,) bool + Returns: + BGR 画布 + """ + canvas = np.full((h, w, 3), 18, np.uint8) + n_valid = int(np.count_nonzero(valid)) + cv2.putText(canvas, + f"Glove IMU 四元数姿态 ({n_valid}/16 sensors)", + (8, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.55, + (220, 220, 220), 1, cv2.LINE_AA) + + cols, rows = 4, 4 + top, gap = 30, 6 + cw = max(40, (w - 2 * gap) // cols) + ch = max(40, (h - top - gap) // rows) + for i in range(16): + cx0 = gap + (i % cols) * cw + cy0 = top + (i // cols) * ch + x1, y1 = cx0 + cw - gap, cy0 + ch - gap + ok = bool(valid[i]) and np.isfinite(quats[i]).all() + cv2.rectangle(canvas, (cx0, cy0), (x1, y1), + (60, 160, 60) if ok else (60, 60, 60), + 1 if ok else 1) + cv2.putText(canvas, f"{i}", (cx0 + 3, cy0 + 12), + cv2.FONT_HERSHEY_SIMPLEX, 0.35, + (120, 200, 120) if ok else (110, 110, 110), + 1, cv2.LINE_AA) + c = (cx0 + x1) // 2, (cy0 + y1) // 2 + if not ok: + cv2.line(canvas, (c[0] - 6, c[1] - 6), (c[0] + 6, c[1] + 6), + (90, 90, 90), 1, cv2.LINE_AA) + cv2.line(canvas, (c[0] - 6, c[1] + 6), (c[0] + 6, c[1] - 6), + (90, 90, 90), 1, cv2.LINE_AA) + continue + try: + R = _quat_to_rotmat(quats[i]) + except Exception: + continue + scale = min(cw, ch) * 0.30 + for k in range(3): + tip = _project(R @ np.eye(3)[k] * scale) + _arrow(canvas, + (int(c[0]), int(c[1])), + (int(c[0] + tip[0]), int(c[1] - tip[1])), + _AXIS_BGR[k], 2) + cv2.putText(canvas, "XYZ", (x1 - 34, y1 - 4), + cv2.FONT_HERSHEY_SIMPLEX, 0.3, (140, 140, 140), + 1, cv2.LINE_AA) + return canvas + + +# ══════════════════════════════════════════════════════════════════ +# 2.5 手部骨架渲染(工具包 apps/rendering/replay.py 的 MANO 21 关键点 +# 骨骼渲染器移植:BONES / FINGER_BGR / Camera / _fit_dist / _bg / +# _grid / _draw_hand,画布尺寸参数化以适配面板,像素口径一致) +# ══════════════════════════════════════════════════════════════════ + +# MANO 21 关键点骨骼连接 + 分组: 0 拇指 1 食指 2 中指 3 无名指 4 小指 5 掌骨 +BONES = [ + (0, 1, 0), (1, 2, 0), (2, 3, 0), (3, 4, 0), # thumb + (0, 5, 1), (5, 6, 1), (6, 7, 1), (7, 8, 1), # index + (0, 9, 2), (9, 10, 2), (10, 11, 2), (11, 12, 2), # middle + (0, 13, 3), (13, 14, 3), (14, 15, 3), (15, 16, 3), # ring + (0, 17, 4), (17, 18, 4), (18, 19, 4), (19, 20, 4), # pinky + (5, 9, 5), (9, 13, 5), (13, 17, 5), # metacarpal +] +# 每根手指分组颜色(BGR) +FINGER_BGR = [ + (60, 80, 255), # 0 拇指 红 + (60, 255, 255), # 1 食指 黄 + (60, 220, 60), # 2 中指 绿 + (255, 210, 60), # 3 无名指 青 + (255, 120, 255), # 4 小指 紫 + (210, 210, 210), # 5 掌骨 白 +] + +_SKEL_FOV_DEG = 50.0 + + +# 骨架显示旋转(绕腕部施加,数值烘焙自 stouch_glove_toolkit 的 +# calibration_pose_preview 初始视角): +# canonical = hand_display_basis(中性右手).T(预览注释: 中性手放在世界 XY +# 网格上,指尖朝 +Y、手背法线朝 +Z),左手先做 align_left_to_right_reference。 +# 该 canonical 视角下相机在 -Z 侧望向 +Z,看到的是掌心;再叠加绕 Y 轴 +# 180°(diag(-1,1,-1),det=1 的旋转)把手背翻向 -Z 正对相机 → 观众看到 +# 手背(右手拇指在画面右侧、左手拇指在画面左侧,与真实手背一致)。 +# 渲染约定 rotated = (kpts - wrist) @ R(与 scipy 的 +# R.from_matrix(R.T) apply 逐点等价,已数值验证,max 误差 ~2e-8)。 +_SKEL_ROT_LEFT = np.array([ + [0.16005944656801546, 0.9859625704810917, 0.04752665751616468], + [0.07954678139330758, -0.06087436335953418, 0.9949706636155343], + [0.983896988070553, -0.1554738611339206, -0.08817366596555032], +], np.float64) +_SKEL_ROT_RIGHT = np.array([ + [0.16005944656801546, -0.9859625704810917, -0.04752665751616468], + [-0.07954678139330756, -0.06087436335953418, 0.9949706636155343], + [-0.983896988070553, -0.15547386113392053, -0.08817366596555033], +], np.float64) + +# 标定预览初始视角相机角(calibration_pose_preview 的 _PREVIEW_*) +_SKEL_YAW_DEG = 186.80125157005767 +_SKEL_ELEV_DEG = -44.31525254354176 +_SKEL_ROLL_DEG = 1.524153207538752 + + +class SkeletonCamera: + """球坐标相机 + 透视投影(照工具包 replay.py 的 Camera,画布尺寸参数化)。 + + pan_px: 图像空间平移(照工具包 Camera,用于把手居中,等价预览里 + pan = (w - cx, h - cy) 的构图逻辑)。 + """ + + def __init__(self, yaw_deg, elev_deg, dist, img_w, img_h, roll_deg=0.0, + pan_px=(0.0, 0.0)): + yaw, elev = np.deg2rad(yaw_deg), np.deg2rad(elev_deg) + roll = np.deg2rad(roll_deg) + cp = np.array([dist * np.cos(elev) * np.sin(yaw), + dist * np.sin(elev), + dist * np.cos(elev) * np.cos(yaw)]) + self.pos = cp + self.fwd = -cp / np.linalg.norm(cp) + self.right = np.cross(self.fwd, [0, 1, 0]) + self.right /= np.linalg.norm(self.right) + self.up = np.cross(self.right, self.fwd) + cos_r, sin_r = np.cos(roll), np.sin(roll) + r0, u0 = self.right, self.up + self.right = r0 * cos_r + u0 * sin_r + self.up = -r0 * sin_r + u0 * cos_r + self.w, self.h = img_w, img_h + self.f = (self.h / 2) / np.tan(np.deg2rad(_SKEL_FOV_DEG) / 2) + self.pan_px = [float(pan_px[0]), float(pan_px[1])] + + def project(self, pts3d): + """(N,3) → (N,2) 图像坐标 + (N,) 深度(相机前方为正)。""" + v = pts3d - self.pos + z = v @ self.fwd + x = v @ self.right + y = v @ self.up + u = self.f * x / z + self.w / 2 + self.pan_px[0] + vv = self.h / 2 - self.f * y / z + self.pan_px[1] + return np.stack([u, vv], -1), z + + +def _fit_dist(kpts): + """按手部空间尺度定相机距离(照工具包 replay.py)。""" + v = kpts[np.isfinite(kpts).all(axis=-1)] + if len(v) == 0: + return 0.5 + r = float(np.abs(v).max()) + return max(0.25, r * 2.6 + 0.1) + + +def _skel_bg(w, h): + img = np.empty((h, w, 3), np.uint8) + ramp = (10 + (10 * np.arange(h) // h)).astype(np.uint8) + img[:] = ramp[:, None, None] + return img + + +def _skel_grid(img, cam, r): + """z=0 平面网格 + 三色坐标轴(照工具包 replay.py 的 _grid)。""" + x = [(i / 6) * r for i in range(-6, 7)] + lines = ([([v, -r, 0.0], [v, r, 0.0]) for v in x] + + [([-r, v, 0.0], [r, v, 0.0]) for v in x]) + for p0, p1 in lines: + pts, z = cam.project(np.array([p0, p1], np.float32)) + if (z > 0).all(): + cv2.line(img, tuple(pts[0].astype(int)), tuple(pts[1].astype(int)), + (40, 44, 52), 1, cv2.LINE_AA) + origin = np.zeros((3,), np.float32) + for axis, col in [(np.array([r, 0.0, 0.0]), (40, 60, 255)), # X 红 + (np.array([0.0, r, 0.0]), (40, 255, 60)), # Y 绿 + (np.array([0.0, 0.0, r]), (255, 60, 40))]: # Z 蓝 + pts, z = cam.project(np.stack([origin, axis])) + if (z > 0).all(): + cv2.line(img, tuple(pts[0].astype(int)), tuple(pts[1].astype(int)), + col, 2, cv2.LINE_AA) + + +def _draw_skeleton_hand(img, cam, kpts): + """深度着色的骨骼连线 + 白色关节点(照工具包 replay.py 的 _draw_hand)。""" + pts, z = cam.project(kpts) + vis = np.isfinite(kpts).all(axis=1) & (z > 0) + # 近亮远暗的深度着色;手指比掌骨略亮 + zmin, zmax = 0.05, 0.6 + lum = np.clip((zmax - z) / (zmax - zmin), 0.35, 1.0) + for a, b, g in BONES: + if vis[a] and vis[b]: + k = 0.5 * (lum[a] + lum[b]) + col = tuple(int(c * k) for c in FINGER_BGR[g]) + cv2.line(img, tuple(pts[a].astype(int)), tuple(pts[b].astype(int)), + col, 3, cv2.LINE_AA) + for p, ok in zip(pts, vis): + if ok: + cv2.circle(img, tuple(p.astype(int)), 2, (255, 255, 255), -1, + cv2.LINE_AA) + + +def render_skeleton(kpts, side="right", w=640, h=420, dist=None, center=None, + label=""): + """单手骨架面板:手背面向观众(标定预览初始视角的相机角 + 绕腕显示旋转)。 + + 视角 = calibration_pose_preview 的初始视角相机 + (_PREVIEW_YAW/ELEV/ROLL:yaw=186.80°/elev=-44.32°/roll=1.52°), + 每侧手先绕腕部施加烘焙好的显示旋转(中性手 → 指尖 +Y、手背翻向 + 相机,矩阵见 _SKEL_ROT_LEFT/_SKEL_ROT_RIGHT;约定 + rotated = (kpts - wrist) @ R),再像预览一样按手部投影中心平移居中 + (pan = (w/2 - cx, h/2 - cy)),手腕落在原点、手指朝上、 + 观众看到手背(右手拇指在画面右侧、左手拇指在画面左侧)。 + + Args: + kpts: (21,3) float 关键点(米,MANO 顺序 0=腕) + side: "left" / "right" 选用哪侧的预览旋转矩阵 + dist: 相机距离(None → 按当前帧 _fit_dist;DemoWindow 传入 + load 时按整段数据一次拟合的固定距离,播放中不缩放) + center: 居中用的 3D 手部中心(None → 按当前帧包围盒中心; + DemoWindow 传入 load 时按整段数据一次计算的固定中心, + 播放中相机完全不动、画面不抖) + Returns: + BGR 画布 + """ + if dist is None: + dist = _fit_dist(kpts) + rot = _SKEL_ROT_LEFT if side == "left" else _SKEL_ROT_RIGHT + finite = np.isfinite(kpts).all(axis=-1) + wrist = kpts[0] if finite[0] else np.zeros(3, np.float64) + rotated = (kpts - wrist) @ rot + img = _skel_bg(w, h) + # 先无平移投影一次求手部中心,再按 (w/2-cx, h/2-cy) 平移居中(照预览) + probe = SkeletonCamera(yaw_deg=_SKEL_YAW_DEG, elev_deg=_SKEL_ELEV_DEG, + roll_deg=_SKEL_ROLL_DEG, dist=dist, + img_w=w, img_h=h) + if center is None: + ok = np.isfinite(rotated).all(axis=-1) + center_pts = rotated[ok] if ok.any() else np.zeros((1, 3), np.float64) + center = 0.5 * (center_pts.min(axis=0) + center_pts.max(axis=0)) + pc, _ = probe.project(center[None]) + cam = SkeletonCamera(yaw_deg=_SKEL_YAW_DEG, elev_deg=_SKEL_ELEV_DEG, + roll_deg=_SKEL_ROLL_DEG, dist=dist, + img_w=w, img_h=h, + pan_px=(w / 2 - float(pc[0, 0]), + h / 2 - float(pc[0, 1]))) + _skel_grid(img, cam, dist * 0.5) + _draw_skeleton_hand(img, cam, rotated) + if label: + cv2.putText(img, label, (12, 24), cv2.FONT_HERSHEY_SIMPLEX, 0.7, + (240, 240, 240), 2, cv2.LINE_AA) + return img + + +# ══════════════════════════════════════════════════════════════════ +# 3. 主窗口 +# ══════════════════════════════════════════════════════════════════ +class DemoWindow(QMainWindow): + def __init__(self, parquet_path=None): + super().__init__() + self.setWindowTitle("Pooled Data Viewer") + self.resize(1500, 920) + self.data = None + self.idx = 0 + self.playing = False + self._play_t0 = 0.0 # 播放实时节奏起点(toggle_play 时按当前帧折算) + self._pending_seek = None # 拖动进度条期间的待渲染目标帧 + self._last_slider_render = 0.0 # 上次拖动渲染时刻(节流用) + self._skel_dists = {} # 骨架相机距离(每侧,整段数据一次拟合后固定) + self._skel_centers = {} # 骨架居中点(每侧,整段数据一次计算后固定) + self.tactile_sensors = [] # 触觉面板显示的传感器(优先左手,无左手回退右手) + + central = QWidget() + # 暗色底:面板被隐藏时,空网格单元不露出白色窗口背景。 + # 用调色板+自动填充而不是 QSS —— QSS 无选择器规则会级联到 + # 所有子控件,把底部控制条的按钮/滑条/勾选框也染成深底深字 + pal = central.palette() + pal.setColor(central.backgroundRole(), QColor("#111111")) + central.setPalette(pal) + central.setAutoFillBackground(True) + self.setCentralWidget(central) + root = QVBoxLayout(central) + + self.lbl_video = QLabel("Video: D435 RGB streams") + self.lbl_depth = QLabel("Depth (Pseudo-color)") + self.lbl_hand = QLabel("Glove Tactile Matrix Panel") + self.lbl_skel = QLabel("Hand Skeleton (MANO 21 keypoints)") + self.lbl_imu = QLabel("IMU Quaternions") + for lb in (self.lbl_video, self.lbl_depth, self.lbl_hand, + self.lbl_skel, self.lbl_imu): + lb.setAlignment(Qt.AlignCenter) + lb.setMinimumSize(1, 1) + lb.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) + lb.setStyleSheet("background:#111; color:#888; font-size:14px;") + + grid = QGridLayout() + grid.addWidget(self.lbl_video, 0, 0) + grid.addWidget(self.lbl_depth, 0, 1) + grid.addWidget(self.lbl_hand, 1, 0) + grid.addWidget(self.lbl_skel, 1, 1) + grid.addWidget(self.lbl_imu, 2, 0, 1, 2) + grid.setRowStretch(0, 3) + grid.setRowStretch(1, 2) + grid.setRowStretch(2, 0) + grid.setColumnStretch(0, 1) + grid.setColumnStretch(1, 1) + root.addLayout(grid, 1) + self.grid = grid + self.lbl_imu.setFixedHeight(260) + + # 控制条:独立浅色容器(调色板填充,不用 QSS), + # 按钮/滑条/勾选框保持原生渲染,深色面板底上依然清晰可读 + barw = QWidget() + pal2 = barw.palette() + pal2.setColor(barw.backgroundRole(), QColor("#d9d9d9")) + barw.setPalette(pal2) + barw.setAutoFillBackground(True) + bar = QHBoxLayout(barw) + self.btn_open = QPushButton("打开 Parquet") + self.btn_play = QPushButton("播放") + self.btn_play.setEnabled(False) + self.slider = QSlider(Qt.Horizontal) + self.slider.setEnabled(False) + self.lbl_frame = QLabel("- / -") + self.btn_prev = QPushButton("|<") + self.btn_next = QPushButton(">|") + for b in (self.btn_prev, self.btn_next): + b.setEnabled(False) + self.chk_imu = QCheckBox("显示 IMU 四元数") + self.chk_imu.setVisible(False) + self.chk_tactile_baseline = QCheckBox("触觉基线校正") + self.chk_tactile_baseline.setChecked(True) + self.chk_tactile_baseline.setVisible(False) + bar.addWidget(self.btn_open) + bar.addWidget(self.btn_play) + bar.addWidget(self.btn_prev) + bar.addWidget(self.slider, 1) + bar.addWidget(self.btn_next) + bar.addWidget(self.chk_tactile_baseline) + bar.addWidget(self.chk_imu) + bar.addWidget(self.lbl_frame) + root.addWidget(barw) + + self.btn_open.clicked.connect(self.open_file_dialog) + self.btn_play.clicked.connect(self.toggle_play) + self.btn_prev.clicked.connect(lambda: self.seek(self.idx - 1)) + self.btn_next.clicked.connect(lambda: self.seek(self.idx + 1)) + self.slider.sliderMoved.connect(self._on_slider_moved) + self.slider.sliderReleased.connect(self._on_slider_released) + self.chk_imu.toggled.connect(self._on_imu_toggle) + self.chk_tactile_baseline.toggled.connect( + lambda _c: self.data is not None and self.render_frame(self.idx)) + + self.timer = QTimer(self) + self.timer.setTimerType(Qt.PreciseTimer) # 节奏计时器要精确节拍 + self.timer.setInterval(33) # 30fps;加载后按数据 fps 重设 + self.timer.timeout.connect(self.next_frame) + + if parquet_path: + self.load(parquet_path) + + # ── 文件 ── + def open_file_dialog(self): + path, _ = QFileDialog.getOpenFileName( + self, "选择池化录制 parquet", "", + "Parquet (*.parquet);;All files (*)") + if path: + self.load(path) + + def load(self, path): + try: + if self.data: + self.data.close() + self.data = PooledSession(path) + except Exception as e: + self.statusBar().showMessage(f"打开失败: {e}", 8000) + return + self.n = self.data.n + self.idx = 0 + self._skel_dists = {} + self._skel_centers = {} + self.has_tactile = self.data.has_tactile() + self.has_depth = self.data.has_depth() + self.has_imu = self.data.has_imu() + self.has_kpts = self.data.has_keypoints() + # 触觉面板只留一个:优先左手;会话没有左手数据时回退显示右手 + # (恢复双面板时改回 sorted(self.data.tactile) 即可) + lefts = [s for s in sorted(self.data.tactile) + if glove_side_of(s) == "left"] + rights = [s for s in sorted(self.data.tactile) + if glove_side_of(s) == "right"] + self.tactile_sensors = lefts or rights + self._update_panel_visibility() + # 骨架相机:距离照工具包 replay.py 按整段数据空间尺度一次拟合、 + # 居中点按整段数据各帧包围盒中心的中位数一次计算,播放中全部 + # 固定(相机不动,画面不抖);渲染前绕腕部做显示旋转,拟合时 + # 同样先减去腕部 + self._skel_dists = {} + self._skel_centers = {} + for side, mat in self.data.keypoints.items(): + k = mat.reshape(self.n, 21, 3) + wk = k - k[:, :1, :] + self._skel_dists[side] = _fit_dist(wk) + rot = _SKEL_ROT_LEFT if side == "left" else _SKEL_ROT_RIGHT + rotated = wk @ rot + ok = np.isfinite(rotated).all(axis=-1) + centers = [0.5 * (rotated[f][ok[f]].min(axis=0) + + rotated[f][ok[f]].max(axis=0)) + for f in range(self.n) if ok[f].any()] + if centers: + self._skel_centers[side] = np.median( + np.asarray(centers), axis=0) + # 触觉列存在但全零(传感器无数据/未采集)→ 占位说明,不再静默隐藏 + if not self.has_tactile and self.tactile_sensors: + self.lbl_hand.setVisible(True) + self.lbl_hand.setText( + "触觉列存在但全为零\n" + "(手套触觉传感器无数据,检查硬件/连接后重新录制)") + elif self.tactile_sensors: + # 单面板回退:优先左手,无左手时显示右手 + side = glove_side_of(self.tactile_sensors[0]) + self.lbl_hand.setText( + f"Glove Tactile Matrix Panel ({side.upper()})") + else: + self.lbl_hand.setText("Glove Tactile Matrix Panel") + self.chk_imu.setVisible(self.has_imu and self.has_kpts) + self.chk_tactile_baseline.setVisible(bool(self.tactile_sensors)) + # 深度流缺失时 RGB 占满整行;有深度时两者左右并排 + self.grid.addWidget(self.lbl_video, 0, 0, + 1, 1 if self.has_depth else 2) + self.grid.addWidget(self.lbl_depth, 0, 1) + self.grid.setRowStretch( + 1, 2 if (self.tactile_sensors or self.data.tactile + or self.has_kpts) else 0) + self.play_fps = max(self.data.fps, 1.0) + self.timer.setInterval(max(1, int(round(1000 / self.play_fps)))) + self.slider.setRange(0, max(0, self.n - 1)) + self.slider.setEnabled(True) + self.btn_play.setEnabled(True) + self.btn_prev.setEnabled(True) + self.btn_next.setEnabled(True) + self.setWindowTitle( + f"Pooled Data Viewer - {os.path.basename(path)} " + f"({self.n} 帧 @ {self.play_fps:g}fps, episode {self.data.episode_index})") + self.render_frame(0) + bits = [f"{self.n} 帧", f"fps {self.play_fps:g}", + f"RGB 视频 {len(self.data.videos)} 路", + f"深度 {len(self.data.depth_videos)} 路"] + if self.data.skipped_depth: + bits.append(f"深度流无法解码: {', '.join(self.data.skipped_depth)}") + tbit = f"触觉 {', '.join(self.data.tactile) or '无'}" + if self.tactile_sensors and glove_side_of( + self.tactile_sensors[0]) == "right": + tbit += "(无左手数据,显示右手)" + elif len(self.data.tactile) > len(self.tactile_sensors): + tbit += "(暂只显示左手)" + bits.append(tbit) + bits.append(f"骨架 {', '.join(self.data.keypoints) or '无'}" + if self.has_kpts else "骨架 无") + bits.append(f"IMU {', '.join(self.data.imu_quats) or '无'}") + self.statusBar().showMessage(" | ".join(bits), 10000) + + def _update_panel_visibility(self): + """骨架/IMU 面板可见性:有骨架时骨架优先,IMU 降为勾选兜底。 + + 触觉面板显示 self.tactile_sensors(优先左手,无左手回退右手)。 + """ + self.lbl_depth.setVisible(self.has_depth) + # 有触觉列就保留面板(正常渲染网格;全零时显示说明占位), + # 完全没有触觉列才隐藏 + self.lbl_hand.setVisible( + bool(self.tactile_sensors) or bool(self.data.tactile)) + self.lbl_skel.setVisible(self.has_kpts) + self.lbl_imu.setVisible( + self.has_imu and (not self.has_kpts or self.chk_imu.isChecked())) + + def _on_imu_toggle(self, _checked): + self._update_panel_visibility() + if self.data is not None: + self.render_frame(self.idx) + + # ── 播放 ── + def toggle_play(self): + self.playing = not self.playing + self.btn_play.setText("暂停" if self.playing else "播放") + if self.playing: + # 实时节奏起点:当前帧对应时刻 t=idx/fps(暂停后从原地续播) + self._play_t0 = time.perf_counter() - self.idx / self.play_fps + self.timer.start() + else: + self.timer.stop() + + def next_frame(self): + if self.data is None: + return + # 拖动进度条时不推进播放(拖动是拖拽刷帧,节流渲染跟着拇指走; + # 播放 tick 插进来会按节奏起点把画面抢走,与拖拽打架) + if self.slider.isSliderDown(): + return + # 实时节奏:目标帧 = 起点 + 已过时间×fps(取模循环,与原行为 + # 一致)。渲染慢时直接跳到目标帧——掉帧保速,而不是像旧的自 + # 适应写法那样把播放时钟拉慢(5 分钟数据播 6 分钟的根因)。 + # keep_clock=True:追赶 tick 不得重设节奏起点,否则每次 tick + # 都把时钟锚到当前帧,绝对时钟追赶失效——快机器上 33ms 定时器 + # 对 33.3ms 帧间隔 int(0.99)=0 每两拍才进 1 帧(≈2 倍慢), + # 渲染慢的机器上每拍只进 1 帧(播放速度 = 每帧渲染耗时,即 + # 一秒视频播一点几秒的根因)。 + target = int((time.perf_counter() - self._play_t0) + * self.play_fps) % self.n + if target != self.idx: + self.seek(target, keep_clock=True) + + def seek(self, i, keep_clock=False): + if self.data is None: + return + self.idx = max(0, min(self.n - 1, int(i))) + # 播放中由用户主动跳转(拖进度条/键盘/按钮)→ 重设节奏起点, + # 从新位置继续播放;不重设的话 next_frame 会按旧起点把画面 + # 弹回原播放处。自动播放追赶(keep_clock=True)不重设。 + if self.playing and not keep_clock: + self._play_t0 = time.perf_counter() - self.idx / self.play_fps + self.render_frame(self.idx) + + def _video_frame_for(self, stream, idx): + """主时钟行序 idx → 该路视频帧号(按各自帧时钟对齐)。 + + 行序 i 对应时刻 t = i/play_fps,该路视频取 round(t×fps) 帧: + 帧率一致时即按帧号读;深度等流帧率不同或帧数不足时按比例 + 映射并夹紧,保证两路画面时间一致(不是简单按帧号对齐)。 + """ + if getattr(stream, "fps", 0) > 0 and self.play_fps > 0: + f = int(round(idx * stream.fps / self.play_fps)) + else: + f = idx + return min(max(f, 0), len(stream) - 1) + + # 拖动进度条:sliderMoved 高频触发,深度 seek 每次 ~20-60ms, + # 逐事件整帧渲染会积压卡死 —— 节流到 ≥100ms 一次;松手后必定 + # 落定到最终位置(所有面板一致,不会有的变有的不变) + def _on_slider_moved(self, i): + self._pending_seek = int(i) + now = time.perf_counter() + if now - self._last_slider_render >= 0.1: + self._last_slider_render = now + self.seek(self._pending_seek) + + def _on_slider_released(self): + self._last_slider_render = time.perf_counter() + if self._pending_seek is not None: + i, self._pending_seek = self._pending_seek, None + self.seek(i) + else: + self.seek(self.slider.value()) + + def keyPressEvent(self, ev): + if ev.key() == Qt.Key_Space: + self.toggle_play() + elif ev.key() == Qt.Key_Left: + self.seek(self.idx - 1) + elif ev.key() == Qt.Key_Right: + self.seek(self.idx + 1) + elif ev.key() == Qt.Key_PageUp: + self.seek(self.idx + max(1, int(round(5 * self.play_fps)))) + elif ev.key() == Qt.Key_PageDown: + self.seek(self.idx - max(1, int(round(5 * self.play_fps)))) + elif ev.key() == Qt.Key_Home: + self.seek(0) + elif ev.key() == Qt.Key_End: + self.seek(self.n - 1) + else: + super().keyPressEvent(ev) + + # ── 渲染 ── + def render_frame(self, idx): + # 拖动中不 setValue:会把拇指弹回已渲染位置,与用户拖拽打架 + # (拖动一次渲染一次时表现为进度条拖不动) + if not self.slider.isSliderDown(): + self.slider.setValue(idx) + ts = self.data.timestamps[idx] + self.lbl_frame.setText( + f"{idx + 1} / {self.n} t={ts:.3f}s") + + # 1) 视频面板:多路 RGB 竖排拼接(按各自帧时钟对齐主时钟) + if self.data.videos: + w = self.lbl_video.width() or 1280 + panels = [] + for v in self.data.videos: + frame = v[self._video_frame_for(v, idx)] + if frame is None: + frame = np.full((360, 640, 3), 15, np.uint8) + frame = np.asarray(frame) + if frame.dtype == np.object_ or frame.ndim != 3: + frame = np.full((360, 640, 3), 15, np.uint8) + if frame.shape[1] != w: + hh = max(1, int(round(frame.shape[0] * w / frame.shape[1]))) + frame = cv2.resize(frame, (w, hh), + interpolation=cv2.INTER_AREA) + put_label(frame, v.name, (12, 26), (0, 255, 255)) + panels.append(frame) + if len(panels) > 1: + pad = np.full((6, w, 3), 10, np.uint8) + top = panels[0] + for p in panels[1:]: + top = np.vstack([top, pad, p]) + else: + top = panels[0] + self._show_image(self.lbl_video, top) + else: + self.lbl_video.setText("无 RGB 视频文件\n" + "(videos/chunk-NNN//episode-FFF.mp4)") + + # 1.5) 深度伪彩面板:多路深度流竖排拼接(按各自帧时钟对齐主时钟, + # JET 热力图) + if self.has_depth and self.data.depth_videos: + w = self.lbl_video.width() or 1280 + panels = [] + for dv in self.data.depth_videos: + frame = dv.read(self._video_frame_for(dv, idx)) + if frame is None: + frame = np.full((360, 640, 3), 15, np.uint8) + frame = np.asarray(frame) + if frame.ndim != 3: + frame = np.full((360, 640, 3), 15, np.uint8) + if frame.shape[1] != w: + hh = max(1, int(round(frame.shape[0] * w / frame.shape[1]))) + frame = cv2.resize(frame, (w, hh), + interpolation=cv2.INTER_AREA) + put_label(frame, dv.name + " (depth, JET)", (12, 26), + (0, 255, 255)) + panels.append(frame) + if len(panels) > 1: + pad = np.full((6, w, 3), 10, np.uint8) + top = panels[0] + for p in panels[1:]: + top = np.vstack([top, pad, p]) + else: + top = panels[0] + self._show_image(self.lbl_depth, top) + + # 2) 手套触觉面板(厂商 Glove-test 移植:只留分区网格,手形热图 + # 已按用户要求移除;优先显示左手,会话无左手数据时回退显示 + # 右手;全零数据时不渲染、保留 load 里的占位说明文字) + sensors = self.tactile_sensors + if self.has_tactile and sensors: + h = max(self.lbl_hand.height() or 560, 240) + w = self.lbl_hand.width() or 1280 + use_baseline = self.chk_tactile_baseline.isChecked() + per_w = max(680, (w - 24 * (len(sensors) - 1)) // len(sensors)) + panels = [] + for sn in sensors: + side = glove_side_of(sn) + mat = self.data.tactile_frame(sn, idx) + baseline = (self.data.tactile_baselines.get(sn) + if use_baseline else None) + panels.append(render_tactile_grid( + mat, side=side, baseline=baseline, + use_baseline=use_baseline, w=int(per_w), h=h)) + pad24 = np.full((h, 24, 3), 15, np.uint8) + bhv = panels[0] + for p in panels[1:]: + bhv = np.hstack([bhv, pad24, p]) + put_label(bhv, "Tactile Matrix (Glove-test V1.4 port)", (12, 26), + (0, 255, 255)) + self._show_image(self.lbl_hand, bhv) + + # 3) 手部骨架面板(MANO 21 关键点,每侧一个面板横排;视角 = + # 标定预览初始视角 yaw=186.8°/elev=-44.3°/roll=1.5° + 每侧 + # 绕腕显示旋转,手背面向观众;相机距离与居中点均为 load 时 + # 按整段数据一次计算的固定值,播放中相机不动) + kpt_sides = sorted(self.data.keypoints) + if self.has_kpts and kpt_sides: + h = max(self.lbl_skel.height() or 420, 360) + w = self.lbl_skel.width() or 1280 + panel_w = max(480, w // len(kpt_sides)) + panels = [] + for side in kpt_sides: + kpts = self.data.keypoints_frame(side, idx) + panels.append(render_skeleton( + kpts, side=side, w=panel_w, h=h, + dist=self._skel_dists.get(side), + center=self._skel_centers.get(side), + label=side.capitalize())) + if len(panels) > 1: + pad = np.full((h, 8, 3), 15, np.uint8) + out = panels[0] + for p in panels[1:]: + out = np.hstack([out, pad, p]) + else: + out = panels[0] + self._show_image(self.lbl_skel, out) + + # 4) IMU 姿态面板(每传感器一个面板,竖排;有骨架时默认隐藏) + imu_sensors = sorted(self.data.imu_quats) + if self.has_imu and imu_sensors and self.lbl_imu.isVisible(): + w = self.lbl_imu.width() or 880 + h = self.lbl_imu.height() or 240 + panels = [] + for sn in imu_sensors: + quats, valid = self.data.imu_frame(sn, idx) + panels.append(render_imu_panel( + quats, valid, w=max(w, 640), h=max(h, 200))) + if len(panels) > 1: + pad = np.full((4, max(w, 640), 3), 10, np.uint8) + out = panels[0] + for p in panels[1:]: + out = np.vstack([out, pad, p]) + self._show_image(self.lbl_imu, out) + else: + self._show_image(self.lbl_imu, panels[0]) + + @staticmethod + def _show_image(label, bgr): + if (not isinstance(bgr, np.ndarray) or bgr.dtype == np.object_ + or bgr.size == 0 or bgr.ndim != 3 or bgr.shape[2] != 3): + return + h, w = bgr.shape[:2] + if not bgr.flags.c_contiguous: + bgr = np.ascontiguousarray(bgr) + # Format_BGR888 直接包住 BGR 数据,免掉每帧全图 cvtColor; + # 缩放到标签尺寸用 FastTransformation(Smooth 每面板每帧数 + # 毫秒,四个面板叠起来是播放掉速的主因之一) + qimg = QImage(bgr.data, w, h, 3 * w, QImage.Format_BGR888) + pix = QPixmap.fromImage(qimg) + label.setPixmap(pix.scaled( + label.size(), Qt.KeepAspectRatio, Qt.FastTransformation)) + + def closeEvent(self, ev): + self.timer.stop() + if self.data: + self.data.close() + super().closeEvent(ev) + + +# ══════════════════════════════════════════════════════════════════ +# 4. 入口 +# ══════════════════════════════════════════════════════════════════ +def main(): + ap = argparse.ArgumentParser( + description="池化存储查看器(D435 视频 + 手套触觉/IMU 可视化)") + ap.add_argument("parquet", nargs="?", + help="episode-NNN.parquet 路径(可选,用界面打开)") + args = ap.parse_args() + + app = QApplication(sys.argv) + win = DemoWindow(args.parquet) + win.show() + sys.exit(app.exec_()) + + +if __name__ == "__main__": + main() diff --git a/collector/tools/demos/pooled_viewer_demo/requirements.txt b/collector/tools/demos/pooled_viewer_demo/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..34c1ae66dd01a27226d005068688f75671dbdd1f --- /dev/null +++ b/collector/tools/demos/pooled_viewer_demo/requirements.txt @@ -0,0 +1,4 @@ +numpy +pyarrow +opencv-python +PyQt5 diff --git a/collector/tools/demos/run_stereo_depth_demo.sh b/collector/tools/demos/run_stereo_depth_demo.sh new file mode 100755 index 0000000000000000000000000000000000000000..a78c0cb17764946ad97ac17b166860b27a15be5c --- /dev/null +++ b/collector/tools/demos/run_stereo_depth_demo.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# S80M 双目深度 Demo 启动器 +# +# 深度引擎 libfayssense_aikit_depth.so 按 SDK 自带 OpenCV 4.2.0 编译, +# 系统 OpenCV 4.6/4.13 不兼容 (cv::Exception: Unknown/unsupported array type). +# 通过 LD_LIBRARY_PATH 让 SDK 库绑定到自带 4.2 (lib406 目录). +# +# 用法: +# ./run_stereo_depth_demo.sh + +set -e +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SDK_DIR="${SDK_DIR:-${FAYSSENSE_SDK_DIR:-}}" +if [ -z "$SDK_DIR" ]; then + echo "[ERROR] 请设置 SDK_DIR 或 FAYSSENSE_SDK_DIR=" >&2 + exit 1 +fi +OPENCV406_DIR="$SDK_DIR/thirdparty/opencv-4.2.0-linux-x86_64/lib406" + +if [ ! -d "$OPENCV406_DIR" ]; then + echo "[ERROR] 找不到自带 OpenCV 4.2 目录: $OPENCV406_DIR" + echo "请先在 SDK 中构建 lib406 (符号链接 4.2 库为 .so.406 命名 + 外部依赖)" >&2 + exit 1 +fi + +export LD_LIBRARY_PATH="$OPENCV406_DIR:$LD_LIBRARY_PATH" +exec python3 -u "$SCRIPT_DIR/test_stereo_depth_calib.py" "$@" diff --git a/collector/tools/demos/stereo_2d_demo/README.md b/collector/tools/demos/stereo_2d_demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0d86f06ceeefc0ca34af2cc9f9e7b48ab52fb3da --- /dev/null +++ b/collector/tools/demos/stereo_2d_demo/README.md @@ -0,0 +1,115 @@ +# stereo_2d_demo —— 双目/单目视频 2D 手部关键点检测 + 渲染 Demo + +**自包含**:整个 demo 只有一个 Python 文件,不依赖仓库里任何其他模块或目录。 +拿到压缩包解压后,装好依赖即可运行。 + +## 目录内容 + +``` +stereo_2d_demo/ +├── stereo_2d_demo.py # 主程序(单文件:检测 + 平滑 + 绘制 + 视频输出) +├── hand_landmarker.task # MediaPipe 手部关键点模型(约 7.5MB) +├── requirements.txt # Python 依赖 +├── run.sh # 一键运行脚本 +└── README.md # 本说明 +``` + +## 环境要求 + +- Python 3.9+(3.10/3.11 均可) +- 建议新建虚拟环境安装依赖: + +```bash +python3 -m venv venv +source venv/bin/activate # Windows: venv\Scripts\activate +pip install -r requirements.txt +``` + +> 模型 `hand_landmarker.task` 必须和 `stereo_2d_demo.py` 放在**同一目录**。 +> 若机器无法联网,用别人装好的环境直接拷贝 venv 目录也可用。 + +## 使用方法 + +### 一键脚本(自动检测 venv) + +```bash +# 双目(左右目并排输出) +./run.sh left.mp4 right.mp4 + +# 单目 +./run.sh demo.mp4 + +# 指定输出文件 +./run.sh left.mp4 right.mp4 -o out.mp4 +``` + +### 直接运行 + +```bash +# 双目(左右目并排输出,默认输出 stereo_2d_output.mp4) +python stereo_2d_demo.py left.mp4 right.mp4 + +# 单目 +python stereo_2d_demo.py demo.mp4 + +# 指定输出 + 跟手调优 +python stereo_2d_demo.py left.mp4 right.mp4 -o out.mp4 --freq-min 15 --beta 0.6 + +# 完全关闭平滑(最跟手,但抖动全部保留) +python stereo_2d_demo.py left.mp4 right.mp4 --no-smooth +``` + +## 参数说明 + +| 参数 | 默认 | 说明 | +|------|------|------| +| `videos` | — | 1 个视频=单目;2 个视频=左右目并排输出 | +| `-o, --output` | `stereo_2d_output.mp4` | 输出视频路径 | +| `--model` | 本目录 `hand_landmarker.task` | 模型路径 | +| `--freq-min` | `15.0` | One-Euro 滤波截止频率 Hz。**越大越跟手**(同时越抖),越小越平滑(越滞后) | +| `--beta` | `0.6` | 速度自适应系数。快速运动时滞后就调大 | +| `--no-smooth` | 关 | 关闭 One-Euro 平滑,关键点完全原始(最跟手,抖动全保留) | + +**跟手性调参建议**: +- 感觉关键点"粘在上一帧、跟不上手" → 调大 `--freq-min`(如 15→30),或加 `--no-smooth` +- 感觉关键点抖动厉害 → 调小 `--freq-min`(如 5) +- 快速挥动手臂时明显滞后 → 调大 `--beta` + +## 输出效果 + +- 每只手:**青绿色包围框** + 底衬标签 `Hand #0 / #1` +- **五指分色骨架**:拇指橙、食指绿、中指黄、无名指紫、小指蓝;掌心灰色连接线、腕部白色大圆 +- 框下方**手势文本**:`open: 食指,中指`(伸开手指名)或 `fist`(握拳) +- 左上角显示摄像头名与帧进度,底部图例说明 + +## 常见问题 + +**Q1: 报错 `无法打开视频`** +视频路径不存在或编码不支持(如 HEVC)。先用 ffplay/VLC 确认能打开,或转成 H.264 再跑。 + +**Q2: 输出的是 mp4v(不压缩)或没有声音** +输出视频只有画面没有声音(demo 不做音频)。若机器没有 ffmpeg,会自动退回 mp4v 编码; +装了 ffmpeg 则会自动转成 H.264 压缩,体积小很多。装 ffmpeg: + +```bash +# Ubuntu/Debian +sudo apt install ffmpeg +# macOS +brew install ffmpeg +``` + +**Q3: 检测不到手 / 双手只显示一只** +- 手离镜头太远或太小 → 拉近拍摄 +- 调整置信度:编辑 `stereo_2d_demo.py` 中 `min_hand_detection_confidence=0.5` 等处 + (数字越小越容易检出,误检越多) + +**Q4: 运行时很慢 / 卡顿** +检测是逐帧 CPU 推理,720p 双目约 40-60 帧/秒(含渲染)。慢机器可先缩小视频 +(如 `ffmpeg -i in.mp4 -vf scale=640:400 out.mp4`)再跑。 + +**Q5: 关掉后重跑为什么还是老输出?** +同名输出文件会被覆盖;如需保留请用 `-o` 指定新名字。 + +## 免责说明 + +手部关键点检测结果受光照、遮挡、手部大小影响,仅供参考,请结合实际场景评估效果。 diff --git a/collector/tools/demos/stereo_2d_demo/hand_landmarker.task b/collector/tools/demos/stereo_2d_demo/hand_landmarker.task new file mode 100755 index 0000000000000000000000000000000000000000..5ecab741879892d97c2f90bbf03bf55d7213db7c --- /dev/null +++ b/collector/tools/demos/stereo_2d_demo/hand_landmarker.task @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbc2a30080c3c557093b5ddfc334698132eb341044ccee322ccf8bcf3607cde1 +size 7819105 diff --git a/collector/tools/demos/stereo_2d_demo/requirements.txt b/collector/tools/demos/stereo_2d_demo/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..bfa4672cf0c47b4b2d7b8aa528a9154d97eccc54 --- /dev/null +++ b/collector/tools/demos/stereo_2d_demo/requirements.txt @@ -0,0 +1,3 @@ +mediapipe>=0.10 +opencv-python>=4.5 +numpy>=1.21 diff --git a/collector/tools/demos/stereo_2d_demo/run.sh b/collector/tools/demos/stereo_2d_demo/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..cc6dc578d622270838fe0ae9a2b60f533d75d15c --- /dev/null +++ b/collector/tools/demos/stereo_2d_demo/run.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# stereo_2d_demo 一键运行脚本(单目或双目) +set -e +cd "$(dirname "$0")" + +if [ $# -lt 1 ]; then + echo "用法: ./run.sh <视频1> [视频2] [-o 输出.mp4] [--no-smooth] [--freq-min 15] [--beta 0.6]" + echo "示例:" + echo " 单目: ./run.sh demo.mp4" + echo " 双目: ./run.sh left.mp4 right.mp4" + echo " 双目+跟手调优: ./run.sh left.mp4 right.mp4 --freq-min 15 --beta 0.6" + echo " 关闭平滑: ./run.sh left.mp4 right.mp4 --no-smooth" + exit 1 +fi + +if ! command -v python3 >/dev/null 2>&1; then + echo "[ERROR] 找不到 python3,请先安装 Python 3.9+" + exit 1 +fi + +# 优先用当前目录的 venv(如部署方自建),否则用系统 python3 +if [ -x "venv/bin/python" ]; then + PY=venv/bin/python + echo "使用本地 venv: $PY" +else + PY=python3 +fi + +echo "运行: $PY stereo_2d_demo.py $*" +exec "$PY" stereo_2d_demo.py "$@" diff --git a/collector/tools/demos/stereo_2d_demo/stereo_2d_demo.py b/collector/tools/demos/stereo_2d_demo/stereo_2d_demo.py new file mode 100644 index 0000000000000000000000000000000000000000..f31b8d6fed0fbf1c0676b3937d0b8dc7a895fad0 --- /dev/null +++ b/collector/tools/demos/stereo_2d_demo/stereo_2d_demo.py @@ -0,0 +1,418 @@ +#!/usr/bin/env python3 +"""stereo_2d_demo.py —— 双目(或单目)视频 2D 手部关键点检测 + 渲染演示。 + +**自包含单文件**:不依赖仓库里任何其他模块。MediaPipe 检测、One-Euro 平滑、 +五指分色绘制、手势识别、视频合成与 H.264 转码全部逻辑都在这一个文件里。 +模型文件 hand_landmarker.task 需与本文件放在同一目录(默认路径为 +本文件所在目录下的 hand_landmarker.task,可用 --model 指定)。 + +用法:: + + # 双目(左右目并排输出,标注 2D 关键点) + python stereo_2d_demo.py left.mp4 right.mp4 -o out.mp4 + + # 单目 + python stereo_2d_demo.py single.mp4 -o out.mp4 + + # 更跟手/更平滑调节 + python stereo_2d_demo.py left.mp4 right.mp4 --freq-min 15 --beta 0.6 + python stereo_2d_demo.py left.mp4 right.mp4 --no-smooth # 完全关平滑 + +依赖(pip install mediapipe opencv-python numpy):: + + pip install mediapipe opencv-python numpy + +输出: 带关键点叠加的视频(H.264 或 mp4v 兜底)。 +""" + +from __future__ import annotations + +import argparse +import math +import os +import shutil +import subprocess +import sys +import time + +import cv2 +import numpy as np + +# ───────────────────────────────────────────────────────────── +# 1. 手部关键点定义(MediaPipe 21 点) +# 0 腕, 1-4 拇指, 5-8 食指, 9-12 中指, 13-16 无名指, 17-20 小指 +# ───────────────────────────────────────────────────────────── + +FINGERS = { + "Thumb": ([1, 2, 3, 4], (255, 128, 0)), + "Index": ([5, 6, 7, 8], (0, 255, 0)), + "Middle": ([9, 10, 11, 12], (0, 255, 255)), + "Ring": ([13, 14, 15, 16], (255, 0, 255)), + "Pinky": ([17, 18, 19, 20], (0, 128, 255)), +} +PALM_CONNECTIONS = [(0, 1), (0, 5), (5, 9), (9, 13), (13, 17), (0, 17)] + + +def _joint_specs(): + specs = [] + for finger, (ids, color) in FINGERS.items(): + a, b, c, d = ids + names = ("CMC", "MCP", "IP") if finger == "Thumb" else ("MCP", "PIP", "DIP") + specs.append((finger, names[0], a, 0, b, color)) + specs.append((finger, names[1], b, a, c, color)) + specs.append((finger, names[2], c, b, d, color)) + return specs + + +JOINT_SPECS = _joint_specs() + +MODEL_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), + "hand_landmarker.task") + +# ───────────────────────────────────────────────────────────── +# 2. 关节角度 / 手势判定 +# ───────────────────────────────────────────────────────────── + +def _angle_between(p_prev, p_vertex, p_next): + """顶点处两条骨段的夹角(度)。180° = 伸直。""" + v1 = np.asarray(p_prev, dtype=np.float64) - np.asarray(p_vertex, dtype=np.float64) + v2 = np.asarray(p_next, dtype=np.float64) - np.asarray(p_vertex, dtype=np.float64) + n1, n2 = np.linalg.norm(v1), np.linalg.norm(v2) + if n1 < 1e-9 or n2 < 1e-9: + return 0.0 + cos = float(np.dot(v1, v2) / (n1 * n2)) + return math.degrees(math.acos(max(-1.0, min(1.0, cos)))) + + +def _compute_joint_angles(pts): + """21 点 (21,2) → 每关节角度 dict {(finger, joint): 度}。""" + return {(f, j): _angle_between(pts[p], pts[v], pts[n]) + for f, j, v, p, n, _ in JOINT_SPECS} + + +def _count_extended_fingers(angles): + """角度 → 伸直手指名列表(空 = 握拳)。""" + out = [] + for finger in FINGERS: + if finger == "Thumb": + ok = angles.get((finger, "MCP"), 0) > 145 and angles.get((finger, "IP"), 0) > 150 + else: + ok = angles.get((finger, "PIP"), 0) > 150 and angles.get((finger, "DIP"), 0) > 140 + if ok: + out.append(finger) + return out + + +# ───────────────────────────────────────────────────────────── +# 3. One-Euro 自适应平滑(关键点跟手性) +# freq_min 越大越跟手(越抖);beta 越大快速运动响应越快 +# ───────────────────────────────────────────────────────────── + +class _OneEuroFilter: + """单值 One-Euro 自适应低通滤波器。""" + + def __init__(self, freq_min=5.0, beta=0.05, dcutoff=1.0): + self.freq_min = freq_min + self.beta = beta + self.dcutoff = dcutoff + self._prev_x = None + self._prev_dx = 0.0 + self._prev_ts = None + + @staticmethod + def _alpha(cutoff, dt): + tau = 1.0 / (2.0 * math.pi * cutoff) if cutoff > 1e-9 else 0.0 + return dt / (dt + tau) if tau > 0 else 1.0 + + def __call__(self, x, ts_ms): + if self._prev_x is None or self._prev_ts is None: + self._prev_x, self._prev_dx, self._prev_ts = x, 0.0, ts_ms + return x + dt = (ts_ms - self._prev_ts) / 1000.0 + if dt <= 1e-9: + return self._prev_x + dx = (x - self._prev_x) / dt + alpha_d = self._alpha(self.dcutoff, dt) + dx_hat = alpha_d * dx + (1.0 - alpha_d) * self._prev_dx + fc = self.freq_min + self.beta * abs(dx_hat) + alpha = self._alpha(fc, dt) + x_hat = alpha * x + (1.0 - alpha) * self._prev_x + self._prev_x, self._prev_dx, self._prev_ts = x_hat, dx_hat, ts_ms + return x_hat + + +class _OneEuroFilter2D: + """对 (x, y) 分量独立滤波。""" + + def __init__(self, freq_min=5.0, beta=0.05, dcutoff=1.0): + self._fx = _OneEuroFilter(freq_min, beta, dcutoff) + self._fy = _OneEuroFilter(freq_min, beta, dcutoff) + + def __call__(self, x, y, ts_ms): + return self._fx(x, ts_ms), self._fy(y, ts_ms) + + +# ───────────────────────────────────────────────────────────── +# 4. MediaPipe 手部检测(Tasks API,VIDEO 模式) +# ───────────────────────────────────────────────────────────── + +class HandDetector: + """每帧返回手部关键点列表:[[(x,y),...21点], ...]。""" + + def __init__(self, model_path=MODEL_PATH, num_hands=2, mirror=False, + smooth=True, freq_min=15.0, beta=0.6, dcutoff=1.0): + import mediapipe as mp + from mediapipe.tasks import python as mp_python + from mediapipe.tasks.python import vision + + if not os.path.isfile(model_path): + raise FileNotFoundError( + f"模型不存在: {model_path}\n" + "请下载 hand_landmarker.task 并与本脚本放同一目录:\n" + "https://storage.googleapis.com/mediapipe-models/hand_landmarker/" + "hand_landmarker/float16/1/hand_landmarker.task") + + self.mirror = mirror + self.smooth = smooth + self._mp = mp + self._freq_min, self._beta, self._dcutoff = freq_min, beta, dcutoff + self._filters: dict = {} + self._t0 = time.perf_counter() + + options = vision.HandLandmarkerOptions( + base_options=mp_python.BaseOptions(model_asset_path=model_path), + running_mode=vision.RunningMode.VIDEO, + num_hands=num_hands, + min_hand_detection_confidence=0.5, + min_hand_presence_confidence=0.5, + min_tracking_confidence=0.5, + ) + self._landmarker = vision.HandLandmarker.create_from_options(options) + + def process(self, frame_bgr): + """BGR 帧 → [[(x, y), ×21], ...] 像素关键点列表(每只手一个)。""" + h, w = frame_bgr.shape[:2] + frame = cv2.flip(frame_bgr, 1) if self.mirror else frame_bgr + mp_image = self._mp.Image(image_format=self._mp.ImageFormat.SRGB, + data=cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)) + ts_ms = int((time.perf_counter() - self._t0) * 1000) + result = self._landmarker.detect_for_video(mp_image, ts_ms) + + hands = [] + for lms in result.hand_landmarks: + if self.smooth: + pts = [] + for j, lm in enumerate(lms): + key = (len(hands), j) + if key not in self._filters: + self._filters[key] = _OneEuroFilter2D( + self._freq_min, self._beta, self._dcutoff) + fx, fy = self._filters[key](lm.x, lm.y, ts_ms) + pts.append((int(fx * w), int(fy * h))) + hands.append(pts) + else: + hands.append([(int(lm.x * w), int(lm.y * h)) for lm in lms]) + return hands + + def close(self): + try: + self._landmarker.close() + except Exception: + pass + + +# ───────────────────────────────────────────────────────────── +# 5. 叠加绘制(demo 风格:五指分色 + 边框标签 + 手势文本) +# ───────────────────────────────────────────────────────────── + +def _draw_hand(frame, pts): + """按五指分色画骨架:掌心灰连接、腕白圆、指尖 7px/关节 5px + 深色描边。""" + p = [(int(x), int(y)) for x, y in pts[:21]] + for a, b in PALM_CONNECTIONS: + cv2.line(frame, p[a], p[b], (200, 200, 200), 2, cv2.LINE_AA) + for finger, (ids, color) in FINGERS.items(): + chain = ids if finger == "Thumb" else [0] + ids + for i in range(len(chain) - 1): + cv2.line(frame, p[chain[i]], p[chain[i + 1]], color, 3, cv2.LINE_AA) + for idx in ids: + r = 7 if idx == ids[-1] else 5 + cv2.circle(frame, p[idx], r, color, -1, cv2.LINE_AA) + cv2.circle(frame, p[idx], r, (30, 30, 30), 1, cv2.LINE_AA) + cv2.circle(frame, p[0], 9, (255, 255, 255), -1, cv2.LINE_AA) + cv2.circle(frame, p[0], 9, (40, 40, 40), 2, cv2.LINE_AA) + + +def _draw_kpts_overlay(frame, hands, cam_label="", frame_idx=0, total=0): + """边框 + 底衬标签 + 分色骨架 + 手势文本;hands: [[(x,y)...21], ...]。""" + for i, pts in enumerate(hands[:2]): + pts = np.asarray(pts, np.float32).reshape(21, 2) + xs, ys = pts[:, 0], pts[:, 1] + pad = 12 + x1, y1 = int(xs.min()) - pad, int(ys.min()) - pad + x2, y2 = int(xs.max()) + pad, int(ys.max()) + pad + cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 220, 220), 2, cv2.LINE_AA) + label = f"Hand #{i}" + (tw, th), _ = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 2) + cv2.rectangle(frame, (x1, y1 - th - 6), (x1 + tw + 6, y1), (0, 200, 200), -1) + cv2.putText(frame, label, (x1 + 3, y1 - 3), cv2.FONT_HERSHEY_SIMPLEX, + 0.5, (0, 0, 0), 2, cv2.LINE_AA) + _draw_hand(frame, pts) + try: + angles = _compute_joint_angles(pts) + extended = _count_extended_fingers(angles) + text = "open: " + ",".join(extended) if extended else "fist" + cv2.putText(frame, text, (x1, y2 + 18), cv2.FONT_HERSHEY_SIMPLEX, + 0.4, (0, 255, 120), 1, cv2.LINE_AA) + except Exception: + pass + + info = cam_label + if total: + info += f" frame {frame_idx}/{total} hands={len(hands)}" + cv2.putText(frame, info, (10, 26), cv2.FONT_HERSHEY_SIMPLEX, 0.7, + (255, 255, 255), 2) + cv2.putText(frame, "COLORED: 2D MediaPipe hand keypoints", + (10, frame.shape[0] - 14), cv2.FONT_HERSHEY_SIMPLEX, 0.6, + (255, 255, 255), 1, cv2.LINE_AA) + return frame + + +# ───────────────────────────────────────────────────────────── +# 6. 视频输出(H.264 转码,无 ffmpeg 时保留 mp4v 兜底) +# ───────────────────────────────────────────────────────────── + +def _create_writer(out_path, fps, width, height): + tmp = os.path.splitext(out_path)[0] + "_tmp.avi" + writer = cv2.VideoWriter(tmp, cv2.VideoWriter_fourcc(*"mp4v"), + fps, (int(width), int(height))) + if not writer.isOpened(): + raise RuntimeError(f"无法创建视频写器: {tmp}") + return writer, tmp + + +def _find_working_ffmpeg(): + """探测可用的 ffmpeg(存在的候选可能不可运行,如损坏的 conda 版本)。""" + candidates = [shutil.which("ffmpeg"), "/usr/bin/ffmpeg", + "/usr/local/bin/ffmpeg", + os.path.expanduser("~/miniconda3/envs/lerobot/bin/ffmpeg"), + os.path.expanduser("~/anaconda3/envs/lerobot/bin/ffmpeg")] + for ff in dict.fromkeys(c for c in candidates if c): + try: + r = subprocess.run([ff, "-version"], capture_output=True, timeout=10) + if r.returncode == 0: + return ff + except (OSError, subprocess.TimeoutExpired): + continue + return None + + +def _finalize(writer, tmp_path, out_path): + writer.release() + ffmpeg = _find_working_ffmpeg() + if ffmpeg: + try: + subprocess.run([ffmpeg, "-y", "-loglevel", "error", "-i", tmp_path, + "-c:v", "libx264", "-crf", "23", "-pix_fmt", "yuv420p", + out_path], check=True, capture_output=True) + os.remove(tmp_path) + return out_path + except (OSError, subprocess.CalledProcessError): + pass # 转换失败则退回 mp4v 原样交付 + os.replace(tmp_path, out_path) # 无 ffmpeg: mp4v 直接改名交付 + return out_path + + +# ───────────────────────────────────────────────────────────── +# 7. 主流程 +# ───────────────────────────────────────────────────────────── + +def process_video(streams, output, detector, cam_labels): + """streams: [cv2.VideoCapture, ...];输出并排叠加视频。""" + n_total = min(int(c.get(cv2.CAP_PROP_FRAME_COUNT)) for c in streams) + fps = streams[0].get(cv2.CAP_PROP_FPS) or 25.0 + w, h = int(streams[0].get(cv2.CAP_PROP_FRAME_WIDTH)), int(streams[0].get(cv2.CAP_PROP_FRAME_HEIGHT)) + out_w = w * len(streams) + writer, tmp = _create_writer(output, fps, out_w, h) + + t0 = time.time() + for i in range(n_total): + frames, hands = [], [] + ok_all = True + for c in streams: + ok, fr = c.read() + if not ok: + ok_all = False + break + frames.append(fr) + hands.append(detector.process(fr)) + if not ok_all: + break + canvases = [] + for fr, hs, lab in zip(frames, hands, cam_labels): + canvases.append(_draw_kpts_overlay(fr, hs, lab, i, n_total)) + writer.write(cv2.hconcat(canvases) if len(canvases) > 1 else canvases[0]) + if (i + 1) % 25 == 0 or i + 1 == n_total: + el = time.time() - t0 + print(f" {i + 1}/{n_total} 帧 ({(i + 1) / el:.1f} fps 检测+渲染)") + + for c in streams: + c.release() + return _finalize(writer, tmp, output) + + +def main(): + ap = argparse.ArgumentParser( + description="双目/单目视频 2D 手部关键点检测 + 渲染 demo(自包含单文件)") + ap.add_argument("videos", nargs="+", help="视频路径(1 个=单目, 2 个=左右目并排)") + ap.add_argument("-o", "--output", default="stereo_2d_output.mp4", + help="输出视频路径(默认 stereo_2d_output.mp4)") + ap.add_argument("--model", default=MODEL_PATH, help="hand_landmarker.task 路径") + ap.add_argument("--freq-min", type=float, default=15.0, + help="One-Euro 位置滤波截止频率 Hz(默认 15;越大越跟手越抖)") + ap.add_argument("--beta", type=float, default=0.6, + help="One-Euro 速度自适应系数(默认 0.6;快速运动滞后就调大)") + ap.add_argument("--no-smooth", action="store_true", + help="关闭 One-Euro 平滑(最跟手,原始抖动)") + args = ap.parse_args() + + if len(args.videos) > 2: + ap.error("最多支持 2 个视频(单目或左右目)") + + streams = [] + try: + for v in args.videos: + if not os.path.isfile(v): + raise FileNotFoundError(f"视频不存在: {v}") + c = cv2.VideoCapture(v) + if not c.isOpened(): + raise RuntimeError(f"无法打开视频: {v}") + streams.append(c) + except Exception as e: + print(f"[ERROR] {e}") + sys.exit(1) + + print(f"加载视频: {args.videos} ({int(streams[0].get(cv2.CAP_PROP_FRAME_COUNT))} 帧, " + f"{streams[0].get(cv2.CAP_PROP_FPS):.1f}fps)") + print(f"模型: {args.model}") + if args.no_smooth: + print("平滑: 关闭") + else: + print(f"平滑: One-Euro freq_min={args.freq_min} beta={args.beta}") + + detector = HandDetector(model_path=args.model, num_hands=2, + smooth=not args.no_smooth, + freq_min=args.freq_min, beta=args.beta) + labels = ["Left", "Right"] if len(args.videos) == 2 else ["Camera"] + + try: + out = process_video(streams, args.output, detector, labels) + print(f"✓ 完成: {out}") + except Exception as e: + print(f"[ERROR] {e}") + sys.exit(1) + finally: + detector.close() + + +if __name__ == "__main__": + main() diff --git a/collector/tools/demos/stereo_depth_640x400.yaml b/collector/tools/demos/stereo_depth_640x400.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e54af6718ec52aeb720e78fb6e29dc96dac15cb9 --- /dev/null +++ b/collector/tools/demos/stereo_depth_640x400.yaml @@ -0,0 +1,28 @@ +# S80M 640x400 stereo depth config (generated by test_stereo_depth_calib.py) +enable_module: 1 +model_path: models/rk3588/stereo_s_general.rknn +calib_path: +input_stereo_width: 640 +input_stereo_height: 400 +stereo_img_scaling: 1 +input_aux_cam_width: 1920 +input_aux_cam_height: 1080 +aux_cam_scaling: 1.0 +thread_num: 1 +async_mode: 0 +restore_depth_dim: 1 +debug_image: 0 +debug_img_save_path: /tmp +depth_mode: 1 +align_cam_id: -1 +align_direction: true +enable_filter: false +wls_filter: true +farthest_dist: 10.0 +cloest_dist: 0.3 +enable_voxel: false +voxelSize: 0.05 +minPoints: 3 +pointcloud_type: 0 +pointcloud_ROI: 0.8 +skip_point: 2 diff --git a/collector/tools/demos/stereo_depth_demo/CMakeLists.txt b/collector/tools/demos/stereo_depth_demo/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..359cdeca15705c0e6bb6d28096eceef6f86eee50 --- /dev/null +++ b/collector/tools/demos/stereo_depth_demo/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.12) +project(stereo_depth_demo) + +# 导出 compile_commands.json (供 VSCode IntelliSense 解析 include 路径, +# 否则头文件在编辑器里报"无法打开", 编译器本身不受影响) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# SDK 路径 (与官方 GUI CMakeLists 相同的 SDK_INCLUDE_DIR/SDK_LIB_DIR 机制) +if(NOT DEFINED SDK_DIR) + set(SDK_DIR "/home/REDACTED/FaysSense_VI_Kit_Release") +endif() +set(SDK_INCLUDE_DIR "${SDK_DIR}/include" CACHE PATH "FaysSense SDK headers") +set(SDK_LIB_DIR "${SDK_DIR}/lib/fays_atrak/${CMAKE_SYSTEM_PROCESSOR}/Release" CACHE PATH "FaysSense SDK libs") +message(STATUS "SDK_INCLUDE_DIR: ${SDK_INCLUDE_DIR}") +message(STATUS "SDK_LIB_DIR: ${SDK_LIB_DIR}") + +# OpenCV: 必须使用 SDK 自带 4.2 (深度引擎按其编译, 系统 4.6/4.13 会崩). +# 在 build.sh 中以 -DOpenCV_DIR 指向 SDK 自带 4.2 的 cmake 配置. +find_package(OpenCV REQUIRED) +message(STATUS "OpenCV ${OpenCV_VERSION}: ${OpenCV_DIR}") + +find_package(Threads REQUIRED) + +include_directories(${SDK_INCLUDE_DIR}) +link_directories(${SDK_LIB_DIR}) + +add_executable(stereo_depth_demo main.cpp) + +# 链接顺序至关重要 (GNU ld 按从左到右解析未定义符号): +# 1. SDK 库在前 (libfayssense_aikit_depth.so 的 cv::ximgproc 等未定义符号) +# 2. 之后是 SDK 自带 OpenCV 4.2 模块 (仅链接深度引擎实际用到的模块) +# 3. 最后是 lib406 外部依赖 shim (4.2 的 TIFF/WebP/TBB/av* 等符号) +set(SDK_CV406_DEPS "${SDK_DIR}/thirdparty/opencv-4.2.0-linux-x86_64/lib406") +target_link_libraries(stereo_depth_demo + fayssense_aikit_depth + fays_vikit + opencv_core + opencv_imgproc + opencv_imgcodecs + opencv_highgui + opencv_calib3d + opencv_ximgproc + opencv_features2d + opencv_flann + opencv_video + opencv_videoio + opencv_photo + opencv_objdetect + opencv_ml + ${SDK_CV406_DEPS}/libtbb.so.2 + ${SDK_CV406_DEPS}/libtiff.so.5 + ${SDK_CV406_DEPS}/libwebp.so.6 + ${SDK_CV406_DEPS}/libdc1394.so.22 + ${SDK_CV406_DEPS}/libavcodec.so.58 + ${SDK_CV406_DEPS}/libavformat.so.58 + ${SDK_CV406_DEPS}/libavutil.so.56 + ${SDK_CV406_DEPS}/libswscale.so.5 + Threads::Threads +) diff --git a/collector/tools/demos/stereo_depth_demo/build.sh b/collector/tools/demos/stereo_depth_demo/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..8be9dcc57b853e5a17a45efa5907bd61de589f4b --- /dev/null +++ b/collector/tools/demos/stereo_depth_demo/build.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# 构建 S80M 双目深度 Demo (严格按 SDK 实现) +# +# 与官方 stereo_depth_gui/build.sh 相同的构建方式, 额外: +# -DOpenCV_DIR 指向 SDK 自带 OpenCV 4.2.0 (深度引擎按其编译, 必须对接 4.2) +# +# 用法: +# ./build.sh # 自动检测 SDK (需设置 SDK_DIR 或 FAYSSENSE_SDK_DIR) +# SDK_DIR=/path/to/sdk ./build.sh + +set -e +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BUILD_DIR="${SCRIPT_DIR}/build" + +if [ -z "$SDK_DIR" ]; then + SDK_DIR="${FAYSSENSE_SDK_DIR:-}" +fi +if [ -z "$SDK_DIR" ]; then + echo "ERROR: 请设置 SDK_DIR 或 FAYSSENSE_SDK_DIR=" >&2 + exit 1 +fi +OPENCV42_DIR="$SDK_DIR/thirdparty/opencv-4.2.0-linux-x86_64" + +if [ ! -d "$SDK_DIR/include/fays_atrak" ]; then + echo "ERROR: SDK not found at $SDK_DIR (set SDK_DIR)" >&2 + exit 1 +fi +if [ ! -f "$OPENCV42_DIR/lib/cmake/opencv4/OpenCVConfig.cmake" ]; then + echo "ERROR: SDK bundled OpenCV 4.2 not found at $OPENCV42_DIR" >&2 + exit 1 +fi + +echo "SDK_DIR: $SDK_DIR" +echo "OpenCV : $OPENCV42_DIR (SDK bundled 4.2)" + +mkdir -p "$BUILD_DIR" +cd "$BUILD_DIR" + +cmake "$SCRIPT_DIR" \ + -DCMAKE_BUILD_TYPE=Release \ + -DSDK_DIR="$SDK_DIR" \ + -DOpenCV_DIR="$OPENCV42_DIR/lib/cmake/opencv4" \ + "$@" + +make -j"$(nproc)" + +echo "" +echo "===== 构建完成 =====" +echo "二进制: $BUILD_DIR/stereo_depth_demo" +echo "" +echo "运行 (自动设置 LD_LIBRARY_PATH 为 SDK 自带 OpenCV 4.2):" +echo " ./run.sh" diff --git a/collector/tools/demos/stereo_depth_demo/main.cpp b/collector/tools/demos/stereo_depth_demo/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5cda4378bfb6ceaf2823aa8f04f16e66591a223f --- /dev/null +++ b/collector/tools/demos/stereo_depth_demo/main.cpp @@ -0,0 +1,737 @@ +// +// S80M 双目深度 Demo —— 严格按 FaysSense VI Kit SDK 官方实现 +// +// 图像读取参考: SDK example/fays_vikit_example.cpp +// FAYS_VIK_CreateHandleWithConfig -> FAYS_VIK_GetStereoFrames (轮询, 预分配缓冲) +// 深度引擎参考: SDK stereo_depth_gui/core/depth_engine.cpp +// FAYS_ATRAK_D_CreateHandleWithConfig -> FAYS_ATRAK_D_BindViKit +// -> FAYS_ATRAK_D_FeedStereoImage -> FAYS_ATRAK_D_GetDepthImage +// -> FAYS_ATRAK_D_GetRectifiedImage -> FAYS_ATRAK_D_GetRectifyInfo +// -> FAYS_ATRAK_D_GetPointcloud +// +// 通道顺序注意 (fays_atrak_types.h): +// - AtrakImage 3 通道为 BGR-packed +// - 点云 AtrakMap::rgb 为 ARGB8 (0x00RRGGBB: R 在高字节, alpha 固定 0) +// +// 构建: ./build.sh 运行: ./run.sh [viKitConfig] [depthConfig] +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "fays_atrak/fays_atrak_types.h" +#include "fays_atrak/fays_vikit.h" +#include "fays_atrak/fays_atrak_depth.h" + +namespace { + +// 点云颜色 ARGB8 (0x00RRGGBB) -> BGR (cv 通道序) +cv::Vec3b argb8ToBgr(uint32_t c) +{ + return cv::Vec3b(static_cast(c & 0xFF), // B + static_cast((c >> 8) & 0xFF), // G + static_cast((c >> 16) & 0xFF)); // R +} + +void savePly(const std::string& path, const AtrakMap& cloud) +{ + std::ofstream f(path); + if (!f) { std::cerr << "[PLY] 无法写入 " << path << std::endl; return; } + const uint32_t n = cloud.point_num; + f << "ply\nformat ascii 1.0\n" + << "element vertex " << n << "\n" + << "property float x\nproperty float y\nproperty float z\n" + << "property uchar red\nproperty uchar green\nproperty uchar blue\n" + << "end_header\n"; + for (uint32_t i = 0; i < n; ++i) { + const float* p = cloud.pos + 3 * i; + const cv::Vec3b bgr = argb8ToBgr(cloud.rgb[i]); + f << p[0] << ' ' << p[1] << ' ' << p[2] << ' ' + << static_cast(bgr[2]) << ' ' // R + << static_cast(bgr[1]) << ' ' // G + << static_cast(bgr[0]) << '\n'; // B + } + std::cout << "[PLY] 已保存 " << path << " (" << n << " 点)" << std::endl; +} + +// ═══════════════════════════════════════════════════════════════ +// 官方 GUI 同款深度着色 (stereo_depth_gui/core/colormap.cpp) +// 深度数据原样, 仅做直方图均衡映射 + JET: 按像素数量分配色阶, +// 近距离层次分明; 无效(<=0)与超出范围(>max)置黑 +// ═══════════════════════════════════════════════════════════════ +static void officialHistogramEqualize(const cv::Mat& depthMeters, cv::Mat& equalized, + const float presetMin, const float presetMax) +{ + const int rows = depthMeters.rows; + const int cols = depthMeters.cols; + + std::vector valid; + valid.reserve(rows * cols); + for (int r = 0; r < rows; ++r) { + const float* row = depthMeters.ptr(r); + for (int c = 0; c < cols; ++c) { + float d = row[c]; + if (d > 0.0f && d >= presetMin && d <= presetMax) + valid.push_back(d); + } + } + + if (valid.size() < 100) { // 有效像素太少 → 线性归一化兜底 + equalized.create(rows, cols, CV_8UC1); + float range = presetMax - presetMin; + float inv = (range > 0) ? (255.0f / range) : 0.0f; + for (int r = 0; r < rows; ++r) { + const float* src = depthMeters.ptr(r); + uchar* dst = equalized.ptr(r); + for (int c = 0; c < cols; ++c) { + float d = src[c]; + if (d <= 0.0f) { dst[c] = 0; continue; } + dst[c] = static_cast( + std::max(0.0f, std::min(255.0f, (d - presetMin) * inv))); + } + } + return; + } + + std::sort(valid.begin(), valid.end()); + int n = static_cast(valid.size()); + + // CDF → LUT (官方同款: 4096 bin, 有效深度 1-255, 0 留黑) + const int kLutSize = 4096; + std::vector lut(kLutSize, 0); + float binWidth = presetMax / kLutSize; + int cumCount = 0; + size_t validIdx = 0; + for (int bin = 0; bin < kLutSize; ++bin) { + float binMax = (bin + 1) * binWidth; + while (validIdx < valid.size() && valid[validIdx] <= binMax) { + cumCount++; + validIdx++; + } + lut[bin] = static_cast(1 + (cumCount * 254) / n); + } + + equalized.create(rows, cols, CV_8UC1); + float invBin = 1.0f / binWidth; + for (int r = 0; r < rows; ++r) { + const float* src = depthMeters.ptr(r); + uchar* dst = equalized.ptr(r); + for (int c = 0; c < cols; ++c) { + float d = src[c]; + if (d <= 0.0f || d > presetMax) { dst[c] = 0; continue; } + int bin = static_cast(d * invBin); + if (bin < 0) bin = 0; + if (bin >= kLutSize) bin = kLutSize - 1; + dst[c] = lut[bin]; + } + } +} + +// 官方范围预设 (control_panel.cpp 同款, 按 M 循环) +struct RangePreset { float minD, maxD; }; +static const RangePreset kRangePresets[] = { + {0.1f, 1.0f}, {0.1f, 2.0f}, {0.1f, 4.0f}, {0.1f, 8.0f}, + {0.3f, 1.0f}, {0.3f, 2.0f}, {0.3f, 4.0f}, {0.3f, 8.0f}, +}; + +} // namespace + +// ═══════════════════════════════════════════════════════════════ +// Demo: 严格按 SDK 官方调用序列 +// ═══════════════════════════════════════════════════════════════ +class StereoDepthDemo { +public: + StereoDepthDemo(const std::string& viKitConfig, const std::string& depthConfig); + ~StereoDepthDemo(); + + bool ok() const { return viHandle_ != nullptr && depthHandle_ != nullptr; } + void run(); + +private: + void* viHandle_ = nullptr; // ViKit 传感器句柄 + void* depthHandle_ = nullptr; // 深度引擎句柄 + std::atomic feedBgr_{true}; // 送引擎通道序: true=BGR (SDK 文档约定), 按 C 切换 + + // ── 线程分离 (官方 GUI 同构): 采集/引擎线程 → 显示线程 ── + // 采集线程: GetStereoFrames → FeedStereoImage → GetDepthImage → 入队 + // 显示线程: 取最新帧 → 后处理 → imshow → waitKey + // 单线程串行时任何一帧处理慢都会拖住采集 (局部卡顿根因). + std::mutex qmtx_; + std::condition_variable qcv_; + std::deque depthQ_; // 640x400 float32 深度 (后处理前) + std::deque rectQ_; // 640x800 矫正显示图 + std::deque stereoQ_; // 640x800 双目显示图 + std::atomic running_{true}; + std::atomic saveReq_{false}; // 主线程按 s → 采集线程存 .bin/_rect.png + std::atomic plyReq_{false}; // 主线程按 p → 采集线程存点云 + std::atomic lastTs_{0}; // 采集线程最近帧时间戳 (命名用) + std::atomic lumMean_{0.0}; // 采集线程算的亮度 (统计输出用) + std::atomic lumOver_{0.0}; + + // 显示模式 (仅主显示线程使用): + // officialMode_=true : 官方 GUI 同款 —— 深度数据原样 + 直方图均衡 + JET + // officialMode_=false: 增强模式 —— 后处理链 + 分位数映射 (历史迭代产物) + bool officialMode_ = true; + int presetIdx_ = 6; // 官方范围预设: 默认 "0.3 – 4.0 m" (官方 kDefaultPreset=6) + + // ── 输出缓冲: 按 SDK 头文件宏预先分配, 调用方管理内存 ── + std::vector stereoBuf_; // FAYS_ATRAK_MONO_MAX_BYTES*3 (官方示例同款) + std::vector rectBuf_; // FAYS_ATRAK_IMG_MAX_BYTES + std::vector pairedBuf_; // FAYS_ATRAK_RGB_MAX_BYTES + std::vector depthBuf_; // FAYS_ATRAK_DEPTH_IMG_MAX_BYTES/sizeof(float) + std::vector dispBuf_; + std::vector cloudPos_; // FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM * 3 + std::vector cloudRgb_; // FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM + + AtrakImage stereoImg_{}; // GetStereoFrames 输出 + AtrakImage rectImg_{}; // GetRectifiedImage 输出 + AtrakImage pairedImg_{}; // GetDepthImage 对齐图像输出 + AtrakDepthImage depthImg_{}; // GetDepthImage 深度输出 (float 米) + AtrakDepthImage dispImg_{}; // GetDepthImage 视差输出 + AtrakMap cloud_{}; // GetPointcloud 输出 +}; + +// 深度显示映射范围 (EMA 平滑, 跨帧持久; 显示线程写, 采集线程统计时读) +static std::atomic gMapLo{0.3f}, gMapHi{1.5f}; + +StereoDepthDemo::StereoDepthDemo(const std::string& viKitConfig, + const std::string& depthConfig) +{ + // 1. 打开相机 (官方示例: FAYS_VIK_CreateHandleWithConfig) + if (FAYS_VIK_CreateHandleWithConfig(&viHandle_, viKitConfig.c_str()) != 0) { + std::cerr << "[ERROR] FAYS_VIK_CreateHandleWithConfig 失败: " + << viKitConfig << std::endl; + return; + } + std::cout << "Fays VIKit Version: " << FAYS_VIK_GetVersion(viHandle_) << std::endl; + + // 2. 创建深度引擎 (官方 GUI: FAYS_ATRAK_D_CreateHandleWithConfig) + if (FAYS_ATRAK_D_CreateHandleWithConfig(&depthHandle_, depthConfig.c_str()) != 0) { + std::cerr << "[ERROR] FAYS_ATRAK_D_CreateHandleWithConfig 失败: " + << depthConfig << std::endl; + return; + } + + // 3. 绑定传感器 (官方 GUI: FAYS_ATRAK_D_BindViKit) + if (FAYS_ATRAK_D_BindViKit(depthHandle_, viHandle_) != 0) { + std::cerr << "[ERROR] FAYS_ATRAK_D_BindViKit 失败" << std::endl; + return; + } + std::cout << "[DepthEngine] 初始化成功, 已绑定 ViKit." << std::endl; + + // 4. 预先分配输出缓冲 + stereoBuf_.resize(FAYS_ATRAK_MONO_MAX_BYTES * 3); + rectBuf_.resize(FAYS_ATRAK_IMG_MAX_BYTES); + pairedBuf_.resize(FAYS_ATRAK_RGB_MAX_BYTES); + const size_t depthFloats = FAYS_ATRAK_DEPTH_IMG_MAX_BYTES / sizeof(float); + depthBuf_.resize(depthFloats); + dispBuf_.resize(depthFloats); + cloudPos_.resize(FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM * 3); + cloudRgb_.resize(FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM); + + stereoImg_.data = stereoBuf_.data(); + rectImg_.data = rectBuf_.data(); + pairedImg_.data = pairedBuf_.data(); + depthImg_.data = depthBuf_.data(); + dispImg_.data = dispBuf_.data(); + cloud_.pos = cloudPos_.data(); + cloud_.rgb = cloudRgb_.data(); +} + +StereoDepthDemo::~StereoDepthDemo() +{ + if (depthHandle_) { + FAYS_ATRAK_D_DestroyHandle(depthHandle_); + depthHandle_ = nullptr; + } + if (viHandle_) { + FAYS_VIK_DestroyHandle(viHandle_); + viHandle_ = nullptr; + } +} + +void StereoDepthDemo::run() +{ + cv::namedWindow("Stereo Input (L/R)", cv::WINDOW_NORMAL); + cv::namedWindow("Rectified (engine)", cv::WINDOW_NORMAL); + cv::namedWindow("Depth", cv::WINDOW_NORMAL); + cv::resizeWindow("Stereo Input (L/R)", 640, 800); + cv::resizeWindow("Rectified (engine)", 640, 800); + cv::resizeWindow("Depth", 640, 400); + + // ── 采集/引擎线程 (官方 GUI 同构) ── + // 单线程串行时任何一帧处理慢都会拖住采集 (局部卡顿根因); + // 分离后采集线程恒定拉帧, 显示线程消费最新帧, 慢帧只丢不拖. + bool rectifyInfoShown = false; + std::thread capThread([this, &rectifyInfoShown]() { + int frames = 0; + auto lastStats = std::chrono::steady_clock::now(); + while (running_.load()) { + // 图像读取 (stereo_swap_lr=1 时输出 上=左目/下=右目) + if (FAYS_VIK_GetStereoFrames(viHandle_, &stereoImg_) != 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + continue; + } + lastTs_.store(stereoImg_.timestamp); + cv::Mat stereo(stereoImg_.height, stereoImg_.width, + stereoImg_.channel == 1 ? CV_8UC1 : CV_8UC3, + stereoImg_.data); + cv::Mat stereoBgr; + if (stereo.channels() == 3) + cv::cvtColor(stereo, stereoBgr, cv::COLOR_RGB2BGR); + else + stereoBgr = stereo; + + // 显示用缩略图 + 亮度统计 (显示线程直接取) + cv::Mat stereoView; + cv::resize(stereoBgr, stereoView, cv::Size(640, 800)); + cv::Mat graySmall; + cv::cvtColor(stereoView, graySmall, cv::COLOR_BGR2GRAY); + lumMean_.store(cv::mean(graySmall)[0]); + lumOver_.store(100.0 * cv::countNonZero(graySmall > 245) / graySmall.total()); + { + std::lock_guard lk(qmtx_); + stereoQ_.push_back(stereoView); + if (stereoQ_.size() > 2) stereoQ_.pop_front(); + } + + // 送引擎 (feedBgr_: BGR=SDK 文档约定 / RGB=固件原始, 按 C 切换) + const cv::Mat& feedMat = feedBgr_.load() ? stereoBgr : stereo; + AtrakImage feed{}; + feed.device_id = 0; // ATRAK_DEV_STEREO + feed.timestamp = stereoImg_.timestamp; + feed.width = feedMat.cols; + feed.height = feedMat.rows; + feed.channel = feedMat.channels(); + feed.step = static_cast(feedMat.step); + feed.bytes = static_cast(feedMat.total() * feedMat.elemSize()); + feed.data = feedMat.data; + feed.encoding = (feedMat.channels() == 1) ? 2 /*AIE_RAW8*/ : 0 /*AIE_BGR8*/; + FAYS_ATRAK_D_FeedStereoImage(depthHandle_, &feed); + + // 取深度 (async_mode=1: 未就绪时下一轮重试) + depthImg_.width = depthImg_.height = depthImg_.channel = 0; + depthImg_.step = depthImg_.bytes = 0; + dispImg_.width = dispImg_.height = dispImg_.channel = 0; + dispImg_.step = dispImg_.bytes = 0; + pairedImg_.width = pairedImg_.height = pairedImg_.channel = 0; + pairedImg_.step = pairedImg_.bytes = 0; + if (FAYS_ATRAK_D_GetDepthImage(depthHandle_, &depthImg_, &dispImg_, &pairedImg_) != 0 || + depthImg_.width == 0 || depthImg_.height == 0) { + continue; + } + cv::Mat depthM(depthImg_.height, depthImg_.width, CV_32FC1, depthImg_.data); + + // 矫正图 (显示用) + rectImg_.width = rectImg_.height = rectImg_.channel = 0; + rectImg_.step = rectImg_.bytes = 0; + bool hasRect = (FAYS_ATRAK_D_GetRectifiedImage(depthHandle_, &rectImg_) == 0 && + rectImg_.width > 0 && rectImg_.height > 0); + if (hasRect) { + cv::Mat rectM(rectImg_.height, rectImg_.width, + rectImg_.channel == 1 ? CV_8UC1 : CV_8UC3, rectImg_.data); + cv::Mat rectView; + cv::resize(rectM, rectView, cv::Size(640, 800)); + std::lock_guard lk(qmtx_); + rectQ_.push_back(rectView); + if (rectQ_.size() > 2) rectQ_.pop_front(); + } + if (!rectifyInfoShown && hasRect) { + AtrakRectifyInfo info; + std::memset(&info, 0, sizeof(info)); + if (FAYS_ATRAK_D_GetRectifyInfo(depthHandle_, &info) == 0) { + double fx = info.P0[0]; + double baseline = std::fabs(info.P1[3]) / fx; // P1[3] = -fx*T_x + std::cout << "[RectifyInfo] fx' = " << fx + << " baseline = " << baseline * 1000.0 << " mm" << std::endl; + } + rectifyInfoShown = true; + } + + // 深度入队 (640x400, 后处理前) + cv::Mat small; + cv::resize(depthM, small, cv::Size(640, 400)); + { + std::lock_guard lk(qmtx_); + if (depthQ_.size() >= 3) depthQ_.pop_front(); // 显示跟不上的帧直接丢 + depthQ_.push_back(small); + qcv_.notify_one(); + } + + // ── 每秒统计 (原始深度, 全尺寸) ── + ++frames; + auto now = std::chrono::steady_clock::now(); + if (now - lastStats >= std::chrono::seconds(1)) { + double elapsed = std::chrono::duration(now - lastStats).count(); + double fps = frames / elapsed; + const float* dp = depthImg_.data; + const size_t npx = depthImg_.width * depthImg_.height; + size_t valid = 0; + float mn = 1e9f, mx = 0.0f; + std::vector vals; + vals.reserve(npx / 2); + for (size_t i = 0; i < npx; ++i) { + float v = dp[i]; + if (v > 0.1f && v < 10.0f) { + ++valid; vals.push_back(v); + if (v < mn) mn = v; + if (v > mx) mx = v; + } + } + std::sort(vals.begin(), vals.end()); + float median = vals.empty() ? 0.0f : vals[vals.size() / 2]; + std::cout << "[Stats] " << fps << " FPS | 有效深度 " + << 100.0 * valid / npx << "% | median " + << median << " m | [" << mn << ", " << mx << "] m | 亮度 " + << lumMean_.load() << " (过曝 " << lumOver_.load() + << "%) | 映射 [" << gMapLo.load() << ", " + << gMapHi.load() << "] m" << std::endl; + // ── 深度分布诊断: 看深度值是否真的铺开 ── + { + int hb[9] = {0}; // 0.2-0.4, 0.4-0.6, ..., 1.8-2.0 + int hNear = 0, hFar = 0; + for (size_t i = 0; i < npx; ++i) { + float v = dp[i]; + if (v <= 0.1f || v >= 10.0f) continue; + if (v < 0.2f) hNear++; + else if (v >= 2.0f) hFar++; + else hb[static_cast((v - 0.2f) / 0.2f)]++; + } + std::cout << "[DepthHist] <0.2m:" << 100.0 * hNear / valid + << "% 0.2-0.4:" << 100.0 * hb[0] / valid + << "% 0.4-0.6:" << 100.0 * hb[1] / valid + << "% 0.6-0.8:" << 100.0 * hb[2] / valid + << "% 0.8-1.0:" << 100.0 * hb[3] / valid + << "% 1.0-1.2:" << 100.0 * hb[4] / valid + << "% 1.2-1.4:" << 100.0 * hb[5] / valid + << "% 1.4-1.6:" << 100.0 * hb[6] / valid + << "% 1.6-1.8:" << 100.0 * hb[7] / valid + << "% 1.8-2.0:" << 100.0 * hb[8] / valid + << "% >2.0m:" << 100.0 * hFar / valid << "%" << std::endl; + } + frames = 0; + lastStats = now; + } + + // 主线程按键请求的执行端 (数据都在本线程, 文件操作也在这里): + // s: 全尺寸 .bin + 矫正图 (主线程已存 disp8 的 _depth.png) + if (saveReq_.load()) { + long long ts = lastTs_.load(); + char base[64]; + std::snprintf(base, sizeof(base), "depth_%lld", + static_cast(ts / 1000000)); + std::ofstream bin(base + std::string(".bin"), std::ios::binary); + bin.write(reinterpret_cast(depthImg_.data), + static_cast(depthImg_.width * + depthImg_.height * sizeof(float))); + bin.close(); + std::string note = "[Save] " + std::string(base) + ".bin"; + if (hasRect) { + cv::Mat rectM(rectImg_.height, rectImg_.width, + rectImg_.channel == 1 ? CV_8UC1 : CV_8UC3, rectImg_.data); + cv::imwrite(std::string(base) + "_rect.png", rectM); + note += " / _rect.png"; + } + std::cout << note << std::endl; + saveReq_.store(false); + } + // p: 点云 PLY + if (plyReq_.load()) { + cloud_.point_num = 0; + int ret = FAYS_ATRAK_D_GetPointcloud(depthHandle_, &cloud_, + FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM); + if (ret == 0 && cloud_.point_num > 0) { + char base[64]; + std::snprintf(base, sizeof(base), "cloud_%lld.ply", + static_cast(lastTs_.load() / 1000000)); + savePly(base, cloud_); + } else { + std::cout << "[PLY] 无点云 (ret=" << ret << ")" << std::endl; + } + plyReq_.store(false); + } + } + }); + + // ── 主显示线程: 取最新帧 → 后处理 → 显示 ── + int64_t prevFrameMs = 0; + int64_t maxGapMs = 0, sumGapMs = 0; + int gapCount = 0; + while (running_.load()) { + cv::Mat normSmall, stereoView, rectView; + { + std::unique_lock lk(qmtx_); + qcv_.wait(lk, [this] { return !depthQ_.empty() || !running_.load(); }); + if (depthQ_.empty()) break; + normSmall = depthQ_.back(); // 取最新, 积压帧丢弃 (不拖采集) + depthQ_.clear(); + if (!stereoQ_.empty()) { stereoView = stereoQ_.back(); stereoQ_.clear(); } + if (!rectQ_.empty()) { rectView = rectQ_.back(); rectQ_.clear(); } + } + + if (!stereoView.empty()) { + int hh = stereoView.rows / 2; + cv::putText(stereoView, "LEFT (cam0)", cv::Point(15, 30), + cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0, 255, 0), 2); + cv::putText(stereoView, "RIGHT (cam1)", cv::Point(15, hh + 30), + cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0, 255, 255), 2); + cv::imshow("Stereo Input (L/R)", stereoView); + } + if (!rectView.empty()) + cv::imshow("Rectified (engine)", rectView); + + // ── 深度显示 ── + // 官方模式 (默认): 官方 GUI 同款 —— 深度数据原样 + 直方图均衡 + JET. + // 范围预设按 M 循环 (0.1-1m ~ 0.3-8m, 默认 0.3-4m 同官方 GUI). + // 这是 SDK 的"正常效果": 引擎输出什么样, 显示就是什么样. + // 增强模式 (按 F): 历史迭代的后处理链 (去噪/填洞/CLAHE), 深度被改值. + cv::Mat disp8; // 保存用 (官方模式=indexed, 增强模式=分位数映射图) + cv::Mat depthColor; + if (officialMode_) { + const float pmin = kRangePresets[presetIdx_].minD; + const float pmax = kRangePresets[presetIdx_].maxD; + officialHistogramEqualize(normSmall, disp8, pmin, pmax); + cv::applyColorMap(disp8, depthColor, cv::COLORMAP_JET); + // JET 的索引 0 是深蓝, 显式把无效像素置黑 (官方 colormap.cpp 同款) + depthColor.setTo(cv::Scalar(0, 0, 0), normSmall <= 0.0f); + } else { + // ── 增强模式: D435 风格深度后处理 (显示侧, 640x400) ── + // 1) speckle: 小于 15px 的孤立有效区是飞点, 置无效 + { + cv::Mat validMask = (normSmall > 0.1f) & (normSmall < 1.5f); + cv::Mat labels, stats, centroids; + cv::connectedComponentsWithStats(validMask, labels, stats, centroids); + for (int i = 1; i < stats.rows; ++i) { + if (stats.at(i, cv::CC_STAT_AREA) < 15) + normSmall.setTo(0.0f, labels == i); + } + } + // 2) 单帧空间一致性剔除 (先于时间滤波!): + // 像素偏离 5x5 邻域中值 > 0.5m 判为错配置无效. + // 顺序关键: 若先做时间中值, 墙面 11 帧里的错配近值互相支持, + // 会把 2.5m 真值拉进近距带 → 整面墙稳定成蓝色 (回归根因). + { + const float kInvalid = 1000.0f; + cv::Mat tmp = normSmall.clone(); + tmp.setTo(kInvalid, normSmall <= 0.1f); + cv::Mat base; + cv::medianBlur(tmp, base, 5); + cv::Mat diff = cv::abs(normSmall - base); + normSmall.setTo(0.0f, diff > 0.5f); + } + // 3) 时间中值 (带远距保护): 5 帧环形缓冲 (11 帧抹边严重, 减负保轮廓; + // 近距候选过半取中值, 近值不足一半但出现过远值 → 1.6m 远档红, + // 全无效 → 0) + { + static std::vector tbuf( + 5, cv::Mat::zeros(normSmall.size(), CV_32FC1)); + static int slot = 0; + normSmall.copyTo(tbuf[slot]); + slot = (slot + 1) % 5; + cv::Mat medT(normSmall.size(), CV_32FC1, cv::Scalar(0.0f)); + const float kFar = 1.6f; + for (int r = 0; r < normSmall.rows; ++r) { + for (int c = 0; c < normSmall.cols; ++c) { + float v[5]; + int near = 0, far = 0; + for (int t = 0; t < 5; ++t) { + float x = tbuf[t].at(r, c); + if (x > 0.1f && x < 1.5f) v[near++] = x; + else if (x >= 1.5f) ++far; + } + if (near >= 3) { + std::nth_element(v, v + near / 2, v + near); + medT.at(r, c) = v[near / 2]; + } else if (far >= 1) { + medT.at(r, c) = kFar; + } + } + } + normSmall = medT; + } + // ── 深度着色: 自适应分位数映射 (D435 Viewer 风格) ── + // 直方图均衡按像素数量分色阶, 远景占多数时近景被压缩; + // 改为每帧取有效深度 [2%,98%] 分位作映射范围, 线性拉伸到全色域. + // 分位范围用 EMA 平滑, 颜色不闪烁. + disp8.create(normSmall.size(), CV_8UC1); + disp8.setTo(cv::Scalar(0)); + { + const int BINS = 4096; + const float dmin = 0.1f, dmax = 1.5f; + const float binW = (dmax - dmin) / BINS; + std::vector hist(BINS, 0); + long long total = 0; + for (int r = 0; r < normSmall.rows; ++r) { + const float* p = normSmall.ptr(r); + for (int c = 0; c < normSmall.cols; ++c) { + float d = p[c]; + if (d > dmin && d < dmax) { + int b = static_cast((d - dmin) / binW); + if (b >= BINS) b = BINS - 1; + hist[b]++; total++; + } + } + } + float lo = dmin, hi = dmax; + if (total >= 1000) { // 有效像素太少时退回固定范围 + long long tLo = total * 2 / 100, tHi = total * 98 / 100; + long long cum = 0; + bool loFound = false; + for (int b = 0; b < BINS; ++b) { + cum += hist[b]; + if (!loFound && cum >= tLo) { lo = dmin + (b + 0.5f) * binW; loFound = true; } + if (cum >= tHi) { hi = dmin + (b + 0.5f) * binW; break; } + } + if (hi - lo < 0.15f) hi = lo + 0.15f; // 最小范围防抖动 + } + gMapLo.store(gMapLo.load() * 0.8f + lo * 0.2f); // 慢速 EMA, 场景切换跟得上 + gMapHi.store(gMapHi.load() * 0.8f + hi * 0.2f); + const float mapLo = gMapLo.load(), mapHi = gMapHi.load(); + const float inv = 255.0f / (mapHi - mapLo); + for (int r = 0; r < normSmall.rows; ++r) { + const float* p = normSmall.ptr(r); + uchar* q = disp8.ptr(r); + for (int c = 0; c < normSmall.cols; ++c) { + float d = p[c]; + if (d > dmin) { // 1.5m 以上自动 clamp 到 255 (最远档红色) + float v = (d - mapLo) * inv; + q[c] = static_cast(std::max(0.0f, std::min(255.0f, v))); + } + } + } + } + // 4) 轮廓增强: 近景掩膜形态学闭运算 → 补掉物体边缘遮挡区窄缝/缺口 + // (洞像素用 3x3 邻域中值填充, 不改变已有深度层次) + { + cv::Mat mask = (normSmall > 0.1f) & (normSmall < 1.6f); + cv::Mat kern = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)); + cv::morphologyEx(mask, mask, cv::MORPH_CLOSE, kern); + cv::Mat hole = mask & (normSmall <= 0.1f); + const float kInvalid = 1000.0f; + cv::Mat tmp = normSmall.clone(); + tmp.setTo(kInvalid, normSmall <= 0.1f); + cv::medianBlur(tmp, tmp, 3); + tmp.setTo(0.0f, tmp > 10.0f); + tmp.copyTo(normSmall, hole); + } + // 5) CLAHE: 局部对比度拉伸, 相邻色阶拉开 → 轮廓视觉上更锐 + { + cv::Mat invMask = disp8 == 0; + cv::Ptr clahe = cv::createCLAHE(2.5, cv::Size(8, 8)); + clahe->apply(disp8, disp8); + disp8.setTo(0, invMask); // 无效区保持黑 + } + cv::applyColorMap(disp8, depthColor, cv::COLORMAP_JET); + } + cv::imshow("Depth", depthColor); + + // ── 显示帧间隔抖动 (局部卡顿的直接度量) ── + auto now = std::chrono::steady_clock::now(); + int64_t nowMs = std::chrono::duration_cast( + now.time_since_epoch()).count(); + if (prevFrameMs != 0) { + int64_t gap = nowMs - prevFrameMs; + if (gap > maxGapMs) maxGapMs = gap; + sumGapMs += gap; + ++gapCount; + } + prevFrameMs = nowMs; + static auto lastDispStats = std::chrono::steady_clock::now(); + if (now - lastDispStats >= std::chrono::seconds(1)) { + double avgGap = gapCount ? static_cast(sumGapMs) / gapCount : 0.0; + std::cout << "[Disp] 显示帧间隔均值 " << avgGap << " ms 最大 " + << maxGapMs << " ms" << std::endl; + lastDispStats = now; + maxGapMs = 0; sumGapMs = 0; gapCount = 0; + } + + // ── 按键 (显示线程; e/g 直调 viKit, 与官方 GUI 同构) ── + int key = cv::waitKey(1); + if (key == 27 || key == 'q' || key == 'Q') { + running_.store(false); + } else if (key == 's' || key == 'S') { + long long ts = lastTs_.load(); + char base[64]; + std::snprintf(base, sizeof(base), "depth_%lld", + static_cast(ts / 1000000)); + cv::imwrite(std::string(base) + "_depth.png", disp8); + saveReq_.store(true); // 采集线程存 .bin + _rect.png + } else if (key == 'c' || key == 'C') { + feedBgr_.store(!feedBgr_.load()); + std::cout << "[Feed] 送引擎通道序切换: " + << (feedBgr_.load() ? "BGR (SDK 文档约定)" : "RGB (固件原始)") + << std::endl; + } else if (key == 'e' || key == 'E') { + // 曝光预设循环 (文档范围 1.0~507.0; -1 = 自动) + static const double kExposurePresets[] = {-1.0, 500.0, 400.0, 300.0, + 200.0, 100.0, 50.0}; + static int expIdx = 0; + expIdx = (expIdx + 1) % + static_cast(sizeof(kExposurePresets) / sizeof(kExposurePresets[0])); + double ev = kExposurePresets[expIdx]; + int ret = FAYS_VIK_SetStereoExposure(viHandle_, ev); + std::cout << "[Exposure] " << (ev < 0 ? "AUTO" : std::to_string(ev)) + << " (ret=" << ret << ")" << std::endl; + } else if (key == 'g' || key == 'G') { + // 增益预设循环 (文档范围 1.0~15.0; -1 = 自动) + static const float kGainPresets[] = {-1.0f, 2.0f, 4.0f, 8.0f, 12.0f}; + static int gainIdx = 0; + gainIdx = (gainIdx + 1) % + static_cast(sizeof(kGainPresets) / sizeof(kGainPresets[0])); + float gv = kGainPresets[gainIdx]; + int ret = FAYS_VIK_SetStereoGain(viHandle_, gv); + std::cout << "[Gain] " << (gv < 0 ? "AUTO" : std::to_string(gv)) + << " (ret=" << ret << ")" << std::endl; + } else if (key == 'p' || key == 'P') { + plyReq_.store(true); + } else if (key == 'f' || key == 'F') { + officialMode_ = !officialMode_; + std::cout << "[Mode] " << (officialMode_ ? "官方模式 (深度原样 + 直方图均衡)" + : "增强模式 (后处理链 + 分位数映射)") + << std::endl; + } else if (key == 'm' || key == 'M') { + presetIdx_ = (presetIdx_ + 1) % + static_cast(sizeof(kRangePresets) / sizeof(kRangePresets[0])); + std::cout << "[Range] " << kRangePresets[presetIdx_].minD << " – " + << kRangePresets[presetIdx_].maxD << " m" << std::endl; + } + } + + running_.store(false); + capThread.join(); + cv::destroyAllWindows(); +} + +int main(int argc, char** argv) +{ + const char* env = std::getenv("SDK_DIR"); + std::string base = env ? env : "/home/REDACTED/FaysSense_VI_Kit_Release"; + std::string viKitConfig = base + "/config/fays_vikit.yaml"; + std::string depthConfig = base + "/config/perception/stereo_depth/stereo_depth.yaml"; + if (argc > 1) viKitConfig = argv[1]; + if (argc > 2) depthConfig = argv[2]; + + std::cout << "== S80M 双目深度 Demo (严格按 SDK 实现) ==" << std::endl; + // 限制 OpenCV 并行线程数 (默认吃满所有核): + // 深度引擎(WLS/SGBM) + 本 demo 后处理全开并行时把系统顶到高负载, + // 与录屏/浏览器抢 CPU → 系统级卡顿. 限 2 线程后引擎仍 25fps, + // CPU 占用大降. (引擎内部线程不受此控制, 见 ps 线程分布) + cv::setNumThreads(2); + StereoDepthDemo demo(viKitConfig, depthConfig); + if (!demo.ok()) return 1; + demo.run(); + return 0; +} diff --git a/collector/tools/demos/stereo_depth_demo/run.sh b/collector/tools/demos/stereo_depth_demo/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..469678ebbc20ee97dd35539b82067f322f488316 --- /dev/null +++ b/collector/tools/demos/stereo_depth_demo/run.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# +# 运行 S80M 双目深度 Demo (严格按 SDK 实现) +# +# LD_LIBRARY_PATH 按官方 GUI 相同方式设置: +# - SDK 自带 OpenCV 4.2 的 lib406 兼容目录 (深度引擎必须绑定 4.2) +# - SDK 官方库目录 (libfays_vikit.so / libfayssense_aikit_depth.so) +# +# 用法: +# ./run.sh [viKitConfig] [depthConfig] + +set -e +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SDK_DIR="${SDK_DIR:-${FAYSSENSE_SDK_DIR:-}}" +if [ -z "$SDK_DIR" ]; then + echo "[ERROR] 请设置 SDK_DIR 或 FAYSSENSE_SDK_DIR=" >&2 + exit 1 +fi + +LIB406_DIR="$SDK_DIR/thirdparty/opencv-4.2.0-linux-x86_64/lib406" +SDK_LIB_DIR="$SDK_DIR/lib/fays_atrak/$(uname -m)/Release" + +if [ ! -d "$LIB406_DIR" ]; then + echo "[ERROR] 找不到 SDK 自带 OpenCV 4.2 目录: $LIB406_DIR" >&2 + exit 1 +fi + +export LD_LIBRARY_PATH="$LIB406_DIR:$SDK_LIB_DIR:$LD_LIBRARY_PATH" +exec "$SCRIPT_DIR/build/stereo_depth_demo" "$@" diff --git a/collector/tools/demos/test_stereo_depth_calib.py b/collector/tools/demos/test_stereo_depth_calib.py new file mode 100644 index 0000000000000000000000000000000000000000..25f9349e63b275ce8db9415f3b494b3b4b8c85ee --- /dev/null +++ b/collector/tools/demos/test_stereo_depth_calib.py @@ -0,0 +1,644 @@ +#!/usr/bin/env python3 +""" +S80M 双目深度 Demo —— 使用 FaysSense VI Kit SDK 官方深度引擎 + +管线 (与 SDK 文档 stereo_depth.md 9.2 节一致): + 1. FAYS_VIK_CreateHandleWithConfig 打开相机 (fays_vikit.yaml) + 2. FAYS_ATRAK_D_CreateHandleWithConfig 创建深度引擎 (stereo_depth.yaml, depth_mode=1 CPU) + 3. FAYS_ATRAK_D_BindViKit 绑定相机到深度引擎 (在线模式, 标定由相机提供) + 4. 循环: + FAYS_VIK_GetStereoFrames -> 上下拼接双目帧 (上半左目 / 下半右目) + FAYS_ATRAK_D_FeedStereoImage -> 送入深度引擎 + FAYS_ATRAK_D_GetDepthImage -> 深度图 (float32, 米) + 视差图 + FAYS_ATRAK_D_GetRectifiedImage -> 矫正后双目图 (BGR8, 上下拼接) + 5. 'p' 键: FAYS_ATRAK_D_GetPointcloud -> 导出点云 PLY + +注: S80M 固件实际拼接为 上=右目/下=左目, 与 SDK 文档假设 (上=左) 相反, + 左右顺序已由官方配置 stereo_swap_lr: 1 (fays_vikit.yaml) 在传感器层解决, + 脚本不再手动交换 (SWAP_LR=False); 可按 L 切换验证. + +用法: + ./run_stereo_depth_demo.sh # 必须用启动器 (深度引擎需 SDK 自带 OpenCV 4.2) +按键: + Q / Esc 退出 | S 截图 | P 导出点云 PLY | L 切换左右 | 1-4 调整深度范围 +""" + +import ctypes +import os +import sys +import time +import struct +from ctypes import ( + c_void_p, c_char_p, c_int, c_short, c_float, + c_ubyte, c_uint, c_uint8, c_uint32, c_ulonglong, + POINTER, Structure, byref, cast, +) + +# ═══════════════════════════════════════════════════════════════ +# 路径 +# ═══════════════════════════════════════════════════════════════ + +SDK_DIR = os.environ.get("FAYSSENSE_SDK_DIR", "") +if not SDK_DIR: + raise SystemExit( + "[ERROR] 请先设置 FAYSSENSE_SDK_DIR=") +VIKIT_LIB = os.path.join(SDK_DIR, "lib", "fays_atrak", "x86_64", "Release", + "libfays_vikit.so") +DEPTH_LIB = os.path.join(SDK_DIR, "lib", "fays_atrak", "x86_64", "Release", + "libfayssense_aikit_depth.so") +VIKIT_CONFIG = os.path.join(SDK_DIR, "config", "fays_vikit.yaml") +DEPTH_CONFIG = os.path.join(SDK_DIR, "config", "perception", + "stereo_depth", "stereo_depth.yaml") + +# ── OpenCV 预加载 (libfays_vikit.so / aikit_depth.so 依赖其符号) ── +# 必须放在 import cv2 之前: SDK 库无 DT_NEEDED, 靠全局符号表解析. +# +# 关键: 深度引擎 libfayssense_aikit_depth.so 按 SDK 自带 OpenCV 4.2.0 编译, +# 它向 cv::stereoRectify 传 MatExpr/STD_ARRAY 数组, 而系统 OpenCV 4.6/4.13 +# 的 getMat_ 不支持这两类 (抛 "Unknown/unsupported array type"). +# 因此优先预载 SDK 自带 4.2 (lib406 目录), 找不到才回退系统 4.6. +OPENCV_LIB406 = os.path.join(SDK_DIR, "thirdparty", "opencv-4.2.0-linux-x86_64", + "lib406") + +def _preload_opencv_dir(libdir): + """从目录预加载 OpenCV 模块 + 外部依赖 (RTLD_GLOBAL).""" + for dep in ["libwebp.so.6", "libtiff.so.5", "libtbb.so.2", "libdc1394.so.22", + "libavcodec.so.58", "libavformat.so.58", "libavutil.so.56", + "libswscale.so.5"]: + p = os.path.join(libdir, dep) + if os.path.exists(p): + try: + ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL) + except OSError: + pass + for mod in ["libopencv_core", "libopencv_imgproc", "libopencv_imgcodecs", + "libopencv_highgui", "libopencv_calib3d", "libopencv_ximgproc", + "libopencv_features2d", "libopencv_flann", "libopencv_video", + "libopencv_videoio", "libopencv_photo", "libopencv_objdetect", + "libopencv_ml"]: + for suffix in [".so.406", ".so.4.2"]: + p = os.path.join(libdir, mod + suffix) + if os.path.exists(p): + try: + ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL) + break + except OSError: + pass + +if os.path.isdir(OPENCV_LIB406): + _preload_opencv_dir(OPENCV_LIB406) +else: + # 回退: 系统 OpenCV 4.6 (引擎在其下会崩, 仅限无自带 4.2 的环境) + for _lib in ["libopencv_core", "libopencv_imgproc", "libopencv_imgcodecs", + "libopencv_highgui", "libopencv_calib3d", "libopencv_ximgproc", + "libopencv_features2d", "libopencv_flann", "libopencv_video"]: + for _suffix in [".so.406", ".so.4.2"]: + try: + ctypes.CDLL(_lib + _suffix, mode=ctypes.RTLD_GLOBAL) + break + except OSError: + continue + +# cv2 在预载后导入: python 的 cv2 走自身 rpath 绑定 4.13, 与 SDK 的 4.2 互不干扰 +import numpy as np +import cv2 + +# ── Qt 平台插件 ────────────────────────────────────────────── +_OV_PLUGINS_DIR = os.path.join(os.path.dirname(cv2.__file__), "qt", "plugins") +_OV_PLATFORMS = os.path.join(_OV_PLUGINS_DIR, "platforms.bak") +if not os.path.isdir(_OV_PLATFORMS): + _OV_PLATFORMS = os.path.join(_OV_PLUGINS_DIR, "platforms") +os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = _OV_PLATFORMS + +# ═══════════════════════════════════════════════════════════════ +# SDK C 结构体 (对应 fays_atrak_types.h) +# ═══════════════════════════════════════════════════════════════ + +FAYS_ATRAK_MAX_CAMERAS = 3 + +class AtrakImage(Structure): + _fields_ = [ + ("device_id", c_int), + ("seq", c_int), + ("timestamp", c_ulonglong), + ("width", c_int), + ("height", c_int), + ("channel", c_int), + ("encoding", c_short), + ("step", c_int), + ("bytes", c_uint), + ("data", POINTER(c_ubyte)), + ] + +class AtrakDepthImage(Structure): + """深度/视差输出: data 指向 float 缓冲区 (深度单位: 米)""" + _fields_ = [ + ("device_id", c_int), + ("seq", c_int), + ("timestamp", c_ulonglong), + ("width", c_int), + ("height", c_int), + ("channel", c_int), + ("encoding", c_short), + ("step", c_int), + ("bytes", c_uint), + ("data", POINTER(c_float)), + ] + +class AtrakRectifyInfo(Structure): + """矫正矩阵 (fays_atrak_types.h)""" + _fields_ = [ + ("cam_pair", c_uint8 * 2), + ("R0", c_float * 9), # 左目 旋转 + ("R1", c_float * 9), # 右目 旋转 + ("P0", c_float * 12), # 左目 投影矩阵 + ("P1", c_float * 12), # 右目 投影矩阵 + ] + +class AtrakMap(Structure): + """点云: pos = N×3 float, rgb = N×1 ARGB8 (0xRRGGBBAA 位序: 高字节 R)""" + _fields_ = [ + ("device_id", c_int), + ("timestamp", c_ulonglong), + ("point_num", c_uint), + ("pos", POINTER(c_float)), + ("rgb", POINTER(c_uint32)), + ] + +class AtrakIntrinsics(Structure): + _fields_ = [ + ("cam_model", c_uint8), + ("width", c_uint32), + ("height", c_uint32), + ("fx", c_float), + ("fy", c_float), + ("cx", c_float), + ("cy", c_float), + ("intrinsic_extra", c_float * 4), + ("distortion_model", c_uint8), + ("distortion", c_float * 8), + ] + +class AtrakExtrinsics(Structure): + _fields_ = [ + ("rot", c_float * 9), + ("trans", c_float * 3), + ] + +class AtrakCamParam(Structure): + _fields_ = [ + ("cam_id", c_uint8), + ("available_mask", c_uint8), + ("intrinsics", AtrakIntrinsics), + ("T_cn_cnm1", AtrakExtrinsics), + ("T_cn_imu", AtrakExtrinsics), + ("timeshift_cam_imu", ctypes.c_double), + ] + +class AtrakCamChainParam(Structure): + _fields_ = [ + ("num_of_cams", c_uint32), + ("downsize_ratio", c_uint32), + ("cameras", AtrakCamParam * FAYS_ATRAK_MAX_CAMERAS), + ] + +class AtrakImuParam(Structure): + _fields_ = [ + ("accelerometer_noise_density", ctypes.c_double), + ("accelerometer_random_walk", ctypes.c_double), + ("gyroscope_noise_density", ctypes.c_double), + ("gyroscope_random_walk", ctypes.c_double), + ("update_rate", c_float), + ] + +class AtrakCalibrationParam(Structure): + _fields_ = [ + ("cameras", AtrakCamChainParam), + ("imu", AtrakImuParam), + ] + +# ═══════════════════════════════════════════════════════════════ +# 加载库 +# libfays_vikit.so -> C++ 混淆符号 (extern C++ 接口) +# libfayssense_aikit_depth.so -> C 符号 (extern "C", 直接可用) +# ═══════════════════════════════════════════════════════════════ + +# vikit 必须 RTLD_GLOBAL 加载: 深度库 dlopen 时需要解析其中的 FAYS_VIK_* 符号 +_vikit = ctypes.CDLL(VIKIT_LIB, mode=ctypes.RTLD_GLOBAL) +try: + _depth = ctypes.CDLL(DEPTH_LIB) +except OSError as e: + print(f"[ERROR] 深度引擎加载失败: {e}") + print(" 请用启动器运行 (它会将 SDK 自带 OpenCV 4.2 加入 LD_LIBRARY_PATH):") + print(" ./run_stereo_depth_demo.sh") + sys.exit(1) + +# ── ViKit (混淆符号) ──────────────────────────────────────── +_vikit_create = getattr(_vikit, "_Z31FAYS_VIK_CreateHandleWithConfigPPvPKc") +_vikit_destroy = getattr(_vikit, "_Z22FAYS_VIK_DestroyHandlePv") +_vikit_stereo = getattr(_vikit, "_Z24FAYS_VIK_GetStereoFramesPvP10AtrakImage") +_vikit_version = getattr(_vikit, "_Z19FAYS_VIK_GetVersionPv") +_vikit_calib = getattr(_vikit, "_Z28FAYS_VIK_GetCalibrationParamPvP21AtrakCalibrationParam") + +_vikit_create.argtypes = [POINTER(c_void_p), c_char_p] +_vikit_create.restype = c_int +_vikit_destroy.argtypes = [c_void_p] +_vikit_destroy.restype = c_int +_vikit_stereo.argtypes = [c_void_p, POINTER(AtrakImage)] +_vikit_stereo.restype = c_int +_vikit_version.argtypes = [c_void_p] +_vikit_version.restype = c_char_p +_vikit_calib.argtypes = [c_void_p, POINTER(AtrakCalibrationParam)] +_vikit_calib.restype = c_int + +# ── 深度引擎 (C 符号) ──────────────────────────────────────── +_d_create = _depth.FAYS_ATRAK_D_CreateHandleWithConfig +_d_destroy = _depth.FAYS_ATRAK_D_DestroyHandle +_d_bind = _depth.FAYS_ATRAK_D_BindViKit +_d_feed = _depth.FAYS_ATRAK_D_FeedStereoImage +_d_get = _depth.FAYS_ATRAK_D_GetDepthImage +_d_rect = _depth.FAYS_ATRAK_D_GetRectifiedImage +_d_rectinfo = _depth.FAYS_ATRAK_D_GetRectifyInfo +_d_cloud = _depth.FAYS_ATRAK_D_GetPointcloud + +_d_create.argtypes = [POINTER(c_void_p), c_char_p] +_d_create.restype = c_int +_d_destroy.argtypes = [c_void_p] +_d_destroy.restype = c_int +_d_bind.argtypes = [c_void_p, c_void_p] +_d_bind.restype = c_int +_d_feed.argtypes = [c_void_p, POINTER(AtrakImage)] +_d_feed.restype = c_int +_d_get.argtypes = [c_void_p, POINTER(AtrakDepthImage), + POINTER(AtrakDepthImage), POINTER(AtrakImage)] +_d_get.restype = c_int +_d_rect.argtypes = [c_void_p, POINTER(AtrakImage)] +_d_rect.restype = c_int +_d_rectinfo.argtypes = [c_void_p, POINTER(AtrakRectifyInfo)] +_d_rectinfo.restype = c_int +_d_cloud.argtypes = [c_void_p, POINTER(AtrakMap), c_int] +_d_cloud.restype = c_int + +# ═══════════════════════════════════════════════════════════════ +# 初始化: 相机 + 深度引擎 + 绑定 +# ═══════════════════════════════════════════════════════════════ + +# ── 1. 打开相机 ── +vikit_handle = c_void_p() +ret = _vikit_create(byref(vikit_handle), VIKIT_CONFIG.encode()) +if ret != 0: + print(f"[ERROR] ViKit 初始化失败, ret={ret} (相机是否连接? /dev/video* 端口配置?)") + sys.exit(1) + +ver = _vikit_version(vikit_handle) +print(f"ViKit 版本: {ver.decode() if ver else 'unknown'}") + +# ── 2. 创建深度引擎 ── +depth_handle = c_void_p() +ret = _d_create(byref(depth_handle), DEPTH_CONFIG.encode()) +if ret != 0: + print(f"[ERROR] 深度引擎创建失败, ret={ret}") + print(f" 请检查 {DEPTH_CONFIG}:") + print(" - depth_mode: 1 (CPU, 无需 NPU 模型)") + print(" - input_stereo_width/height 与 fays_vikit.yaml 的 stereo_single_cam_* 一致") + _vikit_destroy(vikit_handle) + sys.exit(1) +print(f"深度引擎创建成功 (config: {DEPTH_CONFIG})") + +# ── 3. 绑定相机 → 深度引擎 (在线模式, 标定由相机提供) ── +ret = _d_bind(depth_handle, vikit_handle) +if ret != 0: + print(f"[ERROR] BindViKit 失败, ret={ret}") + _d_destroy(depth_handle) + _vikit_destroy(vikit_handle) + sys.exit(1) +print("深度引擎已绑定 ViKit ✓\n") + +# ── 打印标定摘要 (仅信息展示, 校正由引擎内部完成) ── +calib = AtrakCalibrationParam() +if _vikit_calib(vikit_handle, byref(calib)) == 0: + cam0 = calib.cameras.cameras[0] + cam1 = calib.cameras.cameras[1] + baseline = np.linalg.norm(list(cam1.T_cn_cnm1.trans)) + print("相机标定 (信息):") + print(f" Cam0 fx={cam0.intrinsics.fx:.2f} fy={cam0.intrinsics.fy:.2f} " + f"{cam0.intrinsics.width}x{cam0.intrinsics.height}") + print(f" Cam1 fx={cam1.intrinsics.fx:.2f} fy={cam1.intrinsics.fy:.2f} " + f"{cam1.intrinsics.width}x{cam1.intrinsics.height}") + print(f" Baseline = {baseline*1000:.2f} mm") + print() + +# ── 矫正信息 (fx / 基线, 由引擎返回) ── +rect_info = AtrakRectifyInfo() +if _d_rectinfo(depth_handle, byref(rect_info)) == 0: + fx = rect_info.P0[0] + baseline = abs(rect_info.P1[3]) / fx # P1[3] = -fx·Tx + print(f"矫正矩阵: fx'={fx:.1f} baseline'={baseline*1000:.1f} mm") + print() + +# ═══════════════════════════════════════════════════════════════ +# 预分配输出缓冲区 (调用方分配, SDK 写入) +# ═══════════════════════════════════════════════════════════════ + +# SDK 头文件宏 (fays_atrak_types.h) +FAYS_ATRAK_MONO_MAX_BYTES = 1280 * 800 * 2 +FAYS_ATRAK_RGB_MAX_BYTES = 3840 * 2160 * 3 +FAYS_ATRAK_IMG_MAX_BYTES = max(FAYS_ATRAK_MONO_MAX_BYTES, FAYS_ATRAK_RGB_MAX_BYTES) +FAYS_ATRAK_DEPTH_IMG_MAX_BYTES = FAYS_ATRAK_IMG_MAX_BYTES * 4 # * sizeof(float) +FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM = 262144 + +# 输出缓冲必须按 SDK 头文件宏分配: +# 引擎按宏上限写入, 缓冲偏小会在特定时刻越界写堆 -> 随机段错误. +# 与 C++ 版 (stereo_depth_demo/main.cpp) 保持一致. +MAX_STEREO_BYTES = FAYS_ATRAK_MONO_MAX_BYTES * 3 # 双目拼接帧上限 (1280*800*2*3) +MAX_IMG_BYTES = FAYS_ATRAK_IMG_MAX_BYTES # rect/对齐图像上限 (3840*2160*3) +MAX_DEPTH_FLOATS = FAYS_ATRAK_DEPTH_IMG_MAX_BYTES // 4 # 深度/视差: float +MAX_CLOUD_POINTS = FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM + +stereo_buf = (c_ubyte * MAX_STEREO_BYTES)() +stereo_buf2 = (c_ubyte * MAX_STEREO_BYTES)() # 左右交换用缓冲区 +depth_buf = (c_float * MAX_DEPTH_FLOATS)() +disp_buf = (c_float * MAX_DEPTH_FLOATS)() +rect_buf = (c_ubyte * MAX_STEREO_BYTES)() +paired_buf = (c_ubyte * MAX_IMG_BYTES)() +cloud_pos = (c_float * (MAX_CLOUD_POINTS * 3))() +cloud_rgb = (c_uint32 * MAX_CLOUD_POINTS)() + +stereo_img = AtrakImage() +stereo_img.data = cast(stereo_buf, POINTER(c_ubyte)) + +# 左右交换用图像结构 (指向 stereo_buf2) +feed_img = AtrakImage() +feed_img.data = cast(stereo_buf2, POINTER(c_ubyte)) + +depth_out = AtrakDepthImage() +depth_out.data = cast(depth_buf, POINTER(c_float)) +disp_out = AtrakDepthImage() +disp_out.data = cast(disp_buf, POINTER(c_float)) +rect_out = AtrakImage() +rect_out.data = cast(rect_buf, POINTER(c_ubyte)) +paired_out = AtrakImage() +paired_out.data = cast(paired_buf, POINTER(c_ubyte)) + +cloud_out = AtrakMap() +cloud_out.pos = cast(cloud_pos, POINTER(c_float)) +cloud_out.rgb = cast(cloud_rgb, POINTER(c_uint32)) + + +# ═══════════════════════════════════════════════════════════════ +# 工具函数 +# ═══════════════════════════════════════════════════════════════ + +def img_to_numpy(img: AtrakImage) -> np.ndarray: + """AtrakImage (uint8) -> numpy, 按 step 处理行填充, 返回副本.""" + ch = img.channel if img.channel > 0 else 1 + n = img.bytes + arr = np.ctypeslib.as_array(img.data, shape=(n,)).copy() + row_bytes = img.step if img.step > 0 else img.width * ch + if row_bytes == img.width * ch: + return arr.reshape(img.height, img.width, ch) + # 带行填充: 用 as_strided 按 step 切行 + from numpy.lib.stride_tricks import as_strided + return as_strided(arr, shape=(img.height, img.width, ch), + strides=(row_bytes, ch, 1)).copy() + +def depth_to_numpy(img: AtrakDepthImage) -> np.ndarray: + """AtrakDepthImage (float32) -> numpy 2D.""" + n = img.bytes // 4 + arr = np.ctypeslib.as_array(img.data, shape=(n,)).copy() + return arr.reshape(img.height, img.width) + + +def save_pointcloud_ply(path: str, pos: np.ndarray, rgb: np.ndarray): + """pos: (N,3) float32, rgb: (N,) uint32 ARGB8 -> 二进制 PLY.""" + n = pos.shape[0] + with open(path, "wb") as f: + f.write(b"ply\nformat binary_little_endian 1.0\n") + f.write(f"element vertex {n}\n".encode()) + f.write(b"property float x\nproperty float y\nproperty float z\n") + f.write(b"property uchar red\nproperty uchar green\nproperty uchar blue\n") + f.write(b"end_header\n") + for i in range(n): + x, y, z = pos[i] + c = int(rgb[i]) + f.write(struct.pack("> 16) & 0xFF, (c >> 8) & 0xFF, c & 0xFF)) + + +# ═══════════════════════════════════════════════════════════════ +# 实时循环 +# ═══════════════════════════════════════════════════════════════ + +cv2.namedWindow("Depth Heatmap", cv2.WINDOW_NORMAL) +cv2.namedWindow("Stereo (raw/rect)", cv2.WINDOW_NORMAL) +cv2.namedWindow("Disparity", cv2.WINDOW_NORMAL) +cv2.resizeWindow("Depth Heatmap", 640, 400) +cv2.resizeWindow("Stereo (raw/rect)", 640, 480) +cv2.resizeWindow("Disparity", 640, 400) + +D_NEAR, D_FAR = 0.3, 4.0 +# 左右顺序已由官方配置 stereo_swap_lr: 1 (fays_vikit.yaml) 在传感器层解决, +# 脚本不再手动交换; 可按 L 键切换以验证配置是否生效. +SWAP_LR = False +# S80M 固件实际输出 RGB 通道序 (与头文件声称的 BGR 相反), 需转 BGR 再显示/送引擎 +SWAP_RGB = True +frame_idx = 0 +fps = 0.0 +_frame_info_shown = False +_t0 = time.monotonic() + +print(f"\n按 Q/Esc 退出 | S 截图 | P 导出点云 PLY | 1-4 调整深度范围") +print(f"深度显示范围: {D_NEAR}m - {D_FAR}m\n") + +try: + while True: + # ── 1. 获取双目帧 (上下拼接) ── + ret = _vikit_stereo(vikit_handle, byref(stereo_img)) + if ret != 0: # -2 = VIKIT_RET_NO_NEW_FRAME + cv2.waitKey(1) + continue + + # 首次检查帧格式 + if not _frame_info_shown: + enc = stereo_img.encoding # AIE_BGR8=0, AIE_RAW8=2 + print(f"双目帧: {stereo_img.width}x{stereo_img.height} " + f"ch={stereo_img.channel} encoding={enc} bytes={stereo_img.bytes}") + print(f" 左右顺序: {'已交换 (上=右/下=左)' if SWAP_LR else '默认 (上=左/下=右)'} " + f"—— 按 L 切换") + _frame_info_shown = True + + # ── 2. 通道顺序: S80M 固件实际输出 RGB (与头文件声称的 BGR 相反, + # 同类固件怪癖, 与左右顺序反了一样). 统一转 BGR 再显示/送引擎. ── + frame_np = img_to_numpy(stereo_img) # 副本 (H, W, ch) + if SWAP_RGB: + frame_np = np.ascontiguousarray(frame_np[:, :, ::-1]) # RGB -> BGR + + # ── 3. 送引擎 (转换后的帧统一拷入 feed 缓冲) ── + # 左右顺序已由官方配置 stereo_swap_lr: 1 在传感器层解决, 默认不交换; + # 按 L 可切换验证 (不能用 flipud 整帧翻转, 会倒置每只眼). + # 注意: 引擎按 BGR 约定处理输入 (与 C++ 版一致) —— 直接送原始 RGB + # 会导致 rect 输出窗口通道反色 (用户实测确认). + _hh = frame_np.shape[0] // 2 + if SWAP_LR: + frame_np = np.vstack([frame_np[_hh:], frame_np[:_hh]]) # 连续数组 + feed = byref(feed_img) + if frame_np.nbytes <= MAX_STEREO_BYTES: + ctypes.memmove(feed_img.data, frame_np.ctypes.data, frame_np.nbytes) + feed_img.width = stereo_img.width + feed_img.height = stereo_img.height + feed_img.channel = stereo_img.channel + feed_img.encoding = stereo_img.encoding + feed_img.step = stereo_img.step + feed_img.bytes = stereo_img.bytes + feed_img.timestamp = stereo_img.timestamp + feed_img.seq = stereo_img.seq + feed_img.device_id = stereo_img.device_id + + # ── 3. 送入深度引擎 ── + if _d_feed(depth_handle, feed) != 0: + continue + + # ── 3. 取深度 / 视差 (调用前清零字段, 引擎回填) ── + for out in (depth_out, disp_out, paired_out): + out.width = out.height = out.channel = 0 + out.step = out.bytes = 0 + if _d_get(depth_handle, byref(depth_out), byref(disp_out), + byref(paired_out)) != 0 or depth_out.width == 0: + cv2.waitKey(1) + continue + + depth = depth_to_numpy(depth_out) # float32, 米 + disp = depth_to_numpy(disp_out) # float32 视差 + disp = np.maximum(disp, 0.0) + + # ── 4. 矫正图 (上左目 / 下右目) ── + rect_out.width = rect_out.height = rect_out.channel = 0 + rect_out.step = rect_out.bytes = 0 + rect_np = None + if _d_rect(depth_handle, byref(rect_out)) == 0 and rect_out.width > 0: + rect_np = img_to_numpy(rect_out) + + # ── 5. 深度热力图 ── + finite = np.isfinite(depth) + visible = finite & (depth > D_NEAR) & (depth < D_FAR) + normed = np.zeros_like(depth, dtype=np.uint8) + if visible.any(): + vmin, vmax = depth[visible].min(), depth[visible].max() + if vmax > vmin: + normed[visible] = ((depth[visible] - vmin) / + (vmax - vmin) * 254 + 1).astype(np.uint8) + else: + normed[visible] = 128 + heatmap = cv2.applyColorMap(normed, cv2.COLORMAP_JET) + heatmap[~visible] = (0, 0, 0) + + h, w = depth.shape + d_center = depth[h // 2, w // 2] + cv2.putText(heatmap, + f"Frame {frame_idx} | {fps:.1f} fps | Center: " + f"{d_center:.2f} m" if np.isfinite(d_center) and d_center > 0 else + f"Frame {frame_idx} | {fps:.1f} fps | Center: --", + (10, 22), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1) + cv2.putText(heatmap, + f"Depth {D_NEAR:.1f}-{D_FAR:.1f} m | SDK depth " + f"{w}x{h} (float32, m)", + (10, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (200, 200, 200), 1) + + # ── 6. 原始 + 矫正 并排显示 ── + stereo_np = frame_np # 已按 SWAP_LR 交换过 + half_h = stereo_np.shape[0] // 2 + left_raw, right_raw = stereo_np[:half_h], stereo_np[half_h:] + + def _small(im): + s = im.shape + return cv2.resize(im, (s[1] // 4, s[0] // 4)) + + if rect_np is not None: + rh = rect_np.shape[0] // 2 + left_rect, right_rect = rect_np[:rh], rect_np[rh:] + top = np.hstack([_small(left_raw), _small(right_raw)]) + bot = np.hstack([_small(left_rect), _small(right_rect)]) + cv2.putText(top, 'Left raw / Right raw', (5, 16), + cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 255, 255), 1) + cv2.putText(bot, 'Left rect / Right rect', (5, 16), + cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 255, 255), 1) + stereo_view = np.vstack([top, bot]) + else: + stereo_view = np.hstack([_small(left_raw), _small(right_raw)]) + cv2.imshow("Stereo (raw/rect)", stereo_view) + + # ── 7. 视差图 ── + if disp.max() > 0: + disp_norm = ((disp / disp.max()) * 255).astype(np.uint8) + else: + disp_norm = np.zeros_like(disp, dtype=np.uint8) + disp_heat = cv2.applyColorMap(disp_norm, cv2.COLORMAP_TURBO) + cv2.imshow("Disparity", disp_heat) + cv2.imshow("Depth Heatmap", heatmap) + + # ── 8. 按键处理 ── + key = cv2.waitKeyEx(1) + if key == ord('q') or key == 27: + break + elif key == ord('s'): + ts = stereo_img.timestamp + cv2.imwrite(f'depth_heat_{ts}.png', heatmap) + cv2.imwrite(f'disparity_{ts}.png', disp_heat) + if rect_np is not None: + cv2.imwrite(f'stereo_rectified_{ts}.png', rect_np) + with open(f'depth_{ts}.raw', 'wb') as f: + f.write(depth.astype(np.float32).tobytes()) + print(f'[截图] depth_heat_{ts}.png / disparity_{ts}.png / ' + f'depth_{ts}.raw (float32 meters)') + elif key == ord('p'): + cloud_out.point_num = 0 + if _d_cloud(depth_handle, byref(cloud_out), MAX_CLOUD_POINTS) == 0 \ + and cloud_out.point_num > 0: + n = int(cloud_out.point_num) + pos = np.ctypeslib.as_array(cloud_pos, shape=(n * 3,)).copy() + rgb = np.ctypeslib.as_array(cloud_rgb, shape=(n,)).copy() + ply = f'pointcloud_{stereo_img.timestamp}.ply' + save_pointcloud_ply(ply, pos.reshape(n, 3), rgb) + print(f'[点云] {ply} ({n} 点)') + else: + print('[点云] 获取失败 (深度无效区域过多?)') + elif key in (ord('l'), ord('L')): + SWAP_LR = not SWAP_LR + print(f"[左右] 已切换为 {'交换 (上=右/下=左)' if SWAP_LR else '默认 (上=左/下=右)'}") + elif key == ord('1'): + D_NEAR = max(0.05, D_NEAR - 0.1) + print(f"深度显示: [{D_NEAR:.2f}, {D_FAR:.2f}] m") + elif key == ord('2'): + D_NEAR = min(D_FAR - 0.1, D_NEAR + 0.1) + print(f"深度显示: [{D_NEAR:.2f}, {D_FAR:.2f}] m") + elif key == ord('3'): + D_FAR = max(D_NEAR + 0.1, D_FAR - 0.5) + print(f"深度显示: [{D_NEAR:.2f}, {D_FAR:.2f}] m") + elif key == ord('4'): + D_FAR = min(10.0, D_FAR + 0.5) + print(f"深度显示: [{D_NEAR:.2f}, {D_FAR:.2f}] m") + elif key > 0 and key not in (ord('q'), 27, ord('s'), ord('p'), + ord('l'), ord('L'), + ord('1'), ord('2'), ord('3'), ord('4')): + print(f'[按键] code={key} hex=0x{key:04X}') + + frame_idx += 1 + now = time.monotonic() + if now - _t0 >= 1.0: + fps = frame_idx / (now - _t0) + frame_idx = 0 + _t0 = now + # 每秒打印一次深度统计, 方便验证深度数据真实性 + _valid = np.isfinite(depth) & (depth > 0.05) + if _valid.any(): + print(f" [深度] 有效 {_valid.sum()/max(_valid.size,1)*100:.0f}% " + f"中位 {np.median(depth[_valid]):.2f}m " + f"范围 {depth[_valid].min():.2f}-{depth[_valid].max():.2f}m") + else: + print(" [深度] 当前帧无有效深度数据") + +finally: + cv2.destroyAllWindows() + _d_destroy(depth_handle) + _vikit_destroy(vikit_handle) + print("\n已退出, 深度引擎与相机句柄已释放") diff --git a/collector/tools/diag_color.py b/collector/tools/diag_color.py new file mode 100644 index 0000000000000000000000000000000000000000..7c757f31c294b2fd8a0152b2cd7bf28a0e344e11 --- /dev/null +++ b/collector/tools/diag_color.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""诊断: S80M 子进程 pipe 输出的一帧,颜色通道是否正确。 + +抓一帧同时存两份 PNG: + /tmp/s80m_left_BGR.png — 解码后原样 (BGR 布局) + /tmp/s80m_left_RGB.png — 转成 RGB 布局 + +用图片查看器打开,看哪张颜色正常 (如红色物体显示为红色)。 +""" +import ctypes +import struct +import subprocess +import sys +import numpy as np +import cv2 +import os + +SDK_DIR = os.environ.get("FAYSSENSE_SDK_DIR", "") +STERE_DEMO = os.path.join(SDK_DIR, "read_stereo_rgb.py") if SDK_DIR else "" +if not SDK_DIR or not os.path.isfile(STERE_DEMO): + print("[ERROR] 请设置 FAYSSENSE_SDK_DIR=") + sys.exit(1) +VENV_PY = sys.executable # 本脚本须在 DAQ venv 下运行 + +proc = subprocess.Popen( + [VENV_PY, STERE_DEMO, "--pipe", "-"], + cwd=SDK_DIR, + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, +) + +try: + fifo = proc.stdout + # 等第一帧 + for i in range(50): + header = fifo.read(4) + if len(header) < 4: + print(f"[{i}] 无数据, 子进程已退出 code={proc.poll()}") + sys.exit(1) + left_len = struct.unpack(">I", header)[0] + left_data = fifo.read(left_len) + if len(left_data) < left_len: + print("帧不完整") + sys.exit(1) + + header = fifo.read(4) + if len(header) < 4: + print("右目头缺失") + sys.exit(1) + right_len = struct.unpack(">I", header)[0] + right_data = fifo.read(right_len) + + left = cv2.imdecode(np.frombuffer(left_data, np.uint8), cv2.IMREAD_COLOR) + right = cv2.imdecode(np.frombuffer(right_data, np.uint8), cv2.IMREAD_COLOR) + if left is None or right is None: + continue + + # 分割上下半 (与 GUI 一致) + if left.shape[0] > left.shape[1]: + mid = left.shape[0] // 2 + l_top, l_bot = left[:mid], left[mid:] + else: + l_top, l_bot = left, None + + # BGR 原样保存 + cv2.imwrite("/tmp/s80m_left_BGR.png", l_top) + # RGB 转换保存 + cv2.imwrite("/tmp/s80m_left_RGB.png", cv2.cvtColor(l_top, cv2.COLOR_BGR2RGB)) + + print("已保存:") + print(" /tmp/s80m_left_BGR.png (OpenCV 原样, BGR 布局)") + print(" /tmp/s80m_left_RGB.png (BGR→RGB 转换后)") + print("请用图片查看器打开两张,看哪张颜色正常。") + break +finally: + proc.terminate() diff --git a/collector/tools/diag_frame_layout.py b/collector/tools/diag_frame_layout.py new file mode 100644 index 0000000000000000000000000000000000000000..8f203a447be9a43fdf5abb5bd234aa0dc968d1e5 --- /dev/null +++ b/collector/tools/diag_frame_layout.py @@ -0,0 +1,229 @@ +#!/usr/bin/env python3 +""" +诊断脚本:验证 S80M 帧布局 + 标定数据 +""" +import ctypes +import numpy as np +import cv2 +import os, sys +from ctypes import ( + c_void_p, c_char_p, c_int, c_short, c_float, c_double, + c_ubyte, c_uint, c_uint8, c_uint32, c_ulonglong, + POINTER, Structure, byref, addressof, +) + +SDK_DIR = os.environ.get("FAYSSENSE_SDK_DIR", "") +if not SDK_DIR: + print("[ERROR] 请设置 FAYSSENSE_SDK_DIR=", file=sys.stderr) + sys.exit(1) +VIKIT_LIB = os.path.join(SDK_DIR, "lib", "fays_atrak", "x86_64", "Release", "libfays_vikit.so") +VIKIT_CONFIG = os.path.join(SDK_DIR, "config", "fays_vikit.yaml") + +for _lib in ["libopencv_core", "libopencv_imgproc", "libopencv_imgcodecs", "libopencv_highgui"]: + for _suffix in [".so.406", ".so.4.2"]: + try: + ctypes.CDLL(_lib + _suffix, mode=ctypes.RTLD_GLOBAL) + break + except OSError: + continue + +_OV_PLUGINS_DIR = os.path.join(os.path.dirname(cv2.__file__), "qt", "plugins") +_OV_PLATFORMS = os.path.join(_OV_PLUGINS_DIR, "platforms.bak") +if not os.path.isdir(_OV_PLATFORMS): + _OV_PLATFORMS = os.path.join(_OV_PLUGINS_DIR, "platforms") +if os.path.isdir(_OV_PLATFORMS): + os.environ["QT_QPA_PLATFORM_PLUGIN_PATH"] = _OV_PLATFORMS + +# ── Struct definitions ── +class AtrakImage(Structure): + _fields_ = [ + ("device_id", c_int), ("seq", c_int), ("timestamp", c_ulonglong), + ("width", c_int), ("height", c_int), ("channel", c_int), + ("encoding", c_short), ("step", c_int), ("bytes", c_uint), + ("data", POINTER(c_ubyte)), + ] + +class AtrakIntrinsics(Structure): + _fields_ = [ + ("cam_model", c_uint8), + ("width", c_uint32), ("height", c_uint32), + ("fx", c_float), ("fy", c_float), ("cx", c_float), ("cy", c_float), + ("intrinsic_extra", c_float * 4), + ("distortion_model", c_uint8), + ("distortion", c_float * 8), + ] + +class AtrakExtrinsics(Structure): + _fields_ = [("rot", c_float * 9), ("trans", c_float * 3)] + +class AtrakCamParam(Structure): + _fields_ = [ + ("cam_id", c_uint8), ("available_mask", c_uint8), + ("intrinsics", AtrakIntrinsics), + ("T_cn_cnm1", AtrakExtrinsics), + ("T_cn_imu", AtrakExtrinsics), + ("timeshift_cam_imu", c_double), + ] + +class AtrakCamChainParam(Structure): + _fields_ = [("num_of_cams", c_uint32), ("downsize_ratio", c_uint32), + ("cameras", AtrakCamParam * 3)] + +class AtrakImuParam(Structure): + _fields_ = [ + ("accelerometer_noise_density", c_double), + ("accelerometer_random_walk", c_double), + ("gyroscope_noise_density", c_double), + ("gyroscope_random_walk", c_double), + ("update_rate", c_float), + ] + +class AtrakCalibrationParam(Structure): + _fields_ = [("cameras", AtrakCamChainParam), ("imu", AtrakImuParam)] + +# ── Load SDK ── +lib = ctypes.CDLL(VIKIT_LIB) +_fn_create = getattr(lib, "_Z31FAYS_VIK_CreateHandleWithConfigPPvPKc") +_fn_destroy = getattr(lib, "_Z22FAYS_VIK_DestroyHandlePv") +_fn_stereo = getattr(lib, "_Z24FAYS_VIK_GetStereoFramesPvP10AtrakImage") +_fn_version = getattr(lib, "_Z19FAYS_VIK_GetVersionPv") +_fn_calib = getattr(lib, "_Z28FAYS_VIK_GetCalibrationParamPvP21AtrakCalibrationParam") + +_fn_create.argtypes = [POINTER(c_void_p), c_char_p] +_fn_create.restype = c_int +_fn_destroy.argtypes = [c_void_p] +_fn_destroy.restype = c_int +_fn_stereo.argtypes = [c_void_p, POINTER(AtrakImage)] +_fn_stereo.restype = c_int +_fn_version.argtypes = [c_void_p] +_fn_version.restype = c_char_p +_fn_calib.argtypes = [c_void_p, POINTER(AtrakCalibrationParam)] +_fn_calib.restype = c_int + +# ── Init ── +handle = c_void_p() +ret = _fn_create(byref(handle), VIKIT_CONFIG.encode()) +if ret != 0: + print(f"[ERROR] ViKit init failed, ret={ret}") + sys.exit(1) + +ver = _fn_version(handle) +print(f"ViKit version: {ver.decode() if ver else 'unknown'}") + +# ── Read calibration ── +calib = AtrakCalibrationParam() +ret = _fn_calib(handle, byref(calib)) +if ret != 0: + print(f"[ERROR] Read calibration failed, ret={ret}") + sys.exit(1) + +ncams = calib.cameras.num_of_cams +print(f"\n{'='*70}") +print(f" Cameras: {ncams} | Downsize ratio: {calib.cameras.downsize_ratio}") +print(f"{'='*70}") + +for i in range(ncams): + cam = calib.cameras.cameras[i] + intr = cam.intrinsics + ext = cam.T_cn_cnm1 + print(f"\n ── Camera {i} (cam_id={cam.cam_id}, mask=0x{cam.available_mask:02X}) ──") + print(f" Intrinsics: {intr.width}×{intr.height}") + print(f" fx={intr.fx:.3f} fy={intr.fy:.3f} cx={intr.cx:.3f} cy={intr.cy:.3f}") + print(f" cam_model={intr.cam_model} dist_model={intr.distortion_model}") + print(f" distortion: k1={intr.distortion[0]:.6f} k2={intr.distortion[1]:.6f} " + f"k3={intr.distortion[2]:.6f} k4={intr.distortion[3]:.6f}") + print(f" T_cn_cnm1 (cam{i-1}→cam{i}):") + print(f" rot: [{ext.rot[0]:.4f} {ext.rot[1]:.4f} {ext.rot[2]:.4f}") + print(f" {ext.rot[3]:.4f} {ext.rot[4]:.4f} {ext.rot[5]:.4f}") + print(f" {ext.rot[6]:.4f} {ext.rot[7]:.4f} {ext.rot[8]:.4f}]") + print(f" trans: [{ext.trans[0]:.4f} {ext.trans[1]:.4f} {ext.trans[2]:.4f}]") + baseline = np.sqrt(sum(t*t for t in ext.trans)) + print(f" baseline = {baseline*1000:.2f} mm") + +# ── Grab one frame ── +print(f"\n{'='*70}") +print(f" Frame Layout Diagnosis") +print(f"{'='*70}") + +MAX_BYTES = 1280 * 1600 * 3 +img_buf = (c_ubyte * MAX_BYTES)() +img = AtrakImage() +img.data = ctypes.cast(img_buf, POINTER(c_ubyte)) + +for attempt in range(10): + ret = _fn_stereo(handle, byref(img)) + if ret == 0: + break + cv2.waitKey(1) +else: + print("[ERROR] Could not grab frame") + sys.exit(1) + +w, h, ch = img.width, img.height, img.channel +print(f" Raw frame: {w}×{h} channels={ch}") +print(f" mono_w = {w//2}") + +full = np.ctypeslib.as_array( + (c_ubyte * (w * h * ch)).from_address(addressof(img_buf)) +).reshape((h, w, ch)) + +SUB_H = 400 +mono_w = w // 2 + +# ── Extract all 8 sub-regions (2 cols × 4 rows) ── +print(f"\n ── Column 0 (left half of frame) ──") +for ri in range(4): + r0, r1 = ri * SUB_H, (ri + 1) * SUB_H + s = full[r0:r1, :mono_w] + print(f" Row {ri} [{r0}:{r1}, 0:{mono_w}]: " + f"mean={s.mean():.1f} std={s.std():.1f}") + +print(f"\n ── Column 1 (right half of frame) ──") +for ri in range(4): + r0, r1 = ri * SUB_H, (ri + 1) * SUB_H + s = full[r0:r1, mono_w:w] + print(f" Row {ri} [{r0}:{r1}, {mono_w}:{w}]: " + f"mean={s.mean():.1f} std={s.std():.1f}") + +# ── Cross-correlation to check if cols are same lens ── +print(f"\n ── Cross-correlation between col0 and col1 (same row) ──") +for ri in range(4): + r0, r1 = ri * SUB_H, (ri + 1) * SUB_H + c0 = cv2.cvtColor(full[r0:r1, :mono_w], cv2.COLOR_BGR2GRAY).astype(np.float32) + c1 = cv2.cvtColor(full[r0:r1, mono_w:w], cv2.COLOR_BGR2GRAY).astype(np.float32) + corr = cv2.matchTemplate(c0, c1[200:300, 200:300], cv2.TM_CCOEFF_NORMED)[0,0] + print(f" Row {ri}: col0 vs col1 correlation = {corr:.4f}") + +# ── Save diagnostic images ── +# Full frame (resized to fit screen) +full_small = cv2.resize(full, (640, 800)) +cv2.imwrite("/tmp/diag_full_frame.png", full_small) + +# 2×4 grid of all sub-regions +grid = np.zeros((SUB_H * 4, mono_w * 2, 3), dtype=np.uint8) +for ri in range(4): + r0, r1 = ri * SUB_H, (ri + 1) * SUB_H + grid[ri*SUB_H:(ri+1)*SUB_H, 0:mono_w] = full[r0:r1, :mono_w] + grid[ri*SUB_H:(ri+1)*SUB_H, mono_w:mono_w*2] = full[r0:r1, mono_w:w] +cv2.imwrite("/tmp/diag_grid.png", grid) + +print(f"\n Diagnostic images saved:") +print(f" /tmp/diag_full_frame.png (full frame, resized)") +print(f" /tmp/diag_grid.png (2-col × 4-row grid)") + +# ── Check: does col0 look different from col1? ── +col0_all = full[:, :mono_w] +col1_all = full[:, mono_w:] +col0_gray = cv2.cvtColor(col0_all, cv2.COLOR_BGR2GRAY).astype(np.float32) +col1_gray = cv2.cvtColor(col1_all, cv2.COLOR_BGR2GRAY).astype(np.float32) +diff = np.abs(col0_gray - col1_gray) +print(f"\n col0 vs col1 (all rows): mean_diff={diff.mean():.1f} max_diff={diff.max():.0f}") + +# ── Check: are rows 0,1 same lens vs rows 2,3? ── +r01 = cv2.cvtColor(full[:SUB_H*2, :mono_w], cv2.COLOR_BGR2GRAY).astype(np.float32) +r23 = cv2.cvtColor(full[SUB_H*2:, :mono_w], cv2.COLOR_BGR2GRAY).astype(np.float32) +diff_rows = np.abs(r01 - r23) +print(f" col0: rows0-1 vs rows2-3: mean_diff={diff_rows.mean():.1f} max_diff={diff_rows.max():.0f}") + +_fn_destroy(handle) +print("\nDone.") diff --git a/collector/tools/diag_uvc_formats.py b/collector/tools/diag_uvc_formats.py new file mode 100644 index 0000000000000000000000000000000000000000..ed4c70c983db3a97337b00b5f9a3a1e75f307915 --- /dev/null +++ b/collector/tools/diag_uvc_formats.py @@ -0,0 +1,111 @@ +"""UVC camera format/fps diagnostic (Windows + Linux). + +For each camera index, try every FOURCC x resolution combination with the +same backends the main program uses, and MEASURE the real frame rate by +reading frames (~2 s per combination). Use it to find which combination +actually reaches ~30 fps (e.g. YUYV @ 1280x960 is hardware-limited to +5 fps on some cameras while MJPG reaches 30). + +Usage: + Windows: venv\\Scripts\\python.exe tools\\diag_uvc_formats.py [max_index] + Linux: venv/bin/python3 tools/diag_uvc_formats.py [max_index] + +Close the main program (and any app using the cameras) before running. +Output is ASCII-only so the Windows GBK console shows it correctly. +""" + +import sys +import time + +import cv2 + +BACKENDS = ([("DShow", cv2.CAP_DSHOW), ("MSMF", cv2.CAP_MSMF)] + if sys.platform == "win32" else [("V4L2", cv2.CAP_V4L2)]) +FOURCCS = ["MJPG", "YUYV"] +RESES = [(1280, 960), (960, 720), (800, 600), (640, 480)] +TARGET_FPS = 30 +READ_FRAMES = 20 # 实测读帧数:5fps 下约 4s,30fps 下 <1s + + +def _is_sdk_device(index): + """Linux: skip FTDI stereo nodes (need the vendor SDK, not UVC).""" + if sys.platform == "win32": + return False + try: + with open(f"/sys/class/video4linux/video{index}/name") as f: + return "FTDI" in f.read() + except OSError: + return False + + +def measure(index, backend_val, fourcc, w, h): + """Open camera with the given combo and measure the real fps.""" + cap = cv2.VideoCapture(index, backend_val) + if not cap.isOpened(): + return None + try: + if fourcc: + cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*fourcc)) + cap.set(cv2.CAP_PROP_FRAME_WIDTH, w) + cap.set(cv2.CAP_PROP_FRAME_HEIGHT, h) + cap.set(cv2.CAP_PROP_FPS, TARGET_FPS) + rb_w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + rb_h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) + rb_fourcc = int(cap.get(cv2.CAP_PROP_FOURCC)) + rb_fps = float(cap.get(cv2.CAP_PROP_FPS)) + # Windows DShow/MSMF: re-assert FOURCC after res/fps (media-type + # rebuild can drop MJPG back to YUYV) -- same as the main program. + if sys.platform == "win32" and fourcc: + cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*fourcc)) + n, t0, ok = 0, 0.0, False + for _ in range(READ_FRAMES): + ok, frame = cap.read() + if not ok or frame is None: + break + n += 1 + if n == 1: + t0 = time.perf_counter() + if n < 2: + return None + fps = (n - 1) / (time.perf_counter() - t0) + return {"rb_w": rb_w, "rb_h": rb_h, "rb_fourcc": rb_fourcc, + "rb_fps": rb_fps, "fps": fps} + finally: + cap.release() + + +def fourcc_name(v): + return "".join(chr(c) if 32 <= c < 127 else "?" + for c in ((v >> 24) & 0xFF, (v >> 16) & 0xFF, + (v >> 8) & 0xFF, v & 0xFF)) + + +def main(): + max_index = int(sys.argv[1]) if len(sys.argv) > 1 else 8 + print(f"== UVC format/fps diagnostic (target {TARGET_FPS} fps) ==") + for i in range(max_index): + if _is_sdk_device(i): + continue + for bname, bval in BACKENDS: + probe = cv2.VideoCapture(i, bval) + opened = probe.isOpened() + probe.release() + if not opened: + continue + print(f"-- camera index {i} (backend {bname}) --") + for fc in FOURCCS: + for (w, h) in RESES: + r = measure(i, bval, fc, w, h) + if r is None: + print(f" {fc:>4} {w}x{h}: open/read failed") + continue + star = "*" if r["fps"] >= TARGET_FPS * 0.8 else " " + print(f" {star} {fc:>4} {w}x{h}: real {r['fps']:5.1f} fps" + f" (readback fourcc={fourcc_name(r['rb_fourcc'])}" + f" {r['rb_w']}x{r['rb_h']} fps={r['rb_fps']})") + break # per index: prefer the first backend that opens + print("done.") + + +if __name__ == "__main__": + main() diff --git a/collector/tools/fayssense_depth_sdk/CMakeLists.txt b/collector/tools/fayssense_depth_sdk/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..fbe55e8c858c122c2293d6baad311e30c39f3520 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/CMakeLists.txt @@ -0,0 +1,84 @@ +cmake_minimum_required(VERSION 3.10) +project(fayssense_depth_examples CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +# =========================================================================== +# 方式A: read_depth —— CPU 深度算法库 (纯 OpenCV, 用系统自带的 OpenCV 4.x) +# =========================================================================== +find_package(OpenCV 4 REQUIRED COMPONENTS core imgproc calib3d imgcodecs) + +add_executable(read_depth + examples/read_depth.cpp + lib/cpu_depth.cpp + lib/colormap.cpp) +target_include_directories(read_depth PRIVATE lib) +target_link_libraries(read_depth PRIVATE ${OpenCV_LIBS}) + +# =========================================================================== +# 方式B: engine_depth —— FaysSense SDK 深度引擎 +# 依赖: sdk/lib// 下两个 .so + 随包 OpenCV 4.2 (x86_64) +# aarch64 (RK3588) 上请把 SDK_LIB_DIR / OPENCV42_DIR 改到设备上的对应路径, +# 或直接用设备上 SDK 自带的 OpenCV。 +# =========================================================================== +if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64") + set(SDK_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/lib/aarch64) + # 设备端 OpenCV 路径请按实际 rootfs 修改: + set(OPENCV42_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/opencv/x86_64) # 占位, aarch64 需自行提供 +else() + set(SDK_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/lib/x86_64) + set(OPENCV42_DIR ${CMAKE_CURRENT_SOURCE_DIR}/sdk/opencv/x86_64) +endif() + +add_executable(engine_depth + examples/engine_depth.cpp + lib/depth_engine.cpp + lib/colormap.cpp) + +target_include_directories(engine_depth PRIVATE + lib + ${CMAKE_CURRENT_SOURCE_DIR}/sdk/include + ${OPENCV42_DIR}/include/opencv4) + +target_link_directories(engine_depth PRIVATE + ${SDK_LIB_DIR} + ${OPENCV42_DIR}/lib) + +# 注意: 不能写裸库名 opencv_core 等 —— find_package(OpenCV) 生成的 imported target +# 会劫持这些名字, 导致链接到系统 OpenCV 而不是随包 4.2。必须传完整文件路径 +# (与 lib406 垫片相同的处理方式)。 +set(SHIM_DIR ${OPENCV42_DIR}/lib/shim) +set(OPENCV42_LIB_DIR ${OPENCV42_DIR}/lib) +target_link_libraries(engine_depth PRIVATE + fayssense_aikit_depth + fays_vikit + ${OPENCV42_LIB_DIR}/libopencv_core.so + ${OPENCV42_LIB_DIR}/libopencv_imgproc.so + ${OPENCV42_LIB_DIR}/libopencv_imgcodecs.so + ${OPENCV42_LIB_DIR}/libopencv_calib3d.so + ${OPENCV42_LIB_DIR}/libopencv_ximgproc.so + ${OPENCV42_LIB_DIR}/libopencv_video.so + ${OPENCV42_LIB_DIR}/libopencv_features2d.so + ${OPENCV42_LIB_DIR}/libopencv_flann.so + ${SHIM_DIR}/libtbb.so.2 + ${SHIM_DIR}/libtiff.so.5 + ${SHIM_DIR}/libwebp.so.6 + ${SHIM_DIR}/libdc1394.so.22 + ${SHIM_DIR}/libavcodec.so.58 + ${SHIM_DIR}/libavformat.so.58 + ${SHIM_DIR}/libavutil.so.56 + ${SHIM_DIR}/libswscale.so.5) + +# 运行时自动找到同包内的 .so ($ORIGIN 相对 rpath, 免设 LD_LIBRARY_PATH) +set_target_properties(engine_depth PROPERTIES + BUILD_RPATH "$ORIGIN/../sdk/lib/x86_64:$ORIGIN/../sdk/opencv/x86_64/lib:$ORIGIN/../sdk/opencv/x86_64/lib/shim" + INSTALL_RPATH "$ORIGIN/../sdk/lib/x86_64:$ORIGIN/../sdk/opencv/x86_64/lib:$ORIGIN/../sdk/opencv/x86_64/lib/shim" + BUILD_WITH_INSTALL_RPATH FALSE) + +# --disable-new-dtags: 生成可继承的 DT_RPATH 而不是 DT_RUNPATH。 +# 否则随包 opencv 的间接依赖 (libtbb.so.2 等垫片) 不会被搜索到。 +set_property(TARGET engine_depth APPEND PROPERTY LINK_FLAGS "-Wl,--disable-new-dtags") diff --git a/collector/tools/fayssense_depth_sdk/README.md b/collector/tools/fayssense_depth_sdk/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c92e2ecf809f88b75fdb302c7ca7e4415ed4f990 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/README.md @@ -0,0 +1,284 @@ +# FaysSense 双目鱼眼深度 SDK — 外部程序集成包 + +本包从 **FaysSense VI Kit**(FS-VI80-S80C 双目鱼眼相机,VI Kit v3.9.1)工程中抽取深度估计能力, +供**外部程序**读取深度图处理结果。提供两种方式: + +| 方式 | 说明 | 适用场景 | +|------|------|----------| +| **方式A:CPU 深度算法库** | 纯 OpenCV 实现的 5 种双目鱼眼深度算法(C++ 源码),不依赖 SDK 引擎 | 跨平台、可定制参数、x86 开发机直接可用 | +| **方式B:SDK 深度引擎** | 调用官方 `libfayssense_aikit_depth.so` 深度引擎 | 需要官方引擎行为(含 NPU 加速模型,RK3588) | + +两种方式都输出**统一的深度图格式**(float32 米制 raw + 伪彩 PNG + 点云 PLY),外部程序 +(C++ / Python / ROS / 点云库)读取方式一致。 + +--- + +## 1. 目录结构 + +``` +fayssense_depth_sdk/ +├── README.md 本文件 +├── build.sh 一键构建脚本 +├── CMakeLists.txt 构建配置(两个示例) +├── lib/ 方式A 的 CPU 算法库源码(纯 OpenCV,无 SDK 依赖) +│ ├── cpu_depth.h / .cpp 五种算法变体 + 标定解析 + 点云生成 +│ ├── colormap.h / .cpp 深度伪彩图(RealSense 同款色调) +│ └── depth_engine.h/.cpp SDK 引擎的 C++ 封装(方式B 使用) +├── examples/ +│ ├── read_depth.cpp 方式A 示例程序 +│ ├── engine_depth.cpp 方式B 示例程序 +│ └── read_depth.py 深度图读取脚本(numpy,可选 cv2) +├── sdk/ SDK 官方二进制与头文件 +│ ├── include/fays_atrak/ 深度引擎头文件 +│ ├── lib/x86_64/ libfays_vikit.so + libfayssense_aikit_depth.so(x86) +│ ├── lib/aarch64/ 同上(RK3588 / ARM64) +│ └── opencv/x86_64/ 随包 OpenCV 4.2 子集(方式B 在 x86 上链接用,含 lib406 垫片) +├── config/stereo_depth.yaml 方式B 引擎配置(模型/标定路径、CPU/NPU 模式等) +├── calib/calib.yaml 双目鱼眼标定(kalibr 格式:pinhole + equidistant/KB4) +├── models/rk3588/ NPU 深度模型(仅 RK3588 上使用) +└── data/sample_stacked.bmp 示例双目帧(1280×1600 上下堆叠,上半左/下半右) +``` + +--- + +## 2. 快速开始 + +### 2.1 构建 + +```bash +tar xzf fayssense_depth_sdk.tar.gz +cd fayssense_depth_sdk +./build.sh # cmake + make,生成 build/read_depth 和 build/engine_depth +``` + +要求:C++17 编译器、CMake ≥ 3.10、**系统 OpenCV 4.x**(方式A 需要; +`sudo apt install libopencv-dev` 或 `pip`/conda 版本均可,见 FAQ)。 + +### 2.2 运行方式A(CPU 算法库) + +```bash +./build.sh run-cpu +# 等价于: +./build/read_depth data/sample_stacked.bmp calib/calib.yaml 3 out/v3 +``` + +参数:`<双目堆叠图> <标定yaml> <变体 0~4> <输出前缀>` + +变体(五种双目鱼眼深度技术,可分别测试效果): + +| 变体 | 算法 | 特点 | +|------|------|------| +| 0 | V1 针孔校正 + SGBM | 经典方案(与 SDK 引擎相同的校正路径) | +| 1 | V2v 垂直极 ERP + SGBM | 球面校正,行近似极线,视场保留好 | +| 2 | V2b 基线极 ERP + SGBM | 球面校正,行严格极线 | +| 3 | V3 多针孔分带 + SGBM + ERP 融合 | 视场覆盖最大,低纹理场景效果最好(推荐首选测试) | +| 4 | V4 针孔 + StereoBM | 最快(约 15 ms/帧) | + +### 2.3 运行方式B(SDK 引擎) + +```bash +./build.sh run-engine +# 等价于: +./build/engine_depth data/sample_stacked.bmp config/stereo_depth.yaml out/engine +``` + +引擎参数通过 `config/stereo_depth.yaml` 控制(`depth_mode: 1` = CPU SGBM 后端; +`depth_mode: 0` = NPU 模型后端,仅 RK3588 可用)。yaml 中的 model_path / calib_path +为**相对 yaml 所在目录**的路径(引擎自行解析),因此整个包放到任意目录、从任意 +工作目录运行都可以。 + +### 2.4 输出文件 + +每次运行生成(前缀自定义): + +| 文件 | 内容 | +|------|------| +| `<前缀>_depth.raw` | **float32 深度图**,行优先 H×W,单位米,0 = 无效像素 | +| `<前缀>_depth.png` | 伪彩深度图(预览用) | +| `<前缀>_rect.png` | 校正后的双目图(方式A 为算法内部校正图,方式B 为引擎校正图) | +| `<前缀>_pc.ply` | 点云(ASCII PLY,方式A 为校正坐标系,方式B 为引擎点云坐标系) | + +示例帧(方式A V3)预期输出:有效像素约 57%,中位深度约 0.6 m(视场景而定)。 +**注意**:V3 输出深度图尺寸为 ERP 网格(示例帧为 672×288),其余变体与引擎输出为 +单目输入尺寸 1280×800;实际尺寸以程序打印的 `[out] ... (WxH ...)` 为准。 + +--- + +## 3. 深度图数据格式(外部程序读取接口) + +`_depth.raw` 是**无头裸数据**,格式固定: + +``` +float32 小端数组,行优先(第 y 行第 x 列 = data[y*W + x]) +单位: 米 +无效像素: 0.0f +尺寸: 与输入单目分辨率一致(默认 1280×800;restore_depth_dim=1 时引擎输出也为输入尺寸) +``` + +### 3.1 Python 读取 + +```python +import numpy as np +depth = np.fromfile("out/v3_depth.raw", dtype=np.float32).reshape(288, 672) # 尺寸见 [out] 打印 +print("valid:", (depth > 0).mean() * 100, "% median:", np.median(depth[depth > 0])) +``` + +本包自带完整脚本: + +```bash +python3 examples/read_depth.py out/v3_depth.raw 672 288 depth_view.png # V3 为 672x288 +python3 examples/read_depth.py out/engine_depth.raw 1280 800 view.png # 引擎为 1280x800 +# 或连同点云: python3 examples/read_depth.py out/v3_depth.raw 672 288 view.png out_pc.ply +``` + +### 3.2 C++ 读取 + +```cpp +#include +#include +cv::Mat loadDepthRaw(const std::string& path, int w, int h) { + cv::Mat depth(h, w, CV_32FC1); + std::ifstream f(path, std::ios::binary); + f.read((char*)depth.data, (size_t)w * h * sizeof(float)); + return depth; // 米, 0 = 无效 +} +``` + +### 3.3 直接集成算法(不落盘) + +**方式A** —— 把 `lib/cpu_depth.cpp`、`lib/colormap.cpp` 编进你的工程: + +```cpp +#include "cpu_depth.h" +cpu_depth::CpuDepthProcessor proc; +proc.loadCalib("calib/calib.yaml"); +proc.setFrameSize(1280, 800); // 单目分辨率 +cpu_depth::CpuOptions o; o.variant = cpu_depth::V3_BANDS_SGBM; +proc.setOptions(o); +cpu_depth::CpuResult res; +proc.process(stackedBgr, nullptr, nullptr, 0.0, &res); +// res.depth: CV_32FC1 深度(米); res.pcXYZ/pcRGB: 点云; res.rectStereo: 校正图 +``` + +**方式B** —— 把 `lib/depth_engine.cpp` 编进你的工程,链接 SDK 的 .so: + +```cpp +#include "depth_engine.h" +DepthEngine eng("config/stereo_depth.yaml"); +eng.feedStereoImage(stacked, tsNs); +cv::Mat depth, disp, paired; +eng.getDepthImage(depth, disp, paired); // 异步模式需先连续喂几帧预热 +``` + +--- + +## 4. 方式B:SDK 引擎说明 + +### 4.1 两种后端 + +| 后端 | yaml 配置 | 说明 | +|------|-----------|------| +| SGBM(CPU) | `depth_mode: 1` | x86 / RK3588 均可运行;SGBM 参数可运行时调节 | +| NPU 模型 | `depth_mode: 0` | 加载 `models/rk3588/stereo_s_general.rknn`,**仅 RK3588(NPU)可用**,x86 上会初始化失败 | + +运行时调参(示例中已使用与 GUI 默认一致的参数): + +```cpp +const ATRAK_DepthParamKv kvs[] = { + makeKv(ATRAK_DP_SGBM_MIN_DISP, 0), makeKv(ATRAK_DP_SGBM_NUM_DISP, 128), + makeKv(ATRAK_DP_SGBM_WINDOW_SIZE, 11), /* ... 见 examples/engine_depth.cpp */ +}; +eng.setDepthParam(ATRAK_DEPTH_BACKEND_SGBM, kvs, 11); +``` + +### 4.2 关键 yaml 字段(config/stereo_depth.yaml) + +| 字段 | 含义 | +|------|------| +| `depth_mode` | 0 = NPU 模型,1 = CPU SGBM | +| `async_mode` | 1 = 喂帧立即返回(**需预热**:连续喂 5 帧以上,getDepthImage 才有数据) | +| `restore_depth_dim` | 1 = 深度图恢复到输入分辨率(1280×800) | +| `align_cam_id` | -1 = 不对齐;0/1/2 = 对齐到左/右/RGB 相机 | +| `enable_filter` / `wls_filter` | 时序滤波 / WLS 视差滤波开关(CPU 后端) | +| `farthest_dist` / `cloest_dist` | 点云提取深度范围(米) | + +### 4.3 依赖库 + +- `libfayssense_aikit_depth.so` —— 深度引擎本体 +- `libfays_vikit.so` —— 相机/标定接口(引擎会调用其标定读取函数) +- OpenCV 4.2 子集 —— x86 上随包提供(`sdk/opencv/x86_64/`),构建时用 `$ORIGIN` 相对 + rpath 自动定位,**无需设置 LD_LIBRARY_PATH**(随包 opencv 的 RUNPATH 与 lib406 + 垫片的 SONAME 已在打包时改写为相对路径,整个包可任意搬移);aarch64 设备上使用 + 设备系统里 SDK 自带的 OpenCV(修改 CMakeLists.txt 中 `OPENCV42_DIR`)。 + +### 4.4 连续帧用法(接入相机流) + +```cpp +while (true) { + cv::Mat stacked = grabFromViKit(); // 或用 libfays_vikit 取流 + eng.feedStereoImage(stacked, tsNs); + cv::Mat depth, disp, paired; + if (eng.getDepthImage(depth, disp, paired) && !depth.empty()) { + // 处理最新深度图 + } +} +``` + +x86 上 CPU SGBM 后端单帧约 0.7 s;RK3588 上 NPU 后端可实时。 + +--- + +## 5. 性能参考(x86 开发机,1280×800 输入) + +| 方式 | 变体 | 耗时(示例帧实测) | 有效像素 | +|------|------|------|----------| +| A | V1 针孔+SGBM | 70 ms | 23% | +| A | V2v ERP+SGBM | 111 ms | 24% | +| A | V2b ERP+SGBM | 112 ms | 24% | +| A | V3 多针孔分带融合 | 361 ms(672×288 输出) | 57% | +| A | V4 针孔+BM | 46 ms | 6% | +| B | 引擎 SGBM(CPU) | ~700 ms | 25%(中位 0.4 m) | +| B | 引擎 NPU(RK3588) | 实时 | — | + +(数值随场景与机器不同而变化,仅作量级参考。) + +--- + +## 6. FAQ + +**Q: 运行时提示 `libopencv_video.so.4.2: cannot open shared object file`?** +A: 本包示例已内置 `$ORIGIN` rpath,正常从 `build/` 运行不会出现。若自行链接 +SDK 引擎,请把 `sdk/opencv/x86_64/lib` 和 `sdk/opencv/x86_64/lib/shim` 加入 +`LD_LIBRARY_PATH`。 + +**Q: `getDepthImage` 一直失败 / 深度图是空的?** +A: 引擎 `async_mode: 1`,需连续喂 ≥5 帧预热管线(示例已处理,自带 50×100ms 重试)。 + +**Q: `depth_mode: 0`(NPU)在 x86 上初始化失败?** +A: 正常现象。NPU 模型仅支持 RK3588 板端。x86 上请用 `depth_mode: 1`(CPU SGBM)。 + +**Q: 深度图尺寸是多少?** +A: 程序运行时会打印 `[out] xxx_depth.raw (WxH float32, meters, ...)`,以打印为准。 +默认 1280×800(与单目输入一致)。 + +**Q: 深度图与哪个相机对齐?** +A: 默认左相机(cam0)坐标系;`align_cam_id` 可改为右相机或 RGB 相机。 + +**Q: 系统只有 OpenCV 3.x?** +A: 方式A 需要 OpenCV 4.x(`find_package(OpenCV 4 REQUIRED)`)。可以安装 +`libopencv-dev`(Ubuntu 20.04+ 为 4.2/4.5)或 conda `opencv`;方式B 不受影响 +(用随包 OpenCV 4.2)。 + +**Q: 在 RK3588 设备上如何使用?** +A: `sdk/lib/aarch64/` 内已含 ARM64 版 .so。设备镜像里通常已带 OpenCV; +把 CMakeLists.txt 中 `OPENCV42_DIR` 指向设备上 SDK 自带的 OpenCV 路径后按同样步骤 +构建,`depth_mode: 0` 走 NPU 实时推理。 + +--- + +## 7. 版本与来源 + +- 来源工程:FaysSense VI Kit Release v3.9.1(stereo_depth_gui 深度算法库) +- 相机型号:FS-VI80-S80C 双目鱼眼(1280×800×2,基线约 80.5 mm) +- 标定模型:kalibr pinhole + equidistant(KB4) +- 示例数据:`data/sample_stacked.bmp`(一次真实采集的堆叠帧) diff --git a/collector/tools/fayssense_depth_sdk/build.sh b/collector/tools/fayssense_depth_sdk/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..880e468cf67478657c48973c6b28826c1163d12e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/build.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# 一键构建两个示例: read_depth (CPU 算法库) + engine_depth (SDK 引擎) +# 用法: ./build.sh # 编译 +# ./build.sh run-cpu # 编译并运行方式A示例 (处理 data/sample_stacked.bmp) +# ./build.sh run-engine # 编译并运行方式B示例 +set -e + +SDK_ROOT="$(cd "$(dirname "$0")" && pwd)" +BUILD_DIR="$SDK_ROOT/build" + +echo "== configure ==" +cmake -S "$SDK_ROOT" -B "$BUILD_DIR" -DCMAKE_BUILD_TYPE=Release +echo "== build ==" +cmake --build "$BUILD_DIR" -j"$(nproc)" + +echo +echo "构建完成:" +echo " $BUILD_DIR/read_depth (方式A: CPU 算法库, 依赖系统 OpenCV 4.x)" +echo " $BUILD_DIR/engine_depth (方式B: SDK 引擎, 依赖随包 .so, 无需设置 LD_LIBRARY_PATH)" +echo +echo "快速运行:" +echo " $BUILD_DIR/read_depth data/sample_stacked.bmp calib/calib.yaml 3 out/v3" +echo " $BUILD_DIR/engine_depth data/sample_stacked.bmp config/stereo_depth.yaml out/engine" +echo + +case "$1" in + run-cpu) + echo "== run read_depth (variant 3) ==" + mkdir -p "$SDK_ROOT/out" + "$BUILD_DIR/read_depth" "$SDK_ROOT/data/sample_stacked.bmp" \ + "$SDK_ROOT/calib/calib.yaml" 3 "$SDK_ROOT/out/v3" + ;; + run-engine) + echo "== run engine_depth ==" + mkdir -p "$SDK_ROOT/out" + "$BUILD_DIR/engine_depth" "$SDK_ROOT/data/sample_stacked.bmp" \ + "$SDK_ROOT/config/stereo_depth.yaml" "$SDK_ROOT/out/engine" + ;; +esac diff --git a/collector/tools/fayssense_depth_sdk/calib/calib.yaml b/collector/tools/fayssense_depth_sdk/calib/calib.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5258ca57ac7f5ae5544e610c42c5363a18da39c3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/calib/calib.yaml @@ -0,0 +1,29 @@ +cam0: + T_cam_imu: + - [-0.999881744384766, 0.004449303261936, -0.014725826680660, 0.005998577456921] + - [-0.005106299184263, -0.998979330062866, 0.044882606714964, 0.004701206926256] + - [-0.014511099085212, 0.044952493160963, 0.998883724212646, -0.016389895230532] + - [0.0, 0.0, 0.0, 1.0] + camera_model: pinhole + distortion_coeffs: [0.062210198491812, 0.012444571591914, -0.003091567661613, -0.000578491541091] + distortion_model: equidistant + intrinsics: [457.2199401855469, 457.3329772949219, 620.760986328125, 340.13323974609375] + resolution: [1280, 800] + timeshift_cam_imu: -0.001947268727235 +cam1: + T_cam_imu: + - [-0.999790549278259, 0.019221400842071, 0.007029340602458, -0.074173934757710] + - [-0.018963092938066, -0.999202847480774, 0.035132162272930, 0.004080146551132] + - [0.007699025794864, 0.034991502761841, 0.999357938766479, -0.015980923548341] + - [0.0, 0.0, 0.0, 1.0] + T_cn_cnm1: + - [0.999654293060303, -0.013781057670712, 0.022393604740500, -0.079738616943359] + - [0.013997744768858, 0.999856710433960, -0.009548537433147, -0.000860852771439] + - [-0.022258799523115, 0.009858686476946, 0.999703586101532, 0.000491287559271] + - [0.0, 0.0, 0.0, 1.0] + camera_model: pinhole + distortion_coeffs: [0.054715570062399, 0.025506600737572, -0.013235029764473, 0.001610828214325] + distortion_model: equidistant + intrinsics: [457.026245117187500, 457.239990234375000, 631.236145019531250, 403.035675048828125] + resolution: [1280, 800] + timeshift_cam_imu: -0.001850676140748 diff --git a/collector/tools/fayssense_depth_sdk/config/stereo_depth.yaml b/collector/tools/fayssense_depth_sdk/config/stereo_depth.yaml new file mode 100644 index 0000000000000000000000000000000000000000..50961714401cbf08b8e5fa446ab89cb917d16954 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/config/stereo_depth.yaml @@ -0,0 +1,68 @@ +%YAML:1.0 + +# enable depth model or not (1: enable 0:disable) +enable_module: 1 + +# depth model path (relative to THIS yaml file's directory; engine resolves it) +model_path: ../models/rk3588/stereo_s_general.rknn + +# camera calibration (kalibr format) file path (relative to THIS yaml file's directory) +calib_path: ../calib/calib.yaml + +# input stereo image size of a single camera +input_stereo_width: 1280 +input_stereo_height: 800 + +# scaling factor for stereo images (relative to inputs) +stereo_img_scaling: 1 + +# aux camera input image size (middle camera) +input_aux_cam_width: 1920 +input_aux_cam_height: 1080 + +# scaling factor for aux camera (relative to inputs) +aux_cam_scaling: 1.0 + +# num of infer threads +thread_num: 1 + +# 0: wait for result when feed stereo image; 1: feed stereo image func will return immediately +async_mode: 1 + +# 0: keep dimension in depth engine; 1: restore the depth dimension to the input image; +restore_depth_dim: 1 +# debug settings: +# 0: disable debug outputs +# 1: enable debug save images +debug_image: 0 +# Debug file save path +debug_img_save_path: . +# depth mod, 0: NPU 1: CPU +depth_mode: 1 +# cam id need to align.[-1:disable, 0: left cam, 1: right cam, 2: rgb cam] +align_cam_id: -1 +# [true: depth align to other; false: other align to depth] +align_direction: true +# enable Temporal Filtering & Spatial Filtering +enable_filter: false +# enable WLS disparity filtering (only for CPU depth_mode) +wls_filter: false + + +# pointcloud +# the farthest depth distance extracted +farthest_dist: 10 +cloest_dist: 0.3 +# voxel filter params +# whether to enable voxel filter +enable_voxel: true +# voxel size in meter +voxelSize: 0.05 #0.003 +# voxel filtering threshold +minPoints: 3 +# [0]:rectify; [1]:original cam0; [2]:vio +pointcloud_type: 0 +# extract rectify image ROI +pointcloud_ROI: 0.8 +# skip point from depth img to pointcloud +skip_point: 1 diff --git a/collector/tools/fayssense_depth_sdk/data/sample_stacked.bmp b/collector/tools/fayssense_depth_sdk/data/sample_stacked.bmp new file mode 100644 index 0000000000000000000000000000000000000000..5225a6263aaf20cc94d52b6fabb96c1e754fc66e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/data/sample_stacked.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f0cd5a0100f4f8078bc9f9920bdfd7c848d1930b8960cc2b10ad13ff22ca9b8 +size 6144054 diff --git a/collector/tools/fayssense_depth_sdk/examples/engine_depth.cpp b/collector/tools/fayssense_depth_sdk/examples/engine_depth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..90fab9d6655f4ac1662737dc3dad34e7794b927e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/examples/engine_depth.cpp @@ -0,0 +1,153 @@ +// engine_depth.cpp — 方式B示例:调用 FaysSense SDK 深度引擎 (libfayssense_aikit_depth.so) +// 处理一张双目帧,输出深度图 / 校正图 / 点云。 +// +// 用法: engine_depth +// stacked.bmp : 上下堆叠的双目帧 (上半 = 左相机, 下半 = 右相机), 灰度或 BGR +// stereo_depth.yaml : SDK 深度配置文件 (见 config/stereo_depth.yaml) +// out_prefix : 输出文件前缀 +// +// 输出: +// _depth.raw float32 深度图 (米, 0=无效), 行优先 HxW +// _depth.png 伪彩深度图 +// _rect.png 引擎校正后的双目图 +// _pc.ply 引擎点云 (ASCII PLY) +// +// 注意: +// - yaml 中的 model_path / calib_path 支持相对路径 (相对 yaml 所在目录), 引擎自行解析, +// 因此本包可从任意工作目录运行 (config/stereo_depth.yaml 已使用 ../ 相对路径)。 +// - 引擎 async_mode=1, 需要先喂若干帧"预热"管线, 之后 getDepthImage 才返回数据。 +// - 编译与链接依赖见 CMakeLists.txt / build.sh (x86_64 与 aarch64 均可)。 +#include "depth_engine.h" +#include "colormap.h" + +#include +#include +#include +#include +#include +#include + +// ---- ASCII PLY 输出 ---- +static bool writePly(const std::string& path, + const std::vector& xyz, const std::vector& rgb) +{ + FILE* f = fopen(path.c_str(), "w"); + if (!f) return false; + const size_t n = xyz.size() / 3; + fprintf(f, "ply\nformat ascii 1.0\ncomment generated by engine_depth\n"); + fprintf(f, "element vertex %zu\n", n); + fprintf(f, "property float x\nproperty float y\nproperty float z\n"); + fprintf(f, "property uchar red\nproperty uchar green\nproperty uchar blue\nend_header\n"); + for (size_t i = 0; i < n; ++i) { + fprintf(f, "%.4f %.4f %.4f %u %u %u\n", + xyz[3*i], xyz[3*i+1], xyz[3*i+2], + rgb[3*i+2], rgb[3*i+1], rgb[3*i]); // BGR -> RGB + } + fclose(f); + return true; +} + +int main(int argc, char** argv) +{ + if (argc < 4) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + cv::Mat stacked = cv::imread(argv[1], cv::IMREAD_COLOR); + if (stacked.empty()) { fprintf(stderr, "cannot read %s\n", argv[1]); return 1; } + + std::string yamlPath = argv[2]; + + DepthEngine eng(yamlPath); + if (!eng.isInitialized()) { + fprintf(stderr, "engine init failed (check model_path/calib_path and lib deps)\n"); + return 1; + } + + // SGBM 参数 (与 GUI 默认一致), 仅 CPU 后端 (depth_mode: 1) 生效 + { + const ATRAK_DepthParamKv kvs[] = { + makeKv(ATRAK_DP_SGBM_MIN_DISP, 0), + makeKv(ATRAK_DP_SGBM_NUM_DISP, 128), + makeKv(ATRAK_DP_SGBM_WINDOW_SIZE, 11), + makeKv(ATRAK_DP_SGBM_P1, 1904), + makeKv(ATRAK_DP_SGBM_P2, 11616), + makeKv(ATRAK_DP_SGBM_DISP12_MAX_DIFF, 4), + makeKv(ATRAK_DP_SGBM_PRE_FILTER_CAP, 51), + makeKv(ATRAK_DP_SGBM_UNIQUENESS_RATIO, 10), + makeKv(ATRAK_DP_SGBM_SPECKLE_WINDOW_SIZE, 150), + makeKv(ATRAK_DP_SGBM_SPECKLE_RANGE, 1), + makeKv(ATRAK_DP_SGBM_MODE, 0), // 0 = SGBM_3WAY + }; + eng.setDepthParam(ATRAK_DEPTH_BACKEND_SGBM, kvs, 11); + } + + // 预热: 引擎 async_mode=1, 需连续喂帧让管线跑起来 + for (int i = 0; i < 5; ++i) { + eng.feedStereoImage(stacked, static_cast(i) * 40000000ull); + usleep(50000); + } + printf("[engine] warmed up with 5 frames\n"); + + // 拉取深度 (带重试, 引擎前几帧可能还没有输出) + cv::Mat depth, disp, paired; + bool ok = false; + for (int i = 0; i < 50 && !ok; ++i) { + if (eng.getDepthImage(depth, disp, paired) && !depth.empty() && depth.cols > 0) + ok = true; + else + usleep(100000); + } + if (!ok) { fprintf(stderr, "getDepthImage failed\n"); return 1; } + printf("[depth] %dx%d float32 meters\n", depth.cols, depth.rows); + + const std::string pre = argv[3]; + + // 1) float32 raw —— 外部程序读取的主接口 + { + std::string raw = pre + "_depth.raw"; + FILE* f = fopen(raw.c_str(), "wb"); + fwrite(depth.data, 1, depth.total() * sizeof(float), f); + fclose(f); + printf("[out] %s (%dx%d float32, meters, 0=invalid)\n", raw.c_str(), + depth.cols, depth.rows); + } + + // 2) 伪彩 PNG + cv::imwrite(pre + "_depth.png", applyDepthColormap(depth, 0.1f, 5.0f, true)); + + // 3) 校正图 + { + cv::Mat rect; + if (eng.getRectifiedImage(rect) && !rect.empty()) { + cv::imwrite(pre + "_rect.png", rect); + printf("[out] %s_rect.png (%dx%d)\n", pre.c_str(), rect.cols, rect.rows); + } + } + + // 4) 点云 + { + std::vector xyz; + std::vector rgb; + if (eng.getPointCloud(xyz, rgb, 262144) && !xyz.empty()) { + writePly(pre + "_pc.ply", xyz, rgb); + printf("[out] %s_pc.ply (%zu points)\n", pre.c_str(), xyz.size() / 3); + } + } + + // 统计 + { + int valid = 0; + double sum = 0; + for (int y = 0; y < depth.rows; ++y) { + const float* p = depth.ptr(y); + for (int x = 0; x < depth.cols; ++x) + if (p[x] > 0) { ++valid; sum += p[x]; } + } + printf("[done] valid=%.1f%% mean=%.2fm\n", + 100.0 * valid / depth.total(), valid ? sum / valid : 0.0); + } + + return 0; +} diff --git a/collector/tools/fayssense_depth_sdk/examples/read_depth.cpp b/collector/tools/fayssense_depth_sdk/examples/read_depth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a8e9588a196e2ec64a66b1d6e9dc3f7b22ba994 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/examples/read_depth.cpp @@ -0,0 +1,115 @@ +// read_depth.cpp — 方式A示例:用 CPU 深度算法库处理一张双目帧,输出深度图。 +// +// 用法: read_depth +// stacked.bmp : 上下堆叠的双目帧 (上半 = 左相机, 下半 = 右相机) +// calib.yaml : kalibr 格式标定 (pinhole + equidistant/KB4) +// variant : 0=V1 针孔校正+SGBM 1=V2v 垂直极ERP+SGBM 2=V2b 基线极ERP+SGBM +// 3=V3 多针孔分带(覆盖最大) 4=V4 针孔+BM(最快) +// out_prefix : 输出文件前缀 +// +// 输出: +// _depth.raw float32 深度图 (米, 0=无效), 行优先 HxW +// _depth.png 伪彩深度图 +// _rect.png 校正后的双目图 (上=左, 下=右) +// _pc.ply 点云 (ASCII PLY) +// +// 依赖: OpenCV 4.x (系统自带即可), C++17 +#include "cpu_depth.h" +#include "colormap.h" + +#include +#include +#include +#include +#include +#include + +// ---- ASCII PLY 输出 (外部程序可直接用任意点云库读取) ---- +static bool writePly(const std::string& path, + const std::vector& xyz, const std::vector& rgb) +{ + FILE* f = fopen(path.c_str(), "w"); + if (!f) return false; + const size_t n = xyz.size() / 3; + fprintf(f, "ply\nformat ascii 1.0\ncomment generated by read_depth\n"); + fprintf(f, "element vertex %zu\n", n); + fprintf(f, "property float x\nproperty float y\nproperty float z\n"); + fprintf(f, "property uchar red\nproperty uchar green\nproperty uchar blue\nend_header\n"); + for (size_t i = 0; i < n; ++i) { + fprintf(f, "%.4f %.4f %.4f %u %u %u\n", + xyz[3*i], xyz[3*i+1], xyz[3*i+2], + rgb[3*i+2], rgb[3*i+1], rgb[3*i]); // BGR -> RGB + } + fclose(f); + return true; +} + +int main(int argc, char** argv) +{ + if (argc < 5) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + cv::Mat stacked = cv::imread(argv[1], cv::IMREAD_COLOR); + if (stacked.empty()) { fprintf(stderr, "cannot read %s\n", argv[1]); return 1; } + + const int variant = atoi(argv[3]); + if (variant < 0 || variant > cpu_depth::V4_PINHOLE_BM) { + fprintf(stderr, "variant must be 0..4 (V5 needs the SDK engine, see engine_depth)\n"); + return 1; + } + + cpu_depth::CpuDepthProcessor proc; + if (!proc.loadCalib(argv[2])) { fprintf(stderr, "calib load failed: %s\n", argv[2]); return 1; } + proc.setFrameSize(stacked.cols, stacked.rows / 2); + + cpu_depth::CpuOptions o; + o.variant = variant; + // 与 GUI 默认一致的 SGBM 参数, 可按需调整 + o.minDisp = 0; o.numDisp = 128; o.blockSize = 11; + o.P1 = 1904; o.P2 = 11616; o.disp12MaxDiff = 4; o.preFilterCap = 51; + o.uniquenessRatio = 10; o.speckleWindowSize = 150; o.speckleRange = 1; + o.sgbmMode = cv::StereoSGBM::MODE_SGBM_3WAY; + o.bandHalfDeg = 45.0; o.v3OutScale = 1.0; o.v3Relaxed = true; + o.erpFillGap = 8.0; o.erpDensity = 4.0; + proc.setOptions(o); + + cpu_depth::CpuResult res; + if (!proc.process(stacked, nullptr, nullptr, 0.0, &res)) { + fprintf(stderr, "process failed\n"); + return 1; + } + + const std::string pre = argv[4]; + const char* names[] = {"v1", "v2v", "v2b", "v3", "v4"}; + + // 1) float32 raw 深度 (米, 0=无效) —— 外部程序读取的主接口 + { + std::string raw = pre + "_depth.raw"; + FILE* f = fopen(raw.c_str(), "wb"); + fwrite(res.depth.data, 1, res.depth.total() * sizeof(float), f); + fclose(f); + printf("[out] %s (%dx%d float32, meters, 0=invalid)\n", raw.c_str(), + res.depth.cols, res.depth.rows); + } + + // 2) 伪彩 PNG + { + cv::Mat color = applyDepthColormap(res.depth, 0.1f, 5.0f, true); + cv::imwrite(pre + "_depth.png", color); + } + + // 3) 校正双目 PNG + if (!res.rectStereo.empty()) + cv::imwrite(pre + "_rect.png", res.rectStereo); + + // 4) 点云 PLY + if (!res.pcXYZ.empty()) + writePly(pre + "_pc.ply", res.pcXYZ, res.pcRGB); + + printf("[done] %s: %dx%d valid=%.1f%% time=%.1fms\n", names[variant], + res.depth.cols, res.depth.rows, + 100.0 * cv::countNonZero(res.depth > 0) / res.depth.total(), + res.runtimeMs); + return 0; +} diff --git a/collector/tools/fayssense_depth_sdk/examples/read_depth.py b/collector/tools/fayssense_depth_sdk/examples/read_depth.py new file mode 100644 index 0000000000000000000000000000000000000000..d95afe88247b96c2d4a13132c32d4fdb4a1beab7 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/examples/read_depth.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""read_depth.py — 读取 C++ 示例输出的 float32 深度图 (depth.raw)。 + +深度文件格式 (两种示例一致): + float32 数组, 行优先 (row-major), 尺寸 H x W + 单位: 米 (meters) + 无效像素: 0.0 + +用法: + python3 read_depth.py [out.png] [out.ply] + +示例: + python3 read_depth.py out_depth.raw 1280 800 depth_view.png + python3 read_depth.py out_depth.raw 1280 800 depth_view.png out_pc.ply + +依赖: numpy (必须), opencv-python (可选, 用于伪彩 PNG 与点云 PLY)。 +""" +import sys + +import numpy as np + + +def load_depth_raw(path, w, h): + """读取 raw 文件, 返回 (H, W) float32 深度图, 单位米, 0=无效。""" + data = np.fromfile(path, dtype=np.float32) + if data.size != w * h: + raise ValueError( + f"文件大小 {data.size} 与 WxH={w}x{h}={w*h} 不符, " + f"请确认 W/H (深度图实际尺寸以示例打印的 [out] 行为准)" + ) + return data.reshape(h, w) + + +def stats(depth): + """有效像素占比 / 中位数 / 均值。""" + valid = depth[depth > 0] + total = depth.size + print(f"shape : {depth.shape[0]}x{depth.shape[1]}") + print(f"valid : {valid.size}/{total} = {100.0 * valid.size / total:.1f}%") + if valid.size: + print(f"median : {np.median(valid):.3f} m") + print(f"mean : {valid.mean():.3f} m") + print(f"range : {valid.min():.3f} ~ {valid.max():.3f} m") + # 每个像素的坐标 (右 x, 下 y), 便于外部程序换算 + ys, xs = np.nonzero(depth > 0) + print(f"min valid : x={xs.min()} y={ys.min()}, max valid: x={xs.max()} y={ys.max()}") + + +def save_colormap(depth, out_png): + """用 cv2 生成伪彩图 (与 C++ 端 applyDepthColormap 同款色调)。""" + import cv2 + + depth = depth.astype(np.float32) + norm = cv2.normalize(depth, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8) + color = cv2.applyColorMap(norm, cv2.COLORMAP_JET) + color[depth <= 0] = (0, 0, 0) # 无效像素置黑 + cv2.imwrite(out_png, color) + print(f"[out] {out_png}") + + +def save_ply(depth, out_ply, fx=None, fy=None, cx=None, cy=None): + """把深度图转成点云 (需要相机内参; 不传则输出像素坐标占位)。""" + import cv2 # 仅用于读取不了原始图时说明 + + h, w = depth.shape + if fx is None: + # 没有内参时, 输出 x=列, y=行, z=深度(米), 仅作数据结构示例 + ys, xs = np.nonzero(depth > 0) + z = depth[ys, xs] + xyz = np.stack([xs.astype(np.float32), ys.astype(np.float32), z], axis=1) + else: + ys, xs = np.nonzero(depth > 0) + z = depth[ys, xs] + xyz = np.stack([(xs - cx) / fx * z, (ys - cy) / fy * z, z], axis=1) + + with open(out_ply, "w") as f: + f.write("ply\nformat ascii 1.0\ncomment generated by read_depth.py\n") + f.write(f"element vertex {len(xyz)}\n") + f.write("property float x\nproperty float y\nproperty float z\n") + f.write("end_header\n") + for p in xyz: + f.write(f"{p[0]:.4f} {p[1]:.4f} {p[2]:.4f}\n") + print(f"[out] {out_ply} ({len(xyz)} points)") + + +def main(): + if len(sys.argv) < 4: + print(__doc__) + return 1 + + raw_path, w, h = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]) + depth = load_depth_raw(raw_path, w, h) + stats(depth) + + if len(sys.argv) > 4: + try: + save_colormap(depth, sys.argv[4]) + except ImportError: + print("提示: 未安装 opencv-python, 跳过伪彩图 (pip install opencv-python)") + if len(sys.argv) > 5: + try: + save_ply(depth, sys.argv[5]) + except ImportError: + print("提示: 未安装 opencv-python, 跳过点云输出") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/collector/tools/fayssense_depth_sdk/lib/colormap.cpp b/collector/tools/fayssense_depth_sdk/lib/colormap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..544fae511edda2558c0580b75b3100bf6d375362 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/lib/colormap.cpp @@ -0,0 +1,194 @@ +#include "colormap.h" +#include +#include +#include +#include +#include + +// ============================================================================ +// Histogram-equalized depth visualization with JET colormap. +// +// RealSense-style: equalize the depth histogram so different depth layers +// are clearly separated, then apply JET (blue=near, red=far). +// ============================================================================ + +static void histogramEqualize(const cv::Mat& depthMeters, cv::Mat& equalized, + const float presetMin, const float presetMax) +{ + const int rows = depthMeters.rows; + const int cols = depthMeters.cols; + const int total = rows * cols; + + // Collect valid depth values within preset range + std::vector valid; + valid.reserve(total); + for (int r = 0; r < rows; ++r) { + const float* row = depthMeters.ptr(r); + for (int c = 0; c < cols; ++c) { + float d = row[c]; + if (d > 0.0f && d >= presetMin && d <= presetMax) + valid.push_back(d); + } + } + + if (valid.size() < 100) { + // Not enough data — fall back to linear normalization + equalized.create(rows, cols, CV_8UC1); + float range = presetMax - presetMin; + float inv = (range > 0) ? (255.0f / range) : 0.0f; + for (int r = 0; r < rows; ++r) { + const float* src = depthMeters.ptr(r); + uchar* dst = equalized.ptr(r); + for (int c = 0; c < cols; ++c) { + float d = src[c]; + if (d <= 0.0f) { dst[c] = 0; continue; } + float t = (d - presetMin) * inv; + dst[c] = static_cast(std::max(0.0f, std::min(255.0f, t))); + } + } + return; + } + + // Sort and build CDF lookup + std::sort(valid.begin(), valid.end()); + int n = static_cast(valid.size()); + + // Build a LUT: depth value → equalized 0-255 + // Use 4096 bins for 0-presetMax range (~1mm resolution at 4m) + const int kLutSize = 4096; + std::vector lut(kLutSize, 0); + float binWidth = presetMax / kLutSize; + + int cumCount = 0; + size_t validIdx = 0; + for (int bin = 0; bin < kLutSize; ++bin) { + float binMax = (bin + 1) * binWidth; + while (validIdx < valid.size() && valid[validIdx] <= binMax) { + cumCount++; + validIdx++; + } + // CDF → 0-255 (exclude 0 for valid depths to distinguish from invalid) + lut[bin] = static_cast(1 + (cumCount * 254) / n); + } + + // Apply LUT + equalized.create(rows, cols, CV_8UC1); + float invBin = 1.0f / binWidth; + for (int r = 0; r < rows; ++r) { + const float* src = depthMeters.ptr(r); + uchar* dst = equalized.ptr(r); + for (int c = 0; c < cols; ++c) { + float d = src[c]; + if (d <= 0.0f || d > presetMax) { dst[c] = 0; continue; } + int bin = static_cast(d * invBin); + if (bin < 0) bin = 0; + if (bin >= kLutSize) bin = kLutSize - 1; + dst[c] = lut[bin]; + } + } +} + +cv::Mat applyDepthColormap(const cv::Mat& depthMeters, float minDepth, float maxDepth, bool equalize) +{ + if (depthMeters.empty()) return cv::Mat(); + CV_Assert(depthMeters.type() == CV_32FC1); + + cv::Mat indexed; + if (equalize) { + // Histogram equalization for dynamic range + histogramEqualize(depthMeters, indexed, minDepth, maxDepth); + } else { + // Fixed linear mapping within preset range + float range = maxDepth - minDepth; + if (range <= 0.0f) return cv::Mat::zeros(depthMeters.size(), CV_8UC3); + float invRange = 255.0f / range; + int rows = depthMeters.rows, cols = depthMeters.cols; + indexed.create(rows, cols, CV_8UC1); + for (int r = 0; r < rows; ++r) { + const float* src = depthMeters.ptr(r); + uchar* dst = indexed.ptr(r); + for (int c = 0; c < cols; ++c) { + float d = src[c]; + if (d <= 0.0f) { dst[c] = 0; continue; } + float t = (d - minDepth) * invRange / 255.0f; + // t = (d-min)/(max-min), then *255 + int v = static_cast((d - minDepth) * invRange); + dst[c] = static_cast(std::max(0, std::min(255, v))); + } + } + } + + // Apply JET colormap + cv::Mat color; + cv::applyColorMap(indexed, color, cv::COLORMAP_JET); + + // Set invalid pixels (index 0 = depth <= 0) to black + const int rows = depthMeters.rows; + for (int r = 0; r < rows; ++r) { + const float* src = depthMeters.ptr(r); + cv::Vec3b* dst = color.ptr(r); + for (int c = 0; c < depthMeters.cols; ++c) { + if (src[c] <= 0.0f) dst[c] = cv::Vec3b(0, 0, 0); + } + } + + return color; +} + +// ============================================================================ +// Color bar (JET LUT for vertical bar display) +// ============================================================================ + +void buildRealSenseLUT(cv::Mat& lut) +{ + // i=0 → grayscale=0 → JET blue (near/bottom) + // i=255 → grayscale=255 → JET red (far/top) + cv::Mat src(256, 1, CV_8UC1); + for (int i = 0; i < 256; ++i) + src.at(i) = static_cast(i); + cv::applyColorMap(src, lut, cv::COLORMAP_JET); +} + +cv::Mat attachColorBar(const cv::Mat& depthColored, + float minDepth, float maxDepth, + int barWidth) +{ + if (depthColored.empty()) return depthColored; + + static cv::Mat sLUT; + if (sLUT.empty()) buildRealSenseLUT(sLUT); + + int imgH = depthColored.rows, imgW = depthColored.cols; + int totalW = imgW + barWidth + 30; + + cv::Mat combined(imgH, totalW, CV_8UC3, cv::Scalar(20, 20, 30)); + depthColored.copyTo(combined(cv::Rect(0, 0, imgW, imgH))); + + int barX = imgW + 15; + for (int y = 0; y < imgH; ++y) { + int idx = (imgH - 1 - y) * 255 / (imgH - 1); + if (idx < 0) idx = 0; + if (idx > 255) idx = 255; + cv::Vec3b c = sLUT.at(idx); + cv::line(combined, cv::Point(barX, y), cv::Point(barX + barWidth, y), + cv::Scalar(c[0], c[1], c[2])); + } + + cv::rectangle(combined, cv::Point(barX, 0), cv::Point(barX + barWidth, imgH - 1), + cv::Scalar(100, 100, 100), 1); + + int font = cv::FONT_HERSHEY_SIMPLEX; + double fs = 0.4; + cv::Scalar tc(200, 200, 200); + int tx = barX + barWidth + 5; + + std::ostringstream ss; + ss << std::fixed << std::setprecision(1) << maxDepth << "m"; + cv::putText(combined, ss.str(), cv::Point(tx, 12), font, fs, tc, 1); + ss.str(""); ss << std::fixed << std::setprecision(1) << ((minDepth+maxDepth)*0.5f) << "m"; + cv::putText(combined, ss.str(), cv::Point(tx, imgH/2+4), font, fs, tc, 1); + ss.str(""); ss << std::fixed << std::setprecision(1) << minDepth << "m"; + cv::putText(combined, ss.str(), cv::Point(tx, imgH-4), font, fs, tc, 1); + + return combined; +} diff --git a/collector/tools/fayssense_depth_sdk/lib/colormap.h b/collector/tools/fayssense_depth_sdk/lib/colormap.h new file mode 100644 index 0000000000000000000000000000000000000000..44b3920dd2f2070d68e6996a1631b28ef4d22687 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/lib/colormap.h @@ -0,0 +1,47 @@ +#pragma once + +#include + +/** + * @brief Generate a RealSense/Orbbec-style depth colormap using HSV interpolation. + * + * The RealSense viewer uses a color ramp where: + * Near depth → White (255,255,255) + * Near-mid → Red → Yellow → Green → Cyan → Blue + * Far depth → Dark (0,0,0) + * + * This matches the librealsense colorizer default scheme. + */ + +/** + * @brief Apply RealSense-style depth colormap to a float32 depth image. + * + * @param depthMeters CV_32FC1 depth image, values in meters + * @param minDepth Depths at or below this map to white (near) + * @param maxDepth Depths at or above this map to black (far) + * @return CV_8UC3 BGR color image. Invalid pixels (<= 0) are black. + */ +cv::Mat applyDepthColormap(const cv::Mat& depthMeters, + float minDepth = 0.1f, + float maxDepth = 2.0f, + bool equalize = true); + +/** + * @brief Attach a vertical color bar with depth value labels to the depth image. + * + * @param depthColored CV_8UC3 BGR colorized depth image + * @param minDepth Minimum depth value (meters) + * @param maxDepth Maximum depth value (meters) + * @param barWidth Width of the color bar in pixels (default 30) + * @return Combined image (depth + color bar on the right) + */ +cv::Mat attachColorBar(const cv::Mat& depthColored, + float minDepth, float maxDepth, + int barWidth = 30); + +/** + * @brief Build the 256-entry colormap LUT (BGR). + * + * @param lut [out] 256x1x3 uint8 array (BGR) + */ +void buildRealSenseLUT(cv::Mat& lut); diff --git a/collector/tools/fayssense_depth_sdk/lib/cpu_depth.cpp b/collector/tools/fayssense_depth_sdk/lib/cpu_depth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fb330f01a2126bb00280a682d41d4e72062cf658 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/lib/cpu_depth.cpp @@ -0,0 +1,823 @@ +/** + * CPU-only stereo fisheye depth pipeline (C++ port of benchmark/). + * + * Variants: + * V1 cv::fisheye::stereoRectify pinhole rectification + SGBM + * V2v vertical-polar ERP rectification + SGBM + * V2b baseline-polar ERP rectification + SGBM + * V3 multi-pinhole bands + relaxed SGBM + ERP fusion + * V4 pinhole rectification + StereoBM (fast) + * V5 engine-rectified input + own SGBM + */ + +#include "cpu_depth.h" + +#include +#include + +#include +#include +#include +#include + +namespace cpu_depth { + +namespace { + +const double kPi = 3.14159265358979323846; + +inline double deg2rad(double d) { return d * kPi / 180.0; } +inline double rad2deg(double r) { return r * 180.0 / kPi; } + +// --------------------------------------------------------------------------- +// kalibr yaml parsing (line based, no yaml-cpp dependency) +// --------------------------------------------------------------------------- + +std::string trimLine(const std::string& s) +{ + size_t a = s.find_first_not_of(" \t\r"); + size_t b = s.find_last_not_of(" \t\r"); + if (a == std::string::npos) return ""; + return s.substr(a, b - a + 1); +} + +/// Extract the first `[a, b, c, ...]` list of doubles from a yaml line. +std::vector parseList(const std::string& line) +{ + std::vector v; + size_t i = line.find('['); + if (i == std::string::npos) return v; + size_t j = line.find(']', i); + if (j == std::string::npos) j = line.size(); + size_t p = i + 1; + while (p < j) { + while (p < j && (line[p] == ' ' || line[p] == ',' || line[p] == '\t')) ++p; + if (p >= j) break; + char* end = nullptr; + double val = std::strtod(line.c_str() + p, &end); + if (end == line.c_str() + p) break; // not a number + v.push_back(val); + p = end - line.c_str(); + } + return v; +} + +// --------------------------------------------------------------------------- +// KB4 (equidistant) projection +// --------------------------------------------------------------------------- + +/// KB4 forward projection: camera point -> pixel. +void kb4Project(const cv::Vec3d& p, const cv::Matx33d& K, const cv::Vec4d& D, + double& u, double& v) +{ + double rho = std::sqrt(p[0] * p[0] + p[1] * p[1]); + double th = std::atan2(rho, p[2]); + double t2 = th * th, t4 = t2 * t2, t6 = t4 * t2, t8 = t4 * t4; + double td = th * (1.0 + D[0] * t2 + D[1] * t4 + D[2] * t6 + D[3] * t8); + double safe = rho > 1e-12 ? rho : 1.0; + u = K(0, 0) * td * p[0] / safe + K(0, 2); + v = K(1, 1) * td * p[1] / safe + K(1, 2); +} + +/// KB4 inverse: pixel -> unit ray direction (Newton on the odd polynomial). +cv::Vec3d kb4BackProject(double u, double v, const cv::Matx33d& K, const cv::Vec4d& D) +{ + double xn = (u - K(0, 2)) / K(0, 0); + double yn = (v - K(1, 2)) / K(1, 1); + double td = std::sqrt(xn * xn + yn * yn); + double th = td; + for (int it = 0; it < 10; ++it) { + double t2 = th * th, t4 = t2 * t2, t6 = t4 * t2, t8 = t4 * t4; + double f = th * (1.0 + D[0] * t2 + D[1] * t4 + D[2] * t6 + D[3] * t8) - td; + double fp = 1.0 + 3 * D[0] * t2 + 5 * D[1] * t4 + 7 * D[2] * t6 + 9 * D[3] * t8; + th -= f / std::max(std::abs(fp), 1e-9); + } + th = std::min(std::max(th, 0.0), kPi); + double sinT = std::sin(th), cosT = std::cos(th); + double rho = td > 1e-12 ? sinT / td : 0.0; + return cv::Vec3d(rho * xn, rho * yn, td > 1e-12 ? cosT : 1.0); +} + +// --------------------------------------------------------------------------- +// Map building +// --------------------------------------------------------------------------- + +/// Build a u/v pixel grid (CV_32FC1 each). +void buildGrid(int W, int H, cv::Mat& u, cv::Mat& v) +{ + u.create(H, W, CV_32FC1); + v.create(H, W, CV_32FC1); + for (int y = 0; y < H; ++y) { + float* up = u.ptr(y); + float* vp = v.ptr(y); + for (int x = 0; x < W; ++x) { + up[x] = static_cast(x); + vp[x] = static_cast(y); + } + } +} + +/// Back-project rectified rays into both fisheye cams -> remap map pairs + masks. +/// Rays outside the source image or beyond the lens FOV become -1 in the maps. +void raysToRemapPair(const cv::Mat& rays /*Nx3 CV_32F, rectified frame*/, + const StereoCalib& calib, int outW, int outH, + cv::Mat& mapx0, cv::Mat& mapy0, cv::Mat& mapx1, cv::Mat& mapy1, + cv::Mat& valid0, cv::Mat& valid1) +{ + const int N = rays.rows; + mapx0.create(outH, outW, CV_32FC1); + mapy0.create(outH, outW, CV_32FC1); + mapx1.create(outH, outW, CV_32FC1); + mapy1.create(outH, outW, CV_32FC1); + valid0.create(outH, outW, CV_8UC1); + valid1.create(outH, outW, CV_8UC1); + + for (int i = 0; i < N; ++i) { + const float* r = rays.ptr(i); + cv::Vec3d v(r[0], r[1], r[2]); + cv::Vec3d d0 = calib.R_rect.t() * v; // rectified -> cam0 + cv::Vec3d d1 = calib.R1_rect.t() * v; // rectified -> cam1 + double u0, v0, u1, v1; + kb4Project(d0, calib.K[0], calib.D[0], u0, v0); + kb4Project(d1, calib.K[1], calib.D[1], u1, v1); + double th0 = std::acos(std::min(std::max(d0[2], -1.0), 1.0)); + double th1 = std::acos(std::min(std::max(d1[2], -1.0), 1.0)); + bool ok0 = u0 >= 0 && u0 < calib.frameW && v0 >= 0 && v0 < calib.frameH + && th0 <= calib.lensMaxTheta; + bool ok1 = u1 >= 0 && u1 < calib.frameW && v1 >= 0 && v1 < calib.frameH + && th1 <= calib.lensMaxTheta; + mapx0.at(i) = ok0 ? static_cast(u0) : -1.0f; + mapy0.at(i) = ok0 ? static_cast(v0) : -1.0f; + mapx1.at(i) = ok1 ? static_cast(u1) : -1.0f; + mapy1.at(i) = ok1 ? static_cast(v1) : -1.0f; + valid0.at(i) = ok0 ? 1 : 0; + valid1.at(i) = ok1 ? 1 : 0; + } +} + +void remapPair(const cv::Mat& left, const cv::Mat& right, + const cv::Mat& mapx0, const cv::Mat& mapy0, + const cv::Mat& mapx1, const cv::Mat& mapy1, + cv::Mat& rL, cv::Mat& rR) +{ + cv::remap(left, rL, mapx0, mapy0, cv::INTER_LINEAR, + cv::BORDER_CONSTANT, cv::Scalar(0)); + cv::remap(right, rR, mapx1, mapy1, cv::INTER_LINEAR, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +// --------------------------------------------------------------------------- +// Matching +// --------------------------------------------------------------------------- + +cv::Mat toGray(const cv::Mat& m) +{ + if (m.channels() == 1) return m; + cv::Mat g; + cv::cvtColor(m, g, cv::COLOR_BGR2GRAY); + return g; +} + +/// SGBM -> float32 disparity in px. `relaxed` uses the benchmark's band preset +/// (small block, no uniqueness/speckle filter, P1/P2 from the block size). +/// Note: the GUI's WLS checkbox is ignored here — ximgproc may not be linked. +cv::Mat sgbmMatch(const cv::Mat& L, const cv::Mat& R, const CpuOptions& o, bool relaxed) +{ + cv::Mat gL = toGray(L), gR = toGray(R); + int bs = relaxed ? 5 : o.blockSize; + if (bs % 2 == 0) ++bs; + int numDisp = std::max(16, (o.numDisp / 16) * 16); + int P1 = o.P1, P2 = o.P2; + if (relaxed) { + P1 = 8 * 3 * bs * bs; + P2 = 32 * 3 * bs * bs; + } + int uniq = relaxed ? 0 : o.uniquenessRatio; + int sw = relaxed ? 0 : o.speckleWindowSize; + int sr = relaxed ? 0 : o.speckleRange; + cv::Ptr sgbm = cv::StereoSGBM::create( + o.minDisp, numDisp, bs, P1, P2, o.disp12MaxDiff, o.preFilterCap, + uniq, sw, sr, o.sgbmMode); + cv::Mat d16, d; + sgbm->compute(gL, gR, d16); + d16.convertTo(d, CV_32FC1, 1.0 / 16.0); + return d; +} + +cv::Mat bmMatch(const cv::Mat& L, const cv::Mat& R, const CpuOptions& o) +{ + cv::Mat gL = toGray(L), gR = toGray(R); + int numDisp = std::max(16, (o.numDisp / 16) * 16); + cv::Ptr bm = cv::StereoBM::create(numDisp, o.bmBlockSize); + bm->setPreFilterType(cv::StereoBM::PREFILTER_XSOBEL); + bm->setPreFilterSize(9); + bm->setPreFilterCap(31); + bm->setTextureThreshold(20); + bm->setUniquenessRatio(10); + cv::Mat d16, d; + bm->compute(gL, gR, d16); + d16.convertTo(d, CV_32FC1, 1.0 / 16.0); + return d; +} + +// --------------------------------------------------------------------------- +// Depth conversion +// --------------------------------------------------------------------------- + +/// V1/V4/V5: z = fx*B/d on a rectified pinhole pair. 0 = invalid. +void disparityToDepth(const cv::Mat& disp, double fx, double baseline, double maxZ, + cv::Mat& depth) +{ + depth.create(disp.size(), CV_32FC1); + const double scale = fx * baseline; + for (int y = 0; y < disp.rows; ++y) { + const float* dp = disp.ptr(y); + float* zp = depth.ptr(y); + for (int x = 0; x < disp.cols; ++x) { + float d = dp[x]; + float z = d > 0.5f ? static_cast(scale / d) : 0.0f; + zp[x] = z > maxZ ? 0.0f : z; + } + } +} + +/// V2/V3: per-pixel ray triangulation in the rectified frame. +/// s = ((t x u_r) . (u_l x u_r)) / |u_l x u_r|^2 ; depth along the left ray. +void triangulate(const cv::Mat& raysRect /*Nx3 CV_32F*/, + const cv::Mat& disp /*HxW CV_32F px*/, + const cv::Vec3d& tRect, double maxZ, double minD, + cv::Mat& depth, cv::Mat& pts /*Nx3 CV_32F, zeros for invalid*/) +{ + const int H = disp.rows, W = disp.cols; + depth = cv::Mat::zeros(H, W, CV_32FC1); + pts = cv::Mat::zeros(H * W, 3, CV_32FC1); + for (int y = 0; y < H; ++y) { + const float* dp = disp.ptr(y); + float* zp = depth.ptr(y); + for (int x = 0; x < W; ++x) { + float d = dp[x]; + int xr = static_cast(std::lround(x - d)); + bool ok = d > minD && xr >= 0 && xr < W; + if (!ok) { zp[x] = 0.0f; continue; } + const float* ul = raysRect.ptr(y * W + x); + const float* ur = raysRect.ptr(y * W + xr); + cv::Vec3d uL(ul[0], ul[1], ul[2]), uR(ur[0], ur[1], ur[2]); + cv::Vec3d cr = uL.cross(uR); + double denom = cr.dot(cr); + cv::Vec3d tcr = tRect.cross(uR); + double s = tcr.dot(cr) / std::max(denom, 1e-9); + if (s > 0 && s < maxZ) { + zp[x] = static_cast(s); + float* pp = pts.ptr(y * W + x); + pp[0] = static_cast(s * uL[0]); + pp[1] = static_cast(s * uL[1]); + pp[2] = static_cast(s * uL[2]); + } else { + zp[x] = 0.0f; // non-positive, behind-baseline or beyond maxZ + } + } + } +} + +// --------------------------------------------------------------------------- +// V3 fusion +// --------------------------------------------------------------------------- + +struct BandRes { + cv::Mat depth; // band-size CV_32FC1 (m, 0 = invalid) + cv::Mat pts; // band N x 3 CV_32FC1, rectified frame + cv::Mat valid; // band-size CV_8UC1 (both cameras' rays inside the lens) + cv::Mat rectL; // band rectified BGR + cv::Mat rectR; +}; + +/// Fuse band results into one ERP depth map (z-buffer, nearest wins), then +/// gap-fill holes up to fillGap px with the nearest valid pixel (depth, +/// band id and source pixel all propagate), then medianBlur(3). +void fuseToErp(const std::vector& bands, int erpW, int erpH, + double lonDeg, double latDeg, double fillGap, + cv::Mat& fused, cv::Mat& bandId, cv::Mat& srcPix) +{ + fused = cv::Mat::zeros(erpH, erpW, CV_32FC1); + bandId = cv::Mat(erpH, erpW, CV_32S, cv::Scalar(-1)); + srcPix = cv::Mat(erpH, erpW, CV_32S, cv::Scalar(-1)); + const double lonMax = deg2rad(lonDeg / 2.0); + const double latMax = deg2rad(latDeg / 2.0); + + for (size_t b = 0; b < bands.size(); ++b) { + const cv::Mat& d = bands[b].depth; + const cv::Mat& p = bands[b].pts; + const cv::Mat& v = bands[b].valid; + const int BW = d.cols, BH = d.rows; + for (int y = 0; y < BH; ++y) { + const float* dp = d.ptr(y); + const uchar* vp = v.ptr(y); + for (int x = 0; x < BW; ++x) { + if (dp[x] <= 0 || !vp[x]) continue; + const float* pp = p.ptr(y * BW + x); + if (pp[0] == 0 && pp[1] == 0 && pp[2] == 0) continue; + double lon = std::atan2(pp[0], pp[2]); + double lat = std::atan2(pp[1], std::hypot(pp[0], pp[2])); + int u = static_cast(std::lround((lon / lonMax + 1.0) / 2.0 * (erpW - 1))); + int vv = static_cast(std::lround((1.0 - lat / latMax) / 2.0 * (erpH - 1))); + if (u < 0 || u >= erpW || vv < 0 || vv >= erpH) continue; + float cur = fused.at(vv, u); + if (cur == 0 || dp[x] < cur) { + fused.at(vv, u) = dp[x]; + bandId.at(vv, u) = static_cast(b); + srcPix.at(vv, u) = y * BW + x; + } + } + } + } + + // Gap fill: distanceTransform treats src==0 as the source, so with the + // hole mask as input every hole gets the distance to (and 1-based pixel + // index of) its nearest valid pixel. + cv::Mat holes = (fused == 0); + int holeCount = cv::countNonZero(holes); + if (holeCount > 0 && holeCount < erpW * erpH) { + cv::Mat dist, labels; + cv::distanceTransform(holes, dist, labels, cv::DIST_L2, 5, + cv::DIST_LABEL_PIXEL); + for (int y = 0; y < erpH; ++y) { + const float* dp = dist.ptr(y); + const int* lp = labels.ptr(y); + float* fp = fused.ptr(y); + int* bp = bandId.ptr(y); + int* sp = srcPix.ptr(y); + for (int x = 0; x < erpW; ++x) { + if (fp[x] == 0 && dp[x] > 0 && dp[x] <= fillGap && lp[x] > 0) { + int src = lp[x] - 1; // nearest valid pixel index + int sy = src / erpW, sx = src % erpW; + fp[x] = fused.at(sy, sx); + bp[x] = bandId.at(sy, sx); + sp[x] = srcPix.at(sy, sx); + } + } + } + } + cv::medianBlur(fused, fused, 3); +} + +// --------------------------------------------------------------------------- +// Point clouds +// --------------------------------------------------------------------------- + +/// Push one point into the output buffers (caps at maxPoints). +struct PcOut { + std::vector& xyz; + std::vector& rgb; + int maxPoints; + PcOut(std::vector& x, std::vector& c, int max) + : xyz(x), rgb(c), maxPoints(max) {} + void push(double x, double y, double z, const cv::Vec3b& bgr) + { + if (static_cast(xyz.size() / 3) >= maxPoints) return; + xyz.push_back(static_cast(x)); + xyz.push_back(static_cast(y)); + xyz.push_back(static_cast(z)); + rgb.push_back(bgr[2]); // BGR -> RGB + rgb.push_back(bgr[1]); + rgb.push_back(bgr[0]); + } +}; + +int pcStepFor(int N, int maxPoints) +{ + return std::max(1, static_cast(std::ceil(std::sqrt(static_cast(N) / maxPoints)))); +} + +/// V1/V4/V5: rectified-frame points from depth + pinhole intrinsics. +void pcFromPinhole(const cv::Mat& depth, double fx, double fy, double cx, double cy, + const cv::Mat& rectColor, PcOut& out) +{ + const int H = depth.rows, W = depth.cols; + const int step = pcStepFor(H * W, out.maxPoints); + for (int y = 0; y < H; y += step) { + const float* dp = depth.ptr(y); + const cv::Vec3b* cp = rectColor.ptr(y); + for (int x = 0; x < W; x += step) { + float z = dp[x]; + if (z <= 0) continue; + out.push((x - cx) * z / fx, (y - cy) * z / fy, z, cp[x]); + } + } +} + +/// V2: points from the triangulated (N,3) rectified-frame array. +void pcFromTriangulated(const cv::Mat& depth, const cv::Mat& pts, + const cv::Mat& rectColor, PcOut& out) +{ + const int H = depth.rows, W = depth.cols; + const int step = pcStepFor(H * W, out.maxPoints); + for (int y = 0; y < H; y += step) { + const float* dp = depth.ptr(y); + const cv::Vec3b* cp = rectColor.ptr(y); + for (int x = 0; x < W; x += step) { + if (dp[x] <= 0) continue; + const float* pp = pts.ptr(y * W + x); + out.push(pp[0], pp[1], pp[2], cp[x]); + } + } +} + +/// V3: points from the fused ERP (ray direction from lon/lat * depth), colored +/// from the winning band's rectified image. +void pcFromErp(const cv::Mat& fused, const cv::Mat& bandId, const cv::Mat& srcPix, + const std::vector& bands, double lonDeg, double latDeg, PcOut& out) +{ + const int H = fused.rows, W = fused.cols; + const int step = pcStepFor(H * W, out.maxPoints); + const double lonMax = deg2rad(lonDeg / 2.0); + const double latMax = deg2rad(latDeg / 2.0); + for (int y = 0; y < H; y += step) { + const float* dp = fused.ptr(y); + const int* bp = bandId.ptr(y); + const int* sp = srcPix.ptr(y); + for (int x = 0; x < W; x += step) { + float d = dp[x]; + if (d <= 0 || bp[x] < 0 || sp[x] < 0) continue; + double lon = (static_cast(x) / (W - 1) * 2.0 - 1.0) * lonMax; + double lat = (1.0 - static_cast(y) / (H - 1) * 2.0) * latMax; + double cl = std::cos(lat); + cv::Vec3b bgr(0, 0, 0); + const cv::Mat& r = bands[bp[x]].rectL; + int by = sp[x] / r.cols, bx = sp[x] % r.cols; + if (by < r.rows && bx < r.cols) bgr = r.at(by, bx); + out.push(cl * std::sin(lon) * d, std::sin(lat) * d, cl * std::cos(lon) * d, bgr); + } + } +} + +} // namespace + +// --------------------------------------------------------------------------- +// Calibration loading +// --------------------------------------------------------------------------- + +bool loadKalibr(const std::string& path, StereoCalib& out) +{ + std::ifstream f(path); + if (!f.is_open()) return false; + + StereoCalib c; + int section = -1; // 0 = cam0, 1 = cam1 + bool inT = false; + int tRow = 0; + cv::Matx33d R = cv::Matx33d::eye(); + cv::Vec3d t; + bool haveT = false, haveRes = false; + + std::string line; + while (std::getline(f, line)) { + std::string s = trimLine(line); + if (s == "cam0:") { section = 0; inT = false; continue; } + if (s == "cam1:") { section = 1; inT = false; continue; } + if (section < 0) continue; + + if (s.rfind("intrinsics:", 0) == 0) { + std::vector v = parseList(s); + if (v.size() >= 4) { + c.K[section] = cv::Matx33d(v[0], 0, v[2], 0, v[1], v[3], 0, 0, 1); + } + } else if (s.rfind("distortion_coeffs:", 0) == 0) { + std::vector v = parseList(s); + for (size_t i = 0; i < v.size() && i < 4; ++i) c.D[section][i] = v[i]; + } else if (s.rfind("resolution:", 0) == 0) { + std::vector v = parseList(s); + if (v.size() >= 2) { + c.calibW = static_cast(v[0]); + c.calibH = static_cast(v[1]); + haveRes = true; + } + } else if (s.rfind("T_cn_cnm1:", 0) == 0) { + inT = true; tRow = 0; + } else if (inT && s.rfind("- [", 0) == 0) { + std::vector v = parseList(s); + if (v.size() >= 4 && tRow < 3) { + for (int col = 0; col < 3; ++col) R(tRow, col) = v[col]; + t[tRow] = v[3]; + ++tRow; + if (tRow == 3) { inT = false; haveT = true; } + } + } + } + if (!haveT || !haveRes) return false; + + c.R = R; + c.t = t; + c.frameW = c.calibW; + c.frameH = c.calibH; + + // Rectified frame: x along the baseline, z as close as possible to cam0's z + cv::Vec3d t_w1 = -(R.t() * t); // cam1 origin in cam0 frame + c.baseline = cv::norm(t_w1); + if (c.baseline < 1e-9) return false; + cv::Vec3d xr = t_w1 / c.baseline; + cv::Vec3d z0(0, 0, 1); + cv::Vec3d zr = z0 - xr.dot(z0) * xr; + zr /= cv::norm(zr); + cv::Vec3d yr = zr.cross(xr); + c.R_rect = cv::Matx33d(xr[0], xr[1], xr[2], + yr[0], yr[1], yr[2], + zr[0], zr[1], zr[2]); + c.R1_rect = c.R_rect * R.t(); // rectified <- cam1 + c.t_rect = c.R_rect * t_w1; // cam1 origin in rectified frame + + // Max off-axis angle covered by the sensor (image corners of cam0 + 2 deg) + double maxTh = 0.0; + const int corners[4][2] = {{0, 0}, {c.calibW - 1, 0}, + {0, c.calibH - 1}, {c.calibW - 1, c.calibH - 1}}; + for (const auto& cc : corners) { + cv::Vec3d ray = kb4BackProject(cc[0], cc[1], c.K[0], c.D[0]); + maxTh = std::max(maxTh, std::acos(std::min(std::max(ray[2], -1.0), 1.0))); + } + c.lensMaxTheta = maxTh + deg2rad(2.0); + + out = c; + return true; +} + +// --------------------------------------------------------------------------- +// Processor +// --------------------------------------------------------------------------- + +bool CpuDepthProcessor::loadCalib(const std::string& calibPath) +{ + if (!cpu_depth::loadKalibr(calibPath, mCalib)) { + mReady = false; + return false; + } + mKCalib[0] = mCalib.K[0]; + mKCalib[1] = mCalib.K[1]; + mMaps.clear(); + mReady = true; + return true; +} + +void CpuDepthProcessor::setFrameSize(int w, int h) +{ + if (!mReady || w <= 0 || h <= 0) return; + if (w == mCalib.frameW && h == mCalib.frameH) return; + const double sx = static_cast(w) / mCalib.calibW; + const double sy = static_cast(h) / mCalib.calibH; + for (int c = 0; c < 2; ++c) { + mCalib.K[c] = cv::Matx33d(mKCalib[c](0, 0) * sx, 0, mKCalib[c](0, 2) * sx, + 0, mKCalib[c](1, 1) * sy, mKCalib[c](1, 2) * sy, + 0, 0, 1); + } + mCalib.frameW = w; + mCalib.frameH = h; + mMaps.clear(); +} + +bool CpuDepthProcessor::buildMaps(const StereoCalib& c) +{ + mMaps.clear(); + const int W = c.frameW, H = c.frameH; + + if (mOpts.variant == V1_PINHOLE_SGBM || mOpts.variant == V4_PINHOLE_BM) { + // V1/V4: fisheye -> pinhole rectification (same path as the SDK engine) + cv::Mat K0(c.K[0]), D0(1, 4, CV_64F), K1(c.K[1]), D1(1, 4, CV_64F); + for (int i = 0; i < 4; ++i) { + D0.at(i) = c.D[0][i]; + D1.at(i) = c.D[1][i]; + } + cv::Mat R1, R2, P1, P2, Q; + cv::fisheye::stereoRectify( + K0, D0, K1, D1, cv::Size(c.calibW, c.calibH), c.R, c.t, + R1, R2, P1, P2, Q, cv::CALIB_ZERO_DISPARITY, + cv::Size(W, H), mOpts.balance, mOpts.fovScale); + + CpuMaps m; + m.kind = 0; + cv::fisheye::initUndistortRectifyMap(K0, D0, R1, P1, cv::Size(W, H), + CV_32FC1, m.mapx0, m.mapy0); + cv::fisheye::initUndistortRectifyMap(K1, D1, R2, P2, cv::Size(W, H), + CV_32FC1, m.mapx1, m.mapy1); + m.valid0 = (m.mapx0 >= 0); + m.valid1 = (m.mapx1 >= 0); + m.fx = P2.at(0, 0); + m.fy = P2.at(1, 1); + m.cx = P2.at(0, 2); + m.cy = P2.at(1, 2); + m.baseline = -P2.at(0, 3) / m.fx; + mMaps.push_back(m); + return true; + } + + if (mOpts.variant == V2V_ERP_SGBM || mOpts.variant == V2B_ERP_SGBM) { + // V2: spherical rectification on a shared ray grid + cv::Mat u, v; + buildGrid(W, H, u, v); + cv::Mat rays(H * W, 3, CV_32F); + const double lonMax = deg2rad(mOpts.lonDeg); + const double latMax = deg2rad(mOpts.latDeg); + for (int y = 0; y < H; ++y) { + const float* up = u.ptr(y); + const float* vp = v.ptr(y); + for (int x = 0; x < W; ++x) { + float* r = rays.ptr(y * W + x); + if (mOpts.variant == V2V_ERP_SGBM) { + double lon = (up[x] - (W - 1) / 2.0) / std::max(W - 1, 1) * lonMax; + double lat = ((H - 1) / 2.0 - vp[x]) / std::max(H - 1, 1) * latMax; + double cl = std::cos(lat); + r[0] = static_cast(cl * std::sin(lon)); + r[1] = static_cast(std::sin(lat)); + r[2] = static_cast(cl * std::cos(lon)); + } else { + // chi decreases with u so front points get positive disparity + double chi = kPi / 2.0 - (up[x] - (W - 1) / 2.0) / std::max(W - 1, 1) * lonMax; + double psi = (vp[x] - (H - 1) / 2.0) / std::max(H - 1, 1) * latMax + kPi / 2.0; + r[0] = static_cast(std::cos(chi)); + r[1] = static_cast(std::sin(chi) * std::cos(psi)); + r[2] = static_cast(std::sin(chi) * std::sin(psi)); + } + } + } + CpuMaps m; + m.kind = 1; + raysToRemapPair(rays, c, W, H, m.mapx0, m.mapy0, m.mapx1, m.mapy1, + m.valid0, m.valid1); + m.raysRect = rays; + m.tRect = c.t_rect; + mMaps.push_back(m); + return true; + } + + if (mOpts.variant == V3_BANDS_SGBM) { + // V3: one pinhole band per yaw angle; all bands share the ray grid so + // rows are exactly epipolar + const int BW = std::max(32, (static_cast(W * mOpts.v3OutScale) / 16) * 16); + const int BH = std::max(32, (static_cast(H * mOpts.v3OutScale) / 16) * 16); + const double f_v = (BW / 2.0) / std::tan(deg2rad(mOpts.bandHalfDeg)); + const double cy = (BH - 1) / 2.0; + cv::Mat u, v; + buildGrid(BW, BH, u, v); + for (int b = 0; b < mOpts.nYaws; ++b) { + const double yaw = deg2rad(mOpts.yaws[b]); + const double cx = (BW - 1) / 2.0 - f_v * std::tan(yaw); + cv::Mat rays(BH * BW, 3, CV_32F); + for (int y = 0; y < BH; ++y) { + const float* up = u.ptr(y); + const float* vp = v.ptr(y); + for (int x = 0; x < BW; ++x) { + double dx = (up[x] - cx) / f_v; + double dy = (vp[x] - cy) / f_v; + double n = std::sqrt(dx * dx + dy * dy + 1.0); + float* r = rays.ptr(y * BW + x); + r[0] = static_cast(dx / n); + r[1] = static_cast(dy / n); + r[2] = static_cast(1.0 / n); + } + } + CpuMaps m; + m.kind = 2; + raysToRemapPair(rays, c, BW, BH, m.mapx0, m.mapy0, m.mapx1, m.mapy1, + m.valid0, m.valid1); + m.raysRect = rays; + m.tRect = c.t_rect; + m.yaw = mOpts.yaws[b]; + m.f_v = f_v; + mMaps.push_back(m); + } + return true; + } + + return false; // V5 has no CPU maps +} + +bool CpuDepthProcessor::matchV3(const cv::Mat& left, const cv::Mat& right, CpuResult* out) +{ + std::vector bands; + for (const CpuMaps& m : mMaps) { + BandRes b; + remapPair(left, right, m.mapx0, m.mapy0, m.mapx1, m.mapy1, b.rectL, b.rectR); + cv::Mat d = sgbmMatch(b.rectL, b.rectR, mOpts, mOpts.v3Relaxed); + triangulate(m.raysRect, d, m.tRect, mOpts.maxZ, 0.5, b.depth, b.pts); + b.valid = m.valid0 & m.valid1; + bands.push_back(b); + } + + // ERP range matched to the band union; grid at ~4 px/deg (native density) + const BandRes& b0 = bands.front(); + const CpuMaps& m0 = mMaps.front(); + const int BW = b0.depth.cols, BH = b0.depth.rows; + const double vHalf = rad2deg(std::atan((BH / 2.0) / m0.f_v)); + const double hHalf = mOpts.bandHalfDeg; + double maxAbsYaw = 0.0; + for (int i = 0; i < mOpts.nYaws; ++i) maxAbsYaw = std::max(maxAbsYaw, std::abs(mOpts.yaws[i])); + const double latDeg = 2.0 * (vHalf + 3.0); + const double lonDeg = 2.0 * (maxAbsYaw + hHalf + 3.0); + const int erpW = std::max(16, static_cast(std::ceil(mOpts.erpDensity * lonDeg / 16.0)) * 16); + const int erpH = std::max(16, static_cast(std::ceil(mOpts.erpDensity * latDeg / 16.0)) * 16); + + cv::Mat fused, bandId, srcPix; + fuseToErp(bands, erpW, erpH, lonDeg, latDeg, mOpts.erpFillGap, fused, bandId, srcPix); + + // Rectified display: the three band windows side by side + cv::Mat stackedBands; + for (const BandRes& b : bands) { + cv::Mat one; + cv::vconcat(b.rectL, b.rectR, one); + if (stackedBands.empty()) stackedBands = one; + else cv::hconcat(stackedBands, one, stackedBands); + } + + if (out) { + out->depth = fused; + out->rectStereo = stackedBands; + out->disparity = cv::Mat(); + out->pcXYZ.clear(); + out->pcRGB.clear(); + PcOut pc(out->pcXYZ, out->pcRGB, mOpts.maxPoints); + pcFromErp(fused, bandId, srcPix, bands, lonDeg, latDeg, pc); + } + return true; +} + +bool CpuDepthProcessor::process(const cv::Mat& stacked, const cv::Mat* engineRect, + const double* engineP0, double engineBaseline, + CpuResult* out) +{ + if (!mReady || stacked.rows < 2) return false; + const int64 t0 = cv::getTickCount(); + + const int H = stacked.rows / 2, W = stacked.cols; + setFrameSize(W, H); + + const std::string key = [&]() { + std::ostringstream ss; + ss << mOpts.variant << '|' << W << 'x' << H << '|' + << mOpts.balance << '|' << mOpts.fovScale << '|' + << mOpts.lonDeg << '|' << mOpts.latDeg << '|' + << mOpts.bandHalfDeg << '|' << mOpts.v3OutScale << '|' << mOpts.nYaws; + for (int i = 0; i < mOpts.nYaws; ++i) ss << '|' << mOpts.yaws[i]; + return ss.str(); + }(); + if (mMapsKey != key) { + mMapsKey = key; + if (!buildMaps(mCalib)) return false; + } + + const cv::Mat left = stacked.rowRange(0, H); + const cv::Mat right = stacked.rowRange(H, 2 * H); + + CpuResult res; + if (mOpts.variant == V5_ENGINE_SGBM) { + if (!engineRect || engineRect->rows < 2) return false; + const int EH = engineRect->rows / 2; + cv::Mat eL = engineRect->rowRange(0, EH); + cv::Mat eR = engineRect->rowRange(EH, 2 * EH); + res.disparity = sgbmMatch(eL, eR, mOpts, false); + const double fx = engineP0 ? engineP0[0] : 1.0; + disparityToDepth(res.disparity, fx, engineBaseline, mOpts.maxZ, res.depth); + res.rectStereo = engineRect->clone(); + res.pcXYZ.clear(); + res.pcRGB.clear(); + PcOut pc(res.pcXYZ, res.pcRGB, mOpts.maxPoints); + const double fy = engineP0 ? engineP0[1] : fx; + const double cx = engineP0 ? engineP0[2] : 0; + const double cy = engineP0 ? engineP0[3] : 0; + cv::Mat eL3; + if (eL.channels() == 1) cv::cvtColor(eL, eL3, cv::COLOR_GRAY2BGR); + else eL3 = eL; + pcFromPinhole(res.depth, fx, fy, cx, cy, eL3, pc); + } else if (mOpts.variant == V3_BANDS_SGBM) { + if (!matchV3(left, right, &res)) return false; + } else { + const CpuMaps& m = mMaps[0]; + cv::Mat rL, rR; + remapPair(left, right, m.mapx0, m.mapy0, m.mapx1, m.mapy1, rL, rR); + cv::Mat rL3, rR3; + if (rL.channels() == 1) cv::cvtColor(rL, rL3, cv::COLOR_GRAY2BGR); else rL3 = rL; + if (rR.channels() == 1) cv::cvtColor(rR, rR3, cv::COLOR_GRAY2BGR); else rR3 = rR; + cv::vconcat(rL3, rR3, res.rectStereo); + + if (mOpts.variant == V4_PINHOLE_BM) { + res.disparity = bmMatch(rL, rR, mOpts); + } else { + res.disparity = sgbmMatch(rL, rR, mOpts, false); + } + res.pcXYZ.clear(); + res.pcRGB.clear(); + PcOut pc(res.pcXYZ, res.pcRGB, mOpts.maxPoints); + if (m.kind == 0) { + disparityToDepth(res.disparity, m.fx, m.baseline, mOpts.maxZ, res.depth); + pcFromPinhole(res.depth, m.fx, m.fy, m.cx, m.cy, rL3, pc); + } else { + triangulate(m.raysRect, res.disparity, m.tRect, mOpts.maxZ, 0.5, + res.depth, res.pts); + pcFromTriangulated(res.depth, res.pts, rL3, pc); + } + } + + mLastRuntimeMs = static_cast(cv::getTickCount() - t0) * 1000.0 + / cv::getTickFrequency(); + res.runtimeMs = mLastRuntimeMs; + if (out) *out = std::move(res); + return true; +} + +} // namespace cpu_depth diff --git a/collector/tools/fayssense_depth_sdk/lib/cpu_depth.h b/collector/tools/fayssense_depth_sdk/lib/cpu_depth.h new file mode 100644 index 0000000000000000000000000000000000000000..0e5fec424d27a4d814d4cd1e47aa17bd67175524 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/lib/cpu_depth.h @@ -0,0 +1,173 @@ +#pragma once + +/** + * @file cpu_depth.h + * @brief CPU-only stereo fisheye depth pipeline (C++ port of the benchmark/ Python variants). + * + * Implements five alternative techniques for stereo fisheye depth estimation, + * all running on the CPU with OpenCV (no SDK depth engine involved): + * + * V1 fisheye -> pinhole rectification (cv::fisheye::stereoRectify) + SGBM + * (the classic approach, same rectification path as the SDK engine) + * V2v vertical-polar ERP spherical rectification + SGBM (rows approx. epipolar) + * V2b baseline-polar ERP rectification + SGBM (rows exactly epipolar) + * V3 multi-pinhole bands at several yaw angles + SGBM + ERP fusion + * (largest FOV coverage; the winner on low-texture scenes) + * V4 fisheye -> pinhole + StereoBM (fastest) + * V5 SDK-engine-rectified input + own SGBM (isolates the matcher) + * + * All variants output a float32 depth map (meters, 0 = invalid), a rectified + * stacked BGR image for display, and a rectified-frame point cloud. Depth for + * V2/V3 comes from per-pixel ray triangulation; V1/V4/V5 from z = fx*B/d. + * + * The calibration is a kalibr-format yaml (pinhole + equidistant / KB4), the + * same format as config/calib/calib.yaml. + */ + +#include + +#include +#include + +namespace cpu_depth { + +// --------------------------------------------------------------------------- +// Stereo fisheye calibration (kalibr: pinhole + equidistant distortion) +// --------------------------------------------------------------------------- +struct StereoCalib { + cv::Matx33d K[2]; // per-camera intrinsics, scaled to the frame size + cv::Vec4d D[2]; // equidistant distortion coefficients (k1..k4) + int calibW = 0, calibH = 0; // resolution as written in the yaml + int frameW = 0, frameH = 0; // current per-camera frame size (K scaled to this) + + cv::Matx33d R; // cam0 -> cam1 rotation: p1 = R*p0 + t + cv::Vec3d t; // cam0 origin in cam1 frame (m) + cv::Matx33d R_rect; // rectified -> cam0 (rows = rectified axes in cam0 frame) + cv::Matx33d R1_rect; // rectified -> cam1 + cv::Vec3d t_rect; // right camera origin in the rectified frame (~(B,0,0)) + double baseline = 0.0; // m + double lensMaxTheta = 0.0; // max off-axis angle covered by the sensor (rad) +}; + +/// Parse a kalibr cam0/cam1 yaml (line-based, no yaml-cpp dependency). +bool loadKalibr(const std::string& path, StereoCalib& out); + +// --------------------------------------------------------------------------- +// Options +// --------------------------------------------------------------------------- +enum Variant { + V1_PINHOLE_SGBM = 0, + V2V_ERP_SGBM = 1, + V2B_ERP_SGBM = 2, + V3_BANDS_SGBM = 3, + V4_PINHOLE_BM = 4, + V5_ENGINE_SGBM = 5, +}; + +struct CpuOptions { + int variant = V1_PINHOLE_SGBM; + + // SGBM (all SGBM variants; P1/P2 are recomputed from the block size when + // v3Relaxed is set, mirroring the benchmark's relaxed band preset) + int minDisp = 0, numDisp = 128, blockSize = 11; + int P1 = 1904, P2 = 11616, disp12MaxDiff = 4, preFilterCap = 51; + int uniquenessRatio = 10, speckleWindowSize = 150, speckleRange = 1; + int sgbmMode = 1; // cv::StereoSGBM::MODE_SGBM_3WAY + + // StereoBM (V4) + int bmBlockSize = 19; + + // V1/V4 rectification + double balance = 0.0, fovScale = 1.0; + + // V2 rectification (ERP span in degrees) + double lonDeg = 120.0, latDeg = 110.0; + + // V3 bands + double bandHalfDeg = 45.0; + double yaws[3] = {-35.0, 0.0, 35.0}; + int nYaws = 3; + double v3OutScale = 0.5; // band resolution = frame size * scale + bool v3Relaxed = true; // relaxed SGBM for band images (benchmark preset) + double erpFillGap = 8.0; // px, fused-ERP gap fill radius + double erpDensity = 4.0; // px per deg of the fused ERP grid + + // common + double maxZ = 20.0; // m + int maxPoints = 262144; // point cloud cap +}; + +// --------------------------------------------------------------------------- +// Result +// --------------------------------------------------------------------------- +struct CpuResult { + cv::Mat depth; // CV_32FC1 meters, 0 = invalid + cv::Mat rectStereo; // CV_8UC3 stacked BGR (top = left), for display + cv::Mat disparity; // CV_32FC1 px (empty for V3, which has no single grid) + cv::Mat pts; // V2 only: N x 3 CV_32FC1 rectified-frame points + std::vector pcXYZ; // N*3 rectified-frame points (m) + std::vector pcRGB; // N*3 + double runtimeMs = 0.0; +}; + +// --------------------------------------------------------------------------- +// Processor +// --------------------------------------------------------------------------- + +/// One rectification bundle (complete here so std::vector works in any TU). +struct CpuMaps { + int kind = 0; // 0 = V1/V4 pinhole, 1 = V2 ERP, 2 = V3 band + cv::Mat mapx0, mapy0, mapx1, mapy1; // CV_32FC1 + cv::Mat valid0, valid1; // CV_8UC1 + // pinhole meta (kind 0) + double fx = 0, fy = 0, cx = 0, cy = 0, baseline = 0; + // ERP/band meta (kind 1/2) + cv::Mat raysRect; // N x 3 CV_32F + cv::Vec3d tRect; + double yaw = 0, f_v = 0; +}; + +class CpuDepthProcessor { +public: + CpuDepthProcessor() = default; + ~CpuDepthProcessor() = default; + + bool loadCalib(const std::string& calibPath); + + /// Per-camera frame size of the input (stacked frames are 2*frameH tall). + /// Intrinsics are rescaled accordingly; maps rebuild on change. + void setFrameSize(int w, int h); + + bool isReady() const { return mReady; } + + void setOptions(const CpuOptions& opts) { mOpts = opts; } + const CpuOptions& options() const { return mOpts; } + + /// Process a stacked stereo frame (top = left, bottom = right). + /// For V5 pass the engine-rectified stacked image and its intrinsics + /// (engineP0 = {fx, fy, cx, cy}) and baseline. + bool process(const cv::Mat& stacked, + const cv::Mat* engineRect = nullptr, + const double* engineP0 = nullptr, + double engineBaseline = 0.0, + CpuResult* out = nullptr); + + double lastRuntimeMs() const { return mLastRuntimeMs; } + +private: + bool buildMaps(const StereoCalib& calib); + bool matchV3(const cv::Mat& left, const cv::Mat& right, CpuResult* out); + + StereoCalib mCalib; + cv::Matx33d mKCalib[2]; // K at the yaml resolution (scaling baseline) + bool mReady = false; + CpuOptions mOpts; + + // cached maps (rebuilt when variant/geometry/frame size changes) + std::string mMapsKey; + std::vector mMaps; + + double mLastRuntimeMs = 0.0; +}; + +} // namespace cpu_depth diff --git a/collector/tools/fayssense_depth_sdk/lib/depth_engine.cpp b/collector/tools/fayssense_depth_sdk/lib/depth_engine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cd59c0bc6ea0d16bc61027c7adc4b094d278d8a1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/lib/depth_engine.cpp @@ -0,0 +1,267 @@ +#include "depth_engine.h" +#include +#include +#include + +#include "fays_atrak/fays_atrak_depth.h" + +DepthEngine::DepthEngine(const std::string& configPath) +{ + // Create depth engine handle + int ret = FAYS_ATRAK_D_CreateHandleWithConfig(&mHandle, configPath.c_str()); + if (ret != 0) { + std::cerr << "[DepthEngine] Failed to create handle with config: " + << configPath << " (error " << ret << ")" << std::endl; + return; + } + + // Pre-allocate output buffers + size_t depthBytes = kMaxDepthFloats * sizeof(float); + size_t imgBytes = kMaxMonoBytes; + + mDepthBuf = new AtrakDepthImage{}; + mDepthBuf->data = new float[kMaxDepthFloats]; + std::memset(mDepthBuf->data, 0, depthBytes); + + mDispBuf = new AtrakDepthImage{}; + mDispBuf->data = new float[kMaxDepthFloats]; + std::memset(mDispBuf->data, 0, depthBytes); + + mRectBuf = new AtrakImage{}; + mRectBuf->data = new unsigned char[imgBytes * 3]; // worst-case 3-channel + std::memset(mRectBuf->data, 0, imgBytes * 3); + + mPairedBuf = new AtrakImage{}; + mPairedBuf->data = new unsigned char[kMaxRgbBytes]; + std::memset(mPairedBuf->data, 0, kMaxRgbBytes); + + // Pre-allocate point cloud buffer + mCloudMaxPoints = 262144; // FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM + mCloudBuf = new AtrakMap{}; + mCloudBuf->pos = new float[mCloudMaxPoints * 3]; + mCloudBuf->rgb = new uint32_t[mCloudMaxPoints]; + std::memset(mCloudBuf->pos, 0, mCloudMaxPoints * 3 * sizeof(float)); + std::memset(mCloudBuf->rgb, 0, mCloudMaxPoints * sizeof(uint32_t)); + + mInitialized = true; + std::cout << "[DepthEngine] Initialized successfully." << std::endl; +} + +bool DepthEngine::bindViKit(void* viKitHandle) +{ + if (!mInitialized || !viKitHandle) return false; + int ret = FAYS_ATRAK_D_BindViKit(mHandle, viKitHandle); + if (ret == 0) { + std::cout << "[DepthEngine] ViKit bound successfully." << std::endl; + return true; + } + std::cerr << "[DepthEngine] BindViKit failed (error " << ret << ")" << std::endl; + return false; +} + +DepthEngine::~DepthEngine() +{ + if (mHandle) { + FAYS_ATRAK_D_DestroyHandle(mHandle); + mHandle = nullptr; + } + + if (mDepthBuf) { + delete[] mDepthBuf->data; + delete mDepthBuf; + } + if (mDispBuf) { + delete[] mDispBuf->data; + delete mDispBuf; + } + if (mRectBuf) { + delete[] mRectBuf->data; + delete mRectBuf; + } + if (mPairedBuf) { + delete[] mPairedBuf->data; + delete mPairedBuf; + } + if (mCloudBuf) { + delete[] mCloudBuf->pos; + delete[] mCloudBuf->rgb; + delete mCloudBuf; + } +} + +int DepthEngine::feedStereoImage(const cv::Mat& stackedStereo, uint64_t timestampNs) +{ + if (!mInitialized) + return -1; + + // We need a non-const data pointer for the C API. + // Create a local copy to ensure contiguous memory owned by us. + cv::Mat temp; + if (!stackedStereo.isContinuous()) { + temp = stackedStereo.clone(); + } else { + temp = stackedStereo; + } + + AtrakImage img{}; + img.device_id = 0; // ATRAK_DEV_STEREO + img.timestamp = timestampNs; + img.width = temp.cols; + img.height = temp.rows; + img.channel = temp.channels(); + img.step = static_cast(temp.step); + img.bytes = static_cast(temp.total() * temp.elemSize()); + img.data = temp.data; + + if (temp.channels() == 1) + img.encoding = 2; // AIE_RAW8 + else + img.encoding = 0; // AIE_BGR8 + + return FAYS_ATRAK_D_FeedStereoImage(mHandle, &img); +} + +int DepthEngine::feedRgbImage(const cv::Mat& rgbBgr, uint64_t timestampNs) +{ + if (!mInitialized) + return -1; + + cv::Mat temp; + if (!rgbBgr.isContinuous()) { + temp = rgbBgr.clone(); + } else { + temp = rgbBgr; + } + + AtrakImage img{}; + img.device_id = 1; // ATRAK_DEV_MIDDLE + img.timestamp = timestampNs; + img.width = temp.cols; + img.height = temp.rows; + img.channel = temp.channels(); + img.step = static_cast(temp.step); + img.bytes = static_cast(temp.total() * temp.elemSize()); + img.data = temp.data; + img.encoding = 0; // AIE_BGR8 + + return FAYS_ATRAK_D_FeedRGBImage(mHandle, &img); +} + +bool DepthEngine::getDepthImage(cv::Mat& depthMeters, cv::Mat& disparity, cv::Mat& pairedImage) +{ + if (!mInitialized) + return false; + + // Reset buffer fields before calling + mDepthBuf->width = mDepthBuf->height = mDepthBuf->channel = 0; + mDepthBuf->step = mDepthBuf->bytes = 0; + mDispBuf->width = mDispBuf->height = mDispBuf->channel = 0; + mDispBuf->step = mDispBuf->bytes = 0; + mPairedBuf->width = mPairedBuf->height = mPairedBuf->channel = 0; + mPairedBuf->step = mPairedBuf->bytes = 0; + + int ret = FAYS_ATRAK_D_GetDepthImage(mHandle, mDepthBuf, mDispBuf, mPairedBuf); + + if (ret != 0 || mDepthBuf->width == 0 || mDepthBuf->height == 0) + return false; + + // Wrap the SDK's float* buffer into a cv::Mat (no copy — shares the pre-allocated buffer) + depthMeters = cv::Mat(mDepthBuf->height, mDepthBuf->width, CV_32FC1, mDepthBuf->data).clone(); + + // Disparity (optional) + if (!disparity.empty() || mDispBuf->width > 0) { + if (mDispBuf->width > 0 && mDispBuf->height > 0) { + disparity = cv::Mat(mDispBuf->height, mDispBuf->width, CV_32FC1, mDispBuf->data).clone(); + } + } + + // Paired image (optional — only valid when alignment is enabled) + if (!pairedImage.empty() || mPairedBuf->width > 0) { + if (mPairedBuf->width > 0 && mPairedBuf->height > 0 && mPairedBuf->data) { + int type = (mPairedBuf->channel == 1) ? CV_8UC1 : CV_8UC3; + pairedImage = cv::Mat(mPairedBuf->height, mPairedBuf->width, type, mPairedBuf->data).clone(); + } + } + + return true; +} + +bool DepthEngine::getRectifiedImage(cv::Mat& rectifiedStereo) +{ + if (!mInitialized) + return false; + + mRectBuf->width = mRectBuf->height = mRectBuf->channel = 0; + mRectBuf->step = mRectBuf->bytes = 0; + + int ret = FAYS_ATRAK_D_GetRectifiedImage(mHandle, mRectBuf); + + if (ret != 0 || mRectBuf->width == 0 || mRectBuf->height == 0) + return false; + + int type = (mRectBuf->channel == 1) ? CV_8UC1 : CV_8UC3; + rectifiedStereo = cv::Mat(mRectBuf->height, mRectBuf->width, type, mRectBuf->data).clone(); + + return true; +} + +bool DepthEngine::getRectifyInfo(AtrakRectifyInfo& rectifyInfo) +{ + if (!mInitialized) + return false; + + std::memset(&rectifyInfo, 0, sizeof(AtrakRectifyInfo)); + int ret = FAYS_ATRAK_D_GetRectifyInfo(mHandle, &rectifyInfo); + + return ret == 0; +} + +bool DepthEngine::getPointCloud(std::vector& xyz, + std::vector& rgb, + int maxPoints) +{ + if (!mInitialized) + return false; + + if (maxPoints > mCloudMaxPoints) { + maxPoints = mCloudMaxPoints; + } + + mCloudBuf->point_num = 0; + mCloudBuf->pos = mCloudBuf->pos; // retain buffer pointer + mCloudBuf->rgb = mCloudBuf->rgb; + + int ret = FAYS_ATRAK_D_GetPointcloud(mHandle, mCloudBuf, maxPoints); + + if (ret != 0 || mCloudBuf->point_num == 0) + return false; + + int n = static_cast(mCloudBuf->point_num); + if (n > maxPoints) n = maxPoints; + + xyz.resize(n * 3); + rgb.resize(n * 3); + + std::memcpy(xyz.data(), mCloudBuf->pos, n * 3 * sizeof(float)); + + // Set all point cloud points to white + for (int i = 0; i < n; ++i) { + rgb[i * 3 + 0] = 255; // B + rgb[i * 3 + 1] = 255; // G + rgb[i * 3 + 2] = 255; // R + } + + return true; +} + +int DepthEngine::setDepthParam(ATRAK_DepthBackendType backend, const ATRAK_DepthParamKv* kv_array, int kv_count) +{ + if (!mInitialized || !kv_array || kv_count <= 0) return -1; + return FAYS_ATRAK_D_SetDepthParam(mHandle, backend, kv_array, kv_count); // +} + +int DepthEngine::setPointCloudParam(ATRAK_DepthPointBackType backend, const ATRAK_DepthPointParamKv* kv_array, int kv_count) +{ + if (!mInitialized || !kv_array || kv_count <= 0) return -1; + return FAYS_ATRAK_D_SetPointCloudParam(mHandle, backend, kv_array, kv_count); +} \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/lib/depth_engine.h b/collector/tools/fayssense_depth_sdk/lib/depth_engine.h new file mode 100644 index 0000000000000000000000000000000000000000..df6ed8431bd44e5a4dc9979aa5550c5ccf162af9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/lib/depth_engine.h @@ -0,0 +1,134 @@ +#pragma once + +#include +#include +#include +#include + +// SDK types (C++ structs, no extern "C" needed) +#include "fays_atrak/fays_atrak_types.h" +#include "fays_atrak/fays_atrak_depth.h" + +/** + * @brief Wrapper around libfayssense_aikit_depth.so via the C API. + * + * Provides a simple C++ interface for feeding stereo (and optional RGB) + * images and retrieving depth, disparity, rectified images, rectify info, + * and 3D point clouds. + * + * All output buffers are pre-allocated in the constructor and reused. + */ +class DepthEngine { +public: + /** + * @param configPath Path to stereo_depth.yaml + */ + explicit DepthEngine(const std::string& configPath); + ~DepthEngine(); + + bool isInitialized() const { return mInitialized; } + + /// Bind a ViKit sensor handle (live mode) + bool bindViKit(void* viKitHandle); + + // ---- Input ---- + + /** + * @brief Feed a vertically-stacked stereo image. + * + * @param stackedStereo 1-channel grayscale (AIE_RAW8) or 3-channel BGR. + * Left on top half, right on bottom half. + * @param timestampNs Frame timestamp in nanoseconds. + * @return 0 on success, non-zero on error. + */ + int feedStereoImage(const cv::Mat& stackedStereo, uint64_t timestampNs); + + /** + * @brief Set depth algorithm parameters at runtime (key-value batch). + * + * @param backend Target algorithm backend (e.g. ATRAK_DEPTH_BACKEND_SGBM). + * @param kv_array KV array of parameter ID/value pairs. + * @param kv_count Number of KVs in the array. + * @return 0 on success, non-zero on error. + */ + int setDepthParam(ATRAK_DepthBackendType backend, const ATRAK_DepthParamKv* kv_array, int kv_count); + + /** + * @brief Feed the middle RGB camera image for depth-to-RGB alignment. + * + * Only meaningful when the stereo_depth.yaml has align_cam_id != -1. + * + * @param rgbBgr 3-channel BGR image from the middle camera. + * @param timestampNs Frame timestamp in nanoseconds. + * @return 0 on success, non-zero on error. + */ + int feedRgbImage(const cv::Mat& rgbBgr, uint64_t timestampNs); + + // ---- Output ---- + + /** + * @brief Get the latest depth image. + * + * @param depthMeters [out] CV_32FC1, values in meters. + * @param disparity [out] CV_32FC1 raw disparity (required, pass empty mat to skip). + * @param pairedImage [out] Aligned image if alignment enabled (required, pass empty mat to skip). + * @return true if new data was available, false if stale/empty. + */ + bool getDepthImage(cv::Mat& depthMeters, + cv::Mat& disparity, + cv::Mat& pairedImage); + + /** + * @brief Get the latest rectified stereo image. + * + * @param rectifiedStereo [out] Vertically stacked, 3-channel BGR. + * @return true if new data was available. + */ + bool getRectifiedImage(cv::Mat& rectifiedStereo); + + /** + * @brief Get rectification info (R0, R1, P0, P1 matrices). + */ + bool getRectifyInfo(AtrakRectifyInfo& rectifyInfo); + + /** + * @brief Get the 3D point cloud. + * + * @param xyz [out] N*3 interleaved float coordinates (meters). + * @param rgb [out] N*3 uint8 BGR colors. + * @param maxPoints Maximum number of points to retrieve. + * @return true if new data was available. + */ + bool getPointCloud(std::vector& xyz, + std::vector& rgb, + int maxPoints = 262144); + + /** + * @brief Set point cloud generation parameters at runtime (key-value batch). + * + * @param backend Target point cloud generation backend (e.g. ATRAK_DEPTHPOINT_BACK_CPU). + * @param kv_array KV array of parameter ID/value pairs. + * @param kv_count Number of KVs in the array. + * @return 0 on success, non-zero on error. + */ + int setPointCloudParam(ATRAK_DepthPointBackType backend, const ATRAK_DepthPointParamKv* kv_array, int kv_count); + +private: + void* mHandle = nullptr; + bool mInitialized = false; + + // Pre-allocated output buffers + AtrakDepthImage* mDepthBuf = nullptr; + AtrakDepthImage* mDispBuf = nullptr; + AtrakImage* mRectBuf = nullptr; + AtrakImage* mPairedBuf = nullptr; + + // Point cloud output buffer + AtrakMap* mCloudBuf = nullptr; + int mCloudMaxPoints = 0; + + // Maximum buffer sizes — use SDK defines to prevent overflow + static constexpr size_t kMaxDepthFloats = FAYS_ATRAK_IMG_MAX_BYTES; + static constexpr size_t kMaxMonoBytes = FAYS_ATRAK_RGB_MAX_BYTES; + static constexpr size_t kMaxRgbBytes = FAYS_ATRAK_RGB_MAX_BYTES; +}; diff --git a/collector/tools/fayssense_depth_sdk/models/rk3588/stereo_s_general.rknn b/collector/tools/fayssense_depth_sdk/models/rk3588/stereo_s_general.rknn new file mode 100644 index 0000000000000000000000000000000000000000..7570048865044580cc17b2e19dd5ee89d767f12c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/models/rk3588/stereo_s_general.rknn @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c4e4515bc7e8439e83739ec9ea64631b54e39b7aedf5cb797a92d06b994e8c7 +size 13280358 diff --git a/collector/tools/fayssense_depth_sdk/sdk/fays_vikit.yaml b/collector/tools/fayssense_depth_sdk/sdk/fays_vikit.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d39af1cc81fc94649519bf0d1de9a99ed383283f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/fays_vikit.yaml @@ -0,0 +1,59 @@ +%YAML:1.0 +############################ Middle RGB Camera ############################ +# Rgb device number. Valid values: ${DEVICE_NODE} (enable) | NULL (disable) +rgb_dev_port: NULL +# Auto white balance [true/false] +awb: true +# White balance coefficients +rgb_white_balance_r: 1.3 #1 +rgb_white_balance_g: 0.8 #0.7 +rgb_white_balance_b: 2.1 #1.66 +# RGB image rotation angle, currently only 0/180 degree rotation is supported. +rgb_rotate: 0 +# Image format of middle camera [0: bayer image, 1: RGB image] +mid_img_fmt: 1 +# Image size of middle camera [1920x1080 or 960x540] +rgb_cam_width: 1920 +rgb_cam_height: 1080 + +############################## Stereo Camera ############################## +# Stereo device number +stereo_dev_port: /dev/video0 +# The width of the stereo camera image[640/1280] +stereo_single_cam_width: 1280 +# The width of the stereo camera image[400/800] +stereo_single_cam_height: 800 +# The frame rate of the stereo camera[25/50] +stereo_fps: 25 +# Only support color sensors. Output: [0: raw image, 1: RGB image] +# The stereo color camera only supports a resolution of 1280*800. +stereo_color_mode: 0 +# auto white balance for stereo rgb sensor only +stereo_awb: 1 +# rgb digital gains for stereo rgb sensor only (works when awb-mode is off) +stereo_R_gain: 1. +stereo_G_gain: 0.6 +stereo_B_gain: 1.3 +# -1: auto initial exposure (Initially set the exposure to automatic, then fix the value.) +# 1.0 ~ 885.0: manual exposure value +stereo_init_exposure: 600 +# Stereo gain control [ 1.0 ~ 15.0 is manual : -1 auto gain ] +stereo_gain_value: 6 +# Left camera rotation control [0: no rotation, 1: rotate 180 degrees] +left_cam_rotate_180: 1 +# Right camera rotation control [0: no rotation, 1: rotate 180 degrees] +right_cam_rotate_180: 0 +# Swap the left and right images [0: do not swap, 1: swap] +stereo_swap_lr: 1 + +################################### IMU ################################### +# Imu device number +imu_dev_port: /dev/video2 +# The gravity acceleration value of the device location +gravity: 9.7946 + +################################### COMMON ################################### +# Print FPS to stdout every second [true/false] +print_fps: true +# read timeout (milliseconds) +frame_timeout_ms: 2000 diff --git a/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_atrak_depth.h b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_atrak_depth.h new file mode 100644 index 0000000000000000000000000000000000000000..756e467d178562c3e905c2a714681f6320b5926b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_atrak_depth.h @@ -0,0 +1,306 @@ +#pragma once + + +#include "fays_atrak_types.h" + + +#if (defined (_WIN32) || defined(WIN64)) + #define FAYS_ATRAK_API __declspec(dllexport) +#else + #define FAYS_ATRAK_API __attribute__((visibility("default"))) +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + + + +/** + * @brief Maximum number of depth parameter KVs in a single + * FAYS_ATRAK_D_SetDepthParam call. + */ +#define FAYS_ATRAK_DEPTH_PARAM_MAX_COUNT 32 + +/** + * @brief Total number of depth parameter slots in the depth engine. + * + * Each ATRAK_DepthParamId value is used directly as the slot index, so this + * value must always be larger than the greatest defined parameter ID. + */ +#define FAYS_ATRAK_DEPTH_PARAM_SLOT_COUNT 128 + + +/** + * @brief Maximum number of 3D point cloud parameter KVs in a single + * FAYS_ATRAK_D_SetPointCloudParam call. + */ +#define FAYS_ATRAK_PC_PARAM_MAX_COUNT 32 + +/** + * @brief Total number of 3D point cloud parameter slots in the depth engine. + * + * Each ATRAK_DepthPointParamId value is used directly as the slot index, so this + * value must always be larger than the greatest defined parameter ID. + */ +#define FAYS_ATRAK_DEPTHPOINT_PARAM_SLOT_COUNT 256 + + +/**************************************************************************** + * standard stereo-depth SDK + ****************************************************************************/ + +/** + * @brief Depth algorithm backends. + */ +typedef enum { + ATRAK_DEPTH_BACKEND_SGBM = 0, //< OpenCV SGBM (CPU mode) + ATRAK_DEPTH_BACKEND_CUSTOM = 1, //< custom depth model (e.g. NPU) + ATRAK_DEPTH_BACKEND_OTHER = 2, //< reserved for future backends +} ATRAK_DepthBackendType; + +/** + * @brief Depth parameter IDs, used as KV keys. + * + * The ID space is partitioned per backend: + * [101, 120) = SGBM parameters (including the WLS post-filter) + */ +typedef enum { + ATRAK_DP_SGBM_MIN_DISP = 101, //< min_disp + ATRAK_DP_SGBM_NUM_DISP = 102, //< num_disp (multiple of 16, [16, 128]) + ATRAK_DP_SGBM_WINDOW_SIZE = 103, //< window_size / block size (odd, [1, 31]) + ATRAK_DP_SGBM_P1 = 104, //< P1 penalty + ATRAK_DP_SGBM_P2 = 105, //< P2 penalty + ATRAK_DP_SGBM_DISP12_MAX_DIFF = 106, //< disp12MaxDiff + ATRAK_DP_SGBM_PRE_FILTER_CAP = 107, //< preFilterCap + ATRAK_DP_SGBM_UNIQUENESS_RATIO = 108, //< uniquenessRatio + ATRAK_DP_SGBM_SPECKLE_WINDOW_SIZE = 109, //< speckleWindowSize + ATRAK_DP_SGBM_SPECKLE_RANGE = 110, //< speckleRange + ATRAK_DP_SGBM_MODE = 111, //< SGBM mode (0=SGBM_3WAY, 1=SGBM, 2=HH4) + ATRAK_DP_SGBM_WLS_ENABLE = 112, //< WLS filter toggle (0=off, 1=on) + ATRAK_DP_SGBM_WLS_LAMBDA = 113, //< WLS lambda + ATRAK_DP_SGBM_WLS_SIGMA_COLOR = 114, //< WLS sigmaColor + ATRAK_DP_SGBM_WLS_DISC_RADIUS = 115, //< WLS depthDiscontinuityRadius +} ATRAK_DepthParamId; + +/** + * @brief A single depth parameter, addressed by ID with a float value. + */ +typedef struct { + ATRAK_DepthParamId param_id; //< parameter ID + float value; //< parameter value +} ATRAK_DepthParamKv; + +/** + * @brief 3D point cloud generation backends. + */ +typedef enum { + ATRAK_DEPTHPOINT_BACK_CPU = 0, //< CPU point cloud generation + ATRAK_DEPTHPOINT_BACK_OTHER = 1, //< reserved for future backends +} ATRAK_DepthPointBackType; + +/** + * @brief 3D point cloud parameter IDs, used as KV keys. + * + * The ID space is partitioned per backend: + * [201, 220) = point cloud generation parameters + */ +typedef enum { + ATRAK_DPP_POINTCLOUD_TYPE = 201, //< pointcloud_type + ATRAK_DPP_POINTCLOUD_ROI = 202, //< pointcloud_ROI (%) 0~1 + ATRAK_DPP_SKIP_POINT = 203, //< skip_point (stride for point sampling) + ATRAK_DPP_FARTHEST_DIST = 204, //< farthest_dist (m) + ATRAK_DPP_CLOSEST_DIST = 205, //< closest_dist (m) + ATRAK_DPP_VOXEL_SIZE = 206, //< voxelSize (m) + ATRAK_DPP_MIN_POINTS = 207, //< minPoints (minimum points threshold) + ATRAK_DPP_ENABLE_VOXEL = 208, //< enable_voxel (0=off, 1=on) +} ATRAK_DepthPointParamId; + +/** + * @brief A single 3D point cloud parameter, addressed by ID with a float value. + */ +typedef struct { + ATRAK_DepthPointParamId param_id; //< parameter ID + float value; //< parameter value +} ATRAK_DepthPointParamKv; + +/** + * @brief Create a depth engine handle with configuration. + * + * @param[out] handle Depth engine handle. + * @param[in] configPath Path to stereo_depth.yaml configuration file. + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_CreateHandleWithConfig (void** handle, const char* configPath); + +/** + * @brief Destroy the depth engine handle and release all resources. + * + * @param[in] handle Depth engine handle. + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_DestroyHandle (void* handle); + +/** + * @brief Feed a vertically-stacked stereo image to the depth engine. + * + * The image is stacked top-bottom: upper half = left camera, lower half = right camera. + * + * @param[in] handle Depth engine handle. + * @param[in] pStereoImage Stereo image (AIE_RAW8 or AIE_BGR8). + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_FeedStereoImage (void* handle, AtrakImage* pStereoImgae); + +/** + * @brief Feed the middle RGB camera image for depth-to-RGB alignment. + * + * Only meaningful when align_cam_id is set in stereo_depth.yaml. + * + * @param[in] handle Depth engine handle. + * @param[in] pRgbImage RGB image (AIE_BGR8). + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_FeedRGBImage (void* handle, AtrakImage* pStereoImgae); + +/** + * @brief Feed cam0 pose (T_w_cam0) for pointcloud transformation. + * + * @param handle + * @param pPose + * @return Status code: 0 = Success, non-zero = Failure + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_FeedPose (void* handle, AtrakPose* pPose); + +/** + * @brief Get depth results. + * + * Caller must pre-allocate data buffers and is responsible for freeing them. + * + * @param[in] handle Depth engine handle. + * @param[out] pDepthImage Depth image (float, in meters). Caller allocates data buffer. + * @param[out] pDispImage Rectified raw disparity image (non-aligned, possibly downsampled). Caller allocates data buffer. + * @param[out] pairedImg Paired image aligned to depth (only valid if alignment enabled). Caller allocates data buffer. + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_GetDepthImage (void* handle, AtrakDepthImage* pDepthImage, AtrakDepthImage* pDispImage, AtrakImage* pairedImg); + +/** + * @brief Get the rectified stereo image. + * + * Returns a vertically-stacked (top-bottom) rectified stereo image. + * Caller must pre-allocate the data buffer and is responsible for freeing it. + * + * @param[in] handle Depth engine handle. + * @param[out] pRectImage Rectified stereo image (BGR8). Caller allocates data buffer. + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_GetRectifiedImage (void* handle, AtrakImage* pRectImage); + +/** + * @brief Get the rectification matrices for the stereo pair. + * + * Caller allocates the AtrakRectifyInfo struct and is responsible for its lifetime. + * + * @param[in] handle Depth engine handle. + * @param[out] pRectInfo Rectification info (R0, R1, P0, P1 matrices). Caller allocates. + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_GetRectifyInfo (void* handle, AtrakRectifyInfo* pRectInfo); + +/** + * @brief Get the 3D point cloud from the latest depth frame. + * + * @param[in] handle Depth engine handle. + * @param[out] pCloud Point cloud buffer. Caller must pre-allocate pos (float[3N]) and rgb (uint32_t[N]) arrays. + * @param[in] maxPoints Maximum number of points to retrieve. + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_GetPointcloud (void* handle, AtrakMap* pCloud, int maxPoints); + +/** + * @brief Bind a ViKit sensor handle to the depth engine. + * + * Call after FAYS_ATRAK_D_CreateHandleWithConfig + * + * @param depthHandle Depth engine handle. + * @param viKitHandle ViKit sensor handle (from FAYS_VIK_CreateHandleWithConfig). + * @return 0 on success, non-zero on failure. + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_BindViKit (void* depthHandle, void* viKitHandle); + + + +/** + * @brief Set depth algorithm parameters at runtime in a batch of key-value pairs. + * + * Only the passed KVs are updated; all other parameters keep their previous + * values. The parameters take effect on the next processed frame. + * + * SGBM parameters are only applied when backend is ATRAK_DEPTH_BACKEND_SGBM; + * when another backend is active, they are ignored (and the engine keeps + * running with its current parameters). + * + * @param[in] handle Depth engine handle (from FAYS_ATRAK_D_CreateHandleWithConfig). + * @param[in] backend Target algorithm backend the KVs belong to. + * @param[in] kv_array KV array (may be NULL when kv_count is 0). + * @param[in] kv_count Number of KVs in the array (must be >= 0 and <= FAYS_ATRAK_DEPTH_PARAM_MAX_COUNT). + * @return 0 on success, non-zero on failure (invalid handle / null kv_array with non-zero count / count out of range). + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_SetDepthParam(void* handle, + ATRAK_DepthBackendType backend, + const ATRAK_DepthParamKv* kv_array, + int kv_count); + + +/** + * @brief Set the point cloud generation parameters at runtime in a batch of key-value pairs. + * + * Only the passed KVs are updated; all other parameters keep their previous + * values. The parameters take effect on the next processed frame. + * + * 3D point parameters are only applied when backend is ATRAK_DEPTHPOINT_BACK_CPU; + * when another backend is active, they are ignored (and the engine keeps + * generating point clouds with its current parameters). + * + * @param[in] handle Depth engine handle (from FAYS_ATRAK_D_CreateHandleWithConfig). + * @param[in] backend Target point cloud generation backend the KVs belong to. + * @param[in] kv_array KV array (may be NULL when kv_count is 0). + * @param[in] kv_count Number of KVs in the array (must be >= 0 and <= FAYS_ATRAK_PC_PARAM_MAX_COUNT). + * @return 0 on success, non-zero on failure (invalid handle / null kv_array with non-zero count / count out of range). + */ +FAYS_ATRAK_API int FAYS_ATRAK_D_SetPointCloudParam(void* handle, + ATRAK_DepthPointBackType backend, + const ATRAK_DepthPointParamKv* kv_array, + int kv_count); + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus + +/** + * @brief Convenience helper for building a depth parameter KV pair. + */ +inline ATRAK_DepthParamKv makeKv(ATRAK_DepthParamId id, float val) +{ + ATRAK_DepthParamKv kv; + kv.param_id = id; + kv.value = val; + return kv; +} + +/** + * @brief Convenience helper for building a 3D point cloud parameter KV pair. + */ +inline ATRAK_DepthPointParamKv makeKv(ATRAK_DepthPointParamId id, float val) +{ + ATRAK_DepthPointParamKv kv; + kv.param_id = id; + kv.value = val; + return kv; +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_atrak_types.h b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_atrak_types.h new file mode 100644 index 0000000000000000000000000000000000000000..9b5b5c0afb1d57441b2e3ee457861f9a9bc6b1a8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_atrak_types.h @@ -0,0 +1,347 @@ +#pragma once + +#include + +#define FAYS_ATRAK_MAX_CAMERAS 3 +#define FAYS_ATRAK_MAX_TRACK_INSTANCES 1 +#define FAYS_ATRAK_MAX_APRIL_INSTANCES 10 +#define FAYS_ATRAK_MONO_MAX_BYTES (1280 * 800 * 2) +#define FAYS_ATRAK_RGB_MAX_BYTES (3840 * 2160 * 3) +#define FAYS_ATRAK_MAX_DENSE_MAP_POINTS_NUM 262144 +#define FAYS_ATRAK_MAX_SPARSE_MAP_POINTS_NUM 4096 +#if FAYS_ATRAK_MONO_MAX_BYTES > FAYS_ATRAK_RGB_MAX_BYTES +# define FAYS_ATRAK_IMG_MAX_BYTES FAYS_ATRAK_MONO_MAX_BYTES +#else +# define FAYS_ATRAK_IMG_MAX_BYTES FAYS_ATRAK_RGB_MAX_BYTES +#endif +#define FAYS_ATRAK_DEPTH_IMG_MAX_BYTES (FAYS_ATRAK_IMG_MAX_BYTES * sizeof(float)) + +/*********************** Atrak device defines *************************/ +#define ATRAK_DEV_STEREO 0 +#define ATRAK_DEV_MIDDLE 1 +#define ATRAK_DEV_STEREO_RECT 2 +#define ATRAK_DEV_DENSE_MAP 0 +#define ATRAK_DEV_SPARSE_MAP 1 + +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned int uint; +typedef unsigned long ulong; +typedef unsigned long long ull; + +/** + * @brief + * 6DOF State. + * 4 bits: bit0 - idle(0) / running(1), bit1 - normal(0) / error(1), + * bit2 & bit3 holds pose type: + * 01 - Initializing (external pose only in fusion mode / no pose in vio-only mode) + * 10 - Vio pose only (external pose has been missing for a while if in fusion mode) + * 11 - Fusion pose + */ +enum ATRAK_STATE : uint { + AS_STOP = 0, + AS_ERROR = 3, + AS_INITIALIZING = 5, + AS_VIO_POSE_ONLY = 9, + AS_FUSION_POSE = 13 +}; + +enum ATRAK_ERROR_CODE : int { + AEC_NO_ERROR = 0 +}; + +enum ATRAK_TYPE : int { + AT_VIO = 0, + AT_GPOSE_FUSION = 1 +}; + +enum ATRAK_IMG_ENCODING : short +{ + AIE_BGR8 = 0, + AIE_RGB8, + AIE_RAW8, + AIE_JPEG +}; + +enum ATRAK_CAM_MODEL : uint8_t +{ + ACM_UNKNOWN = 0, + ACM_PINHOLE, +}; + +enum ATRAK_DISTORTION_MODEL : uint8_t +{ + ADM_NONE = 0, // No distortion. + ADM_KB4, // KANNALA_BRANDT k1 k2 k3 k4 + ADM_RADTAN, // k1, k2, p1, p2 + ADM_BROWN_CONRADY, // Brown-Conrady k1, k2, p1, p2, k3 + ADM_CVBASIC, // OpenCV basic 8-parameter model k1, k2, p1, p2, k3, k4, k5, k6 +}; + + + +/** + * @brief AI Kit device info + */ +#define FAYS_ATRAK_MAX_INFO_BUFFER_SIZE 64 + +typedef struct AtrakDeviceInfo { + char vendor_name[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + char product_type[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + char product_name[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + char product_serial_number[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + char user_defined_name[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + char device_ip_address[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + char device_version[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + char driver_version[FAYS_ATRAK_MAX_INFO_BUFFER_SIZE]; + + uint32_t device_id; + uint32_t reserved[15]; +} AtrakDeviceInfo; + + +/** + * @brief 6DOF pose + * + */ +typedef struct AtrakPose +{ + ull timestamp; // unit: nanosencond + double pos[3]; // unit: meter + double quat[4]; // Hamilton convention quaternion: w, x, y, z + short confidence; // -1~100 +} AtrakPose; + +typedef struct AtrakImage +{ + int device_id; + int seq; + ull timestamp; // unit: nanosencond + int width; + int height; + int channel; + short encoding; + int step; + uint bytes; // num of data bytes + uchar* data; // pointer to the pre-allocated image buffer (BGR-packed if 3-channels) +} AtrakImage; + +typedef struct AtrakIMU +{ + ull timestamp; // unit: nanosencond + double gyro[3]; + double acc[3]; +} AtrakIMU; + +typedef struct AtrakGNSS +{ + ull timestamp; + int seq; + uchar status; + short service; + double latitude; + double longitude; + double altitude; + double position_cov[9]; + uchar position_cov_type; +} AtrakGNSS; + +typedef struct AtrakExtraPose +{ + int frame; + int seq; + ull timestamp; + uchar status; + double pos[3]; + double quat[4]; // Hamilton convention quaternion: w, x, y, z + double cov[36]; +} AtrakExtraPose; + +typedef struct AtrakMap +{ + int device_id; // ATRAK_DEV_DENSE_MAP | ATRAK_DEV_SPARSE_MAP + ull timestamp; + uint point_num; + float* pos; // total length: 3 * point_num (x1, y1, z1, x2, y2, z2, ...) + uint32_t* rgb; // total length: 1 * point_num (08R8G8B8, ...) +} AtrakMap; + + +/****************************************** template tracking *******************************************/ +typedef struct AtrakTempTrackConfig +{ + ull timestamp; // unit: nanosencond + int seq; + uint cls = 0; // For multi templates tracking (future) + AtrakImage template_img; // BGR 3-channel image support only + float physical_width = -1.F; // physical width of the template if available. uint: meter + float physical_height = -1.F; // physical height of the template if available. uint: meter +} AtrakTempTrackConfig; + +typedef struct AtrakObject2D +{ + int cls; // class id. 0~2^24-1: (customized class), others: reserved + int id; // instance id if available + float confidence; // detection confidence 0.~1. + float bbox[4]; // bounding box in image pixel coordinates: center x, center y, width, height + uint32_t extra_info_mask; // extra info mask. 0: no extra info; 1: position available. Bit(L-->H): position, orientation, angle in image + float pose[7]; // px, py, pz, qw, qx, qy, qz + float angle; // rotation angle in image if available. uint: degree +} AtrakObject2D; + +typedef struct AtrakObject2DDets +{ + ull timestamp; // unit: nanosencond + int seq; + uint num_objs; + AtrakObject2D objs[FAYS_ATRAK_MAX_TRACK_INSTANCES]; +} AtrakObject2DDets; + + +/****************************************** AprilTag tracking *******************************************/ + +enum ATRAK_TAG_FAMILY : uint { + ATF_36H11 = 0, + ATF_25H9, + ATF_16H5, + ATF_CIRCLE21H7, + ATF_CIRCLE49H12, + ATF_CUSTOM48H12, + ATF_STANDARD41H12, + ATF_STANDARD52H13 +}; + +typedef struct AtrakAprilTagTrackConfig +{ + ull timestamp; // unit: nanosencond + int seq; + ATRAK_TAG_FAMILY tag_family; + float tag_size = -1.F; // only support multiple same-size tags for now. unit: meter +} AtrakAprilTagTrackConfig; + +typedef struct AtrakAprilTag +{ + ATRAK_TAG_FAMILY tag_family; // tag family + uint id; // tag id + float corners[8]; // tag corners in image pixel coordinates [u, v, u, v, ...]. These always wrap counter-clock wise around the tag + bool pose_available; // tag pose is available or not + float pos[3]; // tag position if available. uint: meter + float quat[4]; // tag orientation if available. Hamilton convention quaternion: w, x, y, z +} AtrakAprilTag; + +typedef struct AtrakAprilTagDets +{ + ull timestamp; // unit: nanosencond + int seq; + uint num_tags; + AtrakAprilTag tags[FAYS_ATRAK_MAX_APRIL_INSTANCES]; +} AtrakAprilTagDets; + + +/****************************************** Stereo depth *******************************************/ + +typedef struct AtrakDepthImage +{ + int device_id; + int seq; + ull timestamp; // unit: nanosencond + int width; + int height; + int channel; + short encoding; + int step; + uint bytes; // bytes of data array (sizeof(float) * length) + float* data; // pointer to the pre-allocated depth image buffer +} AtrakDepthImage; + +typedef struct AtrakRectifyInfo +{ + // camera pair id + uint8_t cam_pair[2]; + // brings points in the unrectified first camera frame to points in the rectified first camera frame + float R0[9]; + // brings points in the unrectified second camera frame to points in the rectified second camera frame + float R1[9]; + // projects points in the rectified first camera coordinate system into the rectified first camera's image + float P0[12]; + // projects points in the rectified first camera coordinate system into the rectified second camera's image + float P1[12]; +} AtrakRectifyInfo; + + +/****************************************** Calibration info *******************************************/ + +typedef struct AtrakIntrinsics { + ATRAK_CAM_MODEL cam_model; + uint32_t width; + uint32_t height; + float fx; + float fy; + float cx; + float cy; + float intrinsic_extra[4]; // support more camera models + ATRAK_DISTORTION_MODEL distortion_model; + float distortion[8]; +} AtrakIntrinsics; + + +/** + * @brief 6-DoF transformation (rotation/translation) + */ +typedef struct AtrakExtrinsics { + float rot[9]; // row-major rotation matrix + float trans[3]; // translation vector +} AtrakExtrinsics; + +/** + * @brief Camera parameters + */ +typedef struct AtrakCamParam { + uint8_t cam_id; + uint8_t available_mask; // indicator for available info (Bit L to H): intrinsics, T_cn_cnm1, T_cn_imu, timeshift_cam_imu + AtrakIntrinsics intrinsics; + AtrakExtrinsics T_cn_cnm1; // Bring points in {camera n-1} frame to {camera n} frame + AtrakExtrinsics T_cn_imu; // Bring points in {imu} frame to {camera n} frame + double timeshift_cam_imu; // timeshift_cam_imu = t_imu - t_cam +} AtrakCamParam; + +/** + * @brief Camera chain parameters + */ +typedef struct AtrakCamChainParam { + uint32_t num_of_cams; + uint32_t downsize_ratio; + AtrakCamParam cameras[FAYS_ATRAK_MAX_CAMERAS]; +} AtrakCamChainParam; + +/** + * @brief IMU calib parameters + */ +typedef struct AtrakImuParam{ + double accelerometer_noise_density; + double accelerometer_random_walk; + double gyroscope_noise_density; + double gyroscope_random_walk; + float update_rate; +} AtrakImuParam; + +/** + * @brief Cams and IMU calib parameters + */ +typedef struct AtrakCalibrationParam{ + AtrakCamChainParam cameras; + AtrakImuParam imu; +} AtrakCalibrationParam; + +/** + * @brief Device Info + */ +typedef struct ViKitDeviceInfo +{ + char firmware_version[16]; + char device_model[16]; + char serial_number[32]; + uint32_t camera_nums; + uint32_t imu_nums; + uint32_t reserved[32]; +} ViKitDeviceInfo; \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_vikit.h b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_vikit.h new file mode 100644 index 0000000000000000000000000000000000000000..31776dd64d5ce2e3699fde338a85ff016c1184d1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_vikit.h @@ -0,0 +1,318 @@ +/** + * @file fays_vikit.h + * @brief Public API for acquiring sensor data and configuring device properties. + */ + +#pragma once + + +#include "fays_atrak_types.h" +#include + + +#if (defined (_WIN32) || defined(WIN64)) + #define FAYS_VIK_API __declspec(dllexport) +#else + #define FAYS_VIK_API __attribute__((visibility("default"))) +#endif + + +/* **************************************************************************** + * Status & ReturnCode Type Definitions + * ****************************************************************************/ + +/** + * @brief VIKit device status (32-bit). + * + * The status word is designed for future expansion: + * + * 31 8 7 0 + * +----------------------+-----------------+ + * | Sensor status area | Device status | + * +----------------------+-----------------+ + * + * Device status (bits 0-7): + * Bit 0 : Stream error + * Bit 1 : Device control error + * Bit 2-7 : Reserved + * + * Sensor status (bits 8-31): + * Reserved for future sensor-specific status flags. + * + * Bit value: + * 0 = Normal + * 1 = Error + * + * @note + * Currently, only bits 0 and 1 are defined. + * All other bits are reserved for future use and must be ignored. + */ +typedef uint32_t ViKitDeviceStatus; + +/** + * @brief Device-level status flags. + */ +#define VIKIT_STATUS_STREAM_ERROR (1u << 0) /**< Bit 0: Streaming error. */ +#define VIKIT_STATUS_CONTROL_ERROR (1u << 1) /**< Bit 1: Device control error. */ + +/** No errors detected. */ +#define VIKIT_STATUS_OK 0u + +/** + * @brief VIKit function return codes. + * + * Return value convention: + * - 0: Operation completed successfully. + * - Non-zero value indicates an error. + */ +typedef enum { + VIKIT_RET_SUCCESS = 0, /**< Operation completed successfully */ + VIKIT_RET_FAILURE = -1, /**< General unspecified failure */ + VIKIT_RET_NO_NEW_FRAME = -2, /**< No new frame is available */ + VIKIT_RET_INVALID_ARGUMENT = -3, /**< Invalid function argument */ + VIKIT_RET_OUT_OF_RANGE = -4, /**< Parameter value is out of valid range */ + VIKIT_RET_INVALID_CONFIG = -5, /**< Configuration is missing or invalid */ + VIKIT_RET_TIMEOUT = -6, /**< Operation timed out */ + VIKIT_RET_DEVICE_LOST = -7, /**< Device has been disconnected */ + VIKIT_RET_CONTROL_FAILURE = -8, /**< Control operation failed */ +} ViKitReturnCode; + + + + +/**************************************************************************** + * Standard Fays ViKit SDK + ****************************************************************************/ + +/* +* @brief Image callback function definition. +*/ +using FAYS_VIK_ImageCallback = std::function; + +/* +* @brief IMU callback function definition. +*/ +using FAYS_VIK_ImuCallback = std::function; + +/** + * @brief Open sensor . + * + * @param[in] configuration The configuration file path. + * @param[out] handle + * @return Creation success or failure. + */ +FAYS_VIK_API int FAYS_VIK_CreateHandleWithConfig (void** handle, const char* configPath); + +/** + * @brief Destroy the handle and turn off the sensors. + * + * @param[out] handle + * @return Destruction success or failure. + */ +FAYS_VIK_API int FAYS_VIK_DestroyHandle (void* handle); + +/** + * @brief Get device information. + * + * @param[in] handle + * @param[out] pInfo Device information. + * @return Whether getting device information is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_GetDeviceInfo (void* handle, ViKitDeviceInfo* pInfo); + +/** + * @brief Get calibration parameters. + * + * @param[in] handle + * @param[out] pCalib Calibration parameters. + * @return Whether getting calibration parameters is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_GetCalibrationParam (void* handle, AtrakCalibrationParam* pCalib); + +/** + * @brief Get grayscale camera image (The image is stitched together). + * + * @param[in] handle + * @param[out] image Stereo camera grayscale image. + * @return Whether the image acquisition is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_GetStereoFrames (void* handle, AtrakImage* pImage); + +/** + * @brief Set the Gain of the stereo camera. + * + * @param[in] handle + * @param[in] value Target gain value. + * @note Only supports setting gain value through root. + * @note Gain range: 1.0 ~ 15.0. + * @return Set whether gain is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_SetStereoGain (void* handle, float gainValue); + +/** + * @brief Set the exposure time of the stereo camera. + * + * @param[in] handle + * @param[in] value Target exposure value. + * @note Only supports setting exposure value through root. + * @note Exposure range: 1.0 ~ 507.0. + * @return Set whether exposure is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_SetStereoExposure (void* handle, double exposureValue); + +/** + * @attention Feature not open yet. + * @brief Set the camera frame rate. + * + * @param[in] handle + * @note Only supports setting FPS through root. + * @return Set whether FPS is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_SetStereoFPS (void* handle, int fps); + +/** + * @brief Register stereo image callback function. + * + * @param[in] handle + * @param[in] imgCallback Callback function for new images. + * @return Registration success or failure. +*/ +FAYS_VIK_API int FAYS_VIK_RegisterStereoImageCallback (void* handle, FAYS_VIK_ImageCallback imgCallback); + +/** + * @brief Get the RGB image. + * + * @param[in] handle + * @param[out] pImg RGB image data. + * @return Get whether RGB image data is successful or not. +*/ +FAYS_VIK_API int FAYS_VIK_GetRgbFrames (void* handle, AtrakImage* pImg); + +/** + * @brief Set the exposure time of the RGB camera. + * + * @param[in] handle + * @param[in] value Target exposure value. + * @note Only supports setting exposure value through root. + * @note Exposure range: 8.0 ~ 2146.0. + * @return Set whether exposure is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_SetRgbExposure (void* handle, double exposureValue); + +/** + * @brief Set the gain of the RGB camera. + * + * @param[in] handle + * @param[in] value Target gain value. + * @note Only supports setting gain value through root. + * @note Gain range: 1.0 ~ 72.0. + * @return Set whether gain is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_SetRgbGain (void* handle, float gainValue); + +/** + * @brief Register RGB image callback function. + * + * @param[in] handle + * @param[in] imgCallback Callback function for new images. + * @return Registration success or failure. + */ +FAYS_VIK_API int FAYS_VIK_RegisterRgbImageCallback (void* handle, FAYS_VIK_ImageCallback imgCallback); + +/** + * @brief Get imu data. + * + * @param[in] handle + * @param[out] imu 6-axis imu data. + * @return Get whether IMU data is successful or not. + */ +FAYS_VIK_API int FAYS_VIK_GetImuData (void* handle, AtrakIMU* pImu); + +/** + * @brief Get the version of the SDK. + * + * @param[in] handle + * @return The version of the SDK. + */ +FAYS_VIK_API const char* FAYS_VIK_GetVersion (void* handle); + +/** + * @brief Get the current device status. + * + * @param[in] handle Device handle. + * @param[out] status Device status. + * + * @return VIKIT_RET_SUCCESS on success; otherwise, a non-zero error code. + */ +FAYS_VIK_API int FAYS_VIK_GetStatus (void* handle, ViKitDeviceStatus* pStatus); + + +/** + * @brief Reconnect to the device. + * + * @param[in] handle + * @return VIKIT_RET_SUCCESS on success; otherwise, a non-zero error code. + */ +FAYS_VIK_API int FAYS_VIK_ReConnect (void* handle); + +/* + * @brief Register IMU callback function. + * + * @param[in] handle + * @param[in] imuCallback Callback function for new IMU data. + * @return Registration success or failure. + */ +FAYS_VIK_API int FAYS_VIK_RegisterImuCallback (void* handle, FAYS_VIK_ImuCallback imuCallback); + + +/** + * @brief Dump calibration parameters to a yaml file. + * + * @param[in] handle The handle to the ViKit instance. + * @param[in] outdir The output directory path. + * @return Dump success or failure. + */ +FAYS_VIK_API int FAYS_VIK_DumpCalib (void* handle, const char* outdir = "./"); + + + + +/**************************************************************************** + * Offline Fays ViKit SDK + ****************************************************************************/ + +/** + * @brief Create offline functionality handle by loading specified config file. + * @details Initializes offline module context, parses and loads configuration parameters, + * and creates a valid handle for subsequent offline API invocations. + * + * @param[out] offlineHandle Double pointer to receive the created module handle. + * @param[in] configPath Null-terminated string of configuration file path (absolute or relative). + * @return int 0 on success, non-zero error code on failure (invalid path, parse error, init failed, etc.). + * @note The returned handle must be released by @ref FAYS_VIK_Offline_DestroyHandle after use. + */ +FAYS_VIK_API int FAYS_VIK_Offline_CreateHandleWithConfig (void** offlineHandle, const char* configPath); + + +/** + * @brief Destroy offline handle and release all occupied resources. + * @details Releases internal memory, cache and device resources allocated by offline module. + * The handle will be invalidated and must not be used after destruction. + * + * @param[in,out] offlineHandle Valid offline context handle to be destroyed. + * @return int 0 on success, non-zero error code on failure. + * @note Do not call any offline APIs with the handle after destruction. + */ +FAYS_VIK_API int FAYS_VIK_Offline_DestroyHandle (void* offlineHandle); + +/** + * @brief Process single input frame with offline algorithm pipeline. + * @details Executes image analysis and processing logic, outputs processed result image data. + * + * @param[in] offlineHandle Valid offline module handle created in advance. + * @param[in] input Const input image buffer, read-only. + * @param[out] output Output image buffer to store processed result. Must be allocated by caller with sufficient size. + * @param[in] timeoutMs Process timeout in milliseconds, default value: 1000. + * @return int 0 on normal execution, non-zero on timeout/abnormal termination. + */ +FAYS_VIK_API int FAYS_VIK_Offline_ProcessFrame (void* offlineHandle, const AtrakImage* const input, AtrakImage* output, int timeoutMs = 1000); \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_vikit_version.h b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_vikit_version.h new file mode 100644 index 0000000000000000000000000000000000000000..ce26d6076c9107fe6746d171930191094ccf89ed --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/include/fays_atrak/fays_vikit_version.h @@ -0,0 +1,14 @@ +#ifndef _FAYS_VIK_VERSION_H_ +#define _FAYS_VIK_VERSION_H_ + +#define FAYS_VIK_VERSION_MAJOR 3 +#define FAYS_VIK_VERSION_MINOR 9 +#define FAYS_VIK_VERSION_PATCH 1 + +#define FAYS_TO_STRING_HELPER(x) #x +#define FAYS_TO_STRING(x) FAYS_TO_STRING_HELPER(x) +#define FAYS_VIK_VERSION_STRING \ + FAYS_TO_STRING(FAYS_VIK_VERSION_MAJOR) "." \ + FAYS_TO_STRING(FAYS_VIK_VERSION_MINOR) "." \ + FAYS_TO_STRING(FAYS_VIK_VERSION_PATCH) +#endif /* _FAYS_VIK_VERSION_H_ */ \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/lib/aarch64/libfays_vikit.so b/collector/tools/fayssense_depth_sdk/sdk/lib/aarch64/libfays_vikit.so new file mode 100755 index 0000000000000000000000000000000000000000..daa4ffbbd2b822479579fc4dae3610f167929c39 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/lib/aarch64/libfays_vikit.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9ff8122e867e65e6d6821d812878076209f16b70f1d01c5e812c878f79176954 +size 262240 diff --git a/collector/tools/fayssense_depth_sdk/sdk/lib/aarch64/libfayssense_aikit_depth.so b/collector/tools/fayssense_depth_sdk/sdk/lib/aarch64/libfayssense_aikit_depth.so new file mode 100755 index 0000000000000000000000000000000000000000..b6e80f46b320146407c34e03a1afd952911da114 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/lib/aarch64/libfayssense_aikit_depth.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9aa96f843a5bee4468975f522b151e434bd77fcb3f6711675b93069f46b55b9 +size 254336 diff --git a/collector/tools/fayssense_depth_sdk/sdk/lib/x86_64/libfays_vikit.so b/collector/tools/fayssense_depth_sdk/sdk/lib/x86_64/libfays_vikit.so new file mode 100755 index 0000000000000000000000000000000000000000..6c6ad674cbc6e4e40be60951fc36b298a6eed95a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/lib/x86_64/libfays_vikit.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a4c08023278c76e06a0cda8cdefa1838499cf21569a2e163a70df8df8251658 +size 299312 diff --git a/collector/tools/fayssense_depth_sdk/sdk/lib/x86_64/libfayssense_aikit_depth.so b/collector/tools/fayssense_depth_sdk/sdk/lib/x86_64/libfayssense_aikit_depth.so new file mode 100755 index 0000000000000000000000000000000000000000..85b80f852f057ccfd444c2332c019426edc2f32f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/lib/x86_64/libfayssense_aikit_depth.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f66ccf0f04aafaa9c59d2c14aaa698d0fbb46516f966baa14d476ec7395f1196 +size 303776 diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3cf62d2accd398b0f5359637d0e4dfbdde5b1331 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco.hpp @@ -0,0 +1,604 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_ARUCO_HPP__ +#define __OPENCV_ARUCO_HPP__ + +#include +#include +#include "opencv2/aruco/dictionary.hpp" + +/** + * @defgroup aruco ArUco Marker Detection + * This module is dedicated to square fiducial markers (also known as Augmented Reality Markers) + * These markers are useful for easy, fast and robust camera pose estimation.ç + * + * The main functionalities are: + * - Detection of markers in an image + * - Pose estimation from a single marker or from a board/set of markers + * - Detection of ChArUco board for high subpixel accuracy + * - Camera calibration from both, ArUco boards and ChArUco boards. + * - Detection of ChArUco diamond markers + * The samples directory includes easy examples of how to use the module. + * + * The implementation is based on the ArUco Library by R. Muñoz-Salinas and S. Garrido-Jurado @cite Aruco2014. + * + * Markers can also be detected based on the AprilTag 2 @cite wang2016iros fiducial detection method. + * + * @sa S. Garrido-Jurado, R. Muñoz-Salinas, F. J. Madrid-Cuevas, and M. J. Marín-Jiménez. 2014. + * "Automatic generation and detection of highly reliable fiducial markers under occlusion". + * Pattern Recogn. 47, 6 (June 2014), 2280-2292. DOI=10.1016/j.patcog.2014.01.005 + * + * @sa http://www.uco.es/investiga/grupos/ava/node/26 + * + * This module has been originally developed by Sergio Garrido-Jurado as a project + * for Google Summer of Code 2015 (GSoC 15). + * + * +*/ + +namespace cv { +namespace aruco { + +//! @addtogroup aruco +//! @{ + +enum CornerRefineMethod{ + CORNER_REFINE_NONE, ///< Tag and corners detection based on the ArUco approach + CORNER_REFINE_SUBPIX, ///< ArUco approach and refine the corners locations using corner subpixel accuracy + CORNER_REFINE_CONTOUR, ///< ArUco approach and refine the corners locations using the contour-points line fitting + CORNER_REFINE_APRILTAG, ///< Tag and corners detection based on the AprilTag 2 approach @cite wang2016iros +}; + +/** + * @brief Parameters for the detectMarker process: + * - adaptiveThreshWinSizeMin: minimum window size for adaptive thresholding before finding + * contours (default 3). + * - adaptiveThreshWinSizeMax: maximum window size for adaptive thresholding before finding + * contours (default 23). + * - adaptiveThreshWinSizeStep: increments from adaptiveThreshWinSizeMin to adaptiveThreshWinSizeMax + * during the thresholding (default 10). + * - adaptiveThreshConstant: constant for adaptive thresholding before finding contours (default 7) + * - minMarkerPerimeterRate: determine minimum perimeter for marker contour to be detected. This + * is defined as a rate respect to the maximum dimension of the input image (default 0.03). + * - maxMarkerPerimeterRate: determine maximum perimeter for marker contour to be detected. This + * is defined as a rate respect to the maximum dimension of the input image (default 4.0). + * - polygonalApproxAccuracyRate: minimum accuracy during the polygonal approximation process to + * determine which contours are squares. + * - minCornerDistanceRate: minimum distance between corners for detected markers relative to its + * perimeter (default 0.05) + * - minDistanceToBorder: minimum distance of any corner to the image border for detected markers + * (in pixels) (default 3) + * - minMarkerDistanceRate: minimum mean distance beetween two marker corners to be considered + * similar, so that the smaller one is removed. The rate is relative to the smaller perimeter + * of the two markers (default 0.05). + * - cornerRefinementMethod: corner refinement method. (CORNER_REFINE_NONE, no refinement. + * CORNER_REFINE_SUBPIX, do subpixel refinement. CORNER_REFINE_CONTOUR use contour-Points, + * CORNER_REFINE_APRILTAG use the AprilTag2 approach) + * - cornerRefinementWinSize: window size for the corner refinement process (in pixels) (default 5). + * - cornerRefinementMaxIterations: maximum number of iterations for stop criteria of the corner + * refinement process (default 30). + * - cornerRefinementMinAccuracy: minimum error for the stop cristeria of the corner refinement + * process (default: 0.1) + * - markerBorderBits: number of bits of the marker border, i.e. marker border width (default 1). + * - perspectiveRemovePixelPerCell: number of bits (per dimension) for each cell of the marker + * when removing the perspective (default 8). + * - perspectiveRemoveIgnoredMarginPerCell: width of the margin of pixels on each cell not + * considered for the determination of the cell bit. Represents the rate respect to the total + * size of the cell, i.e. perspectiveRemovePixelPerCell (default 0.13) + * - maxErroneousBitsInBorderRate: maximum number of accepted erroneous bits in the border (i.e. + * number of allowed white bits in the border). Represented as a rate respect to the total + * number of bits per marker (default 0.35). + * - minOtsuStdDev: minimun standard deviation in pixels values during the decodification step to + * apply Otsu thresholding (otherwise, all the bits are set to 0 or 1 depending on mean higher + * than 128 or not) (default 5.0) + * - errorCorrectionRate error correction rate respect to the maximun error correction capability + * for each dictionary. (default 0.6). + * - aprilTagMinClusterPixels: reject quads containing too few pixels. + * - aprilTagMaxNmaxima: how many corner candidates to consider when segmenting a group of pixels into a quad. + * - aprilTagCriticalRad: Reject quads where pairs of edges have angles that are close to straight or close to + * 180 degrees. Zero means that no quads are rejected. (In radians). + * - aprilTagMaxLineFitMse: When fitting lines to the contours, what is the maximum mean squared error + * allowed? This is useful in rejecting contours that are far from being quad shaped; rejecting + * these quads "early" saves expensive decoding processing. + * - aprilTagMinWhiteBlackDiff: When we build our model of black & white pixels, we add an extra check that + * the white model must be (overall) brighter than the black model. How much brighter? (in pixel values, [0,255]). + * - aprilTagDeglitch: should the thresholded image be deglitched? Only useful for very noisy images + * - aprilTagQuadDecimate: Detection of quads can be done on a lower-resolution image, improving speed at a + * cost of pose accuracy and a slight decrease in detection rate. Decoding the binary payload is still + * done at full resolution. + * - aprilTagQuadSigma: What Gaussian blur should be applied to the segmented image (used for quad detection?) + * Parameter is the standard deviation in pixels. Very noisy images benefit from non-zero values (e.g. 0.8). + * - detectInvertedMarker: to check if there is a white marker. In order to generate a "white" marker just + * invert a normal marker by using a tilde, ~markerImage. (default false) + */ +struct CV_EXPORTS_W DetectorParameters { + + DetectorParameters(); + + CV_WRAP static Ptr create(); + + CV_PROP_RW int adaptiveThreshWinSizeMin; + CV_PROP_RW int adaptiveThreshWinSizeMax; + CV_PROP_RW int adaptiveThreshWinSizeStep; + CV_PROP_RW double adaptiveThreshConstant; + CV_PROP_RW double minMarkerPerimeterRate; + CV_PROP_RW double maxMarkerPerimeterRate; + CV_PROP_RW double polygonalApproxAccuracyRate; + CV_PROP_RW double minCornerDistanceRate; + CV_PROP_RW int minDistanceToBorder; + CV_PROP_RW double minMarkerDistanceRate; + CV_PROP_RW int cornerRefinementMethod; + CV_PROP_RW int cornerRefinementWinSize; + CV_PROP_RW int cornerRefinementMaxIterations; + CV_PROP_RW double cornerRefinementMinAccuracy; + CV_PROP_RW int markerBorderBits; + CV_PROP_RW int perspectiveRemovePixelPerCell; + CV_PROP_RW double perspectiveRemoveIgnoredMarginPerCell; + CV_PROP_RW double maxErroneousBitsInBorderRate; + CV_PROP_RW double minOtsuStdDev; + CV_PROP_RW double errorCorrectionRate; + + // April :: User-configurable parameters. + CV_PROP_RW float aprilTagQuadDecimate; + CV_PROP_RW float aprilTagQuadSigma; + + // April :: Internal variables + CV_PROP_RW int aprilTagMinClusterPixels; + CV_PROP_RW int aprilTagMaxNmaxima; + CV_PROP_RW float aprilTagCriticalRad; + CV_PROP_RW float aprilTagMaxLineFitMse; + CV_PROP_RW int aprilTagMinWhiteBlackDiff; + CV_PROP_RW int aprilTagDeglitch; + + // to detect white (inverted) markers + CV_PROP_RW bool detectInvertedMarker; +}; + + + +/** + * @brief Basic marker detection + * + * @param image input image + * @param dictionary indicates the type of markers that will be searched + * @param corners vector of detected marker corners. For each marker, its four corners + * are provided, (e.g std::vector > ). For N detected markers, + * the dimensions of this array is Nx4. The order of the corners is clockwise. + * @param ids vector of identifiers of the detected markers. The identifier is of type int + * (e.g. std::vector). For N detected markers, the size of ids is also N. + * The identifiers have the same order than the markers in the imgPoints array. + * @param parameters marker detection parameters + * @param rejectedImgPoints contains the imgPoints of those squares whose inner code has not a + * correct codification. Useful for debugging purposes. + * @param cameraMatrix optional input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeff optional vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * + * Performs marker detection in the input image. Only markers included in the specific dictionary + * are searched. For each detected marker, it returns the 2D position of its corner in the image + * and its corresponding identifier. + * Note that this function does not perform pose estimation. + * @sa estimatePoseSingleMarkers, estimatePoseBoard + * + */ +CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr &dictionary, OutputArrayOfArrays corners, + OutputArray ids, const Ptr ¶meters = DetectorParameters::create(), + OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray()); + + + +/** + * @brief Pose estimation for single markers + * + * @param corners vector of already detected markers corners. For each marker, its four corners + * are provided, (e.g std::vector > ). For N detected markers, + * the dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @sa detectMarkers + * @param markerLength the length of the markers' side. The returning translation vectors will + * be in the same unit. Normally, unit is meters. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvecs array of output rotation vectors (@sa Rodrigues) (e.g. std::vector). + * Each element in rvecs corresponds to the specific marker in imgPoints. + * @param tvecs array of output translation vectors (e.g. std::vector). + * Each element in tvecs corresponds to the specific marker in imgPoints. + * @param _objPoints array of object points of all the marker corners + * + * This function receives the detected markers and returns their pose estimation respect to + * the camera individually. So for each marker, one rotation and translation vector is returned. + * The returned transformation is the one that transforms points from each marker coordinate system + * to the camera coordinate system. + * The marker corrdinate system is centered on the middle of the marker, with the Z axis + * perpendicular to the marker plane. + * The coordinates of the four corners of the marker in its own coordinate system are: + * (-markerLength/2, markerLength/2, 0), (markerLength/2, markerLength/2, 0), + * (markerLength/2, -markerLength/2, 0), (-markerLength/2, -markerLength/2, 0) + */ +CV_EXPORTS_W void estimatePoseSingleMarkers(InputArrayOfArrays corners, float markerLength, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvecs, OutputArray tvecs, OutputArray _objPoints = noArray()); + + + +/** + * @brief Board of markers + * + * A board is a set of markers in the 3D space with a common coordinate system. + * The common form of a board of marker is a planar (2D) board, however any 3D layout can be used. + * A Board object is composed by: + * - The object points of the marker corners, i.e. their coordinates respect to the board system. + * - The dictionary which indicates the type of markers of the board + * - The identifier of all the markers in the board. + */ +class CV_EXPORTS_W Board { + + public: + /** + * @brief Provide way to create Board by passing necessary data. Specially needed in Python. + * + * @param objPoints array of object points of all the marker corners in the board + * @param dictionary the dictionary of markers employed for this board + * @param ids vector of the identifiers of the markers in the board + * + */ + CV_WRAP static Ptr create(InputArrayOfArrays objPoints, const Ptr &dictionary, InputArray ids); + /// array of object points of all the marker corners in the board + /// each marker include its 4 corners in CCW order. For M markers, the size is Mx4. + CV_PROP std::vector< std::vector< Point3f > > objPoints; + + /// the dictionary of markers employed for this board + CV_PROP Ptr dictionary; + + /// vector of the identifiers of the markers in the board (same size than objPoints) + /// The identifiers refers to the board dictionary + CV_PROP std::vector< int > ids; +}; + + + +/** + * @brief Planar board with grid arrangement of markers + * More common type of board. All markers are placed in the same plane in a grid arrangement. + * The board can be drawn using drawPlanarBoard() function (@sa drawPlanarBoard) + */ +class CV_EXPORTS_W GridBoard : public Board { + + public: + /** + * @brief Draw a GridBoard + * + * @param outSize size of the output image in pixels. + * @param img output image with the board. The size of this image will be outSize + * and the board will be on the center, keeping the board proportions. + * @param marginSize minimum margins (in pixels) of the board in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of the GridBoard, ready to be printed. + */ + CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); + + + /** + * @brief Create a GridBoard object + * + * @param markersX number of markers in X direction + * @param markersY number of markers in Y direction + * @param markerLength marker side length (normally in meters) + * @param markerSeparation separation between two markers (same unit as markerLength) + * @param dictionary dictionary of markers indicating the type of markers + * @param firstMarker id of first marker in dictionary to use on board. + * @return the output GridBoard object + * + * This functions creates a GridBoard object given the number of markers in each direction and + * the marker size and marker separation. + */ + CV_WRAP static Ptr create(int markersX, int markersY, float markerLength, + float markerSeparation, const Ptr &dictionary, int firstMarker = 0); + + /** + * + */ + CV_WRAP Size getGridSize() const { return Size(_markersX, _markersY); } + + /** + * + */ + CV_WRAP float getMarkerLength() const { return _markerLength; } + + /** + * + */ + CV_WRAP float getMarkerSeparation() const { return _markerSeparation; } + + + private: + // number of markers in X and Y directions + int _markersX, _markersY; + + // marker side length (normally in meters) + float _markerLength; + + // separation between markers in the grid + float _markerSeparation; +}; + + + +/** + * @brief Pose estimation for a board of markers + * + * @param corners vector of already detected markers corners. For each marker, its four corners + * are provided, (e.g std::vector > ). For N detected markers, the + * dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @param ids list of identifiers for each marker in corners + * @param board layout of markers in the board. The layout is composed by the marker identifiers + * and the positions of each marker corner in the board reference system. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvec Output vector (e.g. cv::Mat) corresponding to the rotation vector of the board + * (see cv::Rodrigues). Used as initial guess if not empty. + * @param tvec Output vector (e.g. cv::Mat) corresponding to the translation vector of the board. + * @param useExtrinsicGuess defines whether initial guess for \b rvec and \b tvec will be used or not. + * Used as initial guess if not empty. + * + * This function receives the detected markers and returns the pose of a marker board composed + * by those markers. + * A Board of marker has a single world coordinate system which is defined by the board layout. + * The returned transformation is the one that transforms points from the board coordinate system + * to the camera coordinate system. + * Input markers that are not included in the board layout are ignored. + * The function returns the number of markers from the input employed for the board pose estimation. + * Note that returning a 0 means the pose has not been estimated. + */ +CV_EXPORTS_W int estimatePoseBoard(InputArrayOfArrays corners, InputArray ids, const Ptr &board, + InputArray cameraMatrix, InputArray distCoeffs, InputOutputArray rvec, + InputOutputArray tvec, bool useExtrinsicGuess = false); + + + + +/** + * @brief Refind not detected markers based on the already detected and the board layout + * + * @param image input image + * @param board layout of markers in the board. + * @param detectedCorners vector of already detected marker corners. + * @param detectedIds vector of already detected marker identifiers. + * @param rejectedCorners vector of rejected candidates during the marker detection process. + * @param cameraMatrix optional input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs optional vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param minRepDistance minimum distance between the corners of the rejected candidate and the + * reprojected marker in order to consider it as a correspondence. + * @param errorCorrectionRate rate of allowed erroneous bits respect to the error correction + * capability of the used dictionary. -1 ignores the error correction step. + * @param checkAllOrders Consider the four posible corner orders in the rejectedCorners array. + * If it set to false, only the provided corner order is considered (default true). + * @param recoveredIdxs Optional array to returns the indexes of the recovered candidates in the + * original rejectedCorners array. + * @param parameters marker detection parameters + * + * This function tries to find markers that were not detected in the basic detecMarkers function. + * First, based on the current detected marker and the board layout, the function interpolates + * the position of the missing markers. Then it tries to find correspondence between the reprojected + * markers and the rejected candidates based on the minRepDistance and errorCorrectionRate + * parameters. + * If camera parameters and distortion coefficients are provided, missing markers are reprojected + * using projectPoint function. If not, missing marker projections are interpolated using global + * homography, and all the marker corners in the board must have the same Z coordinate. + */ +CV_EXPORTS_W void refineDetectedMarkers( + InputArray image,const Ptr &board, InputOutputArrayOfArrays detectedCorners, + InputOutputArray detectedIds, InputOutputArrayOfArrays rejectedCorners, + InputArray cameraMatrix = noArray(), InputArray distCoeffs = noArray(), + float minRepDistance = 10.f, float errorCorrectionRate = 3.f, bool checkAllOrders = true, + OutputArray recoveredIdxs = noArray(), const Ptr ¶meters = DetectorParameters::create()); + + + +/** + * @brief Draw detected markers in image + * + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param corners positions of marker corners on input image. + * (e.g std::vector > ). For N detected markers, the dimensions of + * this array should be Nx4. The order of the corners should be clockwise. + * @param ids vector of identifiers for markers in markersCorners . + * Optional, if not provided, ids are not painted. + * @param borderColor color of marker borders. Rest of colors (text color and first corner color) + * are calculated based on this one to improve visualization. + * + * Given an array of detected marker corners and its corresponding ids, this functions draws + * the markers in the image. The marker borders are painted and the markers identifiers if provided. + * Useful for debugging purposes. + */ +CV_EXPORTS_W void drawDetectedMarkers(InputOutputArray image, InputArrayOfArrays corners, + InputArray ids = noArray(), + Scalar borderColor = Scalar(0, 255, 0)); + + + +/** + * @brief Draw coordinate system axis from pose estimation + * + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvec rotation vector of the coordinate system that will be drawn. (@sa Rodrigues). + * @param tvec translation vector of the coordinate system that will be drawn. + * @param length length of the painted axis in the same unit than tvec (usually in meters) + * + * Given the pose estimation of a marker or board, this function draws the axis of the world + * coordinate system, i.e. the system centered on the marker/board. Useful for debugging purposes. + * + * @deprecated use cv::drawFrameAxes + */ +CV_EXPORTS_W void drawAxis(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs, + InputArray rvec, InputArray tvec, float length); + + + +/** + * @brief Draw a canonical marker image + * + * @param dictionary dictionary of markers indicating the type of markers + * @param id identifier of the marker that will be returned. It has to be a valid id + * in the specified dictionary. + * @param sidePixels size of the image in pixels + * @param img output image with the marker + * @param borderBits width of the marker border. + * + * This function returns a marker image in its canonical form (i.e. ready to be printed) + */ +CV_EXPORTS_W void drawMarker(const Ptr &dictionary, int id, int sidePixels, OutputArray img, + int borderBits = 1); + + + +/** + * @brief Draw a planar board + * @sa _drawPlanarBoardImpl + * + * @param board layout of the board that will be drawn. The board should be planar, + * z coordinate is ignored + * @param outSize size of the output image in pixels. + * @param img output image with the board. The size of this image will be outSize + * and the board will be on the center, keeping the board proportions. + * @param marginSize minimum margins (in pixels) of the board in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of a planar board, ready to be printed. It assumes + * the Board layout specified is planar by ignoring the z coordinates of the object points. + */ +CV_EXPORTS_W void drawPlanarBoard(const Ptr &board, Size outSize, OutputArray img, + int marginSize = 0, int borderBits = 1); + + + +/** + * @brief Implementation of drawPlanarBoard that accepts a raw Board pointer. + */ +void _drawPlanarBoardImpl(Board *board, Size outSize, OutputArray img, + int marginSize = 0, int borderBits = 1); + + + +/** + * @brief Calibrate a camera using aruco markers + * + * @param corners vector of detected marker corners in all frames. + * The corners should have the same format returned by detectMarkers (see #detectMarkers). + * @param ids list of identifiers for each marker in corners + * @param counter number of markers in each frame so that corners and ids can be split + * @param board Marker Board layout + * @param imageSize Size of the image used only to initialize the intrinsic camera matrix. + * @param cameraMatrix Output 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS + * and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be + * initialized before calling the function. + * @param distCoeffs Output vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each board view + * (e.g. std::vector>). That is, each k-th rotation vector together with the corresponding + * k-th translation vector (see the next output parameter description) brings the board pattern + * from the model coordinate space (in which object points are specified) to the world coordinate + * space, that is, a real position of the board pattern in the k-th pattern view (k=0.. *M* -1). + * @param tvecs Output vector of translation vectors estimated for each pattern view. + * @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. + * Order of deviations values: + * \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, + * s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. + * @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. + * Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, + * \f$R_i, T_i\f$ are concatenated 1x3 vectors. + * @param perViewErrors Output vector of average re-projection errors estimated for each pattern view. + * @param flags flags Different flags for the calibration process (see #calibrateCamera for details). + * @param criteria Termination criteria for the iterative optimization algorithm. + * + * This function calibrates a camera using an Aruco Board. The function receives a list of + * detected markers from several views of the Board. The process is similar to the chessboard + * calibration in calibrateCamera(). The function returns the final re-projection error. + */ +CV_EXPORTS_AS(calibrateCameraArucoExtended) double calibrateCameraAruco( + InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics, + OutputArray perViewErrors, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + + +/** @brief It's the same function as #calibrateCameraAruco but without calibration error estimation. + */ +CV_EXPORTS_W double calibrateCameraAruco( + InputArrayOfArrays corners, InputArray ids, InputArray counter, const Ptr &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs = noArray(), OutputArrayOfArrays tvecs = noArray(), int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + + +/** + * @brief Given a board configuration and a set of detected markers, returns the corresponding + * image points and object points to call solvePnP + * + * @param board Marker board layout. + * @param detectedCorners List of detected marker corners of the board. + * @param detectedIds List of identifiers for each marker. + * @param objPoints Vector of vectors of board marker points in the board coordinate space. + * @param imgPoints Vector of vectors of the projections of board marker corner points. +*/ +CV_EXPORTS_W void getBoardObjectAndImagePoints(const Ptr &board, InputArrayOfArrays detectedCorners, + InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints); + + +//! @} +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco/charuco.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco/charuco.hpp new file mode 100644 index 0000000000000000000000000000000000000000..22e0d052f2f1b98be78001c153968b15d94b9cb9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco/charuco.hpp @@ -0,0 +1,343 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_CHARUCO_HPP__ +#define __OPENCV_CHARUCO_HPP__ + +#include +#include +#include + + +namespace cv { +namespace aruco { + +//! @addtogroup aruco +//! @{ + + +/** + * @brief ChArUco board + * Specific class for ChArUco boards. A ChArUco board is a planar board where the markers are placed + * inside the white squares of a chessboard. The benefits of ChArUco boards is that they provide + * both, ArUco markers versatility and chessboard corner precision, which is important for + * calibration and pose estimation. + * This class also allows the easy creation and drawing of ChArUco boards. + */ +class CV_EXPORTS_W CharucoBoard : public Board { + + public: + // vector of chessboard 3D corners precalculated + CV_PROP std::vector< Point3f > chessboardCorners; + + // for each charuco corner, nearest marker id and nearest marker corner id of each marker + CV_PROP std::vector< std::vector< int > > nearestMarkerIdx; + CV_PROP std::vector< std::vector< int > > nearestMarkerCorners; + + /** + * @brief Draw a ChArUco board + * + * @param outSize size of the output image in pixels. + * @param img output image with the board. The size of this image will be outSize + * and the board will be on the center, keeping the board proportions. + * @param marginSize minimum margins (in pixels) of the board in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of the ChArUco board, ready to be printed. + */ + CV_WRAP void draw(Size outSize, OutputArray img, int marginSize = 0, int borderBits = 1); + + + /** + * @brief Create a CharucoBoard object + * + * @param squaresX number of chessboard squares in X direction + * @param squaresY number of chessboard squares in Y direction + * @param squareLength chessboard square side length (normally in meters) + * @param markerLength marker side length (same unit than squareLength) + * @param dictionary dictionary of markers indicating the type of markers. + * The first markers in the dictionary are used to fill the white chessboard squares. + * @return the output CharucoBoard object + * + * This functions creates a CharucoBoard object given the number of squares in each direction + * and the size of the markers and chessboard squares. + */ + CV_WRAP static Ptr create(int squaresX, int squaresY, float squareLength, + float markerLength, const Ptr &dictionary); + + /** + * + */ + CV_WRAP Size getChessboardSize() const { return Size(_squaresX, _squaresY); } + + /** + * + */ + CV_WRAP float getSquareLength() const { return _squareLength; } + + /** + * + */ + CV_WRAP float getMarkerLength() const { return _markerLength; } + + private: + void _getNearestMarkerCorners(); + + // number of markers in X and Y directions + int _squaresX, _squaresY; + + // size of chessboard squares side (normally in meters) + float _squareLength; + + // marker side lenght (normally in meters) + float _markerLength; +}; + + + + +/** + * @brief Interpolate position of ChArUco board corners + * @param markerCorners vector of already detected markers corners. For each marker, its four + * corners are provided, (e.g std::vector > ). For N detected markers, the + * dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @param markerIds list of identifiers for each marker in corners + * @param image input image necesary for corner refinement. Note that markers are not detected and + * should be sent in corners and ids parameters. + * @param board layout of ChArUco board. + * @param charucoCorners interpolated chessboard corners + * @param charucoIds interpolated chessboard corners identifiers + * @param cameraMatrix optional 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs optional vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param minMarkers number of adjacent markers that must be detected to return a charuco corner + * + * This function receives the detected markers and returns the 2D position of the chessboard corners + * from a ChArUco board using the detected Aruco markers. If camera parameters are provided, + * the process is based in an approximated pose estimation, else it is based on local homography. + * Only visible corners are returned. For each corner, its corresponding identifier is + * also returned in charucoIds. + * The function returns the number of interpolated corners. + */ +CV_EXPORTS_W int interpolateCornersCharuco(InputArrayOfArrays markerCorners, InputArray markerIds, + InputArray image, const Ptr &board, + OutputArray charucoCorners, OutputArray charucoIds, + InputArray cameraMatrix = noArray(), + InputArray distCoeffs = noArray(), int minMarkers = 2); + + + + +/** + * @brief Pose estimation for a ChArUco board given some of their corners + * @param charucoCorners vector of detected charuco corners + * @param charucoIds list of identifiers for each corner in charucoCorners + * @param board layout of ChArUco board. + * @param cameraMatrix input 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ + * @param distCoeffs vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvec Output vector (e.g. cv::Mat) corresponding to the rotation vector of the board + * (see cv::Rodrigues). + * @param tvec Output vector (e.g. cv::Mat) corresponding to the translation vector of the board. + * @param useExtrinsicGuess defines whether initial guess for \b rvec and \b tvec will be used or not. + * + * This function estimates a Charuco board pose from some detected corners. + * The function checks if the input corners are enough and valid to perform pose estimation. + * If pose estimation is valid, returns true, else returns false. + */ +CV_EXPORTS_W bool estimatePoseCharucoBoard(InputArray charucoCorners, InputArray charucoIds, + const Ptr &board, InputArray cameraMatrix, + InputArray distCoeffs, InputOutputArray rvec, + InputOutputArray tvec, bool useExtrinsicGuess = false); + + + + +/** + * @brief Draws a set of Charuco corners + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param charucoCorners vector of detected charuco corners + * @param charucoIds list of identifiers for each corner in charucoCorners + * @param cornerColor color of the square surrounding each corner + * + * This function draws a set of detected Charuco corners. If identifiers vector is provided, it also + * draws the id of each corner. + */ +CV_EXPORTS_W void drawDetectedCornersCharuco(InputOutputArray image, InputArray charucoCorners, + InputArray charucoIds = noArray(), + Scalar cornerColor = Scalar(255, 0, 0)); + + + +/** + * @brief Calibrate a camera using Charuco corners + * + * @param charucoCorners vector of detected charuco corners per frame + * @param charucoIds list of identifiers for each corner in charucoCorners per frame + * @param board Marker Board layout + * @param imageSize input image size + * @param cameraMatrix Output 3x3 floating-point camera matrix + * \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS + * and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be + * initialized before calling the function. + * @param distCoeffs Output vector of distortion coefficients + * \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements + * @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each board view + * (e.g. std::vector>). That is, each k-th rotation vector together with the corresponding + * k-th translation vector (see the next output parameter description) brings the board pattern + * from the model coordinate space (in which object points are specified) to the world coordinate + * space, that is, a real position of the board pattern in the k-th pattern view (k=0.. *M* -1). + * @param tvecs Output vector of translation vectors estimated for each pattern view. + * @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. + * Order of deviations values: + * \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, + * s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. + * @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. + * Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, + * \f$R_i, T_i\f$ are concatenated 1x3 vectors. + * @param perViewErrors Output vector of average re-projection errors estimated for each pattern view. + * @param flags flags Different flags for the calibration process (see #calibrateCamera for details). + * @param criteria Termination criteria for the iterative optimization algorithm. + * + * This function calibrates a camera using a set of corners of a Charuco Board. The function + * receives a list of detected corners and its identifiers from several views of the Board. + * The function returns the final re-projection error. + */ +CV_EXPORTS_AS(calibrateCameraCharucoExtended) double calibrateCameraCharuco( + InputArrayOfArrays charucoCorners, InputArrayOfArrays charucoIds, const Ptr &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviationsIntrinsics, OutputArray stdDeviationsExtrinsics, + OutputArray perViewErrors, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + +/** @brief It's the same function as #calibrateCameraCharuco but without calibration error estimation. +*/ +CV_EXPORTS_W double calibrateCameraCharuco( + InputArrayOfArrays charucoCorners, InputArrayOfArrays charucoIds, const Ptr &board, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs = noArray(), OutputArrayOfArrays tvecs = noArray(), int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + + + +/** + * @brief Detect ChArUco Diamond markers + * + * @param image input image necessary for corner subpixel. + * @param markerCorners list of detected marker corners from detectMarkers function. + * @param markerIds list of marker ids in markerCorners. + * @param squareMarkerLengthRate rate between square and marker length: + * squareMarkerLengthRate = squareLength/markerLength. The real units are not necessary. + * @param diamondCorners output list of detected diamond corners (4 corners per diamond). The order + * is the same than in marker corners: top left, top right, bottom right and bottom left. Similar + * format than the corners returned by detectMarkers (e.g std::vector > ). + * @param diamondIds ids of the diamonds in diamondCorners. The id of each diamond is in fact of + * type Vec4i, so each diamond has 4 ids, which are the ids of the aruco markers composing the + * diamond. + * @param cameraMatrix Optional camera calibration matrix. + * @param distCoeffs Optional camera distortion coefficients. + * + * This function detects Diamond markers from the previous detected ArUco markers. The diamonds + * are returned in the diamondCorners and diamondIds parameters. If camera calibration parameters + * are provided, the diamond search is based on reprojection. If not, diamond search is based on + * homography. Homography is faster than reprojection but can slightly reduce the detection rate. + */ +CV_EXPORTS_W void detectCharucoDiamond(InputArray image, InputArrayOfArrays markerCorners, + InputArray markerIds, float squareMarkerLengthRate, + OutputArrayOfArrays diamondCorners, OutputArray diamondIds, + InputArray cameraMatrix = noArray(), + InputArray distCoeffs = noArray()); + + + +/** + * @brief Draw a set of detected ChArUco Diamond markers + * + * @param image input/output image. It must have 1 or 3 channels. The number of channels is not + * altered. + * @param diamondCorners positions of diamond corners in the same format returned by + * detectCharucoDiamond(). (e.g std::vector > ). For N detected markers, + * the dimensions of this array should be Nx4. The order of the corners should be clockwise. + * @param diamondIds vector of identifiers for diamonds in diamondCorners, in the same format + * returned by detectCharucoDiamond() (e.g. std::vector). + * Optional, if not provided, ids are not painted. + * @param borderColor color of marker borders. Rest of colors (text color and first corner color) + * are calculated based on this one. + * + * Given an array of detected diamonds, this functions draws them in the image. The marker borders + * are painted and the markers identifiers if provided. + * Useful for debugging purposes. + */ +CV_EXPORTS_W void drawDetectedDiamonds(InputOutputArray image, InputArrayOfArrays diamondCorners, + InputArray diamondIds = noArray(), + Scalar borderColor = Scalar(0, 0, 255)); + + + + +/** + * @brief Draw a ChArUco Diamond marker + * + * @param dictionary dictionary of markers indicating the type of markers. + * @param ids list of 4 ids for each ArUco marker in the ChArUco marker. + * @param squareLength size of the chessboard squares in pixels. + * @param markerLength size of the markers in pixels. + * @param img output image with the marker. The size of this image will be + * 3*squareLength + 2*marginSize,. + * @param marginSize minimum margins (in pixels) of the marker in the output image + * @param borderBits width of the marker borders. + * + * This function return the image of a ChArUco marker, ready to be printed. + */ +// TODO cannot be exported yet; conversion from/to Vec4i is not wrapped in core +CV_EXPORTS void drawCharucoDiamond(const Ptr &dictionary, Vec4i ids, int squareLength, + int markerLength, OutputArray img, int marginSize = 0, + int borderBits = 1); + + + + +//! @} +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco/dictionary.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco/dictionary.hpp new file mode 100644 index 0000000000000000000000000000000000000000..27c7e5dd734afcc8be1c5e711d2b87b843d8c8cb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/aruco/dictionary.hpp @@ -0,0 +1,212 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_DICTIONARY_HPP__ +#define __OPENCV_DICTIONARY_HPP__ + +#include + +namespace cv { +namespace aruco { + +//! @addtogroup aruco +//! @{ + + +/** + * @brief Dictionary/Set of markers. It contains the inner codification + * + * bytesList contains the marker codewords where + * - bytesList.rows is the dictionary size + * - each marker is encoded using `nbytes = ceil(markerSize*markerSize/8.)` + * - each row contains all 4 rotations of the marker, so its length is `4*nbytes` + * + * `bytesList.ptr(i)[k*nbytes + j]` is then the j-th byte of i-th marker, in its k-th rotation. + */ +class CV_EXPORTS_W Dictionary { + + public: + CV_PROP_RW Mat bytesList; // marker code information + CV_PROP_RW int markerSize; // number of bits per dimension + CV_PROP_RW int maxCorrectionBits; // maximum number of bits that can be corrected + + + /** + */ + Dictionary(const Mat &_bytesList = Mat(), int _markerSize = 0, int _maxcorr = 0); + + + /** + Dictionary(const Dictionary &_dictionary); + */ + + + /** + */ + Dictionary(const Ptr &_dictionary); + + + /** + * @see generateCustomDictionary + */ + CV_WRAP_AS(create) static Ptr create(int nMarkers, int markerSize, int randomSeed=0); + + + /** + * @see generateCustomDictionary + */ + CV_WRAP_AS(create_from) static Ptr create(int nMarkers, int markerSize, + const Ptr &baseDictionary, int randomSeed=0); + + /** + * @see getPredefinedDictionary + */ + CV_WRAP static Ptr get(int dict); + + /** + * @brief Given a matrix of bits. Returns whether if marker is identified or not. + * It returns by reference the correct id (if any) and the correct rotation + */ + bool identify(const Mat &onlyBits, int &idx, int &rotation, double maxCorrectionRate) const; + + /** + * @brief Returns the distance of the input bits to the specific id. If allRotations is true, + * the four posible bits rotation are considered + */ + int getDistanceToId(InputArray bits, int id, bool allRotations = true) const; + + + /** + * @brief Draw a canonical marker image + */ + CV_WRAP void drawMarker(int id, int sidePixels, OutputArray _img, int borderBits = 1) const; + + + /** + * @brief Transform matrix of bits to list of bytes in the 4 rotations + */ + CV_WRAP static Mat getByteListFromBits(const Mat &bits); + + + /** + * @brief Transform list of bytes to matrix of bits + */ + CV_WRAP static Mat getBitsFromByteList(const Mat &byteList, int markerSize); +}; + + + + +/** + * @brief Predefined markers dictionaries/sets + * Each dictionary indicates the number of bits and the number of markers contained + * - DICT_ARUCO_ORIGINAL: standard ArUco Library Markers. 1024 markers, 5x5 bits, 0 minimum + distance + */ +enum PREDEFINED_DICTIONARY_NAME { + DICT_4X4_50 = 0, + DICT_4X4_100, + DICT_4X4_250, + DICT_4X4_1000, + DICT_5X5_50, + DICT_5X5_100, + DICT_5X5_250, + DICT_5X5_1000, + DICT_6X6_50, + DICT_6X6_100, + DICT_6X6_250, + DICT_6X6_1000, + DICT_7X7_50, + DICT_7X7_100, + DICT_7X7_250, + DICT_7X7_1000, + DICT_ARUCO_ORIGINAL, + DICT_APRILTAG_16h5, ///< 4x4 bits, minimum hamming distance between any two codes = 5, 30 codes + DICT_APRILTAG_25h9, ///< 5x5 bits, minimum hamming distance between any two codes = 9, 35 codes + DICT_APRILTAG_36h10, ///< 6x6 bits, minimum hamming distance between any two codes = 10, 2320 codes + DICT_APRILTAG_36h11 ///< 6x6 bits, minimum hamming distance between any two codes = 11, 587 codes +}; + + +/** + * @brief Returns one of the predefined dictionaries defined in PREDEFINED_DICTIONARY_NAME + */ +CV_EXPORTS Ptr getPredefinedDictionary(PREDEFINED_DICTIONARY_NAME name); + + +/** + * @brief Returns one of the predefined dictionaries referenced by DICT_*. + */ +CV_EXPORTS_W Ptr getPredefinedDictionary(int dict); + + +/** + * @see generateCustomDictionary + */ +CV_EXPORTS_AS(custom_dictionary) Ptr generateCustomDictionary( + int nMarkers, + int markerSize, + int randomSeed=0); + + +/** + * @brief Generates a new customizable marker dictionary + * + * @param nMarkers number of markers in the dictionary + * @param markerSize number of bits per dimension of each markers + * @param baseDictionary Include the markers in this dictionary at the beginning (optional) + * @param randomSeed a user supplied seed for theRNG() + * + * This function creates a new dictionary composed by nMarkers markers and each markers composed + * by markerSize x markerSize bits. If baseDictionary is provided, its markers are directly + * included and the rest are generated based on them. If the size of baseDictionary is higher + * than nMarkers, only the first nMarkers in baseDictionary are taken and no new marker is added. + */ +CV_EXPORTS_AS(custom_dictionary_from) Ptr generateCustomDictionary( + int nMarkers, + int markerSize, + const Ptr &baseDictionary, + int randomSeed=0); + + + +//! @} +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bgsegm.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bgsegm.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8ace5d9a5e72df3cfda06f96c946d6b14a024513 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bgsegm.hpp @@ -0,0 +1,380 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_BGSEGM_HPP__ +#define __OPENCV_BGSEGM_HPP__ + +#include "opencv2/video.hpp" + +#ifdef __cplusplus + +/** @defgroup bgsegm Improved Background-Foreground Segmentation Methods +*/ + +namespace cv +{ +namespace bgsegm +{ + +//! @addtogroup bgsegm +//! @{ + +/** @brief Gaussian Mixture-based Background/Foreground Segmentation Algorithm. + +The class implements the algorithm described in @cite KB2001 . + */ +class CV_EXPORTS_W BackgroundSubtractorMOG : public BackgroundSubtractor +{ +public: + CV_WRAP virtual int getHistory() const = 0; + CV_WRAP virtual void setHistory(int nframes) = 0; + + CV_WRAP virtual int getNMixtures() const = 0; + CV_WRAP virtual void setNMixtures(int nmix) = 0; + + CV_WRAP virtual double getBackgroundRatio() const = 0; + CV_WRAP virtual void setBackgroundRatio(double backgroundRatio) = 0; + + CV_WRAP virtual double getNoiseSigma() const = 0; + CV_WRAP virtual void setNoiseSigma(double noiseSigma) = 0; +}; + +/** @brief Creates mixture-of-gaussian background subtractor + +@param history Length of the history. +@param nmixtures Number of Gaussian mixtures. +@param backgroundRatio Background ratio. +@param noiseSigma Noise strength (standard deviation of the brightness or each color channel). 0 +means some automatic value. + */ +CV_EXPORTS_W Ptr + createBackgroundSubtractorMOG(int history=200, int nmixtures=5, + double backgroundRatio=0.7, double noiseSigma=0); + + +/** @brief Background Subtractor module based on the algorithm given in @cite Gold2012 . + + Takes a series of images and returns a sequence of mask (8UC1) + images of the same size, where 255 indicates Foreground and 0 represents Background. + This class implements an algorithm described in "Visual Tracking of Human Visitors under + Variable-Lighting Conditions for a Responsive Audio Art Installation," A. Godbehere, + A. Matsukawa, K. Goldberg, American Control Conference, Montreal, June 2012. + */ +class CV_EXPORTS_W BackgroundSubtractorGMG : public BackgroundSubtractor +{ +public: + /** @brief Returns total number of distinct colors to maintain in histogram. + */ + CV_WRAP virtual int getMaxFeatures() const = 0; + /** @brief Sets total number of distinct colors to maintain in histogram. + */ + CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; + + /** @brief Returns the learning rate of the algorithm. + + It lies between 0.0 and 1.0. It determines how quickly features are "forgotten" from + histograms. + */ + CV_WRAP virtual double getDefaultLearningRate() const = 0; + /** @brief Sets the learning rate of the algorithm. + */ + CV_WRAP virtual void setDefaultLearningRate(double lr) = 0; + + /** @brief Returns the number of frames used to initialize background model. + */ + CV_WRAP virtual int getNumFrames() const = 0; + /** @brief Sets the number of frames used to initialize background model. + */ + CV_WRAP virtual void setNumFrames(int nframes) = 0; + + /** @brief Returns the parameter used for quantization of color-space. + + It is the number of discrete levels in each channel to be used in histograms. + */ + CV_WRAP virtual int getQuantizationLevels() const = 0; + /** @brief Sets the parameter used for quantization of color-space + */ + CV_WRAP virtual void setQuantizationLevels(int nlevels) = 0; + + /** @brief Returns the prior probability that each individual pixel is a background pixel. + */ + CV_WRAP virtual double getBackgroundPrior() const = 0; + /** @brief Sets the prior probability that each individual pixel is a background pixel. + */ + CV_WRAP virtual void setBackgroundPrior(double bgprior) = 0; + + /** @brief Returns the kernel radius used for morphological operations + */ + CV_WRAP virtual int getSmoothingRadius() const = 0; + /** @brief Sets the kernel radius used for morphological operations + */ + CV_WRAP virtual void setSmoothingRadius(int radius) = 0; + + /** @brief Returns the value of decision threshold. + + Decision value is the value above which pixel is determined to be FG. + */ + CV_WRAP virtual double getDecisionThreshold() const = 0; + /** @brief Sets the value of decision threshold. + */ + CV_WRAP virtual void setDecisionThreshold(double thresh) = 0; + + /** @brief Returns the status of background model update + */ + CV_WRAP virtual bool getUpdateBackgroundModel() const = 0; + /** @brief Sets the status of background model update + */ + CV_WRAP virtual void setUpdateBackgroundModel(bool update) = 0; + + /** @brief Returns the minimum value taken on by pixels in image sequence. Usually 0. + */ + CV_WRAP virtual double getMinVal() const = 0; + /** @brief Sets the minimum value taken on by pixels in image sequence. + */ + CV_WRAP virtual void setMinVal(double val) = 0; + + /** @brief Returns the maximum value taken on by pixels in image sequence. e.g. 1.0 or 255. + */ + CV_WRAP virtual double getMaxVal() const = 0; + /** @brief Sets the maximum value taken on by pixels in image sequence. + */ + CV_WRAP virtual void setMaxVal(double val) = 0; +}; + +/** @brief Creates a GMG Background Subtractor + +@param initializationFrames number of frames used to initialize the background models. +@param decisionThreshold Threshold value, above which it is marked foreground, else background. + */ +CV_EXPORTS_W Ptr createBackgroundSubtractorGMG(int initializationFrames=120, + double decisionThreshold=0.8); + +/** @brief Background subtraction based on counting. + + About as fast as MOG2 on a high end system. + More than twice faster than MOG2 on cheap hardware (benchmarked on Raspberry Pi3). + + %Algorithm by Sagi Zeevi ( https://github.com/sagi-z/BackgroundSubtractorCNT ) +*/ +class CV_EXPORTS_W BackgroundSubtractorCNT : public BackgroundSubtractor +{ +public: + // BackgroundSubtractor interface + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; + CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; + + /** @brief Returns number of frames with same pixel color to consider stable. + */ + CV_WRAP virtual int getMinPixelStability() const = 0; + /** @brief Sets the number of frames with same pixel color to consider stable. + */ + CV_WRAP virtual void setMinPixelStability(int value) = 0; + + /** @brief Returns maximum allowed credit for a pixel in history. + */ + CV_WRAP virtual int getMaxPixelStability() const = 0; + /** @brief Sets the maximum allowed credit for a pixel in history. + */ + CV_WRAP virtual void setMaxPixelStability(int value) = 0; + + /** @brief Returns if we're giving a pixel credit for being stable for a long time. + */ + CV_WRAP virtual bool getUseHistory() const = 0; + /** @brief Sets if we're giving a pixel credit for being stable for a long time. + */ + CV_WRAP virtual void setUseHistory(bool value) = 0; + + /** @brief Returns if we're parallelizing the algorithm. + */ + CV_WRAP virtual bool getIsParallel() const = 0; + /** @brief Sets if we're parallelizing the algorithm. + */ + CV_WRAP virtual void setIsParallel(bool value) = 0; +}; + +/** @brief Creates a CNT Background Subtractor + +@param minPixelStability number of frames with same pixel color to consider stable +@param useHistory determines if we're giving a pixel credit for being stable for a long time +@param maxPixelStability maximum allowed credit for a pixel in history +@param isParallel determines if we're parallelizing the algorithm + */ + +CV_EXPORTS_W Ptr +createBackgroundSubtractorCNT(int minPixelStability = 15, + bool useHistory = true, + int maxPixelStability = 15*60, + bool isParallel = true); + +enum LSBPCameraMotionCompensation { + LSBP_CAMERA_MOTION_COMPENSATION_NONE = 0, + LSBP_CAMERA_MOTION_COMPENSATION_LK +}; + +/** @brief Implementation of the different yet better algorithm which is called GSOC, as it was implemented during GSOC and was not originated from any paper. + +This algorithm demonstrates better performance on CDNET 2014 dataset compared to other algorithms in OpenCV. + */ +class CV_EXPORTS_W BackgroundSubtractorGSOC : public BackgroundSubtractor +{ +public: + // BackgroundSubtractor interface + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; + + CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; +}; + +/** @brief Background Subtraction using Local SVD Binary Pattern. More details about the algorithm can be found at @cite LGuo2016 + */ +class CV_EXPORTS_W BackgroundSubtractorLSBP : public BackgroundSubtractor +{ +public: + // BackgroundSubtractor interface + CV_WRAP virtual void apply(InputArray image, OutputArray fgmask, double learningRate=-1) CV_OVERRIDE = 0; + + CV_WRAP virtual void getBackgroundImage(OutputArray backgroundImage) const CV_OVERRIDE = 0; +}; + +/** @brief This is for calculation of the LSBP descriptors. + */ +class CV_EXPORTS_W BackgroundSubtractorLSBPDesc +{ +public: + static void calcLocalSVDValues(OutputArray localSVDValues, const Mat& frame); + + static void computeFromLocalSVDValues(OutputArray desc, const Mat& localSVDValues, const Point2i* LSBPSamplePoints); + + static void compute(OutputArray desc, const Mat& frame, const Point2i* LSBPSamplePoints); +}; + +/** @brief Creates an instance of BackgroundSubtractorGSOC algorithm. + +Implementation of the different yet better algorithm which is called GSOC, as it was implemented during GSOC and was not originated from any paper. + +@param mc Whether to use camera motion compensation. +@param nSamples Number of samples to maintain at each point of the frame. +@param replaceRate Probability of replacing the old sample - how fast the model will update itself. +@param propagationRate Probability of propagating to neighbors. +@param hitsThreshold How many positives the sample must get before it will be considered as a possible replacement. +@param alpha Scale coefficient for threshold. +@param beta Bias coefficient for threshold. +@param blinkingSupressionDecay Blinking supression decay factor. +@param blinkingSupressionMultiplier Blinking supression multiplier. +@param noiseRemovalThresholdFacBG Strength of the noise removal for background points. +@param noiseRemovalThresholdFacFG Strength of the noise removal for foreground points. + */ +CV_EXPORTS_W Ptr createBackgroundSubtractorGSOC(int mc = LSBP_CAMERA_MOTION_COMPENSATION_NONE, int nSamples = 20, float replaceRate = 0.003f, float propagationRate = 0.01f, int hitsThreshold = 32, float alpha = 0.01f, float beta = 0.0022f, float blinkingSupressionDecay = 0.1f, float blinkingSupressionMultiplier = 0.1f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f); + +/** @brief Creates an instance of BackgroundSubtractorLSBP algorithm. + +Background Subtraction using Local SVD Binary Pattern. More details about the algorithm can be found at @cite LGuo2016 + +@param mc Whether to use camera motion compensation. +@param nSamples Number of samples to maintain at each point of the frame. +@param LSBPRadius LSBP descriptor radius. +@param Tlower Lower bound for T-values. See @cite LGuo2016 for details. +@param Tupper Upper bound for T-values. See @cite LGuo2016 for details. +@param Tinc Increase step for T-values. See @cite LGuo2016 for details. +@param Tdec Decrease step for T-values. See @cite LGuo2016 for details. +@param Rscale Scale coefficient for threshold values. +@param Rincdec Increase/Decrease step for threshold values. +@param noiseRemovalThresholdFacBG Strength of the noise removal for background points. +@param noiseRemovalThresholdFacFG Strength of the noise removal for foreground points. +@param LSBPthreshold Threshold for LSBP binary string. +@param minCount Minimal number of matches for sample to be considered as foreground. + */ +CV_EXPORTS_W Ptr createBackgroundSubtractorLSBP(int mc = LSBP_CAMERA_MOTION_COMPENSATION_NONE, int nSamples = 20, int LSBPRadius = 16, float Tlower = 2.0f, float Tupper = 32.0f, float Tinc = 1.0f, float Tdec = 0.05f, float Rscale = 10.0f, float Rincdec = 0.005f, float noiseRemovalThresholdFacBG = 0.0004f, float noiseRemovalThresholdFacFG = 0.0008f, int LSBPthreshold = 8, int minCount = 2); + +/** @brief Synthetic frame sequence generator for testing background subtraction algorithms. + + It will generate the moving object on top of the background. + It will apply some distortion to the background to make the test more complex. + */ +class CV_EXPORTS_W SyntheticSequenceGenerator : public Algorithm +{ +private: + const double amplitude; + const double wavelength; + const double wavespeed; + const double objspeed; + unsigned timeStep; + Point2d pos; + Point2d dir; + Mat background; + Mat object; + RNG rng; + +public: + /** @brief Creates an instance of SyntheticSequenceGenerator. + + @param background Background image for object. + @param object Object image which will move slowly over the background. + @param amplitude Amplitude of wave distortion applied to background. + @param wavelength Length of waves in distortion applied to background. + @param wavespeed How fast waves will move. + @param objspeed How fast object will fly over background. + */ + CV_WRAP SyntheticSequenceGenerator(InputArray background, InputArray object, double amplitude, double wavelength, double wavespeed, double objspeed); + + /** @brief Obtain the next frame in the sequence. + + @param frame Output frame. + @param gtMask Output ground-truth (reference) segmentation mask object/background. + */ + CV_WRAP void getNextFrame(OutputArray frame, OutputArray gtMask); +}; + +/** @brief Creates an instance of SyntheticSequenceGenerator. + +@param background Background image for object. +@param object Object image which will move slowly over the background. +@param amplitude Amplitude of wave distortion applied to background. +@param wavelength Length of waves in distortion applied to background. +@param wavespeed How fast waves will move. +@param objspeed How fast object will fly over background. + */ +CV_EXPORTS_W Ptr createSyntheticSequenceGenerator(InputArray background, InputArray object, double amplitude = 2.0, double wavelength = 20.0, double wavespeed = 0.2, double objspeed = 6.0); + +//! @} + +} +} + +#endif +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9c7e23bd22c11ef371a119b61f7f42e9a7b10552 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired.hpp @@ -0,0 +1,60 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_BIOINSPIRED_HPP__ +#define __OPENCV_BIOINSPIRED_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/bioinspired/retina.hpp" +#include "opencv2/bioinspired/retinafasttonemapping.hpp" +#include "opencv2/bioinspired/transientareassegmentationmodule.hpp" + +/** @defgroup bioinspired Biologically inspired vision models and derivated tools + +The module provides biological visual systems models (human visual system and others). It also +provides derivated objects that take advantage of those bio-inspired models. + +@ref bioinspired_retina + +*/ + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/bioinspired.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/bioinspired.hpp new file mode 100644 index 0000000000000000000000000000000000000000..40be2854eb9c256c87a152fab3ed317aa31ba529 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/bioinspired.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/bioinspired.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/retina.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/retina.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d97a80f6f64ebf7a8986cda9337789469c0ab49f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/retina.hpp @@ -0,0 +1,454 @@ +/*#****************************************************************************** + ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + ** + ** By downloading, copying, installing or using the software you agree to this license. + ** If you do not agree to this license, do not download, install, + ** copy or use the software. + ** + ** + ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab. + ** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping. + ** + ** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications) + ** + ** Creation - enhancement process 2007-2015 + ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France + ** + ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). + ** Refer to the following research paper for more information: + ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: + ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + ** + ** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author : + ** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper: + ** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007 + ** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. + ** ====> more informations in the above cited Jeanny Heraults's book. + ** + ** License Agreement + ** For Open Source Computer Vision Library + ** + ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. + ** + ** For Human Visual System tools (bioinspired) + ** Copyright (C) 2007-2015, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved. + ** + ** Third party copyrights are property of their respective owners. + ** + ** Redistribution and use in source and binary forms, with or without modification, + ** are permitted provided that the following conditions are met: + ** + ** * Redistributions of source code must retain the above copyright notice, + ** this list of conditions and the following disclaimer. + ** + ** * Redistributions in binary form must reproduce the above copyright notice, + ** this list of conditions and the following disclaimer in the documentation + ** and/or other materials provided with the distribution. + ** + ** * The name of the copyright holders may not be used to endorse or promote products + ** derived from this software without specific prior written permission. + ** + ** This software is provided by the copyright holders and contributors "as is" and + ** any express or implied warranties, including, but not limited to, the implied + ** warranties of merchantability and fitness for a particular purpose are disclaimed. + ** In no event shall the Intel Corporation or contributors be liable for any direct, + ** indirect, incidental, special, exemplary, or consequential damages + ** (including, but not limited to, procurement of substitute goods or services; + ** loss of use, data, or profits; or business interruption) however caused + ** and on any theory of liability, whether in contract, strict liability, + ** or tort (including negligence or otherwise) arising in any way out of + ** the use of this software, even if advised of the possibility of such damage. + *******************************************************************************/ + +#ifndef __OPENCV_BIOINSPIRED_RETINA_HPP__ +#define __OPENCV_BIOINSPIRED_RETINA_HPP__ + +/** +@file +@date Jul 19, 2011 +@author Alexandre Benoit +*/ + +#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support + + +namespace cv{ +namespace bioinspired{ + +//! @addtogroup bioinspired +//! @{ + +enum { + RETINA_COLOR_RANDOM, //!< each pixel position is either R, G or B in a random choice + RETINA_COLOR_DIAGONAL,//!< color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR... + RETINA_COLOR_BAYER//!< standard bayer sampling +}; + + +/** @brief retina model parameters structure + + For better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel + + Here is the default configuration file of the retina module. It gives results such as the first + retina output shown on the top of this page. + + @code{xml} + + + + 1 + 1 + 7.5e-01 + 9.0e-01 + 5.3e-01 + 0.01 + 0.5 + 7. + 7.5e-01 + + 1 + 0. + 0. + 7. + 2.0e+00 + 9.5e-01 + 0. + 7. + + @endcode + + Here is the 'realistic" setup used to obtain the second retina output shown on the top of this page. + + @code{xml} + + + + 1 + 1 + 8.9e-01 + 9.0e-01 + 5.3e-01 + 0.3 + 0.5 + 7. + 8.9e-01 + + 1 + 0. + 0. + 7. + 2.0e+00 + 9.5e-01 + 0. + 7. + + @endcode + */ + struct RetinaParameters{ + //! Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters + struct OPLandIplParvoParameters{ + OPLandIplParvoParameters():colorMode(true), + normaliseOutput(true), + photoreceptorsLocalAdaptationSensitivity(0.75f), + photoreceptorsTemporalConstant(0.9f), + photoreceptorsSpatialConstant(0.53f), + horizontalCellsGain(0.01f), + hcellsTemporalConstant(0.5f), + hcellsSpatialConstant(7.f), + ganglionCellsSensitivity(0.75f) { } // default setup + bool colorMode, normaliseOutput; + float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity; + }; + //! Inner Plexiform Layer Magnocellular channel (IplMagno) + struct IplMagnoParameters{ + IplMagnoParameters(): + normaliseOutput(true), + parasolCells_beta(0.f), + parasolCells_tau(0.f), + parasolCells_k(7.f), + amacrinCellsTemporalCutFrequency(2.0f), + V0CompressionParameter(0.95f), + localAdaptintegration_tau(0.f), + localAdaptintegration_k(7.f) { } // default setup + bool normaliseOutput; + float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k; + }; + OPLandIplParvoParameters OPLandIplParvo; + IplMagnoParameters IplMagno; + }; + + + +/** @brief class which allows the Gipsa/Listic Labs model to be used with OpenCV. + +This retina model allows spatio-temporal image processing (applied on still images, video sequences). +As a summary, these are the retina model properties: +- It applies a spectral whithening (mid-frequency details enhancement) +- high frequency spatio-temporal noise reduction +- low frequency luminance to be reduced (luminance range compression) +- local logarithmic luminance compression allows details to be enhanced in low light conditions + +USE : this model can be used basically for spatio-temporal video effects but also for : + _using the getParvo method output matrix : texture analysiswith enhanced signal to noise ratio and enhanced details robust against input images luminance ranges + _using the getMagno method output matrix : motion analysis also with the previously cited properties + +for more information, reer to the following papers : +Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 +Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + +The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author : +take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper: +B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007 +take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions. +more informations in the above cited Jeanny Heraults's book. + */ +class CV_EXPORTS_W Retina : public Algorithm { + +public: + + + /** @brief Retreive retina input buffer size + @return the retina input buffer size + */ + CV_WRAP virtual Size getInputSize()=0; + + /** @brief Retreive retina output buffer size that can be different from the input if a spatial log + transformation is applied + @return the retina output buffer size + */ + CV_WRAP virtual Size getOutputSize()=0; + + /** @brief Try to open an XML retina parameters file to adjust current retina instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param retinaParameterFile the parameters filename + @param applyDefaultSetupOnFailure set to true if an error must be thrown on error + + You can retrieve the current parameters structure using the method Retina::getParameters and update + it before running method Retina::setup. + */ + CV_WRAP virtual void setup(String retinaParameterFile="", const bool applyDefaultSetupOnFailure=true)=0; + + /** @overload + @param fs the open Filestorage which contains retina parameters + @param applyDefaultSetupOnFailure set to true if an error must be thrown on error + */ + virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0; + + /** @overload + @param newParameters a parameters structures updated with the new target configuration. + */ + virtual void setup(RetinaParameters newParameters)=0; + + /** + @return the current parameters setup + */ + virtual RetinaParameters getParameters()=0; + + /** @brief Outputs a string showing the used parameters setup + @return a string which contains formated parameters information + */ + CV_WRAP virtual const String printSetup()=0; + + /** @brief Write xml/yml formated parameters information + @param fs the filename of the xml file that will be open and writen with formatted parameters + information + */ + CV_WRAP virtual void write( String fs ) const=0; + + /** @overload */ + virtual void write( FileStorage& fs ) const CV_OVERRIDE = 0; + + /** @brief Setup the OPL and IPL parvo channels (see biologocal model) + + OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering + which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance + (low frequency energy) IPL parvo is the OPL next processing stage, it refers to a part of the + Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision. See + reference papers for more informations. + for more informations, please have a look at the paper Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + @param colorMode specifies if (true) color is processed of not (false) to then processing gray + level image + @param normaliseOutput specifies if (true) output is rescaled between 0 and 255 of not (false) + @param photoreceptorsLocalAdaptationSensitivity the photoreceptors sensitivity renage is 0-1 + (more log compression effect when value increases) + @param photoreceptorsTemporalConstant the time constant of the first order low pass filter of + the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is + frames, typical value is 1 frame + @param photoreceptorsSpatialConstant the spatial constant of the first order low pass filter of + the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is + pixels, typical value is 1 pixel + @param horizontalCellsGain gain of the horizontal cells network, if 0, then the mean value of + the output is zero, if the parameter is near 1, then, the luminance is not filtered and is + still reachable at the output, typicall value is 0 + @param HcellsTemporalConstant the time constant of the first order low pass filter of the + horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is + frames, typical value is 1 frame, as the photoreceptors + @param HcellsSpatialConstant the spatial constant of the first order low pass filter of the + horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, + typical value is 5 pixel, this value is also used for local contrast computing when computing + the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular + channel model) + @param ganglionCellsSensitivity the compression strengh of the ganglion cells local adaptation + output, set a value between 0.6 and 1 for best results, a high value increases more the low + value sensitivity... and the output saturates faster, recommended value: 0.7 + */ + CV_WRAP virtual void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity=0.7f, const float photoreceptorsTemporalConstant=0.5f, const float photoreceptorsSpatialConstant=0.53f, const float horizontalCellsGain=0.f, const float HcellsTemporalConstant=1.f, const float HcellsSpatialConstant=7.f, const float ganglionCellsSensitivity=0.7f)=0; + + /** @brief Set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel + + this channel processes signals output from OPL processing stage in peripheral vision, it allows + motion information enhancement. It is decorrelated from the details channel. See reference + papers for more details. + + @param normaliseOutput specifies if (true) output is rescaled between 0 and 255 of not (false) + @param parasolCells_beta the low pass filter gain used for local contrast adaptation at the + IPL level of the retina (for ganglion cells local adaptation), typical value is 0 + @param parasolCells_tau the low pass filter time constant used for local contrast adaptation + at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical + value is 0 (immediate response) + @param parasolCells_k the low pass filter spatial constant used for local contrast adaptation + at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical + value is 5 + @param amacrinCellsTemporalCutFrequency the time constant of the first order high pass fiter of + the magnocellular way (motion information channel), unit is frames, typical value is 1.2 + @param V0CompressionParameter the compression strengh of the ganglion cells local adaptation + output, set a value between 0.6 and 1 for best results, a high value increases more the low + value sensitivity... and the output saturates faster, recommended value: 0.95 + @param localAdaptintegration_tau specifies the temporal constant of the low pas filter + involved in the computation of the local "motion mean" for the local adaptation computation + @param localAdaptintegration_k specifies the spatial constant of the low pas filter involved + in the computation of the local "motion mean" for the local adaptation computation + */ + CV_WRAP virtual void setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta=0.f, const float parasolCells_tau=0.f, const float parasolCells_k=7.f, const float amacrinCellsTemporalCutFrequency=1.2f, const float V0CompressionParameter=0.95f, const float localAdaptintegration_tau=0.f, const float localAdaptintegration_k=7.f)=0; + + /** @brief Method which allows retina to be applied on an input image, + + after run, encapsulated retina module is ready to deliver its outputs using dedicated + acccessors, see getParvo and getMagno methods + @param inputImage the input Mat image to be processed, can be gray level or BGR coded in any + format (from 8bit to 16bits) + */ + CV_WRAP virtual void run(InputArray inputImage)=0; + + /** @brief Method which processes an image in the aim to correct its luminance correct + backlight problems, enhance details in shadows. + + This method is designed to perform High Dynamic Range image tone mapping (compress \>8bit/pixel + images to 8bit/pixel). This is a simplified version of the Retina Parvocellular model + (simplified version of the run/getParvo methods call) since it does not include the + spatio-temporal filter modelling the Outer Plexiform Layer of the retina that performs spectral + whitening and many other stuff. However, it works great for tone mapping and in a faster way. + + Check the demos and experiments section to see examples and the way to perform tone mapping + using the original retina model and the method. + + @param inputImage the input image to process (should be coded in float format : CV_32F, + CV_32FC1, CV_32F_C3, CV_32F_C4, the 4th channel won't be considered). + @param outputToneMappedImage the output 8bit/channel tone mapped image (CV_8U or CV_8UC3 format). + */ + CV_WRAP virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0; + + /** @brief Accessor of the details channel of the retina (models foveal vision). + + Warning, getParvoRAW methods return buffers that are not rescaled within range [0;255] while + the non RAW method allows a normalized matrix to be retrieved. + + @param retinaOutput_parvo the output buffer (reallocated if necessary), format can be : + - a Mat, this output is rescaled for standard 8bits image processing use in OpenCV + - RAW methods actually return a 1D matrix (encoding is R1, R2, ... Rn, G1, G2, ..., Gn, B1, + B2, ...Bn), this output is the original retina filter model output, without any + quantification or rescaling. + @see getParvoRAW + */ + CV_WRAP virtual void getParvo(OutputArray retinaOutput_parvo)=0; + + /** @brief Accessor of the details channel of the retina (models foveal vision). + @see getParvo + */ + CV_WRAP virtual void getParvoRAW(OutputArray retinaOutput_parvo)=0; + + /** @brief Accessor of the motion channel of the retina (models peripheral vision). + + Warning, getMagnoRAW methods return buffers that are not rescaled within range [0;255] while + the non RAW method allows a normalized matrix to be retrieved. + @param retinaOutput_magno the output buffer (reallocated if necessary), format can be : + - a Mat, this output is rescaled for standard 8bits image processing use in OpenCV + - RAW methods actually return a 1D matrix (encoding is M1, M2,... Mn), this output is the + original retina filter model output, without any quantification or rescaling. + @see getMagnoRAW + */ + CV_WRAP virtual void getMagno(OutputArray retinaOutput_magno)=0; + + /** @brief Accessor of the motion channel of the retina (models peripheral vision). + @see getMagno + */ + CV_WRAP virtual void getMagnoRAW(OutputArray retinaOutput_magno)=0; + + /** @overload */ + CV_WRAP virtual const Mat getMagnoRAW() const=0; + /** @overload */ + CV_WRAP virtual const Mat getParvoRAW() const=0; + + /** @brief Activate color saturation as the final step of the color demultiplexing process -\> this + saturation is a sigmoide function applied to each channel of the demultiplexed image. + @param saturateColors boolean that activates color saturation (if true) or desactivate (if false) + @param colorSaturationValue the saturation factor : a simple factor applied on the chrominance + buffers + */ + CV_WRAP virtual void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0f)=0; + + /** @brief Clears all retina buffers + + (equivalent to opening the eyes after a long period of eye close ;o) whatchout the temporal + transition occuring just after this method call. + */ + CV_WRAP virtual void clearBuffers()=0; + + /** @brief Activate/desactivate the Magnocellular pathway processing (motion information extraction), by + default, it is activated + @param activate true if Magnocellular output should be activated, false if not... if activated, + the Magnocellular output can be retrieved using the **getMagno** methods + */ + CV_WRAP virtual void activateMovingContoursProcessing(const bool activate)=0; + + /** @brief Activate/desactivate the Parvocellular pathway processing (contours information extraction), by + default, it is activated + @param activate true if Parvocellular (contours information extraction) output should be + activated, false if not... if activated, the Parvocellular output can be retrieved using the + Retina::getParvo methods + */ + CV_WRAP virtual void activateContoursProcessing(const bool activate)=0; + + /** @overload */ + CV_WRAP static Ptr create(Size inputSize); + /** @brief Constructors from standardized interfaces : retreive a smart pointer to a Retina instance + + @param inputSize the input frame size + @param colorMode the chosen processing mode : with or without color processing + @param colorSamplingMethod specifies which kind of color sampling will be used : + - cv::bioinspired::RETINA_COLOR_RANDOM: each pixel position is either R, G or B in a random choice + - cv::bioinspired::RETINA_COLOR_DIAGONAL: color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR... + - cv::bioinspired::RETINA_COLOR_BAYER: standard bayer sampling + @param useRetinaLogSampling activate retina log sampling, if true, the 2 following parameters can + be used + @param reductionFactor only usefull if param useRetinaLogSampling=true, specifies the reduction + factor of the output frame (as the center (fovea) is high resolution and corners can be + underscaled, then a reduction of the output is allowed without precision leak + @param samplingStrenght only usefull if param useRetinaLogSampling=true, specifies the strenght of + the log scale that is applied + */ + CV_WRAP static Ptr create(Size inputSize, const bool colorMode, + int colorSamplingMethod=RETINA_COLOR_BAYER, + const bool useRetinaLogSampling=false, + const float reductionFactor=1.0f, const float samplingStrenght=10.0f); +}; + +//! @} + +} +} +#endif /* __OPENCV_BIOINSPIRED_RETINA_HPP__ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/retinafasttonemapping.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/retinafasttonemapping.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ba1a87292e8139a3cd487e30904ce46b63d37d1f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/retinafasttonemapping.hpp @@ -0,0 +1,138 @@ + +/*#****************************************************************************** + ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + ** + ** By downloading, copying, installing or using the software you agree to this license. + ** If you do not agree to this license, do not download, install, + ** copy or use the software. + ** + ** + ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab. + ** + ** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications) + ** + ** Creation - enhancement process 2007-2013 + ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France + ** + ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). + ** Refer to the following research paper for more information: + ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: + ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + ** + ** + ** + ** + ** + ** This class is based on image processing tools of the author and already used within the Retina class (this is the same code as method retina::applyFastToneMapping, but in an independent class, it is ligth from a memory requirement point of view). It implements an adaptation of the efficient tone mapping algorithm propose by David Alleyson, Sabine Susstruck and Laurence Meylan's work, please cite: + ** -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816 + ** + ** + ** License Agreement + ** For Open Source Computer Vision Library + ** + ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. + ** + ** For Human Visual System tools (bioinspired) + ** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved. + ** + ** Third party copyrights are property of their respective owners. + ** + ** Redistribution and use in source and binary forms, with or without modification, + ** are permitted provided that the following conditions are met: + ** + ** * Redistributions of source code must retain the above copyright notice, + ** this list of conditions and the following disclaimer. + ** + ** * Redistributions in binary form must reproduce the above copyright notice, + ** this list of conditions and the following disclaimer in the documentation + ** and/or other materials provided with the distribution. + ** + ** * The name of the copyright holders may not be used to endorse or promote products + ** derived from this software without specific prior written permission. + ** + ** This software is provided by the copyright holders and contributors "as is" and + ** any express or implied warranties, including, but not limited to, the implied + ** warranties of merchantability and fitness for a particular purpose are disclaimed. + ** In no event shall the Intel Corporation or contributors be liable for any direct, + ** indirect, incidental, special, exemplary, or consequential damages + ** (including, but not limited to, procurement of substitute goods or services; + ** loss of use, data, or profits; or business interruption) however caused + ** and on any theory of liability, whether in contract, strict liability, + ** or tort (including negligence or otherwise) arising in any way out of + ** the use of this software, even if advised of the possibility of such damage. + *******************************************************************************/ + +#ifndef __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ +#define __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ + +/** +@file +@date May 26, 2013 +@author Alexandre Benoit + */ + +#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support + +namespace cv{ +namespace bioinspired{ + +//! @addtogroup bioinspired +//! @{ + +/** @brief a wrapper class which allows the tone mapping algorithm of Meylan&al(2007) to be used with OpenCV. + +This algorithm is already implemented in thre Retina class (retina::applyFastToneMapping) but used it does not require all the retina model to be allocated. This allows a light memory use for low memory devices (smartphones, etc. +As a summary, these are the model properties: +- 2 stages of local luminance adaptation with a different local neighborhood for each. +- first stage models the retina photorecetors local luminance adaptation +- second stage models th ganglion cells local information adaptation +- compared to the initial publication, this class uses spatio-temporal low pass filters instead of spatial only filters. + this can help noise robustness and temporal stability for video sequence use cases. + +for more information, read to the following papers : +Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 +regarding spatio-temporal filter and the bigger retina model : +Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. +*/ +class CV_EXPORTS_W RetinaFastToneMapping : public Algorithm +{ +public: + + /** @brief applies a luminance correction (initially High Dynamic Range (HDR) tone mapping) + + using only the 2 local adaptation stages of the retina parvocellular channel : photoreceptors + level and ganlion cells level. Spatio temporal filtering is applied but limited to temporal + smoothing and eventually high frequencies attenuation. This is a lighter method than the one + available using the regular retina::run method. It is then faster but it does not include + complete temporal filtering nor retina spectral whitening. Then, it can have a more limited + effect on images with a very high dynamic range. This is an adptation of the original still + image HDR tone mapping algorithm of David Alleyson, Sabine Susstruck and Laurence Meylan's + work, please cite: -> Meylan L., Alleysson D., and Susstrunk S., A Model of Retinal Local + Adaptation for the Tone Mapping of Color Filter Array Images, Journal of Optical Society of + America, A, Vol. 24, N 9, September, 1st, 2007, pp. 2807-2816 + + @param inputImage the input image to process RGB or gray levels + @param outputToneMappedImage the output tone mapped image + */ + CV_WRAP virtual void applyFastToneMapping(InputArray inputImage, OutputArray outputToneMappedImage)=0; + + /** @brief updates tone mapping behaviors by adjusing the local luminance computation area + + @param photoreceptorsNeighborhoodRadius the first stage local adaptation area + @param ganglioncellsNeighborhoodRadius the second stage local adaptation area + @param meanLuminanceModulatorK the factor applied to modulate the meanLuminance information + (default is 1, see reference paper) + */ + CV_WRAP virtual void setup(const float photoreceptorsNeighborhoodRadius=3.f, const float ganglioncellsNeighborhoodRadius=1.f, const float meanLuminanceModulatorK=1.f)=0; + + CV_WRAP static Ptr create(Size inputSize); +}; + + +//! @} + +} +} +#endif /* __OPENCV_BIOINSPIRED_RETINAFASTTONEMAPPING_HPP__ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/transientareassegmentationmodule.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/transientareassegmentationmodule.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d5f5b2fd1e5363793b679a781757cf3eda5481eb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/bioinspired/transientareassegmentationmodule.hpp @@ -0,0 +1,204 @@ +/*#****************************************************************************** + ** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + ** + ** By downloading, copying, installing or using the software you agree to this license. + ** If you do not agree to this license, do not download, install, + ** copy or use the software. + ** + ** + ** bioinspired : interfaces allowing OpenCV users to integrate Human Vision System models. + ** TransientAreasSegmentationModule Use: extract areas that present spatio-temporal changes. + ** => It should be used at the output of the cv::bioinspired::Retina::getMagnoRAW() output that enhances spatio-temporal changes + ** + ** Maintainers : Listic lab (code author current affiliation & applications) + ** + ** Creation - enhancement process 2007-2015 + ** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France + ** + ** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr). + ** Refer to the following research paper for more information: + ** Strat, S.T.; Benoit, A.; Lambert, P., "Retina enhanced bag of words descriptors for video classification," Signal Processing Conference (EUSIPCO), 2014 Proceedings of the 22nd European , vol., no., pp.1307,1311, 1-5 Sept. 2014 (http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6952461&isnumber=6951911) + ** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011 + ** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book: + ** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891. + ** + ** + ** License Agreement + ** For Open Source Computer Vision Library + ** + ** Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + ** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. + ** + ** For Human Visual System tools (bioinspired) + ** Copyright (C) 2007-2015, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved. + ** + ** Third party copyrights are property of their respective owners. + ** + ** Redistribution and use in source and binary forms, with or without modification, + ** are permitted provided that the following conditions are met: + ** + ** * Redistributions of source code must retain the above copyright notice, + ** this list of conditions and the following disclaimer. + ** + ** * Redistributions in binary form must reproduce the above copyright notice, + ** this list of conditions and the following disclaimer in the documentation + ** and/or other materials provided with the distribution. + ** + ** * The name of the copyright holders may not be used to endorse or promote products + ** derived from this software without specific prior written permission. + ** + ** This software is provided by the copyright holders and contributors "as is" and + ** any express or implied warranties, including, but not limited to, the implied + ** warranties of merchantability and fitness for a particular purpose are disclaimed. + ** In no event shall the Intel Corporation or contributors be liable for any direct, + ** indirect, incidental, special, exemplary, or consequential damages + ** (including, but not limited to, procurement of substitute goods or services; + ** loss of use, data, or profits; or business interruption) however caused + ** and on any theory of liability, whether in contract, strict liability, + ** or tort (including negligence or otherwise) arising in any way out of + ** the use of this software, even if advised of the possibility of such damage. + *******************************************************************************/ + +#ifndef SEGMENTATIONMODULE_HPP_ +#define SEGMENTATIONMODULE_HPP_ + +/** +@file +@date 2007-2013 +@author Alexandre BENOIT, benoit.alexandre.vision@gmail.com +*/ + +#include "opencv2/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support + +namespace cv +{ +namespace bioinspired +{ +//! @addtogroup bioinspired +//! @{ + +/** @brief parameter structure that stores the transient events detector setup parameters +*/ +struct SegmentationParameters{ // CV_EXPORTS_W_MAP to export to python native dictionnaries + // default structure instance construction with default values + SegmentationParameters(): + thresholdON(100), + thresholdOFF(100), + localEnergy_temporalConstant(0.5), + localEnergy_spatialConstant(5), + neighborhoodEnergy_temporalConstant(1), + neighborhoodEnergy_spatialConstant(15), + contextEnergy_temporalConstant(1), + contextEnergy_spatialConstant(75){}; + // all properties list + float thresholdON; + float thresholdOFF; + //! the time constant of the first order low pass filter, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 0.5 frame + float localEnergy_temporalConstant; + //! the spatial constant of the first order low pass filter, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 5 pixel + float localEnergy_spatialConstant; + //! local neighborhood energy filtering parameters : the aim is to get information about the energy neighborhood to perform a center surround energy analysis + float neighborhoodEnergy_temporalConstant; + float neighborhoodEnergy_spatialConstant; + //! context neighborhood energy filtering parameters : the aim is to get information about the energy on a wide neighborhood area to filtered out local effects + float contextEnergy_temporalConstant; + float contextEnergy_spatialConstant; +}; + +/** @brief class which provides a transient/moving areas segmentation module + +perform a locally adapted segmentation by using the retina magno input data Based on Alexandre +BENOIT thesis: "Le système visuel humain au secours de la vision par ordinateur" + +3 spatio temporal filters are used: +- a first one which filters the noise and local variations of the input motion energy +- a second (more powerfull low pass spatial filter) which gives the neighborhood motion energy the +segmentation consists in the comparison of these both outputs, if the local motion energy is higher +to the neighborhood otion energy, then the area is considered as moving and is segmented +- a stronger third low pass filter helps decision by providing a smooth information about the +"motion context" in a wider area + */ + +class CV_EXPORTS_W TransientAreasSegmentationModule: public Algorithm +{ +public: + + + /** @brief return the sze of the manage input and output images + */ + CV_WRAP virtual Size getSize()=0; + + /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param segmentationParameterFile : the parameters filename + @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error + */ + CV_WRAP virtual void setup(String segmentationParameterFile="", const bool applyDefaultSetupOnFailure=true)=0; + + /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param fs : the open Filestorage which contains segmentation parameters + @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error + */ + virtual void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true)=0; + + /** @brief try to open an XML segmentation parameters file to adjust current segmentation instance setup + + - if the xml file does not exist, then default setup is applied + - warning, Exceptions are thrown if read XML file is not valid + @param newParameters : a parameters structures updated with the new target configuration + */ + virtual void setup(SegmentationParameters newParameters)=0; + + /** @brief return the current parameters setup + */ + virtual SegmentationParameters getParameters()=0; + + /** @brief parameters setup display method + @return a string which contains formatted parameters information + */ + CV_WRAP virtual const String printSetup()=0; + + /** @brief write xml/yml formated parameters information + @param fs : the filename of the xml file that will be open and writen with formatted parameters information + */ + CV_WRAP virtual void write( String fs ) const=0; + + /** @brief write xml/yml formated parameters information + @param fs : a cv::Filestorage object ready to be filled + */ + virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE = 0; + + /** @brief main processing method, get result using methods getSegmentationPicture() + @param inputToSegment : the image to process, it must match the instance buffer size ! + @param channelIndex : the channel to process in case of multichannel images + */ + CV_WRAP virtual void run(InputArray inputToSegment, const int channelIndex=0)=0; + + /** @brief access function + return the last segmentation result: a boolean picture which is resampled between 0 and 255 for a display purpose + */ + CV_WRAP virtual void getSegmentationPicture(OutputArray transientAreas)=0; + + /** @brief cleans all the buffers of the instance + */ + CV_WRAP virtual void clearAllBuffers()=0; + + /** @brief allocator + @param inputSize : size of the images input to segment (output will be the same size) + */ + CV_WRAP static Ptr create(Size inputSize); +}; + +//! @} + +}} // namespaces end : cv and bioinspired + + +#endif + + diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ced32fee9bc278d7a6cdecc232d79e9e0d729222 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d.hpp @@ -0,0 +1,3335 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CALIB3D_HPP +#define OPENCV_CALIB3D_HPP + +#include "opencv2/core.hpp" +#include "opencv2/features2d.hpp" +#include "opencv2/core/affine.hpp" + +/** + @defgroup calib3d Camera Calibration and 3D Reconstruction + +The functions in this section use a so-called pinhole camera model. In this model, a scene view is +formed by projecting 3D points into the image plane using a perspective transformation. + +\f[s \; m' = A [R|t] M'\f] + +or + +\f[s \vecthree{u}{v}{1} = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1} +\begin{bmatrix} +r_{11} & r_{12} & r_{13} & t_x \\ +r_{21} & r_{22} & r_{23} & t_y \\ +r_{31} & r_{32} & r_{33} & t_z +\end{bmatrix} +\begin{bmatrix} +X_w \\ +Y_w \\ +Z_w \\ +1 +\end{bmatrix}\f] + +where: + +- \f$(X_w, Y_w, Z_w)\f$ are the coordinates of a 3D point in the world coordinate space +- \f$(u, v)\f$ are the coordinates of the projection point in pixels +- \f$A\f$ is a camera matrix, or a matrix of intrinsic parameters +- \f$(c_x, c_y)\f$ is a principal point that is usually at the image center +- \f$f_x, f_y\f$ are the focal lengths expressed in pixel units. + +Thus, if an image from the camera is scaled by a factor, all of these parameters should be scaled +(multiplied/divided, respectively) by the same factor. The matrix of intrinsic parameters does not +depend on the scene viewed. So, once estimated, it can be re-used as long as the focal length is +fixed (in case of zoom lens). The joint rotation-translation matrix \f$[R|t]\f$ is called a matrix of +extrinsic parameters. It is used to describe the camera motion around a static scene, or vice versa, +rigid motion of an object in front of a still camera. That is, \f$[R|t]\f$ translates coordinates of a +world point \f$(X_w, Y_w, Z_w)\f$ to a coordinate system, fixed with respect to the camera. +The transformation above is equivalent to the following (when \f$z \ne 0\f$ ): + +\f[\begin{array}{l} +\vecthree{X_c}{Y_c}{Z_c} = R \vecthree{X_w}{Y_w}{Z_w} + t \\ +x' = X_c/Z_c \\ +y' = Y_c/Z_c \\ +u = f_x \times x' + c_x \\ +v = f_y \times y' + c_y +\end{array}\f] + +The following figure illustrates the pinhole camera model. + +![Pinhole camera model](pics/pinhole_camera_model.png) + +Real lenses usually have some distortion, mostly radial distortion and slight tangential distortion. +So, the above model is extended as: + +\f[\begin{array}{l} +\vecthree{X_c}{Y_c}{Z_c} = R \vecthree{X_w}{Y_w}{Z_w} + t \\ +x' = X_c/Z_c \\ +y' = Y_c/Z_c \\ +x'' = x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + 2 p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4 \\ +y'' = y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ +\text{where} \quad r^2 = x'^2 + y'^2 \\ +u = f_x \times x'' + c_x \\ +v = f_y \times y'' + c_y +\end{array}\f] + +\f$k_1\f$, \f$k_2\f$, \f$k_3\f$, \f$k_4\f$, \f$k_5\f$, and \f$k_6\f$ are radial distortion coefficients. \f$p_1\f$ and \f$p_2\f$ are +tangential distortion coefficients. \f$s_1\f$, \f$s_2\f$, \f$s_3\f$, and \f$s_4\f$, are the thin prism distortion +coefficients. Higher-order coefficients are not considered in OpenCV. + +The next figures show two common types of radial distortion: barrel distortion (typically \f$ k_1 < 0 \f$) and pincushion distortion (typically \f$ k_1 > 0 \f$). + +![](pics/distortion_examples.png) +![](pics/distortion_examples2.png) + +In some cases the image sensor may be tilted in order to focus an oblique plane in front of the +camera (Scheimpflug principle). This can be useful for particle image velocimetry (PIV) or +triangulation with a laser fan. The tilt causes a perspective distortion of \f$x''\f$ and +\f$y''\f$. This distortion can be modelled in the following way, see e.g. @cite Louhichi07. + +\f[\begin{array}{l} +s\vecthree{x'''}{y'''}{1} = +\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}(\tau_x, \tau_y)} +{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} +{0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ +u = f_x \times x''' + c_x \\ +v = f_y \times y''' + c_y +\end{array}\f] + +where the matrix \f$R(\tau_x, \tau_y)\f$ is defined by two rotations with angular parameter \f$\tau_x\f$ +and \f$\tau_y\f$, respectively, + +\f[ +R(\tau_x, \tau_y) = +\vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)} +\vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} = +\vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)} +{0}{\cos(\tau_x)}{\sin(\tau_x)} +{\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}. +\f] + +In the functions below the coefficients are passed or returned as + +\f[(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f] + +vector. That is, if the vector contains four elements, it means that \f$k_3=0\f$ . The distortion +coefficients do not depend on the scene viewed. Thus, they also belong to the intrinsic camera +parameters. And they remain the same regardless of the captured image resolution. If, for example, a +camera has been calibrated on images of 320 x 240 resolution, absolutely the same distortion +coefficients can be used for 640 x 480 images from the same camera while \f$f_x\f$, \f$f_y\f$, \f$c_x\f$, and +\f$c_y\f$ need to be scaled appropriately. + +The functions below use the above model to do the following: + +- Project 3D points to the image plane given intrinsic and extrinsic parameters. +- Compute extrinsic parameters given intrinsic parameters, a few 3D points, and their +projections. +- Estimate intrinsic and extrinsic camera parameters from several views of a known calibration +pattern (every view is described by several 3D-2D point correspondences). +- Estimate the relative position and orientation of the stereo camera "heads" and compute the +*rectification* transformation that makes the camera optical axes parallel. + +@note + - A calibration sample for 3 cameras in horizontal position can be found at + opencv_source_code/samples/cpp/3calibration.cpp + - A calibration sample based on a sequence of images can be found at + opencv_source_code/samples/cpp/calibration.cpp + - A calibration sample in order to do 3D reconstruction can be found at + opencv_source_code/samples/cpp/build3dmodel.cpp + - A calibration example on stereo calibration can be found at + opencv_source_code/samples/cpp/stereo_calib.cpp + - A calibration example on stereo matching can be found at + opencv_source_code/samples/cpp/stereo_match.cpp + - (Python) A camera calibration sample can be found at + opencv_source_code/samples/python/calibrate.py + + @{ + @defgroup calib3d_fisheye Fisheye camera model + + Definitions: Let P be a point in 3D of coordinates X in the world reference frame (stored in the + matrix X) The coordinate vector of P in the camera reference frame is: + + \f[Xc = R X + T\f] + + where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om); call x, y + and z the 3 coordinates of Xc: + + \f[x = Xc_1 \\ y = Xc_2 \\ z = Xc_3\f] + + The pinhole projection coordinates of P is [a; b] where + + \f[a = x / z \ and \ b = y / z \\ r^2 = a^2 + b^2 \\ \theta = atan(r)\f] + + Fisheye distortion: + + \f[\theta_d = \theta (1 + k_1 \theta^2 + k_2 \theta^4 + k_3 \theta^6 + k_4 \theta^8)\f] + + The distorted point coordinates are [x'; y'] where + + \f[x' = (\theta_d / r) a \\ y' = (\theta_d / r) b \f] + + Finally, conversion into pixel coordinates: The final pixel coordinates vector [u; v] where: + + \f[u = f_x (x' + \alpha y') + c_x \\ + v = f_y y' + c_y\f] + + @defgroup calib3d_c C API + + @} + */ + +namespace cv +{ + +//! @addtogroup calib3d +//! @{ + +//! type of the robust estimation algorithm +enum { LMEDS = 4, //!< least-median of squares algorithm + RANSAC = 8, //!< RANSAC algorithm + RHO = 16 //!< RHO algorithm + }; + +enum SolvePnPMethod { + SOLVEPNP_ITERATIVE = 0, + SOLVEPNP_EPNP = 1, //!< EPnP: Efficient Perspective-n-Point Camera Pose Estimation @cite lepetit2009epnp + SOLVEPNP_P3P = 2, //!< Complete Solution Classification for the Perspective-Three-Point Problem @cite gao2003complete + SOLVEPNP_DLS = 3, //!< A Direct Least-Squares (DLS) Method for PnP @cite hesch2011direct + SOLVEPNP_UPNP = 4, //!< Exhaustive Linearization for Robust Camera Pose and Focal Length Estimation @cite penate2013exhaustive + SOLVEPNP_AP3P = 5, //!< An Efficient Algebraic Solution to the Perspective-Three-Point Problem @cite Ke17 + SOLVEPNP_IPPE = 6, //!< Infinitesimal Plane-Based Pose Estimation @cite Collins14 \n + //!< Object points must be coplanar. + SOLVEPNP_IPPE_SQUARE = 7, //!< Infinitesimal Plane-Based Pose Estimation @cite Collins14 \n + //!< This is a special case suitable for marker pose estimation.\n + //!< 4 coplanar object points must be defined in the following order: + //!< - point 0: [-squareLength / 2, squareLength / 2, 0] + //!< - point 1: [ squareLength / 2, squareLength / 2, 0] + //!< - point 2: [ squareLength / 2, -squareLength / 2, 0] + //!< - point 3: [-squareLength / 2, -squareLength / 2, 0] +#ifndef CV_DOXYGEN + SOLVEPNP_MAX_COUNT //!< Used for count +#endif +}; + +enum { CALIB_CB_ADAPTIVE_THRESH = 1, + CALIB_CB_NORMALIZE_IMAGE = 2, + CALIB_CB_FILTER_QUADS = 4, + CALIB_CB_FAST_CHECK = 8, + CALIB_CB_EXHAUSTIVE = 16, + CALIB_CB_ACCURACY = 32 + }; + +enum { CALIB_CB_SYMMETRIC_GRID = 1, + CALIB_CB_ASYMMETRIC_GRID = 2, + CALIB_CB_CLUSTERING = 4 + }; + +enum { CALIB_NINTRINSIC = 18, + CALIB_USE_INTRINSIC_GUESS = 0x00001, + CALIB_FIX_ASPECT_RATIO = 0x00002, + CALIB_FIX_PRINCIPAL_POINT = 0x00004, + CALIB_ZERO_TANGENT_DIST = 0x00008, + CALIB_FIX_FOCAL_LENGTH = 0x00010, + CALIB_FIX_K1 = 0x00020, + CALIB_FIX_K2 = 0x00040, + CALIB_FIX_K3 = 0x00080, + CALIB_FIX_K4 = 0x00800, + CALIB_FIX_K5 = 0x01000, + CALIB_FIX_K6 = 0x02000, + CALIB_RATIONAL_MODEL = 0x04000, + CALIB_THIN_PRISM_MODEL = 0x08000, + CALIB_FIX_S1_S2_S3_S4 = 0x10000, + CALIB_TILTED_MODEL = 0x40000, + CALIB_FIX_TAUX_TAUY = 0x80000, + CALIB_USE_QR = 0x100000, //!< use QR instead of SVD decomposition for solving. Faster but potentially less precise + CALIB_FIX_TANGENT_DIST = 0x200000, + // only for stereo + CALIB_FIX_INTRINSIC = 0x00100, + CALIB_SAME_FOCAL_LENGTH = 0x00200, + // for stereo rectification + CALIB_ZERO_DISPARITY = 0x00400, + CALIB_USE_LU = (1 << 17), //!< use LU instead of SVD decomposition for solving. much faster but potentially less precise + CALIB_USE_EXTRINSIC_GUESS = (1 << 22) //!< for stereoCalibrate + }; + +//! the algorithm for finding fundamental matrix +enum { FM_7POINT = 1, //!< 7-point algorithm + FM_8POINT = 2, //!< 8-point algorithm + FM_LMEDS = 4, //!< least-median algorithm. 7-point algorithm is used. + FM_RANSAC = 8 //!< RANSAC algorithm. It needs at least 15 points. 7-point algorithm is used. + }; + +enum HandEyeCalibrationMethod +{ + CALIB_HAND_EYE_TSAI = 0, //!< A New Technique for Fully Autonomous and Efficient 3D Robotics Hand/Eye Calibration @cite Tsai89 + CALIB_HAND_EYE_PARK = 1, //!< Robot Sensor Calibration: Solving AX = XB on the Euclidean Group @cite Park94 + CALIB_HAND_EYE_HORAUD = 2, //!< Hand-eye Calibration @cite Horaud95 + CALIB_HAND_EYE_ANDREFF = 3, //!< On-line Hand-Eye Calibration @cite Andreff99 + CALIB_HAND_EYE_DANIILIDIS = 4 //!< Hand-Eye Calibration Using Dual Quaternions @cite Daniilidis98 +}; + + +/** @brief Converts a rotation matrix to a rotation vector or vice versa. + +@param src Input rotation vector (3x1 or 1x3) or rotation matrix (3x3). +@param dst Output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively. +@param jacobian Optional output Jacobian matrix, 3x9 or 9x3, which is a matrix of partial +derivatives of the output array components with respect to the input array components. + +\f[\begin{array}{l} \theta \leftarrow norm(r) \\ r \leftarrow r/ \theta \\ R = \cos(\theta) I + (1- \cos{\theta} ) r r^T + \sin(\theta) \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} \end{array}\f] + +Inverse transformation can be also done easily, since + +\f[\sin ( \theta ) \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} = \frac{R - R^T}{2}\f] + +A rotation vector is a convenient and most compact representation of a rotation matrix (since any +rotation matrix has just 3 degrees of freedom). The representation is used in the global 3D geometry +optimization procedures like @ref calibrateCamera, @ref stereoCalibrate, or @ref solvePnP . + +@note More information about the computation of the derivative of a 3D rotation matrix with respect to its exponential coordinate +can be found in: + - A Compact Formula for the Derivative of a 3-D Rotation in Exponential Coordinates, Guillermo Gallego, Anthony J. Yezzi @cite Gallego2014ACF + +@note Useful information on SE(3) and Lie Groups can be found in: + - A tutorial on SE(3) transformation parameterizations and on-manifold optimization, Jose-Luis Blanco @cite blanco2010tutorial + - Lie Groups for 2D and 3D Transformation, Ethan Eade @cite Eade17 + - A micro Lie theory for state estimation in robotics, Joan Solà, Jérémie Deray, Dinesh Atchuthan @cite Sol2018AML + */ +CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() ); + + + +/** Levenberg-Marquardt solver. Starting with the specified vector of parameters it + optimizes the target vector criteria "err" + (finds local minima of each target vector component absolute value). + + When needed, it calls user-provided callback. +*/ +class CV_EXPORTS LMSolver : public Algorithm +{ +public: + class CV_EXPORTS Callback + { + public: + virtual ~Callback() {} + /** + computes error and Jacobian for the specified vector of parameters + + @param param the current vector of parameters + @param err output vector of errors: err_i = actual_f_i - ideal_f_i + @param J output Jacobian: J_ij = d(err_i)/d(param_j) + + when J=noArray(), it means that it does not need to be computed. + Dimensionality of error vector and param vector can be different. + The callback should explicitly allocate (with "create" method) each output array + (unless it's noArray()). + */ + virtual bool compute(InputArray param, OutputArray err, OutputArray J) const = 0; + }; + + /** + Runs Levenberg-Marquardt algorithm using the passed vector of parameters as the start point. + The final vector of parameters (whether the algorithm converged or not) is stored at the same + vector. The method returns the number of iterations used. If it's equal to the previously specified + maxIters, there is a big chance the algorithm did not converge. + + @param param initial/final vector of parameters. + + Note that the dimensionality of parameter space is defined by the size of param vector, + and the dimensionality of optimized criteria is defined by the size of err vector + computed by the callback. + */ + virtual int run(InputOutputArray param) const = 0; + + /** + Sets the maximum number of iterations + @param maxIters the number of iterations + */ + virtual void setMaxIters(int maxIters) = 0; + /** + Retrieves the current maximum number of iterations + */ + virtual int getMaxIters() const = 0; + + /** + Creates Levenberg-Marquard solver + + @param cb callback + @param maxIters maximum number of iterations that can be further + modified using setMaxIters() method. + */ + static Ptr create(const Ptr& cb, int maxIters); + static Ptr create(const Ptr& cb, int maxIters, double eps); +}; + + + +/** @example samples/cpp/tutorial_code/features2D/Homography/pose_from_homography.cpp +An example program about pose estimation from coplanar points + +Check @ref tutorial_homography "the corresponding tutorial" for more details +*/ + +/** @brief Finds a perspective transformation between two planes. + +@param srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2 +or vector\ . +@param dstPoints Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or +a vector\ . +@param method Method used to compute a homography matrix. The following methods are possible: +- **0** - a regular method using all the points, i.e., the least squares method +- **RANSAC** - RANSAC-based robust method +- **LMEDS** - Least-Median robust method +- **RHO** - PROSAC-based robust method +@param ransacReprojThreshold Maximum allowed reprojection error to treat a point pair as an inlier +(used in the RANSAC and RHO methods only). That is, if +\f[\| \texttt{dstPoints} _i - \texttt{convertPointsHomogeneous} ( \texttt{H} * \texttt{srcPoints} _i) \|_2 > \texttt{ransacReprojThreshold}\f] +then the point \f$i\f$ is considered as an outlier. If srcPoints and dstPoints are measured in pixels, +it usually makes sense to set this parameter somewhere in the range of 1 to 10. +@param mask Optional output mask set by a robust method ( RANSAC or LMEDS ). Note that the input +mask values are ignored. +@param maxIters The maximum number of RANSAC iterations. +@param confidence Confidence level, between 0 and 1. + +The function finds and returns the perspective transformation \f$H\f$ between the source and the +destination planes: + +\f[s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}\f] + +so that the back-projection error + +\f[\sum _i \left ( x'_i- \frac{h_{11} x_i + h_{12} y_i + h_{13}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2+ \left ( y'_i- \frac{h_{21} x_i + h_{22} y_i + h_{23}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2\f] + +is minimized. If the parameter method is set to the default value 0, the function uses all the point +pairs to compute an initial homography estimate with a simple least-squares scheme. + +However, if not all of the point pairs ( \f$srcPoints_i\f$, \f$dstPoints_i\f$ ) fit the rigid perspective +transformation (that is, there are some outliers), this initial estimate will be poor. In this case, +you can use one of the three robust methods. The methods RANSAC, LMeDS and RHO try many different +random subsets of the corresponding point pairs (of four pairs each, collinear pairs are discarded), estimate the homography matrix +using this subset and a simple least-squares algorithm, and then compute the quality/goodness of the +computed homography (which is the number of inliers for RANSAC or the least median re-projection error for +LMeDS). The best subset is then used to produce the initial estimate of the homography matrix and +the mask of inliers/outliers. + +Regardless of the method, robust or not, the computed homography matrix is refined further (using +inliers only in case of a robust method) with the Levenberg-Marquardt method to reduce the +re-projection error even more. + +The methods RANSAC and RHO can handle practically any ratio of outliers but need a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. Finally, if there are no outliers and the +noise is rather small, use the default method (method=0). + +The function is used to find initial intrinsic and extrinsic matrices. Homography matrix is +determined up to a scale. Thus, it is normalized so that \f$h_{33}=1\f$. Note that whenever an \f$H\f$ matrix +cannot be estimated, an empty one will be returned. + +@sa +getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective, +perspectiveTransform + */ +CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints, + int method = 0, double ransacReprojThreshold = 3, + OutputArray mask=noArray(), const int maxIters = 2000, + const double confidence = 0.995); + +/** @overload */ +CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints, + OutputArray mask, int method = 0, double ransacReprojThreshold = 3 ); + +/** @brief Computes an RQ decomposition of 3x3 matrices. + +@param src 3x3 input matrix. +@param mtxR Output 3x3 upper-triangular matrix. +@param mtxQ Output 3x3 orthogonal matrix. +@param Qx Optional output 3x3 rotation matrix around x-axis. +@param Qy Optional output 3x3 rotation matrix around y-axis. +@param Qz Optional output 3x3 rotation matrix around z-axis. + +The function computes a RQ decomposition using the given rotations. This function is used in +decomposeProjectionMatrix to decompose the left 3x3 submatrix of a projection matrix into a camera +and a rotation matrix. + +It optionally returns three rotation matrices, one for each axis, and the three Euler angles in +degrees (as the return value) that could be used in OpenGL. Note, there is always more than one +sequence of rotations about the three principal axes that results in the same orientation of an +object, e.g. see @cite Slabaugh . Returned tree rotation matrices and corresponding three Euler angles +are only one of the possible solutions. + */ +CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ, + OutputArray Qx = noArray(), + OutputArray Qy = noArray(), + OutputArray Qz = noArray()); + +/** @brief Decomposes a projection matrix into a rotation matrix and a camera matrix. + +@param projMatrix 3x4 input projection matrix P. +@param cameraMatrix Output 3x3 camera matrix K. +@param rotMatrix Output 3x3 external rotation matrix R. +@param transVect Output 4x1 translation vector T. +@param rotMatrixX Optional 3x3 rotation matrix around x-axis. +@param rotMatrixY Optional 3x3 rotation matrix around y-axis. +@param rotMatrixZ Optional 3x3 rotation matrix around z-axis. +@param eulerAngles Optional three-element vector containing three Euler angles of rotation in +degrees. + +The function computes a decomposition of a projection matrix into a calibration and a rotation +matrix and the position of a camera. + +It optionally returns three rotation matrices, one for each axis, and three Euler angles that could +be used in OpenGL. Note, there is always more than one sequence of rotations about the three +principal axes that results in the same orientation of an object, e.g. see @cite Slabaugh . Returned +tree rotation matrices and corresponding three Euler angles are only one of the possible solutions. + +The function is based on RQDecomp3x3 . + */ +CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix, + OutputArray rotMatrix, OutputArray transVect, + OutputArray rotMatrixX = noArray(), + OutputArray rotMatrixY = noArray(), + OutputArray rotMatrixZ = noArray(), + OutputArray eulerAngles =noArray() ); + +/** @brief Computes partial derivatives of the matrix product for each multiplied matrix. + +@param A First multiplied matrix. +@param B Second multiplied matrix. +@param dABdA First output derivative matrix d(A\*B)/dA of size +\f$\texttt{A.rows*B.cols} \times {A.rows*A.cols}\f$ . +@param dABdB Second output derivative matrix d(A\*B)/dB of size +\f$\texttt{A.rows*B.cols} \times {B.rows*B.cols}\f$ . + +The function computes partial derivatives of the elements of the matrix product \f$A*B\f$ with regard to +the elements of each of the two input matrices. The function is used to compute the Jacobian +matrices in stereoCalibrate but can also be used in any other similar optimization function. + */ +CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB ); + +/** @brief Combines two rotation-and-shift transformations. + +@param rvec1 First rotation vector. +@param tvec1 First translation vector. +@param rvec2 Second rotation vector. +@param tvec2 Second translation vector. +@param rvec3 Output rotation vector of the superposition. +@param tvec3 Output translation vector of the superposition. +@param dr3dr1 Optional output derivative of rvec3 with regard to rvec1 +@param dr3dt1 Optional output derivative of rvec3 with regard to tvec1 +@param dr3dr2 Optional output derivative of rvec3 with regard to rvec2 +@param dr3dt2 Optional output derivative of rvec3 with regard to tvec2 +@param dt3dr1 Optional output derivative of tvec3 with regard to rvec1 +@param dt3dt1 Optional output derivative of tvec3 with regard to tvec1 +@param dt3dr2 Optional output derivative of tvec3 with regard to rvec2 +@param dt3dt2 Optional output derivative of tvec3 with regard to tvec2 + +The functions compute: + +\f[\begin{array}{l} \texttt{rvec3} = \mathrm{rodrigues} ^{-1} \left ( \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \mathrm{rodrigues} ( \texttt{rvec1} ) \right ) \\ \texttt{tvec3} = \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \texttt{tvec1} + \texttt{tvec2} \end{array} ,\f] + +where \f$\mathrm{rodrigues}\f$ denotes a rotation vector to a rotation matrix transformation, and +\f$\mathrm{rodrigues}^{-1}\f$ denotes the inverse transformation. See Rodrigues for details. + +Also, the functions can compute the derivatives of the output vectors with regards to the input +vectors (see matMulDeriv ). The functions are used inside stereoCalibrate but can also be used in +your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a +function that contains a matrix multiplication. + */ +CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1, + InputArray rvec2, InputArray tvec2, + OutputArray rvec3, OutputArray tvec3, + OutputArray dr3dr1 = noArray(), OutputArray dr3dt1 = noArray(), + OutputArray dr3dr2 = noArray(), OutputArray dr3dt2 = noArray(), + OutputArray dt3dr1 = noArray(), OutputArray dt3dt1 = noArray(), + OutputArray dt3dr2 = noArray(), OutputArray dt3dt2 = noArray() ); + +/** @brief Projects 3D points to an image plane. + +@param objectPoints Array of object points, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel (or +vector\ ), where N is the number of points in the view. +@param rvec Rotation vector. See Rodrigues for details. +@param tvec Translation vector. +@param cameraMatrix Camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is empty, the zero distortion coefficients are assumed. +@param imagePoints Output array of image points, 1xN/Nx1 2-channel, or +vector\ . +@param jacobian Optional output 2Nx(10+\) jacobian matrix of derivatives of image +points with respect to components of the rotation vector, translation vector, focal lengths, +coordinates of the principal point and the distortion coefficients. In the old interface different +components of the jacobian are returned via different output parameters. +@param aspectRatio Optional "fixed aspect ratio" parameter. If the parameter is not 0, the +function assumes that the aspect ratio (*fx/fy*) is fixed and correspondingly adjusts the jacobian +matrix. + +The function computes projections of 3D points to the image plane given intrinsic and extrinsic +camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of +image points coordinates (as functions of all the input parameters) with respect to the particular +parameters, intrinsic and/or extrinsic. The Jacobians are used during the global optimization in +calibrateCamera, solvePnP, and stereoCalibrate . The function itself can also be used to compute a +re-projection error given the current intrinsic and extrinsic parameters. + +@note By setting rvec=tvec=(0,0,0) or by setting cameraMatrix to a 3x3 identity matrix, or by +passing zero distortion coefficients, you can get various useful partial cases of the function. This +means that you can compute the distorted coordinates for a sparse set of points or apply a +perspective transformation (and also compute the derivatives) in the ideal zero-distortion setup. + */ +CV_EXPORTS_W void projectPoints( InputArray objectPoints, + InputArray rvec, InputArray tvec, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray imagePoints, + OutputArray jacobian = noArray(), + double aspectRatio = 0 ); + +/** @example samples/cpp/tutorial_code/features2D/Homography/homography_from_camera_displacement.cpp +An example program about homography from the camera displacement + +Check @ref tutorial_homography "the corresponding tutorial" for more details +*/ + +/** @brief Finds an object pose from 3D-2D point correspondences. +This function returns the rotation and the translation vectors that transform a 3D point expressed in the object +coordinate frame to the camera coordinate frame, using different methods: +- P3P methods (@ref SOLVEPNP_P3P, @ref SOLVEPNP_AP3P): need 4 input points to return a unique solution. +- @ref SOLVEPNP_IPPE Input points must be >= 4 and object points must be coplanar. +- @ref SOLVEPNP_IPPE_SQUARE Special case suitable for marker pose estimation. +Number of input points must be 4. Object points must be defined in the following order: + - point 0: [-squareLength / 2, squareLength / 2, 0] + - point 1: [ squareLength / 2, squareLength / 2, 0] + - point 2: [ squareLength / 2, -squareLength / 2, 0] + - point 3: [-squareLength / 2, -squareLength / 2, 0] +- for all the other flags, number of input points must be >= 4 and object points can be in any configuration. + +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or +1xN/Nx1 3-channel, where N is the number of points. vector\ can be also passed here. +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, +where N is the number of points. vector\ can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvec Output rotation vector (see @ref Rodrigues ) that, together with tvec, brings points from +the model coordinate system to the camera coordinate system. +@param tvec Output translation vector. +@param useExtrinsicGuess Parameter used for #SOLVEPNP_ITERATIVE. If true (1), the function uses +the provided rvec and tvec values as initial approximations of the rotation and translation +vectors, respectively, and further optimizes them. +@param flags Method for solving a PnP problem: +- **SOLVEPNP_ITERATIVE** Iterative method is based on a Levenberg-Marquardt optimization. In +this case the function finds such a pose that minimizes reprojection error, that is the sum +of squared distances between the observed projections imagePoints and the projected (using +projectPoints ) objectPoints . +- **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang +"Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). +In this case the function requires exactly four object and image points. +- **SOLVEPNP_AP3P** Method is based on the paper of T. Ke, S. Roumeliotis +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). +In this case the function requires exactly four object and image points. +- **SOLVEPNP_EPNP** Method has been introduced by F. Moreno-Noguer, V. Lepetit and P. Fua in the +paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" (@cite lepetit2009epnp). +- **SOLVEPNP_DLS** Method is based on the paper of J. Hesch and S. Roumeliotis. +"A Direct Least-Squares (DLS) Method for PnP" (@cite hesch2011direct). +- **SOLVEPNP_UPNP** Method is based on the paper of A. Penate-Sanchez, J. Andrade-Cetto, +F. Moreno-Noguer. "Exhaustive Linearization for Robust Camera Pose and Focal Length +Estimation" (@cite penate2013exhaustive). In this case the function also estimates the parameters \f$f_x\f$ and \f$f_y\f$ +assuming that both have the same value. Then the cameraMatrix is updated with the estimated +focal length. +- **SOLVEPNP_IPPE** Method is based on the paper of T. Collins and A. Bartoli. +"Infinitesimal Plane-Based Pose Estimation" (@cite Collins14). This method requires coplanar object points. +- **SOLVEPNP_IPPE_SQUARE** Method is based on the paper of Toby Collins and Adrien Bartoli. +"Infinitesimal Plane-Based Pose Estimation" (@cite Collins14). This method is suitable for marker pose estimation. +It requires 4 coplanar object points defined in the following order: + - point 0: [-squareLength / 2, squareLength / 2, 0] + - point 1: [ squareLength / 2, squareLength / 2, 0] + - point 2: [ squareLength / 2, -squareLength / 2, 0] + - point 3: [-squareLength / 2, -squareLength / 2, 0] + +The function estimates the object pose given a set of object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients, see the figure below +(more precisely, the X-axis of the camera frame is pointing to the right, the Y-axis downward +and the Z-axis forward). + +![](pnp.jpg) + +Points expressed in the world frame \f$ \bf{X}_w \f$ are projected into the image plane \f$ \left[ u, v \right] \f$ +using the perspective projection model \f$ \Pi \f$ and the camera intrinsic parameters matrix \f$ \bf{A} \f$: + +\f[ + \begin{align*} + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \bf{A} \hspace{0.1em} \Pi \hspace{0.2em} ^{c}\bf{T}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + f_x & 0 & c_x \\ + 0 & f_y & c_y \\ + 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 \\ + 0 & 0 & 1 & 0 + \end{bmatrix} + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] + +The estimated pose is thus the rotation (`rvec`) and the translation (`tvec`) vectors that allow transforming +a 3D point expressed in the world frame into the camera frame: + +\f[ + \begin{align*} + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \hspace{0.2em} ^{c}\bf{T}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] + +@note + - An example of how to use solvePnP for planar augmented reality can be found at + opencv_source_code/samples/python/plane_ar.py + - If you are using Python: + - Numpy array slices won't work as input because solvePnP requires contiguous + arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of + modules/calib3d/src/solvepnp.cpp version 2.4.9) + - The P3P algorithm requires image points to be in an array of shape (N,1,2) due + to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) + which requires 2-channel information. + - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of + it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = + np.ascontiguousarray(D[:,:2]).reshape((N,1,2)) + - The methods **SOLVEPNP_DLS** and **SOLVEPNP_UPNP** cannot be used as the current implementations are + unstable and sometimes give completely wrong results. If you pass one of these two + flags, **SOLVEPNP_EPNP** method will be used instead. + - The minimum number of points is 4 in the general case. In the case of **SOLVEPNP_P3P** and **SOLVEPNP_AP3P** + methods, it is required to use exactly 4 points (the first 3 points are used to estimate all the solutions + of the P3P problem, the last one is used to retain the best solution that minimizes the reprojection error). + - With **SOLVEPNP_ITERATIVE** method and `useExtrinsicGuess=true`, the minimum number of points is 3 (3 points + are sufficient to compute a pose but there are up to 4 solutions). The initial solution should be close to the + global solution to converge. + - With **SOLVEPNP_IPPE** input points must be >= 4 and object points must be coplanar. + - With **SOLVEPNP_IPPE_SQUARE** this is a special case suitable for marker pose estimation. + Number of input points must be 4. Object points must be defined in the following order: + - point 0: [-squareLength / 2, squareLength / 2, 0] + - point 1: [ squareLength / 2, squareLength / 2, 0] + - point 2: [ squareLength / 2, -squareLength / 2, 0] + - point 3: [-squareLength / 2, -squareLength / 2, 0] + */ +CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, + bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE ); + +/** @brief Finds an object pose from 3D-2D point correspondences using the RANSAC scheme. + +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or +1xN/Nx1 3-channel, where N is the number of points. vector\ can be also passed here. +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, +where N is the number of points. vector\ can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvec Output rotation vector (see @ref Rodrigues ) that, together with tvec, brings points from +the model coordinate system to the camera coordinate system. +@param tvec Output translation vector. +@param useExtrinsicGuess Parameter used for @ref SOLVEPNP_ITERATIVE. If true (1), the function uses +the provided rvec and tvec values as initial approximations of the rotation and translation +vectors, respectively, and further optimizes them. +@param iterationsCount Number of iterations. +@param reprojectionError Inlier threshold value used by the RANSAC procedure. The parameter value +is the maximum allowed distance between the observed and computed point projections to consider it +an inlier. +@param confidence The probability that the algorithm produces a useful result. +@param inliers Output vector that contains indices of inliers in objectPoints and imagePoints . +@param flags Method for solving a PnP problem (see @ref solvePnP ). + +The function estimates an object pose given a set of object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients. This function finds such +a pose that minimizes reprojection error, that is, the sum of squared distances between the observed +projections imagePoints and the projected (using @ref projectPoints ) objectPoints. The use of RANSAC +makes the function resistant to outliers. + +@note + - An example of how to use solvePNPRansac for object detection can be found at + opencv_source_code/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/ + - The default method used to estimate the camera pose for the Minimal Sample Sets step + is #SOLVEPNP_EPNP. Exceptions are: + - if you choose #SOLVEPNP_P3P or #SOLVEPNP_AP3P, these methods will be used. + - if the number of input points is equal to 4, #SOLVEPNP_P3P is used. + - The method used to estimate the camera pose using all the inliers is defined by the + flags parameters unless it is equal to #SOLVEPNP_P3P or #SOLVEPNP_AP3P. In this case, + the method #SOLVEPNP_EPNP will be used instead. + */ +CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArray rvec, OutputArray tvec, + bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, double confidence = 0.99, + OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE ); + +/** @brief Finds an object pose from 3 3D-2D point correspondences. + +@param objectPoints Array of object points in the object coordinate space, 3x3 1-channel or +1x3/3x1 3-channel. vector\ can be also passed here. +@param imagePoints Array of corresponding image points, 3x2 1-channel or 1x3/3x1 2-channel. + vector\ can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvecs Output rotation vectors (see @ref Rodrigues ) that, together with tvecs, brings points from +the model coordinate system to the camera coordinate system. A P3P problem has up to 4 solutions. +@param tvecs Output translation vectors. +@param flags Method for solving a P3P problem: +- **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang +"Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). +- **SOLVEPNP_AP3P** Method is based on the paper of T. Ke and S. Roumeliotis. +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). + +The function estimates the object pose given 3 object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients. + +@note +The solutions are sorted by reprojection errors (lowest to highest). + */ +CV_EXPORTS_W int solveP3P( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + int flags ); + +/** @brief Refine a pose (the translation and the rotation that transform a 3D point expressed in the object coordinate frame +to the camera coordinate frame) from a 3D-2D point correspondences and starting from an initial solution. + +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or 1xN/Nx1 3-channel, +where N is the number of points. vector\ can also be passed here. +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, +where N is the number of points. vector\ can also be passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvec Input/Output rotation vector (see @ref Rodrigues ) that, together with tvec, brings points from +the model coordinate system to the camera coordinate system. Input values are used as an initial solution. +@param tvec Input/Output translation vector. Input values are used as an initial solution. +@param criteria Criteria when to stop the Levenberg-Marquard iterative algorithm. + +The function refines the object pose given at least 3 object points, their corresponding image +projections, an initial solution for the rotation and translation vector, +as well as the camera matrix and the distortion coefficients. +The function minimizes the projection error with respect to the rotation and the translation vectors, according +to a Levenberg-Marquardt iterative minimization @cite Madsen04 @cite Eade13 process. + */ +CV_EXPORTS_W void solvePnPRefineLM( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + InputOutputArray rvec, InputOutputArray tvec, + TermCriteria criteria = TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 20, FLT_EPSILON)); + +/** @brief Refine a pose (the translation and the rotation that transform a 3D point expressed in the object coordinate frame +to the camera coordinate frame) from a 3D-2D point correspondences and starting from an initial solution. + +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or 1xN/Nx1 3-channel, +where N is the number of points. vector\ can also be passed here. +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, +where N is the number of points. vector\ can also be passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvec Input/Output rotation vector (see @ref Rodrigues ) that, together with tvec, brings points from +the model coordinate system to the camera coordinate system. Input values are used as an initial solution. +@param tvec Input/Output translation vector. Input values are used as an initial solution. +@param criteria Criteria when to stop the Levenberg-Marquard iterative algorithm. +@param VVSlambda Gain for the virtual visual servoing control law, equivalent to the \f$\alpha\f$ +gain in the Damped Gauss-Newton formulation. + +The function refines the object pose given at least 3 object points, their corresponding image +projections, an initial solution for the rotation and translation vector, +as well as the camera matrix and the distortion coefficients. +The function minimizes the projection error with respect to the rotation and the translation vectors, using a +virtual visual servoing (VVS) @cite Chaumette06 @cite Marchand16 scheme. + */ +CV_EXPORTS_W void solvePnPRefineVVS( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + InputOutputArray rvec, InputOutputArray tvec, + TermCriteria criteria = TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 20, FLT_EPSILON), + double VVSlambda = 1); + +/** @brief Finds an object pose from 3D-2D point correspondences. +This function returns a list of all the possible solutions (a solution is a +couple), depending on the number of input points and the chosen method: +- P3P methods (@ref SOLVEPNP_P3P, @ref SOLVEPNP_AP3P): 3 or 4 input points. Number of returned solutions can be between 0 and 4 with 3 input points. +- @ref SOLVEPNP_IPPE Input points must be >= 4 and object points must be coplanar. Returns 2 solutions. +- @ref SOLVEPNP_IPPE_SQUARE Special case suitable for marker pose estimation. +Number of input points must be 4 and 2 solutions are returned. Object points must be defined in the following order: + - point 0: [-squareLength / 2, squareLength / 2, 0] + - point 1: [ squareLength / 2, squareLength / 2, 0] + - point 2: [ squareLength / 2, -squareLength / 2, 0] + - point 3: [-squareLength / 2, -squareLength / 2, 0] +- for all the other flags, number of input points must be >= 4 and object points can be in any configuration. +Only 1 solution is returned. + +@param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or +1xN/Nx1 3-channel, where N is the number of points. vector\ can be also passed here. +@param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, +where N is the number of points. vector\ can be also passed here. +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param rvecs Vector of output rotation vectors (see @ref Rodrigues ) that, together with tvecs, brings points from +the model coordinate system to the camera coordinate system. +@param tvecs Vector of output translation vectors. +@param useExtrinsicGuess Parameter used for #SOLVEPNP_ITERATIVE. If true (1), the function uses +the provided rvec and tvec values as initial approximations of the rotation and translation +vectors, respectively, and further optimizes them. +@param flags Method for solving a PnP problem: +- **SOLVEPNP_ITERATIVE** Iterative method is based on a Levenberg-Marquardt optimization. In +this case the function finds such a pose that minimizes reprojection error, that is the sum +of squared distances between the observed projections imagePoints and the projected (using +projectPoints ) objectPoints . +- **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang +"Complete Solution Classification for the Perspective-Three-Point Problem" (@cite gao2003complete). +In this case the function requires exactly four object and image points. +- **SOLVEPNP_AP3P** Method is based on the paper of T. Ke, S. Roumeliotis +"An Efficient Algebraic Solution to the Perspective-Three-Point Problem" (@cite Ke17). +In this case the function requires exactly four object and image points. +- **SOLVEPNP_EPNP** Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the +paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" (@cite lepetit2009epnp). +- **SOLVEPNP_DLS** Method is based on the paper of Joel A. Hesch and Stergios I. Roumeliotis. +"A Direct Least-Squares (DLS) Method for PnP" (@cite hesch2011direct). +- **SOLVEPNP_UPNP** Method is based on the paper of A.Penate-Sanchez, J.Andrade-Cetto, +F.Moreno-Noguer. "Exhaustive Linearization for Robust Camera Pose and Focal Length +Estimation" (@cite penate2013exhaustive). In this case the function also estimates the parameters \f$f_x\f$ and \f$f_y\f$ +assuming that both have the same value. Then the cameraMatrix is updated with the estimated +focal length. +- **SOLVEPNP_IPPE** Method is based on the paper of T. Collins and A. Bartoli. +"Infinitesimal Plane-Based Pose Estimation" (@cite Collins14). This method requires coplanar object points. +- **SOLVEPNP_IPPE_SQUARE** Method is based on the paper of Toby Collins and Adrien Bartoli. +"Infinitesimal Plane-Based Pose Estimation" (@cite Collins14). This method is suitable for marker pose estimation. +It requires 4 coplanar object points defined in the following order: + - point 0: [-squareLength / 2, squareLength / 2, 0] + - point 1: [ squareLength / 2, squareLength / 2, 0] + - point 2: [ squareLength / 2, -squareLength / 2, 0] + - point 3: [-squareLength / 2, -squareLength / 2, 0] +@param rvec Rotation vector used to initialize an iterative PnP refinement algorithm, when flag is SOLVEPNP_ITERATIVE +and useExtrinsicGuess is set to true. +@param tvec Translation vector used to initialize an iterative PnP refinement algorithm, when flag is SOLVEPNP_ITERATIVE +and useExtrinsicGuess is set to true. +@param reprojectionError Optional vector of reprojection error, that is the RMS error +(\f$ \text{RMSE} = \sqrt{\frac{\sum_{i}^{N} \left ( \hat{y_i} - y_i \right )^2}{N}} \f$) between the input image points +and the 3D object points projected with the estimated pose. + +The function estimates the object pose given a set of object points, their corresponding image +projections, as well as the camera matrix and the distortion coefficients, see the figure below +(more precisely, the X-axis of the camera frame is pointing to the right, the Y-axis downward +and the Z-axis forward). + +![](pnp.jpg) + +Points expressed in the world frame \f$ \bf{X}_w \f$ are projected into the image plane \f$ \left[ u, v \right] \f$ +using the perspective projection model \f$ \Pi \f$ and the camera intrinsic parameters matrix \f$ \bf{A} \f$: + +\f[ + \begin{align*} + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \bf{A} \hspace{0.1em} \Pi \hspace{0.2em} ^{c}\bf{T}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + u \\ + v \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + f_x & 0 & c_x \\ + 0 & f_y & c_y \\ + 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 \\ + 0 & 0 & 1 & 0 + \end{bmatrix} + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] + +The estimated pose is thus the rotation (`rvec`) and the translation (`tvec`) vectors that allow transforming +a 3D point expressed in the world frame into the camera frame: + +\f[ + \begin{align*} + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \hspace{0.2em} ^{c}\bf{T}_w + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} \\ + \begin{bmatrix} + X_c \\ + Y_c \\ + Z_c \\ + 1 + \end{bmatrix} &= + \begin{bmatrix} + r_{11} & r_{12} & r_{13} & t_x \\ + r_{21} & r_{22} & r_{23} & t_y \\ + r_{31} & r_{32} & r_{33} & t_z \\ + 0 & 0 & 0 & 1 + \end{bmatrix} + \begin{bmatrix} + X_{w} \\ + Y_{w} \\ + Z_{w} \\ + 1 + \end{bmatrix} + \end{align*} +\f] + +@note + - An example of how to use solvePnP for planar augmented reality can be found at + opencv_source_code/samples/python/plane_ar.py + - If you are using Python: + - Numpy array slices won't work as input because solvePnP requires contiguous + arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of + modules/calib3d/src/solvepnp.cpp version 2.4.9) + - The P3P algorithm requires image points to be in an array of shape (N,1,2) due + to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) + which requires 2-channel information. + - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of + it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = + np.ascontiguousarray(D[:,:2]).reshape((N,1,2)) + - The methods **SOLVEPNP_DLS** and **SOLVEPNP_UPNP** cannot be used as the current implementations are + unstable and sometimes give completely wrong results. If you pass one of these two + flags, **SOLVEPNP_EPNP** method will be used instead. + - The minimum number of points is 4 in the general case. In the case of **SOLVEPNP_P3P** and **SOLVEPNP_AP3P** + methods, it is required to use exactly 4 points (the first 3 points are used to estimate all the solutions + of the P3P problem, the last one is used to retain the best solution that minimizes the reprojection error). + - With **SOLVEPNP_ITERATIVE** method and `useExtrinsicGuess=true`, the minimum number of points is 3 (3 points + are sufficient to compute a pose but there are up to 4 solutions). The initial solution should be close to the + global solution to converge. + - With **SOLVEPNP_IPPE** input points must be >= 4 and object points must be coplanar. + - With **SOLVEPNP_IPPE_SQUARE** this is a special case suitable for marker pose estimation. + Number of input points must be 4. Object points must be defined in the following order: + - point 0: [-squareLength / 2, squareLength / 2, 0] + - point 1: [ squareLength / 2, squareLength / 2, 0] + - point 2: [ squareLength / 2, -squareLength / 2, 0] + - point 3: [-squareLength / 2, -squareLength / 2, 0] + */ +CV_EXPORTS_W int solvePnPGeneric( InputArray objectPoints, InputArray imagePoints, + InputArray cameraMatrix, InputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + bool useExtrinsicGuess = false, SolvePnPMethod flags = SOLVEPNP_ITERATIVE, + InputArray rvec = noArray(), InputArray tvec = noArray(), + OutputArray reprojectionError = noArray() ); + +/** @brief Finds an initial camera matrix from 3D-2D point correspondences. + +@param objectPoints Vector of vectors of the calibration pattern points in the calibration pattern +coordinate space. In the old interface all the per-view vectors are concatenated. See +calibrateCamera for details. +@param imagePoints Vector of vectors of the projections of the calibration pattern points. In the +old interface all the per-view vectors are concatenated. +@param imageSize Image size in pixels used to initialize the principal point. +@param aspectRatio If it is zero or negative, both \f$f_x\f$ and \f$f_y\f$ are estimated independently. +Otherwise, \f$f_x = f_y * \texttt{aspectRatio}\f$ . + +The function estimates and returns an initial camera matrix for the camera calibration process. +Currently, the function only supports planar calibration patterns, which are patterns where each +object point has z-coordinate =0. + */ +CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, + Size imageSize, double aspectRatio = 1.0 ); + +/** @brief Finds the positions of internal corners of the chessboard. + +@param image Source chessboard view. It must be an 8-bit grayscale or color image. +@param patternSize Number of inner corners per a chessboard row and column +( patternSize = cv::Size(points_per_row,points_per_colum) = cv::Size(columns,rows) ). +@param corners Output array of detected corners. +@param flags Various operation flags that can be zero or a combination of the following values: +- **CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black +and white, rather than a fixed threshold level (computed from the average image brightness). +- **CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before +applying fixed or adaptive thresholding. +- **CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter, +square-like shape) to filter out false quads extracted at the contour retrieval stage. +- **CALIB_CB_FAST_CHECK** Run a fast check on the image that looks for chessboard corners, +and shortcut the call if none is found. This can drastically speed up the call in the +degenerate condition when no chessboard is observed. + +The function attempts to determine whether the input image is a view of the chessboard pattern and +locate the internal chessboard corners. The function returns a non-zero value if all of the corners +are found and they are placed in a certain order (row by row, left to right in every row). +Otherwise, if the function fails to find all the corners or reorder them, it returns 0. For example, +a regular chessboard has 8 x 8 squares and 7 x 7 internal corners, that is, points where the black +squares touch each other. The detected coordinates are approximate, and to determine their positions +more accurately, the function calls cornerSubPix. You also may use the function cornerSubPix with +different parameters if returned coordinates are not accurate enough. + +Sample usage of detecting and drawing chessboard corners: : +@code + Size patternsize(8,6); //interior number of corners + Mat gray = ....; //source image + vector corners; //this will be filled by the detected corners + + //CALIB_CB_FAST_CHECK saves a lot of time on images + //that do not contain any chessboard corners + bool patternfound = findChessboardCorners(gray, patternsize, corners, + CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE + + CALIB_CB_FAST_CHECK); + + if(patternfound) + cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1), + TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1)); + + drawChessboardCorners(img, patternsize, Mat(corners), patternfound); +@endcode +@note The function requires white space (like a square-thick border, the wider the better) around +the board to make the detection more robust in various environments. Otherwise, if there is no +border and the background is dark, the outer black squares cannot be segmented properly and so the +square grouping and ordering algorithm fails. + */ +CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, + int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE ); + +/* + Checks whether the image contains chessboard of the specific size or not. + If yes, nonzero value is returned. +*/ +CV_EXPORTS_W bool checkChessboard(InputArray img, Size size); + +/** @brief Finds the positions of internal corners of the chessboard using a sector based approach. + +@param image Source chessboard view. It must be an 8-bit grayscale or color image. +@param patternSize Number of inner corners per a chessboard row and column +( patternSize = cv::Size(points_per_row,points_per_colum) = cv::Size(columns,rows) ). +@param corners Output array of detected corners. +@param flags Various operation flags that can be zero or a combination of the following values: +- **CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before detection. +- **CALIB_CB_EXHAUSTIVE** Run an exhaustive search to improve detection rate. +- **CALIB_CB_ACCURACY** Up sample input image to improve sub-pixel accuracy due to aliasing effects. +This should be used if an accurate camera calibration is required. + +The function is analog to findchessboardCorners but uses a localized radon +transformation approximated by box filters being more robust to all sort of +noise, faster on larger images and is able to directly return the sub-pixel +position of the internal chessboard corners. The Method is based on the paper +@cite duda2018 "Accurate Detection and Localization of Checkerboard Corners for +Calibration" demonstrating that the returned sub-pixel positions are more +accurate than the one returned by cornerSubPix allowing a precise camera +calibration for demanding applications. + +@note The function requires a white boarder with roughly the same width as one +of the checkerboard fields around the whole board to improve the detection in +various environments. In addition, because of the localized radon +transformation it is beneficial to use round corners for the field corners +which are located on the outside of the board. The following figure illustrates +a sample checkerboard optimized for the detection. However, any other checkerboard +can be used as well. +![Checkerboard](pics/checkerboard_radon.png) + */ +CV_EXPORTS_W bool findChessboardCornersSB(InputArray image,Size patternSize, OutputArray corners,int flags=0); + +//! finds subpixel-accurate positions of the chessboard corners +CV_EXPORTS_W bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size ); + +/** @brief Renders the detected chessboard corners. + +@param image Destination image. It must be an 8-bit color image. +@param patternSize Number of inner corners per a chessboard row and column +(patternSize = cv::Size(points_per_row,points_per_column)). +@param corners Array of detected corners, the output of findChessboardCorners. +@param patternWasFound Parameter indicating whether the complete board was found or not. The +return value of findChessboardCorners should be passed here. + +The function draws individual chessboard corners detected either as red circles if the board was not +found, or as colored corners connected with lines if the board was found. + */ +CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize, + InputArray corners, bool patternWasFound ); + +/** @brief Draw axes of the world/object coordinate system from pose estimation. @sa solvePnP + +@param image Input/output image. It must have 1 or 3 channels. The number of channels is not altered. +@param cameraMatrix Input 3x3 floating-point matrix of camera intrinsic parameters. +\f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is empty, the zero distortion coefficients are assumed. +@param rvec Rotation vector (see @ref Rodrigues ) that, together with tvec, brings points from +the model coordinate system to the camera coordinate system. +@param tvec Translation vector. +@param length Length of the painted axes in the same unit than tvec (usually in meters). +@param thickness Line thickness of the painted axes. + +This function draws the axes of the world/object coordinate system w.r.t. to the camera frame. +OX is drawn in red, OY in green and OZ in blue. + */ +CV_EXPORTS_W void drawFrameAxes(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs, + InputArray rvec, InputArray tvec, float length, int thickness=3); + +struct CV_EXPORTS_W_SIMPLE CirclesGridFinderParameters +{ + CV_WRAP CirclesGridFinderParameters(); + CV_PROP_RW cv::Size2f densityNeighborhoodSize; + CV_PROP_RW float minDensity; + CV_PROP_RW int kmeansAttempts; + CV_PROP_RW int minDistanceToAddKeypoint; + CV_PROP_RW int keypointScale; + CV_PROP_RW float minGraphConfidence; + CV_PROP_RW float vertexGain; + CV_PROP_RW float vertexPenalty; + CV_PROP_RW float existingVertexGain; + CV_PROP_RW float edgeGain; + CV_PROP_RW float edgePenalty; + CV_PROP_RW float convexHullFactor; + CV_PROP_RW float minRNGEdgeSwitchDist; + + enum GridType + { + SYMMETRIC_GRID, ASYMMETRIC_GRID + }; + GridType gridType; + + CV_PROP_RW float squareSize; //!< Distance between two adjacent points. Used by CALIB_CB_CLUSTERING. + CV_PROP_RW float maxRectifiedDistance; //!< Max deviation from predicion. Used by CALIB_CB_CLUSTERING. +}; + +#ifndef DISABLE_OPENCV_3_COMPATIBILITY +typedef CirclesGridFinderParameters CirclesGridFinderParameters2; +#endif + +/** @brief Finds centers in the grid of circles. + +@param image grid view of input circles; it must be an 8-bit grayscale or color image. +@param patternSize number of circles per row and column +( patternSize = Size(points_per_row, points_per_colum) ). +@param centers output array of detected centers. +@param flags various operation flags that can be one of the following values: +- **CALIB_CB_SYMMETRIC_GRID** uses symmetric pattern of circles. +- **CALIB_CB_ASYMMETRIC_GRID** uses asymmetric pattern of circles. +- **CALIB_CB_CLUSTERING** uses a special algorithm for grid detection. It is more robust to +perspective distortions but much more sensitive to background clutter. +@param blobDetector feature detector that finds blobs like dark circles on light background. +@param parameters struct for finding circles in a grid pattern. + +The function attempts to determine whether the input image contains a grid of circles. If it is, the +function locates centers of the circles. The function returns a non-zero value if all of the centers +have been found and they have been placed in a certain order (row by row, left to right in every +row). Otherwise, if the function fails to find all the corners or reorder them, it returns 0. + +Sample usage of detecting and drawing the centers of circles: : +@code + Size patternsize(7,7); //number of centers + Mat gray = ....; //source image + vector centers; //this will be filled by the detected centers + + bool patternfound = findCirclesGrid(gray, patternsize, centers); + + drawChessboardCorners(img, patternsize, Mat(centers), patternfound); +@endcode +@note The function requires white space (like a square-thick border, the wider the better) around +the board to make the detection more robust in various environments. + */ +CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, + OutputArray centers, int flags, + const Ptr &blobDetector, + const CirclesGridFinderParameters& parameters); + +/** @overload */ +CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, + OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID, + const Ptr &blobDetector = SimpleBlobDetector::create()); + +/** @brief Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. + +@param objectPoints In the new interface it is a vector of vectors of calibration pattern points in +the calibration pattern coordinate space (e.g. std::vector>). The outer +vector contains as many elements as the number of the pattern views. If the same calibration pattern +is shown in each view and it is fully visible, all the vectors will be the same. Although, it is +possible to use partially occluded patterns, or even different patterns in different views. Then, +the vectors will be different. The points are 3D, but since they are in a pattern coordinate system, +then, if the rig is planar, it may make sense to put the model to a XY coordinate plane so that +Z-coordinate of each input object point is 0. +In the old interface all the vectors of object points from different views are concatenated +together. +@param imagePoints In the new interface it is a vector of vectors of the projections of calibration +pattern points (e.g. std::vector>). imagePoints.size() and +objectPoints.size() and imagePoints[i].size() must be equal to objectPoints[i].size() for each i. +In the old interface all the vectors of object points from different views are concatenated +together. +@param imageSize Size of the image used only to initialize the intrinsic camera matrix. +@param cameraMatrix Output 3x3 floating-point camera matrix +\f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS +and/or CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be +initialized before calling the function. +@param distCoeffs Output vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. +@param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view +(e.g. std::vector>). That is, each k-th rotation vector together with the corresponding +k-th translation vector (see the next output parameter description) brings the calibration pattern +from the model coordinate space (in which object points are specified) to the world coordinate +space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. *M* -1). +@param tvecs Output vector of translation vectors estimated for each pattern view. +@param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. + Order of deviations values: +\f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, + s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. +@param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. + Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, + \f$R_i, T_i\f$ are concatenated 1x3 vectors. + @param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. +@param flags Different flags that may be zero or a combination of the following values: +- **CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of +fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image +center ( imageSize is used), and focal distances are computed in a least-squares fashion. +Note, that if intrinsic parameters are known, there is no need to use this function just to +estimate extrinsic parameters. Use solvePnP instead. +- **CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global +optimization. It stays at the center or at a different location specified when +CALIB_USE_INTRINSIC_GUESS is set too. +- **CALIB_FIX_ASPECT_RATIO** The functions considers only fy as a free parameter. The +ratio fx/fy stays the same as in the input cameraMatrix . When +CALIB_USE_INTRINSIC_GUESS is not set, the actual input values of fx and fy are +ignored, only their ratio is computed and used further. +- **CALIB_ZERO_TANGENT_DIST** Tangential distortion coefficients \f$(p_1, p_2)\f$ are set +to zeros and stay zero. +- **CALIB_FIX_K1,...,CALIB_FIX_K6** The corresponding radial distortion +coefficient is not changed during the optimization. If CALIB_USE_INTRINSIC_GUESS is +set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_RATIONAL_MODEL** Coefficients k4, k5, and k6 are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the rational model and return 8 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the thin prism model and return 12 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the tilted sensor model and return 14 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +@param criteria Termination criteria for the iterative optimization algorithm. + +@return the overall RMS re-projection error. + +The function estimates the intrinsic camera parameters and extrinsic parameters for each of the +views. The algorithm is based on @cite Zhang2000 and @cite BouguetMCT . The coordinates of 3D object +points and their corresponding 2D projections in each view must be specified. That may be achieved +by using an object with a known geometry and easily detectable feature points. Such an object is +called a calibration rig or calibration pattern, and OpenCV has built-in support for a chessboard as +a calibration rig (see findChessboardCorners ). Currently, initialization of intrinsic parameters +(when CALIB_USE_INTRINSIC_GUESS is not set) is only implemented for planar calibration +patterns (where Z-coordinates of the object points must be all zeros). 3D calibration rigs can also +be used as long as initial cameraMatrix is provided. + +The algorithm performs the following steps: + +- Compute the initial intrinsic parameters (the option only available for planar calibration + patterns) or read them from the input parameters. The distortion coefficients are all set to + zeros initially unless some of CALIB_FIX_K? are specified. + +- Estimate the initial camera pose as if the intrinsic parameters have been already known. This is + done using solvePnP . + +- Run the global Levenberg-Marquardt optimization algorithm to minimize the reprojection error, + that is, the total sum of squared distances between the observed feature points imagePoints and + the projected (using the current estimates for camera parameters and the poses) object points + objectPoints. See projectPoints for details. + +@note + If you use a non-square (=non-NxN) grid and findChessboardCorners for calibration, and + calibrateCamera returns bad values (zero distortion coefficients, an image center very far from + (w/2-0.5,h/2-0.5), and/or large differences between \f$f_x\f$ and \f$f_y\f$ (ratios of 10:1 or more)), + then you have probably used patternSize=cvSize(rows,cols) instead of using + patternSize=cvSize(cols,rows) in findChessboardCorners . + +@sa + calibrateCameraRO, findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort + */ +CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray stdDeviationsIntrinsics, + OutputArray stdDeviationsExtrinsics, + OutputArray perViewErrors, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @overload */ +CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @brief Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. + +This function is an extension of calibrateCamera() with the method of releasing object which was +proposed in @cite strobl2011iccv. In many common cases with inaccurate, unmeasured, roughly planar +targets (calibration plates), this method can dramatically improve the precision of the estimated +camera parameters. Both the object-releasing method and standard method are supported by this +function. Use the parameter **iFixedPoint** for method selection. In the internal implementation, +calibrateCamera() is a wrapper for this function. + +@param objectPoints Vector of vectors of calibration pattern points in the calibration pattern +coordinate space. See calibrateCamera() for details. If the method of releasing object to be used, +the identical calibration board must be used in each view and it must be fully visible, and all +objectPoints[i] must be the same and all points should be roughly close to a plane. **The calibration +target has to be rigid, or at least static if the camera (rather than the calibration target) is +shifted for grabbing images.** +@param imagePoints Vector of vectors of the projections of calibration pattern points. See +calibrateCamera() for details. +@param imageSize Size of the image used only to initialize the intrinsic camera matrix. +@param iFixedPoint The index of the 3D object point in objectPoints[0] to be fixed. It also acts as +a switch for calibration method selection. If object-releasing method to be used, pass in the +parameter in the range of [1, objectPoints[0].size()-2], otherwise a value out of this range will +make standard calibration method selected. Usually the top-right corner point of the calibration +board grid is recommended to be fixed when object-releasing method being utilized. According to +\cite strobl2011iccv, two other points are also fixed. In this implementation, objectPoints[0].front +and objectPoints[0].back.z are used. With object-releasing method, accurate rvecs, tvecs and +newObjPoints are only possible if coordinates of these three fixed points are accurate enough. +@param cameraMatrix Output 3x3 floating-point camera matrix. See calibrateCamera() for details. +@param distCoeffs Output vector of distortion coefficients. See calibrateCamera() for details. +@param rvecs Output vector of rotation vectors estimated for each pattern view. See calibrateCamera() +for details. +@param tvecs Output vector of translation vectors estimated for each pattern view. +@param newObjPoints The updated output vector of calibration pattern points. The coordinates might +be scaled based on three fixed points. The returned coordinates are accurate only if the above +mentioned three fixed points are accurate. If not needed, noArray() can be passed in. This parameter +is ignored with standard calibration method. +@param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. +See calibrateCamera() for details. +@param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. +See calibrateCamera() for details. +@param stdDeviationsObjPoints Output vector of standard deviations estimated for refined coordinates +of calibration pattern points. It has the same size and order as objectPoints[0] vector. This +parameter is ignored with standard calibration method. + @param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. +@param flags Different flags that may be zero or a combination of some predefined values. See +calibrateCamera() for details. If the method of releasing object is used, the calibration time may +be much longer. CALIB_USE_QR or CALIB_USE_LU could be used for faster calibration with potentially +less precise and less stable in some rare cases. +@param criteria Termination criteria for the iterative optimization algorithm. + +@return the overall RMS re-projection error. + +The function estimates the intrinsic camera parameters and extrinsic parameters for each of the +views. The algorithm is based on @cite Zhang2000, @cite BouguetMCT and @cite strobl2011iccv. See +calibrateCamera() for other detailed explanations. +@sa + calibrateCamera, findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort + */ +CV_EXPORTS_AS(calibrateCameraROExtended) double calibrateCameraRO( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, int iFixedPoint, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray newObjPoints, + OutputArray stdDeviationsIntrinsics, + OutputArray stdDeviationsExtrinsics, + OutputArray stdDeviationsObjPoints, + OutputArray perViewErrors, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @overload */ +CV_EXPORTS_W double calibrateCameraRO( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints, Size imageSize, int iFixedPoint, + InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + OutputArray newObjPoints, + int flags = 0, TermCriteria criteria = TermCriteria( + TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); + +/** @brief Computes useful camera characteristics from the camera matrix. + +@param cameraMatrix Input camera matrix that can be estimated by calibrateCamera or +stereoCalibrate . +@param imageSize Input image size in pixels. +@param apertureWidth Physical width in mm of the sensor. +@param apertureHeight Physical height in mm of the sensor. +@param fovx Output field of view in degrees along the horizontal sensor axis. +@param fovy Output field of view in degrees along the vertical sensor axis. +@param focalLength Focal length of the lens in mm. +@param principalPoint Principal point in mm. +@param aspectRatio \f$f_y/f_x\f$ + +The function computes various useful camera characteristics from the previously estimated camera +matrix. + +@note + Do keep in mind that the unity measure 'mm' stands for whatever unit of measure one chooses for + the chessboard pitch (it can thus be any value). + */ +CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, Size imageSize, + double apertureWidth, double apertureHeight, + CV_OUT double& fovx, CV_OUT double& fovy, + CV_OUT double& focalLength, CV_OUT Point2d& principalPoint, + CV_OUT double& aspectRatio ); + +/** @brief Calibrates the stereo camera. + +@param objectPoints Vector of vectors of the calibration pattern points. +@param imagePoints1 Vector of vectors of the projections of the calibration pattern points, +observed by the first camera. +@param imagePoints2 Vector of vectors of the projections of the calibration pattern points, +observed by the second camera. +@param cameraMatrix1 Input/output first camera matrix: +\f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If +any of CALIB_USE_INTRINSIC_GUESS , CALIB_FIX_ASPECT_RATIO , +CALIB_FIX_INTRINSIC , or CALIB_FIX_FOCAL_LENGTH are specified, some or all of the +matrix components must be initialized. See the flags description for details. +@param distCoeffs1 Input/output vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. The output vector length depends on the flags. +@param cameraMatrix2 Input/output second camera matrix. The parameter is similar to cameraMatrix1 +@param distCoeffs2 Input/output lens distortion coefficients for the second camera. The parameter +is similar to distCoeffs1 . +@param imageSize Size of the image used only to initialize intrinsic camera matrix. +@param R Output rotation matrix between the 1st and the 2nd camera coordinate systems. +@param T Output translation vector between the coordinate systems of the cameras. +@param E Output essential matrix. +@param F Output fundamental matrix. +@param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. +@param flags Different flags that may be zero or a combination of the following values: +- **CALIB_FIX_INTRINSIC** Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F +matrices are estimated. +- **CALIB_USE_INTRINSIC_GUESS** Optimize some or all of the intrinsic parameters +according to the specified flags. Initial values are provided by the user. +- **CALIB_USE_EXTRINSIC_GUESS** R, T contain valid initial values that are optimized further. +Otherwise R, T are initialized to the median value of the pattern views (each dimension separately). +- **CALIB_FIX_PRINCIPAL_POINT** Fix the principal points during the optimization. +- **CALIB_FIX_FOCAL_LENGTH** Fix \f$f^{(j)}_x\f$ and \f$f^{(j)}_y\f$ . +- **CALIB_FIX_ASPECT_RATIO** Optimize \f$f^{(j)}_y\f$ . Fix the ratio \f$f^{(j)}_x/f^{(j)}_y\f$ +. +- **CALIB_SAME_FOCAL_LENGTH** Enforce \f$f^{(0)}_x=f^{(1)}_x\f$ and \f$f^{(0)}_y=f^{(1)}_y\f$ . +- **CALIB_ZERO_TANGENT_DIST** Set tangential distortion coefficients for each camera to +zeros and fix there. +- **CALIB_FIX_K1,...,CALIB_FIX_K6** Do not change the corresponding radial +distortion coefficient during the optimization. If CALIB_USE_INTRINSIC_GUESS is set, +the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_RATIONAL_MODEL** Enable coefficients k4, k5, and k6. To provide the backward +compatibility, this extra flag should be explicitly specified to make the calibration +function use the rational model and return 8 coefficients. If the flag is not set, the +function computes and returns only 5 distortion coefficients. +- **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the thin prism model and return 12 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +- **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the +backward compatibility, this extra flag should be explicitly specified to make the +calibration function use the tilted sensor model and return 14 coefficients. If the flag is not +set, the function computes and returns only 5 distortion coefficients. +- **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during +the optimization. If CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the +supplied distCoeffs matrix is used. Otherwise, it is set to 0. +@param criteria Termination criteria for the iterative optimization algorithm. + +The function estimates transformation between two cameras making a stereo pair. If you have a stereo +camera where the relative position and orientation of two cameras is fixed, and if you computed +poses of an object relative to the first camera and to the second camera, (R1, T1) and (R2, T2), +respectively (this can be done with solvePnP ), then those poses definitely relate to each other. +This means that, given ( \f$R_1\f$,\f$T_1\f$ ), it should be possible to compute ( \f$R_2\f$,\f$T_2\f$ ). You only +need to know the position and orientation of the second camera relative to the first camera. This is +what the described function does. It computes ( \f$R\f$,\f$T\f$ ) so that: + +\f[R_2=R*R_1\f] +\f[T_2=R*T_1 + T,\f] + +Optionally, it computes the essential matrix E: + +\f[E= \vecthreethree{0}{-T_2}{T_1}{T_2}{0}{-T_0}{-T_1}{T_0}{0} *R\f] + +where \f$T_i\f$ are components of the translation vector \f$T\f$ : \f$T=[T_0, T_1, T_2]^T\f$ . And the function +can also compute the fundamental matrix F: + +\f[F = cameraMatrix2^{-T} E cameraMatrix1^{-1}\f] + +Besides the stereo-related information, the function can also perform a full calibration of each of +two cameras. However, due to the high dimensionality of the parameter space and noise in the input +data, the function can diverge from the correct solution. If the intrinsic parameters can be +estimated with high accuracy for each of the cameras individually (for example, using +calibrateCamera ), you are recommended to do so and then pass CALIB_FIX_INTRINSIC flag to the +function along with the computed intrinsic parameters. Otherwise, if all the parameters are +estimated at once, it makes sense to restrict some parameters, for example, pass +CALIB_SAME_FOCAL_LENGTH and CALIB_ZERO_TANGENT_DIST flags, which is usually a +reasonable assumption. + +Similarly to calibrateCamera , the function minimizes the total re-projection error for all the +points in all the available views from both cameras. The function returns the final value of the +re-projection error. + */ +CV_EXPORTS_AS(stereoCalibrateExtended) double stereoCalibrate( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1, + InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2, + Size imageSize, InputOutputArray R,InputOutputArray T, OutputArray E, OutputArray F, + OutputArray perViewErrors, int flags = CALIB_FIX_INTRINSIC, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) ); + +/// @overload +CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints, + InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1, + InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2, + Size imageSize, OutputArray R,OutputArray T, OutputArray E, OutputArray F, + int flags = CALIB_FIX_INTRINSIC, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) ); + +/** @brief Computes rectification transforms for each head of a calibrated stereo camera. + +@param cameraMatrix1 First camera matrix. +@param distCoeffs1 First camera distortion parameters. +@param cameraMatrix2 Second camera matrix. +@param distCoeffs2 Second camera distortion parameters. +@param imageSize Size of the image used for stereo calibration. +@param R Rotation matrix from the coordinate system of the first camera to the second. +@param T Translation vector from the coordinate system of the first camera to the second. +@param R1 Output 3x3 rectification transform (rotation matrix) for the first camera. +@param R2 Output 3x3 rectification transform (rotation matrix) for the second camera. +@param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first +camera. +@param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second +camera. +@param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). +@param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set, +the function makes the principal points of each camera have the same pixel coordinates in the +rectified views. And if the flag is not set, the function may still shift the images in the +horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the +useful image area. +@param alpha Free scaling parameter. If it is -1 or absent, the function performs the default +scaling. Otherwise, the parameter should be between 0 and 1. alpha=0 means that the rectified +images are zoomed and shifted so that only valid pixels are visible (no black areas after +rectification). alpha=1 means that the rectified image is decimated and shifted so that all the +pixels from the original images from the cameras are retained in the rectified images (no source +image pixels are lost). Obviously, any intermediate value yields an intermediate result between +those two extreme cases. +@param newImageSize New image resolution after rectification. The same size should be passed to +initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) +is passed (default), it is set to the original imageSize . Setting it to larger value can help you +preserve details in the original image, especially when there is a big radial distortion. +@param validPixROI1 Optional output rectangles inside the rectified images where all the pixels +are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller +(see the picture below). +@param validPixROI2 Optional output rectangles inside the rectified images where all the pixels +are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller +(see the picture below). + +The function computes the rotation matrices for each camera that (virtually) make both camera image +planes the same plane. Consequently, this makes all the epipolar lines parallel and thus simplifies +the dense stereo correspondence problem. The function takes the matrices computed by stereoCalibrate +as input. As output, it provides two rotation matrices and also two projection matrices in the new +coordinates. The function distinguishes the following two cases: + +- **Horizontal stereo**: the first and the second camera views are shifted relative to each other + mainly along the x axis (with possible small vertical shift). In the rectified images, the + corresponding epipolar lines in the left and right cameras are horizontal and have the same + y-coordinate. P1 and P2 look like: + + \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx_1 & 0 \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f] + + \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx_2 & T_x*f \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f] + + where \f$T_x\f$ is a horizontal shift between the cameras and \f$cx_1=cx_2\f$ if + CALIB_ZERO_DISPARITY is set. + +- **Vertical stereo**: the first and the second camera views are shifted relative to each other + mainly in vertical direction (and probably a bit in the horizontal direction too). The epipolar + lines in the rectified images are vertical and have the same x-coordinate. P1 and P2 look like: + + \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_1 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f] + + \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_2 & T_y*f \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f] + + where \f$T_y\f$ is a vertical shift between the cameras and \f$cy_1=cy_2\f$ if CALIB_ZERO_DISPARITY is + set. + +As you can see, the first three columns of P1 and P2 will effectively be the new "rectified" camera +matrices. The matrices, together with R1 and R2 , can then be passed to initUndistortRectifyMap to +initialize the rectification map for each camera. + +See below the screenshot from the stereo_calib.cpp sample. Some red horizontal lines pass through +the corresponding image regions. This means that the images are well rectified, which is what most +stereo correspondence algorithms rely on. The green rectangles are roi1 and roi2 . You see that +their interiors are all valid pixels. + +![image](pics/stereo_undistort.jpg) + */ +CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1, + InputArray cameraMatrix2, InputArray distCoeffs2, + Size imageSize, InputArray R, InputArray T, + OutputArray R1, OutputArray R2, + OutputArray P1, OutputArray P2, + OutputArray Q, int flags = CALIB_ZERO_DISPARITY, + double alpha = -1, Size newImageSize = Size(), + CV_OUT Rect* validPixROI1 = 0, CV_OUT Rect* validPixROI2 = 0 ); + +/** @brief Computes a rectification transform for an uncalibrated stereo camera. + +@param points1 Array of feature points in the first image. +@param points2 The corresponding points in the second image. The same formats as in +findFundamentalMat are supported. +@param F Input fundamental matrix. It can be computed from the same set of point pairs using +findFundamentalMat . +@param imgSize Size of the image. +@param H1 Output rectification homography matrix for the first image. +@param H2 Output rectification homography matrix for the second image. +@param threshold Optional threshold used to filter out the outliers. If the parameter is greater +than zero, all the point pairs that do not comply with the epipolar geometry (that is, the points +for which \f$|\texttt{points2[i]}^T*\texttt{F}*\texttt{points1[i]}|>\texttt{threshold}\f$ ) are +rejected prior to computing the homographies. Otherwise, all the points are considered inliers. + +The function computes the rectification transformations without knowing intrinsic parameters of the +cameras and their relative position in the space, which explains the suffix "uncalibrated". Another +related difference from stereoRectify is that the function outputs not the rectification +transformations in the object (3D) space, but the planar perspective transformations encoded by the +homography matrices H1 and H2 . The function implements the algorithm @cite Hartley99 . + +@note + While the algorithm does not need to know the intrinsic parameters of the cameras, it heavily + depends on the epipolar geometry. Therefore, if the camera lenses have a significant distortion, + it would be better to correct it before computing the fundamental matrix and calling this + function. For example, distortion coefficients can be estimated for each head of stereo camera + separately by using calibrateCamera . Then, the images can be corrected using undistort , or + just the point coordinates can be corrected with undistortPoints . + */ +CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2, + InputArray F, Size imgSize, + OutputArray H1, OutputArray H2, + double threshold = 5 ); + +//! computes the rectification transformations for 3-head camera, where all the heads are on the same line. +CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1, + InputArray cameraMatrix2, InputArray distCoeffs2, + InputArray cameraMatrix3, InputArray distCoeffs3, + InputArrayOfArrays imgpt1, InputArrayOfArrays imgpt3, + Size imageSize, InputArray R12, InputArray T12, + InputArray R13, InputArray T13, + OutputArray R1, OutputArray R2, OutputArray R3, + OutputArray P1, OutputArray P2, OutputArray P3, + OutputArray Q, double alpha, Size newImgSize, + CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags ); + +/** @brief Returns the new camera matrix based on the free scaling parameter. + +@param cameraMatrix Input camera matrix. +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of +4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are +assumed. +@param imageSize Original image size. +@param alpha Free scaling parameter between 0 (when all the pixels in the undistorted image are +valid) and 1 (when all the source image pixels are retained in the undistorted image). See +stereoRectify for details. +@param newImgSize Image size after rectification. By default, it is set to imageSize . +@param validPixROI Optional output rectangle that outlines all-good-pixels region in the +undistorted image. See roi1, roi2 description in stereoRectify . +@param centerPrincipalPoint Optional flag that indicates whether in the new camera matrix the +principal point should be at the image center or not. By default, the principal point is chosen to +best fit a subset of the source image (determined by alpha) to the corrected image. +@return new_camera_matrix Output new camera matrix. + +The function computes and returns the optimal new camera matrix based on the free scaling parameter. +By varying this parameter, you may retrieve only sensible pixels alpha=0 , keep all the original +image pixels if there is valuable information in the corners alpha=1 , or get something in between. +When alpha\>0 , the undistorted result is likely to have some black pixels corresponding to +"virtual" pixels outside of the captured distorted image. The original camera matrix, distortion +coefficients, the computed new camera matrix, and newImageSize should be passed to +initUndistortRectifyMap to produce the maps for remap . + */ +CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs, + Size imageSize, double alpha, Size newImgSize = Size(), + CV_OUT Rect* validPixROI = 0, + bool centerPrincipalPoint = false); + +/** @brief Computes Hand-Eye calibration: \f$_{}^{g}\textrm{T}_c\f$ + +@param[in] R_gripper2base Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the gripper frame to the robot base frame (\f$_{}^{b}\textrm{T}_g\f$). +This is a vector (`vector`) that contains the rotation matrices for all the transformations +from gripper frame to robot base frame. +@param[in] t_gripper2base Translation part extracted from the homogeneous matrix that transforms a point +expressed in the gripper frame to the robot base frame (\f$_{}^{b}\textrm{T}_g\f$). +This is a vector (`vector`) that contains the translation vectors for all the transformations +from gripper frame to robot base frame. +@param[in] R_target2cam Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the target frame to the camera frame (\f$_{}^{c}\textrm{T}_t\f$). +This is a vector (`vector`) that contains the rotation matrices for all the transformations +from calibration target frame to camera frame. +@param[in] t_target2cam Rotation part extracted from the homogeneous matrix that transforms a point +expressed in the target frame to the camera frame (\f$_{}^{c}\textrm{T}_t\f$). +This is a vector (`vector`) that contains the translation vectors for all the transformations +from calibration target frame to camera frame. +@param[out] R_cam2gripper Estimated rotation part extracted from the homogeneous matrix that transforms a point +expressed in the camera frame to the gripper frame (\f$_{}^{g}\textrm{T}_c\f$). +@param[out] t_cam2gripper Estimated translation part extracted from the homogeneous matrix that transforms a point +expressed in the camera frame to the gripper frame (\f$_{}^{g}\textrm{T}_c\f$). +@param[in] method One of the implemented Hand-Eye calibration method, see cv::HandEyeCalibrationMethod + +The function performs the Hand-Eye calibration using various methods. One approach consists in estimating the +rotation then the translation (separable solutions) and the following methods are implemented: + - R. Tsai, R. Lenz A New Technique for Fully Autonomous and Efficient 3D Robotics Hand/EyeCalibration \cite Tsai89 + - F. Park, B. Martin Robot Sensor Calibration: Solving AX = XB on the Euclidean Group \cite Park94 + - R. Horaud, F. Dornaika Hand-Eye Calibration \cite Horaud95 + +Another approach consists in estimating simultaneously the rotation and the translation (simultaneous solutions), +with the following implemented method: + - N. Andreff, R. Horaud, B. Espiau On-line Hand-Eye Calibration \cite Andreff99 + - K. Daniilidis Hand-Eye Calibration Using Dual Quaternions \cite Daniilidis98 + +The following picture describes the Hand-Eye calibration problem where the transformation between a camera ("eye") +mounted on a robot gripper ("hand") has to be estimated. + +![](pics/hand-eye_figure.png) + +The calibration procedure is the following: + - a static calibration pattern is used to estimate the transformation between the target frame + and the camera frame + - the robot gripper is moved in order to acquire several poses + - for each pose, the homogeneous transformation between the gripper frame and the robot base frame is recorded using for + instance the robot kinematics +\f[ + \begin{bmatrix} + X_b\\ + Y_b\\ + Z_b\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{b}\textrm{R}_g & _{}^{b}\textrm{t}_g \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_g\\ + Y_g\\ + Z_g\\ + 1 + \end{bmatrix} +\f] + - for each pose, the homogeneous transformation between the calibration target frame and the camera frame is recorded using + for instance a pose estimation method (PnP) from 2D-3D point correspondences +\f[ + \begin{bmatrix} + X_c\\ + Y_c\\ + Z_c\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{c}\textrm{R}_t & _{}^{c}\textrm{t}_t \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_t\\ + Y_t\\ + Z_t\\ + 1 + \end{bmatrix} +\f] + +The Hand-Eye calibration procedure returns the following homogeneous transformation +\f[ + \begin{bmatrix} + X_g\\ + Y_g\\ + Z_g\\ + 1 + \end{bmatrix} + = + \begin{bmatrix} + _{}^{g}\textrm{R}_c & _{}^{g}\textrm{t}_c \\ + 0_{1 \times 3} & 1 + \end{bmatrix} + \begin{bmatrix} + X_c\\ + Y_c\\ + Z_c\\ + 1 + \end{bmatrix} +\f] + +This problem is also known as solving the \f$\mathbf{A}\mathbf{X}=\mathbf{X}\mathbf{B}\f$ equation: +\f[ + \begin{align*} + ^{b}{\textrm{T}_g}^{(1)} \hspace{0.2em} ^{g}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(1)} &= + \hspace{0.1em} ^{b}{\textrm{T}_g}^{(2)} \hspace{0.2em} ^{g}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(2)} \\ + + (^{b}{\textrm{T}_g}^{(2)})^{-1} \hspace{0.2em} ^{b}{\textrm{T}_g}^{(1)} \hspace{0.2em} ^{g}\textrm{T}_c &= + \hspace{0.1em} ^{g}\textrm{T}_c \hspace{0.2em} ^{c}{\textrm{T}_t}^{(2)} (^{c}{\textrm{T}_t}^{(1)})^{-1} \\ + + \textrm{A}_i \textrm{X} &= \textrm{X} \textrm{B}_i \\ + \end{align*} +\f] + +\note +Additional information can be found on this [website](http://campar.in.tum.de/Chair/HandEyeCalibration). +\note +A minimum of 2 motions with non parallel rotation axes are necessary to determine the hand-eye transformation. +So at least 3 different poses are required, but it is strongly recommended to use many more poses. + + */ +CV_EXPORTS_W void calibrateHandEye( InputArrayOfArrays R_gripper2base, InputArrayOfArrays t_gripper2base, + InputArrayOfArrays R_target2cam, InputArrayOfArrays t_target2cam, + OutputArray R_cam2gripper, OutputArray t_cam2gripper, + HandEyeCalibrationMethod method=CALIB_HAND_EYE_TSAI ); + +/** @brief Converts points from Euclidean to homogeneous space. + +@param src Input vector of N-dimensional points. +@param dst Output vector of N+1-dimensional points. + +The function converts points from Euclidean to homogeneous space by appending 1's to the tuple of +point coordinates. That is, each point (x1, x2, ..., xn) is converted to (x1, x2, ..., xn, 1). + */ +CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst ); + +/** @brief Converts points from homogeneous to Euclidean space. + +@param src Input vector of N-dimensional points. +@param dst Output vector of N-1-dimensional points. + +The function converts points homogeneous to Euclidean space using perspective projection. That is, +each point (x1, x2, ... x(n-1), xn) is converted to (x1/xn, x2/xn, ..., x(n-1)/xn). When xn=0, the +output point coordinates will be (0,0,0,...). + */ +CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst ); + +/** @brief Converts points to/from homogeneous coordinates. + +@param src Input array or vector of 2D, 3D, or 4D points. +@param dst Output vector of 2D, 3D, or 4D points. + +The function converts 2D or 3D points from/to homogeneous coordinates by calling either +convertPointsToHomogeneous or convertPointsFromHomogeneous. + +@note The function is obsolete. Use one of the previous two functions instead. + */ +CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst ); + +/** @brief Calculates a fundamental matrix from the corresponding points in two images. + +@param points1 Array of N points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param method Method for computing a fundamental matrix. +- **CV_FM_7POINT** for a 7-point algorithm. \f$N = 7\f$ +- **CV_FM_8POINT** for an 8-point algorithm. \f$N \ge 8\f$ +- **CV_FM_RANSAC** for the RANSAC algorithm. \f$N \ge 8\f$ +- **CV_FM_LMEDS** for the LMedS algorithm. \f$N \ge 8\f$ +@param ransacReprojThreshold Parameter used only for RANSAC. It is the maximum distance from a point to an epipolar +line in pixels, beyond which the point is considered an outlier and is not used for computing the +final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the +point localization, image resolution, and the image noise. +@param confidence Parameter used for the RANSAC and LMedS methods only. It specifies a desirable level +of confidence (probability) that the estimated matrix is correct. +@param mask + +The epipolar geometry is described by the following equation: + +\f[[p_2; 1]^T F [p_1; 1] = 0\f] + +where \f$F\f$ is a fundamental matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the +second images, respectively. + +The function calculates the fundamental matrix using one of four methods listed above and returns +the found fundamental matrix. Normally just one matrix is found. But in case of the 7-point +algorithm, the function may return up to 3 solutions ( \f$9 \times 3\f$ matrix that stores all 3 +matrices sequentially). + +The calculated fundamental matrix may be passed further to computeCorrespondEpilines that finds the +epipolar lines corresponding to the specified points. It can also be passed to +stereoRectifyUncalibrated to compute the rectification transformation. : +@code + // Example. Estimation of fundamental matrix using the RANSAC algorithm + int point_count = 100; + vector points1(point_count); + vector points2(point_count); + + // initialize the points here ... + for( int i = 0; i < point_count; i++ ) + { + points1[i] = ...; + points2[i] = ...; + } + + Mat fundamental_matrix = + findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99); +@endcode + */ +CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2, + int method = FM_RANSAC, + double ransacReprojThreshold = 3., double confidence = 0.99, + OutputArray mask = noArray() ); + +/** @overload */ +CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2, + OutputArray mask, int method = FM_RANSAC, + double ransacReprojThreshold = 3., double confidence = 0.99 ); + +/** @brief Calculates an essential matrix from the corresponding points in two images. + +@param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should +be floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. +@param method Method for computing an essential matrix. +- **RANSAC** for the RANSAC algorithm. +- **LMEDS** for the LMedS algorithm. +@param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of +confidence (probability) that the estimated matrix is correct. +@param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar +line in pixels, beyond which the point is considered an outlier and is not used for computing the +final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the +point localization, image resolution, and the image noise. +@param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 +for the other points. The array is computed only in the RANSAC and LMedS methods. + +This function estimates essential matrix based on the five-point algorithm solver in @cite Nister03 . +@cite SteweniusCFS is also a related. The epipolar geometry is described by the following equation: + +\f[[p_2; 1]^T K^{-T} E K^{-1} [p_1; 1] = 0\f] + +where \f$E\f$ is an essential matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the +second images, respectively. The result of this function may be passed further to +decomposeEssentialMat or recoverPose to recover the relative pose between cameras. + */ +CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, + InputArray cameraMatrix, int method = RANSAC, + double prob = 0.999, double threshold = 1.0, + OutputArray mask = noArray() ); + +/** @overload +@param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should +be floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param focal focal length of the camera. Note that this function assumes that points1 and points2 +are feature points from cameras with same focal length and principal point. +@param pp principal point of the camera. +@param method Method for computing a fundamental matrix. +- **RANSAC** for the RANSAC algorithm. +- **LMEDS** for the LMedS algorithm. +@param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar +line in pixels, beyond which the point is considered an outlier and is not used for computing the +final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the +point localization, image resolution, and the image noise. +@param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of +confidence (probability) that the estimated matrix is correct. +@param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 +for the other points. The array is computed only in the RANSAC and LMedS methods. + +This function differs from the one above that it computes camera matrix from focal length and +principal point: + +\f[K = +\begin{bmatrix} +f & 0 & x_{pp} \\ +0 & f & y_{pp} \\ +0 & 0 & 1 +\end{bmatrix}\f] + */ +CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, + double focal = 1.0, Point2d pp = Point2d(0, 0), + int method = RANSAC, double prob = 0.999, + double threshold = 1.0, OutputArray mask = noArray() ); + +/** @brief Decompose an essential matrix to possible rotations and translation. + +@param E The input essential matrix. +@param R1 One possible rotation matrix. +@param R2 Another possible rotation matrix. +@param t One possible translation. + +This function decompose an essential matrix E using svd decomposition @cite HartleyZ00 . Generally 4 +possible poses exists for a given E. They are \f$[R_1, t]\f$, \f$[R_1, -t]\f$, \f$[R_2, t]\f$, \f$[R_2, -t]\f$. By +decomposing E, you can only get the direction of the translation, so the function returns unit t. + */ +CV_EXPORTS_W void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t ); + +/** @brief Recover relative camera rotation and translation from an estimated essential matrix and the +corresponding points in two images, using cheirality check. Returns the number of inliers which pass +the check. + +@param E The input essential matrix. +@param points1 Array of N 2D points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. +@param R Recovered relative rotation. +@param t Recovered relative translation. +@param mask Input/output mask for inliers in points1 and points2. +: If it is not empty, then it marks inliers in points1 and points2 for then given essential +matrix E. Only these inliers will be used to recover pose. In the output mask only inliers +which pass the cheirality check. +This function decomposes an essential matrix using decomposeEssentialMat and then verifies possible +pose hypotheses by doing cheirality check. The cheirality check basically means that the +triangulated 3D points should have positive depth. Some details can be found in @cite Nister03 . + +This function can be used to process output E and mask from findEssentialMat. In this scenario, +points1 and points2 are the same input for findEssentialMat. : +@code + // Example. Estimation of fundamental matrix using the RANSAC algorithm + int point_count = 100; + vector points1(point_count); + vector points2(point_count); + + // initialize the points here ... + for( int i = 0; i < point_count; i++ ) + { + points1[i] = ...; + points2[i] = ...; + } + + // cametra matrix with both focal lengths = 1, and principal point = (0, 0) + Mat cameraMatrix = Mat::eye(3, 3, CV_64F); + + Mat E, R, t, mask; + + E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask); + recoverPose(E, points1, points2, cameraMatrix, R, t, mask); +@endcode + */ +CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, + InputArray cameraMatrix, OutputArray R, OutputArray t, + InputOutputArray mask = noArray() ); + +/** @overload +@param E The input essential matrix. +@param points1 Array of N 2D points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1 . +@param R Recovered relative rotation. +@param t Recovered relative translation. +@param focal Focal length of the camera. Note that this function assumes that points1 and points2 +are feature points from cameras with same focal length and principal point. +@param pp principal point of the camera. +@param mask Input/output mask for inliers in points1 and points2. +: If it is not empty, then it marks inliers in points1 and points2 for then given essential +matrix E. Only these inliers will be used to recover pose. In the output mask only inliers +which pass the cheirality check. + +This function differs from the one above that it computes camera matrix from focal length and +principal point: + +\f[K = +\begin{bmatrix} +f & 0 & x_{pp} \\ +0 & f & y_{pp} \\ +0 & 0 & 1 +\end{bmatrix}\f] + */ +CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, + OutputArray R, OutputArray t, + double focal = 1.0, Point2d pp = Point2d(0, 0), + InputOutputArray mask = noArray() ); + +/** @overload +@param E The input essential matrix. +@param points1 Array of N 2D points from the first image. The point coordinates should be +floating-point (single or double precision). +@param points2 Array of the second image points of the same size and format as points1. +@param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +Note that this function assumes that points1 and points2 are feature points from cameras with the +same camera matrix. +@param R Recovered relative rotation. +@param t Recovered relative translation. +@param distanceThresh threshold distance which is used to filter out far away points (i.e. infinite points). +@param mask Input/output mask for inliers in points1 and points2. +: If it is not empty, then it marks inliers in points1 and points2 for then given essential +matrix E. Only these inliers will be used to recover pose. In the output mask only inliers +which pass the cheirality check. +@param triangulatedPoints 3d points which were reconstructed by triangulation. + */ + +CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, + InputArray cameraMatrix, OutputArray R, OutputArray t, double distanceThresh, InputOutputArray mask = noArray(), + OutputArray triangulatedPoints = noArray()); + +/** @brief For points in an image of a stereo pair, computes the corresponding epilines in the other image. + +@param points Input points. \f$N \times 1\f$ or \f$1 \times N\f$ matrix of type CV_32FC2 or +vector\ . +@param whichImage Index of the image (1 or 2) that contains the points . +@param F Fundamental matrix that can be estimated using findFundamentalMat or stereoRectify . +@param lines Output vector of the epipolar lines corresponding to the points in the other image. +Each line \f$ax + by + c=0\f$ is encoded by 3 numbers \f$(a, b, c)\f$ . + +For every point in one of the two images of a stereo pair, the function finds the equation of the +corresponding epipolar line in the other image. + +From the fundamental matrix definition (see findFundamentalMat ), line \f$l^{(2)}_i\f$ in the second +image for the point \f$p^{(1)}_i\f$ in the first image (when whichImage=1 ) is computed as: + +\f[l^{(2)}_i = F p^{(1)}_i\f] + +And vice versa, when whichImage=2, \f$l^{(1)}_i\f$ is computed from \f$p^{(2)}_i\f$ as: + +\f[l^{(1)}_i = F^T p^{(2)}_i\f] + +Line coefficients are defined up to a scale. They are normalized so that \f$a_i^2+b_i^2=1\f$ . + */ +CV_EXPORTS_W void computeCorrespondEpilines( InputArray points, int whichImage, + InputArray F, OutputArray lines ); + +/** @brief Reconstructs points by triangulation. + +@param projMatr1 3x4 projection matrix of the first camera. +@param projMatr2 3x4 projection matrix of the second camera. +@param projPoints1 2xN array of feature points in the first image. In case of c++ version it can +be also a vector of feature points or two-channel matrix of size 1xN or Nx1. +@param projPoints2 2xN array of corresponding points in the second image. In case of c++ version +it can be also a vector of feature points or two-channel matrix of size 1xN or Nx1. +@param points4D 4xN array of reconstructed points in homogeneous coordinates. + +The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their +observations with a stereo camera. Projections matrices can be obtained from stereoRectify. + +@note + Keep in mind that all input data should be of float type in order for this function to work. + +@sa + reprojectImageTo3D + */ +CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2, + InputArray projPoints1, InputArray projPoints2, + OutputArray points4D ); + +/** @brief Refines coordinates of corresponding points. + +@param F 3x3 fundamental matrix. +@param points1 1xN array containing the first set of points. +@param points2 1xN array containing the second set of points. +@param newPoints1 The optimized points1. +@param newPoints2 The optimized points2. + +The function implements the Optimal Triangulation Method (see Multiple View Geometry for details). +For each given point correspondence points1[i] \<-\> points2[i], and a fundamental matrix F, it +computes the corrected correspondences newPoints1[i] \<-\> newPoints2[i] that minimize the geometric +error \f$d(points1[i], newPoints1[i])^2 + d(points2[i],newPoints2[i])^2\f$ (where \f$d(a,b)\f$ is the +geometric distance between points \f$a\f$ and \f$b\f$ ) subject to the epipolar constraint +\f$newPoints2^T * F * newPoints1 = 0\f$ . + */ +CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2, + OutputArray newPoints1, OutputArray newPoints2 ); + +/** @brief Filters off small noise blobs (speckles) in the disparity map + +@param img The input 16-bit signed disparity image +@param newVal The disparity value used to paint-off the speckles +@param maxSpeckleSize The maximum speckle size to consider it a speckle. Larger blobs are not +affected by the algorithm +@param maxDiff Maximum difference between neighbor disparity pixels to put them into the same +blob. Note that since StereoBM, StereoSGBM and may be other algorithms return a fixed-point +disparity map, where disparity values are multiplied by 16, this scale factor should be taken into +account when specifying this parameter value. +@param buf The optional temporary buffer to avoid memory allocation within the function. + */ +CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, + int maxSpeckleSize, double maxDiff, + InputOutputArray buf = noArray() ); + +//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) +CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2, + int minDisparity, int numberOfDisparities, + int SADWindowSize ); + +//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm +CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost, + int minDisparity, int numberOfDisparities, + int disp12MaxDisp = 1 ); + +/** @brief Reprojects a disparity image to 3D space. + +@param disparity Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit +floating-point disparity image. +The values of 8-bit / 16-bit signed formats are assumed to have no fractional bits. +If the disparity is 16-bit signed format as computed by +StereoBM/StereoSGBM/StereoBinaryBM/StereoBinarySGBM and may be other algorithms, +it should be divided by 16 (and scaled to float) before being used here. +@param _3dImage Output 3-channel floating-point image of the same size as disparity . Each +element of _3dImage(x,y) contains 3D coordinates of the point (x,y) computed from the disparity +map. +@param Q \f$4 \times 4\f$ perspective transformation matrix that can be obtained with stereoRectify. +@param handleMissingValues Indicates, whether the function should handle missing values (i.e. +points where the disparity was not computed). If handleMissingValues=true, then pixels with the +minimal disparity that corresponds to the outliers (see StereoMatcher::compute ) are transformed +to 3D points with a very large Z value (currently set to 10000). +@param ddepth The optional output array depth. If it is -1, the output image will have CV_32F +depth. ddepth can also be set to CV_16S, CV_32S or CV_32F. + +The function transforms a single-channel disparity map to a 3-channel image representing a 3D +surface. That is, for each pixel (x,y) and the corresponding disparity d=disparity(x,y) , it +computes: + +\f[\begin{array}{l} [X \; Y \; Z \; W]^T = \texttt{Q} *[x \; y \; \texttt{disparity} (x,y) \; 1]^T \\ \texttt{\_3dImage} (x,y) = (X/W, \; Y/W, \; Z/W) \end{array}\f] + +The matrix Q can be an arbitrary \f$4 \times 4\f$ matrix (for example, the one computed by +stereoRectify). To reproject a sparse set of points {(x,y,d),...} to 3D space, use +perspectiveTransform . + */ +CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity, + OutputArray _3dImage, InputArray Q, + bool handleMissingValues = false, + int ddepth = -1 ); + +/** @brief Calculates the Sampson Distance between two points. + +The function cv::sampsonDistance calculates and returns the first order approximation of the geometric error as: +\f[ +sd( \texttt{pt1} , \texttt{pt2} )= +\frac{(\texttt{pt2}^t \cdot \texttt{F} \cdot \texttt{pt1})^2} +{((\texttt{F} \cdot \texttt{pt1})(0))^2 + +((\texttt{F} \cdot \texttt{pt1})(1))^2 + +((\texttt{F}^t \cdot \texttt{pt2})(0))^2 + +((\texttt{F}^t \cdot \texttt{pt2})(1))^2} +\f] +The fundamental matrix may be calculated using the cv::findFundamentalMat function. See @cite HartleyZ00 11.4.3 for details. +@param pt1 first homogeneous 2d point +@param pt2 second homogeneous 2d point +@param F fundamental matrix +@return The computed Sampson distance. +*/ +CV_EXPORTS_W double sampsonDistance(InputArray pt1, InputArray pt2, InputArray F); + +/** @brief Computes an optimal affine transformation between two 3D point sets. + +It computes +\f[ +\begin{bmatrix} +x\\ +y\\ +z\\ +\end{bmatrix} += +\begin{bmatrix} +a_{11} & a_{12} & a_{13}\\ +a_{21} & a_{22} & a_{23}\\ +a_{31} & a_{32} & a_{33}\\ +\end{bmatrix} +\begin{bmatrix} +X\\ +Y\\ +Z\\ +\end{bmatrix} ++ +\begin{bmatrix} +b_1\\ +b_2\\ +b_3\\ +\end{bmatrix} +\f] + +@param src First input 3D point set containing \f$(X,Y,Z)\f$. +@param dst Second input 3D point set containing \f$(x,y,z)\f$. +@param out Output 3D affine transformation matrix \f$3 \times 4\f$ of the form +\f[ +\begin{bmatrix} +a_{11} & a_{12} & a_{13} & b_1\\ +a_{21} & a_{22} & a_{23} & b_2\\ +a_{31} & a_{32} & a_{33} & b_3\\ +\end{bmatrix} +\f] +@param inliers Output vector indicating which points are inliers (1-inlier, 0-outlier). +@param ransacThreshold Maximum reprojection error in the RANSAC algorithm to consider a point as +an inlier. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. + +The function estimates an optimal 3D affine transformation between two 3D point sets using the +RANSAC algorithm. + */ +CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst, + OutputArray out, OutputArray inliers, + double ransacThreshold = 3, double confidence = 0.99); + +/** @brief Computes an optimal affine transformation between two 2D point sets. + +It computes +\f[ +\begin{bmatrix} +x\\ +y\\ +\end{bmatrix} += +\begin{bmatrix} +a_{11} & a_{12}\\ +a_{21} & a_{22}\\ +\end{bmatrix} +\begin{bmatrix} +X\\ +Y\\ +\end{bmatrix} ++ +\begin{bmatrix} +b_1\\ +b_2\\ +\end{bmatrix} +\f] + +@param from First input 2D point set containing \f$(X,Y)\f$. +@param to Second input 2D point set containing \f$(x,y)\f$. +@param inliers Output vector indicating which points are inliers (1-inlier, 0-outlier). +@param method Robust method used to compute transformation. The following methods are possible: +- cv::RANSAC - RANSAC-based robust method +- cv::LMEDS - Least-Median robust method +RANSAC is the default method. +@param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider +a point as an inlier. Applies only to RANSAC. +@param maxIters The maximum number of robust method iterations. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. +@param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). +Passing 0 will disable refining, so the output matrix will be output of robust method. + +@return Output 2D affine transformation matrix \f$2 \times 3\f$ or empty matrix if transformation +could not be estimated. The returned matrix has the following form: +\f[ +\begin{bmatrix} +a_{11} & a_{12} & b_1\\ +a_{21} & a_{22} & b_2\\ +\end{bmatrix} +\f] + +The function estimates an optimal 2D affine transformation between two 2D point sets using the +selected robust algorithm. + +The computed transformation is then refined further (using only inliers) with the +Levenberg-Marquardt method to reduce the re-projection error even more. + +@note +The RANSAC method can handle practically any ratio of outliers but needs a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. + +@sa estimateAffinePartial2D, getAffineTransform +*/ +CV_EXPORTS_W cv::Mat estimateAffine2D(InputArray from, InputArray to, OutputArray inliers = noArray(), + int method = RANSAC, double ransacReprojThreshold = 3, + size_t maxIters = 2000, double confidence = 0.99, + size_t refineIters = 10); + +/** @brief Computes an optimal limited affine transformation with 4 degrees of freedom between +two 2D point sets. + +@param from First input 2D point set. +@param to Second input 2D point set. +@param inliers Output vector indicating which points are inliers. +@param method Robust method used to compute transformation. The following methods are possible: +- cv::RANSAC - RANSAC-based robust method +- cv::LMEDS - Least-Median robust method +RANSAC is the default method. +@param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider +a point as an inlier. Applies only to RANSAC. +@param maxIters The maximum number of robust method iterations. +@param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything +between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation +significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. +@param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). +Passing 0 will disable refining, so the output matrix will be output of robust method. + +@return Output 2D affine transformation (4 degrees of freedom) matrix \f$2 \times 3\f$ or +empty matrix if transformation could not be estimated. + +The function estimates an optimal 2D affine transformation with 4 degrees of freedom limited to +combinations of translation, rotation, and uniform scaling. Uses the selected algorithm for robust +estimation. + +The computed transformation is then refined further (using only inliers) with the +Levenberg-Marquardt method to reduce the re-projection error even more. + +Estimated transformation matrix is: +\f[ \begin{bmatrix} \cos(\theta) \cdot s & -\sin(\theta) \cdot s & t_x \\ + \sin(\theta) \cdot s & \cos(\theta) \cdot s & t_y +\end{bmatrix} \f] +Where \f$ \theta \f$ is the rotation angle, \f$ s \f$ the scaling factor and \f$ t_x, t_y \f$ are +translations in \f$ x, y \f$ axes respectively. + +@note +The RANSAC method can handle practically any ratio of outliers but need a threshold to +distinguish inliers from outliers. The method LMeDS does not need any threshold but it works +correctly only when there are more than 50% of inliers. + +@sa estimateAffine2D, getAffineTransform +*/ +CV_EXPORTS_W cv::Mat estimateAffinePartial2D(InputArray from, InputArray to, OutputArray inliers = noArray(), + int method = RANSAC, double ransacReprojThreshold = 3, + size_t maxIters = 2000, double confidence = 0.99, + size_t refineIters = 10); + +/** @example samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp +An example program with homography decomposition. + +Check @ref tutorial_homography "the corresponding tutorial" for more details. +*/ + +/** @brief Decompose a homography matrix to rotation(s), translation(s) and plane normal(s). + +@param H The input homography matrix between two images. +@param K The input intrinsic camera calibration matrix. +@param rotations Array of rotation matrices. +@param translations Array of translation matrices. +@param normals Array of plane normal matrices. + +This function extracts relative camera motion between two views observing a planar object from the +homography H induced by the plane. The intrinsic camera matrix K must also be provided. The function +may return up to four mathematical solution sets. At least two of the solutions may further be +invalidated if point correspondences are available by applying positive depth constraint (all points +must be in front of the camera). The decomposition method is described in detail in @cite Malis . + */ +CV_EXPORTS_W int decomposeHomographyMat(InputArray H, + InputArray K, + OutputArrayOfArrays rotations, + OutputArrayOfArrays translations, + OutputArrayOfArrays normals); + +/** @brief Filters homography decompositions based on additional information. + +@param rotations Vector of rotation matrices. +@param normals Vector of plane normal matrices. +@param beforePoints Vector of (rectified) visible reference points before the homography is applied +@param afterPoints Vector of (rectified) visible reference points after the homography is applied +@param possibleSolutions Vector of int indices representing the viable solution set after filtering +@param pointsMask optional Mat/Vector of 8u type representing the mask for the inliers as given by the findHomography function + +This function is intended to filter the output of the decomposeHomographyMat based on additional +information as described in @cite Malis . The summary of the method: the decomposeHomographyMat function +returns 2 unique solutions and their "opposites" for a total of 4 solutions. If we have access to the +sets of points visible in the camera frame before and after the homography transformation is applied, +we can determine which are the true potential solutions and which are the opposites by verifying which +homographies are consistent with all visible reference points being in front of the camera. The inputs +are left unchanged; the filtered solution set is returned as indices into the existing one. + +*/ +CV_EXPORTS_W void filterHomographyDecompByVisibleRefpoints(InputArrayOfArrays rotations, + InputArrayOfArrays normals, + InputArray beforePoints, + InputArray afterPoints, + OutputArray possibleSolutions, + InputArray pointsMask = noArray()); + +/** @brief The base class for stereo correspondence algorithms. + */ +class CV_EXPORTS_W StereoMatcher : public Algorithm +{ +public: + enum { DISP_SHIFT = 4, + DISP_SCALE = (1 << DISP_SHIFT) + }; + + /** @brief Computes disparity map for the specified stereo pair + + @param left Left 8-bit single-channel image. + @param right Right image of the same size and the same type as the left one. + @param disparity Output disparity map. It has the same size as the input images. Some algorithms, + like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value + has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map. + */ + CV_WRAP virtual void compute( InputArray left, InputArray right, + OutputArray disparity ) = 0; + + CV_WRAP virtual int getMinDisparity() const = 0; + CV_WRAP virtual void setMinDisparity(int minDisparity) = 0; + + CV_WRAP virtual int getNumDisparities() const = 0; + CV_WRAP virtual void setNumDisparities(int numDisparities) = 0; + + CV_WRAP virtual int getBlockSize() const = 0; + CV_WRAP virtual void setBlockSize(int blockSize) = 0; + + CV_WRAP virtual int getSpeckleWindowSize() const = 0; + CV_WRAP virtual void setSpeckleWindowSize(int speckleWindowSize) = 0; + + CV_WRAP virtual int getSpeckleRange() const = 0; + CV_WRAP virtual void setSpeckleRange(int speckleRange) = 0; + + CV_WRAP virtual int getDisp12MaxDiff() const = 0; + CV_WRAP virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0; +}; + + +/** @brief Class for computing stereo correspondence using the block matching algorithm, introduced and +contributed to OpenCV by K. Konolige. + */ +class CV_EXPORTS_W StereoBM : public StereoMatcher +{ +public: + enum { PREFILTER_NORMALIZED_RESPONSE = 0, + PREFILTER_XSOBEL = 1 + }; + + CV_WRAP virtual int getPreFilterType() const = 0; + CV_WRAP virtual void setPreFilterType(int preFilterType) = 0; + + CV_WRAP virtual int getPreFilterSize() const = 0; + CV_WRAP virtual void setPreFilterSize(int preFilterSize) = 0; + + CV_WRAP virtual int getPreFilterCap() const = 0; + CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; + + CV_WRAP virtual int getTextureThreshold() const = 0; + CV_WRAP virtual void setTextureThreshold(int textureThreshold) = 0; + + CV_WRAP virtual int getUniquenessRatio() const = 0; + CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; + + CV_WRAP virtual int getSmallerBlockSize() const = 0; + CV_WRAP virtual void setSmallerBlockSize(int blockSize) = 0; + + CV_WRAP virtual Rect getROI1() const = 0; + CV_WRAP virtual void setROI1(Rect roi1) = 0; + + CV_WRAP virtual Rect getROI2() const = 0; + CV_WRAP virtual void setROI2(Rect roi2) = 0; + + /** @brief Creates StereoBM object + + @param numDisparities the disparity search range. For each pixel algorithm will find the best + disparity from 0 (default minimum disparity) to numDisparities. The search range can then be + shifted by changing the minimum disparity. + @param blockSize the linear size of the blocks compared by the algorithm. The size should be odd + (as the block is centered at the current pixel). Larger block size implies smoother, though less + accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher + chance for algorithm to find a wrong correspondence. + + The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for + a specific stereo pair. + */ + CV_WRAP static Ptr create(int numDisparities = 0, int blockSize = 21); +}; + +/** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08 that differs from the original +one as follows: + +- By default, the algorithm is single-pass, which means that you consider only 5 directions +instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the +algorithm but beware that it may consume a lot of memory. +- The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the +blocks to single pixels. +- Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi +sub-pixel metric from @cite BT98 is used. Though, the color images are supported as well. +- Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for +example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness +check, quadratic interpolation and speckle filtering). + +@note + - (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found + at opencv_source_code/samples/python/stereo_match.py + */ +class CV_EXPORTS_W StereoSGBM : public StereoMatcher +{ +public: + enum + { + MODE_SGBM = 0, + MODE_HH = 1, + MODE_SGBM_3WAY = 2, + MODE_HH4 = 3 + }; + + CV_WRAP virtual int getPreFilterCap() const = 0; + CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; + + CV_WRAP virtual int getUniquenessRatio() const = 0; + CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; + + CV_WRAP virtual int getP1() const = 0; + CV_WRAP virtual void setP1(int P1) = 0; + + CV_WRAP virtual int getP2() const = 0; + CV_WRAP virtual void setP2(int P2) = 0; + + CV_WRAP virtual int getMode() const = 0; + CV_WRAP virtual void setMode(int mode) = 0; + + /** @brief Creates StereoSGBM object + + @param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes + rectification algorithms can shift images, so this parameter needs to be adjusted accordingly. + @param numDisparities Maximum disparity minus minimum disparity. The value is always greater than + zero. In the current implementation, this parameter must be divisible by 16. + @param blockSize Matched block size. It must be an odd number \>=1 . Normally, it should be + somewhere in the 3..11 range. + @param P1 The first parameter controlling the disparity smoothness. See below. + @param P2 The second parameter controlling the disparity smoothness. The larger the values are, + the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1 + between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor + pixels. The algorithm requires P2 \> P1 . See stereo_match.cpp sample where some reasonably good + P1 and P2 values are shown (like 8\*number_of_image_channels\*SADWindowSize\*SADWindowSize and + 32\*number_of_image_channels\*SADWindowSize\*SADWindowSize , respectively). + @param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right + disparity check. Set it to a non-positive value to disable the check. + @param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first + computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval. + The result values are passed to the Birchfield-Tomasi pixel cost function. + @param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function + value should "win" the second best value to consider the found match correct. Normally, a value + within the 5-15 range is good enough. + @param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles + and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the + 50-200 range. + @param speckleRange Maximum disparity variation within each connected component. If you do speckle + filtering, set the parameter to a positive value, it will be implicitly multiplied by 16. + Normally, 1 or 2 is good enough. + @param mode Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming + algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and + huge for HD-size pictures. By default, it is set to false . + + The first constructor initializes StereoSGBM with all the default parameters. So, you only have to + set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter + to a custom value. + */ + CV_WRAP static Ptr create(int minDisparity = 0, int numDisparities = 16, int blockSize = 3, + int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, + int preFilterCap = 0, int uniquenessRatio = 0, + int speckleWindowSize = 0, int speckleRange = 0, + int mode = StereoSGBM::MODE_SGBM); +}; + + +//! cv::undistort mode +enum UndistortTypes +{ + PROJ_SPHERICAL_ORTHO = 0, + PROJ_SPHERICAL_EQRECT = 1 +}; + +/** @brief Transforms an image to compensate for lens distortion. + +The function transforms an image to compensate radial and tangential lens distortion. + +The function is simply a combination of #initUndistortRectifyMap (with unity R ) and #remap +(with bilinear interpolation). See the former function for details of the transformation being +performed. + +Those pixels in the destination image, for which there is no correspondent pixels in the source +image, are filled with zeros (black color). + +A particular subset of the source image that will be visible in the corrected image can be regulated +by newCameraMatrix. You can use #getOptimalNewCameraMatrix to compute the appropriate +newCameraMatrix depending on your requirements. + +The camera matrix and the distortion parameters can be determined using #calibrateCamera. If +the resolution of images is different from the resolution used at the calibration stage, \f$f_x, +f_y, c_x\f$ and \f$c_y\f$ need to be scaled accordingly, while the distortion coefficients remain +the same. + +@param src Input (distorted) image. +@param dst Output (corrected) image that has the same size and type as src . +@param cameraMatrix Input camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param newCameraMatrix Camera matrix of the distorted image. By default, it is the same as +cameraMatrix but you may additionally scale and shift the result by using a different matrix. + */ +CV_EXPORTS_W void undistort( InputArray src, OutputArray dst, + InputArray cameraMatrix, + InputArray distCoeffs, + InputArray newCameraMatrix = noArray() ); + +/** @brief Computes the undistortion and rectification transformation map. + +The function computes the joint undistortion and rectification transformation and represents the +result in the form of maps for remap. The undistorted image looks like original, as if it is +captured with a camera using the camera matrix =newCameraMatrix and zero distortion. In case of a +monocular camera, newCameraMatrix is usually equal to cameraMatrix, or it can be computed by +#getOptimalNewCameraMatrix for a better control over scaling. In case of a stereo camera, +newCameraMatrix is normally set to P1 or P2 computed by #stereoRectify . + +Also, this new camera is oriented differently in the coordinate space, according to R. That, for +example, helps to align two heads of a stereo camera so that the epipolar lines on both images +become horizontal and have the same y- coordinate (in case of a horizontally aligned stereo camera). + +The function actually builds the maps for the inverse mapping algorithm that is used by remap. That +is, for each pixel \f$(u, v)\f$ in the destination (corrected and rectified) image, the function +computes the corresponding coordinates in the source image (that is, in the original image from +camera). The following process is applied: +\f[ +\begin{array}{l} +x \leftarrow (u - {c'}_x)/{f'}_x \\ +y \leftarrow (v - {c'}_y)/{f'}_y \\ +{[X\,Y\,W]} ^T \leftarrow R^{-1}*[x \, y \, 1]^T \\ +x' \leftarrow X/W \\ +y' \leftarrow Y/W \\ +r^2 \leftarrow x'^2 + y'^2 \\ +x'' \leftarrow x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} ++ 2p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4\\ +y'' \leftarrow y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} ++ p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ +s\vecthree{x'''}{y'''}{1} = +\vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}((\tau_x, \tau_y)} +{0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} +{0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ +map_x(u,v) \leftarrow x''' f_x + c_x \\ +map_y(u,v) \leftarrow y''' f_y + c_y +\end{array} +\f] +where \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +are the distortion coefficients. + +In case of a stereo camera, this function is called twice: once for each camera head, after +stereoRectify, which in its turn is called after #stereoCalibrate. But if the stereo camera +was not calibrated, it is still possible to compute the rectification transformations directly from +the fundamental matrix using #stereoRectifyUncalibrated. For each camera, the function computes +homography H as the rectification transformation in a pixel domain, not a rotation matrix R in 3D +space. R can be computed from H as +\f[\texttt{R} = \texttt{cameraMatrix} ^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix}\f] +where cameraMatrix can be chosen arbitrarily. + +@param cameraMatrix Input camera matrix \f$A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param R Optional rectification transformation in the object space (3x3 matrix). R1 or R2 , +computed by #stereoRectify can be passed here. If the matrix is empty, the identity transformation +is assumed. In cvInitUndistortMap R assumed to be an identity matrix. +@param newCameraMatrix New camera matrix \f$A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}\f$. +@param size Undistorted image size. +@param m1type Type of the first output map that can be CV_32FC1, CV_32FC2 or CV_16SC2, see #convertMaps +@param map1 The first output map. +@param map2 The second output map. + */ +CV_EXPORTS_W +void initUndistortRectifyMap(InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray newCameraMatrix, + Size size, int m1type, OutputArray map1, OutputArray map2); + +//! initializes maps for #remap for wide-angle +CV_EXPORTS +float initWideAngleProjMap(InputArray cameraMatrix, InputArray distCoeffs, + Size imageSize, int destImageWidth, + int m1type, OutputArray map1, OutputArray map2, + enum UndistortTypes projType = PROJ_SPHERICAL_EQRECT, double alpha = 0); +static inline +float initWideAngleProjMap(InputArray cameraMatrix, InputArray distCoeffs, + Size imageSize, int destImageWidth, + int m1type, OutputArray map1, OutputArray map2, + int projType, double alpha = 0) +{ + return initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize, destImageWidth, + m1type, map1, map2, (UndistortTypes)projType, alpha); +} + +/** @brief Returns the default new camera matrix. + +The function returns the camera matrix that is either an exact copy of the input cameraMatrix (when +centerPrinicipalPoint=false ), or the modified one (when centerPrincipalPoint=true). + +In the latter case, the new camera matrix will be: + +\f[\begin{bmatrix} f_x && 0 && ( \texttt{imgSize.width} -1)*0.5 \\ 0 && f_y && ( \texttt{imgSize.height} -1)*0.5 \\ 0 && 0 && 1 \end{bmatrix} ,\f] + +where \f$f_x\f$ and \f$f_y\f$ are \f$(0,0)\f$ and \f$(1,1)\f$ elements of cameraMatrix, respectively. + +By default, the undistortion functions in OpenCV (see #initUndistortRectifyMap, #undistort) do not +move the principal point. However, when you work with stereo, it is important to move the principal +points in both views to the same y-coordinate (which is required by most of stereo correspondence +algorithms), and may be to the same x-coordinate too. So, you can form the new camera matrix for +each view where the principal points are located at the center. + +@param cameraMatrix Input camera matrix. +@param imgsize Camera view image size in pixels. +@param centerPrincipalPoint Location of the principal point in the new camera matrix. The +parameter indicates whether this location should be at the image center or not. + */ +CV_EXPORTS_W +Mat getDefaultNewCameraMatrix(InputArray cameraMatrix, Size imgsize = Size(), + bool centerPrincipalPoint = false); + +/** @brief Computes the ideal point coordinates from the observed point coordinates. + +The function is similar to #undistort and #initUndistortRectifyMap but it operates on a +sparse set of points instead of a raster image. Also the function performs a reverse transformation +to projectPoints. In case of a 3D object, it does not reconstruct its 3D coordinates, but for a +planar object, it does, up to a translation vector, if the proper R is specified. + +For each observed point coordinate \f$(u, v)\f$ the function computes: +\f[ +\begin{array}{l} +x^{"} \leftarrow (u - c_x)/f_x \\ +y^{"} \leftarrow (v - c_y)/f_y \\ +(x',y') = undistort(x^{"},y^{"}, \texttt{distCoeffs}) \\ +{[X\,Y\,W]} ^T \leftarrow R*[x' \, y' \, 1]^T \\ +x \leftarrow X/W \\ +y \leftarrow Y/W \\ +\text{only performed if P is specified:} \\ +u' \leftarrow x {f'}_x + {c'}_x \\ +v' \leftarrow y {f'}_y + {c'}_y +\end{array} +\f] + +where *undistort* is an approximate iterative algorithm that estimates the normalized original +point coordinates out of the normalized distorted point coordinates ("normalized" means that the +coordinates do not depend on the camera matrix). + +The function can be used for both a stereo camera head or a monocular camera (when R is empty). +@param src Observed point coordinates, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel (CV_32FC2 or CV_64FC2) (or +vector\ ). +@param dst Output ideal point coordinates (1xN/Nx1 2-channel or vector\ ) after undistortion and reverse perspective +transformation. If matrix P is identity or omitted, dst will contain normalized point coordinates. +@param cameraMatrix Camera matrix \f$\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . +@param distCoeffs Input vector of distortion coefficients +\f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6[, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ +of 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed. +@param R Rectification transformation in the object space (3x3 matrix). R1 or R2 computed by +#stereoRectify can be passed here. If the matrix is empty, the identity transformation is used. +@param P New camera matrix (3x3) or new projection matrix (3x4) \f$\begin{bmatrix} {f'}_x & 0 & {c'}_x & t_x \\ 0 & {f'}_y & {c'}_y & t_y \\ 0 & 0 & 1 & t_z \end{bmatrix}\f$. P1 or P2 computed by +#stereoRectify can be passed here. If the matrix is empty, the identity new camera matrix is used. + */ +CV_EXPORTS_W +void undistortPoints(InputArray src, OutputArray dst, + InputArray cameraMatrix, InputArray distCoeffs, + InputArray R = noArray(), InputArray P = noArray()); +/** @overload + @note Default version of #undistortPoints does 5 iterations to compute undistorted points. + */ +CV_EXPORTS_AS(undistortPointsIter) +void undistortPoints(InputArray src, OutputArray dst, + InputArray cameraMatrix, InputArray distCoeffs, + InputArray R, InputArray P, TermCriteria criteria); + +//! @} calib3d + +/** @brief The methods in this namespace use a so-called fisheye camera model. + @ingroup calib3d_fisheye +*/ +namespace fisheye +{ +//! @addtogroup calib3d_fisheye +//! @{ + + enum{ + CALIB_USE_INTRINSIC_GUESS = 1 << 0, + CALIB_RECOMPUTE_EXTRINSIC = 1 << 1, + CALIB_CHECK_COND = 1 << 2, + CALIB_FIX_SKEW = 1 << 3, + CALIB_FIX_K1 = 1 << 4, + CALIB_FIX_K2 = 1 << 5, + CALIB_FIX_K3 = 1 << 6, + CALIB_FIX_K4 = 1 << 7, + CALIB_FIX_INTRINSIC = 1 << 8, + CALIB_FIX_PRINCIPAL_POINT = 1 << 9 + }; + + /** @brief Projects points using fisheye model + + @param objectPoints Array of object points, 1xN/Nx1 3-channel (or vector\ ), where N is + the number of points in the view. + @param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or + vector\. + @param affine + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param alpha The skew coefficient. + @param jacobian Optional output 2Nx15 jacobian matrix of derivatives of image points with respect + to components of the focal lengths, coordinates of the principal point, distortion coefficients, + rotation vector, translation vector, and the skew. In the old interface different components of + the jacobian are returned via different output parameters. + + The function computes projections of 3D points to the image plane given intrinsic and extrinsic + camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of + image points coordinates (as functions of all the input parameters) with respect to the particular + parameters, intrinsic and/or extrinsic. + */ + CV_EXPORTS void projectPoints(InputArray objectPoints, OutputArray imagePoints, const Affine3d& affine, + InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray()); + + /** @overload */ + CV_EXPORTS_W void projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec, + InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray()); + + /** @brief Distorts 2D points using fisheye model. + + @param undistorted Array of object points, 1xN/Nx1 2-channel (or vector\ ), where N is + the number of points in the view. + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param alpha The skew coefficient. + @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector\ . + + Note that the function assumes the camera matrix of the undistorted points to be identity. + This means if you want to transform back points undistorted with undistortPoints() you have to + multiply them with \f$P^{-1}\f$. + */ + CV_EXPORTS_W void distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0); + + /** @brief Undistorts 2D points using fisheye model + + @param distorted Array of object points, 1xN/Nx1 2-channel (or vector\ ), where N is the + number of points in the view. + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param undistorted Output array of image points, 1xN/Nx1 2-channel, or vector\ . + */ + CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted, + InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray()); + + /** @brief Computes undistortion and rectification maps for image transform by cv::remap(). If D is empty zero + distortion is used, if R or P is empty identity matrixes are used. + + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param size Undistorted image size. + @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps() + for details. + @param map1 The first output map. + @param map2 The second output map. + */ + CV_EXPORTS_W void initUndistortRectifyMap(InputArray K, InputArray D, InputArray R, InputArray P, + const cv::Size& size, int m1type, OutputArray map1, OutputArray map2); + + /** @brief Transforms an image to compensate for fisheye lens distortion. + + @param distorted image with fisheye lens distortion. + @param undistorted Output image with compensated fisheye lens distortion. + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param Knew Camera matrix of the distorted image. By default, it is the identity matrix but you + may additionally scale and shift the result by using a different matrix. + @param new_size the new size + + The function transforms an image to compensate radial and tangential lens distortion. + + The function is simply a combination of fisheye::initUndistortRectifyMap (with unity R ) and remap + (with bilinear interpolation). See the former function for details of the transformation being + performed. + + See below the results of undistortImage. + - a\) result of undistort of perspective camera model (all possible coefficients (k_1, k_2, k_3, + k_4, k_5, k_6) of distortion were optimized under calibration) + - b\) result of fisheye::undistortImage of fisheye camera model (all possible coefficients (k_1, k_2, + k_3, k_4) of fisheye distortion were optimized under calibration) + - c\) original image was captured with fisheye lens + + Pictures a) and b) almost the same. But if we consider points of image located far from the center + of image, we can notice that on image a) these points are distorted. + + ![image](pics/fisheye_undistorted.jpg) + */ + CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted, + InputArray K, InputArray D, InputArray Knew = cv::noArray(), const Size& new_size = Size()); + + /** @brief Estimates new camera matrix for undistortion or rectification. + + @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param image_size Size of the image + @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param balance Sets the new focal length in range between the min focal length and the max focal + length. Balance is in range of [0, 1]. + @param new_size the new size + @param fov_scale Divisor for new focal length. + */ + CV_EXPORTS_W void estimateNewCameraMatrixForUndistortRectify(InputArray K, InputArray D, const Size &image_size, InputArray R, + OutputArray P, double balance = 0.0, const Size& new_size = Size(), double fov_scale = 1.0); + + /** @brief Performs camera calibaration + + @param objectPoints vector of vectors of calibration pattern points in the calibration pattern + coordinate space. + @param imagePoints vector of vectors of the projections of calibration pattern points. + imagePoints.size() and objectPoints.size() and imagePoints[i].size() must be equal to + objectPoints[i].size() for each i. + @param image_size Size of the image used only to initialize the intrinsic camera matrix. + @param K Output 3x3 floating-point camera matrix + \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If + fisheye::CALIB_USE_INTRINSIC_GUESS/ is specified, some or all of fx, fy, cx, cy must be + initialized before calling the function. + @param D Output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. + @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view. + That is, each k-th rotation vector together with the corresponding k-th translation vector (see + the next output parameter description) brings the calibration pattern from the model coordinate + space (in which object points are specified) to the world coordinate space, that is, a real + position of the calibration pattern in the k-th pattern view (k=0.. *M* -1). + @param tvecs Output vector of translation vectors estimated for each pattern view. + @param flags Different flags that may be zero or a combination of the following values: + - **fisheye::CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of + fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image + center ( imageSize is used), and focal distances are computed in a least-squares fashion. + - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration + of intrinsic optimization. + - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number. + - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero. + - **fisheye::CALIB_FIX_K1..fisheye::CALIB_FIX_K4** Selected distortion coefficients + are set to zeros and stay zero. + - **fisheye::CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global +optimization. It stays at the center or at a different location specified when CALIB_USE_INTRINSIC_GUESS is set too. + @param criteria Termination criteria for the iterative optimization algorithm. + */ + CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size, + InputOutputArray K, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON)); + + /** @brief Stereo rectification for fisheye camera model + + @param K1 First camera matrix. + @param D1 First camera distortion parameters. + @param K2 Second camera matrix. + @param D2 Second camera distortion parameters. + @param imageSize Size of the image used for stereo calibration. + @param R Rotation matrix between the coordinate systems of the first and the second + cameras. + @param tvec Translation vector between coordinate systems of the cameras. + @param R1 Output 3x3 rectification transform (rotation matrix) for the first camera. + @param R2 Output 3x3 rectification transform (rotation matrix) for the second camera. + @param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first + camera. + @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second + camera. + @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). + @param flags Operation flags that may be zero or CALIB_ZERO_DISPARITY . If the flag is set, + the function makes the principal points of each camera have the same pixel coordinates in the + rectified views. And if the flag is not set, the function may still shift the images in the + horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the + useful image area. + @param newImageSize New image resolution after rectification. The same size should be passed to + initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) + is passed (default), it is set to the original imageSize . Setting it to larger value can help you + preserve details in the original image, especially when there is a big radial distortion. + @param balance Sets the new focal length in range between the min focal length and the max focal + length. Balance is in range of [0, 1]. + @param fov_scale Divisor for new focal length. + */ + CV_EXPORTS_W void stereoRectify(InputArray K1, InputArray D1, InputArray K2, InputArray D2, const Size &imageSize, InputArray R, InputArray tvec, + OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags, const Size &newImageSize = Size(), + double balance = 0.0, double fov_scale = 1.0); + + /** @brief Performs stereo calibration + + @param objectPoints Vector of vectors of the calibration pattern points. + @param imagePoints1 Vector of vectors of the projections of the calibration pattern points, + observed by the first camera. + @param imagePoints2 Vector of vectors of the projections of the calibration pattern points, + observed by the second camera. + @param K1 Input/output first camera matrix: + \f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If + any of fisheye::CALIB_USE_INTRINSIC_GUESS , fisheye::CALIB_FIX_INTRINSIC are specified, + some or all of the matrix components must be initialized. + @param D1 Input/output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$ of 4 elements. + @param K2 Input/output second camera matrix. The parameter is similar to K1 . + @param D2 Input/output lens distortion coefficients for the second camera. The parameter is + similar to D1 . + @param imageSize Size of the image used only to initialize intrinsic camera matrix. + @param R Output rotation matrix between the 1st and the 2nd camera coordinate systems. + @param T Output translation vector between the coordinate systems of the cameras. + @param flags Different flags that may be zero or a combination of the following values: + - **fisheye::CALIB_FIX_INTRINSIC** Fix K1, K2? and D1, D2? so that only R, T matrices + are estimated. + - **fisheye::CALIB_USE_INTRINSIC_GUESS** K1, K2 contains valid initial values of + fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image + center (imageSize is used), and focal distances are computed in a least-squares fashion. + - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration + of intrinsic optimization. + - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number. + - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero. + - **fisheye::CALIB_FIX_K1..4** Selected distortion coefficients are set to zeros and stay + zero. + @param criteria Termination criteria for the iterative optimization algorithm. + */ + CV_EXPORTS_W double stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputOutputArray K1, InputOutputArray D1, InputOutputArray K2, InputOutputArray D2, Size imageSize, + OutputArray R, OutputArray T, int flags = fisheye::CALIB_FIX_INTRINSIC, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON)); + +//! @} calib3d_fisheye +} // end namespace fisheye + +} //end namespace cv + +#if 0 //def __cplusplus +////////////////////////////////////////////////////////////////////////////////////////// +class CV_EXPORTS CvLevMarq +{ +public: + CvLevMarq(); + CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + ~CvLevMarq(); + void init( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + bool update( const CvMat*& param, CvMat*& J, CvMat*& err ); + bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm ); + + void clear(); + void step(); + enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 }; + + cv::Ptr mask; + cv::Ptr prevParam; + cv::Ptr param; + cv::Ptr J; + cv::Ptr err; + cv::Ptr JtJ; + cv::Ptr JtJN; + cv::Ptr JtErr; + cv::Ptr JtJV; + cv::Ptr JtJW; + double prevErrNorm, errNorm; + int lambdaLg10; + CvTermCriteria criteria; + int state; + int iters; + bool completeSymmFlag; + int solveMethod; +}; +#endif + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d/calib3d.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d/calib3d.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b3da45edd59c0a0807abb834e0e4216522316443 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d/calib3d.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/calib3d.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d/calib3d_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d/calib3d_c.h new file mode 100644 index 0000000000000000000000000000000000000000..e2af07b2e2ba1e690b7d317acbac479f2186b9db --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/calib3d/calib3d_c.h @@ -0,0 +1,150 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CALIB3D_C_H +#define OPENCV_CALIB3D_C_H + +#include "opencv2/core/types_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Calculates fundamental matrix given a set of corresponding points */ +#define CV_FM_7POINT 1 +#define CV_FM_8POINT 2 + +#define CV_LMEDS 4 +#define CV_RANSAC 8 + +#define CV_FM_LMEDS_ONLY CV_LMEDS +#define CV_FM_RANSAC_ONLY CV_RANSAC +#define CV_FM_LMEDS CV_LMEDS +#define CV_FM_RANSAC CV_RANSAC + +enum +{ + CV_ITERATIVE = 0, + CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation" + CV_P3P = 2, // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem" + CV_DLS = 3 // Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP" +}; + +#define CV_CALIB_CB_ADAPTIVE_THRESH 1 +#define CV_CALIB_CB_NORMALIZE_IMAGE 2 +#define CV_CALIB_CB_FILTER_QUADS 4 +#define CV_CALIB_CB_FAST_CHECK 8 + +#define CV_CALIB_USE_INTRINSIC_GUESS 1 +#define CV_CALIB_FIX_ASPECT_RATIO 2 +#define CV_CALIB_FIX_PRINCIPAL_POINT 4 +#define CV_CALIB_ZERO_TANGENT_DIST 8 +#define CV_CALIB_FIX_FOCAL_LENGTH 16 +#define CV_CALIB_FIX_K1 32 +#define CV_CALIB_FIX_K2 64 +#define CV_CALIB_FIX_K3 128 +#define CV_CALIB_FIX_K4 2048 +#define CV_CALIB_FIX_K5 4096 +#define CV_CALIB_FIX_K6 8192 +#define CV_CALIB_RATIONAL_MODEL 16384 +#define CV_CALIB_THIN_PRISM_MODEL 32768 +#define CV_CALIB_FIX_S1_S2_S3_S4 65536 +#define CV_CALIB_TILTED_MODEL 262144 +#define CV_CALIB_FIX_TAUX_TAUY 524288 +#define CV_CALIB_FIX_TANGENT_DIST 2097152 + +#define CV_CALIB_NINTRINSIC 18 + +#define CV_CALIB_FIX_INTRINSIC 256 +#define CV_CALIB_SAME_FOCAL_LENGTH 512 + +#define CV_CALIB_ZERO_DISPARITY 1024 + +/* stereo correspondence parameters and functions */ +#define CV_STEREO_BM_NORMALIZED_RESPONSE 0 +#define CV_STEREO_BM_XSOBEL 1 + +#ifdef __cplusplus +} // extern "C" + +////////////////////////////////////////////////////////////////////////////////////////// +class CV_EXPORTS CvLevMarq +{ +public: + CvLevMarq(); + CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + ~CvLevMarq(); + void init( int nparams, int nerrs, CvTermCriteria criteria= + cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON), + bool completeSymmFlag=false ); + bool update( const CvMat*& param, CvMat*& J, CvMat*& err ); + bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm ); + + void clear(); + void step(); + enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 }; + + cv::Ptr mask; + cv::Ptr prevParam; + cv::Ptr param; + cv::Ptr J; + cv::Ptr err; + cv::Ptr JtJ; + cv::Ptr JtJN; + cv::Ptr JtErr; + cv::Ptr JtJV; + cv::Ptr JtJW; + double prevErrNorm, errNorm; + int lambdaLg10; + CvTermCriteria criteria; + int state; + int iters; + bool completeSymmFlag; + int solveMethod; +}; + +#endif + +#endif /* OPENCV_CALIB3D_C_H */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib.hpp new file mode 100644 index 0000000000000000000000000000000000000000..538ec0f81b6d0cd665af8688cf641c3fdae510b0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib.hpp @@ -0,0 +1,157 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2014, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#ifndef __OPENCV_CCALIB_HPP__ +#define __OPENCV_CCALIB_HPP__ + +#include +#include +#include +#include + +#include + +/** @defgroup ccalib Custom Calibration Pattern for 3D reconstruction +*/ + +namespace cv{ namespace ccalib{ + +//! @addtogroup ccalib +//! @{ + +class CV_EXPORTS CustomPattern : public Algorithm +{ +public: + CustomPattern(); + virtual ~CustomPattern(); + + bool create(InputArray pattern, const Size2f boardSize, OutputArray output = noArray()); + + bool findPattern(InputArray image, OutputArray matched_features, OutputArray pattern_points, const double ratio = 0.7, + const double proj_error = 8.0, const bool refine_position = false, OutputArray out = noArray(), + OutputArray H = noArray(), OutputArray pattern_corners = noArray()); + + bool isInitialized(); + + void getPatternPoints(std::vector& original_points); + /**< + Returns a vector of the original points. + */ + double getPixelSize(); + /**< + Get the pixel size of the pattern + */ + + bool setFeatureDetector(Ptr featureDetector); + bool setDescriptorExtractor(Ptr extractor); + bool setDescriptorMatcher(Ptr matcher); + + Ptr getFeatureDetector(); + Ptr getDescriptorExtractor(); + Ptr getDescriptorMatcher(); + + double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, + Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, + OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); + /**< + Calls the calirateCamera function with the same inputs. + */ + + bool findRt(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, + InputOutputArray rvec, InputOutputArray tvec, bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE); + bool findRt(InputArray image, InputArray cameraMatrix, InputArray distCoeffs, + InputOutputArray rvec, InputOutputArray tvec, bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE); + /**< + Uses solvePnP to find the rotation and translation of the pattern + with respect to the camera frame. + */ + + bool findRtRANSAC(InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, + InputOutputArray rvec, InputOutputArray tvec, bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, int minInliersCount = 100, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE); + bool findRtRANSAC(InputArray image, InputArray cameraMatrix, InputArray distCoeffs, + InputOutputArray rvec, InputOutputArray tvec, bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, int minInliersCount = 100, OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE); + /**< + Uses solvePnPRansac() + */ + + void drawOrientation(InputOutputArray image, InputArray tvec, InputArray rvec, InputArray cameraMatrix, + InputArray distCoeffs, double axis_length = 3, int axis_width = 2); + /**< + pattern_corners -> projected over the image position of the edges of the pattern. + */ + +private: + + Mat img_roi; + std::vector obj_corners; + double pxSize; + + bool initialized; + + Ptr detector; + Ptr descriptorExtractor; + Ptr descriptorMatcher; + + std::vector keypoints; + std::vector points3d; + Mat descriptor; + + bool init(Mat& image, const float pixel_size, OutputArray output = noArray()); + bool findPatternPass(const Mat& image, std::vector& matched_features, std::vector& pattern_points, + Mat& H, std::vector& scene_corners, const double pratio, const double proj_error, + const bool refine_position = false, const Mat& mask = Mat(), OutputArray output = noArray()); + void scaleFoundPoints(const double squareSize, const std::vector& corners, std::vector& pts3d); + void check_matches(std::vector& matched, const std::vector& pattern, std::vector& good, std::vector& pattern_3d, const Mat& H); + + void keypoints2points(const std::vector& in, std::vector& out); + void updateKeypointsPos(std::vector& in, const std::vector& new_pos); + void refinePointsPos(const Mat& img, std::vector& p); + void refineKeypointsPos(const Mat& img, std::vector& kp); +}; + +//! @} + +}} // namespace ccalib, cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/multicalib.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/multicalib.hpp new file mode 100644 index 0000000000000000000000000000000000000000..686d7a52b09dc8133496003d569244d1c63985ce --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/multicalib.hpp @@ -0,0 +1,212 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, +// all rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_MULTICAMERACALIBRATION_HPP__ +#define __OPENCV_MULTICAMERACALIBRATION_HPP__ + +#include "opencv2/ccalib/randpattern.hpp" +#include "opencv2/ccalib/omnidir.hpp" +#include +#include + +namespace cv { namespace multicalib { + +//! @addtogroup ccalib +//! @{ + +#define HEAD -1 +#define INVALID -2 + +/** @brief Class for multiple camera calibration that supports pinhole camera and omnidirection camera. +For omnidirectional camera model, please refer to omnidir.hpp in ccalib module. +It first calibrate each camera individually, then a bundle adjustment like optimization is applied to +refine extrinsic parameters. So far, it only support "random" pattern for calibration, +see randomPattern.hpp in ccalib module for details. +Images that are used should be named by "cameraIdx-timestamp.*", several images with the same timestamp +means that they are the same pattern that are photographed. cameraIdx should start from 0. + +For more details, please refer to paper + B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System + Calibration Toolbox Using A Feature Descriptor-Based Calibration + Pattern", in IROS 2013. +*/ + +class CV_EXPORTS MultiCameraCalibration +{ +public: + enum { + PINHOLE, + OMNIDIRECTIONAL + //FISHEYE + }; + + // an edge connects a camera and pattern + struct edge + { + int cameraVertex; // vertex index for camera in this edge + int photoVertex; // vertex index for pattern in this edge + int photoIndex; // photo index among photos for this camera + Mat transform; // transform from pattern to camera + + edge(int cv, int pv, int pi, Mat trans) + { + cameraVertex = cv; + photoVertex = pv; + photoIndex = pi; + transform = trans; + } + }; + + struct vertex + { + Mat pose; // relative pose to the first camera. For camera vertex, it is the + // transform from the first camera to this camera, for pattern vertex, + // it is the transform from pattern to the first camera + int timestamp; // timestamp of photo, only available for photo vertex + + vertex(Mat po, int ts) + { + pose = po; + timestamp = ts; + } + + vertex() + { + pose = Mat::eye(4, 4, CV_32F); + timestamp = -1; + } + }; + /* @brief Constructor + @param cameraType camera type, PINHOLE or OMNIDIRECTIONAL + @param nCameras number of cameras + @fileName filename of string list that are used for calibration, the file is generated + by imagelist_creator from OpenCv samples. The first one in the list is the pattern filename. + @patternWidth the physical width of pattern, in user defined unit. + @patternHeight the physical height of pattern, in user defined unit. + @showExtration whether show extracted features and feature filtering. + @nMiniMatches minimal number of matched features for a frame. + @flags Calibration flags + @criteria optimization stopping criteria. + @detector feature detector that detect feature points in pattern and images. + @descriptor feature descriptor. + @matcher feature matcher. + */ + MultiCameraCalibration(int cameraType, int nCameras, const std::string& fileName, float patternWidth, + float patternHeight, int verbose = 0, int showExtration = 0, int nMiniMatches = 20, int flags = 0, + TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 200, 1e-7), + Ptr detector = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.006f), + Ptr descriptor = AKAZE::create(AKAZE::DESCRIPTOR_MLDB,0, 3, 0.006f), + Ptr matcher = DescriptorMatcher::create("BruteForce-L1")); + + /* @brief load images + */ + void loadImages(); + + /* @brief initialize multiple camera calibration. It calibrates each camera individually. + */ + void initialize(); + + /* @brief optimization extrinsic parameters + */ + double optimizeExtrinsics(); + + /* @brief run multi-camera camera calibration, it runs loadImage(), initialize() and optimizeExtrinsics() + */ + double run(); + + /* @brief write camera parameters to file. + */ + void writeParameters(const std::string& filename); + +private: + std::vector readStringList(); + + int getPhotoVertex(int timestamp); + + void graphTraverse(const Mat& G, int begin, std::vector& order, std::vector& pre); + + void findRowNonZero(const Mat& row, Mat& idx); + + void computeJacobianExtrinsic(const Mat& extrinsicParams, Mat& JTJ_inv, Mat& JTE); + + void computePhotoCameraJacobian(const Mat& rvecPhoto, const Mat& tvecPhoto, const Mat& rvecCamera, + const Mat& tvecCamera, Mat& rvecTran, Mat& tvecTran, const Mat& objectPoints, const Mat& imagePoints, const Mat& K, + const Mat& distort, const Mat& xi, Mat& jacobianPhoto, Mat& jacobianCamera, Mat& E); + + void compose_motion(InputArray _om1, InputArray _T1, InputArray _om2, InputArray _T2, Mat& om3, Mat& T3, Mat& dom3dom1, + Mat& dom3dT1, Mat& dom3dom2, Mat& dom3dT2, Mat& dT3dom1, Mat& dT3dT1, Mat& dT3dom2, Mat& dT3dT2); + + void JRodriguesMatlab(const Mat& src, Mat& dst); + void dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB); + + double computeProjectError(Mat& parameters); + + void vector2parameters(const Mat& parameters, std::vector& rvecVertex, std::vector& tvecVertexs); + void parameters2vector(const std::vector& rvecVertex, const std::vector& tvecVertex, Mat& parameters); + + int _camType; //PINHOLE, FISHEYE or OMNIDIRECTIONAL + int _nCamera; + int _nMiniMatches; + int _flags; + int _verbose; + double _error; + float _patternWidth, _patternHeight; + TermCriteria _criteria; + std::string _filename; + int _showExtraction; + Ptr _detector; + Ptr _descriptor; + Ptr _matcher; + + std::vector _edgeList; + std::vector _vertexList; + std::vector > _objectPointsForEachCamera; + std::vector > _imagePointsForEachCamera; + std::vector _cameraMatrix; + std::vector _distortCoeffs; + std::vector _xi; + std::vector > _omEachCamera, _tEachCamera; +}; + +//! @} + +}} // namespace multicalib, cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/omnidir.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/omnidir.hpp new file mode 100644 index 0000000000000000000000000000000000000000..140aede656177677bd7259966ad953781e348595 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/omnidir.hpp @@ -0,0 +1,310 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, +// all rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include +#include + +#ifndef __OPENCV_OMNIDIR_HPP__ +#define __OPENCV_OMNIDIR_HPP__ + +namespace cv +{ +namespace omnidir +{ + //! @addtogroup ccalib + //! @{ + + enum { + CALIB_USE_GUESS = 1, + CALIB_FIX_SKEW = 2, + CALIB_FIX_K1 = 4, + CALIB_FIX_K2 = 8, + CALIB_FIX_P1 = 16, + CALIB_FIX_P2 = 32, + CALIB_FIX_XI = 64, + CALIB_FIX_GAMMA = 128, + CALIB_FIX_CENTER = 256 + }; + + enum{ + RECTIFY_PERSPECTIVE = 1, + RECTIFY_CYLINDRICAL = 2, + RECTIFY_LONGLATI = 3, + RECTIFY_STEREOGRAPHIC = 4 + }; + + enum{ + XYZRGB = 1, + XYZ = 2 + }; +/** + * This module was accepted as a GSoC 2015 project for OpenCV, authored by + * Baisheng Lai, mentored by Bo Li. + */ + + /** @brief Projects points for omnidirectional camera using CMei's model + + @param objectPoints Object points in world coordinate, vector of vector of Vec3f or Mat of + 1xN/Nx1 3-channel of type CV_32F and N is the number of points. 64F is also acceptable. + @param imagePoints Output array of image points, vector of vector of Vec2f or + 1xN/Nx1 2-channel of type CV_32F. 64F is also acceptable. + @param rvec vector of rotation between world coordinate and camera coordinate, i.e., om + @param tvec vector of translation between pattern coordinate and camera coordinate + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. + @param xi The parameter xi for CMei's model + @param jacobian Optional output 2Nx16 of type CV_64F jacobian matrix, contains the derivatives of + image pixel points wrt parameters including \f$om, T, f_x, f_y, s, c_x, c_y, xi, k_1, k_2, p_1, p_2\f$. + This matrix will be used in calibration by optimization. + + The function projects object 3D points of world coordinate to image pixels, parameter by intrinsic + and extrinsic parameters. Also, it optionally compute a by-product: the jacobian matrix containing + contains the derivatives of image pixel points wrt intrinsic and extrinsic parameters. + */ + CV_EXPORTS_W void projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec, + InputArray K, double xi, InputArray D, OutputArray jacobian = noArray()); + + /** @brief Undistort 2D image points for omnidirectional camera using CMei's model + + @param distorted Array of distorted image points, vector of Vec2f + or 1xN/Nx1 2-channel Mat of type CV_32F, 64F depth is also acceptable + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. + @param xi The parameter xi for CMei's model + @param R Rotation trainsform between the original and object space : 3x3 1-channel, or vector: 3x1/1x3 + 1-channel or 1x1 3-channel + @param undistorted array of normalized object points, vector of Vec2f/Vec2d or 1xN/Nx1 2-channel Mat with the same + depth of distorted points. + */ + CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray xi, InputArray R); + + /** @brief Computes undistortion and rectification maps for omnidirectional camera image transform by a rotation R. + It output two maps that are used for cv::remap(). If D is empty then zero distortion is used, + if R or P is empty then identity matrices are used. + + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$, with depth CV_32F or CV_64F + @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$, with depth CV_32F or CV_64F + @param xi The parameter xi for CMei's model + @param R Rotation transform between the original and object space : 3x3 1-channel, or vector: 3x1/1x3, with depth CV_32F or CV_64F + @param P New camera matrix (3x3) or new projection matrix (3x4) + @param size Undistorted image size. + @param mltype Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps() + for details. + @param map1 The first output map. + @param map2 The second output map. + @param flags Flags indicates the rectification type, RECTIFY_PERSPECTIVE, RECTIFY_CYLINDRICAL, RECTIFY_LONGLATI and RECTIFY_STEREOGRAPHIC + are supported. + */ + CV_EXPORTS_W void initUndistortRectifyMap(InputArray K, InputArray D, InputArray xi, InputArray R, InputArray P, const cv::Size& size, + int mltype, OutputArray map1, OutputArray map2, int flags); + + /** @brief Undistort omnidirectional images to perspective images + + @param distorted The input omnidirectional image. + @param undistorted The output undistorted image. + @param K Camera matrix \f$K = \vecthreethree{f_x}{s}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. + @param D Input vector of distortion coefficients \f$(k_1, k_2, p_1, p_2)\f$. + @param xi The parameter xi for CMei's model. + @param flags Flags indicates the rectification type, RECTIFY_PERSPECTIVE, RECTIFY_CYLINDRICAL, RECTIFY_LONGLATI and RECTIFY_STEREOGRAPHIC + @param Knew Camera matrix of the distorted image. If it is not assigned, it is just K. + @param new_size The new image size. By default, it is the size of distorted. + @param R Rotation matrix between the input and output images. By default, it is identity matrix. + */ + CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted, InputArray K, InputArray D, InputArray xi, int flags, + InputArray Knew = cv::noArray(), const Size& new_size = Size(), InputArray R = Mat::eye(3, 3, CV_64F)); + + /** @brief Perform omnidirectional camera calibration, the default depth of outputs is CV_64F. + + @param objectPoints Vector of vector of Vec3f object points in world (pattern) coordinate. + It also can be vector of Mat with size 1xN/Nx1 and type CV_32FC3. Data with depth of 64_F is also acceptable. + @param imagePoints Vector of vector of Vec2f corresponding image points of objectPoints. It must be the same + size and the same type with objectPoints. + @param size Image size of calibration images. + @param K Output calibrated camera matrix. + @param xi Output parameter xi for CMei's model + @param D Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ + @param rvecs Output rotations for each calibration images + @param tvecs Output translation for each calibration images + @param flags The flags that control calibrate + @param criteria Termination criteria for optimization + @param idx Indices of images that pass initialization, which are really used in calibration. So the size of rvecs is the + same as idx.total(). + */ + CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size size, + InputOutputArray K, InputOutputArray xi, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, + int flags, TermCriteria criteria, OutputArray idx=noArray()); + + /** @brief Stereo calibration for omnidirectional camera model. It computes the intrinsic parameters for two + cameras and the extrinsic parameters between two cameras. The default depth of outputs is CV_64F. + + @param objectPoints Object points in world (pattern) coordinate. Its type is vector >. + It also can be vector of Mat with size 1xN/Nx1 and type CV_32FC3. Data with depth of 64_F is also acceptable. + @param imagePoints1 The corresponding image points of the first camera, with type vector >. + It must be the same size and the same type as objectPoints. + @param imagePoints2 The corresponding image points of the second camera, with type vector >. + It must be the same size and the same type as objectPoints. + @param imageSize1 Image size of calibration images of the first camera. + @param imageSize2 Image size of calibration images of the second camera. + @param K1 Output camera matrix for the first camera. + @param xi1 Output parameter xi of Mei's model for the first camera + @param D1 Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the first camera + @param K2 Output camera matrix for the first camera. + @param xi2 Output parameter xi of CMei's model for the second camera + @param D2 Output distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the second camera + @param rvec Output rotation between the first and second camera + @param tvec Output translation between the first and second camera + @param rvecsL Output rotation for each image of the first camera + @param tvecsL Output translation for each image of the first camera + @param flags The flags that control stereoCalibrate + @param criteria Termination criteria for optimization + @param idx Indices of image pairs that pass initialization, which are really used in calibration. So the size of rvecs is the + same as idx.total(). + @ + */ + CV_EXPORTS_W double stereoCalibrate(InputOutputArrayOfArrays objectPoints, InputOutputArrayOfArrays imagePoints1, InputOutputArrayOfArrays imagePoints2, + const Size& imageSize1, const Size& imageSize2, InputOutputArray K1, InputOutputArray xi1, InputOutputArray D1, InputOutputArray K2, InputOutputArray xi2, + InputOutputArray D2, OutputArray rvec, OutputArray tvec, OutputArrayOfArrays rvecsL, OutputArrayOfArrays tvecsL, int flags, TermCriteria criteria, OutputArray idx=noArray()); + + /** @brief Stereo rectification for omnidirectional camera model. It computes the rectification rotations for two cameras + + @param R Rotation between the first and second camera + @param T Translation between the first and second camera + @param R1 Output 3x3 rotation matrix for the first camera + @param R2 Output 3x3 rotation matrix for the second camera + */ + CV_EXPORTS_W void stereoRectify(InputArray R, InputArray T, OutputArray R1, OutputArray R2); + + /** @brief Stereo 3D reconstruction from a pair of images + + @param image1 The first input image + @param image2 The second input image + @param K1 Input camera matrix of the first camera + @param D1 Input distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the first camera + @param xi1 Input parameter xi for the first camera for CMei's model + @param K2 Input camera matrix of the second camera + @param D2 Input distortion parameters \f$(k_1, k_2, p_1, p_2)\f$ for the second camera + @param xi2 Input parameter xi for the second camera for CMei's model + @param R Rotation between the first and second camera + @param T Translation between the first and second camera + @param flag Flag of rectification type, RECTIFY_PERSPECTIVE or RECTIFY_LONGLATI + @param numDisparities The parameter 'numDisparities' in StereoSGBM, see StereoSGBM for details. + @param SADWindowSize The parameter 'SADWindowSize' in StereoSGBM, see StereoSGBM for details. + @param disparity Disparity map generated by stereo matching + @param image1Rec Rectified image of the first image + @param image2Rec rectified image of the second image + @param newSize Image size of rectified image, see omnidir::undistortImage + @param Knew New camera matrix of rectified image, see omnidir::undistortImage + @param pointCloud Point cloud of 3D reconstruction, with type CV_64FC3 + @param pointType Point cloud type, it can be XYZRGB or XYZ + */ + CV_EXPORTS_W void stereoReconstruct(InputArray image1, InputArray image2, InputArray K1, InputArray D1, InputArray xi1, + InputArray K2, InputArray D2, InputArray xi2, InputArray R, InputArray T, int flag, int numDisparities, int SADWindowSize, + OutputArray disparity, OutputArray image1Rec, OutputArray image2Rec, const Size& newSize = Size(), InputArray Knew = cv::noArray(), + OutputArray pointCloud = cv::noArray(), int pointType = XYZRGB); + +namespace internal +{ + void initializeCalibration(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, Size size, OutputArrayOfArrays omAll, + OutputArrayOfArrays tAll, OutputArray K, double& xi, OutputArray idx = noArray()); + + void initializeStereoCalibration(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + const Size& size1, const Size& size2, OutputArray om, OutputArray T, OutputArrayOfArrays omL, OutputArrayOfArrays tL, OutputArray K1, OutputArray D1, OutputArray K2, OutputArray D2, + double &xi1, double &xi2, int flags, OutputArray idx); + + void computeJacobian(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray parameters, Mat& JTJ_inv, Mat& JTE, int flags, + double epsilon); + + void computeJacobianStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, + InputArray parameters, Mat& JTJ_inv, Mat& JTE, int flags, double epsilon); + + void encodeParameters(InputArray K, InputArrayOfArrays omAll, InputArrayOfArrays tAll, InputArray distoaration, double xi, OutputArray parameters); + + void encodeParametersStereo(InputArray K1, InputArray K2, InputArray om, InputArray T, InputArrayOfArrays omL, InputArrayOfArrays tL, + InputArray D1, InputArray D2, double xi1, double xi2, OutputArray parameters); + + void decodeParameters(InputArray paramsters, OutputArray K, OutputArrayOfArrays omAll, OutputArrayOfArrays tAll, OutputArray distoration, double& xi); + + void decodeParametersStereo(InputArray parameters, OutputArray K1, OutputArray K2, OutputArray om, OutputArray T, OutputArrayOfArrays omL, + OutputArrayOfArrays tL, OutputArray D1, OutputArray D2, double& xi1, double& xi2); + + void estimateUncertainties(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray parameters, Mat& errors, Vec2d& std_error, double& rms, int flags); + + void estimateUncertaintiesStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputArray parameters, Mat& errors, + Vec2d& std_error, double& rms, int flags); + + double computeMeanReproErr(InputArrayOfArrays imagePoints, InputArrayOfArrays proImagePoints); + + double computeMeanReproErr(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, InputArray K, InputArray D, double xi, InputArrayOfArrays omAll, + InputArrayOfArrays tAll); + + double computeMeanReproErrStereo(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, InputArray K1, InputArray K2, + InputArray D1, InputArray D2, double xi1, double xi2, InputArray om, InputArray T, InputArrayOfArrays omL, InputArrayOfArrays TL); + + void subMatrix(const Mat& src, Mat& dst, const std::vector& cols, const std::vector& rows); + + void flags2idx(int flags, std::vector& idx, int n); + + void flags2idxStereo(int flags, std::vector& idx, int n); + + void fillFixed(Mat&G, int flags, int n); + + void fillFixedStereo(Mat& G, int flags, int n); + + double findMedian(const Mat& row); + + Vec3d findMedian3(InputArray mat); + + void getInterset(InputArray idx1, InputArray idx2, OutputArray inter1, OutputArray inter2, OutputArray inter_ori); + + void compose_motion(InputArray _om1, InputArray _T1, InputArray _om2, InputArray _T2, Mat& om3, Mat& T3, Mat& dom3dom1, + Mat& dom3dT1, Mat& dom3dom2, Mat& dom3dT2, Mat& dT3dom1, Mat& dT3dT1, Mat& dT3dom2, Mat& dT3dT2); + + //void JRodriguesMatlab(const Mat& src, Mat& dst); + + //void dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB); +} // internal + +//! @} + +} // omnidir + +} //cv +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/randpattern.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/randpattern.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fb362bd5308efe217e16282b0ba4f67312e6d0a6 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ccalib/randpattern.hpp @@ -0,0 +1,184 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University, +// all rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_RANDOMPATTERN_HPP__ +#define __OPENCV_RANDOMPATTERN_HPP__ + +#include "opencv2/features2d.hpp" +#include "opencv2/highgui.hpp" + +namespace cv { namespace randpattern { + + +//! @addtogroup ccalib +//! @{ + +/** @brief Class for finding features points and corresponding 3D in world coordinate of +a "random" pattern, which can be to be used in calibration. It is useful when pattern is +partly occluded or only a part of pattern can be observed in multiple cameras calibration. +The pattern can be generated by RandomPatternGenerator class described in this file. + +Please refer to paper + B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System + Calibration Toolbox Using A Feature Descriptor-Based Calibration + Pattern", in IROS 2013. +*/ + +class CV_EXPORTS RandomPatternCornerFinder +{ +public: + + /* @brief Construct RandomPatternCornerFinder object + + @param patternWidth the real width of "random" pattern in a user defined unit. + @param patternHeight the real height of "random" pattern in a user defined unit. + @param nMiniMatch number of minimal matches, otherwise that image is abandoned + @depth depth of output objectPoints and imagePoints, set it to be CV_32F or CV_64F. + @showExtraction whether show feature extraction, 0 for no and 1 for yes. + @detector feature detector to detect feature points in pattern and images. + @descriptor feature descriptor. + @matcher feature matcher. + */ + RandomPatternCornerFinder(float patternWidth, float patternHeight, + int nminiMatch = 20, int depth = CV_32F, int verbose = 0, int showExtraction = 0, + Ptr detector = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.005f), + Ptr descriptor = AKAZE::create(AKAZE::DESCRIPTOR_MLDB,0, 3, 0.005f), + Ptr matcher = DescriptorMatcher::create("BruteForce-L1")); + + /* @brief Load pattern image and compute features for pattern + @param patternImage image for "random" pattern generated by RandomPatternGenerator, run it first. + */ + void loadPattern(const cv::Mat &patternImage); + + /* @brief Load pattern and features + @param patternImage image for "random" pattern generated by RandomPatternGenerator, run it first. + @param patternKeyPoints keyPoints created from a FeatureDetector. + @param patternDescriptors descriptors created from a DescriptorExtractor. + */ + void loadPattern(const cv::Mat &patternImage, const std::vector &patternKeyPoints, const cv::Mat &patternDescriptors); + + /* @brief Compute matched object points and image points which are used for calibration + The objectPoints (3D) and imagePoints (2D) are stored inside the class. Run getObjectPoints() + and getImagePoints() to get them. + + @param inputImages vector of 8-bit grayscale images containing "random" pattern + that are used for calibration. + */ + void computeObjectImagePoints(std::vector inputImages); + + //void computeObjectImagePoints2(std::vector inputImages); + + /* @brief Compute object and image points for a single image. It returns a vector that + the first element stores the imagePoints and the second one stores the objectPoints. + + @param inputImage single input image for calibration + */ + std::vector computeObjectImagePointsForSingle(cv::Mat inputImage); + + /* @brief Get object(3D) points + */ + const std::vector &getObjectPoints(); + + /* @brief and image(2D) points + */ + const std::vector &getImagePoints(); + +private: + + std::vector _objectPonits, _imagePoints; + float _patternWidth, _patternHeight; + cv::Size _patternImageSize; + int _nminiMatch; + int _depth; + int _verbose; + + Ptr _detector; + Ptr _descriptor; + Ptr _matcher; + Mat _descriptorPattern; + std::vector _keypointsPattern; + Mat _patternImage; + int _showExtraction; + + void keyPoints2MatchedLocation(const std::vector& imageKeypoints, + const std::vector& patternKeypoints, const std::vector matchces, + cv::Mat& matchedImagelocation, cv::Mat& matchedPatternLocation); + void getFilteredLocation(cv::Mat& imageKeypoints, cv::Mat& patternKeypoints, const cv::Mat mask); + void getObjectImagePoints(const cv::Mat& imageKeypoints, const cv::Mat& patternKeypoints); + void crossCheckMatching( cv::Ptr& descriptorMatcher, + const Mat& descriptors1, const Mat& descriptors2, + std::vector& filteredMatches12, int knn=1 ); + void drawCorrespondence(const Mat& image1, const std::vector keypoint1, + const Mat& image2, const std::vector keypoint2, const std::vector matchces, + const Mat& mask1, const Mat& mask2, const int step); +}; + +/* @brief Class to generate "random" pattern image that are used for RandomPatternCornerFinder +Please refer to paper +B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System +Calibration Toolbox Using A Feature Descriptor-Based Calibration +Pattern", in IROS 2013. +*/ +class CV_EXPORTS RandomPatternGenerator +{ +public: + /* @brief Construct RandomPatternGenerator + + @param imageWidth image width of the generated pattern image + @param imageHeight image height of the generated pattern image + */ + RandomPatternGenerator(int imageWidth, int imageHeight); + + /* @brief Generate pattern + */ + void generatePattern(); + /* @brief Get pattern + */ + cv::Mat getPattern(); +private: + cv::Mat _pattern; + int _imageWidth, _imageHeight; +}; + +//! @} + +}} //namespace randpattern, cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ff9fa36232c83030f760f496b429cc68db791206 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core.hpp @@ -0,0 +1,3297 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +// Copyright (C) 2015, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_HPP +#define OPENCV_CORE_HPP + +#ifndef __cplusplus +# error core.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/version.hpp" +#include "opencv2/core/base.hpp" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/traits.hpp" +#include "opencv2/core/matx.hpp" +#include "opencv2/core/types.hpp" +#include "opencv2/core/mat.hpp" +#include "opencv2/core/persistence.hpp" + +/** +@defgroup core Core functionality +@{ + @defgroup core_basic Basic structures + @defgroup core_c C structures and operations + @{ + @defgroup core_c_glue Connections with C++ + @} + @defgroup core_array Operations on arrays + @defgroup core_async Asynchronous API + @defgroup core_xml XML/YAML Persistence + @defgroup core_cluster Clustering + @defgroup core_utils Utility and system functions and macros + @{ + @defgroup core_logging Logging facilities + @defgroup core_utils_sse SSE utilities + @defgroup core_utils_neon NEON utilities + @defgroup core_utils_vsx VSX utilities + @defgroup core_utils_softfloat Softfloat support + @defgroup core_utils_samples Utility functions for OpenCV samples + @} + @defgroup core_opengl OpenGL interoperability + @defgroup core_ipp Intel IPP Asynchronous C/C++ Converters + @defgroup core_optim Optimization Algorithms + @defgroup core_directx DirectX interoperability + @defgroup core_eigen Eigen support + @defgroup core_opencl OpenCL support + @defgroup core_va_intel Intel VA-API/OpenCL (CL-VA) interoperability + @defgroup core_hal Hardware Acceleration Layer + @{ + @defgroup core_hal_functions Functions + @defgroup core_hal_interface Interface + @defgroup core_hal_intrin Universal intrinsics + @{ + @defgroup core_hal_intrin_impl Private implementation helpers + @} + @defgroup core_lowlevel_api Low-level API for external libraries / plugins + @} +@} + */ + +namespace cv { + +//! @addtogroup core_utils +//! @{ + +/*! @brief Class passed to an error. + +This class encapsulates all or almost all necessary +information about the error happened in the program. The exception is +usually constructed and thrown implicitly via CV_Error and CV_Error_ macros. +@see error + */ +class CV_EXPORTS Exception : public std::exception +{ +public: + /*! + Default constructor + */ + Exception(); + /*! + Full constructor. Normally the constructor is not called explicitly. + Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used. + */ + Exception(int _code, const String& _err, const String& _func, const String& _file, int _line); + virtual ~Exception() throw(); + + /*! + \return the error description and the context as a text string. + */ + virtual const char *what() const throw() CV_OVERRIDE; + void formatMessage(); + + String msg; ///< the formatted error message + + int code; ///< error code @see CVStatus + String err; ///< error description + String func; ///< function name. Available only when the compiler supports getting it + String file; ///< source file name where the error has occurred + int line; ///< line number in the source file where the error has occurred +}; + +/*! @brief Signals an error and raises the exception. + +By default the function prints information about the error to stderr, +then it either stops if cv::setBreakOnError() had been called before or raises the exception. +It is possible to alternate error processing by using #redirectError(). +@param exc the exception raisen. +@deprecated drop this version + */ +CV_EXPORTS CV_NORETURN void error(const Exception& exc); + +enum SortFlags { SORT_EVERY_ROW = 0, //!< each matrix row is sorted independently + SORT_EVERY_COLUMN = 1, //!< each matrix column is sorted + //!< independently; this flag and the previous one are + //!< mutually exclusive. + SORT_ASCENDING = 0, //!< each matrix row is sorted in the ascending + //!< order. + SORT_DESCENDING = 16 //!< each matrix row is sorted in the + //!< descending order; this flag and the previous one are also + //!< mutually exclusive. + }; + +//! @} core_utils + +//! @addtogroup core +//! @{ + +//! Covariation flags +enum CovarFlags { + /** The output covariance matrix is calculated as: + \f[\texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...],\f] + The covariance matrix will be nsamples x nsamples. Such an unusual covariance matrix is used + for fast PCA of a set of very large vectors (see, for example, the EigenFaces technique for + face recognition). Eigenvalues of this "scrambled" matrix match the eigenvalues of the true + covariance matrix. The "true" eigenvectors can be easily calculated from the eigenvectors of + the "scrambled" covariance matrix. */ + COVAR_SCRAMBLED = 0, + /**The output covariance matrix is calculated as: + \f[\texttt{scale} \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...] \cdot [ \texttt{vects} [0]- \texttt{mean} , \texttt{vects} [1]- \texttt{mean} ,...]^T,\f] + covar will be a square matrix of the same size as the total number of elements in each input + vector. One and only one of #COVAR_SCRAMBLED and #COVAR_NORMAL must be specified.*/ + COVAR_NORMAL = 1, + /** If the flag is specified, the function does not calculate mean from + the input vectors but, instead, uses the passed mean vector. This is useful if mean has been + pre-calculated or known in advance, or if the covariance matrix is calculated by parts. In + this case, mean is not a mean vector of the input sub-set of vectors but rather the mean + vector of the whole set.*/ + COVAR_USE_AVG = 2, + /** If the flag is specified, the covariance matrix is scaled. In the + "normal" mode, scale is 1./nsamples . In the "scrambled" mode, scale is the reciprocal of the + total number of elements in each input vector. By default (if the flag is not specified), the + covariance matrix is not scaled ( scale=1 ).*/ + COVAR_SCALE = 4, + /** If the flag is + specified, all the input vectors are stored as rows of the samples matrix. mean should be a + single-row vector in this case.*/ + COVAR_ROWS = 8, + /** If the flag is + specified, all the input vectors are stored as columns of the samples matrix. mean should be a + single-column vector in this case.*/ + COVAR_COLS = 16 +}; + +//! k-Means flags +enum KmeansFlags { + /** Select random initial centers in each attempt.*/ + KMEANS_RANDOM_CENTERS = 0, + /** Use kmeans++ center initialization by Arthur and Vassilvitskii [Arthur2007].*/ + KMEANS_PP_CENTERS = 2, + /** During the first (and possibly the only) attempt, use the + user-supplied labels instead of computing them from the initial centers. For the second and + further attempts, use the random or semi-random centers. Use one of KMEANS_\*_CENTERS flag + to specify the exact method.*/ + KMEANS_USE_INITIAL_LABELS = 1 +}; + +enum ReduceTypes { REDUCE_SUM = 0, //!< the output is the sum of all rows/columns of the matrix. + REDUCE_AVG = 1, //!< the output is the mean vector of all rows/columns of the matrix. + REDUCE_MAX = 2, //!< the output is the maximum (column/row-wise) of all rows/columns of the matrix. + REDUCE_MIN = 3 //!< the output is the minimum (column/row-wise) of all rows/columns of the matrix. + }; + + +/** @brief Swaps two matrices +*/ +CV_EXPORTS void swap(Mat& a, Mat& b); +/** @overload */ +CV_EXPORTS void swap( UMat& a, UMat& b ); + +//! @} core + +//! @addtogroup core_array +//! @{ + +/** @brief Computes the source location of an extrapolated pixel. + +The function computes and returns the coordinate of a donor pixel corresponding to the specified +extrapolated pixel when using the specified extrapolation border mode. For example, if you use +cv::BORDER_WRAP mode in the horizontal direction, cv::BORDER_REFLECT_101 in the vertical direction and +want to compute value of the "virtual" pixel Point(-5, 100) in a floating-point image img , it +looks like: +@code{.cpp} + float val = img.at(borderInterpolate(100, img.rows, cv::BORDER_REFLECT_101), + borderInterpolate(-5, img.cols, cv::BORDER_WRAP)); +@endcode +Normally, the function is not called directly. It is used inside filtering functions and also in +copyMakeBorder. +@param p 0-based coordinate of the extrapolated pixel along one of the axes, likely \<0 or \>= len +@param len Length of the array along the corresponding axis. +@param borderType Border type, one of the #BorderTypes, except for #BORDER_TRANSPARENT and +#BORDER_ISOLATED . When borderType==#BORDER_CONSTANT , the function always returns -1, regardless +of p and len. + +@sa copyMakeBorder +*/ +CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType); + +/** @example samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp +An example using copyMakeBorder function. +Check @ref tutorial_copyMakeBorder "the corresponding tutorial" for more details +*/ + +/** @brief Forms a border around an image. + +The function copies the source image into the middle of the destination image. The areas to the +left, to the right, above and below the copied source image will be filled with extrapolated +pixels. This is not what filtering functions based on it do (they extrapolate pixels on-fly), but +what other more complex functions, including your own, may do to simplify image boundary handling. + +The function supports the mode when src is already in the middle of dst . In this case, the +function does not copy src itself but simply constructs the border, for example: + +@code{.cpp} + // let border be the same in all directions + int border=2; + // constructs a larger image to fit both the image and the border + Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth()); + // select the middle part of it w/o copying data + Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows)); + // convert image from RGB to grayscale + cvtColor(rgb, gray, COLOR_RGB2GRAY); + // form a border in-place + copyMakeBorder(gray, gray_buf, border, border, + border, border, BORDER_REPLICATE); + // now do some custom filtering ... + ... +@endcode +@note When the source image is a part (ROI) of a bigger image, the function will try to use the +pixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as +if src was not a ROI, use borderType | #BORDER_ISOLATED. + +@param src Source image. +@param dst Destination image of the same type as src and the size Size(src.cols+left+right, +src.rows+top+bottom) . +@param top the top pixels +@param bottom the bottom pixels +@param left the left pixels +@param right Parameter specifying how many pixels in each direction from the source image rectangle +to extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs +to be built. +@param borderType Border type. See borderInterpolate for details. +@param value Border value if borderType==BORDER_CONSTANT . + +@sa borderInterpolate +*/ +CV_EXPORTS_W void copyMakeBorder(InputArray src, OutputArray dst, + int top, int bottom, int left, int right, + int borderType, const Scalar& value = Scalar() ); + +/** @brief Calculates the per-element sum of two arrays or an array and a scalar. + +The function add calculates: +- Sum of two arrays when both input arrays have the same size and the same number of channels: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f] +- Sum of an array and a scalar when src2 is constructed from Scalar or has the same number of +elements as `src1.channels()`: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f] +- Sum of a scalar and an array when src1 is constructed from Scalar or has the same number of +elements as `src2.channels()`: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} + \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f] +where `I` is a multi-dimensional index of array elements. In case of multi-channel arrays, each +channel is processed independently. + +The first function in the list above can be replaced with matrix expressions: +@code{.cpp} + dst = src1 + src2; + dst += src1; // equivalent to add(dst, src1, dst); +@endcode +The input arrays and the output array can all have the same or different depths. For example, you +can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit +floating-point array. Depth of the output array is determined by the dtype parameter. In the second +and third cases above, as well as in the first case, when src1.depth() == src2.depth(), dtype can +be set to the default -1. In this case, the output array will have the same depth as the input +array, be it src1, src2 or both. +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and number of channels as the input array(s); the +depth is defined by dtype or src1/src2. +@param mask optional operation mask - 8-bit single channel array, that specifies elements of the +output array to be changed. +@param dtype optional depth of the output array (see the discussion below). +@sa subtract, addWeighted, scaleAdd, Mat::convertTo +*/ +CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, + InputArray mask = noArray(), int dtype = -1); + +/** @brief Calculates the per-element difference between two arrays or array and a scalar. + +The function subtract calculates: +- Difference between two arrays, when both input arrays have the same size and the same number of +channels: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f] +- Difference between an array and a scalar, when src2 is constructed from Scalar or has the same +number of elements as `src1.channels()`: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2} ) \quad \texttt{if mask}(I) \ne0\f] +- Difference between a scalar and an array, when src1 is constructed from Scalar or has the same +number of elements as `src2.channels()`: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} - \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0\f] +- The reverse difference between a scalar and an array in the case of `SubRS`: + \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src2} - \texttt{src1}(I) ) \quad \texttt{if mask}(I) \ne0\f] +where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each +channel is processed independently. + +The first function in the list above can be replaced with matrix expressions: +@code{.cpp} + dst = src1 - src2; + dst -= src1; // equivalent to subtract(dst, src1, dst); +@endcode +The input arrays and the output array can all have the same or different depths. For example, you +can subtract to 8-bit unsigned arrays and store the difference in a 16-bit signed array. Depth of +the output array is determined by dtype parameter. In the second and third cases above, as well as +in the first case, when src1.depth() == src2.depth(), dtype can be set to the default -1. In this +case the output array will have the same depth as the input array, be it src1, src2 or both. +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array of the same size and the same number of channels as the input array. +@param mask optional operation mask; this is an 8-bit single channel array that specifies elements +of the output array to be changed. +@param dtype optional depth of the output array +@sa add, addWeighted, scaleAdd, Mat::convertTo + */ +CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, + InputArray mask = noArray(), int dtype = -1); + + +/** @brief Calculates the per-element scaled product of two arrays. + +The function multiply calculates the per-element product of two arrays: + +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f] + +There is also a @ref MatrixExpressions -friendly variant of the first function. See Mat::mul . + +For a not-per-element matrix product, see gemm . + +@note Saturation is not applied when the output array has the depth +CV_32S. You may even get result of an incorrect sign in the case of +overflow. +@param src1 first input array. +@param src2 second input array of the same size and the same type as src1. +@param dst output array of the same size and type as src1. +@param scale optional scale factor. +@param dtype optional depth of the output array +@sa add, subtract, divide, scaleAdd, addWeighted, accumulate, accumulateProduct, accumulateSquare, +Mat::convertTo +*/ +CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, + OutputArray dst, double scale = 1, int dtype = -1); + +/** @brief Performs per-element division of two arrays or a scalar by an array. + +The function cv::divide divides one array by another: +\f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f] +or a scalar by an array when there is no src1 : +\f[\texttt{dst(I) = saturate(scale/src2(I))}\f] + +Different channels of multi-channel arrays are processed independently. + +For integer types when src2(I) is zero, dst(I) will also be zero. + +@note In case of floating point data there is no special defined behavior for zero src2(I) values. +Regular floating-point division is used. +Expect correct IEEE-754 behaviour for floating-point data (with NaN, Inf result values). + +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array. +@param src2 second input array of the same size and type as src1. +@param scale scalar factor. +@param dst output array of the same size and type as src2. +@param dtype optional depth of the output array; if -1, dst will have depth src2.depth(), but in +case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth(). +@sa multiply, add, subtract +*/ +CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst, + double scale = 1, int dtype = -1); + +/** @overload */ +CV_EXPORTS_W void divide(double scale, InputArray src2, + OutputArray dst, int dtype = -1); + +/** @brief Calculates the sum of a scaled array and another array. + +The function scaleAdd is one of the classical primitive linear algebra operations, known as DAXPY +or SAXPY in [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms). It calculates +the sum of a scaled array and another array: +\f[\texttt{dst} (I)= \texttt{scale} \cdot \texttt{src1} (I) + \texttt{src2} (I)\f] +The function can also be emulated with a matrix expression, for example: +@code{.cpp} + Mat A(3, 3, CV_64F); + ... + A.row(0) = A.row(1)*2 + A.row(2); +@endcode +@param src1 first input array. +@param alpha scale factor for the first array. +@param src2 second input array of the same size and type as src1. +@param dst output array of the same size and type as src1. +@sa add, addWeighted, subtract, Mat::dot, Mat::convertTo +*/ +CV_EXPORTS_W void scaleAdd(InputArray src1, double alpha, InputArray src2, OutputArray dst); + +/** @example samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp +Check @ref tutorial_trackbar "the corresponding tutorial" for more details +*/ + +/** @brief Calculates the weighted sum of two arrays. + +The function addWeighted calculates the weighted sum of two arrays as follows: +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f] +where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each +channel is processed independently. +The function can be replaced with a matrix expression: +@code{.cpp} + dst = src1*alpha + src2*beta + gamma; +@endcode +@note Saturation is not applied when the output array has the depth CV_32S. You may even get +result of an incorrect sign in the case of overflow. +@param src1 first input array. +@param alpha weight of the first array elements. +@param src2 second input array of the same size and channel number as src1. +@param beta weight of the second array elements. +@param gamma scalar added to each sum. +@param dst output array that has the same size and number of channels as the input arrays. +@param dtype optional depth of the output array; when both input arrays have the same depth, dtype +can be set to -1, which will be equivalent to src1.depth(). +@sa add, subtract, scaleAdd, Mat::convertTo +*/ +CV_EXPORTS_W void addWeighted(InputArray src1, double alpha, InputArray src2, + double beta, double gamma, OutputArray dst, int dtype = -1); + +/** @brief Scales, calculates absolute values, and converts the result to 8-bit. + +On each element of the input array, the function convertScaleAbs +performs three operations sequentially: scaling, taking an absolute +value, conversion to an unsigned 8-bit type: +\f[\texttt{dst} (I)= \texttt{saturate\_cast} (| \texttt{src} (I)* \texttt{alpha} + \texttt{beta} |)\f] +In case of multi-channel arrays, the function processes each channel +independently. When the output is not 8-bit, the operation can be +emulated by calling the Mat::convertTo method (or by using matrix +expressions) and then by calculating an absolute value of the result. +For example: +@code{.cpp} + Mat_ A(30,30); + randu(A, Scalar(-100), Scalar(100)); + Mat_ B = A*5 + 3; + B = abs(B); + // Mat_ B = abs(A*5+3) will also do the job, + // but it will allocate a temporary matrix +@endcode +@param src input array. +@param dst output array. +@param alpha optional scale factor. +@param beta optional delta added to the scaled values. +@sa Mat::convertTo, cv::abs(const Mat&) +*/ +CV_EXPORTS_W void convertScaleAbs(InputArray src, OutputArray dst, + double alpha = 1, double beta = 0); + +/** @brief Converts an array to half precision floating number. + +This function converts FP32 (single precision floating point) from/to FP16 (half precision floating point). CV_16S format is used to represent FP16 data. +There are two use modes (src -> dst): CV_32F -> CV_16S and CV_16S -> CV_32F. The input array has to have type of CV_32F or +CV_16S to represent the bit depth. If the input array is neither of them, the function will raise an error. +The format of half precision floating point is defined in IEEE 754-2008. + +@param src input array. +@param dst output array. +*/ +CV_EXPORTS_W void convertFp16(InputArray src, OutputArray dst); + +/** @brief Performs a look-up table transform of an array. + +The function LUT fills the output array with values from the look-up table. Indices of the entries +are taken from the input array. That is, the function processes each element of src as follows: +\f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I) + d)}\f] +where +\f[d = \fork{0}{if \(\texttt{src}\) has depth \(\texttt{CV_8U}\)}{128}{if \(\texttt{src}\) has depth \(\texttt{CV_8S}\)}\f] +@param src input array of 8-bit elements. +@param lut look-up table of 256 elements; in case of multi-channel input array, the table should +either have a single channel (in this case the same table is used for all channels) or the same +number of channels as in the input array. +@param dst output array of the same size and number of channels as src, and the same depth as lut. +@sa convertScaleAbs, Mat::convertTo +*/ +CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst); + +/** @brief Calculates the sum of array elements. + +The function cv::sum calculates and returns the sum of array elements, +independently for each channel. +@param src input array that must have from 1 to 4 channels. +@sa countNonZero, mean, meanStdDev, norm, minMaxLoc, reduce +*/ +CV_EXPORTS_AS(sumElems) Scalar sum(InputArray src); + +/** @brief Counts non-zero array elements. + +The function returns the number of non-zero elements in src : +\f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f] +@param src single-channel array. +@sa mean, meanStdDev, norm, minMaxLoc, calcCovarMatrix +*/ +CV_EXPORTS_W int countNonZero( InputArray src ); + +/** @brief Returns the list of locations of non-zero pixels + +Given a binary matrix (likely returned from an operation such +as threshold(), compare(), >, ==, etc, return all of +the non-zero indices as a cv::Mat or std::vector (x,y) +For example: +@code{.cpp} + cv::Mat binaryImage; // input, binary image + cv::Mat locations; // output, locations of non-zero pixels + cv::findNonZero(binaryImage, locations); + + // access pixel coordinates + Point pnt = locations.at(i); +@endcode +or +@code{.cpp} + cv::Mat binaryImage; // input, binary image + vector locations; // output, locations of non-zero pixels + cv::findNonZero(binaryImage, locations); + + // access pixel coordinates + Point pnt = locations[i]; +@endcode +@param src single-channel array +@param idx the output array, type of cv::Mat or std::vector, corresponding to non-zero indices in the input +*/ +CV_EXPORTS_W void findNonZero( InputArray src, OutputArray idx ); + +/** @brief Calculates an average (mean) of array elements. + +The function cv::mean calculates the mean value M of array elements, +independently for each channel, and return it: +\f[\begin{array}{l} N = \sum _{I: \; \texttt{mask} (I) \ne 0} 1 \\ M_c = \left ( \sum _{I: \; \texttt{mask} (I) \ne 0}{ \texttt{mtx} (I)_c} \right )/N \end{array}\f] +When all the mask elements are 0's, the function returns Scalar::all(0) +@param src input array that should have from 1 to 4 channels so that the result can be stored in +Scalar_ . +@param mask optional operation mask. +@sa countNonZero, meanStdDev, norm, minMaxLoc +*/ +CV_EXPORTS_W Scalar mean(InputArray src, InputArray mask = noArray()); + +/** Calculates a mean and standard deviation of array elements. + +The function cv::meanStdDev calculates the mean and the standard deviation M +of array elements independently for each channel and returns it via the +output parameters: +\f[\begin{array}{l} N = \sum _{I, \texttt{mask} (I) \ne 0} 1 \\ \texttt{mean} _c = \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c = \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c - \texttt{mean} _c \right )^2}{N}} \end{array}\f] +When all the mask elements are 0's, the function returns +mean=stddev=Scalar::all(0). +@note The calculated standard deviation is only the diagonal of the +complete normalized covariance matrix. If the full matrix is needed, you +can reshape the multi-channel array M x N to the single-channel array +M\*N x mtx.channels() (only possible when the matrix is continuous) and +then pass the matrix to calcCovarMatrix . +@param src input array that should have from 1 to 4 channels so that the results can be stored in +Scalar_ 's. +@param mean output parameter: calculated mean value. +@param stddev output parameter: calculated standard deviation. +@param mask optional operation mask. +@sa countNonZero, mean, norm, minMaxLoc, calcCovarMatrix +*/ +CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev, + InputArray mask=noArray()); + +/** @brief Calculates the absolute norm of an array. + +This version of #norm calculates the absolute norm of src1. The type of norm to calculate is specified using #NormTypes. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\ + \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\ + \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2 +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\ + \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\ + \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5. +\f} +The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$. +It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$. +![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png) + +When the mask parameter is specified and it is not empty, the norm is + +If normType is not specified, #NORM_L2 is used. +calculated only over the region specified by the mask. + +Multi-channel input arrays are treated as single-channel arrays, that is, +the results for all channels are combined. + +Hamming norms can only be calculated with CV_8U depth arrays. + +@param src1 first input array. +@param normType type of the norm (see #NormTypes). +@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type. +*/ +CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray()); + +/** @brief Calculates an absolute difference norm or a relative difference norm. + +This version of cv::norm calculates the absolute difference norm +or the relative difference norm of arrays src1 and src2. +The type of norm to calculate is specified using #NormTypes. + +@param src1 first input array. +@param src2 second input array of the same size and the same type as src1. +@param normType type of the norm (see #NormTypes). +@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type. +*/ +CV_EXPORTS_W double norm(InputArray src1, InputArray src2, + int normType = NORM_L2, InputArray mask = noArray()); +/** @overload +@param src first input array. +@param normType type of the norm (see #NormTypes). +*/ +CV_EXPORTS double norm( const SparseMat& src, int normType ); + +/** @brief Computes the Peak Signal-to-Noise Ratio (PSNR) image quality metric. + +This function calculates the Peak Signal-to-Noise Ratio (PSNR) image quality metric in decibels (dB), +between two input arrays src1 and src2. The arrays must have the same type. + +The PSNR is calculated as follows: + +\f[ +\texttt{PSNR} = 10 \cdot \log_{10}{\left( \frac{R^2}{MSE} \right) } +\f] + +where R is the maximum integer value of depth (e.g. 255 in the case of CV_8U data) +and MSE is the mean squared error between the two arrays. + +@param src1 first input array. +@param src2 second input array of the same size as src1. +@param R the maximum pixel value (255 by default) + + */ +CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2, double R=255.); + +/** @brief naive nearest neighbor finder + +see http://en.wikipedia.org/wiki/Nearest_neighbor_search +@todo document + */ +CV_EXPORTS_W void batchDistance(InputArray src1, InputArray src2, + OutputArray dist, int dtype, OutputArray nidx, + int normType = NORM_L2, int K = 0, + InputArray mask = noArray(), int update = 0, + bool crosscheck = false); + +/** @brief Normalizes the norm or value range of an array. + +The function cv::normalize normalizes scale and shift the input array elements so that +\f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f] +(where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that +\f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f] + +when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be +normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this +sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or +min-max but modify the whole array, you can use norm and Mat::convertTo. + +In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, +the range transformation for sparse matrices is not allowed since it can shift the zero level. + +Possible usage with some positive example data: +@code{.cpp} + vector positiveData = { 2.0, 8.0, 10.0 }; + vector normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax; + + // Norm to probability (total count) + // sum(numbers) = 20.0 + // 2.0 0.1 (2.0/20.0) + // 8.0 0.4 (8.0/20.0) + // 10.0 0.5 (10.0/20.0) + normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1); + + // Norm to unit vector: ||positiveData|| = 1.0 + // 2.0 0.15 + // 8.0 0.62 + // 10.0 0.77 + normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2); + + // Norm to max element + // 2.0 0.2 (2.0/10.0) + // 8.0 0.8 (8.0/10.0) + // 10.0 1.0 (10.0/10.0) + normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF); + + // Norm to range [0.0;1.0] + // 2.0 0.0 (shift to left border) + // 8.0 0.75 (6.0/8.0) + // 10.0 1.0 (shift to right border) + normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX); +@endcode + +@param src input array. +@param dst output array of the same size as src . +@param alpha norm value to normalize to or the lower range boundary in case of the range +normalization. +@param beta upper range boundary in case of the range normalization; it is not used for the norm +normalization. +@param norm_type normalization type (see cv::NormTypes). +@param dtype when negative, the output array has the same type as src; otherwise, it has the same +number of channels as src and the depth =CV_MAT_DEPTH(dtype). +@param mask optional operation mask. +@sa norm, Mat::convertTo, SparseMat::convertTo +*/ +CV_EXPORTS_W void normalize( InputArray src, InputOutputArray dst, double alpha = 1, double beta = 0, + int norm_type = NORM_L2, int dtype = -1, InputArray mask = noArray()); + +/** @overload +@param src input array. +@param dst output array of the same size as src . +@param alpha norm value to normalize to or the lower range boundary in case of the range +normalization. +@param normType normalization type (see cv::NormTypes). +*/ +CV_EXPORTS void normalize( const SparseMat& src, SparseMat& dst, double alpha, int normType ); + +/** @brief Finds the global minimum and maximum in an array. + +The function cv::minMaxLoc finds the minimum and maximum element values and their positions. The +extremums are searched across the whole array or, if mask is not an empty array, in the specified +array region. + +The function do not work with multi-channel arrays. If you need to find minimum or maximum +elements across all the channels, use Mat::reshape first to reinterpret the array as +single-channel. Or you may extract the particular channel using either extractImageCOI , or +mixChannels , or split . +@param src input single-channel array. +@param minVal pointer to the returned minimum value; NULL is used if not required. +@param maxVal pointer to the returned maximum value; NULL is used if not required. +@param minLoc pointer to the returned minimum location (in 2D case); NULL is used if not required. +@param maxLoc pointer to the returned maximum location (in 2D case); NULL is used if not required. +@param mask optional mask used to select a sub-array. +@sa max, min, compare, inRange, extractImageCOI, mixChannels, split, Mat::reshape +*/ +CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal, + CV_OUT double* maxVal = 0, CV_OUT Point* minLoc = 0, + CV_OUT Point* maxLoc = 0, InputArray mask = noArray()); + + +/** @brief Finds the global minimum and maximum in an array + +The function cv::minMaxIdx finds the minimum and maximum element values and their positions. The +extremums are searched across the whole array or, if mask is not an empty array, in the specified +array region. The function does not work with multi-channel arrays. If you need to find minimum or +maximum elements across all the channels, use Mat::reshape first to reinterpret the array as +single-channel. Or you may extract the particular channel using either extractImageCOI , or +mixChannels , or split . In case of a sparse matrix, the minimum is found among non-zero elements +only. +@note When minIdx is not NULL, it must have at least 2 elements (as well as maxIdx), even if src is +a single-row or single-column matrix. In OpenCV (following MATLAB) each array has at least 2 +dimensions, i.e. single-column matrix is Mx1 matrix (and therefore minIdx/maxIdx will be +(i1,0)/(i2,0)) and single-row matrix is 1xN matrix (and therefore minIdx/maxIdx will be +(0,j1)/(0,j2)). +@param src input single-channel array. +@param minVal pointer to the returned minimum value; NULL is used if not required. +@param maxVal pointer to the returned maximum value; NULL is used if not required. +@param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required; +Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element +in each dimension are stored there sequentially. +@param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required. +@param mask specified array region +*/ +CV_EXPORTS void minMaxIdx(InputArray src, double* minVal, double* maxVal = 0, + int* minIdx = 0, int* maxIdx = 0, InputArray mask = noArray()); + +/** @overload +@param a input single-channel array. +@param minVal pointer to the returned minimum value; NULL is used if not required. +@param maxVal pointer to the returned maximum value; NULL is used if not required. +@param minIdx pointer to the returned minimum location (in nD case); NULL is used if not required; +Otherwise, it must point to an array of src.dims elements, the coordinates of the minimum element +in each dimension are stored there sequentially. +@param maxIdx pointer to the returned maximum location (in nD case). NULL is used if not required. +*/ +CV_EXPORTS void minMaxLoc(const SparseMat& a, double* minVal, + double* maxVal, int* minIdx = 0, int* maxIdx = 0); + +/** @brief Reduces a matrix to a vector. + +The function #reduce reduces the matrix to a vector by treating the matrix rows/columns as a set of +1D vectors and performing the specified operation on the vectors until a single row/column is +obtained. For example, the function can be used to compute horizontal and vertical projections of a +raster image. In case of #REDUCE_MAX and #REDUCE_MIN , the output image should have the same type as the source one. +In case of #REDUCE_SUM and #REDUCE_AVG , the output may have a larger element bit-depth to preserve accuracy. +And multi-channel arrays are also supported in these two reduction modes. + +The following code demonstrates its usage for a single channel matrix. +@snippet snippets/core_reduce.cpp example + +And the following code demonstrates its usage for a two-channel matrix. +@snippet snippets/core_reduce.cpp example2 + +@param src input 2D matrix. +@param dst output vector. Its size and type is defined by dim and dtype parameters. +@param dim dimension index along which the matrix is reduced. 0 means that the matrix is reduced to +a single row. 1 means that the matrix is reduced to a single column. +@param rtype reduction operation that could be one of #ReduceTypes +@param dtype when negative, the output vector will have the same type as the input matrix, +otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()). +@sa repeat +*/ +CV_EXPORTS_W void reduce(InputArray src, OutputArray dst, int dim, int rtype, int dtype = -1); + +/** @brief Creates one multi-channel array out of several single-channel ones. + +The function cv::merge merges several arrays to make a single multi-channel array. That is, each +element of the output array will be a concatenation of the elements of the input arrays, where +elements of i-th input array are treated as mv[i].channels()-element vectors. + +The function cv::split does the reverse operation. If you need to shuffle channels in some other +advanced way, use cv::mixChannels. + +The following example shows how to merge 3 single channel matrices into a single 3-channel matrix. +@snippet snippets/core_merge.cpp example + +@param mv input array of matrices to be merged; all the matrices in mv must have the same +size and the same depth. +@param count number of input matrices when mv is a plain C array; it must be greater than zero. +@param dst output array of the same size and the same depth as mv[0]; The number of channels will +be equal to the parameter count. +@sa mixChannels, split, Mat::reshape +*/ +CV_EXPORTS void merge(const Mat* mv, size_t count, OutputArray dst); + +/** @overload +@param mv input vector of matrices to be merged; all the matrices in mv must have the same +size and the same depth. +@param dst output array of the same size and the same depth as mv[0]; The number of channels will +be the total number of channels in the matrix array. + */ +CV_EXPORTS_W void merge(InputArrayOfArrays mv, OutputArray dst); + +/** @brief Divides a multi-channel array into several single-channel arrays. + +The function cv::split splits a multi-channel array into separate single-channel arrays: +\f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f] +If you need to extract a single channel or do some other sophisticated channel permutation, use +mixChannels . + +The following example demonstrates how to split a 3-channel matrix into 3 single channel matrices. +@snippet snippets/core_split.cpp example + +@param src input multi-channel array. +@param mvbegin output array; the number of arrays must match src.channels(); the arrays themselves are +reallocated, if needed. +@sa merge, mixChannels, cvtColor +*/ +CV_EXPORTS void split(const Mat& src, Mat* mvbegin); + +/** @overload +@param m input multi-channel array. +@param mv output vector of arrays; the arrays themselves are reallocated, if needed. +*/ +CV_EXPORTS_W void split(InputArray m, OutputArrayOfArrays mv); + +/** @brief Copies specified channels from input arrays to the specified channels of +output arrays. + +The function cv::mixChannels provides an advanced mechanism for shuffling image channels. + +cv::split,cv::merge,cv::extractChannel,cv::insertChannel and some forms of cv::cvtColor are partial cases of cv::mixChannels. + +In the example below, the code splits a 4-channel BGRA image into a 3-channel BGR (with B and R +channels swapped) and a separate alpha-channel image: +@code{.cpp} + Mat bgra( 100, 100, CV_8UC4, Scalar(255,0,0,255) ); + Mat bgr( bgra.rows, bgra.cols, CV_8UC3 ); + Mat alpha( bgra.rows, bgra.cols, CV_8UC1 ); + + // forming an array of matrices is a quite efficient operation, + // because the matrix data is not copied, only the headers + Mat out[] = { bgr, alpha }; + // bgra[0] -> bgr[2], bgra[1] -> bgr[1], + // bgra[2] -> bgr[0], bgra[3] -> alpha[0] + int from_to[] = { 0,2, 1,1, 2,0, 3,3 }; + mixChannels( &bgra, 1, out, 2, from_to, 4 ); +@endcode +@note Unlike many other new-style C++ functions in OpenCV (see the introduction section and +Mat::create ), cv::mixChannels requires the output arrays to be pre-allocated before calling the +function. +@param src input array or vector of matrices; all of the matrices must have the same size and the +same depth. +@param nsrcs number of matrices in `src`. +@param dst output array or vector of matrices; all the matrices **must be allocated**; their size and +depth must be the same as in `src[0]`. +@param ndsts number of matrices in `dst`. +@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is +a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in +dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to +src[0].channels()-1, the second input image channels are indexed from src[0].channels() to +src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image +channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is +filled with zero . +@param npairs number of index pairs in `fromTo`. +@sa split, merge, extractChannel, insertChannel, cvtColor +*/ +CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, + const int* fromTo, size_t npairs); + +/** @overload +@param src input array or vector of matrices; all of the matrices must have the same size and the +same depth. +@param dst output array or vector of matrices; all the matrices **must be allocated**; their size and +depth must be the same as in src[0]. +@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is +a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in +dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to +src[0].channels()-1, the second input image channels are indexed from src[0].channels() to +src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image +channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is +filled with zero . +@param npairs number of index pairs in fromTo. +*/ +CV_EXPORTS void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst, + const int* fromTo, size_t npairs); + +/** @overload +@param src input array or vector of matrices; all of the matrices must have the same size and the +same depth. +@param dst output array or vector of matrices; all the matrices **must be allocated**; their size and +depth must be the same as in src[0]. +@param fromTo array of index pairs specifying which channels are copied and where; fromTo[k\*2] is +a 0-based index of the input channel in src, fromTo[k\*2+1] is an index of the output channel in +dst; the continuous channel numbering is used: the first input image channels are indexed from 0 to +src[0].channels()-1, the second input image channels are indexed from src[0].channels() to +src[0].channels() + src[1].channels()-1, and so on, the same scheme is used for the output image +channels; as a special case, when fromTo[k\*2] is negative, the corresponding output channel is +filled with zero . +*/ +CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst, + const std::vector& fromTo); + +/** @brief Extracts a single channel from src (coi is 0-based index) +@param src input array +@param dst output array +@param coi index of channel to extract +@sa mixChannels, split +*/ +CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi); + +/** @brief Inserts a single channel to dst (coi is 0-based index) +@param src input array +@param dst output array +@param coi index of channel for insertion +@sa mixChannels, merge +*/ +CV_EXPORTS_W void insertChannel(InputArray src, InputOutputArray dst, int coi); + +/** @brief Flips a 2D array around vertical, horizontal, or both axes. + +The function cv::flip flips the array in one of three different ways (row +and column indices are 0-based): +\f[\texttt{dst} _{ij} = +\left\{ +\begin{array}{l l} +\texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\ +\texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\ +\texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\ +\end{array} +\right.\f] +The example scenarios of using the function are the following: +* Vertical flipping of the image (flipCode == 0) to switch between + top-left and bottom-left image origin. This is a typical operation + in video processing on Microsoft Windows\* OS. +* Horizontal flipping of the image with the subsequent horizontal + shift and absolute difference calculation to check for a + vertical-axis symmetry (flipCode \> 0). +* Simultaneous horizontal and vertical flipping of the image with + the subsequent shift and absolute difference calculation to check + for a central symmetry (flipCode \< 0). +* Reversing the order of point arrays (flipCode \> 0 or + flipCode == 0). +@param src input array. +@param dst output array of the same size and type as src. +@param flipCode a flag to specify how to flip the array; 0 means +flipping around the x-axis and positive value (for example, 1) means +flipping around y-axis. Negative value (for example, -1) means flipping +around both axes. +@sa transpose , repeat , completeSymm +*/ +CV_EXPORTS_W void flip(InputArray src, OutputArray dst, int flipCode); + +enum RotateFlags { + ROTATE_90_CLOCKWISE = 0, //! A = (cv::Mat_(3, 2) << 1, 4, + 2, 5, + 3, 6); + cv::Mat_ B = (cv::Mat_(3, 2) << 7, 10, + 8, 11, + 9, 12); + + cv::Mat C; + cv::hconcat(A, B, C); + //C: + //[1, 4, 7, 10; + // 2, 5, 8, 11; + // 3, 6, 9, 12] + @endcode + @param src1 first input array to be considered for horizontal concatenation. + @param src2 second input array to be considered for horizontal concatenation. + @param dst output array. It has the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2. + */ +CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst); +/** @overload + @code{.cpp} + std::vector matrices = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)), + cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)), + cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),}; + + cv::Mat out; + cv::hconcat( matrices, out ); + //out: + //[1, 2, 3; + // 1, 2, 3; + // 1, 2, 3; + // 1, 2, 3] + @endcode + @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth. + @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src. +same depth. + */ +CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst); + +/** @brief Applies vertical concatenation to given matrices. + +The function vertically concatenates two or more cv::Mat matrices (with the same number of cols). +@code{.cpp} + cv::Mat matArray[] = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),}; + + cv::Mat out; + cv::vconcat( matArray, 3, out ); + //out: + //[1, 1, 1, 1; + // 2, 2, 2, 2; + // 3, 3, 3, 3] +@endcode +@param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth. +@param nsrc number of matrices in src. +@param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src. +@sa cv::hconcat(const Mat*, size_t, OutputArray), @sa cv::hconcat(InputArrayOfArrays, OutputArray) and @sa cv::hconcat(InputArray, InputArray, OutputArray) +*/ +CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst); +/** @overload + @code{.cpp} + cv::Mat_ A = (cv::Mat_(3, 2) << 1, 7, + 2, 8, + 3, 9); + cv::Mat_ B = (cv::Mat_(3, 2) << 4, 10, + 5, 11, + 6, 12); + + cv::Mat C; + cv::vconcat(A, B, C); + //C: + //[1, 7; + // 2, 8; + // 3, 9; + // 4, 10; + // 5, 11; + // 6, 12] + @endcode + @param src1 first input array to be considered for vertical concatenation. + @param src2 second input array to be considered for vertical concatenation. + @param dst output array. It has the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2. + */ +CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst); +/** @overload + @code{.cpp} + std::vector matrices = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)), + cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),}; + + cv::Mat out; + cv::vconcat( matrices, out ); + //out: + //[1, 1, 1, 1; + // 2, 2, 2, 2; + // 3, 3, 3, 3] + @endcode + @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth + @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src. +same depth. + */ +CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst); + +/** @brief computes bitwise conjunction of the two arrays (dst = src1 & src2) +Calculates the per-element bit-wise conjunction of two arrays or an +array and a scalar. + +The function cv::bitwise_and calculates the per-element bit-wise logical conjunction for: +* Two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +* An array and a scalar when src2 is constructed from Scalar or has + the same number of elements as `src1.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} \quad \texttt{if mask} (I) \ne0\f] +* A scalar and an array when src1 is constructed from Scalar or has + the same number of elements as `src2.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +In case of floating-point arrays, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel arrays, each channel is processed +independently. In the second and third cases above, the scalar is first +converted to the array type. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as the input +arrays. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, + OutputArray dst, InputArray mask = noArray()); + +/** @brief Calculates the per-element bit-wise disjunction of two arrays or an +array and a scalar. + +The function cv::bitwise_or calculates the per-element bit-wise logical disjunction for: +* Two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +* An array and a scalar when src2 is constructed from Scalar or has + the same number of elements as `src1.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} \quad \texttt{if mask} (I) \ne0\f] +* A scalar and an array when src1 is constructed from Scalar or has + the same number of elements as `src2.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +In case of floating-point arrays, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel arrays, each channel is processed +independently. In the second and third cases above, the scalar is first +converted to the array type. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as the input +arrays. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, + OutputArray dst, InputArray mask = noArray()); + +/** @brief Calculates the per-element bit-wise "exclusive or" operation on two +arrays or an array and a scalar. + +The function cv::bitwise_xor calculates the per-element bit-wise logical "exclusive-or" +operation for: +* Two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +* An array and a scalar when src2 is constructed from Scalar or has + the same number of elements as `src1.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} \quad \texttt{if mask} (I) \ne0\f] +* A scalar and an array when src1 is constructed from Scalar or has + the same number of elements as `src2.channels()`: + \f[\texttt{dst} (I) = \texttt{src1} \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0\f] +In case of floating-point arrays, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel arrays, each channel is processed +independently. In the 2nd and 3rd cases above, the scalar is first +converted to the array type. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as the input +arrays. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, + OutputArray dst, InputArray mask = noArray()); + +/** @brief Inverts every bit of an array. + +The function cv::bitwise_not calculates per-element bit-wise inversion of the input +array: +\f[\texttt{dst} (I) = \neg \texttt{src} (I)\f] +In case of a floating-point input array, its machine-specific bit +representation (usually IEEE754-compliant) is used for the operation. In +case of multi-channel arrays, each channel is processed independently. +@param src input array. +@param dst output array that has the same size and type as the input +array. +@param mask optional operation mask, 8-bit single channel array, that +specifies elements of the output array to be changed. +*/ +CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, + InputArray mask = noArray()); + +/** @brief Calculates the per-element absolute difference between two arrays or between an array and a scalar. + +The function cv::absdiff calculates: +* Absolute difference between two arrays when they have the same + size and type: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f] +* Absolute difference between an array and a scalar when the second + array is constructed from Scalar or has as many elements as the + number of channels in `src1`: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2} |)\f] +* Absolute difference between a scalar and an array when the first + array is constructed from Scalar or has as many elements as the + number of channels in `src2`: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1} - \texttt{src2}(I) |)\f] + where I is a multi-dimensional index of array elements. In case of + multi-channel arrays, each channel is processed independently. +@note Saturation is not applied when the arrays have the depth CV_32S. +You may even get a negative value in the case of overflow. +@param src1 first input array or a scalar. +@param src2 second input array or a scalar. +@param dst output array that has the same size and type as input arrays. +@sa cv::abs(const Mat&) +*/ +CV_EXPORTS_W void absdiff(InputArray src1, InputArray src2, OutputArray dst); + +/** @brief This is an overloaded member function, provided for convenience (python) +Copies the matrix to another one. +When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, the newly allocated matrix is initialized with all zeros before copying the data. +@param src source matrix. +@param dst Destination matrix. If it does not have a proper size or type before the operation, it is +reallocated. +@param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix +elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels. +*/ + +void CV_EXPORTS_W copyTo(InputArray src, OutputArray dst, InputArray mask); +/** @brief Checks if array elements lie between the elements of two other arrays. + +The function checks the range as follows: +- For every element of a single-channel input array: + \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0 \leq \texttt{src} (I)_0 \leq \texttt{upperb} (I)_0\f] +- For two-channel arrays: + \f[\texttt{dst} (I)= \texttt{lowerb} (I)_0 \leq \texttt{src} (I)_0 \leq \texttt{upperb} (I)_0 \land \texttt{lowerb} (I)_1 \leq \texttt{src} (I)_1 \leq \texttt{upperb} (I)_1\f] +- and so forth. + +That is, dst (I) is set to 255 (all 1 -bits) if src (I) is within the +specified 1D, 2D, 3D, ... box and 0 otherwise. + +When the lower and/or upper boundary parameters are scalars, the indexes +(I) at lowerb and upperb in the above formulas should be omitted. +@param src first input array. +@param lowerb inclusive lower boundary array or a scalar. +@param upperb inclusive upper boundary array or a scalar. +@param dst output array of the same size as src and CV_8U type. +*/ +CV_EXPORTS_W void inRange(InputArray src, InputArray lowerb, + InputArray upperb, OutputArray dst); + +/** @brief Performs the per-element comparison of two arrays or an array and scalar value. + +The function compares: +* Elements of two arrays when src1 and src2 have the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) \,\texttt{cmpop}\, \texttt{src2} (I)\f] +* Elements of src1 with a scalar src2 when src2 is constructed from + Scalar or has a single element: + \f[\texttt{dst} (I) = \texttt{src1}(I) \,\texttt{cmpop}\, \texttt{src2}\f] +* src1 with elements of src2 when src1 is constructed from Scalar or + has a single element: + \f[\texttt{dst} (I) = \texttt{src1} \,\texttt{cmpop}\, \texttt{src2} (I)\f] +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: +@code{.cpp} + Mat dst1 = src1 >= src2; + Mat dst2 = src1 < 8; + ... +@endcode +@param src1 first input array or a scalar; when it is an array, it must have a single channel. +@param src2 second input array or a scalar; when it is an array, it must have a single channel. +@param dst output array of type ref CV_8U that has the same size and the same number of channels as + the input arrays. +@param cmpop a flag, that specifies correspondence between the arrays (cv::CmpTypes) +@sa checkRange, min, max, threshold +*/ +CV_EXPORTS_W void compare(InputArray src1, InputArray src2, OutputArray dst, int cmpop); + +/** @brief Calculates per-element minimum of two arrays or an array and a scalar. + +The function cv::min calculates the per-element minimum of two arrays: +\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f] +or array and a scalar: +\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{value} )\f] +@param src1 first input array. +@param src2 second input array of the same size and type as src1. +@param dst output array of the same size and type as src1. +@sa max, compare, inRange, minMaxLoc +*/ +CV_EXPORTS_W void min(InputArray src1, InputArray src2, OutputArray dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void min(const UMat& src1, const UMat& src2, UMat& dst); + +/** @brief Calculates per-element maximum of two arrays or an array and a scalar. + +The function cv::max calculates the per-element maximum of two arrays: +\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f] +or array and a scalar: +\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{value} )\f] +@param src1 first input array. +@param src2 second input array of the same size and type as src1 . +@param dst output array of the same size and type as src1. +@sa min, compare, inRange, minMaxLoc, @ref MatrixExpressions +*/ +CV_EXPORTS_W void max(InputArray src1, InputArray src2, OutputArray dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst); +/** @overload +needed to avoid conflicts with const _Tp& std::min(const _Tp&, const _Tp&, _Compare) +*/ +CV_EXPORTS void max(const UMat& src1, const UMat& src2, UMat& dst); + +/** @brief Calculates a square root of array elements. + +The function cv::sqrt calculates a square root of each input array element. +In case of multi-channel arrays, each channel is processed +independently. The accuracy is approximately the same as of the built-in +std::sqrt . +@param src input floating-point array. +@param dst output array of the same size and type as src. +*/ +CV_EXPORTS_W void sqrt(InputArray src, OutputArray dst); + +/** @brief Raises every array element to a power. + +The function cv::pow raises every element of the input array to power : +\f[\texttt{dst} (I) = \fork{\texttt{src}(I)^{power}}{if \(\texttt{power}\) is integer}{|\texttt{src}(I)|^{power}}{otherwise}\f] + +So, for a non-integer power exponent, the absolute values of input array +elements are used. However, it is possible to get true values for +negative values using some extra operations. In the example below, +computing the 5th root of array src shows: +@code{.cpp} + Mat mask = src < 0; + pow(src, 1./5, dst); + subtract(Scalar::all(0), dst, dst, mask); +@endcode +For some values of power, such as integer values, 0.5 and -0.5, +specialized faster algorithms are used. + +Special values (NaN, Inf) are not handled. +@param src input array. +@param power exponent of power. +@param dst output array of the same size and type as src. +@sa sqrt, exp, log, cartToPolar, polarToCart +*/ +CV_EXPORTS_W void pow(InputArray src, double power, OutputArray dst); + +/** @brief Calculates the exponent of every array element. + +The function cv::exp calculates the exponent of every element of the input +array: +\f[\texttt{dst} [I] = e^{ src(I) }\f] + +The maximum relative error is about 7e-6 for single-precision input and +less than 1e-10 for double-precision input. Currently, the function +converts denormalized values to zeros on output. Special values (NaN, +Inf) are not handled. +@param src input array. +@param dst output array of the same size and type as src. +@sa log , cartToPolar , polarToCart , phase , pow , sqrt , magnitude +*/ +CV_EXPORTS_W void exp(InputArray src, OutputArray dst); + +/** @brief Calculates the natural logarithm of every array element. + +The function cv::log calculates the natural logarithm of every element of the input array: +\f[\texttt{dst} (I) = \log (\texttt{src}(I)) \f] + +Output on zero, negative and special (NaN, Inf) values is undefined. + +@param src input array. +@param dst output array of the same size and type as src . +@sa exp, cartToPolar, polarToCart, phase, pow, sqrt, magnitude +*/ +CV_EXPORTS_W void log(InputArray src, OutputArray dst); + +/** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle. + +The function cv::polarToCart calculates the Cartesian coordinates of each 2D +vector represented by the corresponding elements of magnitude and angle: +\f[\begin{array}{l} \texttt{x} (I) = \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) = \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f] + +The relative accuracy of the estimated coordinates is about 1e-6. +@param magnitude input floating-point array of magnitudes of 2D vectors; +it can be an empty matrix (=Mat()), in this case, the function assumes +that all the magnitudes are =1; if it is not empty, it must have the +same size and type as angle. +@param angle input floating-point array of angles of 2D vectors. +@param x output array of x-coordinates of 2D vectors; it has the same +size and type as angle. +@param y output array of y-coordinates of 2D vectors; it has the same +size and type as angle. +@param angleInDegrees when true, the input angles are measured in +degrees, otherwise, they are measured in radians. +@sa cartToPolar, magnitude, phase, exp, log, pow, sqrt +*/ +CV_EXPORTS_W void polarToCart(InputArray magnitude, InputArray angle, + OutputArray x, OutputArray y, bool angleInDegrees = false); + +/** @brief Calculates the magnitude and angle of 2D vectors. + +The function cv::cartToPolar calculates either the magnitude, angle, or both +for every 2D vector (x(I),y(I)): +\f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f] + +The angles are calculated with accuracy about 0.3 degrees. For the point +(0,0), the angle is set to 0. +@param x array of x-coordinates; this must be a single-precision or +double-precision floating-point array. +@param y array of y-coordinates, that must have the same size and same type as x. +@param magnitude output array of magnitudes of the same size and type as x. +@param angle output array of angles that has the same size and type as +x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees). +@param angleInDegrees a flag, indicating whether the angles are measured +in radians (which is by default), or in degrees. +@sa Sobel, Scharr +*/ +CV_EXPORTS_W void cartToPolar(InputArray x, InputArray y, + OutputArray magnitude, OutputArray angle, + bool angleInDegrees = false); + +/** @brief Calculates the rotation angle of 2D vectors. + +The function cv::phase calculates the rotation angle of each 2D vector that +is formed from the corresponding elements of x and y : +\f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f] + +The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 , +the corresponding angle(I) is set to 0. +@param x input floating-point array of x-coordinates of 2D vectors. +@param y input array of y-coordinates of 2D vectors; it must have the +same size and the same type as x. +@param angle output array of vector angles; it has the same size and +same type as x . +@param angleInDegrees when true, the function calculates the angle in +degrees, otherwise, they are measured in radians. +*/ +CV_EXPORTS_W void phase(InputArray x, InputArray y, OutputArray angle, + bool angleInDegrees = false); + +/** @brief Calculates the magnitude of 2D vectors. + +The function cv::magnitude calculates the magnitude of 2D vectors formed +from the corresponding elements of x and y arrays: +\f[\texttt{dst} (I) = \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2}\f] +@param x floating-point array of x-coordinates of the vectors. +@param y floating-point array of y-coordinates of the vectors; it must +have the same size as x. +@param magnitude output array of the same size and type as x. +@sa cartToPolar, polarToCart, phase, sqrt +*/ +CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude); + +/** @brief Checks every element of an input array for invalid values. + +The function cv::checkRange checks that every array element is neither NaN nor infinite. When minVal \> +-DBL_MAX and maxVal \< DBL_MAX, the function also checks that each value is between minVal and +maxVal. In case of multi-channel arrays, each channel is processed independently. If some values +are out of range, position of the first outlier is stored in pos (when pos != NULL). Then, the +function either returns false (when quiet=true) or throws an exception. +@param a input array. +@param quiet a flag, indicating whether the functions quietly return false when the array elements +are out of range or they throw an exception. +@param pos optional output parameter, when not NULL, must be a pointer to array of src.dims +elements. +@param minVal inclusive lower boundary of valid values range. +@param maxVal exclusive upper boundary of valid values range. +*/ +CV_EXPORTS_W bool checkRange(InputArray a, bool quiet = true, CV_OUT Point* pos = 0, + double minVal = -DBL_MAX, double maxVal = DBL_MAX); + +/** @brief converts NaN's to the given number +*/ +CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val = 0); + +/** @brief Performs generalized matrix multiplication. + +The function cv::gemm performs generalized matrix multiplication similar to the +gemm functions in BLAS level 3. For example, +`gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)` +corresponds to +\f[\texttt{dst} = \texttt{alpha} \cdot \texttt{src1} ^T \cdot \texttt{src2} + \texttt{beta} \cdot \texttt{src3} ^T\f] + +In case of complex (two-channel) data, performed a complex matrix +multiplication. + +The function can be replaced with a matrix expression. For example, the +above call can be replaced with: +@code{.cpp} + dst = alpha*src1.t()*src2 + beta*src3.t(); +@endcode +@param src1 first multiplied input matrix that could be real(CV_32FC1, +CV_64FC1) or complex(CV_32FC2, CV_64FC2). +@param src2 second multiplied input matrix of the same type as src1. +@param alpha weight of the matrix product. +@param src3 third optional delta matrix added to the matrix product; it +should have the same type as src1 and src2. +@param beta weight of src3. +@param dst output matrix; it has the proper size and the same type as +input matrices. +@param flags operation flags (cv::GemmFlags) +@sa mulTransposed , transform +*/ +CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha, + InputArray src3, double beta, OutputArray dst, int flags = 0); + +/** @brief Calculates the product of a matrix and its transposition. + +The function cv::mulTransposed calculates the product of src and its +transposition: +\f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} )^T ( \texttt{src} - \texttt{delta} )\f] +if aTa=true , and +\f[\texttt{dst} = \texttt{scale} ( \texttt{src} - \texttt{delta} ) ( \texttt{src} - \texttt{delta} )^T\f] +otherwise. The function is used to calculate the covariance matrix. With +zero delta, it can be used as a faster substitute for general matrix +product A\*B when B=A' +@param src input single-channel matrix. Note that unlike gemm, the +function can multiply not only floating-point matrices. +@param dst output square matrix. +@param aTa Flag specifying the multiplication ordering. See the +description below. +@param delta Optional delta matrix subtracted from src before the +multiplication. When the matrix is empty ( delta=noArray() ), it is +assumed to be zero, that is, nothing is subtracted. If it has the same +size as src , it is simply subtracted. Otherwise, it is "repeated" (see +repeat ) to cover the full src and then subtracted. Type of the delta +matrix, when it is not empty, must be the same as the type of created +output matrix. See the dtype parameter description below. +@param scale Optional scale factor for the matrix product. +@param dtype Optional type of the output matrix. When it is negative, +the output matrix will have the same type as src . Otherwise, it will be +type=CV_MAT_DEPTH(dtype) that should be either CV_32F or CV_64F . +@sa calcCovarMatrix, gemm, repeat, reduce +*/ +CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa, + InputArray delta = noArray(), + double scale = 1, int dtype = -1 ); + +/** @brief Transposes a matrix. + +The function cv::transpose transposes the matrix src : +\f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f] +@note No complex conjugation is done in case of a complex matrix. It +should be done separately if needed. +@param src input array. +@param dst output array of the same type as src. +*/ +CV_EXPORTS_W void transpose(InputArray src, OutputArray dst); + +/** @brief Performs the matrix transformation of every array element. + +The function cv::transform performs the matrix transformation of every +element of the array src and stores the results in dst : +\f[\texttt{dst} (I) = \texttt{m} \cdot \texttt{src} (I)\f] +(when m.cols=src.channels() ), or +\f[\texttt{dst} (I) = \texttt{m} \cdot [ \texttt{src} (I); 1]\f] +(when m.cols=src.channels()+1 ) + +Every element of the N -channel array src is interpreted as N -element +vector that is transformed using the M x N or M x (N+1) matrix m to +M-element vector - the corresponding element of the output array dst . + +The function may be used for geometrical transformation of +N -dimensional points, arbitrary linear color space transformation (such +as various kinds of RGB to YUV transforms), shuffling the image +channels, and so forth. +@param src input array that must have as many channels (1 to 4) as +m.cols or m.cols-1. +@param dst output array of the same size and depth as src; it has as +many channels as m.rows. +@param m transformation 2x2 or 2x3 floating-point matrix. +@sa perspectiveTransform, getAffineTransform, estimateAffine2D, warpAffine, warpPerspective +*/ +CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m ); + +/** @brief Performs the perspective matrix transformation of vectors. + +The function cv::perspectiveTransform transforms every element of src by +treating it as a 2D or 3D vector, in the following way: +\f[(x, y, z) \rightarrow (x'/w, y'/w, z'/w)\f] +where +\f[(x', y', z', w') = \texttt{mat} \cdot \begin{bmatrix} x & y & z & 1 \end{bmatrix}\f] +and +\f[w = \fork{w'}{if \(w' \ne 0\)}{\infty}{otherwise}\f] + +Here a 3D vector transformation is shown. In case of a 2D vector +transformation, the z component is omitted. + +@note The function transforms a sparse set of 2D or 3D vectors. If you +want to transform an image using perspective transformation, use +warpPerspective . If you have an inverse problem, that is, you want to +compute the most probable perspective transformation out of several +pairs of corresponding points, you can use getPerspectiveTransform or +findHomography . +@param src input two-channel or three-channel floating-point array; each +element is a 2D/3D vector to be transformed. +@param dst output array of the same size and type as src. +@param m 3x3 or 4x4 floating-point transformation matrix. +@sa transform, warpPerspective, getPerspectiveTransform, findHomography +*/ +CV_EXPORTS_W void perspectiveTransform(InputArray src, OutputArray dst, InputArray m ); + +/** @brief Copies the lower or the upper half of a square matrix to its another half. + +The function cv::completeSymm copies the lower or the upper half of a square matrix to +its another half. The matrix diagonal remains unchanged: + - \f$\texttt{m}_{ij}=\texttt{m}_{ji}\f$ for \f$i > j\f$ if + lowerToUpper=false + - \f$\texttt{m}_{ij}=\texttt{m}_{ji}\f$ for \f$i < j\f$ if + lowerToUpper=true + +@param m input-output floating-point square matrix. +@param lowerToUpper operation flag; if true, the lower half is copied to +the upper half. Otherwise, the upper half is copied to the lower half. +@sa flip, transpose +*/ +CV_EXPORTS_W void completeSymm(InputOutputArray m, bool lowerToUpper = false); + +/** @brief Initializes a scaled identity matrix. + +The function cv::setIdentity initializes a scaled identity matrix: +\f[\texttt{mtx} (i,j)= \fork{\texttt{value}}{ if \(i=j\)}{0}{otherwise}\f] + +The function can also be emulated using the matrix initializers and the +matrix expressions: +@code + Mat A = Mat::eye(4, 3, CV_32F)*5; + // A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]] +@endcode +@param mtx matrix to initialize (not necessarily square). +@param s value to assign to diagonal elements. +@sa Mat::zeros, Mat::ones, Mat::setTo, Mat::operator= +*/ +CV_EXPORTS_W void setIdentity(InputOutputArray mtx, const Scalar& s = Scalar(1)); + +/** @brief Returns the determinant of a square floating-point matrix. + +The function cv::determinant calculates and returns the determinant of the +specified matrix. For small matrices ( mtx.cols=mtx.rows\<=3 ), the +direct method is used. For larger matrices, the function uses LU +factorization with partial pivoting. + +For symmetric positively-determined matrices, it is also possible to use +eigen decomposition to calculate the determinant. +@param mtx input matrix that must have CV_32FC1 or CV_64FC1 type and +square size. +@sa trace, invert, solve, eigen, @ref MatrixExpressions +*/ +CV_EXPORTS_W double determinant(InputArray mtx); + +/** @brief Returns the trace of a matrix. + +The function cv::trace returns the sum of the diagonal elements of the +matrix mtx . +\f[\mathrm{tr} ( \texttt{mtx} ) = \sum _i \texttt{mtx} (i,i)\f] +@param mtx input matrix. +*/ +CV_EXPORTS_W Scalar trace(InputArray mtx); + +/** @brief Finds the inverse or pseudo-inverse of a matrix. + +The function cv::invert inverts the matrix src and stores the result in dst +. When the matrix src is singular or non-square, the function calculates +the pseudo-inverse matrix (the dst matrix) so that norm(src\*dst - I) is +minimal, where I is an identity matrix. + +In case of the #DECOMP_LU method, the function returns non-zero value if +the inverse has been successfully calculated and 0 if src is singular. + +In case of the #DECOMP_SVD method, the function returns the inverse +condition number of src (the ratio of the smallest singular value to the +largest singular value) and 0 if src is singular. The SVD method +calculates a pseudo-inverse matrix if src is singular. + +Similarly to #DECOMP_LU, the method #DECOMP_CHOLESKY works only with +non-singular square matrices that should also be symmetrical and +positively defined. In this case, the function stores the inverted +matrix in dst and returns non-zero. Otherwise, it returns 0. + +@param src input floating-point M x N matrix. +@param dst output matrix of N x M size and the same type as src. +@param flags inversion method (cv::DecompTypes) +@sa solve, SVD +*/ +CV_EXPORTS_W double invert(InputArray src, OutputArray dst, int flags = DECOMP_LU); + +/** @brief Solves one or more linear systems or least-squares problems. + +The function cv::solve solves a linear system or least-squares problem (the +latter is possible with SVD or QR methods, or by specifying the flag +#DECOMP_NORMAL ): +\f[\texttt{dst} = \arg \min _X \| \texttt{src1} \cdot \texttt{X} - \texttt{src2} \|\f] + +If #DECOMP_LU or #DECOMP_CHOLESKY method is used, the function returns 1 +if src1 (or \f$\texttt{src1}^T\texttt{src1}\f$ ) is non-singular. Otherwise, +it returns 0. In the latter case, dst is not valid. Other methods find a +pseudo-solution in case of a singular left-hand side part. + +@note If you want to find a unity-norm solution of an under-defined +singular system \f$\texttt{src1}\cdot\texttt{dst}=0\f$ , the function solve +will not do the work. Use SVD::solveZ instead. + +@param src1 input matrix on the left-hand side of the system. +@param src2 input matrix on the right-hand side of the system. +@param dst output solution. +@param flags solution (matrix inversion) method (#DecompTypes) +@sa invert, SVD, eigen +*/ +CV_EXPORTS_W bool solve(InputArray src1, InputArray src2, + OutputArray dst, int flags = DECOMP_LU); + +/** @brief Sorts each row or each column of a matrix. + +The function cv::sort sorts each matrix row or each matrix column in +ascending or descending order. So you should pass two operation flags to +get desired behaviour. If you want to sort matrix rows or columns +lexicographically, you can use STL std::sort generic function with the +proper comparison predicate. + +@param src input single-channel array. +@param dst output array of the same size and type as src. +@param flags operation flags, a combination of #SortFlags +@sa sortIdx, randShuffle +*/ +CV_EXPORTS_W void sort(InputArray src, OutputArray dst, int flags); + +/** @brief Sorts each row or each column of a matrix. + +The function cv::sortIdx sorts each matrix row or each matrix column in the +ascending or descending order. So you should pass two operation flags to +get desired behaviour. Instead of reordering the elements themselves, it +stores the indices of sorted elements in the output array. For example: +@code + Mat A = Mat::eye(3,3,CV_32F), B; + sortIdx(A, B, SORT_EVERY_ROW + SORT_ASCENDING); + // B will probably contain + // (because of equal elements in A some permutations are possible): + // [[1, 2, 0], [0, 2, 1], [0, 1, 2]] +@endcode +@param src input single-channel array. +@param dst output integer array of the same size as src. +@param flags operation flags that could be a combination of cv::SortFlags +@sa sort, randShuffle +*/ +CV_EXPORTS_W void sortIdx(InputArray src, OutputArray dst, int flags); + +/** @brief Finds the real roots of a cubic equation. + +The function solveCubic finds the real roots of a cubic equation: +- if coeffs is a 4-element vector: +\f[\texttt{coeffs} [0] x^3 + \texttt{coeffs} [1] x^2 + \texttt{coeffs} [2] x + \texttt{coeffs} [3] = 0\f] +- if coeffs is a 3-element vector: +\f[x^3 + \texttt{coeffs} [0] x^2 + \texttt{coeffs} [1] x + \texttt{coeffs} [2] = 0\f] + +The roots are stored in the roots array. +@param coeffs equation coefficients, an array of 3 or 4 elements. +@param roots output array of real roots that has 1 or 3 elements. +@return number of real roots. It can be 0, 1 or 2. +*/ +CV_EXPORTS_W int solveCubic(InputArray coeffs, OutputArray roots); + +/** @brief Finds the real or complex roots of a polynomial equation. + +The function cv::solvePoly finds real and complex roots of a polynomial equation: +\f[\texttt{coeffs} [n] x^{n} + \texttt{coeffs} [n-1] x^{n-1} + ... + \texttt{coeffs} [1] x + \texttt{coeffs} [0] = 0\f] +@param coeffs array of polynomial coefficients. +@param roots output (complex) array of roots. +@param maxIters maximum number of iterations the algorithm does. +*/ +CV_EXPORTS_W double solvePoly(InputArray coeffs, OutputArray roots, int maxIters = 300); + +/** @brief Calculates eigenvalues and eigenvectors of a symmetric matrix. + +The function cv::eigen calculates just eigenvalues, or eigenvalues and eigenvectors of the symmetric +matrix src: +@code + src*eigenvectors.row(i).t() = eigenvalues.at(i)*eigenvectors.row(i).t() +@endcode + +@note Use cv::eigenNonSymmetric for calculation of real eigenvalues and eigenvectors of non-symmetric matrix. + +@param src input matrix that must have CV_32FC1 or CV_64FC1 type, square size and be symmetrical +(src ^T^ == src). +@param eigenvalues output vector of eigenvalues of the same type as src; the eigenvalues are stored +in the descending order. +@param eigenvectors output matrix of eigenvectors; it has the same size and type as src; the +eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding +eigenvalues. +@sa eigenNonSymmetric, completeSymm , PCA +*/ +CV_EXPORTS_W bool eigen(InputArray src, OutputArray eigenvalues, + OutputArray eigenvectors = noArray()); + +/** @brief Calculates eigenvalues and eigenvectors of a non-symmetric matrix (real eigenvalues only). + +@note Assumes real eigenvalues. + +The function calculates eigenvalues and eigenvectors (optional) of the square matrix src: +@code + src*eigenvectors.row(i).t() = eigenvalues.at(i)*eigenvectors.row(i).t() +@endcode + +@param src input matrix (CV_32FC1 or CV_64FC1 type). +@param eigenvalues output vector of eigenvalues (type is the same type as src). +@param eigenvectors output matrix of eigenvectors (type is the same type as src). The eigenvectors are stored as subsequent matrix rows, in the same order as the corresponding eigenvalues. +@sa eigen +*/ +CV_EXPORTS_W void eigenNonSymmetric(InputArray src, OutputArray eigenvalues, + OutputArray eigenvectors); + +/** @brief Calculates the covariance matrix of a set of vectors. + +The function cv::calcCovarMatrix calculates the covariance matrix and, optionally, the mean vector of +the set of input vectors. +@param samples samples stored as separate matrices +@param nsamples number of samples +@param covar output covariance matrix of the type ctype and square size. +@param mean input or output (depending on the flags) array as the average value of the input vectors. +@param flags operation flags as a combination of #CovarFlags +@param ctype type of the matrixl; it equals 'CV_64F' by default. +@sa PCA, mulTransposed, Mahalanobis +@todo InputArrayOfArrays +*/ +CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean, + int flags, int ctype = CV_64F); + +/** @overload +@note use #COVAR_ROWS or #COVAR_COLS flag +@param samples samples stored as rows/columns of a single matrix. +@param covar output covariance matrix of the type ctype and square size. +@param mean input or output (depending on the flags) array as the average value of the input vectors. +@param flags operation flags as a combination of #CovarFlags +@param ctype type of the matrixl; it equals 'CV_64F' by default. +*/ +CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar, + InputOutputArray mean, int flags, int ctype = CV_64F); + +/** wrap PCA::operator() */ +CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, int maxComponents = 0); + +/** wrap PCA::operator() and add eigenvalues output parameter */ +CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + int maxComponents = 0); + +/** wrap PCA::operator() */ +CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, double retainedVariance); + +/** wrap PCA::operator() and add eigenvalues output parameter */ +CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + double retainedVariance); + +/** wrap PCA::project */ +CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean, + InputArray eigenvectors, OutputArray result); + +/** wrap PCA::backProject */ +CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean, + InputArray eigenvectors, OutputArray result); + +/** wrap SVD::compute */ +CV_EXPORTS_W void SVDecomp( InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags = 0 ); + +/** wrap SVD::backSubst */ +CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt, + InputArray rhs, OutputArray dst ); + +/** @brief Calculates the Mahalanobis distance between two vectors. + +The function cv::Mahalanobis calculates and returns the weighted distance between two vectors: +\f[d( \texttt{vec1} , \texttt{vec2} )= \sqrt{\sum_{i,j}{\texttt{icovar(i,j)}\cdot(\texttt{vec1}(I)-\texttt{vec2}(I))\cdot(\texttt{vec1(j)}-\texttt{vec2(j)})} }\f] +The covariance matrix may be calculated using the #calcCovarMatrix function and then inverted using +the invert function (preferably using the #DECOMP_SVD method, as the most accurate). +@param v1 first 1D input vector. +@param v2 second 1D input vector. +@param icovar inverse covariance matrix. +*/ +CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar); + +/** @brief Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array. + +The function cv::dft performs one of the following: +- Forward the Fourier transform of a 1D vector of N elements: + \f[Y = F^{(N)} \cdot X,\f] + where \f$F^{(N)}_{jk}=\exp(-2\pi i j k/N)\f$ and \f$i=\sqrt{-1}\f$ +- Inverse the Fourier transform of a 1D vector of N elements: + \f[\begin{array}{l} X'= \left (F^{(N)} \right )^{-1} \cdot Y = \left (F^{(N)} \right )^* \cdot y \\ X = (1/N) \cdot X, \end{array}\f] + where \f$F^*=\left(\textrm{Re}(F^{(N)})-\textrm{Im}(F^{(N)})\right)^T\f$ +- Forward the 2D Fourier transform of a M x N matrix: + \f[Y = F^{(M)} \cdot X \cdot F^{(N)}\f] +- Inverse the 2D Fourier transform of a M x N matrix: + \f[\begin{array}{l} X'= \left (F^{(M)} \right )^* \cdot Y \cdot \left (F^{(N)} \right )^* \\ X = \frac{1}{M \cdot N} \cdot X' \end{array}\f] + +In case of real (single-channel) data, the output spectrum of the forward Fourier transform or input +spectrum of the inverse Fourier transform can be represented in a packed format called *CCS* +(complex-conjugate-symmetrical). It was borrowed from IPL (Intel\* Image Processing Library). Here +is how 2D *CCS* spectrum looks: +\f[\begin{bmatrix} Re Y_{0,0} & Re Y_{0,1} & Im Y_{0,1} & Re Y_{0,2} & Im Y_{0,2} & \cdots & Re Y_{0,N/2-1} & Im Y_{0,N/2-1} & Re Y_{0,N/2} \\ Re Y_{1,0} & Re Y_{1,1} & Im Y_{1,1} & Re Y_{1,2} & Im Y_{1,2} & \cdots & Re Y_{1,N/2-1} & Im Y_{1,N/2-1} & Re Y_{1,N/2} \\ Im Y_{1,0} & Re Y_{2,1} & Im Y_{2,1} & Re Y_{2,2} & Im Y_{2,2} & \cdots & Re Y_{2,N/2-1} & Im Y_{2,N/2-1} & Im Y_{1,N/2} \\ \hdotsfor{9} \\ Re Y_{M/2-1,0} & Re Y_{M-3,1} & Im Y_{M-3,1} & \hdotsfor{3} & Re Y_{M-3,N/2-1} & Im Y_{M-3,N/2-1}& Re Y_{M/2-1,N/2} \\ Im Y_{M/2-1,0} & Re Y_{M-2,1} & Im Y_{M-2,1} & \hdotsfor{3} & Re Y_{M-2,N/2-1} & Im Y_{M-2,N/2-1}& Im Y_{M/2-1,N/2} \\ Re Y_{M/2,0} & Re Y_{M-1,1} & Im Y_{M-1,1} & \hdotsfor{3} & Re Y_{M-1,N/2-1} & Im Y_{M-1,N/2-1}& Re Y_{M/2,N/2} \end{bmatrix}\f] + +In case of 1D transform of a real vector, the output looks like the first row of the matrix above. + +So, the function chooses an operation mode depending on the flags and size of the input array: +- If #DFT_ROWS is set or the input array has a single row or single column, the function + performs a 1D forward or inverse transform of each row of a matrix when #DFT_ROWS is set. + Otherwise, it performs a 2D transform. +- If the input array is real and #DFT_INVERSE is not set, the function performs a forward 1D or + 2D transform: + - When #DFT_COMPLEX_OUTPUT is set, the output is a complex matrix of the same size as + input. + - When #DFT_COMPLEX_OUTPUT is not set, the output is a real matrix of the same size as + input. In case of 2D transform, it uses the packed format as shown above. In case of a + single 1D transform, it looks like the first row of the matrix above. In case of + multiple 1D transforms (when using the #DFT_ROWS flag), each row of the output matrix + looks like the first row of the matrix above. +- If the input array is complex and either #DFT_INVERSE or #DFT_REAL_OUTPUT are not set, the + output is a complex array of the same size as input. The function performs a forward or + inverse 1D or 2D transform of the whole input array or each row of the input array + independently, depending on the flags DFT_INVERSE and DFT_ROWS. +- When #DFT_INVERSE is set and the input array is real, or it is complex but #DFT_REAL_OUTPUT + is set, the output is a real array of the same size as input. The function performs a 1D or 2D + inverse transformation of the whole input array or each individual row, depending on the flags + #DFT_INVERSE and #DFT_ROWS. + +If #DFT_SCALE is set, the scaling is done after the transformation. + +Unlike dct , the function supports arrays of arbitrary size. But only those arrays are processed +efficiently, whose sizes can be factorized in a product of small prime numbers (2, 3, and 5 in the +current implementation). Such an efficient DFT size can be calculated using the getOptimalDFTSize +method. + +The sample below illustrates how to calculate a DFT-based convolution of two 2D real arrays: +@code + void convolveDFT(InputArray A, InputArray B, OutputArray C) + { + // reallocate the output array if needed + C.create(abs(A.rows - B.rows)+1, abs(A.cols - B.cols)+1, A.type()); + Size dftSize; + // calculate the size of DFT transform + dftSize.width = getOptimalDFTSize(A.cols + B.cols - 1); + dftSize.height = getOptimalDFTSize(A.rows + B.rows - 1); + + // allocate temporary buffers and initialize them with 0's + Mat tempA(dftSize, A.type(), Scalar::all(0)); + Mat tempB(dftSize, B.type(), Scalar::all(0)); + + // copy A and B to the top-left corners of tempA and tempB, respectively + Mat roiA(tempA, Rect(0,0,A.cols,A.rows)); + A.copyTo(roiA); + Mat roiB(tempB, Rect(0,0,B.cols,B.rows)); + B.copyTo(roiB); + + // now transform the padded A & B in-place; + // use "nonzeroRows" hint for faster processing + dft(tempA, tempA, 0, A.rows); + dft(tempB, tempB, 0, B.rows); + + // multiply the spectrums; + // the function handles packed spectrum representations well + mulSpectrums(tempA, tempB, tempA); + + // transform the product back from the frequency domain. + // Even though all the result rows will be non-zero, + // you need only the first C.rows of them, and thus you + // pass nonzeroRows == C.rows + dft(tempA, tempA, DFT_INVERSE + DFT_SCALE, C.rows); + + // now copy the result back to C. + tempA(Rect(0, 0, C.cols, C.rows)).copyTo(C); + + // all the temporary buffers will be deallocated automatically + } +@endcode +To optimize this sample, consider the following approaches: +- Since nonzeroRows != 0 is passed to the forward transform calls and since A and B are copied to + the top-left corners of tempA and tempB, respectively, it is not necessary to clear the whole + tempA and tempB. It is only necessary to clear the tempA.cols - A.cols ( tempB.cols - B.cols) + rightmost columns of the matrices. +- This DFT-based convolution does not have to be applied to the whole big arrays, especially if B + is significantly smaller than A or vice versa. Instead, you can calculate convolution by parts. + To do this, you need to split the output array C into multiple tiles. For each tile, estimate + which parts of A and B are required to calculate convolution in this tile. If the tiles in C are + too small, the speed will decrease a lot because of repeated work. In the ultimate case, when + each tile in C is a single pixel, the algorithm becomes equivalent to the naive convolution + algorithm. If the tiles are too big, the temporary arrays tempA and tempB become too big and + there is also a slowdown because of bad cache locality. So, there is an optimal tile size + somewhere in the middle. +- If different tiles in C can be calculated in parallel and, thus, the convolution is done by + parts, the loop can be threaded. + +All of the above improvements have been implemented in #matchTemplate and #filter2D . Therefore, by +using them, you can get the performance even better than with the above theoretically optimal +implementation. Though, those two functions actually calculate cross-correlation, not convolution, +so you need to "flip" the second convolution operand B vertically and horizontally using flip . +@note +- An example using the discrete fourier transform can be found at + opencv_source_code/samples/cpp/dft.cpp +- (Python) An example using the dft functionality to perform Wiener deconvolution can be found + at opencv_source/samples/python/deconvolution.py +- (Python) An example rearranging the quadrants of a Fourier image can be found at + opencv_source/samples/python/dft.py +@param src input array that could be real or complex. +@param dst output array whose size and type depends on the flags . +@param flags transformation flags, representing a combination of the #DftFlags +@param nonzeroRows when the parameter is not zero, the function assumes that only the first +nonzeroRows rows of the input array (#DFT_INVERSE is not set) or only the first nonzeroRows of the +output array (#DFT_INVERSE is set) contain non-zeros, thus, the function can handle the rest of the +rows more efficiently and save some time; this technique is very useful for calculating array +cross-correlation or convolution using DFT. +@sa dct , getOptimalDFTSize , mulSpectrums, filter2D , matchTemplate , flip , cartToPolar , +magnitude , phase +*/ +CV_EXPORTS_W void dft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0); + +/** @brief Calculates the inverse Discrete Fourier Transform of a 1D or 2D array. + +idft(src, dst, flags) is equivalent to dft(src, dst, flags | #DFT_INVERSE) . +@note None of dft and idft scales the result by default. So, you should pass #DFT_SCALE to one of +dft or idft explicitly to make these transforms mutually inverse. +@sa dft, dct, idct, mulSpectrums, getOptimalDFTSize +@param src input floating-point real or complex array. +@param dst output array whose size and type depend on the flags. +@param flags operation flags (see dft and #DftFlags). +@param nonzeroRows number of dst rows to process; the rest of the rows have undefined content (see +the convolution sample in dft description. +*/ +CV_EXPORTS_W void idft(InputArray src, OutputArray dst, int flags = 0, int nonzeroRows = 0); + +/** @brief Performs a forward or inverse discrete Cosine transform of 1D or 2D array. + +The function cv::dct performs a forward or inverse discrete Cosine transform (DCT) of a 1D or 2D +floating-point array: +- Forward Cosine transform of a 1D vector of N elements: + \f[Y = C^{(N)} \cdot X\f] + where + \f[C^{(N)}_{jk}= \sqrt{\alpha_j/N} \cos \left ( \frac{\pi(2k+1)j}{2N} \right )\f] + and + \f$\alpha_0=1\f$, \f$\alpha_j=2\f$ for *j \> 0*. +- Inverse Cosine transform of a 1D vector of N elements: + \f[X = \left (C^{(N)} \right )^{-1} \cdot Y = \left (C^{(N)} \right )^T \cdot Y\f] + (since \f$C^{(N)}\f$ is an orthogonal matrix, \f$C^{(N)} \cdot \left(C^{(N)}\right)^T = I\f$ ) +- Forward 2D Cosine transform of M x N matrix: + \f[Y = C^{(N)} \cdot X \cdot \left (C^{(N)} \right )^T\f] +- Inverse 2D Cosine transform of M x N matrix: + \f[X = \left (C^{(N)} \right )^T \cdot X \cdot C^{(N)}\f] + +The function chooses the mode of operation by looking at the flags and size of the input array: +- If (flags & #DCT_INVERSE) == 0 , the function does a forward 1D or 2D transform. Otherwise, it + is an inverse 1D or 2D transform. +- If (flags & #DCT_ROWS) != 0 , the function performs a 1D transform of each row. +- If the array is a single column or a single row, the function performs a 1D transform. +- If none of the above is true, the function performs a 2D transform. + +@note Currently dct supports even-size arrays (2, 4, 6 ...). For data analysis and approximation, you +can pad the array when necessary. +Also, the function performance depends very much, and not monotonically, on the array size (see +getOptimalDFTSize ). In the current implementation DCT of a vector of size N is calculated via DFT +of a vector of size N/2 . Thus, the optimal DCT size N1 \>= N can be calculated as: +@code + size_t getOptimalDCTSize(size_t N) { return 2*getOptimalDFTSize((N+1)/2); } + N1 = getOptimalDCTSize(N); +@endcode +@param src input floating-point array. +@param dst output array of the same size and type as src . +@param flags transformation flags as a combination of cv::DftFlags (DCT_*) +@sa dft , getOptimalDFTSize , idct +*/ +CV_EXPORTS_W void dct(InputArray src, OutputArray dst, int flags = 0); + +/** @brief Calculates the inverse Discrete Cosine Transform of a 1D or 2D array. + +idct(src, dst, flags) is equivalent to dct(src, dst, flags | DCT_INVERSE). +@param src input floating-point single-channel array. +@param dst output array of the same size and type as src. +@param flags operation flags. +@sa dct, dft, idft, getOptimalDFTSize +*/ +CV_EXPORTS_W void idct(InputArray src, OutputArray dst, int flags = 0); + +/** @brief Performs the per-element multiplication of two Fourier spectrums. + +The function cv::mulSpectrums performs the per-element multiplication of the two CCS-packed or complex +matrices that are results of a real or complex Fourier transform. + +The function, together with dft and idft , may be used to calculate convolution (pass conjB=false ) +or correlation (pass conjB=true ) of two arrays rapidly. When the arrays are complex, they are +simply multiplied (per element) with an optional conjugation of the second-array elements. When the +arrays are real, they are assumed to be CCS-packed (see dft for details). +@param a first input array. +@param b second input array of the same size and type as src1 . +@param c output array of the same size and type as src1 . +@param flags operation flags; currently, the only supported flag is cv::DFT_ROWS, which indicates that +each row of src1 and src2 is an independent 1D Fourier spectrum. If you do not want to use this flag, then simply add a `0` as value. +@param conjB optional flag that conjugates the second input array before the multiplication (true) +or not (false). +*/ +CV_EXPORTS_W void mulSpectrums(InputArray a, InputArray b, OutputArray c, + int flags, bool conjB = false); + +/** @brief Returns the optimal DFT size for a given vector size. + +DFT performance is not a monotonic function of a vector size. Therefore, when you calculate +convolution of two arrays or perform the spectral analysis of an array, it usually makes sense to +pad the input data with zeros to get a bit larger array that can be transformed much faster than the +original one. Arrays whose size is a power-of-two (2, 4, 8, 16, 32, ...) are the fastest to process. +Though, the arrays whose size is a product of 2's, 3's, and 5's (for example, 300 = 5\*5\*3\*2\*2) +are also processed quite efficiently. + +The function cv::getOptimalDFTSize returns the minimum number N that is greater than or equal to vecsize +so that the DFT of a vector of size N can be processed efficiently. In the current implementation N += 2 ^p^ \* 3 ^q^ \* 5 ^r^ for some integer p, q, r. + +The function returns a negative number if vecsize is too large (very close to INT_MAX ). + +While the function cannot be used directly to estimate the optimal vector size for DCT transform +(since the current DCT implementation supports only even-size vectors), it can be easily processed +as getOptimalDFTSize((vecsize+1)/2)\*2. +@param vecsize vector size. +@sa dft , dct , idft , idct , mulSpectrums +*/ +CV_EXPORTS_W int getOptimalDFTSize(int vecsize); + +/** @brief Returns the default random number generator. + +The function cv::theRNG returns the default random number generator. For each thread, there is a +separate random number generator, so you can use the function safely in multi-thread environments. +If you just need to get a single random number using this generator or initialize an array, you can +use randu or randn instead. But if you are going to generate many random numbers inside a loop, it +is much faster to use this function to retrieve the generator and then use RNG::operator _Tp() . +@sa RNG, randu, randn +*/ +CV_EXPORTS RNG& theRNG(); + +/** @brief Sets state of default random number generator. + +The function cv::setRNGSeed sets state of default random number generator to custom value. +@param seed new state for default random number generator +@sa RNG, randu, randn +*/ +CV_EXPORTS_W void setRNGSeed(int seed); + +/** @brief Generates a single uniformly-distributed random number or an array of random numbers. + +Non-template variant of the function fills the matrix dst with uniformly-distributed +random numbers from the specified range: +\f[\texttt{low} _c \leq \texttt{dst} (I)_c < \texttt{high} _c\f] +@param dst output array of random numbers; the array must be pre-allocated. +@param low inclusive lower boundary of the generated random numbers. +@param high exclusive upper boundary of the generated random numbers. +@sa RNG, randn, theRNG +*/ +CV_EXPORTS_W void randu(InputOutputArray dst, InputArray low, InputArray high); + +/** @brief Fills the array with normally distributed random numbers. + +The function cv::randn fills the matrix dst with normally distributed random numbers with the specified +mean vector and the standard deviation matrix. The generated random numbers are clipped to fit the +value range of the output array data type. +@param dst output array of random numbers; the array must be pre-allocated and have 1 to 4 channels. +@param mean mean value (expectation) of the generated random numbers. +@param stddev standard deviation of the generated random numbers; it can be either a vector (in +which case a diagonal standard deviation matrix is assumed) or a square matrix. +@sa RNG, randu +*/ +CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev); + +/** @brief Shuffles the array elements randomly. + +The function cv::randShuffle shuffles the specified 1D array by randomly choosing pairs of elements and +swapping them. The number of such swap operations will be dst.rows\*dst.cols\*iterFactor . +@param dst input/output numerical 1D array. +@param iterFactor scale factor that determines the number of random swap operations (see the details +below). +@param rng optional random number generator used for shuffling; if it is zero, theRNG () is used +instead. +@sa RNG, sort +*/ +CV_EXPORTS_W void randShuffle(InputOutputArray dst, double iterFactor = 1., RNG* rng = 0); + +/** @brief Principal Component Analysis + +The class is used to calculate a special basis for a set of vectors. The +basis will consist of eigenvectors of the covariance matrix calculated +from the input set of vectors. The class %PCA can also transform +vectors to/from the new coordinate space defined by the basis. Usually, +in this new coordinate system, each vector from the original set (and +any linear combination of such vectors) can be quite accurately +approximated by taking its first few components, corresponding to the +eigenvectors of the largest eigenvalues of the covariance matrix. +Geometrically it means that you calculate a projection of the vector to +a subspace formed by a few eigenvectors corresponding to the dominant +eigenvalues of the covariance matrix. And usually such a projection is +very close to the original vector. So, you can represent the original +vector from a high-dimensional space with a much shorter vector +consisting of the projected vector's coordinates in the subspace. Such a +transformation is also known as Karhunen-Loeve Transform, or KLT. +See http://en.wikipedia.org/wiki/Principal_component_analysis + +The sample below is the function that takes two matrices. The first +function stores a set of vectors (a row per vector) that is used to +calculate PCA. The second function stores another "test" set of vectors +(a row per vector). First, these vectors are compressed with PCA, then +reconstructed back, and then the reconstruction error norm is computed +and printed for each vector. : + +@code{.cpp} +using namespace cv; + +PCA compressPCA(const Mat& pcaset, int maxComponents, + const Mat& testset, Mat& compressed) +{ + PCA pca(pcaset, // pass the data + Mat(), // we do not have a pre-computed mean vector, + // so let the PCA engine to compute it + PCA::DATA_AS_ROW, // indicate that the vectors + // are stored as matrix rows + // (use PCA::DATA_AS_COL if the vectors are + // the matrix columns) + maxComponents // specify, how many principal components to retain + ); + // if there is no test data, just return the computed basis, ready-to-use + if( !testset.data ) + return pca; + CV_Assert( testset.cols == pcaset.cols ); + + compressed.create(testset.rows, maxComponents, testset.type()); + + Mat reconstructed; + for( int i = 0; i < testset.rows; i++ ) + { + Mat vec = testset.row(i), coeffs = compressed.row(i), reconstructed; + // compress the vector, the result will be stored + // in the i-th row of the output matrix + pca.project(vec, coeffs); + // and then reconstruct it + pca.backProject(coeffs, reconstructed); + // and measure the error + printf("%d. diff = %g\n", i, norm(vec, reconstructed, NORM_L2)); + } + return pca; +} +@endcode +@sa calcCovarMatrix, mulTransposed, SVD, dft, dct +*/ +class CV_EXPORTS PCA +{ +public: + enum Flags { DATA_AS_ROW = 0, //!< indicates that the input samples are stored as matrix rows + DATA_AS_COL = 1, //!< indicates that the input samples are stored as matrix columns + USE_AVG = 2 //! + }; + + /** @brief default constructor + + The default constructor initializes an empty %PCA structure. The other + constructors initialize the structure and call PCA::operator()(). + */ + PCA(); + + /** @overload + @param data input samples stored as matrix rows or matrix columns. + @param mean optional mean value; if the matrix is empty (@c noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout (PCA::Flags) + @param maxComponents maximum number of components that %PCA should + retain; by default, all the components are retained. + */ + PCA(InputArray data, InputArray mean, int flags, int maxComponents = 0); + + /** @overload + @param data input samples stored as matrix rows or matrix columns. + @param mean optional mean value; if the matrix is empty (noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout (PCA::Flags) + @param retainedVariance Percentage of variance that PCA should retain. + Using this parameter will let the PCA decided how many components to + retain but it will always keep at least 2. + */ + PCA(InputArray data, InputArray mean, int flags, double retainedVariance); + + /** @brief performs %PCA + + The operator performs %PCA of the supplied dataset. It is safe to reuse + the same PCA structure for multiple datasets. That is, if the structure + has been previously used with another dataset, the existing internal + data is reclaimed and the new @ref eigenvalues, @ref eigenvectors and @ref + mean are allocated and computed. + + The computed @ref eigenvalues are sorted from the largest to the smallest and + the corresponding @ref eigenvectors are stored as eigenvectors rows. + + @param data input samples stored as the matrix rows or as the matrix + columns. + @param mean optional mean value; if the matrix is empty (noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout. (Flags) + @param maxComponents maximum number of components that PCA should + retain; by default, all the components are retained. + */ + PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents = 0); + + /** @overload + @param data input samples stored as the matrix rows or as the matrix + columns. + @param mean optional mean value; if the matrix is empty (noArray()), + the mean is computed from the data. + @param flags operation flags; currently the parameter is only used to + specify the data layout. (PCA::Flags) + @param retainedVariance Percentage of variance that %PCA should retain. + Using this parameter will let the %PCA decided how many components to + retain but it will always keep at least 2. + */ + PCA& operator()(InputArray data, InputArray mean, int flags, double retainedVariance); + + /** @brief Projects vector(s) to the principal component subspace. + + The methods project one or more vectors to the principal component + subspace, where each vector projection is represented by coefficients in + the principal component basis. The first form of the method returns the + matrix that the second form writes to the result. So the first form can + be used as a part of expression while the second form can be more + efficient in a processing loop. + @param vec input vector(s); must have the same dimensionality and the + same layout as the input data used at %PCA phase, that is, if + DATA_AS_ROW are specified, then `vec.cols==data.cols` + (vector dimensionality) and `vec.rows` is the number of vectors to + project, and the same is true for the PCA::DATA_AS_COL case. + */ + Mat project(InputArray vec) const; + + /** @overload + @param vec input vector(s); must have the same dimensionality and the + same layout as the input data used at PCA phase, that is, if + DATA_AS_ROW are specified, then `vec.cols==data.cols` + (vector dimensionality) and `vec.rows` is the number of vectors to + project, and the same is true for the PCA::DATA_AS_COL case. + @param result output vectors; in case of PCA::DATA_AS_COL, the + output matrix has as many columns as the number of input vectors, this + means that `result.cols==vec.cols` and the number of rows match the + number of principal components (for example, `maxComponents` parameter + passed to the constructor). + */ + void project(InputArray vec, OutputArray result) const; + + /** @brief Reconstructs vectors from their PC projections. + + The methods are inverse operations to PCA::project. They take PC + coordinates of projected vectors and reconstruct the original vectors. + Unless all the principal components have been retained, the + reconstructed vectors are different from the originals. But typically, + the difference is small if the number of components is large enough (but + still much smaller than the original vector dimensionality). As a + result, PCA is used. + @param vec coordinates of the vectors in the principal component + subspace, the layout and size are the same as of PCA::project output + vectors. + */ + Mat backProject(InputArray vec) const; + + /** @overload + @param vec coordinates of the vectors in the principal component + subspace, the layout and size are the same as of PCA::project output + vectors. + @param result reconstructed vectors; the layout and size are the same as + of PCA::project input vectors. + */ + void backProject(InputArray vec, OutputArray result) const; + + /** @brief write PCA objects + + Writes @ref eigenvalues @ref eigenvectors and @ref mean to specified FileStorage + */ + void write(FileStorage& fs) const; + + /** @brief load PCA objects + + Loads @ref eigenvalues @ref eigenvectors and @ref mean from specified FileNode + */ + void read(const FileNode& fn); + + Mat eigenvectors; //!< eigenvectors of the covariation matrix + Mat eigenvalues; //!< eigenvalues of the covariation matrix + Mat mean; //!< mean value subtracted before the projection and added after the back projection +}; + +/** @example samples/cpp/pca.cpp +An example using %PCA for dimensionality reduction while maintaining an amount of variance +*/ + +/** @example samples/cpp/tutorial_code/ml/introduction_to_pca/introduction_to_pca.cpp +Check @ref tutorial_introduction_to_pca "the corresponding tutorial" for more details +*/ + +/** +@brief Linear Discriminant Analysis +@todo document this class +*/ +class CV_EXPORTS LDA +{ +public: + /** @brief constructor + Initializes a LDA with num_components (default 0). + */ + explicit LDA(int num_components = 0); + + /** Initializes and performs a Discriminant Analysis with Fisher's + Optimization Criterion on given data in src and corresponding labels + in labels. If 0 (or less) number of components are given, they are + automatically determined for given data in computation. + */ + LDA(InputArrayOfArrays src, InputArray labels, int num_components = 0); + + /** Serializes this object to a given filename. + */ + void save(const String& filename) const; + + /** Deserializes this object from a given filename. + */ + void load(const String& filename); + + /** Serializes this object to a given cv::FileStorage. + */ + void save(FileStorage& fs) const; + + /** Deserializes this object from a given cv::FileStorage. + */ + void load(const FileStorage& node); + + /** destructor + */ + ~LDA(); + + /** Compute the discriminants for data in src (row aligned) and labels. + */ + void compute(InputArrayOfArrays src, InputArray labels); + + /** Projects samples into the LDA subspace. + src may be one or more row aligned samples. + */ + Mat project(InputArray src); + + /** Reconstructs projections from the LDA subspace. + src may be one or more row aligned projections. + */ + Mat reconstruct(InputArray src); + + /** Returns the eigenvectors of this LDA. + */ + Mat eigenvectors() const { return _eigenvectors; } + + /** Returns the eigenvalues of this LDA. + */ + Mat eigenvalues() const { return _eigenvalues; } + + static Mat subspaceProject(InputArray W, InputArray mean, InputArray src); + static Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src); + +protected: + int _num_components; + Mat _eigenvectors; + Mat _eigenvalues; + void lda(InputArrayOfArrays src, InputArray labels); +}; + +/** @brief Singular Value Decomposition + +Class for computing Singular Value Decomposition of a floating-point +matrix. The Singular Value Decomposition is used to solve least-square +problems, under-determined linear systems, invert matrices, compute +condition numbers, and so on. + +If you want to compute a condition number of a matrix or an absolute value of +its determinant, you do not need `u` and `vt`. You can pass +flags=SVD::NO_UV|... . Another flag SVD::FULL_UV indicates that full-size u +and vt must be computed, which is not necessary most of the time. + +@sa invert, solve, eigen, determinant +*/ +class CV_EXPORTS SVD +{ +public: + enum Flags { + /** allow the algorithm to modify the decomposed matrix; it can save space and speed up + processing. currently ignored. */ + MODIFY_A = 1, + /** indicates that only a vector of singular values `w` is to be processed, while u and vt + will be set to empty matrices */ + NO_UV = 2, + /** when the matrix is not square, by default the algorithm produces u and vt matrices of + sufficiently large size for the further A reconstruction; if, however, FULL_UV flag is + specified, u and vt will be full-size square orthogonal matrices.*/ + FULL_UV = 4 + }; + + /** @brief the default constructor + + initializes an empty SVD structure + */ + SVD(); + + /** @overload + initializes an empty SVD structure and then calls SVD::operator() + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param flags operation flags (SVD::Flags) + */ + SVD( InputArray src, int flags = 0 ); + + /** @brief the operator that performs SVD. The previously allocated u, w and vt are released. + + The operator performs the singular value decomposition of the supplied + matrix. The u,`vt` , and the vector of singular values w are stored in + the structure. The same SVD structure can be reused many times with + different matrices. Each time, if needed, the previous u,`vt` , and w + are reclaimed and the new matrices are created, which is all handled by + Mat::create. + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param flags operation flags (SVD::Flags) + */ + SVD& operator ()( InputArray src, int flags = 0 ); + + /** @brief decomposes matrix and stores the results to user-provided matrices + + The methods/functions perform SVD of matrix. Unlike SVD::SVD constructor + and SVD::operator(), they store the results to the user-provided + matrices: + + @code{.cpp} + Mat A, w, u, vt; + SVD::compute(A, w, u, vt); + @endcode + + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param w calculated singular values + @param u calculated left singular vectors + @param vt transposed matrix of right singular vectors + @param flags operation flags - see SVD::Flags. + */ + static void compute( InputArray src, OutputArray w, + OutputArray u, OutputArray vt, int flags = 0 ); + + /** @overload + computes singular values of a matrix + @param src decomposed matrix. The depth has to be CV_32F or CV_64F. + @param w calculated singular values + @param flags operation flags - see SVD::Flags. + */ + static void compute( InputArray src, OutputArray w, int flags = 0 ); + + /** @brief performs back substitution + */ + static void backSubst( InputArray w, InputArray u, + InputArray vt, InputArray rhs, + OutputArray dst ); + + /** @brief solves an under-determined singular linear system + + The method finds a unit-length solution x of a singular linear system + A\*x = 0. Depending on the rank of A, there can be no solutions, a + single solution or an infinite number of solutions. In general, the + algorithm solves the following problem: + \f[dst = \arg \min _{x: \| x \| =1} \| src \cdot x \|\f] + @param src left-hand-side matrix. + @param dst found solution. + */ + static void solveZ( InputArray src, OutputArray dst ); + + /** @brief performs a singular value back substitution. + + The method calculates a back substitution for the specified right-hand + side: + + \f[\texttt{x} = \texttt{vt} ^T \cdot diag( \texttt{w} )^{-1} \cdot \texttt{u} ^T \cdot \texttt{rhs} \sim \texttt{A} ^{-1} \cdot \texttt{rhs}\f] + + Using this technique you can either get a very accurate solution of the + convenient linear system, or the best (in the least-squares terms) + pseudo-solution of an overdetermined linear system. + + @param rhs right-hand side of a linear system (u\*w\*v')\*dst = rhs to + be solved, where A has been previously decomposed. + + @param dst found solution of the system. + + @note Explicit SVD with the further back substitution only makes sense + if you need to solve many linear systems with the same left-hand side + (for example, src ). If all you need is to solve a single system + (possibly with multiple rhs immediately available), simply call solve + add pass #DECOMP_SVD there. It does absolutely the same thing. + */ + void backSubst( InputArray rhs, OutputArray dst ) const; + + /** @todo document */ + template static + void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt ); + + /** @todo document */ + template static + void compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w ); + + /** @todo document */ + template static + void backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u, const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, Matx<_Tp, n, nb>& dst ); + + Mat u, w, vt; +}; + +/** @brief Random Number Generator + +Random number generator. It encapsulates the state (currently, a 64-bit +integer) and has methods to return scalar random values and to fill +arrays with random values. Currently it supports uniform and Gaussian +(normal) distributions. The generator uses Multiply-With-Carry +algorithm, introduced by G. Marsaglia ( + ). +Gaussian-distribution random numbers are generated using the Ziggurat +algorithm ( ), +introduced by G. Marsaglia and W. W. Tsang. +*/ +class CV_EXPORTS RNG +{ +public: + enum { UNIFORM = 0, + NORMAL = 1 + }; + + /** @brief constructor + + These are the RNG constructors. The first form sets the state to some + pre-defined value, equal to 2\*\*32-1 in the current implementation. The + second form sets the state to the specified value. If you passed state=0 + , the constructor uses the above default value instead to avoid the + singular random number sequence, consisting of all zeros. + */ + RNG(); + /** @overload + @param state 64-bit value used to initialize the RNG. + */ + RNG(uint64 state); + /**The method updates the state using the MWC algorithm and returns the + next 32-bit random number.*/ + unsigned next(); + + /**Each of the methods updates the state using the MWC algorithm and + returns the next random number of the specified type. In case of integer + types, the returned number is from the available value range for the + specified type. In case of floating-point types, the returned value is + from [0,1) range. + */ + operator uchar(); + /** @overload */ + operator schar(); + /** @overload */ + operator ushort(); + /** @overload */ + operator short(); + /** @overload */ + operator unsigned(); + /** @overload */ + operator int(); + /** @overload */ + operator float(); + /** @overload */ + operator double(); + + /** @brief returns a random integer sampled uniformly from [0, N). + + The methods transform the state using the MWC algorithm and return the + next random number. The first form is equivalent to RNG::next . The + second form returns the random number modulo N , which means that the + result is in the range [0, N) . + */ + unsigned operator ()(); + /** @overload + @param N upper non-inclusive boundary of the returned random number. + */ + unsigned operator ()(unsigned N); + + /** @brief returns uniformly distributed integer random number from [a,b) range + + The methods transform the state using the MWC algorithm and return the + next uniformly-distributed random number of the specified type, deduced + from the input parameter type, from the range [a, b) . There is a nuance + illustrated by the following sample: + + @code{.cpp} + RNG rng; + + // always produces 0 + double a = rng.uniform(0, 1); + + // produces double from [0, 1) + double a1 = rng.uniform((double)0, (double)1); + + // produces float from [0, 1) + float b = rng.uniform(0.f, 1.f); + + // produces double from [0, 1) + double c = rng.uniform(0., 1.); + + // may cause compiler error because of ambiguity: + // RNG::uniform(0, (int)0.999999)? or RNG::uniform((double)0, 0.99999)? + double d = rng.uniform(0, 0.999999); + @endcode + + The compiler does not take into account the type of the variable to + which you assign the result of RNG::uniform . The only thing that + matters to the compiler is the type of a and b parameters. So, if you + want a floating-point random number, but the range boundaries are + integer numbers, either put dots in the end, if they are constants, or + use explicit type cast operators, as in the a1 initialization above. + @param a lower inclusive boundary of the returned random number. + @param b upper non-inclusive boundary of the returned random number. + */ + int uniform(int a, int b); + /** @overload */ + float uniform(float a, float b); + /** @overload */ + double uniform(double a, double b); + + /** @brief Fills arrays with random numbers. + + @param mat 2D or N-dimensional matrix; currently matrices with more than + 4 channels are not supported by the methods, use Mat::reshape as a + possible workaround. + @param distType distribution type, RNG::UNIFORM or RNG::NORMAL. + @param a first distribution parameter; in case of the uniform + distribution, this is an inclusive lower boundary, in case of the normal + distribution, this is a mean value. + @param b second distribution parameter; in case of the uniform + distribution, this is a non-inclusive upper boundary, in case of the + normal distribution, this is a standard deviation (diagonal of the + standard deviation matrix or the full standard deviation matrix). + @param saturateRange pre-saturation flag; for uniform distribution only; + if true, the method will first convert a and b to the acceptable value + range (according to the mat datatype) and then will generate uniformly + distributed random numbers within the range [saturate(a), saturate(b)), + if saturateRange=false, the method will generate uniformly distributed + random numbers in the original range [a, b) and then will saturate them, + it means, for example, that + theRNG().fill(mat_8u, RNG::UNIFORM, -DBL_MAX, DBL_MAX) will likely + produce array mostly filled with 0's and 255's, since the range (0, 255) + is significantly smaller than [-DBL_MAX, DBL_MAX). + + Each of the methods fills the matrix with the random values from the + specified distribution. As the new numbers are generated, the RNG state + is updated accordingly. In case of multiple-channel images, every + channel is filled independently, which means that RNG cannot generate + samples from the multi-dimensional Gaussian distribution with + non-diagonal covariance matrix directly. To do that, the method + generates samples from multi-dimensional standard Gaussian distribution + with zero mean and identity covariation matrix, and then transforms them + using transform to get samples from the specified Gaussian distribution. + */ + void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false ); + + /** @brief Returns the next random number sampled from the Gaussian distribution + @param sigma standard deviation of the distribution. + + The method transforms the state using the MWC algorithm and returns the + next random number from the Gaussian distribution N(0,sigma) . That is, + the mean value of the returned random numbers is zero and the standard + deviation is the specified sigma . + */ + double gaussian(double sigma); + + uint64 state; + + bool operator ==(const RNG& other) const; +}; + +/** @brief Mersenne Twister random number generator + +Inspired by http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c +@todo document +*/ +class CV_EXPORTS RNG_MT19937 +{ +public: + RNG_MT19937(); + RNG_MT19937(unsigned s); + void seed(unsigned s); + + unsigned next(); + + operator int(); + operator unsigned(); + operator float(); + operator double(); + + unsigned operator ()(unsigned N); + unsigned operator ()(); + + /** @brief returns uniformly distributed integer random number from [a,b) range*/ + int uniform(int a, int b); + /** @brief returns uniformly distributed floating-point random number from [a,b) range*/ + float uniform(float a, float b); + /** @brief returns uniformly distributed double-precision floating-point random number from [a,b) range*/ + double uniform(double a, double b); + +private: + enum PeriodParameters {N = 624, M = 397}; + unsigned state[N]; + int mti; +}; + +//! @} core_array + +//! @addtogroup core_cluster +//! @{ + +/** @example samples/cpp/kmeans.cpp +An example on K-means clustering +*/ + +/** @brief Finds centers of clusters and groups input samples around the clusters. + +The function kmeans implements a k-means algorithm that finds the centers of cluster_count clusters +and groups the input samples around the clusters. As an output, \f$\texttt{bestLabels}_i\f$ contains a +0-based cluster index for the sample stored in the \f$i^{th}\f$ row of the samples matrix. + +@note +- (Python) An example on K-means clustering can be found at + opencv_source_code/samples/python/kmeans.py +@param data Data for clustering. An array of N-Dimensional points with float coordinates is needed. +Examples of this array can be: +- Mat points(count, 2, CV_32F); +- Mat points(count, 1, CV_32FC2); +- Mat points(1, count, CV_32FC2); +- std::vector\ points(sampleCount); +@param K Number of clusters to split the set by. +@param bestLabels Input/output integer array that stores the cluster indices for every sample. +@param criteria The algorithm termination criteria, that is, the maximum number of iterations and/or +the desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of the cluster +centers moves by less than criteria.epsilon on some iteration, the algorithm stops. +@param attempts Flag to specify the number of times the algorithm is executed using different +initial labellings. The algorithm returns the labels that yield the best compactness (see the last +function parameter). +@param flags Flag that can take values of cv::KmeansFlags +@param centers Output matrix of the cluster centers, one row per each cluster center. +@return The function returns the compactness measure that is computed as +\f[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\f] +after every attempt. The best (minimum) value is chosen and the corresponding labels and the +compactness value are returned by the function. Basically, you can use only the core of the +function, set the number of attempts to 1, initialize labels each time using a custom algorithm, +pass them with the ( flags = #KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best +(most-compact) clustering. +*/ +CV_EXPORTS_W double kmeans( InputArray data, int K, InputOutputArray bestLabels, + TermCriteria criteria, int attempts, + int flags, OutputArray centers = noArray() ); + +//! @} core_cluster + +//! @addtogroup core_basic +//! @{ + +/////////////////////////////// Formatted output of cv::Mat /////////////////////////// + +/** @todo document */ +class CV_EXPORTS Formatted +{ +public: + virtual const char* next() = 0; + virtual void reset() = 0; + virtual ~Formatted(); +}; + +/** @todo document */ +class CV_EXPORTS Formatter +{ +public: + enum FormatType { + FMT_DEFAULT = 0, + FMT_MATLAB = 1, + FMT_CSV = 2, + FMT_PYTHON = 3, + FMT_NUMPY = 4, + FMT_C = 5 + }; + + virtual ~Formatter(); + + virtual Ptr format(const Mat& mtx) const = 0; + + virtual void set16fPrecision(int p = 4) = 0; + virtual void set32fPrecision(int p = 8) = 0; + virtual void set64fPrecision(int p = 16) = 0; + virtual void setMultiline(bool ml = true) = 0; + + static Ptr get(Formatter::FormatType fmt = FMT_DEFAULT); + +}; + +static inline +String& operator << (String& out, Ptr fmtd) +{ + fmtd->reset(); + for(const char* str = fmtd->next(); str; str = fmtd->next()) + out += cv::String(str); + return out; +} + +static inline +String& operator << (String& out, const Mat& mtx) +{ + return out << Formatter::get()->format(mtx); +} + +//////////////////////////////////////// Algorithm //////////////////////////////////// + +class CV_EXPORTS Algorithm; + +template struct ParamType {}; + + +/** @brief This is a base class for all more or less complex algorithms in OpenCV + +especially for classes of algorithms, for which there can be multiple implementations. The examples +are stereo correspondence (for which there are algorithms like block matching, semi-global block +matching, graph-cut etc.), background subtraction (which can be done using mixture-of-gaussians +models, codebook-based algorithm etc.), optical flow (block matching, Lucas-Kanade, Horn-Schunck +etc.). + +Here is example of SimpleBlobDetector use in your application via Algorithm interface: +@snippet snippets/core_various.cpp Algorithm +*/ +class CV_EXPORTS_W Algorithm +{ +public: + Algorithm(); + virtual ~Algorithm(); + + /** @brief Clears the algorithm state + */ + CV_WRAP virtual void clear() {} + + /** @brief Stores algorithm parameters in a file storage + */ + virtual void write(FileStorage& fs) const { CV_UNUSED(fs); } + + /** @brief simplified API for language bindings + * @overload + */ + CV_WRAP void write(const Ptr& fs, const String& name = String()) const; + + /** @brief Reads algorithm parameters from a file storage + */ + CV_WRAP virtual void read(const FileNode& fn) { CV_UNUSED(fn); } + + /** @brief Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read + */ + CV_WRAP virtual bool empty() const { return false; } + + /** @brief Reads algorithm from the file node + + This is static template method of Algorithm. It's usage is following (in the case of SVM): + @code + cv::FileStorage fsRead("example.xml", FileStorage::READ); + Ptr svm = Algorithm::read(fsRead.root()); + @endcode + In order to make this method work, the derived class must overwrite Algorithm::read(const + FileNode& fn) and also have static create() method without parameters + (or with all the optional parameters) + */ + template static Ptr<_Tp> read(const FileNode& fn) + { + Ptr<_Tp> obj = _Tp::create(); + obj->read(fn); + return !obj->empty() ? obj : Ptr<_Tp>(); + } + + /** @brief Loads algorithm from the file + + @param filename Name of the file to read. + @param objname The optional name of the node to read (if empty, the first top-level node will be used) + + This is static template method of Algorithm. It's usage is following (in the case of SVM): + @code + Ptr svm = Algorithm::load("my_svm_model.xml"); + @endcode + In order to make this method work, the derived class must overwrite Algorithm::read(const + FileNode& fn). + */ + template static Ptr<_Tp> load(const String& filename, const String& objname=String()) + { + FileStorage fs(filename, FileStorage::READ); + CV_Assert(fs.isOpened()); + FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]; + if (fn.empty()) return Ptr<_Tp>(); + Ptr<_Tp> obj = _Tp::create(); + obj->read(fn); + return !obj->empty() ? obj : Ptr<_Tp>(); + } + + /** @brief Loads algorithm from a String + + @param strModel The string variable containing the model you want to load. + @param objname The optional name of the node to read (if empty, the first top-level node will be used) + + This is static template method of Algorithm. It's usage is following (in the case of SVM): + @code + Ptr svm = Algorithm::loadFromString(myStringModel); + @endcode + */ + template static Ptr<_Tp> loadFromString(const String& strModel, const String& objname=String()) + { + FileStorage fs(strModel, FileStorage::READ + FileStorage::MEMORY); + FileNode fn = objname.empty() ? fs.getFirstTopLevelNode() : fs[objname]; + Ptr<_Tp> obj = _Tp::create(); + obj->read(fn); + return !obj->empty() ? obj : Ptr<_Tp>(); + } + + /** Saves the algorithm to a file. + In order to make this method work, the derived class must implement Algorithm::write(FileStorage& fs). */ + CV_WRAP virtual void save(const String& filename) const; + + /** Returns the algorithm string identifier. + This string is used as top level xml/yml node tag when the object is saved to a file or string. */ + CV_WRAP virtual String getDefaultName() const; + +protected: + void writeFormat(FileStorage& fs) const; +}; + +enum struct Param { + INT=0, BOOLEAN=1, REAL=2, STRING=3, MAT=4, MAT_VECTOR=5, ALGORITHM=6, FLOAT=7, + UNSIGNED_INT=8, UINT64=9, UCHAR=11, SCALAR=12 +}; + + + +template<> struct ParamType +{ + typedef bool const_param_type; + typedef bool member_type; + + static const Param type = Param::BOOLEAN; +}; + +template<> struct ParamType +{ + typedef int const_param_type; + typedef int member_type; + + static const Param type = Param::INT; +}; + +template<> struct ParamType +{ + typedef double const_param_type; + typedef double member_type; + + static const Param type = Param::REAL; +}; + +template<> struct ParamType +{ + typedef const String& const_param_type; + typedef String member_type; + + static const Param type = Param::STRING; +}; + +template<> struct ParamType +{ + typedef const Mat& const_param_type; + typedef Mat member_type; + + static const Param type = Param::MAT; +}; + +template<> struct ParamType > +{ + typedef const std::vector& const_param_type; + typedef std::vector member_type; + + static const Param type = Param::MAT_VECTOR; +}; + +template<> struct ParamType +{ + typedef const Ptr& const_param_type; + typedef Ptr member_type; + + static const Param type = Param::ALGORITHM; +}; + +template<> struct ParamType +{ + typedef float const_param_type; + typedef float member_type; + + static const Param type = Param::FLOAT; +}; + +template<> struct ParamType +{ + typedef unsigned const_param_type; + typedef unsigned member_type; + + static const Param type = Param::UNSIGNED_INT; +}; + +template<> struct ParamType +{ + typedef uint64 const_param_type; + typedef uint64 member_type; + + static const Param type = Param::UINT64; +}; + +template<> struct ParamType +{ + typedef uchar const_param_type; + typedef uchar member_type; + + static const Param type = Param::UCHAR; +}; + +template<> struct ParamType +{ + typedef const Scalar& const_param_type; + typedef Scalar member_type; + + static const Param type = Param::SCALAR; +}; + +template +struct ParamType<_Tp, typename std::enable_if< std::is_enum<_Tp>::value >::type> +{ + typedef typename std::underlying_type<_Tp>::type const_param_type; + typedef typename std::underlying_type<_Tp>::type member_type; + + static const Param type = Param::INT; +}; + +//! @} core_basic + +} //namespace cv + +#include "opencv2/core/operations.hpp" +#include "opencv2/core/cvstd.inl.hpp" +#include "opencv2/core/utility.hpp" +#include "opencv2/core/optim.hpp" +#include "opencv2/core/ovx.hpp" + +#endif /*OPENCV_CORE_HPP*/ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/affine.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/affine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7e2ed307858323ffbb4fa95c7c1275b9932c0574 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/affine.hpp @@ -0,0 +1,678 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_AFFINE3_HPP +#define OPENCV_CORE_AFFINE3_HPP + +#ifdef __cplusplus + +#include + +namespace cv +{ + +//! @addtogroup core +//! @{ + + /** @brief Affine transform + * + * It represents a 4x4 homogeneous transformation matrix \f$T\f$ + * + * \f[T = + * \begin{bmatrix} + * R & t\\ + * 0 & 1\\ + * \end{bmatrix} + * \f] + * + * where \f$R\f$ is a 3x3 rotation matrix and \f$t\f$ is a 3x1 translation vector. + * + * You can specify \f$R\f$ either by a 3x3 rotation matrix or by a 3x1 rotation vector, + * which is converted to a 3x3 rotation matrix by the Rodrigues formula. + * + * To construct a matrix \f$T\f$ representing first rotation around the axis \f$r\f$ with rotation + * angle \f$|r|\f$ in radian (right hand rule) and then translation by the vector \f$t\f$, you can use + * + * @code + * cv::Vec3f r, t; + * cv::Affine3f T(r, t); + * @endcode + * + * If you already have the rotation matrix \f$R\f$, then you can use + * + * @code + * cv::Matx33f R; + * cv::Affine3f T(R, t); + * @endcode + * + * To extract the rotation matrix \f$R\f$ from \f$T\f$, use + * + * @code + * cv::Matx33f R = T.rotation(); + * @endcode + * + * To extract the translation vector \f$t\f$ from \f$T\f$, use + * + * @code + * cv::Vec3f t = T.translation(); + * @endcode + * + * To extract the rotation vector \f$r\f$ from \f$T\f$, use + * + * @code + * cv::Vec3f r = T.rvec(); + * @endcode + * + * Note that since the mapping from rotation vectors to rotation matrices + * is many to one. The returned rotation vector is not necessarily the one + * you used before to set the matrix. + * + * If you have two transformations \f$T = T_1 * T_2\f$, use + * + * @code + * cv::Affine3f T, T1, T2; + * T = T2.concatenate(T1); + * @endcode + * + * To get the inverse transform of \f$T\f$, use + * + * @code + * cv::Affine3f T, T_inv; + * T_inv = T.inv(); + * @endcode + * + */ + template + class Affine3 + { + public: + typedef T float_type; + typedef Matx Mat3; + typedef Matx Mat4; + typedef Vec Vec3; + + //! Default constructor. It represents a 4x4 identity matrix. + Affine3(); + + //! Augmented affine matrix + Affine3(const Mat4& affine); + + /** + * The resulting 4x4 matrix is + * + * \f[ + * \begin{bmatrix} + * R & t\\ + * 0 & 1\\ + * \end{bmatrix} + * \f] + * + * @param R 3x3 rotation matrix. + * @param t 3x1 translation vector. + */ + Affine3(const Mat3& R, const Vec3& t = Vec3::all(0)); + + /** + * Rodrigues vector. + * + * The last row of the current matrix is set to [0,0,0,1]. + * + * @param rvec 3x1 rotation vector. Its direction indicates the rotation axis and its length + * indicates the rotation angle in radian (using right hand rule). + * @param t 3x1 translation vector. + */ + Affine3(const Vec3& rvec, const Vec3& t = Vec3::all(0)); + + /** + * Combines all constructors above. Supports 4x4, 3x4, 3x3, 1x3, 3x1 sizes of data matrix. + * + * The last row of the current matrix is set to [0,0,0,1] when data is not 4x4. + * + * @param data 1-channel matrix. + * when it is 4x4, it is copied to the current matrix and t is not used. + * When it is 3x4, it is copied to the upper part 3x4 of the current matrix and t is not used. + * When it is 3x3, it is copied to the upper left 3x3 part of the current matrix. + * When it is 3x1 or 1x3, it is treated as a rotation vector and the Rodrigues formula is used + * to compute a 3x3 rotation matrix. + * @param t 3x1 translation vector. It is used only when data is neither 4x4 nor 3x4. + */ + explicit Affine3(const Mat& data, const Vec3& t = Vec3::all(0)); + + //! From 16-element array + explicit Affine3(const float_type* vals); + + //! Create an 4x4 identity transform + static Affine3 Identity(); + + /** + * Rotation matrix. + * + * Copy the rotation matrix to the upper left 3x3 part of the current matrix. + * The remaining elements of the current matrix are not changed. + * + * @param R 3x3 rotation matrix. + * + */ + void rotation(const Mat3& R); + + /** + * Rodrigues vector. + * + * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected. + * + * @param rvec 3x1 rotation vector. The direction indicates the rotation axis and + * its length indicates the rotation angle in radian (using the right thumb convention). + */ + void rotation(const Vec3& rvec); + + /** + * Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix. + * + * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected. + * + * @param data 1-channel matrix. + * When it is a 3x3 matrix, it sets the upper left 3x3 part of the current matrix. + * When it is a 1x3 or 3x1 matrix, it is used as a rotation vector. The Rodrigues formula + * is used to compute the rotation matrix and sets the upper left 3x3 part of the current matrix. + */ + void rotation(const Mat& data); + + /** + * Copy the 3x3 matrix L to the upper left part of the current matrix + * + * It sets the upper left 3x3 part of the matrix. The remaining part is unaffected. + * + * @param L 3x3 matrix. + */ + void linear(const Mat3& L); + + /** + * Copy t to the first three elements of the last column of the current matrix + * + * It sets the upper right 3x1 part of the matrix. The remaining part is unaffected. + * + * @param t 3x1 translation vector. + */ + void translation(const Vec3& t); + + //! @return the upper left 3x3 part + Mat3 rotation() const; + + //! @return the upper left 3x3 part + Mat3 linear() const; + + //! @return the upper right 3x1 part + Vec3 translation() const; + + //! Rodrigues vector. + //! @return a vector representing the upper left 3x3 rotation matrix of the current matrix. + //! @warning Since the mapping between rotation vectors and rotation matrices is many to one, + //! this function returns only one rotation vector that represents the current rotation matrix, + //! which is not necessarily the same one set by `rotation(const Vec3& rvec)`. + Vec3 rvec() const; + + //! @return the inverse of the current matrix. + Affine3 inv(int method = cv::DECOMP_SVD) const; + + //! a.rotate(R) is equivalent to Affine(R, 0) * a; + Affine3 rotate(const Mat3& R) const; + + //! a.rotate(rvec) is equivalent to Affine(rvec, 0) * a; + Affine3 rotate(const Vec3& rvec) const; + + //! a.translate(t) is equivalent to Affine(E, t) * a, where E is an identity matrix + Affine3 translate(const Vec3& t) const; + + //! a.concatenate(affine) is equivalent to affine * a; + Affine3 concatenate(const Affine3& affine) const; + + template operator Affine3() const; + + template Affine3 cast() const; + + Mat4 matrix; + +#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H + Affine3(const Eigen::Transform& affine); + Affine3(const Eigen::Transform& affine); + operator Eigen::Transform() const; + operator Eigen::Transform() const; +#endif + }; + + template static + Affine3 operator*(const Affine3& affine1, const Affine3& affine2); + + //! V is a 3-element vector with member fields x, y and z + template static + V operator*(const Affine3& affine, const V& vector); + + typedef Affine3 Affine3f; + typedef Affine3 Affine3d; + + static Vec3f operator*(const Affine3f& affine, const Vec3f& vector); + static Vec3d operator*(const Affine3d& affine, const Vec3d& vector); + + template class DataType< Affine3<_Tp> > + { + public: + typedef Affine3<_Tp> value_type; + typedef Affine3::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 16, + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; + }; + + namespace traits { + template + struct Depth< Affine3<_Tp> > { enum { value = Depth<_Tp>::value }; }; + template + struct Type< Affine3<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; }; + } // namespace + +//! @} core + +} + +//! @cond IGNORED + +/////////////////////////////////////////////////////////////////////////////////// +// Implementation + +template inline +cv::Affine3::Affine3() + : matrix(Mat4::eye()) +{} + +template inline +cv::Affine3::Affine3(const Mat4& affine) + : matrix(affine) +{} + +template inline +cv::Affine3::Affine3(const Mat3& R, const Vec3& t) +{ + rotation(R); + translation(t); + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template inline +cv::Affine3::Affine3(const Vec3& _rvec, const Vec3& t) +{ + rotation(_rvec); + translation(t); + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template inline +cv::Affine3::Affine3(const cv::Mat& data, const Vec3& t) +{ + CV_Assert(data.type() == cv::traits::Type::value); + CV_Assert(data.channels() == 1); + + if (data.cols == 4 && data.rows == 4) + { + data.copyTo(matrix); + return; + } + else if (data.cols == 4 && data.rows == 3) + { + rotation(data(Rect(0, 0, 3, 3))); + translation(data(Rect(3, 0, 1, 3))); + } + else + { + rotation(data); + translation(t); + } + + matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; + matrix.val[15] = 1; +} + +template inline +cv::Affine3::Affine3(const float_type* vals) : matrix(vals) +{} + +template inline +cv::Affine3 cv::Affine3::Identity() +{ + return Affine3(cv::Affine3::Mat4::eye()); +} + +template inline +void cv::Affine3::rotation(const Mat3& R) +{ + linear(R); +} + +template inline +void cv::Affine3::rotation(const Vec3& _rvec) +{ + double theta = norm(_rvec); + + if (theta < DBL_EPSILON) + rotation(Mat3::eye()); + else + { + double c = std::cos(theta); + double s = std::sin(theta); + double c1 = 1. - c; + double itheta = (theta != 0) ? 1./theta : 0.; + + Point3_ r = _rvec*itheta; + + Mat3 rrt( r.x*r.x, r.x*r.y, r.x*r.z, r.x*r.y, r.y*r.y, r.y*r.z, r.x*r.z, r.y*r.z, r.z*r.z ); + Mat3 r_x( 0, -r.z, r.y, r.z, 0, -r.x, -r.y, r.x, 0 ); + + // R = cos(theta)*I + (1 - cos(theta))*r*rT + sin(theta)*[r_x] + // where [r_x] is [0 -rz ry; rz 0 -rx; -ry rx 0] + Mat3 R = c*Mat3::eye() + c1*rrt + s*r_x; + + rotation(R); + } +} + +//Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix; +template inline +void cv::Affine3::rotation(const cv::Mat& data) +{ + CV_Assert(data.type() == cv::traits::Type::value); + CV_Assert(data.channels() == 1); + + if (data.cols == 3 && data.rows == 3) + { + Mat3 R; + data.copyTo(R); + rotation(R); + } + else if ((data.cols == 3 && data.rows == 1) || (data.cols == 1 && data.rows == 3)) + { + Vec3 _rvec; + data.reshape(1, 3).copyTo(_rvec); + rotation(_rvec); + } + else + CV_Error(Error::StsError, "Input matrix can only be 3x3, 1x3 or 3x1"); +} + +template inline +void cv::Affine3::linear(const Mat3& L) +{ + matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2]; + matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5]; + matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8]; +} + +template inline +void cv::Affine3::translation(const Vec3& t) +{ + matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2]; +} + +template inline +typename cv::Affine3::Mat3 cv::Affine3::rotation() const +{ + return linear(); +} + +template inline +typename cv::Affine3::Mat3 cv::Affine3::linear() const +{ + typename cv::Affine3::Mat3 R; + R.val[0] = matrix.val[0]; R.val[1] = matrix.val[1]; R.val[2] = matrix.val[ 2]; + R.val[3] = matrix.val[4]; R.val[4] = matrix.val[5]; R.val[5] = matrix.val[ 6]; + R.val[6] = matrix.val[8]; R.val[7] = matrix.val[9]; R.val[8] = matrix.val[10]; + return R; +} + +template inline +typename cv::Affine3::Vec3 cv::Affine3::translation() const +{ + return Vec3(matrix.val[3], matrix.val[7], matrix.val[11]); +} + +template inline +typename cv::Affine3::Vec3 cv::Affine3::rvec() const +{ + cv::Vec3d w; + cv::Matx33d u, vt, R = rotation(); + cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A); + R = u * vt; + + double rx = R.val[7] - R.val[5]; + double ry = R.val[2] - R.val[6]; + double rz = R.val[3] - R.val[1]; + + double s = std::sqrt((rx*rx + ry*ry + rz*rz)*0.25); + double c = (R.val[0] + R.val[4] + R.val[8] - 1) * 0.5; + c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c; + double theta = acos(c); + + if( s < 1e-5 ) + { + if( c > 0 ) + rx = ry = rz = 0; + else + { + double t; + t = (R.val[0] + 1) * 0.5; + rx = std::sqrt(std::max(t, 0.0)); + t = (R.val[4] + 1) * 0.5; + ry = std::sqrt(std::max(t, 0.0)) * (R.val[1] < 0 ? -1.0 : 1.0); + t = (R.val[8] + 1) * 0.5; + rz = std::sqrt(std::max(t, 0.0)) * (R.val[2] < 0 ? -1.0 : 1.0); + + if( fabs(rx) < fabs(ry) && fabs(rx) < fabs(rz) && (R.val[5] > 0) != (ry*rz > 0) ) + rz = -rz; + theta /= std::sqrt(rx*rx + ry*ry + rz*rz); + rx *= theta; + ry *= theta; + rz *= theta; + } + } + else + { + double vth = 1/(2*s); + vth *= theta; + rx *= vth; ry *= vth; rz *= vth; + } + + return cv::Vec3d(rx, ry, rz); +} + +template inline +cv::Affine3 cv::Affine3::inv(int method) const +{ + return matrix.inv(method); +} + +template inline +cv::Affine3 cv::Affine3::rotate(const Mat3& R) const +{ + Mat3 Lc = linear(); + Vec3 tc = translation(); + Mat4 result; + result.val[12] = result.val[13] = result.val[14] = 0; + result.val[15] = 1; + + for(int j = 0; j < 3; ++j) + { + for(int i = 0; i < 3; ++i) + { + float_type value = 0; + for(int k = 0; k < 3; ++k) + value += R(j, k) * Lc(k, i); + result(j, i) = value; + } + + result(j, 3) = R.row(j).dot(tc.t()); + } + return result; +} + +template inline +cv::Affine3 cv::Affine3::rotate(const Vec3& _rvec) const +{ + return rotate(Affine3f(_rvec).rotation()); +} + +template inline +cv::Affine3 cv::Affine3::translate(const Vec3& t) const +{ + Mat4 m = matrix; + m.val[ 3] += t[0]; + m.val[ 7] += t[1]; + m.val[11] += t[2]; + return m; +} + +template inline +cv::Affine3 cv::Affine3::concatenate(const Affine3& affine) const +{ + return (*this).rotate(affine.rotation()).translate(affine.translation()); +} + +template template inline +cv::Affine3::operator Affine3() const +{ + return Affine3(matrix); +} + +template template inline +cv::Affine3 cv::Affine3::cast() const +{ + return Affine3(matrix); +} + +template inline +cv::Affine3 cv::operator*(const cv::Affine3& affine1, const cv::Affine3& affine2) +{ + return affine2.concatenate(affine1); +} + +template inline +V cv::operator*(const cv::Affine3& affine, const V& v) +{ + const typename Affine3::Mat4& m = affine.matrix; + + V r; + r.x = m.val[0] * v.x + m.val[1] * v.y + m.val[ 2] * v.z + m.val[ 3]; + r.y = m.val[4] * v.x + m.val[5] * v.y + m.val[ 6] * v.z + m.val[ 7]; + r.z = m.val[8] * v.x + m.val[9] * v.y + m.val[10] * v.z + m.val[11]; + return r; +} + +static inline +cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v) +{ + const cv::Matx44f& m = affine.matrix; + cv::Vec3f r; + r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3]; + r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7]; + r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11]; + return r; +} + +static inline +cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) +{ + const cv::Matx44d& m = affine.matrix; + cv::Vec3d r; + r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3]; + r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7]; + r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11]; + return r; +} + + + +#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H + +template inline +cv::Affine3::Affine3(const Eigen::Transform& affine) +{ + cv::Mat(4, 4, cv::traits::Type::value, affine.matrix().data()).copyTo(matrix); +} + +template inline +cv::Affine3::Affine3(const Eigen::Transform& affine) +{ + Eigen::Transform a = affine; + cv::Mat(4, 4, cv::traits::Type::value, a.matrix().data()).copyTo(matrix); +} + +template inline +cv::Affine3::operator Eigen::Transform() const +{ + Eigen::Transform r; + cv::Mat hdr(4, 4, cv::traits::Type::value, r.matrix().data()); + cv::Mat(matrix, false).copyTo(hdr); + return r; +} + +template inline +cv::Affine3::operator Eigen::Transform() const +{ + return this->operator Eigen::Transform(); +} + +#endif /* defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H */ + +//! @endcond + +#endif /* __cplusplus */ + +#endif /* OPENCV_CORE_AFFINE3_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/async.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/async.hpp new file mode 100644 index 0000000000000000000000000000000000000000..54560c7d001aec72de74f3596402e639786364f8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/async.hpp @@ -0,0 +1,105 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_ASYNC_HPP +#define OPENCV_CORE_ASYNC_HPP + +#include + +#ifdef CV_CXX11 +//#include +#include +#endif + +namespace cv { + +/** @addtogroup core_async + +@{ +*/ + + +/** @brief Returns result of asynchronous operations + +Object has attached asynchronous state. +Assignment operator doesn't clone asynchronous state (it is shared between all instances). + +Result can be fetched via get() method only once. + +*/ +class CV_EXPORTS_W AsyncArray +{ +public: + ~AsyncArray() CV_NOEXCEPT; + CV_WRAP AsyncArray() CV_NOEXCEPT; + AsyncArray(const AsyncArray& o) CV_NOEXCEPT; + AsyncArray& operator=(const AsyncArray& o) CV_NOEXCEPT; + CV_WRAP void release() CV_NOEXCEPT; + + /** Fetch the result. + @param[out] dst destination array + + Waits for result until container has valid result. + Throws exception if exception was stored as a result. + + Throws exception on invalid container state. + + @note Result or stored exception can be fetched only once. + */ + CV_WRAP void get(OutputArray dst) const; + + /** Retrieving the result with timeout + @param[out] dst destination array + @param[in] timeoutNs timeout in nanoseconds, -1 for infinite wait + + @returns true if result is ready, false if the timeout has expired + + @note Result or stored exception can be fetched only once. + */ + bool get(OutputArray dst, int64 timeoutNs) const; + + CV_WRAP inline + bool get(OutputArray dst, double timeoutNs) const { return get(dst, (int64)timeoutNs); } + + bool wait_for(int64 timeoutNs) const; + + CV_WRAP inline + bool wait_for(double timeoutNs) const { return wait_for((int64)timeoutNs); } + + CV_WRAP bool valid() const CV_NOEXCEPT; + +#ifdef CV_CXX11 + inline AsyncArray(AsyncArray&& o) { p = o.p; o.p = NULL; } + inline AsyncArray& operator=(AsyncArray&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; } + + template + inline bool get(OutputArray dst, const std::chrono::duration<_Rep, _Period>& timeout) + { + return get(dst, (int64)(std::chrono::nanoseconds(timeout).count())); + } + + template + inline bool wait_for(const std::chrono::duration<_Rep, _Period>& timeout) + { + return wait_for((int64)(std::chrono::nanoseconds(timeout).count())); + } + +#if 0 + std::future getFutureMat() const; + std::future getFutureUMat() const; +#endif +#endif + + + // PImpl + struct Impl; friend struct Impl; + inline void* _getImpl() const CV_NOEXCEPT { return p; } +protected: + Impl* p; +}; + + +//! @} +} // namespace +#endif // OPENCV_CORE_ASYNC_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/base.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/base.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a3a3e51e0475bf185ba3e13f93db728ef91271db --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/base.hpp @@ -0,0 +1,654 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2014, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_BASE_HPP +#define OPENCV_CORE_BASE_HPP + +#ifndef __cplusplus +# error base.hpp header must be compiled as C++ +#endif + +#include "opencv2/opencv_modules.hpp" + +#include +#include + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" + +namespace cv +{ + +//! @addtogroup core_utils +//! @{ + +namespace Error { +//! error codes +enum Code { + StsOk= 0, //!< everything is ok + StsBackTrace= -1, //!< pseudo error for back trace + StsError= -2, //!< unknown /unspecified error + StsInternal= -3, //!< internal error (bad state) + StsNoMem= -4, //!< insufficient memory + StsBadArg= -5, //!< function arg/param is bad + StsBadFunc= -6, //!< unsupported function + StsNoConv= -7, //!< iteration didn't converge + StsAutoTrace= -8, //!< tracing + HeaderIsNull= -9, //!< image header is NULL + BadImageSize= -10, //!< image size is invalid + BadOffset= -11, //!< offset is invalid + BadDataPtr= -12, //!< + BadStep= -13, //!< image step is wrong, this may happen for a non-continuous matrix. + BadModelOrChSeq= -14, //!< + BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices. + BadNumChannel1U= -16, //!< + BadDepth= -17, //!< input image depth is not supported by the function + BadAlphaChannel= -18, //!< + BadOrder= -19, //!< number of dimensions is out of range + BadOrigin= -20, //!< incorrect input origin + BadAlign= -21, //!< incorrect input align + BadCallBack= -22, //!< + BadTileSize= -23, //!< + BadCOI= -24, //!< input COI is not supported + BadROISize= -25, //!< incorrect input roi + MaskIsTiled= -26, //!< + StsNullPtr= -27, //!< null pointer + StsVecLengthErr= -28, //!< incorrect vector length + StsFilterStructContentErr= -29, //!< incorrect filter structure content + StsKernelStructContentErr= -30, //!< incorrect transform kernel content + StsFilterOffsetErr= -31, //!< incorrect filter offset value + StsBadSize= -201, //!< the input/output structure size is incorrect + StsDivByZero= -202, //!< division by zero + StsInplaceNotSupported= -203, //!< in-place operation is not supported + StsObjectNotFound= -204, //!< request can't be completed + StsUnmatchedFormats= -205, //!< formats of input/output arrays differ + StsBadFlag= -206, //!< flag is wrong or not supported + StsBadPoint= -207, //!< bad CvPoint + StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1) + StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match + StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function + StsOutOfRange= -211, //!< some of parameters are out of range + StsParseError= -212, //!< invalid syntax/structure of the parsed file + StsNotImplemented= -213, //!< the requested function/feature is not implemented + StsBadMemBlock= -214, //!< an allocated block has been corrupted + StsAssert= -215, //!< assertion failed + GpuNotSupported= -216, //!< no CUDA support + GpuApiCallError= -217, //!< GPU API call error + OpenGlNotSupported= -218, //!< no OpenGL support + OpenGlApiCallError= -219, //!< OpenGL API call error + OpenCLApiCallError= -220, //!< OpenCL API call error + OpenCLDoubleNotSupported= -221, + OpenCLInitError= -222, //!< OpenCL initialization error + OpenCLNoAMDBlasFft= -223 +}; +} //Error + +//! @} core_utils + +//! @addtogroup core_array +//! @{ + +//! matrix decomposition types +enum DecompTypes { + /** Gaussian elimination with the optimal pivot element chosen. */ + DECOMP_LU = 0, + /** singular value decomposition (SVD) method; the system can be over-defined and/or the matrix + src1 can be singular */ + DECOMP_SVD = 1, + /** eigenvalue decomposition; the matrix src1 must be symmetrical */ + DECOMP_EIG = 2, + /** Cholesky \f$LL^T\f$ factorization; the matrix src1 must be symmetrical and positively + defined */ + DECOMP_CHOLESKY = 3, + /** QR factorization; the system can be over-defined and/or the matrix src1 can be singular */ + DECOMP_QR = 4, + /** while all the previous flags are mutually exclusive, this flag can be used together with + any of the previous; it means that the normal equations + \f$\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2}\f$ are + solved instead of the original system + \f$\texttt{src1}\cdot\texttt{dst}=\texttt{src2}\f$ */ + DECOMP_NORMAL = 16 +}; + +/** norm types + +src1 and src2 denote input arrays. +*/ + +enum NormTypes { + /** + \f[ + norm = \forkthree + {\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } + {\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) } + {\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) } + \f] + */ + NORM_INF = 1, + /** + \f[ + norm = \forkthree + {\| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\)} + { \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) } + { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) } + \f]*/ + NORM_L1 = 2, + /** + \f[ + norm = \forkthree + { \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } + { \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) } + { \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) } + \f] + */ + NORM_L2 = 4, + /** + \f[ + norm = \forkthree + { \| \texttt{src1} \| _{L_2} ^{2} = \sum_I \texttt{src1}(I)^2} {if \(\texttt{normType} = \texttt{NORM_L2SQR}\)} + { \| \texttt{src1} - \texttt{src2} \| _{L_2} ^{2} = \sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2 }{if \(\texttt{normType} = \texttt{NORM_L2SQR}\) } + { \left(\frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}}\right)^2 }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2SQR}\) } + \f] + */ + NORM_L2SQR = 5, + /** + In the case of one input array, calculates the Hamming distance of the array from zero, + In the case of two input arrays, calculates the Hamming distance between the arrays. + */ + NORM_HAMMING = 6, + /** + Similar to NORM_HAMMING, but in the calculation, each two bits of the input sequence will + be added and treated as a single bit to be used in the same calculation as NORM_HAMMING. + */ + NORM_HAMMING2 = 7, + NORM_TYPE_MASK = 7, //!< bit-mask which can be used to separate norm type from norm flags + NORM_RELATIVE = 8, //!< flag + NORM_MINMAX = 32 //!< flag + }; + +//! comparison types +enum CmpTypes { CMP_EQ = 0, //!< src1 is equal to src2. + CMP_GT = 1, //!< src1 is greater than src2. + CMP_GE = 2, //!< src1 is greater than or equal to src2. + CMP_LT = 3, //!< src1 is less than src2. + CMP_LE = 4, //!< src1 is less than or equal to src2. + CMP_NE = 5 //!< src1 is unequal to src2. + }; + +//! generalized matrix multiplication flags +enum GemmFlags { GEMM_1_T = 1, //!< transposes src1 + GEMM_2_T = 2, //!< transposes src2 + GEMM_3_T = 4 //!< transposes src3 + }; + +enum DftFlags { + /** performs an inverse 1D or 2D transform instead of the default forward + transform. */ + DFT_INVERSE = 1, + /** scales the result: divide it by the number of array elements. Normally, it is + combined with DFT_INVERSE. */ + DFT_SCALE = 2, + /** performs a forward or inverse transform of every individual row of the input + matrix; this flag enables you to transform multiple vectors simultaneously and can be used to + decrease the overhead (which is sometimes several times larger than the processing itself) to + perform 3D and higher-dimensional transformations and so forth.*/ + DFT_ROWS = 4, + /** performs a forward transformation of 1D or 2D real array; the result, + though being a complex array, has complex-conjugate symmetry (*CCS*, see the function + description below for details), and such an array can be packed into a real array of the same + size as input, which is the fastest option and which is what the function does by default; + however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) - + pass the flag to enable the function to produce a full-size complex output array. */ + DFT_COMPLEX_OUTPUT = 16, + /** performs an inverse transformation of a 1D or 2D complex array; the + result is normally a complex array of the same size, however, if the input array has + conjugate-complex symmetry (for example, it is a result of forward transformation with + DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not + check whether the input is symmetrical or not, you can pass the flag and then the function + will assume the symmetry and produce the real output array (note that when the input is packed + into a real array and inverse transformation is executed, the function treats the input as a + packed complex-conjugate symmetrical array, and the output will also be a real array). */ + DFT_REAL_OUTPUT = 32, + /** specifies that input is complex input. If this flag is set, the input must have 2 channels. + On the other hand, for backwards compatibility reason, if input has 2 channels, input is + already considered complex. */ + DFT_COMPLEX_INPUT = 64, + /** performs an inverse 1D or 2D transform instead of the default forward transform. */ + DCT_INVERSE = DFT_INVERSE, + /** performs a forward or inverse transform of every individual row of the input + matrix. This flag enables you to transform multiple vectors simultaneously and can be used to + decrease the overhead (which is sometimes several times larger than the processing itself) to + perform 3D and higher-dimensional transforms and so forth.*/ + DCT_ROWS = DFT_ROWS +}; + +//! Various border types, image boundaries are denoted with `|` +//! @see borderInterpolate, copyMakeBorder +enum BorderTypes { + BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i` + BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh` + BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb` + BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg` + BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba` + BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno` + + BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_ISOLATED = 16 //!< do not look outside of ROI +}; + +//! @} core_array + +//! @addtogroup core_utils +//! @{ + +/*! @brief Signals an error and raises the exception. + +By default the function prints information about the error to stderr, +then it either stops if setBreakOnError() had been called before or raises the exception. +It is possible to alternate error processing by using redirectError(). +@param _code - error code (Error::Code) +@param _err - error description +@param _func - function name. Available only when the compiler supports getting it +@param _file - source file name where the error has occurred +@param _line - line number in the source file where the error has occurred +@see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert + */ +CV_EXPORTS CV_NORETURN void error(int _code, const String& _err, const char* _func, const char* _file, int _line); + +#ifdef CV_STATIC_ANALYSIS + +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#define CV_Error(code, msg) do { (void)(code); (void)(msg); abort(); } while (0) +#define CV_Error_(code, args) do { (void)(code); (void)(cv::format args); abort(); } while (0) +#define CV_Assert( expr ) do { if (!(expr)) abort(); } while (0) + +#else // CV_STATIC_ANALYSIS + +/** @brief Call the error handler. + +Currently, the error handler prints the error code and the error message to the standard +error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that +the execution stack and all the parameters can be analyzed by the debugger. In the Release +configuration, the exception is thrown. + +@param code one of Error::Code +@param msg error message +*/ +#define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ ) + +/** @brief Call the error handler. + +This macro can be used to construct an error message on-fly to include some dynamic information, +for example: +@code + // note the extra parentheses around the formatted text message + CV_Error_(Error::StsOutOfRange, + ("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue)); +@endcode +@param code one of Error::Code +@param args printf-like formatted error message in parentheses +*/ +#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ ) + +/** @brief Checks a condition at runtime and throws exception if it fails + +The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros +raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release +configurations while CV_DbgAssert is only retained in the Debug configuration. +*/ +#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) + +#endif // CV_STATIC_ANALYSIS + +//! @cond IGNORED +#if !defined(__OPENCV_BUILD) // TODO: backward compatibility only +#ifndef CV_ErrorNoReturn +#define CV_ErrorNoReturn CV_Error +#endif +#ifndef CV_ErrorNoReturn_ +#define CV_ErrorNoReturn_ CV_Error_ +#endif +#endif + +#define CV_Assert_1 CV_Assert +#define CV_Assert_2( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_1( __VA_ARGS__ )) +#define CV_Assert_3( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_2( __VA_ARGS__ )) +#define CV_Assert_4( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_3( __VA_ARGS__ )) +#define CV_Assert_5( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_4( __VA_ARGS__ )) +#define CV_Assert_6( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_5( __VA_ARGS__ )) +#define CV_Assert_7( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_6( __VA_ARGS__ )) +#define CV_Assert_8( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_7( __VA_ARGS__ )) +#define CV_Assert_9( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_8( __VA_ARGS__ )) +#define CV_Assert_10( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_9( __VA_ARGS__ )) + +#define CV_Assert_N(...) do { __CV_EXPAND(__CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__)); } while(0) + +//! @endcond + +#if defined _DEBUG || defined CV_STATIC_ANALYSIS +# define CV_DbgAssert(expr) CV_Assert(expr) +#else +/** replaced with CV_Assert(expr) in Debug configuration */ +# define CV_DbgAssert(expr) +#endif + +/* + * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor + * bit count of A exclusive XOR'ed with B + */ +struct CV_EXPORTS Hamming +{ + static const NormTypes normType = NORM_HAMMING; + typedef unsigned char ValueType; + typedef int ResultType; + + /** this will count the bits in a ^ b + */ + ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const; +}; + +typedef Hamming HammingLUT; + +/////////////////////////////////// inline norms //////////////////////////////////// + +template inline _Tp cv_abs(_Tp x) { return std::abs(x); } +inline int cv_abs(uchar x) { return x; } +inline int cv_abs(schar x) { return std::abs(x); } +inline int cv_abs(ushort x) { return x; } +inline int cv_abs(short x) { return std::abs(x); } + +template static inline +_AccTp normL2Sqr(const _Tp* a, int n) +{ + _AccTp s = 0; + int i=0; +#if CV_ENABLE_UNROLLED + for( ; i <= n - 4; i += 4 ) + { + _AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3]; + s += v0*v0 + v1*v1 + v2*v2 + v3*v3; + } +#endif + for( ; i < n; i++ ) + { + _AccTp v = a[i]; + s += v*v; + } + return s; +} + +template static inline +_AccTp normL1(const _Tp* a, int n) +{ + _AccTp s = 0; + int i = 0; +#if CV_ENABLE_UNROLLED + for(; i <= n - 4; i += 4 ) + { + s += (_AccTp)cv_abs(a[i]) + (_AccTp)cv_abs(a[i+1]) + + (_AccTp)cv_abs(a[i+2]) + (_AccTp)cv_abs(a[i+3]); + } +#endif + for( ; i < n; i++ ) + s += cv_abs(a[i]); + return s; +} + +template static inline +_AccTp normInf(const _Tp* a, int n) +{ + _AccTp s = 0; + for( int i = 0; i < n; i++ ) + s = std::max(s, (_AccTp)cv_abs(a[i])); + return s; +} + +template static inline +_AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n) +{ + _AccTp s = 0; + int i= 0; +#if CV_ENABLE_UNROLLED + for(; i <= n - 4; i += 4 ) + { + _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]); + s += v0*v0 + v1*v1 + v2*v2 + v3*v3; + } +#endif + for( ; i < n; i++ ) + { + _AccTp v = _AccTp(a[i] - b[i]); + s += v*v; + } + return s; +} + +static inline float normL2Sqr(const float* a, const float* b, int n) +{ + float s = 0.f; + for( int i = 0; i < n; i++ ) + { + float v = a[i] - b[i]; + s += v*v; + } + return s; +} + +template static inline +_AccTp normL1(const _Tp* a, const _Tp* b, int n) +{ + _AccTp s = 0; + int i= 0; +#if CV_ENABLE_UNROLLED + for(; i <= n - 4; i += 4 ) + { + _AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]); + s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3); + } +#endif + for( ; i < n; i++ ) + { + _AccTp v = _AccTp(a[i] - b[i]); + s += std::abs(v); + } + return s; +} + +inline float normL1(const float* a, const float* b, int n) +{ + float s = 0.f; + for( int i = 0; i < n; i++ ) + { + s += std::abs(a[i] - b[i]); + } + return s; +} + +inline int normL1(const uchar* a, const uchar* b, int n) +{ + int s = 0; + for( int i = 0; i < n; i++ ) + { + s += std::abs(a[i] - b[i]); + } + return s; +} + +template static inline +_AccTp normInf(const _Tp* a, const _Tp* b, int n) +{ + _AccTp s = 0; + for( int i = 0; i < n; i++ ) + { + _AccTp v0 = a[i] - b[i]; + s = std::max(s, std::abs(v0)); + } + return s; +} + +/** @brief Computes the cube root of an argument. + + The function cubeRoot computes \f$\sqrt[3]{\texttt{val}}\f$. Negative arguments are handled correctly. + NaN and Inf are not handled. The accuracy approaches the maximum possible accuracy for + single-precision data. + @param val A function argument. + */ +CV_EXPORTS_W float cubeRoot(float val); + +/** @brief Calculates the angle of a 2D vector in degrees. + + The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured + in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees. + @param x x-coordinate of the vector. + @param y y-coordinate of the vector. + */ +CV_EXPORTS_W float fastAtan2(float y, float x); + +/** proxy for hal::LU */ +CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); +/** proxy for hal::LU */ +CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); +/** proxy for hal::Cholesky */ +CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); +/** proxy for hal::Cholesky */ +CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); + +////////////////// forward declarations for important OpenCV types ////////////////// + +//! @cond IGNORED + +template class Vec; +template class Matx; + +template class Complex; +template class Point_; +template class Point3_; +template class Size_; +template class Rect_; +template class Scalar_; + +class CV_EXPORTS RotatedRect; +class CV_EXPORTS Range; +class CV_EXPORTS TermCriteria; +class CV_EXPORTS KeyPoint; +class CV_EXPORTS DMatch; +class CV_EXPORTS RNG; + +class CV_EXPORTS Mat; +class CV_EXPORTS MatExpr; + +class CV_EXPORTS UMat; + +class CV_EXPORTS SparseMat; +typedef Mat MatND; + +template class Mat_; +template class SparseMat_; + +class CV_EXPORTS MatConstIterator; +class CV_EXPORTS SparseMatIterator; +class CV_EXPORTS SparseMatConstIterator; +template class MatIterator_; +template class MatConstIterator_; +template class SparseMatIterator_; +template class SparseMatConstIterator_; + +namespace ogl +{ + class CV_EXPORTS Buffer; + class CV_EXPORTS Texture2D; + class CV_EXPORTS Arrays; +} + +namespace cuda +{ + class CV_EXPORTS GpuMat; + class CV_EXPORTS HostMem; + class CV_EXPORTS Stream; + class CV_EXPORTS Event; +} + +namespace cudev +{ + template class GpuMat_; +} + +namespace ipp +{ +CV_EXPORTS unsigned long long getIppFeatures(); +CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL, + int line = 0); +CV_EXPORTS int getIppStatus(); +CV_EXPORTS String getIppErrorLocation(); +CV_EXPORTS_W bool useIPP(); +CV_EXPORTS_W void setUseIPP(bool flag); +CV_EXPORTS_W String getIppVersion(); + +// IPP Not-Exact mode. This function may force use of IPP then both IPP and OpenCV provide proper results +// but have internal accuracy differences which have too much direct or indirect impact on accuracy tests. +CV_EXPORTS_W bool useIPP_NotExact(); +CV_EXPORTS_W void setUseIPP_NotExact(bool flag); +#ifndef DISABLE_OPENCV_3_COMPATIBILITY +static inline bool useIPP_NE() { return useIPP_NotExact(); } +static inline void setUseIPP_NE(bool flag) { setUseIPP_NotExact(flag); } +#endif + +} // ipp + +//! @endcond + +//! @} core_utils + + + + +} // cv + +#include "opencv2/core/neon_utils.hpp" +#include "opencv2/core/vsx_utils.hpp" +#include "opencv2/core/check.hpp" + +#endif //OPENCV_CORE_BASE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/bindings_utils.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/bindings_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f693dc8c65f5db0d1a0d2f7463ce353dec391b0c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/bindings_utils.hpp @@ -0,0 +1,87 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_BINDINGS_UTILS_HPP +#define OPENCV_CORE_BINDINGS_UTILS_HPP + +#include +#include + +namespace cv { namespace utils { +//! @addtogroup core_utils +//! @{ + +CV_EXPORTS_W String dumpInputArray(InputArray argument); + +CV_EXPORTS_W String dumpInputArrayOfArrays(InputArrayOfArrays argument); + +CV_EXPORTS_W String dumpInputOutputArray(InputOutputArray argument); + +CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argument); + +CV_WRAP static inline +String dumpBool(bool argument) +{ + return (argument) ? String("Bool: True") : String("Bool: False"); +} + +CV_WRAP static inline +String dumpInt(int argument) +{ + return cv::format("Int: %d", argument); +} + +CV_WRAP static inline +String dumpSizeT(size_t argument) +{ + std::ostringstream oss("size_t: ", std::ios::ate); + oss << argument; + return oss.str(); +} + +CV_WRAP static inline +String dumpFloat(float argument) +{ + return cv::format("Float: %.2f", argument); +} + +CV_WRAP static inline +String dumpDouble(double argument) +{ + return cv::format("Double: %.2f", argument); +} + +CV_WRAP static inline +String dumpCString(const char* argument) +{ + return cv::format("String: %s", argument); +} + +CV_WRAP static inline +AsyncArray testAsyncArray(InputArray argument) +{ + AsyncPromise p; + p.setValue(argument); + return p.getArrayResult(); +} + +CV_WRAP static inline +AsyncArray testAsyncException() +{ + AsyncPromise p; + try + { + CV_Error(Error::StsOk, "Test: Generated async error"); + } + catch (const cv::Exception& e) + { + p.setException(e); + } + return p.getArrayResult(); +} + +//! @} +}} // namespace + +#endif // OPENCV_CORE_BINDINGS_UTILS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/bufferpool.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/bufferpool.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4698e5da167d6a3b6a9ef7672faa3542b23fa662 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/bufferpool.hpp @@ -0,0 +1,40 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. + +#ifndef OPENCV_CORE_BUFFER_POOL_HPP +#define OPENCV_CORE_BUFFER_POOL_HPP + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4265) +#endif + +namespace cv +{ + +//! @addtogroup core +//! @{ + +class BufferPoolController +{ +protected: + ~BufferPoolController() { } +public: + virtual size_t getReservedSize() const = 0; + virtual size_t getMaxReservedSize() const = 0; + virtual void setMaxReservedSize(size_t size) = 0; + virtual void freeAllReservedBuffers() = 0; +}; + +//! @} + +} + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#endif // OPENCV_CORE_BUFFER_POOL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/check.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/check.hpp new file mode 100644 index 0000000000000000000000000000000000000000..604447e8d77d4dcc857f03ba26a2d7d58009a60e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/check.hpp @@ -0,0 +1,159 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_CHECK_HPP +#define OPENCV_CORE_CHECK_HPP + +#include + +namespace cv { + +/** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or "" */ +CV_EXPORTS const char* depthToString(int depth); + +/** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or "" */ +CV_EXPORTS const String typeToString(int type); + + +//! @cond IGNORED +namespace detail { + +/** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or NULL */ +CV_EXPORTS const char* depthToString_(int depth); + +/** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or cv::String() */ +CV_EXPORTS const cv::String typeToString_(int type); + +enum TestOp { + TEST_CUSTOM = 0, + TEST_EQ = 1, + TEST_NE = 2, + TEST_LE = 3, + TEST_LT = 4, + TEST_GE = 5, + TEST_GT = 6, + CV__LAST_TEST_OP +}; + +struct CheckContext { + const char* func; + const char* file; + int line; + enum TestOp testOp; + const char* message; + const char* p1_str; + const char* p2_str; +}; + +#ifndef CV__CHECK_FILENAME +# define CV__CHECK_FILENAME __FILE__ +#endif + +#ifndef CV__CHECK_FUNCTION +# if defined _MSC_VER +# define CV__CHECK_FUNCTION __FUNCSIG__ +# elif defined __GNUC__ +# define CV__CHECK_FUNCTION __PRETTY_FUNCTION__ +# else +# define CV__CHECK_FUNCTION "" +# endif +#endif + +#define CV__CHECK_LOCATION_VARNAME(id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_check_, id), __LINE__) +#define CV__DEFINE_CHECK_CONTEXT(id, message, testOp, p1_str, p2_str) \ + static const cv::detail::CheckContext CV__CHECK_LOCATION_VARNAME(id) = \ + { CV__CHECK_FUNCTION, CV__CHECK_FILENAME, __LINE__, testOp, message, p1_str, p2_str } + +CV_EXPORTS void CV_NORETURN check_failed_auto(const int v1, const int v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v1, const size_t v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const float v1, const float v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const double v1, const double v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_ v1, const Size_ v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v1, const int v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v1, const int v2, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v1, const int v2, const CheckContext& ctx); + +CV_EXPORTS void CV_NORETURN check_failed_auto(const int v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const float v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const double v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_ v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v, const CheckContext& ctx); +CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v, const CheckContext& ctx); + + +#define CV__TEST_EQ(v1, v2) ((v1) == (v2)) +#define CV__TEST_NE(v1, v2) ((v1) != (v2)) +#define CV__TEST_LE(v1, v2) ((v1) <= (v2)) +#define CV__TEST_LT(v1, v2) ((v1) < (v2)) +#define CV__TEST_GE(v1, v2) ((v1) >= (v2)) +#define CV__TEST_GT(v1, v2) ((v1) > (v2)) + +#define CV__CHECK(id, op, type, v1, v2, v1_str, v2_str, msg_str) do { \ + if(CV__TEST_##op((v1), (v2))) ; else { \ + CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_ ## op, v1_str, v2_str); \ + cv::detail::check_failed_ ## type((v1), (v2), CV__CHECK_LOCATION_VARNAME(id)); \ + } \ +} while (0) + +#define CV__CHECK_CUSTOM_TEST(id, type, v, test_expr, v_str, test_expr_str, msg_str) do { \ + if(!!(test_expr)) ; else { \ + CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_CUSTOM, v_str, test_expr_str); \ + cv::detail::check_failed_ ## type((v), CV__CHECK_LOCATION_VARNAME(id)); \ + } \ +} while (0) + +} // namespace +//! @endcond + + +/// Supported values of these types: int, float, double +#define CV_CheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg) +#define CV_CheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg) + +/// Check with additional "decoding" of type values in error message +#define CV_CheckTypeEQ(t1, t2, msg) CV__CHECK(_, EQ, MatType, t1, t2, #t1, #t2, msg) +/// Check with additional "decoding" of depth values in error message +#define CV_CheckDepthEQ(d1, d2, msg) CV__CHECK(_, EQ, MatDepth, d1, d2, #d1, #d2, msg) + +#define CV_CheckChannelsEQ(c1, c2, msg) CV__CHECK(_, EQ, MatChannels, c1, c2, #c1, #c2, msg) + +/// Example: type == CV_8UC1 || type == CV_8UC3 +#define CV_CheckType(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatType, t, (test_expr), #t, #test_expr, msg) + +/// Example: depth == CV_32F || depth == CV_64F +#define CV_CheckDepth(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatDepth, t, (test_expr), #t, #test_expr, msg) + +/// Example: v == A || v == B +#define CV_Check(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg) + +/// Some complex conditions: CV_Check(src2, src2.empty() || (src2.type() == src1.type() && src2.size() == src1.size()), "src2 should have same size/type as src1") +// TODO define pretty-printers + +#ifndef NDEBUG +#define CV_DbgCheck(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg) +#define CV_DbgCheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg) +#define CV_DbgCheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg) +#else +#define CV_DbgCheck(v, test_expr, msg) do { } while (0) +#define CV_DbgCheckEQ(v1, v2, msg) do { } while (0) +#define CV_DbgCheckNE(v1, v2, msg) do { } while (0) +#define CV_DbgCheckLE(v1, v2, msg) do { } while (0) +#define CV_DbgCheckLT(v1, v2, msg) do { } while (0) +#define CV_DbgCheckGE(v1, v2, msg) do { } while (0) +#define CV_DbgCheckGT(v1, v2, msg) do { } while (0) +#endif + +} // namespace + +#endif // OPENCV_CORE_CHECK_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..438918359be44fcf2489dc4f10617385fe3770e9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/core.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/core.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/core_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/core_c.h new file mode 100644 index 0000000000000000000000000000000000000000..2684151f3f33e9bfa9338b0f673d6a4bd13d9e7a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/core_c.h @@ -0,0 +1,3125 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + + +#ifndef OPENCV_CORE_C_H +#define OPENCV_CORE_C_H + +#include "opencv2/core/types_c.h" + +#ifdef __cplusplus +# ifdef _MSC_VER +/* disable warning C4190: 'function' has C-linkage specified, but returns UDT 'typename' + which is incompatible with C + + It is OK to disable it because we only extend few plain structures with + C++ constructors for simpler interoperability with C++ API of the library +*/ +# pragma warning(disable:4190) +# elif defined __clang__ && __clang_major__ >= 3 +# pragma GCC diagnostic ignored "-Wreturn-type-c-linkage" +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup core_c + @{ +*/ + +/****************************************************************************************\ +* Array allocation, deallocation, initialization and access to elements * +\****************************************************************************************/ + +/** `malloc` wrapper. + If there is no enough memory, the function + (as well as other OpenCV functions that call cvAlloc) + raises an error. */ +CVAPI(void*) cvAlloc( size_t size ); + +/** `free` wrapper. + Here and further all the memory releasing functions + (that all call cvFree) take double pointer in order to + to clear pointer to the data after releasing it. + Passing pointer to NULL pointer is Ok: nothing happens in this case +*/ +CVAPI(void) cvFree_( void* ptr ); +#define cvFree(ptr) (cvFree_(*(ptr)), *(ptr)=0) + +/** @brief Creates an image header but does not allocate the image data. + +@param size Image width and height +@param depth Image depth (see cvCreateImage ) +@param channels Number of channels (see cvCreateImage ) + */ +CVAPI(IplImage*) cvCreateImageHeader( CvSize size, int depth, int channels ); + +/** @brief Initializes an image header that was previously allocated. + +The returned IplImage\* points to the initialized header. +@param image Image header to initialize +@param size Image width and height +@param depth Image depth (see cvCreateImage ) +@param channels Number of channels (see cvCreateImage ) +@param origin Top-left IPL_ORIGIN_TL or bottom-left IPL_ORIGIN_BL +@param align Alignment for image rows, typically 4 or 8 bytes + */ +CVAPI(IplImage*) cvInitImageHeader( IplImage* image, CvSize size, int depth, + int channels, int origin CV_DEFAULT(0), + int align CV_DEFAULT(4)); + +/** @brief Creates an image header and allocates the image data. + +This function call is equivalent to the following code: +@code + header = cvCreateImageHeader(size, depth, channels); + cvCreateData(header); +@endcode +@param size Image width and height +@param depth Bit depth of image elements. See IplImage for valid depths. +@param channels Number of channels per pixel. See IplImage for details. This function only creates +images with interleaved channels. + */ +CVAPI(IplImage*) cvCreateImage( CvSize size, int depth, int channels ); + +/** @brief Deallocates an image header. + +This call is an analogue of : +@code + if(image ) + { + iplDeallocate(*image, IPL_IMAGE_HEADER | IPL_IMAGE_ROI); + *image = 0; + } +@endcode +but it does not use IPL functions by default (see the CV_TURN_ON_IPL_COMPATIBILITY macro). +@param image Double pointer to the image header + */ +CVAPI(void) cvReleaseImageHeader( IplImage** image ); + +/** @brief Deallocates the image header and the image data. + +This call is a shortened form of : +@code + if(*image ) + { + cvReleaseData(*image); + cvReleaseImageHeader(image); + } +@endcode +@param image Double pointer to the image header +*/ +CVAPI(void) cvReleaseImage( IplImage** image ); + +/** Creates a copy of IPL image (widthStep may differ) */ +CVAPI(IplImage*) cvCloneImage( const IplImage* image ); + +/** @brief Sets the channel of interest in an IplImage. + +If the ROI is set to NULL and the coi is *not* 0, the ROI is allocated. Most OpenCV functions do +*not* support the COI setting, so to process an individual image/matrix channel one may copy (via +cvCopy or cvSplit) the channel to a separate image/matrix, process it and then copy the result +back (via cvCopy or cvMerge) if needed. +@param image A pointer to the image header +@param coi The channel of interest. 0 - all channels are selected, 1 - first channel is selected, +etc. Note that the channel indices become 1-based. + */ +CVAPI(void) cvSetImageCOI( IplImage* image, int coi ); + +/** @brief Returns the index of the channel of interest. + +Returns the channel of interest of in an IplImage. Returned values correspond to the coi in +cvSetImageCOI. +@param image A pointer to the image header + */ +CVAPI(int) cvGetImageCOI( const IplImage* image ); + +/** @brief Sets an image Region Of Interest (ROI) for a given rectangle. + +If the original image ROI was NULL and the rect is not the whole image, the ROI structure is +allocated. + +Most OpenCV functions support the use of ROI and treat the image rectangle as a separate image. For +example, all of the pixel coordinates are counted from the top-left (or bottom-left) corner of the +ROI, not the original image. +@param image A pointer to the image header +@param rect The ROI rectangle + */ +CVAPI(void) cvSetImageROI( IplImage* image, CvRect rect ); + +/** @brief Resets the image ROI to include the entire image and releases the ROI structure. + +This produces a similar result to the following, but in addition it releases the ROI structure. : +@code + cvSetImageROI(image, cvRect(0, 0, image->width, image->height )); + cvSetImageCOI(image, 0); +@endcode +@param image A pointer to the image header + */ +CVAPI(void) cvResetImageROI( IplImage* image ); + +/** @brief Returns the image ROI. + +If there is no ROI set, cvRect(0,0,image-\>width,image-\>height) is returned. +@param image A pointer to the image header + */ +CVAPI(CvRect) cvGetImageROI( const IplImage* image ); + +/** @brief Creates a matrix header but does not allocate the matrix data. + +The function allocates a new matrix header and returns a pointer to it. The matrix data can then be +allocated using cvCreateData or set explicitly to user-allocated data via cvSetData. +@param rows Number of rows in the matrix +@param cols Number of columns in the matrix +@param type Type of the matrix elements, see cvCreateMat + */ +CVAPI(CvMat*) cvCreateMatHeader( int rows, int cols, int type ); + +#define CV_AUTOSTEP 0x7fffffff + +/** @brief Initializes a pre-allocated matrix header. + +This function is often used to process raw data with OpenCV matrix functions. For example, the +following code computes the matrix product of two matrices, stored as ordinary arrays: +@code + double a[] = { 1, 2, 3, 4, + 5, 6, 7, 8, + 9, 10, 11, 12 }; + + double b[] = { 1, 5, 9, + 2, 6, 10, + 3, 7, 11, + 4, 8, 12 }; + + double c[9]; + CvMat Ma, Mb, Mc ; + + cvInitMatHeader(&Ma, 3, 4, CV_64FC1, a); + cvInitMatHeader(&Mb, 4, 3, CV_64FC1, b); + cvInitMatHeader(&Mc, 3, 3, CV_64FC1, c); + + cvMatMulAdd(&Ma, &Mb, 0, &Mc); + // the c array now contains the product of a (3x4) and b (4x3) +@endcode +@param mat A pointer to the matrix header to be initialized +@param rows Number of rows in the matrix +@param cols Number of columns in the matrix +@param type Type of the matrix elements, see cvCreateMat . +@param data Optional: data pointer assigned to the matrix header +@param step Optional: full row width in bytes of the assigned data. By default, the minimal +possible step is used which assumes there are no gaps between subsequent rows of the matrix. + */ +CVAPI(CvMat*) cvInitMatHeader( CvMat* mat, int rows, int cols, + int type, void* data CV_DEFAULT(NULL), + int step CV_DEFAULT(CV_AUTOSTEP) ); + +/** @brief Creates a matrix header and allocates the matrix data. + +The function call is equivalent to the following code: +@code + CvMat* mat = cvCreateMatHeader(rows, cols, type); + cvCreateData(mat); +@endcode +@param rows Number of rows in the matrix +@param cols Number of columns in the matrix +@param type The type of the matrix elements in the form +CV_\\C\ , where S=signed, U=unsigned, F=float. For +example, CV _ 8UC1 means the elements are 8-bit unsigned and the there is 1 channel, and CV _ +32SC2 means the elements are 32-bit signed and there are 2 channels. + */ +CVAPI(CvMat*) cvCreateMat( int rows, int cols, int type ); + +/** @brief Deallocates a matrix. + +The function decrements the matrix data reference counter and deallocates matrix header. If the data +reference counter is 0, it also deallocates the data. : +@code + if(*mat ) + cvDecRefData(*mat); + cvFree((void**)mat); +@endcode +@param mat Double pointer to the matrix + */ +CVAPI(void) cvReleaseMat( CvMat** mat ); + +/** @brief Decrements an array data reference counter. + +The function decrements the data reference counter in a CvMat or CvMatND if the reference counter + +pointer is not NULL. If the counter reaches zero, the data is deallocated. In the current +implementation the reference counter is not NULL only if the data was allocated using the +cvCreateData function. The counter will be NULL in other cases such as: external data was assigned +to the header using cvSetData, header is part of a larger matrix or image, or the header was +converted from an image or n-dimensional matrix header. +@param arr Pointer to an array header + */ +CV_INLINE void cvDecRefData( CvArr* arr ) +{ + if( CV_IS_MAT( arr )) + { + CvMat* mat = (CvMat*)arr; + mat->data.ptr = NULL; + if( mat->refcount != NULL && --*mat->refcount == 0 ) + cvFree( &mat->refcount ); + mat->refcount = NULL; + } + else if( CV_IS_MATND( arr )) + { + CvMatND* mat = (CvMatND*)arr; + mat->data.ptr = NULL; + if( mat->refcount != NULL && --*mat->refcount == 0 ) + cvFree( &mat->refcount ); + mat->refcount = NULL; + } +} + +/** @brief Increments array data reference counter. + +The function increments CvMat or CvMatND data reference counter and returns the new counter value if +the reference counter pointer is not NULL, otherwise it returns zero. +@param arr Array header + */ +CV_INLINE int cvIncRefData( CvArr* arr ) +{ + int refcount = 0; + if( CV_IS_MAT( arr )) + { + CvMat* mat = (CvMat*)arr; + if( mat->refcount != NULL ) + refcount = ++*mat->refcount; + } + else if( CV_IS_MATND( arr )) + { + CvMatND* mat = (CvMatND*)arr; + if( mat->refcount != NULL ) + refcount = ++*mat->refcount; + } + return refcount; +} + + +/** Creates an exact copy of the input matrix (except, may be, step value) */ +CVAPI(CvMat*) cvCloneMat( const CvMat* mat ); + + +/** @brief Returns matrix header corresponding to the rectangular sub-array of input image or matrix. + +The function returns header, corresponding to a specified rectangle of the input array. In other + +words, it allows the user to treat a rectangular part of input array as a stand-alone array. ROI is +taken into account by the function so the sub-array of ROI is actually extracted. +@param arr Input array +@param submat Pointer to the resultant sub-array header +@param rect Zero-based coordinates of the rectangle of interest + */ +CVAPI(CvMat*) cvGetSubRect( const CvArr* arr, CvMat* submat, CvRect rect ); +#define cvGetSubArr cvGetSubRect + +/** @brief Returns array row or row span. + +The function returns the header, corresponding to a specified row/row span of the input array. +cvGetRow(arr, submat, row) is a shortcut for cvGetRows(arr, submat, row, row+1). +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param start_row Zero-based index of the starting row (inclusive) of the span +@param end_row Zero-based index of the ending row (exclusive) of the span +@param delta_row Index step in the row span. That is, the function extracts every delta_row -th +row from start_row and up to (but not including) end_row . + */ +CVAPI(CvMat*) cvGetRows( const CvArr* arr, CvMat* submat, + int start_row, int end_row, + int delta_row CV_DEFAULT(1)); + +/** @overload +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param row Zero-based index of the selected row +*/ +CV_INLINE CvMat* cvGetRow( const CvArr* arr, CvMat* submat, int row ) +{ + return cvGetRows( arr, submat, row, row + 1, 1 ); +} + + +/** @brief Returns one of more array columns. + +The function returns the header, corresponding to a specified column span of the input array. That + +is, no data is copied. Therefore, any modifications of the submatrix will affect the original array. +If you need to copy the columns, use cvCloneMat. cvGetCol(arr, submat, col) is a shortcut for +cvGetCols(arr, submat, col, col+1). +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param start_col Zero-based index of the starting column (inclusive) of the span +@param end_col Zero-based index of the ending column (exclusive) of the span + */ +CVAPI(CvMat*) cvGetCols( const CvArr* arr, CvMat* submat, + int start_col, int end_col ); + +/** @overload +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param col Zero-based index of the selected column +*/ +CV_INLINE CvMat* cvGetCol( const CvArr* arr, CvMat* submat, int col ) +{ + return cvGetCols( arr, submat, col, col + 1 ); +} + +/** @brief Returns one of array diagonals. + +The function returns the header, corresponding to a specified diagonal of the input array. +@param arr Input array +@param submat Pointer to the resulting sub-array header +@param diag Index of the array diagonal. Zero value corresponds to the main diagonal, -1 +corresponds to the diagonal above the main, 1 corresponds to the diagonal below the main, and so +forth. + */ +CVAPI(CvMat*) cvGetDiag( const CvArr* arr, CvMat* submat, + int diag CV_DEFAULT(0)); + +/** low-level scalar <-> raw data conversion functions */ +CVAPI(void) cvScalarToRawData( const CvScalar* scalar, void* data, int type, + int extend_to_12 CV_DEFAULT(0) ); + +CVAPI(void) cvRawDataToScalar( const void* data, int type, CvScalar* scalar ); + +/** @brief Creates a new matrix header but does not allocate the matrix data. + +The function allocates a header for a multi-dimensional dense array. The array data can further be +allocated using cvCreateData or set explicitly to user-allocated data via cvSetData. +@param dims Number of array dimensions +@param sizes Array of dimension sizes +@param type Type of array elements, see cvCreateMat + */ +CVAPI(CvMatND*) cvCreateMatNDHeader( int dims, const int* sizes, int type ); + +/** @brief Creates the header and allocates the data for a multi-dimensional dense array. + +This function call is equivalent to the following code: +@code + CvMatND* mat = cvCreateMatNDHeader(dims, sizes, type); + cvCreateData(mat); +@endcode +@param dims Number of array dimensions. This must not exceed CV_MAX_DIM (32 by default, but can be +changed at build time). +@param sizes Array of dimension sizes. +@param type Type of array elements, see cvCreateMat . + */ +CVAPI(CvMatND*) cvCreateMatND( int dims, const int* sizes, int type ); + +/** @brief Initializes a pre-allocated multi-dimensional array header. + +@param mat A pointer to the array header to be initialized +@param dims The number of array dimensions +@param sizes An array of dimension sizes +@param type Type of array elements, see cvCreateMat +@param data Optional data pointer assigned to the matrix header + */ +CVAPI(CvMatND*) cvInitMatNDHeader( CvMatND* mat, int dims, const int* sizes, + int type, void* data CV_DEFAULT(NULL) ); + +/** @brief Deallocates a multi-dimensional array. + +The function decrements the array data reference counter and releases the array header. If the +reference counter reaches 0, it also deallocates the data. : +@code + if(*mat ) + cvDecRefData(*mat); + cvFree((void**)mat); +@endcode +@param mat Double pointer to the array + */ +CV_INLINE void cvReleaseMatND( CvMatND** mat ) +{ + cvReleaseMat( (CvMat**)mat ); +} + +/** Creates a copy of CvMatND (except, may be, steps) */ +CVAPI(CvMatND*) cvCloneMatND( const CvMatND* mat ); + +/** @brief Creates sparse array. + +The function allocates a multi-dimensional sparse array. Initially the array contain no elements, +that is PtrND and other related functions will return 0 for every index. +@param dims Number of array dimensions. In contrast to the dense matrix, the number of dimensions is +practically unlimited (up to \f$2^{16}\f$ ). +@param sizes Array of dimension sizes +@param type Type of array elements. The same as for CvMat + */ +CVAPI(CvSparseMat*) cvCreateSparseMat( int dims, const int* sizes, int type ); + +/** @brief Deallocates sparse array. + +The function releases the sparse array and clears the array pointer upon exit. +@param mat Double pointer to the array + */ +CVAPI(void) cvReleaseSparseMat( CvSparseMat** mat ); + +/** Creates a copy of CvSparseMat (except, may be, zero items) */ +CVAPI(CvSparseMat*) cvCloneSparseMat( const CvSparseMat* mat ); + +/** @brief Initializes sparse array elements iterator. + +The function initializes iterator of sparse array elements and returns pointer to the first element, +or NULL if the array is empty. +@param mat Input array +@param mat_iterator Initialized iterator + */ +CVAPI(CvSparseNode*) cvInitSparseMatIterator( const CvSparseMat* mat, + CvSparseMatIterator* mat_iterator ); + +/** @brief Returns the next sparse matrix element + +The function moves iterator to the next sparse matrix element and returns pointer to it. In the +current version there is no any particular order of the elements, because they are stored in the +hash table. The sample below demonstrates how to iterate through the sparse matrix: +@code + // print all the non-zero sparse matrix elements and compute their sum + double sum = 0; + int i, dims = cvGetDims(sparsemat); + CvSparseMatIterator it; + CvSparseNode* node = cvInitSparseMatIterator(sparsemat, &it); + + for(; node != 0; node = cvGetNextSparseNode(&it)) + { + int* idx = CV_NODE_IDX(array, node); + float val = *(float*)CV_NODE_VAL(array, node); + printf("M"); + for(i = 0; i < dims; i++ ) + printf("[%d]", idx[i]); + printf("=%g\n", val); + + sum += val; + } + + printf("nTotal sum = %g\n", sum); +@endcode +@param mat_iterator Sparse array iterator + */ +CV_INLINE CvSparseNode* cvGetNextSparseNode( CvSparseMatIterator* mat_iterator ) +{ + if( mat_iterator->node->next ) + return mat_iterator->node = mat_iterator->node->next; + else + { + int idx; + for( idx = ++mat_iterator->curidx; idx < mat_iterator->mat->hashsize; idx++ ) + { + CvSparseNode* node = (CvSparseNode*)mat_iterator->mat->hashtable[idx]; + if( node ) + { + mat_iterator->curidx = idx; + return mat_iterator->node = node; + } + } + return NULL; + } +} + + +#define CV_MAX_ARR 10 + +/** matrix iterator: used for n-ary operations on dense arrays */ +typedef struct CvNArrayIterator +{ + int count; /**< number of arrays */ + int dims; /**< number of dimensions to iterate */ + CvSize size; /**< maximal common linear size: { width = size, height = 1 } */ + uchar* ptr[CV_MAX_ARR]; /**< pointers to the array slices */ + int stack[CV_MAX_DIM]; /**< for internal use */ + CvMatND* hdr[CV_MAX_ARR]; /**< pointers to the headers of the + matrices that are processed */ +} +CvNArrayIterator; + +#define CV_NO_DEPTH_CHECK 1 +#define CV_NO_CN_CHECK 2 +#define CV_NO_SIZE_CHECK 4 + +/** initializes iterator that traverses through several arrays simultaneously + (the function together with cvNextArraySlice is used for + N-ari element-wise operations) */ +CVAPI(int) cvInitNArrayIterator( int count, CvArr** arrs, + const CvArr* mask, CvMatND* stubs, + CvNArrayIterator* array_iterator, + int flags CV_DEFAULT(0) ); + +/** returns zero value if iteration is finished, non-zero (slice length) otherwise */ +CVAPI(int) cvNextNArraySlice( CvNArrayIterator* array_iterator ); + + +/** @brief Returns type of array elements. + +The function returns type of the array elements. In the case of IplImage the type is converted to +CvMat-like representation. For example, if the image has been created as: +@code + IplImage* img = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3); +@endcode +The code cvGetElemType(img) will return CV_8UC3. +@param arr Input array + */ +CVAPI(int) cvGetElemType( const CvArr* arr ); + +/** @brief Return number of array dimensions + +The function returns the array dimensionality and the array of dimension sizes. In the case of +IplImage or CvMat it always returns 2 regardless of number of image/matrix rows. For example, the +following code calculates total number of array elements: +@code + int sizes[CV_MAX_DIM]; + int i, total = 1; + int dims = cvGetDims(arr, size); + for(i = 0; i < dims; i++ ) + total *= sizes[i]; +@endcode +@param arr Input array +@param sizes Optional output vector of the array dimension sizes. For 2d arrays the number of rows +(height) goes first, number of columns (width) next. + */ +CVAPI(int) cvGetDims( const CvArr* arr, int* sizes CV_DEFAULT(NULL) ); + + +/** @brief Returns array size along the specified dimension. + +@param arr Input array +@param index Zero-based dimension index (for matrices 0 means number of rows, 1 means number of +columns; for images 0 means height, 1 means width) + */ +CVAPI(int) cvGetDimSize( const CvArr* arr, int index ); + + +/** @brief Return pointer to a particular array element. + +The functions return a pointer to a specific array element. Number of array dimension should match +to the number of indices passed to the function except for cvPtr1D function that can be used for +sequential access to 1D, 2D or nD dense arrays. + +The functions can be used for sparse arrays as well - if the requested node does not exist they +create it and set it to zero. + +All these as well as other functions accessing array elements ( cvGetND , cvGetRealND , cvSet +, cvSetND , cvSetRealND ) raise an error in case if the element index is out of range. +@param arr Input array +@param idx0 The first zero-based component of the element index +@param type Optional output parameter: type of matrix elements + */ +CVAPI(uchar*) cvPtr1D( const CvArr* arr, int idx0, int* type CV_DEFAULT(NULL)); +/** @overload */ +CVAPI(uchar*) cvPtr2D( const CvArr* arr, int idx0, int idx1, int* type CV_DEFAULT(NULL) ); +/** @overload */ +CVAPI(uchar*) cvPtr3D( const CvArr* arr, int idx0, int idx1, int idx2, + int* type CV_DEFAULT(NULL)); +/** @overload +@param arr Input array +@param idx Array of the element indices +@param type Optional output parameter: type of matrix elements +@param create_node Optional input parameter for sparse matrices. Non-zero value of the parameter +means that the requested element is created if it does not exist already. +@param precalc_hashval Optional input parameter for sparse matrices. If the pointer is not NULL, +the function does not recalculate the node hash value, but takes it from the specified location. +It is useful for speeding up pair-wise operations (TODO: provide an example) +*/ +CVAPI(uchar*) cvPtrND( const CvArr* arr, const int* idx, int* type CV_DEFAULT(NULL), + int create_node CV_DEFAULT(1), + unsigned* precalc_hashval CV_DEFAULT(NULL)); + +/** @brief Return a specific array element. + +The functions return a specific array element. In the case of a sparse array the functions return 0 +if the requested node does not exist (no new node is created by the functions). +@param arr Input array +@param idx0 The first zero-based component of the element index + */ +CVAPI(CvScalar) cvGet1D( const CvArr* arr, int idx0 ); +/** @overload */ +CVAPI(CvScalar) cvGet2D( const CvArr* arr, int idx0, int idx1 ); +/** @overload */ +CVAPI(CvScalar) cvGet3D( const CvArr* arr, int idx0, int idx1, int idx2 ); +/** @overload +@param arr Input array +@param idx Array of the element indices +*/ +CVAPI(CvScalar) cvGetND( const CvArr* arr, const int* idx ); + +/** @brief Return a specific element of single-channel 1D, 2D, 3D or nD array. + +Returns a specific element of a single-channel array. If the array has multiple channels, a runtime +error is raised. Note that Get?D functions can be used safely for both single-channel and +multiple-channel arrays though they are a bit slower. + +In the case of a sparse array the functions return 0 if the requested node does not exist (no new +node is created by the functions). +@param arr Input array. Must have a single channel. +@param idx0 The first zero-based component of the element index + */ +CVAPI(double) cvGetReal1D( const CvArr* arr, int idx0 ); +/** @overload */ +CVAPI(double) cvGetReal2D( const CvArr* arr, int idx0, int idx1 ); +/** @overload */ +CVAPI(double) cvGetReal3D( const CvArr* arr, int idx0, int idx1, int idx2 ); +/** @overload +@param arr Input array. Must have a single channel. +@param idx Array of the element indices +*/ +CVAPI(double) cvGetRealND( const CvArr* arr, const int* idx ); + +/** @brief Change the particular array element. + +The functions assign the new value to a particular array element. In the case of a sparse array the +functions create the node if it does not exist yet. +@param arr Input array +@param idx0 The first zero-based component of the element index +@param value The assigned value + */ +CVAPI(void) cvSet1D( CvArr* arr, int idx0, CvScalar value ); +/** @overload */ +CVAPI(void) cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value ); +/** @overload */ +CVAPI(void) cvSet3D( CvArr* arr, int idx0, int idx1, int idx2, CvScalar value ); +/** @overload +@param arr Input array +@param idx Array of the element indices +@param value The assigned value +*/ +CVAPI(void) cvSetND( CvArr* arr, const int* idx, CvScalar value ); + +/** @brief Change a specific array element. + +The functions assign a new value to a specific element of a single-channel array. If the array has +multiple channels, a runtime error is raised. Note that the Set\*D function can be used safely for +both single-channel and multiple-channel arrays, though they are a bit slower. + +In the case of a sparse array the functions create the node if it does not yet exist. +@param arr Input array +@param idx0 The first zero-based component of the element index +@param value The assigned value + */ +CVAPI(void) cvSetReal1D( CvArr* arr, int idx0, double value ); +/** @overload */ +CVAPI(void) cvSetReal2D( CvArr* arr, int idx0, int idx1, double value ); +/** @overload */ +CVAPI(void) cvSetReal3D( CvArr* arr, int idx0, + int idx1, int idx2, double value ); +/** @overload +@param arr Input array +@param idx Array of the element indices +@param value The assigned value +*/ +CVAPI(void) cvSetRealND( CvArr* arr, const int* idx, double value ); + +/** clears element of ND dense array, + in case of sparse arrays it deletes the specified node */ +CVAPI(void) cvClearND( CvArr* arr, const int* idx ); + +/** @brief Returns matrix header for arbitrary array. + +The function returns a matrix header for the input array that can be a matrix - CvMat, an image - +IplImage, or a multi-dimensional dense array - CvMatND (the third option is allowed only if +allowND != 0) . In the case of matrix the function simply returns the input pointer. In the case of +IplImage\* or CvMatND it initializes the header structure with parameters of the current image ROI +and returns &header. Because COI is not supported by CvMat, it is returned separately. + +The function provides an easy way to handle both types of arrays - IplImage and CvMat using the same +code. Input array must have non-zero data pointer, otherwise the function will report an error. + +@note If the input array is IplImage with planar data layout and COI set, the function returns the +pointer to the selected plane and COI == 0. This feature allows user to process IplImage structures +with planar data layout, even though OpenCV does not support such images. +@param arr Input array +@param header Pointer to CvMat structure used as a temporary buffer +@param coi Optional output parameter for storing COI +@param allowND If non-zero, the function accepts multi-dimensional dense arrays (CvMatND\*) and +returns 2D matrix (if CvMatND has two dimensions) or 1D matrix (when CvMatND has 1 dimension or +more than 2 dimensions). The CvMatND array must be continuous. +@sa cvGetImage, cvarrToMat. + */ +CVAPI(CvMat*) cvGetMat( const CvArr* arr, CvMat* header, + int* coi CV_DEFAULT(NULL), + int allowND CV_DEFAULT(0)); + +/** @brief Returns image header for arbitrary array. + +The function returns the image header for the input array that can be a matrix (CvMat) or image +(IplImage). In the case of an image the function simply returns the input pointer. In the case of +CvMat it initializes an image_header structure with the parameters of the input matrix. Note that +if we transform IplImage to CvMat using cvGetMat and then transform CvMat back to IplImage using +this function, we will get different headers if the ROI is set in the original image. +@param arr Input array +@param image_header Pointer to IplImage structure used as a temporary buffer + */ +CVAPI(IplImage*) cvGetImage( const CvArr* arr, IplImage* image_header ); + + +/** @brief Changes the shape of a multi-dimensional array without copying the data. + +The function is an advanced version of cvReshape that can work with multi-dimensional arrays as +well (though it can work with ordinary images and matrices) and change the number of dimensions. + +Below are the two samples from the cvReshape description rewritten using cvReshapeMatND: +@code + IplImage* color_img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3); + IplImage gray_img_hdr, *gray_img; + gray_img = (IplImage*)cvReshapeMatND(color_img, sizeof(gray_img_hdr), &gray_img_hdr, 1, 0, 0); + ... + int size[] = { 2, 2, 2 }; + CvMatND* mat = cvCreateMatND(3, size, CV_32F); + CvMat row_header, *row; + row = (CvMat*)cvReshapeMatND(mat, sizeof(row_header), &row_header, 0, 1, 0); +@endcode +In C, the header file for this function includes a convenient macro cvReshapeND that does away with +the sizeof_header parameter. So, the lines containing the call to cvReshapeMatND in the examples +may be replaced as follow: +@code + gray_img = (IplImage*)cvReshapeND(color_img, &gray_img_hdr, 1, 0, 0); + ... + row = (CvMat*)cvReshapeND(mat, &row_header, 0, 1, 0); +@endcode +@param arr Input array +@param sizeof_header Size of output header to distinguish between IplImage, CvMat and CvMatND +output headers +@param header Output header to be filled +@param new_cn New number of channels. new_cn = 0 means that the number of channels remains +unchanged. +@param new_dims New number of dimensions. new_dims = 0 means that the number of dimensions +remains the same. +@param new_sizes Array of new dimension sizes. Only new_dims-1 values are used, because the +total number of elements must remain the same. Thus, if new_dims = 1, new_sizes array is not +used. + */ +CVAPI(CvArr*) cvReshapeMatND( const CvArr* arr, + int sizeof_header, CvArr* header, + int new_cn, int new_dims, int* new_sizes ); + +#define cvReshapeND( arr, header, new_cn, new_dims, new_sizes ) \ + cvReshapeMatND( (arr), sizeof(*(header)), (header), \ + (new_cn), (new_dims), (new_sizes)) + +/** @brief Changes shape of matrix/image without copying data. + +The function initializes the CvMat header so that it points to the same data as the original array +but has a different shape - different number of channels, different number of rows, or both. + +The following example code creates one image buffer and two image headers, the first is for a +320x240x3 image and the second is for a 960x240x1 image: +@code + IplImage* color_img = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 3); + CvMat gray_mat_hdr; + IplImage gray_img_hdr, *gray_img; + cvReshape(color_img, &gray_mat_hdr, 1); + gray_img = cvGetImage(&gray_mat_hdr, &gray_img_hdr); +@endcode +And the next example converts a 3x3 matrix to a single 1x9 vector: +@code + CvMat* mat = cvCreateMat(3, 3, CV_32F); + CvMat row_header, *row; + row = cvReshape(mat, &row_header, 0, 1); +@endcode +@param arr Input array +@param header Output header to be filled +@param new_cn New number of channels. 'new_cn = 0' means that the number of channels remains +unchanged. +@param new_rows New number of rows. 'new_rows = 0' means that the number of rows remains +unchanged unless it needs to be changed according to new_cn value. +*/ +CVAPI(CvMat*) cvReshape( const CvArr* arr, CvMat* header, + int new_cn, int new_rows CV_DEFAULT(0) ); + +/** Repeats source 2d array several times in both horizontal and + vertical direction to fill destination array */ +CVAPI(void) cvRepeat( const CvArr* src, CvArr* dst ); + +/** @brief Allocates array data + +The function allocates image, matrix or multi-dimensional dense array data. Note that in the case of +matrix types OpenCV allocation functions are used. In the case of IplImage they are used unless +CV_TURN_ON_IPL_COMPATIBILITY() has been called before. In the latter case IPL functions are used +to allocate the data. +@param arr Array header + */ +CVAPI(void) cvCreateData( CvArr* arr ); + +/** @brief Releases array data. + +The function releases the array data. In the case of CvMat or CvMatND it simply calls +cvDecRefData(), that is the function can not deallocate external data. See also the note to +cvCreateData . +@param arr Array header + */ +CVAPI(void) cvReleaseData( CvArr* arr ); + +/** @brief Assigns user data to the array header. + +The function assigns user data to the array header. Header should be initialized before using +cvCreateMatHeader, cvCreateImageHeader, cvCreateMatNDHeader, cvInitMatHeader, +cvInitImageHeader or cvInitMatNDHeader. +@param arr Array header +@param data User data +@param step Full row length in bytes + */ +CVAPI(void) cvSetData( CvArr* arr, void* data, int step ); + +/** @brief Retrieves low-level information about the array. + +The function fills output variables with low-level information about the array data. All output + +parameters are optional, so some of the pointers may be set to NULL. If the array is IplImage with +ROI set, the parameters of ROI are returned. + +The following example shows how to get access to array elements. It computes absolute values of the +array elements : +@code + float* data; + int step; + CvSize size; + + cvGetRawData(array, (uchar**)&data, &step, &size); + step /= sizeof(data[0]); + + for(int y = 0; y < size.height; y++, data += step ) + for(int x = 0; x < size.width; x++ ) + data[x] = (float)fabs(data[x]); +@endcode +@param arr Array header +@param data Output pointer to the whole image origin or ROI origin if ROI is set +@param step Output full row length in bytes +@param roi_size Output ROI size + */ +CVAPI(void) cvGetRawData( const CvArr* arr, uchar** data, + int* step CV_DEFAULT(NULL), + CvSize* roi_size CV_DEFAULT(NULL)); + +/** @brief Returns size of matrix or image ROI. + +The function returns number of rows (CvSize::height) and number of columns (CvSize::width) of the +input matrix or image. In the case of image the size of ROI is returned. +@param arr array header + */ +CVAPI(CvSize) cvGetSize( const CvArr* arr ); + +/** @brief Copies one array to another. + +The function copies selected elements from an input array to an output array: + +\f[\texttt{dst} (I)= \texttt{src} (I) \quad \text{if} \quad \texttt{mask} (I) \ne 0.\f] + +If any of the passed arrays is of IplImage type, then its ROI and COI fields are used. Both arrays +must have the same type, the same number of dimensions, and the same size. The function can also +copy sparse arrays (mask is not supported in this case). +@param src The source array +@param dst The destination array +@param mask Operation mask, 8-bit single channel array; specifies elements of the destination array +to be changed + */ +CVAPI(void) cvCopy( const CvArr* src, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Sets every element of an array to a given value. + +The function copies the scalar value to every selected element of the destination array: +\f[\texttt{arr} (I)= \texttt{value} \quad \text{if} \quad \texttt{mask} (I) \ne 0\f] +If array arr is of IplImage type, then is ROI used, but COI must not be set. +@param arr The destination array +@param value Fill value +@param mask Operation mask, 8-bit single channel array; specifies elements of the destination +array to be changed + */ +CVAPI(void) cvSet( CvArr* arr, CvScalar value, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Clears the array. + +The function clears the array. In the case of dense arrays (CvMat, CvMatND or IplImage), +cvZero(array) is equivalent to cvSet(array,cvScalarAll(0),0). In the case of sparse arrays all the +elements are removed. +@param arr Array to be cleared + */ +CVAPI(void) cvSetZero( CvArr* arr ); +#define cvZero cvSetZero + + +/** Splits a multi-channel array into the set of single-channel arrays or + extracts particular [color] plane */ +CVAPI(void) cvSplit( const CvArr* src, CvArr* dst0, CvArr* dst1, + CvArr* dst2, CvArr* dst3 ); + +/** Merges a set of single-channel arrays into the single multi-channel array + or inserts one particular [color] plane to the array */ +CVAPI(void) cvMerge( const CvArr* src0, const CvArr* src1, + const CvArr* src2, const CvArr* src3, + CvArr* dst ); + +/** Copies several channels from input arrays to + certain channels of output arrays */ +CVAPI(void) cvMixChannels( const CvArr** src, int src_count, + CvArr** dst, int dst_count, + const int* from_to, int pair_count ); + +/** @brief Converts one array to another with optional linear transformation. + +The function has several different purposes, and thus has several different names. It copies one +array to another with optional scaling, which is performed first, and/or optional type conversion, +performed after: + +\f[\texttt{dst} (I) = \texttt{scale} \texttt{src} (I) + ( \texttt{shift} _0, \texttt{shift} _1,...)\f] + +All the channels of multi-channel arrays are processed independently. + +The type of conversion is done with rounding and saturation, that is if the result of scaling + +conversion can not be represented exactly by a value of the destination array element type, it is +set to the nearest representable value on the real axis. +@param src Source array +@param dst Destination array +@param scale Scale factor +@param shift Value added to the scaled source array elements + */ +CVAPI(void) cvConvertScale( const CvArr* src, CvArr* dst, + double scale CV_DEFAULT(1), + double shift CV_DEFAULT(0) ); +#define cvCvtScale cvConvertScale +#define cvScale cvConvertScale +#define cvConvert( src, dst ) cvConvertScale( (src), (dst), 1, 0 ) + + +/** Performs linear transformation on every source array element, + stores absolute value of the result: + dst(x,y,c) = abs(scale*src(x,y,c)+shift). + destination array must have 8u type. + In other cases one may use cvConvertScale + cvAbsDiffS */ +CVAPI(void) cvConvertScaleAbs( const CvArr* src, CvArr* dst, + double scale CV_DEFAULT(1), + double shift CV_DEFAULT(0) ); +#define cvCvtScaleAbs cvConvertScaleAbs + + +/** checks termination criteria validity and + sets eps to default_eps (if it is not set), + max_iter to default_max_iters (if it is not set) +*/ +CVAPI(CvTermCriteria) cvCheckTermCriteria( CvTermCriteria criteria, + double default_eps, + int default_max_iters ); + +/****************************************************************************************\ +* Arithmetic, logic and comparison operations * +\****************************************************************************************/ + +/** dst(mask) = src1(mask) + src2(mask) */ +CVAPI(void) cvAdd( const CvArr* src1, const CvArr* src2, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(mask) = src(mask) + value */ +CVAPI(void) cvAddS( const CvArr* src, CvScalar value, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(mask) = src1(mask) - src2(mask) */ +CVAPI(void) cvSub( const CvArr* src1, const CvArr* src2, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(mask) = src(mask) - value = src(mask) + (-value) */ +CV_INLINE void cvSubS( const CvArr* src, CvScalar value, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)) +{ + cvAddS( src, cvScalar( -value.val[0], -value.val[1], -value.val[2], -value.val[3]), + dst, mask ); +} + +/** dst(mask) = value - src(mask) */ +CVAPI(void) cvSubRS( const CvArr* src, CvScalar value, CvArr* dst, + const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src1(idx) * src2(idx) * scale + (scaled element-wise multiplication of 2 arrays) */ +CVAPI(void) cvMul( const CvArr* src1, const CvArr* src2, + CvArr* dst, double scale CV_DEFAULT(1) ); + +/** element-wise division/inversion with scaling: + dst(idx) = src1(idx) * scale / src2(idx) + or dst(idx) = scale / src2(idx) if src1 == 0 */ +CVAPI(void) cvDiv( const CvArr* src1, const CvArr* src2, + CvArr* dst, double scale CV_DEFAULT(1)); + +/** dst = src1 * scale + src2 */ +CVAPI(void) cvScaleAdd( const CvArr* src1, CvScalar scale, + const CvArr* src2, CvArr* dst ); +#define cvAXPY( A, real_scalar, B, C ) cvScaleAdd(A, cvRealScalar(real_scalar), B, C) + +/** dst = src1 * alpha + src2 * beta + gamma */ +CVAPI(void) cvAddWeighted( const CvArr* src1, double alpha, + const CvArr* src2, double beta, + double gamma, CvArr* dst ); + +/** @brief Calculates the dot product of two arrays in Euclidean metrics. + +The function calculates and returns the Euclidean dot product of two arrays. + +\f[src1 \bullet src2 = \sum _I ( \texttt{src1} (I) \texttt{src2} (I))\f] + +In the case of multiple channel arrays, the results for all channels are accumulated. In particular, +cvDotProduct(a,a) where a is a complex vector, will return \f$||\texttt{a}||^2\f$. The function can +process multi-dimensional arrays, row by row, layer by layer, and so on. +@param src1 The first source array +@param src2 The second source array + */ +CVAPI(double) cvDotProduct( const CvArr* src1, const CvArr* src2 ); + +/** dst(idx) = src1(idx) & src2(idx) */ +CVAPI(void) cvAnd( const CvArr* src1, const CvArr* src2, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src(idx) & value */ +CVAPI(void) cvAndS( const CvArr* src, CvScalar value, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src1(idx) | src2(idx) */ +CVAPI(void) cvOr( const CvArr* src1, const CvArr* src2, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src(idx) | value */ +CVAPI(void) cvOrS( const CvArr* src, CvScalar value, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src1(idx) ^ src2(idx) */ +CVAPI(void) cvXor( const CvArr* src1, const CvArr* src2, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = src(idx) ^ value */ +CVAPI(void) cvXorS( const CvArr* src, CvScalar value, + CvArr* dst, const CvArr* mask CV_DEFAULT(NULL)); + +/** dst(idx) = ~src(idx) */ +CVAPI(void) cvNot( const CvArr* src, CvArr* dst ); + +/** dst(idx) = lower(idx) <= src(idx) < upper(idx) */ +CVAPI(void) cvInRange( const CvArr* src, const CvArr* lower, + const CvArr* upper, CvArr* dst ); + +/** dst(idx) = lower <= src(idx) < upper */ +CVAPI(void) cvInRangeS( const CvArr* src, CvScalar lower, + CvScalar upper, CvArr* dst ); + +#define CV_CMP_EQ 0 +#define CV_CMP_GT 1 +#define CV_CMP_GE 2 +#define CV_CMP_LT 3 +#define CV_CMP_LE 4 +#define CV_CMP_NE 5 + +/** The comparison operation support single-channel arrays only. + Destination image should be 8uC1 or 8sC1 */ + +/** dst(idx) = src1(idx) _cmp_op_ src2(idx) */ +CVAPI(void) cvCmp( const CvArr* src1, const CvArr* src2, CvArr* dst, int cmp_op ); + +/** dst(idx) = src1(idx) _cmp_op_ value */ +CVAPI(void) cvCmpS( const CvArr* src, double value, CvArr* dst, int cmp_op ); + +/** dst(idx) = min(src1(idx),src2(idx)) */ +CVAPI(void) cvMin( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** dst(idx) = max(src1(idx),src2(idx)) */ +CVAPI(void) cvMax( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** dst(idx) = min(src(idx),value) */ +CVAPI(void) cvMinS( const CvArr* src, double value, CvArr* dst ); + +/** dst(idx) = max(src(idx),value) */ +CVAPI(void) cvMaxS( const CvArr* src, double value, CvArr* dst ); + +/** dst(x,y,c) = abs(src1(x,y,c) - src2(x,y,c)) */ +CVAPI(void) cvAbsDiff( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** dst(x,y,c) = abs(src(x,y,c) - value(c)) */ +CVAPI(void) cvAbsDiffS( const CvArr* src, CvArr* dst, CvScalar value ); +#define cvAbs( src, dst ) cvAbsDiffS( (src), (dst), cvScalarAll(0)) + +/****************************************************************************************\ +* Math operations * +\****************************************************************************************/ + +/** Does cartesian->polar coordinates conversion. + Either of output components (magnitude or angle) is optional */ +CVAPI(void) cvCartToPolar( const CvArr* x, const CvArr* y, + CvArr* magnitude, CvArr* angle CV_DEFAULT(NULL), + int angle_in_degrees CV_DEFAULT(0)); + +/** Does polar->cartesian coordinates conversion. + Either of output components (magnitude or angle) is optional. + If magnitude is missing it is assumed to be all 1's */ +CVAPI(void) cvPolarToCart( const CvArr* magnitude, const CvArr* angle, + CvArr* x, CvArr* y, + int angle_in_degrees CV_DEFAULT(0)); + +/** Does powering: dst(idx) = src(idx)^power */ +CVAPI(void) cvPow( const CvArr* src, CvArr* dst, double power ); + +/** Does exponention: dst(idx) = exp(src(idx)). + Overflow is not handled yet. Underflow is handled. + Maximal relative error is ~7e-6 for single-precision input */ +CVAPI(void) cvExp( const CvArr* src, CvArr* dst ); + +/** Calculates natural logarithms: dst(idx) = log(abs(src(idx))). + Logarithm of 0 gives large negative number(~-700) + Maximal relative error is ~3e-7 for single-precision output +*/ +CVAPI(void) cvLog( const CvArr* src, CvArr* dst ); + +/** Fast arctangent calculation */ +CVAPI(float) cvFastArctan( float y, float x ); + +/** Fast cubic root calculation */ +CVAPI(float) cvCbrt( float value ); + +#define CV_CHECK_RANGE 1 +#define CV_CHECK_QUIET 2 +/** Checks array values for NaNs, Infs or simply for too large numbers + (if CV_CHECK_RANGE is set). If CV_CHECK_QUIET is set, + no runtime errors is raised (function returns zero value in case of "bad" values). + Otherwise cvError is called */ +CVAPI(int) cvCheckArr( const CvArr* arr, int flags CV_DEFAULT(0), + double min_val CV_DEFAULT(0), double max_val CV_DEFAULT(0)); +#define cvCheckArray cvCheckArr + +#define CV_RAND_UNI 0 +#define CV_RAND_NORMAL 1 + +/** @brief Fills an array with random numbers and updates the RNG state. + +The function fills the destination array with uniformly or normally distributed random numbers. +@param rng CvRNG state initialized by cvRNG +@param arr The destination array +@param dist_type Distribution type +> - **CV_RAND_UNI** uniform distribution +> - **CV_RAND_NORMAL** normal or Gaussian distribution +@param param1 The first parameter of the distribution. In the case of a uniform distribution it is +the inclusive lower boundary of the random numbers range. In the case of a normal distribution it +is the mean value of the random numbers. +@param param2 The second parameter of the distribution. In the case of a uniform distribution it +is the exclusive upper boundary of the random numbers range. In the case of a normal distribution +it is the standard deviation of the random numbers. +@sa randu, randn, RNG::fill. + */ +CVAPI(void) cvRandArr( CvRNG* rng, CvArr* arr, int dist_type, + CvScalar param1, CvScalar param2 ); + +CVAPI(void) cvRandShuffle( CvArr* mat, CvRNG* rng, + double iter_factor CV_DEFAULT(1.)); + +#define CV_SORT_EVERY_ROW 0 +#define CV_SORT_EVERY_COLUMN 1 +#define CV_SORT_ASCENDING 0 +#define CV_SORT_DESCENDING 16 + +CVAPI(void) cvSort( const CvArr* src, CvArr* dst CV_DEFAULT(NULL), + CvArr* idxmat CV_DEFAULT(NULL), + int flags CV_DEFAULT(0)); + +/** Finds real roots of a cubic equation */ +CVAPI(int) cvSolveCubic( const CvMat* coeffs, CvMat* roots ); + +/** Finds all real and complex roots of a polynomial equation */ +CVAPI(void) cvSolvePoly(const CvMat* coeffs, CvMat *roots2, + int maxiter CV_DEFAULT(20), int fig CV_DEFAULT(100)); + +/****************************************************************************************\ +* Matrix operations * +\****************************************************************************************/ + +/** @brief Calculates the cross product of two 3D vectors. + +The function calculates the cross product of two 3D vectors: +\f[\texttt{dst} = \texttt{src1} \times \texttt{src2}\f] +or: +\f[\begin{array}{l} \texttt{dst} _1 = \texttt{src1} _2 \texttt{src2} _3 - \texttt{src1} _3 \texttt{src2} _2 \\ \texttt{dst} _2 = \texttt{src1} _3 \texttt{src2} _1 - \texttt{src1} _1 \texttt{src2} _3 \\ \texttt{dst} _3 = \texttt{src1} _1 \texttt{src2} _2 - \texttt{src1} _2 \texttt{src2} _1 \end{array}\f] +@param src1 The first source vector +@param src2 The second source vector +@param dst The destination vector + */ +CVAPI(void) cvCrossProduct( const CvArr* src1, const CvArr* src2, CvArr* dst ); + +/** Matrix transform: dst = A*B + C, C is optional */ +#define cvMatMulAdd( src1, src2, src3, dst ) cvGEMM( (src1), (src2), 1., (src3), 1., (dst), 0 ) +#define cvMatMul( src1, src2, dst ) cvMatMulAdd( (src1), (src2), NULL, (dst)) + +#define CV_GEMM_A_T 1 +#define CV_GEMM_B_T 2 +#define CV_GEMM_C_T 4 +/** Extended matrix transform: + dst = alpha*op(A)*op(B) + beta*op(C), where op(X) is X or X^T */ +CVAPI(void) cvGEMM( const CvArr* src1, const CvArr* src2, double alpha, + const CvArr* src3, double beta, CvArr* dst, + int tABC CV_DEFAULT(0)); +#define cvMatMulAddEx cvGEMM + +/** Transforms each element of source array and stores + resultant vectors in destination array */ +CVAPI(void) cvTransform( const CvArr* src, CvArr* dst, + const CvMat* transmat, + const CvMat* shiftvec CV_DEFAULT(NULL)); +#define cvMatMulAddS cvTransform + +/** Does perspective transform on every element of input array */ +CVAPI(void) cvPerspectiveTransform( const CvArr* src, CvArr* dst, + const CvMat* mat ); + +/** Calculates (A-delta)*(A-delta)^T (order=0) or (A-delta)^T*(A-delta) (order=1) */ +CVAPI(void) cvMulTransposed( const CvArr* src, CvArr* dst, int order, + const CvArr* delta CV_DEFAULT(NULL), + double scale CV_DEFAULT(1.) ); + +/** Tranposes matrix. Square matrices can be transposed in-place */ +CVAPI(void) cvTranspose( const CvArr* src, CvArr* dst ); +#define cvT cvTranspose + +/** Completes the symmetric matrix from the lower (LtoR=0) or from the upper (LtoR!=0) part */ +CVAPI(void) cvCompleteSymm( CvMat* matrix, int LtoR CV_DEFAULT(0) ); + +/** Mirror array data around horizontal (flip=0), + vertical (flip=1) or both(flip=-1) axises: + cvFlip(src) flips images vertically and sequences horizontally (inplace) */ +CVAPI(void) cvFlip( const CvArr* src, CvArr* dst CV_DEFAULT(NULL), + int flip_mode CV_DEFAULT(0)); +#define cvMirror cvFlip + + +#define CV_SVD_MODIFY_A 1 +#define CV_SVD_U_T 2 +#define CV_SVD_V_T 4 + +/** Performs Singular Value Decomposition of a matrix */ +CVAPI(void) cvSVD( CvArr* A, CvArr* W, CvArr* U CV_DEFAULT(NULL), + CvArr* V CV_DEFAULT(NULL), int flags CV_DEFAULT(0)); + +/** Performs Singular Value Back Substitution (solves A*X = B): + flags must be the same as in cvSVD */ +CVAPI(void) cvSVBkSb( const CvArr* W, const CvArr* U, + const CvArr* V, const CvArr* B, + CvArr* X, int flags ); + +#define CV_LU 0 +#define CV_SVD 1 +#define CV_SVD_SYM 2 +#define CV_CHOLESKY 3 +#define CV_QR 4 +#define CV_NORMAL 16 + +/** Inverts matrix */ +CVAPI(double) cvInvert( const CvArr* src, CvArr* dst, + int method CV_DEFAULT(CV_LU)); +#define cvInv cvInvert + +/** Solves linear system (src1)*(dst) = (src2) + (returns 0 if src1 is a singular and CV_LU method is used) */ +CVAPI(int) cvSolve( const CvArr* src1, const CvArr* src2, CvArr* dst, + int method CV_DEFAULT(CV_LU)); + +/** Calculates determinant of input matrix */ +CVAPI(double) cvDet( const CvArr* mat ); + +/** Calculates trace of the matrix (sum of elements on the main diagonal) */ +CVAPI(CvScalar) cvTrace( const CvArr* mat ); + +/** Finds eigen values and vectors of a symmetric matrix */ +CVAPI(void) cvEigenVV( CvArr* mat, CvArr* evects, CvArr* evals, + double eps CV_DEFAULT(0), + int lowindex CV_DEFAULT(-1), + int highindex CV_DEFAULT(-1)); + +///* Finds selected eigen values and vectors of a symmetric matrix */ +//CVAPI(void) cvSelectedEigenVV( CvArr* mat, CvArr* evects, CvArr* evals, +// int lowindex, int highindex ); + +/** Makes an identity matrix (mat_ij = i == j) */ +CVAPI(void) cvSetIdentity( CvArr* mat, CvScalar value CV_DEFAULT(cvRealScalar(1)) ); + +/** Fills matrix with given range of numbers */ +CVAPI(CvArr*) cvRange( CvArr* mat, double start, double end ); + +/** @anchor core_c_CovarFlags +@name Flags for cvCalcCovarMatrix +@see cvCalcCovarMatrix + @{ +*/ + +/** flag for cvCalcCovarMatrix, transpose([v1-avg, v2-avg,...]) * [v1-avg,v2-avg,...] */ +#define CV_COVAR_SCRAMBLED 0 + +/** flag for cvCalcCovarMatrix, [v1-avg, v2-avg,...] * transpose([v1-avg,v2-avg,...]) */ +#define CV_COVAR_NORMAL 1 + +/** flag for cvCalcCovarMatrix, do not calc average (i.e. mean vector) - use the input vector instead + (useful for calculating covariance matrix by parts) */ +#define CV_COVAR_USE_AVG 2 + +/** flag for cvCalcCovarMatrix, scale the covariance matrix coefficients by number of the vectors */ +#define CV_COVAR_SCALE 4 + +/** flag for cvCalcCovarMatrix, all the input vectors are stored in a single matrix, as its rows */ +#define CV_COVAR_ROWS 8 + +/** flag for cvCalcCovarMatrix, all the input vectors are stored in a single matrix, as its columns */ +#define CV_COVAR_COLS 16 + +/** @} */ + +/** Calculates covariation matrix for a set of vectors +@see @ref core_c_CovarFlags "flags" +*/ +CVAPI(void) cvCalcCovarMatrix( const CvArr** vects, int count, + CvArr* cov_mat, CvArr* avg, int flags ); + +#define CV_PCA_DATA_AS_ROW 0 +#define CV_PCA_DATA_AS_COL 1 +#define CV_PCA_USE_AVG 2 +CVAPI(void) cvCalcPCA( const CvArr* data, CvArr* mean, + CvArr* eigenvals, CvArr* eigenvects, int flags ); + +CVAPI(void) cvProjectPCA( const CvArr* data, const CvArr* mean, + const CvArr* eigenvects, CvArr* result ); + +CVAPI(void) cvBackProjectPCA( const CvArr* proj, const CvArr* mean, + const CvArr* eigenvects, CvArr* result ); + +/** Calculates Mahalanobis(weighted) distance */ +CVAPI(double) cvMahalanobis( const CvArr* vec1, const CvArr* vec2, const CvArr* mat ); +#define cvMahalonobis cvMahalanobis + +/****************************************************************************************\ +* Array Statistics * +\****************************************************************************************/ + +/** Finds sum of array elements */ +CVAPI(CvScalar) cvSum( const CvArr* arr ); + +/** Calculates number of non-zero pixels */ +CVAPI(int) cvCountNonZero( const CvArr* arr ); + +/** Calculates mean value of array elements */ +CVAPI(CvScalar) cvAvg( const CvArr* arr, const CvArr* mask CV_DEFAULT(NULL) ); + +/** Calculates mean and standard deviation of pixel values */ +CVAPI(void) cvAvgSdv( const CvArr* arr, CvScalar* mean, CvScalar* std_dev, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** Finds global minimum, maximum and their positions */ +CVAPI(void) cvMinMaxLoc( const CvArr* arr, double* min_val, double* max_val, + CvPoint* min_loc CV_DEFAULT(NULL), + CvPoint* max_loc CV_DEFAULT(NULL), + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @anchor core_c_NormFlags + @name Flags for cvNorm and cvNormalize + @{ +*/ +#define CV_C 1 +#define CV_L1 2 +#define CV_L2 4 +#define CV_NORM_MASK 7 +#define CV_RELATIVE 8 +#define CV_DIFF 16 +#define CV_MINMAX 32 + +#define CV_DIFF_C (CV_DIFF | CV_C) +#define CV_DIFF_L1 (CV_DIFF | CV_L1) +#define CV_DIFF_L2 (CV_DIFF | CV_L2) +#define CV_RELATIVE_C (CV_RELATIVE | CV_C) +#define CV_RELATIVE_L1 (CV_RELATIVE | CV_L1) +#define CV_RELATIVE_L2 (CV_RELATIVE | CV_L2) +/** @} */ + +/** Finds norm, difference norm or relative difference norm for an array (or two arrays) +@see ref core_c_NormFlags "flags" +*/ +CVAPI(double) cvNorm( const CvArr* arr1, const CvArr* arr2 CV_DEFAULT(NULL), + int norm_type CV_DEFAULT(CV_L2), + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @see ref core_c_NormFlags "flags" */ +CVAPI(void) cvNormalize( const CvArr* src, CvArr* dst, + double a CV_DEFAULT(1.), double b CV_DEFAULT(0.), + int norm_type CV_DEFAULT(CV_L2), + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @anchor core_c_ReduceFlags + @name Flags for cvReduce + @{ +*/ +#define CV_REDUCE_SUM 0 +#define CV_REDUCE_AVG 1 +#define CV_REDUCE_MAX 2 +#define CV_REDUCE_MIN 3 +/** @} */ + +/** @see @ref core_c_ReduceFlags "flags" */ +CVAPI(void) cvReduce( const CvArr* src, CvArr* dst, int dim CV_DEFAULT(-1), + int op CV_DEFAULT(CV_REDUCE_SUM) ); + +/****************************************************************************************\ +* Discrete Linear Transforms and Related Functions * +\****************************************************************************************/ + +/** @anchor core_c_DftFlags + @name Flags for cvDFT, cvDCT and cvMulSpectrums + @{ + */ +#define CV_DXT_FORWARD 0 +#define CV_DXT_INVERSE 1 +#define CV_DXT_SCALE 2 /**< divide result by size of array */ +#define CV_DXT_INV_SCALE (CV_DXT_INVERSE + CV_DXT_SCALE) +#define CV_DXT_INVERSE_SCALE CV_DXT_INV_SCALE +#define CV_DXT_ROWS 4 /**< transform each row individually */ +#define CV_DXT_MUL_CONJ 8 /**< conjugate the second argument of cvMulSpectrums */ +/** @} */ + +/** Discrete Fourier Transform: + complex->complex, + real->ccs (forward), + ccs->real (inverse) +@see core_c_DftFlags "flags" +*/ +CVAPI(void) cvDFT( const CvArr* src, CvArr* dst, int flags, + int nonzero_rows CV_DEFAULT(0) ); +#define cvFFT cvDFT + +/** Multiply results of DFTs: DFT(X)*DFT(Y) or DFT(X)*conj(DFT(Y)) +@see core_c_DftFlags "flags" +*/ +CVAPI(void) cvMulSpectrums( const CvArr* src1, const CvArr* src2, + CvArr* dst, int flags ); + +/** Finds optimal DFT vector size >= size0 */ +CVAPI(int) cvGetOptimalDFTSize( int size0 ); + +/** Discrete Cosine Transform +@see core_c_DftFlags "flags" +*/ +CVAPI(void) cvDCT( const CvArr* src, CvArr* dst, int flags ); + +/****************************************************************************************\ +* Dynamic data structures * +\****************************************************************************************/ + +/** Calculates length of sequence slice (with support of negative indices). */ +CVAPI(int) cvSliceLength( CvSlice slice, const CvSeq* seq ); + + +/** Creates new memory storage. + block_size == 0 means that default, + somewhat optimal size, is used (currently, it is 64K) */ +CVAPI(CvMemStorage*) cvCreateMemStorage( int block_size CV_DEFAULT(0)); + + +/** Creates a memory storage that will borrow memory blocks from parent storage */ +CVAPI(CvMemStorage*) cvCreateChildMemStorage( CvMemStorage* parent ); + + +/** Releases memory storage. All the children of a parent must be released before + the parent. A child storage returns all the blocks to parent when it is released */ +CVAPI(void) cvReleaseMemStorage( CvMemStorage** storage ); + + +/** Clears memory storage. This is the only way(!!!) (besides cvRestoreMemStoragePos) + to reuse memory allocated for the storage - cvClearSeq,cvClearSet ... + do not free any memory. + A child storage returns all the blocks to the parent when it is cleared */ +CVAPI(void) cvClearMemStorage( CvMemStorage* storage ); + +/** Remember a storage "free memory" position */ +CVAPI(void) cvSaveMemStoragePos( const CvMemStorage* storage, CvMemStoragePos* pos ); + +/** Restore a storage "free memory" position */ +CVAPI(void) cvRestoreMemStoragePos( CvMemStorage* storage, CvMemStoragePos* pos ); + +/** Allocates continuous buffer of the specified size in the storage */ +CVAPI(void*) cvMemStorageAlloc( CvMemStorage* storage, size_t size ); + +/** Allocates string in memory storage */ +//CVAPI(CvString) cvMemStorageAllocString( CvMemStorage* storage, const char* ptr, +// int len CV_DEFAULT(-1) ); + +/** Creates new empty sequence that will reside in the specified storage */ +CVAPI(CvSeq*) cvCreateSeq( int seq_flags, size_t header_size, + size_t elem_size, CvMemStorage* storage ); + +/** Changes default size (granularity) of sequence blocks. + The default size is ~1Kbyte */ +CVAPI(void) cvSetSeqBlockSize( CvSeq* seq, int delta_elems ); + + +/** Adds new element to the end of sequence. Returns pointer to the element */ +CVAPI(schar*) cvSeqPush( CvSeq* seq, const void* element CV_DEFAULT(NULL)); + + +/** Adds new element to the beginning of sequence. Returns pointer to it */ +CVAPI(schar*) cvSeqPushFront( CvSeq* seq, const void* element CV_DEFAULT(NULL)); + + +/** Removes the last element from sequence and optionally saves it */ +CVAPI(void) cvSeqPop( CvSeq* seq, void* element CV_DEFAULT(NULL)); + + +/** Removes the first element from sequence and optioanally saves it */ +CVAPI(void) cvSeqPopFront( CvSeq* seq, void* element CV_DEFAULT(NULL)); + + +#define CV_FRONT 1 +#define CV_BACK 0 +/** Adds several new elements to the end of sequence */ +CVAPI(void) cvSeqPushMulti( CvSeq* seq, const void* elements, + int count, int in_front CV_DEFAULT(0) ); + +/** Removes several elements from the end of sequence and optionally saves them */ +CVAPI(void) cvSeqPopMulti( CvSeq* seq, void* elements, + int count, int in_front CV_DEFAULT(0) ); + +/** Inserts a new element in the middle of sequence. + cvSeqInsert(seq,0,elem) == cvSeqPushFront(seq,elem) */ +CVAPI(schar*) cvSeqInsert( CvSeq* seq, int before_index, + const void* element CV_DEFAULT(NULL)); + +/** Removes specified sequence element */ +CVAPI(void) cvSeqRemove( CvSeq* seq, int index ); + + +/** Removes all the elements from the sequence. The freed memory + can be reused later only by the same sequence unless cvClearMemStorage + or cvRestoreMemStoragePos is called */ +CVAPI(void) cvClearSeq( CvSeq* seq ); + + +/** Retrieves pointer to specified sequence element. + Negative indices are supported and mean counting from the end + (e.g -1 means the last sequence element) */ +CVAPI(schar*) cvGetSeqElem( const CvSeq* seq, int index ); + +/** Calculates index of the specified sequence element. + Returns -1 if element does not belong to the sequence */ +CVAPI(int) cvSeqElemIdx( const CvSeq* seq, const void* element, + CvSeqBlock** block CV_DEFAULT(NULL) ); + +/** Initializes sequence writer. The new elements will be added to the end of sequence */ +CVAPI(void) cvStartAppendToSeq( CvSeq* seq, CvSeqWriter* writer ); + + +/** Combination of cvCreateSeq and cvStartAppendToSeq */ +CVAPI(void) cvStartWriteSeq( int seq_flags, int header_size, + int elem_size, CvMemStorage* storage, + CvSeqWriter* writer ); + +/** Closes sequence writer, updates sequence header and returns pointer + to the resultant sequence + (which may be useful if the sequence was created using cvStartWriteSeq)) +*/ +CVAPI(CvSeq*) cvEndWriteSeq( CvSeqWriter* writer ); + + +/** Updates sequence header. May be useful to get access to some of previously + written elements via cvGetSeqElem or sequence reader */ +CVAPI(void) cvFlushSeqWriter( CvSeqWriter* writer ); + + +/** Initializes sequence reader. + The sequence can be read in forward or backward direction */ +CVAPI(void) cvStartReadSeq( const CvSeq* seq, CvSeqReader* reader, + int reverse CV_DEFAULT(0) ); + + +/** Returns current sequence reader position (currently observed sequence element) */ +CVAPI(int) cvGetSeqReaderPos( CvSeqReader* reader ); + + +/** Changes sequence reader position. It may seek to an absolute or + to relative to the current position */ +CVAPI(void) cvSetSeqReaderPos( CvSeqReader* reader, int index, + int is_relative CV_DEFAULT(0)); + +/** Copies sequence content to a continuous piece of memory */ +CVAPI(void*) cvCvtSeqToArray( const CvSeq* seq, void* elements, + CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ) ); + +/** Creates sequence header for array. + After that all the operations on sequences that do not alter the content + can be applied to the resultant sequence */ +CVAPI(CvSeq*) cvMakeSeqHeaderForArray( int seq_type, int header_size, + int elem_size, void* elements, int total, + CvSeq* seq, CvSeqBlock* block ); + +/** Extracts sequence slice (with or without copying sequence elements) */ +CVAPI(CvSeq*) cvSeqSlice( const CvSeq* seq, CvSlice slice, + CvMemStorage* storage CV_DEFAULT(NULL), + int copy_data CV_DEFAULT(0)); + +CV_INLINE CvSeq* cvCloneSeq( const CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL)) +{ + return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 ); +} + +/** Removes sequence slice */ +CVAPI(void) cvSeqRemoveSlice( CvSeq* seq, CvSlice slice ); + +/** Inserts a sequence or array into another sequence */ +CVAPI(void) cvSeqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr ); + +/** a < b ? -1 : a > b ? 1 : 0 */ +typedef int (CV_CDECL* CvCmpFunc)(const void* a, const void* b, void* userdata ); + +/** Sorts sequence in-place given element comparison function */ +CVAPI(void) cvSeqSort( CvSeq* seq, CvCmpFunc func, void* userdata CV_DEFAULT(NULL) ); + +/** Finds element in a [sorted] sequence */ +CVAPI(schar*) cvSeqSearch( CvSeq* seq, const void* elem, CvCmpFunc func, + int is_sorted, int* elem_idx, + void* userdata CV_DEFAULT(NULL) ); + +/** Reverses order of sequence elements in-place */ +CVAPI(void) cvSeqInvert( CvSeq* seq ); + +/** Splits sequence into one or more equivalence classes using the specified criteria */ +CVAPI(int) cvSeqPartition( const CvSeq* seq, CvMemStorage* storage, + CvSeq** labels, CvCmpFunc is_equal, void* userdata ); + +/************ Internal sequence functions ************/ +CVAPI(void) cvChangeSeqBlock( void* reader, int direction ); +CVAPI(void) cvCreateSeqBlock( CvSeqWriter* writer ); + + +/** Creates a new set */ +CVAPI(CvSet*) cvCreateSet( int set_flags, int header_size, + int elem_size, CvMemStorage* storage ); + +/** Adds new element to the set and returns pointer to it */ +CVAPI(int) cvSetAdd( CvSet* set_header, CvSetElem* elem CV_DEFAULT(NULL), + CvSetElem** inserted_elem CV_DEFAULT(NULL) ); + +/** Fast variant of cvSetAdd */ +CV_INLINE CvSetElem* cvSetNew( CvSet* set_header ) +{ + CvSetElem* elem = set_header->free_elems; + if( elem ) + { + set_header->free_elems = elem->next_free; + elem->flags = elem->flags & CV_SET_ELEM_IDX_MASK; + set_header->active_count++; + } + else + cvSetAdd( set_header, NULL, &elem ); + return elem; +} + +/** Removes set element given its pointer */ +CV_INLINE void cvSetRemoveByPtr( CvSet* set_header, void* elem ) +{ + CvSetElem* _elem = (CvSetElem*)elem; + assert( _elem->flags >= 0 /*&& (elem->flags & CV_SET_ELEM_IDX_MASK) < set_header->total*/ ); + _elem->next_free = set_header->free_elems; + _elem->flags = (_elem->flags & CV_SET_ELEM_IDX_MASK) | CV_SET_ELEM_FREE_FLAG; + set_header->free_elems = _elem; + set_header->active_count--; +} + +/** Removes element from the set by its index */ +CVAPI(void) cvSetRemove( CvSet* set_header, int index ); + +/** Returns a set element by index. If the element doesn't belong to the set, + NULL is returned */ +CV_INLINE CvSetElem* cvGetSetElem( const CvSet* set_header, int idx ) +{ + CvSetElem* elem = (CvSetElem*)(void *)cvGetSeqElem( (CvSeq*)set_header, idx ); + return elem && CV_IS_SET_ELEM( elem ) ? elem : 0; +} + +/** Removes all the elements from the set */ +CVAPI(void) cvClearSet( CvSet* set_header ); + +/** Creates new graph */ +CVAPI(CvGraph*) cvCreateGraph( int graph_flags, int header_size, + int vtx_size, int edge_size, + CvMemStorage* storage ); + +/** Adds new vertex to the graph */ +CVAPI(int) cvGraphAddVtx( CvGraph* graph, const CvGraphVtx* vtx CV_DEFAULT(NULL), + CvGraphVtx** inserted_vtx CV_DEFAULT(NULL) ); + + +/** Removes vertex from the graph together with all incident edges */ +CVAPI(int) cvGraphRemoveVtx( CvGraph* graph, int index ); +CVAPI(int) cvGraphRemoveVtxByPtr( CvGraph* graph, CvGraphVtx* vtx ); + + +/** Link two vertices specified by indices or pointers if they + are not connected or return pointer to already existing edge + connecting the vertices. + Functions return 1 if a new edge was created, 0 otherwise */ +CVAPI(int) cvGraphAddEdge( CvGraph* graph, + int start_idx, int end_idx, + const CvGraphEdge* edge CV_DEFAULT(NULL), + CvGraphEdge** inserted_edge CV_DEFAULT(NULL) ); + +CVAPI(int) cvGraphAddEdgeByPtr( CvGraph* graph, + CvGraphVtx* start_vtx, CvGraphVtx* end_vtx, + const CvGraphEdge* edge CV_DEFAULT(NULL), + CvGraphEdge** inserted_edge CV_DEFAULT(NULL) ); + +/** Remove edge connecting two vertices */ +CVAPI(void) cvGraphRemoveEdge( CvGraph* graph, int start_idx, int end_idx ); +CVAPI(void) cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx, + CvGraphVtx* end_vtx ); + +/** Find edge connecting two vertices */ +CVAPI(CvGraphEdge*) cvFindGraphEdge( const CvGraph* graph, int start_idx, int end_idx ); +CVAPI(CvGraphEdge*) cvFindGraphEdgeByPtr( const CvGraph* graph, + const CvGraphVtx* start_vtx, + const CvGraphVtx* end_vtx ); +#define cvGraphFindEdge cvFindGraphEdge +#define cvGraphFindEdgeByPtr cvFindGraphEdgeByPtr + +/** Remove all vertices and edges from the graph */ +CVAPI(void) cvClearGraph( CvGraph* graph ); + + +/** Count number of edges incident to the vertex */ +CVAPI(int) cvGraphVtxDegree( const CvGraph* graph, int vtx_idx ); +CVAPI(int) cvGraphVtxDegreeByPtr( const CvGraph* graph, const CvGraphVtx* vtx ); + + +/** Retrieves graph vertex by given index */ +#define cvGetGraphVtx( graph, idx ) (CvGraphVtx*)cvGetSetElem((CvSet*)(graph), (idx)) + +/** Retrieves index of a graph vertex given its pointer */ +#define cvGraphVtxIdx( graph, vtx ) ((vtx)->flags & CV_SET_ELEM_IDX_MASK) + +/** Retrieves index of a graph edge given its pointer */ +#define cvGraphEdgeIdx( graph, edge ) ((edge)->flags & CV_SET_ELEM_IDX_MASK) + +#define cvGraphGetVtxCount( graph ) ((graph)->active_count) +#define cvGraphGetEdgeCount( graph ) ((graph)->edges->active_count) + +#define CV_GRAPH_VERTEX 1 +#define CV_GRAPH_TREE_EDGE 2 +#define CV_GRAPH_BACK_EDGE 4 +#define CV_GRAPH_FORWARD_EDGE 8 +#define CV_GRAPH_CROSS_EDGE 16 +#define CV_GRAPH_ANY_EDGE 30 +#define CV_GRAPH_NEW_TREE 32 +#define CV_GRAPH_BACKTRACKING 64 +#define CV_GRAPH_OVER -1 + +#define CV_GRAPH_ALL_ITEMS -1 + +/** flags for graph vertices and edges */ +#define CV_GRAPH_ITEM_VISITED_FLAG (1 << 30) +#define CV_IS_GRAPH_VERTEX_VISITED(vtx) \ + (((CvGraphVtx*)(vtx))->flags & CV_GRAPH_ITEM_VISITED_FLAG) +#define CV_IS_GRAPH_EDGE_VISITED(edge) \ + (((CvGraphEdge*)(edge))->flags & CV_GRAPH_ITEM_VISITED_FLAG) +#define CV_GRAPH_SEARCH_TREE_NODE_FLAG (1 << 29) +#define CV_GRAPH_FORWARD_EDGE_FLAG (1 << 28) + +typedef struct CvGraphScanner +{ + CvGraphVtx* vtx; /* current graph vertex (or current edge origin) */ + CvGraphVtx* dst; /* current graph edge destination vertex */ + CvGraphEdge* edge; /* current edge */ + + CvGraph* graph; /* the graph */ + CvSeq* stack; /* the graph vertex stack */ + int index; /* the lower bound of certainly visited vertices */ + int mask; /* event mask */ +} +CvGraphScanner; + +/** Creates new graph scanner. */ +CVAPI(CvGraphScanner*) cvCreateGraphScanner( CvGraph* graph, + CvGraphVtx* vtx CV_DEFAULT(NULL), + int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS)); + +/** Releases graph scanner. */ +CVAPI(void) cvReleaseGraphScanner( CvGraphScanner** scanner ); + +/** Get next graph element */ +CVAPI(int) cvNextGraphItem( CvGraphScanner* scanner ); + +/** Creates a copy of graph */ +CVAPI(CvGraph*) cvCloneGraph( const CvGraph* graph, CvMemStorage* storage ); + + +/** Does look-up transformation. Elements of the source array + (that should be 8uC1 or 8sC1) are used as indexes in lutarr 256-element table */ +CVAPI(void) cvLUT( const CvArr* src, CvArr* dst, const CvArr* lut ); + + +/******************* Iteration through the sequence tree *****************/ +typedef struct CvTreeNodeIterator +{ + const void* node; + int level; + int max_level; +} +CvTreeNodeIterator; + +CVAPI(void) cvInitTreeNodeIterator( CvTreeNodeIterator* tree_iterator, + const void* first, int max_level ); +CVAPI(void*) cvNextTreeNode( CvTreeNodeIterator* tree_iterator ); +CVAPI(void*) cvPrevTreeNode( CvTreeNodeIterator* tree_iterator ); + +/** Inserts sequence into tree with specified "parent" sequence. + If parent is equal to frame (e.g. the most external contour), + then added contour will have null pointer to parent. */ +CVAPI(void) cvInsertNodeIntoTree( void* node, void* parent, void* frame ); + +/** Removes contour from tree (together with the contour children). */ +CVAPI(void) cvRemoveNodeFromTree( void* node, void* frame ); + +/** Gathers pointers to all the sequences, + accessible from the `first`, to the single sequence */ +CVAPI(CvSeq*) cvTreeToNodeSeq( const void* first, int header_size, + CvMemStorage* storage ); + +/** The function implements the K-means algorithm for clustering an array of sample + vectors in a specified number of classes */ +#define CV_KMEANS_USE_INITIAL_LABELS 1 +CVAPI(int) cvKMeans2( const CvArr* samples, int cluster_count, CvArr* labels, + CvTermCriteria termcrit, int attempts CV_DEFAULT(1), + CvRNG* rng CV_DEFAULT(0), int flags CV_DEFAULT(0), + CvArr* _centers CV_DEFAULT(0), double* compactness CV_DEFAULT(0) ); + +/****************************************************************************************\ +* System functions * +\****************************************************************************************/ + +/** Loads optimized functions from IPP, MKL etc. or switches back to pure C code */ +CVAPI(int) cvUseOptimized( int on_off ); + +typedef IplImage* (CV_STDCALL* Cv_iplCreateImageHeader) + (int,int,int,char*,char*,int,int,int,int,int, + IplROI*,IplImage*,void*,IplTileInfo*); +typedef void (CV_STDCALL* Cv_iplAllocateImageData)(IplImage*,int,int); +typedef void (CV_STDCALL* Cv_iplDeallocate)(IplImage*,int); +typedef IplROI* (CV_STDCALL* Cv_iplCreateROI)(int,int,int,int,int); +typedef IplImage* (CV_STDCALL* Cv_iplCloneImage)(const IplImage*); + +/** @brief Makes OpenCV use IPL functions for allocating IplImage and IplROI structures. + +Normally, the function is not called directly. Instead, a simple macro +CV_TURN_ON_IPL_COMPATIBILITY() is used that calls cvSetIPLAllocators and passes there pointers +to IPL allocation functions. : +@code + ... + CV_TURN_ON_IPL_COMPATIBILITY() + ... +@endcode +@param create_header pointer to a function, creating IPL image header. +@param allocate_data pointer to a function, allocating IPL image data. +@param deallocate pointer to a function, deallocating IPL image. +@param create_roi pointer to a function, creating IPL image ROI (i.e. Region of Interest). +@param clone_image pointer to a function, cloning an IPL image. + */ +CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header, + Cv_iplAllocateImageData allocate_data, + Cv_iplDeallocate deallocate, + Cv_iplCreateROI create_roi, + Cv_iplCloneImage clone_image ); + +#define CV_TURN_ON_IPL_COMPATIBILITY() \ + cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImage, \ + iplDeallocate, iplCreateROI, iplCloneImage ) + +/****************************************************************************************\ +* Data Persistence * +\****************************************************************************************/ + +#if 0 +/********************************** High-level functions ********************************/ + +/** @brief Opens file storage for reading or writing data. + +The function opens file storage for reading or writing data. In the latter case, a new file is +created or an existing file is rewritten. The type of the read or written file is determined by the +filename extension: .xml for XML, .yml or .yaml for YAML and .json for JSON. + +At the same time, it also supports adding parameters like "example.xml?base64". + +The function returns a pointer to the CvFileStorage structure. +If the file cannot be opened then the function returns NULL. +@param filename Name of the file associated with the storage +@param memstorage Memory storage used for temporary data and for +: storing dynamic structures, such as CvSeq or CvGraph . If it is NULL, a temporary memory + storage is created and used. +@param flags Can be one of the following: +> - **CV_STORAGE_READ** the storage is open for reading +> - **CV_STORAGE_WRITE** the storage is open for writing + (use **CV_STORAGE_WRITE | CV_STORAGE_WRITE_BASE64** to write rawdata in Base64) +@param encoding + */ +CVAPI(CvFileStorage*) cvOpenFileStorage( const char* filename, CvMemStorage* memstorage, + int flags, const char* encoding CV_DEFAULT(NULL) ); + +/** @brief Releases file storage. + +The function closes the file associated with the storage and releases all the temporary structures. +It must be called after all I/O operations with the storage are finished. +@param fs Double pointer to the released file storage + */ +CVAPI(void) cvReleaseFileStorage( CvFileStorage** fs ); + +/** returns attribute value or 0 (NULL) if there is no such attribute */ +CVAPI(const char*) cvAttrValue( const CvAttrList* attr, const char* attr_name ); + +/** @brief Starts writing a new structure. + +The function starts writing a compound structure (collection) that can be a sequence or a map. After +all the structure fields, which can be scalars or structures, are written, cvEndWriteStruct should +be called. The function can be used to group some objects or to implement the write function for a +some user object (see CvTypeInfo). +@param fs File storage +@param name Name of the written structure. The structure can be accessed by this name when the +storage is read. +@param struct_flags A combination one of the following values: +- **CV_NODE_SEQ** the written structure is a sequence (see discussion of CvFileStorage ), + that is, its elements do not have a name. +- **CV_NODE_MAP** the written structure is a map (see discussion of CvFileStorage ), that + is, all its elements have names. +One and only one of the two above flags must be specified +- **CV_NODE_FLOW** the optional flag that makes sense only for YAML streams. It means that + the structure is written as a flow (not as a block), which is more compact. It is + recommended to use this flag for structures or arrays whose elements are all scalars. +@param type_name Optional parameter - the object type name. In + case of XML it is written as a type_id attribute of the structure opening tag. In the case of + YAML it is written after a colon following the structure name (see the example in + CvFileStorage description). In case of JSON it is written as a name/value pair. + Mainly it is used with user objects. When the storage is read, the + encoded type name is used to determine the object type (see CvTypeInfo and cvFindType ). +@param attributes This parameter is not used in the current implementation + */ +CVAPI(void) cvStartWriteStruct( CvFileStorage* fs, const char* name, + int struct_flags, const char* type_name CV_DEFAULT(NULL), + CvAttrList attributes CV_DEFAULT(cvAttrList())); + +/** @brief Finishes writing to a file node collection. +@param fs File storage +@sa cvStartWriteStruct. + */ +CVAPI(void) cvEndWriteStruct( CvFileStorage* fs ); + +/** @brief Writes an integer value. + +The function writes a single integer value (with or without a name) to the file storage. +@param fs File storage +@param name Name of the written value. Should be NULL if and only if the parent structure is a +sequence. +@param value The written value + */ +CVAPI(void) cvWriteInt( CvFileStorage* fs, const char* name, int value ); + +/** @brief Writes a floating-point value. + +The function writes a single floating-point value (with or without a name) to file storage. Special +values are encoded as follows: NaN (Not A Number) as .NaN, infinity as +.Inf or -.Inf. + +The following example shows how to use the low-level writing functions to store custom structures, +such as termination criteria, without registering a new type. : +@code + void write_termcriteria( CvFileStorage* fs, const char* struct_name, + CvTermCriteria* termcrit ) + { + cvStartWriteStruct( fs, struct_name, CV_NODE_MAP, NULL, cvAttrList(0,0)); + cvWriteComment( fs, "termination criteria", 1 ); // just a description + if( termcrit->type & CV_TERMCRIT_ITER ) + cvWriteInteger( fs, "max_iterations", termcrit->max_iter ); + if( termcrit->type & CV_TERMCRIT_EPS ) + cvWriteReal( fs, "accuracy", termcrit->epsilon ); + cvEndWriteStruct( fs ); + } +@endcode +@param fs File storage +@param name Name of the written value. Should be NULL if and only if the parent structure is a +sequence. +@param value The written value +*/ +CVAPI(void) cvWriteReal( CvFileStorage* fs, const char* name, double value ); + +/** @brief Writes a text string. + +The function writes a text string to file storage. +@param fs File storage +@param name Name of the written string . Should be NULL if and only if the parent structure is a +sequence. +@param str The written text string +@param quote If non-zero, the written string is put in quotes, regardless of whether they are +required. Otherwise, if the flag is zero, quotes are used only when they are required (e.g. when +the string starts with a digit or contains spaces). + */ +CVAPI(void) cvWriteString( CvFileStorage* fs, const char* name, + const char* str, int quote CV_DEFAULT(0) ); + +/** @brief Writes a comment. + +The function writes a comment into file storage. The comments are skipped when the storage is read. +@param fs File storage +@param comment The written comment, single-line or multi-line +@param eol_comment If non-zero, the function tries to put the comment at the end of current line. +If the flag is zero, if the comment is multi-line, or if it does not fit at the end of the current +line, the comment starts a new line. + */ +CVAPI(void) cvWriteComment( CvFileStorage* fs, const char* comment, + int eol_comment ); + +/** @brief Writes an object to file storage. + +The function writes an object to file storage. First, the appropriate type info is found using +cvTypeOf. Then, the write method associated with the type info is called. + +Attributes are used to customize the writing procedure. The standard types support the following +attributes (all the dt attributes have the same format as in cvWriteRawData): + +-# CvSeq + - **header_dt** description of user fields of the sequence header that follow CvSeq, or + CvChain (if the sequence is a Freeman chain) or CvContour (if the sequence is a contour or + point sequence) + - **dt** description of the sequence elements. + - **recursive** if the attribute is present and is not equal to "0" or "false", the whole + tree of sequences (contours) is stored. +-# CvGraph + - **header_dt** description of user fields of the graph header that follows CvGraph; + - **vertex_dt** description of user fields of graph vertices + - **edge_dt** description of user fields of graph edges (note that the edge weight is + always written, so there is no need to specify it explicitly) + +Below is the code that creates the YAML file shown in the CvFileStorage description: +@code + #include "cxcore.h" + + int main( int argc, char** argv ) + { + CvMat* mat = cvCreateMat( 3, 3, CV_32F ); + CvFileStorage* fs = cvOpenFileStorage( "example.yml", 0, CV_STORAGE_WRITE ); + + cvSetIdentity( mat ); + cvWrite( fs, "A", mat, cvAttrList(0,0) ); + + cvReleaseFileStorage( &fs ); + cvReleaseMat( &mat ); + return 0; + } +@endcode +@param fs File storage +@param name Name of the written object. Should be NULL if and only if the parent structure is a +sequence. +@param ptr Pointer to the object +@param attributes The attributes of the object. They are specific for each particular type (see +the discussion below). + */ +CVAPI(void) cvWrite( CvFileStorage* fs, const char* name, const void* ptr, + CvAttrList attributes CV_DEFAULT(cvAttrList())); + +/** @brief Starts the next stream. + +The function finishes the currently written stream and starts the next stream. In the case of XML +the file with multiple streams looks like this: +@code{.xml} + + + + + + + ... +@endcode +The YAML file will look like this: +@code{.yaml} + %YAML 1.0 + # stream #1 data + ... + --- + # stream #2 data +@endcode +This is useful for concatenating files or for resuming the writing process. +@param fs File storage + */ +CVAPI(void) cvStartNextStream( CvFileStorage* fs ); + +/** @brief Writes multiple numbers. + +The function writes an array, whose elements consist of single or multiple numbers. The function +call can be replaced with a loop containing a few cvWriteInt and cvWriteReal calls, but a single +call is more efficient. Note that because none of the elements have a name, they should be written +to a sequence rather than a map. +@param fs File storage +@param src Pointer to the written array +@param len Number of the array elements to write +@param dt Specification of each array element, see @ref format_spec "format specification" + */ +CVAPI(void) cvWriteRawData( CvFileStorage* fs, const void* src, + int len, const char* dt ); + +/** @brief Writes multiple numbers in Base64. + +If either CV_STORAGE_WRITE_BASE64 or cv::FileStorage::WRITE_BASE64 is used, +this function will be the same as cvWriteRawData. If neither, the main +difference is that it outputs a sequence in Base64 encoding rather than +in plain text. + +This function can only be used to write a sequence with a type "binary". + +@param fs File storage +@param src Pointer to the written array +@param len Number of the array elements to write +@param dt Specification of each array element, see @ref format_spec "format specification" +*/ +CVAPI(void) cvWriteRawDataBase64( CvFileStorage* fs, const void* src, + int len, const char* dt ); + +/** @brief Returns a unique pointer for a given name. + +The function returns a unique pointer for each particular file node name. This pointer can be then +passed to the cvGetFileNode function that is faster than cvGetFileNodeByName because it compares +text strings by comparing pointers rather than the strings' content. + +Consider the following example where an array of points is encoded as a sequence of 2-entry maps: +@code + points: + - { x: 10, y: 10 } + - { x: 20, y: 20 } + - { x: 30, y: 30 } + # ... +@endcode +Then, it is possible to get hashed "x" and "y" pointers to speed up decoding of the points. : +@code + #include "cxcore.h" + + int main( int argc, char** argv ) + { + CvFileStorage* fs = cvOpenFileStorage( "points.yml", 0, CV_STORAGE_READ ); + CvStringHashNode* x_key = cvGetHashedNode( fs, "x", -1, 1 ); + CvStringHashNode* y_key = cvGetHashedNode( fs, "y", -1, 1 ); + CvFileNode* points = cvGetFileNodeByName( fs, 0, "points" ); + + if( CV_NODE_IS_SEQ(points->tag) ) + { + CvSeq* seq = points->data.seq; + int i, total = seq->total; + CvSeqReader reader; + cvStartReadSeq( seq, &reader, 0 ); + for( i = 0; i < total; i++ ) + { + CvFileNode* pt = (CvFileNode*)reader.ptr; + #if 1 // faster variant + CvFileNode* xnode = cvGetFileNode( fs, pt, x_key, 0 ); + CvFileNode* ynode = cvGetFileNode( fs, pt, y_key, 0 ); + assert( xnode && CV_NODE_IS_INT(xnode->tag) && + ynode && CV_NODE_IS_INT(ynode->tag)); + int x = xnode->data.i; // or x = cvReadInt( xnode, 0 ); + int y = ynode->data.i; // or y = cvReadInt( ynode, 0 ); + #elif 1 // slower variant; does not use x_key & y_key + CvFileNode* xnode = cvGetFileNodeByName( fs, pt, "x" ); + CvFileNode* ynode = cvGetFileNodeByName( fs, pt, "y" ); + assert( xnode && CV_NODE_IS_INT(xnode->tag) && + ynode && CV_NODE_IS_INT(ynode->tag)); + int x = xnode->data.i; // or x = cvReadInt( xnode, 0 ); + int y = ynode->data.i; // or y = cvReadInt( ynode, 0 ); + #else // the slowest yet the easiest to use variant + int x = cvReadIntByName( fs, pt, "x", 0 ); + int y = cvReadIntByName( fs, pt, "y", 0 ); + #endif + CV_NEXT_SEQ_ELEM( seq->elem_size, reader ); + printf(" + } + } + cvReleaseFileStorage( &fs ); + return 0; + } +@endcode +Please note that whatever method of accessing a map you are using, it is still much slower than +using plain sequences; for example, in the above example, it is more efficient to encode the points +as pairs of integers in a single numeric sequence. +@param fs File storage +@param name Literal node name +@param len Length of the name (if it is known apriori), or -1 if it needs to be calculated +@param create_missing Flag that specifies, whether an absent key should be added into the hash table +*/ +CVAPI(CvStringHashNode*) cvGetHashedKey( CvFileStorage* fs, const char* name, + int len CV_DEFAULT(-1), + int create_missing CV_DEFAULT(0)); + +/** @brief Retrieves one of the top-level nodes of the file storage. + +The function returns one of the top-level file nodes. The top-level nodes do not have a name, they +correspond to the streams that are stored one after another in the file storage. If the index is out +of range, the function returns a NULL pointer, so all the top-level nodes can be iterated by +subsequent calls to the function with stream_index=0,1,..., until the NULL pointer is returned. +This function can be used as a base for recursive traversal of the file storage. +@param fs File storage +@param stream_index Zero-based index of the stream. See cvStartNextStream . In most cases, +there is only one stream in the file; however, there can be several. + */ +CVAPI(CvFileNode*) cvGetRootFileNode( const CvFileStorage* fs, + int stream_index CV_DEFAULT(0) ); + +/** @brief Finds a node in a map or file storage. + +The function finds a file node. It is a faster version of cvGetFileNodeByName (see +cvGetHashedKey discussion). Also, the function can insert a new node, if it is not in the map yet. +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. If both map and +key are NULLs, the function returns the root file node - a map that contains top-level nodes. +@param key Unique pointer to the node name, retrieved with cvGetHashedKey +@param create_missing Flag that specifies whether an absent node should be added to the map + */ +CVAPI(CvFileNode*) cvGetFileNode( CvFileStorage* fs, CvFileNode* map, + const CvStringHashNode* key, + int create_missing CV_DEFAULT(0) ); + +/** @brief Finds a node in a map or file storage. + +The function finds a file node by name. The node is searched either in map or, if the pointer is +NULL, among the top-level file storage nodes. Using this function for maps and cvGetSeqElem (or +sequence reader) for sequences, it is possible to navigate through the file storage. To speed up +multiple queries for a certain key (e.g., in the case of an array of structures) one may use a +combination of cvGetHashedKey and cvGetFileNode. +@param fs File storage +@param map The parent map. If it is NULL, the function searches in all the top-level nodes +(streams), starting with the first one. +@param name The file node name + */ +CVAPI(CvFileNode*) cvGetFileNodeByName( const CvFileStorage* fs, + const CvFileNode* map, + const char* name ); + +/** @brief Retrieves an integer value from a file node. + +The function returns an integer that is represented by the file node. If the file node is NULL, the +default_value is returned (thus, it is convenient to call the function right after cvGetFileNode +without checking for a NULL pointer). If the file node has type CV_NODE_INT, then node-\>data.i is +returned. If the file node has type CV_NODE_REAL, then node-\>data.f is converted to an integer +and returned. Otherwise the error is reported. +@param node File node +@param default_value The value that is returned if node is NULL + */ +CV_INLINE int cvReadInt( const CvFileNode* node, int default_value CV_DEFAULT(0) ) +{ + return !node ? default_value : + CV_NODE_IS_INT(node->tag) ? node->data.i : + CV_NODE_IS_REAL(node->tag) ? cvRound(node->data.f) : 0x7fffffff; +} + +/** @brief Finds a file node and returns its value. + +The function is a simple superposition of cvGetFileNodeByName and cvReadInt. +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param default_value The value that is returned if the file node is not found + */ +CV_INLINE int cvReadIntByName( const CvFileStorage* fs, const CvFileNode* map, + const char* name, int default_value CV_DEFAULT(0) ) +{ + return cvReadInt( cvGetFileNodeByName( fs, map, name ), default_value ); +} + +/** @brief Retrieves a floating-point value from a file node. + +The function returns a floating-point value that is represented by the file node. If the file node +is NULL, the default_value is returned (thus, it is convenient to call the function right after +cvGetFileNode without checking for a NULL pointer). If the file node has type CV_NODE_REAL , +then node-\>data.f is returned. If the file node has type CV_NODE_INT , then node-:math:\>data.f +is converted to floating-point and returned. Otherwise the result is not determined. +@param node File node +@param default_value The value that is returned if node is NULL + */ +CV_INLINE double cvReadReal( const CvFileNode* node, double default_value CV_DEFAULT(0.) ) +{ + return !node ? default_value : + CV_NODE_IS_INT(node->tag) ? (double)node->data.i : + CV_NODE_IS_REAL(node->tag) ? node->data.f : 1e300; +} + +/** @brief Finds a file node and returns its value. + +The function is a simple superposition of cvGetFileNodeByName and cvReadReal . +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param default_value The value that is returned if the file node is not found + */ +CV_INLINE double cvReadRealByName( const CvFileStorage* fs, const CvFileNode* map, + const char* name, double default_value CV_DEFAULT(0.) ) +{ + return cvReadReal( cvGetFileNodeByName( fs, map, name ), default_value ); +} + +/** @brief Retrieves a text string from a file node. + +The function returns a text string that is represented by the file node. If the file node is NULL, +the default_value is returned (thus, it is convenient to call the function right after +cvGetFileNode without checking for a NULL pointer). If the file node has type CV_NODE_STR , then +node-:math:\>data.str.ptr is returned. Otherwise the result is not determined. +@param node File node +@param default_value The value that is returned if node is NULL + */ +CV_INLINE const char* cvReadString( const CvFileNode* node, + const char* default_value CV_DEFAULT(NULL) ) +{ + return !node ? default_value : CV_NODE_IS_STRING(node->tag) ? node->data.str.ptr : 0; +} + +/** @brief Finds a file node by its name and returns its value. + +The function is a simple superposition of cvGetFileNodeByName and cvReadString . +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param default_value The value that is returned if the file node is not found + */ +CV_INLINE const char* cvReadStringByName( const CvFileStorage* fs, const CvFileNode* map, + const char* name, const char* default_value CV_DEFAULT(NULL) ) +{ + return cvReadString( cvGetFileNodeByName( fs, map, name ), default_value ); +} + + +/** @brief Decodes an object and returns a pointer to it. + +The function decodes a user object (creates an object in a native representation from the file +storage subtree) and returns it. The object to be decoded must be an instance of a registered type +that supports the read method (see CvTypeInfo). The type of the object is determined by the type +name that is encoded in the file. If the object is a dynamic structure, it is created either in +memory storage and passed to cvOpenFileStorage or, if a NULL pointer was passed, in temporary +memory storage, which is released when cvReleaseFileStorage is called. Otherwise, if the object is +not a dynamic structure, it is created in a heap and should be released with a specialized function +or by using the generic cvRelease. +@param fs File storage +@param node The root object node +@param attributes Unused parameter + */ +CVAPI(void*) cvRead( CvFileStorage* fs, CvFileNode* node, + CvAttrList* attributes CV_DEFAULT(NULL)); + +/** @brief Finds an object by name and decodes it. + +The function is a simple superposition of cvGetFileNodeByName and cvRead. +@param fs File storage +@param map The parent map. If it is NULL, the function searches a top-level node. +@param name The node name +@param attributes Unused parameter + */ +CV_INLINE void* cvReadByName( CvFileStorage* fs, const CvFileNode* map, + const char* name, CvAttrList* attributes CV_DEFAULT(NULL) ) +{ + return cvRead( fs, cvGetFileNodeByName( fs, map, name ), attributes ); +} + + +/** @brief Initializes the file node sequence reader. + +The function initializes the sequence reader to read data from a file node. The initialized reader +can be then passed to cvReadRawDataSlice. +@param fs File storage +@param src The file node (a sequence) to read numbers from +@param reader Pointer to the sequence reader + */ +CVAPI(void) cvStartReadRawData( const CvFileStorage* fs, const CvFileNode* src, + CvSeqReader* reader ); + +/** @brief Initializes file node sequence reader. + +The function reads one or more elements from the file node, representing a sequence, to a +user-specified array. The total number of read sequence elements is a product of total and the +number of components in each array element. For example, if dt=2if, the function will read total\*3 +sequence elements. As with any sequence, some parts of the file node sequence can be skipped or read +repeatedly by repositioning the reader using cvSetSeqReaderPos. +@param fs File storage +@param reader The sequence reader. Initialize it with cvStartReadRawData . +@param count The number of elements to read +@param dst Pointer to the destination array +@param dt Specification of each array element. It has the same format as in cvWriteRawData . + */ +CVAPI(void) cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader, + int count, void* dst, const char* dt ); + +/** @brief Reads multiple numbers. + +The function reads elements from a file node that represents a sequence of scalars. +@param fs File storage +@param src The file node (a sequence) to read numbers from +@param dst Pointer to the destination array +@param dt Specification of each array element. It has the same format as in cvWriteRawData . + */ +CVAPI(void) cvReadRawData( const CvFileStorage* fs, const CvFileNode* src, + void* dst, const char* dt ); + +/** @brief Writes a file node to another file storage. + +The function writes a copy of a file node to file storage. Possible applications of the function are +merging several file storages into one and conversion between XML, YAML and JSON formats. +@param fs Destination file storage +@param new_node_name New name of the file node in the destination file storage. To keep the +existing name, use cvcvGetFileNodeName +@param node The written node +@param embed If the written node is a collection and this parameter is not zero, no extra level of +hierarchy is created. Instead, all the elements of node are written into the currently written +structure. Of course, map elements can only be embedded into another map, and sequence elements +can only be embedded into another sequence. + */ +CVAPI(void) cvWriteFileNode( CvFileStorage* fs, const char* new_node_name, + const CvFileNode* node, int embed ); + +/** @brief Returns the name of a file node. + +The function returns the name of a file node or NULL, if the file node does not have a name or if +node is NULL. +@param node File node + */ +CVAPI(const char*) cvGetFileNodeName( const CvFileNode* node ); + +/*********************************** Adding own types ***********************************/ + +/** @brief Registers a new type. + +The function registers a new type, which is described by info . The function creates a copy of the +structure, so the user should delete it after calling the function. +@param info Type info structure + */ +CVAPI(void) cvRegisterType( const CvTypeInfo* info ); + +/** @brief Unregisters the type. + +The function unregisters a type with a specified name. If the name is unknown, it is possible to +locate the type info by an instance of the type using cvTypeOf or by iterating the type list, +starting from cvFirstType, and then calling cvUnregisterType(info-\>typeName). +@param type_name Name of an unregistered type + */ +CVAPI(void) cvUnregisterType( const char* type_name ); + +/** @brief Returns the beginning of a type list. + +The function returns the first type in the list of registered types. Navigation through the list can +be done via the prev and next fields of the CvTypeInfo structure. + */ +CVAPI(CvTypeInfo*) cvFirstType(void); + +/** @brief Finds a type by its name. + +The function finds a registered type by its name. It returns NULL if there is no type with the +specified name. +@param type_name Type name + */ +CVAPI(CvTypeInfo*) cvFindType( const char* type_name ); + +/** @brief Returns the type of an object. + +The function finds the type of a given object. It iterates through the list of registered types and +calls the is_instance function/method for every type info structure with that object until one of +them returns non-zero or until the whole list has been traversed. In the latter case, the function +returns NULL. +@param struct_ptr The object pointer + */ +CVAPI(CvTypeInfo*) cvTypeOf( const void* struct_ptr ); + +#endif + +/** @brief Releases an object. + + The function finds the type of a given object and calls release with the double pointer. + @param struct_ptr Double pointer to the object + */ +CVAPI(void) cvRelease( void** struct_ptr ); + +/** @brief Makes a clone of an object. + +The function finds the type of a given object and calls clone with the passed object. Of course, if +you know the object type, for example, struct_ptr is CvMat\*, it is faster to call the specific +function, like cvCloneMat. +@param struct_ptr The object to clone + */ +CVAPI(void*) cvClone( const void* struct_ptr ); + +/*********************************** Measuring Execution Time ***************************/ + +/** helper functions for RNG initialization and accurate time measurement: + uses internal clock counter on x86 */ +CVAPI(int64) cvGetTickCount( void ); +CVAPI(double) cvGetTickFrequency( void ); + +/*********************************** CPU capabilities ***********************************/ + +CVAPI(int) cvCheckHardwareSupport(int feature); + +/*********************************** Multi-Threading ************************************/ + +/** retrieve/set the number of threads used in OpenMP implementations */ +CVAPI(int) cvGetNumThreads( void ); +CVAPI(void) cvSetNumThreads( int threads CV_DEFAULT(0) ); +/** get index of the thread being executed */ +CVAPI(int) cvGetThreadNum( void ); + + +/********************************** Error Handling **************************************/ + +/** Get current OpenCV error status */ +CVAPI(int) cvGetErrStatus( void ); + +/** Sets error status silently */ +CVAPI(void) cvSetErrStatus( int status ); + +#define CV_ErrModeLeaf 0 /* Print error and exit program */ +#define CV_ErrModeParent 1 /* Print error and continue */ +#define CV_ErrModeSilent 2 /* Don't print and continue */ + +/** Retrieves current error processing mode */ +CVAPI(int) cvGetErrMode( void ); + +/** Sets error processing mode, returns previously used mode */ +CVAPI(int) cvSetErrMode( int mode ); + +/** Sets error status and performs some additional actions (displaying message box, + writing message to stderr, terminating application etc.) + depending on the current error mode */ +CVAPI(void) cvError( int status, const char* func_name, + const char* err_msg, const char* file_name, int line ); + +/** Retrieves textual description of the error given its code */ +CVAPI(const char*) cvErrorStr( int status ); + +/** Retrieves detailed information about the last error occurred */ +CVAPI(int) cvGetErrInfo( const char** errcode_desc, const char** description, + const char** filename, int* line ); + +/** Maps IPP error codes to the counterparts from OpenCV */ +CVAPI(int) cvErrorFromIppStatus( int ipp_status ); + +typedef int (CV_CDECL *CvErrorCallback)( int status, const char* func_name, + const char* err_msg, const char* file_name, int line, void* userdata ); + +/** Assigns a new error-handling function */ +CVAPI(CvErrorCallback) cvRedirectError( CvErrorCallback error_handler, + void* userdata CV_DEFAULT(NULL), + void** prev_userdata CV_DEFAULT(NULL) ); + +/** Output nothing */ +CVAPI(int) cvNulDevReport( int status, const char* func_name, const char* err_msg, + const char* file_name, int line, void* userdata ); + +/** Output to console(fprintf(stderr,...)) */ +CVAPI(int) cvStdErrReport( int status, const char* func_name, const char* err_msg, + const char* file_name, int line, void* userdata ); + +/** Output to MessageBox(WIN32) */ +CVAPI(int) cvGuiBoxReport( int status, const char* func_name, const char* err_msg, + const char* file_name, int line, void* userdata ); + +#define OPENCV_ERROR(status,func,context) \ +cvError((status),(func),(context),__FILE__,__LINE__) + +#define OPENCV_ASSERT(expr,func,context) \ +{if (! (expr)) \ +{OPENCV_ERROR(CV_StsInternal,(func),(context));}} + +#define OPENCV_CALL( Func ) \ +{ \ +Func; \ +} + + +/** CV_FUNCNAME macro defines icvFuncName constant which is used by CV_ERROR macro */ +#ifdef CV_NO_FUNC_NAMES +#define CV_FUNCNAME( Name ) +#define cvFuncName "" +#else +#define CV_FUNCNAME( Name ) \ +static char cvFuncName[] = Name +#endif + + +/** + CV_ERROR macro unconditionally raises error with passed code and message. + After raising error, control will be transferred to the exit label. + */ +#define CV_ERROR( Code, Msg ) \ +{ \ + cvError( (Code), cvFuncName, Msg, __FILE__, __LINE__ ); \ + __CV_EXIT__; \ +} + +/** + CV_CHECK macro checks error status after CV (or IPL) + function call. If error detected, control will be transferred to the exit + label. + */ +#define CV_CHECK() \ +{ \ + if( cvGetErrStatus() < 0 ) \ + CV_ERROR( CV_StsBackTrace, "Inner function failed." ); \ +} + + +/** + CV_CALL macro calls CV (or IPL) function, checks error status and + signals a error if the function failed. Useful in "parent node" + error processing mode + */ +#define CV_CALL( Func ) \ +{ \ + Func; \ + CV_CHECK(); \ +} + + +/** Runtime assertion macro */ +#define CV_ASSERT( Condition ) \ +{ \ + if( !(Condition) ) \ + CV_ERROR( CV_StsInternal, "Assertion: " #Condition " failed" ); \ +} + +#define __CV_BEGIN__ { +#define __CV_END__ goto exit; exit: ; } +#define __CV_EXIT__ goto exit + +/** @} core_c */ + +#ifdef __cplusplus +} // extern "C" +#endif + +#ifdef __cplusplus + +#include "opencv2/core/utility.hpp" + +namespace cv +{ + +//! @addtogroup core_c_glue +//! @{ + +/////////////////////////////////////////// glue /////////////////////////////////////////// + +//! converts array (CvMat or IplImage) to cv::Mat +CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false, + bool allowND=true, int coiMode=0, + AutoBuffer* buf=0); + +static inline Mat cvarrToMatND(const CvArr* arr, bool copyData=false, int coiMode=0) +{ + return cvarrToMat(arr, copyData, true, coiMode); +} + + +//! extracts Channel of Interest from CvMat or IplImage and makes cv::Mat out of it. +CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1); +//! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage +CV_EXPORTS void insertImageCOI(InputArray coiimg, CvArr* arr, int coi=-1); + + + +////// specialized implementations of DefaultDeleter::operator() for classic OpenCV types ////// + +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMat* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(IplImage* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMatND* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvSparseMat* obj) const; }; +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvMemStorage* obj) const; }; + +////////////// convenient wrappers for operating old-style dynamic structures ////////////// + +template class SeqIterator; + +typedef Ptr MemStorage; + +/*! + Template Sequence Class derived from CvSeq + + The class provides more convenient access to sequence elements, + STL-style operations and iterators. + + \note The class is targeted for simple data types, + i.e. no constructors or destructors + are called for the sequence elements. +*/ +template class Seq +{ +public: + typedef SeqIterator<_Tp> iterator; + typedef SeqIterator<_Tp> const_iterator; + + //! the default constructor + Seq(); + //! the constructor for wrapping CvSeq structure. The real element type in CvSeq should match _Tp. + Seq(const CvSeq* seq); + //! creates the empty sequence that resides in the specified storage + Seq(MemStorage& storage, int headerSize = sizeof(CvSeq)); + //! returns read-write reference to the specified element + _Tp& operator [](int idx); + //! returns read-only reference to the specified element + const _Tp& operator[](int idx) const; + //! returns iterator pointing to the beginning of the sequence + SeqIterator<_Tp> begin() const; + //! returns iterator pointing to the element following the last sequence element + SeqIterator<_Tp> end() const; + //! returns the number of elements in the sequence + size_t size() const; + //! returns the type of sequence elements (CV_8UC1 ... CV_64FC(CV_CN_MAX) ...) + int type() const; + //! returns the depth of sequence elements (CV_8U ... CV_64F) + int depth() const; + //! returns the number of channels in each sequence element + int channels() const; + //! returns the size of each sequence element + size_t elemSize() const; + //! returns index of the specified sequence element + size_t index(const _Tp& elem) const; + //! appends the specified element to the end of the sequence + void push_back(const _Tp& elem); + //! appends the specified element to the front of the sequence + void push_front(const _Tp& elem); + //! appends zero or more elements to the end of the sequence + void push_back(const _Tp* elems, size_t count); + //! appends zero or more elements to the front of the sequence + void push_front(const _Tp* elems, size_t count); + //! inserts the specified element to the specified position + void insert(int idx, const _Tp& elem); + //! inserts zero or more elements to the specified position + void insert(int idx, const _Tp* elems, size_t count); + //! removes element at the specified position + void remove(int idx); + //! removes the specified subsequence + void remove(const Range& r); + + //! returns reference to the first sequence element + _Tp& front(); + //! returns read-only reference to the first sequence element + const _Tp& front() const; + //! returns reference to the last sequence element + _Tp& back(); + //! returns read-only reference to the last sequence element + const _Tp& back() const; + //! returns true iff the sequence contains no elements + bool empty() const; + + //! removes all the elements from the sequence + void clear(); + //! removes the first element from the sequence + void pop_front(); + //! removes the last element from the sequence + void pop_back(); + //! removes zero or more elements from the beginning of the sequence + void pop_front(_Tp* elems, size_t count); + //! removes zero or more elements from the end of the sequence + void pop_back(_Tp* elems, size_t count); + + //! copies the whole sequence or the sequence slice to the specified vector + void copyTo(std::vector<_Tp>& vec, const Range& range=Range::all()) const; + //! returns the vector containing all the sequence elements + operator std::vector<_Tp>() const; + + CvSeq* seq; +}; + + +/*! + STL-style Sequence Iterator inherited from the CvSeqReader structure +*/ +template class SeqIterator : public CvSeqReader +{ +public: + //! the default constructor + SeqIterator(); + //! the constructor setting the iterator to the beginning or to the end of the sequence + SeqIterator(const Seq<_Tp>& seq, bool seekEnd=false); + //! positions the iterator within the sequence + void seek(size_t pos); + //! reports the current iterator position + size_t tell() const; + //! returns reference to the current sequence element + _Tp& operator *(); + //! returns read-only reference to the current sequence element + const _Tp& operator *() const; + //! moves iterator to the next sequence element + SeqIterator& operator ++(); + //! moves iterator to the next sequence element + SeqIterator operator ++(int) const; + //! moves iterator to the previous sequence element + SeqIterator& operator --(); + //! moves iterator to the previous sequence element + SeqIterator operator --(int) const; + + //! moves iterator forward by the specified offset (possibly negative) + SeqIterator& operator +=(int); + //! moves iterator backward by the specified offset (possibly negative) + SeqIterator& operator -=(int); + + // this is index of the current element module seq->total*2 + // (to distinguish between 0 and seq->total) + int index; +}; + + + +// bridge C++ => C Seq API +CV_EXPORTS schar* seqPush( CvSeq* seq, const void* element=0); +CV_EXPORTS schar* seqPushFront( CvSeq* seq, const void* element=0); +CV_EXPORTS void seqPop( CvSeq* seq, void* element=0); +CV_EXPORTS void seqPopFront( CvSeq* seq, void* element=0); +CV_EXPORTS void seqPopMulti( CvSeq* seq, void* elements, + int count, int in_front=0 ); +CV_EXPORTS void seqRemove( CvSeq* seq, int index ); +CV_EXPORTS void clearSeq( CvSeq* seq ); +CV_EXPORTS schar* getSeqElem( const CvSeq* seq, int index ); +CV_EXPORTS void seqRemoveSlice( CvSeq* seq, CvSlice slice ); +CV_EXPORTS void seqInsertSlice( CvSeq* seq, int before_index, const CvArr* from_arr ); + +template inline Seq<_Tp>::Seq() : seq(0) {} +template inline Seq<_Tp>::Seq( const CvSeq* _seq ) : seq((CvSeq*)_seq) +{ + CV_Assert(!_seq || _seq->elem_size == sizeof(_Tp)); +} + +template inline Seq<_Tp>::Seq( MemStorage& storage, + int headerSize ) +{ + CV_Assert(headerSize >= (int)sizeof(CvSeq)); + seq = cvCreateSeq(DataType<_Tp>::type, headerSize, sizeof(_Tp), storage); +} + +template inline _Tp& Seq<_Tp>::operator [](int idx) +{ return *(_Tp*)getSeqElem(seq, idx); } + +template inline const _Tp& Seq<_Tp>::operator [](int idx) const +{ return *(_Tp*)getSeqElem(seq, idx); } + +template inline SeqIterator<_Tp> Seq<_Tp>::begin() const +{ return SeqIterator<_Tp>(*this); } + +template inline SeqIterator<_Tp> Seq<_Tp>::end() const +{ return SeqIterator<_Tp>(*this, true); } + +template inline size_t Seq<_Tp>::size() const +{ return seq ? seq->total : 0; } + +template inline int Seq<_Tp>::type() const +{ return seq ? CV_MAT_TYPE(seq->flags) : 0; } + +template inline int Seq<_Tp>::depth() const +{ return seq ? CV_MAT_DEPTH(seq->flags) : 0; } + +template inline int Seq<_Tp>::channels() const +{ return seq ? CV_MAT_CN(seq->flags) : 0; } + +template inline size_t Seq<_Tp>::elemSize() const +{ return seq ? seq->elem_size : 0; } + +template inline size_t Seq<_Tp>::index(const _Tp& elem) const +{ return cvSeqElemIdx(seq, &elem); } + +template inline void Seq<_Tp>::push_back(const _Tp& elem) +{ cvSeqPush(seq, &elem); } + +template inline void Seq<_Tp>::push_front(const _Tp& elem) +{ cvSeqPushFront(seq, &elem); } + +template inline void Seq<_Tp>::push_back(const _Tp* elem, size_t count) +{ cvSeqPushMulti(seq, elem, (int)count, 0); } + +template inline void Seq<_Tp>::push_front(const _Tp* elem, size_t count) +{ cvSeqPushMulti(seq, elem, (int)count, 1); } + +template inline _Tp& Seq<_Tp>::back() +{ return *(_Tp*)getSeqElem(seq, -1); } + +template inline const _Tp& Seq<_Tp>::back() const +{ return *(const _Tp*)getSeqElem(seq, -1); } + +template inline _Tp& Seq<_Tp>::front() +{ return *(_Tp*)getSeqElem(seq, 0); } + +template inline const _Tp& Seq<_Tp>::front() const +{ return *(const _Tp*)getSeqElem(seq, 0); } + +template inline bool Seq<_Tp>::empty() const +{ return !seq || seq->total == 0; } + +template inline void Seq<_Tp>::clear() +{ if(seq) clearSeq(seq); } + +template inline void Seq<_Tp>::pop_back() +{ seqPop(seq); } + +template inline void Seq<_Tp>::pop_front() +{ seqPopFront(seq); } + +template inline void Seq<_Tp>::pop_back(_Tp* elem, size_t count) +{ seqPopMulti(seq, elem, (int)count, 0); } + +template inline void Seq<_Tp>::pop_front(_Tp* elem, size_t count) +{ seqPopMulti(seq, elem, (int)count, 1); } + +template inline void Seq<_Tp>::insert(int idx, const _Tp& elem) +{ seqInsert(seq, idx, &elem); } + +template inline void Seq<_Tp>::insert(int idx, const _Tp* elems, size_t count) +{ + CvMat m = cvMat(1, count, DataType<_Tp>::type, elems); + seqInsertSlice(seq, idx, &m); +} + +template inline void Seq<_Tp>::remove(int idx) +{ seqRemove(seq, idx); } + +template inline void Seq<_Tp>::remove(const Range& r) +{ seqRemoveSlice(seq, cvSlice(r.start, r.end)); } + +template inline void Seq<_Tp>::copyTo(std::vector<_Tp>& vec, const Range& range) const +{ + size_t len = !seq ? 0 : range == Range::all() ? seq->total : range.end - range.start; + vec.resize(len); + if( seq && len ) + cvCvtSeqToArray(seq, &vec[0], cvSlice(range)); +} + +template inline Seq<_Tp>::operator std::vector<_Tp>() const +{ + std::vector<_Tp> vec; + copyTo(vec); + return vec; +} + +template inline SeqIterator<_Tp>::SeqIterator() +{ memset(this, 0, sizeof(*this)); } + +template inline SeqIterator<_Tp>::SeqIterator(const Seq<_Tp>& _seq, bool seekEnd) +{ + cvStartReadSeq(_seq.seq, this); + index = seekEnd ? _seq.seq->total : 0; +} + +template inline void SeqIterator<_Tp>::seek(size_t pos) +{ + cvSetSeqReaderPos(this, (int)pos, false); + index = pos; +} + +template inline size_t SeqIterator<_Tp>::tell() const +{ return index; } + +template inline _Tp& SeqIterator<_Tp>::operator *() +{ return *(_Tp*)ptr; } + +template inline const _Tp& SeqIterator<_Tp>::operator *() const +{ return *(const _Tp*)ptr; } + +template inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator ++() +{ + CV_NEXT_SEQ_ELEM(sizeof(_Tp), *this); + if( ++index >= seq->total*2 ) + index = 0; + return *this; +} + +template inline SeqIterator<_Tp> SeqIterator<_Tp>::operator ++(int) const +{ + SeqIterator<_Tp> it = *this; + ++*this; + return it; +} + +template inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator --() +{ + CV_PREV_SEQ_ELEM(sizeof(_Tp), *this); + if( --index < 0 ) + index = seq->total*2-1; + return *this; +} + +template inline SeqIterator<_Tp> SeqIterator<_Tp>::operator --(int) const +{ + SeqIterator<_Tp> it = *this; + --*this; + return it; +} + +template inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator +=(int delta) +{ + cvSetSeqReaderPos(this, delta, 1); + index += delta; + int n = seq->total*2; + if( index < 0 ) + index += n; + if( index >= n ) + index -= n; + return *this; +} + +template inline SeqIterator<_Tp>& SeqIterator<_Tp>::operator -=(int delta) +{ + return (*this += -delta); +} + +template inline ptrdiff_t operator - (const SeqIterator<_Tp>& a, + const SeqIterator<_Tp>& b) +{ + ptrdiff_t delta = a.index - b.index, n = a.seq->total; + if( delta > n || delta < -n ) + delta += delta < 0 ? n : -n; + return delta; +} + +template inline bool operator == (const SeqIterator<_Tp>& a, + const SeqIterator<_Tp>& b) +{ + return a.seq == b.seq && a.index == b.index; +} + +template inline bool operator != (const SeqIterator<_Tp>& a, + const SeqIterator<_Tp>& b) +{ + return !(a == b); +} + +//! @} + +} // cv + +#endif + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda.hpp new file mode 100644 index 0000000000000000000000000000000000000000..99819d75cc8a6d36822631eb1980e8f89c993108 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda.hpp @@ -0,0 +1,1049 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_CUDA_HPP +#define OPENCV_CORE_CUDA_HPP + +#ifndef __cplusplus +# error cuda.hpp header must be compiled as C++ +#endif + +#include "opencv2/core.hpp" +#include "opencv2/core/cuda_types.hpp" + +/** + @defgroup cuda CUDA-accelerated Computer Vision + @{ + @defgroup cudacore Core part + @{ + @defgroup cudacore_init Initialization and Information + @defgroup cudacore_struct Data Structures + @} + @} + */ + +namespace cv { namespace cuda { + +//! @addtogroup cudacore_struct +//! @{ + +//=================================================================================== +// GpuMat +//=================================================================================== + +/** @brief Base storage class for GPU memory with reference counting. + +Its interface matches the Mat interface with the following limitations: + +- no arbitrary dimensions support (only 2D) +- no functions that return references to their data (because references on GPU are not valid for + CPU) +- no expression templates technique support + +Beware that the latter limitation may lead to overloaded matrix operators that cause memory +allocations. The GpuMat class is convertible to cuda::PtrStepSz and cuda::PtrStep so it can be +passed directly to the kernel. + +@note In contrast with Mat, in most cases GpuMat::isContinuous() == false . This means that rows are +aligned to a size depending on the hardware. Single-row GpuMat is always a continuous matrix. + +@note You are not recommended to leave static or global GpuMat variables allocated, that is, to rely +on its destructor. The destruction order of such variables and CUDA context is undefined. GPU memory +release function returns error if the CUDA context has been destroyed before. + +Some member functions are described as a "Blocking Call" while some are described as a +"Non-Blocking Call". Blocking functions are synchronous to host. It is guaranteed that the GPU +operation is finished when the function returns. However, non-blocking functions are asynchronous to +host. Those functions may return even if the GPU operation is not finished. + +Compared to their blocking counterpart, non-blocking functions accept Stream as an additional +argument. If a non-default stream is passed, the GPU operation may overlap with operations in other +streams. + +@sa Mat + */ +class CV_EXPORTS_W GpuMat +{ +public: + class CV_EXPORTS_W Allocator + { + public: + virtual ~Allocator() {} + + // allocator must fill data, step and refcount fields + virtual bool allocate(GpuMat* mat, int rows, int cols, size_t elemSize) = 0; + virtual void free(GpuMat* mat) = 0; + }; + + //! default allocator + CV_WRAP static GpuMat::Allocator* defaultAllocator(); + CV_WRAP static void setDefaultAllocator(GpuMat::Allocator* allocator); + + //! default constructor + CV_WRAP explicit GpuMat(GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + + //! constructs GpuMat of the specified size and type + CV_WRAP GpuMat(int rows, int cols, int type, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + CV_WRAP GpuMat(Size size, int type, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + + //! constructs GpuMat and fills it with the specified value _s + CV_WRAP GpuMat(int rows, int cols, int type, Scalar s, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + CV_WRAP GpuMat(Size size, int type, Scalar s, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + + //! copy constructor + CV_WRAP GpuMat(const GpuMat& m); + + //! constructor for GpuMat headers pointing to user-allocated data + GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP); + GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP); + + //! creates a GpuMat header for a part of the bigger matrix + CV_WRAP GpuMat(const GpuMat& m, Range rowRange, Range colRange); + CV_WRAP GpuMat(const GpuMat& m, Rect roi); + + //! builds GpuMat from host memory (Blocking call) + CV_WRAP explicit GpuMat(InputArray arr, GpuMat::Allocator* allocator = GpuMat::defaultAllocator()); + + //! destructor - calls release() + ~GpuMat(); + + //! assignment operators + GpuMat& operator =(const GpuMat& m); + + //! allocates new GpuMat data unless the GpuMat already has specified size and type + CV_WRAP void create(int rows, int cols, int type); + CV_WRAP void create(Size size, int type); + + //! decreases reference counter, deallocate the data when reference counter reaches 0 + void release(); + + //! swaps with other smart pointer + CV_WRAP void swap(GpuMat& mat); + + /** @brief Performs data upload to GpuMat (Blocking call) + + This function copies data from host memory to device memory. As being a blocking call, it is + guaranteed that the copy operation is finished when this function returns. + */ + CV_WRAP void upload(InputArray arr); + + /** @brief Performs data upload to GpuMat (Non-Blocking call) + + This function copies data from host memory to device memory. As being a non-blocking call, this + function may return even if the copy operation is not finished. + + The copy operation may be overlapped with operations in other non-default streams if \p stream is + not the default stream and \p dst is HostMem allocated with HostMem::PAGE_LOCKED option. + */ + CV_WRAP void upload(InputArray arr, Stream& stream); + + /** @brief Performs data download from GpuMat (Blocking call) + + This function copies data from device memory to host memory. As being a blocking call, it is + guaranteed that the copy operation is finished when this function returns. + */ + CV_WRAP void download(OutputArray dst) const; + + /** @brief Performs data download from GpuMat (Non-Blocking call) + + This function copies data from device memory to host memory. As being a non-blocking call, this + function may return even if the copy operation is not finished. + + The copy operation may be overlapped with operations in other non-default streams if \p stream is + not the default stream and \p dst is HostMem allocated with HostMem::PAGE_LOCKED option. + */ + CV_WRAP void download(OutputArray dst, Stream& stream) const; + + //! returns deep copy of the GpuMat, i.e. the data is copied + CV_WRAP GpuMat clone() const; + + //! copies the GpuMat content to device memory (Blocking call) + CV_WRAP void copyTo(OutputArray dst) const; + + //! copies the GpuMat content to device memory (Non-Blocking call) + CV_WRAP void copyTo(OutputArray dst, Stream& stream) const; + + //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Blocking call) + CV_WRAP void copyTo(OutputArray dst, InputArray mask) const; + + //! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Non-Blocking call) + CV_WRAP void copyTo(OutputArray dst, InputArray mask, Stream& stream) const; + + //! sets some of the GpuMat elements to s (Blocking call) + CV_WRAP GpuMat& setTo(Scalar s); + + //! sets some of the GpuMat elements to s (Non-Blocking call) + CV_WRAP GpuMat& setTo(Scalar s, Stream& stream); + + //! sets some of the GpuMat elements to s, according to the mask (Blocking call) + CV_WRAP GpuMat& setTo(Scalar s, InputArray mask); + + //! sets some of the GpuMat elements to s, according to the mask (Non-Blocking call) + CV_WRAP GpuMat& setTo(Scalar s, InputArray mask, Stream& stream); + + //! converts GpuMat to another datatype (Blocking call) + CV_WRAP void convertTo(OutputArray dst, int rtype) const; + + //! converts GpuMat to another datatype (Non-Blocking call) + CV_WRAP void convertTo(OutputArray dst, int rtype, Stream& stream) const; + + //! converts GpuMat to another datatype with scaling (Blocking call) + CV_WRAP void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const; + + //! converts GpuMat to another datatype with scaling (Non-Blocking call) + CV_WRAP void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const; + + //! converts GpuMat to another datatype with scaling (Non-Blocking call) + CV_WRAP void convertTo(OutputArray dst, int rtype, double alpha, double beta, Stream& stream) const; + + CV_WRAP void assignTo(GpuMat& m, int type = -1) const; + + //! returns pointer to y-th row + uchar* ptr(int y = 0); + const uchar* ptr(int y = 0) const; + + //! template version of the above method + template _Tp* ptr(int y = 0); + template const _Tp* ptr(int y = 0) const; + + template operator PtrStepSz<_Tp>() const; + template operator PtrStep<_Tp>() const; + + //! returns a new GpuMat header for the specified row + CV_WRAP GpuMat row(int y) const; + + //! returns a new GpuMat header for the specified column + CV_WRAP GpuMat col(int x) const; + + //! ... for the specified row span + CV_WRAP GpuMat rowRange(int startrow, int endrow) const; + CV_WRAP GpuMat rowRange(Range r) const; + + //! ... for the specified column span + CV_WRAP GpuMat colRange(int startcol, int endcol) const; + CV_WRAP GpuMat colRange(Range r) const; + + //! extracts a rectangular sub-GpuMat (this is a generalized form of row, rowRange etc.) + GpuMat operator ()(Range rowRange, Range colRange) const; + GpuMat operator ()(Rect roi) const; + + //! creates alternative GpuMat header for the same data, with different + //! number of channels and/or different number of rows + CV_WRAP GpuMat reshape(int cn, int rows = 0) const; + + //! locates GpuMat header within a parent GpuMat + CV_WRAP void locateROI(Size& wholeSize, Point& ofs) const; + + //! moves/resizes the current GpuMat ROI inside the parent GpuMat + CV_WRAP GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright); + + //! returns true iff the GpuMat data is continuous + //! (i.e. when there are no gaps between successive rows) + CV_WRAP bool isContinuous() const; + + //! returns element size in bytes + CV_WRAP size_t elemSize() const; + + //! returns the size of element channel in bytes + CV_WRAP size_t elemSize1() const; + + //! returns element type + CV_WRAP int type() const; + + //! returns element type + CV_WRAP int depth() const; + + //! returns number of channels + CV_WRAP int channels() const; + + //! returns step/elemSize1() + CV_WRAP size_t step1() const; + + //! returns GpuMat size : width == number of columns, height == number of rows + CV_WRAP Size size() const; + + //! returns true if GpuMat data is NULL + CV_WRAP bool empty() const; + + //! internal use method: updates the continuity flag + CV_WRAP void updateContinuityFlag(); + + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + + //! the number of rows and columns + int rows, cols; + + //! a distance between successive rows in bytes; includes the gap if any + CV_PROP size_t step; + + //! pointer to the data + uchar* data; + + //! pointer to the reference counter; + //! when GpuMat points to user-allocated data, the pointer is NULL + int* refcount; + + //! helper fields used in locateROI and adjustROI + uchar* datastart; + const uchar* dataend; + + //! allocator + Allocator* allocator; +}; + +/** @brief Creates a continuous matrix. + +@param rows Row count. +@param cols Column count. +@param type Type of the matrix. +@param arr Destination matrix. This parameter changes only if it has a proper type and area ( +\f$\texttt{rows} \times \texttt{cols}\f$ ). + +Matrix is called continuous if its elements are stored continuously, that is, without gaps at the +end of each row. + */ +CV_EXPORTS_W void createContinuous(int rows, int cols, int type, OutputArray arr); + +/** @brief Ensures that the size of a matrix is big enough and the matrix has a proper type. + +@param rows Minimum desired number of rows. +@param cols Minimum desired number of columns. +@param type Desired matrix type. +@param arr Destination matrix. + +The function does not reallocate memory if the matrix has proper attributes already. + */ +CV_EXPORTS_W void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr); + +/** @brief BufferPool for use with CUDA streams + +BufferPool utilizes Stream's allocator to create new buffers for GpuMat's. It is +only useful when enabled with #setBufferPoolUsage. + +@code + setBufferPoolUsage(true); +@endcode + +@note #setBufferPoolUsage must be called \em before any Stream declaration. + +Users may specify custom allocator for Stream and may implement their own stream based +functions utilizing the same underlying GPU memory management. + +If custom allocator is not specified, BufferPool utilizes StackAllocator by +default. StackAllocator allocates a chunk of GPU device memory beforehand, +and when GpuMat is declared later on, it is given the pre-allocated memory. +This kind of strategy reduces the number of calls for memory allocating APIs +such as cudaMalloc or cudaMallocPitch. + +Below is an example that utilizes BufferPool with StackAllocator: + +@code + #include + + using namespace cv; + using namespace cv::cuda + + int main() + { + setBufferPoolUsage(true); // Tell OpenCV that we are going to utilize BufferPool + setBufferPoolConfig(getDevice(), 1024 * 1024 * 64, 2); // Allocate 64 MB, 2 stacks (default is 10 MB, 5 stacks) + + Stream stream1, stream2; // Each stream uses 1 stack + BufferPool pool1(stream1), pool2(stream2); + + GpuMat d_src1 = pool1.getBuffer(4096, 4096, CV_8UC1); // 16MB + GpuMat d_dst1 = pool1.getBuffer(4096, 4096, CV_8UC3); // 48MB, pool1 is now full + + GpuMat d_src2 = pool2.getBuffer(1024, 1024, CV_8UC1); // 1MB + GpuMat d_dst2 = pool2.getBuffer(1024, 1024, CV_8UC3); // 3MB + + cvtColor(d_src1, d_dst1, CV_GRAY2BGR, 0, stream1); + cvtColor(d_src2, d_dst2, CV_GRAY2BGR, 0, stream2); + } +@endcode + +If we allocate another GpuMat on pool1 in the above example, it will be carried out by +the DefaultAllocator since the stack for pool1 is full. + +@code + GpuMat d_add1 = pool1.getBuffer(1024, 1024, CV_8UC1); // Stack for pool1 is full, memory is allocated with DefaultAllocator +@endcode + +If a third stream is declared in the above example, allocating with #getBuffer +within that stream will also be carried out by the DefaultAllocator because we've run out of +stacks. + +@code + Stream stream3; // Only 2 stacks were allocated, we've run out of stacks + BufferPool pool3(stream3); + GpuMat d_src3 = pool3.getBuffer(1024, 1024, CV_8UC1); // Memory is allocated with DefaultAllocator +@endcode + +@warning When utilizing StackAllocator, deallocation order is important. + +Just like a stack, deallocation must be done in LIFO order. Below is an example of +erroneous usage that violates LIFO rule. If OpenCV is compiled in Debug mode, this +sample code will emit CV_Assert error. + +@code + int main() + { + setBufferPoolUsage(true); // Tell OpenCV that we are going to utilize BufferPool + Stream stream; // A default size (10 MB) stack is allocated to this stream + BufferPool pool(stream); + + GpuMat mat1 = pool.getBuffer(1024, 1024, CV_8UC1); // Allocate mat1 (1MB) + GpuMat mat2 = pool.getBuffer(1024, 1024, CV_8UC1); // Allocate mat2 (1MB) + + mat1.release(); // erroneous usage : mat2 must be deallocated before mat1 + } +@endcode + +Since C++ local variables are destroyed in the reverse order of construction, +the code sample below satisfies the LIFO rule. Local GpuMat's are deallocated +and the corresponding memory is automatically returned to the pool for later usage. + +@code + int main() + { + setBufferPoolUsage(true); // Tell OpenCV that we are going to utilize BufferPool + setBufferPoolConfig(getDevice(), 1024 * 1024 * 64, 2); // Allocate 64 MB, 2 stacks (default is 10 MB, 5 stacks) + + Stream stream1, stream2; // Each stream uses 1 stack + BufferPool pool1(stream1), pool2(stream2); + + for (int i = 0; i < 10; i++) + { + GpuMat d_src1 = pool1.getBuffer(4096, 4096, CV_8UC1); // 16MB + GpuMat d_dst1 = pool1.getBuffer(4096, 4096, CV_8UC3); // 48MB, pool1 is now full + + GpuMat d_src2 = pool2.getBuffer(1024, 1024, CV_8UC1); // 1MB + GpuMat d_dst2 = pool2.getBuffer(1024, 1024, CV_8UC3); // 3MB + + d_src1.setTo(Scalar(i), stream1); + d_src2.setTo(Scalar(i), stream2); + + cvtColor(d_src1, d_dst1, CV_GRAY2BGR, 0, stream1); + cvtColor(d_src2, d_dst2, CV_GRAY2BGR, 0, stream2); + // The order of destruction of the local variables is: + // d_dst2 => d_src2 => d_dst1 => d_src1 + // LIFO rule is satisfied, this code runs without error + } + } +@endcode + */ +class CV_EXPORTS_W BufferPool +{ +public: + + //! Gets the BufferPool for the given stream. + explicit BufferPool(Stream& stream); + + //! Allocates a new GpuMat of given size and type. + CV_WRAP GpuMat getBuffer(int rows, int cols, int type); + + //! Allocates a new GpuMat of given size and type. + CV_WRAP GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); } + + //! Returns the allocator associated with the stream. + CV_WRAP Ptr getAllocator() const { return allocator_; } + +private: + Ptr allocator_; +}; + +//! BufferPool management (must be called before Stream creation) +CV_EXPORTS_W void setBufferPoolUsage(bool on); +CV_EXPORTS_W void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount); + +//=================================================================================== +// HostMem +//=================================================================================== + +/** @brief Class with reference counting wrapping special memory type allocation functions from CUDA. + +Its interface is also Mat-like but with additional memory type parameters. + +- **PAGE_LOCKED** sets a page locked memory type used commonly for fast and asynchronous + uploading/downloading data from/to GPU. +- **SHARED** specifies a zero copy memory allocation that enables mapping the host memory to GPU + address space, if supported. +- **WRITE_COMBINED** sets the write combined buffer that is not cached by CPU. Such buffers are + used to supply GPU with data when GPU only reads it. The advantage is a better CPU cache + utilization. + +@note Allocation size of such memory types is usually limited. For more details, see *CUDA 2.2 +Pinned Memory APIs* document or *CUDA C Programming Guide*. + */ +class CV_EXPORTS_W HostMem +{ +public: + enum AllocType { PAGE_LOCKED = 1, SHARED = 2, WRITE_COMBINED = 4 }; + + static MatAllocator* getAllocator(HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); + + CV_WRAP explicit HostMem(HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); + + HostMem(const HostMem& m); + + CV_WRAP HostMem(int rows, int cols, int type, HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); + CV_WRAP HostMem(Size size, int type, HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); + + //! creates from host memory with coping data + CV_WRAP explicit HostMem(InputArray arr, HostMem::AllocType alloc_type = HostMem::AllocType::PAGE_LOCKED); + + ~HostMem(); + + HostMem& operator =(const HostMem& m); + + //! swaps with other smart pointer + CV_WRAP void swap(HostMem& b); + + //! returns deep copy of the matrix, i.e. the data is copied + CV_WRAP HostMem clone() const; + + //! allocates new matrix data unless the matrix already has specified size and type. + CV_WRAP void create(int rows, int cols, int type); + void create(Size size, int type); + + //! creates alternative HostMem header for the same data, with different + //! number of channels and/or different number of rows + CV_WRAP HostMem reshape(int cn, int rows = 0) const; + + //! decrements reference counter and released memory if needed. + void release(); + + //! returns matrix header with disabled reference counting for HostMem data. + CV_WRAP Mat createMatHeader() const; + + /** @brief Maps CPU memory to GPU address space and creates the cuda::GpuMat header without reference counting + for it. + + This can be done only if memory was allocated with the SHARED flag and if it is supported by the + hardware. Laptops often share video and CPU memory, so address spaces can be mapped, which + eliminates an extra copy. + */ + GpuMat createGpuMatHeader() const; + + // Please see cv::Mat for descriptions + CV_WRAP bool isContinuous() const; + CV_WRAP size_t elemSize() const; + CV_WRAP size_t elemSize1() const; + CV_WRAP int type() const; + CV_WRAP int depth() const; + CV_WRAP int channels() const; + CV_WRAP size_t step1() const; + CV_WRAP Size size() const; + CV_WRAP bool empty() const; + + // Please see cv::Mat for descriptions + int flags; + int rows, cols; + CV_PROP size_t step; + + uchar* data; + int* refcount; + + uchar* datastart; + const uchar* dataend; + + AllocType alloc_type; +}; + +/** @brief Page-locks the memory of matrix and maps it for the device(s). + +@param m Input matrix. + */ +CV_EXPORTS_W void registerPageLocked(Mat& m); + +/** @brief Unmaps the memory of matrix and makes it pageable again. + +@param m Input matrix. + */ +CV_EXPORTS_W void unregisterPageLocked(Mat& m); + +//=================================================================================== +// Stream +//=================================================================================== + +/** @brief This class encapsulates a queue of asynchronous calls. + +@note Currently, you may face problems if an operation is enqueued twice with different data. Some +functions use the constant GPU memory, and next call may update the memory before the previous one +has been finished. But calling different operations asynchronously is safe because each operation +has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are +also safe. + +@note The Stream class is not thread-safe. Please use different Stream objects for different CPU threads. + +@code +void thread1() +{ + cv::cuda::Stream stream1; + cv::cuda::func1(..., stream1); +} + +void thread2() +{ + cv::cuda::Stream stream2; + cv::cuda::func2(..., stream2); +} +@endcode + +@note By default all CUDA routines are launched in Stream::Null() object, if the stream is not specified by user. +In multi-threading environment the stream objects must be passed explicitly (see previous note). + */ +class CV_EXPORTS_W Stream +{ + typedef void (Stream::*bool_type)() const; + void this_type_does_not_support_comparisons() const {} + +public: + typedef void (*StreamCallback)(int status, void* userData); + + //! creates a new asynchronous stream + CV_WRAP Stream(); + + //! creates a new asynchronous stream with custom allocator + CV_WRAP Stream(const Ptr& allocator); + + /** @brief Returns true if the current stream queue is finished. Otherwise, it returns false. + */ + CV_WRAP bool queryIfComplete() const; + + /** @brief Blocks the current CPU thread until all operations in the stream are complete. + */ + CV_WRAP void waitForCompletion(); + + /** @brief Makes a compute stream wait on an event. + */ + CV_WRAP void waitEvent(const Event& event); + + /** @brief Adds a callback to be called on the host after all currently enqueued items in the stream have + completed. + + @note Callbacks must not make any CUDA API calls. Callbacks must not perform any synchronization + that may depend on outstanding device work or other callbacks that are not mandated to run earlier. + Callbacks without a mandated order (in independent streams) execute in undefined order and may be + serialized. + */ + void enqueueHostCallback(StreamCallback callback, void* userData); + + //! return Stream object for default CUDA stream + CV_WRAP static Stream& Null(); + + //! returns true if stream object is not default (!= 0) + operator bool_type() const; + + class Impl; + +private: + Ptr impl_; + Stream(const Ptr& impl); + + friend struct StreamAccessor; + friend class BufferPool; + friend class DefaultDeviceInitializer; +}; + +class CV_EXPORTS_W Event +{ +public: + enum CreateFlags + { + DEFAULT = 0x00, /**< Default event flag */ + BLOCKING_SYNC = 0x01, /**< Event uses blocking synchronization */ + DISABLE_TIMING = 0x02, /**< Event will not record timing data */ + INTERPROCESS = 0x04 /**< Event is suitable for interprocess use. DisableTiming must be set */ + }; + + CV_WRAP explicit Event(Event::CreateFlags flags = Event::CreateFlags::DEFAULT); + + //! records an event + CV_WRAP void record(Stream& stream = Stream::Null()); + + //! queries an event's status + CV_WRAP bool queryIfComplete() const; + + //! waits for an event to complete + CV_WRAP void waitForCompletion(); + + //! computes the elapsed time between events + CV_WRAP static float elapsedTime(const Event& start, const Event& end); + + class Impl; + +private: + Ptr impl_; + Event(const Ptr& impl); + + friend struct EventAccessor; +}; + +//! @} cudacore_struct + +//=================================================================================== +// Initialization & Info +//=================================================================================== + +//! @addtogroup cudacore_init +//! @{ + +/** @brief Returns the number of installed CUDA-enabled devices. + +Use this function before any other CUDA functions calls. If OpenCV is compiled without CUDA support, +this function returns 0. If the CUDA driver is not installed, or is incompatible, this function +returns -1. + */ +CV_EXPORTS_W int getCudaEnabledDeviceCount(); + +/** @brief Sets a device and initializes it for the current thread. + +@param device System index of a CUDA device starting with 0. + +If the call of this function is omitted, a default device is initialized at the fist CUDA usage. + */ +CV_EXPORTS_W void setDevice(int device); + +/** @brief Returns the current device index set by cuda::setDevice or initialized by default. + */ +CV_EXPORTS_W int getDevice(); + +/** @brief Explicitly destroys and cleans up all resources associated with the current device in the current +process. + +Any subsequent API call to this device will reinitialize the device. + */ +CV_EXPORTS_W void resetDevice(); + +/** @brief Enumeration providing CUDA computing features. + */ +enum FeatureSet +{ + FEATURE_SET_COMPUTE_10 = 10, + FEATURE_SET_COMPUTE_11 = 11, + FEATURE_SET_COMPUTE_12 = 12, + FEATURE_SET_COMPUTE_13 = 13, + FEATURE_SET_COMPUTE_20 = 20, + FEATURE_SET_COMPUTE_21 = 21, + FEATURE_SET_COMPUTE_30 = 30, + FEATURE_SET_COMPUTE_32 = 32, + FEATURE_SET_COMPUTE_35 = 35, + FEATURE_SET_COMPUTE_50 = 50, + + GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11, + SHARED_ATOMICS = FEATURE_SET_COMPUTE_12, + NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13, + WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30, + DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35 +}; + +//! checks whether current device supports the given feature +CV_EXPORTS bool deviceSupports(FeatureSet feature_set); + +/** @brief Class providing a set of static methods to check what NVIDIA\* card architecture the CUDA module was +built for. + +According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute +capability can always be compiled to binary code of greater or equal compute capability". + */ +class CV_EXPORTS_W TargetArchs +{ +public: + /** @brief The following method checks whether the module was built with the support of the given feature: + + @param feature_set Features to be checked. See :ocvcuda::FeatureSet. + */ + static bool builtWith(FeatureSet feature_set); + + /** @brief There is a set of methods to check whether the module contains intermediate (PTX) or binary CUDA + code for the given architecture(s): + + @param major Major compute capability version. + @param minor Minor compute capability version. + */ + CV_WRAP static bool has(int major, int minor); + CV_WRAP static bool hasPtx(int major, int minor); + CV_WRAP static bool hasBin(int major, int minor); + + CV_WRAP static bool hasEqualOrLessPtx(int major, int minor); + CV_WRAP static bool hasEqualOrGreater(int major, int minor); + CV_WRAP static bool hasEqualOrGreaterPtx(int major, int minor); + CV_WRAP static bool hasEqualOrGreaterBin(int major, int minor); +}; + +/** @brief Class providing functionality for querying the specified GPU properties. + */ +class CV_EXPORTS_W DeviceInfo +{ +public: + //! creates DeviceInfo object for the current GPU + CV_WRAP DeviceInfo(); + + /** @brief The constructors. + + @param device_id System index of the CUDA device starting with 0. + + Constructs the DeviceInfo object for the specified device. If device_id parameter is missed, it + constructs an object for the current device. + */ + CV_WRAP DeviceInfo(int device_id); + + /** @brief Returns system index of the CUDA device starting with 0. + */ + CV_WRAP int deviceID() const; + + //! ASCII string identifying device + const char* name() const; + + //! global memory available on device in bytes + CV_WRAP size_t totalGlobalMem() const; + + //! shared memory available per block in bytes + CV_WRAP size_t sharedMemPerBlock() const; + + //! 32-bit registers available per block + CV_WRAP int regsPerBlock() const; + + //! warp size in threads + CV_WRAP int warpSize() const; + + //! maximum pitch in bytes allowed by memory copies + CV_WRAP size_t memPitch() const; + + //! maximum number of threads per block + CV_WRAP int maxThreadsPerBlock() const; + + //! maximum size of each dimension of a block + CV_WRAP Vec3i maxThreadsDim() const; + + //! maximum size of each dimension of a grid + CV_WRAP Vec3i maxGridSize() const; + + //! clock frequency in kilohertz + CV_WRAP int clockRate() const; + + //! constant memory available on device in bytes + CV_WRAP size_t totalConstMem() const; + + //! major compute capability + CV_WRAP int majorVersion() const; + + //! minor compute capability + CV_WRAP int minorVersion() const; + + //! alignment requirement for textures + CV_WRAP size_t textureAlignment() const; + + //! pitch alignment requirement for texture references bound to pitched memory + CV_WRAP size_t texturePitchAlignment() const; + + //! number of multiprocessors on device + CV_WRAP int multiProcessorCount() const; + + //! specified whether there is a run time limit on kernels + CV_WRAP bool kernelExecTimeoutEnabled() const; + + //! device is integrated as opposed to discrete + CV_WRAP bool integrated() const; + + //! device can map host memory with cudaHostAlloc/cudaHostGetDevicePointer + CV_WRAP bool canMapHostMemory() const; + + enum ComputeMode + { + ComputeModeDefault, /**< default compute mode (Multiple threads can use cudaSetDevice with this device) */ + ComputeModeExclusive, /**< compute-exclusive-thread mode (Only one thread in one process will be able to use cudaSetDevice with this device) */ + ComputeModeProhibited, /**< compute-prohibited mode (No threads can use cudaSetDevice with this device) */ + ComputeModeExclusiveProcess /**< compute-exclusive-process mode (Many threads in one process will be able to use cudaSetDevice with this device) */ + }; + + //! compute mode + CV_WRAP DeviceInfo::ComputeMode computeMode() const; + + //! maximum 1D texture size + CV_WRAP int maxTexture1D() const; + + //! maximum 1D mipmapped texture size + CV_WRAP int maxTexture1DMipmap() const; + + //! maximum size for 1D textures bound to linear memory + CV_WRAP int maxTexture1DLinear() const; + + //! maximum 2D texture dimensions + CV_WRAP Vec2i maxTexture2D() const; + + //! maximum 2D mipmapped texture dimensions + CV_WRAP Vec2i maxTexture2DMipmap() const; + + //! maximum dimensions (width, height, pitch) for 2D textures bound to pitched memory + CV_WRAP Vec3i maxTexture2DLinear() const; + + //! maximum 2D texture dimensions if texture gather operations have to be performed + CV_WRAP Vec2i maxTexture2DGather() const; + + //! maximum 3D texture dimensions + CV_WRAP Vec3i maxTexture3D() const; + + //! maximum Cubemap texture dimensions + CV_WRAP int maxTextureCubemap() const; + + //! maximum 1D layered texture dimensions + CV_WRAP Vec2i maxTexture1DLayered() const; + + //! maximum 2D layered texture dimensions + CV_WRAP Vec3i maxTexture2DLayered() const; + + //! maximum Cubemap layered texture dimensions + CV_WRAP Vec2i maxTextureCubemapLayered() const; + + //! maximum 1D surface size + CV_WRAP int maxSurface1D() const; + + //! maximum 2D surface dimensions + CV_WRAP Vec2i maxSurface2D() const; + + //! maximum 3D surface dimensions + CV_WRAP Vec3i maxSurface3D() const; + + //! maximum 1D layered surface dimensions + CV_WRAP Vec2i maxSurface1DLayered() const; + + //! maximum 2D layered surface dimensions + CV_WRAP Vec3i maxSurface2DLayered() const; + + //! maximum Cubemap surface dimensions + CV_WRAP int maxSurfaceCubemap() const; + + //! maximum Cubemap layered surface dimensions + CV_WRAP Vec2i maxSurfaceCubemapLayered() const; + + //! alignment requirements for surfaces + CV_WRAP size_t surfaceAlignment() const; + + //! device can possibly execute multiple kernels concurrently + CV_WRAP bool concurrentKernels() const; + + //! device has ECC support enabled + CV_WRAP bool ECCEnabled() const; + + //! PCI bus ID of the device + CV_WRAP int pciBusID() const; + + //! PCI device ID of the device + CV_WRAP int pciDeviceID() const; + + //! PCI domain ID of the device + CV_WRAP int pciDomainID() const; + + //! true if device is a Tesla device using TCC driver, false otherwise + CV_WRAP bool tccDriver() const; + + //! number of asynchronous engines + CV_WRAP int asyncEngineCount() const; + + //! device shares a unified address space with the host + CV_WRAP bool unifiedAddressing() const; + + //! peak memory clock frequency in kilohertz + CV_WRAP int memoryClockRate() const; + + //! global memory bus width in bits + CV_WRAP int memoryBusWidth() const; + + //! size of L2 cache in bytes + CV_WRAP int l2CacheSize() const; + + //! maximum resident threads per multiprocessor + CV_WRAP int maxThreadsPerMultiProcessor() const; + + //! gets free and total device memory + CV_WRAP void queryMemory(size_t& totalMemory, size_t& freeMemory) const; + CV_WRAP size_t freeMemory() const; + CV_WRAP size_t totalMemory() const; + + /** @brief Provides information on CUDA feature support. + + @param feature_set Features to be checked. See cuda::FeatureSet. + + This function returns true if the device has the specified CUDA feature. Otherwise, it returns false + */ + bool supports(FeatureSet feature_set) const; + + /** @brief Checks the CUDA module and device compatibility. + + This function returns true if the CUDA module can be run on the specified device. Otherwise, it + returns false . + */ + CV_WRAP bool isCompatible() const; + +private: + int device_id_; +}; + +CV_EXPORTS_W void printCudaDeviceInfo(int device); +CV_EXPORTS_W void printShortCudaDeviceInfo(int device); + +/** @brief Converts an array to half precision floating number. + +@param _src input array. +@param _dst output array. +@param stream Stream for the asynchronous version. +@sa convertFp16 +*/ +CV_EXPORTS void convertFp16(InputArray _src, OutputArray _dst, Stream& stream = Stream::Null()); + +//! @} cudacore_init + +}} // namespace cv { namespace cuda { + + +#include "opencv2/core/cuda.inl.hpp" + +#endif /* OPENCV_CORE_CUDA_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda.inl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda.inl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..35ae2e49d77f331cca5d6cb13a48f3a6885c2ab7 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda.inl.hpp @@ -0,0 +1,631 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_CUDAINL_HPP +#define OPENCV_CORE_CUDAINL_HPP + +#include "opencv2/core/cuda.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { + +//=================================================================================== +// GpuMat +//=================================================================================== + +inline +GpuMat::GpuMat(Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{} + +inline +GpuMat::GpuMat(int rows_, int cols_, int type_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (rows_ > 0 && cols_ > 0) + create(rows_, cols_, type_); +} + +inline +GpuMat::GpuMat(Size size_, int type_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (size_.height > 0 && size_.width > 0) + create(size_.height, size_.width, type_); +} + +inline +GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (rows_ > 0 && cols_ > 0) + { + create(rows_, cols_, type_); + setTo(s_); + } +} + +inline +GpuMat::GpuMat(Size size_, int type_, Scalar s_, Allocator* allocator_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + if (size_.height > 0 && size_.width > 0) + { + create(size_.height, size_.width, type_); + setTo(s_); + } +} + +inline +GpuMat::GpuMat(const GpuMat& m) + : flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), allocator(m.allocator) +{ + if (refcount) + CV_XADD(refcount, 1); +} + +inline +GpuMat::GpuMat(InputArray arr, Allocator* allocator_) : + flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_) +{ + upload(arr); +} + +inline +GpuMat::~GpuMat() +{ + release(); +} + +inline +GpuMat& GpuMat::operator =(const GpuMat& m) +{ + if (this != &m) + { + GpuMat temp(m); + swap(temp); + } + + return *this; +} + +inline +void GpuMat::create(Size size_, int type_) +{ + create(size_.height, size_.width, type_); +} + +inline +void GpuMat::swap(GpuMat& b) +{ + std::swap(flags, b.flags); + std::swap(rows, b.rows); + std::swap(cols, b.cols); + std::swap(step, b.step); + std::swap(data, b.data); + std::swap(datastart, b.datastart); + std::swap(dataend, b.dataend); + std::swap(refcount, b.refcount); + std::swap(allocator, b.allocator); +} + +inline +GpuMat GpuMat::clone() const +{ + GpuMat m; + copyTo(m); + return m; +} + +inline +void GpuMat::copyTo(OutputArray dst, InputArray mask) const +{ + copyTo(dst, mask, Stream::Null()); +} + +inline +GpuMat& GpuMat::setTo(Scalar s) +{ + return setTo(s, Stream::Null()); +} + +inline +GpuMat& GpuMat::setTo(Scalar s, InputArray mask) +{ + return setTo(s, mask, Stream::Null()); +} + +inline +void GpuMat::convertTo(OutputArray dst, int rtype) const +{ + convertTo(dst, rtype, Stream::Null()); +} + +inline +void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, double beta) const +{ + convertTo(dst, rtype, alpha, beta, Stream::Null()); +} + +inline +void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const +{ + convertTo(dst, rtype, alpha, 0.0, stream); +} + +inline +void GpuMat::assignTo(GpuMat& m, int _type) const +{ + if (_type < 0) + m = *this; + else + convertTo(m, _type); +} + +inline +uchar* GpuMat::ptr(int y) +{ + CV_DbgAssert( (unsigned)y < (unsigned)rows ); + return data + step * y; +} + +inline +const uchar* GpuMat::ptr(int y) const +{ + CV_DbgAssert( (unsigned)y < (unsigned)rows ); + return data + step * y; +} + +template inline +_Tp* GpuMat::ptr(int y) +{ + return (_Tp*)ptr(y); +} + +template inline +const _Tp* GpuMat::ptr(int y) const +{ + return (const _Tp*)ptr(y); +} + +template inline +GpuMat::operator PtrStepSz() const +{ + return PtrStepSz(rows, cols, (T*)data, step); +} + +template inline +GpuMat::operator PtrStep() const +{ + return PtrStep((T*)data, step); +} + +inline +GpuMat GpuMat::row(int y) const +{ + return GpuMat(*this, Range(y, y+1), Range::all()); +} + +inline +GpuMat GpuMat::col(int x) const +{ + return GpuMat(*this, Range::all(), Range(x, x+1)); +} + +inline +GpuMat GpuMat::rowRange(int startrow, int endrow) const +{ + return GpuMat(*this, Range(startrow, endrow), Range::all()); +} + +inline +GpuMat GpuMat::rowRange(Range r) const +{ + return GpuMat(*this, r, Range::all()); +} + +inline +GpuMat GpuMat::colRange(int startcol, int endcol) const +{ + return GpuMat(*this, Range::all(), Range(startcol, endcol)); +} + +inline +GpuMat GpuMat::colRange(Range r) const +{ + return GpuMat(*this, Range::all(), r); +} + +inline +GpuMat GpuMat::operator ()(Range rowRange_, Range colRange_) const +{ + return GpuMat(*this, rowRange_, colRange_); +} + +inline +GpuMat GpuMat::operator ()(Rect roi) const +{ + return GpuMat(*this, roi); +} + +inline +bool GpuMat::isContinuous() const +{ + return (flags & Mat::CONTINUOUS_FLAG) != 0; +} + +inline +size_t GpuMat::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} + +inline +size_t GpuMat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int GpuMat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int GpuMat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int GpuMat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t GpuMat::step1() const +{ + return step / elemSize1(); +} + +inline +Size GpuMat::size() const +{ + return Size(cols, rows); +} + +inline +bool GpuMat::empty() const +{ + return data == 0; +} + +static inline +GpuMat createContinuous(int rows, int cols, int type) +{ + GpuMat m; + createContinuous(rows, cols, type, m); + return m; +} + +static inline +void createContinuous(Size size, int type, OutputArray arr) +{ + createContinuous(size.height, size.width, type, arr); +} + +static inline +GpuMat createContinuous(Size size, int type) +{ + GpuMat m; + createContinuous(size, type, m); + return m; +} + +static inline +void ensureSizeIsEnough(Size size, int type, OutputArray arr) +{ + ensureSizeIsEnough(size.height, size.width, type, arr); +} + +static inline +void swap(GpuMat& a, GpuMat& b) +{ + a.swap(b); +} + +//=================================================================================== +// HostMem +//=================================================================================== + +inline +HostMem::HostMem(AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ +} + +inline +HostMem::HostMem(const HostMem& m) + : flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), alloc_type(m.alloc_type) +{ + if( refcount ) + CV_XADD(refcount, 1); +} + +inline +HostMem::HostMem(int rows_, int cols_, int type_, AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ + if (rows_ > 0 && cols_ > 0) + create(rows_, cols_, type_); +} + +inline +HostMem::HostMem(Size size_, int type_, AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ + if (size_.height > 0 && size_.width > 0) + create(size_.height, size_.width, type_); +} + +inline +HostMem::HostMem(InputArray arr, AllocType alloc_type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_) +{ + arr.getMat().copyTo(*this); +} + +inline +HostMem::~HostMem() +{ + release(); +} + +inline +HostMem& HostMem::operator =(const HostMem& m) +{ + if (this != &m) + { + HostMem temp(m); + swap(temp); + } + + return *this; +} + +inline +void HostMem::swap(HostMem& b) +{ + std::swap(flags, b.flags); + std::swap(rows, b.rows); + std::swap(cols, b.cols); + std::swap(step, b.step); + std::swap(data, b.data); + std::swap(datastart, b.datastart); + std::swap(dataend, b.dataend); + std::swap(refcount, b.refcount); + std::swap(alloc_type, b.alloc_type); +} + +inline +HostMem HostMem::clone() const +{ + HostMem m(size(), type(), alloc_type); + createMatHeader().copyTo(m); + return m; +} + +inline +void HostMem::create(Size size_, int type_) +{ + create(size_.height, size_.width, type_); +} + +inline +Mat HostMem::createMatHeader() const +{ + return Mat(size(), type(), data, step); +} + +inline +bool HostMem::isContinuous() const +{ + return (flags & Mat::CONTINUOUS_FLAG) != 0; +} + +inline +size_t HostMem::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} + +inline +size_t HostMem::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int HostMem::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int HostMem::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int HostMem::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t HostMem::step1() const +{ + return step / elemSize1(); +} + +inline +Size HostMem::size() const +{ + return Size(cols, rows); +} + +inline +bool HostMem::empty() const +{ + return data == 0; +} + +static inline +void swap(HostMem& a, HostMem& b) +{ + a.swap(b); +} + +//=================================================================================== +// Stream +//=================================================================================== + +inline +Stream::Stream(const Ptr& impl) + : impl_(impl) +{ +} + +//=================================================================================== +// Event +//=================================================================================== + +inline +Event::Event(const Ptr& impl) + : impl_(impl) +{ +} + +//=================================================================================== +// Initialization & Info +//=================================================================================== + +inline +bool TargetArchs::has(int major, int minor) +{ + return hasPtx(major, minor) || hasBin(major, minor); +} + +inline +bool TargetArchs::hasEqualOrGreater(int major, int minor) +{ + return hasEqualOrGreaterPtx(major, minor) || hasEqualOrGreaterBin(major, minor); +} + +inline +DeviceInfo::DeviceInfo() +{ + device_id_ = getDevice(); +} + +inline +DeviceInfo::DeviceInfo(int device_id) +{ + CV_Assert( device_id >= 0 && device_id < getCudaEnabledDeviceCount() ); + device_id_ = device_id; +} + +inline +int DeviceInfo::deviceID() const +{ + return device_id_; +} + +inline +size_t DeviceInfo::freeMemory() const +{ + size_t _totalMemory = 0, _freeMemory = 0; + queryMemory(_totalMemory, _freeMemory); + return _freeMemory; +} + +inline +size_t DeviceInfo::totalMemory() const +{ + size_t _totalMemory = 0, _freeMemory = 0; + queryMemory(_totalMemory, _freeMemory); + return _totalMemory; +} + +inline +bool DeviceInfo::supports(FeatureSet feature_set) const +{ + int version = majorVersion() * 10 + minorVersion(); + return version >= feature_set; +} + + +}} // namespace cv { namespace cuda { + +//=================================================================================== +// Mat +//=================================================================================== + +namespace cv { + +inline +Mat::Mat(const cuda::GpuMat& m) + : flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows) +{ + m.download(*this); +} + +} + +//! @endcond + +#endif // OPENCV_CORE_CUDAINL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/block.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/block.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c277f0ea9c411b6763ba04d6dec56644eb25479a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/block.hpp @@ -0,0 +1,211 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_DEVICE_BLOCK_HPP +#define OPENCV_CUDA_DEVICE_BLOCK_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct Block + { + static __device__ __forceinline__ unsigned int id() + { + return blockIdx.x; + } + + static __device__ __forceinline__ unsigned int stride() + { + return blockDim.x * blockDim.y * blockDim.z; + } + + static __device__ __forceinline__ void sync() + { + __syncthreads(); + } + + static __device__ __forceinline__ int flattenedThreadId() + { + return threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x; + } + + template + static __device__ __forceinline__ void fill(It beg, It end, const T& value) + { + int STRIDE = stride(); + It t = beg + flattenedThreadId(); + + for(; t < end; t += STRIDE) + *t = value; + } + + template + static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value) + { + int STRIDE = stride(); + int tid = flattenedThreadId(); + value += tid; + + for(OutIt t = beg + tid; t < end; t += STRIDE, value += STRIDE) + *t = value; + } + + template + static __device__ __forceinline__ void copy(InIt beg, InIt end, OutIt out) + { + int STRIDE = stride(); + InIt t = beg + flattenedThreadId(); + OutIt o = out + (t - beg); + + for(; t < end; t += STRIDE, o += STRIDE) + *o = *t; + } + + template + static __device__ __forceinline__ void transform(InIt beg, InIt end, OutIt out, UnOp op) + { + int STRIDE = stride(); + InIt t = beg + flattenedThreadId(); + OutIt o = out + (t - beg); + + for(; t < end; t += STRIDE, o += STRIDE) + *o = op(*t); + } + + template + static __device__ __forceinline__ void transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op) + { + int STRIDE = stride(); + InIt1 t1 = beg1 + flattenedThreadId(); + InIt2 t2 = beg2 + flattenedThreadId(); + OutIt o = out + (t1 - beg1); + + for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, o += STRIDE) + *o = op(*t1, *t2); + } + + template + static __device__ __forceinline__ void reduce(volatile T* buffer, BinOp op) + { + int tid = flattenedThreadId(); + T val = buffer[tid]; + + if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); } + if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); } + if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); } + if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); } + + if (tid < 32) + { + if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); } + if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); } + if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); } + if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); } + if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); } + if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); } + } + } + + template + static __device__ __forceinline__ T reduce(volatile T* buffer, T init, BinOp op) + { + int tid = flattenedThreadId(); + T val = buffer[tid] = init; + __syncthreads(); + + if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); } + if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); } + if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); } + if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); } + + if (tid < 32) + { + if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); } + if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); } + if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); } + if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); } + if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); } + if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); } + } + __syncthreads(); + return buffer[0]; + } + + template + static __device__ __forceinline__ void reduce_n(T* data, unsigned int n, BinOp op) + { + int ftid = flattenedThreadId(); + int sft = stride(); + + if (sft < n) + { + for (unsigned int i = sft + ftid; i < n; i += sft) + data[ftid] = op(data[ftid], data[i]); + + __syncthreads(); + + n = sft; + } + + while (n > 1) + { + unsigned int half = n/2; + + if (ftid < half) + data[ftid] = op(data[ftid], data[n - ftid - 1]); + + __syncthreads(); + + n = n - half; + } + } + }; +}}} + +//! @endcond + +#endif /* OPENCV_CUDA_DEVICE_BLOCK_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/border_interpolate.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/border_interpolate.hpp new file mode 100644 index 0000000000000000000000000000000000000000..874f705baf0249644f0b92ea31cfa2cb31b4ae19 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/border_interpolate.hpp @@ -0,0 +1,722 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_BORDER_INTERPOLATE_HPP +#define OPENCV_CUDA_BORDER_INTERPOLATE_HPP + +#include "saturate_cast.hpp" +#include "vec_traits.hpp" +#include "vec_math.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + ////////////////////////////////////////////////////////////// + // BrdConstant + + template struct BrdRowConstant + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowConstant(int width_, const D& val_ = VecTraits::all(0)) : width(width_), val(val_) {} + + template __device__ __forceinline__ D at_low(int x, const T* data) const + { + return x >= 0 ? saturate_cast(data[x]) : val; + } + + template __device__ __forceinline__ D at_high(int x, const T* data) const + { + return x < width ? saturate_cast(data[x]) : val; + } + + template __device__ __forceinline__ D at(int x, const T* data) const + { + return (x >= 0 && x < width) ? saturate_cast(data[x]) : val; + } + + int width; + D val; + }; + + template struct BrdColConstant + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColConstant(int height_, const D& val_ = VecTraits::all(0)) : height(height_), val(val_) {} + + template __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return y >= 0 ? saturate_cast(*(const T*)((const char*)data + y * step)) : val; + } + + template __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return y < height ? saturate_cast(*(const T*)((const char*)data + y * step)) : val; + } + + template __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return (y >= 0 && y < height) ? saturate_cast(*(const T*)((const char*)data + y * step)) : val; + } + + int height; + D val; + }; + + template struct BrdConstant + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdConstant(int height_, int width_, const D& val_ = VecTraits::all(0)) : height(height_), width(width_), val(val_) + { + } + + template __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast(((const T*)((const uchar*)data + y * step))[x]) : val; + } + + template __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast(src(y, x)) : val; + } + + int height; + int width; + D val; + }; + + ////////////////////////////////////////////////////////////// + // BrdReplicate + + template struct BrdRowReplicate + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowReplicate(int width) : last_col(width - 1) {} + template __host__ __device__ __forceinline__ BrdRowReplicate(int width, U) : last_col(width - 1) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::max(x, 0); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::min(x, last_col); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast(data[idx_col_low(x)]); + } + + template __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast(data[idx_col_high(x)]); + } + + template __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast(data[idx_col(x)]); + } + + int last_col; + }; + + template struct BrdColReplicate + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColReplicate(int height) : last_row(height - 1) {} + template __host__ __device__ __forceinline__ BrdColReplicate(int height, U) : last_row(height - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::max(y, 0); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::min(y, last_row); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + template __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast(*(const T*)((const char*)data + idx_row_low(y) * step)); + } + + template __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast(*(const T*)((const char*)data + idx_row_high(y) * step)); + } + + template __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast(*(const T*)((const char*)data + idx_row(y) * step)); + } + + int last_row; + }; + + template struct BrdReplicate + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdReplicate(int height, int width) : last_row(height - 1), last_col(width - 1) {} + template __host__ __device__ __forceinline__ BrdReplicate(int height, int width, U) : last_row(height - 1), last_col(width - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::max(y, 0); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::min(y, last_row); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::max(x, 0); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::min(x, last_col); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast(src(idx_row(y), idx_col(x))); + } + + int last_row; + int last_col; + }; + + ////////////////////////////////////////////////////////////// + // BrdReflect101 + + template struct BrdRowReflect101 + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowReflect101(int width) : last_col(width - 1) {} + template __host__ __device__ __forceinline__ BrdRowReflect101(int width, U) : last_col(width - 1) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::abs(x) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::abs(last_col - ::abs(last_col - x)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast(data[idx_col_low(x)]); + } + + template __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast(data[idx_col_high(x)]); + } + + template __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast(data[idx_col(x)]); + } + + int last_col; + }; + + template struct BrdColReflect101 + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColReflect101(int height) : last_row(height - 1) {} + template __host__ __device__ __forceinline__ BrdColReflect101(int height, U) : last_row(height - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::abs(y) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::abs(last_row - ::abs(last_row - y)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + template __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row_low(y) * step)); + } + + template __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row_high(y) * step)); + } + + template __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row(y) * step)); + } + + int last_row; + }; + + template struct BrdReflect101 + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdReflect101(int height, int width) : last_row(height - 1), last_col(width - 1) {} + template __host__ __device__ __forceinline__ BrdReflect101(int height, int width, U) : last_row(height - 1), last_col(width - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return ::abs(y) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::abs(last_row - ::abs(last_row - y)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return ::abs(x) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::abs(last_col - ::abs(last_col - x)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast(src(idx_row(y), idx_col(x))); + } + + int last_row; + int last_col; + }; + + ////////////////////////////////////////////////////////////// + // BrdReflect + + template struct BrdRowReflect + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowReflect(int width) : last_col(width - 1) {} + template __host__ __device__ __forceinline__ BrdRowReflect(int width, U) : last_col(width - 1) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (::abs(x) - (x < 0)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return ::abs(last_col - ::abs(last_col - x) + (x > last_col)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_high(::abs(x) - (x < 0)); + } + + template __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast(data[idx_col_low(x)]); + } + + template __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast(data[idx_col_high(x)]); + } + + template __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast(data[idx_col(x)]); + } + + int last_col; + }; + + template struct BrdColReflect + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColReflect(int height) : last_row(height - 1) {} + template __host__ __device__ __forceinline__ BrdColReflect(int height, U) : last_row(height - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (::abs(y) - (y < 0)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return ::abs(last_row - ::abs(last_row - y) + (y > last_row)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_high(::abs(y) - (y < 0)); + } + + template __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row_low(y) * step)); + } + + template __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row_high(y) * step)); + } + + template __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row(y) * step)); + } + + int last_row; + }; + + template struct BrdReflect + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdReflect(int height, int width) : last_row(height - 1), last_col(width - 1) {} + template __host__ __device__ __forceinline__ BrdReflect(int height, int width, U) : last_row(height - 1), last_col(width - 1) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (::abs(y) - (y < 0)) % (last_row + 1); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return /*::abs*/(last_row - ::abs(last_row - y) + (y > last_row)) /*% (last_row + 1)*/; + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_low(idx_row_high(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (::abs(x) - (x < 0)) % (last_col + 1); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return (last_col - ::abs(last_col - x) + (x > last_col)); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_low(idx_col_high(x)); + } + + template __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast(src(idx_row(y), idx_col(x))); + } + + int last_row; + int last_col; + }; + + ////////////////////////////////////////////////////////////// + // BrdWrap + + template struct BrdRowWrap + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdRowWrap(int width_) : width(width_) {} + template __host__ __device__ __forceinline__ BrdRowWrap(int width_, U) : width(width_) {} + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (x >= 0) * x + (x < 0) * (x - ((x - width + 1) / width) * width); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return (x < width) * x + (x >= width) * (x % width); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_high(idx_col_low(x)); + } + + template __device__ __forceinline__ D at_low(int x, const T* data) const + { + return saturate_cast(data[idx_col_low(x)]); + } + + template __device__ __forceinline__ D at_high(int x, const T* data) const + { + return saturate_cast(data[idx_col_high(x)]); + } + + template __device__ __forceinline__ D at(int x, const T* data) const + { + return saturate_cast(data[idx_col(x)]); + } + + int width; + }; + + template struct BrdColWrap + { + typedef D result_type; + + explicit __host__ __device__ __forceinline__ BrdColWrap(int height_) : height(height_) {} + template __host__ __device__ __forceinline__ BrdColWrap(int height_, U) : height(height_) {} + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (y >= 0) * y + (y < 0) * (y - ((y - height + 1) / height) * height); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return (y < height) * y + (y >= height) * (y % height); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_high(idx_row_low(y)); + } + + template __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row_low(y) * step)); + } + + template __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row_high(y) * step)); + } + + template __device__ __forceinline__ D at(int y, const T* data, size_t step) const + { + return saturate_cast(*(const D*)((const char*)data + idx_row(y) * step)); + } + + int height; + }; + + template struct BrdWrap + { + typedef D result_type; + + __host__ __device__ __forceinline__ BrdWrap(int height_, int width_) : + height(height_), width(width_) + { + } + template + __host__ __device__ __forceinline__ BrdWrap(int height_, int width_, U) : + height(height_), width(width_) + { + } + + __device__ __forceinline__ int idx_row_low(int y) const + { + return (y >= 0) ? y : (y - ((y - height + 1) / height) * height); + } + + __device__ __forceinline__ int idx_row_high(int y) const + { + return (y < height) ? y : (y % height); + } + + __device__ __forceinline__ int idx_row(int y) const + { + return idx_row_high(idx_row_low(y)); + } + + __device__ __forceinline__ int idx_col_low(int x) const + { + return (x >= 0) ? x : (x - ((x - width + 1) / width) * width); + } + + __device__ __forceinline__ int idx_col_high(int x) const + { + return (x < width) ? x : (x % width); + } + + __device__ __forceinline__ int idx_col(int x) const + { + return idx_col_high(idx_col_low(x)); + } + + template __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const + { + return saturate_cast(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]); + } + + template __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const + { + return saturate_cast(src(idx_row(y), idx_col(x))); + } + + int height; + int width; + }; + + ////////////////////////////////////////////////////////////// + // BorderReader + + template struct BorderReader + { + typedef typename B::result_type elem_type; + typedef typename Ptr2D::index_type index_type; + + __host__ __device__ __forceinline__ BorderReader(const Ptr2D& ptr_, const B& b_) : ptr(ptr_), b(b_) {} + + __device__ __forceinline__ elem_type operator ()(index_type y, index_type x) const + { + return b.at(y, x, ptr); + } + + Ptr2D ptr; + B b; + }; + + // under win32 there is some bug with templated types that passed as kernel parameters + // with this specialization all works fine + template struct BorderReader< Ptr2D, BrdConstant > + { + typedef typename BrdConstant::result_type elem_type; + typedef typename Ptr2D::index_type index_type; + + __host__ __device__ __forceinline__ BorderReader(const Ptr2D& src_, const BrdConstant& b) : + src(src_), height(b.height), width(b.width), val(b.val) + { + } + + __device__ __forceinline__ D operator ()(index_type y, index_type x) const + { + return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast(src(y, x)) : val; + } + + Ptr2D src; + int height; + int width; + D val; + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_BORDER_INTERPOLATE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/color.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/color.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dcce280214826d3495bb89699be3197822085090 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/color.hpp @@ -0,0 +1,309 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_COLOR_HPP +#define OPENCV_CUDA_COLOR_HPP + +#include "detail/color_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + // All OPENCV_CUDA_IMPLEMENT_*_TRAITS(ColorSpace1_to_ColorSpace2, ...) macros implements + // template class ColorSpace1_to_ColorSpace2_traits + // { + // typedef ... functor_type; + // static __host__ __device__ functor_type create_functor(); + // }; + + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_rgba, 4, 4, 2) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgr_to_bgr555, 3, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgr_to_bgr565, 3, 0, 6) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgb_to_bgr555, 3, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgb_to_bgr565, 3, 2, 6) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgra_to_bgr555, 4, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgra_to_bgr565, 4, 0, 6) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgba_to_bgr555, 4, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgba_to_bgr565, 4, 2, 6) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_rgb, 3, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_rgb, 3, 2, 6) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_bgr, 3, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_bgr, 3, 0, 6) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_rgba, 4, 2, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_rgba, 4, 2, 6) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_bgra, 4, 0, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_bgra, 4, 0, 6) + + #undef OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(gray_to_bgr, 3) + OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(gray_to_bgra, 4) + + #undef OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(gray_to_bgr555, 5) + OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(gray_to_bgr565, 6) + + #undef OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(bgr555_to_gray, 5) + OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(bgr565_to_gray, 6) + + #undef OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(rgb_to_gray, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(bgr_to_gray, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(rgba_to_gray, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(bgra_to_gray, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgb_to_yuv, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgba_to_yuv, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgb_to_yuv4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgba_to_yuv4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgr_to_yuv, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgra_to_yuv, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgr_to_yuv4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgra_to_yuv4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS + + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgb_to_YCrCb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgba_to_YCrCb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgb_to_YCrCb4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgba_to_YCrCb4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgr_to_YCrCb, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgra_to_YCrCb, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgr_to_YCrCb4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgra_to_YCrCb4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS + + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgb_to_xyz, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgba_to_xyz, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgb_to_xyz4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgba_to_xyz4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgr_to_xyz, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgra_to_xyz, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgr_to_xyz4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgra_to_xyz4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS + + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgb_to_hsv, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgba_to_hsv, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgb_to_hsv4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgba_to_hsv4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgr_to_hsv, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgra_to_hsv, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgr_to_hsv4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgra_to_hsv4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS + + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgb_to_hls, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgba_to_hls, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgb_to_hls4, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgba_to_hls4, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgr_to_hls, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgra_to_hls, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgr_to_hls4, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgra_to_hls4, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS + + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_rgb, 3, 3, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_rgba, 3, 4, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_rgb, 4, 3, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_rgba, 4, 4, 2) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_bgr, 3, 3, 0) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_bgra, 3, 4, 0) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_bgr, 4, 3, 0) + OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_bgra, 4, 4, 0) + + #undef OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgb_to_lab, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgba_to_lab, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgb_to_lab4, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgba_to_lab4, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgr_to_lab, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgra_to_lab, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgr_to_lab4, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgra_to_lab4, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgb_to_lab, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgba_to_lab, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgb_to_lab4, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgba_to_lab4, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgr_to_lab, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgra_to_lab, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgr_to_lab4, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgra_to_lab4, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS + + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_rgb, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_rgb, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_rgba, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_rgba, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_bgr, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_bgr, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_bgra, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_bgra, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lrgb, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lrgb, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lrgba, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lrgba, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lbgr, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lbgr, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lbgra, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lbgra, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS + + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgb_to_luv, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgba_to_luv, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgb_to_luv4, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgba_to_luv4, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgr_to_luv, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgra_to_luv, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgr_to_luv4, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgra_to_luv4, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgb_to_luv, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgba_to_luv, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgb_to_luv4, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgba_to_luv4, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgr_to_luv, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgra_to_luv, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgr_to_luv4, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgra_to_luv4, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS + + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_rgb, 3, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_rgb, 4, 3, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_rgba, 3, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_rgba, 4, 4, true, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_bgr, 3, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_bgr, 4, 3, true, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_bgra, 3, 4, true, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_bgra, 4, 4, true, 0) + + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lrgb, 3, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lrgb, 4, 3, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lrgba, 3, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lrgba, 4, 4, false, 2) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lbgr, 3, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lbgr, 4, 3, false, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lbgra, 3, 4, false, 0) + OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lbgra, 4, 4, false, 0) + + #undef OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_COLOR_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/common.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/common.hpp new file mode 100644 index 0000000000000000000000000000000000000000..14b1f3f5aecd40562c3b8b9ad06d05098fa3da30 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/common.hpp @@ -0,0 +1,109 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_COMMON_HPP +#define OPENCV_CUDA_COMMON_HPP + +#include +#include "opencv2/core/cuda_types.hpp" +#include "opencv2/core/cvdef.h" +#include "opencv2/core/base.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +#ifndef CV_PI_F + #ifndef CV_PI + #define CV_PI_F 3.14159265f + #else + #define CV_PI_F ((float)CV_PI) + #endif +#endif + +namespace cv { namespace cuda { + static inline void checkCudaError(cudaError_t err, const char* file, const int line, const char* func) + { + if (cudaSuccess != err) + cv::error(cv::Error::GpuApiCallError, cudaGetErrorString(err), func, file, line); + } +}} + +#ifndef cudaSafeCall + #define cudaSafeCall(expr) cv::cuda::checkCudaError(expr, __FILE__, __LINE__, CV_Func) +#endif + +namespace cv { namespace cuda +{ + template static inline bool isAligned(const T* ptr, size_t size) + { + return reinterpret_cast(ptr) % size == 0; + } + + static inline bool isAligned(size_t step, size_t size) + { + return step % size == 0; + } +}} + +namespace cv { namespace cuda +{ + namespace device + { + __host__ __device__ __forceinline__ int divUp(int total, int grain) + { + return (total + grain - 1) / grain; + } + + template inline void bindTexture(const textureReference* tex, const PtrStepSz& img) + { + cudaChannelFormatDesc desc = cudaCreateChannelDesc(); + cudaSafeCall( cudaBindTexture2D(0, tex, img.ptr(), &desc, img.cols, img.rows, img.step) ); + } + } +}} + +//! @endcond + +#endif // OPENCV_CUDA_COMMON_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/datamov_utils.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/datamov_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6820d0fd64de9090dd9f02a296ea3de0a3884ef1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/datamov_utils.hpp @@ -0,0 +1,113 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_DATAMOV_UTILS_HPP +#define OPENCV_CUDA_DATAMOV_UTILS_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 200 + + // for Fermi memory space is detected automatically + template struct ForceGlob + { + __device__ __forceinline__ static void Load(const T* ptr, int offset, T& val) { val = ptr[offset]; } + }; + + #else // __CUDA_ARCH__ >= 200 + + #if defined(_WIN64) || defined(__LP64__) + // 64-bit register modifier for inlined asm + #define OPENCV_CUDA_ASM_PTR "l" + #else + // 32-bit register modifier for inlined asm + #define OPENCV_CUDA_ASM_PTR "r" + #endif + + template struct ForceGlob; + + #define OPENCV_CUDA_DEFINE_FORCE_GLOB(base_type, ptx_type, reg_mod) \ + template <> struct ForceGlob \ + { \ + __device__ __forceinline__ static void Load(const base_type* ptr, int offset, base_type& val) \ + { \ + asm("ld.global."#ptx_type" %0, [%1];" : "="#reg_mod(val) : OPENCV_CUDA_ASM_PTR(ptr + offset)); \ + } \ + }; + + #define OPENCV_CUDA_DEFINE_FORCE_GLOB_B(base_type, ptx_type) \ + template <> struct ForceGlob \ + { \ + __device__ __forceinline__ static void Load(const base_type* ptr, int offset, base_type& val) \ + { \ + asm("ld.global."#ptx_type" %0, [%1];" : "=r"(*reinterpret_cast(&val)) : OPENCV_CUDA_ASM_PTR(ptr + offset)); \ + } \ + }; + + OPENCV_CUDA_DEFINE_FORCE_GLOB_B(uchar, u8) + OPENCV_CUDA_DEFINE_FORCE_GLOB_B(schar, s8) + OPENCV_CUDA_DEFINE_FORCE_GLOB_B(char, b8) + OPENCV_CUDA_DEFINE_FORCE_GLOB (ushort, u16, h) + OPENCV_CUDA_DEFINE_FORCE_GLOB (short, s16, h) + OPENCV_CUDA_DEFINE_FORCE_GLOB (uint, u32, r) + OPENCV_CUDA_DEFINE_FORCE_GLOB (int, s32, r) + OPENCV_CUDA_DEFINE_FORCE_GLOB (float, f32, f) + OPENCV_CUDA_DEFINE_FORCE_GLOB (double, f64, d) + + #undef OPENCV_CUDA_DEFINE_FORCE_GLOB + #undef OPENCV_CUDA_DEFINE_FORCE_GLOB_B + #undef OPENCV_CUDA_ASM_PTR + + #endif // __CUDA_ARCH__ >= 200 +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_DATAMOV_UTILS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/color_detail.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/color_detail.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f4b4796571dc22dedf5ea66fd2fd8b5a3bb9aef9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/color_detail.hpp @@ -0,0 +1,2018 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_COLOR_DETAIL_HPP +#define OPENCV_CUDA_COLOR_DETAIL_HPP + +#include "../common.hpp" +#include "../vec_traits.hpp" +#include "../saturate_cast.hpp" +#include "../limits.hpp" +#include "../functional.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + #ifndef CV_DESCALE + #define CV_DESCALE(x, n) (((x) + (1 << ((n)-1))) >> (n)) + #endif + + namespace color_detail + { + template struct ColorChannel + { + typedef float worktype_f; + static __device__ __forceinline__ T max() { return numeric_limits::max(); } + static __device__ __forceinline__ T half() { return (T)(max()/2 + 1); } + }; + + template<> struct ColorChannel + { + typedef float worktype_f; + static __device__ __forceinline__ float max() { return 1.f; } + static __device__ __forceinline__ float half() { return 0.5f; } + }; + + template static __device__ __forceinline__ void setAlpha(typename TypeVec::vec_type& vec, T val) + { + } + + template static __device__ __forceinline__ void setAlpha(typename TypeVec::vec_type& vec, T val) + { + vec.w = val; + } + + template static __device__ __forceinline__ T getAlpha(const typename TypeVec::vec_type& vec) + { + return ColorChannel::max(); + } + + template static __device__ __forceinline__ T getAlpha(const typename TypeVec::vec_type& vec) + { + return vec.w; + } + + //constants for conversion from/to RGB and Gray, YUV, YCrCb according to BT.601 + constexpr float B2YF = 0.114f; + constexpr float G2YF = 0.587f; + constexpr float R2YF = 0.299f; + + //to YCbCr + constexpr float YCBF = 0.564f; // == 1/2/(1-B2YF) + constexpr float YCRF = 0.713f; // == 1/2/(1-R2YF) + const int YCBI = 9241; // == YCBF*16384 + const int YCRI = 11682; // == YCRF*16384 + //to YUV + constexpr float B2UF = 0.492f; + constexpr float R2VF = 0.877f; + const int B2UI = 8061; // == B2UF*16384 + const int R2VI = 14369; // == R2VF*16384 + //from YUV + constexpr float U2BF = 2.032f; + constexpr float U2GF = -0.395f; + constexpr float V2GF = -0.581f; + constexpr float V2RF = 1.140f; + const int U2BI = 33292; + const int U2GI = -6472; + const int V2GI = -9519; + const int V2RI = 18678; + //from YCrCb + constexpr float CB2BF = 1.773f; + constexpr float CB2GF = -0.344f; + constexpr float CR2GF = -0.714f; + constexpr float CR2RF = 1.403f; + const int CB2BI = 29049; + const int CB2GI = -5636; + const int CR2GI = -11698; + const int CR2RI = 22987; + + enum + { + yuv_shift = 14, + xyz_shift = 12, + gray_shift = 15, + R2Y = 4899, + G2Y = 9617, + B2Y = 1868, + RY15 = 9798, // == R2YF*32768 + 0.5 + GY15 = 19235, // == G2YF*32768 + 0.5 + BY15 = 3735, // == B2YF*32768 + 0.5 + BLOCK_SIZE = 256 + }; + } + +////////////////// Various 3/4-channel to 3/4-channel RGB transformations ///////////////// + + namespace color_detail + { + template struct RGB2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ typename TypeVec::vec_type operator()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + dst.x = (&src.x)[bidx]; + dst.y = src.y; + dst.z = (&src.x)[bidx^2]; + setAlpha(dst, getAlpha(src)); + + return dst; + } + + __host__ __device__ __forceinline__ RGB2RGB() {} + __host__ __device__ __forceinline__ RGB2RGB(const RGB2RGB&) {} + }; + + template <> struct RGB2RGB : unary_function + { + __device__ uint operator()(uint src) const + { + uint dst = 0; + + dst |= (0xffu & (src >> 16)); + dst |= (0xffu & (src >> 8)) << 8; + dst |= (0xffu & (src)) << 16; + dst |= (0xffu & (src >> 24)) << 24; + + return dst; + } + + __host__ __device__ __forceinline__ RGB2RGB() {} + __host__ __device__ __forceinline__ RGB2RGB(const RGB2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +/////////// Transforming 16-bit (565 or 555) RGB to/from 24/32-bit (888[8]) RGB ////////// + + namespace color_detail + { + template struct RGB2RGB5x5Converter; + template struct RGB2RGB5x5Converter<6, bidx> + { + static __device__ __forceinline__ ushort cvt(const uchar3& src) + { + return (ushort)(((&src.x)[bidx] >> 3) | ((src.y & ~3) << 3) | (((&src.x)[bidx^2] & ~7) << 8)); + } + + static __device__ __forceinline__ ushort cvt(uint src) + { + uint b = 0xffu & (src >> (bidx * 8)); + uint g = 0xffu & (src >> 8); + uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + return (ushort)((b >> 3) | ((g & ~3) << 3) | ((r & ~7) << 8)); + } + }; + + template struct RGB2RGB5x5Converter<5, bidx> + { + static __device__ __forceinline__ ushort cvt(const uchar3& src) + { + return (ushort)(((&src.x)[bidx] >> 3) | ((src.y & ~7) << 2) | (((&src.x)[bidx^2] & ~7) << 7)); + } + + static __device__ __forceinline__ ushort cvt(uint src) + { + uint b = 0xffu & (src >> (bidx * 8)); + uint g = 0xffu & (src >> 8); + uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + uint a = 0xffu & (src >> 24); + return (ushort)((b >> 3) | ((g & ~7) << 2) | ((r & ~7) << 7) | (a * 0x8000)); + } + }; + + template struct RGB2RGB5x5; + + template struct RGB2RGB5x5<3, bidx,green_bits> : unary_function + { + __device__ __forceinline__ ushort operator()(const uchar3& src) const + { + return RGB2RGB5x5Converter::cvt(src); + } + + __host__ __device__ __forceinline__ RGB2RGB5x5() {} + __host__ __device__ __forceinline__ RGB2RGB5x5(const RGB2RGB5x5&) {} + }; + + template struct RGB2RGB5x5<4, bidx,green_bits> : unary_function + { + __device__ __forceinline__ ushort operator()(uint src) const + { + return RGB2RGB5x5Converter::cvt(src); + } + + __host__ __device__ __forceinline__ RGB2RGB5x5() {} + __host__ __device__ __forceinline__ RGB2RGB5x5(const RGB2RGB5x5&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(name, scn, bidx, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2RGB5x5 functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template struct RGB5x52RGBConverter; + + template struct RGB5x52RGBConverter<5, bidx> + { + static __device__ __forceinline__ void cvt(uint src, uchar3& dst) + { + (&dst.x)[bidx] = src << 3; + dst.y = (src >> 2) & ~7; + (&dst.x)[bidx ^ 2] = (src >> 7) & ~7; + } + + static __device__ __forceinline__ void cvt(uint src, uint& dst) + { + dst = 0; + + dst |= (0xffu & (src << 3)) << (bidx * 8); + dst |= (0xffu & ((src >> 2) & ~7)) << 8; + dst |= (0xffu & ((src >> 7) & ~7)) << ((bidx ^ 2) * 8); + dst |= ((src & 0x8000) * 0xffu) << 24; + } + }; + + template struct RGB5x52RGBConverter<6, bidx> + { + static __device__ __forceinline__ void cvt(uint src, uchar3& dst) + { + (&dst.x)[bidx] = src << 3; + dst.y = (src >> 3) & ~3; + (&dst.x)[bidx ^ 2] = (src >> 8) & ~7; + } + + static __device__ __forceinline__ void cvt(uint src, uint& dst) + { + dst = 0xffu << 24; + + dst |= (0xffu & (src << 3)) << (bidx * 8); + dst |= (0xffu &((src >> 3) & ~3)) << 8; + dst |= (0xffu & ((src >> 8) & ~7)) << ((bidx ^ 2) * 8); + } + }; + + template struct RGB5x52RGB; + + template struct RGB5x52RGB<3, bidx, green_bits> : unary_function + { + __device__ __forceinline__ uchar3 operator()(ushort src) const + { + uchar3 dst; + RGB5x52RGBConverter::cvt(src, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB5x52RGB() {} + __host__ __device__ __forceinline__ RGB5x52RGB(const RGB5x52RGB&) {} + + }; + + template struct RGB5x52RGB<4, bidx, green_bits> : unary_function + { + __device__ __forceinline__ uint operator()(ushort src) const + { + uint dst; + RGB5x52RGBConverter::cvt(src, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB5x52RGB() {} + __host__ __device__ __forceinline__ RGB5x52RGB(const RGB5x52RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(name, dcn, bidx, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB5x52RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////// Grayscale to Color //////////////////////////////// + + namespace color_detail + { + template struct Gray2RGB : unary_function::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator()(T src) const + { + typename TypeVec::vec_type dst; + + dst.z = dst.y = dst.x = src; + setAlpha(dst, ColorChannel::max()); + + return dst; + } + __host__ __device__ __forceinline__ Gray2RGB() {} + __host__ __device__ __forceinline__ Gray2RGB(const Gray2RGB&) {} + }; + + template <> struct Gray2RGB : unary_function + { + __device__ __forceinline__ uint operator()(uint src) const + { + uint dst = 0xffu << 24; + + dst |= src; + dst |= src << 8; + dst |= src << 16; + + return dst; + } + __host__ __device__ __forceinline__ Gray2RGB() {} + __host__ __device__ __forceinline__ Gray2RGB(const Gray2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(name, dcn) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Gray2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template struct Gray2RGB5x5Converter; + template<> struct Gray2RGB5x5Converter<6> + { + static __device__ __forceinline__ ushort cvt(uint t) + { + return (ushort)((t >> 3) | ((t & ~3) << 3) | ((t & ~7) << 8)); + } + }; + + template<> struct Gray2RGB5x5Converter<5> + { + static __device__ __forceinline__ ushort cvt(uint t) + { + t >>= 3; + return (ushort)(t | (t << 5) | (t << 10)); + } + }; + + template struct Gray2RGB5x5 : unary_function + { + __device__ __forceinline__ ushort operator()(uint src) const + { + return Gray2RGB5x5Converter::cvt(src); + } + + __host__ __device__ __forceinline__ Gray2RGB5x5() {} + __host__ __device__ __forceinline__ Gray2RGB5x5(const Gray2RGB5x5&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(name, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Gray2RGB5x5 functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////// Color to Grayscale //////////////////////////////// + + namespace color_detail + { + template struct RGB5x52GrayConverter; + template <> struct RGB5x52GrayConverter<6> + { + static __device__ __forceinline__ uchar cvt(uint t) + { + return (uchar)CV_DESCALE(((t << 3) & 0xf8) * BY15 + ((t >> 3) & 0xfc) * GY15 + ((t >> 8) & 0xf8) * RY15, gray_shift); + } + }; + + template <> struct RGB5x52GrayConverter<5> + { + static __device__ __forceinline__ uchar cvt(uint t) + { + return (uchar)CV_DESCALE(((t << 3) & 0xf8) * BY15 + ((t >> 2) & 0xf8) * GY15 + ((t >> 7) & 0xf8) * RY15, gray_shift); + } + }; + + template struct RGB5x52Gray : unary_function + { + __device__ __forceinline__ uchar operator()(uint src) const + { + return RGB5x52GrayConverter::cvt(src); + } + __host__ __device__ __forceinline__ RGB5x52Gray() {} + __host__ __device__ __forceinline__ RGB5x52Gray(const RGB5x52Gray&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(name, green_bits) \ + struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB5x52Gray functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template static __device__ __forceinline__ T RGB2GrayConvert(const T* src) + { + return (T)CV_DESCALE((unsigned)(src[bidx] * BY15 + src[1] * GY15 + src[bidx^2] * RY15), gray_shift); + } + + template static __device__ __forceinline__ uchar RGB2GrayConvert(uint src) + { + uint b = 0xffu & (src >> (bidx * 8)); + uint g = 0xffu & (src >> 8); + uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + return CV_DESCALE((uint)(b * BY15 + g * GY15 + r * RY15), gray_shift); + } + + template static __device__ __forceinline__ float RGB2GrayConvert(const float* src) + { + return src[bidx] * B2YF + src[1] * G2YF + src[bidx^2] * R2YF; + } + + template struct RGB2Gray : unary_function::vec_type, T> + { + __device__ __forceinline__ T operator()(const typename TypeVec::vec_type& src) const + { + return RGB2GrayConvert(&src.x); + } + __host__ __device__ __forceinline__ RGB2Gray() {} + __host__ __device__ __forceinline__ RGB2Gray(const RGB2Gray&) {} + }; + + template struct RGB2Gray : unary_function + { + __device__ __forceinline__ uchar operator()(uint src) const + { + return RGB2GrayConvert(src); + } + __host__ __device__ __forceinline__ RGB2Gray() {} + __host__ __device__ __forceinline__ RGB2Gray(const RGB2Gray&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(name, scn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2Gray functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> YUV ////////////////////////////////////// + + namespace color_detail + { + __constant__ float c_RGB2YUVCoeffs_f[5] = { B2YF, G2YF, R2YF, B2UF, R2VF }; + __constant__ int c_RGB2YUVCoeffs_i[5] = { B2Y, G2Y, R2Y, B2UI, R2VI }; + + template static __device__ void RGB2YUVConvert(const T* src, D& dst) + { + const int delta = ColorChannel::half() * (1 << yuv_shift); + + const int Y = CV_DESCALE(src[0] * c_RGB2YUVCoeffs_i[bidx^2] + src[1] * c_RGB2YUVCoeffs_i[1] + src[2] * c_RGB2YUVCoeffs_i[bidx], yuv_shift); + const int Cr = CV_DESCALE((src[bidx^2] - Y) * c_RGB2YUVCoeffs_i[3] + delta, yuv_shift); + const int Cb = CV_DESCALE((src[bidx] - Y) * c_RGB2YUVCoeffs_i[4] + delta, yuv_shift); + + dst.x = saturate_cast(Y); + dst.y = saturate_cast(Cr); + dst.z = saturate_cast(Cb); + } + + template static __device__ __forceinline__ void RGB2YUVConvert(const float* src, D& dst) + { + dst.x = src[0] * c_RGB2YUVCoeffs_f[bidx^2] + src[1] * c_RGB2YUVCoeffs_f[1] + src[2] * c_RGB2YUVCoeffs_f[bidx]; + dst.y = (src[bidx^2] - dst.x) * c_RGB2YUVCoeffs_f[3] + ColorChannel::half(); + dst.z = (src[bidx] - dst.x) * c_RGB2YUVCoeffs_f[4] + ColorChannel::half(); + } + + template struct RGB2YUV + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + RGB2YUVConvert(&src.x, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB2YUV() {} + __host__ __device__ __forceinline__ RGB2YUV(const RGB2YUV&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2YUV functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_YUV2RGBCoeffs_f[5] = { U2BF, U2GF, V2GF, V2RF }; + __constant__ int c_YUV2RGBCoeffs_i[5] = { U2BI, U2GI, V2GI, V2RI }; + + template static __device__ void YUV2RGBConvert(const T& src, D* dst) + { + const int b = src.x + CV_DESCALE((src.z - ColorChannel::half()) * c_YUV2RGBCoeffs_i[3], yuv_shift); + + const int g = src.x + CV_DESCALE((src.z - ColorChannel::half()) * c_YUV2RGBCoeffs_i[2] + + (src.y - ColorChannel::half()) * c_YUV2RGBCoeffs_i[1], yuv_shift); + + const int r = src.x + CV_DESCALE((src.y - ColorChannel::half()) * c_YUV2RGBCoeffs_i[0], yuv_shift); + + dst[bidx] = saturate_cast(b); + dst[1] = saturate_cast(g); + dst[bidx^2] = saturate_cast(r); + } + + template static __device__ uint YUV2RGBConvert(uint src) + { + const int x = 0xff & (src); + const int y = 0xff & (src >> 8); + const int z = 0xff & (src >> 16); + + const int b = x + CV_DESCALE((z - ColorChannel::half()) * c_YUV2RGBCoeffs_i[3], yuv_shift); + + const int g = x + CV_DESCALE((z - ColorChannel::half()) * c_YUV2RGBCoeffs_i[2] + + (y - ColorChannel::half()) * c_YUV2RGBCoeffs_i[1], yuv_shift); + + const int r = x + CV_DESCALE((y - ColorChannel::half()) * c_YUV2RGBCoeffs_i[0], yuv_shift); + + uint dst = 0xffu << 24; + + dst |= saturate_cast(b) << (bidx * 8); + dst |= saturate_cast(g) << 8; + dst |= saturate_cast(r) << ((bidx ^ 2) * 8); + + return dst; + } + + template static __device__ __forceinline__ void YUV2RGBConvert(const T& src, float* dst) + { + dst[bidx] = src.x + (src.z - ColorChannel::half()) * c_YUV2RGBCoeffs_f[3]; + + dst[1] = src.x + (src.z - ColorChannel::half()) * c_YUV2RGBCoeffs_f[2] + + (src.y - ColorChannel::half()) * c_YUV2RGBCoeffs_f[1]; + + dst[bidx^2] = src.x + (src.y - ColorChannel::half()) * c_YUV2RGBCoeffs_f[0]; + } + + template struct YUV2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + YUV2RGBConvert(src, &dst.x); + setAlpha(dst, ColorChannel::max()); + + return dst; + } + __host__ __device__ __forceinline__ YUV2RGB() {} + __host__ __device__ __forceinline__ YUV2RGB(const YUV2RGB&) {} + }; + + template struct YUV2RGB : unary_function + { + __device__ __forceinline__ uint operator ()(uint src) const + { + return YUV2RGBConvert(src); + } + __host__ __device__ __forceinline__ YUV2RGB() {} + __host__ __device__ __forceinline__ YUV2RGB(const YUV2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::YUV2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> YCrCb ////////////////////////////////////// + + namespace color_detail + { + __constant__ float c_RGB2YCrCbCoeffs_f[5] = {R2YF, G2YF, B2YF, YCRF, YCBF}; + __constant__ int c_RGB2YCrCbCoeffs_i[5] = {R2Y, G2Y, B2Y, YCRI, YCBI}; + + template static __device__ void RGB2YCrCbConvert(const T* src, D& dst) + { + const int delta = ColorChannel::half() * (1 << yuv_shift); + + const int Y = CV_DESCALE(src[0] * c_RGB2YCrCbCoeffs_i[bidx^2] + src[1] * c_RGB2YCrCbCoeffs_i[1] + src[2] * c_RGB2YCrCbCoeffs_i[bidx], yuv_shift); + const int Cr = CV_DESCALE((src[bidx^2] - Y) * c_RGB2YCrCbCoeffs_i[3] + delta, yuv_shift); + const int Cb = CV_DESCALE((src[bidx] - Y) * c_RGB2YCrCbCoeffs_i[4] + delta, yuv_shift); + + dst.x = saturate_cast(Y); + dst.y = saturate_cast(Cr); + dst.z = saturate_cast(Cb); + } + + template static __device__ uint RGB2YCrCbConvert(uint src) + { + const int delta = ColorChannel::half() * (1 << yuv_shift); + + const int Y = CV_DESCALE((0xffu & src) * c_RGB2YCrCbCoeffs_i[bidx^2] + (0xffu & (src >> 8)) * c_RGB2YCrCbCoeffs_i[1] + (0xffu & (src >> 16)) * c_RGB2YCrCbCoeffs_i[bidx], yuv_shift); + const int Cr = CV_DESCALE(((0xffu & (src >> ((bidx ^ 2) * 8))) - Y) * c_RGB2YCrCbCoeffs_i[3] + delta, yuv_shift); + const int Cb = CV_DESCALE(((0xffu & (src >> (bidx * 8))) - Y) * c_RGB2YCrCbCoeffs_i[4] + delta, yuv_shift); + + uint dst = 0; + + dst |= saturate_cast(Y); + dst |= saturate_cast(Cr) << 8; + dst |= saturate_cast(Cb) << 16; + + return dst; + } + + template static __device__ __forceinline__ void RGB2YCrCbConvert(const float* src, D& dst) + { + dst.x = src[0] * c_RGB2YCrCbCoeffs_f[bidx^2] + src[1] * c_RGB2YCrCbCoeffs_f[1] + src[2] * c_RGB2YCrCbCoeffs_f[bidx]; + dst.y = (src[bidx^2] - dst.x) * c_RGB2YCrCbCoeffs_f[3] + ColorChannel::half(); + dst.z = (src[bidx] - dst.x) * c_RGB2YCrCbCoeffs_f[4] + ColorChannel::half(); + } + + template struct RGB2YCrCb + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + RGB2YCrCbConvert(&src.x, dst); + return dst; + } + __host__ __device__ __forceinline__ RGB2YCrCb() {} + __host__ __device__ __forceinline__ RGB2YCrCb(const RGB2YCrCb&) {} + }; + + template struct RGB2YCrCb : unary_function + { + __device__ __forceinline__ uint operator ()(uint src) const + { + return RGB2YCrCbConvert(src); + } + + __host__ __device__ __forceinline__ RGB2YCrCb() {} + __host__ __device__ __forceinline__ RGB2YCrCb(const RGB2YCrCb&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2YCrCb functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_YCrCb2RGBCoeffs_f[5] = {CR2RF, CR2GF, CB2GF, CB2BF}; + __constant__ int c_YCrCb2RGBCoeffs_i[5] = {CR2RI, CR2GI, CB2GI, CB2BI}; + + template static __device__ void YCrCb2RGBConvert(const T& src, D* dst) + { + const int b = src.x + CV_DESCALE((src.z - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[3], yuv_shift); + const int g = src.x + CV_DESCALE((src.z - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[2] + (src.y - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[1], yuv_shift); + const int r = src.x + CV_DESCALE((src.y - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[0], yuv_shift); + + dst[bidx] = saturate_cast(b); + dst[1] = saturate_cast(g); + dst[bidx^2] = saturate_cast(r); + } + + template static __device__ uint YCrCb2RGBConvert(uint src) + { + const int x = 0xff & (src); + const int y = 0xff & (src >> 8); + const int z = 0xff & (src >> 16); + + const int b = x + CV_DESCALE((z - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[3], yuv_shift); + const int g = x + CV_DESCALE((z - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[2] + (y - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[1], yuv_shift); + const int r = x + CV_DESCALE((y - ColorChannel::half()) * c_YCrCb2RGBCoeffs_i[0], yuv_shift); + + uint dst = 0xffu << 24; + + dst |= saturate_cast(b) << (bidx * 8); + dst |= saturate_cast(g) << 8; + dst |= saturate_cast(r) << ((bidx ^ 2) * 8); + + return dst; + } + + template __device__ __forceinline__ void YCrCb2RGBConvert(const T& src, float* dst) + { + dst[bidx] = src.x + (src.z - ColorChannel::half()) * c_YCrCb2RGBCoeffs_f[3]; + dst[1] = src.x + (src.z - ColorChannel::half()) * c_YCrCb2RGBCoeffs_f[2] + (src.y - ColorChannel::half()) * c_YCrCb2RGBCoeffs_f[1]; + dst[bidx^2] = src.x + (src.y - ColorChannel::half()) * c_YCrCb2RGBCoeffs_f[0]; + } + + template struct YCrCb2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + YCrCb2RGBConvert(src, &dst.x); + setAlpha(dst, ColorChannel::max()); + + return dst; + } + __host__ __device__ __forceinline__ YCrCb2RGB() {} + __host__ __device__ __forceinline__ YCrCb2RGB(const YCrCb2RGB&) {} + }; + + template struct YCrCb2RGB : unary_function + { + __device__ __forceinline__ uint operator ()(uint src) const + { + return YCrCb2RGBConvert(src); + } + __host__ __device__ __forceinline__ YCrCb2RGB() {} + __host__ __device__ __forceinline__ YCrCb2RGB(const YCrCb2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::YCrCb2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +////////////////////////////////////// RGB <-> XYZ /////////////////////////////////////// + + namespace color_detail + { + __constant__ float c_RGB2XYZ_D65f[9] = { 0.412453f, 0.357580f, 0.180423f, 0.212671f, 0.715160f, 0.072169f, 0.019334f, 0.119193f, 0.950227f }; + __constant__ int c_RGB2XYZ_D65i[9] = { 1689, 1465, 739, 871, 2929, 296, 79, 488, 3892 }; + + template static __device__ __forceinline__ void RGB2XYZConvert(const T* src, D& dst) + { + dst.z = saturate_cast(CV_DESCALE(src[bidx^2] * c_RGB2XYZ_D65i[6] + src[1] * c_RGB2XYZ_D65i[7] + src[bidx] * c_RGB2XYZ_D65i[8], xyz_shift)); + dst.x = saturate_cast(CV_DESCALE(src[bidx^2] * c_RGB2XYZ_D65i[0] + src[1] * c_RGB2XYZ_D65i[1] + src[bidx] * c_RGB2XYZ_D65i[2], xyz_shift)); + dst.y = saturate_cast(CV_DESCALE(src[bidx^2] * c_RGB2XYZ_D65i[3] + src[1] * c_RGB2XYZ_D65i[4] + src[bidx] * c_RGB2XYZ_D65i[5], xyz_shift)); + } + + template static __device__ __forceinline__ uint RGB2XYZConvert(uint src) + { + const uint b = 0xffu & (src >> (bidx * 8)); + const uint g = 0xffu & (src >> 8); + const uint r = 0xffu & (src >> ((bidx ^ 2) * 8)); + + const uint x = saturate_cast(CV_DESCALE(r * c_RGB2XYZ_D65i[0] + g * c_RGB2XYZ_D65i[1] + b * c_RGB2XYZ_D65i[2], xyz_shift)); + const uint y = saturate_cast(CV_DESCALE(r * c_RGB2XYZ_D65i[3] + g * c_RGB2XYZ_D65i[4] + b * c_RGB2XYZ_D65i[5], xyz_shift)); + const uint z = saturate_cast(CV_DESCALE(r * c_RGB2XYZ_D65i[6] + g * c_RGB2XYZ_D65i[7] + b * c_RGB2XYZ_D65i[8], xyz_shift)); + + uint dst = 0; + + dst |= x; + dst |= y << 8; + dst |= z << 16; + + return dst; + } + + template static __device__ __forceinline__ void RGB2XYZConvert(const float* src, D& dst) + { + dst.x = src[bidx^2] * c_RGB2XYZ_D65f[0] + src[1] * c_RGB2XYZ_D65f[1] + src[bidx] * c_RGB2XYZ_D65f[2]; + dst.y = src[bidx^2] * c_RGB2XYZ_D65f[3] + src[1] * c_RGB2XYZ_D65f[4] + src[bidx] * c_RGB2XYZ_D65f[5]; + dst.z = src[bidx^2] * c_RGB2XYZ_D65f[6] + src[1] * c_RGB2XYZ_D65f[7] + src[bidx] * c_RGB2XYZ_D65f[8]; + } + + template struct RGB2XYZ + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + RGB2XYZConvert(&src.x, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2XYZ() {} + __host__ __device__ __forceinline__ RGB2XYZ(const RGB2XYZ&) {} + }; + + template struct RGB2XYZ : unary_function + { + __device__ __forceinline__ uint operator()(uint src) const + { + return RGB2XYZConvert(src); + } + __host__ __device__ __forceinline__ RGB2XYZ() {} + __host__ __device__ __forceinline__ RGB2XYZ(const RGB2XYZ&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2XYZ functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_XYZ2sRGB_D65f[9] = { 3.240479f, -1.53715f, -0.498535f, -0.969256f, 1.875991f, 0.041556f, 0.055648f, -0.204043f, 1.057311f }; + __constant__ int c_XYZ2sRGB_D65i[9] = { 13273, -6296, -2042, -3970, 7684, 170, 228, -836, 4331 }; + + template static __device__ __forceinline__ void XYZ2RGBConvert(const T& src, D* dst) + { + dst[bidx^2] = saturate_cast(CV_DESCALE(src.x * c_XYZ2sRGB_D65i[0] + src.y * c_XYZ2sRGB_D65i[1] + src.z * c_XYZ2sRGB_D65i[2], xyz_shift)); + dst[1] = saturate_cast(CV_DESCALE(src.x * c_XYZ2sRGB_D65i[3] + src.y * c_XYZ2sRGB_D65i[4] + src.z * c_XYZ2sRGB_D65i[5], xyz_shift)); + dst[bidx] = saturate_cast(CV_DESCALE(src.x * c_XYZ2sRGB_D65i[6] + src.y * c_XYZ2sRGB_D65i[7] + src.z * c_XYZ2sRGB_D65i[8], xyz_shift)); + } + + template static __device__ __forceinline__ uint XYZ2RGBConvert(uint src) + { + const int x = 0xff & src; + const int y = 0xff & (src >> 8); + const int z = 0xff & (src >> 16); + + const uint r = saturate_cast(CV_DESCALE(x * c_XYZ2sRGB_D65i[0] + y * c_XYZ2sRGB_D65i[1] + z * c_XYZ2sRGB_D65i[2], xyz_shift)); + const uint g = saturate_cast(CV_DESCALE(x * c_XYZ2sRGB_D65i[3] + y * c_XYZ2sRGB_D65i[4] + z * c_XYZ2sRGB_D65i[5], xyz_shift)); + const uint b = saturate_cast(CV_DESCALE(x * c_XYZ2sRGB_D65i[6] + y * c_XYZ2sRGB_D65i[7] + z * c_XYZ2sRGB_D65i[8], xyz_shift)); + + uint dst = 0xffu << 24; + + dst |= b << (bidx * 8); + dst |= g << 8; + dst |= r << ((bidx ^ 2) * 8); + + return dst; + } + + template static __device__ __forceinline__ void XYZ2RGBConvert(const T& src, float* dst) + { + dst[bidx^2] = src.x * c_XYZ2sRGB_D65f[0] + src.y * c_XYZ2sRGB_D65f[1] + src.z * c_XYZ2sRGB_D65f[2]; + dst[1] = src.x * c_XYZ2sRGB_D65f[3] + src.y * c_XYZ2sRGB_D65f[4] + src.z * c_XYZ2sRGB_D65f[5]; + dst[bidx] = src.x * c_XYZ2sRGB_D65f[6] + src.y * c_XYZ2sRGB_D65f[7] + src.z * c_XYZ2sRGB_D65f[8]; + } + + template struct XYZ2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + XYZ2RGBConvert(src, &dst.x); + setAlpha(dst, ColorChannel::max()); + + return dst; + } + __host__ __device__ __forceinline__ XYZ2RGB() {} + __host__ __device__ __forceinline__ XYZ2RGB(const XYZ2RGB&) {} + }; + + template struct XYZ2RGB : unary_function + { + __device__ __forceinline__ uint operator()(uint src) const + { + return XYZ2RGBConvert(src); + } + __host__ __device__ __forceinline__ XYZ2RGB() {} + __host__ __device__ __forceinline__ XYZ2RGB(const XYZ2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::XYZ2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +////////////////////////////////////// RGB <-> HSV /////////////////////////////////////// + + namespace color_detail + { + __constant__ int c_HsvDivTable [256] = {0, 1044480, 522240, 348160, 261120, 208896, 174080, 149211, 130560, 116053, 104448, 94953, 87040, 80345, 74606, 69632, 65280, 61440, 58027, 54973, 52224, 49737, 47476, 45412, 43520, 41779, 40172, 38684, 37303, 36017, 34816, 33693, 32640, 31651, 30720, 29842, 29013, 28229, 27486, 26782, 26112, 25475, 24869, 24290, 23738, 23211, 22706, 22223, 21760, 21316, 20890, 20480, 20086, 19707, 19342, 18991, 18651, 18324, 18008, 17703, 17408, 17123, 16846, 16579, 16320, 16069, 15825, 15589, 15360, 15137, 14921, 14711, 14507, 14308, 14115, 13926, 13743, 13565, 13391, 13221, 13056, 12895, 12738, 12584, 12434, 12288, 12145, 12006, 11869, 11736, 11605, 11478, 11353, 11231, 11111, 10995, 10880, 10768, 10658, 10550, 10445, 10341, 10240, 10141, 10043, 9947, 9854, 9761, 9671, 9582, 9495, 9410, 9326, 9243, 9162, 9082, 9004, 8927, 8852, 8777, 8704, 8632, 8561, 8492, 8423, 8356, 8290, 8224, 8160, 8097, 8034, 7973, 7913, 7853, 7795, 7737, 7680, 7624, 7569, 7514, 7461, 7408, 7355, 7304, 7253, 7203, 7154, 7105, 7057, 7010, 6963, 6917, 6872, 6827, 6782, 6739, 6695, 6653, 6611, 6569, 6528, 6487, 6447, 6408, 6369, 6330, 6292, 6254, 6217, 6180, 6144, 6108, 6073, 6037, 6003, 5968, 5935, 5901, 5868, 5835, 5803, 5771, 5739, 5708, 5677, 5646, 5615, 5585, 5556, 5526, 5497, 5468, 5440, 5412, 5384, 5356, 5329, 5302, 5275, 5249, 5222, 5196, 5171, 5145, 5120, 5095, 5070, 5046, 5022, 4998, 4974, 4950, 4927, 4904, 4881, 4858, 4836, 4813, 4791, 4769, 4748, 4726, 4705, 4684, 4663, 4642, 4622, 4601, 4581, 4561, 4541, 4522, 4502, 4483, 4464, 4445, 4426, 4407, 4389, 4370, 4352, 4334, 4316, 4298, 4281, 4263, 4246, 4229, 4212, 4195, 4178, 4161, 4145, 4128, 4112, 4096}; + __constant__ int c_HsvDivTable180[256] = {0, 122880, 61440, 40960, 30720, 24576, 20480, 17554, 15360, 13653, 12288, 11171, 10240, 9452, 8777, 8192, 7680, 7228, 6827, 6467, 6144, 5851, 5585, 5343, 5120, 4915, 4726, 4551, 4389, 4237, 4096, 3964, 3840, 3724, 3614, 3511, 3413, 3321, 3234, 3151, 3072, 2997, 2926, 2858, 2793, 2731, 2671, 2614, 2560, 2508, 2458, 2409, 2363, 2318, 2276, 2234, 2194, 2156, 2119, 2083, 2048, 2014, 1982, 1950, 1920, 1890, 1862, 1834, 1807, 1781, 1755, 1731, 1707, 1683, 1661, 1638, 1617, 1596, 1575, 1555, 1536, 1517, 1499, 1480, 1463, 1446, 1429, 1412, 1396, 1381, 1365, 1350, 1336, 1321, 1307, 1293, 1280, 1267, 1254, 1241, 1229, 1217, 1205, 1193, 1182, 1170, 1159, 1148, 1138, 1127, 1117, 1107, 1097, 1087, 1078, 1069, 1059, 1050, 1041, 1033, 1024, 1016, 1007, 999, 991, 983, 975, 968, 960, 953, 945, 938, 931, 924, 917, 910, 904, 897, 890, 884, 878, 871, 865, 859, 853, 847, 842, 836, 830, 825, 819, 814, 808, 803, 798, 793, 788, 783, 778, 773, 768, 763, 759, 754, 749, 745, 740, 736, 731, 727, 723, 719, 714, 710, 706, 702, 698, 694, 690, 686, 683, 679, 675, 671, 668, 664, 661, 657, 654, 650, 647, 643, 640, 637, 633, 630, 627, 624, 621, 617, 614, 611, 608, 605, 602, 599, 597, 594, 591, 588, 585, 582, 580, 577, 574, 572, 569, 566, 564, 561, 559, 556, 554, 551, 549, 546, 544, 541, 539, 537, 534, 532, 530, 527, 525, 523, 521, 518, 516, 514, 512, 510, 508, 506, 504, 502, 500, 497, 495, 493, 492, 490, 488, 486, 484, 482}; + __constant__ int c_HsvDivTable256[256] = {0, 174763, 87381, 58254, 43691, 34953, 29127, 24966, 21845, 19418, 17476, 15888, 14564, 13443, 12483, 11651, 10923, 10280, 9709, 9198, 8738, 8322, 7944, 7598, 7282, 6991, 6722, 6473, 6242, 6026, 5825, 5638, 5461, 5296, 5140, 4993, 4855, 4723, 4599, 4481, 4369, 4263, 4161, 4064, 3972, 3884, 3799, 3718, 3641, 3567, 3495, 3427, 3361, 3297, 3236, 3178, 3121, 3066, 3013, 2962, 2913, 2865, 2819, 2774, 2731, 2689, 2648, 2608, 2570, 2533, 2497, 2461, 2427, 2394, 2362, 2330, 2300, 2270, 2241, 2212, 2185, 2158, 2131, 2106, 2081, 2056, 2032, 2009, 1986, 1964, 1942, 1920, 1900, 1879, 1859, 1840, 1820, 1802, 1783, 1765, 1748, 1730, 1713, 1697, 1680, 1664, 1649, 1633, 1618, 1603, 1589, 1574, 1560, 1547, 1533, 1520, 1507, 1494, 1481, 1469, 1456, 1444, 1432, 1421, 1409, 1398, 1387, 1376, 1365, 1355, 1344, 1334, 1324, 1314, 1304, 1295, 1285, 1276, 1266, 1257, 1248, 1239, 1231, 1222, 1214, 1205, 1197, 1189, 1181, 1173, 1165, 1157, 1150, 1142, 1135, 1128, 1120, 1113, 1106, 1099, 1092, 1085, 1079, 1072, 1066, 1059, 1053, 1046, 1040, 1034, 1028, 1022, 1016, 1010, 1004, 999, 993, 987, 982, 976, 971, 966, 960, 955, 950, 945, 940, 935, 930, 925, 920, 915, 910, 906, 901, 896, 892, 887, 883, 878, 874, 869, 865, 861, 857, 853, 848, 844, 840, 836, 832, 828, 824, 820, 817, 813, 809, 805, 802, 798, 794, 791, 787, 784, 780, 777, 773, 770, 767, 763, 760, 757, 753, 750, 747, 744, 741, 737, 734, 731, 728, 725, 722, 719, 716, 713, 710, 708, 705, 702, 699, 696, 694, 691, 688, 685}; + + template static __device__ void RGB2HSVConvert(const uchar* src, D& dst) + { + const int hsv_shift = 12; + const int* hdiv_table = hr == 180 ? c_HsvDivTable180 : c_HsvDivTable256; + + int b = src[bidx], g = src[1], r = src[bidx^2]; + int h, s, v = b; + int vmin = b, diff; + int vr, vg; + + v = ::max(v, g); + v = ::max(v, r); + vmin = ::min(vmin, g); + vmin = ::min(vmin, r); + + diff = v - vmin; + vr = (v == r) * -1; + vg = (v == g) * -1; + + s = (diff * c_HsvDivTable[v] + (1 << (hsv_shift-1))) >> hsv_shift; + h = (vr & (g - b)) + (~vr & ((vg & (b - r + 2 * diff)) + ((~vg) & (r - g + 4 * diff)))); + h = (h * hdiv_table[diff] + (1 << (hsv_shift-1))) >> hsv_shift; + h += (h < 0) * hr; + + dst.x = saturate_cast(h); + dst.y = (uchar)s; + dst.z = (uchar)v; + } + + template static __device__ uint RGB2HSVConvert(uint src) + { + const int hsv_shift = 12; + const int* hdiv_table = hr == 180 ? c_HsvDivTable180 : c_HsvDivTable256; + + const int b = 0xff & (src >> (bidx * 8)); + const int g = 0xff & (src >> 8); + const int r = 0xff & (src >> ((bidx ^ 2) * 8)); + + int h, s, v = b; + int vmin = b, diff; + int vr, vg; + + v = ::max(v, g); + v = ::max(v, r); + vmin = ::min(vmin, g); + vmin = ::min(vmin, r); + + diff = v - vmin; + vr = (v == r) * -1; + vg = (v == g) * -1; + + s = (diff * c_HsvDivTable[v] + (1 << (hsv_shift-1))) >> hsv_shift; + h = (vr & (g - b)) + (~vr & ((vg & (b - r + 2 * diff)) + ((~vg) & (r - g + 4 * diff)))); + h = (h * hdiv_table[diff] + (1 << (hsv_shift-1))) >> hsv_shift; + h += (h < 0) * hr; + + uint dst = 0; + + dst |= saturate_cast(h); + dst |= (0xffu & s) << 8; + dst |= (0xffu & v) << 16; + + return dst; + } + + template static __device__ void RGB2HSVConvert(const float* src, D& dst) + { + const float hscale = hr * (1.f / 360.f); + + float b = src[bidx], g = src[1], r = src[bidx^2]; + float h, s, v; + + float vmin, diff; + + v = vmin = r; + v = fmax(v, g); + v = fmax(v, b); + vmin = fmin(vmin, g); + vmin = fmin(vmin, b); + + diff = v - vmin; + s = diff / (float)(::fabs(v) + numeric_limits::epsilon()); + diff = (float)(60. / (diff + numeric_limits::epsilon())); + + h = (v == r) * (g - b) * diff; + h += (v != r && v == g) * ((b - r) * diff + 120.f); + h += (v != r && v != g) * ((r - g) * diff + 240.f); + h += (h < 0) * 360.f; + + dst.x = h * hscale; + dst.y = s; + dst.z = v; + } + + template struct RGB2HSV + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + RGB2HSVConvert(&src.x, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2HSV() {} + __host__ __device__ __forceinline__ RGB2HSV(const RGB2HSV&) {} + }; + + template struct RGB2HSV : unary_function + { + __device__ __forceinline__ uint operator()(uint src) const + { + return RGB2HSVConvert(src); + } + __host__ __device__ __forceinline__ RGB2HSV() {} + __host__ __device__ __forceinline__ RGB2HSV(const RGB2HSV&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HSV functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ int c_HsvSectorData[6][3] = { {1,3,0}, {1,0,2}, {3,0,1}, {0,2,1}, {0,1,3}, {2,1,0} }; + + template static __device__ void HSV2RGBConvert(const T& src, float* dst) + { + const float hscale = 6.f / hr; + + float h = src.x, s = src.y, v = src.z; + float b = v, g = v, r = v; + + if (s != 0) + { + h *= hscale; + + if( h < 0 ) + do h += 6; while( h < 0 ); + else if( h >= 6 ) + do h -= 6; while( h >= 6 ); + + int sector = __float2int_rd(h); + h -= sector; + + if ( (unsigned)sector >= 6u ) + { + sector = 0; + h = 0.f; + } + + float tab[4]; + tab[0] = v; + tab[1] = v * (1.f - s); + tab[2] = v * (1.f - s * h); + tab[3] = v * (1.f - s * (1.f - h)); + + b = tab[c_HsvSectorData[sector][0]]; + g = tab[c_HsvSectorData[sector][1]]; + r = tab[c_HsvSectorData[sector][2]]; + } + + dst[bidx] = b; + dst[1] = g; + dst[bidx^2] = r; + } + + template static __device__ void HSV2RGBConvert(const T& src, uchar* dst) + { + float3 buf; + + buf.x = src.x; + buf.y = src.y * (1.f / 255.f); + buf.z = src.z * (1.f / 255.f); + + HSV2RGBConvert(buf, &buf.x); + + dst[0] = saturate_cast(buf.x * 255.f); + dst[1] = saturate_cast(buf.y * 255.f); + dst[2] = saturate_cast(buf.z * 255.f); + } + + template static __device__ uint HSV2RGBConvert(uint src) + { + float3 buf; + + buf.x = src & 0xff; + buf.y = ((src >> 8) & 0xff) * (1.f/255.f); + buf.z = ((src >> 16) & 0xff) * (1.f/255.f); + + HSV2RGBConvert(buf, &buf.x); + + uint dst = 0xffu << 24; + + dst |= saturate_cast(buf.x * 255.f); + dst |= saturate_cast(buf.y * 255.f) << 8; + dst |= saturate_cast(buf.z * 255.f) << 16; + + return dst; + } + + template struct HSV2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + HSV2RGBConvert(src, &dst.x); + setAlpha(dst, ColorChannel::max()); + + return dst; + } + __host__ __device__ __forceinline__ HSV2RGB() {} + __host__ __device__ __forceinline__ HSV2RGB(const HSV2RGB&) {} + }; + + template struct HSV2RGB : unary_function + { + __device__ __forceinline__ uint operator()(uint src) const + { + return HSV2RGBConvert(src); + } + __host__ __device__ __forceinline__ HSV2RGB() {} + __host__ __device__ __forceinline__ HSV2RGB(const HSV2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::HSV2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +/////////////////////////////////////// RGB <-> HLS //////////////////////////////////////// + + namespace color_detail + { + template static __device__ void RGB2HLSConvert(const float* src, D& dst) + { + const float hscale = hr * (1.f / 360.f); + + float b = src[bidx], g = src[1], r = src[bidx^2]; + float h = 0.f, s = 0.f, l; + float vmin, vmax, diff; + + vmax = vmin = r; + vmax = fmax(vmax, g); + vmax = fmax(vmax, b); + vmin = fmin(vmin, g); + vmin = fmin(vmin, b); + + diff = vmax - vmin; + l = (vmax + vmin) * 0.5f; + + if (diff > numeric_limits::epsilon()) + { + s = (l < 0.5f) * diff / (vmax + vmin); + s += (l >= 0.5f) * diff / (2.0f - vmax - vmin); + + diff = 60.f / diff; + + h = (vmax == r) * (g - b) * diff; + h += (vmax != r && vmax == g) * ((b - r) * diff + 120.f); + h += (vmax != r && vmax != g) * ((r - g) * diff + 240.f); + h += (h < 0.f) * 360.f; + } + + dst.x = h * hscale; + dst.y = l; + dst.z = s; + } + + template static __device__ void RGB2HLSConvert(const uchar* src, D& dst) + { + float3 buf; + + buf.x = src[0] * (1.f / 255.f); + buf.y = src[1] * (1.f / 255.f); + buf.z = src[2] * (1.f / 255.f); + + RGB2HLSConvert(&buf.x, buf); + + dst.x = saturate_cast(buf.x); + dst.y = saturate_cast(buf.y*255.f); + dst.z = saturate_cast(buf.z*255.f); + } + + template static __device__ uint RGB2HLSConvert(uint src) + { + float3 buf; + + buf.x = (0xff & src) * (1.f / 255.f); + buf.y = (0xff & (src >> 8)) * (1.f / 255.f); + buf.z = (0xff & (src >> 16)) * (1.f / 255.f); + + RGB2HLSConvert(&buf.x, buf); + + uint dst = 0xffu << 24; + + dst |= saturate_cast(buf.x); + dst |= saturate_cast(buf.y * 255.f) << 8; + dst |= saturate_cast(buf.z * 255.f) << 16; + + return dst; + } + + template struct RGB2HLS + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + RGB2HLSConvert(&src.x, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2HLS() {} + __host__ __device__ __forceinline__ RGB2HLS(const RGB2HLS&) {} + }; + + template struct RGB2HLS : unary_function + { + __device__ __forceinline__ uint operator()(uint src) const + { + return RGB2HLSConvert(src); + } + __host__ __device__ __forceinline__ RGB2HLS() {} + __host__ __device__ __forceinline__ RGB2HLS(const RGB2HLS&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2HLS functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ int c_HlsSectorData[6][3] = { {1,3,0}, {1,0,2}, {3,0,1}, {0,2,1}, {0,1,3}, {2,1,0} }; + + template static __device__ void HLS2RGBConvert(const T& src, float* dst) + { + const float hscale = 6.0f / hr; + + float h = src.x, l = src.y, s = src.z; + float b = l, g = l, r = l; + + if (s != 0) + { + float p2 = (l <= 0.5f) * l * (1 + s); + p2 += (l > 0.5f) * (l + s - l * s); + float p1 = 2 * l - p2; + + h *= hscale; + + if( h < 0 ) + do h += 6; while( h < 0 ); + else if( h >= 6 ) + do h -= 6; while( h >= 6 ); + + int sector; + sector = __float2int_rd(h); + + h -= sector; + + float tab[4]; + tab[0] = p2; + tab[1] = p1; + tab[2] = p1 + (p2 - p1) * (1 - h); + tab[3] = p1 + (p2 - p1) * h; + + b = tab[c_HlsSectorData[sector][0]]; + g = tab[c_HlsSectorData[sector][1]]; + r = tab[c_HlsSectorData[sector][2]]; + } + + dst[bidx] = b; + dst[1] = g; + dst[bidx^2] = r; + } + + template static __device__ void HLS2RGBConvert(const T& src, uchar* dst) + { + float3 buf; + + buf.x = src.x; + buf.y = src.y * (1.f / 255.f); + buf.z = src.z * (1.f / 255.f); + + HLS2RGBConvert(buf, &buf.x); + + dst[0] = saturate_cast(buf.x * 255.f); + dst[1] = saturate_cast(buf.y * 255.f); + dst[2] = saturate_cast(buf.z * 255.f); + } + + template static __device__ uint HLS2RGBConvert(uint src) + { + float3 buf; + + buf.x = 0xff & src; + buf.y = (0xff & (src >> 8)) * (1.f / 255.f); + buf.z = (0xff & (src >> 16)) * (1.f / 255.f); + + HLS2RGBConvert(buf, &buf.x); + + uint dst = 0xffu << 24; + + dst |= saturate_cast(buf.x * 255.f); + dst |= saturate_cast(buf.y * 255.f) << 8; + dst |= saturate_cast(buf.z * 255.f) << 16; + + return dst; + } + + template struct HLS2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + HLS2RGBConvert(src, &dst.x); + setAlpha(dst, ColorChannel::max()); + + return dst; + } + __host__ __device__ __forceinline__ HLS2RGB() {} + __host__ __device__ __forceinline__ HLS2RGB(const HLS2RGB&) {} + }; + + template struct HLS2RGB : unary_function + { + __device__ __forceinline__ uint operator()(uint src) const + { + return HLS2RGBConvert(src); + } + __host__ __device__ __forceinline__ HLS2RGB() {} + __host__ __device__ __forceinline__ HLS2RGB(const HLS2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(name, scn, dcn, bidx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; \ + template <> struct name ## _full_traits \ + { \ + typedef ::cv::cuda::device::color_detail::HLS2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> Lab ///////////////////////////////////// + + namespace color_detail + { + enum + { + LAB_CBRT_TAB_SIZE = 1024, + GAMMA_TAB_SIZE = 1024, + lab_shift = xyz_shift, + gamma_shift = 3, + lab_shift2 = (lab_shift + gamma_shift), + LAB_CBRT_TAB_SIZE_B = (256 * 3 / 2 * (1 << gamma_shift)) + }; + + __constant__ ushort c_sRGBGammaTab_b[] = {0,1,1,2,2,3,4,4,5,6,6,7,8,8,9,10,11,11,12,13,14,15,16,17,19,20,21,22,24,25,26,28,29,31,33,34,36,38,40,41,43,45,47,49,51,54,56,58,60,63,65,68,70,73,75,78,81,83,86,89,92,95,98,101,105,108,111,115,118,121,125,129,132,136,140,144,147,151,155,160,164,168,172,176,181,185,190,194,199,204,209,213,218,223,228,233,239,244,249,255,260,265,271,277,282,288,294,300,306,312,318,324,331,337,343,350,356,363,370,376,383,390,397,404,411,418,426,433,440,448,455,463,471,478,486,494,502,510,518,527,535,543,552,560,569,578,586,595,604,613,622,631,641,650,659,669,678,688,698,707,717,727,737,747,757,768,778,788,799,809,820,831,842,852,863,875,886,897,908,920,931,943,954,966,978,990,1002,1014,1026,1038,1050,1063,1075,1088,1101,1113,1126,1139,1152,1165,1178,1192,1205,1218,1232,1245,1259,1273,1287,1301,1315,1329,1343,1357,1372,1386,1401,1415,1430,1445,1460,1475,1490,1505,1521,1536,1551,1567,1583,1598,1614,1630,1646,1662,1678,1695,1711,1728,1744,1761,1778,1794,1811,1828,1846,1863,1880,1897,1915,1933,1950,1968,1986,2004,2022,2040}; + + __device__ __forceinline__ int LabCbrt_b(int i) + { + float x = i * (1.f / (255.f * (1 << gamma_shift))); + return (1 << lab_shift2) * (x < 0.008856f ? x * 7.787f + 0.13793103448275862f : ::cbrtf(x)); + } + + template + __device__ __forceinline__ void RGB2LabConvert_b(const T& src, D& dst) + { + const int Lscale = (116 * 255 + 50) / 100; + const int Lshift = -((16 * 255 * (1 << lab_shift2) + 50) / 100); + + int B = blueIdx == 0 ? src.x : src.z; + int G = src.y; + int R = blueIdx == 0 ? src.z : src.x; + + if (srgb) + { + B = c_sRGBGammaTab_b[B]; + G = c_sRGBGammaTab_b[G]; + R = c_sRGBGammaTab_b[R]; + } + else + { + B <<= 3; + G <<= 3; + R <<= 3; + } + + int fX = LabCbrt_b(CV_DESCALE(B * 778 + G * 1541 + R * 1777, lab_shift)); + int fY = LabCbrt_b(CV_DESCALE(B * 296 + G * 2929 + R * 871, lab_shift)); + int fZ = LabCbrt_b(CV_DESCALE(B * 3575 + G * 448 + R * 73, lab_shift)); + + int L = CV_DESCALE(Lscale * fY + Lshift, lab_shift2); + int a = CV_DESCALE(500 * (fX - fY) + 128 * (1 << lab_shift2), lab_shift2); + int b = CV_DESCALE(200 * (fY - fZ) + 128 * (1 << lab_shift2), lab_shift2); + + dst.x = saturate_cast(L); + dst.y = saturate_cast(a); + dst.z = saturate_cast(b); + } + + __device__ __forceinline__ float splineInterpolate(float x, const float* tab, int n) + { + int ix = ::min(::max(int(x), 0), n-1); + x -= ix; + tab += ix * 4; + return ((tab[3] * x + tab[2]) * x + tab[1]) * x + tab[0]; + } + + __constant__ float c_sRGBGammaTab[] = {0,7.55853e-05,0.,-7.51331e-13,7.55853e-05,7.55853e-05,-2.25399e-12,3.75665e-12,0.000151171,7.55853e-05,9.01597e-12,-6.99932e-12,0.000226756,7.55853e-05,-1.1982e-11,2.41277e-12,0.000302341,7.55853e-05,-4.74369e-12,1.19001e-11,0.000377927,7.55853e-05,3.09568e-11,-2.09095e-11,0.000453512,7.55853e-05,-3.17718e-11,1.35303e-11,0.000529097,7.55853e-05,8.81905e-12,-4.10782e-12,0.000604683,7.55853e-05,-3.50439e-12,2.90097e-12,0.000680268,7.55853e-05,5.19852e-12,-7.49607e-12,0.000755853,7.55853e-05,-1.72897e-11,2.70833e-11,0.000831439,7.55854e-05,6.39602e-11,-4.26295e-11,0.000907024,7.55854e-05,-6.39282e-11,2.70193e-11,0.000982609,7.55853e-05,1.71298e-11,-7.24017e-12,0.00105819,7.55853e-05,-4.59077e-12,1.94137e-12,0.00113378,7.55853e-05,1.23333e-12,-5.25291e-13,0.00120937,7.55853e-05,-3.42545e-13,1.59799e-13,0.00128495,7.55853e-05,1.36852e-13,-1.13904e-13,0.00136054,7.55853e-05,-2.04861e-13,2.95818e-13,0.00143612,7.55853e-05,6.82594e-13,-1.06937e-12,0.00151171,7.55853e-05,-2.52551e-12,3.98166e-12,0.00158729,7.55853e-05,9.41946e-12,-1.48573e-11,0.00166288,7.55853e-05,-3.51523e-11,5.54474e-11,0.00173846,7.55854e-05,1.3119e-10,-9.0517e-11,0.00181405,7.55854e-05,-1.40361e-10,7.37899e-11,0.00188963,7.55853e-05,8.10085e-11,-8.82272e-11,0.00196522,7.55852e-05,-1.83673e-10,1.62704e-10,0.0020408,7.55853e-05,3.04438e-10,-2.13341e-10,0.00211639,7.55853e-05,-3.35586e-10,2.25e-10,0.00219197,7.55853e-05,3.39414e-10,-2.20997e-10,0.00226756,7.55853e-05,-3.23576e-10,1.93326e-10,0.00234315,7.55853e-05,2.564e-10,-8.66446e-11,0.00241873,7.55855e-05,-3.53328e-12,-7.9578e-11,0.00249432,7.55853e-05,-2.42267e-10,1.72126e-10,0.0025699,7.55853e-05,2.74111e-10,-1.43265e-10,0.00264549,7.55854e-05,-1.55683e-10,-6.47292e-11,0.00272107,7.55849e-05,-3.4987e-10,8.67842e-10,0.00279666,7.55868e-05,2.25366e-09,-3.8723e-09,0.00287224,7.55797e-05,-9.36325e-09,1.5087e-08,0.00294783,7.56063e-05,3.58978e-08,-5.69415e-08,0.00302341,7.55072e-05,-1.34927e-07,2.13144e-07,0.003099,7.58768e-05,5.04507e-07,1.38713e-07,0.00317552,7.7302e-05,9.20646e-07,-1.55186e-07,0.00325359,7.86777e-05,4.55087e-07,4.26813e-08,0.00333276,7.97159e-05,5.83131e-07,-1.06495e-08,0.00341305,8.08502e-05,5.51182e-07,3.87467e-09,0.00349446,8.19642e-05,5.62806e-07,-1.92586e-10,0.00357698,8.30892e-05,5.62228e-07,1.0866e-09,0.00366063,8.4217e-05,5.65488e-07,5.02818e-10,0.00374542,8.53494e-05,5.66997e-07,8.60211e-10,0.00383133,8.6486e-05,5.69577e-07,7.13044e-10,0.00391839,8.76273e-05,5.71716e-07,4.78527e-10,0.00400659,8.87722e-05,5.73152e-07,1.09818e-09,0.00409594,8.99218e-05,5.76447e-07,2.50964e-10,0.00418644,9.10754e-05,5.772e-07,1.15762e-09,0.00427809,9.22333e-05,5.80672e-07,2.40865e-10,0.0043709,9.33954e-05,5.81395e-07,1.13854e-09,0.00446488,9.45616e-05,5.84811e-07,3.27267e-10,0.00456003,9.57322e-05,5.85792e-07,8.1197e-10,0.00465635,9.69062e-05,5.88228e-07,6.15823e-10,0.00475384,9.80845e-05,5.90076e-07,9.15747e-10,0.00485252,9.92674e-05,5.92823e-07,3.778e-10,0.00495238,0.000100454,5.93956e-07,8.32623e-10,0.00505343,0.000101645,5.96454e-07,4.82695e-10,0.00515567,0.000102839,5.97902e-07,9.61904e-10,0.00525911,0.000104038,6.00788e-07,3.26281e-10,0.00536375,0.00010524,6.01767e-07,9.926e-10,0.00546959,0.000106447,6.04745e-07,3.59933e-10,0.00557664,0.000107657,6.05824e-07,8.2728e-10,0.0056849,0.000108871,6.08306e-07,5.21898e-10,0.00579438,0.00011009,6.09872e-07,8.10492e-10,0.00590508,0.000111312,6.12303e-07,4.27046e-10,0.00601701,0.000112538,6.13585e-07,7.40878e-10,0.00613016,0.000113767,6.15807e-07,8.00469e-10,0.00624454,0.000115001,6.18209e-07,2.48178e-10,0.00636016,0.000116238,6.18953e-07,1.00073e-09,0.00647702,0.000117479,6.21955e-07,4.05654e-10,0.00659512,0.000118724,6.23172e-07,6.36192e-10,0.00671447,0.000119973,6.25081e-07,7.74927e-10,0.00683507,0.000121225,6.27406e-07,4.54975e-10,0.00695692,0.000122481,6.28771e-07,6.64841e-10,0.00708003,0.000123741,6.30765e-07,6.10972e-10,0.00720441,0.000125004,6.32598e-07,6.16543e-10,0.00733004,0.000126271,6.34448e-07,6.48204e-10,0.00745695,0.000127542,6.36392e-07,5.15835e-10,0.00758513,0.000128816,6.3794e-07,5.48103e-10,0.00771458,0.000130094,6.39584e-07,1.01706e-09,0.00784532,0.000131376,6.42635e-07,4.0283e-11,0.00797734,0.000132661,6.42756e-07,6.84471e-10,0.00811064,0.000133949,6.4481e-07,9.47144e-10,0.00824524,0.000135241,6.47651e-07,1.83472e-10,0.00838112,0.000136537,6.48201e-07,1.11296e-09,0.00851831,0.000137837,6.5154e-07,2.13163e-11,0.0086568,0.00013914,6.51604e-07,6.64462e-10,0.00879659,0.000140445,6.53598e-07,1.04613e-09,0.00893769,0.000141756,6.56736e-07,-1.92377e-10,0.0090801,0.000143069,6.56159e-07,1.58601e-09,0.00922383,0.000144386,6.60917e-07,-5.63754e-10,0.00936888,0.000145706,6.59226e-07,1.60033e-09,0.00951524,0.000147029,6.64027e-07,-2.49543e-10,0.00966294,0.000148356,6.63278e-07,1.26043e-09,0.00981196,0.000149687,6.67059e-07,-1.35572e-10,0.00996231,0.00015102,6.66653e-07,1.14458e-09,0.010114,0.000152357,6.70086e-07,2.13864e-10,0.010267,0.000153698,6.70728e-07,7.93856e-10,0.0104214,0.000155042,6.73109e-07,3.36077e-10,0.0105771,0.000156389,6.74118e-07,6.55765e-10,0.0107342,0.000157739,6.76085e-07,7.66211e-10,0.0108926,0.000159094,6.78384e-07,4.66116e-12,0.0110524,0.000160451,6.78398e-07,1.07775e-09,0.0112135,0.000161811,6.81631e-07,3.41023e-10,0.011376,0.000163175,6.82654e-07,3.5205e-10,0.0115398,0.000164541,6.8371e-07,1.04473e-09,0.0117051,0.000165912,6.86844e-07,1.25757e-10,0.0118717,0.000167286,6.87222e-07,3.14818e-10,0.0120396,0.000168661,6.88166e-07,1.40886e-09,0.012209,0.000170042,6.92393e-07,-3.62244e-10,0.0123797,0.000171425,6.91306e-07,9.71397e-10,0.0125518,0.000172811,6.9422e-07,2.02003e-10,0.0127253,0.0001742,6.94826e-07,1.01448e-09,0.0129002,0.000175593,6.97869e-07,3.96653e-10,0.0130765,0.00017699,6.99059e-07,1.92927e-10,0.0132542,0.000178388,6.99638e-07,6.94305e-10,0.0134333,0.00017979,7.01721e-07,7.55108e-10,0.0136138,0.000181195,7.03986e-07,1.05918e-11,0.0137957,0.000182603,7.04018e-07,1.06513e-09,0.013979,0.000184015,7.07214e-07,3.85512e-10,0.0141637,0.00018543,7.0837e-07,1.86769e-10,0.0143499,0.000186848,7.0893e-07,7.30116e-10,0.0145374,0.000188268,7.11121e-07,6.17983e-10,0.0147264,0.000189692,7.12975e-07,5.23282e-10,0.0149168,0.000191119,7.14545e-07,8.28398e-11,0.0151087,0.000192549,7.14793e-07,1.0081e-09,0.0153019,0.000193981,7.17817e-07,5.41244e-10,0.0154966,0.000195418,7.19441e-07,-3.7907e-10,0.0156928,0.000196856,7.18304e-07,1.90641e-09,0.0158903,0.000198298,7.24023e-07,-7.27387e-10,0.0160893,0.000199744,7.21841e-07,1.00317e-09,0.0162898,0.000201191,7.24851e-07,4.39949e-10,0.0164917,0.000202642,7.2617e-07,9.6234e-10,0.0166951,0.000204097,7.29057e-07,-5.64019e-10,0.0168999,0.000205554,7.27365e-07,1.29374e-09,0.0171062,0.000207012,7.31247e-07,9.77025e-10,0.017314,0.000208478,7.34178e-07,-1.47651e-09,0.0175232,0.000209942,7.29748e-07,3.06636e-09,0.0177338,0.00021141,7.38947e-07,-1.47573e-09,0.017946,0.000212884,7.3452e-07,9.7386e-10,0.0181596,0.000214356,7.37442e-07,1.30562e-09,0.0183747,0.000215835,7.41358e-07,-6.08376e-10,0.0185913,0.000217315,7.39533e-07,1.12785e-09,0.0188093,0.000218798,7.42917e-07,-1.77711e-10,0.0190289,0.000220283,7.42384e-07,1.44562e-09,0.0192499,0.000221772,7.46721e-07,-1.68825e-11,0.0194724,0.000223266,7.4667e-07,4.84533e-10,0.0196964,0.000224761,7.48124e-07,-5.85298e-11,0.0199219,0.000226257,7.47948e-07,1.61217e-09,0.0201489,0.000227757,7.52785e-07,-8.02136e-10,0.0203775,0.00022926,7.50378e-07,1.59637e-09,0.0206075,0.000230766,7.55167e-07,4.47168e-12,0.020839,0.000232276,7.55181e-07,2.48387e-10,0.021072,0.000233787,7.55926e-07,8.6474e-10,0.0213066,0.000235302,7.5852e-07,1.78299e-11,0.0215426,0.000236819,7.58573e-07,9.26567e-10,0.0217802,0.000238339,7.61353e-07,1.34529e-12,0.0220193,0.000239862,7.61357e-07,9.30659e-10,0.0222599,0.000241387,7.64149e-07,1.34529e-12,0.0225021,0.000242915,7.64153e-07,9.26567e-10,0.0227458,0.000244447,7.66933e-07,1.76215e-11,0.022991,0.00024598,7.66986e-07,8.65536e-10,0.0232377,0.000247517,7.69582e-07,2.45677e-10,0.023486,0.000249057,7.70319e-07,1.44193e-11,0.0237358,0.000250598,7.70363e-07,1.55918e-09,0.0239872,0.000252143,7.7504e-07,-6.63173e-10,0.0242401,0.000253691,7.73051e-07,1.09357e-09,0.0244946,0.000255241,7.76331e-07,1.41919e-11,0.0247506,0.000256793,7.76374e-07,7.12248e-10,0.0250082,0.000258348,7.78511e-07,8.62049e-10,0.0252673,0.000259908,7.81097e-07,-4.35061e-10,0.025528,0.000261469,7.79792e-07,8.7825e-10,0.0257902,0.000263031,7.82426e-07,6.47181e-10,0.0260541,0.000264598,7.84368e-07,2.58448e-10,0.0263194,0.000266167,7.85143e-07,1.81558e-10,0.0265864,0.000267738,7.85688e-07,8.78041e-10,0.0268549,0.000269312,7.88322e-07,3.15102e-11,0.027125,0.000270889,7.88417e-07,8.58525e-10,0.0273967,0.000272468,7.90992e-07,2.59812e-10,0.02767,0.000274051,7.91772e-07,-3.5224e-11,0.0279448,0.000275634,7.91666e-07,1.74377e-09,0.0282212,0.000277223,7.96897e-07,-1.35196e-09,0.0284992,0.000278813,7.92841e-07,1.80141e-09,0.0287788,0.000280404,7.98246e-07,-2.65629e-10,0.0290601,0.000281999,7.97449e-07,1.12374e-09,0.0293428,0.000283598,8.0082e-07,-5.04106e-10,0.0296272,0.000285198,7.99308e-07,8.92764e-10,0.0299132,0.000286799,8.01986e-07,6.58379e-10,0.0302008,0.000288405,8.03961e-07,1.98971e-10,0.0304901,0.000290014,8.04558e-07,4.08382e-10,0.0307809,0.000291624,8.05783e-07,3.01839e-11,0.0310733,0.000293236,8.05874e-07,1.33343e-09,0.0313673,0.000294851,8.09874e-07,2.2419e-10,0.031663,0.000296472,8.10547e-07,-3.67606e-10,0.0319603,0.000298092,8.09444e-07,1.24624e-09,0.0322592,0.000299714,8.13182e-07,-8.92025e-10,0.0325597,0.000301338,8.10506e-07,2.32183e-09,0.0328619,0.000302966,8.17472e-07,-9.44719e-10,0.0331657,0.000304598,8.14638e-07,1.45703e-09,0.0334711,0.000306232,8.19009e-07,-1.15805e-09,0.0337781,0.000307866,8.15535e-07,3.17507e-09,0.0340868,0.000309507,8.2506e-07,-4.09161e-09,0.0343971,0.000311145,8.12785e-07,5.74079e-09,0.0347091,0.000312788,8.30007e-07,-3.97034e-09,0.0350227,0.000314436,8.18096e-07,2.68985e-09,0.035338,0.00031608,8.26166e-07,6.61676e-10,0.0356549,0.000317734,8.28151e-07,-1.61123e-09,0.0359734,0.000319386,8.23317e-07,2.05786e-09,0.0362936,0.000321038,8.29491e-07,8.30388e-10,0.0366155,0.0003227,8.31982e-07,-1.65424e-09,0.036939,0.000324359,8.27019e-07,2.06129e-09,0.0372642,0.000326019,8.33203e-07,8.59719e-10,0.0375911,0.000327688,8.35782e-07,-1.77488e-09,0.0379196,0.000329354,8.30458e-07,2.51464e-09,0.0382498,0.000331023,8.38002e-07,-8.33135e-10,0.0385817,0.000332696,8.35502e-07,8.17825e-10,0.0389152,0.00033437,8.37956e-07,1.28718e-09,0.0392504,0.00033605,8.41817e-07,-2.2413e-09,0.0395873,0.000337727,8.35093e-07,3.95265e-09,0.0399258,0.000339409,8.46951e-07,-2.39332e-09,0.0402661,0.000341095,8.39771e-07,1.89533e-09,0.040608,0.000342781,8.45457e-07,-1.46271e-09,0.0409517,0.000344467,8.41069e-07,3.95554e-09,0.041297,0.000346161,8.52936e-07,-3.18369e-09,0.041644,0.000347857,8.43385e-07,1.32873e-09,0.0419927,0.000349548,8.47371e-07,1.59402e-09,0.0423431,0.000351248,8.52153e-07,-2.54336e-10,0.0426952,0.000352951,8.5139e-07,-5.76676e-10,0.043049,0.000354652,8.4966e-07,2.56114e-09,0.0434045,0.000356359,8.57343e-07,-2.21744e-09,0.0437617,0.000358067,8.50691e-07,2.58344e-09,0.0441206,0.000359776,8.58441e-07,-6.65826e-10,0.0444813,0.000361491,8.56444e-07,7.99218e-11,0.0448436,0.000363204,8.56684e-07,3.46063e-10,0.0452077,0.000364919,8.57722e-07,2.26116e-09,0.0455734,0.000366641,8.64505e-07,-1.94005e-09,0.045941,0.000368364,8.58685e-07,1.77384e-09,0.0463102,0.000370087,8.64007e-07,-1.43005e-09,0.0466811,0.000371811,8.59717e-07,3.94634e-09,0.0470538,0.000373542,8.71556e-07,-3.17946e-09,0.0474282,0.000375276,8.62017e-07,1.32104e-09,0.0478043,0.000377003,8.6598e-07,1.62045e-09,0.0481822,0.00037874,8.70842e-07,-3.52297e-10,0.0485618,0.000380481,8.69785e-07,-2.11211e-10,0.0489432,0.00038222,8.69151e-07,1.19716e-09,0.0493263,0.000383962,8.72743e-07,-8.52026e-10,0.0497111,0.000385705,8.70187e-07,2.21092e-09,0.0500977,0.000387452,8.76819e-07,-5.41339e-10,0.050486,0.000389204,8.75195e-07,-4.5361e-11,0.0508761,0.000390954,8.75059e-07,7.22669e-10,0.0512679,0.000392706,8.77227e-07,8.79936e-10,0.0516615,0.000394463,8.79867e-07,-5.17048e-10,0.0520568,0.000396222,8.78316e-07,1.18833e-09,0.0524539,0.000397982,8.81881e-07,-5.11022e-10,0.0528528,0.000399744,8.80348e-07,8.55683e-10,0.0532534,0.000401507,8.82915e-07,8.13562e-10,0.0536558,0.000403276,8.85356e-07,-3.84603e-10,0.05406,0.000405045,8.84202e-07,7.24962e-10,0.0544659,0.000406816,8.86377e-07,1.20986e-09,0.0548736,0.000408592,8.90006e-07,-1.83896e-09,0.0552831,0.000410367,8.84489e-07,2.42071e-09,0.0556944,0.000412143,8.91751e-07,-3.93413e-10,0.0561074,0.000413925,8.90571e-07,-8.46967e-10,0.0565222,0.000415704,8.8803e-07,3.78122e-09,0.0569388,0.000417491,8.99374e-07,-3.1021e-09,0.0573572,0.000419281,8.90068e-07,1.17658e-09,0.0577774,0.000421064,8.93597e-07,2.12117e-09,0.0581993,0.000422858,8.99961e-07,-2.21068e-09,0.0586231,0.000424651,8.93329e-07,2.9961e-09,0.0590486,0.000426447,9.02317e-07,-2.32311e-09,0.059476,0.000428244,8.95348e-07,2.57122e-09,0.0599051,0.000430043,9.03062e-07,-5.11098e-10,0.0603361,0.000431847,9.01528e-07,-5.27166e-10,0.0607688,0.000433649,8.99947e-07,2.61984e-09,0.0612034,0.000435457,9.07806e-07,-2.50141e-09,0.0616397,0.000437265,9.00302e-07,3.66045e-09,0.0620779,0.000439076,9.11283e-07,-4.68977e-09,0.0625179,0.000440885,8.97214e-07,7.64783e-09,0.0629597,0.000442702,9.20158e-07,-7.27499e-09,0.0634033,0.000444521,8.98333e-07,6.55113e-09,0.0638487,0.000446337,9.17986e-07,-4.02844e-09,0.0642959,0.000448161,9.05901e-07,2.11196e-09,0.064745,0.000449979,9.12236e-07,3.03125e-09,0.0651959,0.000451813,9.2133e-07,-6.78648e-09,0.0656486,0.000453635,9.00971e-07,9.21375e-09,0.0661032,0.000455464,9.28612e-07,-7.71684e-09,0.0665596,0.000457299,9.05462e-07,6.7522e-09,0.0670178,0.00045913,9.25718e-07,-4.3907e-09,0.0674778,0.000460968,9.12546e-07,3.36e-09,0.0679397,0.000462803,9.22626e-07,-1.59876e-09,0.0684034,0.000464644,9.1783e-07,3.0351e-09,0.068869,0.000466488,9.26935e-07,-3.09101e-09,0.0693364,0.000468333,9.17662e-07,1.8785e-09,0.0698057,0.000470174,9.23298e-07,3.02733e-09,0.0702768,0.00047203,9.3238e-07,-6.53722e-09,0.0707497,0.000473875,9.12768e-07,8.22054e-09,0.0712245,0.000475725,9.37429e-07,-3.99325e-09,0.0717012,0.000477588,9.2545e-07,3.01839e-10,0.0721797,0.00047944,9.26355e-07,2.78597e-09,0.0726601,0.000481301,9.34713e-07,-3.99507e-09,0.0731423,0.000483158,9.22728e-07,5.7435e-09,0.0736264,0.000485021,9.39958e-07,-4.07776e-09,0.0741123,0.000486888,9.27725e-07,3.11695e-09,0.0746002,0.000488753,9.37076e-07,-9.39394e-10,0.0750898,0.000490625,9.34258e-07,6.4055e-10,0.0755814,0.000492495,9.3618e-07,-1.62265e-09,0.0760748,0.000494363,9.31312e-07,5.84995e-09,0.0765701,0.000496243,9.48861e-07,-6.87601e-09,0.0770673,0.00049812,9.28233e-07,6.75296e-09,0.0775664,0.000499997,9.48492e-07,-5.23467e-09,0.0780673,0.000501878,9.32788e-07,6.73523e-09,0.0785701,0.000503764,9.52994e-07,-6.80514e-09,0.0790748,0.000505649,9.32578e-07,5.5842e-09,0.0795814,0.000507531,9.49331e-07,-6.30583e-10,0.0800899,0.000509428,9.47439e-07,-3.0618e-09,0.0806003,0.000511314,9.38254e-07,5.4273e-09,0.0811125,0.000513206,9.54536e-07,-3.74627e-09,0.0816267,0.000515104,9.43297e-07,2.10713e-09,0.0821427,0.000516997,9.49618e-07,2.76839e-09,0.0826607,0.000518905,9.57924e-07,-5.73006e-09,0.0831805,0.000520803,9.40733e-07,5.25072e-09,0.0837023,0.0005227,9.56486e-07,-3.71718e-10,0.084226,0.000524612,9.5537e-07,-3.76404e-09,0.0847515,0.000526512,9.44078e-07,7.97735e-09,0.085279,0.000528424,9.6801e-07,-5.79367e-09,0.0858084,0.000530343,9.50629e-07,2.96268e-10,0.0863397,0.000532245,9.51518e-07,4.6086e-09,0.0868729,0.000534162,9.65344e-07,-3.82947e-09,0.087408,0.000536081,9.53856e-07,3.25861e-09,0.087945,0.000537998,9.63631e-07,-1.7543e-09,0.088484,0.00053992,9.58368e-07,3.75849e-09,0.0890249,0.000541848,9.69644e-07,-5.82891e-09,0.0895677,0.00054377,9.52157e-07,4.65593e-09,0.0901124,0.000545688,9.66125e-07,2.10643e-09,0.0906591,0.000547627,9.72444e-07,-5.63099e-09,0.0912077,0.000549555,9.55551e-07,5.51627e-09,0.0917582,0.000551483,9.721e-07,-1.53292e-09,0.0923106,0.000553422,9.67501e-07,6.15311e-10,0.092865,0.000555359,9.69347e-07,-9.28291e-10,0.0934213,0.000557295,9.66562e-07,3.09774e-09,0.0939796,0.000559237,9.75856e-07,-4.01186e-09,0.0945398,0.000561177,9.6382e-07,5.49892e-09,0.095102,0.000563121,9.80317e-07,-3.08258e-09,0.0956661,0.000565073,9.71069e-07,-6.19176e-10,0.0962321,0.000567013,9.69212e-07,5.55932e-09,0.0968001,0.000568968,9.8589e-07,-6.71704e-09,0.09737,0.00057092,9.65738e-07,6.40762e-09,0.0979419,0.00057287,9.84961e-07,-4.0122e-09,0.0985158,0.000574828,9.72925e-07,2.19059e-09,0.0990916,0.000576781,9.79496e-07,2.70048e-09,0.0996693,0.000578748,9.87598e-07,-5.54193e-09,0.100249,0.000580706,9.70972e-07,4.56597e-09,0.100831,0.000582662,9.8467e-07,2.17923e-09,0.101414,0.000584638,9.91208e-07,-5.83232e-09,0.102,0.000586603,9.73711e-07,6.24884e-09,0.102588,0.000588569,9.92457e-07,-4.26178e-09,0.103177,0.000590541,9.79672e-07,3.34781e-09,0.103769,0.00059251,9.89715e-07,-1.67904e-09,0.104362,0.000594485,9.84678e-07,3.36839e-09,0.104958,0.000596464,9.94783e-07,-4.34397e-09,0.105555,0.000598441,9.81751e-07,6.55696e-09,0.106155,0.000600424,1.00142e-06,-6.98272e-09,0.106756,0.000602406,9.80474e-07,6.4728e-09,0.107359,0.000604386,9.99893e-07,-4.00742e-09,0.107965,0.000606374,9.8787e-07,2.10654e-09,0.108572,0.000608356,9.9419e-07,3.0318e-09,0.109181,0.000610353,1.00329e-06,-6.7832e-09,0.109793,0.00061234,9.82936e-07,9.1998e-09,0.110406,0.000614333,1.01054e-06,-7.6642e-09,0.111021,0.000616331,9.87543e-07,6.55579e-09,0.111639,0.000618326,1.00721e-06,-3.65791e-09,0.112258,0.000620329,9.96236e-07,6.25467e-10,0.112879,0.000622324,9.98113e-07,1.15593e-09,0.113503,0.000624323,1.00158e-06,2.20158e-09,0.114128,0.000626333,1.00819e-06,-2.51191e-09,0.114755,0.000628342,1.00065e-06,3.95517e-10,0.115385,0.000630345,1.00184e-06,9.29807e-10,0.116016,0.000632351,1.00463e-06,3.33599e-09,0.116649,0.00063437,1.01463e-06,-6.82329e-09,0.117285,0.000636379,9.94163e-07,9.05595e-09,0.117922,0.000638395,1.02133e-06,-7.04862e-09,0.118562,0.000640416,1.00019e-06,4.23737e-09,0.119203,0.000642429,1.0129e-06,-2.45033e-09,0.119847,0.000644448,1.00555e-06,5.56395e-09,0.120492,0.000646475,1.02224e-06,-4.9043e-09,0.121139,0.000648505,1.00753e-06,-8.47952e-10,0.121789,0.000650518,1.00498e-06,8.29622e-09,0.122441,0.000652553,1.02987e-06,-9.98538e-09,0.123094,0.000654582,9.99914e-07,9.2936e-09,0.12375,0.00065661,1.02779e-06,-4.83707e-09,0.124407,0.000658651,1.01328e-06,2.60411e-09,0.125067,0.000660685,1.0211e-06,-5.57945e-09,0.125729,0.000662711,1.00436e-06,1.22631e-08,0.126392,0.000664756,1.04115e-06,-1.36704e-08,0.127058,0.000666798,1.00014e-06,1.26161e-08,0.127726,0.000668836,1.03798e-06,-6.99155e-09,0.128396,0.000670891,1.01701e-06,4.48836e-10,0.129068,0.000672926,1.01836e-06,5.19606e-09,0.129742,0.000674978,1.03394e-06,-6.3319e-09,0.130418,0.000677027,1.01495e-06,5.2305e-09,0.131096,0.000679073,1.03064e-06,3.11123e-10,0.131776,0.000681135,1.03157e-06,-6.47511e-09,0.132458,0.000683179,1.01215e-06,1.06882e-08,0.133142,0.000685235,1.04421e-06,-6.47519e-09,0.133829,0.000687304,1.02479e-06,3.11237e-10,0.134517,0.000689355,1.02572e-06,5.23035e-09,0.135207,0.000691422,1.04141e-06,-6.3316e-09,0.1359,0.000693486,1.02242e-06,5.19484e-09,0.136594,0.000695546,1.038e-06,4.53497e-10,0.137291,0.000697623,1.03936e-06,-7.00891e-09,0.137989,0.000699681,1.01834e-06,1.2681e-08,0.13869,0.000701756,1.05638e-06,-1.39128e-08,0.139393,0.000703827,1.01464e-06,1.31679e-08,0.140098,0.000705896,1.05414e-06,-8.95659e-09,0.140805,0.000707977,1.02727e-06,7.75742e-09,0.141514,0.000710055,1.05055e-06,-7.17182e-09,0.142225,0.000712135,1.02903e-06,6.02862e-09,0.142938,0.000714211,1.04712e-06,-2.04163e-09,0.143653,0.000716299,1.04099e-06,2.13792e-09,0.144371,0.000718387,1.04741e-06,-6.51009e-09,0.14509,0.000720462,1.02787e-06,9.00123e-09,0.145812,0.000722545,1.05488e-06,3.07523e-10,0.146535,0.000724656,1.0558e-06,-1.02312e-08,0.147261,0.000726737,1.02511e-06,1.0815e-08,0.147989,0.000728819,1.05755e-06,-3.22681e-09,0.148719,0.000730925,1.04787e-06,2.09244e-09,0.14945,0.000733027,1.05415e-06,-5.143e-09,0.150185,0.00073512,1.03872e-06,3.57844e-09,0.150921,0.000737208,1.04946e-06,5.73027e-09,0.151659,0.000739324,1.06665e-06,-1.15983e-08,0.152399,0.000741423,1.03185e-06,1.08605e-08,0.153142,0.000743519,1.06443e-06,-2.04106e-09,0.153886,0.000745642,1.05831e-06,-2.69642e-09,0.154633,0.00074775,1.05022e-06,-2.07425e-09,0.155382,0.000749844,1.044e-06,1.09934e-08,0.156133,0.000751965,1.07698e-06,-1.20972e-08,0.156886,0.000754083,1.04069e-06,7.59288e-09,0.157641,0.000756187,1.06347e-06,-3.37305e-09,0.158398,0.000758304,1.05335e-06,5.89921e-09,0.159158,0.000760428,1.07104e-06,-5.32248e-09,0.159919,0.000762554,1.05508e-06,4.8927e-10,0.160683,0.000764666,1.05654e-06,3.36547e-09,0.161448,0.000766789,1.06664e-06,9.50081e-10,0.162216,0.000768925,1.06949e-06,-7.16568e-09,0.162986,0.000771043,1.04799e-06,1.28114e-08,0.163758,0.000773177,1.08643e-06,-1.42774e-08,0.164533,0.000775307,1.0436e-06,1.44956e-08,0.165309,0.000777438,1.08708e-06,-1.39025e-08,0.166087,0.00077957,1.04538e-06,1.13118e-08,0.166868,0.000781695,1.07931e-06,-1.54224e-09,0.167651,0.000783849,1.07468e-06,-5.14312e-09,0.168436,0.000785983,1.05925e-06,7.21381e-09,0.169223,0.000788123,1.0809e-06,-8.81096e-09,0.170012,0.000790259,1.05446e-06,1.31289e-08,0.170803,0.000792407,1.09385e-06,-1.39022e-08,0.171597,0.000794553,1.05214e-06,1.26775e-08,0.172392,0.000796695,1.09018e-06,-7.00557e-09,0.17319,0.000798855,1.06916e-06,4.43796e-10,0.17399,0.000800994,1.07049e-06,5.23031e-09,0.174792,0.000803151,1.08618e-06,-6.46397e-09,0.175596,0.000805304,1.06679e-06,5.72444e-09,0.176403,0.000807455,1.08396e-06,-1.53254e-09,0.177211,0.000809618,1.07937e-06,4.05673e-10,0.178022,0.000811778,1.08058e-06,-9.01916e-11,0.178835,0.000813939,1.08031e-06,-4.49821e-11,0.17965,0.000816099,1.08018e-06,2.70234e-10,0.180467,0.00081826,1.08099e-06,-1.03603e-09,0.181286,0.000820419,1.07788e-06,3.87392e-09,0.182108,0.000822587,1.0895e-06,4.41522e-10,0.182932,0.000824767,1.09083e-06,-5.63997e-09,0.183758,0.000826932,1.07391e-06,7.21707e-09,0.184586,0.000829101,1.09556e-06,-8.32718e-09,0.185416,0.000831267,1.07058e-06,1.11907e-08,0.186248,0.000833442,1.10415e-06,-6.63336e-09,0.187083,0.00083563,1.08425e-06,4.41484e-10,0.187919,0.0008378,1.08557e-06,4.86754e-09,0.188758,0.000839986,1.10017e-06,-5.01041e-09,0.189599,0.000842171,1.08514e-06,2.72811e-10,0.190443,0.000844342,1.08596e-06,3.91916e-09,0.191288,0.000846526,1.09772e-06,-1.04819e-09,0.192136,0.000848718,1.09457e-06,2.73531e-10,0.192985,0.000850908,1.0954e-06,-4.58916e-11,0.193837,0.000853099,1.09526e-06,-9.01158e-11,0.194692,0.000855289,1.09499e-06,4.06506e-10,0.195548,0.00085748,1.09621e-06,-1.53595e-09,0.196407,0.000859668,1.0916e-06,5.73717e-09,0.197267,0.000861869,1.10881e-06,-6.51164e-09,0.19813,0.000864067,1.08928e-06,5.40831e-09,0.198995,0.000866261,1.1055e-06,-2.20401e-10,0.199863,0.000868472,1.10484e-06,-4.52652e-09,0.200732,0.000870668,1.09126e-06,3.42508e-09,0.201604,0.000872861,1.10153e-06,5.72762e-09,0.202478,0.000875081,1.11872e-06,-1.14344e-08,0.203354,0.000877284,1.08441e-06,1.02076e-08,0.204233,0.000879484,1.11504e-06,4.06355e-10,0.205113,0.000881715,1.11626e-06,-1.18329e-08,0.205996,0.000883912,1.08076e-06,1.71227e-08,0.206881,0.000886125,1.13213e-06,-1.19546e-08,0.207768,0.000888353,1.09626e-06,8.93465e-10,0.208658,0.000890548,1.09894e-06,8.38062e-09,0.209549,0.000892771,1.12408e-06,-4.61353e-09,0.210443,0.000895006,1.11024e-06,-4.82756e-09,0.211339,0.000897212,1.09576e-06,9.02245e-09,0.212238,0.00089943,1.12283e-06,-1.45997e-09,0.213138,0.000901672,1.11845e-06,-3.18255e-09,0.214041,0.000903899,1.1089e-06,-7.11073e-10,0.214946,0.000906115,1.10677e-06,6.02692e-09,0.215853,0.000908346,1.12485e-06,-8.49548e-09,0.216763,0.00091057,1.09936e-06,1.30537e-08,0.217675,0.000912808,1.13852e-06,-1.3917e-08,0.218588,0.000915044,1.09677e-06,1.28121e-08,0.219505,0.000917276,1.13521e-06,-7.5288e-09,0.220423,0.000919523,1.11262e-06,2.40205e-09,0.221344,0.000921756,1.11983e-06,-2.07941e-09,0.222267,0.000923989,1.11359e-06,5.91551e-09,0.223192,0.000926234,1.13134e-06,-6.68149e-09,0.224119,0.000928477,1.11129e-06,5.90929e-09,0.225049,0.000930717,1.12902e-06,-2.05436e-09,0.22598,0.000932969,1.12286e-06,2.30807e-09,0.226915,0.000935222,1.12978e-06,-7.17796e-09,0.227851,0.00093746,1.10825e-06,1.15028e-08,0.228789,0.000939711,1.14276e-06,-9.03083e-09,0.22973,0.000941969,1.11566e-06,9.71932e-09,0.230673,0.00094423,1.14482e-06,-1.49452e-08,0.231619,0.000946474,1.09998e-06,2.02591e-08,0.232566,0.000948735,1.16076e-06,-2.13879e-08,0.233516,0.000950993,1.0966e-06,2.05888e-08,0.234468,0.000953247,1.15837e-06,-1.62642e-08,0.235423,0.000955515,1.10957e-06,1.46658e-08,0.236379,0.000957779,1.15357e-06,-1.25966e-08,0.237338,0.000960048,1.11578e-06,5.91793e-09,0.238299,0.000962297,1.13353e-06,3.82602e-09,0.239263,0.000964576,1.14501e-06,-6.3208e-09,0.240229,0.000966847,1.12605e-06,6.55613e-09,0.241197,0.000969119,1.14572e-06,-5.00268e-09,0.242167,0.000971395,1.13071e-06,-1.44659e-09,0.243139,0.000973652,1.12637e-06,1.07891e-08,0.244114,0.000975937,1.15874e-06,-1.19073e-08,0.245091,0.000978219,1.12302e-06,7.03782e-09,0.246071,0.000980486,1.14413e-06,-1.34276e-09,0.247052,0.00098277,1.1401e-06,-1.66669e-09,0.248036,0.000985046,1.1351e-06,8.00935e-09,0.249022,0.00098734,1.15913e-06,-1.54694e-08,0.250011,0.000989612,1.11272e-06,2.4066e-08,0.251002,0.000991909,1.18492e-06,-2.11901e-08,0.251995,0.000994215,1.12135e-06,1.08973e-09,0.25299,0.000996461,1.12462e-06,1.68311e-08,0.253988,0.000998761,1.17511e-06,-8.8094e-09,0.254987,0.00100109,1.14868e-06,-1.13958e-08,0.25599,0.00100335,1.1145e-06,2.45902e-08,0.256994,0.00100565,1.18827e-06,-2.73603e-08,0.258001,0.00100795,1.10618e-06,2.52464e-08,0.25901,0.00101023,1.18192e-06,-1.40207e-08,0.260021,0.00101256,1.13986e-06,1.03387e-09,0.261035,0.00101484,1.14296e-06,9.8853e-09,0.262051,0.00101715,1.17262e-06,-1.07726e-08,0.263069,0.00101947,1.1403e-06,3.40272e-09,0.26409,0.00102176,1.15051e-06,-2.83827e-09,0.265113,0.00102405,1.142e-06,7.95039e-09,0.266138,0.00102636,1.16585e-06,8.39047e-10,0.267166,0.00102869,1.16836e-06,-1.13066e-08,0.268196,0.00103099,1.13444e-06,1.4585e-08,0.269228,0.00103331,1.1782e-06,-1.72314e-08,0.270262,0.00103561,1.1265e-06,2.45382e-08,0.271299,0.00103794,1.20012e-06,-2.13166e-08,0.272338,0.00104028,1.13617e-06,1.12364e-09,0.273379,0.00104255,1.13954e-06,1.68221e-08,0.274423,0.00104488,1.19001e-06,-8.80736e-09,0.275469,0.00104723,1.16358e-06,-1.13948e-08,0.276518,0.00104953,1.1294e-06,2.45839e-08,0.277568,0.00105186,1.20315e-06,-2.73361e-08,0.278621,0.00105418,1.12114e-06,2.51559e-08,0.279677,0.0010565,1.19661e-06,-1.36832e-08,0.280734,0.00105885,1.15556e-06,-2.25706e-10,0.281794,0.00106116,1.15488e-06,1.45862e-08,0.282857,0.00106352,1.19864e-06,-2.83167e-08,0.283921,0.00106583,1.11369e-06,3.90759e-08,0.284988,0.00106817,1.23092e-06,-3.85801e-08,0.286058,0.00107052,1.11518e-06,2.58375e-08,0.287129,0.00107283,1.19269e-06,-5.16498e-09,0.288203,0.0010752,1.1772e-06,-5.17768e-09,0.28928,0.00107754,1.16167e-06,-3.92671e-09,0.290358,0.00107985,1.14988e-06,2.08846e-08,0.29144,0.00108221,1.21254e-06,-2.00072e-08,0.292523,0.00108458,1.15252e-06,-4.60659e-10,0.293609,0.00108688,1.15114e-06,2.18499e-08,0.294697,0.00108925,1.21669e-06,-2.73343e-08,0.295787,0.0010916,1.13468e-06,2.78826e-08,0.29688,0.00109395,1.21833e-06,-2.45915e-08,0.297975,0.00109632,1.14456e-06,1.08787e-08,0.299073,0.00109864,1.17719e-06,1.08788e-08,0.300172,0.00110102,1.20983e-06,-2.45915e-08,0.301275,0.00110337,1.13605e-06,2.78828e-08,0.302379,0.00110573,1.2197e-06,-2.73348e-08,0.303486,0.00110808,1.1377e-06,2.18518e-08,0.304595,0.00111042,1.20325e-06,-4.67556e-10,0.305707,0.00111283,1.20185e-06,-1.99816e-08,0.306821,0.00111517,1.14191e-06,2.07891e-08,0.307937,0.00111752,1.20427e-06,-3.57026e-09,0.309056,0.00111992,1.19356e-06,-6.50797e-09,0.310177,0.00112228,1.17404e-06,-2.00165e-10,0.3113,0.00112463,1.17344e-06,7.30874e-09,0.312426,0.001127,1.19536e-06,7.67424e-10,0.313554,0.00112939,1.19767e-06,-1.03784e-08,0.314685,0.00113176,1.16653e-06,1.09437e-08,0.315818,0.00113412,1.19936e-06,-3.59406e-09,0.316953,0.00113651,1.18858e-06,3.43251e-09,0.318091,0.0011389,1.19888e-06,-1.0136e-08,0.319231,0.00114127,1.16847e-06,7.30915e-09,0.320374,0.00114363,1.1904e-06,1.07018e-08,0.321518,0.00114604,1.2225e-06,-2.03137e-08,0.322666,0.00114842,1.16156e-06,1.09484e-08,0.323815,0.00115078,1.19441e-06,6.32224e-09,0.324967,0.00115319,1.21337e-06,-6.43509e-09,0.326122,0.00115559,1.19407e-06,-1.03842e-08,0.327278,0.00115795,1.16291e-06,1.81697e-08,0.328438,0.00116033,1.21742e-06,-2.6901e-09,0.329599,0.00116276,1.20935e-06,-7.40939e-09,0.330763,0.00116515,1.18713e-06,2.52533e-09,0.331929,0.00116754,1.1947e-06,-2.69191e-09,0.333098,0.00116992,1.18663e-06,8.24218e-09,0.334269,0.00117232,1.21135e-06,-4.74377e-10,0.335443,0.00117474,1.20993e-06,-6.34471e-09,0.336619,0.00117714,1.1909e-06,-3.94922e-09,0.337797,0.00117951,1.17905e-06,2.21417e-08,0.338978,0.00118193,1.24547e-06,-2.50128e-08,0.340161,0.00118435,1.17043e-06,1.8305e-08,0.341346,0.00118674,1.22535e-06,-1.84048e-08,0.342534,0.00118914,1.17013e-06,2.55121e-08,0.343725,0.00119156,1.24667e-06,-2.40389e-08,0.344917,0.00119398,1.17455e-06,1.10389e-08,0.346113,0.00119636,1.20767e-06,9.68574e-09,0.34731,0.0011988,1.23673e-06,-1.99797e-08,0.34851,0.00120122,1.17679e-06,1.06284e-08,0.349713,0.0012036,1.20867e-06,7.26868e-09,0.350917,0.00120604,1.23048e-06,-9.90072e-09,0.352125,0.00120847,1.20078e-06,2.53177e-09,0.353334,0.00121088,1.20837e-06,-2.26199e-10,0.354546,0.0012133,1.20769e-06,-1.62705e-09,0.355761,0.00121571,1.20281e-06,6.73435e-09,0.356978,0.00121813,1.22302e-06,4.49207e-09,0.358197,0.00122059,1.23649e-06,-2.47027e-08,0.359419,0.00122299,1.16238e-06,3.47142e-08,0.360643,0.00122542,1.26653e-06,-2.47472e-08,0.36187,0.00122788,1.19229e-06,4.66965e-09,0.363099,0.00123028,1.20629e-06,6.06872e-09,0.36433,0.00123271,1.2245e-06,8.57729e-10,0.365564,0.00123516,1.22707e-06,-9.49952e-09,0.366801,0.00123759,1.19858e-06,7.33792e-09,0.36804,0.00124001,1.22059e-06,9.95025e-09,0.369281,0.00124248,1.25044e-06,-1.73366e-08,0.370525,0.00124493,1.19843e-06,-2.08464e-10,0.371771,0.00124732,1.1978e-06,1.81704e-08,0.373019,0.00124977,1.25232e-06,-1.28683e-08,0.37427,0.00125224,1.21371e-06,3.50042e-09,0.375524,0.00125468,1.22421e-06,-1.1335e-09,0.37678,0.00125712,1.22081e-06,1.03345e-09,0.378038,0.00125957,1.22391e-06,-3.00023e-09,0.379299,0.00126201,1.21491e-06,1.09676e-08,0.380562,0.00126447,1.24781e-06,-1.10676e-08,0.381828,0.00126693,1.21461e-06,3.50042e-09,0.383096,0.00126937,1.22511e-06,-2.93403e-09,0.384366,0.00127181,1.21631e-06,8.23574e-09,0.385639,0.00127427,1.24102e-06,-2.06607e-10,0.386915,0.00127675,1.2404e-06,-7.40935e-09,0.388193,0.00127921,1.21817e-06,4.1761e-11,0.389473,0.00128165,1.21829e-06,7.24223e-09,0.390756,0.0012841,1.24002e-06,7.91564e-10,0.392042,0.00128659,1.2424e-06,-1.04086e-08,0.393329,0.00128904,1.21117e-06,1.10405e-08,0.39462,0.0012915,1.24429e-06,-3.951e-09,0.395912,0.00129397,1.23244e-06,4.7634e-09,0.397208,0.00129645,1.24673e-06,-1.51025e-08,0.398505,0.0012989,1.20142e-06,2.58443e-08,0.399805,0.00130138,1.27895e-06,-2.86702e-08,0.401108,0.00130385,1.19294e-06,2.92318e-08,0.402413,0.00130632,1.28064e-06,-2.86524e-08,0.403721,0.0013088,1.19468e-06,2.57731e-08,0.405031,0.00131127,1.272e-06,-1.48355e-08,0.406343,0.00131377,1.2275e-06,3.76652e-09,0.407658,0.00131623,1.23879e-06,-2.30784e-10,0.408976,0.00131871,1.2381e-06,-2.84331e-09,0.410296,0.00132118,1.22957e-06,1.16041e-08,0.411618,0.00132367,1.26438e-06,-1.37708e-08,0.412943,0.00132616,1.22307e-06,1.36768e-08,0.41427,0.00132865,1.2641e-06,-1.1134e-08,0.4156,0.00133114,1.2307e-06,1.05714e-09,0.416933,0.00133361,1.23387e-06,6.90538e-09,0.418267,0.00133609,1.25459e-06,1.12372e-09,0.419605,0.00133861,1.25796e-06,-1.14002e-08,0.420945,0.00134109,1.22376e-06,1.46747e-08,0.422287,0.00134358,1.26778e-06,-1.7496e-08,0.423632,0.00134606,1.21529e-06,2.5507e-08,0.424979,0.00134857,1.29182e-06,-2.49272e-08,0.426329,0.00135108,1.21703e-06,1.45972e-08,0.427681,0.00135356,1.26083e-06,-3.65935e-09,0.429036,0.00135607,1.24985e-06,4.00178e-11,0.430393,0.00135857,1.24997e-06,3.49917e-09,0.431753,0.00136108,1.26047e-06,-1.40366e-08,0.433116,0.00136356,1.21836e-06,2.28448e-08,0.43448,0.00136606,1.28689e-06,-1.77378e-08,0.435848,0.00136858,1.23368e-06,1.83043e-08,0.437218,0.0013711,1.28859e-06,-2.56769e-08,0.43859,0.0013736,1.21156e-06,2.47987e-08,0.439965,0.0013761,1.28595e-06,-1.39133e-08,0.441342,0.00137863,1.24421e-06,1.05202e-09,0.442722,0.00138112,1.24737e-06,9.70507e-09,0.444104,0.00138365,1.27649e-06,-1.00698e-08,0.445489,0.00138617,1.24628e-06,7.72123e-10,0.446877,0.00138867,1.24859e-06,6.98132e-09,0.448267,0.00139118,1.26954e-06,1.10477e-09,0.449659,0.00139373,1.27285e-06,-1.14003e-08,0.451054,0.00139624,1.23865e-06,1.4694e-08,0.452452,0.00139876,1.28273e-06,-1.75734e-08,0.453852,0.00140127,1.23001e-06,2.5797e-08,0.455254,0.00140381,1.3074e-06,-2.60097e-08,0.456659,0.00140635,1.22937e-06,1.86371e-08,0.458067,0.00140886,1.28529e-06,-1.8736e-08,0.459477,0.00141137,1.22908e-06,2.65048e-08,0.46089,0.00141391,1.30859e-06,-2.76784e-08,0.462305,0.00141645,1.22556e-06,2.46043e-08,0.463722,0.00141897,1.29937e-06,-1.11341e-08,0.465143,0.00142154,1.26597e-06,-9.87033e-09,0.466565,0.00142404,1.23636e-06,2.08131e-08,0.467991,0.00142657,1.2988e-06,-1.37773e-08,0.469419,0.00142913,1.25746e-06,4.49378e-09,0.470849,0.00143166,1.27094e-06,-4.19781e-09,0.472282,0.00143419,1.25835e-06,1.22975e-08,0.473717,0.00143674,1.29524e-06,-1.51902e-08,0.475155,0.00143929,1.24967e-06,1.86608e-08,0.476596,0.00144184,1.30566e-06,-2.96506e-08,0.478039,0.00144436,1.2167e-06,4.03368e-08,0.479485,0.00144692,1.33771e-06,-4.22896e-08,0.480933,0.00144947,1.21085e-06,3.94148e-08,0.482384,0.00145201,1.32909e-06,-2.59626e-08,0.483837,0.00145459,1.2512e-06,4.83124e-09,0.485293,0.0014571,1.2657e-06,6.63757e-09,0.486751,0.00145966,1.28561e-06,-1.57911e-09,0.488212,0.00146222,1.28087e-06,-3.21468e-10,0.489676,0.00146478,1.27991e-06,2.86517e-09,0.491142,0.00146735,1.2885e-06,-1.11392e-08,0.49261,0.00146989,1.25508e-06,1.18893e-08,0.494081,0.00147244,1.29075e-06,-6.61574e-09,0.495555,0.001475,1.27091e-06,1.45736e-08,0.497031,0.00147759,1.31463e-06,-2.18759e-08,0.49851,0.00148015,1.249e-06,1.33252e-08,0.499992,0.00148269,1.28897e-06,-1.62277e-09,0.501476,0.00148526,1.28411e-06,-6.83421e-09,0.502962,0.00148781,1.2636e-06,2.89596e-08,0.504451,0.00149042,1.35048e-06,-4.93997e-08,0.505943,0.00149298,1.20228e-06,4.94299e-08,0.507437,0.00149553,1.35057e-06,-2.91107e-08,0.508934,0.00149814,1.26324e-06,7.40848e-09,0.510434,0.00150069,1.28547e-06,-5.23187e-10,0.511936,0.00150326,1.2839e-06,-5.31585e-09,0.51344,0.00150581,1.26795e-06,2.17866e-08,0.514947,0.00150841,1.33331e-06,-2.22257e-08,0.516457,0.00151101,1.26663e-06,7.51178e-09,0.517969,0.00151357,1.28917e-06,-7.82128e-09,0.519484,0.00151613,1.2657e-06,2.37733e-08,0.521002,0.00151873,1.33702e-06,-2.76674e-08,0.522522,0.00152132,1.25402e-06,2.72917e-08,0.524044,0.00152391,1.3359e-06,-2.18949e-08,0.525569,0.00152652,1.27021e-06,6.83372e-10,0.527097,0.00152906,1.27226e-06,1.91613e-08,0.528628,0.00153166,1.32974e-06,-1.77241e-08,0.53016,0.00153427,1.27657e-06,-7.86963e-09,0.531696,0.0015368,1.25296e-06,4.92027e-08,0.533234,0.00153945,1.40057e-06,-6.9732e-08,0.534775,0.00154204,1.19138e-06,5.09114e-08,0.536318,0.00154458,1.34411e-06,-1.4704e-08,0.537864,0.00154722,1.3e-06,7.9048e-09,0.539413,0.00154984,1.32371e-06,-1.69152e-08,0.540964,0.00155244,1.27297e-06,1.51355e-10,0.542517,0.00155499,1.27342e-06,1.63099e-08,0.544074,0.00155758,1.32235e-06,-5.78647e-09,0.545633,0.00156021,1.30499e-06,6.83599e-09,0.547194,0.00156284,1.3255e-06,-2.15575e-08,0.548758,0.00156543,1.26083e-06,1.97892e-08,0.550325,0.00156801,1.32019e-06,2.00525e-09,0.551894,0.00157065,1.32621e-06,-2.78103e-08,0.553466,0.00157322,1.24278e-06,4.96314e-08,0.555041,0.00157586,1.39167e-06,-5.1506e-08,0.556618,0.00157849,1.23716e-06,3.71835e-08,0.558198,0.00158107,1.34871e-06,-3.76233e-08,0.55978,0.00158366,1.23584e-06,5.37052e-08,0.561365,0.00158629,1.39695e-06,-5.79884e-08,0.562953,0.00158891,1.22299e-06,5.90392e-08,0.564543,0.00159153,1.4001e-06,-5.89592e-08,0.566136,0.00159416,1.22323e-06,5.7588e-08,0.567731,0.00159678,1.39599e-06,-5.21835e-08,0.569329,0.00159941,1.23944e-06,3.19369e-08,0.57093,0.00160199,1.33525e-06,-1.59594e-08,0.572533,0.00160461,1.28737e-06,3.19006e-08,0.574139,0.00160728,1.38307e-06,-5.20383e-08,0.575748,0.00160989,1.22696e-06,5.70431e-08,0.577359,0.00161251,1.39809e-06,-5.69247e-08,0.578973,0.00161514,1.22731e-06,5.14463e-08,0.580589,0.00161775,1.38165e-06,-2.9651e-08,0.582208,0.00162042,1.2927e-06,7.55339e-09,0.58383,0.00162303,1.31536e-06,-5.62636e-10,0.585455,0.00162566,1.31367e-06,-5.30281e-09,0.587081,0.00162827,1.29776e-06,2.17738e-08,0.588711,0.00163093,1.36309e-06,-2.21875e-08,0.590343,0.00163359,1.29652e-06,7.37164e-09,0.591978,0.00163621,1.31864e-06,-7.29907e-09,0.593616,0.00163882,1.29674e-06,2.18247e-08,0.595256,0.00164148,1.36221e-06,-2.03952e-08,0.596899,0.00164414,1.30103e-06,1.51241e-10,0.598544,0.00164675,1.30148e-06,1.97902e-08,0.600192,0.00164941,1.36085e-06,-1.97074e-08,0.601843,0.00165207,1.30173e-06,-5.65175e-10,0.603496,0.00165467,1.30004e-06,2.1968e-08,0.605152,0.00165734,1.36594e-06,-2.77024e-08,0.606811,0.00165999,1.28283e-06,2.92369e-08,0.608472,0.00166264,1.37054e-06,-2.96407e-08,0.610136,0.00166529,1.28162e-06,2.97215e-08,0.611803,0.00166795,1.37079e-06,-2.96408e-08,0.613472,0.0016706,1.28186e-06,2.92371e-08,0.615144,0.00167325,1.36957e-06,-2.77031e-08,0.616819,0.00167591,1.28647e-06,2.19708e-08,0.618496,0.00167855,1.35238e-06,-5.75407e-10,0.620176,0.00168125,1.35065e-06,-1.9669e-08,0.621858,0.00168389,1.29164e-06,1.96468e-08,0.623544,0.00168653,1.35058e-06,6.86403e-10,0.625232,0.00168924,1.35264e-06,-2.23924e-08,0.626922,0.00169187,1.28547e-06,2.92788e-08,0.628615,0.00169453,1.3733e-06,-3.51181e-08,0.630311,0.00169717,1.26795e-06,5.15889e-08,0.63201,0.00169987,1.42272e-06,-5.2028e-08,0.633711,0.00170255,1.26663e-06,3.73139e-08,0.635415,0.0017052,1.37857e-06,-3.76227e-08,0.637121,0.00170784,1.2657e-06,5.35722e-08,0.63883,0.00171054,1.42642e-06,-5.74567e-08,0.640542,0.00171322,1.25405e-06,5.70456e-08,0.642257,0.0017159,1.42519e-06,-5.15163e-08,0.643974,0.00171859,1.27064e-06,2.98103e-08,0.645694,0.00172122,1.36007e-06,-8.12016e-09,0.647417,0.00172392,1.33571e-06,2.67039e-09,0.649142,0.0017266,1.34372e-06,-2.56152e-09,0.65087,0.00172928,1.33604e-06,7.57571e-09,0.6526,0.00173197,1.35876e-06,-2.77413e-08,0.654334,0.00173461,1.27554e-06,4.3785e-08,0.65607,0.00173729,1.40689e-06,-2.81896e-08,0.657808,0.00174002,1.32233e-06,9.36893e-09,0.65955,0.00174269,1.35043e-06,-9.28617e-09,0.661294,0.00174536,1.32257e-06,2.77757e-08,0.66304,0.00174809,1.4059e-06,-4.2212e-08,0.66479,0.00175078,1.27926e-06,2.1863e-08,0.666542,0.0017534,1.34485e-06,1.43648e-08,0.668297,0.00175613,1.38795e-06,-1.97177e-08,0.670054,0.00175885,1.3288e-06,4.90115e-09,0.671814,0.00176152,1.3435e-06,1.13232e-10,0.673577,0.00176421,1.34384e-06,-5.3542e-09,0.675343,0.00176688,1.32778e-06,2.13035e-08,0.677111,0.0017696,1.39169e-06,-2.02553e-08,0.678882,0.00177232,1.33092e-06,1.13005e-10,0.680656,0.00177499,1.33126e-06,1.98031e-08,0.682432,0.00177771,1.39067e-06,-1.97211e-08,0.684211,0.00178043,1.33151e-06,-5.2349e-10,0.685993,0.00178309,1.32994e-06,2.18151e-08,0.687777,0.00178582,1.39538e-06,-2.71325e-08,0.689564,0.00178853,1.31398e-06,2.71101e-08,0.691354,0.00179124,1.39531e-06,-2.17035e-08,0.693147,0.00179396,1.3302e-06,9.92865e-11,0.694942,0.00179662,1.3305e-06,2.13063e-08,0.69674,0.00179935,1.39442e-06,-2.57198e-08,0.698541,0.00180206,1.31726e-06,2.19682e-08,0.700344,0.00180476,1.38317e-06,-2.54852e-09,0.70215,0.00180752,1.37552e-06,-1.17741e-08,0.703959,0.00181023,1.3402e-06,-9.95999e-09,0.705771,0.00181288,1.31032e-06,5.16141e-08,0.707585,0.00181566,1.46516e-06,-7.72869e-08,0.709402,0.00181836,1.2333e-06,7.87197e-08,0.711222,0.00182106,1.46946e-06,-5.87781e-08,0.713044,0.00182382,1.29312e-06,3.71834e-08,0.714869,0.00182652,1.40467e-06,-3.03511e-08,0.716697,0.00182924,1.31362e-06,2.46161e-08,0.718528,0.00183194,1.38747e-06,-8.5087e-09,0.720361,0.00183469,1.36194e-06,9.41892e-09,0.722197,0.00183744,1.3902e-06,-2.91671e-08,0.724036,0.00184014,1.3027e-06,4.76448e-08,0.725878,0.00184288,1.44563e-06,-4.22028e-08,0.727722,0.00184565,1.31902e-06,1.95682e-09,0.729569,0.00184829,1.3249e-06,3.43754e-08,0.731419,0.00185104,1.42802e-06,-2.0249e-08,0.733271,0.00185384,1.36727e-06,-1.29838e-08,0.735126,0.00185654,1.32832e-06,1.25794e-08,0.736984,0.00185923,1.36606e-06,2.22711e-08,0.738845,0.00186203,1.43287e-06,-4.20594e-08,0.740708,0.00186477,1.3067e-06,2.67571e-08,0.742574,0.00186746,1.38697e-06,-5.36424e-09,0.744443,0.00187022,1.37087e-06,-5.30023e-09,0.746315,0.00187295,1.35497e-06,2.65653e-08,0.748189,0.00187574,1.43467e-06,-4.13564e-08,0.750066,0.00187848,1.3106e-06,1.9651e-08,0.751946,0.00188116,1.36955e-06,2.23572e-08,0.753828,0.00188397,1.43663e-06,-4.9475e-08,0.755714,0.00188669,1.2882e-06,5.63335e-08,0.757602,0.00188944,1.4572e-06,-5.66499e-08,0.759493,0.00189218,1.28725e-06,5.10567e-08,0.761386,0.00189491,1.44042e-06,-2.83677e-08,0.763283,0.00189771,1.35532e-06,2.80962e-09,0.765182,0.00190042,1.36375e-06,1.71293e-08,0.767083,0.0019032,1.41513e-06,-1.17221e-08,0.768988,0.001906,1.37997e-06,-2.98453e-08,0.770895,0.00190867,1.29043e-06,7.14987e-08,0.772805,0.00191146,1.50493e-06,-7.73354e-08,0.774718,0.00191424,1.27292e-06,5.90292e-08,0.776634,0.00191697,1.45001e-06,-3.9572e-08,0.778552,0.00191975,1.33129e-06,3.9654e-08,0.780473,0.00192253,1.45026e-06,-5.94395e-08,0.782397,0.00192525,1.27194e-06,7.88945e-08,0.784324,0.00192803,1.50862e-06,-7.73249e-08,0.786253,0.00193082,1.27665e-06,5.15913e-08,0.788185,0.00193352,1.43142e-06,-9.83099e-09,0.79012,0.00193636,1.40193e-06,-1.22672e-08,0.792058,0.00193912,1.36513e-06,-7.05275e-10,0.793999,0.00194185,1.36301e-06,1.50883e-08,0.795942,0.00194462,1.40828e-06,-4.33147e-11,0.797888,0.00194744,1.40815e-06,-1.49151e-08,0.799837,0.00195021,1.3634e-06,9.93244e-11,0.801788,0.00195294,1.3637e-06,1.45179e-08,0.803743,0.00195571,1.40725e-06,1.43363e-09,0.8057,0.00195853,1.41155e-06,-2.02525e-08,0.80766,0.00196129,1.35079e-06,1.99718e-08,0.809622,0.00196405,1.41071e-06,-3.01649e-11,0.811588,0.00196687,1.41062e-06,-1.9851e-08,0.813556,0.00196964,1.35107e-06,1.98296e-08,0.815527,0.0019724,1.41056e-06,1.37485e-10,0.817501,0.00197522,1.41097e-06,-2.03796e-08,0.819477,0.00197798,1.34983e-06,2.17763e-08,0.821457,0.00198074,1.41516e-06,-7.12085e-09,0.823439,0.00198355,1.3938e-06,6.70707e-09,0.825424,0.00198636,1.41392e-06,-1.97074e-08,0.827412,0.00198913,1.35479e-06,1.25179e-08,0.829402,0.00199188,1.39235e-06,2.92405e-08,0.831396,0.00199475,1.48007e-06,-6.98755e-08,0.833392,0.0019975,1.27044e-06,7.14477e-08,0.835391,0.00200026,1.48479e-06,-3.71014e-08,0.837392,0.00200311,1.37348e-06,1.73533e-08,0.839397,0.00200591,1.42554e-06,-3.23118e-08,0.841404,0.00200867,1.32861e-06,5.2289e-08,0.843414,0.00201148,1.48547e-06,-5.76348e-08,0.845427,0.00201428,1.31257e-06,5.9041e-08,0.847443,0.00201708,1.48969e-06,-5.93197e-08,0.849461,0.00201988,1.31173e-06,5.90289e-08,0.851482,0.00202268,1.48882e-06,-5.75864e-08,0.853507,0.00202549,1.31606e-06,5.21075e-08,0.855533,0.00202828,1.47238e-06,-3.16344e-08,0.857563,0.00203113,1.37748e-06,1.48257e-08,0.859596,0.00203393,1.42196e-06,-2.76684e-08,0.861631,0.00203669,1.33895e-06,3.62433e-08,0.863669,0.00203947,1.44768e-06,1.90463e-09,0.86571,0.00204237,1.45339e-06,-4.38617e-08,0.867754,0.00204515,1.32181e-06,5.43328e-08,0.8698,0.00204796,1.48481e-06,-5.42603e-08,0.87185,0.00205076,1.32203e-06,4.34989e-08,0.873902,0.00205354,1.45252e-06,-5.26029e-10,0.875957,0.00205644,1.45095e-06,-4.13949e-08,0.878015,0.00205922,1.32676e-06,4.68962e-08,0.880075,0.00206201,1.46745e-06,-2.69807e-08,0.882139,0.00206487,1.38651e-06,1.42181e-09,0.884205,0.00206764,1.39077e-06,2.12935e-08,0.886274,0.00207049,1.45465e-06,-2.69912e-08,0.888346,0.00207332,1.37368e-06,2.70664e-08,0.890421,0.00207615,1.45488e-06,-2.16698e-08,0.892498,0.00207899,1.38987e-06,8.14756e-12,0.894579,0.00208177,1.38989e-06,2.16371e-08,0.896662,0.00208462,1.45481e-06,-2.6952e-08,0.898748,0.00208744,1.37395e-06,2.65663e-08,0.900837,0.00209027,1.45365e-06,-1.97084e-08,0.902928,0.00209312,1.39452e-06,-7.33731e-09,0.905023,0.00209589,1.37251e-06,4.90578e-08,0.90712,0.00209878,1.51968e-06,-6.96845e-08,0.90922,0.00210161,1.31063e-06,5.08664e-08,0.911323,0.00210438,1.46323e-06,-1.45717e-08,0.913429,0.00210727,1.41952e-06,7.42038e-09,0.915538,0.00211013,1.44178e-06,-1.51097e-08,0.917649,0.00211297,1.39645e-06,-6.58618e-09,0.919764,0.00211574,1.37669e-06,4.14545e-08,0.921881,0.00211862,1.50105e-06,-4.00222e-08,0.924001,0.0021215,1.38099e-06,-5.7518e-10,0.926124,0.00212426,1.37926e-06,4.23229e-08,0.92825,0.00212714,1.50623e-06,-4.9507e-08,0.930378,0.00213001,1.35771e-06,3.64958e-08,0.93251,0.00213283,1.4672e-06,-3.68713e-08,0.934644,0.00213566,1.35658e-06,5.13848e-08,0.936781,0.00213852,1.51074e-06,-4.94585e-08,0.938921,0.0021414,1.36236e-06,2.72399e-08,0.941064,0.0021442,1.44408e-06,1.0372e-10,0.943209,0.00214709,1.44439e-06,-2.76547e-08,0.945358,0.0021499,1.36143e-06,5.09106e-08,0.947509,0.00215277,1.51416e-06,-5.67784e-08,0.949663,0.00215563,1.34382e-06,5.69935e-08,0.95182,0.00215849,1.5148e-06,-5.19861e-08,0.95398,0.00216136,1.35885e-06,3.17417e-08,0.956143,0.00216418,1.45407e-06,-1.53758e-08,0.958309,0.00216704,1.40794e-06,2.97615e-08,0.960477,0.00216994,1.49723e-06,-4.40657e-08,0.962649,0.00217281,1.36503e-06,2.72919e-08,0.964823,0.00217562,1.44691e-06,-5.49729e-09,0.967,0.0021785,1.43041e-06,-5.30273e-09,0.96918,0.00218134,1.41451e-06,2.67084e-08,0.971363,0.00218425,1.49463e-06,-4.19265e-08,0.973548,0.00218711,1.36885e-06,2.17881e-08,0.975737,0.00218992,1.43422e-06,1.43789e-08,0.977928,0.00219283,1.47735e-06,-1.96989e-08,0.980122,0.00219572,1.41826e-06,4.81221e-09,0.98232,0.00219857,1.43269e-06,4.50048e-10,0.98452,0.00220144,1.43404e-06,-6.61237e-09,0.986722,0.00220429,1.41421e-06,2.59993e-08,0.988928,0.0022072,1.4922e-06,-3.77803e-08,0.991137,0.00221007,1.37886e-06,5.9127e-09,0.993348,0.00221284,1.3966e-06,1.33339e-07,0.995563,0.00221604,1.79662e-06,-5.98872e-07,0.99778,0.00222015,0.,0.}; + + template + __device__ __forceinline__ void RGB2LabConvert_f(const T& src, D& dst) + { + const float _1_3 = 1.0f / 3.0f; + const float _a = 16.0f / 116.0f; + + float B = blueIdx == 0 ? src.x : src.z; + float G = src.y; + float R = blueIdx == 0 ? src.z : src.x; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + } + + float X = B * 0.189828f + G * 0.376219f + R * 0.433953f; + float Y = B * 0.072169f + G * 0.715160f + R * 0.212671f; + float Z = B * 0.872766f + G * 0.109477f + R * 0.017758f; + + float FX = X > 0.008856f ? ::powf(X, _1_3) : (7.787f * X + _a); + float FY = Y > 0.008856f ? ::powf(Y, _1_3) : (7.787f * Y + _a); + float FZ = Z > 0.008856f ? ::powf(Z, _1_3) : (7.787f * Z + _a); + + float L = Y > 0.008856f ? (116.f * FY - 16.f) : (903.3f * Y); + float a = 500.f * (FX - FY); + float b = 200.f * (FY - FZ); + + dst.x = L; + dst.y = a; + dst.z = b; + } + + template struct RGB2Lab; + template + struct RGB2Lab + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + RGB2LabConvert_b(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Lab() {} + __host__ __device__ __forceinline__ RGB2Lab(const RGB2Lab&) {} + }; + template + struct RGB2Lab + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + RGB2LabConvert_f(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Lab() {} + __host__ __device__ __forceinline__ RGB2Lab(const RGB2Lab&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2Lab functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + __constant__ float c_sRGBInvGammaTab[] = {0,0.0126255,0.,-8.33961e-06,0.0126172,0.0126005,-2.50188e-05,4.1698e-05,0.0252344,0.0126756,0.000100075,-0.000158451,0.0378516,0.0124004,-0.000375277,-0.000207393,0.0496693,0.0110276,-0.000997456,0.00016837,0.0598678,0.00953783,-0.000492346,2.07235e-05,0.068934,0.00861531,-0.000430176,3.62876e-05,0.0771554,0.00786382,-0.000321313,1.87625e-05,0.0847167,0.00727748,-0.000265025,1.53594e-05,0.0917445,0.00679351,-0.000218947,1.10545e-05,0.0983301,0.00638877,-0.000185784,8.66984e-06,0.104542,0.00604322,-0.000159774,6.82996e-06,0.110432,0.00574416,-0.000139284,5.51008e-06,0.116042,0.00548212,-0.000122754,4.52322e-06,0.121406,0.00525018,-0.000109184,3.75557e-06,0.126551,0.00504308,-9.79177e-05,3.17134e-06,0.131499,0.00485676,-8.84037e-05,2.68469e-06,0.13627,0.004688,-8.03496e-05,2.31725e-06,0.14088,0.00453426,-7.33978e-05,2.00868e-06,0.145343,0.00439349,-6.73718e-05,1.74775e-06,0.149671,0.00426399,-6.21286e-05,1.53547e-06,0.153875,0.00414434,-5.75222e-05,1.364e-06,0.157963,0.00403338,-5.34301e-05,1.20416e-06,0.161944,0.00393014,-4.98177e-05,1.09114e-06,0.165825,0.00383377,-4.65443e-05,9.57987e-07,0.169613,0.00374356,-4.36703e-05,8.88359e-07,0.173314,0.00365888,-4.10052e-05,7.7849e-07,0.176933,0.00357921,-3.86697e-05,7.36254e-07,0.180474,0.00350408,-3.6461e-05,6.42534e-07,0.183942,0.00343308,-3.45334e-05,6.12614e-07,0.187342,0.00336586,-3.26955e-05,5.42894e-07,0.190675,0.00330209,-3.10669e-05,5.08967e-07,0.193947,0.00324149,-2.954e-05,4.75977e-07,0.197159,0.00318383,-2.8112e-05,4.18343e-07,0.200315,0.00312887,-2.6857e-05,4.13651e-07,0.203418,0.00307639,-2.5616e-05,3.70847e-07,0.206469,0.00302627,-2.45035e-05,3.3813e-07,0.209471,0.00297828,-2.34891e-05,3.32999e-07,0.212426,0.0029323,-2.24901e-05,2.96826e-07,0.215336,0.00288821,-2.15996e-05,2.82736e-07,0.218203,0.00284586,-2.07514e-05,2.70961e-07,0.221029,0.00280517,-1.99385e-05,2.42744e-07,0.223814,0.00276602,-1.92103e-05,2.33277e-07,0.226561,0.0027283,-1.85105e-05,2.2486e-07,0.229271,0.00269195,-1.78359e-05,2.08383e-07,0.231945,0.00265691,-1.72108e-05,1.93305e-07,0.234585,0.00262307,-1.66308e-05,1.80687e-07,0.237192,0.00259035,-1.60888e-05,1.86632e-07,0.239766,0.00255873,-1.55289e-05,1.60569e-07,0.24231,0.00252815,-1.50472e-05,1.54566e-07,0.244823,0.00249852,-1.45835e-05,1.59939e-07,0.247307,0.00246983,-1.41037e-05,1.29549e-07,0.249763,0.00244202,-1.3715e-05,1.41429e-07,0.252191,0.00241501,-1.32907e-05,1.39198e-07,0.254593,0.00238885,-1.28731e-05,1.06444e-07,0.256969,0.00236342,-1.25538e-05,1.2048e-07,0.25932,0.00233867,-1.21924e-05,1.26892e-07,0.261647,0.00231467,-1.18117e-05,8.72084e-08,0.26395,0.00229131,-1.15501e-05,1.20323e-07,0.26623,0.00226857,-1.11891e-05,8.71514e-08,0.268487,0.00224645,-1.09276e-05,9.73165e-08,0.270723,0.00222489,-1.06357e-05,8.98259e-08,0.272937,0.00220389,-1.03662e-05,7.98218e-08,0.275131,0.00218339,-1.01267e-05,9.75254e-08,0.277304,0.00216343,-9.83416e-06,6.65195e-08,0.279458,0.00214396,-9.63461e-06,8.34313e-08,0.281592,0.00212494,-9.38431e-06,7.65919e-08,0.283708,0.00210641,-9.15454e-06,5.7236e-08,0.285805,0.00208827,-8.98283e-06,8.18939e-08,0.287885,0.00207055,-8.73715e-06,6.2224e-08,0.289946,0.00205326,-8.55047e-06,5.66388e-08,0.291991,0.00203633,-8.38056e-06,6.88491e-08,0.294019,0.00201978,-8.17401e-06,5.53955e-08,0.296031,0.00200359,-8.00782e-06,6.71971e-08,0.298027,0.00198778,-7.80623e-06,3.34439e-08,0.300007,0.00197227,-7.7059e-06,6.7248e-08,0.301971,0.00195706,-7.50416e-06,5.51915e-08,0.303921,0.00194221,-7.33858e-06,3.98124e-08,0.305856,0.00192766,-7.21915e-06,5.37795e-08,0.307776,0.00191338,-7.05781e-06,4.30919e-08,0.309683,0.00189939,-6.92853e-06,4.20744e-08,0.311575,0.00188566,-6.80231e-06,5.68321e-08,0.313454,0.00187223,-6.63181e-06,2.86195e-08,0.31532,0.00185905,-6.54595e-06,3.73075e-08,0.317172,0.00184607,-6.43403e-06,6.05684e-08,0.319012,0.00183338,-6.25233e-06,1.84426e-08,0.320839,0.00182094,-6.197e-06,4.44757e-08,0.322654,0.00180867,-6.06357e-06,4.20729e-08,0.324456,0.00179667,-5.93735e-06,2.56511e-08,0.326247,0.00178488,-5.8604e-06,3.41368e-08,0.328026,0.00177326,-5.75799e-06,4.64177e-08,0.329794,0.00176188,-5.61874e-06,1.86107e-08,0.33155,0.0017507,-5.5629e-06,2.81511e-08,0.333295,0.00173966,-5.47845e-06,4.75987e-08,0.335029,0.00172884,-5.33565e-06,1.98726e-08,0.336753,0.00171823,-5.27604e-06,2.19226e-08,0.338466,0.00170775,-5.21027e-06,4.14483e-08,0.340169,0.00169745,-5.08592e-06,2.09017e-08,0.341861,0.00168734,-5.02322e-06,2.39561e-08,0.343543,0.00167737,-4.95135e-06,3.22852e-08,0.345216,0.00166756,-4.85449e-06,2.57173e-08,0.346878,0.00165793,-4.77734e-06,1.38569e-08,0.348532,0.00164841,-4.73577e-06,3.80634e-08,0.350175,0.00163906,-4.62158e-06,1.27043e-08,0.35181,0.00162985,-4.58347e-06,3.03279e-08,0.353435,0.00162078,-4.49249e-06,1.49961e-08,0.355051,0.00161184,-4.4475e-06,2.88977e-08,0.356659,0.00160303,-4.3608e-06,1.84241e-08,0.358257,0.00159436,-4.30553e-06,1.6616e-08,0.359848,0.0015858,-4.25568e-06,3.43218e-08,0.361429,0.00157739,-4.15272e-06,-4.89172e-09,0.363002,0.00156907,-4.16739e-06,4.48498e-08,0.364567,0.00156087,-4.03284e-06,4.30676e-09,0.366124,0.00155282,-4.01992e-06,2.73303e-08,0.367673,0.00154486,-3.93793e-06,5.58036e-09,0.369214,0.001537,-3.92119e-06,3.97554e-08,0.370747,0.00152928,-3.80193e-06,-1.55904e-08,0.372272,0.00152163,-3.8487e-06,5.24081e-08,0.37379,0.00151409,-3.69147e-06,-1.52272e-08,0.375301,0.00150666,-3.73715e-06,3.83028e-08,0.376804,0.0014993,-3.62225e-06,1.10278e-08,0.378299,0.00149209,-3.58916e-06,6.99326e-09,0.379788,0.00148493,-3.56818e-06,2.06038e-08,0.381269,0.00147786,-3.50637e-06,2.98009e-08,0.382744,0.00147093,-3.41697e-06,-2.05978e-08,0.384211,0.00146404,-3.47876e-06,5.25899e-08,0.385672,0.00145724,-3.32099e-06,-1.09471e-08,0.387126,0.00145056,-3.35383e-06,2.10009e-08,0.388573,0.00144392,-3.29083e-06,1.63501e-08,0.390014,0.00143739,-3.24178e-06,3.00641e-09,0.391448,0.00143091,-3.23276e-06,3.12282e-08,0.392875,0.00142454,-3.13908e-06,-8.70932e-09,0.394297,0.00141824,-3.16521e-06,3.34114e-08,0.395712,0.00141201,-3.06497e-06,-5.72754e-09,0.397121,0.00140586,-3.08215e-06,1.9301e-08,0.398524,0.00139975,-3.02425e-06,1.7931e-08,0.39992,0.00139376,-2.97046e-06,-1.61822e-09,0.401311,0.00138781,-2.97531e-06,1.83442e-08,0.402696,0.00138192,-2.92028e-06,1.76485e-08,0.404075,0.00137613,-2.86733e-06,4.68617e-10,0.405448,0.00137039,-2.86593e-06,1.02794e-08,0.406816,0.00136469,-2.83509e-06,1.80179e-08,0.408178,0.00135908,-2.78104e-06,7.05594e-09,0.409534,0.00135354,-2.75987e-06,1.33633e-08,0.410885,0.00134806,-2.71978e-06,-9.04568e-10,0.41223,0.00134261,-2.72249e-06,2.0057e-08,0.41357,0.00133723,-2.66232e-06,1.00841e-08,0.414905,0.00133194,-2.63207e-06,-7.88835e-10,0.416234,0.00132667,-2.63444e-06,2.28734e-08,0.417558,0.00132147,-2.56582e-06,-1.29785e-09,0.418877,0.00131633,-2.56971e-06,1.21205e-08,0.420191,0.00131123,-2.53335e-06,1.24202e-08,0.421499,0.0013062,-2.49609e-06,-2.19681e-09,0.422803,0.0013012,-2.50268e-06,2.61696e-08,0.424102,0.00129628,-2.42417e-06,-1.30747e-08,0.425396,0.00129139,-2.46339e-06,2.6129e-08,0.426685,0.00128654,-2.38501e-06,-2.03454e-09,0.427969,0.00128176,-2.39111e-06,1.18115e-08,0.429248,0.00127702,-2.35567e-06,1.43932e-08,0.430523,0.00127235,-2.31249e-06,-9.77965e-09,0.431793,0.00126769,-2.34183e-06,2.47253e-08,0.433058,0.00126308,-2.26766e-06,2.85278e-10,0.434319,0.00125855,-2.2668e-06,3.93614e-09,0.435575,0.00125403,-2.25499e-06,1.37722e-08,0.436827,0.00124956,-2.21368e-06,5.79803e-10,0.438074,0.00124513,-2.21194e-06,1.37112e-08,0.439317,0.00124075,-2.1708e-06,4.17973e-09,0.440556,0.00123642,-2.15826e-06,-6.27703e-10,0.44179,0.0012321,-2.16015e-06,2.81332e-08,0.44302,0.00122787,-2.07575e-06,-2.24985e-08,0.444246,0.00122365,-2.14324e-06,3.20586e-08,0.445467,0.00121946,-2.04707e-06,-1.6329e-08,0.446685,0.00121532,-2.09605e-06,3.32573e-08,0.447898,0.00121122,-1.99628e-06,-2.72927e-08,0.449107,0.00120715,-2.07816e-06,4.6111e-08,0.450312,0.00120313,-1.93983e-06,-3.79416e-08,0.451514,0.00119914,-2.05365e-06,4.60507e-08,0.452711,0.00119517,-1.9155e-06,-2.7052e-08,0.453904,0.00119126,-1.99666e-06,3.23551e-08,0.455093,0.00118736,-1.89959e-06,-1.29613e-08,0.456279,0.00118352,-1.93848e-06,1.94905e-08,0.45746,0.0011797,-1.88e-06,-5.39588e-09,0.458638,0.00117593,-1.89619e-06,2.09282e-09,0.459812,0.00117214,-1.88991e-06,2.68267e-08,0.460982,0.00116844,-1.80943e-06,-1.99925e-08,0.462149,0.00116476,-1.86941e-06,2.3341e-08,0.463312,0.00116109,-1.79939e-06,-1.37674e-08,0.464471,0.00115745,-1.84069e-06,3.17287e-08,0.465627,0.00115387,-1.7455e-06,-2.37407e-08,0.466779,0.00115031,-1.81673e-06,3.34315e-08,0.467927,0.00114677,-1.71643e-06,-2.05786e-08,0.469073,0.00114328,-1.77817e-06,1.90802e-08,0.470214,0.00113978,-1.72093e-06,3.86247e-09,0.471352,0.00113635,-1.70934e-06,-4.72759e-09,0.472487,0.00113292,-1.72352e-06,1.50478e-08,0.473618,0.00112951,-1.67838e-06,4.14108e-09,0.474746,0.00112617,-1.66595e-06,-1.80986e-09,0.47587,0.00112283,-1.67138e-06,3.09816e-09,0.476991,0.0011195,-1.66209e-06,1.92198e-08,0.478109,0.00111623,-1.60443e-06,-2.03726e-08,0.479224,0.00111296,-1.66555e-06,3.2468e-08,0.480335,0.00110973,-1.56814e-06,-2.00922e-08,0.481443,0.00110653,-1.62842e-06,1.80983e-08,0.482548,0.00110333,-1.57413e-06,7.30362e-09,0.48365,0.0011002,-1.55221e-06,-1.75107e-08,0.484749,0.00109705,-1.60475e-06,3.29373e-08,0.485844,0.00109393,-1.50594e-06,-2.48315e-08,0.486937,0.00109085,-1.58043e-06,3.65865e-08,0.488026,0.0010878,-1.47067e-06,-3.21078e-08,0.489112,0.00108476,-1.56699e-06,3.22397e-08,0.490195,0.00108172,-1.47027e-06,-7.44391e-09,0.491276,0.00107876,-1.49261e-06,-2.46428e-09,0.492353,0.00107577,-1.5e-06,1.73011e-08,0.493427,0.00107282,-1.4481e-06,-7.13552e-09,0.494499,0.0010699,-1.4695e-06,1.1241e-08,0.495567,0.001067,-1.43578e-06,-8.02637e-09,0.496633,0.0010641,-1.45986e-06,2.08645e-08,0.497695,0.00106124,-1.39726e-06,-1.58271e-08,0.498755,0.0010584,-1.44475e-06,1.26415e-08,0.499812,0.00105555,-1.40682e-06,2.48655e-08,0.500866,0.00105281,-1.33222e-06,-5.24988e-08,0.501918,0.00104999,-1.48972e-06,6.59206e-08,0.502966,0.00104721,-1.29196e-06,-3.237e-08,0.504012,0.00104453,-1.38907e-06,3.95479e-09,0.505055,0.00104176,-1.3772e-06,1.65509e-08,0.506096,0.00103905,-1.32755e-06,-1.05539e-08,0.507133,0.00103637,-1.35921e-06,2.56648e-08,0.508168,0.00103373,-1.28222e-06,-3.25007e-08,0.509201,0.00103106,-1.37972e-06,4.47336e-08,0.51023,0.00102844,-1.24552e-06,-2.72245e-08,0.511258,0.00102587,-1.32719e-06,4.55952e-09,0.512282,0.00102323,-1.31352e-06,8.98645e-09,0.513304,0.00102063,-1.28656e-06,1.90992e-08,0.514323,0.00101811,-1.22926e-06,-2.57786e-08,0.51534,0.00101557,-1.30659e-06,2.44104e-08,0.516355,0.00101303,-1.23336e-06,-1.22581e-08,0.517366,0.00101053,-1.27014e-06,2.4622e-08,0.518376,0.00100806,-1.19627e-06,-2.66253e-08,0.519383,0.00100559,-1.27615e-06,2.22744e-08,0.520387,0.00100311,-1.20932e-06,-2.8679e-09,0.521389,0.00100068,-1.21793e-06,-1.08029e-08,0.522388,0.000998211,-1.25034e-06,4.60795e-08,0.523385,0.000995849,-1.1121e-06,-5.4306e-08,0.52438,0.000993462,-1.27502e-06,5.19354e-08,0.525372,0.000991067,-1.11921e-06,-3.42262e-08,0.526362,0.000988726,-1.22189e-06,2.53646e-08,0.52735,0.000986359,-1.14579e-06,-7.62782e-09,0.528335,0.000984044,-1.16868e-06,5.14668e-09,0.529318,0.000981722,-1.15324e-06,-1.29589e-08,0.530298,0.000979377,-1.19211e-06,4.66888e-08,0.531276,0.000977133,-1.05205e-06,-5.45868e-08,0.532252,0.000974865,-1.21581e-06,5.24495e-08,0.533226,0.000972591,-1.05846e-06,-3.60019e-08,0.534198,0.000970366,-1.16647e-06,3.19537e-08,0.535167,0.000968129,-1.07061e-06,-3.2208e-08,0.536134,0.000965891,-1.16723e-06,3.72738e-08,0.537099,0.000963668,-1.05541e-06,2.32205e-09,0.538061,0.000961564,-1.04844e-06,-4.65618e-08,0.539022,0.000959328,-1.18813e-06,6.47159e-08,0.53998,0.000957146,-9.93979e-07,-3.3488e-08,0.540936,0.000955057,-1.09444e-06,9.63166e-09,0.54189,0.000952897,-1.06555e-06,-5.03871e-09,0.542842,0.000950751,-1.08066e-06,1.05232e-08,0.543792,0.000948621,-1.04909e-06,2.25503e-08,0.544739,0.000946591,-9.81444e-07,-4.11195e-08,0.545685,0.000944504,-1.1048e-06,2.27182e-08,0.546628,0.000942363,-1.03665e-06,9.85146e-09,0.54757,0.000940319,-1.00709e-06,-2.51938e-09,0.548509,0.000938297,-1.01465e-06,2.25858e-10,0.549446,0.000936269,-1.01397e-06,1.61598e-09,0.550381,0.000934246,-1.00913e-06,-6.68983e-09,0.551315,0.000932207,-1.0292e-06,2.51434e-08,0.552246,0.000930224,-9.53765e-07,-3.42793e-08,0.553175,0.000928214,-1.0566e-06,5.23688e-08,0.554102,0.000926258,-8.99497e-07,-5.59865e-08,0.555028,0.000924291,-1.06746e-06,5.23679e-08,0.555951,0.000922313,-9.10352e-07,-3.42763e-08,0.556872,0.00092039,-1.01318e-06,2.51326e-08,0.557792,0.000918439,-9.37783e-07,-6.64954e-09,0.558709,0.000916543,-9.57732e-07,1.46554e-09,0.559625,0.000914632,-9.53335e-07,7.87281e-10,0.560538,0.000912728,-9.50973e-07,-4.61466e-09,0.56145,0.000910812,-9.64817e-07,1.76713e-08,0.56236,0.000908935,-9.11804e-07,-6.46564e-09,0.563268,0.000907092,-9.312e-07,8.19121e-09,0.564174,0.000905255,-9.06627e-07,-2.62992e-08,0.565078,0.000903362,-9.85524e-07,3.74007e-08,0.565981,0.000901504,-8.73322e-07,-4.0942e-09,0.566882,0.000899745,-8.85605e-07,-2.1024e-08,0.56778,0.00089791,-9.48677e-07,2.85854e-08,0.568677,0.000896099,-8.62921e-07,-3.3713e-08,0.569573,0.000894272,-9.64059e-07,4.6662e-08,0.570466,0.000892484,-8.24073e-07,-3.37258e-08,0.571358,0.000890734,-9.25251e-07,2.86365e-08,0.572247,0.00088897,-8.39341e-07,-2.12155e-08,0.573135,0.000887227,-9.02988e-07,-3.37913e-09,0.574022,0.000885411,-9.13125e-07,3.47319e-08,0.574906,0.000883689,-8.08929e-07,-1.63394e-08,0.575789,0.000882022,-8.57947e-07,-2.8979e-08,0.57667,0.00088022,-9.44885e-07,7.26509e-08,0.57755,0.000878548,-7.26932e-07,-8.28106e-08,0.578427,0.000876845,-9.75364e-07,7.97774e-08,0.579303,0.000875134,-7.36032e-07,-5.74849e-08,0.580178,0.00087349,-9.08486e-07,3.09529e-08,0.58105,0.000871765,-8.15628e-07,-6.72206e-09,0.581921,0.000870114,-8.35794e-07,-4.06451e-09,0.582791,0.00086843,-8.47987e-07,2.29799e-08,0.583658,0.000866803,-7.79048e-07,-2.82503e-08,0.584524,0.00086516,-8.63799e-07,3.04167e-08,0.585388,0.000863524,-7.72548e-07,-3.38119e-08,0.586251,0.000861877,-8.73984e-07,4.52264e-08,0.587112,0.000860265,-7.38305e-07,-2.78842e-08,0.587972,0.000858705,-8.21958e-07,6.70567e-09,0.58883,0.000857081,-8.01841e-07,1.06161e-09,0.589686,0.000855481,-7.98656e-07,-1.09521e-08,0.590541,0.00085385,-8.31512e-07,4.27468e-08,0.591394,0.000852316,-7.03272e-07,-4.08257e-08,0.592245,0.000850787,-8.25749e-07,1.34677e-09,0.593095,0.000849139,-8.21709e-07,3.54387e-08,0.593944,0.000847602,-7.15393e-07,-2.38924e-08,0.59479,0.0008461,-7.8707e-07,5.26143e-10,0.595636,0.000844527,-7.85491e-07,2.17879e-08,0.596479,0.000843021,-7.20127e-07,-2.80733e-08,0.597322,0.000841497,-8.04347e-07,3.09005e-08,0.598162,0.000839981,-7.11646e-07,-3.5924e-08,0.599002,0.00083845,-8.19418e-07,5.3191e-08,0.599839,0.000836971,-6.59845e-07,-5.76307e-08,0.600676,0.000835478,-8.32737e-07,5.81227e-08,0.60151,0.000833987,-6.58369e-07,-5.56507e-08,0.602344,0.000832503,-8.25321e-07,4.52706e-08,0.603175,0.000830988,-6.89509e-07,-6.22236e-09,0.604006,0.000829591,-7.08176e-07,-2.03811e-08,0.604834,0.000828113,-7.6932e-07,2.8142e-08,0.605662,0.000826659,-6.84894e-07,-3.25822e-08,0.606488,0.000825191,-7.8264e-07,4.25823e-08,0.607312,0.000823754,-6.54893e-07,-1.85376e-08,0.608135,0.000822389,-7.10506e-07,-2.80365e-08,0.608957,0.000820883,-7.94616e-07,7.1079e-08,0.609777,0.000819507,-5.81379e-07,-7.74655e-08,0.610596,0.000818112,-8.13775e-07,5.9969e-08,0.611413,0.000816665,-6.33868e-07,-4.32013e-08,0.612229,0.000815267,-7.63472e-07,5.32313e-08,0.613044,0.0008139,-6.03778e-07,-5.05148e-08,0.613857,0.000812541,-7.55323e-07,2.96187e-08,0.614669,0.000811119,-6.66466e-07,-8.35545e-09,0.615479,0.000809761,-6.91533e-07,3.80301e-09,0.616288,0.00080839,-6.80124e-07,-6.85666e-09,0.617096,0.000807009,-7.00694e-07,2.36237e-08,0.617903,0.000805678,-6.29822e-07,-2.80336e-08,0.618708,0.000804334,-7.13923e-07,2.8906e-08,0.619511,0.000802993,-6.27205e-07,-2.79859e-08,0.620314,0.000801655,-7.11163e-07,2.34329e-08,0.621114,0.000800303,-6.40864e-07,-6.14108e-09,0.621914,0.000799003,-6.59287e-07,1.13151e-09,0.622712,0.000797688,-6.55893e-07,1.61507e-09,0.62351,0.000796381,-6.51048e-07,-7.59186e-09,0.624305,0.000795056,-6.73823e-07,2.87524e-08,0.6251,0.000793794,-5.87566e-07,-4.7813e-08,0.625893,0.000792476,-7.31005e-07,4.32901e-08,0.626685,0.000791144,-6.01135e-07,-6.13814e-09,0.627475,0.000789923,-6.19549e-07,-1.87376e-08,0.628264,0.000788628,-6.75762e-07,2.14837e-08,0.629052,0.000787341,-6.11311e-07,-7.59265e-09,0.629839,0.000786095,-6.34089e-07,8.88692e-09,0.630625,0.000784854,-6.07428e-07,-2.7955e-08,0.631409,0.000783555,-6.91293e-07,4.33285e-08,0.632192,0.000782302,-5.61307e-07,-2.61497e-08,0.632973,0.000781101,-6.39757e-07,1.6658e-09,0.633754,0.000779827,-6.34759e-07,1.94866e-08,0.634533,0.000778616,-5.76299e-07,-2.00076e-08,0.635311,0.000777403,-6.36322e-07,9.39091e-10,0.636088,0.000776133,-6.33505e-07,1.62512e-08,0.636863,0.000774915,-5.84751e-07,-6.33937e-09,0.637638,0.000773726,-6.03769e-07,9.10609e-09,0.638411,0.000772546,-5.76451e-07,-3.00849e-08,0.639183,0.000771303,-6.66706e-07,5.1629e-08,0.639953,0.000770125,-5.11819e-07,-5.7222e-08,0.640723,0.000768929,-6.83485e-07,5.80497e-08,0.641491,0.000767736,-5.09336e-07,-5.57674e-08,0.642259,0.000766551,-6.76638e-07,4.58105e-08,0.643024,0.000765335,-5.39206e-07,-8.26541e-09,0.643789,0.000764231,-5.64002e-07,-1.27488e-08,0.644553,0.000763065,-6.02249e-07,-3.44168e-10,0.645315,0.00076186,-6.03281e-07,1.41254e-08,0.646077,0.000760695,-5.60905e-07,3.44727e-09,0.646837,0.000759584,-5.50563e-07,-2.79144e-08,0.647596,0.000758399,-6.34307e-07,4.86057e-08,0.648354,0.000757276,-4.88489e-07,-4.72989e-08,0.64911,0.000756158,-6.30386e-07,2.13807e-08,0.649866,0.000754961,-5.66244e-07,2.13808e-08,0.65062,0.000753893,-5.02102e-07,-4.7299e-08,0.651374,0.000752746,-6.43999e-07,4.86059e-08,0.652126,0.000751604,-4.98181e-07,-2.79154e-08,0.652877,0.000750524,-5.81927e-07,3.45089e-09,0.653627,0.000749371,-5.71575e-07,1.41119e-08,0.654376,0.00074827,-5.29239e-07,-2.93748e-10,0.655123,0.00074721,-5.3012e-07,-1.29368e-08,0.65587,0.000746111,-5.68931e-07,-7.56355e-09,0.656616,0.000744951,-5.91621e-07,4.3191e-08,0.65736,0.000743897,-4.62048e-07,-4.59911e-08,0.658103,0.000742835,-6.00022e-07,2.15642e-08,0.658846,0.0007417,-5.35329e-07,1.93389e-08,0.659587,0.000740687,-4.77312e-07,-3.93152e-08,0.660327,0.000739615,-5.95258e-07,1.87126e-08,0.661066,0.00073848,-5.3912e-07,2.40695e-08,0.661804,0.000737474,-4.66912e-07,-5.53859e-08,0.662541,0.000736374,-6.33069e-07,7.82648e-08,0.663277,0.000735343,-3.98275e-07,-7.88593e-08,0.664012,0.00073431,-6.34853e-07,5.83585e-08,0.664745,0.000733215,-4.59777e-07,-3.53656e-08,0.665478,0.000732189,-5.65874e-07,2.34994e-08,0.66621,0.000731128,-4.95376e-07,9.72743e-10,0.66694,0.00073014,-4.92458e-07,-2.73903e-08,0.66767,0.000729073,-5.74629e-07,4.89839e-08,0.668398,0.000728071,-4.27677e-07,-4.93359e-08,0.669126,0.000727068,-5.75685e-07,2.91504e-08,0.669853,0.000726004,-4.88234e-07,-7.66109e-09,0.670578,0.000725004,-5.11217e-07,1.49392e-09,0.671303,0.000723986,-5.06735e-07,1.68533e-09,0.672026,0.000722978,-5.01679e-07,-8.23525e-09,0.672749,0.00072195,-5.26385e-07,3.12556e-08,0.67347,0.000720991,-4.32618e-07,-5.71825e-08,0.674191,0.000719954,-6.04166e-07,7.8265e-08,0.67491,0.00071898,-3.69371e-07,-7.70634e-08,0.675628,0.00071801,-6.00561e-07,5.11747e-08,0.676346,0.000716963,-4.47037e-07,-8.42615e-09,0.677062,0.000716044,-4.72315e-07,-1.747e-08,0.677778,0.000715046,-5.24725e-07,1.87015e-08,0.678493,0.000714053,-4.68621e-07,2.26856e-09,0.679206,0.000713123,-4.61815e-07,-2.77758e-08,0.679919,0.000712116,-5.45142e-07,4.92298e-08,0.68063,0.000711173,-3.97453e-07,-4.99339e-08,0.681341,0.000710228,-5.47255e-07,3.12967e-08,0.682051,0.000709228,-4.53365e-07,-1.56481e-08,0.68276,0.000708274,-5.00309e-07,3.12958e-08,0.683467,0.000707367,-4.06422e-07,-4.99303e-08,0.684174,0.000706405,-5.56213e-07,4.9216e-08,0.68488,0.00070544,-4.08565e-07,-2.77245e-08,0.685585,0.00070454,-4.91738e-07,2.07748e-09,0.686289,0.000703562,-4.85506e-07,1.94146e-08,0.686992,0.00070265,-4.27262e-07,-2.01314e-08,0.687695,0.000701735,-4.87656e-07,1.50616e-09,0.688396,0.000700764,-4.83137e-07,1.41067e-08,0.689096,0.00069984,-4.40817e-07,1.67168e-09,0.689795,0.000698963,-4.35802e-07,-2.07934e-08,0.690494,0.000698029,-4.98182e-07,2.18972e-08,0.691192,0.000697099,-4.32491e-07,-7.19092e-09,0.691888,0.000696212,-4.54064e-07,6.86642e-09,0.692584,0.000695325,-4.33464e-07,-2.02747e-08,0.693279,0.000694397,-4.94288e-07,1.46279e-08,0.693973,0.000693452,-4.50405e-07,2.13678e-08,0.694666,0.000692616,-3.86301e-07,-4.04945e-08,0.695358,0.000691721,-5.07785e-07,2.14009e-08,0.696049,0.00069077,-4.43582e-07,1.44955e-08,0.69674,0.000689926,-4.00096e-07,-1.97783e-08,0.697429,0.000689067,-4.5943e-07,5.01296e-09,0.698118,0.000688163,-4.44392e-07,-2.73521e-10,0.698805,0.000687273,-4.45212e-07,-3.91893e-09,0.699492,0.000686371,-4.56969e-07,1.59493e-08,0.700178,0.000685505,-4.09121e-07,-2.73351e-10,0.700863,0.000684686,-4.09941e-07,-1.4856e-08,0.701548,0.000683822,-4.54509e-07,9.25979e-11,0.702231,0.000682913,-4.54231e-07,1.44855e-08,0.702913,0.000682048,-4.10775e-07,1.56992e-09,0.703595,0.000681231,-4.06065e-07,-2.07652e-08,0.704276,0.000680357,-4.68361e-07,2.18864e-08,0.704956,0.000679486,-4.02701e-07,-7.17595e-09,0.705635,0.000678659,-4.24229e-07,6.81748e-09,0.706313,0.000677831,-4.03777e-07,-2.0094e-08,0.70699,0.000676963,-4.64059e-07,1.39538e-08,0.707667,0.000676077,-4.22197e-07,2.38835e-08,0.708343,0.000675304,-3.50547e-07,-4.98831e-08,0.709018,0.000674453,-5.00196e-07,5.64395e-08,0.709692,0.000673622,-3.30878e-07,-5.66657e-08,0.710365,0.00067279,-5.00875e-07,5.1014e-08,0.711037,0.000671942,-3.47833e-07,-2.81809e-08,0.711709,0.000671161,-4.32376e-07,2.10513e-09,0.712379,0.000670303,-4.2606e-07,1.97604e-08,0.713049,0.00066951,-3.66779e-07,-2.15422e-08,0.713718,0.000668712,-4.31406e-07,6.8038e-09,0.714387,0.000667869,-4.10994e-07,-5.67295e-09,0.715054,0.00066703,-4.28013e-07,1.5888e-08,0.715721,0.000666222,-3.80349e-07,1.72576e-09,0.716387,0.000665467,-3.75172e-07,-2.27911e-08,0.717052,0.000664648,-4.43545e-07,2.9834e-08,0.717716,0.00066385,-3.54043e-07,-3.69401e-08,0.718379,0.000663031,-4.64864e-07,5.83219e-08,0.719042,0.000662277,-2.89898e-07,-7.71382e-08,0.719704,0.000661465,-5.21313e-07,7.14171e-08,0.720365,0.000660637,-3.07061e-07,-2.97161e-08,0.721025,0.000659934,-3.96209e-07,-1.21575e-08,0.721685,0.000659105,-4.32682e-07,1.87412e-08,0.722343,0.000658296,-3.76458e-07,-3.2029e-09,0.723001,0.000657533,-3.86067e-07,-5.9296e-09,0.723659,0.000656743,-4.03856e-07,2.69213e-08,0.724315,0.000656016,-3.23092e-07,-4.21511e-08,0.724971,0.000655244,-4.49545e-07,2.24737e-08,0.725625,0.000654412,-3.82124e-07,1.18611e-08,0.726279,0.000653683,-3.46541e-07,-1.03132e-08,0.726933,0.000652959,-3.7748e-07,-3.02128e-08,0.727585,0.000652114,-4.68119e-07,7.15597e-08,0.728237,0.000651392,-2.5344e-07,-7.72119e-08,0.728888,0.000650654,-4.85075e-07,5.8474e-08,0.729538,0.000649859,-3.09654e-07,-3.74746e-08,0.730188,0.000649127,-4.22077e-07,3.18197e-08,0.730837,0.000648379,-3.26618e-07,-3.01997e-08,0.731485,0.000647635,-4.17217e-07,2.93747e-08,0.732132,0.000646888,-3.29093e-07,-2.76943e-08,0.732778,0.000646147,-4.12176e-07,2.17979e-08,0.733424,0.000645388,-3.46783e-07,1.07292e-10,0.734069,0.000644695,-3.46461e-07,-2.22271e-08,0.734713,0.000643935,-4.13142e-07,2.91963e-08,0.735357,0.000643197,-3.25553e-07,-3.49536e-08,0.736,0.000642441,-4.30414e-07,5.10133e-08,0.736642,0.000641733,-2.77374e-07,-4.98904e-08,0.737283,0.000641028,-4.27045e-07,2.93392e-08,0.737924,0.000640262,-3.39028e-07,-7.86156e-09,0.738564,0.000639561,-3.62612e-07,2.10703e-09,0.739203,0.000638842,-3.56291e-07,-5.6653e-10,0.739842,0.000638128,-3.57991e-07,1.59086e-10,0.740479,0.000637412,-3.57513e-07,-6.98321e-11,0.741116,0.000636697,-3.57723e-07,1.20214e-10,0.741753,0.000635982,-3.57362e-07,-4.10987e-10,0.742388,0.000635266,-3.58595e-07,1.5237e-09,0.743023,0.000634553,-3.54024e-07,-5.68376e-09,0.743657,0.000633828,-3.71075e-07,2.12113e-08,0.744291,0.00063315,-3.07441e-07,-1.95569e-08,0.744924,0.000632476,-3.66112e-07,-2.58816e-09,0.745556,0.000631736,-3.73877e-07,2.99096e-08,0.746187,0.000631078,-2.84148e-07,-5.74454e-08,0.746818,0.000630337,-4.56484e-07,8.06629e-08,0.747448,0.000629666,-2.14496e-07,-8.63922e-08,0.748077,0.000628978,-4.73672e-07,8.60918e-08,0.748706,0.000628289,-2.15397e-07,-7.91613e-08,0.749334,0.000627621,-4.5288e-07,5.17393e-08,0.749961,0.00062687,-2.97663e-07,-8.58662e-09,0.750588,0.000626249,-3.23422e-07,-1.73928e-08,0.751214,0.00062555,-3.75601e-07,1.85532e-08,0.751839,0.000624855,-3.19941e-07,2.78479e-09,0.752463,0.000624223,-3.11587e-07,-2.96923e-08,0.753087,0.000623511,-4.00664e-07,5.63799e-08,0.75371,0.000622879,-2.31524e-07,-7.66179e-08,0.754333,0.000622186,-4.61378e-07,7.12778e-08,0.754955,0.000621477,-2.47545e-07,-2.96794e-08,0.755576,0.000620893,-3.36583e-07,-1.21648e-08,0.756196,0.000620183,-3.73077e-07,1.87339e-08,0.756816,0.000619493,-3.16875e-07,-3.16622e-09,0.757435,0.00061885,-3.26374e-07,-6.0691e-09,0.758054,0.000618179,-3.44581e-07,2.74426e-08,0.758672,0.000617572,-2.62254e-07,-4.40968e-08,0.759289,0.000616915,-3.94544e-07,2.97352e-08,0.759906,0.000616215,-3.05338e-07,-1.52393e-08,0.760522,0.000615559,-3.51056e-07,3.12221e-08,0.761137,0.000614951,-2.5739e-07,-5.00443e-08,0.761751,0.000614286,-4.07523e-07,4.9746e-08,0.762365,0.00061362,-2.58285e-07,-2.97303e-08,0.762979,0.000613014,-3.47476e-07,9.57079e-09,0.763591,0.000612348,-3.18764e-07,-8.55287e-09,0.764203,0.000611685,-3.44422e-07,2.46407e-08,0.764815,0.00061107,-2.705e-07,-3.04053e-08,0.765426,0.000610437,-3.61716e-07,3.73759e-08,0.766036,0.000609826,-2.49589e-07,-5.94935e-08,0.766645,0.000609149,-4.28069e-07,8.13889e-08,0.767254,0.000608537,-1.83902e-07,-8.72483e-08,0.767862,0.000607907,-4.45647e-07,8.87901e-08,0.76847,0.000607282,-1.79277e-07,-8.90983e-08,0.769077,0.000606656,-4.46572e-07,8.87892e-08,0.769683,0.000606029,-1.80204e-07,-8.72446e-08,0.770289,0.000605407,-4.41938e-07,8.13752e-08,0.770894,0.000604768,-1.97812e-07,-5.94423e-08,0.771498,0.000604194,-3.76139e-07,3.71848e-08,0.772102,0.000603553,-2.64585e-07,-2.96922e-08,0.772705,0.000602935,-3.53661e-07,2.19793e-08,0.773308,0.000602293,-2.87723e-07,1.37955e-09,0.77391,0.000601722,-2.83585e-07,-2.74976e-08,0.774512,0.000601072,-3.66077e-07,4.9006e-08,0.775112,0.000600487,-2.19059e-07,-4.93171e-08,0.775712,0.000599901,-3.67011e-07,2.90531e-08,0.776312,0.000599254,-2.79851e-07,-7.29081e-09,0.776911,0.000598673,-3.01724e-07,1.10077e-10,0.777509,0.00059807,-3.01393e-07,6.85053e-09,0.778107,0.000597487,-2.80842e-07,-2.75123e-08,0.778704,0.000596843,-3.63379e-07,4.35939e-08,0.779301,0.000596247,-2.32597e-07,-2.7654e-08,0.779897,0.000595699,-3.15559e-07,7.41741e-09,0.780492,0.00059509,-2.93307e-07,-2.01562e-09,0.781087,0.000594497,-2.99354e-07,6.45059e-10,0.781681,0.000593901,-2.97418e-07,-5.64635e-10,0.782275,0.000593304,-2.99112e-07,1.61347e-09,0.782868,0.000592711,-2.94272e-07,-5.88926e-09,0.78346,0.000592105,-3.1194e-07,2.19436e-08,0.784052,0.000591546,-2.46109e-07,-2.22805e-08,0.784643,0.000590987,-3.1295e-07,7.57368e-09,0.785234,0.000590384,-2.90229e-07,-8.01428e-09,0.785824,0.00058978,-3.14272e-07,2.44834e-08,0.786414,0.000589225,-2.40822e-07,-3.03148e-08,0.787003,0.000588652,-3.31766e-07,3.7171e-08,0.787591,0.0005881,-2.20253e-07,-5.87646e-08,0.788179,0.000587483,-3.96547e-07,7.86782e-08,0.788766,0.000586926,-1.60512e-07,-7.71342e-08,0.789353,0.000586374,-3.91915e-07,5.10444e-08,0.789939,0.000585743,-2.38782e-07,-7.83422e-09,0.790524,0.000585242,-2.62284e-07,-1.97076e-08,0.791109,0.000584658,-3.21407e-07,2.70598e-08,0.791693,0.000584097,-2.40228e-07,-2.89269e-08,0.792277,0.000583529,-3.27008e-07,2.90431e-08,0.792861,0.000582963,-2.39879e-07,-2.76409e-08,0.793443,0.0005824,-3.22802e-07,2.1916e-08,0.794025,0.00058182,-2.57054e-07,-4.18368e-10,0.794607,0.000581305,-2.58309e-07,-2.02425e-08,0.795188,0.000580727,-3.19036e-07,2.17838e-08,0.795768,0.000580155,-2.53685e-07,-7.28814e-09,0.796348,0.000579625,-2.75549e-07,7.36871e-09,0.796928,0.000579096,-2.53443e-07,-2.21867e-08,0.797506,0.000578523,-3.20003e-07,2.17736e-08,0.798085,0.000577948,-2.54683e-07,-5.30296e-09,0.798662,0.000577423,-2.70592e-07,-5.61698e-10,0.799239,0.00057688,-2.72277e-07,7.54977e-09,0.799816,0.000576358,-2.49627e-07,-2.96374e-08,0.800392,0.00057577,-3.38539e-07,5.1395e-08,0.800968,0.000575247,-1.84354e-07,-5.67335e-08,0.801543,0.000574708,-3.54555e-07,5.63297e-08,0.802117,0.000574168,-1.85566e-07,-4.93759e-08,0.802691,0.000573649,-3.33693e-07,2.19646e-08,0.803264,0.000573047,-2.678e-07,2.1122e-08,0.803837,0.000572575,-2.04433e-07,-4.68482e-08,0.804409,0.000572026,-3.44978e-07,4.70613e-08,0.804981,0.000571477,-2.03794e-07,-2.21877e-08,0.805552,0.000571003,-2.70357e-07,-1.79153e-08,0.806123,0.000570408,-3.24103e-07,3.42443e-08,0.806693,0.000569863,-2.2137e-07,1.47556e-10,0.807263,0.000569421,-2.20928e-07,-3.48345e-08,0.807832,0.000568874,-3.25431e-07,1.99812e-08,0.808401,0.000568283,-2.65487e-07,1.45143e-08,0.808969,0.000567796,-2.21945e-07,-1.84338e-08,0.809536,0.000567297,-2.77246e-07,-3.83608e-10,0.810103,0.000566741,-2.78397e-07,1.99683e-08,0.81067,0.000566244,-2.18492e-07,-1.98848e-08,0.811236,0.000565747,-2.78146e-07,-3.38976e-11,0.811801,0.000565191,-2.78248e-07,2.00204e-08,0.812366,0.000564695,-2.18187e-07,-2.04429e-08,0.812931,0.000564197,-2.79516e-07,2.1467e-09,0.813495,0.000563644,-2.73076e-07,1.18561e-08,0.814058,0.000563134,-2.37507e-07,1.00334e-08,0.814621,0.000562689,-2.07407e-07,-5.19898e-08,0.815183,0.000562118,-3.63376e-07,7.87163e-08,0.815745,0.000561627,-1.27227e-07,-8.40616e-08,0.816306,0.000561121,-3.79412e-07,7.87163e-08,0.816867,0.000560598,-1.43263e-07,-5.19898e-08,0.817428,0.000560156,-2.99233e-07,1.00335e-08,0.817988,0.000559587,-2.69132e-07,1.18559e-08,0.818547,0.000559085,-2.33564e-07,2.14764e-09,0.819106,0.000558624,-2.27122e-07,-2.04464e-08,0.819664,0.000558108,-2.88461e-07,2.00334e-08,0.820222,0.000557591,-2.28361e-07,-8.24277e-11,0.820779,0.000557135,-2.28608e-07,-1.97037e-08,0.821336,0.000556618,-2.87719e-07,1.92925e-08,0.821893,0.000556101,-2.29841e-07,2.13831e-09,0.822448,0.000555647,-2.23427e-07,-2.78458e-08,0.823004,0.000555117,-3.06964e-07,4.96402e-08,0.823559,0.000554652,-1.58043e-07,-5.15058e-08,0.824113,0.000554181,-3.12561e-07,3.71737e-08,0.824667,0.000553668,-2.0104e-07,-3.75844e-08,0.82522,0.000553153,-3.13793e-07,5.35592e-08,0.825773,0.000552686,-1.53115e-07,-5.74431e-08,0.826326,0.000552207,-3.25444e-07,5.7004e-08,0.826878,0.000551728,-1.54433e-07,-5.13635e-08,0.827429,0.000551265,-3.08523e-07,2.92406e-08,0.82798,0.000550735,-2.20801e-07,-5.99424e-09,0.828531,0.000550276,-2.38784e-07,-5.26363e-09,0.829081,0.000549782,-2.54575e-07,2.70488e-08,0.82963,0.000549354,-1.73429e-07,-4.33268e-08,0.83018,0.000548878,-3.03409e-07,2.7049e-08,0.830728,0.000548352,-2.22262e-07,-5.26461e-09,0.831276,0.000547892,-2.38056e-07,-5.99057e-09,0.831824,0.000547397,-2.56027e-07,2.92269e-08,0.832371,0.000546973,-1.68347e-07,-5.13125e-08,0.832918,0.000546482,-3.22284e-07,5.68139e-08,0.833464,0.000546008,-1.51843e-07,-5.67336e-08,0.83401,0.000545534,-3.22043e-07,5.09113e-08,0.834555,0.000545043,-1.6931e-07,-2.77022e-08,0.8351,0.000544621,-2.52416e-07,2.92924e-10,0.835644,0.000544117,-2.51537e-07,2.65305e-08,0.836188,0.000543694,-1.71946e-07,-4.68105e-08,0.836732,0.00054321,-3.12377e-07,4.15021e-08,0.837275,0.000542709,-1.87871e-07,1.13355e-11,0.837817,0.000542334,-1.87837e-07,-4.15474e-08,0.838359,0.000541833,-3.12479e-07,4.69691e-08,0.838901,0.000541349,-1.71572e-07,-2.71196e-08,0.839442,0.000540925,-2.52931e-07,1.90462e-09,0.839983,0.000540425,-2.47217e-07,1.95011e-08,0.840523,0.000539989,-1.88713e-07,-2.03045e-08,0.841063,0.00053955,-2.49627e-07,2.11216e-09,0.841602,0.000539057,-2.4329e-07,1.18558e-08,0.842141,0.000538606,-2.07723e-07,1.00691e-08,0.842679,0.000538221,-1.77516e-07,-5.21324e-08,0.843217,0.00053771,-3.33913e-07,7.92513e-08,0.843755,0.00053728,-9.6159e-08,-8.60587e-08,0.844292,0.000536829,-3.54335e-07,8.61696e-08,0.844828,0.000536379,-9.58263e-08,-7.98057e-08,0.845364,0.000535948,-3.35243e-07,5.42394e-08,0.8459,0.00053544,-1.72525e-07,-1.79426e-08,0.846435,0.000535041,-2.26353e-07,1.75308e-08,0.84697,0.000534641,-1.73761e-07,-5.21806e-08,0.847505,0.000534137,-3.30302e-07,7.19824e-08,0.848038,0.000533692,-1.14355e-07,-5.69349e-08,0.848572,0.000533293,-2.8516e-07,3.65479e-08,0.849105,0.000532832,-1.75516e-07,-2.96519e-08,0.849638,0.000532392,-2.64472e-07,2.2455e-08,0.85017,0.000531931,-1.97107e-07,-5.63451e-10,0.850702,0.000531535,-1.98797e-07,-2.02011e-08,0.851233,0.000531077,-2.59401e-07,2.17634e-08,0.851764,0.000530623,-1.94111e-07,-7.24794e-09,0.852294,0.000530213,-2.15854e-07,7.22832e-09,0.852824,0.000529803,-1.94169e-07,-2.16653e-08,0.853354,0.00052935,-2.59165e-07,1.98283e-08,0.853883,0.000528891,-1.9968e-07,1.95678e-09,0.854412,0.000528497,-1.9381e-07,-2.76554e-08,0.85494,0.000528027,-2.76776e-07,4.90603e-08,0.855468,0.00052762,-1.29596e-07,-4.93764e-08,0.855995,0.000527213,-2.77725e-07,2.92361e-08,0.856522,0.000526745,-1.90016e-07,-7.96341e-09,0.857049,0.000526341,-2.13907e-07,2.61752e-09,0.857575,0.000525922,-2.06054e-07,-2.50665e-09,0.8581,0.000525502,-2.13574e-07,7.40906e-09,0.858626,0.000525097,-1.91347e-07,-2.71296e-08,0.859151,0.000524633,-2.72736e-07,4.15048e-08,0.859675,0.000524212,-1.48221e-07,-1.96802e-08,0.860199,0.000523856,-2.07262e-07,-2.23886e-08,0.860723,0.000523375,-2.74428e-07,4.96299e-08,0.861246,0.000522975,-1.25538e-07,-5.69216e-08,0.861769,0.000522553,-2.96303e-07,5.88473e-08,0.862291,0.000522137,-1.19761e-07,-5.92584e-08,0.862813,0.00052172,-2.97536e-07,5.8977e-08,0.863334,0.000521301,-1.20605e-07,-5.74403e-08,0.863855,0.000520888,-2.92926e-07,5.15751e-08,0.864376,0.000520457,-1.38201e-07,-2.96506e-08,0.864896,0.000520091,-2.27153e-07,7.42277e-09,0.865416,0.000519659,-2.04885e-07,-4.05057e-11,0.865936,0.00051925,-2.05006e-07,-7.26074e-09,0.866455,0.000518818,-2.26788e-07,2.90835e-08,0.866973,0.000518451,-1.39538e-07,-4.94686e-08,0.867492,0.000518024,-2.87944e-07,4.95814e-08,0.868009,0.000517597,-1.39199e-07,-2.96479e-08,0.868527,0.000517229,-2.28143e-07,9.40539e-09,0.869044,0.000516801,-1.99927e-07,-7.9737e-09,0.86956,0.000516378,-2.23848e-07,2.24894e-08,0.870077,0.000515997,-1.5638e-07,-2.23793e-08,0.870592,0.000515617,-2.23517e-07,7.42302e-09,0.871108,0.000515193,-2.01248e-07,-7.31283e-09,0.871623,0.000514768,-2.23187e-07,2.18283e-08,0.872137,0.000514387,-1.57702e-07,-2.03959e-08,0.872652,0.000514011,-2.1889e-07,1.50711e-10,0.873165,0.000513573,-2.18437e-07,1.97931e-08,0.873679,0.000513196,-1.59058e-07,-1.97183e-08,0.874192,0.000512819,-2.18213e-07,-5.24324e-10,0.874704,0.000512381,-2.19786e-07,2.18156e-08,0.875217,0.000512007,-1.54339e-07,-2.71336e-08,0.875728,0.000511616,-2.3574e-07,2.71141e-08,0.87624,0.000511226,-1.54398e-07,-2.17182e-08,0.876751,0.000510852,-2.19552e-07,1.54131e-10,0.877262,0.000510414,-2.1909e-07,2.11017e-08,0.877772,0.000510039,-1.55785e-07,-2.49562e-08,0.878282,0.000509652,-2.30654e-07,1.91183e-08,0.878791,0.000509248,-1.73299e-07,8.08751e-09,0.8793,0.000508926,-1.49036e-07,-5.14684e-08,0.879809,0.000508474,-3.03441e-07,7.85766e-08,0.880317,0.000508103,-6.77112e-08,-8.40242e-08,0.880825,0.000507715,-3.19784e-07,7.87063e-08,0.881333,0.000507312,-8.36649e-08,-5.19871e-08,0.88184,0.000506988,-2.39626e-07,1.00327e-08,0.882346,0.000506539,-2.09528e-07,1.18562e-08,0.882853,0.000506156,-1.73959e-07,2.14703e-09,0.883359,0.000505814,-1.67518e-07,-2.04444e-08,0.883864,0.000505418,-2.28851e-07,2.00258e-08,0.88437,0.00050502,-1.68774e-07,-5.42855e-11,0.884874,0.000504682,-1.68937e-07,-1.98087e-08,0.885379,0.000504285,-2.28363e-07,1.96842e-08,0.885883,0.000503887,-1.6931e-07,6.76342e-10,0.886387,0.000503551,-1.67281e-07,-2.23896e-08,0.88689,0.000503149,-2.3445e-07,2.92774e-08,0.887393,0.000502768,-1.46618e-07,-3.51152e-08,0.887896,0.00050237,-2.51963e-07,5.15787e-08,0.888398,0.00050202,-9.72271e-08,-5.19903e-08,0.8889,0.00050167,-2.53198e-07,3.71732e-08,0.889401,0.000501275,-1.41678e-07,-3.70978e-08,0.889902,0.00050088,-2.52972e-07,5.16132e-08,0.890403,0.000500529,-9.81321e-08,-5.01459e-08,0.890903,0.000500183,-2.4857e-07,2.9761e-08,0.891403,0.000499775,-1.59287e-07,-9.29351e-09,0.891903,0.000499428,-1.87167e-07,7.41301e-09,0.892402,0.000499076,-1.64928e-07,-2.03585e-08,0.892901,0.000498685,-2.26004e-07,1.44165e-08,0.893399,0.000498276,-1.82754e-07,2.22974e-08,0.893898,0.000497978,-1.15862e-07,-4.40013e-08,0.894395,0.000497614,-2.47866e-07,3.44985e-08,0.894893,0.000497222,-1.44371e-07,-3.43882e-08,0.89539,0.00049683,-2.47535e-07,4.34497e-08,0.895886,0.000496465,-1.17186e-07,-2.02012e-08,0.896383,0.00049617,-1.7779e-07,-2.22497e-08,0.896879,0.000495748,-2.44539e-07,4.95952e-08,0.897374,0.000495408,-9.57532e-08,-5.69217e-08,0.89787,0.000495045,-2.66518e-07,5.88823e-08,0.898364,0.000494689,-8.98713e-08,-5.93983e-08,0.898859,0.000494331,-2.68066e-07,5.95017e-08,0.899353,0.000493973,-8.95613e-08,-5.9399e-08,0.899847,0.000493616,-2.67758e-07,5.8885e-08,0.90034,0.000493257,-9.11033e-08,-5.69317e-08,0.900833,0.000492904,-2.61898e-07,4.96326e-08,0.901326,0.000492529,-1.13001e-07,-2.23893e-08,0.901819,0.000492236,-1.80169e-07,-1.968e-08,0.902311,0.000491817,-2.39209e-07,4.15047e-08,0.902802,0.000491463,-1.14694e-07,-2.71296e-08,0.903293,0.000491152,-1.96083e-07,7.409e-09,0.903784,0.000490782,-1.73856e-07,-2.50645e-09,0.904275,0.000490427,-1.81376e-07,2.61679e-09,0.904765,0.000490072,-1.73525e-07,-7.96072e-09,0.905255,0.000489701,-1.97407e-07,2.92261e-08,0.905745,0.000489394,-1.09729e-07,-4.93389e-08,0.906234,0.000489027,-2.57746e-07,4.89204e-08,0.906723,0.000488658,-1.10985e-07,-2.71333e-08,0.907211,0.000488354,-1.92385e-07,8.30861e-12,0.907699,0.00048797,-1.9236e-07,2.71001e-08,0.908187,0.000487666,-1.1106e-07,-4.88041e-08,0.908675,0.000487298,-2.57472e-07,4.89069e-08,0.909162,0.000486929,-1.10751e-07,-2.76143e-08,0.909649,0.000486625,-1.93594e-07,1.9457e-09,0.910135,0.000486244,-1.87757e-07,1.98315e-08,0.910621,0.000485928,-1.28262e-07,-2.16671e-08,0.911107,0.000485606,-1.93264e-07,7.23216e-09,0.911592,0.000485241,-1.71567e-07,-7.26152e-09,0.912077,0.000484877,-1.93352e-07,2.18139e-08,0.912562,0.000484555,-1.2791e-07,-2.03895e-08,0.913047,0.000484238,-1.89078e-07,1.39494e-10,0.913531,0.000483861,-1.8866e-07,1.98315e-08,0.914014,0.000483543,-1.29165e-07,-1.98609e-08,0.914498,0.000483225,-1.88748e-07,7.39912e-12,0.914981,0.000482847,-1.88726e-07,1.98313e-08,0.915463,0.000482529,-1.29232e-07,-1.9728e-08,0.915946,0.000482212,-1.88416e-07,-5.24035e-10,0.916428,0.000481833,-1.89988e-07,2.18241e-08,0.916909,0.000481519,-1.24516e-07,-2.71679e-08,0.917391,0.000481188,-2.06019e-07,2.72427e-08,0.917872,0.000480858,-1.24291e-07,-2.21985e-08,0.918353,0.000480543,-1.90886e-07,1.94644e-09,0.918833,0.000480167,-1.85047e-07,1.44127e-08,0.919313,0.00047984,-1.41809e-07,7.39438e-12,0.919793,0.000479556,-1.41787e-07,-1.44423e-08,0.920272,0.000479229,-1.85114e-07,-1.84291e-09,0.920751,0.000478854,-1.90642e-07,2.18139e-08,0.92123,0.000478538,-1.25201e-07,-2.58081e-08,0.921708,0.00047821,-2.02625e-07,2.18139e-08,0.922186,0.00047787,-1.37183e-07,-1.84291e-09,0.922664,0.00047759,-1.42712e-07,-1.44423e-08,0.923141,0.000477262,-1.86039e-07,7.34701e-12,0.923618,0.00047689,-1.86017e-07,1.44129e-08,0.924095,0.000476561,-1.42778e-07,1.94572e-09,0.924572,0.000476281,-1.36941e-07,-2.21958e-08,0.925048,0.000475941,-2.03528e-07,2.72327e-08,0.925523,0.000475615,-1.2183e-07,-2.71304e-08,0.925999,0.00047529,-2.03221e-07,2.16843e-08,0.926474,0.000474949,-1.38168e-07,-2.16005e-12,0.926949,0.000474672,-1.38175e-07,-2.16756e-08,0.927423,0.000474331,-2.03202e-07,2.71001e-08,0.927897,0.000474006,-1.21902e-07,-2.71201e-08,0.928371,0.000473681,-2.03262e-07,2.17757e-08,0.928845,0.00047334,-1.37935e-07,-3.78028e-10,0.929318,0.000473063,-1.39069e-07,-2.02636e-08,0.929791,0.000472724,-1.9986e-07,2.18276e-08,0.930263,0.000472389,-1.34377e-07,-7.44231e-09,0.930736,0.000472098,-1.56704e-07,7.94165e-09,0.931208,0.000471809,-1.32879e-07,-2.43243e-08,0.931679,0.00047147,-2.05851e-07,2.97508e-08,0.932151,0.000471148,-1.16599e-07,-3.50742e-08,0.932622,0.000470809,-2.21822e-07,5.09414e-08,0.933092,0.000470518,-6.89976e-08,-4.94821e-08,0.933563,0.000470232,-2.17444e-07,2.77775e-08,0.934033,0.00046988,-1.34111e-07,-2.02351e-09,0.934502,0.000469606,-1.40182e-07,-1.96835e-08,0.934972,0.000469267,-1.99232e-07,2.11529e-08,0.935441,0.000468932,-1.35774e-07,-5.32332e-09,0.93591,0.000468644,-1.51743e-07,1.40413e-10,0.936378,0.000468341,-1.51322e-07,4.76166e-09,0.936846,0.000468053,-1.37037e-07,-1.9187e-08,0.937314,0.000467721,-1.94598e-07,1.23819e-08,0.937782,0.000467369,-1.57453e-07,2.92642e-08,0.938249,0.000467142,-6.96601e-08,-6.98342e-08,0.938716,0.000466793,-2.79163e-07,7.12586e-08,0.939183,0.000466449,-6.53869e-08,-3.63863e-08,0.939649,0.000466209,-1.74546e-07,1.46818e-08,0.940115,0.000465904,-1.305e-07,-2.2341e-08,0.940581,0.000465576,-1.97523e-07,1.50774e-08,0.941046,0.000465226,-1.52291e-07,2.16359e-08,0.941511,0.000464986,-8.73832e-08,-4.20162e-08,0.941976,0.000464685,-2.13432e-07,2.72198e-08,0.942441,0.00046434,-1.31773e-07,-7.2581e-09,0.942905,0.000464055,-1.53547e-07,1.81263e-09,0.943369,0.000463753,-1.48109e-07,7.58386e-12,0.943832,0.000463457,-1.48086e-07,-1.84298e-09,0.944296,0.000463155,-1.53615e-07,7.36433e-09,0.944759,0.00046287,-1.31522e-07,-2.76143e-08,0.945221,0.000462524,-2.14365e-07,4.34883e-08,0.945684,0.000462226,-8.39003e-08,-2.71297e-08,0.946146,0.000461977,-1.65289e-07,5.42595e-09,0.946608,0.000461662,-1.49012e-07,5.42593e-09,0.947069,0.000461381,-1.32734e-07,-2.71297e-08,0.94753,0.000461034,-2.14123e-07,4.34881e-08,0.947991,0.000460736,-8.36585e-08,-2.76134e-08,0.948452,0.000460486,-1.66499e-07,7.36083e-09,0.948912,0.000460175,-1.44416e-07,-1.82993e-09,0.949372,0.000459881,-1.49906e-07,-4.11073e-11,0.949832,0.000459581,-1.50029e-07,1.99434e-09,0.950291,0.000459287,-1.44046e-07,-7.93627e-09,0.950751,0.000458975,-1.67855e-07,2.97507e-08,0.951209,0.000458728,-7.86029e-08,-5.1462e-08,0.951668,0.000458417,-2.32989e-07,5.6888e-08,0.952126,0.000458121,-6.2325e-08,-5.68806e-08,0.952584,0.000457826,-2.32967e-07,5.14251e-08,0.953042,0.000457514,-7.86914e-08,-2.96107e-08,0.953499,0.000457268,-1.67523e-07,7.41296e-09,0.953956,0.000456955,-1.45285e-07,-4.11262e-11,0.954413,0.000456665,-1.45408e-07,-7.24847e-09,0.95487,0.000456352,-1.67153e-07,2.9035e-08,0.955326,0.000456105,-8.00484e-08,-4.92869e-08,0.955782,0.000455797,-2.27909e-07,4.89032e-08,0.956238,0.000455488,-8.11994e-08,-2.71166e-08,0.956693,0.000455244,-1.62549e-07,-4.13678e-11,0.957148,0.000454919,-1.62673e-07,2.72821e-08,0.957603,0.000454675,-8.0827e-08,-4.94824e-08,0.958057,0.000454365,-2.29274e-07,5.14382e-08,0.958512,0.000454061,-7.49597e-08,-3.7061e-08,0.958965,0.0004538,-1.86143e-07,3.72013e-08,0.959419,0.000453539,-7.45389e-08,-5.21396e-08,0.959873,0.000453234,-2.30958e-07,5.21476e-08,0.960326,0.000452928,-7.45146e-08,-3.72416e-08,0.960778,0.000452667,-1.8624e-07,3.72143e-08,0.961231,0.000452407,-7.45967e-08,-5.20109e-08,0.961683,0.000452101,-2.30629e-07,5.16199e-08,0.962135,0.000451795,-7.57696e-08,-3.52595e-08,0.962587,0.000451538,-1.81548e-07,2.98133e-08,0.963038,0.000451264,-9.2108e-08,-2.43892e-08,0.963489,0.000451007,-1.65276e-07,8.13892e-09,0.96394,0.000450701,-1.40859e-07,-8.16647e-09,0.964391,0.000450394,-1.65358e-07,2.45269e-08,0.964841,0.000450137,-9.17775e-08,-3.03367e-08,0.965291,0.000449863,-1.82787e-07,3.7215e-08,0.965741,0.000449609,-7.11424e-08,-5.89188e-08,0.96619,0.00044929,-2.47899e-07,7.92509e-08,0.966639,0.000449032,-1.01462e-08,-7.92707e-08,0.967088,0.000448773,-2.47958e-07,5.90181e-08,0.967537,0.000448455,-7.0904e-08,-3.75925e-08,0.967985,0.0004482,-1.83681e-07,3.17471e-08,0.968433,0.000447928,-8.84401e-08,-2.97913e-08,0.968881,0.000447662,-1.77814e-07,2.78133e-08,0.969329,0.000447389,-9.4374e-08,-2.18572e-08,0.969776,0.000447135,-1.59946e-07,1.10134e-11,0.970223,0.000446815,-1.59913e-07,2.18132e-08,0.97067,0.000446561,-9.44732e-08,-2.76591e-08,0.971116,0.000446289,-1.7745e-07,2.92185e-08,0.971562,0.000446022,-8.97948e-08,-2.96104e-08,0.972008,0.000445753,-1.78626e-07,2.96185e-08,0.972454,0.000445485,-8.97706e-08,-2.92588e-08,0.972899,0.000445218,-1.77547e-07,2.78123e-08,0.973344,0.000444946,-9.41103e-08,-2.23856e-08,0.973789,0.000444691,-1.61267e-07,2.12559e-09,0.974233,0.000444374,-1.5489e-07,1.38833e-08,0.974678,0.000444106,-1.13241e-07,1.94591e-09,0.975122,0.000443886,-1.07403e-07,-2.16669e-08,0.975565,0.000443606,-1.72404e-07,2.5117e-08,0.976009,0.000443336,-9.70526e-08,-1.91963e-08,0.976452,0.000443085,-1.54642e-07,-7.93627e-09,0.976895,0.000442752,-1.7845e-07,5.09414e-08,0.977338,0.000442548,-2.56262e-08,-7.66201e-08,0.97778,0.000442266,-2.55486e-07,7.67249e-08,0.978222,0.000441986,-2.53118e-08,-5.14655e-08,0.978664,0.000441781,-1.79708e-07,9.92773e-09,0.979106,0.000441451,-1.49925e-07,1.17546e-08,0.979547,0.000441186,-1.14661e-07,2.65868e-09,0.979988,0.000440965,-1.06685e-07,-2.23893e-08,0.980429,0.000440684,-1.73853e-07,2.72939e-08,0.980869,0.000440419,-9.19716e-08,-2.71816e-08,0.98131,0.000440153,-1.73516e-07,2.18278e-08,0.98175,0.000439872,-1.08033e-07,-5.24833e-10,0.982189,0.000439654,-1.09607e-07,-1.97284e-08,0.982629,0.000439376,-1.68793e-07,1.98339e-08,0.983068,0.000439097,-1.09291e-07,-2.62901e-12,0.983507,0.000438879,-1.09299e-07,-1.98234e-08,0.983946,0.000438601,-1.68769e-07,1.96916e-08,0.984384,0.000438322,-1.09694e-07,6.6157e-10,0.984823,0.000438105,-1.0771e-07,-2.23379e-08,0.985261,0.000437823,-1.74723e-07,2.90855e-08,0.985698,0.00043756,-8.74669e-08,-3.43992e-08,0.986136,0.000437282,-1.90665e-07,4.89068e-08,0.986573,0.000437048,-4.39442e-08,-4.20188e-08,0.98701,0.000436834,-1.7e-07,-4.11073e-11,0.987446,0.000436494,-1.70124e-07,4.21832e-08,0.987883,0.00043628,-4.35742e-08,-4.94824e-08,0.988319,0.000436044,-1.92021e-07,3.6537e-08,0.988755,0.00043577,-8.24102e-08,-3.70611e-08,0.989191,0.000435494,-1.93593e-07,5.21026e-08,0.989626,0.000435263,-3.72855e-08,-5.21402e-08,0.990061,0.000435032,-1.93706e-07,3.7249e-08,0.990496,0.000434756,-8.19592e-08,-3.72512e-08,0.990931,0.000434481,-1.93713e-07,5.21511e-08,0.991365,0.00043425,-3.72595e-08,-5.21439e-08,0.991799,0.000434019,-1.93691e-07,3.72152e-08,0.992233,0.000433743,-8.20456e-08,-3.71123e-08,0.992667,0.000433468,-1.93382e-07,5.16292e-08,0.9931,0.000433236,-3.84947e-08,-5.01953e-08,0.993533,0.000433008,-1.89081e-07,2.99427e-08,0.993966,0.00043272,-9.92525e-08,-9.9708e-09,0.994399,0.000432491,-1.29165e-07,9.94051e-09,0.994831,0.000432263,-9.93434e-08,-2.97912e-08,0.995263,0.000431975,-1.88717e-07,4.96198e-08,0.995695,0.000431746,-3.98578e-08,-4.94785e-08,0.996127,0.000431518,-1.88293e-07,2.9085e-08,0.996558,0.000431229,-1.01038e-07,-7.25675e-09,0.996989,0.000431005,-1.22809e-07,-5.79945e-11,0.99742,0.000430759,-1.22983e-07,7.48873e-09,0.997851,0.000430536,-1.00516e-07,-2.98969e-08,0.998281,0.000430245,-1.90207e-07,5.24942e-08,0.998711,0.000430022,-3.27246e-08,-6.08706e-08,0.999141,0.000429774,-2.15336e-07,7.17788e-08,0.999571,0.000429392,0.,0.}; + + template + __device__ __forceinline__ void Lab2RGBConvert_f(const T& src, D& dst) + { + const float lThresh = 0.008856f * 903.3f; + const float fThresh = 7.787f * 0.008856f + 16.0f / 116.0f; + + float Y, fy; + + if (src.x <= lThresh) + { + Y = src.x / 903.3f; + fy = 7.787f * Y + 16.0f / 116.0f; + } + else + { + fy = (src.x + 16.0f) / 116.0f; + Y = fy * fy * fy; + } + + float X = src.y / 500.0f + fy; + float Z = fy - src.z / 200.0f; + + if (X <= fThresh) + X = (X - 16.0f / 116.0f) / 7.787f; + else + X = X * X * X; + + if (Z <= fThresh) + Z = (Z - 16.0f / 116.0f) / 7.787f; + else + Z = Z * Z * Z; + + float B = 0.052891f * X - 0.204043f * Y + 1.151152f * Z; + float G = -0.921235f * X + 1.875991f * Y + 0.045244f * Z; + float R = 3.079933f * X - 1.537150f * Y - 0.542782f * Z; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + } + + dst.x = blueIdx == 0 ? B : R; + dst.y = G; + dst.z = blueIdx == 0 ? R : B; + setAlpha(dst, ColorChannel::max()); + } + + template + __device__ __forceinline__ void Lab2RGBConvert_b(const T& src, D& dst) + { + float3 srcf, dstf; + + srcf.x = src.x * (100.f / 255.f); + srcf.y = src.y - 128; + srcf.z = src.z - 128; + + Lab2RGBConvert_f(srcf, dstf); + + dst.x = saturate_cast(dstf.x * 255.f); + dst.y = saturate_cast(dstf.y * 255.f); + dst.z = saturate_cast(dstf.z * 255.f); + setAlpha(dst, ColorChannel::max()); + } + + template struct Lab2RGB; + template + struct Lab2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + Lab2RGBConvert_b(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Lab2RGB() {} + __host__ __device__ __forceinline__ Lab2RGB(const Lab2RGB&) {} + }; + template + struct Lab2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + Lab2RGBConvert_f(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Lab2RGB() {} + __host__ __device__ __forceinline__ Lab2RGB(const Lab2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Lab2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + +///////////////////////////////////// RGB <-> Luv ///////////////////////////////////// + + namespace color_detail + { + __constant__ float c_LabCbrtTab[] = {0.137931,0.0114066,0.,1.18859e-07,0.149338,0.011407,3.56578e-07,-5.79396e-07,0.160745,0.0114059,-1.38161e-06,2.16892e-06,0.172151,0.0114097,5.12516e-06,-8.0814e-06,0.183558,0.0113957,-1.9119e-05,3.01567e-05,0.194965,0.0114479,7.13509e-05,-0.000112545,0.206371,0.011253,-0.000266285,-0.000106493,0.217252,0.0104009,-0.000585765,7.32149e-05,0.22714,0.00944906,-0.00036612,1.21917e-05,0.236235,0.0087534,-0.000329545,2.01753e-05,0.244679,0.00815483,-0.000269019,1.24435e-05,0.252577,0.00765412,-0.000231689,1.05618e-05,0.26001,0.00722243,-0.000200003,8.26662e-06,0.267041,0.00684723,-0.000175203,6.76746e-06,0.27372,0.00651712,-0.000154901,5.61192e-06,0.280088,0.00622416,-0.000138065,4.67009e-06,0.286179,0.00596204,-0.000124055,3.99012e-06,0.292021,0.0057259,-0.000112085,3.36032e-06,0.297638,0.00551181,-0.000102004,2.95338e-06,0.30305,0.00531666,-9.31435e-05,2.52875e-06,0.308277,0.00513796,-8.55572e-05,2.22022e-06,0.313331,0.00497351,-7.88966e-05,1.97163e-06,0.318228,0.00482163,-7.29817e-05,1.7248e-06,0.322978,0.00468084,-6.78073e-05,1.55998e-06,0.327593,0.0045499,-6.31274e-05,1.36343e-06,0.332081,0.00442774,-5.90371e-05,1.27136e-06,0.336451,0.00431348,-5.5223e-05,1.09111e-06,0.34071,0.00420631,-5.19496e-05,1.0399e-06,0.344866,0.00410553,-4.88299e-05,9.18347e-07,0.348923,0.00401062,-4.60749e-05,8.29942e-07,0.352889,0.00392096,-4.35851e-05,7.98478e-07,0.356767,0.00383619,-4.11896e-05,6.84917e-07,0.360562,0.00375586,-3.91349e-05,6.63976e-07,0.36428,0.00367959,-3.7143e-05,5.93086e-07,0.367923,0.00360708,-3.53637e-05,5.6976e-07,0.371495,0.00353806,-3.36544e-05,4.95533e-07,0.375,0.00347224,-3.21678e-05,4.87951e-07,0.378441,0.00340937,-3.0704e-05,4.4349e-07,0.38182,0.00334929,-2.93735e-05,4.20297e-07,0.38514,0.0032918,-2.81126e-05,3.7872e-07,0.388404,0.00323671,-2.69764e-05,3.596e-07,0.391614,0.00318384,-2.58976e-05,3.5845e-07,0.394772,0.00313312,-2.48223e-05,2.92765e-07,0.397881,0.00308435,-2.3944e-05,3.18232e-07,0.400942,0.00303742,-2.29893e-05,2.82046e-07,0.403957,0.00299229,-2.21432e-05,2.52315e-07,0.406927,0.00294876,-2.13862e-05,2.58416e-07,0.409855,0.00290676,-2.0611e-05,2.33939e-07,0.412741,0.00286624,-1.99092e-05,2.36342e-07,0.415587,0.00282713,-1.92001e-05,1.916e-07,0.418396,0.00278931,-1.86253e-05,2.1915e-07,0.421167,0.00275271,-1.79679e-05,1.83498e-07,0.423901,0.00271733,-1.74174e-05,1.79343e-07,0.426602,0.00268303,-1.68794e-05,1.72013e-07,0.429268,0.00264979,-1.63633e-05,1.75686e-07,0.431901,0.00261759,-1.58363e-05,1.3852e-07,0.434503,0.00258633,-1.54207e-05,1.64304e-07,0.437074,0.00255598,-1.49278e-05,1.28136e-07,0.439616,0.00252651,-1.45434e-05,1.57618e-07,0.442128,0.0024979,-1.40705e-05,1.0566e-07,0.444612,0.00247007,-1.37535e-05,1.34998e-07,0.447068,0.00244297,-1.33485e-05,1.29207e-07,0.449498,0.00241666,-1.29609e-05,9.32347e-08,0.451902,0.00239102,-1.26812e-05,1.23703e-07,0.45428,0.00236603,-1.23101e-05,9.74072e-08,0.456634,0.0023417,-1.20179e-05,1.12518e-07,0.458964,0.002318,-1.16803e-05,7.83681e-08,0.46127,0.00229488,-1.14452e-05,1.10452e-07,0.463554,0.00227232,-1.11139e-05,7.58719e-08,0.465815,0.00225032,-1.08863e-05,9.2699e-08,0.468055,0.00222882,-1.06082e-05,8.97738e-08,0.470273,0.00220788,-1.03388e-05,5.4845e-08,0.47247,0.00218736,-1.01743e-05,1.0808e-07,0.474648,0.00216734,-9.85007e-06,4.9277e-08,0.476805,0.00214779,-9.70224e-06,8.22408e-08,0.478943,0.00212863,-9.45551e-06,6.87942e-08,0.481063,0.00210993,-9.24913e-06,5.98144e-08,0.483163,0.00209161,-9.06969e-06,7.93789e-08,0.485246,0.00207371,-8.83155e-06,3.99032e-08,0.487311,0.00205616,-8.71184e-06,8.88325e-08,0.489358,0.002039,-8.44534e-06,2.20004e-08,0.491389,0.00202218,-8.37934e-06,9.13872e-08,0.493403,0.0020057,-8.10518e-06,2.96829e-08,0.495401,0.00198957,-8.01613e-06,5.81028e-08,0.497382,0.00197372,-7.84183e-06,6.5731e-08,0.499348,0.00195823,-7.64463e-06,3.66019e-08,0.501299,0.00194305,-7.53483e-06,2.62811e-08,0.503234,0.00192806,-7.45598e-06,9.66907e-08,0.505155,0.00191344,-7.16591e-06,4.18928e-09,0.507061,0.00189912,-7.15334e-06,6.53665e-08,0.508953,0.00188501,-6.95724e-06,3.23686e-08,0.510831,0.00187119,-6.86014e-06,4.35774e-08,0.512696,0.0018576,-6.72941e-06,3.17406e-08,0.514547,0.00184424,-6.63418e-06,6.78785e-08,0.516384,0.00183117,-6.43055e-06,-5.23126e-09,0.518209,0.0018183,-6.44624e-06,7.22562e-08,0.520021,0.00180562,-6.22947e-06,1.42292e-08,0.52182,0.0017932,-6.18679e-06,4.9641e-08,0.523607,0.00178098,-6.03786e-06,2.56259e-08,0.525382,0.00176898,-5.96099e-06,2.66696e-08,0.527145,0.00175714,-5.88098e-06,4.65094e-08,0.528897,0.00174552,-5.74145e-06,2.57114e-08,0.530637,0.00173411,-5.66431e-06,2.94588e-08,0.532365,0.00172287,-5.57594e-06,3.52667e-08,0.534082,0.00171182,-5.47014e-06,8.28868e-09,0.535789,0.00170091,-5.44527e-06,5.07871e-08,0.537484,0.00169017,-5.29291e-06,2.69817e-08,0.539169,0.00167967,-5.21197e-06,2.01009e-08,0.540844,0.0016693,-5.15166e-06,1.18237e-08,0.542508,0.00165903,-5.11619e-06,5.18135e-08,0.544162,0.00164896,-4.96075e-06,1.9341e-08,0.545806,0.00163909,-4.90273e-06,-9.96867e-09,0.54744,0.00162926,-4.93263e-06,8.01382e-08,0.549064,0.00161963,-4.69222e-06,-1.25601e-08,0.550679,0.00161021,-4.7299e-06,2.97067e-08,0.552285,0.00160084,-4.64078e-06,1.29426e-08,0.553881,0.0015916,-4.60195e-06,3.77327e-08,0.555468,0.00158251,-4.48875e-06,1.49412e-08,0.557046,0.00157357,-4.44393e-06,2.17118e-08,0.558615,0.00156475,-4.3788e-06,1.74206e-08,0.560176,0.00155605,-4.32653e-06,2.78152e-08,0.561727,0.00154748,-4.24309e-06,-9.47239e-09,0.563271,0.00153896,-4.27151e-06,6.9679e-08,0.564805,0.00153063,-4.06247e-06,-3.08246e-08,0.566332,0.00152241,-4.15494e-06,5.36188e-08,0.56785,0.00151426,-3.99409e-06,-4.83594e-09,0.56936,0.00150626,-4.00859e-06,2.53293e-08,0.570863,0.00149832,-3.93261e-06,2.27286e-08,0.572357,0.00149052,-3.86442e-06,2.96541e-09,0.573844,0.0014828,-3.85552e-06,2.50147e-08,0.575323,0.00147516,-3.78048e-06,1.61842e-08,0.576794,0.00146765,-3.73193e-06,2.94582e-08,0.578258,0.00146028,-3.64355e-06,-1.48076e-08,0.579715,0.00145295,-3.68798e-06,2.97724e-08,0.581164,0.00144566,-3.59866e-06,1.49272e-08,0.582606,0.00143851,-3.55388e-06,2.97285e-08,0.584041,0.00143149,-3.46469e-06,-1.46323e-08,0.585469,0.00142451,-3.50859e-06,2.88004e-08,0.58689,0.00141758,-3.42219e-06,1.864e-08,0.588304,0.00141079,-3.36627e-06,1.58482e-08,0.589712,0.00140411,-3.31872e-06,-2.24279e-08,0.591112,0.00139741,-3.38601e-06,7.38639e-08,0.592507,0.00139085,-3.16441e-06,-3.46088e-08,0.593894,0.00138442,-3.26824e-06,4.96675e-09,0.595275,0.0013779,-3.25334e-06,7.4346e-08,0.59665,0.00137162,-3.0303e-06,-6.39319e-08,0.598019,0.00136536,-3.2221e-06,6.21725e-08,0.599381,0.00135911,-3.03558e-06,-5.94423e-09,0.600737,0.00135302,-3.05341e-06,2.12091e-08,0.602087,0.00134697,-2.98979e-06,-1.92876e-08,0.603431,0.00134094,-3.04765e-06,5.5941e-08,0.604769,0.00133501,-2.87983e-06,-2.56622e-08,0.606101,0.00132917,-2.95681e-06,4.67078e-08,0.607427,0.0013234,-2.81669e-06,-4.19592e-08,0.608748,0.00131764,-2.94257e-06,6.15243e-08,0.610062,0.00131194,-2.75799e-06,-2.53244e-08,0.611372,0.00130635,-2.83397e-06,3.97739e-08,0.612675,0.0013008,-2.71465e-06,-1.45618e-08,0.613973,0.00129533,-2.75833e-06,1.84733e-08,0.615266,0.00128986,-2.70291e-06,2.73606e-10,0.616553,0.00128446,-2.70209e-06,4.00367e-08,0.617835,0.00127918,-2.58198e-06,-4.12113e-08,0.619111,0.00127389,-2.70561e-06,6.52039e-08,0.620383,0.00126867,-2.51e-06,-4.07901e-08,0.621649,0.00126353,-2.63237e-06,3.83516e-08,0.62291,0.00125838,-2.51732e-06,6.59315e-09,0.624166,0.00125337,-2.49754e-06,-5.11939e-09,0.625416,0.00124836,-2.5129e-06,1.38846e-08,0.626662,0.00124337,-2.47124e-06,9.18514e-09,0.627903,0.00123846,-2.44369e-06,8.97952e-09,0.629139,0.0012336,-2.41675e-06,1.45012e-08,0.63037,0.00122881,-2.37325e-06,-7.37949e-09,0.631597,0.00122404,-2.39538e-06,1.50169e-08,0.632818,0.00121929,-2.35033e-06,6.91648e-09,0.634035,0.00121461,-2.32958e-06,1.69219e-08,0.635248,0.00121,-2.27882e-06,-1.49997e-08,0.636455,0.0012054,-2.32382e-06,4.30769e-08,0.637659,0.00120088,-2.19459e-06,-3.80986e-08,0.638857,0.00119638,-2.30888e-06,4.97134e-08,0.640051,0.00119191,-2.15974e-06,-4.15463e-08,0.641241,0.00118747,-2.28438e-06,5.68667e-08,0.642426,0.00118307,-2.11378e-06,-7.10641e-09,0.643607,0.00117882,-2.1351e-06,-2.8441e-08,0.644784,0.00117446,-2.22042e-06,6.12658e-08,0.645956,0.00117021,-2.03663e-06,-3.78083e-08,0.647124,0.00116602,-2.15005e-06,3.03627e-08,0.648288,0.00116181,-2.05896e-06,-2.40379e-08,0.649448,0.00115762,-2.13108e-06,6.57887e-08,0.650603,0.00115356,-1.93371e-06,-6.03028e-08,0.651755,0.00114951,-2.11462e-06,5.62134e-08,0.652902,0.00114545,-1.94598e-06,-4.53417e-08,0.654046,0.00114142,-2.082e-06,6.55489e-08,0.655185,0.00113745,-1.88536e-06,-3.80396e-08,0.656321,0.00113357,-1.99948e-06,2.70049e-08,0.657452,0.00112965,-1.91846e-06,-1.03755e-08,0.65858,0.00112578,-1.94959e-06,1.44973e-08,0.659704,0.00112192,-1.9061e-06,1.1991e-08,0.660824,0.00111815,-1.87012e-06,-2.85634e-09,0.66194,0.0011144,-1.87869e-06,-5.65782e-10,0.663053,0.00111064,-1.88039e-06,5.11947e-09,0.664162,0.0011069,-1.86503e-06,3.96924e-08,0.665267,0.00110328,-1.74595e-06,-4.46795e-08,0.666368,0.00109966,-1.87999e-06,1.98161e-08,0.667466,0.00109596,-1.82054e-06,2.502e-08,0.66856,0.00109239,-1.74548e-06,-6.86593e-10,0.669651,0.0010889,-1.74754e-06,-2.22739e-08,0.670738,0.00108534,-1.81437e-06,3.01776e-08,0.671821,0.0010818,-1.72383e-06,2.07732e-08,0.672902,0.00107841,-1.66151e-06,-5.36658e-08,0.673978,0.00107493,-1.82251e-06,7.46802e-08,0.675051,0.00107151,-1.59847e-06,-6.62411e-08,0.676121,0.00106811,-1.79719e-06,7.10748e-08,0.677188,0.00106473,-1.58397e-06,-3.92441e-08,0.678251,0.00106145,-1.7017e-06,2.62973e-08,0.679311,0.00105812,-1.62281e-06,-6.34035e-09,0.680367,0.00105486,-1.64183e-06,-9.36249e-10,0.68142,0.00105157,-1.64464e-06,1.00854e-08,0.68247,0.00104831,-1.61438e-06,2.01995e-08,0.683517,0.00104514,-1.55378e-06,-3.1279e-08,0.68456,0.00104194,-1.64762e-06,4.53114e-08,0.685601,0.00103878,-1.51169e-06,-3.07573e-08,0.686638,0.00103567,-1.60396e-06,1.81133e-08,0.687672,0.00103251,-1.54962e-06,1.79085e-08,0.688703,0.00102947,-1.49589e-06,-3.01428e-08,0.689731,0.00102639,-1.58632e-06,4.30583e-08,0.690756,0.00102334,-1.45715e-06,-2.28814e-08,0.691778,0.00102036,-1.52579e-06,-1.11373e-08,0.692797,0.00101727,-1.5592e-06,6.74305e-08,0.693812,0.00101436,-1.35691e-06,-7.97709e-08,0.694825,0.0010114,-1.59622e-06,7.28391e-08,0.695835,0.00100843,-1.37771e-06,-3.27715e-08,0.696842,0.00100558,-1.47602e-06,-1.35807e-09,0.697846,0.00100262,-1.48009e-06,3.82037e-08,0.698847,0.000999775,-1.36548e-06,-3.22474e-08,0.699846,0.000996948,-1.46223e-06,3.11809e-08,0.700841,0.000994117,-1.36868e-06,-3.28714e-08,0.701834,0.000991281,-1.4673e-06,4.07001e-08,0.702824,0.000988468,-1.3452e-06,-1.07197e-08,0.703811,0.000985746,-1.37736e-06,2.17866e-09,0.704795,0.000982998,-1.37082e-06,2.00521e-09,0.705777,0.000980262,-1.3648e-06,-1.01996e-08,0.706756,0.000977502,-1.3954e-06,3.87931e-08,0.707732,0.000974827,-1.27902e-06,-2.57632e-08,0.708706,0.000972192,-1.35631e-06,4.65513e-09,0.709676,0.000969493,-1.34235e-06,7.14257e-09,0.710645,0.00096683,-1.32092e-06,2.63791e-08,0.71161,0.000964267,-1.24178e-06,-5.30543e-08,0.712573,0.000961625,-1.40095e-06,6.66289e-08,0.713533,0.000959023,-1.20106e-06,-3.46474e-08,0.714491,0.000956517,-1.305e-06,1.23559e-08,0.715446,0.000953944,-1.26793e-06,-1.47763e-08,0.716399,0.000951364,-1.31226e-06,4.67494e-08,0.717349,0.000948879,-1.17201e-06,-5.3012e-08,0.718297,0.000946376,-1.33105e-06,4.60894e-08,0.719242,0.000943852,-1.19278e-06,-1.21366e-08,0.720185,0.00094143,-1.22919e-06,2.45673e-09,0.721125,0.000938979,-1.22182e-06,2.30966e-09,0.722063,0.000936543,-1.21489e-06,-1.16954e-08,0.722998,0.000934078,-1.24998e-06,4.44718e-08,0.723931,0.000931711,-1.11656e-06,-4.69823e-08,0.724861,0.000929337,-1.25751e-06,2.4248e-08,0.725789,0.000926895,-1.18477e-06,9.5949e-09,0.726715,0.000924554,-1.15598e-06,-3.02286e-09,0.727638,0.000922233,-1.16505e-06,2.49649e-09,0.72856,0.00091991,-1.15756e-06,-6.96321e-09,0.729478,0.000917575,-1.17845e-06,2.53564e-08,0.730395,0.000915294,-1.10238e-06,-3.48578e-08,0.731309,0.000912984,-1.20695e-06,5.44704e-08,0.732221,0.000910734,-1.04354e-06,-6.38144e-08,0.73313,0.000908455,-1.23499e-06,8.15781e-08,0.734038,0.00090623,-9.90253e-07,-8.3684e-08,0.734943,0.000903999,-1.2413e-06,7.43441e-08,0.735846,0.000901739,-1.01827e-06,-3.48787e-08,0.736746,0.000899598,-1.12291e-06,5.56596e-09,0.737645,0.000897369,-1.10621e-06,1.26148e-08,0.738541,0.000895194,-1.06837e-06,3.57935e-09,0.739435,0.000893068,-1.05763e-06,-2.69322e-08,0.740327,0.000890872,-1.13842e-06,4.45448e-08,0.741217,0.000888729,-1.00479e-06,-3.20376e-08,0.742105,0.000886623,-1.1009e-06,2.40011e-08,0.74299,0.000884493,-1.0289e-06,-4.36209e-09,0.743874,0.000882422,-1.04199e-06,-6.55268e-09,0.744755,0.000880319,-1.06164e-06,3.05728e-08,0.745634,0.000878287,-9.69926e-07,-5.61338e-08,0.746512,0.000876179,-1.13833e-06,7.4753e-08,0.747387,0.000874127,-9.14068e-07,-6.40644e-08,0.74826,0.000872106,-1.10626e-06,6.22955e-08,0.749131,0.000870081,-9.19375e-07,-6.59083e-08,0.75,0.000868044,-1.1171e-06,8.21284e-08,0.750867,0.000866056,-8.70714e-07,-8.37915e-08,0.751732,0.000864064,-1.12209e-06,7.42237e-08,0.752595,0.000862042,-8.99418e-07,-3.42894e-08,0.753456,0.00086014,-1.00229e-06,3.32955e-09,0.754315,0.000858146,-9.92297e-07,2.09712e-08,0.755173,0.000856224,-9.29384e-07,-2.76096e-08,0.756028,0.000854282,-1.01221e-06,2.98627e-08,0.756881,0.000852348,-9.22625e-07,-3.22365e-08,0.757733,0.000850406,-1.01933e-06,3.94786e-08,0.758582,0.000848485,-9.00898e-07,-6.46833e-09,0.75943,0.000846664,-9.20303e-07,-1.36052e-08,0.760275,0.000844783,-9.61119e-07,1.28447e-09,0.761119,0.000842864,-9.57266e-07,8.4674e-09,0.761961,0.000840975,-9.31864e-07,2.44506e-08,0.762801,0.000839185,-8.58512e-07,-4.6665e-08,0.763639,0.000837328,-9.98507e-07,4.30001e-08,0.764476,0.00083546,-8.69507e-07,-6.12609e-09,0.76531,0.000833703,-8.87885e-07,-1.84959e-08,0.766143,0.000831871,-9.43372e-07,2.05052e-08,0.766974,0.000830046,-8.81857e-07,-3.92026e-09,0.767803,0.000828271,-8.93618e-07,-4.82426e-09,0.768631,0.000826469,-9.0809e-07,2.32172e-08,0.769456,0.000824722,-8.38439e-07,-2.84401e-08,0.77028,0.00082296,-9.23759e-07,3.09386e-08,0.771102,0.000821205,-8.30943e-07,-3.57099e-08,0.771922,0.000819436,-9.38073e-07,5.22963e-08,0.772741,0.000817717,-7.81184e-07,-5.42658e-08,0.773558,0.000815992,-9.43981e-07,4.55579e-08,0.774373,0.000814241,-8.07308e-07,-8.75656e-09,0.775186,0.0008126,-8.33578e-07,-1.05315e-08,0.775998,0.000810901,-8.65172e-07,-8.72188e-09,0.776808,0.000809145,-8.91338e-07,4.54191e-08,0.777616,0.000807498,-7.5508e-07,-5.37454e-08,0.778423,0.000805827,-9.16317e-07,5.03532e-08,0.779228,0.000804145,-7.65257e-07,-2.84584e-08,0.780031,0.000802529,-8.50632e-07,3.87579e-09,0.780833,0.00080084,-8.39005e-07,1.29552e-08,0.781633,0.0007992,-8.00139e-07,3.90804e-09,0.782432,0.000797612,-7.88415e-07,-2.85874e-08,0.783228,0.000795949,-8.74177e-07,5.0837e-08,0.784023,0.000794353,-7.21666e-07,-5.55513e-08,0.784817,0.000792743,-8.8832e-07,5.21587e-08,0.785609,0.000791123,-7.31844e-07,-3.38744e-08,0.786399,0.000789558,-8.33467e-07,2.37342e-08,0.787188,0.000787962,-7.62264e-07,-1.45775e-09,0.787975,0.000786433,-7.66638e-07,-1.79034e-08,0.788761,0.000784846,-8.20348e-07,1.34665e-08,0.789545,0.000783246,-7.79948e-07,2.3642e-08,0.790327,0.000781757,-7.09022e-07,-4.84297e-08,0.791108,0.000780194,-8.54311e-07,5.08674e-08,0.791888,0.000778638,-7.01709e-07,-3.58303e-08,0.792666,0.000777127,-8.092e-07,3.28493e-08,0.793442,0.000775607,-7.10652e-07,-3.59624e-08,0.794217,0.000774078,-8.1854e-07,5.13959e-08,0.79499,0.000772595,-6.64352e-07,-5.04121e-08,0.795762,0.000771115,-8.15588e-07,3.10431e-08,0.796532,0.000769577,-7.22459e-07,-1.41557e-08,0.797301,0.00076809,-7.64926e-07,2.55795e-08,0.798069,0.000766636,-6.88187e-07,-2.85578e-08,0.798835,0.000765174,-7.73861e-07,2.90472e-08,0.799599,0.000763714,-6.86719e-07,-2.80262e-08,0.800362,0.000762256,-7.70798e-07,2.34531e-08,0.801123,0.000760785,-7.00438e-07,-6.18144e-09,0.801884,0.000759366,-7.18983e-07,1.27263e-09,0.802642,0.000757931,-7.15165e-07,1.09101e-09,0.803399,0.000756504,-7.11892e-07,-5.63675e-09,0.804155,0.000755064,-7.28802e-07,2.14559e-08,0.80491,0.00075367,-6.64434e-07,-2.05821e-08,0.805663,0.00075228,-7.26181e-07,1.26812e-09,0.806414,0.000750831,-7.22377e-07,1.55097e-08,0.807164,0.000749433,-6.75848e-07,-3.70216e-09,0.807913,0.00074807,-6.86954e-07,-7.0105e-10,0.80866,0.000746694,-6.89057e-07,6.5063e-09,0.809406,0.000745336,-6.69538e-07,-2.53242e-08,0.810151,0.000743921,-7.45511e-07,3.51858e-08,0.810894,0.000742535,-6.39953e-07,3.79034e-09,0.811636,0.000741267,-6.28582e-07,-5.03471e-08,0.812377,0.000739858,-7.79624e-07,7.83886e-08,0.813116,0.000738534,-5.44458e-07,-8.43935e-08,0.813854,0.000737192,-7.97638e-07,8.03714e-08,0.81459,0.000735838,-5.56524e-07,-5.82784e-08,0.815325,0.00073455,-7.31359e-07,3.35329e-08,0.816059,0.000733188,-6.3076e-07,-1.62486e-08,0.816792,0.000731878,-6.79506e-07,3.14614e-08,0.817523,0.000730613,-5.85122e-07,-4.99925e-08,0.818253,0.000729293,-7.35099e-07,4.92994e-08,0.818982,0.000727971,-5.87201e-07,-2.79959e-08,0.819709,0.000726712,-6.71189e-07,3.07959e-09,0.820435,0.000725379,-6.6195e-07,1.56777e-08,0.82116,0.000724102,-6.14917e-07,-6.18564e-09,0.821883,0.000722854,-6.33474e-07,9.06488e-09,0.822606,0.000721614,-6.06279e-07,-3.00739e-08,0.823327,0.000720311,-6.96501e-07,5.16262e-08,0.824046,0.000719073,-5.41623e-07,-5.72214e-08,0.824765,0.000717818,-7.13287e-07,5.80503e-08,0.825482,0.000716566,-5.39136e-07,-5.57703e-08,0.826198,0.00071532,-7.06447e-07,4.58215e-08,0.826912,0.000714045,-5.68983e-07,-8.30636e-09,0.827626,0.000712882,-5.93902e-07,-1.25961e-08,0.828338,0.000711656,-6.3169e-07,-9.13985e-10,0.829049,0.00071039,-6.34432e-07,1.62519e-08,0.829759,0.00070917,-5.85676e-07,-4.48904e-09,0.830468,0.000707985,-5.99143e-07,1.70418e-09,0.831175,0.000706792,-5.9403e-07,-2.32768e-09,0.831881,0.000705597,-6.01014e-07,7.60648e-09,0.832586,0.000704418,-5.78194e-07,-2.80982e-08,0.83329,0.000703177,-6.62489e-07,4.51817e-08,0.833993,0.000701988,-5.26944e-07,-3.34192e-08,0.834694,0.000700834,-6.27201e-07,2.88904e-08,0.835394,0.000699666,-5.4053e-07,-2.25378e-08,0.836093,0.000698517,-6.08143e-07,1.65589e-09,0.836791,0.000697306,-6.03176e-07,1.59142e-08,0.837488,0.000696147,-5.55433e-07,-5.70801e-09,0.838184,0.000695019,-5.72557e-07,6.91792e-09,0.838878,0.000693895,-5.51803e-07,-2.19637e-08,0.839571,0.000692725,-6.17694e-07,2.13321e-08,0.840263,0.000691554,-5.53698e-07,-3.75996e-09,0.840954,0.000690435,-5.64978e-07,-6.29219e-09,0.841644,0.000689287,-5.83855e-07,2.89287e-08,0.842333,0.000688206,-4.97068e-07,-4.98181e-08,0.843021,0.000687062,-6.46523e-07,5.11344e-08,0.843707,0.000685922,-4.9312e-07,-3.55102e-08,0.844393,0.00068483,-5.9965e-07,3.13019e-08,0.845077,0.000683724,-5.05745e-07,-3.00925e-08,0.84576,0.000682622,-5.96022e-07,2.94636e-08,0.846442,0.000681519,-5.07631e-07,-2.81572e-08,0.847123,0.000680419,-5.92103e-07,2.35606e-08,0.847803,0.000679306,-5.21421e-07,-6.48045e-09,0.848482,0.000678243,-5.40863e-07,2.36124e-09,0.849159,0.000677169,-5.33779e-07,-2.96461e-09,0.849836,0.000676092,-5.42673e-07,9.49728e-09,0.850512,0.000675035,-5.14181e-07,-3.50245e-08,0.851186,0.000673902,-6.19254e-07,7.09959e-08,0.851859,0.000672876,-4.06267e-07,-7.01453e-08,0.852532,0.000671853,-6.16703e-07,3.07714e-08,0.853203,0.000670712,-5.24388e-07,6.66423e-09,0.853873,0.000669684,-5.04396e-07,2.17629e-09,0.854542,0.000668681,-4.97867e-07,-1.53693e-08,0.855211,0.000667639,-5.43975e-07,-3.03752e-10,0.855878,0.000666551,-5.44886e-07,1.65844e-08,0.856544,0.000665511,-4.95133e-07,-6.42907e-09,0.857209,0.000664501,-5.1442e-07,9.13195e-09,0.857873,0.0006635,-4.87024e-07,-3.00987e-08,0.858536,0.000662435,-5.7732e-07,5.16584e-08,0.859198,0.000661436,-4.22345e-07,-5.73255e-08,0.859859,0.000660419,-5.94322e-07,5.84343e-08,0.860518,0.000659406,-4.19019e-07,-5.72022e-08,0.861177,0.000658396,-5.90626e-07,5.11653e-08,0.861835,0.000657368,-4.3713e-07,-2.82495e-08,0.862492,0.000656409,-5.21878e-07,2.22788e-09,0.863148,0.000655372,-5.15195e-07,1.9338e-08,0.863803,0.0006544,-4.5718e-07,-1.99754e-08,0.864457,0.000653425,-5.17107e-07,9.59024e-10,0.86511,0.000652394,-5.1423e-07,1.61393e-08,0.865762,0.000651414,-4.65812e-07,-5.91149e-09,0.866413,0.000650465,-4.83546e-07,7.50665e-09,0.867063,0.00064952,-4.61026e-07,-2.4115e-08,0.867712,0.000648526,-5.33371e-07,2.93486e-08,0.86836,0.000647547,-4.45325e-07,-3.36748e-08,0.869007,0.000646555,-5.4635e-07,4.57461e-08,0.869653,0.0006456,-4.09112e-07,-3.01002e-08,0.870298,0.000644691,-4.99412e-07,1.50501e-08,0.870942,0.000643738,-4.54262e-07,-3.01002e-08,0.871585,0.000642739,-5.44563e-07,4.57461e-08,0.872228,0.000641787,-4.07324e-07,-3.36748e-08,0.872869,0.000640871,-5.08349e-07,2.93486e-08,0.873509,0.000639943,-4.20303e-07,-2.4115e-08,0.874149,0.00063903,-4.92648e-07,7.50655e-09,0.874787,0.000638067,-4.70128e-07,-5.91126e-09,0.875425,0.000637109,-4.87862e-07,1.61385e-08,0.876062,0.000636182,-4.39447e-07,9.61961e-10,0.876697,0.000635306,-4.36561e-07,-1.99863e-08,0.877332,0.000634373,-4.9652e-07,1.93785e-08,0.877966,0.000633438,-4.38384e-07,2.07697e-09,0.878599,0.000632567,-4.32153e-07,-2.76864e-08,0.879231,0.00063162,-5.15212e-07,4.90641e-08,0.879862,0.000630737,-3.6802e-07,-4.93606e-08,0.880493,0.000629852,-5.16102e-07,2.9169e-08,0.881122,0.000628908,-4.28595e-07,-7.71083e-09,0.881751,0.000628027,-4.51727e-07,1.6744e-09,0.882378,0.000627129,-4.46704e-07,1.01317e-09,0.883005,0.000626239,-4.43665e-07,-5.72703e-09,0.883631,0.000625334,-4.60846e-07,2.1895e-08,0.884255,0.000624478,-3.95161e-07,-2.22481e-08,0.88488,0.000623621,-4.61905e-07,7.4928e-09,0.885503,0.00062272,-4.39427e-07,-7.72306e-09,0.886125,0.000621818,-4.62596e-07,2.33995e-08,0.886746,0.000620963,-3.92398e-07,-2.62704e-08,0.887367,0.000620099,-4.71209e-07,2.20775e-08,0.887987,0.000619223,-4.04976e-07,-2.43496e-09,0.888605,0.000618406,-4.12281e-07,-1.23377e-08,0.889223,0.000617544,-4.49294e-07,-7.81876e-09,0.88984,0.000616622,-4.72751e-07,4.36128e-08,0.890457,0.000615807,-3.41912e-07,-4.7423e-08,0.891072,0.000614981,-4.84181e-07,2.68698e-08,0.891687,0.000614093,-4.03572e-07,-4.51384e-10,0.8923,0.000613285,-4.04926e-07,-2.50643e-08,0.892913,0.0006124,-4.80119e-07,4.11038e-08,0.893525,0.000611563,-3.56808e-07,-2.01414e-08,0.894136,0.000610789,-4.17232e-07,-2.01426e-08,0.894747,0.000609894,-4.7766e-07,4.11073e-08,0.895356,0.000609062,-3.54338e-07,-2.50773e-08,0.895965,0.000608278,-4.2957e-07,-4.02954e-10,0.896573,0.000607418,-4.30779e-07,2.66891e-08,0.89718,0.000606636,-3.50711e-07,-4.67489e-08,0.897786,0.000605795,-4.90958e-07,4.10972e-08,0.898391,0.000604936,-3.67666e-07,1.56948e-09,0.898996,0.000604205,-3.62958e-07,-4.73751e-08,0.8996,0.000603337,-5.05083e-07,6.87214e-08,0.900202,0.000602533,-2.98919e-07,-4.86966e-08,0.900805,0.000601789,-4.45009e-07,6.85589e-09,0.901406,0.00060092,-4.24441e-07,2.1273e-08,0.902007,0.000600135,-3.60622e-07,-3.23434e-08,0.902606,0.000599317,-4.57652e-07,4.84959e-08,0.903205,0.000598547,-3.12164e-07,-4.24309e-08,0.903803,0.000597795,-4.39457e-07,2.01844e-09,0.904401,0.000596922,-4.33402e-07,3.43571e-08,0.904997,0.000596159,-3.30331e-07,-2.02374e-08,0.905593,0.000595437,-3.91043e-07,-1.30123e-08,0.906188,0.000594616,-4.3008e-07,1.26819e-08,0.906782,0.000593794,-3.92034e-07,2.18894e-08,0.907376,0.000593076,-3.26366e-07,-4.06349e-08,0.907968,0.000592301,-4.4827e-07,2.1441e-08,0.90856,0.000591469,-3.83947e-07,1.44754e-08,0.909151,0.000590744,-3.40521e-07,-1.97379e-08,0.909742,0.000590004,-3.99735e-07,4.87161e-09,0.910331,0.000589219,-3.8512e-07,2.51532e-10,0.91092,0.00058845,-3.84366e-07,-5.87776e-09,0.911508,0.000587663,-4.01999e-07,2.32595e-08,0.912096,0.000586929,-3.3222e-07,-2.75554e-08,0.912682,0.000586182,-4.14887e-07,2.73573e-08,0.913268,0.000585434,-3.32815e-07,-2.22692e-08,0.913853,0.000584702,-3.99622e-07,2.11486e-09,0.914437,0.000583909,-3.93278e-07,1.38098e-08,0.915021,0.000583164,-3.51848e-07,2.25042e-09,0.915604,0.000582467,-3.45097e-07,-2.28115e-08,0.916186,0.000581708,-4.13531e-07,2.93911e-08,0.916767,0.000580969,-3.25358e-07,-3.51481e-08,0.917348,0.000580213,-4.30803e-07,5.15967e-08,0.917928,0.000579506,-2.76012e-07,-5.20296e-08,0.918507,0.000578798,-4.32101e-07,3.73124e-08,0.919085,0.000578046,-3.20164e-07,-3.76154e-08,0.919663,0.000577293,-4.3301e-07,5.35447e-08,0.92024,0.000576587,-2.72376e-07,-5.7354e-08,0.920816,0.000575871,-4.44438e-07,5.66621e-08,0.921391,0.000575152,-2.74452e-07,-5.00851e-08,0.921966,0.000574453,-4.24707e-07,2.4469e-08,0.92254,0.000573677,-3.513e-07,1.18138e-08,0.923114,0.000573009,-3.15859e-07,-1.21195e-08,0.923686,0.000572341,-3.52217e-07,-2.29403e-08,0.924258,0.000571568,-4.21038e-07,4.4276e-08,0.924829,0.000570859,-2.8821e-07,-3.49546e-08,0.9254,0.000570178,-3.93074e-07,3.59377e-08,0.92597,0.000569499,-2.85261e-07,-4.91915e-08,0.926539,0.000568781,-4.32835e-07,4.16189e-08,0.927107,0.00056804,-3.07979e-07,1.92523e-09,0.927675,0.00056743,-3.02203e-07,-4.93198e-08,0.928242,0.000566678,-4.50162e-07,7.61447e-08,0.928809,0.000566006,-2.21728e-07,-7.6445e-08,0.929374,0.000565333,-4.51063e-07,5.08216e-08,0.929939,0.000564583,-2.98599e-07,-7.63212e-09,0.930503,0.000563963,-3.21495e-07,-2.02931e-08,0.931067,0.000563259,-3.82374e-07,2.92001e-08,0.93163,0.000562582,-2.94774e-07,-3.69025e-08,0.932192,0.000561882,-4.05482e-07,5.88053e-08,0.932754,0.000561247,-2.29066e-07,-7.91094e-08,0.933315,0.000560552,-4.66394e-07,7.88184e-08,0.933875,0.000559856,-2.29939e-07,-5.73501e-08,0.934434,0.000559224,-4.01989e-07,3.13727e-08,0.934993,0.000558514,-3.07871e-07,-8.53611e-09,0.935551,0.000557873,-3.33479e-07,2.77175e-09,0.936109,0.000557214,-3.25164e-07,-2.55091e-09,0.936666,0.000556556,-3.32817e-07,7.43188e-09,0.937222,0.000555913,-3.10521e-07,-2.71766e-08,0.937778,0.00055521,-3.92051e-07,4.167e-08,0.938333,0.000554551,-2.67041e-07,-2.02941e-08,0.938887,0.000553956,-3.27923e-07,-2.00984e-08,0.93944,0.00055324,-3.88218e-07,4.10828e-08,0.939993,0.000552587,-2.6497e-07,-2.50237e-08,0.940546,0.000551982,-3.40041e-07,-5.92583e-10,0.941097,0.0005513,-3.41819e-07,2.7394e-08,0.941648,0.000550698,-2.59637e-07,-4.93788e-08,0.942199,0.000550031,-4.07773e-07,5.09119e-08,0.942748,0.000549368,-2.55038e-07,-3.50595e-08,0.943297,0.000548753,-3.60216e-07,2.97214e-08,0.943846,0.000548122,-2.71052e-07,-2.42215e-08,0.944394,0.000547507,-3.43716e-07,7.55985e-09,0.944941,0.000546842,-3.21037e-07,-6.01796e-09,0.945487,0.000546182,-3.3909e-07,1.65119e-08,0.946033,0.000545553,-2.89555e-07,-4.2498e-10,0.946578,0.000544973,-2.9083e-07,-1.4812e-08,0.947123,0.000544347,-3.35266e-07,6.83068e-11,0.947667,0.000543676,-3.35061e-07,1.45388e-08,0.94821,0.00054305,-2.91444e-07,1.38123e-09,0.948753,0.000542471,-2.87301e-07,-2.00637e-08,0.949295,0.000541836,-3.47492e-07,1.92688e-08,0.949837,0.000541199,-2.89685e-07,2.59298e-09,0.950378,0.000540628,-2.81906e-07,-2.96407e-08,0.950918,0.000539975,-3.70829e-07,5.63652e-08,0.951458,0.000539402,-2.01733e-07,-7.66107e-08,0.951997,0.000538769,-4.31565e-07,7.12638e-08,0.952535,0.00053812,-2.17774e-07,-2.96305e-08,0.953073,0.000537595,-3.06665e-07,-1.23464e-08,0.95361,0.000536945,-3.43704e-07,1.94114e-08,0.954147,0.000536316,-2.8547e-07,-5.69451e-09,0.954683,0.000535728,-3.02554e-07,3.36666e-09,0.955219,0.000535133,-2.92454e-07,-7.77208e-09,0.955753,0.000534525,-3.1577e-07,2.77216e-08,0.956288,0.000533976,-2.32605e-07,-4.35097e-08,0.956821,0.00053338,-3.63134e-07,2.7108e-08,0.957354,0.000532735,-2.8181e-07,-5.31772e-09,0.957887,0.000532156,-2.97764e-07,-5.83718e-09,0.958419,0.000531543,-3.15275e-07,2.86664e-08,0.95895,0.000530998,-2.29276e-07,-4.9224e-08,0.959481,0.000530392,-3.76948e-07,4.90201e-08,0.960011,0.000529785,-2.29887e-07,-2.76471e-08,0.96054,0.000529243,-3.12829e-07,1.96385e-09,0.961069,0.000528623,-3.06937e-07,1.97917e-08,0.961598,0.000528068,-2.47562e-07,-2.15261e-08,0.962125,0.000527508,-3.1214e-07,6.70795e-09,0.962653,0.000526904,-2.92016e-07,-5.30573e-09,0.963179,0.000526304,-3.07934e-07,1.4515e-08,0.963705,0.000525732,-2.64389e-07,6.85048e-09,0.964231,0.000525224,-2.43837e-07,-4.19169e-08,0.964756,0.00052461,-3.69588e-07,4.1608e-08,0.96528,0.000523996,-2.44764e-07,-5.30598e-09,0.965804,0.000523491,-2.60682e-07,-2.03841e-08,0.966327,0.000522908,-3.21834e-07,2.72378e-08,0.966849,0.000522346,-2.40121e-07,-2.89625e-08,0.967371,0.000521779,-3.27008e-07,2.90075e-08,0.967893,0.000521212,-2.39986e-07,-2.74629e-08,0.968414,0.00052065,-3.22374e-07,2.12396e-08,0.968934,0.000520069,-2.58656e-07,2.10922e-09,0.969454,0.000519558,-2.52328e-07,-2.96765e-08,0.969973,0.000518964,-3.41357e-07,5.6992e-08,0.970492,0.000518452,-1.70382e-07,-7.90821e-08,0.97101,0.000517874,-4.07628e-07,8.05224e-08,0.971528,0.000517301,-1.66061e-07,-6.41937e-08,0.972045,0.000516776,-3.58642e-07,5.70429e-08,0.972561,0.00051623,-1.87513e-07,-4.47686e-08,0.973077,0.00051572,-3.21819e-07,2.82237e-09,0.973593,0.000515085,-3.13352e-07,3.34792e-08,0.974108,0.000514559,-2.12914e-07,-1.75298e-08,0.974622,0.000514081,-2.65503e-07,-2.29648e-08,0.975136,0.000513481,-3.34398e-07,4.97843e-08,0.975649,0.000512961,-1.85045e-07,-5.6963e-08,0.976162,0.00051242,-3.55934e-07,5.88585e-08,0.976674,0.000511885,-1.79359e-07,-5.92616e-08,0.977185,0.000511348,-3.57143e-07,5.89785e-08,0.977696,0.000510811,-1.80208e-07,-5.74433e-08,0.978207,0.000510278,-3.52538e-07,5.15854e-08,0.978717,0.000509728,-1.97781e-07,-2.9689e-08,0.979226,0.000509243,-2.86848e-07,7.56591e-09,0.979735,0.000508692,-2.64151e-07,-5.74649e-10,0.980244,0.000508162,-2.65875e-07,-5.26732e-09,0.980752,0.000507615,-2.81677e-07,2.16439e-08,0.981259,0.000507116,-2.16745e-07,-2.17037e-08,0.981766,0.000506618,-2.81856e-07,5.56636e-09,0.982272,0.000506071,-2.65157e-07,-5.61689e-10,0.982778,0.000505539,-2.66842e-07,-3.31963e-09,0.983283,0.000504995,-2.76801e-07,1.38402e-08,0.983788,0.000504483,-2.3528e-07,7.56339e-09,0.984292,0.000504035,-2.1259e-07,-4.40938e-08,0.984796,0.000503478,-3.44871e-07,4.96026e-08,0.985299,0.000502937,-1.96064e-07,-3.51071e-08,0.985802,0.000502439,-3.01385e-07,3.12212e-08,0.986304,0.00050193,-2.07721e-07,-3.0173e-08,0.986806,0.000501424,-2.9824e-07,2.9866e-08,0.987307,0.000500917,-2.08642e-07,-2.96865e-08,0.987808,0.000500411,-2.97702e-07,2.92753e-08,0.988308,0.000499903,-2.09876e-07,-2.78101e-08,0.988807,0.0004994,-2.93306e-07,2.23604e-08,0.989307,0.000498881,-2.26225e-07,-2.02681e-09,0.989805,0.000498422,-2.32305e-07,-1.42531e-08,0.990303,0.000497915,-2.75065e-07,-5.65232e-10,0.990801,0.000497363,-2.76761e-07,1.65141e-08,0.991298,0.000496859,-2.27218e-07,-5.88639e-09,0.991795,0.000496387,-2.44878e-07,7.0315e-09,0.992291,0.000495918,-2.23783e-07,-2.22396e-08,0.992787,0.000495404,-2.90502e-07,2.23224e-08,0.993282,0.00049489,-2.23535e-07,-7.44543e-09,0.993776,0.000494421,-2.45871e-07,7.45924e-09,0.994271,0.000493951,-2.23493e-07,-2.23915e-08,0.994764,0.000493437,-2.90668e-07,2.25021e-08,0.995257,0.000492923,-2.23161e-07,-8.01218e-09,0.99575,0.000492453,-2.47198e-07,9.54669e-09,0.996242,0.000491987,-2.18558e-07,-3.01746e-08,0.996734,0.000491459,-3.09082e-07,5.1547e-08,0.997225,0.000490996,-1.54441e-07,-5.68039e-08,0.997716,0.000490517,-3.24853e-07,5.64594e-08,0.998206,0.000490036,-1.55474e-07,-4.98245e-08,0.998696,0.000489576,-3.04948e-07,2.36292e-08,0.999186,0.000489037,-2.3406e-07,1.49121e-08,0.999674,0.000488613,-1.89324e-07,-2.3673e-08,1.00016,0.000488164,-2.60343e-07,2.01754e-08,1.00065,0.000487704,-1.99816e-07,-5.70288e-08,1.00114,0.000487133,-3.70903e-07,8.87303e-08,1.00162,0.000486657,-1.04712e-07,-5.94737e-08,1.00211,0.000486269,-2.83133e-07,2.99553e-08,1.0026,0.000485793,-1.93267e-07,-6.03474e-08,1.00308,0.000485225,-3.74309e-07,9.2225e-08,1.00357,0.000484754,-9.76345e-08,-7.0134e-08,1.00405,0.000484348,-3.08036e-07,6.91016e-08,1.00454,0.000483939,-1.00731e-07,-8.70633e-08,1.00502,0.000483476,-3.61921e-07,4.07328e-08,1.0055,0.000482875,-2.39723e-07,4.33413e-08,1.00599,0.000482525,-1.09699e-07,-9.48886e-08,1.00647,0.000482021,-3.94365e-07,9.77947e-08,1.00695,0.000481526,-1.00981e-07,-5.78713e-08,1.00743,0.00048115,-2.74595e-07,1.44814e-08,1.00791,0.000480645,-2.31151e-07,-5.42665e-11,1.00839,0.000480182,-2.31314e-07,-1.42643e-08,1.00887,0.000479677,-2.74106e-07,5.71115e-08,1.00935,0.0004793,-1.02772e-07,-9.49724e-08,1.00983,0.000478809,-3.87689e-07,8.43596e-08,1.01031,0.000478287,-1.3461e-07,-4.04755e-09,1.01079,0.000478006,-1.46753e-07,-6.81694e-08,1.01127,0.000477508,-3.51261e-07,3.83067e-08,1.01174,0.00047692,-2.36341e-07,3.41521e-08,1.01222,0.00047655,-1.33885e-07,-5.57058e-08,1.0127,0.000476115,-3.01002e-07,6.94616e-08,1.01317,0.000475721,-9.26174e-08,-1.02931e-07,1.01365,0.000475227,-4.01412e-07,1.03846e-07,1.01412,0.000474736,-8.98751e-08,-7.40321e-08,1.0146,0.000474334,-3.11971e-07,7.30735e-08,1.01507,0.00047393,-9.27508e-08,-9.90527e-08,1.01554,0.000473447,-3.89909e-07,8.47188e-08,1.01602,0.000472921,-1.35753e-07,-1.40381e-09,1.01649,0.000472645,-1.39964e-07,-7.91035e-08,1.01696,0.000472128,-3.77275e-07,7.93993e-08,1.01744,0.000471612,-1.39077e-07,-7.52607e-11,1.01791,0.000471334,-1.39302e-07,-7.90983e-08,1.01838,0.000470818,-3.76597e-07,7.80499e-08,1.01885,0.000470299,-1.42448e-07,5.31733e-09,1.01932,0.00047003,-1.26496e-07,-9.93193e-08,1.01979,0.000469479,-4.24453e-07,1.53541e-07,1.02026,0.00046909,3.617e-08,-1.57217e-07,1.02073,0.000468691,-4.35482e-07,1.177e-07,1.02119,0.000468173,-8.23808e-08,-7.51659e-08,1.02166,0.000467783,-3.07878e-07,6.37538e-08,1.02213,0.000467358,-1.16617e-07,-6.064e-08,1.0226,0.000466943,-2.98537e-07,5.9597e-08,1.02306,0.000466525,-1.19746e-07,-5.85386e-08,1.02353,0.00046611,-2.95362e-07,5.53482e-08,1.024,0.000465685,-1.29317e-07,-4.36449e-08,1.02446,0.000465296,-2.60252e-07,2.20268e-11,1.02493,0.000464775,-2.60186e-07,4.35568e-08,1.02539,0.000464386,-1.29516e-07,-5.50398e-08,1.02586,0.000463961,-2.94635e-07,5.73932e-08,1.02632,0.000463544,-1.22456e-07,-5.53236e-08,1.02678,0.000463133,-2.88426e-07,4.46921e-08,1.02725,0.000462691,-1.5435e-07,-4.23534e-09,1.02771,0.000462369,-1.67056e-07,-2.77507e-08,1.02817,0.000461952,-2.50308e-07,-3.97101e-09,1.02863,0.000461439,-2.62221e-07,4.36348e-08,1.02909,0.000461046,-1.31317e-07,-5.13589e-08,1.02955,0.000460629,-2.85394e-07,4.25913e-08,1.03001,0.000460186,-1.5762e-07,2.0285e-10,1.03047,0.000459871,-1.57011e-07,-4.34027e-08,1.03093,0.000459427,-2.87219e-07,5.41987e-08,1.03139,0.000459015,-1.24623e-07,-5.4183e-08,1.03185,0.000458604,-2.87172e-07,4.33239e-08,1.03231,0.000458159,-1.572e-07,9.65817e-11,1.03277,0.000457845,-1.56911e-07,-4.37103e-08,1.03323,0.0004574,-2.88041e-07,5.55351e-08,1.03368,0.000456991,-1.21436e-07,-5.9221e-08,1.03414,0.00045657,-2.99099e-07,6.21394e-08,1.0346,0.000456158,-1.1268e-07,-7.01275e-08,1.03505,0.000455723,-3.23063e-07,9.91614e-08,1.03551,0.000455374,-2.55788e-08,-8.80996e-08,1.03596,0.000455058,-2.89878e-07,1.48184e-08,1.03642,0.000454523,-2.45422e-07,2.88258e-08,1.03687,0.000454119,-1.58945e-07,-1.09125e-08,1.03733,0.000453768,-1.91682e-07,1.48241e-08,1.03778,0.000453429,-1.4721e-07,-4.83838e-08,1.03823,0.00045299,-2.92361e-07,5.95019e-08,1.03869,0.000452584,-1.13856e-07,-7.04146e-08,1.03914,0.000452145,-3.25099e-07,1.02947e-07,1.03959,0.000451803,-1.62583e-08,-1.02955e-07,1.04004,0.000451462,-3.25123e-07,7.04544e-08,1.04049,0.000451023,-1.1376e-07,-5.96534e-08,1.04094,0.000450616,-2.9272e-07,4.89499e-08,1.04139,0.000450178,-1.45871e-07,-1.69369e-08,1.04184,0.000449835,-1.96681e-07,1.87977e-08,1.04229,0.000449498,-1.40288e-07,-5.82539e-08,1.04274,0.000449043,-3.1505e-07,9.50087e-08,1.04319,0.000448698,-3.00238e-08,-8.33623e-08,1.04364,0.000448388,-2.80111e-07,2.20363e-11,1.04409,0.000447828,-2.80045e-07,8.32742e-08,1.04454,0.000447517,-3.02221e-08,-9.47002e-08,1.04498,0.000447173,-3.14323e-07,5.7108e-08,1.04543,0.000446716,-1.42999e-07,-1.45225e-08,1.04588,0.000446386,-1.86566e-07,9.82022e-10,1.04632,0.000446016,-1.8362e-07,1.05944e-08,1.04677,0.00044568,-1.51837e-07,-4.33597e-08,1.04721,0.000445247,-2.81916e-07,4.36352e-08,1.04766,0.000444814,-1.51011e-07,-1.19717e-08,1.0481,0.000444476,-1.86926e-07,4.25158e-09,1.04855,0.000444115,-1.74171e-07,-5.03461e-09,1.04899,0.000443751,-1.89275e-07,1.58868e-08,1.04944,0.00044342,-1.41614e-07,-5.85127e-08,1.04988,0.000442961,-3.17152e-07,9.89548e-08,1.05032,0.000442624,-2.0288e-08,-9.88878e-08,1.05076,0.000442287,-3.16951e-07,5.81779e-08,1.05121,0.000441827,-1.42418e-07,-1.46144e-08,1.05165,0.000441499,-1.86261e-07,2.79892e-10,1.05209,0.000441127,-1.85421e-07,1.34949e-08,1.05253,0.000440797,-1.44937e-07,-5.42594e-08,1.05297,0.000440344,-3.07715e-07,8.43335e-08,1.05341,0.000439982,-5.47146e-08,-4.46558e-08,1.05385,0.000439738,-1.88682e-07,-2.49193e-08,1.05429,0.000439286,-2.6344e-07,2.5124e-08,1.05473,0.000438835,-1.88068e-07,4.36328e-08,1.05517,0.000438589,-5.71699e-08,-8.04459e-08,1.05561,0.000438234,-2.98508e-07,3.97324e-08,1.05605,0.000437756,-1.79311e-07,4.07258e-08,1.05648,0.000437519,-5.71332e-08,-8.34263e-08,1.05692,0.000437155,-3.07412e-07,5.45608e-08,1.05736,0.000436704,-1.4373e-07,-1.56078e-08,1.05779,0.000436369,-1.90553e-07,7.87043e-09,1.05823,0.000436012,-1.66942e-07,-1.58739e-08,1.05867,0.00043563,-2.14563e-07,5.56251e-08,1.0591,0.000435368,-4.76881e-08,-8.74172e-08,1.05954,0.000435011,-3.0994e-07,5.56251e-08,1.05997,0.000434558,-1.43064e-07,-1.58739e-08,1.06041,0.000434224,-1.90686e-07,7.87042e-09,1.06084,0.000433866,-1.67075e-07,-1.56078e-08,1.06127,0.000433485,-2.13898e-07,5.45609e-08,1.06171,0.000433221,-5.02157e-08,-8.34263e-08,1.06214,0.00043287,-3.00495e-07,4.07258e-08,1.06257,0.000432391,-1.78317e-07,3.97325e-08,1.063,0.000432154,-5.91198e-08,-8.04464e-08,1.06344,0.000431794,-3.00459e-07,4.36347e-08,1.06387,0.000431324,-1.69555e-07,2.5117e-08,1.0643,0.000431061,-9.42041e-08,-2.48934e-08,1.06473,0.000430798,-1.68884e-07,-4.47527e-08,1.06516,0.000430326,-3.03142e-07,8.46951e-08,1.06559,0.000429973,-4.90573e-08,-5.56089e-08,1.06602,0.000429708,-2.15884e-07,1.85314e-08,1.06645,0.000429332,-1.6029e-07,-1.85166e-08,1.06688,0.000428956,-2.1584e-07,5.5535e-08,1.06731,0.000428691,-4.92347e-08,-8.44142e-08,1.06774,0.000428339,-3.02477e-07,4.37032e-08,1.06816,0.000427865,-1.71368e-07,2.88107e-08,1.06859,0.000427609,-8.49356e-08,-3.97367e-08,1.06902,0.00042732,-2.04146e-07,1.09267e-08,1.06945,0.000426945,-1.71365e-07,-3.97023e-09,1.06987,0.00042659,-1.83276e-07,4.9542e-09,1.0703,0.000426238,-1.68414e-07,-1.58466e-08,1.07073,0.000425854,-2.15953e-07,5.84321e-08,1.07115,0.000425597,-4.0657e-08,-9.86725e-08,1.07158,0.00042522,-3.36674e-07,9.78392e-08,1.072,0.00042484,-4.31568e-08,-5.42658e-08,1.07243,0.000424591,-2.05954e-07,1.45377e-11,1.07285,0.000424179,-2.0591e-07,5.42076e-08,1.07328,0.00042393,-4.32877e-08,-9.76357e-08,1.0737,0.00042355,-3.36195e-07,9.79165e-08,1.07412,0.000423172,-4.24451e-08,-5.56118e-08,1.07455,0.00042292,-2.09281e-07,5.32143e-09,1.07497,0.000422518,-1.93316e-07,3.43261e-08,1.07539,0.000422234,-9.0338e-08,-2.34165e-08,1.07581,0.000421983,-1.60588e-07,-5.98692e-08,1.07623,0.000421482,-3.40195e-07,1.43684e-07,1.07666,0.000421233,9.08574e-08,-1.5724e-07,1.07708,0.000420943,-3.80862e-07,1.27647e-07,1.0775,0.000420564,2.0791e-09,-1.1493e-07,1.07792,0.000420223,-3.4271e-07,9.36534e-08,1.07834,0.000419819,-6.17499e-08,-2.12653e-08,1.07876,0.000419632,-1.25546e-07,-8.59219e-09,1.07918,0.000419355,-1.51322e-07,-6.35752e-08,1.0796,0.000418861,-3.42048e-07,1.43684e-07,1.08002,0.000418608,8.90034e-08,-1.53532e-07,1.08043,0.000418326,-3.71593e-07,1.12817e-07,1.08085,0.000417921,-3.31414e-08,-5.93184e-08,1.08127,0.000417677,-2.11097e-07,5.24697e-09,1.08169,0.00041727,-1.95356e-07,3.83305e-08,1.0821,0.000416995,-8.03642e-08,-3.93597e-08,1.08252,0.000416716,-1.98443e-07,-1.0094e-10,1.08294,0.000416319,-1.98746e-07,3.97635e-08,1.08335,0.00041604,-7.94557e-08,-3.97437e-08,1.08377,0.000415762,-1.98687e-07,1.94215e-12,1.08419,0.000415365,-1.98681e-07,3.97359e-08,1.0846,0.000415087,-7.94732e-08,-3.97362e-08,1.08502,0.000414809,-1.98682e-07,-4.31063e-13,1.08543,0.000414411,-1.98683e-07,3.97379e-08,1.08584,0.000414133,-7.94694e-08,-3.97418e-08,1.08626,0.000413855,-1.98695e-07,2.00563e-11,1.08667,0.000413458,-1.98635e-07,3.96616e-08,1.08709,0.000413179,-7.965e-08,-3.9457e-08,1.0875,0.000412902,-1.98021e-07,-1.04281e-09,1.08791,0.000412502,-2.01149e-07,4.36282e-08,1.08832,0.000412231,-7.02648e-08,-5.42608e-08,1.08874,0.000411928,-2.33047e-07,5.42057e-08,1.08915,0.000411624,-7.04301e-08,-4.33527e-08,1.08956,0.000411353,-2.00488e-07,-4.07378e-12,1.08997,0.000410952,-2.005e-07,4.3369e-08,1.09038,0.000410681,-7.03934e-08,-5.42627e-08,1.09079,0.000410378,-2.33182e-07,5.44726e-08,1.0912,0.000410075,-6.97637e-08,-4.44186e-08,1.09161,0.000409802,-2.03019e-07,3.99235e-09,1.09202,0.000409408,-1.91042e-07,2.84491e-08,1.09243,0.000409111,-1.05695e-07,1.42043e-09,1.09284,0.000408904,-1.01434e-07,-3.41308e-08,1.09325,0.000408599,-2.03826e-07,1.58937e-08,1.09366,0.000408239,-1.56145e-07,-2.94438e-08,1.09406,0.000407838,-2.44476e-07,1.01881e-07,1.09447,0.000407655,6.11676e-08,-1.39663e-07,1.09488,0.000407358,-3.57822e-07,9.91432e-08,1.09529,0.00040694,-6.03921e-08,-1.84912e-08,1.09569,0.000406764,-1.15866e-07,-2.51785e-08,1.0961,0.000406457,-1.91401e-07,-4.03115e-12,1.09651,0.000406074,-1.91413e-07,2.51947e-08,1.09691,0.000405767,-1.15829e-07,1.84346e-08,1.09732,0.00040559,-6.05254e-08,-9.89332e-08,1.09772,0.000405172,-3.57325e-07,1.3888e-07,1.09813,0.000404874,5.93136e-08,-9.8957e-08,1.09853,0.000404696,-2.37557e-07,1.853e-08,1.09894,0.000404277,-1.81968e-07,2.48372e-08,1.09934,0.000403987,-1.07456e-07,1.33047e-09,1.09975,0.000403776,-1.03465e-07,-3.01591e-08,1.10015,0.000403479,-1.93942e-07,9.66054e-11,1.10055,0.000403091,-1.93652e-07,2.97727e-08,1.10096,0.000402793,-1.04334e-07,2.19273e-11,1.10136,0.000402585,-1.04268e-07,-2.98604e-08,1.10176,0.000402287,-1.93849e-07,2.10325e-10,1.10216,0.0004019,-1.93218e-07,2.90191e-08,1.10256,0.0004016,-1.06161e-07,2.92264e-09,1.10297,0.000401397,-9.73931e-08,-4.07096e-08,1.10337,0.00040108,-2.19522e-07,4.07067e-08,1.10377,0.000400763,-9.7402e-08,-2.90783e-09,1.10417,0.000400559,-1.06126e-07,-2.90754e-08,1.10457,0.00040026,-1.93352e-07,9.00021e-14,1.10497,0.000399873,-1.93351e-07,2.9075e-08,1.10537,0.000399574,-1.06126e-07,2.90902e-09,1.10577,0.00039937,-9.73992e-08,-4.07111e-08,1.10617,0.000399053,-2.19533e-07,4.07262e-08,1.10657,0.000398736,-9.73541e-08,-2.98424e-09,1.10697,0.000398533,-1.06307e-07,-2.87892e-08,1.10736,0.000398234,-1.92674e-07,-1.06824e-09,1.10776,0.000397845,-1.95879e-07,3.30622e-08,1.10816,0.000397552,-9.66926e-08,-1.19712e-08,1.10856,0.000397323,-1.32606e-07,1.48225e-08,1.10895,0.000397102,-8.81387e-08,-4.73187e-08,1.10935,0.000396784,-2.30095e-07,5.52429e-08,1.10975,0.00039649,-6.4366e-08,-5.44437e-08,1.11014,0.000396198,-2.27697e-07,4.33226e-08,1.11054,0.000395872,-9.77293e-08,3.62656e-10,1.11094,0.000395678,-9.66414e-08,-4.47732e-08,1.11133,0.00039535,-2.30961e-07,5.95208e-08,1.11173,0.000395067,-5.23985e-08,-7.41008e-08,1.11212,0.00039474,-2.74701e-07,1.17673e-07,1.11252,0.000394543,7.83181e-08,-1.58172e-07,1.11291,0.000394225,-3.96199e-07,1.57389e-07,1.1133,0.000393905,7.59679e-08,-1.13756e-07,1.1137,0.000393716,-2.653e-07,5.92165e-08,1.11409,0.000393363,-8.76507e-08,-3.90074e-09,1.11449,0.000393176,-9.93529e-08,-4.36136e-08,1.11488,0.000392846,-2.30194e-07,5.91457e-08,1.11527,0.000392563,-5.27564e-08,-7.376e-08,1.11566,0.000392237,-2.74037e-07,1.16685e-07,1.11606,0.000392039,7.60189e-08,-1.54562e-07,1.11645,0.000391727,-3.87667e-07,1.43935e-07,1.11684,0.000391384,4.4137e-08,-6.35487e-08,1.11723,0.000391281,-1.46509e-07,-8.94896e-09,1.11762,0.000390961,-1.73356e-07,-1.98647e-08,1.11801,0.000390555,-2.3295e-07,8.8408e-08,1.1184,0.000390354,3.22736e-08,-9.53486e-08,1.11879,0.000390133,-2.53772e-07,5.45677e-08,1.11918,0.000389789,-9.0069e-08,-3.71296e-09,1.11957,0.000389598,-1.01208e-07,-3.97159e-08,1.11996,0.000389276,-2.20355e-07,4.33671e-08,1.12035,0.000388966,-9.02542e-08,-1.45431e-08,1.12074,0.000388741,-1.33883e-07,1.48052e-08,1.12113,0.000388518,-8.94678e-08,-4.46778e-08,1.12152,0.000388205,-2.23501e-07,4.46966e-08,1.12191,0.000387892,-8.94114e-08,-1.48992e-08,1.12229,0.000387669,-1.34109e-07,1.49003e-08,1.12268,0.000387445,-8.94082e-08,-4.47019e-08,1.12307,0.000387132,-2.23514e-07,4.4698e-08,1.12345,0.000386819,-8.942e-08,-1.48806e-08,1.12384,0.000386596,-1.34062e-07,1.48245e-08,1.12423,0.000386372,-8.95885e-08,-4.44172e-08,1.12461,0.00038606,-2.2284e-07,4.36351e-08,1.125,0.000385745,-9.19348e-08,-1.09139e-08,1.12539,0.000385528,-1.24677e-07,2.05584e-11,1.12577,0.000385279,-1.24615e-07,1.08317e-08,1.12616,0.000385062,-9.21198e-08,-4.33473e-08,1.12654,0.000384748,-2.22162e-07,4.33481e-08,1.12693,0.000384434,-9.21174e-08,-1.08356e-08,1.12731,0.000384217,-1.24624e-07,-5.50907e-12,1.12769,0.000383968,-1.24641e-07,1.08577e-08,1.12808,0.000383751,-9.20679e-08,-4.34252e-08,1.12846,0.000383437,-2.22343e-07,4.36337e-08,1.12884,0.000383123,-9.14422e-08,-1.19005e-08,1.12923,0.000382904,-1.27144e-07,3.96813e-09,1.12961,0.000382662,-1.15239e-07,-3.97207e-09,1.12999,0.000382419,-1.27155e-07,1.19201e-08,1.13038,0.000382201,-9.1395e-08,-4.37085e-08,1.13076,0.000381887,-2.2252e-07,4.37046e-08,1.13114,0.000381573,-9.14068e-08,-1.19005e-08,1.13152,0.000381355,-1.27108e-07,3.89734e-09,1.1319,0.000381112,-1.15416e-07,-3.68887e-09,1.13228,0.00038087,-1.26483e-07,1.08582e-08,1.13266,0.00038065,-9.39083e-08,-3.97438e-08,1.13304,0.000380343,-2.1314e-07,2.89076e-08,1.13342,0.000380003,-1.26417e-07,4.33225e-08,1.1338,0.00037988,3.55072e-09,-8.29883e-08,1.13418,0.000379638,-2.45414e-07,5.0212e-08,1.13456,0.000379298,-9.47781e-08,1.34964e-09,1.13494,0.000379113,-9.07292e-08,-5.56105e-08,1.13532,0.000378764,-2.57561e-07,1.01883e-07,1.1357,0.000378555,4.80889e-08,-1.13504e-07,1.13608,0.000378311,-2.92423e-07,1.13713e-07,1.13646,0.000378067,4.87176e-08,-1.02931e-07,1.13683,0.000377856,-2.60076e-07,5.95923e-08,1.13721,0.000377514,-8.12988e-08,-1.62288e-08,1.13759,0.000377303,-1.29985e-07,5.32278e-09,1.13797,0.000377059,-1.14017e-07,-5.06237e-09,1.13834,0.000376816,-1.29204e-07,1.49267e-08,1.13872,0.000376602,-8.44237e-08,-5.46444e-08,1.1391,0.000376269,-2.48357e-07,8.44417e-08,1.13947,0.000376026,4.96815e-09,-4.47039e-08,1.13985,0.000375902,-1.29143e-07,-2.48355e-08,1.14023,0.000375569,-2.0365e-07,2.48368e-08,1.1406,0.000375236,-1.2914e-07,4.46977e-08,1.14098,0.000375112,4.95341e-09,-8.44184e-08,1.14135,0.000374869,-2.48302e-07,5.45572e-08,1.14173,0.000374536,-8.463e-08,-1.46013e-08,1.1421,0.000374323,-1.28434e-07,3.8478e-09,1.14247,0.000374077,-1.1689e-07,-7.89941e-10,1.14285,0.000373841,-1.1926e-07,-6.88042e-10,1.14322,0.0003736,-1.21324e-07,3.54213e-09,1.1436,0.000373368,-1.10698e-07,-1.34805e-08,1.14397,0.000373107,-1.51139e-07,5.03798e-08,1.14434,0.000372767,0.,0.}; + + template + __device__ __forceinline__ void RGB2LuvConvert_f(const T& src, D& dst) + { + const float _d = 1.f / (0.950456f + 15 + 1.088754f * 3); + const float _un = 13 * (4 * 0.950456f * _d); + const float _vn = 13 * (9 * _d); + + float B = blueIdx == 0 ? src.x : src.z; + float G = src.y; + float R = blueIdx == 0 ? src.z : src.x; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBGammaTab, GAMMA_TAB_SIZE); + } + + float X = R * 0.412453f + G * 0.357580f + B * 0.180423f; + float Y = R * 0.212671f + G * 0.715160f + B * 0.072169f; + float Z = R * 0.019334f + G * 0.119193f + B * 0.950227f; + + float L = splineInterpolate(Y * (LAB_CBRT_TAB_SIZE / 1.5f), c_LabCbrtTab, LAB_CBRT_TAB_SIZE); + L = 116.f * L - 16.f; + + const float d = (4 * 13) / ::fmaxf(X + 15 * Y + 3 * Z, numeric_limits::epsilon()); + float u = L * (X * d - _un); + float v = L * ((9 * 0.25f) * Y * d - _vn); + + dst.x = L; + dst.y = u; + dst.z = v; + } + + template + __device__ __forceinline__ void RGB2LuvConvert_b(const T& src, D& dst) + { + float3 srcf, dstf; + + srcf.x = src.x * (1.f / 255.f); + srcf.y = src.y * (1.f / 255.f); + srcf.z = src.z * (1.f / 255.f); + + RGB2LuvConvert_f(srcf, dstf); + + dst.x = saturate_cast(dstf.x * 2.55f); + dst.y = saturate_cast(dstf.y * 0.72033898305084743f + 96.525423728813564f); + dst.z = saturate_cast(dstf.z * 0.9732824427480916f + 136.259541984732824f); + } + + template struct RGB2Luv; + template + struct RGB2Luv + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + RGB2LuvConvert_b(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Luv() {} + __host__ __device__ __forceinline__ RGB2Luv(const RGB2Luv&) {} + }; + template + struct RGB2Luv + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + RGB2LuvConvert_f(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ RGB2Luv() {} + __host__ __device__ __forceinline__ RGB2Luv(const RGB2Luv&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::RGB2Luv functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + namespace color_detail + { + template + __device__ __forceinline__ void Luv2RGBConvert_f(const T& src, D& dst) + { + const float _d = 1.f / (0.950456f + 15 + 1.088754f * 3); + const float _un = 4 * 0.950456f * _d; + const float _vn = 9 * _d; + + float L = src.x; + float u = src.y; + float v = src.z; + + float Y = (L + 16.f) * (1.f / 116.f); + Y = Y * Y * Y; + + float d = (1.f / 13.f) / L; + u = u * d + _un; + v = v * d + _vn; + + float iv = 1.f / v; + float X = 2.25f * u * Y * iv; + float Z = (12 - 3 * u - 20 * v) * Y * 0.25f * iv; + + float B = 0.055648f * X - 0.204043f * Y + 1.057311f * Z; + float G = -0.969256f * X + 1.875991f * Y + 0.041556f * Z; + float R = 3.240479f * X - 1.537150f * Y - 0.498535f * Z; + + if (srgb) + { + B = splineInterpolate(B * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + G = splineInterpolate(G * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + R = splineInterpolate(R * GAMMA_TAB_SIZE, c_sRGBInvGammaTab, GAMMA_TAB_SIZE); + } + + dst.x = blueIdx == 0 ? B : R; + dst.y = G; + dst.z = blueIdx == 0 ? R : B; + setAlpha(dst, ColorChannel::max()); + } + + template + __device__ __forceinline__ void Luv2RGBConvert_b(const T& src, D& dst) + { + float3 srcf, dstf; + + srcf.x = src.x * (100.f / 255.f); + srcf.y = src.y * 1.388235294117647f - 134.f; + srcf.z = src.z * 1.027450980392157f - 140.f; + + Luv2RGBConvert_f(srcf, dstf); + + dst.x = saturate_cast(dstf.x * 255.f); + dst.y = saturate_cast(dstf.y * 255.f); + dst.z = saturate_cast(dstf.z * 255.f); + setAlpha(dst, ColorChannel::max()); + } + + template struct Luv2RGB; + template + struct Luv2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + Luv2RGBConvert_b(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Luv2RGB() {} + __host__ __device__ __forceinline__ Luv2RGB(const Luv2RGB&) {} + }; + template + struct Luv2RGB + : unary_function::vec_type, typename TypeVec::vec_type> + { + __device__ __forceinline__ typename TypeVec::vec_type operator ()(const typename TypeVec::vec_type& src) const + { + typename TypeVec::vec_type dst; + + Luv2RGBConvert_f(src, dst); + + return dst; + } + __host__ __device__ __forceinline__ Luv2RGB() {} + __host__ __device__ __forceinline__ Luv2RGB(const Luv2RGB&) {} + }; + } + +#define OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(name, scn, dcn, srgb, blueIdx) \ + template struct name ## _traits \ + { \ + typedef ::cv::cuda::device::color_detail::Luv2RGB functor_type; \ + static __host__ __device__ __forceinline__ functor_type create_functor() \ + { \ + return functor_type(); \ + } \ + }; + + #undef CV_DESCALE + +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_COLOR_DETAIL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/reduce.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/reduce.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8af20b0dc86d76232220c5111bbdf5a2bc31748c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/reduce.hpp @@ -0,0 +1,365 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_REDUCE_DETAIL_HPP +#define OPENCV_CUDA_REDUCE_DETAIL_HPP + +#include +#include "../warp.hpp" +#include "../warp_shuffle.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace reduce_detail + { + template struct GetType; + template struct GetType + { + typedef T type; + }; + template struct GetType + { + typedef T type; + }; + template struct GetType + { + typedef T type; + }; + + template + struct For + { + template + static __device__ void loadToSmem(const PointerTuple& smem, const ValTuple& val, unsigned int tid) + { + thrust::get(smem)[tid] = thrust::get(val); + + For::loadToSmem(smem, val, tid); + } + template + static __device__ void loadFromSmem(const PointerTuple& smem, const ValTuple& val, unsigned int tid) + { + thrust::get(val) = thrust::get(smem)[tid]; + + For::loadFromSmem(smem, val, tid); + } + + template + static __device__ void merge(const PointerTuple& smem, const ValTuple& val, unsigned int tid, unsigned int delta, const OpTuple& op) + { + typename GetType::type>::type reg = thrust::get(smem)[tid + delta]; + thrust::get(smem)[tid] = thrust::get(val) = thrust::get(op)(thrust::get(val), reg); + + For::merge(smem, val, tid, delta, op); + } + template + static __device__ void mergeShfl(const ValTuple& val, unsigned int delta, unsigned int width, const OpTuple& op) + { + typename GetType::type>::type reg = shfl_down(thrust::get(val), delta, width); + thrust::get(val) = thrust::get(op)(thrust::get(val), reg); + + For::mergeShfl(val, delta, width, op); + } + }; + template + struct For + { + template + static __device__ void loadToSmem(const PointerTuple&, const ValTuple&, unsigned int) + { + } + template + static __device__ void loadFromSmem(const PointerTuple&, const ValTuple&, unsigned int) + { + } + + template + static __device__ void merge(const PointerTuple&, const ValTuple&, unsigned int, unsigned int, const OpTuple&) + { + } + template + static __device__ void mergeShfl(const ValTuple&, unsigned int, unsigned int, const OpTuple&) + { + } + }; + + template + __device__ __forceinline__ void loadToSmem(volatile T* smem, T& val, unsigned int tid) + { + smem[tid] = val; + } + template + __device__ __forceinline__ void loadFromSmem(volatile T* smem, T& val, unsigned int tid) + { + val = smem[tid]; + } + template + __device__ __forceinline__ void loadToSmem(const thrust::tuple& smem, + const thrust::tuple& val, + unsigned int tid) + { + For<0, thrust::tuple_size >::value>::loadToSmem(smem, val, tid); + } + template + __device__ __forceinline__ void loadFromSmem(const thrust::tuple& smem, + const thrust::tuple& val, + unsigned int tid) + { + For<0, thrust::tuple_size >::value>::loadFromSmem(smem, val, tid); + } + + template + __device__ __forceinline__ void merge(volatile T* smem, T& val, unsigned int tid, unsigned int delta, const Op& op) + { + T reg = smem[tid + delta]; + smem[tid] = val = op(val, reg); + } + template + __device__ __forceinline__ void mergeShfl(T& val, unsigned int delta, unsigned int width, const Op& op) + { + T reg = shfl_down(val, delta, width); + val = op(val, reg); + } + template + __device__ __forceinline__ void merge(const thrust::tuple& smem, + const thrust::tuple& val, + unsigned int tid, + unsigned int delta, + const thrust::tuple& op) + { + For<0, thrust::tuple_size >::value>::merge(smem, val, tid, delta, op); + } + template + __device__ __forceinline__ void mergeShfl(const thrust::tuple& val, + unsigned int delta, + unsigned int width, + const thrust::tuple& op) + { + For<0, thrust::tuple_size >::value>::mergeShfl(val, delta, width, op); + } + + template struct Generic + { + template + static __device__ void reduce(Pointer smem, Reference val, unsigned int tid, Op op) + { + loadToSmem(smem, val, tid); + if (N >= 32) + __syncthreads(); + + if (N >= 2048) + { + if (tid < 1024) + merge(smem, val, tid, 1024, op); + + __syncthreads(); + } + if (N >= 1024) + { + if (tid < 512) + merge(smem, val, tid, 512, op); + + __syncthreads(); + } + if (N >= 512) + { + if (tid < 256) + merge(smem, val, tid, 256, op); + + __syncthreads(); + } + if (N >= 256) + { + if (tid < 128) + merge(smem, val, tid, 128, op); + + __syncthreads(); + } + if (N >= 128) + { + if (tid < 64) + merge(smem, val, tid, 64, op); + + __syncthreads(); + } + if (N >= 64) + { + if (tid < 32) + merge(smem, val, tid, 32, op); + } + + if (tid < 16) + { + merge(smem, val, tid, 16, op); + merge(smem, val, tid, 8, op); + merge(smem, val, tid, 4, op); + merge(smem, val, tid, 2, op); + merge(smem, val, tid, 1, op); + } + } + }; + + template + struct Unroll + { + static __device__ void loopShfl(Reference val, Op op, unsigned int N) + { + mergeShfl(val, I, N, op); + Unroll::loopShfl(val, op, N); + } + static __device__ void loop(Pointer smem, Reference val, unsigned int tid, Op op) + { + merge(smem, val, tid, I, op); + Unroll::loop(smem, val, tid, op); + } + }; + template + struct Unroll<0, Pointer, Reference, Op> + { + static __device__ void loopShfl(Reference, Op, unsigned int) + { + } + static __device__ void loop(Pointer, Reference, unsigned int, Op) + { + } + }; + + template struct WarpOptimized + { + template + static __device__ void reduce(Pointer smem, Reference val, unsigned int tid, Op op) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + CV_UNUSED(smem); + CV_UNUSED(tid); + + Unroll::loopShfl(val, op, N); + #else + loadToSmem(smem, val, tid); + + if (tid < N / 2) + Unroll::loop(smem, val, tid, op); + #endif + } + }; + + template struct GenericOptimized32 + { + enum { M = N / 32 }; + + template + static __device__ void reduce(Pointer smem, Reference val, unsigned int tid, Op op) + { + const unsigned int laneId = Warp::laneId(); + + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + Unroll<16, Pointer, Reference, Op>::loopShfl(val, op, warpSize); + + if (laneId == 0) + loadToSmem(smem, val, tid / 32); + #else + loadToSmem(smem, val, tid); + + if (laneId < 16) + Unroll<16, Pointer, Reference, Op>::loop(smem, val, tid, op); + + __syncthreads(); + + if (laneId == 0) + loadToSmem(smem, val, tid / 32); + #endif + + __syncthreads(); + + loadFromSmem(smem, val, tid); + + if (tid < 32) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + Unroll::loopShfl(val, op, M); + #else + Unroll::loop(smem, val, tid, op); + #endif + } + } + }; + + template struct StaticIf; + template struct StaticIf + { + typedef T1 type; + }; + template struct StaticIf + { + typedef T2 type; + }; + + template struct IsPowerOf2 + { + enum { value = ((N != 0) && !(N & (N - 1))) }; + }; + + template struct Dispatcher + { + typedef typename StaticIf< + (N <= 32) && IsPowerOf2::value, + WarpOptimized, + typename StaticIf< + (N <= 1024) && IsPowerOf2::value, + GenericOptimized32, + Generic + >::type + >::type reductor; + }; + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_REDUCE_DETAIL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/reduce_key_val.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/reduce_key_val.hpp new file mode 100644 index 0000000000000000000000000000000000000000..df37c173be64bed1331f49260388acceea6de56b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/reduce_key_val.hpp @@ -0,0 +1,502 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_PRED_VAL_REDUCE_DETAIL_HPP +#define OPENCV_CUDA_PRED_VAL_REDUCE_DETAIL_HPP + +#include +#include "../warp.hpp" +#include "../warp_shuffle.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace reduce_key_val_detail + { + template struct GetType; + template struct GetType + { + typedef T type; + }; + template struct GetType + { + typedef T type; + }; + template struct GetType + { + typedef T type; + }; + + template + struct For + { + template + static __device__ void loadToSmem(const PointerTuple& smem, const ReferenceTuple& data, unsigned int tid) + { + thrust::get(smem)[tid] = thrust::get(data); + + For::loadToSmem(smem, data, tid); + } + template + static __device__ void loadFromSmem(const PointerTuple& smem, const ReferenceTuple& data, unsigned int tid) + { + thrust::get(data) = thrust::get(smem)[tid]; + + For::loadFromSmem(smem, data, tid); + } + + template + static __device__ void copyShfl(const ReferenceTuple& val, unsigned int delta, int width) + { + thrust::get(val) = shfl_down(thrust::get(val), delta, width); + + For::copyShfl(val, delta, width); + } + template + static __device__ void copy(const PointerTuple& svals, const ReferenceTuple& val, unsigned int tid, unsigned int delta) + { + thrust::get(svals)[tid] = thrust::get(val) = thrust::get(svals)[tid + delta]; + + For::copy(svals, val, tid, delta); + } + + template + static __device__ void mergeShfl(const KeyReferenceTuple& key, const ValReferenceTuple& val, const CmpTuple& cmp, unsigned int delta, int width) + { + typename GetType::type>::type reg = shfl_down(thrust::get(key), delta, width); + + if (thrust::get(cmp)(reg, thrust::get(key))) + { + thrust::get(key) = reg; + thrust::get(val) = shfl_down(thrust::get(val), delta, width); + } + + For::mergeShfl(key, val, cmp, delta, width); + } + template + static __device__ void merge(const KeyPointerTuple& skeys, const KeyReferenceTuple& key, + const ValPointerTuple& svals, const ValReferenceTuple& val, + const CmpTuple& cmp, + unsigned int tid, unsigned int delta) + { + typename GetType::type>::type reg = thrust::get(skeys)[tid + delta]; + + if (thrust::get(cmp)(reg, thrust::get(key))) + { + thrust::get(skeys)[tid] = thrust::get(key) = reg; + thrust::get(svals)[tid] = thrust::get(val) = thrust::get(svals)[tid + delta]; + } + + For::merge(skeys, key, svals, val, cmp, tid, delta); + } + }; + template + struct For + { + template + static __device__ void loadToSmem(const PointerTuple&, const ReferenceTuple&, unsigned int) + { + } + template + static __device__ void loadFromSmem(const PointerTuple&, const ReferenceTuple&, unsigned int) + { + } + + template + static __device__ void copyShfl(const ReferenceTuple&, unsigned int, int) + { + } + template + static __device__ void copy(const PointerTuple&, const ReferenceTuple&, unsigned int, unsigned int) + { + } + + template + static __device__ void mergeShfl(const KeyReferenceTuple&, const ValReferenceTuple&, const CmpTuple&, unsigned int, int) + { + } + template + static __device__ void merge(const KeyPointerTuple&, const KeyReferenceTuple&, + const ValPointerTuple&, const ValReferenceTuple&, + const CmpTuple&, + unsigned int, unsigned int) + { + } + }; + + ////////////////////////////////////////////////////// + // loadToSmem + + template + __device__ __forceinline__ void loadToSmem(volatile T* smem, T& data, unsigned int tid) + { + smem[tid] = data; + } + template + __device__ __forceinline__ void loadFromSmem(volatile T* smem, T& data, unsigned int tid) + { + data = smem[tid]; + } + template + __device__ __forceinline__ void loadToSmem(const thrust::tuple& smem, + const thrust::tuple& data, + unsigned int tid) + { + For<0, thrust::tuple_size >::value>::loadToSmem(smem, data, tid); + } + template + __device__ __forceinline__ void loadFromSmem(const thrust::tuple& smem, + const thrust::tuple& data, + unsigned int tid) + { + For<0, thrust::tuple_size >::value>::loadFromSmem(smem, data, tid); + } + + ////////////////////////////////////////////////////// + // copyVals + + template + __device__ __forceinline__ void copyValsShfl(V& val, unsigned int delta, int width) + { + val = shfl_down(val, delta, width); + } + template + __device__ __forceinline__ void copyVals(volatile V* svals, V& val, unsigned int tid, unsigned int delta) + { + svals[tid] = val = svals[tid + delta]; + } + template + __device__ __forceinline__ void copyValsShfl(const thrust::tuple& val, + unsigned int delta, + int width) + { + For<0, thrust::tuple_size >::value>::copyShfl(val, delta, width); + } + template + __device__ __forceinline__ void copyVals(const thrust::tuple& svals, + const thrust::tuple& val, + unsigned int tid, unsigned int delta) + { + For<0, thrust::tuple_size >::value>::copy(svals, val, tid, delta); + } + + ////////////////////////////////////////////////////// + // merge + + template + __device__ __forceinline__ void mergeShfl(K& key, V& val, const Cmp& cmp, unsigned int delta, int width) + { + K reg = shfl_down(key, delta, width); + + if (cmp(reg, key)) + { + key = reg; + copyValsShfl(val, delta, width); + } + } + template + __device__ __forceinline__ void merge(volatile K* skeys, K& key, volatile V* svals, V& val, const Cmp& cmp, unsigned int tid, unsigned int delta) + { + K reg = skeys[tid + delta]; + + if (cmp(reg, key)) + { + skeys[tid] = key = reg; + copyVals(svals, val, tid, delta); + } + } + template + __device__ __forceinline__ void mergeShfl(K& key, + const thrust::tuple& val, + const Cmp& cmp, + unsigned int delta, int width) + { + K reg = shfl_down(key, delta, width); + + if (cmp(reg, key)) + { + key = reg; + copyValsShfl(val, delta, width); + } + } + template + __device__ __forceinline__ void merge(volatile K* skeys, K& key, + const thrust::tuple& svals, + const thrust::tuple& val, + const Cmp& cmp, unsigned int tid, unsigned int delta) + { + K reg = skeys[tid + delta]; + + if (cmp(reg, key)) + { + skeys[tid] = key = reg; + copyVals(svals, val, tid, delta); + } + } + template + __device__ __forceinline__ void mergeShfl(const thrust::tuple& key, + const thrust::tuple& val, + const thrust::tuple& cmp, + unsigned int delta, int width) + { + For<0, thrust::tuple_size >::value>::mergeShfl(key, val, cmp, delta, width); + } + template + __device__ __forceinline__ void merge(const thrust::tuple& skeys, + const thrust::tuple& key, + const thrust::tuple& svals, + const thrust::tuple& val, + const thrust::tuple& cmp, + unsigned int tid, unsigned int delta) + { + For<0, thrust::tuple_size >::value>::merge(skeys, key, svals, val, cmp, tid, delta); + } + + ////////////////////////////////////////////////////// + // Generic + + template struct Generic + { + template + static __device__ void reduce(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + loadToSmem(skeys, key, tid); + loadValsToSmem(svals, val, tid); + if (N >= 32) + __syncthreads(); + + if (N >= 2048) + { + if (tid < 1024) + merge(skeys, key, svals, val, cmp, tid, 1024); + + __syncthreads(); + } + if (N >= 1024) + { + if (tid < 512) + merge(skeys, key, svals, val, cmp, tid, 512); + + __syncthreads(); + } + if (N >= 512) + { + if (tid < 256) + merge(skeys, key, svals, val, cmp, tid, 256); + + __syncthreads(); + } + if (N >= 256) + { + if (tid < 128) + merge(skeys, key, svals, val, cmp, tid, 128); + + __syncthreads(); + } + if (N >= 128) + { + if (tid < 64) + merge(skeys, key, svals, val, cmp, tid, 64); + + __syncthreads(); + } + if (N >= 64) + { + if (tid < 32) + merge(skeys, key, svals, val, cmp, tid, 32); + } + + if (tid < 16) + { + merge(skeys, key, svals, val, cmp, tid, 16); + merge(skeys, key, svals, val, cmp, tid, 8); + merge(skeys, key, svals, val, cmp, tid, 4); + merge(skeys, key, svals, val, cmp, tid, 2); + merge(skeys, key, svals, val, cmp, tid, 1); + } + } + }; + + template + struct Unroll + { + static __device__ void loopShfl(KR key, VR val, Cmp cmp, unsigned int N) + { + mergeShfl(key, val, cmp, I, N); + Unroll::loopShfl(key, val, cmp, N); + } + static __device__ void loop(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + merge(skeys, key, svals, val, cmp, tid, I); + Unroll::loop(skeys, key, svals, val, tid, cmp); + } + }; + template + struct Unroll<0, KP, KR, VP, VR, Cmp> + { + static __device__ void loopShfl(KR, VR, Cmp, unsigned int) + { + } + static __device__ void loop(KP, KR, VP, VR, unsigned int, Cmp) + { + } + }; + + template struct WarpOptimized + { + template + static __device__ void reduce(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + #if 0 // __CUDA_ARCH__ >= 300 + CV_UNUSED(skeys); + CV_UNUSED(svals); + CV_UNUSED(tid); + + Unroll::loopShfl(key, val, cmp, N); + #else + loadToSmem(skeys, key, tid); + loadToSmem(svals, val, tid); + + if (tid < N / 2) + Unroll::loop(skeys, key, svals, val, tid, cmp); + #endif + } + }; + + template struct GenericOptimized32 + { + enum { M = N / 32 }; + + template + static __device__ void reduce(KP skeys, KR key, VP svals, VR val, unsigned int tid, Cmp cmp) + { + const unsigned int laneId = Warp::laneId(); + + #if 0 // __CUDA_ARCH__ >= 300 + Unroll<16, KP, KR, VP, VR, Cmp>::loopShfl(key, val, cmp, warpSize); + + if (laneId == 0) + { + loadToSmem(skeys, key, tid / 32); + loadToSmem(svals, val, tid / 32); + } + #else + loadToSmem(skeys, key, tid); + loadToSmem(svals, val, tid); + + if (laneId < 16) + Unroll<16, KP, KR, VP, VR, Cmp>::loop(skeys, key, svals, val, tid, cmp); + + __syncthreads(); + + if (laneId == 0) + { + loadToSmem(skeys, key, tid / 32); + loadToSmem(svals, val, tid / 32); + } + #endif + + __syncthreads(); + + loadFromSmem(skeys, key, tid); + + if (tid < 32) + { + #if 0 // __CUDA_ARCH__ >= 300 + loadFromSmem(svals, val, tid); + + Unroll::loopShfl(key, val, cmp, M); + #else + Unroll::loop(skeys, key, svals, val, tid, cmp); + #endif + } + } + }; + + template struct StaticIf; + template struct StaticIf + { + typedef T1 type; + }; + template struct StaticIf + { + typedef T2 type; + }; + + template struct IsPowerOf2 + { + enum { value = ((N != 0) && !(N & (N - 1))) }; + }; + + template struct Dispatcher + { + typedef typename StaticIf< + (N <= 32) && IsPowerOf2::value, + WarpOptimized, + typename StaticIf< + (N <= 1024) && IsPowerOf2::value, + GenericOptimized32, + Generic + >::type + >::type reductor; + }; + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_PRED_VAL_REDUCE_DETAIL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/transform_detail.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/transform_detail.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1919848827543461c62aeacc90b41c8c105fa5ea --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/transform_detail.hpp @@ -0,0 +1,392 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_TRANSFORM_DETAIL_HPP +#define OPENCV_CUDA_TRANSFORM_DETAIL_HPP + +#include "../common.hpp" +#include "../vec_traits.hpp" +#include "../functional.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace transform_detail + { + //! Read Write Traits + + template struct UnaryReadWriteTraits + { + typedef typename TypeVec::vec_type read_type; + typedef typename TypeVec::vec_type write_type; + }; + + template struct BinaryReadWriteTraits + { + typedef typename TypeVec::vec_type read_type1; + typedef typename TypeVec::vec_type read_type2; + typedef typename TypeVec::vec_type write_type; + }; + + //! Transform kernels + + template struct OpUnroller; + template <> struct OpUnroller<1> + { + template + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + } + + template + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + } + }; + template <> struct OpUnroller<2> + { + template + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src.y); + } + + template + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src1.y, src2.y); + } + }; + template <> struct OpUnroller<3> + { + template + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, const UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src.z); + } + + template + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, const BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src1.y, src2.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src1.z, src2.z); + } + }; + template <> struct OpUnroller<4> + { + template + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, const UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src.z); + if (mask(y, x_shifted + 3)) + dst.w = op(src.w); + } + + template + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, const BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.x = op(src1.x, src2.x); + if (mask(y, x_shifted + 1)) + dst.y = op(src1.y, src2.y); + if (mask(y, x_shifted + 2)) + dst.z = op(src1.z, src2.z); + if (mask(y, x_shifted + 3)) + dst.w = op(src1.w, src2.w); + } + }; + template <> struct OpUnroller<8> + { + template + static __device__ __forceinline__ void unroll(const T& src, D& dst, const Mask& mask, const UnOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.a0 = op(src.a0); + if (mask(y, x_shifted + 1)) + dst.a1 = op(src.a1); + if (mask(y, x_shifted + 2)) + dst.a2 = op(src.a2); + if (mask(y, x_shifted + 3)) + dst.a3 = op(src.a3); + if (mask(y, x_shifted + 4)) + dst.a4 = op(src.a4); + if (mask(y, x_shifted + 5)) + dst.a5 = op(src.a5); + if (mask(y, x_shifted + 6)) + dst.a6 = op(src.a6); + if (mask(y, x_shifted + 7)) + dst.a7 = op(src.a7); + } + + template + static __device__ __forceinline__ void unroll(const T1& src1, const T2& src2, D& dst, const Mask& mask, const BinOp& op, int x_shifted, int y) + { + if (mask(y, x_shifted)) + dst.a0 = op(src1.a0, src2.a0); + if (mask(y, x_shifted + 1)) + dst.a1 = op(src1.a1, src2.a1); + if (mask(y, x_shifted + 2)) + dst.a2 = op(src1.a2, src2.a2); + if (mask(y, x_shifted + 3)) + dst.a3 = op(src1.a3, src2.a3); + if (mask(y, x_shifted + 4)) + dst.a4 = op(src1.a4, src2.a4); + if (mask(y, x_shifted + 5)) + dst.a5 = op(src1.a5, src2.a5); + if (mask(y, x_shifted + 6)) + dst.a6 = op(src1.a6, src2.a6); + if (mask(y, x_shifted + 7)) + dst.a7 = op(src1.a7, src2.a7); + } + }; + + template + static __global__ void transformSmart(const PtrStepSz src_, PtrStep dst_, const Mask mask, const UnOp op) + { + typedef TransformFunctorTraits ft; + typedef typename UnaryReadWriteTraits::read_type read_type; + typedef typename UnaryReadWriteTraits::write_type write_type; + + const int x = threadIdx.x + blockIdx.x * blockDim.x; + const int y = threadIdx.y + blockIdx.y * blockDim.y; + const int x_shifted = x * ft::smart_shift; + + if (y < src_.rows) + { + const T* src = src_.ptr(y); + D* dst = dst_.ptr(y); + + if (x_shifted + ft::smart_shift - 1 < src_.cols) + { + const read_type src_n_el = ((const read_type*)src)[x]; + OpUnroller::unroll(src_n_el, ((write_type*)dst)[x], mask, op, x_shifted, y); + } + else + { + for (int real_x = x_shifted; real_x < src_.cols; ++real_x) + { + if (mask(y, real_x)) + dst[real_x] = op(src[real_x]); + } + } + } + } + + template + __global__ static void transformSimple(const PtrStepSz src, PtrStep dst, const Mask mask, const UnOp op) + { + const int x = blockDim.x * blockIdx.x + threadIdx.x; + const int y = blockDim.y * blockIdx.y + threadIdx.y; + + if (x < src.cols && y < src.rows && mask(y, x)) + { + dst.ptr(y)[x] = op(src.ptr(y)[x]); + } + } + + template + static __global__ void transformSmart(const PtrStepSz src1_, const PtrStep src2_, PtrStep dst_, + const Mask mask, const BinOp op) + { + typedef TransformFunctorTraits ft; + typedef typename BinaryReadWriteTraits::read_type1 read_type1; + typedef typename BinaryReadWriteTraits::read_type2 read_type2; + typedef typename BinaryReadWriteTraits::write_type write_type; + + const int x = threadIdx.x + blockIdx.x * blockDim.x; + const int y = threadIdx.y + blockIdx.y * blockDim.y; + const int x_shifted = x * ft::smart_shift; + + if (y < src1_.rows) + { + const T1* src1 = src1_.ptr(y); + const T2* src2 = src2_.ptr(y); + D* dst = dst_.ptr(y); + + if (x_shifted + ft::smart_shift - 1 < src1_.cols) + { + const read_type1 src1_n_el = ((const read_type1*)src1)[x]; + const read_type2 src2_n_el = ((const read_type2*)src2)[x]; + + OpUnroller::unroll(src1_n_el, src2_n_el, ((write_type*)dst)[x], mask, op, x_shifted, y); + } + else + { + for (int real_x = x_shifted; real_x < src1_.cols; ++real_x) + { + if (mask(y, real_x)) + dst[real_x] = op(src1[real_x], src2[real_x]); + } + } + } + } + + template + static __global__ void transformSimple(const PtrStepSz src1, const PtrStep src2, PtrStep dst, + const Mask mask, const BinOp op) + { + const int x = blockDim.x * blockIdx.x + threadIdx.x; + const int y = blockDim.y * blockIdx.y + threadIdx.y; + + if (x < src1.cols && y < src1.rows && mask(y, x)) + { + const T1 src1_data = src1.ptr(y)[x]; + const T2 src2_data = src2.ptr(y)[x]; + dst.ptr(y)[x] = op(src1_data, src2_data); + } + } + + template struct TransformDispatcher; + template<> struct TransformDispatcher + { + template + static void call(PtrStepSz src, PtrStepSz dst, UnOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits ft; + + const dim3 threads(ft::simple_block_dim_x, ft::simple_block_dim_y, 1); + const dim3 grid(divUp(src.cols, threads.x), divUp(src.rows, threads.y), 1); + + transformSimple<<>>(src, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + + template + static void call(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, BinOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits ft; + + const dim3 threads(ft::simple_block_dim_x, ft::simple_block_dim_y, 1); + const dim3 grid(divUp(src1.cols, threads.x), divUp(src1.rows, threads.y), 1); + + transformSimple<<>>(src1, src2, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + }; + template<> struct TransformDispatcher + { + template + static void call(PtrStepSz src, PtrStepSz dst, UnOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits ft; + + CV_StaticAssert(ft::smart_shift != 1, ""); + + if (!isAligned(src.data, ft::smart_shift * sizeof(T)) || !isAligned(src.step, ft::smart_shift * sizeof(T)) || + !isAligned(dst.data, ft::smart_shift * sizeof(D)) || !isAligned(dst.step, ft::smart_shift * sizeof(D))) + { + TransformDispatcher::call(src, dst, op, mask, stream); + return; + } + + const dim3 threads(ft::smart_block_dim_x, ft::smart_block_dim_y, 1); + const dim3 grid(divUp(src.cols, threads.x * ft::smart_shift), divUp(src.rows, threads.y), 1); + + transformSmart<<>>(src, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + + template + static void call(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, BinOp op, Mask mask, cudaStream_t stream) + { + typedef TransformFunctorTraits ft; + + CV_StaticAssert(ft::smart_shift != 1, ""); + + if (!isAligned(src1.data, ft::smart_shift * sizeof(T1)) || !isAligned(src1.step, ft::smart_shift * sizeof(T1)) || + !isAligned(src2.data, ft::smart_shift * sizeof(T2)) || !isAligned(src2.step, ft::smart_shift * sizeof(T2)) || + !isAligned(dst.data, ft::smart_shift * sizeof(D)) || !isAligned(dst.step, ft::smart_shift * sizeof(D))) + { + TransformDispatcher::call(src1, src2, dst, op, mask, stream); + return; + } + + const dim3 threads(ft::smart_block_dim_x, ft::smart_block_dim_y, 1); + const dim3 grid(divUp(src1.cols, threads.x * ft::smart_shift), divUp(src1.rows, threads.y), 1); + + transformSmart<<>>(src1, src2, dst, mask, op); + cudaSafeCall( cudaGetLastError() ); + + if (stream == 0) + cudaSafeCall( cudaDeviceSynchronize() ); + } + }; + } // namespace transform_detail +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_TRANSFORM_DETAIL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/type_traits_detail.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/type_traits_detail.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a78bd2c0d858f10d785cabef7258ac4ed656586f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/type_traits_detail.hpp @@ -0,0 +1,191 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_TYPE_TRAITS_DETAIL_HPP +#define OPENCV_CUDA_TYPE_TRAITS_DETAIL_HPP + +#include "../common.hpp" +#include "../vec_traits.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace type_traits_detail + { + template struct Select { typedef T1 type; }; + template struct Select { typedef T2 type; }; + + template struct IsSignedIntergral { enum {value = 0}; }; + template <> struct IsSignedIntergral { enum {value = 1}; }; + template <> struct IsSignedIntergral { enum {value = 1}; }; + template <> struct IsSignedIntergral { enum {value = 1}; }; + template <> struct IsSignedIntergral { enum {value = 1}; }; + template <> struct IsSignedIntergral { enum {value = 1}; }; + template <> struct IsSignedIntergral { enum {value = 1}; }; + + template struct IsUnsignedIntegral { enum {value = 0}; }; + template <> struct IsUnsignedIntegral { enum {value = 1}; }; + template <> struct IsUnsignedIntegral { enum {value = 1}; }; + template <> struct IsUnsignedIntegral { enum {value = 1}; }; + template <> struct IsUnsignedIntegral { enum {value = 1}; }; + template <> struct IsUnsignedIntegral { enum {value = 1}; }; + template <> struct IsUnsignedIntegral { enum {value = 1}; }; + + template struct IsIntegral { enum {value = IsSignedIntergral::value || IsUnsignedIntegral::value}; }; + template <> struct IsIntegral { enum {value = 1}; }; + template <> struct IsIntegral { enum {value = 1}; }; + + template struct IsFloat { enum {value = 0}; }; + template <> struct IsFloat { enum {value = 1}; }; + template <> struct IsFloat { enum {value = 1}; }; + + template struct IsVec { enum {value = 0}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + template <> struct IsVec { enum {value = 1}; }; + + template struct AddParameterType { typedef const U& type; }; + template struct AddParameterType { typedef U& type; }; + template <> struct AddParameterType { typedef void type; }; + + template struct ReferenceTraits + { + enum { value = false }; + typedef U type; + }; + template struct ReferenceTraits + { + enum { value = true }; + typedef U type; + }; + + template struct PointerTraits + { + enum { value = false }; + typedef void type; + }; + template struct PointerTraits + { + enum { value = true }; + typedef U type; + }; + template struct PointerTraits + { + enum { value = true }; + typedef U type; + }; + + template struct UnConst + { + typedef U type; + enum { value = 0 }; + }; + template struct UnConst + { + typedef U type; + enum { value = 1 }; + }; + template struct UnConst + { + typedef U& type; + enum { value = 1 }; + }; + + template struct UnVolatile + { + typedef U type; + enum { value = 0 }; + }; + template struct UnVolatile + { + typedef U type; + enum { value = 1 }; + }; + template struct UnVolatile + { + typedef U& type; + enum { value = 1 }; + }; + } // namespace type_traits_detail +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_TYPE_TRAITS_DETAIL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/vec_distance_detail.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/vec_distance_detail.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8283a99560d995f34a768fb40b0c4a33d5bcfee2 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/detail/vec_distance_detail.hpp @@ -0,0 +1,121 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP +#define OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP + +#include "../datamov_utils.hpp" + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + namespace vec_distance_detail + { + template struct UnrollVecDiffCached + { + template + static __device__ void calcCheck(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int ind) + { + if (ind < len) + { + T1 val1 = *vecCached++; + + T2 val2; + ForceGlob::Load(vecGlob, ind, val2); + + dist.reduceIter(val1, val2); + + UnrollVecDiffCached::calcCheck(vecCached, vecGlob, len, dist, ind + THREAD_DIM); + } + } + + template + static __device__ void calcWithoutCheck(const T1* vecCached, const T2* vecGlob, Dist& dist) + { + T1 val1 = *vecCached++; + + T2 val2; + ForceGlob::Load(vecGlob, 0, val2); + vecGlob += THREAD_DIM; + + dist.reduceIter(val1, val2); + + UnrollVecDiffCached::calcWithoutCheck(vecCached, vecGlob, dist); + } + }; + template struct UnrollVecDiffCached + { + template + static __device__ __forceinline__ void calcCheck(const T1*, const T2*, int, Dist&, int) + { + } + + template + static __device__ __forceinline__ void calcWithoutCheck(const T1*, const T2*, Dist&) + { + } + }; + + template struct VecDiffCachedCalculator; + template struct VecDiffCachedCalculator + { + template + static __device__ __forceinline__ void calc(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int tid) + { + UnrollVecDiffCached::calcCheck(vecCached, vecGlob, len, dist, tid); + } + }; + template struct VecDiffCachedCalculator + { + template + static __device__ __forceinline__ void calc(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int tid) + { + UnrollVecDiffCached::calcWithoutCheck(vecCached, vecGlob + tid, dist); + } + }; + } // namespace vec_distance_detail +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/dynamic_smem.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/dynamic_smem.hpp new file mode 100644 index 0000000000000000000000000000000000000000..42570c6830c41bb53e7f9802f2a430f5181218c0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/dynamic_smem.hpp @@ -0,0 +1,88 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_DYNAMIC_SMEM_HPP +#define OPENCV_CUDA_DYNAMIC_SMEM_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template struct DynamicSharedMem + { + __device__ __forceinline__ operator T*() + { + extern __shared__ int __smem[]; + return (T*)__smem; + } + + __device__ __forceinline__ operator const T*() const + { + extern __shared__ int __smem[]; + return (T*)__smem; + } + }; + + // specialize for double to avoid unaligned memory access compile errors + template<> struct DynamicSharedMem + { + __device__ __forceinline__ operator double*() + { + extern __shared__ double __smem_d[]; + return (double*)__smem_d; + } + + __device__ __forceinline__ operator const double*() const + { + extern __shared__ double __smem_d[]; + return (double*)__smem_d; + } + }; +}}} + +//! @endcond + +#endif // OPENCV_CUDA_DYNAMIC_SMEM_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/emulation.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/emulation.hpp new file mode 100644 index 0000000000000000000000000000000000000000..17dc1171a237e2f1979ad2f782e79c3a9b7f9d53 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/emulation.hpp @@ -0,0 +1,269 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_EMULATION_HPP_ +#define OPENCV_CUDA_EMULATION_HPP_ + +#include "common.hpp" +#include "warp_reduce.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct Emulation + { + + static __device__ __forceinline__ int syncthreadsOr(int pred) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 200) + // just campilation stab + return 0; +#else + return __syncthreads_or(pred); +#endif + } + + template + static __forceinline__ __device__ int Ballot(int predicate) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ >= 200) + return __ballot(predicate); +#else + __shared__ volatile int cta_buffer[CTA_SIZE]; + + int tid = threadIdx.x; + cta_buffer[tid] = predicate ? (1 << (tid & 31)) : 0; + return warp_reduce(cta_buffer); +#endif + } + + struct smem + { + enum { TAG_MASK = (1U << ( (sizeof(unsigned int) << 3) - 5U)) - 1U }; + + template + static __device__ __forceinline__ T atomicInc(T* address, T val) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120) + T count; + unsigned int tag = threadIdx.x << ( (sizeof(unsigned int) << 3) - 5U); + do + { + count = *address & TAG_MASK; + count = tag | (count + 1); + *address = count; + } while (*address != count); + + return (count & TAG_MASK) - 1; +#else + return ::atomicInc(address, val); +#endif + } + + template + static __device__ __forceinline__ T atomicAdd(T* address, T val) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120) + T count; + unsigned int tag = threadIdx.x << ( (sizeof(unsigned int) << 3) - 5U); + do + { + count = *address & TAG_MASK; + count = tag | (count + val); + *address = count; + } while (*address != count); + + return (count & TAG_MASK) - val; +#else + return ::atomicAdd(address, val); +#endif + } + + template + static __device__ __forceinline__ T atomicMin(T* address, T val) + { +#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120) + T count = ::min(*address, val); + do + { + *address = count; + } while (*address > count); + + return count; +#else + return ::atomicMin(address, val); +#endif + } + }; // struct cmem + + struct glob + { + static __device__ __forceinline__ int atomicAdd(int* address, int val) + { + return ::atomicAdd(address, val); + } + static __device__ __forceinline__ unsigned int atomicAdd(unsigned int* address, unsigned int val) + { + return ::atomicAdd(address, val); + } + static __device__ __forceinline__ float atomicAdd(float* address, float val) + { + #if __CUDA_ARCH__ >= 200 + return ::atomicAdd(address, val); + #else + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(val + __int_as_float(assumed))); + } while (assumed != old); + return __int_as_float(old); + #endif + } + static __device__ __forceinline__ double atomicAdd(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(val + __longlong_as_double(assumed))); + } while (assumed != old); + return __longlong_as_double(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0; + #endif + } + + static __device__ __forceinline__ int atomicMin(int* address, int val) + { + return ::atomicMin(address, val); + } + static __device__ __forceinline__ float atomicMin(float* address, float val) + { + #if __CUDA_ARCH__ >= 120 + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(::fminf(val, __int_as_float(assumed)))); + } while (assumed != old); + return __int_as_float(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0f; + #endif + } + static __device__ __forceinline__ double atomicMin(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(::fmin(val, __longlong_as_double(assumed)))); + } while (assumed != old); + return __longlong_as_double(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0; + #endif + } + + static __device__ __forceinline__ int atomicMax(int* address, int val) + { + return ::atomicMax(address, val); + } + static __device__ __forceinline__ float atomicMax(float* address, float val) + { + #if __CUDA_ARCH__ >= 120 + int* address_as_i = (int*) address; + int old = *address_as_i, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_i, assumed, + __float_as_int(::fmaxf(val, __int_as_float(assumed)))); + } while (assumed != old); + return __int_as_float(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0f; + #endif + } + static __device__ __forceinline__ double atomicMax(double* address, double val) + { + #if __CUDA_ARCH__ >= 130 + unsigned long long int* address_as_ull = (unsigned long long int*) address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = ::atomicCAS(address_as_ull, assumed, + __double_as_longlong(::fmax(val, __longlong_as_double(assumed)))); + } while (assumed != old); + return __longlong_as_double(old); + #else + CV_UNUSED(address); + CV_UNUSED(val); + return 0.0; + #endif + } + }; + }; //struct Emulation +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif /* OPENCV_CUDA_EMULATION_HPP_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/filters.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/filters.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bb94212299a7f2ae5a2fa9fe7d38323adddfb3c3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/filters.hpp @@ -0,0 +1,286 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_FILTERS_HPP +#define OPENCV_CUDA_FILTERS_HPP + +#include "saturate_cast.hpp" +#include "vec_traits.hpp" +#include "vec_math.hpp" +#include "type_traits.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template struct PointFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ PointFilter(const Ptr2D& src_, float fx = 0.f, float fy = 0.f) + : src(src_) + { + CV_UNUSED(fx); + CV_UNUSED(fy); + } + + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + return src(__float2int_rz(y), __float2int_rz(x)); + } + + Ptr2D src; + }; + + template struct LinearFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ LinearFilter(const Ptr2D& src_, float fx = 0.f, float fy = 0.f) + : src(src_) + { + CV_UNUSED(fx); + CV_UNUSED(fy); + } + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + typedef typename TypeVec::cn>::vec_type work_type; + + work_type out = VecTraits::all(0); + + const int x1 = __float2int_rd(x); + const int y1 = __float2int_rd(y); + const int x2 = x1 + 1; + const int y2 = y1 + 1; + + elem_type src_reg = src(y1, x1); + out = out + src_reg * ((x2 - x) * (y2 - y)); + + src_reg = src(y1, x2); + out = out + src_reg * ((x - x1) * (y2 - y)); + + src_reg = src(y2, x1); + out = out + src_reg * ((x2 - x) * (y - y1)); + + src_reg = src(y2, x2); + out = out + src_reg * ((x - x1) * (y - y1)); + + return saturate_cast(out); + } + + Ptr2D src; + }; + + template struct CubicFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + typedef typename TypeVec::cn>::vec_type work_type; + + explicit __host__ __device__ __forceinline__ CubicFilter(const Ptr2D& src_, float fx = 0.f, float fy = 0.f) + : src(src_) + { + CV_UNUSED(fx); + CV_UNUSED(fy); + } + + static __device__ __forceinline__ float bicubicCoeff(float x_) + { + float x = fabsf(x_); + if (x <= 1.0f) + { + return x * x * (1.5f * x - 2.5f) + 1.0f; + } + else if (x < 2.0f) + { + return x * (x * (-0.5f * x + 2.5f) - 4.0f) + 2.0f; + } + else + { + return 0.0f; + } + } + + __device__ elem_type operator ()(float y, float x) const + { + const float xmin = ::ceilf(x - 2.0f); + const float xmax = ::floorf(x + 2.0f); + + const float ymin = ::ceilf(y - 2.0f); + const float ymax = ::floorf(y + 2.0f); + + work_type sum = VecTraits::all(0); + float wsum = 0.0f; + + for (float cy = ymin; cy <= ymax; cy += 1.0f) + { + for (float cx = xmin; cx <= xmax; cx += 1.0f) + { + const float w = bicubicCoeff(x - cx) * bicubicCoeff(y - cy); + sum = sum + w * src(__float2int_rd(cy), __float2int_rd(cx)); + wsum += w; + } + } + + work_type res = (!wsum)? VecTraits::all(0) : sum / wsum; + + return saturate_cast(res); + } + + Ptr2D src; + }; + // for integer scaling + template struct IntegerAreaFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ IntegerAreaFilter(const Ptr2D& src_, float scale_x_, float scale_y_) + : src(src_), scale_x(scale_x_), scale_y(scale_y_), scale(1.f / (scale_x * scale_y)) {} + + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + float fsx1 = x * scale_x; + float fsx2 = fsx1 + scale_x; + + int sx1 = __float2int_ru(fsx1); + int sx2 = __float2int_rd(fsx2); + + float fsy1 = y * scale_y; + float fsy2 = fsy1 + scale_y; + + int sy1 = __float2int_ru(fsy1); + int sy2 = __float2int_rd(fsy2); + + typedef typename TypeVec::cn>::vec_type work_type; + work_type out = VecTraits::all(0.f); + + for(int dy = sy1; dy < sy2; ++dy) + for(int dx = sx1; dx < sx2; ++dx) + { + out = out + src(dy, dx) * scale; + } + + return saturate_cast(out); + } + + Ptr2D src; + float scale_x, scale_y ,scale; + }; + + template struct AreaFilter + { + typedef typename Ptr2D::elem_type elem_type; + typedef float index_type; + + explicit __host__ __device__ __forceinline__ AreaFilter(const Ptr2D& src_, float scale_x_, float scale_y_) + : src(src_), scale_x(scale_x_), scale_y(scale_y_){} + + __device__ __forceinline__ elem_type operator ()(float y, float x) const + { + float fsx1 = x * scale_x; + float fsx2 = fsx1 + scale_x; + + int sx1 = __float2int_ru(fsx1); + int sx2 = __float2int_rd(fsx2); + + float fsy1 = y * scale_y; + float fsy2 = fsy1 + scale_y; + + int sy1 = __float2int_ru(fsy1); + int sy2 = __float2int_rd(fsy2); + + float scale = 1.f / (fminf(scale_x, src.width - fsx1) * fminf(scale_y, src.height - fsy1)); + + typedef typename TypeVec::cn>::vec_type work_type; + work_type out = VecTraits::all(0.f); + + for (int dy = sy1; dy < sy2; ++dy) + { + for (int dx = sx1; dx < sx2; ++dx) + out = out + src(dy, dx) * scale; + + if (sx1 > fsx1) + out = out + src(dy, (sx1 -1) ) * ((sx1 - fsx1) * scale); + + if (sx2 < fsx2) + out = out + src(dy, sx2) * ((fsx2 -sx2) * scale); + } + + if (sy1 > fsy1) + for (int dx = sx1; dx < sx2; ++dx) + out = out + src( (sy1 - 1) , dx) * ((sy1 -fsy1) * scale); + + if (sy2 < fsy2) + for (int dx = sx1; dx < sx2; ++dx) + out = out + src(sy2, dx) * ((fsy2 -sy2) * scale); + + if ((sy1 > fsy1) && (sx1 > fsx1)) + out = out + src( (sy1 - 1) , (sx1 - 1)) * ((sy1 -fsy1) * (sx1 -fsx1) * scale); + + if ((sy1 > fsy1) && (sx2 < fsx2)) + out = out + src( (sy1 - 1) , sx2) * ((sy1 -fsy1) * (fsx2 -sx2) * scale); + + if ((sy2 < fsy2) && (sx2 < fsx2)) + out = out + src(sy2, sx2) * ((fsy2 -sy2) * (fsx2 -sx2) * scale); + + if ((sy2 < fsy2) && (sx1 > fsx1)) + out = out + src(sy2, (sx1 - 1)) * ((fsy2 -sy2) * (sx1 -fsx1) * scale); + + return saturate_cast(out); + } + + Ptr2D src; + float scale_x, scale_y; + int width, haight; + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_FILTERS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/funcattrib.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/funcattrib.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f58208048882076cb4748706491c46462833ad44 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/funcattrib.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP +#define OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP + +#include + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template + void printFuncAttrib(Func& func) + { + + cudaFuncAttributes attrs; + cudaFuncGetAttributes(&attrs, func); + + printf("=== Function stats ===\n"); + printf("Name: \n"); + printf("sharedSizeBytes = %d\n", attrs.sharedSizeBytes); + printf("constSizeBytes = %d\n", attrs.constSizeBytes); + printf("localSizeBytes = %d\n", attrs.localSizeBytes); + printf("maxThreadsPerBlock = %d\n", attrs.maxThreadsPerBlock); + printf("numRegs = %d\n", attrs.numRegs); + printf("ptxVersion = %d\n", attrs.ptxVersion); + printf("binaryVersion = %d\n", attrs.binaryVersion); + printf("\n"); + fflush(stdout); + } +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif /* OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/functional.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/functional.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9f53d87527c1d7e23dd4bfdf7483cf92d04ba9d3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/functional.hpp @@ -0,0 +1,805 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_FUNCTIONAL_HPP +#define OPENCV_CUDA_FUNCTIONAL_HPP + +#include +#include "saturate_cast.hpp" +#include "vec_traits.hpp" +#include "type_traits.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + // Function Objects + template struct unary_function + { + typedef Argument argument_type; + typedef Result result_type; + }; + template struct binary_function + { + typedef Argument1 first_argument_type; + typedef Argument2 second_argument_type; + typedef Result result_type; + }; + + // Arithmetic Operations + template struct plus : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a + b; + } + __host__ __device__ __forceinline__ plus() {} + __host__ __device__ __forceinline__ plus(const plus&) {} + }; + + template struct minus : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a - b; + } + __host__ __device__ __forceinline__ minus() {} + __host__ __device__ __forceinline__ minus(const minus&) {} + }; + + template struct multiplies : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a * b; + } + __host__ __device__ __forceinline__ multiplies() {} + __host__ __device__ __forceinline__ multiplies(const multiplies&) {} + }; + + template struct divides : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a / b; + } + __host__ __device__ __forceinline__ divides() {} + __host__ __device__ __forceinline__ divides(const divides&) {} + }; + + template struct modulus : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a % b; + } + __host__ __device__ __forceinline__ modulus() {} + __host__ __device__ __forceinline__ modulus(const modulus&) {} + }; + + template struct negate : unary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a) const + { + return -a; + } + __host__ __device__ __forceinline__ negate() {} + __host__ __device__ __forceinline__ negate(const negate&) {} + }; + + // Comparison Operations + template struct equal_to : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a == b; + } + __host__ __device__ __forceinline__ equal_to() {} + __host__ __device__ __forceinline__ equal_to(const equal_to&) {} + }; + + template struct not_equal_to : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a != b; + } + __host__ __device__ __forceinline__ not_equal_to() {} + __host__ __device__ __forceinline__ not_equal_to(const not_equal_to&) {} + }; + + template struct greater : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a > b; + } + __host__ __device__ __forceinline__ greater() {} + __host__ __device__ __forceinline__ greater(const greater&) {} + }; + + template struct less : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a < b; + } + __host__ __device__ __forceinline__ less() {} + __host__ __device__ __forceinline__ less(const less&) {} + }; + + template struct greater_equal : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a >= b; + } + __host__ __device__ __forceinline__ greater_equal() {} + __host__ __device__ __forceinline__ greater_equal(const greater_equal&) {} + }; + + template struct less_equal : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a <= b; + } + __host__ __device__ __forceinline__ less_equal() {} + __host__ __device__ __forceinline__ less_equal(const less_equal&) {} + }; + + // Logical Operations + template struct logical_and : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a && b; + } + __host__ __device__ __forceinline__ logical_and() {} + __host__ __device__ __forceinline__ logical_and(const logical_and&) {} + }; + + template struct logical_or : binary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a || b; + } + __host__ __device__ __forceinline__ logical_or() {} + __host__ __device__ __forceinline__ logical_or(const logical_or&) {} + }; + + template struct logical_not : unary_function + { + __device__ __forceinline__ bool operator ()(typename TypeTraits::ParameterType a) const + { + return !a; + } + __host__ __device__ __forceinline__ logical_not() {} + __host__ __device__ __forceinline__ logical_not(const logical_not&) {} + }; + + // Bitwise Operations + template struct bit_and : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a & b; + } + __host__ __device__ __forceinline__ bit_and() {} + __host__ __device__ __forceinline__ bit_and(const bit_and&) {} + }; + + template struct bit_or : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a | b; + } + __host__ __device__ __forceinline__ bit_or() {} + __host__ __device__ __forceinline__ bit_or(const bit_or&) {} + }; + + template struct bit_xor : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType a, + typename TypeTraits::ParameterType b) const + { + return a ^ b; + } + __host__ __device__ __forceinline__ bit_xor() {} + __host__ __device__ __forceinline__ bit_xor(const bit_xor&) {} + }; + + template struct bit_not : unary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType v) const + { + return ~v; + } + __host__ __device__ __forceinline__ bit_not() {} + __host__ __device__ __forceinline__ bit_not(const bit_not&) {} + }; + + // Generalized Identity Operations + template struct identity : unary_function + { + __device__ __forceinline__ typename TypeTraits::ParameterType operator()(typename TypeTraits::ParameterType x) const + { + return x; + } + __host__ __device__ __forceinline__ identity() {} + __host__ __device__ __forceinline__ identity(const identity&) {} + }; + + template struct project1st : binary_function + { + __device__ __forceinline__ typename TypeTraits::ParameterType operator()(typename TypeTraits::ParameterType lhs, typename TypeTraits::ParameterType rhs) const + { + return lhs; + } + __host__ __device__ __forceinline__ project1st() {} + __host__ __device__ __forceinline__ project1st(const project1st&) {} + }; + + template struct project2nd : binary_function + { + __device__ __forceinline__ typename TypeTraits::ParameterType operator()(typename TypeTraits::ParameterType lhs, typename TypeTraits::ParameterType rhs) const + { + return rhs; + } + __host__ __device__ __forceinline__ project2nd() {} + __host__ __device__ __forceinline__ project2nd(const project2nd&) {} + }; + + // Min/Max Operations + +#define OPENCV_CUDA_IMPLEMENT_MINMAX(name, type, op) \ + template <> struct name : binary_function \ + { \ + __device__ __forceinline__ type operator()(type lhs, type rhs) const {return op(lhs, rhs);} \ + __host__ __device__ __forceinline__ name() {}\ + __host__ __device__ __forceinline__ name(const name&) {}\ + }; + + template struct maximum : binary_function + { + __device__ __forceinline__ T operator()(typename TypeTraits::ParameterType lhs, typename TypeTraits::ParameterType rhs) const + { + return max(lhs, rhs); + } + __host__ __device__ __forceinline__ maximum() {} + __host__ __device__ __forceinline__ maximum(const maximum&) {} + }; + + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, uchar, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, schar, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, char, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, ushort, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, short, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, int, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, uint, ::max) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, float, ::fmax) + OPENCV_CUDA_IMPLEMENT_MINMAX(maximum, double, ::fmax) + + template struct minimum : binary_function + { + __device__ __forceinline__ T operator()(typename TypeTraits::ParameterType lhs, typename TypeTraits::ParameterType rhs) const + { + return min(lhs, rhs); + } + __host__ __device__ __forceinline__ minimum() {} + __host__ __device__ __forceinline__ minimum(const minimum&) {} + }; + + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, uchar, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, schar, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, char, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, ushort, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, short, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, int, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, uint, ::min) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, float, ::fmin) + OPENCV_CUDA_IMPLEMENT_MINMAX(minimum, double, ::fmin) + +#undef OPENCV_CUDA_IMPLEMENT_MINMAX + + // Math functions + + template struct abs_func : unary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType x) const + { + return abs(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ unsigned char operator ()(unsigned char x) const + { + return x; + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ signed char operator ()(signed char x) const + { + return ::abs((int)x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ char operator ()(char x) const + { + return ::abs((int)x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ unsigned short operator ()(unsigned short x) const + { + return x; + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ short operator ()(short x) const + { + return ::abs((int)x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ unsigned int operator ()(unsigned int x) const + { + return x; + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ int operator ()(int x) const + { + return ::abs(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ float operator ()(float x) const + { + return ::fabsf(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + template <> struct abs_func : unary_function + { + __device__ __forceinline__ double operator ()(double x) const + { + return ::fabs(x); + } + + __host__ __device__ __forceinline__ abs_func() {} + __host__ __device__ __forceinline__ abs_func(const abs_func&) {} + }; + +#define OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(name, func) \ + template struct name ## _func : unary_function \ + { \ + __device__ __forceinline__ float operator ()(typename TypeTraits::ParameterType v) const \ + { \ + return func ## f(v); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; \ + template <> struct name ## _func : unary_function \ + { \ + __device__ __forceinline__ double operator ()(double v) const \ + { \ + return func(v); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; + +#define OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(name, func) \ + template struct name ## _func : binary_function \ + { \ + __device__ __forceinline__ float operator ()(typename TypeTraits::ParameterType v1, typename TypeTraits::ParameterType v2) const \ + { \ + return func ## f(v1, v2); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; \ + template <> struct name ## _func : binary_function \ + { \ + __device__ __forceinline__ double operator ()(double v1, double v2) const \ + { \ + return func(v1, v2); \ + } \ + __host__ __device__ __forceinline__ name ## _func() {} \ + __host__ __device__ __forceinline__ name ## _func(const name ## _func&) {} \ + }; + + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(sqrt, ::sqrt) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(exp, ::exp) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(exp2, ::exp2) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(exp10, ::exp10) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(log, ::log) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(log2, ::log2) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(log10, ::log10) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(sin, ::sin) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(cos, ::cos) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(tan, ::tan) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(asin, ::asin) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(acos, ::acos) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(atan, ::atan) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(sinh, ::sinh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(cosh, ::cosh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(tanh, ::tanh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(asinh, ::asinh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(acosh, ::acosh) + OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR(atanh, ::atanh) + + OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(hypot, ::hypot) + OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(atan2, ::atan2) + OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR(pow, ::pow) + + #undef OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR + #undef OPENCV_CUDA_IMPLEMENT_UN_FUNCTOR_NO_DOUBLE + #undef OPENCV_CUDA_IMPLEMENT_BIN_FUNCTOR + + template struct hypot_sqr_func : binary_function + { + __device__ __forceinline__ T operator ()(typename TypeTraits::ParameterType src1, typename TypeTraits::ParameterType src2) const + { + return src1 * src1 + src2 * src2; + } + __host__ __device__ __forceinline__ hypot_sqr_func() {} + __host__ __device__ __forceinline__ hypot_sqr_func(const hypot_sqr_func&) {} + }; + + // Saturate Cast Functor + template struct saturate_cast_func : unary_function + { + __device__ __forceinline__ D operator ()(typename TypeTraits::ParameterType v) const + { + return saturate_cast(v); + } + __host__ __device__ __forceinline__ saturate_cast_func() {} + __host__ __device__ __forceinline__ saturate_cast_func(const saturate_cast_func&) {} + }; + + // Threshold Functors + template struct thresh_binary_func : unary_function + { + __host__ __device__ __forceinline__ thresh_binary_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {} + + __device__ __forceinline__ T operator()(typename TypeTraits::ParameterType src) const + { + return (src > thresh) * maxVal; + } + + __host__ __device__ __forceinline__ thresh_binary_func() {} + __host__ __device__ __forceinline__ thresh_binary_func(const thresh_binary_func& other) + : thresh(other.thresh), maxVal(other.maxVal) {} + + T thresh; + T maxVal; + }; + + template struct thresh_binary_inv_func : unary_function + { + __host__ __device__ __forceinline__ thresh_binary_inv_func(T thresh_, T maxVal_) : thresh(thresh_), maxVal(maxVal_) {} + + __device__ __forceinline__ T operator()(typename TypeTraits::ParameterType src) const + { + return (src <= thresh) * maxVal; + } + + __host__ __device__ __forceinline__ thresh_binary_inv_func() {} + __host__ __device__ __forceinline__ thresh_binary_inv_func(const thresh_binary_inv_func& other) + : thresh(other.thresh), maxVal(other.maxVal) {} + + T thresh; + T maxVal; + }; + + template struct thresh_trunc_func : unary_function + { + explicit __host__ __device__ __forceinline__ thresh_trunc_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {CV_UNUSED(maxVal_);} + + __device__ __forceinline__ T operator()(typename TypeTraits::ParameterType src) const + { + return minimum()(src, thresh); + } + + __host__ __device__ __forceinline__ thresh_trunc_func() {} + __host__ __device__ __forceinline__ thresh_trunc_func(const thresh_trunc_func& other) + : thresh(other.thresh) {} + + T thresh; + }; + + template struct thresh_to_zero_func : unary_function + { + explicit __host__ __device__ __forceinline__ thresh_to_zero_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {CV_UNUSED(maxVal_);} + + __device__ __forceinline__ T operator()(typename TypeTraits::ParameterType src) const + { + return (src > thresh) * src; + } + + __host__ __device__ __forceinline__ thresh_to_zero_func() {} + __host__ __device__ __forceinline__ thresh_to_zero_func(const thresh_to_zero_func& other) + : thresh(other.thresh) {} + + T thresh; + }; + + template struct thresh_to_zero_inv_func : unary_function + { + explicit __host__ __device__ __forceinline__ thresh_to_zero_inv_func(T thresh_, T maxVal_ = 0) : thresh(thresh_) {CV_UNUSED(maxVal_);} + + __device__ __forceinline__ T operator()(typename TypeTraits::ParameterType src) const + { + return (src <= thresh) * src; + } + + __host__ __device__ __forceinline__ thresh_to_zero_inv_func() {} + __host__ __device__ __forceinline__ thresh_to_zero_inv_func(const thresh_to_zero_inv_func& other) + : thresh(other.thresh) {} + + T thresh; + }; + + // Function Object Adaptors + template struct unary_negate : unary_function + { + explicit __host__ __device__ __forceinline__ unary_negate(const Predicate& p) : pred(p) {} + + __device__ __forceinline__ bool operator()(typename TypeTraits::ParameterType x) const + { + return !pred(x); + } + + __host__ __device__ __forceinline__ unary_negate() {} + __host__ __device__ __forceinline__ unary_negate(const unary_negate& other) : pred(other.pred) {} + + Predicate pred; + }; + + template __host__ __device__ __forceinline__ unary_negate not1(const Predicate& pred) + { + return unary_negate(pred); + } + + template struct binary_negate : binary_function + { + explicit __host__ __device__ __forceinline__ binary_negate(const Predicate& p) : pred(p) {} + + __device__ __forceinline__ bool operator()(typename TypeTraits::ParameterType x, + typename TypeTraits::ParameterType y) const + { + return !pred(x,y); + } + + __host__ __device__ __forceinline__ binary_negate() {} + __host__ __device__ __forceinline__ binary_negate(const binary_negate& other) : pred(other.pred) {} + + Predicate pred; + }; + + template __host__ __device__ __forceinline__ binary_negate not2(const BinaryPredicate& pred) + { + return binary_negate(pred); + } + + template struct binder1st : unary_function + { + __host__ __device__ __forceinline__ binder1st(const Op& op_, const typename Op::first_argument_type& arg1_) : op(op_), arg1(arg1_) {} + + __device__ __forceinline__ typename Op::result_type operator ()(typename TypeTraits::ParameterType a) const + { + return op(arg1, a); + } + + __host__ __device__ __forceinline__ binder1st() {} + __host__ __device__ __forceinline__ binder1st(const binder1st& other) : op(other.op), arg1(other.arg1) {} + + Op op; + typename Op::first_argument_type arg1; + }; + + template __host__ __device__ __forceinline__ binder1st bind1st(const Op& op, const T& x) + { + return binder1st(op, typename Op::first_argument_type(x)); + } + + template struct binder2nd : unary_function + { + __host__ __device__ __forceinline__ binder2nd(const Op& op_, const typename Op::second_argument_type& arg2_) : op(op_), arg2(arg2_) {} + + __forceinline__ __device__ typename Op::result_type operator ()(typename TypeTraits::ParameterType a) const + { + return op(a, arg2); + } + + __host__ __device__ __forceinline__ binder2nd() {} + __host__ __device__ __forceinline__ binder2nd(const binder2nd& other) : op(other.op), arg2(other.arg2) {} + + Op op; + typename Op::second_argument_type arg2; + }; + + template __host__ __device__ __forceinline__ binder2nd bind2nd(const Op& op, const T& x) + { + return binder2nd(op, typename Op::second_argument_type(x)); + } + + // Functor Traits + template struct IsUnaryFunction + { + typedef char Yes; + struct No {Yes a[2];}; + + template static Yes check(unary_function); + static No check(...); + + static F makeF(); + + enum { value = (sizeof(check(makeF())) == sizeof(Yes)) }; + }; + + template struct IsBinaryFunction + { + typedef char Yes; + struct No {Yes a[2];}; + + template static Yes check(binary_function); + static No check(...); + + static F makeF(); + + enum { value = (sizeof(check(makeF())) == sizeof(Yes)) }; + }; + + namespace functional_detail + { + template struct UnOpShift { enum { shift = 1 }; }; + template struct UnOpShift { enum { shift = 4 }; }; + template struct UnOpShift { enum { shift = 2 }; }; + + template struct DefaultUnaryShift + { + enum { shift = UnOpShift::shift }; + }; + + template struct BinOpShift { enum { shift = 1 }; }; + template struct BinOpShift { enum { shift = 4 }; }; + template struct BinOpShift { enum { shift = 2 }; }; + + template struct DefaultBinaryShift + { + enum { shift = BinOpShift::shift }; + }; + + template ::value> struct ShiftDispatcher; + template struct ShiftDispatcher + { + enum { shift = DefaultUnaryShift::shift }; + }; + template struct ShiftDispatcher + { + enum { shift = DefaultBinaryShift::shift }; + }; + } + + template struct DefaultTransformShift + { + enum { shift = functional_detail::ShiftDispatcher::shift }; + }; + + template struct DefaultTransformFunctorTraits + { + enum { simple_block_dim_x = 16 }; + enum { simple_block_dim_y = 16 }; + + enum { smart_block_dim_x = 16 }; + enum { smart_block_dim_y = 16 }; + enum { smart_shift = DefaultTransformShift::shift }; + }; + + template struct TransformFunctorTraits : DefaultTransformFunctorTraits {}; + +#define OPENCV_CUDA_TRANSFORM_FUNCTOR_TRAITS(type) \ + template <> struct TransformFunctorTraits< type > : DefaultTransformFunctorTraits< type > +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_FUNCTIONAL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/limits.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/limits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7e15ed629a395ae7a79e46883bd8f0d67eebb8ee --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/limits.hpp @@ -0,0 +1,128 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_LIMITS_HPP +#define OPENCV_CUDA_LIMITS_HPP + +#include +#include +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ +template struct numeric_limits; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static bool min() { return false; } + __device__ __forceinline__ static bool max() { return true; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static signed char min() { return SCHAR_MIN; } + __device__ __forceinline__ static signed char max() { return SCHAR_MAX; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static unsigned char min() { return 0; } + __device__ __forceinline__ static unsigned char max() { return UCHAR_MAX; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static short min() { return SHRT_MIN; } + __device__ __forceinline__ static short max() { return SHRT_MAX; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static unsigned short min() { return 0; } + __device__ __forceinline__ static unsigned short max() { return USHRT_MAX; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static int min() { return INT_MIN; } + __device__ __forceinline__ static int max() { return INT_MAX; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static unsigned int min() { return 0; } + __device__ __forceinline__ static unsigned int max() { return UINT_MAX; } + static const bool is_signed = false; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static float min() { return FLT_MIN; } + __device__ __forceinline__ static float max() { return FLT_MAX; } + __device__ __forceinline__ static float epsilon() { return FLT_EPSILON; } + static const bool is_signed = true; +}; + +template <> struct numeric_limits +{ + __device__ __forceinline__ static double min() { return DBL_MIN; } + __device__ __forceinline__ static double max() { return DBL_MAX; } + __device__ __forceinline__ static double epsilon() { return DBL_EPSILON; } + static const bool is_signed = true; +}; +}}} // namespace cv { namespace cuda { namespace cudev { + +//! @endcond + +#endif // OPENCV_CUDA_LIMITS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/reduce.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/reduce.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5de365081789d6be1b6e5b35f3648fa07e091650 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/reduce.hpp @@ -0,0 +1,209 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_REDUCE_HPP +#define OPENCV_CUDA_REDUCE_HPP + +#ifndef THRUST_DEBUG // eliminate -Wundef warning +#define THRUST_DEBUG 0 +#endif + +#include +#include "detail/reduce.hpp" +#include "detail/reduce_key_val.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template + __device__ __forceinline__ void reduce(volatile T* smem, T& val, unsigned int tid, const Op& op) + { + reduce_detail::Dispatcher::reductor::template reduce(smem, val, tid, op); + } + template + __device__ __forceinline__ void reduce(const thrust::tuple& smem, + const thrust::tuple& val, + unsigned int tid, + const thrust::tuple& op) + { + reduce_detail::Dispatcher::reductor::template reduce< + const thrust::tuple&, + const thrust::tuple&, + const thrust::tuple&>(smem, val, tid, op); + } + + template + __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key, volatile V* svals, V& val, unsigned int tid, const Cmp& cmp) + { + reduce_key_val_detail::Dispatcher::reductor::template reduce(skeys, key, svals, val, tid, cmp); + } + template + __device__ __forceinline__ void reduceKeyVal(volatile K* skeys, K& key, + const thrust::tuple& svals, + const thrust::tuple& val, + unsigned int tid, const Cmp& cmp) + { + reduce_key_val_detail::Dispatcher::reductor::template reduce&, + const thrust::tuple&, + const Cmp&>(skeys, key, svals, val, tid, cmp); + } + template + __device__ __forceinline__ void reduceKeyVal(const thrust::tuple& skeys, + const thrust::tuple& key, + const thrust::tuple& svals, + const thrust::tuple& val, + unsigned int tid, + const thrust::tuple& cmp) + { + reduce_key_val_detail::Dispatcher::reductor::template reduce< + const thrust::tuple&, + const thrust::tuple&, + const thrust::tuple&, + const thrust::tuple&, + const thrust::tuple& + >(skeys, key, svals, val, tid, cmp); + } + + // smem_tuple + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0) + { + return thrust::make_tuple((volatile T0*) t0); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7, (volatile T8*) t8); + } + + template + __device__ __forceinline__ + thrust::tuple + smem_tuple(T0* t0, T1* t1, T2* t2, T3* t3, T4* t4, T5* t5, T6* t6, T7* t7, T8* t8, T9* t9) + { + return thrust::make_tuple((volatile T0*) t0, (volatile T1*) t1, (volatile T2*) t2, (volatile T3*) t3, (volatile T4*) t4, (volatile T5*) t5, (volatile T6*) t6, (volatile T7*) t7, (volatile T8*) t8, (volatile T9*) t9); + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_REDUCE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/saturate_cast.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/saturate_cast.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c3a3d1cb8338375118930fc7abf918e57a041ceb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/saturate_cast.hpp @@ -0,0 +1,292 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_SATURATE_CAST_HPP +#define OPENCV_CUDA_SATURATE_CAST_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template __device__ __forceinline__ _Tp saturate_cast(uchar v) { return _Tp(v); } + template __device__ __forceinline__ _Tp saturate_cast(schar v) { return _Tp(v); } + template __device__ __forceinline__ _Tp saturate_cast(ushort v) { return _Tp(v); } + template __device__ __forceinline__ _Tp saturate_cast(short v) { return _Tp(v); } + template __device__ __forceinline__ _Tp saturate_cast(uint v) { return _Tp(v); } + template __device__ __forceinline__ _Tp saturate_cast(int v) { return _Tp(v); } + template __device__ __forceinline__ _Tp saturate_cast(float v) { return _Tp(v); } + template __device__ __forceinline__ _Tp saturate_cast(double v) { return _Tp(v); } + + template<> __device__ __forceinline__ uchar saturate_cast(schar v) + { + uint res = 0; + int vi = v; + asm("cvt.sat.u8.s8 %0, %1;" : "=r"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast(short v) + { + uint res = 0; + asm("cvt.sat.u8.s16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast(ushort v) + { + uint res = 0; + asm("cvt.sat.u8.u16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast(int v) + { + uint res = 0; + asm("cvt.sat.u8.s32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast(uint v) + { + uint res = 0; + asm("cvt.sat.u8.u32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast(float v) + { + uint res = 0; + asm("cvt.rni.sat.u8.f32 %0, %1;" : "=r"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ uchar saturate_cast(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + uint res = 0; + asm("cvt.rni.sat.u8.f64 %0, %1;" : "=r"(res) : "d"(v)); + return res; + #else + return saturate_cast((float)v); + #endif + } + + template<> __device__ __forceinline__ schar saturate_cast(uchar v) + { + uint res = 0; + uint vi = v; + asm("cvt.sat.s8.u8 %0, %1;" : "=r"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast(short v) + { + uint res = 0; + asm("cvt.sat.s8.s16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast(ushort v) + { + uint res = 0; + asm("cvt.sat.s8.u16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast(int v) + { + uint res = 0; + asm("cvt.sat.s8.s32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast(uint v) + { + uint res = 0; + asm("cvt.sat.s8.u32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast(float v) + { + uint res = 0; + asm("cvt.rni.sat.s8.f32 %0, %1;" : "=r"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ schar saturate_cast(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + uint res = 0; + asm("cvt.rni.sat.s8.f64 %0, %1;" : "=r"(res) : "d"(v)); + return res; + #else + return saturate_cast((float)v); + #endif + } + + template<> __device__ __forceinline__ ushort saturate_cast(schar v) + { + ushort res = 0; + int vi = v; + asm("cvt.sat.u16.s8 %0, %1;" : "=h"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast(short v) + { + ushort res = 0; + asm("cvt.sat.u16.s16 %0, %1;" : "=h"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast(int v) + { + ushort res = 0; + asm("cvt.sat.u16.s32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast(uint v) + { + ushort res = 0; + asm("cvt.sat.u16.u32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast(float v) + { + ushort res = 0; + asm("cvt.rni.sat.u16.f32 %0, %1;" : "=h"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ ushort saturate_cast(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + ushort res = 0; + asm("cvt.rni.sat.u16.f64 %0, %1;" : "=h"(res) : "d"(v)); + return res; + #else + return saturate_cast((float)v); + #endif + } + + template<> __device__ __forceinline__ short saturate_cast(ushort v) + { + short res = 0; + asm("cvt.sat.s16.u16 %0, %1;" : "=h"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast(int v) + { + short res = 0; + asm("cvt.sat.s16.s32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast(uint v) + { + short res = 0; + asm("cvt.sat.s16.u32 %0, %1;" : "=h"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast(float v) + { + short res = 0; + asm("cvt.rni.sat.s16.f32 %0, %1;" : "=h"(res) : "f"(v)); + return res; + } + template<> __device__ __forceinline__ short saturate_cast(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + short res = 0; + asm("cvt.rni.sat.s16.f64 %0, %1;" : "=h"(res) : "d"(v)); + return res; + #else + return saturate_cast((float)v); + #endif + } + + template<> __device__ __forceinline__ int saturate_cast(uint v) + { + int res = 0; + asm("cvt.sat.s32.u32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ int saturate_cast(float v) + { + return __float2int_rn(v); + } + template<> __device__ __forceinline__ int saturate_cast(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + return __double2int_rn(v); + #else + return saturate_cast((float)v); + #endif + } + + template<> __device__ __forceinline__ uint saturate_cast(schar v) + { + uint res = 0; + int vi = v; + asm("cvt.sat.u32.s8 %0, %1;" : "=r"(res) : "r"(vi)); + return res; + } + template<> __device__ __forceinline__ uint saturate_cast(short v) + { + uint res = 0; + asm("cvt.sat.u32.s16 %0, %1;" : "=r"(res) : "h"(v)); + return res; + } + template<> __device__ __forceinline__ uint saturate_cast(int v) + { + uint res = 0; + asm("cvt.sat.u32.s32 %0, %1;" : "=r"(res) : "r"(v)); + return res; + } + template<> __device__ __forceinline__ uint saturate_cast(float v) + { + return __float2uint_rn(v); + } + template<> __device__ __forceinline__ uint saturate_cast(double v) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 130 + return __double2uint_rn(v); + #else + return saturate_cast((float)v); + #endif + } +}}} + +//! @endcond + +#endif /* OPENCV_CUDA_SATURATE_CAST_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/scan.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/scan.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e128fb0962efb20ecaa6b16c545b16d5917549f4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/scan.hpp @@ -0,0 +1,258 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_SCAN_HPP +#define OPENCV_CUDA_SCAN_HPP + +#include "opencv2/core/cuda/common.hpp" +#include "opencv2/core/cuda/utility.hpp" +#include "opencv2/core/cuda/warp.hpp" +#include "opencv2/core/cuda/warp_shuffle.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + enum ScanKind { EXCLUSIVE = 0, INCLUSIVE = 1 }; + + template struct WarpScan + { + __device__ __forceinline__ WarpScan() {} + __device__ __forceinline__ WarpScan(const WarpScan& other) { CV_UNUSED(other); } + + __device__ __forceinline__ T operator()( volatile T *ptr , const unsigned int idx) + { + const unsigned int lane = idx & 31; + F op; + + if ( lane >= 1) ptr [idx ] = op(ptr [idx - 1], ptr [idx]); + if ( lane >= 2) ptr [idx ] = op(ptr [idx - 2], ptr [idx]); + if ( lane >= 4) ptr [idx ] = op(ptr [idx - 4], ptr [idx]); + if ( lane >= 8) ptr [idx ] = op(ptr [idx - 8], ptr [idx]); + if ( lane >= 16) ptr [idx ] = op(ptr [idx - 16], ptr [idx]); + + if( Kind == INCLUSIVE ) + return ptr [idx]; + else + return (lane > 0) ? ptr [idx - 1] : 0; + } + + __device__ __forceinline__ unsigned int index(const unsigned int tid) + { + return tid; + } + + __device__ __forceinline__ void init(volatile T *ptr){} + + static const int warp_offset = 0; + + typedef WarpScan merge; + }; + + template struct WarpScanNoComp + { + __device__ __forceinline__ WarpScanNoComp() {} + __device__ __forceinline__ WarpScanNoComp(const WarpScanNoComp& other) { CV_UNUSED(other); } + + __device__ __forceinline__ T operator()( volatile T *ptr , const unsigned int idx) + { + const unsigned int lane = threadIdx.x & 31; + F op; + + ptr [idx ] = op(ptr [idx - 1], ptr [idx]); + ptr [idx ] = op(ptr [idx - 2], ptr [idx]); + ptr [idx ] = op(ptr [idx - 4], ptr [idx]); + ptr [idx ] = op(ptr [idx - 8], ptr [idx]); + ptr [idx ] = op(ptr [idx - 16], ptr [idx]); + + if( Kind == INCLUSIVE ) + return ptr [idx]; + else + return (lane > 0) ? ptr [idx - 1] : 0; + } + + __device__ __forceinline__ unsigned int index(const unsigned int tid) + { + return (tid >> warp_log) * warp_smem_stride + 16 + (tid & warp_mask); + } + + __device__ __forceinline__ void init(volatile T *ptr) + { + ptr[threadIdx.x] = 0; + } + + static const int warp_smem_stride = 32 + 16 + 1; + static const int warp_offset = 16; + static const int warp_log = 5; + static const int warp_mask = 31; + + typedef WarpScanNoComp merge; + }; + + template struct BlockScan + { + __device__ __forceinline__ BlockScan() {} + __device__ __forceinline__ BlockScan(const BlockScan& other) { CV_UNUSED(other); } + + __device__ __forceinline__ T operator()(volatile T *ptr) + { + const unsigned int tid = threadIdx.x; + const unsigned int lane = tid & warp_mask; + const unsigned int warp = tid >> warp_log; + + Sc scan; + typename Sc::merge merge_scan; + const unsigned int idx = scan.index(tid); + + T val = scan(ptr, idx); + __syncthreads (); + + if( warp == 0) + scan.init(ptr); + __syncthreads (); + + if( lane == 31 ) + ptr [scan.warp_offset + warp ] = (Kind == INCLUSIVE) ? val : ptr [idx]; + __syncthreads (); + + if( warp == 0 ) + merge_scan(ptr, idx); + __syncthreads(); + + if ( warp > 0) + val = ptr [scan.warp_offset + warp - 1] + val; + __syncthreads (); + + ptr[idx] = val; + __syncthreads (); + + return val ; + } + + static const int warp_log = 5; + static const int warp_mask = 31; + }; + + template + __device__ T warpScanInclusive(T idata, volatile T* s_Data, unsigned int tid) + { + #if __CUDA_ARCH__ >= 300 + const unsigned int laneId = cv::cuda::device::Warp::laneId(); + + // scan on shuffl functions + #pragma unroll + for (int i = 1; i <= (OPENCV_CUDA_WARP_SIZE / 2); i *= 2) + { + const T n = cv::cuda::device::shfl_up(idata, i); + if (laneId >= i) + idata += n; + } + + return idata; + #else + unsigned int pos = 2 * tid - (tid & (OPENCV_CUDA_WARP_SIZE - 1)); + s_Data[pos] = 0; + pos += OPENCV_CUDA_WARP_SIZE; + s_Data[pos] = idata; + + s_Data[pos] += s_Data[pos - 1]; + s_Data[pos] += s_Data[pos - 2]; + s_Data[pos] += s_Data[pos - 4]; + s_Data[pos] += s_Data[pos - 8]; + s_Data[pos] += s_Data[pos - 16]; + + return s_Data[pos]; + #endif + } + + template + __device__ __forceinline__ T warpScanExclusive(T idata, volatile T* s_Data, unsigned int tid) + { + return warpScanInclusive(idata, s_Data, tid) - idata; + } + + template + __device__ T blockScanInclusive(T idata, volatile T* s_Data, unsigned int tid) + { + if (tiNumScanThreads > OPENCV_CUDA_WARP_SIZE) + { + //Bottom-level inclusive warp scan + T warpResult = warpScanInclusive(idata, s_Data, tid); + + //Save top elements of each warp for exclusive warp scan + //sync to wait for warp scans to complete (because s_Data is being overwritten) + __syncthreads(); + if ((tid & (OPENCV_CUDA_WARP_SIZE - 1)) == (OPENCV_CUDA_WARP_SIZE - 1)) + { + s_Data[tid >> OPENCV_CUDA_LOG_WARP_SIZE] = warpResult; + } + + //wait for warp scans to complete + __syncthreads(); + + if (tid < (tiNumScanThreads / OPENCV_CUDA_WARP_SIZE) ) + { + //grab top warp elements + T val = s_Data[tid]; + //calculate exclusive scan and write back to shared memory + s_Data[tid] = warpScanExclusive(val, s_Data, tid); + } + + //return updated warp scans with exclusive scan results + __syncthreads(); + + return warpResult + s_Data[tid >> OPENCV_CUDA_LOG_WARP_SIZE]; + } + else + { + return warpScanInclusive(idata, s_Data, tid); + } + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_SCAN_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/simd_functions.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/simd_functions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3d8c2e0d8e56ae109e1f7ab839aec46b492c556c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/simd_functions.hpp @@ -0,0 +1,869 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +/* + * Copyright (c) 2013 NVIDIA Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of NVIDIA Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef OPENCV_CUDA_SIMD_FUNCTIONS_HPP +#define OPENCV_CUDA_SIMD_FUNCTIONS_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + // 2 + + static __device__ __forceinline__ unsigned int vadd2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vadd2.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vadd.u32.u32.u32.sat %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = a ^ b; // sum bits + r = a + b; // actual sum + s = s ^ r; // determine carry-ins for each bit position + s = s & 0x00010000; // carry-in to high word (= carry-out from low word) + r = r - s; // subtract out carry-out from low word + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsub2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vsub2.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vsub.u32.u32.u32.sat %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = a ^ b; // sum bits + r = a - b; // actual sum + s = s ^ r; // determine carry-ins for each bit position + s = s & 0x00010000; // borrow to high word + r = r + s; // compensate for borrow from low word + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vabsdiff2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vabsdiff2.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vabsdiff.u32.u32.u32.sat %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t, u, v; + s = a & 0x0000ffff; // extract low halfword + r = b & 0x0000ffff; // extract low halfword + u = ::max(r, s); // maximum of low halfwords + v = ::min(r, s); // minimum of low halfwords + s = a & 0xffff0000; // extract high halfword + r = b & 0xffff0000; // extract high halfword + t = ::max(r, s); // maximum of high halfwords + s = ::min(r, s); // minimum of high halfwords + r = u | t; // maximum of both halfwords + s = v | s; // minimum of both halfwords + r = r - s; // |a - b| = max(a,b) - min(a,b); + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vavg2(unsigned int a, unsigned int b) + { + unsigned int r, s; + + // HAKMEM #23: a + b = 2 * (a & b) + (a ^ b) ==> + // (a + b) / 2 = (a & b) + ((a ^ b) >> 1) + s = a ^ b; + r = a & b; + s = s & 0xfffefffe; // ensure shift doesn't cross halfword boundaries + s = s >> 1; + s = r + s; + + return s; + } + + static __device__ __forceinline__ unsigned int vavrg2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vavrg2.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // HAKMEM #23: a + b = 2 * (a | b) - (a ^ b) ==> + // (a + b + 1) / 2 = (a | b) - ((a ^ b) >> 1) + unsigned int s; + s = a ^ b; + r = a | b; + s = s & 0xfffefffe; // ensure shift doesn't cross half-word boundaries + s = s >> 1; + r = r - s; + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vseteq2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.eq %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + r = r ^ c; // extract msbs, msb = 1 if r < 0x8000 + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r & ~c; // msb = 1, if r was 0x0000 + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpeq2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vseteq2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + r = r ^ c; // extract msbs, msb = 1 if r < 0x8000 + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r & ~c; // msb = 1, if r was 0x0000 + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetge2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.ge %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavrg2(a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpge2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetge2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavrg2(a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetgt2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.gt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg2(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80008000; // msbs = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpgt2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetgt2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg2(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80008000; // msbs = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetle2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.le %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg2(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmple2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetle2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg2(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetlt2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset2.u32.u32.lt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg2(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmplt2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetlt2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg2(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80008000; // msb = carry-outs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetne2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm ("vset2.u32.u32.ne %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r | c; // msb = 1, if r was not 0x0000 + c = c & 0x80008000; // extract msbs + r = c >> 15; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpne2(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetne2(a, b); + c = r << 16; // convert bool + r = c - r; // into mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + r = a ^ b; // 0x0000 if a == b + c = r | 0x80008000; // set msbs, to catch carry out + c = c - 0x00010001; // msb = 0, if r was 0x0000 or 0x8000 + c = r | c; // msb = 1, if r was not 0x0000 + c = c & 0x80008000; // extract msbs + r = c >> 15; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vmax2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmax2.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmax.u32.u32.u32 %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t, u; + r = a & 0x0000ffff; // extract low halfword + s = b & 0x0000ffff; // extract low halfword + t = ::max(r, s); // maximum of low halfwords + r = a & 0xffff0000; // extract high halfword + s = b & 0xffff0000; // extract high halfword + u = ::max(r, s); // maximum of high halfwords + r = t | u; // combine halfword maximums + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vmin2(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmin2.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmin.u32.u32.u32 %0.h0, %1.h0, %2.h0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.h1, %1.h1, %2.h1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t, u; + r = a & 0x0000ffff; // extract low halfword + s = b & 0x0000ffff; // extract low halfword + t = ::min(r, s); // minimum of low halfwords + r = a & 0xffff0000; // extract high halfword + s = b & 0xffff0000; // extract high halfword + u = ::min(r, s); // minimum of high halfwords + r = t | u; // combine halfword minimums + #endif + + return r; + } + + // 4 + + static __device__ __forceinline__ unsigned int vadd4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vadd4.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vadd.u32.u32.u32.sat %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vadd.u32.u32.u32.sat %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t; + s = a ^ b; // sum bits + r = a & 0x7f7f7f7f; // clear msbs + t = b & 0x7f7f7f7f; // clear msbs + s = s & 0x80808080; // msb sum bits + r = r + t; // add without msbs, record carry-out in msbs + r = r ^ s; // sum of msb sum and carry-in bits, w/o carry-out + #endif /* __CUDA_ARCH__ >= 300 */ + + return r; + } + + static __device__ __forceinline__ unsigned int vsub4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vsub4.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vsub.u32.u32.u32.sat %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vsub.u32.u32.u32.sat %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s, t; + s = a ^ ~b; // inverted sum bits + r = a | 0x80808080; // set msbs + t = b & 0x7f7f7f7f; // clear msbs + s = s & 0x80808080; // inverted msb sum bits + r = r - t; // subtract w/o msbs, record inverted borrows in msb + r = r ^ s; // combine inverted msb sum bits and borrows + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vavg4(unsigned int a, unsigned int b) + { + unsigned int r, s; + + // HAKMEM #23: a + b = 2 * (a & b) + (a ^ b) ==> + // (a + b) / 2 = (a & b) + ((a ^ b) >> 1) + s = a ^ b; + r = a & b; + s = s & 0xfefefefe; // ensure following shift doesn't cross byte boundaries + s = s >> 1; + s = r + s; + + return s; + } + + static __device__ __forceinline__ unsigned int vavrg4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vavrg4.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // HAKMEM #23: a + b = 2 * (a | b) - (a ^ b) ==> + // (a + b + 1) / 2 = (a | b) - ((a ^ b) >> 1) + unsigned int c; + c = a ^ b; + r = a | b; + c = c & 0xfefefefe; // ensure following shift doesn't cross byte boundaries + c = c >> 1; + r = r - c; + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vseteq4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.eq %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x00 if a == b + c = r | 0x80808080; // set msbs, to catch carry out + r = r ^ c; // extract msbs, msb = 1 if r < 0x80 + c = c - 0x01010101; // msb = 0, if r was 0x00 or 0x80 + c = r & ~c; // msb = 1, if r was 0x00 + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpeq4(unsigned int a, unsigned int b) + { + unsigned int r, t; + + #if __CUDA_ARCH__ >= 300 + r = vseteq4(a, b); + t = r << 8; // convert bool + r = t - r; // to mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + t = a ^ b; // 0x00 if a == b + r = t | 0x80808080; // set msbs, to catch carry out + t = t ^ r; // extract msbs, msb = 1 if t < 0x80 + r = r - 0x01010101; // msb = 0, if t was 0x00 or 0x80 + r = t & ~r; // msb = 1, if t was 0x00 + t = r >> 7; // build mask + t = r - t; // from + r = t | r; // msbs + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetle4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.le %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg4(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmple4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetle4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavrg4(a, b); // (b + ~a + 1) / 2 = (b - a) / 2 + c = c & 0x80808080; // msbs = carry-outs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetlt4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.lt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg4(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmplt4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetlt4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + asm("not.b32 %0, %0;" : "+r"(a)); + c = vavg4(a, b); // (b + ~a) / 2 = (b - a) / 2 [rounded down] + c = c & 0x80808080; // msbs = carry-outs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetge4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.ge %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavrg4(a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpge4(unsigned int a, unsigned int b) + { + unsigned int r, s; + + #if __CUDA_ARCH__ >= 300 + r = vsetge4(a, b); + s = r << 8; // convert bool + r = s - r; // to mask + #else + asm ("not.b32 %0,%0;" : "+r"(b)); + r = vavrg4 (a, b); // (a + ~b + 1) / 2 = (a - b) / 2 + r = r & 0x80808080; // msb = carry-outs + s = r >> 7; // build mask + s = r - s; // from + r = s | r; // msbs + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetgt4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.gt %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int c; + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg4(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpgt4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetgt4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + asm("not.b32 %0, %0;" : "+r"(b)); + c = vavg4(a, b); // (a + ~b) / 2 = (a - b) / 2 [rounded down] + c = c & 0x80808080; // msb = carry-outs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vsetne4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vset4.u32.u32.ne %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + unsigned int c; + r = a ^ b; // 0x00 if a == b + c = r | 0x80808080; // set msbs, to catch carry out + c = c - 0x01010101; // msb = 0, if r was 0x00 or 0x80 + c = r | c; // msb = 1, if r was not 0x00 + c = c & 0x80808080; // extract msbs + r = c >> 7; // convert to bool + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vcmpne4(unsigned int a, unsigned int b) + { + unsigned int r, c; + + #if __CUDA_ARCH__ >= 300 + r = vsetne4(a, b); + c = r << 8; // convert bool + r = c - r; // to mask + #else + // inspired by Alan Mycroft's null-byte detection algorithm: + // null_byte(x) = ((x - 0x01010101) & (~x & 0x80808080)) + r = a ^ b; // 0x00 if a == b + c = r | 0x80808080; // set msbs, to catch carry out + c = c - 0x01010101; // msb = 0, if r was 0x00 or 0x80 + c = r | c; // msb = 1, if r was not 0x00 + c = c & 0x80808080; // extract msbs + r = c >> 7; // convert + r = c - r; // msbs to + r = c | r; // mask + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vabsdiff4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vabsdiff4.u32.u32.u32.sat %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vabsdiff.u32.u32.u32.sat %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vabsdiff.u32.u32.u32.sat %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = vcmpge4(a, b); // mask = 0xff if a >= b + r = a ^ b; // + s = (r & s) ^ b; // select a when a >= b, else select b => max(a,b) + r = s ^ r; // select a when b >= a, else select b => min(a,b) + r = s - r; // |a - b| = max(a,b) - min(a,b); + #endif + + return r; + } + + static __device__ __forceinline__ unsigned int vmax4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmax4.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmax.u32.u32.u32 %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmax.u32.u32.u32 %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = vcmpge4(a, b); // mask = 0xff if a >= b + r = a & s; // select a when b >= a + s = b & ~s; // select b when b < a + r = r | s; // combine byte selections + #endif + + return r; // byte-wise unsigned maximum + } + + static __device__ __forceinline__ unsigned int vmin4(unsigned int a, unsigned int b) + { + unsigned int r = 0; + + #if __CUDA_ARCH__ >= 300 + asm("vmin4.u32.u32.u32 %0, %1, %2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #elif __CUDA_ARCH__ >= 200 + asm("vmin.u32.u32.u32 %0.b0, %1.b0, %2.b0, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.b1, %1.b1, %2.b1, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.b2, %1.b2, %2.b2, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + asm("vmin.u32.u32.u32 %0.b3, %1.b3, %2.b3, %3;" : "=r"(r) : "r"(a), "r"(b), "r"(r)); + #else + unsigned int s; + s = vcmpge4(b, a); // mask = 0xff if a >= b + r = a & s; // select a when b >= a + s = b & ~s; // select b when b < a + r = r | s; // combine byte selections + #endif + + return r; + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_SIMD_FUNCTIONS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/transform.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/transform.hpp new file mode 100644 index 0000000000000000000000000000000000000000..42aa6ea170f21f95fc1e3702c2c410dbd3cc45e7 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/transform.hpp @@ -0,0 +1,75 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_TRANSFORM_HPP +#define OPENCV_CUDA_TRANSFORM_HPP + +#include "common.hpp" +#include "utility.hpp" +#include "detail/transform_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template + static inline void transform(PtrStepSz src, PtrStepSz dst, UnOp op, const Mask& mask, cudaStream_t stream) + { + typedef TransformFunctorTraits ft; + transform_detail::TransformDispatcher::cn == 1 && VecTraits::cn == 1 && ft::smart_shift != 1>::call(src, dst, op, mask, stream); + } + + template + static inline void transform(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, BinOp op, const Mask& mask, cudaStream_t stream) + { + typedef TransformFunctorTraits ft; + transform_detail::TransformDispatcher::cn == 1 && VecTraits::cn == 1 && VecTraits::cn == 1 && ft::smart_shift != 1>::call(src1, src2, dst, op, mask, stream); + } +}}} + +//! @endcond + +#endif // OPENCV_CUDA_TRANSFORM_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/type_traits.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/type_traits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8b7a3fd16832df41f6bdb47a06569f6265ccad9d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/type_traits.hpp @@ -0,0 +1,90 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_TYPE_TRAITS_HPP +#define OPENCV_CUDA_TYPE_TRAITS_HPP + +#include "detail/type_traits_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template struct IsSimpleParameter + { + enum {value = type_traits_detail::IsIntegral::value || type_traits_detail::IsFloat::value || + type_traits_detail::PointerTraits::type>::value}; + }; + + template struct TypeTraits + { + typedef typename type_traits_detail::UnConst::type NonConstType; + typedef typename type_traits_detail::UnVolatile::type NonVolatileType; + typedef typename type_traits_detail::UnVolatile::type>::type UnqualifiedType; + typedef typename type_traits_detail::PointerTraits::type PointeeType; + typedef typename type_traits_detail::ReferenceTraits::type ReferredType; + + enum { isConst = type_traits_detail::UnConst::value }; + enum { isVolatile = type_traits_detail::UnVolatile::value }; + + enum { isReference = type_traits_detail::ReferenceTraits::value }; + enum { isPointer = type_traits_detail::PointerTraits::type>::value }; + + enum { isUnsignedInt = type_traits_detail::IsUnsignedIntegral::value }; + enum { isSignedInt = type_traits_detail::IsSignedIntergral::value }; + enum { isIntegral = type_traits_detail::IsIntegral::value }; + enum { isFloat = type_traits_detail::IsFloat::value }; + enum { isArith = isIntegral || isFloat }; + enum { isVec = type_traits_detail::IsVec::value }; + + typedef typename type_traits_detail::Select::value, + T, typename type_traits_detail::AddParameterType::type>::type ParameterType; + }; +}}} + +//! @endcond + +#endif // OPENCV_CUDA_TYPE_TRAITS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/utility.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/utility.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7f5db48a500f6e8b0399c04ad05d79a0a0137741 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/utility.hpp @@ -0,0 +1,230 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_UTILITY_HPP +#define OPENCV_CUDA_UTILITY_HPP + +#include "saturate_cast.hpp" +#include "datamov_utils.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct CV_EXPORTS ThrustAllocator + { + typedef uchar value_type; + virtual ~ThrustAllocator(); + virtual __device__ __host__ uchar* allocate(size_t numBytes) = 0; + virtual __device__ __host__ void deallocate(uchar* ptr, size_t numBytes) = 0; + static ThrustAllocator& getAllocator(); + static void setAllocator(ThrustAllocator* allocator); + }; + #define OPENCV_CUDA_LOG_WARP_SIZE (5) + #define OPENCV_CUDA_WARP_SIZE (1 << OPENCV_CUDA_LOG_WARP_SIZE) + #define OPENCV_CUDA_LOG_MEM_BANKS ((__CUDA_ARCH__ >= 200) ? 5 : 4) // 32 banks on fermi, 16 on tesla + #define OPENCV_CUDA_MEM_BANKS (1 << OPENCV_CUDA_LOG_MEM_BANKS) + + /////////////////////////////////////////////////////////////////////////////// + // swap + + template void __device__ __host__ __forceinline__ swap(T& a, T& b) + { + const T temp = a; + a = b; + b = temp; + } + + /////////////////////////////////////////////////////////////////////////////// + // Mask Reader + + struct SingleMask + { + explicit __host__ __device__ __forceinline__ SingleMask(PtrStepb mask_) : mask(mask_) {} + __host__ __device__ __forceinline__ SingleMask(const SingleMask& mask_): mask(mask_.mask){} + + __device__ __forceinline__ bool operator()(int y, int x) const + { + return mask.ptr(y)[x] != 0; + } + + PtrStepb mask; + }; + + struct SingleMaskChannels + { + __host__ __device__ __forceinline__ SingleMaskChannels(PtrStepb mask_, int channels_) + : mask(mask_), channels(channels_) {} + __host__ __device__ __forceinline__ SingleMaskChannels(const SingleMaskChannels& mask_) + :mask(mask_.mask), channels(mask_.channels){} + + __device__ __forceinline__ bool operator()(int y, int x) const + { + return mask.ptr(y)[x / channels] != 0; + } + + PtrStepb mask; + int channels; + }; + + struct MaskCollection + { + explicit __host__ __device__ __forceinline__ MaskCollection(PtrStepb* maskCollection_) + : maskCollection(maskCollection_) {} + + __device__ __forceinline__ MaskCollection(const MaskCollection& masks_) + : maskCollection(masks_.maskCollection), curMask(masks_.curMask){} + + __device__ __forceinline__ void next() + { + curMask = *maskCollection++; + } + __device__ __forceinline__ void setMask(int z) + { + curMask = maskCollection[z]; + } + + __device__ __forceinline__ bool operator()(int y, int x) const + { + uchar val; + return curMask.data == 0 || (ForceGlob::Load(curMask.ptr(y), x, val), (val != 0)); + } + + const PtrStepb* maskCollection; + PtrStepb curMask; + }; + + struct WithOutMask + { + __host__ __device__ __forceinline__ WithOutMask(){} + __host__ __device__ __forceinline__ WithOutMask(const WithOutMask&){} + + __device__ __forceinline__ void next() const + { + } + __device__ __forceinline__ void setMask(int) const + { + } + + __device__ __forceinline__ bool operator()(int, int) const + { + return true; + } + + __device__ __forceinline__ bool operator()(int, int, int) const + { + return true; + } + + static __device__ __forceinline__ bool check(int, int) + { + return true; + } + + static __device__ __forceinline__ bool check(int, int, int) + { + return true; + } + }; + + /////////////////////////////////////////////////////////////////////////////// + // Solve linear system + + // solve 2x2 linear system Ax=b + template __device__ __forceinline__ bool solve2x2(const T A[2][2], const T b[2], T x[2]) + { + T det = A[0][0] * A[1][1] - A[1][0] * A[0][1]; + + if (det != 0) + { + double invdet = 1.0 / det; + + x[0] = saturate_cast(invdet * (b[0] * A[1][1] - b[1] * A[0][1])); + + x[1] = saturate_cast(invdet * (A[0][0] * b[1] - A[1][0] * b[0])); + + return true; + } + + return false; + } + + // solve 3x3 linear system Ax=b + template __device__ __forceinline__ bool solve3x3(const T A[3][3], const T b[3], T x[3]) + { + T det = A[0][0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) + - A[0][1] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) + + A[0][2] * (A[1][0] * A[2][1] - A[1][1] * A[2][0]); + + if (det != 0) + { + double invdet = 1.0 / det; + + x[0] = saturate_cast(invdet * + (b[0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) - + A[0][1] * (b[1] * A[2][2] - A[1][2] * b[2] ) + + A[0][2] * (b[1] * A[2][1] - A[1][1] * b[2] ))); + + x[1] = saturate_cast(invdet * + (A[0][0] * (b[1] * A[2][2] - A[1][2] * b[2] ) - + b[0] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) + + A[0][2] * (A[1][0] * b[2] - b[1] * A[2][0]))); + + x[2] = saturate_cast(invdet * + (A[0][0] * (A[1][1] * b[2] - b[1] * A[2][1]) - + A[0][1] * (A[1][0] * b[2] - b[1] * A[2][0]) + + b[0] * (A[1][0] * A[2][1] - A[1][1] * A[2][0]))); + + return true; + } + + return false; + } +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_UTILITY_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_distance.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_distance.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ef6e51087d33e8fd859c63be04515a7e99fd6afb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_distance.hpp @@ -0,0 +1,232 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_VEC_DISTANCE_HPP +#define OPENCV_CUDA_VEC_DISTANCE_HPP + +#include "reduce.hpp" +#include "functional.hpp" +#include "detail/vec_distance_detail.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template struct L1Dist + { + typedef int value_type; + typedef int result_type; + + __device__ __forceinline__ L1Dist() : mySum(0) {} + + __device__ __forceinline__ void reduceIter(int val1, int val2) + { + mySum = __sad(val1, val2, mySum); + } + + template __device__ __forceinline__ void reduceAll(int* smem, int tid) + { + reduce(smem, mySum, tid, plus()); + } + + __device__ __forceinline__ operator int() const + { + return mySum; + } + + int mySum; + }; + template <> struct L1Dist + { + typedef float value_type; + typedef float result_type; + + __device__ __forceinline__ L1Dist() : mySum(0.0f) {} + + __device__ __forceinline__ void reduceIter(float val1, float val2) + { + mySum += ::fabs(val1 - val2); + } + + template __device__ __forceinline__ void reduceAll(float* smem, int tid) + { + reduce(smem, mySum, tid, plus()); + } + + __device__ __forceinline__ operator float() const + { + return mySum; + } + + float mySum; + }; + + struct L2Dist + { + typedef float value_type; + typedef float result_type; + + __device__ __forceinline__ L2Dist() : mySum(0.0f) {} + + __device__ __forceinline__ void reduceIter(float val1, float val2) + { + float reg = val1 - val2; + mySum += reg * reg; + } + + template __device__ __forceinline__ void reduceAll(float* smem, int tid) + { + reduce(smem, mySum, tid, plus()); + } + + __device__ __forceinline__ operator float() const + { + return sqrtf(mySum); + } + + float mySum; + }; + + struct HammingDist + { + typedef int value_type; + typedef int result_type; + + __device__ __forceinline__ HammingDist() : mySum(0) {} + + __device__ __forceinline__ void reduceIter(int val1, int val2) + { + mySum += __popc(val1 ^ val2); + } + + template __device__ __forceinline__ void reduceAll(int* smem, int tid) + { + reduce(smem, mySum, tid, plus()); + } + + __device__ __forceinline__ operator int() const + { + return mySum; + } + + int mySum; + }; + + // calc distance between two vectors in global memory + template + __device__ void calcVecDiffGlobal(const T1* vec1, const T2* vec2, int len, Dist& dist, typename Dist::result_type* smem, int tid) + { + for (int i = tid; i < len; i += THREAD_DIM) + { + T1 val1; + ForceGlob::Load(vec1, i, val1); + + T2 val2; + ForceGlob::Load(vec2, i, val2); + + dist.reduceIter(val1, val2); + } + + dist.reduceAll(smem, tid); + } + + // calc distance between two vectors, first vector is cached in register or shared memory, second vector is in global memory + template + __device__ __forceinline__ void calcVecDiffCached(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, typename Dist::result_type* smem, int tid) + { + vec_distance_detail::VecDiffCachedCalculator::calc(vecCached, vecGlob, len, dist, tid); + + dist.reduceAll(smem, tid); + } + + // calc distance between two vectors in global memory + template struct VecDiffGlobal + { + explicit __device__ __forceinline__ VecDiffGlobal(const T1* vec1_, int = 0, void* = 0, int = 0, int = 0) + { + vec1 = vec1_; + } + + template + __device__ __forceinline__ void calc(const T2* vec2, int len, Dist& dist, typename Dist::result_type* smem, int tid) const + { + calcVecDiffGlobal(vec1, vec2, len, dist, smem, tid); + } + + const T1* vec1; + }; + + // calc distance between two vectors, first vector is cached in register memory, second vector is in global memory + template struct VecDiffCachedRegister + { + template __device__ __forceinline__ VecDiffCachedRegister(const T1* vec1, int len, U* smem, int glob_tid, int tid) + { + if (glob_tid < len) + smem[glob_tid] = vec1[glob_tid]; + __syncthreads(); + + U* vec1ValsPtr = vec1Vals; + + #pragma unroll + for (int i = tid; i < MAX_LEN; i += THREAD_DIM) + *vec1ValsPtr++ = smem[i]; + + __syncthreads(); + } + + template + __device__ __forceinline__ void calc(const T2* vec2, int len, Dist& dist, typename Dist::result_type* smem, int tid) const + { + calcVecDiffCached(vec1Vals, vec2, len, dist, smem, tid); + } + + U vec1Vals[MAX_LEN / THREAD_DIM]; + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_VEC_DISTANCE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_math.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_math.hpp new file mode 100644 index 0000000000000000000000000000000000000000..80b130368187ea6b15aab5c3ffb32b8cbcacbfd8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_math.hpp @@ -0,0 +1,923 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_VECMATH_HPP +#define OPENCV_CUDA_VECMATH_HPP + +#include "vec_traits.hpp" +#include "saturate_cast.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + +// saturate_cast + +namespace vec_math_detail +{ + template struct SatCastHelper; + template struct SatCastHelper<1, VecD> + { + template static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits::elem_type D; + return VecTraits::make(saturate_cast(v.x)); + } + }; + template struct SatCastHelper<2, VecD> + { + template static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits::elem_type D; + return VecTraits::make(saturate_cast(v.x), saturate_cast(v.y)); + } + }; + template struct SatCastHelper<3, VecD> + { + template static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits::elem_type D; + return VecTraits::make(saturate_cast(v.x), saturate_cast(v.y), saturate_cast(v.z)); + } + }; + template struct SatCastHelper<4, VecD> + { + template static __device__ __forceinline__ VecD cast(const VecS& v) + { + typedef typename VecTraits::elem_type D; + return VecTraits::make(saturate_cast(v.x), saturate_cast(v.y), saturate_cast(v.z), saturate_cast(v.w)); + } + }; + + template static __device__ __forceinline__ VecD saturate_cast_helper(const VecS& v) + { + return SatCastHelper::cn, VecD>::cast(v); + } +} + +template static __device__ __forceinline__ T saturate_cast(const uchar1& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const char1& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const ushort1& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const short1& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const uint1& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const int1& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const float1& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const double1& v) {return vec_math_detail::saturate_cast_helper(v);} + +template static __device__ __forceinline__ T saturate_cast(const uchar2& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const char2& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const ushort2& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const short2& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const uint2& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const int2& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const float2& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const double2& v) {return vec_math_detail::saturate_cast_helper(v);} + +template static __device__ __forceinline__ T saturate_cast(const uchar3& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const char3& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const ushort3& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const short3& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const uint3& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const int3& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const float3& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const double3& v) {return vec_math_detail::saturate_cast_helper(v);} + +template static __device__ __forceinline__ T saturate_cast(const uchar4& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const char4& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const ushort4& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const short4& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const uint4& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const int4& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const float4& v) {return vec_math_detail::saturate_cast_helper(v);} +template static __device__ __forceinline__ T saturate_cast(const double4& v) {return vec_math_detail::saturate_cast_helper(v);} + +// unary operators + +#define CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(op, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 operator op(const input_type ## 1 & a) \ + { \ + return VecTraits::make(op (a.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(const input_type ## 2 & a) \ + { \ + return VecTraits::make(op (a.x), op (a.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(const input_type ## 3 & a) \ + { \ + return VecTraits::make(op (a.x), op (a.y), op (a.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(const input_type ## 4 & a) \ + { \ + return VecTraits::make(op (a.x), op (a.y), op (a.z), op (a.w)); \ + } + +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, char, char) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, short, short) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, int, int) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(-, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(!, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, char, char) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, short, short) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, int, int) +CV_CUDEV_IMPLEMENT_VEC_UNARY_OP(~, uint, uint) + +#undef CV_CUDEV_IMPLEMENT_VEC_UNARY_OP + +// unary functions + +#define CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(func_name, func, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 func_name(const input_type ## 1 & a) \ + { \ + return VecTraits::make(func (a.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(const input_type ## 2 & a) \ + { \ + return VecTraits::make(func (a.x), func (a.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(const input_type ## 3 & a) \ + { \ + return VecTraits::make(func (a.x), func (a.y), func (a.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(const input_type ## 4 & a) \ + { \ + return VecTraits::make(func (a.x), func (a.y), func (a.z), func (a.w)); \ + } + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(abs, ::fabsf, float, float) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrtf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sqrt, ::sqrt, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::expf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp, ::exp, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp2, ::exp2, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(exp10, ::exp10, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::logf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log, ::log, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log2, ::log2, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10f, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(log10, ::log10, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sinf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sin, ::sin, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cosf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cos, ::cos, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tanf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tan, ::tan, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asinf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asin, ::asin, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acosf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acos, ::acos, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atanf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atan, ::atan, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(sinh, ::sinh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::coshf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(cosh, ::cosh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(tanh, ::tanh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(asinh, ::asinh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acoshf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(acosh, ::acosh, double, double) + +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, char, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, short, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, int, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanhf, float, float) +CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC(atanh, ::atanh, double, double) + +#undef CV_CUDEV_IMPLEMENT_VEC_UNARY_FUNC + +// binary operators (vec & vec) + +#define CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(op, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 operator op(const input_type ## 1 & a, const input_type ## 1 & b) \ + { \ + return VecTraits::make(a.x op b.x); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(const input_type ## 2 & a, const input_type ## 2 & b) \ + { \ + return VecTraits::make(a.x op b.x, a.y op b.y); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(const input_type ## 3 & a, const input_type ## 3 & b) \ + { \ + return VecTraits::make(a.x op b.x, a.y op b.y, a.z op b.z); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(const input_type ## 4 & a, const input_type ## 4 & b) \ + { \ + return VecTraits::make(a.x op b.x, a.y op b.y, a.z op b.z, a.w op b.w); \ + } + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(+, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(-, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(*, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, uchar, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, char, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, ushort, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, short, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(/, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(==, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(!=, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(>=, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(<=, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&&, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, char, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, ushort, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, short, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, int, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, uint, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, float, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(||, double, uchar) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(&, uint, uint) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(|, uint, uint) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_OP(^, uint, uint) + +#undef CV_CUDEV_IMPLEMENT_VEC_BINARY_OP + +// binary operators (vec & scalar) + +#define CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(op, input_type, scalar_type, output_type) \ + __device__ __forceinline__ output_type ## 1 operator op(const input_type ## 1 & a, scalar_type s) \ + { \ + return VecTraits::make(a.x op s); \ + } \ + __device__ __forceinline__ output_type ## 1 operator op(scalar_type s, const input_type ## 1 & b) \ + { \ + return VecTraits::make(s op b.x); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(const input_type ## 2 & a, scalar_type s) \ + { \ + return VecTraits::make(a.x op s, a.y op s); \ + } \ + __device__ __forceinline__ output_type ## 2 operator op(scalar_type s, const input_type ## 2 & b) \ + { \ + return VecTraits::make(s op b.x, s op b.y); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(const input_type ## 3 & a, scalar_type s) \ + { \ + return VecTraits::make(a.x op s, a.y op s, a.z op s); \ + } \ + __device__ __forceinline__ output_type ## 3 operator op(scalar_type s, const input_type ## 3 & b) \ + { \ + return VecTraits::make(s op b.x, s op b.y, s op b.z); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(const input_type ## 4 & a, scalar_type s) \ + { \ + return VecTraits::make(a.x op s, a.y op s, a.z op s, a.w op s); \ + } \ + __device__ __forceinline__ output_type ## 4 operator op(scalar_type s, const input_type ## 4 & b) \ + { \ + return VecTraits::make(s op b.x, s op b.y, s op b.z, s op b.w); \ + } + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(+, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(-, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(*, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uchar, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, char, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, ushort, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, short, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(/, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(==, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(!=, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(>=, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(<=, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&&, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, char, char, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, ushort, ushort, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, short, short, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, int, int, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, uint, uint, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, float, float, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(||, double, double, uchar) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(&, uint, uint, uint) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(|, uint, uint, uint) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP(^, uint, uint, uint) + +#undef CV_CUDEV_IMPLEMENT_SCALAR_BINARY_OP + +// binary function (vec & vec) + +#define CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(func_name, func, input_type, output_type) \ + __device__ __forceinline__ output_type ## 1 func_name(const input_type ## 1 & a, const input_type ## 1 & b) \ + { \ + return VecTraits::make(func (a.x, b.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(const input_type ## 2 & a, const input_type ## 2 & b) \ + { \ + return VecTraits::make(func (a.x, b.x), func (a.y, b.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(const input_type ## 3 & a, const input_type ## 3 & b) \ + { \ + return VecTraits::make(func (a.x, b.x), func (a.y, b.y), func (a.z, b.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(const input_type ## 4 & a, const input_type ## 4 & b) \ + { \ + return VecTraits::make(func (a.x, b.x), func (a.y, b.y), func (a.z, b.z), func (a.w, b.w)); \ + } + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::max, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::fmaxf, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(max, ::fmax, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, uchar, uchar) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, char, char) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, ushort, ushort) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, short, short) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, uint, uint) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::min, int, int) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::fminf, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(min, ::fmin, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, char, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, short, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, uint, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, int, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypotf, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(hypot, ::hypot, double, double) + +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, uchar, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, char, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, ushort, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, short, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, uint, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, int, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2f, float, float) +CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC(atan2, ::atan2, double, double) + +#undef CV_CUDEV_IMPLEMENT_VEC_BINARY_FUNC + +// binary function (vec & scalar) + +#define CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(func_name, func, input_type, scalar_type, output_type) \ + __device__ __forceinline__ output_type ## 1 func_name(const input_type ## 1 & a, scalar_type s) \ + { \ + return VecTraits::make(func ((output_type) a.x, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 1 func_name(scalar_type s, const input_type ## 1 & b) \ + { \ + return VecTraits::make(func ((output_type) s, (output_type) b.x)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(const input_type ## 2 & a, scalar_type s) \ + { \ + return VecTraits::make(func ((output_type) a.x, (output_type) s), func ((output_type) a.y, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 2 func_name(scalar_type s, const input_type ## 2 & b) \ + { \ + return VecTraits::make(func ((output_type) s, (output_type) b.x), func ((output_type) s, (output_type) b.y)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(const input_type ## 3 & a, scalar_type s) \ + { \ + return VecTraits::make(func ((output_type) a.x, (output_type) s), func ((output_type) a.y, (output_type) s), func ((output_type) a.z, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 3 func_name(scalar_type s, const input_type ## 3 & b) \ + { \ + return VecTraits::make(func ((output_type) s, (output_type) b.x), func ((output_type) s, (output_type) b.y), func ((output_type) s, (output_type) b.z)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(const input_type ## 4 & a, scalar_type s) \ + { \ + return VecTraits::make(func ((output_type) a.x, (output_type) s), func ((output_type) a.y, (output_type) s), func ((output_type) a.z, (output_type) s), func ((output_type) a.w, (output_type) s)); \ + } \ + __device__ __forceinline__ output_type ## 4 func_name(scalar_type s, const input_type ## 4 & b) \ + { \ + return VecTraits::make(func ((output_type) s, (output_type) b.x), func ((output_type) s, (output_type) b.y), func ((output_type) s, (output_type) b.z), func ((output_type) s, (output_type) b.w)); \ + } + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::max, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmaxf, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(max, ::fmax, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, uchar, uchar, uchar) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, char, char, char) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, ushort, ushort, ushort) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, short, short, short) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, uint, uint, uint) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::min, int, int, int) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fminf, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(min, ::fmin, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypotf, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(hypot, ::hypot, double, double, double) + +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, uchar, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, uchar, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, char, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, char, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, ushort, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, ushort, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, short, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, short, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, uint, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, uint, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, int, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, int, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2f, float, float, float) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, float, double, double) +CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC(atan2, ::atan2, double, double, double) + +#undef CV_CUDEV_IMPLEMENT_SCALAR_BINARY_FUNC + +}}} // namespace cv { namespace cuda { namespace device + +//! @endcond + +#endif // OPENCV_CUDA_VECMATH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_traits.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_traits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b5ff281a0b8a3b7c5a6a481fa7880b7f24e4786f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/vec_traits.hpp @@ -0,0 +1,288 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_VEC_TRAITS_HPP +#define OPENCV_CUDA_VEC_TRAITS_HPP + +#include "common.hpp" + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template struct TypeVec; + + struct __align__(8) uchar8 + { + uchar a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ uchar8 make_uchar8(uchar a0, uchar a1, uchar a2, uchar a3, uchar a4, uchar a5, uchar a6, uchar a7) + { + uchar8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(8) char8 + { + schar a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ char8 make_char8(schar a0, schar a1, schar a2, schar a3, schar a4, schar a5, schar a6, schar a7) + { + char8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(16) ushort8 + { + ushort a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ ushort8 make_ushort8(ushort a0, ushort a1, ushort a2, ushort a3, ushort a4, ushort a5, ushort a6, ushort a7) + { + ushort8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(16) short8 + { + short a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ short8 make_short8(short a0, short a1, short a2, short a3, short a4, short a5, short a6, short a7) + { + short8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(32) uint8 + { + uint a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ uint8 make_uint8(uint a0, uint a1, uint a2, uint a3, uint a4, uint a5, uint a6, uint a7) + { + uint8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(32) int8 + { + int a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ int8 make_int8(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7) + { + int8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct __align__(32) float8 + { + float a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ float8 make_float8(float a0, float a1, float a2, float a3, float a4, float a5, float a6, float a7) + { + float8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + struct double8 + { + double a0, a1, a2, a3, a4, a5, a6, a7; + }; + static __host__ __device__ __forceinline__ double8 make_double8(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7) + { + double8 val = {a0, a1, a2, a3, a4, a5, a6, a7}; + return val; + } + +#define OPENCV_CUDA_IMPLEMENT_TYPE_VEC(type) \ + template<> struct TypeVec { typedef type vec_type; }; \ + template<> struct TypeVec { typedef type ## 1 vec_type; }; \ + template<> struct TypeVec { typedef type ## 2 vec_type; }; \ + template<> struct TypeVec { typedef type ## 2 vec_type; }; \ + template<> struct TypeVec { typedef type ## 3 vec_type; }; \ + template<> struct TypeVec { typedef type ## 3 vec_type; }; \ + template<> struct TypeVec { typedef type ## 4 vec_type; }; \ + template<> struct TypeVec { typedef type ## 4 vec_type; }; \ + template<> struct TypeVec { typedef type ## 8 vec_type; }; \ + template<> struct TypeVec { typedef type ## 8 vec_type; }; + + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(uchar) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(char) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(ushort) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(short) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(int) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(uint) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(float) + OPENCV_CUDA_IMPLEMENT_TYPE_VEC(double) + + #undef OPENCV_CUDA_IMPLEMENT_TYPE_VEC + + template<> struct TypeVec { typedef schar vec_type; }; + template<> struct TypeVec { typedef char2 vec_type; }; + template<> struct TypeVec { typedef char3 vec_type; }; + template<> struct TypeVec { typedef char4 vec_type; }; + template<> struct TypeVec { typedef char8 vec_type; }; + + template<> struct TypeVec { typedef uchar vec_type; }; + template<> struct TypeVec { typedef uchar2 vec_type; }; + template<> struct TypeVec { typedef uchar3 vec_type; }; + template<> struct TypeVec { typedef uchar4 vec_type; }; + template<> struct TypeVec { typedef uchar8 vec_type; }; + + template struct VecTraits; + +#define OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(type) \ + template<> struct VecTraits \ + { \ + typedef type elem_type; \ + enum {cn=1}; \ + static __device__ __host__ __forceinline__ type all(type v) {return v;} \ + static __device__ __host__ __forceinline__ type make(type x) {return x;} \ + static __device__ __host__ __forceinline__ type make(const type* v) {return *v;} \ + }; \ + template<> struct VecTraits \ + { \ + typedef type elem_type; \ + enum {cn=1}; \ + static __device__ __host__ __forceinline__ type ## 1 all(type v) {return make_ ## type ## 1(v);} \ + static __device__ __host__ __forceinline__ type ## 1 make(type x) {return make_ ## type ## 1(x);} \ + static __device__ __host__ __forceinline__ type ## 1 make(const type* v) {return make_ ## type ## 1(*v);} \ + }; \ + template<> struct VecTraits \ + { \ + typedef type elem_type; \ + enum {cn=2}; \ + static __device__ __host__ __forceinline__ type ## 2 all(type v) {return make_ ## type ## 2(v, v);} \ + static __device__ __host__ __forceinline__ type ## 2 make(type x, type y) {return make_ ## type ## 2(x, y);} \ + static __device__ __host__ __forceinline__ type ## 2 make(const type* v) {return make_ ## type ## 2(v[0], v[1]);} \ + }; \ + template<> struct VecTraits \ + { \ + typedef type elem_type; \ + enum {cn=3}; \ + static __device__ __host__ __forceinline__ type ## 3 all(type v) {return make_ ## type ## 3(v, v, v);} \ + static __device__ __host__ __forceinline__ type ## 3 make(type x, type y, type z) {return make_ ## type ## 3(x, y, z);} \ + static __device__ __host__ __forceinline__ type ## 3 make(const type* v) {return make_ ## type ## 3(v[0], v[1], v[2]);} \ + }; \ + template<> struct VecTraits \ + { \ + typedef type elem_type; \ + enum {cn=4}; \ + static __device__ __host__ __forceinline__ type ## 4 all(type v) {return make_ ## type ## 4(v, v, v, v);} \ + static __device__ __host__ __forceinline__ type ## 4 make(type x, type y, type z, type w) {return make_ ## type ## 4(x, y, z, w);} \ + static __device__ __host__ __forceinline__ type ## 4 make(const type* v) {return make_ ## type ## 4(v[0], v[1], v[2], v[3]);} \ + }; \ + template<> struct VecTraits \ + { \ + typedef type elem_type; \ + enum {cn=8}; \ + static __device__ __host__ __forceinline__ type ## 8 all(type v) {return make_ ## type ## 8(v, v, v, v, v, v, v, v);} \ + static __device__ __host__ __forceinline__ type ## 8 make(type a0, type a1, type a2, type a3, type a4, type a5, type a6, type a7) {return make_ ## type ## 8(a0, a1, a2, a3, a4, a5, a6, a7);} \ + static __device__ __host__ __forceinline__ type ## 8 make(const type* v) {return make_ ## type ## 8(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);} \ + }; + + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(uchar) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(ushort) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(short) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(int) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(uint) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(float) + OPENCV_CUDA_IMPLEMENT_VEC_TRAITS(double) + + #undef OPENCV_CUDA_IMPLEMENT_VEC_TRAITS + + template<> struct VecTraits + { + typedef char elem_type; + enum {cn=1}; + static __device__ __host__ __forceinline__ char all(char v) {return v;} + static __device__ __host__ __forceinline__ char make(char x) {return x;} + static __device__ __host__ __forceinline__ char make(const char* x) {return *x;} + }; + template<> struct VecTraits + { + typedef schar elem_type; + enum {cn=1}; + static __device__ __host__ __forceinline__ schar all(schar v) {return v;} + static __device__ __host__ __forceinline__ schar make(schar x) {return x;} + static __device__ __host__ __forceinline__ schar make(const schar* x) {return *x;} + }; + template<> struct VecTraits + { + typedef schar elem_type; + enum {cn=1}; + static __device__ __host__ __forceinline__ char1 all(schar v) {return make_char1(v);} + static __device__ __host__ __forceinline__ char1 make(schar x) {return make_char1(x);} + static __device__ __host__ __forceinline__ char1 make(const schar* v) {return make_char1(v[0]);} + }; + template<> struct VecTraits + { + typedef schar elem_type; + enum {cn=2}; + static __device__ __host__ __forceinline__ char2 all(schar v) {return make_char2(v, v);} + static __device__ __host__ __forceinline__ char2 make(schar x, schar y) {return make_char2(x, y);} + static __device__ __host__ __forceinline__ char2 make(const schar* v) {return make_char2(v[0], v[1]);} + }; + template<> struct VecTraits + { + typedef schar elem_type; + enum {cn=3}; + static __device__ __host__ __forceinline__ char3 all(schar v) {return make_char3(v, v, v);} + static __device__ __host__ __forceinline__ char3 make(schar x, schar y, schar z) {return make_char3(x, y, z);} + static __device__ __host__ __forceinline__ char3 make(const schar* v) {return make_char3(v[0], v[1], v[2]);} + }; + template<> struct VecTraits + { + typedef schar elem_type; + enum {cn=4}; + static __device__ __host__ __forceinline__ char4 all(schar v) {return make_char4(v, v, v, v);} + static __device__ __host__ __forceinline__ char4 make(schar x, schar y, schar z, schar w) {return make_char4(x, y, z, w);} + static __device__ __host__ __forceinline__ char4 make(const schar* v) {return make_char4(v[0], v[1], v[2], v[3]);} + }; + template<> struct VecTraits + { + typedef schar elem_type; + enum {cn=8}; + static __device__ __host__ __forceinline__ char8 all(schar v) {return make_char8(v, v, v, v, v, v, v, v);} + static __device__ __host__ __forceinline__ char8 make(schar a0, schar a1, schar a2, schar a3, schar a4, schar a5, schar a6, schar a7) {return make_char8(a0, a1, a2, a3, a4, a5, a6, a7);} + static __device__ __host__ __forceinline__ char8 make(const schar* v) {return make_char8(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]);} + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif // OPENCV_CUDA_VEC_TRAITS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8af7e6a212afd45cc9ddd00c26010875f55d80bf --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp.hpp @@ -0,0 +1,139 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_DEVICE_WARP_HPP +#define OPENCV_CUDA_DEVICE_WARP_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + struct Warp + { + enum + { + LOG_WARP_SIZE = 5, + WARP_SIZE = 1 << LOG_WARP_SIZE, + STRIDE = WARP_SIZE + }; + + /** \brief Returns the warp lane ID of the calling thread. */ + static __device__ __forceinline__ unsigned int laneId() + { + unsigned int ret; + asm("mov.u32 %0, %%laneid;" : "=r"(ret) ); + return ret; + } + + template + static __device__ __forceinline__ void fill(It beg, It end, const T& value) + { + for(It t = beg + laneId(); t < end; t += STRIDE) + *t = value; + } + + template + static __device__ __forceinline__ OutIt copy(InIt beg, InIt end, OutIt out) + { + for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE) + *out = *t; + return out; + } + + template + static __device__ __forceinline__ OutIt transform(InIt beg, InIt end, OutIt out, UnOp op) + { + for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE) + *out = op(*t); + return out; + } + + template + static __device__ __forceinline__ OutIt transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op) + { + unsigned int lane = laneId(); + + InIt1 t1 = beg1 + lane; + InIt2 t2 = beg2 + lane; + for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, out += STRIDE) + *out = op(*t1, *t2); + return out; + } + + template + static __device__ __forceinline__ T reduce(volatile T *ptr, BinOp op) + { + const unsigned int lane = laneId(); + + if (lane < 16) + { + T partial = ptr[lane]; + + ptr[lane] = partial = op(partial, ptr[lane + 16]); + ptr[lane] = partial = op(partial, ptr[lane + 8]); + ptr[lane] = partial = op(partial, ptr[lane + 4]); + ptr[lane] = partial = op(partial, ptr[lane + 2]); + ptr[lane] = partial = op(partial, ptr[lane + 1]); + } + + return *ptr; + } + + template + static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value) + { + unsigned int lane = laneId(); + value += lane; + + for(OutIt t = beg + lane; t < end; t += STRIDE, value += STRIDE) + *t = value; + } + }; +}}} // namespace cv { namespace cuda { namespace cudev + +//! @endcond + +#endif /* OPENCV_CUDA_DEVICE_WARP_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp_reduce.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp_reduce.hpp new file mode 100644 index 0000000000000000000000000000000000000000..530303d2495fe878340b80bf1a4b330ed7aadc5f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp_reduce.hpp @@ -0,0 +1,76 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_WARP_REDUCE_HPP__ +#define OPENCV_CUDA_WARP_REDUCE_HPP__ + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ + template + __device__ __forceinline__ T warp_reduce(volatile T *ptr , const unsigned int tid = threadIdx.x) + { + const unsigned int lane = tid & 31; // index of thread in warp (0..31) + + if (lane < 16) + { + T partial = ptr[tid]; + + ptr[tid] = partial = partial + ptr[tid + 16]; + ptr[tid] = partial = partial + ptr[tid + 8]; + ptr[tid] = partial = partial + ptr[tid + 4]; + ptr[tid] = partial = partial + ptr[tid + 2]; + ptr[tid] = partial = partial + ptr[tid + 1]; + } + + return ptr[tid - lane]; + } +}}} // namespace cv { namespace cuda { namespace cudev { + +//! @endcond + +#endif /* OPENCV_CUDA_WARP_REDUCE_HPP__ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp_shuffle.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp_shuffle.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0da54aee99bf82f0946b64ed39d3bb9bceaf5d7b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda/warp_shuffle.hpp @@ -0,0 +1,162 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CUDA_WARP_SHUFFLE_HPP +#define OPENCV_CUDA_WARP_SHUFFLE_HPP + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +namespace cv { namespace cuda { namespace device +{ +#if __CUDACC_VER_MAJOR__ >= 9 +# define __shfl(x, y, z) __shfl_sync(0xFFFFFFFFU, x, y, z) +# define __shfl_up(x, y, z) __shfl_up_sync(0xFFFFFFFFU, x, y, z) +# define __shfl_down(x, y, z) __shfl_down_sync(0xFFFFFFFFU, x, y, z) +#endif + template + __device__ __forceinline__ T shfl(T val, int srcLane, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return __shfl(val, srcLane, width); + #else + return T(); + #endif + } + __device__ __forceinline__ unsigned int shfl(unsigned int val, int srcLane, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return (unsigned int) __shfl((int) val, srcLane, width); + #else + return 0; + #endif + } + __device__ __forceinline__ double shfl(double val, int srcLane, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + int lo = __double2loint(val); + int hi = __double2hiint(val); + + lo = __shfl(lo, srcLane, width); + hi = __shfl(hi, srcLane, width); + + return __hiloint2double(hi, lo); + #else + return 0.0; + #endif + } + + template + __device__ __forceinline__ T shfl_down(T val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return __shfl_down(val, delta, width); + #else + return T(); + #endif + } + __device__ __forceinline__ unsigned int shfl_down(unsigned int val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return (unsigned int) __shfl_down((int) val, delta, width); + #else + return 0; + #endif + } + __device__ __forceinline__ double shfl_down(double val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + int lo = __double2loint(val); + int hi = __double2hiint(val); + + lo = __shfl_down(lo, delta, width); + hi = __shfl_down(hi, delta, width); + + return __hiloint2double(hi, lo); + #else + return 0.0; + #endif + } + + template + __device__ __forceinline__ T shfl_up(T val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return __shfl_up(val, delta, width); + #else + return T(); + #endif + } + __device__ __forceinline__ unsigned int shfl_up(unsigned int val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + return (unsigned int) __shfl_up((int) val, delta, width); + #else + return 0; + #endif + } + __device__ __forceinline__ double shfl_up(double val, unsigned int delta, int width = warpSize) + { + #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300 + int lo = __double2loint(val); + int hi = __double2hiint(val); + + lo = __shfl_up(lo, delta, width); + hi = __shfl_up(hi, delta, width); + + return __hiloint2double(hi, lo); + #else + return 0.0; + #endif + } +}}} + +# undef __shfl +# undef __shfl_up +# undef __shfl_down + +//! @endcond + +#endif // OPENCV_CUDA_WARP_SHUFFLE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda_stream_accessor.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda_stream_accessor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..deaf356fff4311ffddcc388ee28106d0b5459f3f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda_stream_accessor.hpp @@ -0,0 +1,86 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP +#define OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP + +#ifndef __cplusplus +# error cuda_stream_accessor.hpp header must be compiled as C++ +#endif + +/** @file cuda_stream_accessor.hpp + * This is only header file that depends on CUDA Runtime API. All other headers are independent. + */ + +#include +#include "opencv2/core/cuda.hpp" + +namespace cv +{ + namespace cuda + { + +//! @addtogroup cudacore_struct +//! @{ + + /** @brief Class that enables getting cudaStream_t from cuda::Stream + */ + struct StreamAccessor + { + CV_EXPORTS static cudaStream_t getStream(const Stream& stream); + CV_EXPORTS static Stream wrapStream(cudaStream_t stream); + }; + + /** @brief Class that enables getting cudaEvent_t from cuda::Event + */ + struct EventAccessor + { + CV_EXPORTS static cudaEvent_t getEvent(const Event& event); + CV_EXPORTS static Event wrapEvent(cudaEvent_t event); + }; + +//! @} + + } +} + +#endif /* OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda_types.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda_types.hpp new file mode 100644 index 0000000000000000000000000000000000000000..45dc2cad1c873c4de66bfd57aac8787b688f7758 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cuda_types.hpp @@ -0,0 +1,144 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_CUDA_TYPES_HPP +#define OPENCV_CORE_CUDA_TYPES_HPP + +#ifndef __cplusplus +# error cuda_types.hpp header must be compiled as C++ +#endif + +#if defined(__OPENCV_BUILD) && defined(__clang__) +#pragma clang diagnostic ignored "-Winconsistent-missing-override" +#endif +#if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5 +#pragma GCC diagnostic ignored "-Wsuggest-override" +#endif + +/** @file + * @deprecated Use @ref cudev instead. + */ + +//! @cond IGNORED + +#ifdef __CUDACC__ + #define __CV_CUDA_HOST_DEVICE__ __host__ __device__ __forceinline__ +#else + #define __CV_CUDA_HOST_DEVICE__ +#endif + +namespace cv +{ + namespace cuda + { + + // Simple lightweight structures that encapsulates information about an image on device. + // It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile + + template struct DevPtr + { + typedef T elem_type; + typedef int index_type; + + enum { elem_size = sizeof(elem_type) }; + + T* data; + + __CV_CUDA_HOST_DEVICE__ DevPtr() : data(0) {} + __CV_CUDA_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {} + + __CV_CUDA_HOST_DEVICE__ size_t elemSize() const { return elem_size; } + __CV_CUDA_HOST_DEVICE__ operator T*() { return data; } + __CV_CUDA_HOST_DEVICE__ operator const T*() const { return data; } + }; + + template struct PtrSz : public DevPtr + { + __CV_CUDA_HOST_DEVICE__ PtrSz() : size(0) {} + __CV_CUDA_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr(data_), size(size_) {} + + size_t size; + }; + + template struct PtrStep : public DevPtr + { + __CV_CUDA_HOST_DEVICE__ PtrStep() : step(0) {} + __CV_CUDA_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr(data_), step(step_) {} + + size_t step; + + __CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr::data + y * step); } + __CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr::data + y * step); } + + __CV_CUDA_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } + __CV_CUDA_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } + }; + + template struct PtrStepSz : public PtrStep + { + __CV_CUDA_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {} + __CV_CUDA_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_) + : PtrStep(data_, step_), cols(cols_), rows(rows_) {} + + template + explicit PtrStepSz(const PtrStepSz& d) : PtrStep((T*)d.data, d.step), cols(d.cols), rows(d.rows){} + + int cols; + int rows; + }; + + typedef PtrStepSz PtrStepSzb; + typedef PtrStepSz PtrStepSzus; + typedef PtrStepSz PtrStepSzf; + typedef PtrStepSz PtrStepSzi; + + typedef PtrStep PtrStepb; + typedef PtrStep PtrStepus; + typedef PtrStep PtrStepf; + typedef PtrStep PtrStepi; + + } +} + +//! @endcond + +#endif /* OPENCV_CORE_CUDA_TYPES_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cv_cpu_dispatch.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cv_cpu_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..42651aed5efc0ea69fc236d519d78d3a82dd31e3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cv_cpu_dispatch.h @@ -0,0 +1,345 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#if defined __OPENCV_BUILD \ + +#include "cv_cpu_config.h" +#include "cv_cpu_helper.h" + +#ifdef CV_CPU_DISPATCH_MODE +#define CV_CPU_OPTIMIZATION_NAMESPACE __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) +#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace __CV_CAT(opt_, CV_CPU_DISPATCH_MODE) { +#define CV_CPU_OPTIMIZATION_NAMESPACE_END } +#else +#define CV_CPU_OPTIMIZATION_NAMESPACE cpu_baseline +#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace cpu_baseline { +#define CV_CPU_OPTIMIZATION_NAMESPACE_END } +#define CV_CPU_BASELINE_MODE 1 +#endif + + +#define __CV_CPU_DISPATCH_CHAIN_END(fn, args, mode, ...) /* done */ +#define __CV_CPU_DISPATCH(fn, args, mode, ...) __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) +#define __CV_CPU_DISPATCH_EXPAND(fn, args, ...) __CV_EXPAND(__CV_CPU_DISPATCH(fn, args, __VA_ARGS__)) +#define CV_CPU_DISPATCH(fn, args, ...) __CV_CPU_DISPATCH_EXPAND(fn, args, __VA_ARGS__, END) // expand macros + + +#if defined CV_ENABLE_INTRINSICS \ + && !defined CV_DISABLE_OPTIMIZATION \ + && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ \ + +#ifdef CV_CPU_COMPILE_SSE2 +# include +# define CV_MMX 1 +# define CV_SSE 1 +# define CV_SSE2 1 +#endif +#ifdef CV_CPU_COMPILE_SSE3 +# include +# define CV_SSE3 1 +#endif +#ifdef CV_CPU_COMPILE_SSSE3 +# include +# define CV_SSSE3 1 +#endif +#ifdef CV_CPU_COMPILE_SSE4_1 +# include +# define CV_SSE4_1 1 +#endif +#ifdef CV_CPU_COMPILE_SSE4_2 +# include +# define CV_SSE4_2 1 +#endif +#ifdef CV_CPU_COMPILE_POPCNT +# ifdef _MSC_VER +# include +# if defined(_M_X64) +# define CV_POPCNT_U64 _mm_popcnt_u64 +# endif +# define CV_POPCNT_U32 _mm_popcnt_u32 +# else +# include +# if defined(__x86_64__) +# define CV_POPCNT_U64 __builtin_popcountll +# endif +# define CV_POPCNT_U32 __builtin_popcount +# endif +# define CV_POPCNT 1 +#endif +#ifdef CV_CPU_COMPILE_AVX +# include +# define CV_AVX 1 +#endif +#ifdef CV_CPU_COMPILE_FP16 +# if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64) +# include +# else +# include +# endif +# define CV_FP16 1 +#endif +#ifdef CV_CPU_COMPILE_AVX2 +# include +# define CV_AVX2 1 +#endif +#ifdef CV_CPU_COMPILE_AVX_512F +# include +# define CV_AVX_512F 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_COMMON +# define CV_AVX512_COMMON 1 +# define CV_AVX_512CD 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_KNL +# define CV_AVX512_KNL 1 +# define CV_AVX_512ER 1 +# define CV_AVX_512PF 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_KNM +# define CV_AVX512_KNM 1 +# define CV_AVX_5124FMAPS 1 +# define CV_AVX_5124VNNIW 1 +# define CV_AVX_512VPOPCNTDQ 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_SKX +# define CV_AVX512_SKX 1 +# define CV_AVX_512VL 1 +# define CV_AVX_512BW 1 +# define CV_AVX_512DQ 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_CNL +# define CV_AVX512_CNL 1 +# define CV_AVX_512IFMA 1 +# define CV_AVX_512VBMI 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_CLX +# define CV_AVX512_CLX 1 +# define CV_AVX_512VNNI 1 +#endif +#ifdef CV_CPU_COMPILE_AVX512_ICL +# define CV_AVX512_ICL 1 +# undef CV_AVX_512IFMA +# define CV_AVX_512IFMA 1 +# undef CV_AVX_512VBMI +# define CV_AVX_512VBMI 1 +# undef CV_AVX_512VNNI +# define CV_AVX_512VNNI 1 +# define CV_AVX_512VBMI2 1 +# define CV_AVX_512BITALG 1 +# define CV_AVX_512VPOPCNTDQ 1 +#endif +#ifdef CV_CPU_COMPILE_FMA3 +# define CV_FMA3 1 +#endif + +#if defined _WIN32 && (defined(_M_ARM) || defined(_M_ARM64)) && (defined(CV_CPU_COMPILE_NEON) || !defined(_MSC_VER)) +# include +# include +# define CV_NEON 1 +#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) +# include +# define CV_NEON 1 +#endif + +#if defined(__ARM_NEON__) || defined(__aarch64__) +# include +#endif + +#ifdef CV_CPU_COMPILE_VSX +# include +# undef vector +# undef pixel +# undef bool +# define CV_VSX 1 +#endif + +#ifdef CV_CPU_COMPILE_VSX3 +# define CV_VSX3 1 +#endif + +#ifdef CV_CPU_COMPILE_MSA +# include "hal/msa_macros.h" +# define CV_MSA 1 +#endif + +#ifdef __EMSCRIPTEN__ +# define CV_WASM_SIMD 1 +# include +#endif + +#endif // CV_ENABLE_INTRINSICS && !CV_DISABLE_OPTIMIZATION && !__CUDACC__ + +#if defined CV_CPU_COMPILE_AVX && !defined CV_CPU_BASELINE_COMPILE_AVX +struct VZeroUpperGuard { +#ifdef __GNUC__ + __attribute__((always_inline)) +#endif + inline VZeroUpperGuard() { _mm256_zeroupper(); } +#ifdef __GNUC__ + __attribute__((always_inline)) +#endif + inline ~VZeroUpperGuard() { _mm256_zeroupper(); } +}; +#define __CV_AVX_GUARD VZeroUpperGuard __vzeroupper_guard; CV_UNUSED(__vzeroupper_guard); +#endif + +#ifdef __CV_AVX_GUARD +#define CV_AVX_GUARD __CV_AVX_GUARD +#else +#define CV_AVX_GUARD +#endif + +#endif // __OPENCV_BUILD + + + +#if !defined __OPENCV_BUILD /* Compatibility code */ \ + && !defined __CUDACC__ /* do not include SSE/AVX/NEON headers for NVCC compiler */ +#if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) +# include +# define CV_MMX 1 +# define CV_SSE 1 +# define CV_SSE2 1 +#elif defined _WIN32 && (defined(_M_ARM) || defined(_M_ARM64)) && (defined(CV_CPU_COMPILE_NEON) || !defined(_MSC_VER)) +# include +# include +# define CV_NEON 1 +#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__)) +# include +# define CV_NEON 1 +#elif defined(__VSX__) && defined(__PPC64__) && defined(__LITTLE_ENDIAN__) +# include +# undef vector +# undef pixel +# undef bool +# define CV_VSX 1 +#endif + +#endif // !__OPENCV_BUILD && !__CUDACC (Compatibility code) + + + +#ifndef CV_MMX +# define CV_MMX 0 +#endif +#ifndef CV_SSE +# define CV_SSE 0 +#endif +#ifndef CV_SSE2 +# define CV_SSE2 0 +#endif +#ifndef CV_SSE3 +# define CV_SSE3 0 +#endif +#ifndef CV_SSSE3 +# define CV_SSSE3 0 +#endif +#ifndef CV_SSE4_1 +# define CV_SSE4_1 0 +#endif +#ifndef CV_SSE4_2 +# define CV_SSE4_2 0 +#endif +#ifndef CV_POPCNT +# define CV_POPCNT 0 +#endif +#ifndef CV_AVX +# define CV_AVX 0 +#endif +#ifndef CV_FP16 +# define CV_FP16 0 +#endif +#ifndef CV_AVX2 +# define CV_AVX2 0 +#endif +#ifndef CV_FMA3 +# define CV_FMA3 0 +#endif +#ifndef CV_AVX_512F +# define CV_AVX_512F 0 +#endif +#ifndef CV_AVX_512BW +# define CV_AVX_512BW 0 +#endif +#ifndef CV_AVX_512CD +# define CV_AVX_512CD 0 +#endif +#ifndef CV_AVX_512DQ +# define CV_AVX_512DQ 0 +#endif +#ifndef CV_AVX_512ER +# define CV_AVX_512ER 0 +#endif +#ifndef CV_AVX_512IFMA +# define CV_AVX_512IFMA 0 +#endif +#define CV_AVX_512IFMA512 CV_AVX_512IFMA // deprecated +#ifndef CV_AVX_512PF +# define CV_AVX_512PF 0 +#endif +#ifndef CV_AVX_512VBMI +# define CV_AVX_512VBMI 0 +#endif +#ifndef CV_AVX_512VL +# define CV_AVX_512VL 0 +#endif +#ifndef CV_AVX_5124FMAPS +# define CV_AVX_5124FMAPS 0 +#endif +#ifndef CV_AVX_5124VNNIW +# define CV_AVX_5124VNNIW 0 +#endif +#ifndef CV_AVX_512VPOPCNTDQ +# define CV_AVX_512VPOPCNTDQ 0 +#endif +#ifndef CV_AVX_512VNNI +# define CV_AVX_512VNNI 0 +#endif +#ifndef CV_AVX_512VBMI2 +# define CV_AVX_512VBMI2 0 +#endif +#ifndef CV_AVX_512BITALG +# define CV_AVX_512BITALG 0 +#endif +#ifndef CV_AVX512_COMMON +# define CV_AVX512_COMMON 0 +#endif +#ifndef CV_AVX512_KNL +# define CV_AVX512_KNL 0 +#endif +#ifndef CV_AVX512_KNM +# define CV_AVX512_KNM 0 +#endif +#ifndef CV_AVX512_SKX +# define CV_AVX512_SKX 0 +#endif +#ifndef CV_AVX512_CNL +# define CV_AVX512_CNL 0 +#endif +#ifndef CV_AVX512_CLX +# define CV_AVX512_CLX 0 +#endif +#ifndef CV_AVX512_ICL +# define CV_AVX512_ICL 0 +#endif + +#ifndef CV_NEON +# define CV_NEON 0 +#endif + +#ifndef CV_VSX +# define CV_VSX 0 +#endif + +#ifndef CV_VSX3 +# define CV_VSX3 0 +#endif + +#ifndef CV_MSA +# define CV_MSA 0 +#endif + +#ifndef CV_WASM_SIMD +# define CV_WASM_SIMD 0 +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cv_cpu_helper.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cv_cpu_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..aaa89ed4156e9029ebe60bcc807bbea3de20e0d5 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cv_cpu_helper.h @@ -0,0 +1,487 @@ +// AUTOGENERATED, DO NOT EDIT + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE +# define CV_TRY_SSE 1 +# define CV_CPU_FORCE_SSE 1 +# define CV_CPU_HAS_SUPPORT_SSE 1 +# define CV_CPU_CALL_SSE(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE_(fn, args) return (opt_SSE::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE +# define CV_TRY_SSE 1 +# define CV_CPU_FORCE_SSE 0 +# define CV_CPU_HAS_SUPPORT_SSE (cv::checkHardwareSupport(CV_CPU_SSE)) +# define CV_CPU_CALL_SSE(fn, args) if (CV_CPU_HAS_SUPPORT_SSE) return (opt_SSE::fn args) +# define CV_CPU_CALL_SSE_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE) return (opt_SSE::fn args) +#else +# define CV_TRY_SSE 0 +# define CV_CPU_FORCE_SSE 0 +# define CV_CPU_HAS_SUPPORT_SSE 0 +# define CV_CPU_CALL_SSE(fn, args) +# define CV_CPU_CALL_SSE_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE(fn, args, mode, ...) CV_CPU_CALL_SSE(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE2 +# define CV_TRY_SSE2 1 +# define CV_CPU_FORCE_SSE2 1 +# define CV_CPU_HAS_SUPPORT_SSE2 1 +# define CV_CPU_CALL_SSE2(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE2_(fn, args) return (opt_SSE2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE2 +# define CV_TRY_SSE2 1 +# define CV_CPU_FORCE_SSE2 0 +# define CV_CPU_HAS_SUPPORT_SSE2 (cv::checkHardwareSupport(CV_CPU_SSE2)) +# define CV_CPU_CALL_SSE2(fn, args) if (CV_CPU_HAS_SUPPORT_SSE2) return (opt_SSE2::fn args) +# define CV_CPU_CALL_SSE2_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE2) return (opt_SSE2::fn args) +#else +# define CV_TRY_SSE2 0 +# define CV_CPU_FORCE_SSE2 0 +# define CV_CPU_HAS_SUPPORT_SSE2 0 +# define CV_CPU_CALL_SSE2(fn, args) +# define CV_CPU_CALL_SSE2_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE2(fn, args, mode, ...) CV_CPU_CALL_SSE2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE3 +# define CV_TRY_SSE3 1 +# define CV_CPU_FORCE_SSE3 1 +# define CV_CPU_HAS_SUPPORT_SSE3 1 +# define CV_CPU_CALL_SSE3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE3_(fn, args) return (opt_SSE3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE3 +# define CV_TRY_SSE3 1 +# define CV_CPU_FORCE_SSE3 0 +# define CV_CPU_HAS_SUPPORT_SSE3 (cv::checkHardwareSupport(CV_CPU_SSE3)) +# define CV_CPU_CALL_SSE3(fn, args) if (CV_CPU_HAS_SUPPORT_SSE3) return (opt_SSE3::fn args) +# define CV_CPU_CALL_SSE3_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE3) return (opt_SSE3::fn args) +#else +# define CV_TRY_SSE3 0 +# define CV_CPU_FORCE_SSE3 0 +# define CV_CPU_HAS_SUPPORT_SSE3 0 +# define CV_CPU_CALL_SSE3(fn, args) +# define CV_CPU_CALL_SSE3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE3(fn, args, mode, ...) CV_CPU_CALL_SSE3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSSE3 +# define CV_TRY_SSSE3 1 +# define CV_CPU_FORCE_SSSE3 1 +# define CV_CPU_HAS_SUPPORT_SSSE3 1 +# define CV_CPU_CALL_SSSE3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSSE3_(fn, args) return (opt_SSSE3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSSE3 +# define CV_TRY_SSSE3 1 +# define CV_CPU_FORCE_SSSE3 0 +# define CV_CPU_HAS_SUPPORT_SSSE3 (cv::checkHardwareSupport(CV_CPU_SSSE3)) +# define CV_CPU_CALL_SSSE3(fn, args) if (CV_CPU_HAS_SUPPORT_SSSE3) return (opt_SSSE3::fn args) +# define CV_CPU_CALL_SSSE3_(fn, args) if (CV_CPU_HAS_SUPPORT_SSSE3) return (opt_SSSE3::fn args) +#else +# define CV_TRY_SSSE3 0 +# define CV_CPU_FORCE_SSSE3 0 +# define CV_CPU_HAS_SUPPORT_SSSE3 0 +# define CV_CPU_CALL_SSSE3(fn, args) +# define CV_CPU_CALL_SSSE3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSSE3(fn, args, mode, ...) CV_CPU_CALL_SSSE3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE4_1 +# define CV_TRY_SSE4_1 1 +# define CV_CPU_FORCE_SSE4_1 1 +# define CV_CPU_HAS_SUPPORT_SSE4_1 1 +# define CV_CPU_CALL_SSE4_1(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE4_1_(fn, args) return (opt_SSE4_1::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE4_1 +# define CV_TRY_SSE4_1 1 +# define CV_CPU_FORCE_SSE4_1 0 +# define CV_CPU_HAS_SUPPORT_SSE4_1 (cv::checkHardwareSupport(CV_CPU_SSE4_1)) +# define CV_CPU_CALL_SSE4_1(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_1) return (opt_SSE4_1::fn args) +# define CV_CPU_CALL_SSE4_1_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_1) return (opt_SSE4_1::fn args) +#else +# define CV_TRY_SSE4_1 0 +# define CV_CPU_FORCE_SSE4_1 0 +# define CV_CPU_HAS_SUPPORT_SSE4_1 0 +# define CV_CPU_CALL_SSE4_1(fn, args) +# define CV_CPU_CALL_SSE4_1_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE4_1(fn, args, mode, ...) CV_CPU_CALL_SSE4_1(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_SSE4_2 +# define CV_TRY_SSE4_2 1 +# define CV_CPU_FORCE_SSE4_2 1 +# define CV_CPU_HAS_SUPPORT_SSE4_2 1 +# define CV_CPU_CALL_SSE4_2(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_SSE4_2_(fn, args) return (opt_SSE4_2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_SSE4_2 +# define CV_TRY_SSE4_2 1 +# define CV_CPU_FORCE_SSE4_2 0 +# define CV_CPU_HAS_SUPPORT_SSE4_2 (cv::checkHardwareSupport(CV_CPU_SSE4_2)) +# define CV_CPU_CALL_SSE4_2(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_2) return (opt_SSE4_2::fn args) +# define CV_CPU_CALL_SSE4_2_(fn, args) if (CV_CPU_HAS_SUPPORT_SSE4_2) return (opt_SSE4_2::fn args) +#else +# define CV_TRY_SSE4_2 0 +# define CV_CPU_FORCE_SSE4_2 0 +# define CV_CPU_HAS_SUPPORT_SSE4_2 0 +# define CV_CPU_CALL_SSE4_2(fn, args) +# define CV_CPU_CALL_SSE4_2_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_SSE4_2(fn, args, mode, ...) CV_CPU_CALL_SSE4_2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_POPCNT +# define CV_TRY_POPCNT 1 +# define CV_CPU_FORCE_POPCNT 1 +# define CV_CPU_HAS_SUPPORT_POPCNT 1 +# define CV_CPU_CALL_POPCNT(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_POPCNT_(fn, args) return (opt_POPCNT::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_POPCNT +# define CV_TRY_POPCNT 1 +# define CV_CPU_FORCE_POPCNT 0 +# define CV_CPU_HAS_SUPPORT_POPCNT (cv::checkHardwareSupport(CV_CPU_POPCNT)) +# define CV_CPU_CALL_POPCNT(fn, args) if (CV_CPU_HAS_SUPPORT_POPCNT) return (opt_POPCNT::fn args) +# define CV_CPU_CALL_POPCNT_(fn, args) if (CV_CPU_HAS_SUPPORT_POPCNT) return (opt_POPCNT::fn args) +#else +# define CV_TRY_POPCNT 0 +# define CV_CPU_FORCE_POPCNT 0 +# define CV_CPU_HAS_SUPPORT_POPCNT 0 +# define CV_CPU_CALL_POPCNT(fn, args) +# define CV_CPU_CALL_POPCNT_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_POPCNT(fn, args, mode, ...) CV_CPU_CALL_POPCNT(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX +# define CV_TRY_AVX 1 +# define CV_CPU_FORCE_AVX 1 +# define CV_CPU_HAS_SUPPORT_AVX 1 +# define CV_CPU_CALL_AVX(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX_(fn, args) return (opt_AVX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX +# define CV_TRY_AVX 1 +# define CV_CPU_FORCE_AVX 0 +# define CV_CPU_HAS_SUPPORT_AVX (cv::checkHardwareSupport(CV_CPU_AVX)) +# define CV_CPU_CALL_AVX(fn, args) if (CV_CPU_HAS_SUPPORT_AVX) return (opt_AVX::fn args) +# define CV_CPU_CALL_AVX_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX) return (opt_AVX::fn args) +#else +# define CV_TRY_AVX 0 +# define CV_CPU_FORCE_AVX 0 +# define CV_CPU_HAS_SUPPORT_AVX 0 +# define CV_CPU_CALL_AVX(fn, args) +# define CV_CPU_CALL_AVX_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX(fn, args, mode, ...) CV_CPU_CALL_AVX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_FP16 +# define CV_TRY_FP16 1 +# define CV_CPU_FORCE_FP16 1 +# define CV_CPU_HAS_SUPPORT_FP16 1 +# define CV_CPU_CALL_FP16(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_FP16_(fn, args) return (opt_FP16::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_FP16 +# define CV_TRY_FP16 1 +# define CV_CPU_FORCE_FP16 0 +# define CV_CPU_HAS_SUPPORT_FP16 (cv::checkHardwareSupport(CV_CPU_FP16)) +# define CV_CPU_CALL_FP16(fn, args) if (CV_CPU_HAS_SUPPORT_FP16) return (opt_FP16::fn args) +# define CV_CPU_CALL_FP16_(fn, args) if (CV_CPU_HAS_SUPPORT_FP16) return (opt_FP16::fn args) +#else +# define CV_TRY_FP16 0 +# define CV_CPU_FORCE_FP16 0 +# define CV_CPU_HAS_SUPPORT_FP16 0 +# define CV_CPU_CALL_FP16(fn, args) +# define CV_CPU_CALL_FP16_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_FP16(fn, args, mode, ...) CV_CPU_CALL_FP16(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX2 +# define CV_TRY_AVX2 1 +# define CV_CPU_FORCE_AVX2 1 +# define CV_CPU_HAS_SUPPORT_AVX2 1 +# define CV_CPU_CALL_AVX2(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX2_(fn, args) return (opt_AVX2::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX2 +# define CV_TRY_AVX2 1 +# define CV_CPU_FORCE_AVX2 0 +# define CV_CPU_HAS_SUPPORT_AVX2 (cv::checkHardwareSupport(CV_CPU_AVX2)) +# define CV_CPU_CALL_AVX2(fn, args) if (CV_CPU_HAS_SUPPORT_AVX2) return (opt_AVX2::fn args) +# define CV_CPU_CALL_AVX2_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX2) return (opt_AVX2::fn args) +#else +# define CV_TRY_AVX2 0 +# define CV_CPU_FORCE_AVX2 0 +# define CV_CPU_HAS_SUPPORT_AVX2 0 +# define CV_CPU_CALL_AVX2(fn, args) +# define CV_CPU_CALL_AVX2_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX2(fn, args, mode, ...) CV_CPU_CALL_AVX2(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_FMA3 +# define CV_TRY_FMA3 1 +# define CV_CPU_FORCE_FMA3 1 +# define CV_CPU_HAS_SUPPORT_FMA3 1 +# define CV_CPU_CALL_FMA3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_FMA3_(fn, args) return (opt_FMA3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_FMA3 +# define CV_TRY_FMA3 1 +# define CV_CPU_FORCE_FMA3 0 +# define CV_CPU_HAS_SUPPORT_FMA3 (cv::checkHardwareSupport(CV_CPU_FMA3)) +# define CV_CPU_CALL_FMA3(fn, args) if (CV_CPU_HAS_SUPPORT_FMA3) return (opt_FMA3::fn args) +# define CV_CPU_CALL_FMA3_(fn, args) if (CV_CPU_HAS_SUPPORT_FMA3) return (opt_FMA3::fn args) +#else +# define CV_TRY_FMA3 0 +# define CV_CPU_FORCE_FMA3 0 +# define CV_CPU_HAS_SUPPORT_FMA3 0 +# define CV_CPU_CALL_FMA3(fn, args) +# define CV_CPU_CALL_FMA3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_FMA3(fn, args, mode, ...) CV_CPU_CALL_FMA3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX_512F +# define CV_TRY_AVX_512F 1 +# define CV_CPU_FORCE_AVX_512F 1 +# define CV_CPU_HAS_SUPPORT_AVX_512F 1 +# define CV_CPU_CALL_AVX_512F(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX_512F_(fn, args) return (opt_AVX_512F::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX_512F +# define CV_TRY_AVX_512F 1 +# define CV_CPU_FORCE_AVX_512F 0 +# define CV_CPU_HAS_SUPPORT_AVX_512F (cv::checkHardwareSupport(CV_CPU_AVX_512F)) +# define CV_CPU_CALL_AVX_512F(fn, args) if (CV_CPU_HAS_SUPPORT_AVX_512F) return (opt_AVX_512F::fn args) +# define CV_CPU_CALL_AVX_512F_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX_512F) return (opt_AVX_512F::fn args) +#else +# define CV_TRY_AVX_512F 0 +# define CV_CPU_FORCE_AVX_512F 0 +# define CV_CPU_HAS_SUPPORT_AVX_512F 0 +# define CV_CPU_CALL_AVX_512F(fn, args) +# define CV_CPU_CALL_AVX_512F_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX_512F(fn, args, mode, ...) CV_CPU_CALL_AVX_512F(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_COMMON +# define CV_TRY_AVX512_COMMON 1 +# define CV_CPU_FORCE_AVX512_COMMON 1 +# define CV_CPU_HAS_SUPPORT_AVX512_COMMON 1 +# define CV_CPU_CALL_AVX512_COMMON(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_COMMON_(fn, args) return (opt_AVX512_COMMON::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_COMMON +# define CV_TRY_AVX512_COMMON 1 +# define CV_CPU_FORCE_AVX512_COMMON 0 +# define CV_CPU_HAS_SUPPORT_AVX512_COMMON (cv::checkHardwareSupport(CV_CPU_AVX512_COMMON)) +# define CV_CPU_CALL_AVX512_COMMON(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_COMMON) return (opt_AVX512_COMMON::fn args) +# define CV_CPU_CALL_AVX512_COMMON_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_COMMON) return (opt_AVX512_COMMON::fn args) +#else +# define CV_TRY_AVX512_COMMON 0 +# define CV_CPU_FORCE_AVX512_COMMON 0 +# define CV_CPU_HAS_SUPPORT_AVX512_COMMON 0 +# define CV_CPU_CALL_AVX512_COMMON(fn, args) +# define CV_CPU_CALL_AVX512_COMMON_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_COMMON(fn, args, mode, ...) CV_CPU_CALL_AVX512_COMMON(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_KNL +# define CV_TRY_AVX512_KNL 1 +# define CV_CPU_FORCE_AVX512_KNL 1 +# define CV_CPU_HAS_SUPPORT_AVX512_KNL 1 +# define CV_CPU_CALL_AVX512_KNL(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_KNL_(fn, args) return (opt_AVX512_KNL::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_KNL +# define CV_TRY_AVX512_KNL 1 +# define CV_CPU_FORCE_AVX512_KNL 0 +# define CV_CPU_HAS_SUPPORT_AVX512_KNL (cv::checkHardwareSupport(CV_CPU_AVX512_KNL)) +# define CV_CPU_CALL_AVX512_KNL(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_KNL) return (opt_AVX512_KNL::fn args) +# define CV_CPU_CALL_AVX512_KNL_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_KNL) return (opt_AVX512_KNL::fn args) +#else +# define CV_TRY_AVX512_KNL 0 +# define CV_CPU_FORCE_AVX512_KNL 0 +# define CV_CPU_HAS_SUPPORT_AVX512_KNL 0 +# define CV_CPU_CALL_AVX512_KNL(fn, args) +# define CV_CPU_CALL_AVX512_KNL_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_KNL(fn, args, mode, ...) CV_CPU_CALL_AVX512_KNL(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_KNM +# define CV_TRY_AVX512_KNM 1 +# define CV_CPU_FORCE_AVX512_KNM 1 +# define CV_CPU_HAS_SUPPORT_AVX512_KNM 1 +# define CV_CPU_CALL_AVX512_KNM(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_KNM_(fn, args) return (opt_AVX512_KNM::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_KNM +# define CV_TRY_AVX512_KNM 1 +# define CV_CPU_FORCE_AVX512_KNM 0 +# define CV_CPU_HAS_SUPPORT_AVX512_KNM (cv::checkHardwareSupport(CV_CPU_AVX512_KNM)) +# define CV_CPU_CALL_AVX512_KNM(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_KNM) return (opt_AVX512_KNM::fn args) +# define CV_CPU_CALL_AVX512_KNM_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_KNM) return (opt_AVX512_KNM::fn args) +#else +# define CV_TRY_AVX512_KNM 0 +# define CV_CPU_FORCE_AVX512_KNM 0 +# define CV_CPU_HAS_SUPPORT_AVX512_KNM 0 +# define CV_CPU_CALL_AVX512_KNM(fn, args) +# define CV_CPU_CALL_AVX512_KNM_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_KNM(fn, args, mode, ...) CV_CPU_CALL_AVX512_KNM(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_SKX +# define CV_TRY_AVX512_SKX 1 +# define CV_CPU_FORCE_AVX512_SKX 1 +# define CV_CPU_HAS_SUPPORT_AVX512_SKX 1 +# define CV_CPU_CALL_AVX512_SKX(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_SKX_(fn, args) return (opt_AVX512_SKX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_SKX +# define CV_TRY_AVX512_SKX 1 +# define CV_CPU_FORCE_AVX512_SKX 0 +# define CV_CPU_HAS_SUPPORT_AVX512_SKX (cv::checkHardwareSupport(CV_CPU_AVX512_SKX)) +# define CV_CPU_CALL_AVX512_SKX(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_SKX) return (opt_AVX512_SKX::fn args) +# define CV_CPU_CALL_AVX512_SKX_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_SKX) return (opt_AVX512_SKX::fn args) +#else +# define CV_TRY_AVX512_SKX 0 +# define CV_CPU_FORCE_AVX512_SKX 0 +# define CV_CPU_HAS_SUPPORT_AVX512_SKX 0 +# define CV_CPU_CALL_AVX512_SKX(fn, args) +# define CV_CPU_CALL_AVX512_SKX_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_SKX(fn, args, mode, ...) CV_CPU_CALL_AVX512_SKX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_CNL +# define CV_TRY_AVX512_CNL 1 +# define CV_CPU_FORCE_AVX512_CNL 1 +# define CV_CPU_HAS_SUPPORT_AVX512_CNL 1 +# define CV_CPU_CALL_AVX512_CNL(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_CNL_(fn, args) return (opt_AVX512_CNL::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_CNL +# define CV_TRY_AVX512_CNL 1 +# define CV_CPU_FORCE_AVX512_CNL 0 +# define CV_CPU_HAS_SUPPORT_AVX512_CNL (cv::checkHardwareSupport(CV_CPU_AVX512_CNL)) +# define CV_CPU_CALL_AVX512_CNL(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_CNL) return (opt_AVX512_CNL::fn args) +# define CV_CPU_CALL_AVX512_CNL_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_CNL) return (opt_AVX512_CNL::fn args) +#else +# define CV_TRY_AVX512_CNL 0 +# define CV_CPU_FORCE_AVX512_CNL 0 +# define CV_CPU_HAS_SUPPORT_AVX512_CNL 0 +# define CV_CPU_CALL_AVX512_CNL(fn, args) +# define CV_CPU_CALL_AVX512_CNL_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_CNL(fn, args, mode, ...) CV_CPU_CALL_AVX512_CNL(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_CLX +# define CV_TRY_AVX512_CLX 1 +# define CV_CPU_FORCE_AVX512_CLX 1 +# define CV_CPU_HAS_SUPPORT_AVX512_CLX 1 +# define CV_CPU_CALL_AVX512_CLX(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_CLX_(fn, args) return (opt_AVX512_CLX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_CLX +# define CV_TRY_AVX512_CLX 1 +# define CV_CPU_FORCE_AVX512_CLX 0 +# define CV_CPU_HAS_SUPPORT_AVX512_CLX (cv::checkHardwareSupport(CV_CPU_AVX512_CLX)) +# define CV_CPU_CALL_AVX512_CLX(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_CLX) return (opt_AVX512_CLX::fn args) +# define CV_CPU_CALL_AVX512_CLX_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_CLX) return (opt_AVX512_CLX::fn args) +#else +# define CV_TRY_AVX512_CLX 0 +# define CV_CPU_FORCE_AVX512_CLX 0 +# define CV_CPU_HAS_SUPPORT_AVX512_CLX 0 +# define CV_CPU_CALL_AVX512_CLX(fn, args) +# define CV_CPU_CALL_AVX512_CLX_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_CLX(fn, args, mode, ...) CV_CPU_CALL_AVX512_CLX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_AVX512_ICL +# define CV_TRY_AVX512_ICL 1 +# define CV_CPU_FORCE_AVX512_ICL 1 +# define CV_CPU_HAS_SUPPORT_AVX512_ICL 1 +# define CV_CPU_CALL_AVX512_ICL(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_AVX512_ICL_(fn, args) return (opt_AVX512_ICL::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_AVX512_ICL +# define CV_TRY_AVX512_ICL 1 +# define CV_CPU_FORCE_AVX512_ICL 0 +# define CV_CPU_HAS_SUPPORT_AVX512_ICL (cv::checkHardwareSupport(CV_CPU_AVX512_ICL)) +# define CV_CPU_CALL_AVX512_ICL(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_ICL) return (opt_AVX512_ICL::fn args) +# define CV_CPU_CALL_AVX512_ICL_(fn, args) if (CV_CPU_HAS_SUPPORT_AVX512_ICL) return (opt_AVX512_ICL::fn args) +#else +# define CV_TRY_AVX512_ICL 0 +# define CV_CPU_FORCE_AVX512_ICL 0 +# define CV_CPU_HAS_SUPPORT_AVX512_ICL 0 +# define CV_CPU_CALL_AVX512_ICL(fn, args) +# define CV_CPU_CALL_AVX512_ICL_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_AVX512_ICL(fn, args, mode, ...) CV_CPU_CALL_AVX512_ICL(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_NEON +# define CV_TRY_NEON 1 +# define CV_CPU_FORCE_NEON 1 +# define CV_CPU_HAS_SUPPORT_NEON 1 +# define CV_CPU_CALL_NEON(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_NEON_(fn, args) return (opt_NEON::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_NEON +# define CV_TRY_NEON 1 +# define CV_CPU_FORCE_NEON 0 +# define CV_CPU_HAS_SUPPORT_NEON (cv::checkHardwareSupport(CV_CPU_NEON)) +# define CV_CPU_CALL_NEON(fn, args) if (CV_CPU_HAS_SUPPORT_NEON) return (opt_NEON::fn args) +# define CV_CPU_CALL_NEON_(fn, args) if (CV_CPU_HAS_SUPPORT_NEON) return (opt_NEON::fn args) +#else +# define CV_TRY_NEON 0 +# define CV_CPU_FORCE_NEON 0 +# define CV_CPU_HAS_SUPPORT_NEON 0 +# define CV_CPU_CALL_NEON(fn, args) +# define CV_CPU_CALL_NEON_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_NEON(fn, args, mode, ...) CV_CPU_CALL_NEON(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_MSA +# define CV_TRY_MSA 1 +# define CV_CPU_FORCE_MSA 1 +# define CV_CPU_HAS_SUPPORT_MSA 1 +# define CV_CPU_CALL_MSA(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_MSA_(fn, args) return (opt_MSA::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_MSA +# define CV_TRY_MSA 1 +# define CV_CPU_FORCE_MSA 0 +# define CV_CPU_HAS_SUPPORT_MSA (cv::checkHardwareSupport(CV_CPU_MSA)) +# define CV_CPU_CALL_MSA(fn, args) if (CV_CPU_HAS_SUPPORT_MSA) return (opt_MSA::fn args) +# define CV_CPU_CALL_MSA_(fn, args) if (CV_CPU_HAS_SUPPORT_MSA) return (opt_MSA::fn args) +#else +# define CV_TRY_MSA 0 +# define CV_CPU_FORCE_MSA 0 +# define CV_CPU_HAS_SUPPORT_MSA 0 +# define CV_CPU_CALL_MSA(fn, args) +# define CV_CPU_CALL_MSA_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_MSA(fn, args, mode, ...) CV_CPU_CALL_MSA(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_VSX +# define CV_TRY_VSX 1 +# define CV_CPU_FORCE_VSX 1 +# define CV_CPU_HAS_SUPPORT_VSX 1 +# define CV_CPU_CALL_VSX(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_VSX_(fn, args) return (opt_VSX::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_VSX +# define CV_TRY_VSX 1 +# define CV_CPU_FORCE_VSX 0 +# define CV_CPU_HAS_SUPPORT_VSX (cv::checkHardwareSupport(CV_CPU_VSX)) +# define CV_CPU_CALL_VSX(fn, args) if (CV_CPU_HAS_SUPPORT_VSX) return (opt_VSX::fn args) +# define CV_CPU_CALL_VSX_(fn, args) if (CV_CPU_HAS_SUPPORT_VSX) return (opt_VSX::fn args) +#else +# define CV_TRY_VSX 0 +# define CV_CPU_FORCE_VSX 0 +# define CV_CPU_HAS_SUPPORT_VSX 0 +# define CV_CPU_CALL_VSX(fn, args) +# define CV_CPU_CALL_VSX_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_VSX(fn, args, mode, ...) CV_CPU_CALL_VSX(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#if !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_COMPILE_VSX3 +# define CV_TRY_VSX3 1 +# define CV_CPU_FORCE_VSX3 1 +# define CV_CPU_HAS_SUPPORT_VSX3 1 +# define CV_CPU_CALL_VSX3(fn, args) return (cpu_baseline::fn args) +# define CV_CPU_CALL_VSX3_(fn, args) return (opt_VSX3::fn args) +#elif !defined CV_DISABLE_OPTIMIZATION && defined CV_ENABLE_INTRINSICS && defined CV_CPU_DISPATCH_COMPILE_VSX3 +# define CV_TRY_VSX3 1 +# define CV_CPU_FORCE_VSX3 0 +# define CV_CPU_HAS_SUPPORT_VSX3 (cv::checkHardwareSupport(CV_CPU_VSX3)) +# define CV_CPU_CALL_VSX3(fn, args) if (CV_CPU_HAS_SUPPORT_VSX3) return (opt_VSX3::fn args) +# define CV_CPU_CALL_VSX3_(fn, args) if (CV_CPU_HAS_SUPPORT_VSX3) return (opt_VSX3::fn args) +#else +# define CV_TRY_VSX3 0 +# define CV_CPU_FORCE_VSX3 0 +# define CV_CPU_HAS_SUPPORT_VSX3 0 +# define CV_CPU_CALL_VSX3(fn, args) +# define CV_CPU_CALL_VSX3_(fn, args) +#endif +#define __CV_CPU_DISPATCH_CHAIN_VSX3(fn, args, mode, ...) CV_CPU_CALL_VSX3(fn, args); __CV_EXPAND(__CV_CPU_DISPATCH_CHAIN_ ## mode(fn, args, __VA_ARGS__)) + +#define CV_CPU_CALL_BASELINE(fn, args) return (cpu_baseline::fn args) +#define __CV_CPU_DISPATCH_CHAIN_BASELINE(fn, args, mode, ...) CV_CPU_CALL_BASELINE(fn, args) /* last in sequence */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvdef.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvdef.h new file mode 100644 index 0000000000000000000000000000000000000000..792f59e7e8f7982ee1ef66788c466fe07bf664a9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvdef.h @@ -0,0 +1,896 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_CVDEF_H +#define OPENCV_CORE_CVDEF_H + +//! @addtogroup core_utils +//! @{ + +#ifdef OPENCV_INCLUDE_PORT_FILE // User-provided header file with custom platform configuration +#include OPENCV_INCLUDE_PORT_FILE +#endif + +#if !defined CV_DOXYGEN && !defined CV_IGNORE_DEBUG_BUILD_GUARD +#if (defined(_MSC_VER) && (defined(DEBUG) || defined(_DEBUG))) || \ + (defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_DEBUG_PEDANTIC)) +// Guard to prevent using of binary incompatible binaries / runtimes +// https://github.com/opencv/opencv/pull/9161 +#define CV__DEBUG_NS_BEGIN namespace debug_build_guard { +#define CV__DEBUG_NS_END } +namespace cv { namespace debug_build_guard { } using namespace debug_build_guard; } +#endif +#endif + +#ifndef CV__DEBUG_NS_BEGIN +#define CV__DEBUG_NS_BEGIN +#define CV__DEBUG_NS_END +#endif + + +#ifdef __OPENCV_BUILD +#include "cvconfig.h" +#endif + +#ifndef __CV_EXPAND +#define __CV_EXPAND(x) x +#endif + +#ifndef __CV_CAT +#define __CV_CAT__(x, y) x ## y +#define __CV_CAT_(x, y) __CV_CAT__(x, y) +#define __CV_CAT(x, y) __CV_CAT_(x, y) +#endif + +#define __CV_VA_NUM_ARGS_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N +#define __CV_VA_NUM_ARGS(...) __CV_EXPAND(__CV_VA_NUM_ARGS_HELPER(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) + +#if defined __GNUC__ +#define CV_Func __func__ +#elif defined _MSC_VER +#define CV_Func __FUNCTION__ +#else +#define CV_Func "" +#endif + +//! @cond IGNORED + +//////////////// static assert ///////////////// +#define CVAUX_CONCAT_EXP(a, b) a##b +#define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b) + +#if defined(__clang__) +# ifndef __has_extension +# define __has_extension __has_feature /* compatibility, for older versions of clang */ +# endif +# if __has_extension(cxx_static_assert) +# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition) +# elif __has_extension(c_static_assert) +# define CV_StaticAssert(condition, reason) _Static_assert((condition), reason " " #condition) +# endif +#elif defined(__GNUC__) +# if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L) +# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition) +# endif +#elif defined(_MSC_VER) +# if _MSC_VER >= 1600 /* MSVC 10 */ +# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition) +# endif +#endif +#ifndef CV_StaticAssert +# if !defined(__clang__) && defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302) +# define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); }) +# else +namespace cv { + template struct CV_StaticAssert_failed; + template <> struct CV_StaticAssert_failed { enum { val = 1 }; }; + template struct CV_StaticAssert_test {}; +} +# define CV_StaticAssert(condition, reason)\ + typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__) +# endif +#endif + +// Suppress warning "-Wdeprecated-declarations" / C4996 +#if defined(_MSC_VER) + #define CV_DO_PRAGMA(x) __pragma(x) +#elif defined(__GNUC__) + #define CV_DO_PRAGMA(x) _Pragma (#x) +#else + #define CV_DO_PRAGMA(x) +#endif + +#ifdef _MSC_VER +#define CV_SUPPRESS_DEPRECATED_START \ + CV_DO_PRAGMA(warning(push)) \ + CV_DO_PRAGMA(warning(disable: 4996)) +#define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop)) +#elif defined (__clang__) || ((__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 405)) +#define CV_SUPPRESS_DEPRECATED_START \ + CV_DO_PRAGMA(GCC diagnostic push) \ + CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations") +#define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop) +#else +#define CV_SUPPRESS_DEPRECATED_START +#define CV_SUPPRESS_DEPRECATED_END +#endif + +#define CV_UNUSED(name) (void)name + +//! @endcond + +// undef problematic defines sometimes defined by system headers (windows.h in particular) +#undef small +#undef min +#undef max +#undef abs +#undef Complex + +#include +#include "opencv2/core/hal/interface.h" + +#if defined __ICL +# define CV_ICC __ICL +#elif defined __ICC +# define CV_ICC __ICC +#elif defined __ECL +# define CV_ICC __ECL +#elif defined __ECC +# define CV_ICC __ECC +#elif defined __INTEL_COMPILER +# define CV_ICC __INTEL_COMPILER +#endif + +#ifndef CV_INLINE +# if defined __cplusplus +# define CV_INLINE static inline +# elif defined _MSC_VER +# define CV_INLINE __inline +# else +# define CV_INLINE static +# endif +#endif + +#ifndef CV_ALWAYS_INLINE +#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) +#define CV_ALWAYS_INLINE inline __attribute__((always_inline)) +#elif defined(_MSC_VER) +#define CV_ALWAYS_INLINE __forceinline +#else +#define CV_ALWAYS_INLINE inline +#endif +#endif + +#if defined CV_DISABLE_OPTIMIZATION || (defined CV_ICC && !defined CV_ENABLE_UNROLLED) +# define CV_ENABLE_UNROLLED 0 +#else +# define CV_ENABLE_UNROLLED 1 +#endif + +#ifdef __GNUC__ +# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x))) +#elif defined _MSC_VER +# define CV_DECL_ALIGNED(x) __declspec(align(x)) +#else +# define CV_DECL_ALIGNED(x) +#endif + +/* CPU features and intrinsics support */ +#define CV_CPU_NONE 0 +#define CV_CPU_MMX 1 +#define CV_CPU_SSE 2 +#define CV_CPU_SSE2 3 +#define CV_CPU_SSE3 4 +#define CV_CPU_SSSE3 5 +#define CV_CPU_SSE4_1 6 +#define CV_CPU_SSE4_2 7 +#define CV_CPU_POPCNT 8 +#define CV_CPU_FP16 9 +#define CV_CPU_AVX 10 +#define CV_CPU_AVX2 11 +#define CV_CPU_FMA3 12 + +#define CV_CPU_AVX_512F 13 +#define CV_CPU_AVX_512BW 14 +#define CV_CPU_AVX_512CD 15 +#define CV_CPU_AVX_512DQ 16 +#define CV_CPU_AVX_512ER 17 +#define CV_CPU_AVX_512IFMA512 18 // deprecated +#define CV_CPU_AVX_512IFMA 18 +#define CV_CPU_AVX_512PF 19 +#define CV_CPU_AVX_512VBMI 20 +#define CV_CPU_AVX_512VL 21 +#define CV_CPU_AVX_512VBMI2 22 +#define CV_CPU_AVX_512VNNI 23 +#define CV_CPU_AVX_512BITALG 24 +#define CV_CPU_AVX_512VPOPCNTDQ 25 +#define CV_CPU_AVX_5124VNNIW 26 +#define CV_CPU_AVX_5124FMAPS 27 + +#define CV_CPU_NEON 100 + +#define CV_CPU_MSA 150 + +#define CV_CPU_VSX 200 +#define CV_CPU_VSX3 201 + +// CPU features groups +#define CV_CPU_AVX512_SKX 256 +#define CV_CPU_AVX512_COMMON 257 +#define CV_CPU_AVX512_KNL 258 +#define CV_CPU_AVX512_KNM 259 +#define CV_CPU_AVX512_CNL 260 +#define CV_CPU_AVX512_CLX 261 +#define CV_CPU_AVX512_ICL 262 + +// when adding to this list remember to update the following enum +#define CV_HARDWARE_MAX_FEATURE 512 + +/** @brief Available CPU features. +*/ +enum CpuFeatures { + CPU_MMX = 1, + CPU_SSE = 2, + CPU_SSE2 = 3, + CPU_SSE3 = 4, + CPU_SSSE3 = 5, + CPU_SSE4_1 = 6, + CPU_SSE4_2 = 7, + CPU_POPCNT = 8, + CPU_FP16 = 9, + CPU_AVX = 10, + CPU_AVX2 = 11, + CPU_FMA3 = 12, + + CPU_AVX_512F = 13, + CPU_AVX_512BW = 14, + CPU_AVX_512CD = 15, + CPU_AVX_512DQ = 16, + CPU_AVX_512ER = 17, + CPU_AVX_512IFMA512 = 18, // deprecated + CPU_AVX_512IFMA = 18, + CPU_AVX_512PF = 19, + CPU_AVX_512VBMI = 20, + CPU_AVX_512VL = 21, + CPU_AVX_512VBMI2 = 22, + CPU_AVX_512VNNI = 23, + CPU_AVX_512BITALG = 24, + CPU_AVX_512VPOPCNTDQ= 25, + CPU_AVX_5124VNNIW = 26, + CPU_AVX_5124FMAPS = 27, + + CPU_NEON = 100, + + CPU_MSA = 150, + + CPU_VSX = 200, + CPU_VSX3 = 201, + + CPU_AVX512_SKX = 256, //!< Skylake-X with AVX-512F/CD/BW/DQ/VL + CPU_AVX512_COMMON = 257, //!< Common instructions AVX-512F/CD for all CPUs that support AVX-512 + CPU_AVX512_KNL = 258, //!< Knights Landing with AVX-512F/CD/ER/PF + CPU_AVX512_KNM = 259, //!< Knights Mill with AVX-512F/CD/ER/PF/4FMAPS/4VNNIW/VPOPCNTDQ + CPU_AVX512_CNL = 260, //!< Cannon Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI + CPU_AVX512_CLX = 261, //!< Cascade Lake with AVX-512F/CD/BW/DQ/VL/VNNI + CPU_AVX512_ICL = 262, //!< Ice Lake with AVX-512F/CD/BW/DQ/VL/IFMA/VBMI/VNNI/VBMI2/BITALG/VPOPCNTDQ + + CPU_MAX_FEATURE = 512 // see CV_HARDWARE_MAX_FEATURE +}; + + +#include "cv_cpu_dispatch.h" + + +/* fundamental constants */ +#define CV_PI 3.1415926535897932384626433832795 +#define CV_2PI 6.283185307179586476925286766559 +#define CV_LOG2 0.69314718055994530941723212145818 + +#if defined __ARM_FP16_FORMAT_IEEE \ + && !defined __CUDACC__ +# define CV_FP16_TYPE 1 +#else +# define CV_FP16_TYPE 0 +#endif + +typedef union Cv16suf +{ + short i; + ushort u; +#if CV_FP16_TYPE + __fp16 h; +#endif +} +Cv16suf; + +typedef union Cv32suf +{ + int i; + unsigned u; + float f; +} +Cv32suf; + +typedef union Cv64suf +{ + int64 i; + uint64 u; + double f; +} +Cv64suf; + +#define OPENCV_ABI_COMPATIBILITY 400 + +#ifdef __OPENCV_BUILD +# define DISABLE_OPENCV_3_COMPATIBILITY +# define OPENCV_DISABLE_DEPRECATED_COMPATIBILITY +#endif + +#ifndef CV_EXPORTS +# if (defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined(CVAPI_EXPORTS) +# define CV_EXPORTS __declspec(dllexport) +# elif defined __GNUC__ && __GNUC__ >= 4 && (defined(CVAPI_EXPORTS) || defined(__APPLE__)) +# define CV_EXPORTS __attribute__ ((visibility ("default"))) +# endif +#endif + +#ifndef CV_EXPORTS +# define CV_EXPORTS +#endif + +#ifdef _MSC_VER +# define CV_EXPORTS_TEMPLATE +#else +# define CV_EXPORTS_TEMPLATE CV_EXPORTS +#endif + +#ifndef CV_DEPRECATED +# if defined(__GNUC__) +# define CV_DEPRECATED __attribute__ ((deprecated)) +# elif defined(_MSC_VER) +# define CV_DEPRECATED __declspec(deprecated) +# else +# define CV_DEPRECATED +# endif +#endif + +#ifndef CV_DEPRECATED_EXTERNAL +# if defined(__OPENCV_BUILD) +# define CV_DEPRECATED_EXTERNAL /* nothing */ +# else +# define CV_DEPRECATED_EXTERNAL CV_DEPRECATED +# endif +#endif + + +#ifndef CV_EXTERN_C +# ifdef __cplusplus +# define CV_EXTERN_C extern "C" +# else +# define CV_EXTERN_C +# endif +#endif + +/* special informative macros for wrapper generators */ +#define CV_EXPORTS_W CV_EXPORTS +#define CV_EXPORTS_W_SIMPLE CV_EXPORTS +#define CV_EXPORTS_AS(synonym) CV_EXPORTS +#define CV_EXPORTS_W_MAP CV_EXPORTS +#define CV_IN_OUT +#define CV_OUT +#define CV_PROP +#define CV_PROP_RW +#define CV_WRAP +#define CV_WRAP_AS(synonym) +#define CV_WRAP_MAPPABLE(mappable) +#define CV_WRAP_PHANTOM(phantom_header) +#define CV_WRAP_DEFAULT(val) + +/****************************************************************************************\ +* Matrix type (Mat) * +\****************************************************************************************/ + +#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) +#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) +#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) +#define CV_MAT_CONT_FLAG_SHIFT 14 +#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT) +#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG) +#define CV_IS_CONT_MAT CV_IS_MAT_CONT +#define CV_SUBMAT_FLAG_SHIFT 15 +#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT) +#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) + +/** Size of each channel item, + 0x28442211 = 0010 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ +#define CV_ELEM_SIZE1(type) ((0x28442211 >> CV_MAT_DEPTH(type)*4) & 15) + +#define CV_ELEM_SIZE(type) (CV_MAT_CN(type)*CV_ELEM_SIZE1(type)) + +#ifndef MIN +# define MIN(a,b) ((a) > (b) ? (b) : (a)) +#endif + +#ifndef MAX +# define MAX(a,b) ((a) < (b) ? (b) : (a)) +#endif + +///////////////////////////////////////// Enum operators /////////////////////////////////////// + +/** + +Provides compatibility operators for both classical and C++11 enum classes, +as well as exposing the C++11 enum class members for backwards compatibility + +@code + // Provides operators required for flag enums + CV_ENUM_FLAGS(AccessFlag) + + // Exposes the listed members of the enum class AccessFlag to the current namespace + CV_ENUM_CLASS_EXPOSE(AccessFlag, ACCESS_READ [, ACCESS_WRITE [, ...] ]); +@endcode +*/ + +#define __CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST) \ +static const EnumType MEMBER_CONST = EnumType::MEMBER_CONST; \ + +#define __CV_ENUM_CLASS_EXPOSE_2(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_1(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_3(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_2(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_4(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_3(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_5(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_4(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_6(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_5(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_7(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_6(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_8(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_7(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_CLASS_EXPOSE_9(EnumType, MEMBER_CONST, ...) \ +__CV_ENUM_CLASS_EXPOSE_1(EnumType, MEMBER_CONST); \ +__CV_EXPAND(__CV_ENUM_CLASS_EXPOSE_8(EnumType, __VA_ARGS__)); \ + +#define __CV_ENUM_FLAGS_LOGICAL_NOT(EnumType) \ +static inline bool operator!(const EnumType& val) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return !static_cast(val); \ +} \ + +#define __CV_ENUM_FLAGS_LOGICAL_NOT_EQ(Arg1Type, Arg2Type) \ +static inline bool operator!=(const Arg1Type& a, const Arg2Type& b) \ +{ \ + return static_cast(a) != static_cast(b); \ +} \ + +#define __CV_ENUM_FLAGS_LOGICAL_EQ(Arg1Type, Arg2Type) \ +static inline bool operator==(const Arg1Type& a, const Arg2Type& b) \ +{ \ + return static_cast(a) == static_cast(b); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_NOT(EnumType) \ +static inline EnumType operator~(const EnumType& val) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(~static_cast(val)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_OR(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator|(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) | static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_AND(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator&(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) & static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_XOR(EnumType, Arg1Type, Arg2Type) \ +static inline EnumType operator^(const Arg1Type& a, const Arg2Type& b) \ +{ \ + typedef std::underlying_type::type UnderlyingType; \ + return static_cast(static_cast(a) ^ static_cast(b)); \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_OR_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator|=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) | static_cast(val)); \ + return _this; \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_AND_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator&=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) & static_cast(val)); \ + return _this; \ +} \ + +#define __CV_ENUM_FLAGS_BITWISE_XOR_EQ(EnumType, Arg1Type) \ +static inline EnumType& operator^=(EnumType& _this, const Arg1Type& val) \ +{ \ + _this = static_cast(static_cast(_this) ^ static_cast(val)); \ + return _this; \ +} \ + +#define CV_ENUM_CLASS_EXPOSE(EnumType, ...) \ +__CV_EXPAND(__CV_CAT(__CV_ENUM_CLASS_EXPOSE_, __CV_VA_NUM_ARGS(__VA_ARGS__))(EnumType, __VA_ARGS__)); \ + +#define CV_ENUM_FLAGS(EnumType) \ +__CV_ENUM_FLAGS_LOGICAL_NOT (EnumType) \ +__CV_ENUM_FLAGS_LOGICAL_EQ (EnumType, int) \ +__CV_ENUM_FLAGS_LOGICAL_NOT_EQ (EnumType, int) \ + \ +__CV_ENUM_FLAGS_BITWISE_NOT (EnumType) \ +__CV_ENUM_FLAGS_BITWISE_OR (EnumType, EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_AND (EnumType, EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_XOR (EnumType, EnumType, EnumType) \ + \ +__CV_ENUM_FLAGS_BITWISE_OR_EQ (EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_AND_EQ (EnumType, EnumType) \ +__CV_ENUM_FLAGS_BITWISE_XOR_EQ (EnumType, EnumType) \ + +/****************************************************************************************\ +* static analysys * +\****************************************************************************************/ + +// In practice, some macro are not processed correctly (noreturn is not detected). +// We need to use simplified definition for them. +#ifndef CV_STATIC_ANALYSIS +# if defined(__KLOCWORK__) || defined(__clang_analyzer__) || defined(__COVERITY__) +# define CV_STATIC_ANALYSIS 1 +# endif +#else +# if defined(CV_STATIC_ANALYSIS) && !(__CV_CAT(1, CV_STATIC_ANALYSIS) == 1) // defined and not empty +# if 0 == CV_STATIC_ANALYSIS +# undef CV_STATIC_ANALYSIS +# endif +# endif +#endif + +/****************************************************************************************\ +* Thread sanitizer * +\****************************************************************************************/ +#ifndef CV_THREAD_SANITIZER +# if defined(__has_feature) +# if __has_feature(thread_sanitizer) +# define CV_THREAD_SANITIZER +# endif +# endif +#endif + +/****************************************************************************************\ +* exchange-add operation for atomic operations on reference counters * +\****************************************************************************************/ + +#ifdef CV_XADD + // allow to use user-defined macro +#elif defined __GNUC__ || defined __clang__ +# if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__) && !defined __INTEL_COMPILER +# ifdef __ATOMIC_ACQ_REL +# define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL) +# else +# define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4) +# endif +# else +# if defined __ATOMIC_ACQ_REL && !defined __clang__ + // version for gcc >= 4.7 +# define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL) +# else +# define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta)) +# endif +# endif +#elif defined _MSC_VER && !defined RC_INVOKED +# include +# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta) +#else + #ifdef OPENCV_FORCE_UNSAFE_XADD + CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; } + #else + #error "OpenCV: can't define safe CV_XADD macro for current platform (unsupported). Define CV_XADD macro through custom port header (see OPENCV_INCLUDE_PORT_FILE)" + #endif +#endif + + +/****************************************************************************************\ +* CV_NORETURN attribute * +\****************************************************************************************/ + +#ifndef CV_NORETURN +# if defined(__GNUC__) +# define CV_NORETURN __attribute__((__noreturn__)) +# elif defined(_MSC_VER) && (_MSC_VER >= 1300) +# define CV_NORETURN __declspec(noreturn) +# else +# define CV_NORETURN /* nothing by default */ +# endif +#endif + + +/****************************************************************************************\ +* CV_NODISCARD attribute * +* encourages the compiler to issue a warning if the return value is discarded (C++17) * +\****************************************************************************************/ +#ifndef CV_NODISCARD +# if defined(__GNUC__) +# define CV_NODISCARD __attribute__((__warn_unused_result__)) // at least available with GCC 3.4 +# elif defined(__clang__) && defined(__has_attribute) +# if __has_attribute(__warn_unused_result__) +# define CV_NODISCARD __attribute__((__warn_unused_result__)) +# endif +# endif +#endif +#ifndef CV_NODISCARD +# define CV_NODISCARD /* nothing by default */ +#endif + + +/****************************************************************************************\ +* C++ 11 * +\****************************************************************************************/ +#ifndef CV_CXX11 +# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) +# define CV_CXX11 1 +# endif +#else +# if CV_CXX11 == 0 +# undef CV_CXX11 +# endif +#endif +#ifndef CV_CXX11 +# error "OpenCV 4.x+ requires enabled C++11 support" +#endif + +#define CV_CXX_MOVE_SEMANTICS 1 +#define CV_CXX_MOVE(x) std::move(x) +#define CV_CXX_STD_ARRAY 1 +#include +#ifndef CV_OVERRIDE +# define CV_OVERRIDE override +#endif +#ifndef CV_FINAL +# define CV_FINAL final +#endif + +#ifndef CV_NOEXCEPT +# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) +# define CV_NOEXCEPT noexcept +# endif +#endif +#ifndef CV_NOEXCEPT +# define CV_NOEXCEPT +#endif + +#ifndef CV_CONSTEXPR +# if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) +# define CV_CONSTEXPR constexpr +# endif +#endif +#ifndef CV_CONSTEXPR +# define CV_CONSTEXPR +#endif + +// Integer types portatibility +#ifdef OPENCV_STDINT_HEADER +#include OPENCV_STDINT_HEADER +#elif defined(__cplusplus) +#if defined(_MSC_VER) && _MSC_VER < 1600 /* MSVS 2010 */ +namespace cv { +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed __int64 int64_t; +typedef unsigned __int64 uint64_t; +} +#elif defined(_MSC_VER) || __cplusplus >= 201103L +#include +namespace cv { +using std::int8_t; +using std::uint8_t; +using std::int16_t; +using std::uint16_t; +using std::int32_t; +using std::uint32_t; +using std::int64_t; +using std::uint64_t; +} +#else +#include +namespace cv { +typedef ::int8_t int8_t; +typedef ::uint8_t uint8_t; +typedef ::int16_t int16_t; +typedef ::uint16_t uint16_t; +typedef ::int32_t int32_t; +typedef ::uint32_t uint32_t; +typedef ::int64_t int64_t; +typedef ::uint64_t uint64_t; +} +#endif +#else // pure C +#include +#endif + +#ifdef __cplusplus +namespace cv +{ + +class float16_t +{ +public: +#if CV_FP16_TYPE + + float16_t() : h(0) {} + explicit float16_t(float x) { h = (__fp16)x; } + operator float() const { return (float)h; } + static float16_t fromBits(ushort w) + { + Cv16suf u; + u.u = w; + float16_t result; + result.h = u.h; + return result; + } + static float16_t zero() + { + float16_t result; + result.h = (__fp16)0; + return result; + } + ushort bits() const + { + Cv16suf u; + u.h = h; + return u.u; + } +protected: + __fp16 h; + +#else + float16_t() : w(0) {} + explicit float16_t(float x) + { + #if CV_AVX2 + __m128 v = _mm_load_ss(&x); + w = (ushort)_mm_cvtsi128_si32(_mm_cvtps_ph(v, 0)); + #else + Cv32suf in; + in.f = x; + unsigned sign = in.u & 0x80000000; + in.u ^= sign; + + if( in.u >= 0x47800000 ) + w = (ushort)(in.u > 0x7f800000 ? 0x7e00 : 0x7c00); + else + { + if (in.u < 0x38800000) + { + in.f += 0.5f; + w = (ushort)(in.u - 0x3f000000); + } + else + { + unsigned t = in.u + 0xc8000fff; + w = (ushort)((t + ((in.u >> 13) & 1)) >> 13); + } + } + + w = (ushort)(w | (sign >> 16)); + #endif + } + + operator float() const + { + #if CV_AVX2 + float f; + _mm_store_ss(&f, _mm_cvtph_ps(_mm_cvtsi32_si128(w))); + return f; + #else + Cv32suf out; + + unsigned t = ((w & 0x7fff) << 13) + 0x38000000; + unsigned sign = (w & 0x8000) << 16; + unsigned e = w & 0x7c00; + + out.u = t + (1 << 23); + out.u = (e >= 0x7c00 ? t + 0x38000000 : + e == 0 ? (static_cast(out.f -= 6.103515625e-05f), out.u) : t) | sign; + return out.f; + #endif + } + + static float16_t fromBits(ushort b) + { + float16_t result; + result.w = b; + return result; + } + static float16_t zero() + { + float16_t result; + result.w = (ushort)0; + return result; + } + ushort bits() const { return w; } +protected: + ushort w; + +#endif +}; + +} +#endif + +//! @} + +#ifndef __cplusplus +#include "opencv2/core/fast_math.hpp" // define cvRound(double) +#endif + +#endif // OPENCV_CORE_CVDEF_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6ce9e4b06024c066d1d72d033406a69c2c014fa3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd.hpp @@ -0,0 +1,190 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_CVSTD_HPP +#define OPENCV_CORE_CVSTD_HPP + +#ifndef __cplusplus +# error cvstd.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" +#include +#include +#include + +#include + +// import useful primitives from stl +# include +# include +# include //for abs(int) +# include + +namespace cv +{ + static inline uchar abs(uchar a) { return a; } + static inline ushort abs(ushort a) { return a; } + static inline unsigned abs(unsigned a) { return a; } + static inline uint64 abs(uint64 a) { return a; } + + using std::min; + using std::max; + using std::abs; + using std::swap; + using std::sqrt; + using std::exp; + using std::pow; + using std::log; +} + +#include "cvstd_wrapper.hpp" + +namespace cv { + +//! @addtogroup core_utils +//! @{ + +//////////////////////////// memory management functions //////////////////////////// + +/** @brief Allocates an aligned memory buffer. + +The function allocates the buffer of the specified size and returns it. When the buffer size is 16 +bytes or more, the returned buffer is aligned to 16 bytes. +@param bufSize Allocated buffer size. + */ +CV_EXPORTS void* fastMalloc(size_t bufSize); + +/** @brief Deallocates a memory buffer. + +The function deallocates the buffer allocated with fastMalloc . If NULL pointer is passed, the +function does nothing. C version of the function clears the pointer *pptr* to avoid problems with +double memory deallocation. +@param ptr Pointer to the allocated buffer. + */ +CV_EXPORTS void fastFree(void* ptr); + +/*! + The STL-compliant memory Allocator based on cv::fastMalloc() and cv::fastFree() +*/ +template class Allocator +{ +public: + typedef _Tp value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + template class rebind { typedef Allocator other; }; + + explicit Allocator() {} + ~Allocator() {} + explicit Allocator(Allocator const&) {} + template + explicit Allocator(Allocator const&) {} + + // address + pointer address(reference r) { return &r; } + const_pointer address(const_reference r) { return &r; } + + pointer allocate(size_type count, const void* =0) { return reinterpret_cast(fastMalloc(count * sizeof (_Tp))); } + void deallocate(pointer p, size_type) { fastFree(p); } + + void construct(pointer p, const _Tp& v) { new(static_cast(p)) _Tp(v); } + void destroy(pointer p) { p->~_Tp(); } + + size_type max_size() const { return cv::max(static_cast<_Tp>(-1)/sizeof(_Tp), 1); } +}; + +//! @} core_utils + +//! @endcond + +//! @addtogroup core_basic +//! @{ + +//////////////////////////////// string class //////////////////////////////// + +class CV_EXPORTS FileNode; //for string constructor from FileNode + +typedef std::string String; + +#ifndef OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS + +//! @cond IGNORED +namespace details { +// std::tolower is int->int +static inline char char_tolower(char ch) +{ + return (char)std::tolower((int)ch); +} +// std::toupper is int->int +static inline char char_toupper(char ch) +{ + return (char)std::toupper((int)ch); +} +} // namespace details +//! @endcond + +static inline std::string toLowerCase(const std::string& str) +{ + std::string result(str); + std::transform(result.begin(), result.end(), result.begin(), details::char_tolower); + return result; +} + +static inline std::string toUpperCase(const std::string& str) +{ + std::string result(str); + std::transform(result.begin(), result.end(), result.begin(), details::char_toupper); + return result; +} + +#endif // OPENCV_DISABLE_STRING_LOWER_UPPER_CONVERSIONS + +//! @} core_basic +} // cv + +#endif //OPENCV_CORE_CVSTD_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd.inl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd.inl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4a85bfd06274844be8af320720ee9d3d4bdaa778 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd.inl.hpp @@ -0,0 +1,196 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_CVSTDINL_HPP +#define OPENCV_CORE_CVSTDINL_HPP + +#include +#include + +//! @cond IGNORED + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4127 ) +#endif + +namespace cv +{ + +template class DataType< std::complex<_Tp> > +{ +public: + typedef std::complex<_Tp> value_type; + typedef value_type work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + depth = DataType::depth, + channels = 2, + fmt = DataType::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) }; + + typedef Vec vec_type; +}; + +static inline +std::ostream& operator << (std::ostream& out, Ptr fmtd) +{ + fmtd->reset(); + for(const char* str = fmtd->next(); str; str = fmtd->next()) + out << str; + return out; +} + +static inline +std::ostream& operator << (std::ostream& out, const Mat& mtx) +{ + return out << Formatter::get()->format(mtx); +} + +static inline +std::ostream& operator << (std::ostream& out, const UMat& m) +{ + return out << m.getMat(ACCESS_READ); +} + +template static inline +std::ostream& operator << (std::ostream& out, const Complex<_Tp>& c) +{ + return out << "(" << c.re << "," << c.im << ")"; +} + +template static inline +std::ostream& operator << (std::ostream& out, const std::vector >& vec) +{ + return out << Formatter::get()->format(Mat(vec)); +} + + +template static inline +std::ostream& operator << (std::ostream& out, const std::vector >& vec) +{ + return out << Formatter::get()->format(Mat(vec)); +} + + +template static inline +std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx) +{ + return out << Formatter::get()->format(Mat(matx)); +} + +template static inline +std::ostream& operator << (std::ostream& out, const Point_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << "]"; + return out; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Point3_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << ", " << p.z << "]"; + return out; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec) +{ + out << "["; + if (cv::traits::Depth<_Tp>::value <= CV_32S) + { + for (int i = 0; i < n - 1; ++i) { + out << (int)vec[i] << ", "; + } + out << (int)vec[n-1] << "]"; + } + else + { + for (int i = 0; i < n - 1; ++i) { + out << vec[i] << ", "; + } + out << vec[n-1] << "]"; + } + + return out; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Size_<_Tp>& size) +{ + return out << "[" << size.width << " x " << size.height << "]"; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect) +{ + return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; +} + +static inline std::ostream& operator << (std::ostream& out, const MatSize& msize) +{ + int i, dims = msize.dims(); + for( i = 0; i < dims; i++ ) + { + out << msize[i]; + if( i < dims-1 ) + out << " x "; + } + return out; +} + +static inline std::ostream &operator<< (std::ostream &s, cv::Range &r) +{ + return s << "[" << r.start << " : " << r.end << ")"; +} + +} // cv + +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + +//! @endcond + +#endif // OPENCV_CORE_CVSTDINL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd_wrapper.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd_wrapper.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e2c2ea507637941d75beb3c73e1d6e8495fdb89e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/cvstd_wrapper.hpp @@ -0,0 +1,154 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_CVSTD_WRAPPER_HPP +#define OPENCV_CORE_CVSTD_WRAPPER_HPP + +#include "opencv2/core/cvdef.h" + +#include +#include // std::shared_ptr +#include // std::enable_if + +namespace cv { + +using std::nullptr_t; + +//! @addtogroup core_basic +//! @{ + +#ifdef CV_DOXYGEN + +template using Ptr = std::shared_ptr<_Tp>; // In ideal world it should look like this, but we need some compatibility workarounds below + +template static inline +Ptr<_Tp> makePtr(const A1&... a1) { return std::make_shared<_Tp>(a1...); } + +#else // cv::Ptr with compatibility workarounds + +// It should be defined for C-API types only. +// C++ types should use regular "delete" operator. +template struct DefaultDeleter; +#if 0 +{ + void operator()(Y* p) const; +}; +#endif + +namespace sfinae { +template +struct has_parenthesis_operator +{ +private: + template + static CV_CONSTEXPR std::true_type check(typename std::is_same().operator()(std::declval()...))>::type, Ret>::type*); + + template static CV_CONSTEXPR std::false_type check(...); + + typedef decltype(check(0)) type; + +public: +#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) + static CV_CONSTEXPR bool value = type::value; +#else + // support MSVS 2013 + static const int value = type::value; +#endif +}; +} // namespace sfinae + +template +struct has_custom_delete + : public std::false_type {}; + +// Force has_custom_delete to std::false_type when NVCC is compiling CUDA source files +#ifndef __CUDACC__ +template +struct has_custom_delete, void, T*>::value >::type > + : public std::true_type {}; +#endif + +template +struct Ptr : public std::shared_ptr +{ +#if 0 + using std::shared_ptr::shared_ptr; // GCC 5.x can't handle this +#else + inline Ptr() CV_NOEXCEPT : std::shared_ptr() {} + inline Ptr(nullptr_t) CV_NOEXCEPT : std::shared_ptr(nullptr) {} + template inline Ptr(Y* p, D d) : std::shared_ptr(p, d) {} + template inline Ptr(nullptr_t, D d) : std::shared_ptr(nullptr, d) {} + + template inline Ptr(const Ptr& r, T* ptr) CV_NOEXCEPT : std::shared_ptr(r, ptr) {} + + inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} + + template inline Ptr(const Ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + template inline Ptr(Ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} +#endif + inline Ptr(const std::shared_ptr& o) CV_NOEXCEPT : std::shared_ptr(o) {} + inline Ptr(std::shared_ptr&& o) CV_NOEXCEPT : std::shared_ptr(std::move(o)) {} + + // Overload with custom DefaultDeleter: Ptr(...) + template + inline Ptr(const std::true_type&, Y* ptr) : std::shared_ptr(ptr, DefaultDeleter()) {} + + // Overload without custom deleter: Ptr(...); + template + inline Ptr(const std::false_type&, Y* ptr) : std::shared_ptr(ptr) {} + + template + inline Ptr(Y* ptr) : Ptr(has_custom_delete(), ptr) {} + + // Overload with custom DefaultDeleter: Ptr(...) + template + inline void reset(const std::true_type&, Y* ptr) { std::shared_ptr::reset(ptr, DefaultDeleter()); } + + // Overload without custom deleter: Ptr(...); + template + inline void reset(const std::false_type&, Y* ptr) { std::shared_ptr::reset(ptr); } + + template + inline void reset(Y* ptr) { Ptr::reset(has_custom_delete(), ptr); } + + template + void reset(Y* ptr, Deleter d) { std::shared_ptr::reset(ptr, d); } + + void reset() CV_NOEXCEPT { std::shared_ptr::reset(); } + + Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } + template inline Ptr& operator=(const Ptr& o) { std::shared_ptr::operator =(o); return *this; } + + T* operator->() const CV_NOEXCEPT { return std::shared_ptr::get();} + typename std::add_lvalue_reference::type operator*() const CV_NOEXCEPT { return *std::shared_ptr::get(); } + + // OpenCV 3.x methods (not a part of standard C++ library) + inline void release() { std::shared_ptr::reset(); } + inline operator T* () const { return std::shared_ptr::get(); } + inline bool empty() const { return std::shared_ptr::get() == nullptr; } + + template inline + Ptr staticCast() const CV_NOEXCEPT { return std::static_pointer_cast(*this); } + + template inline + Ptr constCast() const CV_NOEXCEPT { return std::const_pointer_cast(*this); } + + template inline + Ptr dynamicCast() const CV_NOEXCEPT { return std::dynamic_pointer_cast(*this); } +}; + +template static inline +Ptr<_Tp> makePtr(const A1&... a1) +{ + static_assert( !has_custom_delete<_Tp>::value, "Can't use this makePtr with custom DefaultDeleter"); + return (Ptr<_Tp>)std::make_shared<_Tp>(a1...); +} + +#endif // CV_DOXYGEN + +//! @} core_basic +} // cv + +#endif //OPENCV_CORE_CVSTD_WRAPPER_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/detail/async_promise.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/detail/async_promise.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6eb3fb52c1a10d1fe74932462e0659fb02ac5da8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/detail/async_promise.hpp @@ -0,0 +1,71 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_ASYNC_PROMISE_HPP +#define OPENCV_CORE_ASYNC_PROMISE_HPP + +#include "../async.hpp" + +#include "exception_ptr.hpp" + +namespace cv { + +/** @addtogroup core_async +@{ +*/ + + +/** @brief Provides result of asynchronous operations + +*/ +class CV_EXPORTS AsyncPromise +{ +public: + ~AsyncPromise() CV_NOEXCEPT; + AsyncPromise() CV_NOEXCEPT; + explicit AsyncPromise(const AsyncPromise& o) CV_NOEXCEPT; + AsyncPromise& operator=(const AsyncPromise& o) CV_NOEXCEPT; + void release() CV_NOEXCEPT; + + /** Returns associated AsyncArray + @note Can be called once + */ + AsyncArray getArrayResult(); + + /** Stores asynchronous result. + @param[in] value result + */ + void setValue(InputArray value); + + // TODO "move" setters + +#if CV__EXCEPTION_PTR + /** Stores exception. + @param[in] exception exception to be raised in AsyncArray + */ + void setException(std::exception_ptr exception); +#endif + + /** Stores exception. + @param[in] exception exception to be raised in AsyncArray + */ + void setException(const cv::Exception& exception); + +#ifdef CV_CXX11 + explicit AsyncPromise(AsyncPromise&& o) { p = o.p; o.p = NULL; } + AsyncPromise& operator=(AsyncPromise&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; } +#endif + + + // PImpl + typedef struct AsyncArray::Impl Impl; friend struct AsyncArray::Impl; + inline void* _getImpl() const CV_NOEXCEPT { return p; } +protected: + Impl* p; +}; + + +//! @} +} // namespace +#endif // OPENCV_CORE_ASYNC_PROMISE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/detail/exception_ptr.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/detail/exception_ptr.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d98ffc40c63ccd6bfa4002c47b76200c2cb5ee8e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/detail/exception_ptr.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_DETAILS_EXCEPTION_PTR_H +#define OPENCV_CORE_DETAILS_EXCEPTION_PTR_H + +#ifndef CV__EXCEPTION_PTR +# if defined(__ANDROID__) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE < 2 +# define CV__EXCEPTION_PTR 0 // Not supported, details: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58938 +# elif defined(CV_CXX11) +# define CV__EXCEPTION_PTR 1 +# elif defined(_MSC_VER) +# define CV__EXCEPTION_PTR (_MSC_VER >= 1600) +# elif defined(__clang__) +# define CV__EXCEPTION_PTR 0 // C++11 only (see above) +# elif defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) +# define CV__EXCEPTION_PTR (__GXX_EXPERIMENTAL_CXX0X__ > 0) +# endif +#endif +#ifndef CV__EXCEPTION_PTR +# define CV__EXCEPTION_PTR 0 +#elif CV__EXCEPTION_PTR +# include // std::exception_ptr +#endif + +#endif // OPENCV_CORE_DETAILS_EXCEPTION_PTR_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/directx.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/directx.hpp new file mode 100644 index 0000000000000000000000000000000000000000..056a85a1bc996f1483b681273887fc25840f7251 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/directx.hpp @@ -0,0 +1,184 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors as is and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the copyright holders or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_DIRECTX_HPP +#define OPENCV_CORE_DIRECTX_HPP + +#include "mat.hpp" +#include "ocl.hpp" + +#if !defined(__d3d11_h__) +struct ID3D11Device; +struct ID3D11Texture2D; +#endif + +#if !defined(__d3d10_h__) +struct ID3D10Device; +struct ID3D10Texture2D; +#endif + +#if !defined(_D3D9_H_) +struct IDirect3DDevice9; +struct IDirect3DDevice9Ex; +struct IDirect3DSurface9; +#endif + + +namespace cv { namespace directx { + +namespace ocl { +using namespace cv::ocl; + +//! @addtogroup core_directx +// This section describes OpenCL and DirectX interoperability. +// +// To enable DirectX support, configure OpenCV using CMake with WITH_DIRECTX=ON . Note, DirectX is +// supported only on Windows. +// +// To use OpenCL functionality you should first initialize OpenCL context from DirectX resource. +// +//! @{ + +// TODO static functions in the Context class +//! @brief Creates OpenCL context from D3D11 device +// +//! @param pD3D11Device - pointer to D3D11 device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device); + +//! @brief Creates OpenCL context from D3D10 device +// +//! @param pD3D10Device - pointer to D3D10 device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device); + +//! @brief Creates OpenCL context from Direct3DDevice9Ex device +// +//! @param pDirect3DDevice9Ex - pointer to Direct3DDevice9Ex device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex); + +//! @brief Creates OpenCL context from Direct3DDevice9 device +// +//! @param pDirect3DDevice9 - pointer to Direct3Device9 device +//! @return Returns reference to OpenCL Context +CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9); + +//! @} + +} // namespace cv::directx::ocl + +//! @addtogroup core_directx +//! @{ + +//! @brief Converts InputArray to ID3D11Texture2D. If destination texture format is DXGI_FORMAT_NV12 then +//! input UMat expected to be in BGR format and data will be downsampled and color-converted to NV12. +// +//! @note Note: Destination texture must be allocated by application. Function does memory copy from src to +//! pD3D11Texture2D +// +//! @param src - source InputArray +//! @param pD3D11Texture2D - destination D3D11 texture +CV_EXPORTS void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D); + +//! @brief Converts ID3D11Texture2D to OutputArray. If input texture format is DXGI_FORMAT_NV12 then +//! data will be upsampled and color-converted to BGR format. +// +//! @note Note: Destination matrix will be re-allocated if it has not enough memory to match texture size. +//! function does memory copy from pD3D11Texture2D to dst +// +//! @param pD3D11Texture2D - source D3D11 texture +//! @param dst - destination OutputArray +CV_EXPORTS void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst); + +//! @brief Converts InputArray to ID3D10Texture2D +// +//! @note Note: function does memory copy from src to +//! pD3D10Texture2D +// +//! @param src - source InputArray +//! @param pD3D10Texture2D - destination D3D10 texture +CV_EXPORTS void convertToD3D10Texture2D(InputArray src, ID3D10Texture2D* pD3D10Texture2D); + +//! @brief Converts ID3D10Texture2D to OutputArray +// +//! @note Note: function does memory copy from pD3D10Texture2D +//! to dst +// +//! @param pD3D10Texture2D - source D3D10 texture +//! @param dst - destination OutputArray +CV_EXPORTS void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst); + +//! @brief Converts InputArray to IDirect3DSurface9 +// +//! @note Note: function does memory copy from src to +//! pDirect3DSurface9 +// +//! @param src - source InputArray +//! @param pDirect3DSurface9 - destination D3D10 texture +//! @param surfaceSharedHandle - shared handle +CV_EXPORTS void convertToDirect3DSurface9(InputArray src, IDirect3DSurface9* pDirect3DSurface9, void* surfaceSharedHandle = NULL); + +//! @brief Converts IDirect3DSurface9 to OutputArray +// +//! @note Note: function does memory copy from pDirect3DSurface9 +//! to dst +// +//! @param pDirect3DSurface9 - source D3D10 texture +//! @param dst - destination OutputArray +//! @param surfaceSharedHandle - shared handle +CV_EXPORTS void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArray dst, void* surfaceSharedHandle = NULL); + +//! @brief Get OpenCV type from DirectX type +//! @param iDXGI_FORMAT - enum DXGI_FORMAT for D3D10/D3D11 +//! @return OpenCV type or -1 if there is no equivalent +CV_EXPORTS int getTypeFromDXGI_FORMAT(const int iDXGI_FORMAT); // enum DXGI_FORMAT for D3D10/D3D11 + +//! @brief Get OpenCV type from DirectX type +//! @param iD3DFORMAT - enum D3DTYPE for D3D9 +//! @return OpenCV type or -1 if there is no equivalent +CV_EXPORTS int getTypeFromD3DFORMAT(const int iD3DFORMAT); // enum D3DTYPE for D3D9 + +//! @} + +} } // namespace cv::directx + +#endif // OPENCV_CORE_DIRECTX_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/eigen.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/eigen.hpp new file mode 100644 index 0000000000000000000000000000000000000000..741648edb8fb12e6597d75691fd0019f07ded093 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/eigen.hpp @@ -0,0 +1,280 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + + +#ifndef OPENCV_CORE_EIGEN_HPP +#define OPENCV_CORE_EIGEN_HPP + +#include "opencv2/core.hpp" + +#if defined _MSC_VER && _MSC_VER >= 1200 +#pragma warning( disable: 4714 ) //__forceinline is not inlined +#pragma warning( disable: 4127 ) //conditional expression is constant +#pragma warning( disable: 4244 ) //conversion from '__int64' to 'int', possible loss of data +#endif + +namespace cv +{ + +//! @addtogroup core_eigen +//! @{ + +template static inline +void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, OutputArray dst ) +{ + if( !(src.Flags & Eigen::RowMajorBit) ) + { + Mat _src(src.cols(), src.rows(), traits::Type<_Tp>::value, + (void*)src.data(), src.outerStride()*sizeof(_Tp)); + transpose(_src, dst); + } + else + { + Mat _src(src.rows(), src.cols(), traits::Type<_Tp>::value, + (void*)src.data(), src.outerStride()*sizeof(_Tp)); + _src.copyTo(dst); + } +} + +// Matx case +template static inline +void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, + Matx<_Tp, _rows, _cols>& dst ) +{ + if( !(src.Flags & Eigen::RowMajorBit) ) + { + dst = Matx<_Tp, _cols, _rows>(static_cast(src.data())).t(); + } + else + { + dst = Matx<_Tp, _rows, _cols>(static_cast(src.data())); + } +} + +template static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) +{ + CV_DbgAssert(src.rows == _rows && src.cols == _cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else if( src.cols == src.rows ) + { + src.convertTo(_dst, _dst.type()); + transpose(_dst, _dst); + } + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +// Matx case +template static inline +void cv2eigen( const Matx<_Tp, _rows, _cols>& src, + Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) +{ + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + Mat(src).copyTo(_dst); + } +} + +template static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst ) +{ + dst.resize(src.rows, src.cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else if( src.cols == src.rows ) + { + src.convertTo(_dst, _dst.type()); + transpose(_dst, _dst); + } + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +// Matx case +template static inline +void cv2eigen( const Matx<_Tp, _rows, _cols>& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst ) +{ + dst.resize(_rows, _cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + Mat(src).copyTo(_dst); + } +} + +template static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst ) +{ + CV_Assert(src.cols == 1); + dst.resize(src.rows); + + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +// Matx case +template static inline +void cv2eigen( const Matx<_Tp, _rows, 1>& src, + Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst ) +{ + dst.resize(_rows); + + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(1, _rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(_rows, 1, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.copyTo(_dst); + } +} + + +template static inline +void cv2eigen( const Mat& src, + Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst ) +{ + CV_Assert(src.rows == 1); + dst.resize(src.cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + if( src.type() == _dst.type() ) + transpose(src, _dst); + else + Mat(src.t()).convertTo(_dst, _dst.type()); + } + else + { + const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + src.convertTo(_dst, _dst.type()); + } +} + +//Matx +template static inline +void cv2eigen( const Matx<_Tp, 1, _cols>& src, + Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst ) +{ + dst.resize(_cols); + if( !(dst.Flags & Eigen::RowMajorBit) ) + { + const Mat _dst(_cols, 1, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + transpose(src, _dst); + } + else + { + const Mat _dst(1, _cols, traits::Type<_Tp>::value, + dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp))); + Mat(src).copyTo(_dst); + } +} + +//! @} + +} // cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/fast_math.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/fast_math.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0f53cf5c1b909f14b085a22961b80894a86e8e7b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/fast_math.hpp @@ -0,0 +1,408 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_FAST_MATH_HPP +#define OPENCV_CORE_FAST_MATH_HPP + +#include "opencv2/core/cvdef.h" + +//! @addtogroup core_utils +//! @{ + +/****************************************************************************************\ +* fast math * +\****************************************************************************************/ + +#ifdef __cplusplus +# include +#else +# ifdef __BORLANDC__ +# include +# else +# include +# endif +#endif + +#if defined(__CUDACC__) + // nothing, intrinsics/asm code is not supported +#else + #if ((defined _MSC_VER && defined _M_X64) \ + || (defined __GNUC__ && defined __x86_64__ && defined __SSE2__)) \ + && !defined(OPENCV_SKIP_INCLUDE_EMMINTRIN_H) + #include + #endif + + #if defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 \ + && !defined(OPENCV_SKIP_INCLUDE_ALTIVEC_H) + #include + #endif + + #if defined(CV_INLINE_ROUND_FLT) + // user-specified version + // CV_INLINE_ROUND_DBL should be defined too + #elif defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__ + // 1. general scheme + #define ARM_ROUND(_value, _asm_string) \ + int res; \ + float temp; \ + CV_UNUSED(temp); \ + __asm__(_asm_string : [res] "=r" (res), [temp] "=w" (temp) : [value] "w" (_value)); \ + return res + // 2. version for double + #ifdef __clang__ + #define CV_INLINE_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %[value] \n vmov %[res], %[temp]") + #else + #define CV_INLINE_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %P[value] \n vmov %[res], %[temp]") + #endif + // 3. version for float + #define CV_INLINE_ROUND_FLT(value) ARM_ROUND(value, "vcvtr.s32.f32 %[temp], %[value]\n vmov %[res], %[temp]") + #elif defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 + // P8 and newer machines can convert fp32/64 to int quickly. + #define CV_INLINE_ROUND_DBL(value) \ + int out; \ + double temp; \ + __asm__( "fctiw %[temp],%[in]\n\tmfvsrwz %[out],%[temp]\n\t" : [out] "=r" (out), [temp] "=d" (temp) : [in] "d" ((double)(value)) : ); \ + return out; + + // FP32 also works with FP64 routine above + #define CV_INLINE_ROUND_FLT(value) CV_INLINE_ROUND_DBL(value) + #endif + + #ifdef CV_INLINE_ISINF_FLT + // user-specified version + // CV_INLINE_ISINF_DBL should be defined too + #elif defined __PPC64__ && defined _ARCH_PWR9 && defined(scalar_test_data_class) + #define CV_INLINE_ISINF_DBL(value) return scalar_test_data_class(value, 0x30); + #define CV_INLINE_ISINF_FLT(value) CV_INLINE_ISINF_DBL(value) + #endif + + #ifdef CV_INLINE_ISNAN_FLT + // user-specified version + // CV_INLINE_ISNAN_DBL should be defined too + #elif defined __PPC64__ && defined _ARCH_PWR9 && defined(scalar_test_data_class) + #define CV_INLINE_ISNAN_DBL(value) return scalar_test_data_class(value, 0x40); + #define CV_INLINE_ISNAN_FLT(value) CV_INLINE_ISNAN_DBL(value) + #endif + + #if !defined(OPENCV_USE_FASTMATH_BUILTINS) \ + && ( \ + defined(__x86_64__) || defined(__i686__) \ + || defined(__arm__) \ + || defined(__PPC64__) \ + ) + /* Let builtin C math functions when available. Dedicated hardware is available to + round and convert FP values. */ + #define OPENCV_USE_FASTMATH_BUILTINS 1 + #endif + + /* Enable builtin math functions if possible, desired, and available. + Note, not all math functions inline equally. E.g lrint will not inline + without the -fno-math-errno option. */ + #if defined(CV_ICC) + // nothing + #elif defined(OPENCV_USE_FASTMATH_BUILTINS) && OPENCV_USE_FASTMATH_BUILTINS + #if defined(__clang__) + #define CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS + #if !defined(CV_INLINE_ISNAN_DBL) && __has_builtin(__builtin_isnan) + #define CV_INLINE_ISNAN_DBL(value) return __builtin_isnan(value); + #endif + #if !defined(CV_INLINE_ISNAN_FLT) && __has_builtin(__builtin_isnan) + #define CV_INLINE_ISNAN_FLT(value) return __builtin_isnan(value); + #endif + #if !defined(CV_INLINE_ISINF_DBL) && __has_builtin(__builtin_isinf) + #define CV_INLINE_ISINF_DBL(value) return __builtin_isinf(value); + #endif + #if !defined(CV_INLINE_ISINF_FLT) && __has_builtin(__builtin_isinf) + #define CV_INLINE_ISINF_FLT(value) return __builtin_isinf(value); + #endif + #elif defined(__GNUC__) + #define CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS + #if !defined(CV_INLINE_ISNAN_DBL) + #define CV_INLINE_ISNAN_DBL(value) return __builtin_isnan(value); + #endif + #if !defined(CV_INLINE_ISNAN_FLT) + #define CV_INLINE_ISNAN_FLT(value) return __builtin_isnanf(value); + #endif + #if !defined(CV_INLINE_ISINF_DBL) + #define CV_INLINE_ISINF_DBL(value) return __builtin_isinf(value); + #endif + #if !defined(CV_INLINE_ISINF_FLT) + #define CV_INLINE_ISINF_FLT(value) return __builtin_isinff(value); + #endif + #elif defined(_MSC_VER) + #if !defined(CV_INLINE_ISNAN_DBL) + #define CV_INLINE_ISNAN_DBL(value) return isnan(value); + #endif + #if !defined(CV_INLINE_ISNAN_FLT) + #define CV_INLINE_ISNAN_FLT(value) return isnan(value); + #endif + #if !defined(CV_INLINE_ISINF_DBL) + #define CV_INLINE_ISINF_DBL(value) return isinf(value); + #endif + #if !defined(CV_INLINE_ISINF_FLT) + #define CV_INLINE_ISINF_FLT(value) return isinf(value); + #endif + #endif + #endif + +#endif // defined(__CUDACC__) + +/** @brief Rounds floating-point number to the nearest integer + + @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the + result is not defined. + */ +CV_INLINE int +cvRound( double value ) +{ +#if defined CV_INLINE_ROUND_DBL + CV_INLINE_ROUND_DBL(value); +#elif ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) \ + && !defined(__CUDACC__) + __m128d t = _mm_set_sd( value ); + return _mm_cvtsd_si32(t); +#elif defined _MSC_VER && defined _M_IX86 + int t; + __asm + { + fld value; + fistp t; + } + return t; +#elif defined CV_ICC || defined __GNUC__ + return (int)(lrint(value)); +#else + /* it's ok if round does not comply with IEEE754 standard; + the tests should allow +/-1 difference when the tested functions use round */ + return (int)(value + (value >= 0 ? 0.5 : -0.5)); +#endif +} + + +/** @brief Rounds floating-point number to the nearest integer not larger than the original. + + The function computes an integer i such that: + \f[i \le \texttt{value} < i+1\f] + @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the + result is not defined. + */ +CV_INLINE int cvFloor( double value ) +{ +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) + return __builtin_floor(value); +#else + int i = (int)value; + return i - (i > value); +#endif +} + +/** @brief Rounds floating-point number to the nearest integer not smaller than the original. + + The function computes an integer i such that: + \f[i \le \texttt{value} < i+1\f] + @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the + result is not defined. + */ +CV_INLINE int cvCeil( double value ) +{ +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) + return __builtin_ceil(value); +#else + int i = (int)value; + return i + (i < value); +#endif +} + +/** @brief Determines if the argument is Not A Number. + + @param value The input floating-point value + + The function returns 1 if the argument is Not A Number (as defined by IEEE754 standard), 0 + otherwise. */ +CV_INLINE int cvIsNaN( double value ) +{ +#if defined CV_INLINE_ISNAN_DBL + CV_INLINE_ISNAN_DBL(value); +#else + Cv64suf ieee754; + ieee754.f = value; + return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) + + ((unsigned)ieee754.u != 0) > 0x7ff00000; +#endif +} + +/** @brief Determines if the argument is Infinity. + + @param value The input floating-point value + + The function returns 1 if the argument is a plus or minus infinity (as defined by IEEE754 standard) + and 0 otherwise. */ +CV_INLINE int cvIsInf( double value ) +{ +#if defined CV_INLINE_ISINF_DBL + CV_INLINE_ISINF_DBL(value); +#elif defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__PPC64__) + Cv64suf ieee754; + ieee754.f = value; + return (ieee754.u & 0x7fffffff00000000) == + 0x7ff0000000000000; +#else + Cv64suf ieee754; + ieee754.f = value; + return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 && + (unsigned)ieee754.u == 0; +#endif +} + +#ifdef __cplusplus + +/** @overload */ +CV_INLINE int cvRound(float value) +{ +#if defined CV_INLINE_ROUND_FLT + CV_INLINE_ROUND_FLT(value); +#elif ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) \ + && !defined(__CUDACC__) + __m128 t = _mm_set_ss( value ); + return _mm_cvtss_si32(t); +#elif defined _MSC_VER && defined _M_IX86 + int t; + __asm + { + fld value; + fistp t; + } + return t; +#elif defined CV_ICC || defined __GNUC__ + return (int)(lrintf(value)); +#else + /* it's ok if round does not comply with IEEE754 standard; + the tests should allow +/-1 difference when the tested functions use round */ + return (int)(value + (value >= 0 ? 0.5f : -0.5f)); +#endif +} + +/** @overload */ +CV_INLINE int cvRound( int value ) +{ + return value; +} + +/** @overload */ +CV_INLINE int cvFloor( float value ) +{ +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) + return __builtin_floorf(value); +#else + int i = (int)value; + return i - (i > value); +#endif +} + +/** @overload */ +CV_INLINE int cvFloor( int value ) +{ + return value; +} + +/** @overload */ +CV_INLINE int cvCeil( float value ) +{ +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) + return __builtin_ceilf(value); +#else + int i = (int)value; + return i + (i < value); +#endif +} + +/** @overload */ +CV_INLINE int cvCeil( int value ) +{ + return value; +} + +/** @overload */ +CV_INLINE int cvIsNaN( float value ) +{ +#if defined CV_INLINE_ISNAN_FLT + CV_INLINE_ISNAN_FLT(value); +#else + Cv32suf ieee754; + ieee754.f = value; + return (ieee754.u & 0x7fffffff) > 0x7f800000; +#endif +} + +/** @overload */ +CV_INLINE int cvIsInf( float value ) +{ +#if defined CV_INLINE_ISINF_FLT + CV_INLINE_ISINF_FLT(value); +#else + Cv32suf ieee754; + ieee754.f = value; + return (ieee754.u & 0x7fffffff) == 0x7f800000; +#endif +} + +#endif // __cplusplus + +//! @} core_utils + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/hal.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/hal.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0d68078d98d606904a7e67d1b1f51adb8fcb71f3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/hal.hpp @@ -0,0 +1,256 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_HPP +#define OPENCV_HAL_HPP + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/hal/interface.h" + +namespace cv { namespace hal { + +//! @addtogroup core_hal_functions +//! @{ + +CV_EXPORTS int normHamming(const uchar* a, int n); +CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n); + +CV_EXPORTS int normHamming(const uchar* a, int n, int cellSize); +CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize); + +CV_EXPORTS int LU32f(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS int LU64f(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky32f(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky64f(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS void SVD32f(float* At, size_t astep, float* W, float* U, size_t ustep, float* Vt, size_t vstep, int m, int n, int flags); +CV_EXPORTS void SVD64f(double* At, size_t astep, double* W, double* U, size_t ustep, double* Vt, size_t vstep, int m, int n, int flags); +CV_EXPORTS int QR32f(float* A, size_t astep, int m, int n, int k, float* b, size_t bstep, float* hFactors); +CV_EXPORTS int QR64f(double* A, size_t astep, int m, int n, int k, double* b, size_t bstep, double* hFactors); + +CV_EXPORTS void gemm32f(const float* src1, size_t src1_step, const float* src2, size_t src2_step, + float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm64f(const double* src1, size_t src1_step, const double* src2, size_t src2_step, + double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm32fc(const float* src1, size_t src1_step, const float* src2, size_t src2_step, + float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); +CV_EXPORTS void gemm64fc(const double* src1, size_t src1_step, const double* src2, size_t src2_step, + double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step, + int m_a, int n_a, int n_d, int flags); + +CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n); +CV_EXPORTS float normL1_(const float* a, const float* b, int n); +CV_EXPORTS float normL2Sqr_(const float* a, const float* b, int n); + +CV_EXPORTS void exp32f(const float* src, float* dst, int n); +CV_EXPORTS void exp64f(const double* src, double* dst, int n); +CV_EXPORTS void log32f(const float* src, float* dst, int n); +CV_EXPORTS void log64f(const double* src, double* dst, int n); + +CV_EXPORTS void fastAtan32f(const float* y, const float* x, float* dst, int n, bool angleInDegrees); +CV_EXPORTS void fastAtan64f(const double* y, const double* x, double* dst, int n, bool angleInDegrees); +CV_EXPORTS void magnitude32f(const float* x, const float* y, float* dst, int n); +CV_EXPORTS void magnitude64f(const double* x, const double* y, double* dst, int n); +CV_EXPORTS void sqrt32f(const float* src, float* dst, int len); +CV_EXPORTS void sqrt64f(const double* src, double* dst, int len); +CV_EXPORTS void invSqrt32f(const float* src, float* dst, int len); +CV_EXPORTS void invSqrt64f(const double* src, double* dst, int len); + +CV_EXPORTS void split8u(const uchar* src, uchar** dst, int len, int cn ); +CV_EXPORTS void split16u(const ushort* src, ushort** dst, int len, int cn ); +CV_EXPORTS void split32s(const int* src, int** dst, int len, int cn ); +CV_EXPORTS void split64s(const int64* src, int64** dst, int len, int cn ); + +CV_EXPORTS void merge8u(const uchar** src, uchar* dst, int len, int cn ); +CV_EXPORTS void merge16u(const ushort** src, ushort* dst, int len, int cn ); +CV_EXPORTS void merge32s(const int** src, int* dst, int len, int cn ); +CV_EXPORTS void merge64s(const int64** src, int64* dst, int len, int cn ); + +CV_EXPORTS void add8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void add64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void sub8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void sub64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void max8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void max64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void min8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void min64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void absdiff8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void absdiff64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void and8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void or8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void xor8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); +CV_EXPORTS void not8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* ); + +CV_EXPORTS void cmp8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp8s(const schar* src1, size_t step1, const schar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp16u(const ushort* src1, size_t step1, const ushort* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp16s(const short* src1, size_t step1, const short* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp32s(const int* src1, size_t step1, const int* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp32f(const float* src1, size_t step1, const float* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); +CV_EXPORTS void cmp64f(const double* src1, size_t step1, const double* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop); + +CV_EXPORTS void mul8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void mul64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); + +CV_EXPORTS void div8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void div64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); + +CV_EXPORTS void recip8u( const uchar *, size_t, const uchar * src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip8s( const schar *, size_t, const schar * src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip16u( const ushort *, size_t, const ushort * src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip16s( const short *, size_t, const short * src2, size_t step2, short* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip32s( const int *, size_t, const int * src2, size_t step2, int* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip32f( const float *, size_t, const float * src2, size_t step2, float* dst, size_t step, int width, int height, void* scale); +CV_EXPORTS void recip64f( const double *, size_t, const double * src2, size_t step2, double* dst, size_t step, int width, int height, void* scale); + +CV_EXPORTS void addWeighted8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _scalars ); +CV_EXPORTS void addWeighted8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scalars ); +CV_EXPORTS void addWeighted64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scalars ); + +CV_EXPORTS void cvt16f32f( const float16_t* src, float* dst, int len ); +CV_EXPORTS void cvt32f16f( const float* src, float16_t* dst, int len ); + +CV_EXPORTS void addRNGBias32f( float* arr, const float* scaleBiasPairs, int len ); +CV_EXPORTS void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len ); + +struct CV_EXPORTS DFT1D +{ + static Ptr create(int len, int count, int depth, int flags, bool * useBuffer = 0); + virtual void apply(const uchar *src, uchar *dst) = 0; + virtual ~DFT1D() {} +}; + +struct CV_EXPORTS DFT2D +{ + static Ptr create(int width, int height, int depth, + int src_channels, int dst_channels, + int flags, int nonzero_rows = 0); + virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0; + virtual ~DFT2D() {} +}; + +struct CV_EXPORTS DCT2D +{ + static Ptr create(int width, int height, int depth, int flags); + virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0; + virtual ~DCT2D() {} +}; + +//! @} core_hal + +//============================================================================= +// for binary compatibility with 3.0 + +//! @cond IGNORED + +CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n); +CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n); + +CV_EXPORTS void exp(const float* src, float* dst, int n); +CV_EXPORTS void exp(const double* src, double* dst, int n); +CV_EXPORTS void log(const float* src, float* dst, int n); +CV_EXPORTS void log(const double* src, double* dst, int n); + +CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees); +CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n); +CV_EXPORTS void magnitude(const double* x, const double* y, double* dst, int n); +CV_EXPORTS void sqrt(const float* src, float* dst, int len); +CV_EXPORTS void sqrt(const double* src, double* dst, int len); +CV_EXPORTS void invSqrt(const float* src, float* dst, int len); +CV_EXPORTS void invSqrt(const double* src, double* dst, int len); + +//! @endcond + +}} //cv::hal + +#endif //OPENCV_HAL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/interface.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/interface.h new file mode 100644 index 0000000000000000000000000000000000000000..6f0a83d35928bc035e1807f82a261c844beddc33 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/interface.h @@ -0,0 +1,190 @@ +#ifndef OPENCV_CORE_HAL_INTERFACE_H +#define OPENCV_CORE_HAL_INTERFACE_H + +//! @addtogroup core_hal_interface +//! @{ + +//! @name Return codes +//! @{ +#define CV_HAL_ERROR_OK 0 +#define CV_HAL_ERROR_NOT_IMPLEMENTED 1 +#define CV_HAL_ERROR_UNKNOWN -1 +//! @} + +#ifdef __cplusplus +#include +#else +#include +#include +#endif + +//! @name Data types +//! primitive types +//! - schar - signed 1 byte integer +//! - uchar - unsigned 1 byte integer +//! - short - signed 2 byte integer +//! - ushort - unsigned 2 byte integer +//! - int - signed 4 byte integer +//! - uint - unsigned 4 byte integer +//! - int64 - signed 8 byte integer +//! - uint64 - unsigned 8 byte integer +//! @{ +#if !defined _MSC_VER && !defined __BORLANDC__ +# if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__ +# include +# ifdef __NEWLIB__ + typedef unsigned int uint; +# else + typedef std::uint32_t uint; +# endif +# else +# include + typedef uint32_t uint; +# endif +#else + typedef unsigned uint; +#endif + +typedef signed char schar; + +#ifndef __IPL_H__ + typedef unsigned char uchar; + typedef unsigned short ushort; +#endif + +#if defined _MSC_VER || defined __BORLANDC__ + typedef __int64 int64; + typedef unsigned __int64 uint64; +# define CV_BIG_INT(n) n##I64 +# define CV_BIG_UINT(n) n##UI64 +#else + typedef int64_t int64; + typedef uint64_t uint64; +# define CV_BIG_INT(n) n##LL +# define CV_BIG_UINT(n) n##ULL +#endif + +#define CV_USRTYPE1 (void)"CV_USRTYPE1 support has been dropped in OpenCV 4.0" + +#define CV_CN_MAX 512 +#define CV_CN_SHIFT 3 +#define CV_DEPTH_MAX (1 << CV_CN_SHIFT) + +#define CV_8U 0 +#define CV_8S 1 +#define CV_16U 2 +#define CV_16S 3 +#define CV_32S 4 +#define CV_32F 5 +#define CV_64F 6 +#define CV_16F 7 + +#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) +#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) + +#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) +#define CV_MAKE_TYPE CV_MAKETYPE + +#define CV_8UC1 CV_MAKETYPE(CV_8U,1) +#define CV_8UC2 CV_MAKETYPE(CV_8U,2) +#define CV_8UC3 CV_MAKETYPE(CV_8U,3) +#define CV_8UC4 CV_MAKETYPE(CV_8U,4) +#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) + +#define CV_8SC1 CV_MAKETYPE(CV_8S,1) +#define CV_8SC2 CV_MAKETYPE(CV_8S,2) +#define CV_8SC3 CV_MAKETYPE(CV_8S,3) +#define CV_8SC4 CV_MAKETYPE(CV_8S,4) +#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) + +#define CV_16UC1 CV_MAKETYPE(CV_16U,1) +#define CV_16UC2 CV_MAKETYPE(CV_16U,2) +#define CV_16UC3 CV_MAKETYPE(CV_16U,3) +#define CV_16UC4 CV_MAKETYPE(CV_16U,4) +#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) + +#define CV_16SC1 CV_MAKETYPE(CV_16S,1) +#define CV_16SC2 CV_MAKETYPE(CV_16S,2) +#define CV_16SC3 CV_MAKETYPE(CV_16S,3) +#define CV_16SC4 CV_MAKETYPE(CV_16S,4) +#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) + +#define CV_32SC1 CV_MAKETYPE(CV_32S,1) +#define CV_32SC2 CV_MAKETYPE(CV_32S,2) +#define CV_32SC3 CV_MAKETYPE(CV_32S,3) +#define CV_32SC4 CV_MAKETYPE(CV_32S,4) +#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) + +#define CV_32FC1 CV_MAKETYPE(CV_32F,1) +#define CV_32FC2 CV_MAKETYPE(CV_32F,2) +#define CV_32FC3 CV_MAKETYPE(CV_32F,3) +#define CV_32FC4 CV_MAKETYPE(CV_32F,4) +#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) + +#define CV_64FC1 CV_MAKETYPE(CV_64F,1) +#define CV_64FC2 CV_MAKETYPE(CV_64F,2) +#define CV_64FC3 CV_MAKETYPE(CV_64F,3) +#define CV_64FC4 CV_MAKETYPE(CV_64F,4) +#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) + +#define CV_16FC1 CV_MAKETYPE(CV_16F,1) +#define CV_16FC2 CV_MAKETYPE(CV_16F,2) +#define CV_16FC3 CV_MAKETYPE(CV_16F,3) +#define CV_16FC4 CV_MAKETYPE(CV_16F,4) +#define CV_16FC(n) CV_MAKETYPE(CV_16F,(n)) +//! @} + +//! @name Comparison operation +//! @sa cv::CmpTypes +//! @{ +#define CV_HAL_CMP_EQ 0 +#define CV_HAL_CMP_GT 1 +#define CV_HAL_CMP_GE 2 +#define CV_HAL_CMP_LT 3 +#define CV_HAL_CMP_LE 4 +#define CV_HAL_CMP_NE 5 +//! @} + +//! @name Border processing modes +//! @sa cv::BorderTypes +//! @{ +#define CV_HAL_BORDER_CONSTANT 0 +#define CV_HAL_BORDER_REPLICATE 1 +#define CV_HAL_BORDER_REFLECT 2 +#define CV_HAL_BORDER_WRAP 3 +#define CV_HAL_BORDER_REFLECT_101 4 +#define CV_HAL_BORDER_TRANSPARENT 5 +#define CV_HAL_BORDER_ISOLATED 16 +//! @} + +//! @name DFT flags +//! @{ +#define CV_HAL_DFT_INVERSE 1 +#define CV_HAL_DFT_SCALE 2 +#define CV_HAL_DFT_ROWS 4 +#define CV_HAL_DFT_COMPLEX_OUTPUT 16 +#define CV_HAL_DFT_REAL_OUTPUT 32 +#define CV_HAL_DFT_TWO_STAGE 64 +#define CV_HAL_DFT_STAGE_COLS 128 +#define CV_HAL_DFT_IS_CONTINUOUS 512 +#define CV_HAL_DFT_IS_INPLACE 1024 +//! @} + +//! @name SVD flags +//! @{ +#define CV_HAL_SVD_NO_UV 1 +#define CV_HAL_SVD_SHORT_UV 2 +#define CV_HAL_SVD_MODIFY_A 4 +#define CV_HAL_SVD_FULL_UV 8 +//! @} + +//! @name Gemm flags +//! @{ +#define CV_HAL_GEMM_1_T 1 +#define CV_HAL_GEMM_2_T 2 +#define CV_HAL_GEMM_3_T 4 +//! @} + +//! @} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5a105a7a41872cf15991c00c9abfdc66ce9c18c5 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin.hpp @@ -0,0 +1,482 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_INTRIN_HPP +#define OPENCV_HAL_INTRIN_HPP + +#include +#include +#include +#include "opencv2/core/cvdef.h" + +#define OPENCV_HAL_ADD(a, b) ((a) + (b)) +#define OPENCV_HAL_AND(a, b) ((a) & (b)) +#define OPENCV_HAL_NOP(a) (a) +#define OPENCV_HAL_1ST(a, b) (a) + +namespace { +inline unsigned int trailingZeros32(unsigned int value) { +#if defined(_MSC_VER) +#if (_MSC_VER < 1700) || defined(_M_ARM) || defined(_M_ARM64) + unsigned long index = 0; + _BitScanForward(&index, value); + return (unsigned int)index; +#elif defined(__clang__) + // clang-cl doesn't export _tzcnt_u32 for non BMI systems + return value ? __builtin_ctz(value) : 32; +#else + return _tzcnt_u32(value); +#endif +#elif defined(__GNUC__) || defined(__GNUG__) + return __builtin_ctz(value); +#elif defined(__ICC) || defined(__INTEL_COMPILER) + return _bit_scan_forward(value); +#elif defined(__clang__) + return llvm.cttz.i32(value, true); +#else + static const int MultiplyDeBruijnBitPosition[32] = { + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, + 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; + return MultiplyDeBruijnBitPosition[((uint32_t)((value & -value) * 0x077CB531U)) >> 27]; +#endif +} +} + +// unlike HAL API, which is in cv::hal, +// we put intrinsics into cv namespace to make its +// access from within opencv code more accessible +namespace cv { + +namespace hal { + +enum StoreMode +{ + STORE_UNALIGNED = 0, + STORE_ALIGNED = 1, + STORE_ALIGNED_NOCACHE = 2 +}; + +} + +template struct V_TypeTraits +{ +}; + +#define CV_INTRIN_DEF_TYPE_TRAITS(type, int_type_, uint_type_, abs_type_, w_type_, q_type_, sum_type_, nlanes128_) \ + template<> struct V_TypeTraits \ + { \ + typedef type value_type; \ + typedef int_type_ int_type; \ + typedef abs_type_ abs_type; \ + typedef uint_type_ uint_type; \ + typedef w_type_ w_type; \ + typedef q_type_ q_type; \ + typedef sum_type_ sum_type; \ + enum { nlanes128 = nlanes128_ }; \ + \ + static inline int_type reinterpret_int(type x) \ + { \ + union { type l; int_type i; } v; \ + v.l = x; \ + return v.i; \ + } \ + \ + static inline type reinterpret_from_int(int_type x) \ + { \ + union { type l; int_type i; } v; \ + v.i = x; \ + return v.l; \ + } \ + } + +CV_INTRIN_DEF_TYPE_TRAITS(uchar, schar, uchar, uchar, ushort, unsigned, unsigned, 16); +CV_INTRIN_DEF_TYPE_TRAITS(schar, schar, uchar, uchar, short, int, int, 16); +CV_INTRIN_DEF_TYPE_TRAITS(ushort, short, ushort, ushort, unsigned, uint64, unsigned, 8); +CV_INTRIN_DEF_TYPE_TRAITS(short, short, ushort, ushort, int, int64, int, 8); +CV_INTRIN_DEF_TYPE_TRAITS(unsigned, int, unsigned, unsigned, uint64, void, unsigned, 4); +CV_INTRIN_DEF_TYPE_TRAITS(int, int, unsigned, unsigned, int64, void, int, 4); +CV_INTRIN_DEF_TYPE_TRAITS(float, int, unsigned, float, double, void, float, 4); +CV_INTRIN_DEF_TYPE_TRAITS(uint64, int64, uint64, uint64, void, void, uint64, 2); +CV_INTRIN_DEF_TYPE_TRAITS(int64, int64, uint64, uint64, void, void, int64, 2); +CV_INTRIN_DEF_TYPE_TRAITS(double, int64, uint64, double, void, void, double, 2); + +#ifndef CV_DOXYGEN + +#ifndef CV_CPU_OPTIMIZATION_HAL_NAMESPACE +#ifdef CV_CPU_DISPATCH_MODE + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE __CV_CAT(hal_, CV_CPU_DISPATCH_MODE) + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace __CV_CAT(hal_, CV_CPU_DISPATCH_MODE) { + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END } +#else + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE hal_baseline + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN namespace hal_baseline { + #define CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END } +#endif +#endif // CV_CPU_OPTIMIZATION_HAL_NAMESPACE + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE; +#endif +} + +#ifdef CV_DOXYGEN +# undef CV_AVX2 +# undef CV_SSE2 +# undef CV_NEON +# undef CV_VSX +# undef CV_FP16 +# undef CV_MSA +#endif + +#if (CV_SSE2 || CV_NEON || CV_VSX || CV_MSA || CV_WASM_SIMD) && !defined(CV_FORCE_SIMD128_CPP) +#define CV__SIMD_FORWARD 128 +#include "opencv2/core/hal/intrin_forward.hpp" +#endif + +#if CV_SSE2 && !defined(CV_FORCE_SIMD128_CPP) + +#include "opencv2/core/hal/intrin_sse_em.hpp" +#include "opencv2/core/hal/intrin_sse.hpp" + +#elif CV_NEON && !defined(CV_FORCE_SIMD128_CPP) + +#include "opencv2/core/hal/intrin_neon.hpp" + +#elif CV_VSX && !defined(CV_FORCE_SIMD128_CPP) + +#include "opencv2/core/hal/intrin_vsx.hpp" + +#elif CV_MSA && !defined(CV_FORCE_SIMD128_CPP) + +#include "opencv2/core/hal/intrin_msa.hpp" + +#elif CV_WASM_SIMD && !defined(CV_FORCE_SIMD128_CPP) +#include "opencv2/core/hal/intrin_wasm.hpp" + +#else + +#define CV_SIMD128_CPP 1 +#include "opencv2/core/hal/intrin_cpp.hpp" + +#endif + +// AVX2 can be used together with SSE2, so +// we define those two sets of intrinsics at once. +// Most of the intrinsics do not conflict (the proper overloaded variant is +// resolved by the argument types, e.g. v_float32x4 ~ SSE2, v_float32x8 ~ AVX2), +// but some of AVX2 intrinsics get v256_ prefix instead of v_, e.g. v256_load() vs v_load(). +// Correspondingly, the wide intrinsics (which are mapped to the "widest" +// available instruction set) will get vx_ prefix +// (and will be mapped to v256_ counterparts) (e.g. vx_load() => v256_load()) +#if CV_AVX2 + +#define CV__SIMD_FORWARD 256 +#include "opencv2/core/hal/intrin_forward.hpp" +#include "opencv2/core/hal/intrin_avx.hpp" + +#endif + +// AVX512 can be used together with SSE2 and AVX2, so +// we define those sets of intrinsics at once. +// For some of AVX512 intrinsics get v512_ prefix instead of v_, e.g. v512_load() vs v_load(). +// Wide intrinsics will be mapped to v512_ counterparts in this case(e.g. vx_load() => v512_load()) +#if CV_AVX512_SKX + +#define CV__SIMD_FORWARD 512 +#include "opencv2/core/hal/intrin_forward.hpp" +#include "opencv2/core/hal/intrin_avx512.hpp" + +#endif + +//! @cond IGNORED + +namespace cv { + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +#endif + +#ifndef CV_SIMD128 +#define CV_SIMD128 0 +#endif + +#ifndef CV_SIMD128_64F +#define CV_SIMD128_64F 0 +#endif + +#ifndef CV_SIMD256 +#define CV_SIMD256 0 +#endif + +#ifndef CV_SIMD256_64F +#define CV_SIMD256_64F 0 +#endif + +#ifndef CV_SIMD512 +#define CV_SIMD512 0 +#endif + +#ifndef CV_SIMD512_64F +#define CV_SIMD512_64F 0 +#endif + +#ifndef CV_SIMD128_FP16 +#define CV_SIMD128_FP16 0 +#endif + +#ifndef CV_SIMD256_FP16 +#define CV_SIMD256_FP16 0 +#endif + +#ifndef CV_SIMD512_FP16 +#define CV_SIMD512_FP16 0 +#endif + +//================================================================================================== + +#define CV_INTRIN_DEFINE_WIDE_INTRIN(typ, vtyp, short_typ, prefix, loadsfx) \ + inline vtyp vx_setall_##short_typ(typ v) { return prefix##_setall_##short_typ(v); } \ + inline vtyp vx_setzero_##short_typ() { return prefix##_setzero_##short_typ(); } \ + inline vtyp vx_##loadsfx(const typ* ptr) { return prefix##_##loadsfx(ptr); } \ + inline vtyp vx_##loadsfx##_aligned(const typ* ptr) { return prefix##_##loadsfx##_aligned(ptr); } \ + inline vtyp vx_##loadsfx##_low(const typ* ptr) { return prefix##_##loadsfx##_low(ptr); } \ + inline vtyp vx_##loadsfx##_halves(const typ* ptr0, const typ* ptr1) { return prefix##_##loadsfx##_halves(ptr0, ptr1); } \ + inline void vx_store(typ* ptr, const vtyp& v) { return v_store(ptr, v); } \ + inline void vx_store_aligned(typ* ptr, const vtyp& v) { return v_store_aligned(ptr, v); } \ + inline vtyp vx_lut(const typ* ptr, const int* idx) { return prefix##_lut(ptr, idx); } \ + inline vtyp vx_lut_pairs(const typ* ptr, const int* idx) { return prefix##_lut_pairs(ptr, idx); } + +#define CV_INTRIN_DEFINE_WIDE_LUT_QUAD(typ, vtyp, prefix) \ + inline vtyp vx_lut_quads(const typ* ptr, const int* idx) { return prefix##_lut_quads(ptr, idx); } + +#define CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(typ, wtyp, prefix) \ + inline wtyp vx_load_expand(const typ* ptr) { return prefix##_load_expand(ptr); } + +#define CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND_Q(typ, qtyp, prefix) \ + inline qtyp vx_load_expand_q(const typ* ptr) { return prefix##_load_expand_q(ptr); } + +#define CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(typ, vtyp, short_typ, wtyp, qtyp, prefix, loadsfx) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(typ, vtyp, short_typ, prefix, loadsfx) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(typ, vtyp, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(typ, wtyp, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND_Q(typ, qtyp, prefix) + +#define CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(uchar, v_uint8, u8, v_uint16, v_uint32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_INTRIN_WITH_EXPAND(schar, v_int8, s8, v_int16, v_int32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(ushort, v_uint16, u16, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(ushort, v_uint16, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(ushort, v_uint32, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(short, v_int16, s16, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(short, v_int16, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(short, v_int32, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(int, v_int32, s32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(int, v_int32, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(int, v_int64, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(unsigned, v_uint32, u32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(unsigned, v_uint32, prefix) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(unsigned, v_uint64, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(float, v_float32, f32, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LUT_QUAD(float, v_float32, prefix) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(int64, v_int64, s64, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_INTRIN(uint64, v_uint64, u64, prefix, load) \ + CV_INTRIN_DEFINE_WIDE_LOAD_EXPAND(float16_t, v_float32, prefix) + +template struct V_RegTraits +{ +}; + +#define CV_DEF_REG_TRAITS(prefix, _reg, lane_type, suffix, _u_reg, _w_reg, _q_reg, _int_reg, _round_reg) \ + template<> struct V_RegTraits<_reg> \ + { \ + typedef _reg reg; \ + typedef _u_reg u_reg; \ + typedef _w_reg w_reg; \ + typedef _q_reg q_reg; \ + typedef _int_reg int_reg; \ + typedef _round_reg round_reg; \ + } + +#if CV_SIMD128 || CV_SIMD128_CPP + CV_DEF_REG_TRAITS(v, v_uint8x16, uchar, u8, v_uint8x16, v_uint16x8, v_uint32x4, v_int8x16, void); + CV_DEF_REG_TRAITS(v, v_int8x16, schar, s8, v_uint8x16, v_int16x8, v_int32x4, v_int8x16, void); + CV_DEF_REG_TRAITS(v, v_uint16x8, ushort, u16, v_uint16x8, v_uint32x4, v_uint64x2, v_int16x8, void); + CV_DEF_REG_TRAITS(v, v_int16x8, short, s16, v_uint16x8, v_int32x4, v_int64x2, v_int16x8, void); + CV_DEF_REG_TRAITS(v, v_uint32x4, unsigned, u32, v_uint32x4, v_uint64x2, void, v_int32x4, void); + CV_DEF_REG_TRAITS(v, v_int32x4, int, s32, v_uint32x4, v_int64x2, void, v_int32x4, void); +#if CV_SIMD128_64F + CV_DEF_REG_TRAITS(v, v_float32x4, float, f32, v_float32x4, v_float64x2, void, v_int32x4, v_int32x4); +#else + CV_DEF_REG_TRAITS(v, v_float32x4, float, f32, v_float32x4, void, void, v_int32x4, v_int32x4); +#endif + CV_DEF_REG_TRAITS(v, v_uint64x2, uint64, u64, v_uint64x2, void, void, v_int64x2, void); + CV_DEF_REG_TRAITS(v, v_int64x2, int64, s64, v_uint64x2, void, void, v_int64x2, void); +#if CV_SIMD128_64F + CV_DEF_REG_TRAITS(v, v_float64x2, double, f64, v_float64x2, void, void, v_int64x2, v_int32x4); +#endif +#endif + +#if CV_SIMD256 + CV_DEF_REG_TRAITS(v256, v_uint8x32, uchar, u8, v_uint8x32, v_uint16x16, v_uint32x8, v_int8x32, void); + CV_DEF_REG_TRAITS(v256, v_int8x32, schar, s8, v_uint8x32, v_int16x16, v_int32x8, v_int8x32, void); + CV_DEF_REG_TRAITS(v256, v_uint16x16, ushort, u16, v_uint16x16, v_uint32x8, v_uint64x4, v_int16x16, void); + CV_DEF_REG_TRAITS(v256, v_int16x16, short, s16, v_uint16x16, v_int32x8, v_int64x4, v_int16x16, void); + CV_DEF_REG_TRAITS(v256, v_uint32x8, unsigned, u32, v_uint32x8, v_uint64x4, void, v_int32x8, void); + CV_DEF_REG_TRAITS(v256, v_int32x8, int, s32, v_uint32x8, v_int64x4, void, v_int32x8, void); + CV_DEF_REG_TRAITS(v256, v_float32x8, float, f32, v_float32x8, v_float64x4, void, v_int32x8, v_int32x8); + CV_DEF_REG_TRAITS(v256, v_uint64x4, uint64, u64, v_uint64x4, void, void, v_int64x4, void); + CV_DEF_REG_TRAITS(v256, v_int64x4, int64, s64, v_uint64x4, void, void, v_int64x4, void); + CV_DEF_REG_TRAITS(v256, v_float64x4, double, f64, v_float64x4, void, void, v_int64x4, v_int32x8); +#endif + +#if CV_SIMD512 + CV_DEF_REG_TRAITS(v512, v_uint8x64, uchar, u8, v_uint8x64, v_uint16x32, v_uint32x16, v_int8x64, void); + CV_DEF_REG_TRAITS(v512, v_int8x64, schar, s8, v_uint8x64, v_int16x32, v_int32x16, v_int8x64, void); + CV_DEF_REG_TRAITS(v512, v_uint16x32, ushort, u16, v_uint16x32, v_uint32x16, v_uint64x8, v_int16x32, void); + CV_DEF_REG_TRAITS(v512, v_int16x32, short, s16, v_uint16x32, v_int32x16, v_int64x8, v_int16x32, void); + CV_DEF_REG_TRAITS(v512, v_uint32x16, unsigned, u32, v_uint32x16, v_uint64x8, void, v_int32x16, void); + CV_DEF_REG_TRAITS(v512, v_int32x16, int, s32, v_uint32x16, v_int64x8, void, v_int32x16, void); + CV_DEF_REG_TRAITS(v512, v_float32x16, float, f32, v_float32x16, v_float64x8, void, v_int32x16, v_int32x16); + CV_DEF_REG_TRAITS(v512, v_uint64x8, uint64, u64, v_uint64x8, void, void, v_int64x8, void); + CV_DEF_REG_TRAITS(v512, v_int64x8, int64, s64, v_uint64x8, void, void, v_int64x8, void); + CV_DEF_REG_TRAITS(v512, v_float64x8, double, f64, v_float64x8, void, void, v_int64x8, v_int32x16); +#endif + +#if CV_SIMD512 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 512) +#define CV__SIMD_NAMESPACE simd512 +namespace CV__SIMD_NAMESPACE { + #define CV_SIMD 1 + #define CV_SIMD_64F CV_SIMD512_64F + #define CV_SIMD_FP16 CV_SIMD512_FP16 + #define CV_SIMD_WIDTH 64 + typedef v_uint8x64 v_uint8; + typedef v_int8x64 v_int8; + typedef v_uint16x32 v_uint16; + typedef v_int16x32 v_int16; + typedef v_uint32x16 v_uint32; + typedef v_int32x16 v_int32; + typedef v_uint64x8 v_uint64; + typedef v_int64x8 v_int64; + typedef v_float32x16 v_float32; + CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v512) +#if CV_SIMD512_64F + typedef v_float64x8 v_float64; + CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v512, load) +#endif + inline void vx_cleanup() { v512_cleanup(); } +} // namespace +using namespace CV__SIMD_NAMESPACE; +#elif CV_SIMD256 && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 256) +#define CV__SIMD_NAMESPACE simd256 +namespace CV__SIMD_NAMESPACE { + #define CV_SIMD 1 + #define CV_SIMD_64F CV_SIMD256_64F + #define CV_SIMD_FP16 CV_SIMD256_FP16 + #define CV_SIMD_WIDTH 32 + typedef v_uint8x32 v_uint8; + typedef v_int8x32 v_int8; + typedef v_uint16x16 v_uint16; + typedef v_int16x16 v_int16; + typedef v_uint32x8 v_uint32; + typedef v_int32x8 v_int32; + typedef v_uint64x4 v_uint64; + typedef v_int64x4 v_int64; + typedef v_float32x8 v_float32; + CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v256) + #if CV_SIMD256_64F + typedef v_float64x4 v_float64; + CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v256, load) + #endif + inline void vx_cleanup() { v256_cleanup(); } +} // namespace +using namespace CV__SIMD_NAMESPACE; +#elif (CV_SIMD128 || CV_SIMD128_CPP) && (!defined(CV__SIMD_FORCE_WIDTH) || CV__SIMD_FORCE_WIDTH == 128) +#define CV__SIMD_NAMESPACE simd128 +namespace CV__SIMD_NAMESPACE { + #define CV_SIMD CV_SIMD128 + #define CV_SIMD_64F CV_SIMD128_64F + #define CV_SIMD_WIDTH 16 + typedef v_uint8x16 v_uint8; + typedef v_int8x16 v_int8; + typedef v_uint16x8 v_uint16; + typedef v_int16x8 v_int16; + typedef v_uint32x4 v_uint32; + typedef v_int32x4 v_int32; + typedef v_uint64x2 v_uint64; + typedef v_int64x2 v_int64; + typedef v_float32x4 v_float32; + CV_INTRIN_DEFINE_WIDE_INTRIN_ALL_TYPES(v) + #if CV_SIMD128_64F + typedef v_float64x2 v_float64; + CV_INTRIN_DEFINE_WIDE_INTRIN(double, v_float64, f64, v, load) + #endif + inline void vx_cleanup() { v_cleanup(); } +} // namespace +using namespace CV__SIMD_NAMESPACE; +#endif + +#ifndef CV_SIMD_64F +#define CV_SIMD_64F 0 +#endif + +#ifndef CV_SIMD_FP16 +#define CV_SIMD_FP16 0 //!< Defined to 1 on native support of operations with float16x8_t / float16x16_t (SIMD256) types +#endif + +#ifndef CV_SIMD +#define CV_SIMD 0 +#endif + +#include "simd_utils.impl.hpp" + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +#endif + +} // cv:: + +//! @endcond + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_avx.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_avx.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6fc03b72748908c96142343b3bff8b06375df772 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_avx.hpp @@ -0,0 +1,3125 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_INTRIN_AVX_HPP +#define OPENCV_HAL_INTRIN_AVX_HPP + +#define CV_SIMD256 1 +#define CV_SIMD256_64F 1 +#define CV_SIMD256_FP16 0 // no native operations with FP16 type. Only load/store from float32x8 are available (if CV_FP16 == 1) + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Utils //////////// + +inline __m256i _v256_combine(const __m128i& lo, const __m128i& hi) +{ return _mm256_inserti128_si256(_mm256_castsi128_si256(lo), hi, 1); } + +inline __m256 _v256_combine(const __m128& lo, const __m128& hi) +{ return _mm256_insertf128_ps(_mm256_castps128_ps256(lo), hi, 1); } + +inline __m256d _v256_combine(const __m128d& lo, const __m128d& hi) +{ return _mm256_insertf128_pd(_mm256_castpd128_pd256(lo), hi, 1); } + +inline int _v_cvtsi256_si32(const __m256i& a) +{ return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); } + +inline __m256i _v256_shuffle_odd_64(const __m256i& v) +{ return _mm256_permute4x64_epi64(v, _MM_SHUFFLE(3, 1, 2, 0)); } + +inline __m256d _v256_shuffle_odd_64(const __m256d& v) +{ return _mm256_permute4x64_pd(v, _MM_SHUFFLE(3, 1, 2, 0)); } + +template +inline __m256i _v256_permute2x128(const __m256i& a, const __m256i& b) +{ return _mm256_permute2x128_si256(a, b, imm); } + +template +inline __m256 _v256_permute2x128(const __m256& a, const __m256& b) +{ return _mm256_permute2f128_ps(a, b, imm); } + +template +inline __m256d _v256_permute2x128(const __m256d& a, const __m256d& b) +{ return _mm256_permute2f128_pd(a, b, imm); } + +template +inline _Tpvec v256_permute2x128(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(_v256_permute2x128(a.val, b.val)); } + +template +inline __m256i _v256_permute4x64(const __m256i& a) +{ return _mm256_permute4x64_epi64(a, imm); } + +template +inline __m256d _v256_permute4x64(const __m256d& a) +{ return _mm256_permute4x64_pd(a, imm); } + +template +inline _Tpvec v256_permute4x64(const _Tpvec& a) +{ return _Tpvec(_v256_permute4x64(a.val)); } + +inline __m128i _v256_extract_high(const __m256i& v) +{ return _mm256_extracti128_si256(v, 1); } + +inline __m128 _v256_extract_high(const __m256& v) +{ return _mm256_extractf128_ps(v, 1); } + +inline __m128d _v256_extract_high(const __m256d& v) +{ return _mm256_extractf128_pd(v, 1); } + +inline __m128i _v256_extract_low(const __m256i& v) +{ return _mm256_castsi256_si128(v); } + +inline __m128 _v256_extract_low(const __m256& v) +{ return _mm256_castps256_ps128(v); } + +inline __m128d _v256_extract_low(const __m256d& v) +{ return _mm256_castpd256_pd128(v); } + +inline __m256i _v256_packs_epu32(const __m256i& a, const __m256i& b) +{ + const __m256i m = _mm256_set1_epi32(65535); + __m256i am = _mm256_min_epu32(a, m); + __m256i bm = _mm256_min_epu32(b, m); + return _mm256_packus_epi32(am, bm); +} + +template +inline int _v256_extract_epi8(const __m256i& a) +{ +#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/)) + return _mm256_extract_epi8(a, i); +#else + __m128i b = _mm256_extractf128_si256(a, ((i) >> 4)); + return _mm_extract_epi8(b, i & 15); // SSE4.1 +#endif +} + +template +inline int _v256_extract_epi16(const __m256i& a) +{ +#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/)) + return _mm256_extract_epi16(a, i); +#else + __m128i b = _mm256_extractf128_si256(a, ((i) >> 3)); + return _mm_extract_epi16(b, i & 7); // SSE2 +#endif +} + +template +inline int _v256_extract_epi32(const __m256i& a) +{ +#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/)) + return _mm256_extract_epi32(a, i); +#else + __m128i b = _mm256_extractf128_si256(a, ((i) >> 2)); + return _mm_extract_epi32(b, i & 3); // SSE4.1 +#endif +} + +template +inline int64 _v256_extract_epi64(const __m256i& a) +{ +#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/)) + return _mm256_extract_epi64(a, i); +#else + __m128i b = _mm256_extractf128_si256(a, ((i) >> 1)); + return _mm_extract_epi64(b, i & 1); // SSE4.1 +#endif +} + +///////// Types //////////// + +struct v_uint8x32 +{ + typedef uchar lane_type; + enum { nlanes = 32 }; + __m256i val; + + explicit v_uint8x32(__m256i v) : val(v) {} + v_uint8x32(uchar v0, uchar v1, uchar v2, uchar v3, + uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, + uchar v12, uchar v13, uchar v14, uchar v15, + uchar v16, uchar v17, uchar v18, uchar v19, + uchar v20, uchar v21, uchar v22, uchar v23, + uchar v24, uchar v25, uchar v26, uchar v27, + uchar v28, uchar v29, uchar v30, uchar v31) + { + val = _mm256_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, + (char)v4, (char)v5, (char)v6 , (char)v7, (char)v8, (char)v9, + (char)v10, (char)v11, (char)v12, (char)v13, (char)v14, (char)v15, + (char)v16, (char)v17, (char)v18, (char)v19, (char)v20, (char)v21, + (char)v22, (char)v23, (char)v24, (char)v25, (char)v26, (char)v27, + (char)v28, (char)v29, (char)v30, (char)v31); + } + v_uint8x32() : val(_mm256_setzero_si256()) {} + uchar get0() const { return (uchar)_v_cvtsi256_si32(val); } +}; + +struct v_int8x32 +{ + typedef schar lane_type; + enum { nlanes = 32 }; + __m256i val; + + explicit v_int8x32(__m256i v) : val(v) {} + v_int8x32(schar v0, schar v1, schar v2, schar v3, + schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, + schar v12, schar v13, schar v14, schar v15, + schar v16, schar v17, schar v18, schar v19, + schar v20, schar v21, schar v22, schar v23, + schar v24, schar v25, schar v26, schar v27, + schar v28, schar v29, schar v30, schar v31) + { + val = _mm256_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, + v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, + v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31); + } + v_int8x32() : val(_mm256_setzero_si256()) {} + schar get0() const { return (schar)_v_cvtsi256_si32(val); } +}; + +struct v_uint16x16 +{ + typedef ushort lane_type; + enum { nlanes = 16 }; + __m256i val; + + explicit v_uint16x16(__m256i v) : val(v) {} + v_uint16x16(ushort v0, ushort v1, ushort v2, ushort v3, + ushort v4, ushort v5, ushort v6, ushort v7, + ushort v8, ushort v9, ushort v10, ushort v11, + ushort v12, ushort v13, ushort v14, ushort v15) + { + val = _mm256_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, + (short)v4, (short)v5, (short)v6, (short)v7, (short)v8, (short)v9, + (short)v10, (short)v11, (short)v12, (short)v13, (short)v14, (short)v15); + } + v_uint16x16() : val(_mm256_setzero_si256()) {} + ushort get0() const { return (ushort)_v_cvtsi256_si32(val); } +}; + +struct v_int16x16 +{ + typedef short lane_type; + enum { nlanes = 16 }; + __m256i val; + + explicit v_int16x16(__m256i v) : val(v) {} + v_int16x16(short v0, short v1, short v2, short v3, + short v4, short v5, short v6, short v7, + short v8, short v9, short v10, short v11, + short v12, short v13, short v14, short v15) + { + val = _mm256_setr_epi16(v0, v1, v2, v3, v4, v5, v6, v7, + v8, v9, v10, v11, v12, v13, v14, v15); + } + v_int16x16() : val(_mm256_setzero_si256()) {} + short get0() const { return (short)_v_cvtsi256_si32(val); } +}; + +struct v_uint32x8 +{ + typedef unsigned lane_type; + enum { nlanes = 8 }; + __m256i val; + + explicit v_uint32x8(__m256i v) : val(v) {} + v_uint32x8(unsigned v0, unsigned v1, unsigned v2, unsigned v3, + unsigned v4, unsigned v5, unsigned v6, unsigned v7) + { + val = _mm256_setr_epi32((unsigned)v0, (unsigned)v1, (unsigned)v2, + (unsigned)v3, (unsigned)v4, (unsigned)v5, (unsigned)v6, (unsigned)v7); + } + v_uint32x8() : val(_mm256_setzero_si256()) {} + unsigned get0() const { return (unsigned)_v_cvtsi256_si32(val); } +}; + +struct v_int32x8 +{ + typedef int lane_type; + enum { nlanes = 8 }; + __m256i val; + + explicit v_int32x8(__m256i v) : val(v) {} + v_int32x8(int v0, int v1, int v2, int v3, + int v4, int v5, int v6, int v7) + { + val = _mm256_setr_epi32(v0, v1, v2, v3, v4, v5, v6, v7); + } + v_int32x8() : val(_mm256_setzero_si256()) {} + int get0() const { return _v_cvtsi256_si32(val); } +}; + +struct v_float32x8 +{ + typedef float lane_type; + enum { nlanes = 8 }; + __m256 val; + + explicit v_float32x8(__m256 v) : val(v) {} + v_float32x8(float v0, float v1, float v2, float v3, + float v4, float v5, float v6, float v7) + { + val = _mm256_setr_ps(v0, v1, v2, v3, v4, v5, v6, v7); + } + v_float32x8() : val(_mm256_setzero_ps()) {} + float get0() const { return _mm_cvtss_f32(_mm256_castps256_ps128(val)); } +}; + +struct v_uint64x4 +{ + typedef uint64 lane_type; + enum { nlanes = 4 }; + __m256i val; + + explicit v_uint64x4(__m256i v) : val(v) {} + v_uint64x4(uint64 v0, uint64 v1, uint64 v2, uint64 v3) + { val = _mm256_setr_epi64x((int64)v0, (int64)v1, (int64)v2, (int64)v3); } + v_uint64x4() : val(_mm256_setzero_si256()) {} + uint64 get0() const + { + #if defined __x86_64__ || defined _M_X64 + return (uint64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val)); + #else + int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val)); + int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32))); + return (unsigned)a | ((uint64)(unsigned)b << 32); + #endif + } +}; + +struct v_int64x4 +{ + typedef int64 lane_type; + enum { nlanes = 4 }; + __m256i val; + + explicit v_int64x4(__m256i v) : val(v) {} + v_int64x4(int64 v0, int64 v1, int64 v2, int64 v3) + { val = _mm256_setr_epi64x(v0, v1, v2, v3); } + v_int64x4() : val(_mm256_setzero_si256()) {} + + int64 get0() const + { + #if defined __x86_64__ || defined _M_X64 + return (int64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val)); + #else + int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val)); + int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32))); + return (int64)((unsigned)a | ((uint64)(unsigned)b << 32)); + #endif + } +}; + +struct v_float64x4 +{ + typedef double lane_type; + enum { nlanes = 4 }; + __m256d val; + + explicit v_float64x4(__m256d v) : val(v) {} + v_float64x4(double v0, double v1, double v2, double v3) + { val = _mm256_setr_pd(v0, v1, v2, v3); } + v_float64x4() : val(_mm256_setzero_pd()) {} + double get0() const { return _mm_cvtsd_f64(_mm256_castpd256_pd128(val)); } +}; + +//////////////// Load and store operations /////////////// + +#define OPENCV_HAL_IMPL_AVX_LOADSTORE(_Tpvec, _Tp) \ + inline _Tpvec v256_load(const _Tp* ptr) \ + { return _Tpvec(_mm256_loadu_si256((const __m256i*)ptr)); } \ + inline _Tpvec v256_load_aligned(const _Tp* ptr) \ + { return _Tpvec(_mm256_load_si256((const __m256i*)ptr)); } \ + inline _Tpvec v256_load_low(const _Tp* ptr) \ + { \ + __m128i v128 = _mm_loadu_si128((const __m128i*)ptr); \ + return _Tpvec(_mm256_castsi128_si256(v128)); \ + } \ + inline _Tpvec v256_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ + { \ + __m128i vlo = _mm_loadu_si128((const __m128i*)ptr0); \ + __m128i vhi = _mm_loadu_si128((const __m128i*)ptr1); \ + return _Tpvec(_v256_combine(vlo, vhi)); \ + } \ + inline void v_store(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_si256((__m256i*)ptr, a.val); } \ + inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ + { _mm256_store_si256((__m256i*)ptr, a.val); } \ + inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ + { _mm256_stream_si256((__m256i*)ptr, a.val); } \ + inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ + { \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm256_storeu_si256((__m256i*)ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm256_stream_si256((__m256i*)ptr, a.val); \ + else \ + _mm256_store_si256((__m256i*)ptr, a.val); \ + } \ + inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_si128((__m128i*)ptr, _v256_extract_low(a.val)); } \ + inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_si128((__m128i*)ptr, _v256_extract_high(a.val)); } + +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint8x32, uchar) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int8x32, schar) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint16x16, ushort) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int16x16, short) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint32x8, unsigned) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int32x8, int) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint64x4, uint64) +OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int64x4, int64) + +#define OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(_Tpvec, _Tp, suffix, halfreg) \ + inline _Tpvec v256_load(const _Tp* ptr) \ + { return _Tpvec(_mm256_loadu_##suffix(ptr)); } \ + inline _Tpvec v256_load_aligned(const _Tp* ptr) \ + { return _Tpvec(_mm256_load_##suffix(ptr)); } \ + inline _Tpvec v256_load_low(const _Tp* ptr) \ + { \ + return _Tpvec(_mm256_cast##suffix##128_##suffix##256 \ + (_mm_loadu_##suffix(ptr))); \ + } \ + inline _Tpvec v256_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ + { \ + halfreg vlo = _mm_loadu_##suffix(ptr0); \ + halfreg vhi = _mm_loadu_##suffix(ptr1); \ + return _Tpvec(_v256_combine(vlo, vhi)); \ + } \ + inline void v_store(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_##suffix(ptr, a.val); } \ + inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ + { _mm256_store_##suffix(ptr, a.val); } \ + inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ + { _mm256_stream_##suffix(ptr, a.val); } \ + inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ + { \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm256_storeu_##suffix(ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm256_stream_##suffix(ptr, a.val); \ + else \ + _mm256_store_##suffix(ptr, a.val); \ + } \ + inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_##suffix(ptr, _v256_extract_low(a.val)); } \ + inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ + { _mm_storeu_##suffix(ptr, _v256_extract_high(a.val)); } + +OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(v_float32x8, float, ps, __m128) +OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(v_float64x4, double, pd, __m128d) + +#define OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, _Tpvecf, suffix, cast) \ + inline _Tpvec v_reinterpret_as_##suffix(const _Tpvecf& a) \ + { return _Tpvec(cast(a.val)); } + +#define OPENCV_HAL_IMPL_AVX_INIT(_Tpvec, _Tp, suffix, ssuffix, ctype_s) \ + inline _Tpvec v256_setzero_##suffix() \ + { return _Tpvec(_mm256_setzero_si256()); } \ + inline _Tpvec v256_setall_##suffix(_Tp v) \ + { return _Tpvec(_mm256_set1_##ssuffix((ctype_s)v)); } \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint8x32, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int8x32, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint16x16, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int16x16, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint32x8, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int32x8, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint64x4, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int64x4, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_float32x8, suffix, _mm256_castps_si256) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_float64x4, suffix, _mm256_castpd_si256) + +OPENCV_HAL_IMPL_AVX_INIT(v_uint8x32, uchar, u8, epi8, char) +OPENCV_HAL_IMPL_AVX_INIT(v_int8x32, schar, s8, epi8, char) +OPENCV_HAL_IMPL_AVX_INIT(v_uint16x16, ushort, u16, epi16, short) +OPENCV_HAL_IMPL_AVX_INIT(v_int16x16, short, s16, epi16, short) +OPENCV_HAL_IMPL_AVX_INIT(v_uint32x8, unsigned, u32, epi32, int) +OPENCV_HAL_IMPL_AVX_INIT(v_int32x8, int, s32, epi32, int) +OPENCV_HAL_IMPL_AVX_INIT(v_uint64x4, uint64, u64, epi64x, int64) +OPENCV_HAL_IMPL_AVX_INIT(v_int64x4, int64, s64, epi64x, int64) + +#define OPENCV_HAL_IMPL_AVX_INIT_FLT(_Tpvec, _Tp, suffix, zsuffix, cast) \ + inline _Tpvec v256_setzero_##suffix() \ + { return _Tpvec(_mm256_setzero_##zsuffix()); } \ + inline _Tpvec v256_setall_##suffix(_Tp v) \ + { return _Tpvec(_mm256_set1_##zsuffix(v)); } \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint8x32, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int8x32, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint16x16, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int16x16, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint32x8, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int32x8, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint64x4, suffix, cast) \ + OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int64x4, suffix, cast) + +OPENCV_HAL_IMPL_AVX_INIT_FLT(v_float32x8, float, f32, ps, _mm256_castsi256_ps) +OPENCV_HAL_IMPL_AVX_INIT_FLT(v_float64x4, double, f64, pd, _mm256_castsi256_pd) + +inline v_float32x8 v_reinterpret_as_f32(const v_float32x8& a) +{ return a; } +inline v_float32x8 v_reinterpret_as_f32(const v_float64x4& a) +{ return v_float32x8(_mm256_castpd_ps(a.val)); } + +inline v_float64x4 v_reinterpret_as_f64(const v_float64x4& a) +{ return a; } +inline v_float64x4 v_reinterpret_as_f64(const v_float32x8& a) +{ return v_float64x4(_mm256_castps_pd(a.val)); } + +/* Recombine */ +/*#define OPENCV_HAL_IMPL_AVX_COMBINE(_Tpvec, perm) \ + inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(perm(a.val, b.val, 0x20)); } \ + inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(perm(a.val, b.val, 0x31)); } \ + inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ + { c = v_combine_low(a, b); d = v_combine_high(a, b); } + +#define OPENCV_HAL_IMPL_AVX_UNPACKS(_Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_COMBINE(_Tpvec, _mm256_permute2x128_si256) \ + inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, \ + _Tpvec& b0, _Tpvec& b1) \ + { \ + __m256i v0 = _v256_shuffle_odd_64(a0.val); \ + __m256i v1 = _v256_shuffle_odd_64(a1.val); \ + b0.val = _mm256_unpacklo_##suffix(v0, v1); \ + b1.val = _mm256_unpackhi_##suffix(v0, v1); \ + } + +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint64x4, epi64) +OPENCV_HAL_IMPL_AVX_UNPACKS(v_int64x4, epi64) +OPENCV_HAL_IMPL_AVX_COMBINE(v_float32x8, _mm256_permute2f128_ps) +OPENCV_HAL_IMPL_AVX_COMBINE(v_float64x4, _mm256_permute2f128_pd) + +inline void v_zip(const v_float32x8& a0, const v_float32x8& a1, v_float32x8& b0, v_float32x8& b1) +{ + __m256 v0 = _mm256_unpacklo_ps(a0.val, a1.val); + __m256 v1 = _mm256_unpackhi_ps(a0.val, a1.val); + v_recombine(v_float32x8(v0), v_float32x8(v1), b0, b1); +} + +inline void v_zip(const v_float64x4& a0, const v_float64x4& a1, v_float64x4& b0, v_float64x4& b1) +{ + __m256d v0 = _v_shuffle_odd_64(a0.val); + __m256d v1 = _v_shuffle_odd_64(a1.val); + b0.val = _mm256_unpacklo_pd(v0, v1); + b1.val = _mm256_unpackhi_pd(v0, v1); +}*/ + +//////////////// Variant Value reordering /////////////// + +// unpacks +#define OPENCV_HAL_IMPL_AVX_UNPACK(_Tpvec, suffix) \ + inline _Tpvec v256_unpacklo(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_unpacklo_##suffix(a.val, b.val)); } \ + inline _Tpvec v256_unpackhi(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_unpackhi_##suffix(a.val, b.val)); } + +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int8x32, epi8) +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int16x16, epi16) +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int32x8, epi32) +OPENCV_HAL_IMPL_AVX_UNPACK(v_uint64x4, epi64) +OPENCV_HAL_IMPL_AVX_UNPACK(v_int64x4, epi64) +OPENCV_HAL_IMPL_AVX_UNPACK(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_UNPACK(v_float64x4, pd) + +// blend +#define OPENCV_HAL_IMPL_AVX_BLEND(_Tpvec, suffix) \ + template \ + inline _Tpvec v256_blend(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_blend_##suffix(a.val, b.val, m)); } + +OPENCV_HAL_IMPL_AVX_BLEND(v_uint16x16, epi16) +OPENCV_HAL_IMPL_AVX_BLEND(v_int16x16, epi16) +OPENCV_HAL_IMPL_AVX_BLEND(v_uint32x8, epi32) +OPENCV_HAL_IMPL_AVX_BLEND(v_int32x8, epi32) +OPENCV_HAL_IMPL_AVX_BLEND(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_BLEND(v_float64x4, pd) + +template +inline v_uint64x4 v256_blend(const v_uint64x4& a, const v_uint64x4& b) +{ + enum {M0 = m}; + enum {M1 = (M0 | (M0 << 2)) & 0x33}; + enum {M2 = (M1 | (M1 << 1)) & 0x55}; + enum {MM = M2 | (M2 << 1)}; + return v_uint64x4(_mm256_blend_epi32(a.val, b.val, MM)); +} +template +inline v_int64x4 v256_blend(const v_int64x4& a, const v_int64x4& b) +{ return v_int64x4(v256_blend(v_uint64x4(a.val), v_uint64x4(b.val)).val); } + +// shuffle +// todo: emluate 64bit +#define OPENCV_HAL_IMPL_AVX_SHUFFLE(_Tpvec, intrin) \ + template \ + inline _Tpvec v256_shuffle(const _Tpvec& a) \ + { return _Tpvec(_mm256_##intrin(a.val, m)); } + +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_uint32x8, shuffle_epi32) +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_int32x8, shuffle_epi32) +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_float32x8, permute_ps) +OPENCV_HAL_IMPL_AVX_SHUFFLE(v_float64x4, permute_pd) + +template +inline void v256_zip(const _Tpvec& a, const _Tpvec& b, _Tpvec& ab0, _Tpvec& ab1) +{ + ab0 = v256_unpacklo(a, b); + ab1 = v256_unpackhi(a, b); +} + +template +inline _Tpvec v256_combine_diagonal(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(_mm256_blend_epi32(a.val, b.val, 0xf0)); } + +inline v_float32x8 v256_combine_diagonal(const v_float32x8& a, const v_float32x8& b) +{ return v256_blend<0xf0>(a, b); } + +inline v_float64x4 v256_combine_diagonal(const v_float64x4& a, const v_float64x4& b) +{ return v256_blend<0xc>(a, b); } + +template +inline _Tpvec v256_alignr_128(const _Tpvec& a, const _Tpvec& b) +{ return v256_permute2x128<0x21>(a, b); } + +template +inline _Tpvec v256_alignr_64(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(_mm256_alignr_epi8(a.val, b.val, 8)); } +inline v_float64x4 v256_alignr_64(const v_float64x4& a, const v_float64x4& b) +{ return v_float64x4(_mm256_shuffle_pd(b.val, a.val, _MM_SHUFFLE(0, 0, 1, 1))); } +// todo: emulate float32 + +template +inline _Tpvec v256_swap_halves(const _Tpvec& a) +{ return v256_permute2x128<1>(a, a); } + +template +inline _Tpvec v256_reverse_64(const _Tpvec& a) +{ return v256_permute4x64<_MM_SHUFFLE(0, 1, 2, 3)>(a); } + +// ZIP +#define OPENCV_HAL_IMPL_AVX_ZIP(_Tpvec) \ + inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ + { return v256_permute2x128<0x20>(a, b); } \ + inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ + { return v256_permute2x128<0x31>(a, b); } \ + inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ + { \ + _Tpvec a1b0 = v256_alignr_128(a, b); \ + c = v256_combine_diagonal(a, a1b0); \ + d = v256_combine_diagonal(a1b0, b); \ + } \ + inline void v_zip(const _Tpvec& a, const _Tpvec& b, \ + _Tpvec& ab0, _Tpvec& ab1) \ + { \ + _Tpvec ab0ab2, ab1ab3; \ + v256_zip(a, b, ab0ab2, ab1ab3); \ + v_recombine(ab0ab2, ab1ab3, ab0, ab1); \ + } + +OPENCV_HAL_IMPL_AVX_ZIP(v_uint8x32) +OPENCV_HAL_IMPL_AVX_ZIP(v_int8x32) +OPENCV_HAL_IMPL_AVX_ZIP(v_uint16x16) +OPENCV_HAL_IMPL_AVX_ZIP(v_int16x16) +OPENCV_HAL_IMPL_AVX_ZIP(v_uint32x8) +OPENCV_HAL_IMPL_AVX_ZIP(v_int32x8) +OPENCV_HAL_IMPL_AVX_ZIP(v_uint64x4) +OPENCV_HAL_IMPL_AVX_ZIP(v_int64x4) +OPENCV_HAL_IMPL_AVX_ZIP(v_float32x8) +OPENCV_HAL_IMPL_AVX_ZIP(v_float64x4) + +////////// Arithmetic, bitwise and comparison operations ///////// + +/* Element-wise binary and unary operations */ + +/** Arithmetics **/ +#define OPENCV_HAL_IMPL_AVX_BIN_OP(bin_op, _Tpvec, intrin) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(intrin(a.val, b.val)); } \ + inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ + { a.val = intrin(a.val, b.val); return a; } + +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint8x32, _mm256_adds_epu8) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint8x32, _mm256_subs_epu8) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int8x32, _mm256_adds_epi8) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int8x32, _mm256_subs_epi8) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint16x16, _mm256_adds_epu16) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint16x16, _mm256_subs_epu16) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int16x16, _mm256_adds_epi16) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int16x16, _mm256_subs_epi16) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint32x8, _mm256_add_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint32x8, _mm256_sub_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_uint32x8, _mm256_mullo_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int32x8, _mm256_add_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int32x8, _mm256_sub_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_int32x8, _mm256_mullo_epi32) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint64x4, _mm256_add_epi64) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint64x4, _mm256_sub_epi64) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int64x4, _mm256_add_epi64) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int64x4, _mm256_sub_epi64) + +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_float32x8, _mm256_add_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_float32x8, _mm256_sub_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_float32x8, _mm256_mul_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(/, v_float32x8, _mm256_div_ps) +OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_float64x4, _mm256_add_pd) +OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_float64x4, _mm256_sub_pd) +OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_float64x4, _mm256_mul_pd) +OPENCV_HAL_IMPL_AVX_BIN_OP(/, v_float64x4, _mm256_div_pd) + +// saturating multiply 8-bit, 16-bit +inline v_uint8x32 operator * (const v_uint8x32& a, const v_uint8x32& b) +{ + v_uint16x16 c, d; + v_mul_expand(a, b, c, d); + return v_pack(c, d); +} +inline v_int8x32 operator * (const v_int8x32& a, const v_int8x32& b) +{ + v_int16x16 c, d; + v_mul_expand(a, b, c, d); + return v_pack(c, d); +} +inline v_uint16x16 operator * (const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i pl = _mm256_mullo_epi16(a.val, b.val); + __m256i ph = _mm256_mulhi_epu16(a.val, b.val); + __m256i p0 = _mm256_unpacklo_epi16(pl, ph); + __m256i p1 = _mm256_unpackhi_epi16(pl, ph); + return v_uint16x16(_v256_packs_epu32(p0, p1)); +} +inline v_int16x16 operator * (const v_int16x16& a, const v_int16x16& b) +{ + __m256i pl = _mm256_mullo_epi16(a.val, b.val); + __m256i ph = _mm256_mulhi_epi16(a.val, b.val); + __m256i p0 = _mm256_unpacklo_epi16(pl, ph); + __m256i p1 = _mm256_unpackhi_epi16(pl, ph); + return v_int16x16(_mm256_packs_epi32(p0, p1)); +} +inline v_uint8x32& operator *= (v_uint8x32& a, const v_uint8x32& b) +{ a = a * b; return a; } +inline v_int8x32& operator *= (v_int8x32& a, const v_int8x32& b) +{ a = a * b; return a; } +inline v_uint16x16& operator *= (v_uint16x16& a, const v_uint16x16& b) +{ a = a * b; return a; } +inline v_int16x16& operator *= (v_int16x16& a, const v_int16x16& b) +{ a = a * b; return a; } + +/** Non-saturating arithmetics **/ +#define OPENCV_HAL_IMPL_AVX_BIN_FUNC(func, _Tpvec, intrin) \ + inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(intrin(a.val, b.val)); } + +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_uint8x32, _mm256_add_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_int8x32, _mm256_add_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_uint16x16, _mm256_add_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_int16x16, _mm256_add_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_uint8x32, _mm256_sub_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_int8x32, _mm256_sub_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_uint16x16, _mm256_sub_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_int16x16, _mm256_sub_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_mul_wrap, v_uint16x16, _mm256_mullo_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_mul_wrap, v_int16x16, _mm256_mullo_epi16) + +inline v_uint8x32 v_mul_wrap(const v_uint8x32& a, const v_uint8x32& b) +{ + __m256i ad = _mm256_srai_epi16(a.val, 8); + __m256i bd = _mm256_srai_epi16(b.val, 8); + __m256i p0 = _mm256_mullo_epi16(a.val, b.val); // even + __m256i p1 = _mm256_slli_epi16(_mm256_mullo_epi16(ad, bd), 8); // odd + + const __m256i b01 = _mm256_set1_epi32(0xFF00FF00); + return v_uint8x32(_mm256_blendv_epi8(p0, p1, b01)); +} +inline v_int8x32 v_mul_wrap(const v_int8x32& a, const v_int8x32& b) +{ + return v_reinterpret_as_s8(v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b))); +} + +// Multiply and expand +inline void v_mul_expand(const v_uint8x32& a, const v_uint8x32& b, + v_uint16x16& c, v_uint16x16& d) +{ + v_uint16x16 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int8x32& a, const v_int8x32& b, + v_int16x16& c, v_int16x16& d) +{ + v_int16x16 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int16x16& a, const v_int16x16& b, + v_int32x8& c, v_int32x8& d) +{ + v_int16x16 vhi = v_int16x16(_mm256_mulhi_epi16(a.val, b.val)); + + v_int16x16 v0, v1; + v_zip(v_mul_wrap(a, b), vhi, v0, v1); + + c = v_reinterpret_as_s32(v0); + d = v_reinterpret_as_s32(v1); +} + +inline void v_mul_expand(const v_uint16x16& a, const v_uint16x16& b, + v_uint32x8& c, v_uint32x8& d) +{ + v_uint16x16 vhi = v_uint16x16(_mm256_mulhi_epu16(a.val, b.val)); + + v_uint16x16 v0, v1; + v_zip(v_mul_wrap(a, b), vhi, v0, v1); + + c = v_reinterpret_as_u32(v0); + d = v_reinterpret_as_u32(v1); +} + +inline void v_mul_expand(const v_uint32x8& a, const v_uint32x8& b, + v_uint64x4& c, v_uint64x4& d) +{ + __m256i v0 = _mm256_mul_epu32(a.val, b.val); + __m256i v1 = _mm256_mul_epu32(_mm256_srli_epi64(a.val, 32), _mm256_srli_epi64(b.val, 32)); + v_zip(v_uint64x4(v0), v_uint64x4(v1), c, d); +} + +inline v_int16x16 v_mul_hi(const v_int16x16& a, const v_int16x16& b) { return v_int16x16(_mm256_mulhi_epi16(a.val, b.val)); } +inline v_uint16x16 v_mul_hi(const v_uint16x16& a, const v_uint16x16& b) { return v_uint16x16(_mm256_mulhi_epu16(a.val, b.val)); } + +/** Bitwise shifts **/ +#define OPENCV_HAL_IMPL_AVX_SHIFT_OP(_Tpuvec, _Tpsvec, suffix, srai) \ + inline _Tpuvec operator << (const _Tpuvec& a, int imm) \ + { return _Tpuvec(_mm256_slli_##suffix(a.val, imm)); } \ + inline _Tpsvec operator << (const _Tpsvec& a, int imm) \ + { return _Tpsvec(_mm256_slli_##suffix(a.val, imm)); } \ + inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \ + { return _Tpuvec(_mm256_srli_##suffix(a.val, imm)); } \ + inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \ + { return _Tpsvec(srai(a.val, imm)); } \ + template \ + inline _Tpuvec v_shl(const _Tpuvec& a) \ + { return _Tpuvec(_mm256_slli_##suffix(a.val, imm)); } \ + template \ + inline _Tpsvec v_shl(const _Tpsvec& a) \ + { return _Tpsvec(_mm256_slli_##suffix(a.val, imm)); } \ + template \ + inline _Tpuvec v_shr(const _Tpuvec& a) \ + { return _Tpuvec(_mm256_srli_##suffix(a.val, imm)); } \ + template \ + inline _Tpsvec v_shr(const _Tpsvec& a) \ + { return _Tpsvec(srai(a.val, imm)); } + +OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint16x16, v_int16x16, epi16, _mm256_srai_epi16) +OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint32x8, v_int32x8, epi32, _mm256_srai_epi32) + +inline __m256i _mm256_srai_epi64xx(const __m256i a, int imm) +{ + __m256i d = _mm256_set1_epi64x((int64)1 << 63); + __m256i r = _mm256_srli_epi64(_mm256_add_epi64(a, d), imm); + return _mm256_sub_epi64(r, _mm256_srli_epi64(d, imm)); +} +OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint64x4, v_int64x4, epi64, _mm256_srai_epi64xx) + + +/** Bitwise logic **/ +#define OPENCV_HAL_IMPL_AVX_LOGIC_OP(_Tpvec, suffix, not_const) \ + OPENCV_HAL_IMPL_AVX_BIN_OP(&, _Tpvec, _mm256_and_##suffix) \ + OPENCV_HAL_IMPL_AVX_BIN_OP(|, _Tpvec, _mm256_or_##suffix) \ + OPENCV_HAL_IMPL_AVX_BIN_OP(^, _Tpvec, _mm256_xor_##suffix) \ + inline _Tpvec operator ~ (const _Tpvec& a) \ + { return _Tpvec(_mm256_xor_##suffix(a.val, not_const)); } + +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint8x32, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int8x32, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint16x16, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int16x16, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint32x8, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int32x8, si256, _mm256_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint64x4, si256, _mm256_set1_epi64x(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int64x4, si256, _mm256_set1_epi64x(-1)) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_float32x8, ps, _mm256_castsi256_ps(_mm256_set1_epi32(-1))) +OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_float64x4, pd, _mm256_castsi256_pd(_mm256_set1_epi32(-1))) + +/** Select **/ +#define OPENCV_HAL_IMPL_AVX_SELECT(_Tpvec, suffix) \ + inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_blendv_##suffix(b.val, a.val, mask.val)); } + +OPENCV_HAL_IMPL_AVX_SELECT(v_uint8x32, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_int8x32, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_uint16x16, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_int16x16, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_uint32x8, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_int32x8, epi8) +OPENCV_HAL_IMPL_AVX_SELECT(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_SELECT(v_float64x4, pd) + +/** Comparison **/ +#define OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpvec) \ + inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ + { return ~(a == b); } \ + inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ + { return b > a; } \ + inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ + { return ~(a < b); } \ + inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ + { return b >= a; } + +#define OPENCV_HAL_IMPL_AVX_CMP_OP_INT(_Tpuvec, _Tpsvec, suffix, sbit) \ + inline _Tpuvec operator == (const _Tpuvec& a, const _Tpuvec& b) \ + { return _Tpuvec(_mm256_cmpeq_##suffix(a.val, b.val)); } \ + inline _Tpuvec operator > (const _Tpuvec& a, const _Tpuvec& b) \ + { \ + __m256i smask = _mm256_set1_##suffix(sbit); \ + return _Tpuvec(_mm256_cmpgt_##suffix( \ + _mm256_xor_si256(a.val, smask), \ + _mm256_xor_si256(b.val, smask))); \ + } \ + inline _Tpsvec operator == (const _Tpsvec& a, const _Tpsvec& b) \ + { return _Tpsvec(_mm256_cmpeq_##suffix(a.val, b.val)); } \ + inline _Tpsvec operator > (const _Tpsvec& a, const _Tpsvec& b) \ + { return _Tpsvec(_mm256_cmpgt_##suffix(a.val, b.val)); } \ + OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpuvec) \ + OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpsvec) + +OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint8x32, v_int8x32, epi8, (char)-128) +OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint16x16, v_int16x16, epi16, (short)-32768) +OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint32x8, v_int32x8, epi32, (int)0x80000000) + +#define OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(_Tpvec) \ + inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_cmpeq_epi64(a.val, b.val)); } \ + inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ + { return ~(a == b); } + +OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_uint64x4) +OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_int64x4) + +#define OPENCV_HAL_IMPL_AVX_CMP_FLT(bin_op, imm8, _Tpvec, suffix) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm256_cmp_##suffix(a.val, b.val, imm8)); } + +#define OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(_Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(==, _CMP_EQ_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(!=, _CMP_NEQ_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(<, _CMP_LT_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(>, _CMP_GT_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(<=, _CMP_LE_OQ, _Tpvec, suffix) \ + OPENCV_HAL_IMPL_AVX_CMP_FLT(>=, _CMP_GE_OQ, _Tpvec, suffix) + +OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(v_float64x4, pd) + +inline v_float32x8 v_not_nan(const v_float32x8& a) +{ return v_float32x8(_mm256_cmp_ps(a.val, a.val, _CMP_ORD_Q)); } +inline v_float64x4 v_not_nan(const v_float64x4& a) +{ return v_float64x4(_mm256_cmp_pd(a.val, a.val, _CMP_ORD_Q)); } + +/** min/max **/ +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint8x32, _mm256_min_epu8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint8x32, _mm256_max_epu8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int8x32, _mm256_min_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int8x32, _mm256_max_epi8) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint16x16, _mm256_min_epu16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint16x16, _mm256_max_epu16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int16x16, _mm256_min_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int16x16, _mm256_max_epi16) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint32x8, _mm256_min_epu32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint32x8, _mm256_max_epu32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int32x8, _mm256_min_epi32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int32x8, _mm256_max_epi32) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_float32x8, _mm256_min_ps) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_float32x8, _mm256_max_ps) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_float64x4, _mm256_min_pd) +OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_float64x4, _mm256_max_pd) + +/** Rotate **/ +template +inline v_uint8x32 v_rotate_left(const v_uint8x32& a, const v_uint8x32& b) +{ + enum {IMM_R = (16 - imm) & 0xFF}; + enum {IMM_R2 = (32 - imm) & 0xFF}; + + if (imm == 0) return a; + if (imm == 32) return b; + if (imm > 32) return v_uint8x32(); + + __m256i swap = _mm256_permute2x128_si256(a.val, b.val, 0x03); + if (imm == 16) return v_uint8x32(swap); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(a.val, swap, IMM_R)); + return v_uint8x32(_mm256_alignr_epi8(swap, b.val, IMM_R2)); // imm < 32 +} + +template +inline v_uint8x32 v_rotate_right(const v_uint8x32& a, const v_uint8x32& b) +{ + enum {IMM_L = (imm - 16) & 0xFF}; + + if (imm == 0) return a; + if (imm == 32) return b; + if (imm > 32) return v_uint8x32(); + + __m256i swap = _mm256_permute2x128_si256(a.val, b.val, 0x21); + if (imm == 16) return v_uint8x32(swap); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(swap, a.val, imm)); + return v_uint8x32(_mm256_alignr_epi8(b.val, swap, IMM_L)); +} + +template +inline v_uint8x32 v_rotate_left(const v_uint8x32& a) +{ + enum {IMM_L = (imm - 16) & 0xFF}; + enum {IMM_R = (16 - imm) & 0xFF}; + + if (imm == 0) return a; + if (imm > 32) return v_uint8x32(); + + // ESAC control[3] ? [127:0] = 0 + __m256i swapz = _mm256_permute2x128_si256(a.val, a.val, _MM_SHUFFLE(0, 0, 2, 0)); + if (imm == 16) return v_uint8x32(swapz); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(a.val, swapz, IMM_R)); + return v_uint8x32(_mm256_slli_si256(swapz, IMM_L)); +} + +template +inline v_uint8x32 v_rotate_right(const v_uint8x32& a) +{ + enum {IMM_L = (imm - 16) & 0xFF}; + + if (imm == 0) return a; + if (imm > 32) return v_uint8x32(); + + // ESAC control[3] ? [127:0] = 0 + __m256i swapz = _mm256_permute2x128_si256(a.val, a.val, _MM_SHUFFLE(2, 0, 0, 1)); + if (imm == 16) return v_uint8x32(swapz); + if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(swapz, a.val, imm)); + return v_uint8x32(_mm256_srli_si256(swapz, IMM_L)); +} + +#define OPENCV_HAL_IMPL_AVX_ROTATE_CAST(intrin, _Tpvec, cast) \ + template \ + inline _Tpvec intrin(const _Tpvec& a, const _Tpvec& b) \ + { \ + enum {IMMxW = imm * sizeof(typename _Tpvec::lane_type)}; \ + v_uint8x32 ret = intrin(v_reinterpret_as_u8(a), \ + v_reinterpret_as_u8(b)); \ + return _Tpvec(cast(ret.val)); \ + } \ + template \ + inline _Tpvec intrin(const _Tpvec& a) \ + { \ + enum {IMMxW = imm * sizeof(typename _Tpvec::lane_type)}; \ + v_uint8x32 ret = intrin(v_reinterpret_as_u8(a)); \ + return _Tpvec(cast(ret.val)); \ + } + +#define OPENCV_HAL_IMPL_AVX_ROTATE(_Tpvec) \ + OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, _Tpvec, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, _Tpvec, OPENCV_HAL_NOP) + +OPENCV_HAL_IMPL_AVX_ROTATE(v_int8x32) +OPENCV_HAL_IMPL_AVX_ROTATE(v_uint16x16) +OPENCV_HAL_IMPL_AVX_ROTATE(v_int16x16) +OPENCV_HAL_IMPL_AVX_ROTATE(v_uint32x8) +OPENCV_HAL_IMPL_AVX_ROTATE(v_int32x8) +OPENCV_HAL_IMPL_AVX_ROTATE(v_uint64x4) +OPENCV_HAL_IMPL_AVX_ROTATE(v_int64x4) + +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, v_float32x8, _mm256_castsi256_ps) +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, v_float32x8, _mm256_castsi256_ps) +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, v_float64x4, _mm256_castsi256_pd) +OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, v_float64x4, _mm256_castsi256_pd) + +/** Reverse **/ +inline v_uint8x32 v_reverse(const v_uint8x32 &a) +{ + static const __m256i perm = _mm256_setr_epi8( + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, + 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); + __m256i vec = _mm256_shuffle_epi8(a.val, perm); + return v_uint8x32(_mm256_permute2x128_si256(vec, vec, 1)); +} + +inline v_int8x32 v_reverse(const v_int8x32 &a) +{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); } + +inline v_uint16x16 v_reverse(const v_uint16x16 &a) +{ + static const __m256i perm = _mm256_setr_epi8( + 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1, + 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1); + __m256i vec = _mm256_shuffle_epi8(a.val, perm); + return v_uint16x16(_mm256_permute2x128_si256(vec, vec, 1)); +} + +inline v_int16x16 v_reverse(const v_int16x16 &a) +{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); } + +inline v_uint32x8 v_reverse(const v_uint32x8 &a) +{ + static const __m256i perm = _mm256_setr_epi32(7, 6, 5, 4, 3, 2, 1, 0); + return v_uint32x8(_mm256_permutevar8x32_epi32(a.val, perm)); +} + +inline v_int32x8 v_reverse(const v_int32x8 &a) +{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_float32x8 v_reverse(const v_float32x8 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x4 v_reverse(const v_uint64x4 &a) +{ + return v_uint64x4(_mm256_permute4x64_epi64(a.val, _MM_SHUFFLE(0, 1, 2, 3))); +} + +inline v_int64x4 v_reverse(const v_int64x4 &a) +{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); } + +inline v_float64x4 v_reverse(const v_float64x4 &a) +{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); } + +////////// Reduce and mask ///////// + +/** Reduce **/ +inline unsigned v_reduce_sum(const v_uint8x32& a) +{ + __m256i half = _mm256_sad_epu8(a.val, _mm256_setzero_si256()); + __m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half)); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter))); +} +inline int v_reduce_sum(const v_int8x32& a) +{ + __m256i half = _mm256_sad_epu8(_mm256_xor_si256(a.val, _mm256_set1_epi8((schar)-128)), _mm256_setzero_si256()); + __m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half)); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter))) - 4096; +} +#define OPENCV_HAL_IMPL_AVX_REDUCE_32(_Tpvec, sctype, func, intrin) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { \ + __m128i val = intrin(_v256_extract_low(a.val), _v256_extract_high(a.val)); \ + val = intrin(val, _mm_srli_si128(val,8)); \ + val = intrin(val, _mm_srli_si128(val,4)); \ + val = intrin(val, _mm_srli_si128(val,2)); \ + val = intrin(val, _mm_srli_si128(val,1)); \ + return (sctype)_mm_cvtsi128_si32(val); \ + } + +OPENCV_HAL_IMPL_AVX_REDUCE_32(v_uint8x32, uchar, min, _mm_min_epu8) +OPENCV_HAL_IMPL_AVX_REDUCE_32(v_int8x32, schar, min, _mm_min_epi8) +OPENCV_HAL_IMPL_AVX_REDUCE_32(v_uint8x32, uchar, max, _mm_max_epu8) +OPENCV_HAL_IMPL_AVX_REDUCE_32(v_int8x32, schar, max, _mm_max_epi8) + +#define OPENCV_HAL_IMPL_AVX_REDUCE_16(_Tpvec, sctype, func, intrin) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { \ + __m128i v0 = _v256_extract_low(a.val); \ + __m128i v1 = _v256_extract_high(a.val); \ + v0 = intrin(v0, v1); \ + v0 = intrin(v0, _mm_srli_si128(v0, 8)); \ + v0 = intrin(v0, _mm_srli_si128(v0, 4)); \ + v0 = intrin(v0, _mm_srli_si128(v0, 2)); \ + return (sctype) _mm_cvtsi128_si32(v0); \ + } + +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_uint16x16, ushort, min, _mm_min_epu16) +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_int16x16, short, min, _mm_min_epi16) +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_uint16x16, ushort, max, _mm_max_epu16) +OPENCV_HAL_IMPL_AVX_REDUCE_16(v_int16x16, short, max, _mm_max_epi16) + +#define OPENCV_HAL_IMPL_AVX_REDUCE_8(_Tpvec, sctype, func, intrin) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { \ + __m128i v0 = _v256_extract_low(a.val); \ + __m128i v1 = _v256_extract_high(a.val); \ + v0 = intrin(v0, v1); \ + v0 = intrin(v0, _mm_srli_si128(v0, 8)); \ + v0 = intrin(v0, _mm_srli_si128(v0, 4)); \ + return (sctype) _mm_cvtsi128_si32(v0); \ + } + +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_uint32x8, unsigned, min, _mm_min_epu32) +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_int32x8, int, min, _mm_min_epi32) +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_uint32x8, unsigned, max, _mm_max_epu32) +OPENCV_HAL_IMPL_AVX_REDUCE_8(v_int32x8, int, max, _mm_max_epi32) + +#define OPENCV_HAL_IMPL_AVX_REDUCE_FLT(func, intrin) \ + inline float v_reduce_##func(const v_float32x8& a) \ + { \ + __m128 v0 = _v256_extract_low(a.val); \ + __m128 v1 = _v256_extract_high(a.val); \ + v0 = intrin(v0, v1); \ + v0 = intrin(v0, _mm_permute_ps(v0, _MM_SHUFFLE(0, 0, 3, 2))); \ + v0 = intrin(v0, _mm_permute_ps(v0, _MM_SHUFFLE(0, 0, 0, 1))); \ + return _mm_cvtss_f32(v0); \ + } + +OPENCV_HAL_IMPL_AVX_REDUCE_FLT(min, _mm_min_ps) +OPENCV_HAL_IMPL_AVX_REDUCE_FLT(max, _mm_max_ps) + +inline int v_reduce_sum(const v_int32x8& a) +{ + __m256i s0 = _mm256_hadd_epi32(a.val, a.val); + s0 = _mm256_hadd_epi32(s0, s0); + + __m128i s1 = _v256_extract_high(s0); + s1 = _mm_add_epi32(_v256_extract_low(s0), s1); + + return _mm_cvtsi128_si32(s1); +} + +inline unsigned v_reduce_sum(const v_uint32x8& a) +{ return v_reduce_sum(v_reinterpret_as_s32(a)); } + +inline int v_reduce_sum(const v_int16x16& a) +{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); } +inline unsigned v_reduce_sum(const v_uint16x16& a) +{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); } + +inline float v_reduce_sum(const v_float32x8& a) +{ + __m256 s0 = _mm256_hadd_ps(a.val, a.val); + s0 = _mm256_hadd_ps(s0, s0); + + __m128 s1 = _v256_extract_high(s0); + s1 = _mm_add_ps(_v256_extract_low(s0), s1); + + return _mm_cvtss_f32(s1); +} + +inline uint64 v_reduce_sum(const v_uint64x4& a) +{ + uint64 CV_DECL_ALIGNED(32) idx[2]; + _mm_store_si128((__m128i*)idx, _mm_add_epi64(_v256_extract_low(a.val), _v256_extract_high(a.val))); + return idx[0] + idx[1]; +} +inline int64 v_reduce_sum(const v_int64x4& a) +{ + int64 CV_DECL_ALIGNED(32) idx[2]; + _mm_store_si128((__m128i*)idx, _mm_add_epi64(_v256_extract_low(a.val), _v256_extract_high(a.val))); + return idx[0] + idx[1]; +} +inline double v_reduce_sum(const v_float64x4& a) +{ + __m256d s0 = _mm256_hadd_pd(a.val, a.val); + return _mm_cvtsd_f64(_mm_add_pd(_v256_extract_low(s0), _v256_extract_high(s0))); +} + +inline v_float32x8 v_reduce_sum4(const v_float32x8& a, const v_float32x8& b, + const v_float32x8& c, const v_float32x8& d) +{ + __m256 ab = _mm256_hadd_ps(a.val, b.val); + __m256 cd = _mm256_hadd_ps(c.val, d.val); + return v_float32x8(_mm256_hadd_ps(ab, cd)); +} + +inline unsigned v_reduce_sad(const v_uint8x32& a, const v_uint8x32& b) +{ + __m256i half = _mm256_sad_epu8(a.val, b.val); + __m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half)); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter))); +} +inline unsigned v_reduce_sad(const v_int8x32& a, const v_int8x32& b) +{ + __m256i half = _mm256_set1_epi8(0x7f); + half = _mm256_sad_epu8(_mm256_add_epi8(a.val, half), _mm256_add_epi8(b.val, half)); + __m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half)); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter))); +} +inline unsigned v_reduce_sad(const v_uint16x16& a, const v_uint16x16& b) +{ + v_uint32x8 l, h; + v_expand(v_add_wrap(a - b, b - a), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_int16x16& a, const v_int16x16& b) +{ + v_uint32x8 l, h; + v_expand(v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_uint32x8& a, const v_uint32x8& b) +{ + return v_reduce_sum(v_max(a, b) - v_min(a, b)); +} +inline unsigned v_reduce_sad(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 m = a < b; + return v_reduce_sum(v_reinterpret_as_u32(((a - b) ^ m) - m)); +} +inline float v_reduce_sad(const v_float32x8& a, const v_float32x8& b) +{ + return v_reduce_sum((a - b) & v_float32x8(_mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff)))); +} + +/** Popcount **/ +inline v_uint8x32 v_popcount(const v_uint8x32& a) +{ + __m256i _popcnt_table = _mm256_setr_epi8(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4); + __m256i _popcnt_mask = _mm256_set1_epi8(0x0F); + return v_uint8x32(_mm256_add_epi8(_mm256_shuffle_epi8(_popcnt_table, _mm256_and_si256( a.val , _popcnt_mask)), + _mm256_shuffle_epi8(_popcnt_table, _mm256_and_si256(_mm256_srli_epi16(a.val, 4), _popcnt_mask)))); +} +inline v_uint16x16 v_popcount(const v_uint16x16& a) +{ + v_uint8x32 p = v_popcount(v_reinterpret_as_u8(a)); + p += v_rotate_right<1>(p); + return v_reinterpret_as_u16(p) & v256_setall_u16(0x00ff); +} +inline v_uint32x8 v_popcount(const v_uint32x8& a) +{ + v_uint8x32 p = v_popcount(v_reinterpret_as_u8(a)); + p += v_rotate_right<1>(p); + p += v_rotate_right<2>(p); + return v_reinterpret_as_u32(p) & v256_setall_u32(0x000000ff); +} +inline v_uint64x4 v_popcount(const v_uint64x4& a) +{ + return v_uint64x4(_mm256_sad_epu8(v_popcount(v_reinterpret_as_u8(a)).val, _mm256_setzero_si256())); +} +inline v_uint8x32 v_popcount(const v_int8x32& a) +{ return v_popcount(v_reinterpret_as_u8(a)); } +inline v_uint16x16 v_popcount(const v_int16x16& a) +{ return v_popcount(v_reinterpret_as_u16(a)); } +inline v_uint32x8 v_popcount(const v_int32x8& a) +{ return v_popcount(v_reinterpret_as_u32(a)); } +inline v_uint64x4 v_popcount(const v_int64x4& a) +{ return v_popcount(v_reinterpret_as_u64(a)); } + +/** Mask **/ +inline int v_signmask(const v_int8x32& a) +{ return _mm256_movemask_epi8(a.val); } +inline int v_signmask(const v_uint8x32& a) +{ return v_signmask(v_reinterpret_as_s8(a)); } + +inline int v_signmask(const v_int16x16& a) +{ return v_signmask(v_pack(a, a)) & 0xFFFF; } +inline int v_signmask(const v_uint16x16& a) +{ return v_signmask(v_reinterpret_as_s16(a)); } + +inline int v_signmask(const v_float32x8& a) +{ return _mm256_movemask_ps(a.val); } +inline int v_signmask(const v_float64x4& a) +{ return _mm256_movemask_pd(a.val); } + +inline int v_signmask(const v_int32x8& a) +{ return v_signmask(v_reinterpret_as_f32(a)); } +inline int v_signmask(const v_uint32x8& a) +{ return v_signmask(v_reinterpret_as_f32(a)); } + +inline int v_signmask(const v_int64x4& a) +{ return v_signmask(v_reinterpret_as_f64(a)); } +inline int v_signmask(const v_uint64x4& a) +{ return v_signmask(v_reinterpret_as_f64(a)); } + +inline int v_scan_forward(const v_int8x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); } +inline int v_scan_forward(const v_uint8x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); } +inline int v_scan_forward(const v_int16x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; } +inline int v_scan_forward(const v_uint16x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; } +inline int v_scan_forward(const v_int32x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_uint32x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_float32x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_int64x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } +inline int v_scan_forward(const v_uint64x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } +inline int v_scan_forward(const v_float64x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } + +/** Checks **/ +#define OPENCV_HAL_IMPL_AVX_CHECK(_Tpvec, allmask) \ + inline bool v_check_all(const _Tpvec& a) { return v_signmask(a) == allmask; } \ + inline bool v_check_any(const _Tpvec& a) { return v_signmask(a) != 0; } +OPENCV_HAL_IMPL_AVX_CHECK(v_uint8x32, -1) +OPENCV_HAL_IMPL_AVX_CHECK(v_int8x32, -1) +OPENCV_HAL_IMPL_AVX_CHECK(v_uint32x8, 255) +OPENCV_HAL_IMPL_AVX_CHECK(v_int32x8, 255) +OPENCV_HAL_IMPL_AVX_CHECK(v_uint64x4, 15) +OPENCV_HAL_IMPL_AVX_CHECK(v_int64x4, 15) +OPENCV_HAL_IMPL_AVX_CHECK(v_float32x8, 255) +OPENCV_HAL_IMPL_AVX_CHECK(v_float64x4, 15) + +#define OPENCV_HAL_IMPL_AVX_CHECK_SHORT(_Tpvec) \ + inline bool v_check_all(const _Tpvec& a) { return (v_signmask(v_reinterpret_as_s8(a)) & 0xaaaaaaaa) == 0xaaaaaaaa; } \ + inline bool v_check_any(const _Tpvec& a) { return (v_signmask(v_reinterpret_as_s8(a)) & 0xaaaaaaaa) != 0; } +OPENCV_HAL_IMPL_AVX_CHECK_SHORT(v_uint16x16) +OPENCV_HAL_IMPL_AVX_CHECK_SHORT(v_int16x16) + +////////// Other math ///////// + +/** Some frequent operations **/ +#define OPENCV_HAL_IMPL_AVX_MULADD(_Tpvec, suffix) \ + inline _Tpvec v_fma(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ + { return _Tpvec(_mm256_fmadd_##suffix(a.val, b.val, c.val)); } \ + inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ + { return _Tpvec(_mm256_fmadd_##suffix(a.val, b.val, c.val)); } \ + inline _Tpvec v_sqrt(const _Tpvec& x) \ + { return _Tpvec(_mm256_sqrt_##suffix(x.val)); } \ + inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ + { return v_fma(a, a, b * b); } \ + inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ + { return v_sqrt(v_fma(a, a, b*b)); } + +OPENCV_HAL_IMPL_AVX_MULADD(v_float32x8, ps) +OPENCV_HAL_IMPL_AVX_MULADD(v_float64x4, pd) + +inline v_int32x8 v_fma(const v_int32x8& a, const v_int32x8& b, const v_int32x8& c) +{ + return a * b + c; +} + +inline v_int32x8 v_muladd(const v_int32x8& a, const v_int32x8& b, const v_int32x8& c) +{ + return v_fma(a, b, c); +} + +inline v_float32x8 v_invsqrt(const v_float32x8& x) +{ + v_float32x8 half = x * v256_setall_f32(0.5); + v_float32x8 t = v_float32x8(_mm256_rsqrt_ps(x.val)); + // todo: _mm256_fnmsub_ps + t *= v256_setall_f32(1.5) - ((t * t) * half); + return t; +} + +inline v_float64x4 v_invsqrt(const v_float64x4& x) +{ + return v256_setall_f64(1.) / v_sqrt(x); +} + +/** Absolute values **/ +#define OPENCV_HAL_IMPL_AVX_ABS(_Tpvec, suffix) \ + inline v_u##_Tpvec v_abs(const v_##_Tpvec& x) \ + { return v_u##_Tpvec(_mm256_abs_##suffix(x.val)); } + +OPENCV_HAL_IMPL_AVX_ABS(int8x32, epi8) +OPENCV_HAL_IMPL_AVX_ABS(int16x16, epi16) +OPENCV_HAL_IMPL_AVX_ABS(int32x8, epi32) + +inline v_float32x8 v_abs(const v_float32x8& x) +{ return x & v_float32x8(_mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff))); } +inline v_float64x4 v_abs(const v_float64x4& x) +{ return x & v_float64x4(_mm256_castsi256_pd(_mm256_srli_epi64(_mm256_set1_epi64x(-1), 1))); } + +/** Absolute difference **/ +inline v_uint8x32 v_absdiff(const v_uint8x32& a, const v_uint8x32& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint16x16 v_absdiff(const v_uint16x16& a, const v_uint16x16& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint32x8 v_absdiff(const v_uint32x8& a, const v_uint32x8& b) +{ return v_max(a, b) - v_min(a, b); } + +inline v_uint8x32 v_absdiff(const v_int8x32& a, const v_int8x32& b) +{ + v_int8x32 d = v_sub_wrap(a, b); + v_int8x32 m = a < b; + return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m)); +} + +inline v_uint16x16 v_absdiff(const v_int16x16& a, const v_int16x16& b) +{ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); } + +inline v_uint32x8 v_absdiff(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 d = a - b; + v_int32x8 m = a < b; + return v_reinterpret_as_u32((d ^ m) - m); +} + +inline v_float32x8 v_absdiff(const v_float32x8& a, const v_float32x8& b) +{ return v_abs(a - b); } + +inline v_float64x4 v_absdiff(const v_float64x4& a, const v_float64x4& b) +{ return v_abs(a - b); } + +/** Saturating absolute difference **/ +inline v_int8x32 v_absdiffs(const v_int8x32& a, const v_int8x32& b) +{ + v_int8x32 d = a - b; + v_int8x32 m = a < b; + return (d ^ m) - m; +} +inline v_int16x16 v_absdiffs(const v_int16x16& a, const v_int16x16& b) +{ return v_max(a, b) - v_min(a, b); } + +////////// Conversions ///////// + +/** Rounding **/ +inline v_int32x8 v_round(const v_float32x8& a) +{ return v_int32x8(_mm256_cvtps_epi32(a.val)); } + +inline v_int32x8 v_round(const v_float64x4& a) +{ return v_int32x8(_mm256_castsi128_si256(_mm256_cvtpd_epi32(a.val))); } + +inline v_int32x8 v_round(const v_float64x4& a, const v_float64x4& b) +{ + __m128i ai = _mm256_cvtpd_epi32(a.val), bi = _mm256_cvtpd_epi32(b.val); + return v_int32x8(_v256_combine(ai, bi)); +} + +inline v_int32x8 v_trunc(const v_float32x8& a) +{ return v_int32x8(_mm256_cvttps_epi32(a.val)); } + +inline v_int32x8 v_trunc(const v_float64x4& a) +{ return v_int32x8(_mm256_castsi128_si256(_mm256_cvttpd_epi32(a.val))); } + +inline v_int32x8 v_floor(const v_float32x8& a) +{ return v_int32x8(_mm256_cvttps_epi32(_mm256_floor_ps(a.val))); } + +inline v_int32x8 v_floor(const v_float64x4& a) +{ return v_trunc(v_float64x4(_mm256_floor_pd(a.val))); } + +inline v_int32x8 v_ceil(const v_float32x8& a) +{ return v_int32x8(_mm256_cvttps_epi32(_mm256_ceil_ps(a.val))); } + +inline v_int32x8 v_ceil(const v_float64x4& a) +{ return v_trunc(v_float64x4(_mm256_ceil_pd(a.val))); } + +/** To float **/ +inline v_float32x8 v_cvt_f32(const v_int32x8& a) +{ return v_float32x8(_mm256_cvtepi32_ps(a.val)); } + +inline v_float32x8 v_cvt_f32(const v_float64x4& a) +{ return v_float32x8(_mm256_castps128_ps256(_mm256_cvtpd_ps(a.val))); } + +inline v_float32x8 v_cvt_f32(const v_float64x4& a, const v_float64x4& b) +{ + __m128 af = _mm256_cvtpd_ps(a.val), bf = _mm256_cvtpd_ps(b.val); + return v_float32x8(_v256_combine(af, bf)); +} + +inline v_float64x4 v_cvt_f64(const v_int32x8& a) +{ return v_float64x4(_mm256_cvtepi32_pd(_v256_extract_low(a.val))); } + +inline v_float64x4 v_cvt_f64_high(const v_int32x8& a) +{ return v_float64x4(_mm256_cvtepi32_pd(_v256_extract_high(a.val))); } + +inline v_float64x4 v_cvt_f64(const v_float32x8& a) +{ return v_float64x4(_mm256_cvtps_pd(_v256_extract_low(a.val))); } + +inline v_float64x4 v_cvt_f64_high(const v_float32x8& a) +{ return v_float64x4(_mm256_cvtps_pd(_v256_extract_high(a.val))); } + +// from (Mysticial and wim) https://stackoverflow.com/q/41144668 +inline v_float64x4 v_cvt_f64(const v_int64x4& v) +{ + // constants encoded as floating-point + __m256i magic_i_lo = _mm256_set1_epi64x(0x4330000000000000); // 2^52 + __m256i magic_i_hi32 = _mm256_set1_epi64x(0x4530000080000000); // 2^84 + 2^63 + __m256i magic_i_all = _mm256_set1_epi64x(0x4530000080100000); // 2^84 + 2^63 + 2^52 + __m256d magic_d_all = _mm256_castsi256_pd(magic_i_all); + + // Blend the 32 lowest significant bits of v with magic_int_lo + __m256i v_lo = _mm256_blend_epi32(magic_i_lo, v.val, 0x55); + // Extract the 32 most significant bits of v + __m256i v_hi = _mm256_srli_epi64(v.val, 32); + // Flip the msb of v_hi and blend with 0x45300000 + v_hi = _mm256_xor_si256(v_hi, magic_i_hi32); + // Compute in double precision + __m256d v_hi_dbl = _mm256_sub_pd(_mm256_castsi256_pd(v_hi), magic_d_all); + // (v_hi - magic_d_all) + v_lo Do not assume associativity of floating point addition + __m256d result = _mm256_add_pd(v_hi_dbl, _mm256_castsi256_pd(v_lo)); + return v_float64x4(result); +} + +////////////// Lookup table access //////////////////// + +inline v_int8x32 v256_lut(const schar* tab, const int* idx) +{ + return v_int8x32(_mm256_setr_epi8(tab[idx[ 0]], tab[idx[ 1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]], + tab[idx[ 8]], tab[idx[ 9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]], + tab[idx[16]], tab[idx[17]], tab[idx[18]], tab[idx[19]], tab[idx[20]], tab[idx[21]], tab[idx[22]], tab[idx[23]], + tab[idx[24]], tab[idx[25]], tab[idx[26]], tab[idx[27]], tab[idx[28]], tab[idx[29]], tab[idx[30]], tab[idx[31]])); +} +inline v_int8x32 v256_lut_pairs(const schar* tab, const int* idx) +{ + return v_int8x32(_mm256_setr_epi16(*(const short*)(tab + idx[ 0]), *(const short*)(tab + idx[ 1]), *(const short*)(tab + idx[ 2]), *(const short*)(tab + idx[ 3]), + *(const short*)(tab + idx[ 4]), *(const short*)(tab + idx[ 5]), *(const short*)(tab + idx[ 6]), *(const short*)(tab + idx[ 7]), + *(const short*)(tab + idx[ 8]), *(const short*)(tab + idx[ 9]), *(const short*)(tab + idx[10]), *(const short*)(tab + idx[11]), + *(const short*)(tab + idx[12]), *(const short*)(tab + idx[13]), *(const short*)(tab + idx[14]), *(const short*)(tab + idx[15]))); +} +inline v_int8x32 v256_lut_quads(const schar* tab, const int* idx) +{ + return v_int8x32(_mm256_i32gather_epi32((const int*)tab, _mm256_loadu_si256((const __m256i*)idx), 1)); +} +inline v_uint8x32 v256_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut((const schar *)tab, idx)); } +inline v_uint8x32 v256_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut_pairs((const schar *)tab, idx)); } +inline v_uint8x32 v256_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut_quads((const schar *)tab, idx)); } + +inline v_int16x16 v256_lut(const short* tab, const int* idx) +{ + return v_int16x16(_mm256_setr_epi16(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]], + tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]])); +} +inline v_int16x16 v256_lut_pairs(const short* tab, const int* idx) +{ + return v_int16x16(_mm256_i32gather_epi32((const int*)tab, _mm256_loadu_si256((const __m256i*)idx), 2)); +} +inline v_int16x16 v256_lut_quads(const short* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int16x16(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 2));//Looks like intrinsic has wrong definition +#else + return v_int16x16(_mm256_i32gather_epi64((const int64*)tab, _mm_loadu_si128((const __m128i*)idx), 2)); +#endif +} +inline v_uint16x16 v256_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut((const short *)tab, idx)); } +inline v_uint16x16 v256_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut_pairs((const short *)tab, idx)); } +inline v_uint16x16 v256_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut_quads((const short *)tab, idx)); } + +inline v_int32x8 v256_lut(const int* tab, const int* idx) +{ + return v_int32x8(_mm256_i32gather_epi32(tab, _mm256_loadu_si256((const __m256i*)idx), 4)); +} +inline v_int32x8 v256_lut_pairs(const int* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int32x8(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 4)); +#else + return v_int32x8(_mm256_i32gather_epi64((const int64*)tab, _mm_loadu_si128((const __m128i*)idx), 4)); +#endif +} +inline v_int32x8 v256_lut_quads(const int* tab, const int* idx) +{ + return v_int32x8(_v256_combine(_mm_loadu_si128((const __m128i*)(tab + idx[0])), _mm_loadu_si128((const __m128i*)(tab + idx[1])))); +} +inline v_uint32x8 v256_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut((const int *)tab, idx)); } +inline v_uint32x8 v256_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut_pairs((const int *)tab, idx)); } +inline v_uint32x8 v256_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut_quads((const int *)tab, idx)); } + +inline v_int64x4 v256_lut(const int64* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int64x4(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 8)); +#else + return v_int64x4(_mm256_i32gather_epi64(tab, _mm_loadu_si128((const __m128i*)idx), 8)); +#endif +} +inline v_int64x4 v256_lut_pairs(const int64* tab, const int* idx) +{ + return v_int64x4(_v256_combine(_mm_loadu_si128((const __m128i*)(tab + idx[0])), _mm_loadu_si128((const __m128i*)(tab + idx[1])))); +} +inline v_uint64x4 v256_lut(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v256_lut((const int64 *)tab, idx)); } +inline v_uint64x4 v256_lut_pairs(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v256_lut_pairs((const int64 *)tab, idx)); } + +inline v_float32x8 v256_lut(const float* tab, const int* idx) +{ + return v_float32x8(_mm256_i32gather_ps(tab, _mm256_loadu_si256((const __m256i*)idx), 4)); +} +inline v_float32x8 v256_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v256_lut_pairs((const int *)tab, idx)); } +inline v_float32x8 v256_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v256_lut_quads((const int *)tab, idx)); } + +inline v_float64x4 v256_lut(const double* tab, const int* idx) +{ + return v_float64x4(_mm256_i32gather_pd(tab, _mm_loadu_si128((const __m128i*)idx), 8)); +} +inline v_float64x4 v256_lut_pairs(const double* tab, const int* idx) { return v_float64x4(_v256_combine(_mm_loadu_pd(tab + idx[0]), _mm_loadu_pd(tab + idx[1]))); } + +inline v_int32x8 v_lut(const int* tab, const v_int32x8& idxvec) +{ + return v_int32x8(_mm256_i32gather_epi32(tab, idxvec.val, 4)); +} + +inline v_uint32x8 v_lut(const unsigned* tab, const v_int32x8& idxvec) +{ + return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec)); +} + +inline v_float32x8 v_lut(const float* tab, const v_int32x8& idxvec) +{ + return v_float32x8(_mm256_i32gather_ps(tab, idxvec.val, 4)); +} + +inline v_float64x4 v_lut(const double* tab, const v_int32x8& idxvec) +{ + return v_float64x4(_mm256_i32gather_pd(tab, _mm256_castsi256_si128(idxvec.val), 8)); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x8& idxvec, v_float32x8& x, v_float32x8& y) +{ + int CV_DECL_ALIGNED(32) idx[8]; + v_store_aligned(idx, idxvec); + __m128 z = _mm_setzero_ps(); + __m128 xy01, xy45, xy23, xy67; + xy01 = _mm_loadl_pi(z, (const __m64*)(tab + idx[0])); + xy01 = _mm_loadh_pi(xy01, (const __m64*)(tab + idx[1])); + xy45 = _mm_loadl_pi(z, (const __m64*)(tab + idx[4])); + xy45 = _mm_loadh_pi(xy45, (const __m64*)(tab + idx[5])); + __m256 xy0145 = _v256_combine(xy01, xy45); + xy23 = _mm_loadl_pi(z, (const __m64*)(tab + idx[2])); + xy23 = _mm_loadh_pi(xy23, (const __m64*)(tab + idx[3])); + xy67 = _mm_loadl_pi(z, (const __m64*)(tab + idx[6])); + xy67 = _mm_loadh_pi(xy67, (const __m64*)(tab + idx[7])); + __m256 xy2367 = _v256_combine(xy23, xy67); + + __m256 xxyy0145 = _mm256_unpacklo_ps(xy0145, xy2367); + __m256 xxyy2367 = _mm256_unpackhi_ps(xy0145, xy2367); + + x = v_float32x8(_mm256_unpacklo_ps(xxyy0145, xxyy2367)); + y = v_float32x8(_mm256_unpackhi_ps(xxyy0145, xxyy2367)); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x8& idxvec, v_float64x4& x, v_float64x4& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_low(idx, idxvec); + __m128d xy0 = _mm_loadu_pd(tab + idx[0]); + __m128d xy2 = _mm_loadu_pd(tab + idx[2]); + __m128d xy1 = _mm_loadu_pd(tab + idx[1]); + __m128d xy3 = _mm_loadu_pd(tab + idx[3]); + __m256d xy02 = _v256_combine(xy0, xy2); + __m256d xy13 = _v256_combine(xy1, xy3); + + x = v_float64x4(_mm256_unpacklo_pd(xy02, xy13)); + y = v_float64x4(_mm256_unpackhi_pd(xy02, xy13)); +} + +inline v_int8x32 v_interleave_pairs(const v_int8x32& vec) +{ + return v_int8x32(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0d0e0c0b090a08, 0x0705060403010200, 0x0f0d0e0c0b090a08, 0x0705060403010200))); +} +inline v_uint8x32 v_interleave_pairs(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x32 v_interleave_quads(const v_int8x32& vec) +{ + return v_int8x32(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0b0e0a0d090c08, 0x0703060205010400, 0x0f0b0e0a0d090c08, 0x0703060205010400))); +} +inline v_uint8x32 v_interleave_quads(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x16 v_interleave_pairs(const v_int16x16& vec) +{ + return v_int16x16(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0e0b0a0d0c0908, 0x0706030205040100, 0x0f0e0b0a0d0c0908, 0x0706030205040100))); +} +inline v_uint16x16 v_interleave_pairs(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x16 v_interleave_quads(const v_int16x16& vec) +{ + return v_int16x16(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0e07060d0c0504, 0x0b0a030209080100, 0x0f0e07060d0c0504, 0x0b0a030209080100))); +} +inline v_uint16x16 v_interleave_quads(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x8 v_interleave_pairs(const v_int32x8& vec) +{ + return v_int32x8(_mm256_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0))); +} +inline v_uint32x8 v_interleave_pairs(const v_uint32x8& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x8 v_interleave_pairs(const v_float32x8& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x32 v_pack_triplets(const v_int8x32& vec) +{ + return v_int8x32(_mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(vec.val, _mm256_broadcastsi128_si256(_mm_set_epi64x(0xffffff0f0e0d0c0a, 0x0908060504020100))), + _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} +inline v_uint8x32 v_pack_triplets(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x16 v_pack_triplets(const v_int16x16& vec) +{ + return v_int16x16(_mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(vec.val, _mm256_broadcastsi128_si256(_mm_set_epi64x(0xffff0f0e0d0c0b0a, 0x0908050403020100))), + _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} +inline v_uint16x16 v_pack_triplets(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x8 v_pack_triplets(const v_int32x8& vec) +{ + return v_int32x8(_mm256_permutevar8x32_epi32(vec.val, _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} +inline v_uint32x8 v_pack_triplets(const v_uint32x8& vec) { return v_reinterpret_as_u32(v_pack_triplets(v_reinterpret_as_s32(vec))); } +inline v_float32x8 v_pack_triplets(const v_float32x8& vec) +{ + return v_float32x8(_mm256_permutevar8x32_ps(vec.val, _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000))); +} + +////////// Matrix operations ///////// + +//////// Dot Product //////// + +// 16 >> 32 +inline v_int32x8 v_dotprod(const v_int16x16& a, const v_int16x16& b) +{ return v_int32x8(_mm256_madd_epi16(a.val, b.val)); } +inline v_int32x8 v_dotprod(const v_int16x16& a, const v_int16x16& b, const v_int32x8& c) +{ return v_dotprod(a, b) + c; } + +// 32 >> 64 +inline v_int64x4 v_dotprod(const v_int32x8& a, const v_int32x8& b) +{ + __m256i even = _mm256_mul_epi32(a.val, b.val); + __m256i odd = _mm256_mul_epi32(_mm256_srli_epi64(a.val, 32), _mm256_srli_epi64(b.val, 32)); + return v_int64x4(_mm256_add_epi64(even, odd)); +} +inline v_int64x4 v_dotprod(const v_int32x8& a, const v_int32x8& b, const v_int64x4& c) +{ return v_dotprod(a, b) + c; } + +// 8 >> 32 +inline v_uint32x8 v_dotprod_expand(const v_uint8x32& a, const v_uint8x32& b) +{ + __m256i even_m = _mm256_set1_epi32(0xFF00FF00); + __m256i even_a = _mm256_blendv_epi8(a.val, _mm256_setzero_si256(), even_m); + __m256i odd_a = _mm256_srli_epi16(a.val, 8); + + __m256i even_b = _mm256_blendv_epi8(b.val, _mm256_setzero_si256(), even_m); + __m256i odd_b = _mm256_srli_epi16(b.val, 8); + + __m256i prod0 = _mm256_madd_epi16(even_a, even_b); + __m256i prod1 = _mm256_madd_epi16(odd_a, odd_b); + return v_uint32x8(_mm256_add_epi32(prod0, prod1)); +} +inline v_uint32x8 v_dotprod_expand(const v_uint8x32& a, const v_uint8x32& b, const v_uint32x8& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int32x8 v_dotprod_expand(const v_int8x32& a, const v_int8x32& b) +{ + __m256i even_a = _mm256_srai_epi16(_mm256_bslli_epi128(a.val, 1), 8); + __m256i odd_a = _mm256_srai_epi16(a.val, 8); + + __m256i even_b = _mm256_srai_epi16(_mm256_bslli_epi128(b.val, 1), 8); + __m256i odd_b = _mm256_srai_epi16(b.val, 8); + + __m256i prod0 = _mm256_madd_epi16(even_a, even_b); + __m256i prod1 = _mm256_madd_epi16(odd_a, odd_b); + return v_int32x8(_mm256_add_epi32(prod0, prod1)); +} +inline v_int32x8 v_dotprod_expand(const v_int8x32& a, const v_int8x32& b, const v_int32x8& c) +{ return v_dotprod_expand(a, b) + c; } + +// 16 >> 64 +inline v_uint64x4 v_dotprod_expand(const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i mullo = _mm256_mullo_epi16(a.val, b.val); + __m256i mulhi = _mm256_mulhi_epu16(a.val, b.val); + __m256i mul0 = _mm256_unpacklo_epi16(mullo, mulhi); + __m256i mul1 = _mm256_unpackhi_epi16(mullo, mulhi); + + __m256i p02 = _mm256_blend_epi32(mul0, _mm256_setzero_si256(), 0xAA); + __m256i p13 = _mm256_srli_epi64(mul0, 32); + __m256i p46 = _mm256_blend_epi32(mul1, _mm256_setzero_si256(), 0xAA); + __m256i p57 = _mm256_srli_epi64(mul1, 32); + + __m256i p15_ = _mm256_add_epi64(p02, p13); + __m256i p9d_ = _mm256_add_epi64(p46, p57); + + return v_uint64x4(_mm256_add_epi64( + _mm256_unpacklo_epi64(p15_, p9d_), + _mm256_unpackhi_epi64(p15_, p9d_) + )); +} +inline v_uint64x4 v_dotprod_expand(const v_uint16x16& a, const v_uint16x16& b, const v_uint64x4& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int64x4 v_dotprod_expand(const v_int16x16& a, const v_int16x16& b) +{ + __m256i prod = _mm256_madd_epi16(a.val, b.val); + __m256i sign = _mm256_srai_epi32(prod, 31); + + __m256i lo = _mm256_unpacklo_epi32(prod, sign); + __m256i hi = _mm256_unpackhi_epi32(prod, sign); + + return v_int64x4(_mm256_add_epi64( + _mm256_unpacklo_epi64(lo, hi), + _mm256_unpackhi_epi64(lo, hi) + )); +} +inline v_int64x4 v_dotprod_expand(const v_int16x16& a, const v_int16x16& b, const v_int64x4& c) +{ return v_dotprod_expand(a, b) + c; } + +// 32 >> 64f +inline v_float64x4 v_dotprod_expand(const v_int32x8& a, const v_int32x8& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x4 v_dotprod_expand(const v_int32x8& a, const v_int32x8& b, const v_float64x4& c) +{ return v_dotprod_expand(a, b) + c; } + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x8 v_dotprod_fast(const v_int16x16& a, const v_int16x16& b) +{ return v_dotprod(a, b); } +inline v_int32x8 v_dotprod_fast(const v_int16x16& a, const v_int16x16& b, const v_int32x8& c) +{ return v_dotprod(a, b, c); } + +// 32 >> 64 +inline v_int64x4 v_dotprod_fast(const v_int32x8& a, const v_int32x8& b) +{ return v_dotprod(a, b); } +inline v_int64x4 v_dotprod_fast(const v_int32x8& a, const v_int32x8& b, const v_int64x4& c) +{ return v_dotprod(a, b, c); } + +// 8 >> 32 +inline v_uint32x8 v_dotprod_expand_fast(const v_uint8x32& a, const v_uint8x32& b) +{ return v_dotprod_expand(a, b); } +inline v_uint32x8 v_dotprod_expand_fast(const v_uint8x32& a, const v_uint8x32& b, const v_uint32x8& c) +{ return v_dotprod_expand(a, b, c); } + +inline v_int32x8 v_dotprod_expand_fast(const v_int8x32& a, const v_int8x32& b) +{ return v_dotprod_expand(a, b); } +inline v_int32x8 v_dotprod_expand_fast(const v_int8x32& a, const v_int8x32& b, const v_int32x8& c) +{ return v_dotprod_expand(a, b, c); } + +// 16 >> 64 +inline v_uint64x4 v_dotprod_expand_fast(const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i mullo = _mm256_mullo_epi16(a.val, b.val); + __m256i mulhi = _mm256_mulhi_epu16(a.val, b.val); + __m256i mul0 = _mm256_unpacklo_epi16(mullo, mulhi); + __m256i mul1 = _mm256_unpackhi_epi16(mullo, mulhi); + + __m256i p02 = _mm256_blend_epi32(mul0, _mm256_setzero_si256(), 0xAA); + __m256i p13 = _mm256_srli_epi64(mul0, 32); + __m256i p46 = _mm256_blend_epi32(mul1, _mm256_setzero_si256(), 0xAA); + __m256i p57 = _mm256_srli_epi64(mul1, 32); + + __m256i p15_ = _mm256_add_epi64(p02, p13); + __m256i p9d_ = _mm256_add_epi64(p46, p57); + + return v_uint64x4(_mm256_add_epi64(p15_, p9d_)); +} +inline v_uint64x4 v_dotprod_expand_fast(const v_uint16x16& a, const v_uint16x16& b, const v_uint64x4& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +inline v_int64x4 v_dotprod_expand_fast(const v_int16x16& a, const v_int16x16& b) +{ + __m256i prod = _mm256_madd_epi16(a.val, b.val); + __m256i sign = _mm256_srai_epi32(prod, 31); + __m256i lo = _mm256_unpacklo_epi32(prod, sign); + __m256i hi = _mm256_unpackhi_epi32(prod, sign); + return v_int64x4(_mm256_add_epi64(lo, hi)); +} +inline v_int64x4 v_dotprod_expand_fast(const v_int16x16& a, const v_int16x16& b, const v_int64x4& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +// 32 >> 64f +inline v_float64x4 v_dotprod_expand_fast(const v_int32x8& a, const v_int32x8& b) +{ return v_dotprod_expand(a, b); } +inline v_float64x4 v_dotprod_expand_fast(const v_int32x8& a, const v_int32x8& b, const v_float64x4& c) +{ return v_dotprod_expand(a, b, c); } + +#define OPENCV_HAL_AVX_SPLAT2_PS(a, im) \ + v_float32x8(_mm256_permute_ps(a.val, _MM_SHUFFLE(im, im, im, im))) + +inline v_float32x8 v_matmul(const v_float32x8& v, const v_float32x8& m0, + const v_float32x8& m1, const v_float32x8& m2, + const v_float32x8& m3) +{ + v_float32x8 v04 = OPENCV_HAL_AVX_SPLAT2_PS(v, 0); + v_float32x8 v15 = OPENCV_HAL_AVX_SPLAT2_PS(v, 1); + v_float32x8 v26 = OPENCV_HAL_AVX_SPLAT2_PS(v, 2); + v_float32x8 v37 = OPENCV_HAL_AVX_SPLAT2_PS(v, 3); + return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, v37 * m3))); +} + +inline v_float32x8 v_matmuladd(const v_float32x8& v, const v_float32x8& m0, + const v_float32x8& m1, const v_float32x8& m2, + const v_float32x8& a) +{ + v_float32x8 v04 = OPENCV_HAL_AVX_SPLAT2_PS(v, 0); + v_float32x8 v15 = OPENCV_HAL_AVX_SPLAT2_PS(v, 1); + v_float32x8 v26 = OPENCV_HAL_AVX_SPLAT2_PS(v, 2); + return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, a))); +} + +#define OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \ + inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \ + { \ + __m256i t0 = cast_from(_mm256_unpacklo_##suffix(a0.val, a1.val)); \ + __m256i t1 = cast_from(_mm256_unpacklo_##suffix(a2.val, a3.val)); \ + __m256i t2 = cast_from(_mm256_unpackhi_##suffix(a0.val, a1.val)); \ + __m256i t3 = cast_from(_mm256_unpackhi_##suffix(a2.val, a3.val)); \ + b0.val = cast_to(_mm256_unpacklo_epi64(t0, t1)); \ + b1.val = cast_to(_mm256_unpackhi_epi64(t0, t1)); \ + b2.val = cast_to(_mm256_unpacklo_epi64(t2, t3)); \ + b3.val = cast_to(_mm256_unpackhi_epi64(t2, t3)); \ + } + +OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_uint32x8, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_int32x8, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_float32x8, ps, _mm256_castps_si256, _mm256_castsi256_ps) + +//////////////// Value reordering /////////////// + +/* Expand */ +#define OPENCV_HAL_IMPL_AVX_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \ + inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ + { \ + b0.val = intrin(_v256_extract_low(a.val)); \ + b1.val = intrin(_v256_extract_high(a.val)); \ + } \ + inline _Tpwvec v_expand_low(const _Tpvec& a) \ + { return _Tpwvec(intrin(_v256_extract_low(a.val))); } \ + inline _Tpwvec v_expand_high(const _Tpvec& a) \ + { return _Tpwvec(intrin(_v256_extract_high(a.val))); } \ + inline _Tpwvec v256_load_expand(const _Tp* ptr) \ + { \ + __m128i a = _mm_loadu_si128((const __m128i*)ptr); \ + return _Tpwvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_AVX_EXPAND(v_uint8x32, v_uint16x16, uchar, _mm256_cvtepu8_epi16) +OPENCV_HAL_IMPL_AVX_EXPAND(v_int8x32, v_int16x16, schar, _mm256_cvtepi8_epi16) +OPENCV_HAL_IMPL_AVX_EXPAND(v_uint16x16, v_uint32x8, ushort, _mm256_cvtepu16_epi32) +OPENCV_HAL_IMPL_AVX_EXPAND(v_int16x16, v_int32x8, short, _mm256_cvtepi16_epi32) +OPENCV_HAL_IMPL_AVX_EXPAND(v_uint32x8, v_uint64x4, unsigned, _mm256_cvtepu32_epi64) +OPENCV_HAL_IMPL_AVX_EXPAND(v_int32x8, v_int64x4, int, _mm256_cvtepi32_epi64) + +#define OPENCV_HAL_IMPL_AVX_EXPAND_Q(_Tpvec, _Tp, intrin) \ + inline _Tpvec v256_load_expand_q(const _Tp* ptr) \ + { \ + __m128i a = _mm_loadl_epi64((const __m128i*)ptr); \ + return _Tpvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_AVX_EXPAND_Q(v_uint32x8, uchar, _mm256_cvtepu8_epi32) +OPENCV_HAL_IMPL_AVX_EXPAND_Q(v_int32x8, schar, _mm256_cvtepi8_epi32) + +/* pack */ +// 16 +inline v_int8x32 v_pack(const v_int16x16& a, const v_int16x16& b) +{ return v_int8x32(_v256_shuffle_odd_64(_mm256_packs_epi16(a.val, b.val))); } + +inline v_uint8x32 v_pack(const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i t = _mm256_set1_epi16(255); + __m256i a1 = _mm256_min_epu16(a.val, t); + __m256i b1 = _mm256_min_epu16(b.val, t); + return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a1, b1))); +} + +inline v_uint8x32 v_pack_u(const v_int16x16& a, const v_int16x16& b) +{ + return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a.val, b.val))); +} + +inline void v_pack_store(schar* ptr, const v_int16x16& a) +{ v_store_low(ptr, v_pack(a, a)); } + +inline void v_pack_store(uchar* ptr, const v_uint16x16& a) +{ + const __m256i m = _mm256_set1_epi16(255); + __m256i am = _mm256_min_epu16(a.val, m); + am = _v256_shuffle_odd_64(_mm256_packus_epi16(am, am)); + v_store_low(ptr, v_uint8x32(am)); +} + +inline void v_pack_u_store(uchar* ptr, const v_int16x16& a) +{ v_store_low(ptr, v_pack_u(a, a)); } + +template inline +v_uint8x32 v_rshr_pack(const v_uint16x16& a, const v_uint16x16& b) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + v_uint16x16 delta = v256_setall_u16((short)(1 << (n-1))); + return v_pack_u(v_reinterpret_as_s16((a + delta) >> n), + v_reinterpret_as_s16((b + delta) >> n)); +} + +template inline +void v_rshr_pack_store(uchar* ptr, const v_uint16x16& a) +{ + v_uint16x16 delta = v256_setall_u16((short)(1 << (n-1))); + v_pack_u_store(ptr, v_reinterpret_as_s16((a + delta) >> n)); +} + +template inline +v_uint8x32 v_rshr_pack_u(const v_int16x16& a, const v_int16x16& b) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + return v_pack_u((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_u_store(uchar* ptr, const v_int16x16& a) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + v_pack_u_store(ptr, (a + delta) >> n); +} + +template inline +v_int8x32 v_rshr_pack(const v_int16x16& a, const v_int16x16& b) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(schar* ptr, const v_int16x16& a) +{ + v_int16x16 delta = v256_setall_s16((short)(1 << (n-1))); + v_pack_store(ptr, (a + delta) >> n); +} + +// 32 +inline v_int16x16 v_pack(const v_int32x8& a, const v_int32x8& b) +{ return v_int16x16(_v256_shuffle_odd_64(_mm256_packs_epi32(a.val, b.val))); } + +inline v_uint16x16 v_pack(const v_uint32x8& a, const v_uint32x8& b) +{ return v_uint16x16(_v256_shuffle_odd_64(_v256_packs_epu32(a.val, b.val))); } + +inline v_uint16x16 v_pack_u(const v_int32x8& a, const v_int32x8& b) +{ return v_uint16x16(_v256_shuffle_odd_64(_mm256_packus_epi32(a.val, b.val))); } + +inline void v_pack_store(short* ptr, const v_int32x8& a) +{ v_store_low(ptr, v_pack(a, a)); } + +inline void v_pack_store(ushort* ptr, const v_uint32x8& a) +{ + const __m256i m = _mm256_set1_epi32(65535); + __m256i am = _mm256_min_epu32(a.val, m); + am = _v256_shuffle_odd_64(_mm256_packus_epi32(am, am)); + v_store_low(ptr, v_uint16x16(am)); +} + +inline void v_pack_u_store(ushort* ptr, const v_int32x8& a) +{ v_store_low(ptr, v_pack_u(a, a)); } + + +template inline +v_uint16x16 v_rshr_pack(const v_uint32x8& a, const v_uint32x8& b) +{ + // we assume that n > 0, and so the shifted 32-bit values can be treated as signed numbers. + v_uint32x8 delta = v256_setall_u32(1 << (n-1)); + return v_pack_u(v_reinterpret_as_s32((a + delta) >> n), + v_reinterpret_as_s32((b + delta) >> n)); +} + +template inline +void v_rshr_pack_store(ushort* ptr, const v_uint32x8& a) +{ + v_uint32x8 delta = v256_setall_u32(1 << (n-1)); + v_pack_u_store(ptr, v_reinterpret_as_s32((a + delta) >> n)); +} + +template inline +v_uint16x16 v_rshr_pack_u(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + return v_pack_u((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_u_store(ushort* ptr, const v_int32x8& a) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + v_pack_u_store(ptr, (a + delta) >> n); +} + +template inline +v_int16x16 v_rshr_pack(const v_int32x8& a, const v_int32x8& b) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(short* ptr, const v_int32x8& a) +{ + v_int32x8 delta = v256_setall_s32(1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +// 64 +// Non-saturating pack +inline v_uint32x8 v_pack(const v_uint64x4& a, const v_uint64x4& b) +{ + __m256i a0 = _mm256_shuffle_epi32(a.val, _MM_SHUFFLE(0, 0, 2, 0)); + __m256i b0 = _mm256_shuffle_epi32(b.val, _MM_SHUFFLE(0, 0, 2, 0)); + __m256i ab = _mm256_unpacklo_epi64(a0, b0); // a0, a1, b0, b1, a2, a3, b2, b3 + return v_uint32x8(_v256_shuffle_odd_64(ab)); +} + +inline v_int32x8 v_pack(const v_int64x4& a, const v_int64x4& b) +{ return v_reinterpret_as_s32(v_pack(v_reinterpret_as_u64(a), v_reinterpret_as_u64(b))); } + +inline void v_pack_store(unsigned* ptr, const v_uint64x4& a) +{ + __m256i a0 = _mm256_shuffle_epi32(a.val, _MM_SHUFFLE(0, 0, 2, 0)); + v_store_low(ptr, v_uint32x8(_v256_shuffle_odd_64(a0))); +} + +inline void v_pack_store(int* ptr, const v_int64x4& b) +{ v_pack_store((unsigned*)ptr, v_reinterpret_as_u64(b)); } + +template inline +v_uint32x8 v_rshr_pack(const v_uint64x4& a, const v_uint64x4& b) +{ + v_uint64x4 delta = v256_setall_u64((uint64)1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(unsigned* ptr, const v_uint64x4& a) +{ + v_uint64x4 delta = v256_setall_u64((uint64)1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +template inline +v_int32x8 v_rshr_pack(const v_int64x4& a, const v_int64x4& b) +{ + v_int64x4 delta = v256_setall_s64((int64)1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(int* ptr, const v_int64x4& a) +{ + v_int64x4 delta = v256_setall_s64((int64)1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +// pack boolean +inline v_uint8x32 v_pack_b(const v_uint16x16& a, const v_uint16x16& b) +{ + __m256i ab = _mm256_packs_epi16(a.val, b.val); + return v_uint8x32(_v256_shuffle_odd_64(ab)); +} + +inline v_uint8x32 v_pack_b(const v_uint32x8& a, const v_uint32x8& b, + const v_uint32x8& c, const v_uint32x8& d) +{ + __m256i ab = _mm256_packs_epi32(a.val, b.val); + __m256i cd = _mm256_packs_epi32(c.val, d.val); + + __m256i abcd = _v256_shuffle_odd_64(_mm256_packs_epi16(ab, cd)); + return v_uint8x32(_mm256_shuffle_epi32(abcd, _MM_SHUFFLE(3, 1, 2, 0))); +} + +inline v_uint8x32 v_pack_b(const v_uint64x4& a, const v_uint64x4& b, const v_uint64x4& c, + const v_uint64x4& d, const v_uint64x4& e, const v_uint64x4& f, + const v_uint64x4& g, const v_uint64x4& h) +{ + __m256i ab = _mm256_packs_epi32(a.val, b.val); + __m256i cd = _mm256_packs_epi32(c.val, d.val); + __m256i ef = _mm256_packs_epi32(e.val, f.val); + __m256i gh = _mm256_packs_epi32(g.val, h.val); + + __m256i abcd = _mm256_packs_epi32(ab, cd); + __m256i efgh = _mm256_packs_epi32(ef, gh); + __m256i pkall = _v256_shuffle_odd_64(_mm256_packs_epi16(abcd, efgh)); + + __m256i rev = _mm256_alignr_epi8(pkall, pkall, 8); + return v_uint8x32(_mm256_unpacklo_epi16(pkall, rev)); +} + +/* Recombine */ +// its up there with load and store operations + +/* Extract */ +#define OPENCV_HAL_IMPL_AVX_EXTRACT(_Tpvec) \ + template \ + inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \ + { return v_rotate_right(a, b); } + +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint8x32) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int8x32) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint16x16) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int16x16) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint32x8) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int32x8) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint64x4) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_int64x4) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_float32x8) +OPENCV_HAL_IMPL_AVX_EXTRACT(v_float64x4) + +template +inline uchar v_extract_n(v_uint8x32 a) +{ + return (uchar)_v256_extract_epi8(a.val); +} + +template +inline schar v_extract_n(v_int8x32 a) +{ + return (schar)v_extract_n(v_reinterpret_as_u8(a)); +} + +template +inline ushort v_extract_n(v_uint16x16 a) +{ + return (ushort)_v256_extract_epi16(a.val); +} + +template +inline short v_extract_n(v_int16x16 a) +{ + return (short)v_extract_n(v_reinterpret_as_u16(a)); +} + +template +inline uint v_extract_n(v_uint32x8 a) +{ + return (uint)_v256_extract_epi32(a.val); +} + +template +inline int v_extract_n(v_int32x8 a) +{ + return (int)v_extract_n(v_reinterpret_as_u32(a)); +} + +template +inline uint64 v_extract_n(v_uint64x4 a) +{ + return (uint64)_v256_extract_epi64(a.val); +} + +template +inline int64 v_extract_n(v_int64x4 v) +{ + return (int64)v_extract_n(v_reinterpret_as_u64(v)); +} + +template +inline float v_extract_n(v_float32x8 v) +{ + union { uint iv; float fv; } d; + d.iv = v_extract_n(v_reinterpret_as_u32(v)); + return d.fv; +} + +template +inline double v_extract_n(v_float64x4 v) +{ + union { uint64 iv; double dv; } d; + d.iv = v_extract_n(v_reinterpret_as_u64(v)); + return d.dv; +} + +template +inline v_uint32x8 v_broadcast_element(v_uint32x8 a) +{ + static const __m256i perm = _mm256_set1_epi32((char)i); + return v_uint32x8(_mm256_permutevar8x32_epi32(a.val, perm)); +} + +template +inline v_int32x8 v_broadcast_element(const v_int32x8 &a) +{ return v_reinterpret_as_s32(v_broadcast_element(v_reinterpret_as_u32(a))); } + +template +inline v_float32x8 v_broadcast_element(const v_float32x8 &a) +{ return v_reinterpret_as_f32(v_broadcast_element(v_reinterpret_as_u32(a))); } + + +///////////////////// load deinterleave ///////////////////////////// + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + + const __m256i sh = _mm256_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15, + 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15); + __m256i p0 = _mm256_shuffle_epi8(ab0, sh); + __m256i p1 = _mm256_shuffle_epi8(ab1, sh); + __m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint8x32(a0); + b = v_uint8x32(b0); +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + + const __m256i sh = _mm256_setr_epi8(0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15, + 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15); + __m256i p0 = _mm256_shuffle_epi8(ab0, sh); + __m256i p1 = _mm256_shuffle_epi8(ab1, sh); + __m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint16x16(a0); + b = v_uint16x16(b0); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + + const int sh = 0+2*4+1*16+3*64; + __m256i p0 = _mm256_shuffle_epi32(ab0, sh); + __m256i p1 = _mm256_shuffle_epi32(ab1, sh); + __m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint32x8(a0); + b = v_uint32x8(b0); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b ) +{ + __m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 4)); + + __m256i pl = _mm256_permute2x128_si256(ab0, ab1, 0 + 2*16); + __m256i ph = _mm256_permute2x128_si256(ab0, ab1, 1 + 3*16); + __m256i a0 = _mm256_unpacklo_epi64(pl, ph); + __m256i b0 = _mm256_unpackhi_epi64(pl, ph); + a = v_uint64x4(a0); + b = v_uint64x4(b0); +} + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b, v_uint8x32& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 64)); + + __m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16); + __m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16); + + const __m256i m0 = _mm256_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, + 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, + -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1); + + __m256i b0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_low, s02_high, m0), bgr1, m1); + __m256i g0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_high, s02_low, m1), bgr1, m0); + __m256i r0 = _mm256_blendv_epi8(_mm256_blendv_epi8(bgr1, s02_low, m0), s02_high, m1); + + const __m256i + sh_b = _mm256_setr_epi8(0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13, + 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13), + sh_g = _mm256_setr_epi8(1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, + 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14), + sh_r = _mm256_setr_epi8(2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, + 2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15); + b0 = _mm256_shuffle_epi8(b0, sh_b); + g0 = _mm256_shuffle_epi8(g0, sh_g); + r0 = _mm256_shuffle_epi8(r0, sh_r); + + a = v_uint8x32(b0); + b = v_uint8x32(g0); + c = v_uint8x32(r0); +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b, v_uint16x16& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + + __m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16); + __m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16); + + const __m256i m0 = _mm256_setr_epi8(0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, + 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, + -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0); + __m256i b0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_low, s02_high, m0), bgr1, m1); + __m256i g0 = _mm256_blendv_epi8(_mm256_blendv_epi8(bgr1, s02_low, m0), s02_high, m1); + __m256i r0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_high, s02_low, m1), bgr1, m0); + const __m256i sh_b = _mm256_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11, + 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m256i sh_g = _mm256_setr_epi8(2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, + 2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13); + const __m256i sh_r = _mm256_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, + 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + b0 = _mm256_shuffle_epi8(b0, sh_b); + g0 = _mm256_shuffle_epi8(g0, sh_g); + r0 = _mm256_shuffle_epi8(r0, sh_r); + + a = v_uint16x16(b0); + b = v_uint16x16(g0); + c = v_uint16x16(r0); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b, v_uint32x8& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + + __m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16); + __m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16); + + __m256i b0 = _mm256_blend_epi32(_mm256_blend_epi32(s02_low, s02_high, 0x24), bgr1, 0x92); + __m256i g0 = _mm256_blend_epi32(_mm256_blend_epi32(s02_high, s02_low, 0x92), bgr1, 0x24); + __m256i r0 = _mm256_blend_epi32(_mm256_blend_epi32(bgr1, s02_low, 0x24), s02_high, 0x92); + + b0 = _mm256_shuffle_epi32(b0, 0x6c); + g0 = _mm256_shuffle_epi32(g0, 0xb1); + r0 = _mm256_shuffle_epi32(r0, 0xc6); + + a = v_uint32x8(b0); + b = v_uint32x8(g0); + c = v_uint32x8(r0); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b, v_uint64x4& c ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 4)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + + __m256i s01 = _mm256_blend_epi32(bgr0, bgr1, 0xf0); + __m256i s12 = _mm256_blend_epi32(bgr1, bgr2, 0xf0); + __m256i s20r = _mm256_permute4x64_epi64(_mm256_blend_epi32(bgr2, bgr0, 0xf0), 0x1b); + __m256i b0 = _mm256_unpacklo_epi64(s01, s20r); + __m256i g0 = _mm256_alignr_epi8(s12, s01, 8); + __m256i r0 = _mm256_unpackhi_epi64(s20r, s12); + + a = v_uint64x4(b0); + b = v_uint64x4(g0); + c = v_uint64x4(r0); +} + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b, v_uint8x32& c, v_uint8x32& d ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 64)); + __m256i bgr3 = _mm256_loadu_si256((const __m256i*)(ptr + 96)); + const __m256i sh = _mm256_setr_epi8(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, + 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15); + + __m256i p0 = _mm256_shuffle_epi8(bgr0, sh); + __m256i p1 = _mm256_shuffle_epi8(bgr1, sh); + __m256i p2 = _mm256_shuffle_epi8(bgr2, sh); + __m256i p3 = _mm256_shuffle_epi8(bgr3, sh); + + __m256i p01l = _mm256_unpacklo_epi32(p0, p1); + __m256i p01h = _mm256_unpackhi_epi32(p0, p1); + __m256i p23l = _mm256_unpacklo_epi32(p2, p3); + __m256i p23h = _mm256_unpackhi_epi32(p2, p3); + + __m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16); + __m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16); + __m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16); + __m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi32(pll, plh); + __m256i g0 = _mm256_unpackhi_epi32(pll, plh); + __m256i r0 = _mm256_unpacklo_epi32(phl, phh); + __m256i a0 = _mm256_unpackhi_epi32(phl, phh); + + a = v_uint8x32(b0); + b = v_uint8x32(g0); + c = v_uint8x32(r0); + d = v_uint8x32(a0); +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b, v_uint16x16& c, v_uint16x16& d ) +{ + __m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + __m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 32)); + __m256i bgr3 = _mm256_loadu_si256((const __m256i*)(ptr + 48)); + const __m256i sh = _mm256_setr_epi8(0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15, + 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15); + __m256i p0 = _mm256_shuffle_epi8(bgr0, sh); + __m256i p1 = _mm256_shuffle_epi8(bgr1, sh); + __m256i p2 = _mm256_shuffle_epi8(bgr2, sh); + __m256i p3 = _mm256_shuffle_epi8(bgr3, sh); + + __m256i p01l = _mm256_unpacklo_epi32(p0, p1); + __m256i p01h = _mm256_unpackhi_epi32(p0, p1); + __m256i p23l = _mm256_unpacklo_epi32(p2, p3); + __m256i p23h = _mm256_unpackhi_epi32(p2, p3); + + __m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16); + __m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16); + __m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16); + __m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi32(pll, plh); + __m256i g0 = _mm256_unpackhi_epi32(pll, plh); + __m256i r0 = _mm256_unpacklo_epi32(phl, phh); + __m256i a0 = _mm256_unpackhi_epi32(phl, phh); + + a = v_uint16x16(b0); + b = v_uint16x16(g0); + c = v_uint16x16(r0); + d = v_uint16x16(a0); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b, v_uint32x8& c, v_uint32x8& d ) +{ + __m256i p0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i p1 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + __m256i p2 = _mm256_loadu_si256((const __m256i*)(ptr + 16)); + __m256i p3 = _mm256_loadu_si256((const __m256i*)(ptr + 24)); + + __m256i p01l = _mm256_unpacklo_epi32(p0, p1); + __m256i p01h = _mm256_unpackhi_epi32(p0, p1); + __m256i p23l = _mm256_unpacklo_epi32(p2, p3); + __m256i p23h = _mm256_unpackhi_epi32(p2, p3); + + __m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16); + __m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16); + __m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16); + __m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi32(pll, plh); + __m256i g0 = _mm256_unpackhi_epi32(pll, plh); + __m256i r0 = _mm256_unpacklo_epi32(phl, phh); + __m256i a0 = _mm256_unpackhi_epi32(phl, phh); + + a = v_uint32x8(b0); + b = v_uint32x8(g0); + c = v_uint32x8(r0); + d = v_uint32x8(a0); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b, v_uint64x4& c, v_uint64x4& d ) +{ + __m256i bgra0 = _mm256_loadu_si256((const __m256i*)ptr); + __m256i bgra1 = _mm256_loadu_si256((const __m256i*)(ptr + 4)); + __m256i bgra2 = _mm256_loadu_si256((const __m256i*)(ptr + 8)); + __m256i bgra3 = _mm256_loadu_si256((const __m256i*)(ptr + 12)); + + __m256i l02 = _mm256_permute2x128_si256(bgra0, bgra2, 0 + 2*16); + __m256i h02 = _mm256_permute2x128_si256(bgra0, bgra2, 1 + 3*16); + __m256i l13 = _mm256_permute2x128_si256(bgra1, bgra3, 0 + 2*16); + __m256i h13 = _mm256_permute2x128_si256(bgra1, bgra3, 1 + 3*16); + + __m256i b0 = _mm256_unpacklo_epi64(l02, l13); + __m256i g0 = _mm256_unpackhi_epi64(l02, l13); + __m256i r0 = _mm256_unpacklo_epi64(h02, h13); + __m256i a0 = _mm256_unpackhi_epi64(h02, h13); + + a = v_uint64x4(b0); + b = v_uint64x4(g0); + c = v_uint64x4(r0); + d = v_uint64x4(a0); +} + +///////////////////////////// store interleave ///////////////////////////////////// + +inline void v_store_interleave( uchar* ptr, const v_uint8x32& x, const v_uint8x32& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi8(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi8(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 32), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 32), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 32), xy1); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x16& x, const v_uint16x16& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi16(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi16(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 16), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 16), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 16), xy1); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x8& x, const v_uint32x8& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi32(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi32(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 8), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 8), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 8), xy1); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x4& x, const v_uint64x4& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i xy_l = _mm256_unpacklo_epi64(x.val, y.val); + __m256i xy_h = _mm256_unpackhi_epi64(x.val, y.val); + + __m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16); + __m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, xy0); + _mm256_stream_si256((__m256i*)(ptr + 4), xy1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, xy0); + _mm256_store_si256((__m256i*)(ptr + 4), xy1); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, xy0); + _mm256_storeu_si256((__m256i*)(ptr + 4), xy1); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x32& a, const v_uint8x32& b, const v_uint8x32& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + const __m256i sh_b = _mm256_setr_epi8( + 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5, + 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5); + const __m256i sh_g = _mm256_setr_epi8( + 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, + 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10); + const __m256i sh_r = _mm256_setr_epi8( + 10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, + 10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15); + + __m256i b0 = _mm256_shuffle_epi8(a.val, sh_b); + __m256i g0 = _mm256_shuffle_epi8(b.val, sh_g); + __m256i r0 = _mm256_shuffle_epi8(c.val, sh_r); + + const __m256i m0 = _mm256_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, + 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, + 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0); + + __m256i p0 = _mm256_blendv_epi8(_mm256_blendv_epi8(b0, g0, m0), r0, m1); + __m256i p1 = _mm256_blendv_epi8(_mm256_blendv_epi8(g0, r0, m0), b0, m1); + __m256i p2 = _mm256_blendv_epi8(_mm256_blendv_epi8(r0, b0, m0), g0, m1); + + __m256i bgr0 = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + __m256i bgr1 = _mm256_permute2x128_si256(p2, p0, 0 + 3*16); + __m256i bgr2 = _mm256_permute2x128_si256(p1, p2, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 32), bgr1); + _mm256_stream_si256((__m256i*)(ptr + 64), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 32), bgr1); + _mm256_store_si256((__m256i*)(ptr + 64), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgr1); + _mm256_storeu_si256((__m256i*)(ptr + 64), bgr2); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x16& a, const v_uint16x16& b, const v_uint16x16& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + const __m256i sh_b = _mm256_setr_epi8( + 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11, + 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m256i sh_g = _mm256_setr_epi8( + 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, + 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5); + const __m256i sh_r = _mm256_setr_epi8( + 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, + 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + + __m256i b0 = _mm256_shuffle_epi8(a.val, sh_b); + __m256i g0 = _mm256_shuffle_epi8(b.val, sh_g); + __m256i r0 = _mm256_shuffle_epi8(c.val, sh_r); + + const __m256i m0 = _mm256_setr_epi8(0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, + 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0); + const __m256i m1 = _mm256_setr_epi8(0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, + -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0); + + __m256i p0 = _mm256_blendv_epi8(_mm256_blendv_epi8(b0, g0, m0), r0, m1); + __m256i p1 = _mm256_blendv_epi8(_mm256_blendv_epi8(g0, r0, m0), b0, m1); + __m256i p2 = _mm256_blendv_epi8(_mm256_blendv_epi8(r0, b0, m0), g0, m1); + + __m256i bgr0 = _mm256_permute2x128_si256(p0, p2, 0 + 2*16); + //__m256i bgr1 = p1; + __m256i bgr2 = _mm256_permute2x128_si256(p0, p2, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 16), p1); + _mm256_stream_si256((__m256i*)(ptr + 32), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 16), p1); + _mm256_store_si256((__m256i*)(ptr + 32), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 16), p1); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgr2); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x8& a, const v_uint32x8& b, const v_uint32x8& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i b0 = _mm256_shuffle_epi32(a.val, 0x6c); + __m256i g0 = _mm256_shuffle_epi32(b.val, 0xb1); + __m256i r0 = _mm256_shuffle_epi32(c.val, 0xc6); + + __m256i p0 = _mm256_blend_epi32(_mm256_blend_epi32(b0, g0, 0x92), r0, 0x24); + __m256i p1 = _mm256_blend_epi32(_mm256_blend_epi32(g0, r0, 0x92), b0, 0x24); + __m256i p2 = _mm256_blend_epi32(_mm256_blend_epi32(r0, b0, 0x92), g0, 0x24); + + __m256i bgr0 = _mm256_permute2x128_si256(p0, p1, 0 + 2*16); + //__m256i bgr1 = p2; + __m256i bgr2 = _mm256_permute2x128_si256(p0, p1, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 8), p2); + _mm256_stream_si256((__m256i*)(ptr + 16), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 8), p2); + _mm256_store_si256((__m256i*)(ptr + 16), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 8), p2); + _mm256_storeu_si256((__m256i*)(ptr + 16), bgr2); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x4& a, const v_uint64x4& b, const v_uint64x4& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i s01 = _mm256_unpacklo_epi64(a.val, b.val); + __m256i s12 = _mm256_unpackhi_epi64(b.val, c.val); + __m256i s20 = _mm256_blend_epi32(c.val, a.val, 0xcc); + + __m256i bgr0 = _mm256_permute2x128_si256(s01, s20, 0 + 2*16); + __m256i bgr1 = _mm256_blend_epi32(s01, s12, 0x0f); + __m256i bgr2 = _mm256_permute2x128_si256(s20, s12, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgr0); + _mm256_stream_si256((__m256i*)(ptr + 4), bgr1); + _mm256_stream_si256((__m256i*)(ptr + 8), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgr0); + _mm256_store_si256((__m256i*)(ptr + 4), bgr1); + _mm256_store_si256((__m256i*)(ptr + 8), bgr2); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgr0); + _mm256_storeu_si256((__m256i*)(ptr + 4), bgr1); + _mm256_storeu_si256((__m256i*)(ptr + 8), bgr2); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x32& a, const v_uint8x32& b, + const v_uint8x32& c, const v_uint8x32& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi8(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi8(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi8(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi8(c.val, d.val); + + __m256i bgra0_ = _mm256_unpacklo_epi16(bg0, ra0); + __m256i bgra1_ = _mm256_unpackhi_epi16(bg0, ra0); + __m256i bgra2_ = _mm256_unpacklo_epi16(bg1, ra1); + __m256i bgra3_ = _mm256_unpackhi_epi16(bg1, ra1); + + __m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16); + __m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16); + __m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 32), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 64), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 96), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 32), bgra1); + _mm256_store_si256((__m256i*)(ptr + 64), bgra2); + _mm256_store_si256((__m256i*)(ptr + 96), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 64), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 96), bgra3); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x16& a, const v_uint16x16& b, + const v_uint16x16& c, const v_uint16x16& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi16(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi16(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi16(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi16(c.val, d.val); + + __m256i bgra0_ = _mm256_unpacklo_epi32(bg0, ra0); + __m256i bgra1_ = _mm256_unpackhi_epi32(bg0, ra0); + __m256i bgra2_ = _mm256_unpacklo_epi32(bg1, ra1); + __m256i bgra3_ = _mm256_unpackhi_epi32(bg1, ra1); + + __m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16); + __m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16); + __m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 16), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 32), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 48), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 16), bgra1); + _mm256_store_si256((__m256i*)(ptr + 32), bgra2); + _mm256_store_si256((__m256i*)(ptr + 48), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 16), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 32), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 48), bgra3); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x8& a, const v_uint32x8& b, + const v_uint32x8& c, const v_uint32x8& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi32(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi32(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi32(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi32(c.val, d.val); + + __m256i bgra0_ = _mm256_unpacklo_epi64(bg0, ra0); + __m256i bgra1_ = _mm256_unpackhi_epi64(bg0, ra0); + __m256i bgra2_ = _mm256_unpacklo_epi64(bg1, ra1); + __m256i bgra3_ = _mm256_unpackhi_epi64(bg1, ra1); + + __m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16); + __m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16); + __m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 8), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 16), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 24), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 8), bgra1); + _mm256_store_si256((__m256i*)(ptr + 16), bgra2); + _mm256_store_si256((__m256i*)(ptr + 24), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 8), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 16), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 24), bgra3); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x4& a, const v_uint64x4& b, + const v_uint64x4& c, const v_uint64x4& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m256i bg0 = _mm256_unpacklo_epi64(a.val, b.val); + __m256i bg1 = _mm256_unpackhi_epi64(a.val, b.val); + __m256i ra0 = _mm256_unpacklo_epi64(c.val, d.val); + __m256i ra1 = _mm256_unpackhi_epi64(c.val, d.val); + + __m256i bgra0 = _mm256_permute2x128_si256(bg0, ra0, 0 + 2*16); + __m256i bgra1 = _mm256_permute2x128_si256(bg1, ra1, 0 + 2*16); + __m256i bgra2 = _mm256_permute2x128_si256(bg0, ra0, 1 + 3*16); + __m256i bgra3 = _mm256_permute2x128_si256(bg1, ra1, 1 + 3*16); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm256_stream_si256((__m256i*)ptr, bgra0); + _mm256_stream_si256((__m256i*)(ptr + 4), bgra1); + _mm256_stream_si256((__m256i*)(ptr + 8), bgra2); + _mm256_stream_si256((__m256i*)(ptr + 12), bgra3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm256_store_si256((__m256i*)ptr, bgra0); + _mm256_store_si256((__m256i*)(ptr + 4), bgra1); + _mm256_store_si256((__m256i*)(ptr + 8), bgra2); + _mm256_store_si256((__m256i*)(ptr + 12), bgra3); + } + else + { + _mm256_storeu_si256((__m256i*)ptr, bgra0); + _mm256_storeu_si256((__m256i*)(ptr + 4), bgra1); + _mm256_storeu_si256((__m256i*)(ptr + 8), bgra2); + _mm256_storeu_si256((__m256i*)(ptr + 12), bgra3); + } +} + +#define OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \ +{ \ + _Tpvec1 a1, b1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \ +{ \ + _Tpvec1 a1, b1, c1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \ +{ \ + _Tpvec1 a1, b1, c1, d1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ + d0 = v_reinterpret_as_##suffix0(d1); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, const _Tpvec0& c0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, const _Tpvec0& d0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + _Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \ +} + +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int8x32, schar, s8, v_uint8x32, uchar, u8) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int16x16, short, s16, v_uint16x16, ushort, u16) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int32x8, int, s32, v_uint32x8, unsigned, u32) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float32x8, float, f32, v_uint32x8, unsigned, u32) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int64x4, int64, s64, v_uint64x4, uint64, u64) +OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float64x4, double, f64, v_uint64x4, uint64, u64) + +// FP16 +inline v_float32x8 v256_load_expand(const float16_t* ptr) +{ + return v_float32x8(_mm256_cvtph_ps(_mm_loadu_si128((const __m128i*)ptr))); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x8& a) +{ + __m128i ah = _mm256_cvtps_ph(a.val, 0); + _mm_storeu_si128((__m128i*)ptr, ah); +} + +inline void v256_cleanup() { _mm256_zeroall(); } + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} // cv:: + +#endif // OPENCV_HAL_INTRIN_AVX_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_avx512.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_avx512.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3fa9027c04ed8d6879965e6e2216241ec77fe60c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_avx512.hpp @@ -0,0 +1,3049 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_INTRIN_AVX512_HPP +#define OPENCV_HAL_INTRIN_AVX512_HPP + +#if defined(_MSC_VER) && (_MSC_VER < 1920/*MSVS2019*/) +# pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned +# pragma warning(disable:4309) // 'argument': truncation of constant value +# pragma warning(disable:4310) // cast truncates constant value +#endif + +#define CVT_ROUND_MODES_IMPLEMENTED 0 + +#define CV_SIMD512 1 +#define CV_SIMD512_64F 1 +#define CV_SIMD512_FP16 0 // no native operations with FP16 type. Only load/store from float32x8 are available (if CV_FP16 == 1) + +#define _v512_set_epu64(a7, a6, a5, a4, a3, a2, a1, a0) _mm512_set_epi64((int64)(a7),(int64)(a6),(int64)(a5),(int64)(a4),(int64)(a3),(int64)(a2),(int64)(a1),(int64)(a0)) +#define _v512_set_epu32(a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \ + _mm512_set_epi64(((int64)(a15)<<32)|(int64)(a14), ((int64)(a13)<<32)|(int64)(a12), ((int64)(a11)<<32)|(int64)(a10), ((int64)( a9)<<32)|(int64)( a8), \ + ((int64)( a7)<<32)|(int64)( a6), ((int64)( a5)<<32)|(int64)( a4), ((int64)( a3)<<32)|(int64)( a2), ((int64)( a1)<<32)|(int64)( a0)) +#define _v512_set_epu16(a31, a30, a29, a28, a27, a26, a25, a24, a23, a22, a21, a20, a19, a18, a17, a16, \ + a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \ + _v512_set_epu32(((unsigned)(a31)<<16)|(unsigned)(a30), ((unsigned)(a29)<<16)|(unsigned)(a28), ((unsigned)(a27)<<16)|(unsigned)(a26), ((unsigned)(a25)<<16)|(unsigned)(a24), \ + ((unsigned)(a23)<<16)|(unsigned)(a22), ((unsigned)(a21)<<16)|(unsigned)(a20), ((unsigned)(a19)<<16)|(unsigned)(a18), ((unsigned)(a17)<<16)|(unsigned)(a16), \ + ((unsigned)(a15)<<16)|(unsigned)(a14), ((unsigned)(a13)<<16)|(unsigned)(a12), ((unsigned)(a11)<<16)|(unsigned)(a10), ((unsigned)( a9)<<16)|(unsigned)( a8), \ + ((unsigned)( a7)<<16)|(unsigned)( a6), ((unsigned)( a5)<<16)|(unsigned)( a4), ((unsigned)( a3)<<16)|(unsigned)( a2), ((unsigned)( a1)<<16)|(unsigned)( a0)) +#define _v512_set_epu8(a63, a62, a61, a60, a59, a58, a57, a56, a55, a54, a53, a52, a51, a50, a49, a48, \ + a47, a46, a45, a44, a43, a42, a41, a40, a39, a38, a37, a36, a35, a34, a33, a32, \ + a31, a30, a29, a28, a27, a26, a25, a24, a23, a22, a21, a20, a19, a18, a17, a16, \ + a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \ + _v512_set_epu32(((unsigned)(a63)<<24)|((unsigned)(a62)<<16)|((unsigned)(a61)<<8)|(unsigned)(a60),((unsigned)(a59)<<24)|((unsigned)(a58)<<16)|((unsigned)(a57)<<8)|(unsigned)(a56), \ + ((unsigned)(a55)<<24)|((unsigned)(a54)<<16)|((unsigned)(a53)<<8)|(unsigned)(a52),((unsigned)(a51)<<24)|((unsigned)(a50)<<16)|((unsigned)(a49)<<8)|(unsigned)(a48), \ + ((unsigned)(a47)<<24)|((unsigned)(a46)<<16)|((unsigned)(a45)<<8)|(unsigned)(a44),((unsigned)(a43)<<24)|((unsigned)(a42)<<16)|((unsigned)(a41)<<8)|(unsigned)(a40), \ + ((unsigned)(a39)<<24)|((unsigned)(a38)<<16)|((unsigned)(a37)<<8)|(unsigned)(a36),((unsigned)(a35)<<24)|((unsigned)(a34)<<16)|((unsigned)(a33)<<8)|(unsigned)(a32), \ + ((unsigned)(a31)<<24)|((unsigned)(a30)<<16)|((unsigned)(a29)<<8)|(unsigned)(a28),((unsigned)(a27)<<24)|((unsigned)(a26)<<16)|((unsigned)(a25)<<8)|(unsigned)(a24), \ + ((unsigned)(a23)<<24)|((unsigned)(a22)<<16)|((unsigned)(a21)<<8)|(unsigned)(a20),((unsigned)(a19)<<24)|((unsigned)(a18)<<16)|((unsigned)(a17)<<8)|(unsigned)(a16), \ + ((unsigned)(a15)<<24)|((unsigned)(a14)<<16)|((unsigned)(a13)<<8)|(unsigned)(a12),((unsigned)(a11)<<24)|((unsigned)(a10)<<16)|((unsigned)( a9)<<8)|(unsigned)( a8), \ + ((unsigned)( a7)<<24)|((unsigned)( a6)<<16)|((unsigned)( a5)<<8)|(unsigned)( a4),((unsigned)( a3)<<24)|((unsigned)( a2)<<16)|((unsigned)( a1)<<8)|(unsigned)( a0)) +#define _v512_set_epi8(a63, a62, a61, a60, a59, a58, a57, a56, a55, a54, a53, a52, a51, a50, a49, a48, \ + a47, a46, a45, a44, a43, a42, a41, a40, a39, a38, a37, a36, a35, a34, a33, a32, \ + a31, a30, a29, a28, a27, a26, a25, a24, a23, a22, a21, a20, a19, a18, a17, a16, \ + a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \ + _v512_set_epu8((uchar)(a63), (uchar)(a62), (uchar)(a61), (uchar)(a60), (uchar)(a59), (uchar)(a58), (uchar)(a57), (uchar)(a56), \ + (uchar)(a55), (uchar)(a54), (uchar)(a53), (uchar)(a52), (uchar)(a51), (uchar)(a50), (uchar)(a49), (uchar)(a48), \ + (uchar)(a47), (uchar)(a46), (uchar)(a45), (uchar)(a44), (uchar)(a43), (uchar)(a42), (uchar)(a41), (uchar)(a40), \ + (uchar)(a39), (uchar)(a38), (uchar)(a37), (uchar)(a36), (uchar)(a35), (uchar)(a34), (uchar)(a33), (uchar)(a32), \ + (uchar)(a31), (uchar)(a30), (uchar)(a29), (uchar)(a28), (uchar)(a27), (uchar)(a26), (uchar)(a25), (uchar)(a24), \ + (uchar)(a23), (uchar)(a22), (uchar)(a21), (uchar)(a20), (uchar)(a19), (uchar)(a18), (uchar)(a17), (uchar)(a16), \ + (uchar)(a15), (uchar)(a14), (uchar)(a13), (uchar)(a12), (uchar)(a11), (uchar)(a10), (uchar)( a9), (uchar)( a8), \ + (uchar)( a7), (uchar)( a6), (uchar)( a5), (uchar)( a4), (uchar)( a3), (uchar)( a2), (uchar)( a1), (uchar)( a0)) + +#ifndef _mm512_cvtpd_pslo +#ifdef _mm512_zextsi256_si512 +#define _mm512_cvtpd_pslo(a) _mm512_zextps256_ps512(_mm512_cvtpd_ps(a)) +#else +//if preferred way to extend with zeros is unavailable +#define _mm512_cvtpd_pslo(a) _mm512_castps256_ps512(_mm512_cvtpd_ps(a)) +#endif +#endif +///////// Utils //////////// + +namespace +{ + +inline __m512i _v512_combine(const __m256i& lo, const __m256i& hi) +{ return _mm512_inserti32x8(_mm512_castsi256_si512(lo), hi, 1); } + +inline __m512 _v512_combine(const __m256& lo, const __m256& hi) +{ return _mm512_insertf32x8(_mm512_castps256_ps512(lo), hi, 1); } + +inline __m512d _v512_combine(const __m256d& lo, const __m256d& hi) +{ return _mm512_insertf64x4(_mm512_castpd256_pd512(lo), hi, 1); } + +inline int _v_cvtsi512_si32(const __m512i& a) +{ return _mm_cvtsi128_si32(_mm512_castsi512_si128(a)); } + +inline __m256i _v512_extract_high(const __m512i& v) +{ return _mm512_extracti32x8_epi32(v, 1); } + +inline __m256 _v512_extract_high(const __m512& v) +{ return _mm512_extractf32x8_ps(v, 1); } + +inline __m256d _v512_extract_high(const __m512d& v) +{ return _mm512_extractf64x4_pd(v, 1); } + +inline __m256i _v512_extract_low(const __m512i& v) +{ return _mm512_castsi512_si256(v); } + +inline __m256 _v512_extract_low(const __m512& v) +{ return _mm512_castps512_ps256(v); } + +inline __m256d _v512_extract_low(const __m512d& v) +{ return _mm512_castpd512_pd256(v); } + +inline __m512i _v512_insert(const __m512i& a, const __m256i& b) +{ return _mm512_inserti32x8(a, b, 0); } + +inline __m512 _v512_insert(const __m512& a, const __m256& b) +{ return _mm512_insertf32x8(a, b, 0); } + +inline __m512d _v512_insert(const __m512d& a, const __m256d& b) +{ return _mm512_insertf64x4(a, b, 0); } + +} + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Types //////////// + +struct v_uint8x64 +{ + typedef uchar lane_type; + enum { nlanes = 64 }; + __m512i val; + + explicit v_uint8x64(__m512i v) : val(v) {} + v_uint8x64(uchar v0, uchar v1, uchar v2, uchar v3, + uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, + uchar v12, uchar v13, uchar v14, uchar v15, + uchar v16, uchar v17, uchar v18, uchar v19, + uchar v20, uchar v21, uchar v22, uchar v23, + uchar v24, uchar v25, uchar v26, uchar v27, + uchar v28, uchar v29, uchar v30, uchar v31, + uchar v32, uchar v33, uchar v34, uchar v35, + uchar v36, uchar v37, uchar v38, uchar v39, + uchar v40, uchar v41, uchar v42, uchar v43, + uchar v44, uchar v45, uchar v46, uchar v47, + uchar v48, uchar v49, uchar v50, uchar v51, + uchar v52, uchar v53, uchar v54, uchar v55, + uchar v56, uchar v57, uchar v58, uchar v59, + uchar v60, uchar v61, uchar v62, uchar v63) + { + val = _v512_set_epu8(v63, v62, v61, v60, v59, v58, v57, v56, v55, v54, v53, v52, v51, v50, v49, v48, + v47, v46, v45, v44, v43, v42, v41, v40, v39, v38, v37, v36, v35, v34, v33, v32, + v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16, + v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1, v0); + } + v_uint8x64() : val(_mm512_setzero_si512()) {} + uchar get0() const { return (uchar)_v_cvtsi512_si32(val); } +}; + +struct v_int8x64 +{ + typedef schar lane_type; + enum { nlanes = 64 }; + __m512i val; + + explicit v_int8x64(__m512i v) : val(v) {} + v_int8x64(schar v0, schar v1, schar v2, schar v3, + schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, + schar v12, schar v13, schar v14, schar v15, + schar v16, schar v17, schar v18, schar v19, + schar v20, schar v21, schar v22, schar v23, + schar v24, schar v25, schar v26, schar v27, + schar v28, schar v29, schar v30, schar v31, + schar v32, schar v33, schar v34, schar v35, + schar v36, schar v37, schar v38, schar v39, + schar v40, schar v41, schar v42, schar v43, + schar v44, schar v45, schar v46, schar v47, + schar v48, schar v49, schar v50, schar v51, + schar v52, schar v53, schar v54, schar v55, + schar v56, schar v57, schar v58, schar v59, + schar v60, schar v61, schar v62, schar v63) + { + val = _v512_set_epi8(v63, v62, v61, v60, v59, v58, v57, v56, v55, v54, v53, v52, v51, v50, v49, v48, + v47, v46, v45, v44, v43, v42, v41, v40, v39, v38, v37, v36, v35, v34, v33, v32, + v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16, + v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1, v0); + } + v_int8x64() : val(_mm512_setzero_si512()) {} + schar get0() const { return (schar)_v_cvtsi512_si32(val); } +}; + +struct v_uint16x32 +{ + typedef ushort lane_type; + enum { nlanes = 32 }; + __m512i val; + + explicit v_uint16x32(__m512i v) : val(v) {} + v_uint16x32(ushort v0, ushort v1, ushort v2, ushort v3, + ushort v4, ushort v5, ushort v6, ushort v7, + ushort v8, ushort v9, ushort v10, ushort v11, + ushort v12, ushort v13, ushort v14, ushort v15, + ushort v16, ushort v17, ushort v18, ushort v19, + ushort v20, ushort v21, ushort v22, ushort v23, + ushort v24, ushort v25, ushort v26, ushort v27, + ushort v28, ushort v29, ushort v30, ushort v31) + { + val = _v512_set_epu16(v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16, + v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1, v0); + } + v_uint16x32() : val(_mm512_setzero_si512()) {} + ushort get0() const { return (ushort)_v_cvtsi512_si32(val); } +}; + +struct v_int16x32 +{ + typedef short lane_type; + enum { nlanes = 32 }; + __m512i val; + + explicit v_int16x32(__m512i v) : val(v) {} + v_int16x32(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7, + short v8, short v9, short v10, short v11, short v12, short v13, short v14, short v15, + short v16, short v17, short v18, short v19, short v20, short v21, short v22, short v23, + short v24, short v25, short v26, short v27, short v28, short v29, short v30, short v31) + { + val = _v512_set_epu16((ushort)v31, (ushort)v30, (ushort)v29, (ushort)v28, (ushort)v27, (ushort)v26, (ushort)v25, (ushort)v24, + (ushort)v23, (ushort)v22, (ushort)v21, (ushort)v20, (ushort)v19, (ushort)v18, (ushort)v17, (ushort)v16, + (ushort)v15, (ushort)v14, (ushort)v13, (ushort)v12, (ushort)v11, (ushort)v10, (ushort)v9 , (ushort)v8, + (ushort)v7 , (ushort)v6 , (ushort)v5 , (ushort)v4 , (ushort)v3 , (ushort)v2 , (ushort)v1 , (ushort)v0); + } + v_int16x32() : val(_mm512_setzero_si512()) {} + short get0() const { return (short)_v_cvtsi512_si32(val); } +}; + +struct v_uint32x16 +{ + typedef unsigned lane_type; + enum { nlanes = 16 }; + __m512i val; + + explicit v_uint32x16(__m512i v) : val(v) {} + v_uint32x16(unsigned v0, unsigned v1, unsigned v2, unsigned v3, + unsigned v4, unsigned v5, unsigned v6, unsigned v7, + unsigned v8, unsigned v9, unsigned v10, unsigned v11, + unsigned v12, unsigned v13, unsigned v14, unsigned v15) + { + val = _mm512_setr_epi32((int)v0, (int)v1, (int)v2, (int)v3, (int)v4, (int)v5, (int)v6, (int)v7, + (int)v8, (int)v9, (int)v10, (int)v11, (int)v12, (int)v13, (int)v14, (int)v15); + } + v_uint32x16() : val(_mm512_setzero_si512()) {} + unsigned get0() const { return (unsigned)_v_cvtsi512_si32(val); } +}; + +struct v_int32x16 +{ + typedef int lane_type; + enum { nlanes = 16 }; + __m512i val; + + explicit v_int32x16(__m512i v) : val(v) {} + v_int32x16(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7, + int v8, int v9, int v10, int v11, int v12, int v13, int v14, int v15) + { + val = _mm512_setr_epi32(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15); + } + v_int32x16() : val(_mm512_setzero_si512()) {} + int get0() const { return _v_cvtsi512_si32(val); } +}; + +struct v_float32x16 +{ + typedef float lane_type; + enum { nlanes = 16 }; + __m512 val; + + explicit v_float32x16(__m512 v) : val(v) {} + v_float32x16(float v0, float v1, float v2, float v3, float v4, float v5, float v6, float v7, + float v8, float v9, float v10, float v11, float v12, float v13, float v14, float v15) + { + val = _mm512_setr_ps(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15); + } + v_float32x16() : val(_mm512_setzero_ps()) {} + float get0() const { return _mm_cvtss_f32(_mm512_castps512_ps128(val)); } +}; + +struct v_uint64x8 +{ + typedef uint64 lane_type; + enum { nlanes = 8 }; + __m512i val; + + explicit v_uint64x8(__m512i v) : val(v) {} + v_uint64x8(uint64 v0, uint64 v1, uint64 v2, uint64 v3, uint64 v4, uint64 v5, uint64 v6, uint64 v7) + { val = _mm512_setr_epi64((int64)v0, (int64)v1, (int64)v2, (int64)v3, (int64)v4, (int64)v5, (int64)v6, (int64)v7); } + v_uint64x8() : val(_mm512_setzero_si512()) {} + uint64 get0() const + { + #if defined __x86_64__ || defined _M_X64 + return (uint64)_mm_cvtsi128_si64(_mm512_castsi512_si128(val)); + #else + int a = _mm_cvtsi128_si32(_mm512_castsi512_si128(val)); + int b = _mm_cvtsi128_si32(_mm512_castsi512_si128(_mm512_srli_epi64(val, 32))); + return (unsigned)a | ((uint64)(unsigned)b << 32); + #endif + } +}; + +struct v_int64x8 +{ + typedef int64 lane_type; + enum { nlanes = 8 }; + __m512i val; + + explicit v_int64x8(__m512i v) : val(v) {} + v_int64x8(int64 v0, int64 v1, int64 v2, int64 v3, int64 v4, int64 v5, int64 v6, int64 v7) + { val = _mm512_setr_epi64(v0, v1, v2, v3, v4, v5, v6, v7); } + v_int64x8() : val(_mm512_setzero_si512()) {} + + int64 get0() const + { + #if defined __x86_64__ || defined _M_X64 + return (int64)_mm_cvtsi128_si64(_mm512_castsi512_si128(val)); + #else + int a = _mm_cvtsi128_si32(_mm512_castsi512_si128(val)); + int b = _mm_cvtsi128_si32(_mm512_castsi512_si128(_mm512_srli_epi64(val, 32))); + return (int64)((unsigned)a | ((uint64)(unsigned)b << 32)); + #endif + } +}; + +struct v_float64x8 +{ + typedef double lane_type; + enum { nlanes = 8 }; + __m512d val; + + explicit v_float64x8(__m512d v) : val(v) {} + v_float64x8(double v0, double v1, double v2, double v3, double v4, double v5, double v6, double v7) + { val = _mm512_setr_pd(v0, v1, v2, v3, v4, v5, v6, v7); } + v_float64x8() : val(_mm512_setzero_pd()) {} + double get0() const { return _mm_cvtsd_f64(_mm512_castpd512_pd128(val)); } +}; + +//////////////// Load and store operations /////////////// + +#define OPENCV_HAL_IMPL_AVX512_LOADSTORE(_Tpvec, _Tp) \ + inline _Tpvec v512_load(const _Tp* ptr) \ + { return _Tpvec(_mm512_loadu_si512((const __m512i*)ptr)); } \ + inline _Tpvec v512_load_aligned(const _Tp* ptr) \ + { return _Tpvec(_mm512_load_si512((const __m512i*)ptr)); } \ + inline _Tpvec v512_load_low(const _Tp* ptr) \ + { \ + __m256i v256 = _mm256_loadu_si256((const __m256i*)ptr); \ + return _Tpvec(_mm512_castsi256_si512(v256)); \ + } \ + inline _Tpvec v512_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ + { \ + __m256i vlo = _mm256_loadu_si256((const __m256i*)ptr0); \ + __m256i vhi = _mm256_loadu_si256((const __m256i*)ptr1); \ + return _Tpvec(_v512_combine(vlo, vhi)); \ + } \ + inline void v_store(_Tp* ptr, const _Tpvec& a) \ + { _mm512_storeu_si512((__m512i*)ptr, a.val); } \ + inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ + { _mm512_store_si512((__m512i*)ptr, a.val); } \ + inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ + { _mm512_stream_si512((__m512i*)ptr, a.val); } \ + inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ + { \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm512_storeu_si512((__m512i*)ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm512_stream_si512((__m512i*)ptr, a.val); \ + else \ + _mm512_store_si512((__m512i*)ptr, a.val); \ + } \ + inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_si256((__m256i*)ptr, _v512_extract_low(a.val)); } \ + inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_si256((__m256i*)ptr, _v512_extract_high(a.val)); } + +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint8x64, uchar) +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int8x64, schar) +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint16x32, ushort) +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int16x32, short) +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint32x16, unsigned) +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int32x16, int) +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint64x8, uint64) +OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int64x8, int64) + +#define OPENCV_HAL_IMPL_AVX512_LOADSTORE_FLT(_Tpvec, _Tp, suffix, halfreg) \ + inline _Tpvec v512_load(const _Tp* ptr) \ + { return _Tpvec(_mm512_loadu_##suffix(ptr)); } \ + inline _Tpvec v512_load_aligned(const _Tp* ptr) \ + { return _Tpvec(_mm512_load_##suffix(ptr)); } \ + inline _Tpvec v512_load_low(const _Tp* ptr) \ + { \ + return _Tpvec(_mm512_cast##suffix##256_##suffix##512 \ + (_mm256_loadu_##suffix(ptr))); \ + } \ + inline _Tpvec v512_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ + { \ + halfreg vlo = _mm256_loadu_##suffix(ptr0); \ + halfreg vhi = _mm256_loadu_##suffix(ptr1); \ + return _Tpvec(_v512_combine(vlo, vhi)); \ + } \ + inline void v_store(_Tp* ptr, const _Tpvec& a) \ + { _mm512_storeu_##suffix(ptr, a.val); } \ + inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ + { _mm512_store_##suffix(ptr, a.val); } \ + inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ + { _mm512_stream_##suffix(ptr, a.val); } \ + inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ + { \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm512_storeu_##suffix(ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm512_stream_##suffix(ptr, a.val); \ + else \ + _mm512_store_##suffix(ptr, a.val); \ + } \ + inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_##suffix(ptr, _v512_extract_low(a.val)); } \ + inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ + { _mm256_storeu_##suffix(ptr, _v512_extract_high(a.val)); } + +OPENCV_HAL_IMPL_AVX512_LOADSTORE_FLT(v_float32x16, float, ps, __m256) +OPENCV_HAL_IMPL_AVX512_LOADSTORE_FLT(v_float64x8, double, pd, __m256d) + +#define OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, _Tpvecf, suffix, cast) \ + inline _Tpvec v_reinterpret_as_##suffix(const _Tpvecf& a) \ + { return _Tpvec(cast(a.val)); } + +#define OPENCV_HAL_IMPL_AVX512_INIT(_Tpvec, _Tp, suffix, ssuffix, ctype_s) \ + inline _Tpvec v512_setzero_##suffix() \ + { return _Tpvec(_mm512_setzero_si512()); } \ + inline _Tpvec v512_setall_##suffix(_Tp v) \ + { return _Tpvec(_mm512_set1_##ssuffix((ctype_s)v)); } \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint8x64, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int8x64, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint16x32, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int16x32, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint32x16, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int32x16, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint64x8, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int64x8, suffix, OPENCV_HAL_NOP) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_float32x16, suffix, _mm512_castps_si512) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_float64x8, suffix, _mm512_castpd_si512) + +OPENCV_HAL_IMPL_AVX512_INIT(v_uint8x64, uchar, u8, epi8, char) +OPENCV_HAL_IMPL_AVX512_INIT(v_int8x64, schar, s8, epi8, char) +OPENCV_HAL_IMPL_AVX512_INIT(v_uint16x32, ushort, u16, epi16, short) +OPENCV_HAL_IMPL_AVX512_INIT(v_int16x32, short, s16, epi16, short) +OPENCV_HAL_IMPL_AVX512_INIT(v_uint32x16, unsigned, u32, epi32, int) +OPENCV_HAL_IMPL_AVX512_INIT(v_int32x16, int, s32, epi32, int) +OPENCV_HAL_IMPL_AVX512_INIT(v_uint64x8, uint64, u64, epi64, int64) +OPENCV_HAL_IMPL_AVX512_INIT(v_int64x8, int64, s64, epi64, int64) + +#define OPENCV_HAL_IMPL_AVX512_INIT_FLT(_Tpvec, _Tp, suffix, zsuffix, cast) \ + inline _Tpvec v512_setzero_##suffix() \ + { return _Tpvec(_mm512_setzero_##zsuffix()); } \ + inline _Tpvec v512_setall_##suffix(_Tp v) \ + { return _Tpvec(_mm512_set1_##zsuffix(v)); } \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint8x64, suffix, cast) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int8x64, suffix, cast) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint16x32, suffix, cast) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int16x32, suffix, cast) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint32x16, suffix, cast) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int32x16, suffix, cast) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint64x8, suffix, cast) \ + OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int64x8, suffix, cast) + +OPENCV_HAL_IMPL_AVX512_INIT_FLT(v_float32x16, float, f32, ps, _mm512_castsi512_ps) +OPENCV_HAL_IMPL_AVX512_INIT_FLT(v_float64x8, double, f64, pd, _mm512_castsi512_pd) + +inline v_float32x16 v_reinterpret_as_f32(const v_float32x16& a) +{ return a; } +inline v_float32x16 v_reinterpret_as_f32(const v_float64x8& a) +{ return v_float32x16(_mm512_castpd_ps(a.val)); } + +inline v_float64x8 v_reinterpret_as_f64(const v_float64x8& a) +{ return a; } +inline v_float64x8 v_reinterpret_as_f64(const v_float32x16& a) +{ return v_float64x8(_mm512_castps_pd(a.val)); } + +// FP16 +inline v_float32x16 v512_load_expand(const float16_t* ptr) +{ + return v_float32x16(_mm512_cvtph_ps(_mm256_loadu_si256((const __m256i*)ptr))); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x16& a) +{ + __m256i ah = _mm512_cvtps_ph(a.val, 0); + _mm256_storeu_si256((__m256i*)ptr, ah); +} + +/* Recombine & ZIP */ +inline void v_zip(const v_int8x64& a, const v_int8x64& b, v_int8x64& ab0, v_int8x64& ab1) +{ +#if CV_AVX_512VBMI + __m512i mask0 = _v512_set_epu8( 95, 31, 94, 30, 93, 29, 92, 28, 91, 27, 90, 26, 89, 25, 88, 24, + 87, 23, 86, 22, 85, 21, 84, 20, 83, 19, 82, 18, 81, 17, 80, 16, + 79, 15, 78, 14, 77, 13, 76, 12, 75, 11, 74, 10, 73, 9, 72, 8, + 71, 7, 70, 6, 69, 5, 68, 4, 67, 3, 66, 2, 65, 1, 64, 0); + ab0 = v_int8x64(_mm512_permutex2var_epi8(a.val, mask0, b.val)); + __m512i mask1 = _v512_set_epu8(127, 63, 126, 62, 125, 61, 124, 60, 123, 59, 122, 58, 121, 57, 120, 56, + 119, 55, 118, 54, 117, 53, 116, 52, 115, 51, 114, 50, 113, 49, 112, 48, + 111, 47, 110, 46, 109, 45, 108, 44, 107, 43, 106, 42, 105, 41, 104, 40, + 103, 39, 102, 38, 101, 37, 100, 36, 99, 35, 98, 34, 97, 33, 96, 32); + ab1 = v_int8x64(_mm512_permutex2var_epi8(a.val, mask1, b.val)); +#else + __m512i low = _mm512_unpacklo_epi8(a.val, b.val); + __m512i high = _mm512_unpackhi_epi8(a.val, b.val); + ab0 = v_int8x64(_mm512_permutex2var_epi64(low, _v512_set_epu64(11, 10, 3, 2, 9, 8, 1, 0), high)); + ab1 = v_int8x64(_mm512_permutex2var_epi64(low, _v512_set_epu64(15, 14, 7, 6, 13, 12, 5, 4), high)); +#endif +} +inline void v_zip(const v_int16x32& a, const v_int16x32& b, v_int16x32& ab0, v_int16x32& ab1) +{ + __m512i mask0 = _v512_set_epu16(47, 15, 46, 14, 45, 13, 44, 12, 43, 11, 42, 10, 41, 9, 40, 8, + 39, 7, 38, 6, 37, 5, 36, 4, 35, 3, 34, 2, 33, 1, 32, 0); + ab0 = v_int16x32(_mm512_permutex2var_epi16(a.val, mask0, b.val)); + __m512i mask1 = _v512_set_epu16(63, 31, 62, 30, 61, 29, 60, 28, 59, 27, 58, 26, 57, 25, 56, 24, + 55, 23, 54, 22, 53, 21, 52, 20, 51, 19, 50, 18, 49, 17, 48, 16); + ab1 = v_int16x32(_mm512_permutex2var_epi16(a.val, mask1, b.val)); +} +inline void v_zip(const v_int32x16& a, const v_int32x16& b, v_int32x16& ab0, v_int32x16& ab1) +{ + __m512i mask0 = _v512_set_epu32(23, 7, 22, 6, 21, 5, 20, 4, 19, 3, 18, 2, 17, 1, 16, 0); + ab0 = v_int32x16(_mm512_permutex2var_epi32(a.val, mask0, b.val)); + __m512i mask1 = _v512_set_epu32(31, 15, 30, 14, 29, 13, 28, 12, 27, 11, 26, 10, 25, 9, 24, 8); + ab1 = v_int32x16(_mm512_permutex2var_epi32(a.val, mask1, b.val)); +} +inline void v_zip(const v_int64x8& a, const v_int64x8& b, v_int64x8& ab0, v_int64x8& ab1) +{ + __m512i mask0 = _v512_set_epu64(11, 3, 10, 2, 9, 1, 8, 0); + ab0 = v_int64x8(_mm512_permutex2var_epi64(a.val, mask0, b.val)); + __m512i mask1 = _v512_set_epu64(15, 7, 14, 6, 13, 5, 12, 4); + ab1 = v_int64x8(_mm512_permutex2var_epi64(a.val, mask1, b.val)); +} + +inline void v_zip(const v_uint8x64& a, const v_uint8x64& b, v_uint8x64& ab0, v_uint8x64& ab1) +{ + v_int8x64 i0, i1; + v_zip(v_reinterpret_as_s8(a), v_reinterpret_as_s8(b), i0, i1); + ab0 = v_reinterpret_as_u8(i0); + ab1 = v_reinterpret_as_u8(i1); +} +inline void v_zip(const v_uint16x32& a, const v_uint16x32& b, v_uint16x32& ab0, v_uint16x32& ab1) +{ + v_int16x32 i0, i1; + v_zip(v_reinterpret_as_s16(a), v_reinterpret_as_s16(b), i0, i1); + ab0 = v_reinterpret_as_u16(i0); + ab1 = v_reinterpret_as_u16(i1); +} +inline void v_zip(const v_uint32x16& a, const v_uint32x16& b, v_uint32x16& ab0, v_uint32x16& ab1) +{ + v_int32x16 i0, i1; + v_zip(v_reinterpret_as_s32(a), v_reinterpret_as_s32(b), i0, i1); + ab0 = v_reinterpret_as_u32(i0); + ab1 = v_reinterpret_as_u32(i1); +} +inline void v_zip(const v_uint64x8& a, const v_uint64x8& b, v_uint64x8& ab0, v_uint64x8& ab1) +{ + v_int64x8 i0, i1; + v_zip(v_reinterpret_as_s64(a), v_reinterpret_as_s64(b), i0, i1); + ab0 = v_reinterpret_as_u64(i0); + ab1 = v_reinterpret_as_u64(i1); +} +inline void v_zip(const v_float32x16& a, const v_float32x16& b, v_float32x16& ab0, v_float32x16& ab1) +{ + v_int32x16 i0, i1; + v_zip(v_reinterpret_as_s32(a), v_reinterpret_as_s32(b), i0, i1); + ab0 = v_reinterpret_as_f32(i0); + ab1 = v_reinterpret_as_f32(i1); +} +inline void v_zip(const v_float64x8& a, const v_float64x8& b, v_float64x8& ab0, v_float64x8& ab1) +{ + v_int64x8 i0, i1; + v_zip(v_reinterpret_as_s64(a), v_reinterpret_as_s64(b), i0, i1); + ab0 = v_reinterpret_as_f64(i0); + ab1 = v_reinterpret_as_f64(i1); +} + +#define OPENCV_HAL_IMPL_AVX512_COMBINE(_Tpvec, suffix) \ + inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_v512_combine(_v512_extract_low(a.val), _v512_extract_low(b.val))); } \ + inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_v512_insert(b.val, _v512_extract_high(a.val))); } \ + inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ + { \ + c.val = _v512_combine(_v512_extract_low(a.val),_v512_extract_low(b.val)); \ + d.val = _v512_insert(b.val,_v512_extract_high(a.val)); \ + } + + +OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint8x64, epi8) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_int8x64, epi8) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint16x32, epi16) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_int16x32, epi16) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint32x16, epi32) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_int32x16, epi32) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint64x8, epi64) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_int64x8, epi64) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_float32x16, ps) +OPENCV_HAL_IMPL_AVX512_COMBINE(v_float64x8, pd) + +////////// Arithmetic, bitwise and comparison operations ///////// + +/* Element-wise binary and unary operations */ + +/** Non-saturating arithmetics **/ +#define OPENCV_HAL_IMPL_AVX512_BIN_FUNC(func, _Tpvec, intrin) \ + inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(intrin(a.val, b.val)); } + +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_uint8x64, _mm512_add_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_int8x64, _mm512_add_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_uint16x32, _mm512_add_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_int16x32, _mm512_add_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_uint8x64, _mm512_sub_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_int8x64, _mm512_sub_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_uint16x32, _mm512_sub_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_int16x32, _mm512_sub_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_mul_wrap, v_uint16x32, _mm512_mullo_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_mul_wrap, v_int16x32, _mm512_mullo_epi16) + +inline v_uint8x64 v_mul_wrap(const v_uint8x64& a, const v_uint8x64& b) +{ + __m512i ad = _mm512_srai_epi16(a.val, 8); + __m512i bd = _mm512_srai_epi16(b.val, 8); + __m512i p0 = _mm512_mullo_epi16(a.val, b.val); // even + __m512i p1 = _mm512_slli_epi16(_mm512_mullo_epi16(ad, bd), 8); // odd + return v_uint8x64(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, p0, p1)); +} +inline v_int8x64 v_mul_wrap(const v_int8x64& a, const v_int8x64& b) +{ + return v_reinterpret_as_s8(v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b))); +} + +#define OPENCV_HAL_IMPL_AVX512_BIN_OP(bin_op, _Tpvec, intrin) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(intrin(a.val, b.val)); } \ + inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ + { a.val = intrin(a.val, b.val); return a; } + +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint32x16, _mm512_add_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint32x16, _mm512_sub_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int32x16, _mm512_add_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int32x16, _mm512_sub_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint64x8, _mm512_add_epi64) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint64x8, _mm512_sub_epi64) +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int64x8, _mm512_add_epi64) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int64x8, _mm512_sub_epi64) + +OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_uint32x16, _mm512_mullo_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_int32x16, _mm512_mullo_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_uint64x8, _mm512_mullo_epi64) +OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_int64x8, _mm512_mullo_epi64) + +/** Saturating arithmetics **/ +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint8x64, _mm512_adds_epu8) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint8x64, _mm512_subs_epu8) +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int8x64, _mm512_adds_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int8x64, _mm512_subs_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint16x32, _mm512_adds_epu16) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint16x32, _mm512_subs_epu16) +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int16x32, _mm512_adds_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int16x32, _mm512_subs_epi16) + +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_float32x16, _mm512_add_ps) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_float32x16, _mm512_sub_ps) +OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_float32x16, _mm512_mul_ps) +OPENCV_HAL_IMPL_AVX512_BIN_OP(/, v_float32x16, _mm512_div_ps) +OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_float64x8, _mm512_add_pd) +OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_float64x8, _mm512_sub_pd) +OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_float64x8, _mm512_mul_pd) +OPENCV_HAL_IMPL_AVX512_BIN_OP(/, v_float64x8, _mm512_div_pd) + +// saturating multiply +inline v_uint8x64 operator * (const v_uint8x64& a, const v_uint8x64& b) +{ + v_uint16x32 c, d; + v_mul_expand(a, b, c, d); + return v_pack(c, d); +} +inline v_int8x64 operator * (const v_int8x64& a, const v_int8x64& b) +{ + v_int16x32 c, d; + v_mul_expand(a, b, c, d); + return v_pack(c, d); +} +inline v_uint16x32 operator * (const v_uint16x32& a, const v_uint16x32& b) +{ + __m512i pl = _mm512_mullo_epi16(a.val, b.val); + __m512i ph = _mm512_mulhi_epu16(a.val, b.val); + __m512i p0 = _mm512_unpacklo_epi16(pl, ph); + __m512i p1 = _mm512_unpackhi_epi16(pl, ph); + + const __m512i m = _mm512_set1_epi32(65535); + return v_uint16x32(_mm512_packus_epi32(_mm512_min_epu32(p0, m), _mm512_min_epu32(p1, m))); +} +inline v_int16x32 operator * (const v_int16x32& a, const v_int16x32& b) +{ + __m512i pl = _mm512_mullo_epi16(a.val, b.val); + __m512i ph = _mm512_mulhi_epi16(a.val, b.val); + __m512i p0 = _mm512_unpacklo_epi16(pl, ph); + __m512i p1 = _mm512_unpackhi_epi16(pl, ph); + return v_int16x32(_mm512_packs_epi32(p0, p1)); +} + +inline v_uint8x64& operator *= (v_uint8x64& a, const v_uint8x64& b) +{ a = a * b; return a; } +inline v_int8x64& operator *= (v_int8x64& a, const v_int8x64& b) +{ a = a * b; return a; } +inline v_uint16x32& operator *= (v_uint16x32& a, const v_uint16x32& b) +{ a = a * b; return a; } +inline v_int16x32& operator *= (v_int16x32& a, const v_int16x32& b) +{ a = a * b; return a; } + +inline v_int16x32 v_mul_hi(const v_int16x32& a, const v_int16x32& b) { return v_int16x32(_mm512_mulhi_epi16(a.val, b.val)); } +inline v_uint16x32 v_mul_hi(const v_uint16x32& a, const v_uint16x32& b) { return v_uint16x32(_mm512_mulhi_epu16(a.val, b.val)); } + +// Multiply and expand +inline void v_mul_expand(const v_uint8x64& a, const v_uint8x64& b, + v_uint16x32& c, v_uint16x32& d) +{ + v_uint16x32 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int8x64& a, const v_int8x64& b, + v_int16x32& c, v_int16x32& d) +{ + v_int16x32 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int16x32& a, const v_int16x32& b, + v_int32x16& c, v_int32x16& d) +{ + v_int16x32 v0, v1; + v_zip(v_mul_wrap(a, b), v_mul_hi(a, b), v0, v1); + + c = v_reinterpret_as_s32(v0); + d = v_reinterpret_as_s32(v1); +} + +inline void v_mul_expand(const v_uint16x32& a, const v_uint16x32& b, + v_uint32x16& c, v_uint32x16& d) +{ + v_uint16x32 v0, v1; + v_zip(v_mul_wrap(a, b), v_mul_hi(a, b), v0, v1); + + c = v_reinterpret_as_u32(v0); + d = v_reinterpret_as_u32(v1); +} + +inline void v_mul_expand(const v_uint32x16& a, const v_uint32x16& b, + v_uint64x8& c, v_uint64x8& d) +{ + v_zip(v_uint64x8(_mm512_mul_epu32(a.val, b.val)), + v_uint64x8(_mm512_mul_epu32(_mm512_srli_epi64(a.val, 32), _mm512_srli_epi64(b.val, 32))), c, d); +} + +inline void v_mul_expand(const v_int32x16& a, const v_int32x16& b, + v_int64x8& c, v_int64x8& d) +{ + v_zip(v_int64x8(_mm512_mul_epi32(a.val, b.val)), + v_int64x8(_mm512_mul_epi32(_mm512_srli_epi64(a.val, 32), _mm512_srli_epi64(b.val, 32))), c, d); +} + +/** Bitwise shifts **/ +#define OPENCV_HAL_IMPL_AVX512_SHIFT_OP(_Tpuvec, _Tpsvec, suffix) \ + inline _Tpuvec operator << (const _Tpuvec& a, int imm) \ + { return _Tpuvec(_mm512_slli_##suffix(a.val, imm)); } \ + inline _Tpsvec operator << (const _Tpsvec& a, int imm) \ + { return _Tpsvec(_mm512_slli_##suffix(a.val, imm)); } \ + inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \ + { return _Tpuvec(_mm512_srli_##suffix(a.val, imm)); } \ + inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \ + { return _Tpsvec(_mm512_srai_##suffix(a.val, imm)); } \ + template \ + inline _Tpuvec v_shl(const _Tpuvec& a) \ + { return _Tpuvec(_mm512_slli_##suffix(a.val, imm)); } \ + template \ + inline _Tpsvec v_shl(const _Tpsvec& a) \ + { return _Tpsvec(_mm512_slli_##suffix(a.val, imm)); } \ + template \ + inline _Tpuvec v_shr(const _Tpuvec& a) \ + { return _Tpuvec(_mm512_srli_##suffix(a.val, imm)); } \ + template \ + inline _Tpsvec v_shr(const _Tpsvec& a) \ + { return _Tpsvec(_mm512_srai_##suffix(a.val, imm)); } + +OPENCV_HAL_IMPL_AVX512_SHIFT_OP(v_uint16x32, v_int16x32, epi16) +OPENCV_HAL_IMPL_AVX512_SHIFT_OP(v_uint32x16, v_int32x16, epi32) +OPENCV_HAL_IMPL_AVX512_SHIFT_OP(v_uint64x8, v_int64x8, epi64) + + +/** Bitwise logic **/ +#define OPENCV_HAL_IMPL_AVX512_LOGIC_OP(_Tpvec, suffix, not_const) \ + OPENCV_HAL_IMPL_AVX512_BIN_OP(&, _Tpvec, _mm512_and_##suffix) \ + OPENCV_HAL_IMPL_AVX512_BIN_OP(|, _Tpvec, _mm512_or_##suffix) \ + OPENCV_HAL_IMPL_AVX512_BIN_OP(^, _Tpvec, _mm512_xor_##suffix) \ + inline _Tpvec operator ~ (const _Tpvec& a) \ + { return _Tpvec(_mm512_xor_##suffix(a.val, not_const)); } + +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint8x64, si512, _mm512_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int8x64, si512, _mm512_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint16x32, si512, _mm512_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int16x32, si512, _mm512_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint32x16, si512, _mm512_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int32x16, si512, _mm512_set1_epi32(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint64x8, si512, _mm512_set1_epi64(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int64x8, si512, _mm512_set1_epi64(-1)) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_float32x16, ps, _mm512_castsi512_ps(_mm512_set1_epi32(-1))) +OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_float64x8, pd, _mm512_castsi512_pd(_mm512_set1_epi32(-1))) + +/** Select **/ +#define OPENCV_HAL_IMPL_AVX512_SELECT(_Tpvec, suffix, zsuf) \ + inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm512_mask_blend_##suffix(_mm512_cmp_##suffix##_mask(mask.val, _mm512_setzero_##zsuf(), _MM_CMPINT_EQ), a.val, b.val)); } + +OPENCV_HAL_IMPL_AVX512_SELECT(v_uint8x64, epi8, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_int8x64, epi8, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_uint16x32, epi16, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_int16x32, epi16, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_uint32x16, epi32, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_int32x16, epi32, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_uint64x8, epi64, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_int64x8, epi64, si512) +OPENCV_HAL_IMPL_AVX512_SELECT(v_float32x16, ps, ps) +OPENCV_HAL_IMPL_AVX512_SELECT(v_float64x8, pd, pd) + +/** Comparison **/ +#define OPENCV_HAL_IMPL_AVX512_CMP_INT(bin_op, imm8, _Tpvec, sufcmp, sufset, tval) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm512_maskz_set1_##sufset(_mm512_cmp_##sufcmp##_mask(a.val, b.val, imm8), tval)); } + +#define OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(_Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_INT(==, _MM_CMPINT_EQ, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_INT(!=, _MM_CMPINT_NE, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_INT(<, _MM_CMPINT_LT, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_INT(>, _MM_CMPINT_NLE, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_INT(<=, _MM_CMPINT_LE, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_INT(>=, _MM_CMPINT_NLT, _Tpvec, sufcmp, sufset, tval) + +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint8x64, epu8, epi8, (char)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int8x64, epi8, epi8, (char)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint16x32, epu16, epi16, (short)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int16x32, epi16, epi16, (short)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint32x16, epu32, epi32, (int)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int32x16, epi32, epi32, (int)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint64x8, epu64, epi64, (int64)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int64x8, epi64, epi64, (int64)-1) + +#define OPENCV_HAL_IMPL_AVX512_CMP_FLT(bin_op, imm8, _Tpvec, sufcmp, sufset, tval) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { return _Tpvec(_mm512_castsi512_##sufcmp(_mm512_maskz_set1_##sufset(_mm512_cmp_##sufcmp##_mask(a.val, b.val, imm8), tval))); } + +#define OPENCV_HAL_IMPL_AVX512_CMP_OP_FLT(_Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_FLT(==, _CMP_EQ_OQ, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_FLT(!=, _CMP_NEQ_OQ, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_FLT(<, _CMP_LT_OQ, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_FLT(>, _CMP_GT_OQ, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_FLT(<=, _CMP_LE_OQ, _Tpvec, sufcmp, sufset, tval) \ + OPENCV_HAL_IMPL_AVX512_CMP_FLT(>=, _CMP_GE_OQ, _Tpvec, sufcmp, sufset, tval) + +OPENCV_HAL_IMPL_AVX512_CMP_OP_FLT(v_float32x16, ps, epi32, (int)-1) +OPENCV_HAL_IMPL_AVX512_CMP_OP_FLT(v_float64x8, pd, epi64, (int64)-1) + +inline v_float32x16 v_not_nan(const v_float32x16& a) +{ return v_float32x16(_mm512_castsi512_ps(_mm512_maskz_set1_epi32(_mm512_cmp_ps_mask(a.val, a.val, _CMP_ORD_Q), (int)-1))); } +inline v_float64x8 v_not_nan(const v_float64x8& a) +{ return v_float64x8(_mm512_castsi512_pd(_mm512_maskz_set1_epi64(_mm512_cmp_pd_mask(a.val, a.val, _CMP_ORD_Q), (int64)-1))); } + +/** min/max **/ +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint8x64, _mm512_min_epu8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint8x64, _mm512_max_epu8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int8x64, _mm512_min_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int8x64, _mm512_max_epi8) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint16x32, _mm512_min_epu16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint16x32, _mm512_max_epu16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int16x32, _mm512_min_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int16x32, _mm512_max_epi16) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint32x16, _mm512_min_epu32) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint32x16, _mm512_max_epu32) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int32x16, _mm512_min_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int32x16, _mm512_max_epi32) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint64x8, _mm512_min_epu64) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint64x8, _mm512_max_epu64) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int64x8, _mm512_min_epi64) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int64x8, _mm512_max_epi64) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_float32x16, _mm512_min_ps) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_float32x16, _mm512_max_ps) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_float64x8, _mm512_min_pd) +OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_float64x8, _mm512_max_pd) + +/** Rotate **/ +namespace { + template + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64&) { return v_int8x64(); }}; + template + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64& b) + { + return v_int8x64(_mm512_or_si512(_mm512_srli_epi32(_mm512_alignr_epi32(b.val, a.val, imm32 ), imm4 *8), + _mm512_slli_epi32(_mm512_alignr_epi32(b.val, a.val, imm32 + 1), (4-imm4)*8))); + }}; + template + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64& b) + { + return v_int8x64(_mm512_or_si512(_mm512_srli_epi32(_mm512_alignr_epi32(b.val, a.val, 15), imm4 *8), + _mm512_slli_epi32( b.val, (4-imm4)*8))); + }}; + template + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b) + { + return v_int8x64(_mm512_or_si512(_mm512_srli_epi32(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, imm32 - 16), imm4 *8), + _mm512_slli_epi32(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, imm32 - 15), (4-imm4)*8))); + }}; + template + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b) + { return v_int8x64(_mm512_srli_epi32(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, 15), imm4*8)); }}; + template + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64& b) + { return v_int8x64(_mm512_alignr_epi32(b.val, a.val, imm32)); }}; + template<> + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64&) { return a; }}; + template + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b) + { return v_int8x64(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, imm32 - 16)); }}; + template<> + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b) { return b; }}; + template<> + struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64&) { return v_int8x64(); }}; +} +template inline v_int8x64 v_rotate_right(const v_int8x64& a, const v_int8x64& b) +{ + return imm >= 128 ? v_int8x64() : +#if CV_AVX_512VBMI + v_int8x64(_mm512_permutex2var_epi8(a.val, + _v512_set_epu8(0x3f + imm, 0x3e + imm, 0x3d + imm, 0x3c + imm, 0x3b + imm, 0x3a + imm, 0x39 + imm, 0x38 + imm, + 0x37 + imm, 0x36 + imm, 0x35 + imm, 0x34 + imm, 0x33 + imm, 0x32 + imm, 0x31 + imm, 0x30 + imm, + 0x2f + imm, 0x2e + imm, 0x2d + imm, 0x2c + imm, 0x2b + imm, 0x2a + imm, 0x29 + imm, 0x28 + imm, + 0x27 + imm, 0x26 + imm, 0x25 + imm, 0x24 + imm, 0x23 + imm, 0x22 + imm, 0x21 + imm, 0x20 + imm, + 0x1f + imm, 0x1e + imm, 0x1d + imm, 0x1c + imm, 0x1b + imm, 0x1a + imm, 0x19 + imm, 0x18 + imm, + 0x17 + imm, 0x16 + imm, 0x15 + imm, 0x14 + imm, 0x13 + imm, 0x12 + imm, 0x11 + imm, 0x10 + imm, + 0x0f + imm, 0x0e + imm, 0x0d + imm, 0x0c + imm, 0x0b + imm, 0x0a + imm, 0x09 + imm, 0x08 + imm, + 0x07 + imm, 0x06 + imm, 0x05 + imm, 0x04 + imm, 0x03 + imm, 0x02 + imm, 0x01 + imm, 0x00 + imm), b.val)); +#else + _v_rotate_right 15), imm/4>::eval(a, b); +#endif +} +template +inline v_int8x64 v_rotate_left(const v_int8x64& a, const v_int8x64& b) +{ + if (imm == 0) return a; + if (imm == 64) return b; + if (imm >= 128) return v_int8x64(); +#if CV_AVX_512VBMI + return v_int8x64(_mm512_permutex2var_epi8(b.val, + _v512_set_epi8(0x7f - imm,0x7e - imm,0x7d - imm,0x7c - imm,0x7b - imm,0x7a - imm,0x79 - imm,0x78 - imm, + 0x77 - imm,0x76 - imm,0x75 - imm,0x74 - imm,0x73 - imm,0x72 - imm,0x71 - imm,0x70 - imm, + 0x6f - imm,0x6e - imm,0x6d - imm,0x6c - imm,0x6b - imm,0x6a - imm,0x69 - imm,0x68 - imm, + 0x67 - imm,0x66 - imm,0x65 - imm,0x64 - imm,0x63 - imm,0x62 - imm,0x61 - imm,0x60 - imm, + 0x5f - imm,0x5e - imm,0x5d - imm,0x5c - imm,0x5b - imm,0x5a - imm,0x59 - imm,0x58 - imm, + 0x57 - imm,0x56 - imm,0x55 - imm,0x54 - imm,0x53 - imm,0x52 - imm,0x51 - imm,0x50 - imm, + 0x4f - imm,0x4e - imm,0x4d - imm,0x4c - imm,0x4b - imm,0x4a - imm,0x49 - imm,0x48 - imm, + 0x47 - imm,0x46 - imm,0x45 - imm,0x44 - imm,0x43 - imm,0x42 - imm,0x41 - imm,0x40 - imm), a.val)); +#else + return imm < 64 ? v_rotate_right<64 - imm>(b, a) : v_rotate_right<128 - imm>(v512_setzero_s8(), b); +#endif +} +template +inline v_int8x64 v_rotate_right(const v_int8x64& a) +{ + if (imm == 0) return a; + if (imm >= 64) return v_int8x64(); +#if CV_AVX_512VBMI + return v_int8x64(_mm512_maskz_permutexvar_epi8(0xFFFFFFFFFFFFFFFF >> imm, + _v512_set_epu8(0x3f + imm,0x3e + imm,0x3d + imm,0x3c + imm,0x3b + imm,0x3a + imm,0x39 + imm,0x38 + imm, + 0x37 + imm,0x36 + imm,0x35 + imm,0x34 + imm,0x33 + imm,0x32 + imm,0x31 + imm,0x30 + imm, + 0x2f + imm,0x2e + imm,0x2d + imm,0x2c + imm,0x2b + imm,0x2a + imm,0x29 + imm,0x28 + imm, + 0x27 + imm,0x26 + imm,0x25 + imm,0x24 + imm,0x23 + imm,0x22 + imm,0x21 + imm,0x20 + imm, + 0x1f + imm,0x1e + imm,0x1d + imm,0x1c + imm,0x1b + imm,0x1a + imm,0x19 + imm,0x18 + imm, + 0x17 + imm,0x16 + imm,0x15 + imm,0x14 + imm,0x13 + imm,0x12 + imm,0x11 + imm,0x10 + imm, + 0x0f + imm,0x0e + imm,0x0d + imm,0x0c + imm,0x0b + imm,0x0a + imm,0x09 + imm,0x08 + imm, + 0x07 + imm,0x06 + imm,0x05 + imm,0x04 + imm,0x03 + imm,0x02 + imm,0x01 + imm,0x00 + imm), a.val)); +#else + return v_rotate_right(a, v512_setzero_s8()); +#endif +} +template +inline v_int8x64 v_rotate_left(const v_int8x64& a) +{ + if (imm == 0) return a; + if (imm >= 64) return v_int8x64(); +#if CV_AVX_512VBMI + return v_int8x64(_mm512_maskz_permutexvar_epi8(0xFFFFFFFFFFFFFFFF << imm, + _v512_set_epi8(0x3f - imm,0x3e - imm,0x3d - imm,0x3c - imm,0x3b - imm,0x3a - imm,0x39 - imm,0x38 - imm, + 0x37 - imm,0x36 - imm,0x35 - imm,0x34 - imm,0x33 - imm,0x32 - imm,0x31 - imm,0x30 - imm, + 0x2f - imm,0x2e - imm,0x2d - imm,0x2c - imm,0x2b - imm,0x2a - imm,0x29 - imm,0x28 - imm, + 0x27 - imm,0x26 - imm,0x25 - imm,0x24 - imm,0x23 - imm,0x22 - imm,0x21 - imm,0x20 - imm, + 0x1f - imm,0x1e - imm,0x1d - imm,0x1c - imm,0x1b - imm,0x1a - imm,0x19 - imm,0x18 - imm, + 0x17 - imm,0x16 - imm,0x15 - imm,0x14 - imm,0x13 - imm,0x12 - imm,0x11 - imm,0x10 - imm, + 0x0f - imm,0x0e - imm,0x0d - imm,0x0c - imm,0x0b - imm,0x0a - imm,0x09 - imm,0x08 - imm, + 0x07 - imm,0x06 - imm,0x05 - imm,0x04 - imm,0x03 - imm,0x02 - imm,0x01 - imm,0x00 - imm), a.val)); +#else + return v_rotate_right<64 - imm>(v512_setzero_s8(), a); +#endif +} + +#define OPENCV_HAL_IMPL_AVX512_ROTATE_PM(_Tpvec, suffix) \ +template inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ return v_reinterpret_as_##suffix(v_rotate_left(v_reinterpret_as_s8(a), v_reinterpret_as_s8(b))); } \ +template inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ return v_reinterpret_as_##suffix(v_rotate_right(v_reinterpret_as_s8(a), v_reinterpret_as_s8(b))); } \ +template inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ return v_reinterpret_as_##suffix(v_rotate_left(v_reinterpret_as_s8(a))); } \ +template inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ return v_reinterpret_as_##suffix(v_rotate_right(v_reinterpret_as_s8(a))); } + +#define OPENCV_HAL_IMPL_AVX512_ROTATE_EC(_Tpvec, suffix) \ +template \ +inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ \ + enum { SHIFT2 = (_Tpvec::nlanes - imm) }; \ + enum { MASK = ((1 << _Tpvec::nlanes) - 1) }; \ + if (imm == 0) return a; \ + if (imm == _Tpvec::nlanes) return b; \ + if (imm >= 2*_Tpvec::nlanes) return _Tpvec(); \ + return _Tpvec(_mm512_mask_expand_##suffix(_mm512_maskz_compress_##suffix((MASK << SHIFT2)&MASK, b.val), (MASK << (imm))&MASK, a.val)); \ +} \ +template \ +inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ \ + enum { SHIFT2 = (_Tpvec::nlanes - imm) }; \ + enum { MASK = ((1 << _Tpvec::nlanes) - 1) }; \ + if (imm == 0) return a; \ + if (imm == _Tpvec::nlanes) return b; \ + if (imm >= 2*_Tpvec::nlanes) return _Tpvec(); \ + return _Tpvec(_mm512_mask_expand_##suffix(_mm512_maskz_compress_##suffix((MASK << (imm))&MASK, a.val), (MASK << SHIFT2)&MASK, b.val)); \ +} \ +template \ +inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ \ + if (imm == 0) return a; \ + if (imm >= _Tpvec::nlanes) return _Tpvec(); \ + return _Tpvec(_mm512_maskz_expand_##suffix((1 << _Tpvec::nlanes) - (1 << (imm)), a.val)); \ +} \ +template \ +inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ \ + if (imm == 0) return a; \ + if (imm >= _Tpvec::nlanes) return _Tpvec(); \ + return _Tpvec(_mm512_maskz_compress_##suffix((1 << _Tpvec::nlanes) - (1 << (imm)), a.val)); \ +} + +OPENCV_HAL_IMPL_AVX512_ROTATE_PM(v_uint8x64, u8) +OPENCV_HAL_IMPL_AVX512_ROTATE_PM(v_uint16x32, u16) +OPENCV_HAL_IMPL_AVX512_ROTATE_PM(v_int16x32, s16) +OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_uint32x16, epi32) +OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_int32x16, epi32) +OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_uint64x8, epi64) +OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_int64x8, epi64) +OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_float32x16, ps) +OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_float64x8, pd) + +/** Reverse **/ +inline v_uint8x64 v_reverse(const v_uint8x64 &a) +{ +#if CV_AVX_512VBMI + static const __m512i perm = _mm512_set_epi32( + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f, + 0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f, + 0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f); + return v_uint8x64(_mm512_permutexvar_epi8(perm, a.val)); +#else + static const __m512i shuf = _mm512_set_epi32( + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f, + 0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f); + static const __m512i perm = _mm512_set_epi64(1, 0, 3, 2, 5, 4, 7, 6); + __m512i vec = _mm512_shuffle_epi8(a.val, shuf); + return v_uint8x64(_mm512_permutexvar_epi64(perm, vec)); +#endif +} + +inline v_int8x64 v_reverse(const v_int8x64 &a) +{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); } + +inline v_uint16x32 v_reverse(const v_uint16x32 &a) +{ +#if CV_AVX_512VBMI + static const __m512i perm = _mm512_set_epi32( + 0x00000001, 0x00020003, 0x00040005, 0x00060007, + 0x00080009, 0x000a000b, 0x000c000d, 0x000e000f, + 0x00100011, 0x00120013, 0x00140015, 0x00160017, + 0x00180019, 0x001a001b, 0x001c001d, 0x001e001f); + return v_uint16x32(_mm512_permutexvar_epi16(perm, a.val)); +#else + static const __m512i shuf = _mm512_set_epi32( + 0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e, + 0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e, + 0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e, + 0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e); + static const __m512i perm = _mm512_set_epi64(1, 0, 3, 2, 5, 4, 7, 6); + __m512i vec = _mm512_shuffle_epi8(a.val, shuf); + return v_uint16x32(_mm512_permutexvar_epi64(perm, vec)); +#endif +} + +inline v_int16x32 v_reverse(const v_int16x32 &a) +{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); } + +inline v_uint32x16 v_reverse(const v_uint32x16 &a) +{ + static const __m512i perm = _mm512_set_epi32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,14, 15); + return v_uint32x16(_mm512_permutexvar_epi32(perm, a.val)); +} + +inline v_int32x16 v_reverse(const v_int32x16 &a) +{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_float32x16 v_reverse(const v_float32x16 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x8 v_reverse(const v_uint64x8 &a) +{ + static const __m512i perm = _mm512_set_epi64(0, 1, 2, 3, 4, 5, 6, 7); + return v_uint64x8(_mm512_permutexvar_epi64(perm, a.val)); +} + +inline v_int64x8 v_reverse(const v_int64x8 &a) +{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); } + +inline v_float64x8 v_reverse(const v_float64x8 &a) +{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); } + +////////// Reduce ///////// + +/** Reduce **/ +#define OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64(a, b) a + b +#define OPENCV_HAL_IMPL_AVX512_REDUCE_8(sctype, func, _Tpvec, ifunc, scop) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \ + sctype CV_DECL_ALIGNED(64) idx[2]; \ + _mm_store_si128((__m128i*)idx, _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1))); \ + return scop(idx[0], idx[1]); } +OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, min, v_uint64x8, min_epu64, min) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, max, v_uint64x8, max_epu64, max) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, sum, v_uint64x8, add_epi64, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, min, v_int64x8, min_epi64, min) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, max, v_int64x8, max_epi64, max) +OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, sum, v_int64x8, add_epi64, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64) + +#define OPENCV_HAL_IMPL_AVX512_REDUCE_8F(func, ifunc, scop) \ + inline double v_reduce_##func(const v_float64x8& a) \ + { __m256d half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \ + double CV_DECL_ALIGNED(64) idx[2]; \ + _mm_store_pd(idx, _mm_##ifunc(_mm256_castpd256_pd128(half), _mm256_extractf128_pd(half, 1))); \ + return scop(idx[0], idx[1]); } +OPENCV_HAL_IMPL_AVX512_REDUCE_8F(min, min_pd, min) +OPENCV_HAL_IMPL_AVX512_REDUCE_8F(max, max_pd, max) +OPENCV_HAL_IMPL_AVX512_REDUCE_8F(sum, add_pd, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64) + +#define OPENCV_HAL_IMPL_AVX512_REDUCE_16(sctype, func, _Tpvec, ifunc) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \ + __m128i quarter = _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 8)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 4)); \ + return (sctype)_mm_cvtsi128_si32(quarter); } +OPENCV_HAL_IMPL_AVX512_REDUCE_16(uint, min, v_uint32x16, min_epu32) +OPENCV_HAL_IMPL_AVX512_REDUCE_16(uint, max, v_uint32x16, max_epu32) +OPENCV_HAL_IMPL_AVX512_REDUCE_16(int, min, v_int32x16, min_epi32) +OPENCV_HAL_IMPL_AVX512_REDUCE_16(int, max, v_int32x16, max_epi32) + +#define OPENCV_HAL_IMPL_AVX512_REDUCE_16F(func, ifunc) \ + inline float v_reduce_##func(const v_float32x16& a) \ + { __m256 half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \ + __m128 quarter = _mm_##ifunc(_mm256_castps256_ps128(half), _mm256_extractf128_ps(half, 1)); \ + quarter = _mm_##ifunc(quarter, _mm_permute_ps(quarter, _MM_SHUFFLE(0, 0, 3, 2))); \ + quarter = _mm_##ifunc(quarter, _mm_permute_ps(quarter, _MM_SHUFFLE(0, 0, 0, 1))); \ + return _mm_cvtss_f32(quarter); } +OPENCV_HAL_IMPL_AVX512_REDUCE_16F(min, min_ps) +OPENCV_HAL_IMPL_AVX512_REDUCE_16F(max, max_ps) + +inline float v_reduce_sum(const v_float32x16& a) +{ + __m256 half = _mm256_add_ps(_v512_extract_low(a.val), _v512_extract_high(a.val)); + __m128 quarter = _mm_add_ps(_mm256_castps256_ps128(half), _mm256_extractf128_ps(half, 1)); + quarter = _mm_hadd_ps(quarter, quarter); + return _mm_cvtss_f32(_mm_hadd_ps(quarter, quarter)); +} +inline int v_reduce_sum(const v_int32x16& a) +{ + __m256i half = _mm256_add_epi32(_v512_extract_low(a.val), _v512_extract_high(a.val)); + __m128i quarter = _mm_add_epi32(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); + quarter = _mm_hadd_epi32(quarter, quarter); + return _mm_cvtsi128_si32(_mm_hadd_epi32(quarter, quarter)); +} +inline uint v_reduce_sum(const v_uint32x16& a) +{ return (uint)v_reduce_sum(v_reinterpret_as_s32(a)); } + +#define OPENCV_HAL_IMPL_AVX512_REDUCE_32(sctype, func, _Tpvec, ifunc) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \ + __m128i quarter = _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 8)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 4)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 2)); \ + return (sctype)_mm_cvtsi128_si32(quarter); } +OPENCV_HAL_IMPL_AVX512_REDUCE_32(ushort, min, v_uint16x32, min_epu16) +OPENCV_HAL_IMPL_AVX512_REDUCE_32(ushort, max, v_uint16x32, max_epu16) +OPENCV_HAL_IMPL_AVX512_REDUCE_32(short, min, v_int16x32, min_epi16) +OPENCV_HAL_IMPL_AVX512_REDUCE_32(short, max, v_int16x32, max_epi16) + +inline int v_reduce_sum(const v_int16x32& a) +{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); } +inline uint v_reduce_sum(const v_uint16x32& a) +{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); } + +#define OPENCV_HAL_IMPL_AVX512_REDUCE_64(sctype, func, _Tpvec, ifunc) \ + inline sctype v_reduce_##func(const _Tpvec& a) \ + { __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \ + __m128i quarter = _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 8)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 4)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 2)); \ + quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 1)); \ + return (sctype)_mm_cvtsi128_si32(quarter); } +OPENCV_HAL_IMPL_AVX512_REDUCE_64(uchar, min, v_uint8x64, min_epu8) +OPENCV_HAL_IMPL_AVX512_REDUCE_64(uchar, max, v_uint8x64, max_epu8) +OPENCV_HAL_IMPL_AVX512_REDUCE_64(schar, min, v_int8x64, min_epi8) +OPENCV_HAL_IMPL_AVX512_REDUCE_64(schar, max, v_int8x64, max_epi8) + +#define OPENCV_HAL_IMPL_AVX512_REDUCE_64_SUM(sctype, _Tpvec, suffix) \ + inline sctype v_reduce_sum(const _Tpvec& a) \ + { __m512i a16 = _mm512_add_epi16(_mm512_cvt##suffix##_epi16(_v512_extract_low(a.val)), \ + _mm512_cvt##suffix##_epi16(_v512_extract_high(a.val))); \ + a16 = _mm512_cvtepi16_epi32(_mm256_add_epi16(_v512_extract_low(a16), _v512_extract_high(a16))); \ + __m256i a8 = _mm256_add_epi32(_v512_extract_low(a16), _v512_extract_high(a16)); \ + __m128i a4 = _mm_add_epi32(_mm256_castsi256_si128(a8), _mm256_extracti128_si256(a8, 1)); \ + a4 = _mm_hadd_epi32(a4, a4); \ + return (sctype)_mm_cvtsi128_si32(_mm_hadd_epi32(a4, a4)); } +OPENCV_HAL_IMPL_AVX512_REDUCE_64_SUM(uint, v_uint8x64, epu8) +OPENCV_HAL_IMPL_AVX512_REDUCE_64_SUM(int, v_int8x64, epi8) + +inline v_float32x16 v_reduce_sum4(const v_float32x16& a, const v_float32x16& b, + const v_float32x16& c, const v_float32x16& d) +{ + __m256 abl = _mm256_hadd_ps(_v512_extract_low(a.val), _v512_extract_low(b.val)); + __m256 abh = _mm256_hadd_ps(_v512_extract_high(a.val), _v512_extract_high(b.val)); + __m256 cdl = _mm256_hadd_ps(_v512_extract_low(c.val), _v512_extract_low(d.val)); + __m256 cdh = _mm256_hadd_ps(_v512_extract_high(c.val), _v512_extract_high(d.val)); + return v_float32x16(_v512_combine(_mm256_hadd_ps(abl, cdl), _mm256_hadd_ps(abh, cdh))); +} + +inline unsigned v_reduce_sad(const v_uint8x64& a, const v_uint8x64& b) +{ + __m512i val = _mm512_sad_epu8(a.val, b.val); + __m256i half = _mm256_add_epi32(_v512_extract_low(val), _v512_extract_high(val)); + __m128i quarter = _mm_add_epi32(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter))); +} +inline unsigned v_reduce_sad(const v_int8x64& a, const v_int8x64& b) +{ + __m512i val = _mm512_set1_epi8(-128); + val = _mm512_sad_epu8(_mm512_add_epi8(a.val, val), _mm512_add_epi8(b.val, val)); + __m256i half = _mm256_add_epi32(_v512_extract_low(val), _v512_extract_high(val)); + __m128i quarter = _mm_add_epi32(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter))); +} +inline unsigned v_reduce_sad(const v_uint16x32& a, const v_uint16x32& b) +{ return v_reduce_sum(v_add_wrap(a - b, b - a)); } +inline unsigned v_reduce_sad(const v_int16x32& a, const v_int16x32& b) +{ return v_reduce_sum(v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b)))); } +inline unsigned v_reduce_sad(const v_uint32x16& a, const v_uint32x16& b) +{ return v_reduce_sum(v_max(a, b) - v_min(a, b)); } +inline unsigned v_reduce_sad(const v_int32x16& a, const v_int32x16& b) +{ return v_reduce_sum(v_reinterpret_as_u32(v_max(a, b) - v_min(a, b))); } +inline float v_reduce_sad(const v_float32x16& a, const v_float32x16& b) +{ return v_reduce_sum((a - b) & v_float32x16(_mm512_castsi512_ps(_mm512_set1_epi32(0x7fffffff)))); } +inline double v_reduce_sad(const v_float64x8& a, const v_float64x8& b) +{ return v_reduce_sum((a - b) & v_float64x8(_mm512_castsi512_pd(_mm512_set1_epi64(0x7fffffffffffffff)))); } + +/** Popcount **/ +inline v_uint8x64 v_popcount(const v_int8x64& a) +{ +#if CV_AVX_512BITALG + return v_uint8x64(_mm512_popcnt_epi8(a.val)); +#elif CV_AVX_512VBMI + __m512i _popcnt_table0 = _v512_set_epu8(7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, + 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, + 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1, + 4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0); + __m512i _popcnt_table1 = _v512_set_epu8(7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2, + 5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1); + return v_uint8x64(_mm512_sub_epi8(_mm512_permutex2var_epi8(_popcnt_table0, a.val, _popcnt_table1), _mm512_movm_epi8(_mm512_movepi8_mask(a.val)))); +#else + __m512i _popcnt_table = _mm512_set4_epi32(0x04030302, 0x03020201, 0x03020201, 0x02010100); + __m512i _popcnt_mask = _mm512_set1_epi8(0x0F); + + return v_uint8x64(_mm512_add_epi8(_mm512_shuffle_epi8(_popcnt_table, _mm512_and_si512( a.val, _popcnt_mask)), + _mm512_shuffle_epi8(_popcnt_table, _mm512_and_si512(_mm512_srli_epi16(a.val, 4), _popcnt_mask)))); +#endif +} +inline v_uint16x32 v_popcount(const v_int16x32& a) +{ +#if CV_AVX_512BITALG + return v_uint16x32(_mm512_popcnt_epi16(a.val)); +#elif CV_AVX_512VPOPCNTDQ + __m512i zero = _mm512_setzero_si512(); + return v_uint16x32(_mm512_packs_epi32(_mm512_popcnt_epi32(_mm512_unpacklo_epi16(a.val, zero)), + _mm512_popcnt_epi32(_mm512_unpackhi_epi16(a.val, zero)))); +#else + v_uint8x64 p = v_popcount(v_reinterpret_as_s8(a)); + p += v_rotate_right<1>(p); + return v_reinterpret_as_u16(p) & v512_setall_u16(0x00ff); +#endif +} +inline v_uint32x16 v_popcount(const v_int32x16& a) +{ +#if CV_AVX_512VPOPCNTDQ + return v_uint32x16(_mm512_popcnt_epi32(a.val)); +#else + v_uint8x64 p = v_popcount(v_reinterpret_as_s8(a)); + p += v_rotate_right<1>(p); + p += v_rotate_right<2>(p); + return v_reinterpret_as_u32(p) & v512_setall_u32(0x000000ff); +#endif +} +inline v_uint64x8 v_popcount(const v_int64x8& a) +{ +#if CV_AVX_512VPOPCNTDQ + return v_uint64x8(_mm512_popcnt_epi64(a.val)); +#else + return v_uint64x8(_mm512_sad_epu8(v_popcount(v_reinterpret_as_s8(a)).val, _mm512_setzero_si512())); +#endif +} + + +inline v_uint8x64 v_popcount(const v_uint8x64& a) { return v_popcount(v_reinterpret_as_s8 (a)); } +inline v_uint16x32 v_popcount(const v_uint16x32& a) { return v_popcount(v_reinterpret_as_s16(a)); } +inline v_uint32x16 v_popcount(const v_uint32x16& a) { return v_popcount(v_reinterpret_as_s32(a)); } +inline v_uint64x8 v_popcount(const v_uint64x8& a) { return v_popcount(v_reinterpret_as_s64(a)); } + + +////////// Other math ///////// + +/** Some frequent operations **/ +#define OPENCV_HAL_IMPL_AVX512_MULADD(_Tpvec, suffix) \ + inline _Tpvec v_fma(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ + { return _Tpvec(_mm512_fmadd_##suffix(a.val, b.val, c.val)); } \ + inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ + { return _Tpvec(_mm512_fmadd_##suffix(a.val, b.val, c.val)); } \ + inline _Tpvec v_sqrt(const _Tpvec& x) \ + { return _Tpvec(_mm512_sqrt_##suffix(x.val)); } \ + inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ + { return v_fma(a, a, b * b); } \ + inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ + { return v_sqrt(v_fma(a, a, b * b)); } + +OPENCV_HAL_IMPL_AVX512_MULADD(v_float32x16, ps) +OPENCV_HAL_IMPL_AVX512_MULADD(v_float64x8, pd) + +inline v_int32x16 v_fma(const v_int32x16& a, const v_int32x16& b, const v_int32x16& c) +{ return a * b + c; } +inline v_int32x16 v_muladd(const v_int32x16& a, const v_int32x16& b, const v_int32x16& c) +{ return v_fma(a, b, c); } + +inline v_float32x16 v_invsqrt(const v_float32x16& x) +{ +#if CV_AVX_512ER + return v_float32x16(_mm512_rsqrt28_ps(x.val)); +#else + v_float32x16 half = x * v512_setall_f32(0.5); + v_float32x16 t = v_float32x16(_mm512_rsqrt14_ps(x.val)); + t *= v512_setall_f32(1.5) - ((t * t) * half); + return t; +#endif +} + +inline v_float64x8 v_invsqrt(const v_float64x8& x) +{ +#if CV_AVX_512ER + return v_float64x8(_mm512_rsqrt28_pd(x.val)); +#else + return v512_setall_f64(1.) / v_sqrt(x); +// v_float64x8 half = x * v512_setall_f64(0.5); +// v_float64x8 t = v_float64x8(_mm512_rsqrt14_pd(x.val)); +// t *= v512_setall_f64(1.5) - ((t * t) * half); +// t *= v512_setall_f64(1.5) - ((t * t) * half); +// return t; +#endif +} + +/** Absolute values **/ +#define OPENCV_HAL_IMPL_AVX512_ABS(_Tpvec, _Tpuvec, suffix) \ + inline _Tpuvec v_abs(const _Tpvec& x) \ + { return _Tpuvec(_mm512_abs_##suffix(x.val)); } + +OPENCV_HAL_IMPL_AVX512_ABS(v_int8x64, v_uint8x64, epi8) +OPENCV_HAL_IMPL_AVX512_ABS(v_int16x32, v_uint16x32, epi16) +OPENCV_HAL_IMPL_AVX512_ABS(v_int32x16, v_uint32x16, epi32) +OPENCV_HAL_IMPL_AVX512_ABS(v_int64x8, v_uint64x8, epi64) + +inline v_float32x16 v_abs(const v_float32x16& x) +{ +#ifdef _mm512_abs_pd + return v_float32x16(_mm512_abs_ps(x.val)); +#else + return v_float32x16(_mm512_castsi512_ps(_mm512_and_si512(_mm512_castps_si512(x.val), + _v512_set_epu64(0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, + 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF)))); +#endif +} + +inline v_float64x8 v_abs(const v_float64x8& x) +{ +#ifdef _mm512_abs_pd + #if defined __GNUC__ && (__GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ <= 3) || (__GNUC__ == 8 && __GNUC_MINOR__ <= 2)) + // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87476 + return v_float64x8(_mm512_abs_pd(_mm512_castpd_ps(x.val))); + #else + return v_float64x8(_mm512_abs_pd(x.val)); + #endif +#else + return v_float64x8(_mm512_castsi512_pd(_mm512_and_si512(_mm512_castpd_si512(x.val), + _v512_set_epu64(0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, + 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF)))); +#endif +} + +/** Absolute difference **/ +inline v_uint8x64 v_absdiff(const v_uint8x64& a, const v_uint8x64& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint16x32 v_absdiff(const v_uint16x32& a, const v_uint16x32& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint32x16 v_absdiff(const v_uint32x16& a, const v_uint32x16& b) +{ return v_max(a, b) - v_min(a, b); } + +inline v_uint8x64 v_absdiff(const v_int8x64& a, const v_int8x64& b) +{ + v_int8x64 d = v_sub_wrap(a, b); + v_int8x64 m = a < b; + return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m)); +} + +inline v_uint16x32 v_absdiff(const v_int16x32& a, const v_int16x32& b) +{ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); } + +inline v_uint32x16 v_absdiff(const v_int32x16& a, const v_int32x16& b) +{ + v_int32x16 d = a - b; + v_int32x16 m = a < b; + return v_reinterpret_as_u32((d ^ m) - m); +} + +inline v_float32x16 v_absdiff(const v_float32x16& a, const v_float32x16& b) +{ return v_abs(a - b); } + +inline v_float64x8 v_absdiff(const v_float64x8& a, const v_float64x8& b) +{ return v_abs(a - b); } + +/** Saturating absolute difference **/ +inline v_int8x64 v_absdiffs(const v_int8x64& a, const v_int8x64& b) +{ + v_int8x64 d = a - b; + v_int8x64 m = a < b; + return (d ^ m) - m; +} +inline v_int16x32 v_absdiffs(const v_int16x32& a, const v_int16x32& b) +{ return v_max(a, b) - v_min(a, b); } + +////////// Conversions ///////// + +/** Rounding **/ +inline v_int32x16 v_round(const v_float32x16& a) +{ return v_int32x16(_mm512_cvtps_epi32(a.val)); } + +inline v_int32x16 v_round(const v_float64x8& a) +{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvtpd_epi32(a.val))); } + +inline v_int32x16 v_round(const v_float64x8& a, const v_float64x8& b) +{ return v_int32x16(_v512_combine(_mm512_cvtpd_epi32(a.val), _mm512_cvtpd_epi32(b.val))); } + +inline v_int32x16 v_trunc(const v_float32x16& a) +{ return v_int32x16(_mm512_cvttps_epi32(a.val)); } + +inline v_int32x16 v_trunc(const v_float64x8& a) +{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvttpd_epi32(a.val))); } + +#if CVT_ROUND_MODES_IMPLEMENTED +inline v_int32x16 v_floor(const v_float32x16& a) +{ return v_int32x16(_mm512_cvt_roundps_epi32(a.val, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)); } + +inline v_int32x16 v_floor(const v_float64x8& a) +{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvt_roundpd_epi32(a.val, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC))); } + +inline v_int32x16 v_ceil(const v_float32x16& a) +{ return v_int32x16(_mm512_cvt_roundps_epi32(a.val, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)); } + +inline v_int32x16 v_ceil(const v_float64x8& a) +{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvt_roundpd_epi32(a.val, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC))); } +#else +inline v_int32x16 v_floor(const v_float32x16& a) +{ return v_int32x16(_mm512_cvtps_epi32(_mm512_roundscale_ps(a.val, 1))); } + +inline v_int32x16 v_floor(const v_float64x8& a) +{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvtpd_epi32(_mm512_roundscale_pd(a.val, 1)))); } + +inline v_int32x16 v_ceil(const v_float32x16& a) +{ return v_int32x16(_mm512_cvtps_epi32(_mm512_roundscale_ps(a.val, 2))); } + +inline v_int32x16 v_ceil(const v_float64x8& a) +{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvtpd_epi32(_mm512_roundscale_pd(a.val, 2)))); } +#endif + +/** To float **/ +inline v_float32x16 v_cvt_f32(const v_int32x16& a) +{ return v_float32x16(_mm512_cvtepi32_ps(a.val)); } + +inline v_float32x16 v_cvt_f32(const v_float64x8& a) +{ return v_float32x16(_mm512_cvtpd_pslo(a.val)); } + +inline v_float32x16 v_cvt_f32(const v_float64x8& a, const v_float64x8& b) +{ return v_float32x16(_v512_combine(_mm512_cvtpd_ps(a.val), _mm512_cvtpd_ps(b.val))); } + +inline v_float64x8 v_cvt_f64(const v_int32x16& a) +{ return v_float64x8(_mm512_cvtepi32_pd(_v512_extract_low(a.val))); } + +inline v_float64x8 v_cvt_f64_high(const v_int32x16& a) +{ return v_float64x8(_mm512_cvtepi32_pd(_v512_extract_high(a.val))); } + +inline v_float64x8 v_cvt_f64(const v_float32x16& a) +{ return v_float64x8(_mm512_cvtps_pd(_v512_extract_low(a.val))); } + +inline v_float64x8 v_cvt_f64_high(const v_float32x16& a) +{ return v_float64x8(_mm512_cvtps_pd(_v512_extract_high(a.val))); } + +// from (Mysticial and wim) https://stackoverflow.com/q/41144668 +inline v_float64x8 v_cvt_f64(const v_int64x8& v) +{ +#if CV_AVX_512DQ + return v_float64x8(_mm512_cvtepi64_pd(v.val)); +#else + // constants encoded as floating-point + __m512i magic_i_lo = _mm512_set1_epi64x(0x4330000000000000); // 2^52 + __m512i magic_i_hi32 = _mm512_set1_epi64x(0x4530000080000000); // 2^84 + 2^63 + __m512i magic_i_all = _mm512_set1_epi64x(0x4530000080100000); // 2^84 + 2^63 + 2^52 + __m512d magic_d_all = _mm512_castsi512_pd(magic_i_all); + + // Blend the 32 lowest significant bits of v with magic_int_lo + __m512i v_lo = _mm512_blend_epi32(magic_i_lo, v.val, 0x55); + // Extract the 32 most significant bits of v + __m512i v_hi = _mm512_srli_epi64(v.val, 32); + // Flip the msb of v_hi and blend with 0x45300000 + v_hi = _mm512_xor_si512(v_hi, magic_i_hi32); + // Compute in double precision + __m512d v_hi_dbl = _mm512_sub_pd(_mm512_castsi512_pd(v_hi), magic_d_all); + // (v_hi - magic_d_all) + v_lo Do not assume associativity of floating point addition + __m512d result = _mm512_add_pd(v_hi_dbl, _mm512_castsi512_pd(v_lo)); + return v_float64x8(result); +#endif +} + +////////////// Lookup table access //////////////////// + +inline v_int8x64 v512_lut(const schar* tab, const int* idx) +{ + __m128i p0 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx ), (const int *)tab, 1)); + __m128i p1 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 1), (const int *)tab, 1)); + __m128i p2 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 2), (const int *)tab, 1)); + __m128i p3 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 3), (const int *)tab, 1)); + return v_int8x64(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_castsi128_si512(p0), p1, 1), p2, 2), p3, 3)); +} +inline v_int8x64 v512_lut_pairs(const schar* tab, const int* idx) +{ + __m256i p0 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx ), (const int *)tab, 1)); + __m256i p1 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 1), (const int *)tab, 1)); + return v_int8x64(_v512_combine(p0, p1)); +} +inline v_int8x64 v512_lut_quads(const schar* tab, const int* idx) +{ + return v_int8x64(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx), (const int *)tab, 1)); +} +inline v_uint8x64 v512_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v512_lut((const schar *)tab, idx)); } +inline v_uint8x64 v512_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v512_lut_pairs((const schar *)tab, idx)); } +inline v_uint8x64 v512_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v512_lut_quads((const schar *)tab, idx)); } + +inline v_int16x32 v512_lut(const short* tab, const int* idx) +{ + __m256i p0 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx ), (const int *)tab, 2)); + __m256i p1 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 1), (const int *)tab, 2)); + return v_int16x32(_v512_combine(p0, p1)); +} +inline v_int16x32 v512_lut_pairs(const short* tab, const int* idx) +{ + return v_int16x32(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx), (const int *)tab, 2)); +} +inline v_int16x32 v512_lut_quads(const short* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int16x32(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const long long int*)tab, 2)); +#else + return v_int16x32(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const int64*)tab, 2)); +#endif +} +inline v_uint16x32 v512_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v512_lut((const short *)tab, idx)); } +inline v_uint16x32 v512_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v512_lut_pairs((const short *)tab, idx)); } +inline v_uint16x32 v512_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v512_lut_quads((const short *)tab, idx)); } + +inline v_int32x16 v512_lut(const int* tab, const int* idx) +{ + return v_int32x16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx), tab, 4)); +} +inline v_int32x16 v512_lut_pairs(const int* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int32x16(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const long long int*)tab, 4)); +#else + return v_int32x16(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const int64*)tab, 4)); +#endif +} +inline v_int32x16 v512_lut_quads(const int* tab, const int* idx) +{ + return v_int32x16(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_castsi128_si512( + _mm_loadu_si128((const __m128i*)(tab + idx[0]))), + _mm_loadu_si128((const __m128i*)(tab + idx[1])), 1), + _mm_loadu_si128((const __m128i*)(tab + idx[2])), 2), + _mm_loadu_si128((const __m128i*)(tab + idx[3])), 3)); +} +inline v_uint32x16 v512_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v512_lut((const int *)tab, idx)); } +inline v_uint32x16 v512_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v512_lut_pairs((const int *)tab, idx)); } +inline v_uint32x16 v512_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v512_lut_quads((const int *)tab, idx)); } + +inline v_int64x8 v512_lut(const int64* tab, const int* idx) +{ +#if defined(__GNUC__) + return v_int64x8(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const long long int*)tab, 8)); +#else + return v_int64x8(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), tab , 8)); +#endif +} +inline v_int64x8 v512_lut_pairs(const int64* tab, const int* idx) +{ + return v_int64x8(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_castsi128_si512( + _mm_loadu_si128((const __m128i*)(tab + idx[0]))), + _mm_loadu_si128((const __m128i*)(tab + idx[1])), 1), + _mm_loadu_si128((const __m128i*)(tab + idx[2])), 2), + _mm_loadu_si128((const __m128i*)(tab + idx[3])), 3)); +} +inline v_uint64x8 v512_lut(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v512_lut((const int64 *)tab, idx)); } +inline v_uint64x8 v512_lut_pairs(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v512_lut_pairs((const int64 *)tab, idx)); } + +inline v_float32x16 v512_lut(const float* tab, const int* idx) +{ + return v_float32x16(_mm512_i32gather_ps(_mm512_loadu_si512((const __m512i*)idx), tab, 4)); +} +inline v_float32x16 v512_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v512_lut_pairs((const int *)tab, idx)); } +inline v_float32x16 v512_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v512_lut_quads((const int *)tab, idx)); } + +inline v_float64x8 v512_lut(const double* tab, const int* idx) +{ + return v_float64x8(_mm512_i32gather_pd(_mm256_loadu_si256((const __m256i*)idx), tab, 8)); +} +inline v_float64x8 v512_lut_pairs(const double* tab, const int* idx) +{ + return v_float64x8(_mm512_insertf64x2(_mm512_insertf64x2(_mm512_insertf64x2(_mm512_castpd128_pd512( + _mm_loadu_pd(tab + idx[0])), + _mm_loadu_pd(tab + idx[1]), 1), + _mm_loadu_pd(tab + idx[2]), 2), + _mm_loadu_pd(tab + idx[3]), 3)); +} + +inline v_int32x16 v_lut(const int* tab, const v_int32x16& idxvec) +{ + return v_int32x16(_mm512_i32gather_epi32(idxvec.val, tab, 4)); +} + +inline v_uint32x16 v_lut(const unsigned* tab, const v_int32x16& idxvec) +{ + return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec)); +} + +inline v_float32x16 v_lut(const float* tab, const v_int32x16& idxvec) +{ + return v_float32x16(_mm512_i32gather_ps(idxvec.val, tab, 4)); +} + +inline v_float64x8 v_lut(const double* tab, const v_int32x16& idxvec) +{ + return v_float64x8(_mm512_i32gather_pd(_v512_extract_low(idxvec.val), tab, 8)); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x16& idxvec, v_float32x16& x, v_float32x16& y) +{ + x.val = _mm512_i32gather_ps(idxvec.val, tab, 4); + y.val = _mm512_i32gather_ps(idxvec.val, &tab[1], 4); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x16& idxvec, v_float64x8& x, v_float64x8& y) +{ + x.val = _mm512_i32gather_pd(_v512_extract_low(idxvec.val), tab, 8); + y.val = _mm512_i32gather_pd(_v512_extract_low(idxvec.val), &tab[1], 8); +} + +inline v_int8x64 v_interleave_pairs(const v_int8x64& vec) +{ + return v_int8x64(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0d0e0c, 0x0b090a08, 0x07050604, 0x03010200))); +} +inline v_uint8x64 v_interleave_pairs(const v_uint8x64& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x64 v_interleave_quads(const v_int8x64& vec) +{ + return v_int8x64(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0b0e0a, 0x0d090c08, 0x07030602, 0x05010400))); +} +inline v_uint8x64 v_interleave_quads(const v_uint8x64& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x32 v_interleave_pairs(const v_int16x32& vec) +{ + return v_int16x32(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0e0b0a, 0x0d0c0908, 0x07060302, 0x05040100))); +} +inline v_uint16x32 v_interleave_pairs(const v_uint16x32& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x32 v_interleave_quads(const v_int16x32& vec) +{ + return v_int16x32(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0e0706, 0x0d0c0504, 0x0b0a0302, 0x09080100))); +} +inline v_uint16x32 v_interleave_quads(const v_uint16x32& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x16 v_interleave_pairs(const v_int32x16& vec) +{ + return v_int32x16(_mm512_shuffle_epi32(vec.val, _MM_PERM_ACBD)); +} +inline v_uint32x16 v_interleave_pairs(const v_uint32x16& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x16 v_interleave_pairs(const v_float32x16& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x64 v_pack_triplets(const v_int8x64& vec) +{ + return v_int8x64(_mm512_permutexvar_epi32(_v512_set_epu64(0x0000000f0000000f, 0x0000000f0000000f, 0x0000000e0000000d, 0x0000000c0000000a, + 0x0000000900000008, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000), + _mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0xffffff0f, 0x0e0d0c0a, 0x09080605, 0x04020100)))); +} +inline v_uint8x64 v_pack_triplets(const v_uint8x64& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x32 v_pack_triplets(const v_int16x32& vec) +{ + return v_int16x32(_mm512_permutexvar_epi16(_v512_set_epu64(0x001f001f001f001f, 0x001f001f001f001f, 0x001e001d001c001a, 0x0019001800160015, + 0x0014001200110010, 0x000e000d000c000a, 0x0009000800060005, 0x0004000200010000), vec.val)); +} +inline v_uint16x32 v_pack_triplets(const v_uint16x32& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x16 v_pack_triplets(const v_int32x16& vec) +{ + return v_int32x16(_mm512_permutexvar_epi32(_v512_set_epu64(0x0000000f0000000f, 0x0000000f0000000f, 0x0000000e0000000d, 0x0000000c0000000a, + 0x0000000900000008, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000), vec.val)); +} +inline v_uint32x16 v_pack_triplets(const v_uint32x16& vec) { return v_reinterpret_as_u32(v_pack_triplets(v_reinterpret_as_s32(vec))); } +inline v_float32x16 v_pack_triplets(const v_float32x16& vec) +{ + return v_float32x16(_mm512_permutexvar_ps(_v512_set_epu64(0x0000000f0000000f, 0x0000000f0000000f, 0x0000000e0000000d, 0x0000000c0000000a, + 0x0000000900000008, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000), vec.val)); +} + +////////// Matrix operations ///////// + +//////// Dot Product //////// + +// 16 >> 32 +inline v_int32x16 v_dotprod(const v_int16x32& a, const v_int16x32& b) +{ return v_int32x16(_mm512_madd_epi16(a.val, b.val)); } +inline v_int32x16 v_dotprod(const v_int16x32& a, const v_int16x32& b, const v_int32x16& c) +{ return v_dotprod(a, b) + c; } + +// 32 >> 64 +inline v_int64x8 v_dotprod(const v_int32x16& a, const v_int32x16& b) +{ + __m512i even = _mm512_mul_epi32(a.val, b.val); + __m512i odd = _mm512_mul_epi32(_mm512_srli_epi64(a.val, 32), _mm512_srli_epi64(b.val, 32)); + return v_int64x8(_mm512_add_epi64(even, odd)); +} +inline v_int64x8 v_dotprod(const v_int32x16& a, const v_int32x16& b, const v_int64x8& c) +{ return v_dotprod(a, b) + c; } + +// 8 >> 32 +inline v_uint32x16 v_dotprod_expand(const v_uint8x64& a, const v_uint8x64& b) +{ + __m512i even_a = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, a.val, _mm512_setzero_si512()); + __m512i odd_a = _mm512_srli_epi16(a.val, 8); + + __m512i even_b = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, b.val, _mm512_setzero_si512()); + __m512i odd_b = _mm512_srli_epi16(b.val, 8); + + __m512i prod0 = _mm512_madd_epi16(even_a, even_b); + __m512i prod1 = _mm512_madd_epi16(odd_a, odd_b); + return v_uint32x16(_mm512_add_epi32(prod0, prod1)); +} +inline v_uint32x16 v_dotprod_expand(const v_uint8x64& a, const v_uint8x64& b, const v_uint32x16& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int32x16 v_dotprod_expand(const v_int8x64& a, const v_int8x64& b) +{ + __m512i even_a = _mm512_srai_epi16(_mm512_bslli_epi128(a.val, 1), 8); + __m512i odd_a = _mm512_srai_epi16(a.val, 8); + + __m512i even_b = _mm512_srai_epi16(_mm512_bslli_epi128(b.val, 1), 8); + __m512i odd_b = _mm512_srai_epi16(b.val, 8); + + __m512i prod0 = _mm512_madd_epi16(even_a, even_b); + __m512i prod1 = _mm512_madd_epi16(odd_a, odd_b); + return v_int32x16(_mm512_add_epi32(prod0, prod1)); +} +inline v_int32x16 v_dotprod_expand(const v_int8x64& a, const v_int8x64& b, const v_int32x16& c) +{ return v_dotprod_expand(a, b) + c; } + +// 16 >> 64 +inline v_uint64x8 v_dotprod_expand(const v_uint16x32& a, const v_uint16x32& b) +{ + __m512i mullo = _mm512_mullo_epi16(a.val, b.val); + __m512i mulhi = _mm512_mulhi_epu16(a.val, b.val); + __m512i mul0 = _mm512_unpacklo_epi16(mullo, mulhi); + __m512i mul1 = _mm512_unpackhi_epi16(mullo, mulhi); + + __m512i p02 = _mm512_mask_blend_epi32(0xAAAA, mul0, _mm512_setzero_si512()); + __m512i p13 = _mm512_srli_epi64(mul0, 32); + __m512i p46 = _mm512_mask_blend_epi32(0xAAAA, mul1, _mm512_setzero_si512()); + __m512i p57 = _mm512_srli_epi64(mul1, 32); + + __m512i p15_ = _mm512_add_epi64(p02, p13); + __m512i p9d_ = _mm512_add_epi64(p46, p57); + + return v_uint64x8(_mm512_add_epi64( + _mm512_unpacklo_epi64(p15_, p9d_), + _mm512_unpackhi_epi64(p15_, p9d_) + )); +} +inline v_uint64x8 v_dotprod_expand(const v_uint16x32& a, const v_uint16x32& b, const v_uint64x8& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int64x8 v_dotprod_expand(const v_int16x32& a, const v_int16x32& b) +{ + __m512i prod = _mm512_madd_epi16(a.val, b.val); + __m512i even = _mm512_srai_epi64(_mm512_bslli_epi128(prod, 4), 32); + __m512i odd = _mm512_srai_epi64(prod, 32); + return v_int64x8(_mm512_add_epi64(even, odd)); +} +inline v_int64x8 v_dotprod_expand(const v_int16x32& a, const v_int16x32& b, const v_int64x8& c) +{ return v_dotprod_expand(a, b) + c; } + +// 32 >> 64f +inline v_float64x8 v_dotprod_expand(const v_int32x16& a, const v_int32x16& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x8 v_dotprod_expand(const v_int32x16& a, const v_int32x16& b, const v_float64x8& c) +{ return v_dotprod_expand(a, b) + c; } + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x16 v_dotprod_fast(const v_int16x32& a, const v_int16x32& b) +{ return v_dotprod(a, b); } +inline v_int32x16 v_dotprod_fast(const v_int16x32& a, const v_int16x32& b, const v_int32x16& c) +{ return v_dotprod(a, b, c); } + +// 32 >> 64 +inline v_int64x8 v_dotprod_fast(const v_int32x16& a, const v_int32x16& b) +{ return v_dotprod(a, b); } +inline v_int64x8 v_dotprod_fast(const v_int32x16& a, const v_int32x16& b, const v_int64x8& c) +{ return v_dotprod(a, b, c); } + +// 8 >> 32 +inline v_uint32x16 v_dotprod_expand_fast(const v_uint8x64& a, const v_uint8x64& b) +{ return v_dotprod_expand(a, b); } +inline v_uint32x16 v_dotprod_expand_fast(const v_uint8x64& a, const v_uint8x64& b, const v_uint32x16& c) +{ return v_dotprod_expand(a, b, c); } + +inline v_int32x16 v_dotprod_expand_fast(const v_int8x64& a, const v_int8x64& b) +{ return v_dotprod_expand(a, b); } +inline v_int32x16 v_dotprod_expand_fast(const v_int8x64& a, const v_int8x64& b, const v_int32x16& c) +{ return v_dotprod_expand(a, b, c); } + +// 16 >> 64 +inline v_uint64x8 v_dotprod_expand_fast(const v_uint16x32& a, const v_uint16x32& b) +{ + __m512i mullo = _mm512_mullo_epi16(a.val, b.val); + __m512i mulhi = _mm512_mulhi_epu16(a.val, b.val); + __m512i mul0 = _mm512_unpacklo_epi16(mullo, mulhi); + __m512i mul1 = _mm512_unpackhi_epi16(mullo, mulhi); + + __m512i p02 = _mm512_mask_blend_epi32(0xAAAA, mul0, _mm512_setzero_si512()); + __m512i p13 = _mm512_srli_epi64(mul0, 32); + __m512i p46 = _mm512_mask_blend_epi32(0xAAAA, mul1, _mm512_setzero_si512()); + __m512i p57 = _mm512_srli_epi64(mul1, 32); + + __m512i p15_ = _mm512_add_epi64(p02, p13); + __m512i p9d_ = _mm512_add_epi64(p46, p57); + return v_uint64x8(_mm512_add_epi64(p15_, p9d_)); +} +inline v_uint64x8 v_dotprod_expand_fast(const v_uint16x32& a, const v_uint16x32& b, const v_uint64x8& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +inline v_int64x8 v_dotprod_expand_fast(const v_int16x32& a, const v_int16x32& b) +{ return v_dotprod_expand(a, b); } +inline v_int64x8 v_dotprod_expand_fast(const v_int16x32& a, const v_int16x32& b, const v_int64x8& c) +{ return v_dotprod_expand(a, b, c); } + +// 32 >> 64f +inline v_float64x8 v_dotprod_expand_fast(const v_int32x16& a, const v_int32x16& b) +{ return v_dotprod_expand(a, b); } +inline v_float64x8 v_dotprod_expand_fast(const v_int32x16& a, const v_int32x16& b, const v_float64x8& c) +{ return v_dotprod_expand(a, b) + c; } + + +#define OPENCV_HAL_AVX512_SPLAT2_PS(a, im) \ + v_float32x16(_mm512_permute_ps(a.val, _MM_SHUFFLE(im, im, im, im))) + +inline v_float32x16 v_matmul(const v_float32x16& v, + const v_float32x16& m0, const v_float32x16& m1, + const v_float32x16& m2, const v_float32x16& m3) +{ + v_float32x16 v04 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 0); + v_float32x16 v15 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 1); + v_float32x16 v26 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 2); + v_float32x16 v37 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 3); + return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, v37 * m3))); +} + +inline v_float32x16 v_matmuladd(const v_float32x16& v, + const v_float32x16& m0, const v_float32x16& m1, + const v_float32x16& m2, const v_float32x16& a) +{ + v_float32x16 v04 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 0); + v_float32x16 v15 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 1); + v_float32x16 v26 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 2); + return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, a))); +} + +#define OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \ + inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \ + { \ + __m512i t0 = cast_from(_mm512_unpacklo_##suffix(a0.val, a1.val)); \ + __m512i t1 = cast_from(_mm512_unpacklo_##suffix(a2.val, a3.val)); \ + __m512i t2 = cast_from(_mm512_unpackhi_##suffix(a0.val, a1.val)); \ + __m512i t3 = cast_from(_mm512_unpackhi_##suffix(a2.val, a3.val)); \ + b0.val = cast_to(_mm512_unpacklo_epi64(t0, t1)); \ + b1.val = cast_to(_mm512_unpackhi_epi64(t0, t1)); \ + b2.val = cast_to(_mm512_unpacklo_epi64(t2, t3)); \ + b3.val = cast_to(_mm512_unpackhi_epi64(t2, t3)); \ + } + +OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(v_uint32x16, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(v_int32x16, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(v_float32x16, ps, _mm512_castps_si512, _mm512_castsi512_ps) + +//////////////// Value reordering /////////////// + +/* Expand */ +#define OPENCV_HAL_IMPL_AVX512_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \ + inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ + { \ + b0.val = intrin(_v512_extract_low(a.val)); \ + b1.val = intrin(_v512_extract_high(a.val)); \ + } \ + inline _Tpwvec v_expand_low(const _Tpvec& a) \ + { return _Tpwvec(intrin(_v512_extract_low(a.val))); } \ + inline _Tpwvec v_expand_high(const _Tpvec& a) \ + { return _Tpwvec(intrin(_v512_extract_high(a.val))); } \ + inline _Tpwvec v512_load_expand(const _Tp* ptr) \ + { \ + __m256i a = _mm256_loadu_si256((const __m256i*)ptr); \ + return _Tpwvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_AVX512_EXPAND(v_uint8x64, v_uint16x32, uchar, _mm512_cvtepu8_epi16) +OPENCV_HAL_IMPL_AVX512_EXPAND(v_int8x64, v_int16x32, schar, _mm512_cvtepi8_epi16) +OPENCV_HAL_IMPL_AVX512_EXPAND(v_uint16x32, v_uint32x16, ushort, _mm512_cvtepu16_epi32) +OPENCV_HAL_IMPL_AVX512_EXPAND(v_int16x32, v_int32x16, short, _mm512_cvtepi16_epi32) +OPENCV_HAL_IMPL_AVX512_EXPAND(v_uint32x16, v_uint64x8, unsigned, _mm512_cvtepu32_epi64) +OPENCV_HAL_IMPL_AVX512_EXPAND(v_int32x16, v_int64x8, int, _mm512_cvtepi32_epi64) + +#define OPENCV_HAL_IMPL_AVX512_EXPAND_Q(_Tpvec, _Tp, intrin) \ + inline _Tpvec v512_load_expand_q(const _Tp* ptr) \ + { \ + __m128i a = _mm_loadu_si128((const __m128i*)ptr); \ + return _Tpvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_AVX512_EXPAND_Q(v_uint32x16, uchar, _mm512_cvtepu8_epi32) +OPENCV_HAL_IMPL_AVX512_EXPAND_Q(v_int32x16, schar, _mm512_cvtepi8_epi32) + +/* pack */ +// 16 +inline v_int8x64 v_pack(const v_int16x32& a, const v_int16x32& b) +{ return v_int8x64(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packs_epi16(a.val, b.val))); } + +inline v_uint8x64 v_pack(const v_uint16x32& a, const v_uint16x32& b) +{ + const __m512i t = _mm512_set1_epi16(255); + return v_uint8x64(_v512_combine(_mm512_cvtepi16_epi8(_mm512_min_epu16(a.val, t)), _mm512_cvtepi16_epi8(_mm512_min_epu16(b.val, t)))); +} + +inline v_uint8x64 v_pack_u(const v_int16x32& a, const v_int16x32& b) +{ + return v_uint8x64(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packus_epi16(a.val, b.val))); +} + +inline void v_pack_store(schar* ptr, const v_int16x32& a) +{ v_store_low(ptr, v_pack(a, a)); } + +inline void v_pack_store(uchar* ptr, const v_uint16x32& a) +{ + const __m512i m = _mm512_set1_epi16(255); + _mm256_storeu_si256((__m256i*)ptr, _mm512_cvtepi16_epi8(_mm512_min_epu16(a.val, m))); +} + +inline void v_pack_u_store(uchar* ptr, const v_int16x32& a) +{ v_store_low(ptr, v_pack_u(a, a)); } + +template inline +v_uint8x64 v_rshr_pack(const v_uint16x32& a, const v_uint16x32& b) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + v_uint16x32 delta = v512_setall_u16((short)(1 << (n-1))); + return v_pack_u(v_reinterpret_as_s16((a + delta) >> n), + v_reinterpret_as_s16((b + delta) >> n)); +} + +template inline +void v_rshr_pack_store(uchar* ptr, const v_uint16x32& a) +{ + v_uint16x32 delta = v512_setall_u16((short)(1 << (n-1))); + v_pack_u_store(ptr, v_reinterpret_as_s16((a + delta) >> n)); +} + +template inline +v_uint8x64 v_rshr_pack_u(const v_int16x32& a, const v_int16x32& b) +{ + v_int16x32 delta = v512_setall_s16((short)(1 << (n-1))); + return v_pack_u((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_u_store(uchar* ptr, const v_int16x32& a) +{ + v_int16x32 delta = v512_setall_s16((short)(1 << (n-1))); + v_pack_u_store(ptr, (a + delta) >> n); +} + +template inline +v_int8x64 v_rshr_pack(const v_int16x32& a, const v_int16x32& b) +{ + v_int16x32 delta = v512_setall_s16((short)(1 << (n-1))); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(schar* ptr, const v_int16x32& a) +{ + v_int16x32 delta = v512_setall_s16((short)(1 << (n-1))); + v_pack_store(ptr, (a + delta) >> n); +} + +// 32 +inline v_int16x32 v_pack(const v_int32x16& a, const v_int32x16& b) +{ return v_int16x32(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packs_epi32(a.val, b.val))); } + +inline v_uint16x32 v_pack(const v_uint32x16& a, const v_uint32x16& b) +{ + const __m512i m = _mm512_set1_epi32(65535); + return v_uint16x32(_v512_combine(_mm512_cvtepi32_epi16(_mm512_min_epu32(a.val, m)), _mm512_cvtepi32_epi16(_mm512_min_epu32(b.val, m)))); +} + +inline v_uint16x32 v_pack_u(const v_int32x16& a, const v_int32x16& b) +{ return v_uint16x32(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packus_epi32(a.val, b.val))); } + +inline void v_pack_store(short* ptr, const v_int32x16& a) +{ v_store_low(ptr, v_pack(a, a)); } + +inline void v_pack_store(ushort* ptr, const v_uint32x16& a) +{ + const __m512i m = _mm512_set1_epi32(65535); + _mm256_storeu_si256((__m256i*)ptr, _mm512_cvtepi32_epi16(_mm512_min_epu32(a.val, m))); +} + +inline void v_pack_u_store(ushort* ptr, const v_int32x16& a) +{ v_store_low(ptr, v_pack_u(a, a)); } + + +template inline +v_uint16x32 v_rshr_pack(const v_uint32x16& a, const v_uint32x16& b) +{ + v_uint32x16 delta = v512_setall_u32(1 << (n-1)); + return v_pack_u(v_reinterpret_as_s32((a + delta) >> n), + v_reinterpret_as_s32((b + delta) >> n)); +} + +template inline +void v_rshr_pack_store(ushort* ptr, const v_uint32x16& a) +{ + v_uint32x16 delta = v512_setall_u32(1 << (n-1)); + v_pack_u_store(ptr, v_reinterpret_as_s32((a + delta) >> n)); +} + +template inline +v_uint16x32 v_rshr_pack_u(const v_int32x16& a, const v_int32x16& b) +{ + v_int32x16 delta = v512_setall_s32(1 << (n-1)); + return v_pack_u((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_u_store(ushort* ptr, const v_int32x16& a) +{ + v_int32x16 delta = v512_setall_s32(1 << (n-1)); + v_pack_u_store(ptr, (a + delta) >> n); +} + +template inline +v_int16x32 v_rshr_pack(const v_int32x16& a, const v_int32x16& b) +{ + v_int32x16 delta = v512_setall_s32(1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(short* ptr, const v_int32x16& a) +{ + v_int32x16 delta = v512_setall_s32(1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +// 64 +// Non-saturating pack +inline v_uint32x16 v_pack(const v_uint64x8& a, const v_uint64x8& b) +{ return v_uint32x16(_v512_combine(_mm512_cvtepi64_epi32(a.val), _mm512_cvtepi64_epi32(b.val))); } + +inline v_int32x16 v_pack(const v_int64x8& a, const v_int64x8& b) +{ return v_reinterpret_as_s32(v_pack(v_reinterpret_as_u64(a), v_reinterpret_as_u64(b))); } + +inline void v_pack_store(unsigned* ptr, const v_uint64x8& a) +{ _mm256_storeu_si256((__m256i*)ptr, _mm512_cvtepi64_epi32(a.val)); } + +inline void v_pack_store(int* ptr, const v_int64x8& b) +{ v_pack_store((unsigned*)ptr, v_reinterpret_as_u64(b)); } + +template inline +v_uint32x16 v_rshr_pack(const v_uint64x8& a, const v_uint64x8& b) +{ + v_uint64x8 delta = v512_setall_u64((uint64)1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(unsigned* ptr, const v_uint64x8& a) +{ + v_uint64x8 delta = v512_setall_u64((uint64)1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +template inline +v_int32x16 v_rshr_pack(const v_int64x8& a, const v_int64x8& b) +{ + v_int64x8 delta = v512_setall_s64((int64)1 << (n-1)); + return v_pack((a + delta) >> n, (b + delta) >> n); +} + +template inline +void v_rshr_pack_store(int* ptr, const v_int64x8& a) +{ + v_int64x8 delta = v512_setall_s64((int64)1 << (n-1)); + v_pack_store(ptr, (a + delta) >> n); +} + +// pack boolean +inline v_uint8x64 v_pack_b(const v_uint16x32& a, const v_uint16x32& b) +{ return v_uint8x64(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packs_epi16(a.val, b.val))); } + +inline v_uint8x64 v_pack_b(const v_uint32x16& a, const v_uint32x16& b, + const v_uint32x16& c, const v_uint32x16& d) +{ + __m512i ab = _mm512_packs_epi32(a.val, b.val); + __m512i cd = _mm512_packs_epi32(c.val, d.val); + + return v_uint8x64(_mm512_permutexvar_epi32(_v512_set_epu32(15, 11, 7, 3, 14, 10, 6, 2, 13, 9, 5, 1, 12, 8, 4, 0), _mm512_packs_epi16(ab, cd))); +} + +inline v_uint8x64 v_pack_b(const v_uint64x8& a, const v_uint64x8& b, const v_uint64x8& c, + const v_uint64x8& d, const v_uint64x8& e, const v_uint64x8& f, + const v_uint64x8& g, const v_uint64x8& h) +{ + __m512i ab = _mm512_packs_epi32(a.val, b.val); + __m512i cd = _mm512_packs_epi32(c.val, d.val); + __m512i ef = _mm512_packs_epi32(e.val, f.val); + __m512i gh = _mm512_packs_epi32(g.val, h.val); + + __m512i abcd = _mm512_packs_epi32(ab, cd); + __m512i efgh = _mm512_packs_epi32(ef, gh); + + return v_uint8x64(_mm512_permutexvar_epi16(_v512_set_epu16(31, 23, 15, 7, 30, 22, 14, 6, 29, 21, 13, 5, 28, 20, 12, 4, + 27, 19, 11, 3, 26, 18, 10, 2, 25, 17, 9, 1, 24, 16, 8, 0), _mm512_packs_epi16(abcd, efgh))); +} + +/* Recombine */ +// its up there with load and store operations + +/* Extract */ +#define OPENCV_HAL_IMPL_AVX512_EXTRACT(_Tpvec) \ + template \ + inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \ + { return v_rotate_right(a, b); } + +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint8x64) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int8x64) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint16x32) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int16x32) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint32x16) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int32x16) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint64x8) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int64x8) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_float32x16) +OPENCV_HAL_IMPL_AVX512_EXTRACT(v_float64x8) + +#define OPENCV_HAL_IMPL_AVX512_EXTRACT_N(_Tpvec, _Tp) \ +template inline _Tp v_extract_n(_Tpvec v) { return v_rotate_right(v).get0(); } + +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint8x64, uchar) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int8x64, schar) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint16x32, ushort) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int16x32, short) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint32x16, uint) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int32x16, int) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint64x8, uint64) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int64x8, int64) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_float32x16, float) +OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_float64x8, double) + +template +inline v_uint32x16 v_broadcast_element(v_uint32x16 a) +{ + static const __m512i perm = _mm512_set1_epi32((char)i); + return v_uint32x16(_mm512_permutexvar_epi32(perm, a.val)); +} + +template +inline v_int32x16 v_broadcast_element(const v_int32x16 &a) +{ return v_reinterpret_as_s32(v_broadcast_element(v_reinterpret_as_u32(a))); } + +template +inline v_float32x16 v_broadcast_element(const v_float32x16 &a) +{ return v_reinterpret_as_f32(v_broadcast_element(v_reinterpret_as_u32(a))); } + + +///////////////////// load deinterleave ///////////////////////////// + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x64& a, v_uint8x64& b ) +{ + __m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 64)); +#if CV_AVX_512VBMI + __m512i mask0 = _v512_set_epu8(126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, + 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, + 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, + 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu8(127, 125, 123, 121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99, 97, + 95, 93, 91, 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65, + 63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33, + 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1); + a = v_uint8x64(_mm512_permutex2var_epi8(ab0, mask0, ab1)); + b = v_uint8x64(_mm512_permutex2var_epi8(ab0, mask1, ab1)); +#else + __m512i mask0 = _mm512_set4_epi32(0x0f0d0b09, 0x07050301, 0x0e0c0a08, 0x06040200); + __m512i a0b0 = _mm512_shuffle_epi8(ab0, mask0); + __m512i a1b1 = _mm512_shuffle_epi8(ab1, mask0); + __m512i mask1 = _v512_set_epu64(14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask2 = _v512_set_epu64(15, 13, 11, 9, 7, 5, 3, 1); + a = v_uint8x64(_mm512_permutex2var_epi64(a0b0, mask1, a1b1)); + b = v_uint8x64(_mm512_permutex2var_epi64(a0b0, mask2, a1b1)); +#endif +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x32& a, v_uint16x32& b ) +{ + __m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 32)); + __m512i mask0 = _v512_set_epu16(62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, + 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu16(63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33, + 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1); + a = v_uint16x32(_mm512_permutex2var_epi16(ab0, mask0, ab1)); + b = v_uint16x32(_mm512_permutex2var_epi16(ab0, mask1, ab1)); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x16& a, v_uint32x16& b ) +{ + __m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 16)); + __m512i mask0 = _v512_set_epu32(30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu32(31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1); + a = v_uint32x16(_mm512_permutex2var_epi32(ab0, mask0, ab1)); + b = v_uint32x16(_mm512_permutex2var_epi32(ab0, mask1, ab1)); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x8& a, v_uint64x8& b ) +{ + __m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 8)); + __m512i mask0 = _v512_set_epu64(14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu64(15, 13, 11, 9, 7, 5, 3, 1); + a = v_uint64x8(_mm512_permutex2var_epi64(ab0, mask0, ab1)); + b = v_uint64x8(_mm512_permutex2var_epi64(ab0, mask1, ab1)); +} + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x64& a, v_uint8x64& b, v_uint8x64& c ) +{ + __m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 64)); + __m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 128)); + +#if CV_AVX_512VBMI2 + __m512i mask0 = _v512_set_epu8(126, 123, 120, 117, 114, 111, 108, 105, 102, 99, 96, 93, 90, 87, 84, 81, + 78, 75, 72, 69, 66, 63, 60, 57, 54, 51, 48, 45, 42, 39, 36, 33, + 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0, 62, 59, 56, 53, 50, + 47, 44, 41, 38, 35, 32, 29, 26, 23, 20, 17, 14, 11, 8, 5, 2); + __m512i r0b01 = _mm512_permutex2var_epi8(bgr0, mask0, bgr1); + __m512i b1g12 = _mm512_permutex2var_epi8(bgr1, mask0, bgr2); + __m512i r12b2 = _mm512_permutex2var_epi8(bgr1, + _v512_set_epu8(125, 122, 119, 116, 113, 110, 107, 104, 101, 98, 95, 92, 89, 86, 83, 80, + 77, 74, 71, 68, 65, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97, + 94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49, + 46, 43, 40, 37, 34, 31, 28, 25, 22, 19, 16, 13, 10, 7, 4, 1), bgr2); + a = v_uint8x64(_mm512_mask_compress_epi8(r12b2, 0xffffffffffe00000, r0b01)); + b = v_uint8x64(_mm512_mask_compress_epi8(b1g12, 0x2492492492492492, bgr0)); + c = v_uint8x64(_mm512_mask_expand_epi8(r0b01, 0xffffffffffe00000, r12b2)); +#elif CV_AVX_512VBMI + __m512i b0g0b1 = _mm512_mask_blend_epi8(0xb6db6db6db6db6db, bgr1, bgr0); + __m512i g1r1g2 = _mm512_mask_blend_epi8(0xb6db6db6db6db6db, bgr2, bgr1); + __m512i r2b2r0 = _mm512_mask_blend_epi8(0xb6db6db6db6db6db, bgr0, bgr2); + a = v_uint8x64(_mm512_permutex2var_epi8(b0g0b1, _v512_set_epu8(125, 122, 119, 116, 113, 110, 107, 104, 101, 98, 95, 92, 89, 86, 83, 80, + 77, 74, 71, 68, 65, 63, 61, 60, 58, 57, 55, 54, 52, 51, 49, 48, + 46, 45, 43, 42, 40, 39, 37, 36, 34, 33, 31, 30, 28, 27, 25, 24, + 23, 21, 20, 18, 17, 15, 14, 12, 11, 9, 8, 6, 5, 3, 2, 0), bgr2)); + b = v_uint8x64(_mm512_permutex2var_epi8(g1r1g2, _v512_set_epu8( 63, 61, 60, 58, 57, 55, 54, 52, 51, 49, 48, 46, 45, 43, 42, 40, + 39, 37, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 18, 17, + 15, 14, 12, 11, 9, 8, 6, 5, 3, 2, 0, 126, 123, 120, 117, 114, + 111, 108, 105, 102, 99, 96, 93, 90, 87, 84, 81, 78, 75, 72, 69, 66), bgr0)); + c = v_uint8x64(_mm512_permutex2var_epi8(r2b2r0, _v512_set_epu8( 63, 60, 57, 54, 51, 48, 45, 42, 39, 36, 33, 30, 27, 24, 21, 18, + 15, 12, 9, 6, 3, 0, 125, 122, 119, 116, 113, 110, 107, 104, 101, 98, + 95, 92, 89, 86, 83, 80, 77, 74, 71, 68, 65, 62, 59, 56, 53, 50, + 47, 44, 41, 38, 35, 32, 29, 26, 23, 20, 17, 14, 11, 8, 5, 2), bgr1)); +#else + __m512i mask0 = _v512_set_epu16(61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 63, 60, 57, 54, 51, 48, + 45, 42, 39, 36, 33, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0); + __m512i b01g1 = _mm512_permutex2var_epi16(bgr0, mask0, bgr1); + __m512i r12b2 = _mm512_permutex2var_epi16(bgr1, mask0, bgr2); + __m512i g20r0 = _mm512_permutex2var_epi16(bgr2, mask0, bgr0); + + __m512i b0g0 = _mm512_mask_blend_epi32(0xf800, b01g1, r12b2); + __m512i r0b1 = _mm512_permutex2var_epi16(bgr1, _v512_set_epu16(42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 29, 26, 23, 20, 17, + 14, 11, 8, 5, 2, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43), g20r0); + __m512i g1r1 = _mm512_alignr_epi32(r12b2, g20r0, 11); + a = v_uint8x64(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, b0g0, r0b1)); + c = v_uint8x64(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, r0b1, g1r1)); + b = v_uint8x64(_mm512_shuffle_epi8(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, g1r1, b0g0), _mm512_set4_epi32(0x0e0f0c0d, 0x0a0b0809, 0x06070405, 0x02030001))); +#endif +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x32& a, v_uint16x32& b, v_uint16x32& c ) +{ + __m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 32)); + __m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 64)); + + __m512i mask0 = _v512_set_epu16(61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 63, 60, 57, 54, 51, 48, + 45, 42, 39, 36, 33, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0); + __m512i b01g1 = _mm512_permutex2var_epi16(bgr0, mask0, bgr1); + __m512i r12b2 = _mm512_permutex2var_epi16(bgr1, mask0, bgr2); + __m512i g20r0 = _mm512_permutex2var_epi16(bgr2, mask0, bgr0); + + a = v_uint16x32(_mm512_mask_blend_epi32(0xf800, b01g1, r12b2)); + b = v_uint16x32(_mm512_permutex2var_epi16(bgr1, _v512_set_epu16(42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 29, 26, 23, 20, 17, + 14, 11, 8, 5, 2, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43), g20r0)); + c = v_uint16x32(_mm512_alignr_epi32(r12b2, g20r0, 11)); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x16& a, v_uint32x16& b, v_uint32x16& c ) +{ + __m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 16)); + __m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 32)); + + __m512i mask0 = _v512_set_epu32(29, 26, 23, 20, 17, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0); + __m512i b01r1 = _mm512_permutex2var_epi32(bgr0, mask0, bgr1); + __m512i g12b2 = _mm512_permutex2var_epi32(bgr1, mask0, bgr2); + __m512i r20g0 = _mm512_permutex2var_epi32(bgr2, mask0, bgr0); + + a = v_uint32x16(_mm512_mask_blend_epi32(0xf800, b01r1, g12b2)); + b = v_uint32x16(_mm512_alignr_epi32(g12b2, r20g0, 11)); + c = v_uint32x16(_mm512_permutex2var_epi32(bgr1, _v512_set_epu32(21, 20, 19, 18, 17, 16, 13, 10, 7, 4, 1, 26, 25, 24, 23, 22), r20g0)); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x8& a, v_uint64x8& b, v_uint64x8& c ) +{ + __m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 8)); + __m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 16)); + + __m512i mask0 = _v512_set_epu64(13, 10, 15, 12, 9, 6, 3, 0); + __m512i b01g1 = _mm512_permutex2var_epi64(bgr0, mask0, bgr1); + __m512i r12b2 = _mm512_permutex2var_epi64(bgr1, mask0, bgr2); + __m512i g20r0 = _mm512_permutex2var_epi64(bgr2, mask0, bgr0); + + a = v_uint64x8(_mm512_mask_blend_epi64(0xc0, b01g1, r12b2)); + c = v_uint64x8(_mm512_alignr_epi64(r12b2, g20r0, 6)); + b = v_uint64x8(_mm512_permutex2var_epi64(bgr1, _v512_set_epu64(10, 9, 8, 5, 2, 13, 12, 11), g20r0)); +} + +inline void v_load_deinterleave( const uchar* ptr, v_uint8x64& a, v_uint8x64& b, v_uint8x64& c, v_uint8x64& d ) +{ + __m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 64)); + __m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 128)); + __m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 192)); + +#if CV_AVX_512VBMI + __m512i mask0 = _v512_set_epu8(126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96, + 94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64, + 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, + 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu8(127, 125, 123, 121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99, 97, + 95, 93, 91, 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65, + 63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33, + 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1); + + __m512i br01 = _mm512_permutex2var_epi8(bgra0, mask0, bgra1); + __m512i ga01 = _mm512_permutex2var_epi8(bgra0, mask1, bgra1); + __m512i br23 = _mm512_permutex2var_epi8(bgra2, mask0, bgra3); + __m512i ga23 = _mm512_permutex2var_epi8(bgra2, mask1, bgra3); + + a = v_uint8x64(_mm512_permutex2var_epi8(br01, mask0, br23)); + c = v_uint8x64(_mm512_permutex2var_epi8(br01, mask1, br23)); + b = v_uint8x64(_mm512_permutex2var_epi8(ga01, mask0, ga23)); + d = v_uint8x64(_mm512_permutex2var_epi8(ga01, mask1, ga23)); +#else + __m512i mask = _mm512_set4_epi32(0x0f0b0703, 0x0e0a0602, 0x0d090501, 0x0c080400); + __m512i b0g0r0a0 = _mm512_shuffle_epi8(bgra0, mask); + __m512i b1g1r1a1 = _mm512_shuffle_epi8(bgra1, mask); + __m512i b2g2r2a2 = _mm512_shuffle_epi8(bgra2, mask); + __m512i b3g3r3a3 = _mm512_shuffle_epi8(bgra3, mask); + + __m512i mask0 = _v512_set_epu32(30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu32(31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1); + + __m512i br01 = _mm512_permutex2var_epi32(b0g0r0a0, mask0, b1g1r1a1); + __m512i ga01 = _mm512_permutex2var_epi32(b0g0r0a0, mask1, b1g1r1a1); + __m512i br23 = _mm512_permutex2var_epi32(b2g2r2a2, mask0, b3g3r3a3); + __m512i ga23 = _mm512_permutex2var_epi32(b2g2r2a2, mask1, b3g3r3a3); + + a = v_uint8x64(_mm512_permutex2var_epi32(br01, mask0, br23)); + c = v_uint8x64(_mm512_permutex2var_epi32(br01, mask1, br23)); + b = v_uint8x64(_mm512_permutex2var_epi32(ga01, mask0, ga23)); + d = v_uint8x64(_mm512_permutex2var_epi32(ga01, mask1, ga23)); +#endif +} + +inline void v_load_deinterleave( const ushort* ptr, v_uint16x32& a, v_uint16x32& b, v_uint16x32& c, v_uint16x32& d ) +{ + __m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 32)); + __m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 64)); + __m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 96)); + + __m512i mask0 = _v512_set_epu16(62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, + 30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu16(63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33, + 31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1); + + __m512i br01 = _mm512_permutex2var_epi16(bgra0, mask0, bgra1); + __m512i ga01 = _mm512_permutex2var_epi16(bgra0, mask1, bgra1); + __m512i br23 = _mm512_permutex2var_epi16(bgra2, mask0, bgra3); + __m512i ga23 = _mm512_permutex2var_epi16(bgra2, mask1, bgra3); + + a = v_uint16x32(_mm512_permutex2var_epi16(br01, mask0, br23)); + c = v_uint16x32(_mm512_permutex2var_epi16(br01, mask1, br23)); + b = v_uint16x32(_mm512_permutex2var_epi16(ga01, mask0, ga23)); + d = v_uint16x32(_mm512_permutex2var_epi16(ga01, mask1, ga23)); +} + +inline void v_load_deinterleave( const unsigned* ptr, v_uint32x16& a, v_uint32x16& b, v_uint32x16& c, v_uint32x16& d ) +{ + __m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 16)); + __m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 32)); + __m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 48)); + + __m512i mask0 = _v512_set_epu32(30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu32(31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1); + + __m512i br01 = _mm512_permutex2var_epi32(bgra0, mask0, bgra1); + __m512i ga01 = _mm512_permutex2var_epi32(bgra0, mask1, bgra1); + __m512i br23 = _mm512_permutex2var_epi32(bgra2, mask0, bgra3); + __m512i ga23 = _mm512_permutex2var_epi32(bgra2, mask1, bgra3); + + a = v_uint32x16(_mm512_permutex2var_epi32(br01, mask0, br23)); + c = v_uint32x16(_mm512_permutex2var_epi32(br01, mask1, br23)); + b = v_uint32x16(_mm512_permutex2var_epi32(ga01, mask0, ga23)); + d = v_uint32x16(_mm512_permutex2var_epi32(ga01, mask1, ga23)); +} + +inline void v_load_deinterleave( const uint64* ptr, v_uint64x8& a, v_uint64x8& b, v_uint64x8& c, v_uint64x8& d ) +{ + __m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr); + __m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 8)); + __m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 16)); + __m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 24)); + + __m512i mask0 = _v512_set_epu64(14, 12, 10, 8, 6, 4, 2, 0); + __m512i mask1 = _v512_set_epu64(15, 13, 11, 9, 7, 5, 3, 1); + + __m512i br01 = _mm512_permutex2var_epi64(bgra0, mask0, bgra1); + __m512i ga01 = _mm512_permutex2var_epi64(bgra0, mask1, bgra1); + __m512i br23 = _mm512_permutex2var_epi64(bgra2, mask0, bgra3); + __m512i ga23 = _mm512_permutex2var_epi64(bgra2, mask1, bgra3); + + a = v_uint64x8(_mm512_permutex2var_epi64(br01, mask0, br23)); + c = v_uint64x8(_mm512_permutex2var_epi64(br01, mask1, br23)); + b = v_uint64x8(_mm512_permutex2var_epi64(ga01, mask0, ga23)); + d = v_uint64x8(_mm512_permutex2var_epi64(ga01, mask1, ga23)); +} + +///////////////////////////// store interleave ///////////////////////////////////// + +inline void v_store_interleave( uchar* ptr, const v_uint8x64& x, const v_uint8x64& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint8x64 low, high; + v_zip(x, y, low, high); + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, low.val); + _mm512_stream_si512((__m512i*)(ptr + 64), high.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, low.val); + _mm512_store_si512((__m512i*)(ptr + 64), high.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, low.val); + _mm512_storeu_si512((__m512i*)(ptr + 64), high.val); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x32& x, const v_uint16x32& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint16x32 low, high; + v_zip(x, y, low, high); + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, low.val); + _mm512_stream_si512((__m512i*)(ptr + 32), high.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, low.val); + _mm512_store_si512((__m512i*)(ptr + 32), high.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, low.val); + _mm512_storeu_si512((__m512i*)(ptr + 32), high.val); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x16& x, const v_uint32x16& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint32x16 low, high; + v_zip(x, y, low, high); + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, low.val); + _mm512_stream_si512((__m512i*)(ptr + 16), high.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, low.val); + _mm512_store_si512((__m512i*)(ptr + 16), high.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, low.val); + _mm512_storeu_si512((__m512i*)(ptr + 16), high.val); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x8& x, const v_uint64x8& y, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint64x8 low, high; + v_zip(x, y, low, high); + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, low.val); + _mm512_stream_si512((__m512i*)(ptr + 8), high.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, low.val); + _mm512_store_si512((__m512i*)(ptr + 8), high.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, low.val); + _mm512_storeu_si512((__m512i*)(ptr + 8), high.val); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x64& a, const v_uint8x64& b, const v_uint8x64& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ +#if CV_AVX_512VBMI + __m512i mask0 = _v512_set_epu8(127, 84, 20, 126, 83, 19, 125, 82, 18, 124, 81, 17, 123, 80, 16, 122, + 79, 15, 121, 78, 14, 120, 77, 13, 119, 76, 12, 118, 75, 11, 117, 74, + 10, 116, 73, 9, 115, 72, 8, 114, 71, 7, 113, 70, 6, 112, 69, 5, + 111, 68, 4, 110, 67, 3, 109, 66, 2, 108, 65, 1, 107, 64, 0, 106); + __m512i mask1 = _v512_set_epu8( 21, 42, 105, 20, 41, 104, 19, 40, 103, 18, 39, 102, 17, 38, 101, 16, + 37, 100, 15, 36, 99, 14, 35, 98, 13, 34, 97, 12, 33, 96, 11, 32, + 95, 10, 31, 94, 9, 30, 93, 8, 29, 92, 7, 28, 91, 6, 27, 90, + 5, 26, 89, 4, 25, 88, 3, 24, 87, 2, 23, 86, 1, 22, 85, 0); + __m512i mask2 = _v512_set_epu8(106, 127, 63, 105, 126, 62, 104, 125, 61, 103, 124, 60, 102, 123, 59, 101, + 122, 58, 100, 121, 57, 99, 120, 56, 98, 119, 55, 97, 118, 54, 96, 117, + 53, 95, 116, 52, 94, 115, 51, 93, 114, 50, 92, 113, 49, 91, 112, 48, + 90, 111, 47, 89, 110, 46, 88, 109, 45, 87, 108, 44, 86, 107, 43, 85); + __m512i r2g0r0 = _mm512_permutex2var_epi8(b.val, mask0, c.val); + __m512i b0r1b1 = _mm512_permutex2var_epi8(a.val, mask1, c.val); + __m512i g1b2g2 = _mm512_permutex2var_epi8(a.val, mask2, b.val); + + __m512i bgr0 = _mm512_mask_blend_epi8(0x9249249249249249, r2g0r0, b0r1b1); + __m512i bgr1 = _mm512_mask_blend_epi8(0x9249249249249249, b0r1b1, g1b2g2); + __m512i bgr2 = _mm512_mask_blend_epi8(0x9249249249249249, g1b2g2, r2g0r0); +#else + __m512i g1g0 = _mm512_shuffle_epi8(b.val, _mm512_set4_epi32(0x0e0f0c0d, 0x0a0b0809, 0x06070405, 0x02030001)); + __m512i b0g0 = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, a.val, g1g0); + __m512i r0b1 = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, c.val, a.val); + __m512i g1r1 = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, g1g0, c.val); + + __m512i mask0 = _v512_set_epu16(42, 10, 31, 41, 9, 30, 40, 8, 29, 39, 7, 28, 38, 6, 27, 37, + 5, 26, 36, 4, 25, 35, 3, 24, 34, 2, 23, 33, 1, 22, 32, 0); + __m512i mask1 = _v512_set_epu16(21, 52, 41, 20, 51, 40, 19, 50, 39, 18, 49, 38, 17, 48, 37, 16, + 47, 36, 15, 46, 35, 14, 45, 34, 13, 44, 33, 12, 43, 32, 11, 42); + __m512i mask2 = _v512_set_epu16(63, 31, 20, 62, 30, 19, 61, 29, 18, 60, 28, 17, 59, 27, 16, 58, + 26, 15, 57, 25, 14, 56, 24, 13, 55, 23, 12, 54, 22, 11, 53, 21); + __m512i b0g0b2 = _mm512_permutex2var_epi16(b0g0, mask0, r0b1); + __m512i r1b1r0 = _mm512_permutex2var_epi16(b0g0, mask1, g1r1); + __m512i g2r2g1 = _mm512_permutex2var_epi16(r0b1, mask2, g1r1); + + __m512i bgr0 = _mm512_mask_blend_epi16(0x24924924, b0g0b2, r1b1r0); + __m512i bgr1 = _mm512_mask_blend_epi16(0x24924924, r1b1r0, g2r2g1); + __m512i bgr2 = _mm512_mask_blend_epi16(0x24924924, g2r2g1, b0g0b2); +#endif + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgr0); + _mm512_stream_si512((__m512i*)(ptr + 64), bgr1); + _mm512_stream_si512((__m512i*)(ptr + 128), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgr0); + _mm512_store_si512((__m512i*)(ptr + 64), bgr1); + _mm512_store_si512((__m512i*)(ptr + 128), bgr2); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgr0); + _mm512_storeu_si512((__m512i*)(ptr + 64), bgr1); + _mm512_storeu_si512((__m512i*)(ptr + 128), bgr2); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x32& a, const v_uint16x32& b, const v_uint16x32& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m512i mask0 = _v512_set_epu16(42, 10, 31, 41, 9, 30, 40, 8, 29, 39, 7, 28, 38, 6, 27, 37, + 5, 26, 36, 4, 25, 35, 3, 24, 34, 2, 23, 33, 1, 22, 32, 0); + __m512i mask1 = _v512_set_epu16(21, 52, 41, 20, 51, 40, 19, 50, 39, 18, 49, 38, 17, 48, 37, 16, + 47, 36, 15, 46, 35, 14, 45, 34, 13, 44, 33, 12, 43, 32, 11, 42); + __m512i mask2 = _v512_set_epu16(63, 31, 20, 62, 30, 19, 61, 29, 18, 60, 28, 17, 59, 27, 16, 58, + 26, 15, 57, 25, 14, 56, 24, 13, 55, 23, 12, 54, 22, 11, 53, 21); + __m512i b0g0b2 = _mm512_permutex2var_epi16(a.val, mask0, b.val); + __m512i r1b1r0 = _mm512_permutex2var_epi16(a.val, mask1, c.val); + __m512i g2r2g1 = _mm512_permutex2var_epi16(b.val, mask2, c.val); + + __m512i bgr0 = _mm512_mask_blend_epi16(0x24924924, b0g0b2, r1b1r0); + __m512i bgr1 = _mm512_mask_blend_epi16(0x24924924, r1b1r0, g2r2g1); + __m512i bgr2 = _mm512_mask_blend_epi16(0x24924924, g2r2g1, b0g0b2); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgr0); + _mm512_stream_si512((__m512i*)(ptr + 32), bgr1); + _mm512_stream_si512((__m512i*)(ptr + 64), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgr0); + _mm512_store_si512((__m512i*)(ptr + 32), bgr1); + _mm512_store_si512((__m512i*)(ptr + 64), bgr2); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgr0); + _mm512_storeu_si512((__m512i*)(ptr + 32), bgr1); + _mm512_storeu_si512((__m512i*)(ptr + 64), bgr2); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x16& a, const v_uint32x16& b, const v_uint32x16& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m512i mask0 = _v512_set_epu32(26, 31, 15, 25, 30, 14, 24, 29, 13, 23, 28, 12, 22, 27, 11, 21); + __m512i mask1 = _v512_set_epu32(31, 10, 25, 30, 9, 24, 29, 8, 23, 28, 7, 22, 27, 6, 21, 26); + __m512i g1b2g2 = _mm512_permutex2var_epi32(a.val, mask0, b.val); + __m512i r2r1b1 = _mm512_permutex2var_epi32(a.val, mask1, c.val); + + __m512i bgr0 = _mm512_mask_expand_epi32(_mm512_mask_expand_epi32(_mm512_maskz_expand_epi32(0x9249, a.val), 0x2492, b.val), 0x4924, c.val); + __m512i bgr1 = _mm512_mask_blend_epi32(0x9249, r2r1b1, g1b2g2); + __m512i bgr2 = _mm512_mask_blend_epi32(0x9249, g1b2g2, r2r1b1); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgr0); + _mm512_stream_si512((__m512i*)(ptr + 16), bgr1); + _mm512_stream_si512((__m512i*)(ptr + 32), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgr0); + _mm512_store_si512((__m512i*)(ptr + 16), bgr1); + _mm512_store_si512((__m512i*)(ptr + 32), bgr2); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgr0); + _mm512_storeu_si512((__m512i*)(ptr + 16), bgr1); + _mm512_storeu_si512((__m512i*)(ptr + 32), bgr2); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x8& a, const v_uint64x8& b, const v_uint64x8& c, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + __m512i mask0 = _v512_set_epu64( 5, 12, 7, 4, 11, 6, 3, 10); + __m512i mask1 = _v512_set_epu64(15, 7, 4, 14, 6, 3, 13, 5); + __m512i r1b1b2 = _mm512_permutex2var_epi64(a.val, mask0, c.val); + __m512i g2r2g1 = _mm512_permutex2var_epi64(b.val, mask1, c.val); + + __m512i bgr0 = _mm512_mask_expand_epi64(_mm512_mask_expand_epi64(_mm512_maskz_expand_epi64(0x49, a.val), 0x92, b.val), 0x24, c.val); + __m512i bgr1 = _mm512_mask_blend_epi64(0xdb, g2r2g1, r1b1b2); + __m512i bgr2 = _mm512_mask_blend_epi64(0xdb, r1b1b2, g2r2g1); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgr0); + _mm512_stream_si512((__m512i*)(ptr + 8), bgr1); + _mm512_stream_si512((__m512i*)(ptr + 16), bgr2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgr0); + _mm512_store_si512((__m512i*)(ptr + 8), bgr1); + _mm512_store_si512((__m512i*)(ptr + 16), bgr2); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgr0); + _mm512_storeu_si512((__m512i*)(ptr + 8), bgr1); + _mm512_storeu_si512((__m512i*)(ptr + 16), bgr2); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x64& a, const v_uint8x64& b, + const v_uint8x64& c, const v_uint8x64& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint8x64 br01, br23, ga01, ga23; + v_zip(a, c, br01, br23); + v_zip(b, d, ga01, ga23); + v_uint8x64 bgra0, bgra1, bgra2, bgra3; + v_zip(br01, ga01, bgra0, bgra1); + v_zip(br23, ga23, bgra2, bgra3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgra0.val); + _mm512_stream_si512((__m512i*)(ptr + 64), bgra1.val); + _mm512_stream_si512((__m512i*)(ptr + 128), bgra2.val); + _mm512_stream_si512((__m512i*)(ptr + 192), bgra3.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgra0.val); + _mm512_store_si512((__m512i*)(ptr + 64), bgra1.val); + _mm512_store_si512((__m512i*)(ptr + 128), bgra2.val); + _mm512_store_si512((__m512i*)(ptr + 192), bgra3.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgra0.val); + _mm512_storeu_si512((__m512i*)(ptr + 64), bgra1.val); + _mm512_storeu_si512((__m512i*)(ptr + 128), bgra2.val); + _mm512_storeu_si512((__m512i*)(ptr + 192), bgra3.val); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x32& a, const v_uint16x32& b, + const v_uint16x32& c, const v_uint16x32& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint16x32 br01, br23, ga01, ga23; + v_zip(a, c, br01, br23); + v_zip(b, d, ga01, ga23); + v_uint16x32 bgra0, bgra1, bgra2, bgra3; + v_zip(br01, ga01, bgra0, bgra1); + v_zip(br23, ga23, bgra2, bgra3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgra0.val); + _mm512_stream_si512((__m512i*)(ptr + 32), bgra1.val); + _mm512_stream_si512((__m512i*)(ptr + 64), bgra2.val); + _mm512_stream_si512((__m512i*)(ptr + 96), bgra3.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgra0.val); + _mm512_store_si512((__m512i*)(ptr + 32), bgra1.val); + _mm512_store_si512((__m512i*)(ptr + 64), bgra2.val); + _mm512_store_si512((__m512i*)(ptr + 96), bgra3.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgra0.val); + _mm512_storeu_si512((__m512i*)(ptr + 32), bgra1.val); + _mm512_storeu_si512((__m512i*)(ptr + 64), bgra2.val); + _mm512_storeu_si512((__m512i*)(ptr + 96), bgra3.val); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x16& a, const v_uint32x16& b, + const v_uint32x16& c, const v_uint32x16& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint32x16 br01, br23, ga01, ga23; + v_zip(a, c, br01, br23); + v_zip(b, d, ga01, ga23); + v_uint32x16 bgra0, bgra1, bgra2, bgra3; + v_zip(br01, ga01, bgra0, bgra1); + v_zip(br23, ga23, bgra2, bgra3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgra0.val); + _mm512_stream_si512((__m512i*)(ptr + 16), bgra1.val); + _mm512_stream_si512((__m512i*)(ptr + 32), bgra2.val); + _mm512_stream_si512((__m512i*)(ptr + 48), bgra3.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgra0.val); + _mm512_store_si512((__m512i*)(ptr + 16), bgra1.val); + _mm512_store_si512((__m512i*)(ptr + 32), bgra2.val); + _mm512_store_si512((__m512i*)(ptr + 48), bgra3.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgra0.val); + _mm512_storeu_si512((__m512i*)(ptr + 16), bgra1.val); + _mm512_storeu_si512((__m512i*)(ptr + 32), bgra2.val); + _mm512_storeu_si512((__m512i*)(ptr + 48), bgra3.val); + } +} + +inline void v_store_interleave( uint64* ptr, const v_uint64x8& a, const v_uint64x8& b, + const v_uint64x8& c, const v_uint64x8& d, + hal::StoreMode mode=hal::STORE_UNALIGNED ) +{ + v_uint64x8 br01, br23, ga01, ga23; + v_zip(a, c, br01, br23); + v_zip(b, d, ga01, ga23); + v_uint64x8 bgra0, bgra1, bgra2, bgra3; + v_zip(br01, ga01, bgra0, bgra1); + v_zip(br23, ga23, bgra2, bgra3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm512_stream_si512((__m512i*)ptr, bgra0.val); + _mm512_stream_si512((__m512i*)(ptr + 8), bgra1.val); + _mm512_stream_si512((__m512i*)(ptr + 16), bgra2.val); + _mm512_stream_si512((__m512i*)(ptr + 24), bgra3.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm512_store_si512((__m512i*)ptr, bgra0.val); + _mm512_store_si512((__m512i*)(ptr + 8), bgra1.val); + _mm512_store_si512((__m512i*)(ptr + 16), bgra2.val); + _mm512_store_si512((__m512i*)(ptr + 24), bgra3.val); + } + else + { + _mm512_storeu_si512((__m512i*)ptr, bgra0.val); + _mm512_storeu_si512((__m512i*)(ptr + 8), bgra1.val); + _mm512_storeu_si512((__m512i*)(ptr + 16), bgra2.val); + _mm512_storeu_si512((__m512i*)(ptr + 24), bgra3.val); + } +} + +#define OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \ +{ \ + _Tpvec1 a1, b1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \ +{ \ + _Tpvec1 a1, b1, c1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \ +{ \ + _Tpvec1 a1, b1, c1, d1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ + d0 = v_reinterpret_as_##suffix0(d1); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, const _Tpvec0& c0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, const _Tpvec0& d0, \ + hal::StoreMode mode=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + _Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \ +} + +OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int8x64, schar, s8, v_uint8x64, uchar, u8) +OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int16x32, short, s16, v_uint16x32, ushort, u16) +OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int32x16, int, s32, v_uint32x16, unsigned, u32) +OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_float32x16, float, f32, v_uint32x16, unsigned, u32) +OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int64x8, int64, s64, v_uint64x8, uint64, u64) +OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_float64x8, double, f64, v_uint64x8, uint64, u64) + +////////// Mask and checks ///////// + +/** Mask **/ +inline int64 v_signmask(const v_int8x64& a) { return (int64)_mm512_movepi8_mask(a.val); } +inline int v_signmask(const v_int16x32& a) { return (int)_mm512_cmp_epi16_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); } +inline int v_signmask(const v_int32x16& a) { return (int)_mm512_cmp_epi32_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); } +inline int v_signmask(const v_int64x8& a) { return (int)_mm512_cmp_epi64_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); } + +inline int64 v_signmask(const v_uint8x64& a) { return v_signmask(v_reinterpret_as_s8(a)); } +inline int v_signmask(const v_uint16x32& a) { return v_signmask(v_reinterpret_as_s16(a)); } +inline int v_signmask(const v_uint32x16& a) { return v_signmask(v_reinterpret_as_s32(a)); } +inline int v_signmask(const v_uint64x8& a) { return v_signmask(v_reinterpret_as_s64(a)); } +inline int v_signmask(const v_float32x16& a) { return v_signmask(v_reinterpret_as_s32(a)); } +inline int v_signmask(const v_float64x8& a) { return v_signmask(v_reinterpret_as_s64(a)); } + +/** Checks **/ +inline bool v_check_all(const v_int8x64& a) { return !(bool)_mm512_cmp_epi8_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); } +inline bool v_check_any(const v_int8x64& a) { return (bool)_mm512_movepi8_mask(a.val); } +inline bool v_check_all(const v_int16x32& a) { return !(bool)_mm512_cmp_epi16_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); } +inline bool v_check_any(const v_int16x32& a) { return (bool)_mm512_cmp_epi16_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); } +inline bool v_check_all(const v_int32x16& a) { return !(bool)_mm512_cmp_epi32_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); } +inline bool v_check_any(const v_int32x16& a) { return (bool)_mm512_cmp_epi32_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); } +inline bool v_check_all(const v_int64x8& a) { return !(bool)_mm512_cmp_epi64_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); } +inline bool v_check_any(const v_int64x8& a) { return (bool)_mm512_cmp_epi64_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); } + +inline bool v_check_all(const v_float32x16& a) { return v_check_all(v_reinterpret_as_s32(a)); } +inline bool v_check_any(const v_float32x16& a) { return v_check_any(v_reinterpret_as_s32(a)); } +inline bool v_check_all(const v_float64x8& a) { return v_check_all(v_reinterpret_as_s64(a)); } +inline bool v_check_any(const v_float64x8& a) { return v_check_any(v_reinterpret_as_s64(a)); } +inline bool v_check_all(const v_uint8x64& a) { return v_check_all(v_reinterpret_as_s8(a)); } +inline bool v_check_all(const v_uint16x32& a) { return v_check_all(v_reinterpret_as_s16(a)); } +inline bool v_check_all(const v_uint32x16& a) { return v_check_all(v_reinterpret_as_s32(a)); } +inline bool v_check_all(const v_uint64x8& a) { return v_check_all(v_reinterpret_as_s64(a)); } +inline bool v_check_any(const v_uint8x64& a) { return v_check_any(v_reinterpret_as_s8(a)); } +inline bool v_check_any(const v_uint16x32& a) { return v_check_any(v_reinterpret_as_s16(a)); } +inline bool v_check_any(const v_uint32x16& a) { return v_check_any(v_reinterpret_as_s32(a)); } +inline bool v_check_any(const v_uint64x8& a) { return v_check_any(v_reinterpret_as_s64(a)); } + +inline int v_scan_forward(const v_int8x64& a) +{ + int64 mask = _mm512_movepi8_mask(a.val); + int mask32 = (int)mask; + return mask != 0 ? mask32 != 0 ? trailingZeros32(mask32) : 32 + trailingZeros32((int)(mask >> 32)) : 0; +} +inline int v_scan_forward(const v_uint8x64& a) { return v_scan_forward(v_reinterpret_as_s8(a)); } +inline int v_scan_forward(const v_int16x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))); } +inline int v_scan_forward(const v_uint16x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))); } +inline int v_scan_forward(const v_int32x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 2; } +inline int v_scan_forward(const v_uint32x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 2; } +inline int v_scan_forward(const v_float32x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 2; } +inline int v_scan_forward(const v_int64x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 4; } +inline int v_scan_forward(const v_uint64x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 4; } +inline int v_scan_forward(const v_float64x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 4; } + +inline void v512_cleanup() { _mm256_zeroall(); } + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} // cv:: + +#endif // OPENCV_HAL_INTRIN_AVX_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_cpp.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_cpp.hpp new file mode 100644 index 0000000000000000000000000000000000000000..67d3155f0086be0a535bd8617b5925fed912e082 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_cpp.hpp @@ -0,0 +1,2557 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_INTRIN_CPP_HPP +#define OPENCV_HAL_INTRIN_CPP_HPP + +#include +#include +#include +#include "opencv2/core/saturate.hpp" + +namespace cv +{ + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN +#endif + +/** @addtogroup core_hal_intrin + +"Universal intrinsics" is a types and functions set intended to simplify vectorization of code on +different platforms. Currently there are two supported SIMD extensions: __SSE/SSE2__ on x86 +architectures and __NEON__ on ARM architectures, both allow working with 128 bit registers +containing packed values of different types. In case when there is no SIMD extension available +during compilation, fallback C++ implementation of intrinsics will be chosen and code will work as +expected although it could be slower. + +### Types + +There are several types representing 128-bit register as a vector of packed values, each type is +implemented as a structure based on a one SIMD register. + +- cv::v_uint8x16 and cv::v_int8x16: sixteen 8-bit integer values (unsigned/signed) - char +- cv::v_uint16x8 and cv::v_int16x8: eight 16-bit integer values (unsigned/signed) - short +- cv::v_uint32x4 and cv::v_int32x4: four 32-bit integer values (unsgined/signed) - int +- cv::v_uint64x2 and cv::v_int64x2: two 64-bit integer values (unsigned/signed) - int64 +- cv::v_float32x4: four 32-bit floating point values (signed) - float +- cv::v_float64x2: two 64-bit floating point values (signed) - double + +@note +cv::v_float64x2 is not implemented in NEON variant, if you want to use this type, don't forget to +check the CV_SIMD128_64F preprocessor definition: +@code +#if CV_SIMD128_64F +//... +#endif +@endcode + +### Load and store operations + +These operations allow to set contents of the register explicitly or by loading it from some memory +block and to save contents of the register to memory block. + +- Constructors: +@ref v_reg::v_reg(const _Tp *ptr) "from memory", +@ref v_reg::v_reg(_Tp s0, _Tp s1) "from two values", ... +- Other create methods: +@ref v_setall_s8, @ref v_setall_u8, ..., +@ref v_setzero_u8, @ref v_setzero_s8, ... +- Memory operations: +@ref v_load, @ref v_load_aligned, @ref v_load_low, @ref v_load_halves, +@ref v_store, @ref v_store_aligned, +@ref v_store_high, @ref v_store_low + +### Value reordering + +These operations allow to reorder or recombine elements in one or multiple vectors. + +- Interleave, deinterleave (2, 3 and 4 channels): @ref v_load_deinterleave, @ref v_store_interleave +- Expand: @ref v_load_expand, @ref v_load_expand_q, @ref v_expand, @ref v_expand_low, @ref v_expand_high +- Pack: @ref v_pack, @ref v_pack_u, @ref v_pack_b, @ref v_rshr_pack, @ref v_rshr_pack_u, +@ref v_pack_store, @ref v_pack_u_store, @ref v_rshr_pack_store, @ref v_rshr_pack_u_store +- Recombine: @ref v_zip, @ref v_recombine, @ref v_combine_low, @ref v_combine_high +- Reverse: @ref v_reverse +- Extract: @ref v_extract + + +### Arithmetic, bitwise and comparison operations + +Element-wise binary and unary operations. + +- Arithmetics: +@ref operator +(const v_reg &a, const v_reg &b) "+", +@ref operator -(const v_reg &a, const v_reg &b) "-", +@ref operator *(const v_reg &a, const v_reg &b) "*", +@ref operator /(const v_reg &a, const v_reg &b) "/", +@ref v_mul_expand + +- Non-saturating arithmetics: @ref v_add_wrap, @ref v_sub_wrap + +- Bitwise shifts: +@ref operator <<(const v_reg &a, int s) "<<", +@ref operator >>(const v_reg &a, int s) ">>", +@ref v_shl, @ref v_shr + +- Bitwise logic: +@ref operator&(const v_reg &a, const v_reg &b) "&", +@ref operator |(const v_reg &a, const v_reg &b) "|", +@ref operator ^(const v_reg &a, const v_reg &b) "^", +@ref operator ~(const v_reg &a) "~" + +- Comparison: +@ref operator >(const v_reg &a, const v_reg &b) ">", +@ref operator >=(const v_reg &a, const v_reg &b) ">=", +@ref operator <(const v_reg &a, const v_reg &b) "<", +@ref operator <=(const v_reg &a, const v_reg &b) "<=", +@ref operator==(const v_reg &a, const v_reg &b) "==", +@ref operator !=(const v_reg &a, const v_reg &b) "!=" + +- min/max: @ref v_min, @ref v_max + +### Reduce and mask + +Most of these operations return only one value. + +- Reduce: @ref v_reduce_min, @ref v_reduce_max, @ref v_reduce_sum, @ref v_popcount +- Mask: @ref v_signmask, @ref v_check_all, @ref v_check_any, @ref v_select + +### Other math + +- Some frequent operations: @ref v_sqrt, @ref v_invsqrt, @ref v_magnitude, @ref v_sqr_magnitude +- Absolute values: @ref v_abs, @ref v_absdiff, @ref v_absdiffs + +### Conversions + +Different type conversions and casts: + +- Rounding: @ref v_round, @ref v_floor, @ref v_ceil, @ref v_trunc, +- To float: @ref v_cvt_f32, @ref v_cvt_f64 +- Reinterpret: @ref v_reinterpret_as_u8, @ref v_reinterpret_as_s8, ... + +### Matrix operations + +In these operations vectors represent matrix rows/columns: @ref v_dotprod, @ref v_dotprod_fast, +@ref v_dotprod_expand, @ref v_dotprod_expand_fast, @ref v_matmul, @ref v_transpose4x4 + +### Usability + +Most operations are implemented only for some subset of the available types, following matrices +shows the applicability of different operations to the types. + +Regular integers: + +| Operations\\Types | uint 8x16 | int 8x16 | uint 16x8 | int 16x8 | uint 32x4 | int 32x4 | +|-------------------|:-:|:-:|:-:|:-:|:-:|:-:| +|load, store | x | x | x | x | x | x | +|interleave | x | x | x | x | x | x | +|expand | x | x | x | x | x | x | +|expand_low | x | x | x | x | x | x | +|expand_high | x | x | x | x | x | x | +|expand_q | x | x | | | | | +|add, sub | x | x | x | x | x | x | +|add_wrap, sub_wrap | x | x | x | x | | | +|mul_wrap | x | x | x | x | | | +|mul | x | x | x | x | x | x | +|mul_expand | x | x | x | x | x | | +|compare | x | x | x | x | x | x | +|shift | | | x | x | x | x | +|dotprod | | | | x | | x | +|dotprod_fast | | | | x | | x | +|dotprod_expand | x | x | x | x | | x | +|dotprod_expand_fast| x | x | x | x | | x | +|logical | x | x | x | x | x | x | +|min, max | x | x | x | x | x | x | +|absdiff | x | x | x | x | x | x | +|absdiffs | | x | | x | | | +|reduce | | | | | x | x | +|mask | x | x | x | x | x | x | +|pack | x | x | x | x | x | x | +|pack_u | x | | x | | | | +|pack_b | x | | | | | | +|unpack | x | x | x | x | x | x | +|extract | x | x | x | x | x | x | +|rotate (lanes) | x | x | x | x | x | x | +|cvt_flt32 | | | | | | x | +|cvt_flt64 | | | | | | x | +|transpose4x4 | | | | | x | x | +|reverse | x | x | x | x | x | x | +|extract_n | x | x | x | x | x | x | +|broadcast_element | | | | | x | x | + +Big integers: + +| Operations\\Types | uint 64x2 | int 64x2 | +|-------------------|:-:|:-:| +|load, store | x | x | +|add, sub | x | x | +|shift | x | x | +|logical | x | x | +|reverse | x | x | +|extract | x | x | +|rotate (lanes) | x | x | +|cvt_flt64 | | x | +|extract_n | x | x | + +Floating point: + +| Operations\\Types | float 32x4 | float 64x2 | +|-------------------|:-:|:-:| +|load, store | x | x | +|interleave | x | | +|add, sub | x | x | +|mul | x | x | +|div | x | x | +|compare | x | x | +|min, max | x | x | +|absdiff | x | x | +|reduce | x | | +|mask | x | x | +|unpack | x | x | +|cvt_flt32 | | x | +|cvt_flt64 | x | | +|sqrt, abs | x | x | +|float math | x | x | +|transpose4x4 | x | | +|extract | x | x | +|rotate (lanes) | x | x | +|reverse | x | x | +|extract_n | x | x | +|broadcast_element | x | | + + @{ */ + +template struct v_reg +{ +//! @cond IGNORED + typedef _Tp lane_type; + enum { nlanes = n }; +// !@endcond + + /** @brief Constructor + + Initializes register with data from memory + @param ptr pointer to memory block with data for register */ + explicit v_reg(const _Tp* ptr) { for( int i = 0; i < n; i++ ) s[i] = ptr[i]; } + + /** @brief Constructor + + Initializes register with two 64-bit values */ + v_reg(_Tp s0, _Tp s1) { s[0] = s0; s[1] = s1; } + + /** @brief Constructor + + Initializes register with four 32-bit values */ + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3) { s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; } + + /** @brief Constructor + + Initializes register with eight 16-bit values */ + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, + _Tp s4, _Tp s5, _Tp s6, _Tp s7) + { + s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; + s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; + } + + /** @brief Constructor + + Initializes register with sixteen 8-bit values */ + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, + _Tp s4, _Tp s5, _Tp s6, _Tp s7, + _Tp s8, _Tp s9, _Tp s10, _Tp s11, + _Tp s12, _Tp s13, _Tp s14, _Tp s15) + { + s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; + s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; + s[8] = s8; s[9] = s9; s[10] = s10; s[11] = s11; + s[12] = s12; s[13] = s13; s[14] = s14; s[15] = s15; + } + + /** @brief Default constructor + + Does not initialize anything*/ + v_reg() {} + + /** @brief Copy constructor */ + v_reg(const v_reg<_Tp, n> & r) + { + for( int i = 0; i < n; i++ ) + s[i] = r.s[i]; + } + /** @brief Access first value + + Returns value of the first lane according to register type, for example: + @code{.cpp} + v_int32x4 r(1, 2, 3, 4); + int v = r.get0(); // returns 1 + v_uint64x2 r(1, 2); + uint64_t v = r.get0(); // returns 1 + @endcode + */ + _Tp get0() const { return s[0]; } + +//! @cond IGNORED + _Tp get(const int i) const { return s[i]; } + v_reg<_Tp, n> high() const + { + v_reg<_Tp, n> c; + int i; + for( i = 0; i < n/2; i++ ) + { + c.s[i] = s[i+(n/2)]; + c.s[i+(n/2)] = 0; + } + return c; + } + + static v_reg<_Tp, n> zero() + { + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = (_Tp)0; + return c; + } + + static v_reg<_Tp, n> all(_Tp s) + { + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = s; + return c; + } + + template v_reg<_Tp2, n2> reinterpret_as() const + { + size_t bytes = std::min(sizeof(_Tp2)*n2, sizeof(_Tp)*n); + v_reg<_Tp2, n2> c; + std::memcpy(&c.s[0], &s[0], bytes); + return c; + } + + v_reg& operator=(const v_reg<_Tp, n> & r) + { + for( int i = 0; i < n; i++ ) + s[i] = r.s[i]; + return *this; + } + + _Tp s[n]; +//! @endcond +}; + +/** @brief Sixteen 8-bit unsigned integer values */ +typedef v_reg v_uint8x16; +/** @brief Sixteen 8-bit signed integer values */ +typedef v_reg v_int8x16; +/** @brief Eight 16-bit unsigned integer values */ +typedef v_reg v_uint16x8; +/** @brief Eight 16-bit signed integer values */ +typedef v_reg v_int16x8; +/** @brief Four 32-bit unsigned integer values */ +typedef v_reg v_uint32x4; +/** @brief Four 32-bit signed integer values */ +typedef v_reg v_int32x4; +/** @brief Four 32-bit floating point values (single precision) */ +typedef v_reg v_float32x4; +/** @brief Two 64-bit floating point values (double precision) */ +typedef v_reg v_float64x2; +/** @brief Two 64-bit unsigned integer values */ +typedef v_reg v_uint64x2; +/** @brief Two 64-bit signed integer values */ +typedef v_reg v_int64x2; + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_BIN_OP(bin_op) \ +template inline v_reg<_Tp, n> \ + operator bin_op (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ + return c; \ +} \ +template inline v_reg<_Tp, n>& \ + operator bin_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + for( int i = 0; i < n; i++ ) \ + a.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ + return a; \ +} + +/** @brief Add values + +For all types. */ +OPENCV_HAL_IMPL_BIN_OP(+) + +/** @brief Subtract values + +For all types. */ +OPENCV_HAL_IMPL_BIN_OP(-) + +/** @brief Multiply values + +For 16- and 32-bit integer types and floating types. */ +OPENCV_HAL_IMPL_BIN_OP(*) + +/** @brief Divide values + +For floating types only. */ +OPENCV_HAL_IMPL_BIN_OP(/) + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_BIT_OP(bit_op) \ +template inline v_reg<_Tp, n> operator bit_op \ + (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ + V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ + return c; \ +} \ +template inline v_reg<_Tp, n>& operator \ + bit_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + for( int i = 0; i < n; i++ ) \ + a.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ + V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ + return a; \ +} + +/** @brief Bitwise AND + +Only for integer types. */ +OPENCV_HAL_IMPL_BIT_OP(&) + +/** @brief Bitwise OR + +Only for integer types. */ +OPENCV_HAL_IMPL_BIT_OP(|) + +/** @brief Bitwise XOR + +Only for integer types.*/ +OPENCV_HAL_IMPL_BIT_OP(^) + +/** @brief Bitwise NOT + +Only for integer types.*/ +template inline v_reg<_Tp, n> operator ~ (const v_reg<_Tp, n>& a) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int(~V_TypeTraits<_Tp>::reinterpret_int(a.s[i])); + } + return c; +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_MATH_FUNC(func, cfunc, _Tp2) \ +template inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a) \ +{ \ + v_reg<_Tp2, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cfunc(a.s[i]); \ + return c; \ +} + +/** @brief Square root of elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_sqrt, std::sqrt, _Tp) + +//! @cond IGNORED +OPENCV_HAL_IMPL_MATH_FUNC(v_sin, std::sin, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_cos, std::cos, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_exp, std::exp, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_log, std::log, _Tp) +//! @endcond + +/** @brief Absolute value of elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_abs, (typename V_TypeTraits<_Tp>::abs_type)std::abs, + typename V_TypeTraits<_Tp>::abs_type) + +/** @brief Round elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_round, cvRound, int) + +/** @brief Floor elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_floor, cvFloor, int) + +/** @brief Ceil elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_ceil, cvCeil, int) + +/** @brief Truncate elements + +Only for floating point types.*/ +OPENCV_HAL_IMPL_MATH_FUNC(v_trunc, int, int) + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_MINMAX_FUNC(func, cfunc) \ +template inline v_reg<_Tp, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cfunc(a.s[i], b.s[i]); \ + return c; \ +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(func, cfunc) \ +template inline _Tp func(const v_reg<_Tp, n>& a) \ +{ \ + _Tp c = a.s[0]; \ + for( int i = 1; i < n; i++ ) \ + c = cfunc(c, a.s[i]); \ + return c; \ +} + +/** @brief Choose min values for each pair + +Scheme: +@code +{A1 A2 ...} +{B1 B2 ...} +-------------- +{min(A1,B1) min(A2,B2) ...} +@endcode +For all types except 64-bit integer. */ +OPENCV_HAL_IMPL_MINMAX_FUNC(v_min, std::min) + +/** @brief Choose max values for each pair + +Scheme: +@code +{A1 A2 ...} +{B1 B2 ...} +-------------- +{max(A1,B1) max(A2,B2) ...} +@endcode +For all types except 64-bit integer. */ +OPENCV_HAL_IMPL_MINMAX_FUNC(v_max, std::max) + +/** @brief Find one min value + +Scheme: +@code +{A1 A2 A3 ...} => min(A1,A2,A3,...) +@endcode +For 32-bit integer and 32-bit floating point types. */ +OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_min, std::min) + +/** @brief Find one max value + +Scheme: +@code +{A1 A2 A3 ...} => max(A1,A2,A3,...) +@endcode +For 32-bit integer and 32-bit floating point types. */ +OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_max, std::max) + +static const unsigned char popCountTable[] = +{ + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; +/** @brief Count the 1 bits in the vector lanes and return result as corresponding unsigned type + +Scheme: +@code +{A1 A2 A3 ...} => {popcount(A1), popcount(A2), popcount(A3), ...} +@endcode +For all integer types. */ +template +inline v_reg::abs_type, n> v_popcount(const v_reg<_Tp, n>& a) +{ + v_reg::abs_type, n> b = v_reg::abs_type, n>::zero(); + for (int i = 0; i < n*(int)sizeof(_Tp); i++) + b.s[i/sizeof(_Tp)] += popCountTable[v_reinterpret_as_u8(a).s[i]]; + return b; +} + + +//! @cond IGNORED +template +inline void v_minmax( const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg<_Tp, n>& minval, v_reg<_Tp, n>& maxval ) +{ + for( int i = 0; i < n; i++ ) + { + minval.s[i] = std::min(a.s[i], b.s[i]); + maxval.s[i] = std::max(a.s[i], b.s[i]); + } +} +//! @endcond + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_CMP_OP(cmp_op) \ +template \ +inline v_reg<_Tp, n> operator cmp_op(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)-(int)(a.s[i] cmp_op b.s[i])); \ + return c; \ +} + +/** @brief Less-than comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(<) + +/** @brief Greater-than comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(>) + +/** @brief Less-than or equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(<=) + +/** @brief Greater-than or equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(>=) + +/** @brief Equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(==) + +/** @brief Not equal comparison + +For all types except 64-bit integer values. */ +OPENCV_HAL_IMPL_CMP_OP(!=) + +template +inline v_reg v_not_nan(const v_reg& a) +{ + typedef typename V_TypeTraits::int_type itype; + v_reg c; + for (int i = 0; i < n; i++) + c.s[i] = V_TypeTraits::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); + return c; +} +template +inline v_reg v_not_nan(const v_reg& a) +{ + typedef typename V_TypeTraits::int_type itype; + v_reg c; + for (int i = 0; i < n; i++) + c.s[i] = V_TypeTraits::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); + return c; +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_ARITHM_OP(func, bin_op, cast_op, _Tp2) \ +template \ +inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef _Tp2 rtype; \ + v_reg c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cast_op(a.s[i] bin_op b.s[i]); \ + return c; \ +} + +/** @brief Add values without saturation + +For 8- and 16-bit integer values. */ +OPENCV_HAL_IMPL_ARITHM_OP(v_add_wrap, +, (_Tp), _Tp) + +/** @brief Subtract values without saturation + +For 8- and 16-bit integer values. */ +OPENCV_HAL_IMPL_ARITHM_OP(v_sub_wrap, -, (_Tp), _Tp) + +/** @brief Multiply values without saturation + +For 8- and 16-bit integer values. */ +OPENCV_HAL_IMPL_ARITHM_OP(v_mul_wrap, *, (_Tp), _Tp) + +//! @cond IGNORED +template inline T _absdiff(T a, T b) +{ + return a > b ? a - b : b - a; +} +//! @endcond + +/** @brief Absolute difference + +Returns \f$ |a - b| \f$ converted to corresponding unsigned type. +Example: +@code{.cpp} +v_int32x4 a, b; // {1, 2, 3, 4} and {4, 3, 2, 1} +v_uint32x4 c = v_absdiff(a, b); // result is {3, 1, 1, 3} +@endcode +For 8-, 16-, 32-bit integer source types. */ +template +inline v_reg::abs_type, n> v_absdiff(const v_reg<_Tp, n>& a, const v_reg<_Tp, n> & b) +{ + typedef typename V_TypeTraits<_Tp>::abs_type rtype; + v_reg c; + const rtype mask = (rtype)(std::numeric_limits<_Tp>::is_signed ? (1 << (sizeof(rtype)*8 - 1)) : 0); + for( int i = 0; i < n; i++ ) + { + rtype ua = a.s[i] ^ mask; + rtype ub = b.s[i] ^ mask; + c.s[i] = _absdiff(ua, ub); + } + return c; +} + +/** @overload + +For 32-bit floating point values */ +inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +{ + v_float32x4 c; + for( int i = 0; i < c.nlanes; i++ ) + c.s[i] = _absdiff(a.s[i], b.s[i]); + return c; +} + +/** @overload + +For 64-bit floating point values */ +inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 c; + for( int i = 0; i < c.nlanes; i++ ) + c.s[i] = _absdiff(a.s[i], b.s[i]); + return c; +} + +/** @brief Saturating absolute difference + +Returns \f$ saturate(|a - b|) \f$ . +For 8-, 16-bit signed integer source types. */ +template +inline v_reg<_Tp, n> v_absdiffs(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++) + c.s[i] = saturate_cast<_Tp>(std::abs(a.s[i] - b.s[i])); + return c; +} + +/** @brief Inversed square root + +Returns \f$ 1/sqrt(a) \f$ +For floating point types only. */ +template +inline v_reg<_Tp, n> v_invsqrt(const v_reg<_Tp, n>& a) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = 1.f/std::sqrt(a.s[i]); + return c; +} + +/** @brief Magnitude + +Returns \f$ sqrt(a^2 + b^2) \f$ +For floating point types only. */ +template +inline v_reg<_Tp, n> v_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = std::sqrt(a.s[i]*a.s[i] + b.s[i]*b.s[i]); + return c; +} + +/** @brief Square of the magnitude + +Returns \f$ a^2 + b^2 \f$ +For floating point types only. */ +template +inline v_reg<_Tp, n> v_sqr_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = a.s[i]*a.s[i] + b.s[i]*b.s[i]; + return c; +} + +/** @brief Multiply and add + + Returns \f$ a*b + c \f$ + For floating point types and signed 32bit int only. */ +template +inline v_reg<_Tp, n> v_fma(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg<_Tp, n>& c) +{ + v_reg<_Tp, n> d; + for( int i = 0; i < n; i++ ) + d.s[i] = a.s[i]*b.s[i] + c.s[i]; + return d; +} + +/** @brief A synonym for v_fma */ +template +inline v_reg<_Tp, n> v_muladd(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg<_Tp, n>& c) +{ + return v_fma(a, b, c); +} + +/** @brief Dot product of elements + +Multiply values in two registers and sum adjacent result pairs. + +Scheme: +@code + {A1 A2 ...} // 16-bit +x {B1 B2 ...} // 16-bit +------------- +{A1B1+A2B2 ...} // 32-bit + +@endcode +*/ +template inline v_reg::w_type, n/2> +v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg c; + for( int i = 0; i < (n/2); i++ ) + c.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1]; + return c; +} + +/** @brief Dot product of elements + +Same as cv::v_dotprod, but add a third element to the sum of adjacent pairs. +Scheme: +@code + {A1 A2 ...} // 16-bit +x {B1 B2 ...} // 16-bit +------------- + {A1B1+A2B2+C1 ...} // 32-bit +@endcode +*/ +template inline v_reg::w_type, n/2> +v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg::w_type, n / 2>& c) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg s; + for( int i = 0; i < (n/2); i++ ) + s.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1] + c.s[i]; + return s; +} + +/** @brief Fast Dot product of elements + +Same as cv::v_dotprod, but it may perform unorder sum between result pairs in some platforms, +this intrinsic can be used if the sum among all lanes is only matters +and also it should be yielding better performance on the affected platforms. + +*/ +template inline v_reg::w_type, n/2> +v_dotprod_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ return v_dotprod(a, b); } + +/** @brief Fast Dot product of elements + +Same as cv::v_dotprod_fast, but add a third element to the sum of adjacent pairs. +*/ +template inline v_reg::w_type, n/2> +v_dotprod_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg::w_type, n / 2>& c) +{ return v_dotprod(a, b, c); } + +/** @brief Dot product of elements and expand + +Multiply values in two registers and expand the sum of adjacent result pairs. + +Scheme: +@code + {A1 A2 A3 A4 ...} // 8-bit +x {B1 B2 B3 B4 ...} // 8-bit +------------- + {A1B1+A2B2+A3B3+A4B4 ...} // 32-bit + +@endcode +*/ +template inline v_reg::q_type, n/4> +v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg s; + for( int i = 0; i < (n/4); i++ ) + s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] + + (q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3]; + return s; +} + +/** @brief Dot product of elements + +Same as cv::v_dotprod_expand, but add a third element to the sum of adjacent pairs. +Scheme: +@code + {A1 A2 A3 A4 ...} // 8-bit +x {B1 B2 B3 B4 ...} // 8-bit +------------- + {A1B1+A2B2+A3B3+A4B4+C1 ...} // 32-bit +@endcode +*/ +template inline v_reg::q_type, n/4> +v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg::q_type, n / 4>& c) +{ + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg s; + for( int i = 0; i < (n/4); i++ ) + s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] + + (q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3] + c.s[i]; + return s; +} + +/** @brief Fast Dot product of elements and expand + +Multiply values in two registers and expand the sum of adjacent result pairs. + +Same as cv::v_dotprod_expand, but it may perform unorder sum between result pairs in some platforms, +this intrinsic can be used if the sum among all lanes is only matters +and also it should be yielding better performance on the affected platforms. + +*/ +template inline v_reg::q_type, n/4> +v_dotprod_expand_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ return v_dotprod_expand(a, b); } + +/** @brief Fast Dot product of elements + +Same as cv::v_dotprod_expand_fast, but add a third element to the sum of adjacent pairs. +*/ +template inline v_reg::q_type, n/4> +v_dotprod_expand_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg::q_type, n / 4>& c) +{ return v_dotprod_expand(a, b, c); } + +/** @brief Multiply and expand + +Multiply values two registers and store results in two registers with wider pack type. +Scheme: +@code + {A B C D} // 32-bit +x {E F G H} // 32-bit +--------------- +{AE BF} // 64-bit + {CG DH} // 64-bit +@endcode +Example: +@code{.cpp} +v_uint32x4 a, b; // {1,2,3,4} and {2,2,2,2} +v_uint64x2 c, d; // results +v_mul_expand(a, b, c, d); // c, d = {2,4}, {6, 8} +@endcode +Implemented only for 16- and unsigned 32-bit source types (v_int16x8, v_uint16x8, v_uint32x4). +*/ +template inline void v_mul_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg::w_type, n/2>& c, + v_reg::w_type, n/2>& d) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = (w_type)a.s[i]*b.s[i]; + d.s[i] = (w_type)a.s[i+(n/2)]*b.s[i+(n/2)]; + } +} + +/** @brief Multiply and extract high part + +Multiply values two registers and store high part of the results. +Implemented only for 16-bit source types (v_int16x8, v_uint16x8). Returns \f$ a*b >> 16 \f$ +*/ +template inline v_reg<_Tp, n> v_mul_hi(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg<_Tp, n> c; + for (int i = 0; i < n; i++) + c.s[i] = (_Tp)(((w_type)a.s[i] * b.s[i]) >> sizeof(_Tp)*8); + return c; +} + +//! @cond IGNORED +template inline void v_hsum(const v_reg<_Tp, n>& a, + v_reg::w_type, n/2>& c) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = (w_type)a.s[i*2] + a.s[i*2+1]; + } +} +//! @endcond + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_SHIFT_OP(shift_op) \ +template inline v_reg<_Tp, n> operator shift_op(const v_reg<_Tp, n>& a, int imm) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = (_Tp)(a.s[i] shift_op imm); \ + return c; \ +} + +/** @brief Bitwise shift left + +For 16-, 32- and 64-bit integer values. */ +OPENCV_HAL_IMPL_SHIFT_OP(<< ) + +/** @brief Bitwise shift right + +For 16-, 32- and 64-bit integer values. */ +OPENCV_HAL_IMPL_SHIFT_OP(>> ) + +/** @brief Element shift left among vector + +For all type */ +#define OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(suffix,opA,opB) \ +template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a) \ +{ \ + v_reg<_Tp, n> b; \ + for (int i = 0; i < n; i++) \ + { \ + int sIndex = i opA imm; \ + if (0 <= sIndex && sIndex < n) \ + { \ + b.s[i] = a.s[sIndex]; \ + } \ + else \ + { \ + b.s[i] = 0; \ + } \ + } \ + return b; \ +} \ +template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for (int i = 0; i < n; i++) \ + { \ + int aIndex = i opA imm; \ + int bIndex = i opA imm opB n; \ + if (0 <= bIndex && bIndex < n) \ + { \ + c.s[i] = b.s[bIndex]; \ + } \ + else if (0 <= aIndex && aIndex < n) \ + { \ + c.s[i] = a.s[aIndex]; \ + } \ + else \ + { \ + c.s[i] = 0; \ + } \ + } \ + return c; \ +} + +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(left, -, +) +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(right, +, -) + +/** @brief Sum packed values + +Scheme: +@code +{A1 A2 A3 ...} => sum{A1,A2,A3,...} +@endcode +For 32-bit integer and 32-bit floating point types.*/ +template inline typename V_TypeTraits<_Tp>::sum_type v_reduce_sum(const v_reg<_Tp, n>& a) +{ + typename V_TypeTraits<_Tp>::sum_type c = a.s[0]; + for( int i = 1; i < n; i++ ) + c += a.s[i]; + return c; +} + +/** @brief Sums all elements of each input vector, returns the vector of sums + + Scheme: + @code + result[0] = a[0] + a[1] + a[2] + a[3] + result[1] = b[0] + b[1] + b[2] + b[3] + result[2] = c[0] + c[1] + c[2] + c[3] + result[3] = d[0] + d[1] + d[2] + d[3] + @endcode +*/ +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + v_float32x4 r; + r.s[0] = a.s[0] + a.s[1] + a.s[2] + a.s[3]; + r.s[1] = b.s[0] + b.s[1] + b.s[2] + b.s[3]; + r.s[2] = c.s[0] + c.s[1] + c.s[2] + c.s[3]; + r.s[3] = d.s[0] + d.s[1] + d.s[2] + d.s[3]; + return r; +} + +/** @brief Sum absolute differences of values + +Scheme: +@code +{A1 A2 A3 ...} {B1 B2 B3 ...} => sum{ABS(A1-B1),abs(A2-B2),abs(A3-B3),...} +@endcode +For all types except 64-bit types.*/ +template inline typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type v_reduce_sad(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type c = _absdiff(a.s[0], b.s[0]); + for (int i = 1; i < n; i++) + c += _absdiff(a.s[i], b.s[i]); + return c; +} + +/** @brief Get negative values mask +@deprecated v_signmask depends on a lane count heavily and therefore isn't universal enough + +Returned value is a bit mask with bits set to 1 on places corresponding to negative packed values indexes. +Example: +@code{.cpp} +v_int32x4 r; // set to {-1, -1, 1, 1} +int mask = v_signmask(r); // mask = 3 <== 00000000 00000000 00000000 00000011 +@endcode +*/ +template inline int v_signmask(const v_reg<_Tp, n>& a) +{ + int mask = 0; + for( int i = 0; i < n; i++ ) + mask |= (V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0) << i; + return mask; +} + +/** @brief Get first negative lane index + +Returned value is an index of first negative lane (undefined for input of all positive values) +Example: +@code{.cpp} +v_int32x4 r; // set to {0, 0, -1, -1} +int idx = v_heading_zeros(r); // idx = 2 +@endcode +*/ +template inline int v_scan_forward(const v_reg<_Tp, n>& a) +{ + for (int i = 0; i < n; i++) + if(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0) + return i; + return 0; +} + +/** @brief Check if all packed values are less than zero + +Unsigned values will be casted to signed: `uchar 254 => char -2`. +*/ +template inline bool v_check_all(const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) >= 0 ) + return false; + return true; +} + +/** @brief Check if any of packed values is less than zero + +Unsigned values will be casted to signed: `uchar 254 => char -2`. +*/ +template inline bool v_check_any(const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0 ) + return true; + return false; +} + +/** @brief Per-element select (blend operation) + +Return value will be built by combining values _a_ and _b_ using the following scheme: + result[i] = mask[i] ? a[i] : b[i]; + +@note: _mask_ element values are restricted to these values: +- 0: select element from _b_ +- 0xff/0xffff/etc: select element from _a_ +(fully compatible with bitwise-based operator) +*/ +template inline v_reg<_Tp, n> v_select(const v_reg<_Tp, n>& mask, + const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef V_TypeTraits<_Tp> Traits; + typedef typename Traits::int_type int_type; + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + { + int_type m = Traits::reinterpret_int(mask.s[i]); + CV_DbgAssert(m == 0 || m == (~(int_type)0)); // restrict mask values: 0 or 0xff/0xffff/etc + c.s[i] = m ? a.s[i] : b.s[i]; + } + return c; +} + +/** @brief Expand values to the wider pack type + +Copy contents of register to two registers with 2x wider pack type. +Scheme: +@code + int32x4 int64x2 int64x2 +{A B C D} ==> {A B} , {C D} +@endcode */ +template inline void v_expand(const v_reg<_Tp, n>& a, + v_reg::w_type, n/2>& b0, + v_reg::w_type, n/2>& b1) +{ + for( int i = 0; i < (n/2); i++ ) + { + b0.s[i] = a.s[i]; + b1.s[i] = a.s[i+(n/2)]; + } +} + +/** @brief Expand lower values to the wider pack type + +Same as cv::v_expand, but return lower half of the vector. + +Scheme: +@code + int32x4 int64x2 +{A B C D} ==> {A B} +@endcode */ +template +inline v_reg::w_type, n/2> +v_expand_low(const v_reg<_Tp, n>& a) +{ + v_reg::w_type, n/2> b; + for( int i = 0; i < (n/2); i++ ) + b.s[i] = a.s[i]; + return b; +} + +/** @brief Expand higher values to the wider pack type + +Same as cv::v_expand_low, but expand higher half of the vector instead. + +Scheme: +@code + int32x4 int64x2 +{A B C D} ==> {C D} +@endcode */ +template +inline v_reg::w_type, n/2> +v_expand_high(const v_reg<_Tp, n>& a) +{ + v_reg::w_type, n/2> b; + for( int i = 0; i < (n/2); i++ ) + b.s[i] = a.s[i+(n/2)]; + return b; +} + +//! @cond IGNORED +template inline v_reg::int_type, n> + v_reinterpret_as_int(const v_reg<_Tp, n>& a) +{ + v_reg::int_type, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = V_TypeTraits<_Tp>::reinterpret_int(a.s[i]); + return c; +} + +template inline v_reg::uint_type, n> + v_reinterpret_as_uint(const v_reg<_Tp, n>& a) +{ + v_reg::uint_type, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = V_TypeTraits<_Tp>::reinterpret_uint(a.s[i]); + return c; +} +//! @endcond + +/** @brief Interleave two vectors + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +--------------- + {A1 B1 A2 B2} and {A3 B3 A4 B4} +@endcode +For all types except 64-bit. +*/ +template inline void v_zip( const v_reg<_Tp, n>& a0, const v_reg<_Tp, n>& a1, + v_reg<_Tp, n>& b0, v_reg<_Tp, n>& b1 ) +{ + int i; + for( i = 0; i < n/2; i++ ) + { + b0.s[i*2] = a0.s[i]; + b0.s[i*2+1] = a1.s[i]; + } + for( ; i < n; i++ ) + { + b1.s[i*2-n] = a0.s[i]; + b1.s[i*2-n+1] = a1.s[i]; + } +} + +/** @brief Load register contents from memory + +@param ptr pointer to memory block with data +@return register object + +@note Returned type will be detected from passed pointer type, for example uchar ==> cv::v_uint8x16, int ==> cv::v_int32x4, etc. + */ +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load(const _Tp* ptr) +{ + return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); +} + +/** @brief Load register contents from memory (aligned) + +similar to cv::v_load, but source memory block should be aligned (to 16-byte boundary) + */ +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_aligned(const _Tp* ptr) +{ + return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); +} + +/** @brief Load 64-bits of data to lower part (high part is undefined). + +@param ptr memory block containing data for first half (0..n/2) + +@code{.cpp} +int lo[2] = { 1, 2 }; +v_int32x4 r = v_load_low(lo); +@endcode + */ +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for( int i = 0; i < c.nlanes/2; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +/** @brief Load register contents from two memory blocks + +@param loptr memory block containing data for first half (0..n/2) +@param hiptr memory block containing data for second half (n/2..n) + +@code{.cpp} +int lo[2] = { 1, 2 }, hi[2] = { 3, 4 }; +v_int32x4 r = v_load_halves(lo, hi); +@endcode + */ +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_halves(const _Tp* loptr, const _Tp* hiptr) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for( int i = 0; i < c.nlanes/2; i++ ) + { + c.s[i] = loptr[i]; + c.s[i+c.nlanes/2] = hiptr[i]; + } + return c; +} + +/** @brief Load register contents from memory with double expand + +Same as cv::v_load, but result pack type will be 2x wider than memory type. + +@code{.cpp} +short buf[4] = {1, 2, 3, 4}; // type is int16 +v_int32x4 r = v_load_expand(buf); // r = {1, 2, 3, 4} - type is int32 +@endcode +For 8-, 16-, 32-bit integer source types. */ +template +inline v_reg::w_type, V_TypeTraits<_Tp>::nlanes128 / 2> +v_load_expand(const _Tp* ptr) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg::nlanes128> c; + for( int i = 0; i < c.nlanes; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +/** @brief Load register contents from memory with quad expand + +Same as cv::v_load_expand, but result type is 4 times wider than source. +@code{.cpp} +char buf[4] = {1, 2, 3, 4}; // type is int8 +v_int32x4 r = v_load_q(buf); // r = {1, 2, 3, 4} - type is int32 +@endcode +For 8-bit integer source types. */ +template +inline v_reg::q_type, V_TypeTraits<_Tp>::nlanes128 / 4> +v_load_expand_q(const _Tp* ptr) +{ + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg::nlanes128> c; + for( int i = 0; i < c.nlanes; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +/** @brief Load and deinterleave (2 channels) + +Load data from memory deinterleave and store to 2 registers. +Scheme: +@code +{A1 B1 A2 B2 ...} ==> {A1 A2 ...}, {B1 B2 ...} +@endcode +For all types except 64-bit. */ +template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + a.s[i] = ptr[i2]; + b.s[i] = ptr[i2+1]; + } +} + +/** @brief Load and deinterleave (3 channels) + +Load data from memory deinterleave and store to 3 registers. +Scheme: +@code +{A1 B1 C1 A2 B2 C2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} +@endcode +For all types except 64-bit. */ +template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b, v_reg<_Tp, n>& c) +{ + int i, i3; + for( i = i3 = 0; i < n; i++, i3 += 3 ) + { + a.s[i] = ptr[i3]; + b.s[i] = ptr[i3+1]; + c.s[i] = ptr[i3+2]; + } +} + +/** @brief Load and deinterleave (4 channels) + +Load data from memory deinterleave and store to 4 registers. +Scheme: +@code +{A1 B1 C1 D1 A2 B2 C2 D2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} +@endcode +For all types except 64-bit. */ +template +inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b, v_reg<_Tp, n>& c, + v_reg<_Tp, n>& d) +{ + int i, i4; + for( i = i4 = 0; i < n; i++, i4 += 4 ) + { + a.s[i] = ptr[i4]; + b.s[i] = ptr[i4+1]; + c.s[i] = ptr[i4+2]; + d.s[i] = ptr[i4+3]; + } +} + +/** @brief Interleave and store (2 channels) + +Interleave and store data from 2 registers to memory. +Scheme: +@code +{A1 A2 ...}, {B1 B2 ...} ==> {A1 B1 A2 B2 ...} +@endcode +For all types except 64-bit. */ +template +inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + ptr[i2] = a.s[i]; + ptr[i2+1] = b.s[i]; + } +} + +/** @brief Interleave and store (3 channels) + +Interleave and store data from 3 registers to memory. +Scheme: +@code +{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} ==> {A1 B1 C1 A2 B2 C2 ...} +@endcode +For all types except 64-bit. */ +template +inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i3; + for( i = i3 = 0; i < n; i++, i3 += 3 ) + { + ptr[i3] = a.s[i]; + ptr[i3+1] = b.s[i]; + ptr[i3+2] = c.s[i]; + } +} + +/** @brief Interleave and store (4 channels) + +Interleave and store data from 4 registers to memory. +Scheme: +@code +{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} ==> {A1 B1 C1 D1 A2 B2 C2 D2 ...} +@endcode +For all types except 64-bit. */ +template inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, + const v_reg<_Tp, n>& d, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i4; + for( i = i4 = 0; i < n; i++, i4 += 4 ) + { + ptr[i4] = a.s[i]; + ptr[i4+1] = b.s[i]; + ptr[i4+2] = c.s[i]; + ptr[i4+3] = d.s[i]; + } +} + +/** @brief Store data to memory + +Store register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {A B C D} +@endcode +Pointer can be unaligned. */ +template +inline void v_store(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +/** @brief Store data to memory (lower half) + +Store lower half of register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {A B} +@endcode */ +template +inline void v_store_low(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < (n/2); i++ ) + ptr[i] = a.s[i]; +} + +/** @brief Store data to memory (higher half) + +Store higher half of register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {C D} +@endcode */ +template +inline void v_store_high(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < (n/2); i++ ) + ptr[i] = a.s[i+(n/2)]; +} + +/** @brief Store data to memory (aligned) + +Store register contents to memory. +Scheme: +@code + REG {A B C D} ==> MEM {A B C D} +@endcode +Pointer __should__ be aligned by 16-byte boundary. */ +template +inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template +inline void v_store_aligned_nocache(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template +inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +/** @brief Combine vector from first elements of two vectors + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +--------------- + {A1 A2 B1 B2} +@endcode +For all types except 64-bit. */ +template +inline v_reg<_Tp, n> v_combine_low(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = a.s[i]; + c.s[i+(n/2)] = b.s[i]; + } + return c; +} + +/** @brief Combine vector from last elements of two vectors + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +--------------- + {A3 A4 B3 B4} +@endcode +For all types except 64-bit. */ +template +inline v_reg<_Tp, n> v_combine_high(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = a.s[i+(n/2)]; + c.s[i+(n/2)] = b.s[i+(n/2)]; + } + return c; +} + +/** @brief Combine two vectors from lower and higher parts of two other vectors + +@code{.cpp} +low = cv::v_combine_low(a, b); +high = cv::v_combine_high(a, b); +@endcode */ +template +inline void v_recombine(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg<_Tp, n>& low, v_reg<_Tp, n>& high) +{ + for( int i = 0; i < (n/2); i++ ) + { + low.s[i] = a.s[i]; + low.s[i+(n/2)] = b.s[i]; + high.s[i] = a.s[i+(n/2)]; + high.s[i+(n/2)] = b.s[i+(n/2)]; + } +} + +/** @brief Vector reverse order + +Reverse the order of the vector +Scheme: +@code + REG {A1 ... An} ==> REG {An ... A1} +@endcode +For all types. */ +template +inline v_reg<_Tp, n> v_reverse(const v_reg<_Tp, n>& a) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = a.s[n-i-1]; + return c; +} + +/** @brief Vector extract + +Scheme: +@code + {A1 A2 A3 A4} + {B1 B2 B3 B4} +======================== +shift = 1 {A2 A3 A4 B1} +shift = 2 {A3 A4 B1 B2} +shift = 3 {A4 B1 B2 B3} +@endcode +Restriction: 0 <= shift < nlanes + +Usage: +@code +v_int32x4 a, b, c; +c = v_extract<2>(a, b); +@endcode +For all types. */ +template +inline v_reg<_Tp, n> v_extract(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> r; + const int shift = n - s; + int i = 0; + for (; i < shift; ++i) + r.s[i] = a.s[i+s]; + for (; i < n; ++i) + r.s[i] = b.s[i-shift]; + return r; +} + +/** @brief Vector extract + +Scheme: +Return the s-th element of v. +Restriction: 0 <= s < nlanes + +Usage: +@code +v_int32x4 a; +int r; +r = v_extract_n<2>(a); +@endcode +For all types. */ +template +inline _Tp v_extract_n(const v_reg<_Tp, n>& v) +{ + CV_DbgAssert(s >= 0 && s < n); + return v.s[s]; +} + +/** @brief Broadcast i-th element of vector + +Scheme: +@code +{ v[0] v[1] v[2] ... v[SZ] } => { v[i], v[i], v[i] ... v[i] } +@endcode +Restriction: 0 <= i < nlanes +Supported types: 32-bit integers and floats (s32/u32/f32) + */ +template +inline v_reg<_Tp, n> v_broadcast_element(const v_reg<_Tp, n>& a) +{ + CV_DbgAssert(i >= 0 && i < n); + return v_reg<_Tp, n>::all(a.s[i]); +} + +/** @brief Round + +Rounds each value. Input type is float vector ==> output type is int vector.*/ +template inline v_reg v_round(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvRound(a.s[i]); + return c; +} + +/** @overload */ +template inline v_reg v_round(const v_reg& a, const v_reg& b) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvRound(a.s[i]); + c.s[i+n] = cvRound(b.s[i]); + } + return c; +} + +/** @brief Floor + +Floor each value. Input type is float vector ==> output type is int vector.*/ +template inline v_reg v_floor(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvFloor(a.s[i]); + return c; +} + +/** @brief Ceil + +Ceil each value. Input type is float vector ==> output type is int vector.*/ +template inline v_reg v_ceil(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvCeil(a.s[i]); + return c; +} + +/** @brief Trunc + +Truncate each value. Input type is float vector ==> output type is int vector.*/ +template inline v_reg v_trunc(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = (int)(a.s[i]); + return c; +} + +/** @overload */ +template inline v_reg v_round(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvRound(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @overload */ +template inline v_reg v_floor(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvFloor(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @overload */ +template inline v_reg v_ceil(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvCeil(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @overload */ +template inline v_reg v_trunc(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvCeil(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +/** @brief Convert to float + +Supported input type is cv::v_int32x4. */ +template inline v_reg v_cvt_f32(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = (float)a.s[i]; + return c; +} + +template inline v_reg v_cvt_f32(const v_reg& a, const v_reg& b) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = (float)a.s[i]; + c.s[i+n] = (float)b.s[i]; + } + return c; +} + +/** @brief Convert to double + +Supported input type is cv::v_int32x4. */ +template inline v_reg v_cvt_f64(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +/** @brief Convert to double + +Supported input type is cv::v_float32x4. */ +template inline v_reg v_cvt_f64(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +/** @brief Convert to double + +Supported input type is cv::v_int64x2. */ +template inline v_reg v_cvt_f64(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i]]; + return c; +} +template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_pairs(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i / 2] + i % 2]; + return c; +} +template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_quads(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i / 4] + i % 4]; + return c; +} + +template inline v_reg v_lut(const int* tab, const v_reg& idx) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline v_reg v_lut(const unsigned* tab, const v_reg& idx) +{ + v_reg c; + for (int i = 0; i < n; i++) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline v_reg v_lut(const float* tab, const v_reg& idx) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline v_reg v_lut(const double* tab, const v_reg& idx) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline void v_lut_deinterleave(const float* tab, const v_reg& idx, + v_reg& x, v_reg& y) +{ + for( int i = 0; i < n; i++ ) + { + int j = idx.s[i]; + x.s[i] = tab[j]; + y.s[i] = tab[j+1]; + } +} + +template inline void v_lut_deinterleave(const double* tab, const v_reg& idx, + v_reg& x, v_reg& y) +{ + for( int i = 0; i < n; i++ ) + { + int j = idx.s[i]; + x.s[i] = tab[j]; + y.s[i] = tab[j+1]; + } +} + +template inline v_reg<_Tp, n> v_interleave_pairs(const v_reg<_Tp, n>& vec) +{ + v_reg c; + for (int i = 0; i < n/4; i++) + { + c.s[4*i ] = vec.s[4*i ]; + c.s[4*i+1] = vec.s[4*i+2]; + c.s[4*i+2] = vec.s[4*i+1]; + c.s[4*i+3] = vec.s[4*i+3]; + } + return c; +} + +template inline v_reg<_Tp, n> v_interleave_quads(const v_reg<_Tp, n>& vec) +{ + v_reg c; + for (int i = 0; i < n/8; i++) + { + c.s[8*i ] = vec.s[8*i ]; + c.s[8*i+1] = vec.s[8*i+4]; + c.s[8*i+2] = vec.s[8*i+1]; + c.s[8*i+3] = vec.s[8*i+5]; + c.s[8*i+4] = vec.s[8*i+2]; + c.s[8*i+5] = vec.s[8*i+6]; + c.s[8*i+6] = vec.s[8*i+3]; + c.s[8*i+7] = vec.s[8*i+7]; + } + return c; +} + +template inline v_reg<_Tp, n> v_pack_triplets(const v_reg<_Tp, n>& vec) +{ + v_reg c; + for (int i = 0; i < n/4; i++) + { + c.s[3*i ] = vec.s[4*i ]; + c.s[3*i+1] = vec.s[4*i+1]; + c.s[3*i+2] = vec.s[4*i+2]; + } + return c; +} + +/** @brief Transpose 4x4 matrix + +Scheme: +@code +a0 {A1 A2 A3 A4} +a1 {B1 B2 B3 B4} +a2 {C1 C2 C3 C4} +a3 {D1 D2 D3 D4} +=============== +b0 {A1 B1 C1 D1} +b1 {A2 B2 C2 D2} +b2 {A3 B3 C3 D3} +b3 {A4 B4 C4 D4} +@endcode +*/ +template +inline void v_transpose4x4( v_reg<_Tp, 4>& a0, const v_reg<_Tp, 4>& a1, + const v_reg<_Tp, 4>& a2, const v_reg<_Tp, 4>& a3, + v_reg<_Tp, 4>& b0, v_reg<_Tp, 4>& b1, + v_reg<_Tp, 4>& b2, v_reg<_Tp, 4>& b3 ) +{ + b0 = v_reg<_Tp, 4>(a0.s[0], a1.s[0], a2.s[0], a3.s[0]); + b1 = v_reg<_Tp, 4>(a0.s[1], a1.s[1], a2.s[1], a3.s[1]); + b2 = v_reg<_Tp, 4>(a0.s[2], a1.s[2], a2.s[2], a3.s[2]); + b3 = v_reg<_Tp, 4>(a0.s[3], a1.s[3], a2.s[3], a3.s[3]); +} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_INIT_ZERO(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec::zero(); } + +//! @name Init with zero +//! @{ +//! @brief Create new vector with zero elements +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x2, int64, s64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_INIT_VAL(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_setall_##suffix(_Tp val) { return _Tpvec::all(val); } + +//! @name Init with value +//! @{ +//! @brief Create new vector with elements set to a specific value +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x2, int64, s64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_REINTERPRET(_Tpvec, _Tp, suffix) \ +template inline _Tpvec \ + v_reinterpret_as_##suffix(const v_reg<_Tp0, n0>& a) \ +{ return a.template reinterpret_as<_Tp, _Tpvec::nlanes>(); } + +//! @name Reinterpret +//! @{ +//! @brief Convert vector to different type without modifying underlying data. +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int64x2, int64, s64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_SHIFTL(_Tpvec, _Tp) \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ return a << n; } + +//! @name Left shift +//! @{ +//! @brief Shift left +OPENCV_HAL_IMPL_C_SHIFTL(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_SHIFTL(v_int16x8, short) +OPENCV_HAL_IMPL_C_SHIFTL(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_SHIFTL(v_int32x4, int) +OPENCV_HAL_IMPL_C_SHIFTL(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_SHIFTL(v_int64x2, int64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_SHIFTR(_Tpvec, _Tp) \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ return a >> n; } + +//! @name Right shift +//! @{ +//! @brief Shift right +OPENCV_HAL_IMPL_C_SHIFTR(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_SHIFTR(v_int16x8, short) +OPENCV_HAL_IMPL_C_SHIFTR(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_SHIFTR(v_int32x4, int) +OPENCV_HAL_IMPL_C_SHIFTR(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_SHIFTR(v_int64x2, int64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_RSHIFTR(_Tpvec, _Tp) \ +template inline _Tpvec v_rshr(const _Tpvec& a) \ +{ \ + _Tpvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + c.s[i] = (_Tp)((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + return c; \ +} + +//! @name Rounding shift +//! @{ +//! @brief Rounding shift right +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int16x8, short) +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int32x4, int) +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int64x2, int64) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix, cast) \ +inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpnvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + { \ + c.s[i] = cast<_Tpn>(a.s[i]); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>(b.s[i]); \ + } \ + return c; \ +} + +//! @name Pack +//! @{ +//! @brief Pack values from two vectors to one +//! +//! Return vector type have twice more elements than input vector types. Variant with _u_ suffix also +//! converts to corresponding unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +template inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpnvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + { \ + c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + } \ + return c; \ +} + +//! @name Pack with rounding shift +//! @{ +//! @brief Pack values from two vectors to one with rounding shift +//! +//! Values from the input vectors will be shifted right by _n_ bits with rounding, converted to narrower +//! type and returned in the result vector. Variant with _u_ suffix converts to unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +{ \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + ptr[i] = cast<_Tpn>(a.s[i]); \ +} + +//! @name Pack and store +//! @{ +//! @brief Store values from the input vector into memory with pack +//! +//! Values will be stored into memory with conversion to narrower type. +//! Variant with _u_ suffix converts to corresponding unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @brief Helper macro +//! @ingroup core_hal_intrin_impl +#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +{ \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ +} + +//! @name Pack and store with rounding shift +//! @{ +//! @brief Store values from the input vector into memory with pack +//! +//! Values will be shifted _n_ bits right with rounding, converted to narrower type and stored into +//! memory. Variant with _u_ suffix converts to unsigned type. +//! +//! - pack: for 16-, 32- and 64-bit integer input types +//! - pack_u: for 16- and 32-bit signed integer input types +//! +//! @note All variants except 64-bit use saturation. +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) +//! @} + +//! @cond IGNORED +template +inline void _pack_b(_Tpm* mptr, const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + for (int i = 0; i < n; ++i) + { + mptr[i] = (_Tpm)a.s[i]; + mptr[i + n] = (_Tpm)b.s[i]; + } +} +//! @endcond + +//! @name Pack boolean values +//! @{ +//! @brief Pack boolean values from multiple vectors to one unsigned 8-bit integer vector +//! +//! @note Must provide valid boolean values to guarantee same result for all architectures. + +/** @brief +//! For 16-bit boolean values + +Scheme: +@code +a {0xFFFF 0 0 0xFFFF 0 0xFFFF 0xFFFF 0} +b {0xFFFF 0 0xFFFF 0 0 0xFFFF 0 0xFFFF} +=============== +{ + 0xFF 0 0 0xFF 0 0xFF 0xFF 0 + 0xFF 0 0xFF 0 0 0xFF 0 0xFF +} +@endcode */ + +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + return mask; +} + +/** @overload +For 32-bit boolean values + +Scheme: +@code +a {0xFFFF.. 0 0 0xFFFF..} +b {0 0xFFFF.. 0xFFFF.. 0} +c {0xFFFF.. 0 0xFFFF.. 0} +d {0 0xFFFF.. 0 0xFFFF..} +=============== +{ + 0xFF 0 0 0xFF 0 0xFF 0xFF 0 + 0xFF 0 0xFF 0 0 0xFF 0 0xFF +} +@endcode */ + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + _pack_b(mask.s + 8, c, d); + return mask; +} + +/** @overload +For 64-bit boolean values + +Scheme: +@code +a {0xFFFF.. 0} +b {0 0xFFFF..} +c {0xFFFF.. 0} +d {0 0xFFFF..} + +e {0xFFFF.. 0} +f {0xFFFF.. 0} +g {0 0xFFFF..} +h {0 0xFFFF..} +=============== +{ + 0xFF 0 0 0xFF 0xFF 0 0 0xFF + 0xFF 0 0xFF 0 0 0xFF 0 0xFF +} +@endcode */ +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + _pack_b(mask.s + 4, c, d); + _pack_b(mask.s + 8, e, f); + _pack_b(mask.s + 12, g, h); + return mask; +} +//! @} + +/** @brief Matrix multiplication + +Scheme: +@code +{A0 A1 A2 A3} |V0| +{B0 B1 B2 B3} |V1| +{C0 C1 C2 C3} |V2| +{D0 D1 D2 D3} x |V3| +==================== +{R0 R1 R2 R3}, where: +R0 = A0V0 + A1V1 + A2V2 + A3V3, +R1 = B0V0 + B1V1 + B2V2 + B3V3 +... +@endcode +*/ +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + v.s[3]*m3.s[0], + v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + v.s[3]*m3.s[1], + v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + v.s[3]*m3.s[2], + v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + v.s[3]*m3.s[3]); +} + +/** @brief Matrix multiplication and add + +Scheme: +@code +{A0 A1 A2 } |V0| |D0| +{B0 B1 B2 } |V1| |D1| +{C0 C1 C2 } x |V2| + |D2| +==================== +{R0 R1 R2 R3}, where: +R0 = A0V0 + A1V1 + A2V2 + D0, +R1 = B0V0 + B1V1 + B2V2 + D1 +... +@endcode +*/ +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + m3.s[0], + v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + m3.s[1], + v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + m3.s[2], + v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]); +} + +////// FP16 support /////// + +inline v_reg::nlanes128> +v_load_expand(const float16_t* ptr) +{ + v_reg::nlanes128> v; + for( int i = 0; i < v.nlanes; i++ ) + { + v.s[i] = ptr[i]; + } + return v; +} + +inline void +v_pack_store(float16_t* ptr, v_reg::nlanes128>& v) +{ + for( int i = 0; i < v.nlanes; i++ ) + { + ptr[i] = float16_t(v.s[i]); + } +} + +inline void v_cleanup() {} + +//! @} + +#ifndef CV_DOXYGEN +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END +#endif +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_forward.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_forward.hpp new file mode 100644 index 0000000000000000000000000000000000000000..979f15a277d173914282a6eda2c4066ccb450892 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_forward.hpp @@ -0,0 +1,191 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef CV__SIMD_FORWARD +#error "Need to pre-define forward width" +#endif + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +/** Types **/ +#if CV__SIMD_FORWARD == 1024 +// [todo] 1024 +#error "1024-long ops not implemented yet" +#elif CV__SIMD_FORWARD == 512 +// 512 +#define __CV_VX(fun) v512_##fun +#define __CV_V_UINT8 v_uint8x64 +#define __CV_V_INT8 v_int8x64 +#define __CV_V_UINT16 v_uint16x32 +#define __CV_V_INT16 v_int16x32 +#define __CV_V_UINT32 v_uint32x16 +#define __CV_V_INT32 v_int32x16 +#define __CV_V_UINT64 v_uint64x8 +#define __CV_V_INT64 v_int64x8 +#define __CV_V_FLOAT32 v_float32x16 +#define __CV_V_FLOAT64 v_float64x8 +struct v_uint8x64; +struct v_int8x64; +struct v_uint16x32; +struct v_int16x32; +struct v_uint32x16; +struct v_int32x16; +struct v_uint64x8; +struct v_int64x8; +struct v_float32x16; +struct v_float64x8; +#elif CV__SIMD_FORWARD == 256 +// 256 +#define __CV_VX(fun) v256_##fun +#define __CV_V_UINT8 v_uint8x32 +#define __CV_V_INT8 v_int8x32 +#define __CV_V_UINT16 v_uint16x16 +#define __CV_V_INT16 v_int16x16 +#define __CV_V_UINT32 v_uint32x8 +#define __CV_V_INT32 v_int32x8 +#define __CV_V_UINT64 v_uint64x4 +#define __CV_V_INT64 v_int64x4 +#define __CV_V_FLOAT32 v_float32x8 +#define __CV_V_FLOAT64 v_float64x4 +struct v_uint8x32; +struct v_int8x32; +struct v_uint16x16; +struct v_int16x16; +struct v_uint32x8; +struct v_int32x8; +struct v_uint64x4; +struct v_int64x4; +struct v_float32x8; +struct v_float64x4; +#else +// 128 +#define __CV_VX(fun) v_##fun +#define __CV_V_UINT8 v_uint8x16 +#define __CV_V_INT8 v_int8x16 +#define __CV_V_UINT16 v_uint16x8 +#define __CV_V_INT16 v_int16x8 +#define __CV_V_UINT32 v_uint32x4 +#define __CV_V_INT32 v_int32x4 +#define __CV_V_UINT64 v_uint64x2 +#define __CV_V_INT64 v_int64x2 +#define __CV_V_FLOAT32 v_float32x4 +#define __CV_V_FLOAT64 v_float64x2 +struct v_uint8x16; +struct v_int8x16; +struct v_uint16x8; +struct v_int16x8; +struct v_uint32x4; +struct v_int32x4; +struct v_uint64x2; +struct v_int64x2; +struct v_float32x4; +struct v_float64x2; +#endif + +/** Value reordering **/ + +// Expansion +void v_expand(const __CV_V_UINT8&, __CV_V_UINT16&, __CV_V_UINT16&); +void v_expand(const __CV_V_INT8&, __CV_V_INT16&, __CV_V_INT16&); +void v_expand(const __CV_V_UINT16&, __CV_V_UINT32&, __CV_V_UINT32&); +void v_expand(const __CV_V_INT16&, __CV_V_INT32&, __CV_V_INT32&); +void v_expand(const __CV_V_UINT32&, __CV_V_UINT64&, __CV_V_UINT64&); +void v_expand(const __CV_V_INT32&, __CV_V_INT64&, __CV_V_INT64&); +// Low Expansion +__CV_V_UINT16 v_expand_low(const __CV_V_UINT8&); +__CV_V_INT16 v_expand_low(const __CV_V_INT8&); +__CV_V_UINT32 v_expand_low(const __CV_V_UINT16&); +__CV_V_INT32 v_expand_low(const __CV_V_INT16&); +__CV_V_UINT64 v_expand_low(const __CV_V_UINT32&); +__CV_V_INT64 v_expand_low(const __CV_V_INT32&); +// High Expansion +__CV_V_UINT16 v_expand_high(const __CV_V_UINT8&); +__CV_V_INT16 v_expand_high(const __CV_V_INT8&); +__CV_V_UINT32 v_expand_high(const __CV_V_UINT16&); +__CV_V_INT32 v_expand_high(const __CV_V_INT16&); +__CV_V_UINT64 v_expand_high(const __CV_V_UINT32&); +__CV_V_INT64 v_expand_high(const __CV_V_INT32&); +// Load & Low Expansion +__CV_V_UINT16 __CV_VX(load_expand)(const uchar*); +__CV_V_INT16 __CV_VX(load_expand)(const schar*); +__CV_V_UINT32 __CV_VX(load_expand)(const ushort*); +__CV_V_INT32 __CV_VX(load_expand)(const short*); +__CV_V_UINT64 __CV_VX(load_expand)(const uint*); +__CV_V_INT64 __CV_VX(load_expand)(const int*); +// Load lower 8-bit and expand into 32-bit +__CV_V_UINT32 __CV_VX(load_expand_q)(const uchar*); +__CV_V_INT32 __CV_VX(load_expand_q)(const schar*); + +// Saturating Pack +__CV_V_UINT8 v_pack(const __CV_V_UINT16&, const __CV_V_UINT16&); +__CV_V_INT8 v_pack(const __CV_V_INT16&, const __CV_V_INT16&); +__CV_V_UINT16 v_pack(const __CV_V_UINT32&, const __CV_V_UINT32&); +__CV_V_INT16 v_pack(const __CV_V_INT32&, const __CV_V_INT32&); +// Non-saturating Pack +__CV_V_UINT32 v_pack(const __CV_V_UINT64&, const __CV_V_UINT64&); +__CV_V_INT32 v_pack(const __CV_V_INT64&, const __CV_V_INT64&); +// Pack signed integers with unsigned saturation +__CV_V_UINT8 v_pack_u(const __CV_V_INT16&, const __CV_V_INT16&); +__CV_V_UINT16 v_pack_u(const __CV_V_INT32&, const __CV_V_INT32&); + +/** Arithmetic, bitwise and comparison operations **/ + +// Non-saturating multiply +#if CV_VSX +template +Tvec v_mul_wrap(const Tvec& a, const Tvec& b); +#else +__CV_V_UINT8 v_mul_wrap(const __CV_V_UINT8&, const __CV_V_UINT8&); +__CV_V_INT8 v_mul_wrap(const __CV_V_INT8&, const __CV_V_INT8&); +__CV_V_UINT16 v_mul_wrap(const __CV_V_UINT16&, const __CV_V_UINT16&); +__CV_V_INT16 v_mul_wrap(const __CV_V_INT16&, const __CV_V_INT16&); +#endif + +// Multiply and expand +#if CV_VSX +template +void v_mul_expand(const Tvec& a, const Tvec& b, Twvec& c, Twvec& d); +#else +void v_mul_expand(const __CV_V_UINT8&, const __CV_V_UINT8&, __CV_V_UINT16&, __CV_V_UINT16&); +void v_mul_expand(const __CV_V_INT8&, const __CV_V_INT8&, __CV_V_INT16&, __CV_V_INT16&); +void v_mul_expand(const __CV_V_UINT16&, const __CV_V_UINT16&, __CV_V_UINT32&, __CV_V_UINT32&); +void v_mul_expand(const __CV_V_INT16&, const __CV_V_INT16&, __CV_V_INT32&, __CV_V_INT32&); +void v_mul_expand(const __CV_V_UINT32&, const __CV_V_UINT32&, __CV_V_UINT64&, __CV_V_UINT64&); +void v_mul_expand(const __CV_V_INT32&, const __CV_V_INT32&, __CV_V_INT64&, __CV_V_INT64&); +#endif + +// Conversions +__CV_V_FLOAT32 v_cvt_f32(const __CV_V_INT32& a); +__CV_V_FLOAT32 v_cvt_f32(const __CV_V_FLOAT64& a); +__CV_V_FLOAT32 v_cvt_f32(const __CV_V_FLOAT64& a, const __CV_V_FLOAT64& b); +__CV_V_FLOAT64 v_cvt_f64(const __CV_V_INT32& a); +__CV_V_FLOAT64 v_cvt_f64_high(const __CV_V_INT32& a); +__CV_V_FLOAT64 v_cvt_f64(const __CV_V_FLOAT32& a); +__CV_V_FLOAT64 v_cvt_f64_high(const __CV_V_FLOAT32& a); +__CV_V_FLOAT64 v_cvt_f64(const __CV_V_INT64& a); + +/** Cleanup **/ +#undef CV__SIMD_FORWARD +#undef __CV_VX +#undef __CV_V_UINT8 +#undef __CV_V_INT8 +#undef __CV_V_UINT16 +#undef __CV_V_INT16 +#undef __CV_V_UINT32 +#undef __CV_V_INT32 +#undef __CV_V_UINT64 +#undef __CV_V_INT64 +#undef __CV_V_FLOAT32 +#undef __CV_V_FLOAT64 + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} // cv:: \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_msa.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_msa.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0db137b03209701d5bc874385407ae10b3df6527 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_msa.hpp @@ -0,0 +1,1856 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_HAL_INTRIN_MSA_HPP +#define OPENCV_HAL_INTRIN_MSA_HPP + +#include +#include "opencv2/core/utility.hpp" + +namespace cv +{ + +//! @cond IGNORED +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#define CV_SIMD128 1 + +//MSA implements 128-bit wide vector registers shared with the 64-bit wide floating-point unit registers. +//MSA and FPU can not be both present, unless the FPU has 64-bit floating-point registers. +#define CV_SIMD128_64F 1 + +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + + v_uint8x16() : val(msa_dupq_n_u8(0)) {} + explicit v_uint8x16(v16u8 v) : val(v) {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = msa_ld1q_u8(v); + } + uchar get0() const + { + return msa_getq_lane_u8(val, 0); + } + + v16u8 val; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + + v_int8x16() : val(msa_dupq_n_s8(0)) {} + explicit v_int8x16(v16i8 v) : val(v) {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = msa_ld1q_s8(v); + } + schar get0() const + { + return msa_getq_lane_s8(val, 0); + } + + v16i8 val; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + + v_uint16x8() : val(msa_dupq_n_u16(0)) {} + explicit v_uint16x8(v8u16 v) : val(v) {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = msa_ld1q_u16(v); + } + ushort get0() const + { + return msa_getq_lane_u16(val, 0); + } + + v8u16 val; +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + + v_int16x8() : val(msa_dupq_n_s16(0)) {} + explicit v_int16x8(v8i16 v) : val(v) {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + short v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = msa_ld1q_s16(v); + } + short get0() const + { + return msa_getq_lane_s16(val, 0); + } + + v8i16 val; +}; + +struct v_uint32x4 +{ + typedef unsigned int lane_type; + enum { nlanes = 4 }; + + v_uint32x4() : val(msa_dupq_n_u32(0)) {} + explicit v_uint32x4(v4u32 v) : val(v) {} + v_uint32x4(unsigned int v0, unsigned int v1, unsigned int v2, unsigned int v3) + { + unsigned int v[] = {v0, v1, v2, v3}; + val = msa_ld1q_u32(v); + } + unsigned int get0() const + { + return msa_getq_lane_u32(val, 0); + } + + v4u32 val; +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + + v_int32x4() : val(msa_dupq_n_s32(0)) {} + explicit v_int32x4(v4i32 v) : val(v) {} + v_int32x4(int v0, int v1, int v2, int v3) + { + int v[] = {v0, v1, v2, v3}; + val = msa_ld1q_s32(v); + } + int get0() const + { + return msa_getq_lane_s32(val, 0); + } + v4i32 val; +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + + v_float32x4() : val(msa_dupq_n_f32(0.0f)) {} + explicit v_float32x4(v4f32 v) : val(v) {} + v_float32x4(float v0, float v1, float v2, float v3) + { + float v[] = {v0, v1, v2, v3}; + val = msa_ld1q_f32(v); + } + float get0() const + { + return msa_getq_lane_f32(val, 0); + } + v4f32 val; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + + v_uint64x2() : val(msa_dupq_n_u64(0)) {} + explicit v_uint64x2(v2u64 v) : val(v) {} + v_uint64x2(uint64 v0, uint64 v1) + { + uint64 v[] = {v0, v1}; + val = msa_ld1q_u64(v); + } + uint64 get0() const + { + return msa_getq_lane_u64(val, 0); + } + v2u64 val; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + + v_int64x2() : val(msa_dupq_n_s64(0)) {} + explicit v_int64x2(v2i64 v) : val(v) {} + v_int64x2(int64 v0, int64 v1) + { + int64 v[] = {v0, v1}; + val = msa_ld1q_s64(v); + } + int64 get0() const + { + return msa_getq_lane_s64(val, 0); + } + v2i64 val; +}; + +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + + v_float64x2() : val(msa_dupq_n_f64(0.0f)) {} + explicit v_float64x2(v2f64 v) : val(v) {} + v_float64x2(double v0, double v1) + { + double v[] = {v0, v1}; + val = msa_ld1q_f64(v); + } + double get0() const + { + return msa_getq_lane_f64(val, 0); + } + v2f64 val; +}; + +#define OPENCV_HAL_IMPL_MSA_INIT(_Tpv, _Tp, suffix) \ +inline v_##_Tpv v_setzero_##suffix() { return v_##_Tpv(msa_dupq_n_##suffix((_Tp)0)); } \ +inline v_##_Tpv v_setall_##suffix(_Tp v) { return v_##_Tpv(msa_dupq_n_##suffix(v)); } \ +inline v_uint8x16 v_reinterpret_as_u8(const v_##_Tpv& v) { return v_uint8x16(MSA_TPV_REINTERPRET(v16u8, v.val)); } \ +inline v_int8x16 v_reinterpret_as_s8(const v_##_Tpv& v) { return v_int8x16(MSA_TPV_REINTERPRET(v16i8, v.val)); } \ +inline v_uint16x8 v_reinterpret_as_u16(const v_##_Tpv& v) { return v_uint16x8(MSA_TPV_REINTERPRET(v8u16, v.val)); } \ +inline v_int16x8 v_reinterpret_as_s16(const v_##_Tpv& v) { return v_int16x8(MSA_TPV_REINTERPRET(v8i16, v.val)); } \ +inline v_uint32x4 v_reinterpret_as_u32(const v_##_Tpv& v) { return v_uint32x4(MSA_TPV_REINTERPRET(v4u32, v.val)); } \ +inline v_int32x4 v_reinterpret_as_s32(const v_##_Tpv& v) { return v_int32x4(MSA_TPV_REINTERPRET(v4i32, v.val)); } \ +inline v_uint64x2 v_reinterpret_as_u64(const v_##_Tpv& v) { return v_uint64x2(MSA_TPV_REINTERPRET(v2u64, v.val)); } \ +inline v_int64x2 v_reinterpret_as_s64(const v_##_Tpv& v) { return v_int64x2(MSA_TPV_REINTERPRET(v2i64, v.val)); } \ +inline v_float32x4 v_reinterpret_as_f32(const v_##_Tpv& v) { return v_float32x4(MSA_TPV_REINTERPRET(v4f32, v.val)); } \ +inline v_float64x2 v_reinterpret_as_f64(const v_##_Tpv& v) { return v_float64x2(MSA_TPV_REINTERPRET(v2f64, v.val)); } + +OPENCV_HAL_IMPL_MSA_INIT(uint8x16, uchar, u8) +OPENCV_HAL_IMPL_MSA_INIT(int8x16, schar, s8) +OPENCV_HAL_IMPL_MSA_INIT(uint16x8, ushort, u16) +OPENCV_HAL_IMPL_MSA_INIT(int16x8, short, s16) +OPENCV_HAL_IMPL_MSA_INIT(uint32x4, unsigned int, u32) +OPENCV_HAL_IMPL_MSA_INIT(int32x4, int, s32) +OPENCV_HAL_IMPL_MSA_INIT(uint64x2, uint64, u64) +OPENCV_HAL_IMPL_MSA_INIT(int64x2, int64, s64) +OPENCV_HAL_IMPL_MSA_INIT(float32x4, float, f32) +OPENCV_HAL_IMPL_MSA_INIT(float64x2, double, f64) + +#define OPENCV_HAL_IMPL_MSA_PACK(_Tpvec, _Tpwvec, pack, mov, rshr) \ +inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + return _Tpvec(mov(a.val, b.val)); \ +} \ +template inline \ +_Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + return _Tpvec(rshr(a.val, b.val, n)); \ +} + +OPENCV_HAL_IMPL_MSA_PACK(v_uint8x16, v_uint16x8, pack, msa_qpack_u16, msa_qrpackr_u16) +OPENCV_HAL_IMPL_MSA_PACK(v_int8x16, v_int16x8, pack, msa_qpack_s16, msa_qrpackr_s16) +OPENCV_HAL_IMPL_MSA_PACK(v_uint16x8, v_uint32x4, pack, msa_qpack_u32, msa_qrpackr_u32) +OPENCV_HAL_IMPL_MSA_PACK(v_int16x8, v_int32x4, pack, msa_qpack_s32, msa_qrpackr_s32) +OPENCV_HAL_IMPL_MSA_PACK(v_uint32x4, v_uint64x2, pack, msa_pack_u64, msa_rpackr_u64) +OPENCV_HAL_IMPL_MSA_PACK(v_int32x4, v_int64x2, pack, msa_pack_s64, msa_rpackr_s64) +OPENCV_HAL_IMPL_MSA_PACK(v_uint8x16, v_int16x8, pack_u, msa_qpacku_s16, msa_qrpackru_s16) +OPENCV_HAL_IMPL_MSA_PACK(v_uint16x8, v_int32x4, pack_u, msa_qpacku_s32, msa_qrpackru_s32) + +#define OPENCV_HAL_IMPL_MSA_PACK_STORE(_Tpvec, _Tp, hreg, suffix, _Tpwvec, pack, mov, rshr) \ +inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + hreg a1 = mov(a.val); \ + msa_st1_##suffix(ptr, a1); \ +} \ +template inline \ +void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + hreg a1 = rshr(a.val, n); \ + msa_st1_##suffix(ptr, a1); \ +} + +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint8x16, uchar, v8u8, u8, v_uint16x8, pack, msa_qmovn_u16, msa_qrshrn_n_u16) +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_int8x16, schar, v8i8, s8, v_int16x8, pack, msa_qmovn_s16, msa_qrshrn_n_s16) +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint16x8, ushort, v4u16, u16, v_uint32x4, pack, msa_qmovn_u32, msa_qrshrn_n_u32) +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_int16x8, short, v4i16, s16, v_int32x4, pack, msa_qmovn_s32, msa_qrshrn_n_s32) +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint32x4, unsigned, v2u32, u32, v_uint64x2, pack, msa_movn_u64, msa_rshrn_n_u64) +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_int32x4, int, v2i32, s32, v_int64x2, pack, msa_movn_s64, msa_rshrn_n_s64) +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint8x16, uchar, v8u8, u8, v_int16x8, pack_u, msa_qmovun_s16, msa_qrshrun_n_s16) +OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint16x8, ushort, v4u16, u16, v_int32x4, pack_u, msa_qmovun_s32, msa_qrshrun_n_s32) + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + return v_uint8x16(msa_pack_u16(a.val, b.val)); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + return v_uint8x16(msa_pack_u16(msa_pack_u32(a.val, b.val), msa_pack_u32(c.val, d.val))); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + v8u16 abcd = msa_pack_u32(msa_pack_u64(a.val, b.val), msa_pack_u64(c.val, d.val)); + v8u16 efgh = msa_pack_u32(msa_pack_u64(e.val, f.val), msa_pack_u64(g.val, h.val)); + return v_uint8x16(msa_pack_u16(abcd, efgh)); +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + v4f32 v0 = v.val; + v4f32 res = msa_mulq_lane_f32(m0.val, v0, 0); + res = msa_mlaq_lane_f32(res, m1.val, v0, 1); + res = msa_mlaq_lane_f32(res, m2.val, v0, 2); + res = msa_mlaq_lane_f32(res, m3.val, v0, 3); + return v_float32x4(res); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + v4f32 v0 = v.val; + v4f32 res = msa_mulq_lane_f32(m0.val, v0, 0); + res = msa_mlaq_lane_f32(res, m1.val, v0, 1); + res = msa_mlaq_lane_f32(res, m2.val, v0, 2); + res = msa_addq_f32(res, a.val); + return v_float32x4(res); +} + +#define OPENCV_HAL_IMPL_MSA_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + a.val = intrin(a.val, b.val); \ + return a; \ +} + +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint8x16, msa_qaddq_u8) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint8x16, msa_qsubq_u8) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int8x16, msa_qaddq_s8) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int8x16, msa_qsubq_s8) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint16x8, msa_qaddq_u16) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint16x8, msa_qsubq_u16) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int16x8, msa_qaddq_s16) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int16x8, msa_qsubq_s16) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int32x4, msa_addq_s32) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int32x4, msa_subq_s32) +OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_int32x4, msa_mulq_s32) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint32x4, msa_addq_u32) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint32x4, msa_subq_u32) +OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_uint32x4, msa_mulq_u32) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_float32x4, msa_addq_f32) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_float32x4, msa_subq_f32) +OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_float32x4, msa_mulq_f32) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int64x2, msa_addq_s64) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int64x2, msa_subq_s64) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint64x2, msa_addq_u64) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint64x2, msa_subq_u64) +OPENCV_HAL_IMPL_MSA_BIN_OP(/, v_float32x4, msa_divq_f32) +OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_float64x2, msa_addq_f64) +OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_float64x2, msa_subq_f64) +OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_float64x2, msa_mulq_f64) +OPENCV_HAL_IMPL_MSA_BIN_OP(/, v_float64x2, msa_divq_f64) + +// saturating multiply 8-bit, 16-bit +#define OPENCV_HAL_IMPL_MSA_MUL_SAT(_Tpvec, _Tpwvec) \ +inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ +} \ +inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ +{a = a * b; return a; } + +OPENCV_HAL_IMPL_MSA_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_MSA_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_MSA_MUL_SAT(v_int16x8, v_int32x4) +OPENCV_HAL_IMPL_MSA_MUL_SAT(v_uint16x8, v_uint32x4) + +// Multiply and expand +inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, + v_int16x8& c, v_int16x8& d) +{ + v16i8 a_lo, a_hi, b_lo, b_hi; + + ILVRL_B2_SB(a.val, msa_dupq_n_s8(0), a_lo, a_hi); + ILVRL_B2_SB(b.val, msa_dupq_n_s8(0), b_lo, b_hi); + c.val = msa_mulq_s16(msa_paddlq_s8(a_lo), msa_paddlq_s8(b_lo)); + d.val = msa_mulq_s16(msa_paddlq_s8(a_hi), msa_paddlq_s8(b_hi)); +} + +inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, + v_uint16x8& c, v_uint16x8& d) +{ + v16u8 a_lo, a_hi, b_lo, b_hi; + + ILVRL_B2_UB(a.val, msa_dupq_n_u8(0), a_lo, a_hi); + ILVRL_B2_UB(b.val, msa_dupq_n_u8(0), b_lo, b_hi); + c.val = msa_mulq_u16(msa_paddlq_u8(a_lo), msa_paddlq_u8(b_lo)); + d.val = msa_mulq_u16(msa_paddlq_u8(a_hi), msa_paddlq_u8(b_hi)); +} + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, + v_int32x4& c, v_int32x4& d) +{ + v8i16 a_lo, a_hi, b_lo, b_hi; + + ILVRL_H2_SH(a.val, msa_dupq_n_s16(0), a_lo, a_hi); + ILVRL_H2_SH(b.val, msa_dupq_n_s16(0), b_lo, b_hi); + c.val = msa_mulq_s32(msa_paddlq_s16(a_lo), msa_paddlq_s16(b_lo)); + d.val = msa_mulq_s32(msa_paddlq_s16(a_hi), msa_paddlq_s16(b_hi)); +} + +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, + v_uint32x4& c, v_uint32x4& d) +{ + v8u16 a_lo, a_hi, b_lo, b_hi; + + ILVRL_H2_UH(a.val, msa_dupq_n_u16(0), a_lo, a_hi); + ILVRL_H2_UH(b.val, msa_dupq_n_u16(0), b_lo, b_hi); + c.val = msa_mulq_u32(msa_paddlq_u16(a_lo), msa_paddlq_u16(b_lo)); + d.val = msa_mulq_u32(msa_paddlq_u16(a_hi), msa_paddlq_u16(b_hi)); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, + v_uint64x2& c, v_uint64x2& d) +{ + v4u32 a_lo, a_hi, b_lo, b_hi; + + ILVRL_W2_UW(a.val, msa_dupq_n_u32(0), a_lo, a_hi); + ILVRL_W2_UW(b.val, msa_dupq_n_u32(0), b_lo, b_hi); + c.val = msa_mulq_u64(msa_paddlq_u32(a_lo), msa_paddlq_u32(b_lo)); + d.val = msa_mulq_u64(msa_paddlq_u32(a_hi), msa_paddlq_u32(b_hi)); +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + v8i16 a_lo, a_hi, b_lo, b_hi; + + ILVRL_H2_SH(a.val, msa_dupq_n_s16(0), a_lo, a_hi); + ILVRL_H2_SH(b.val, msa_dupq_n_s16(0), b_lo, b_hi); + + return v_int16x8(msa_packr_s32(msa_mulq_s32(msa_paddlq_s16(a_lo), msa_paddlq_s16(b_lo)), + msa_mulq_s32(msa_paddlq_s16(a_hi), msa_paddlq_s16(b_hi)), 16)); +} + +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + v8u16 a_lo, a_hi, b_lo, b_hi; + + ILVRL_H2_UH(a.val, msa_dupq_n_u16(0), a_lo, a_hi); + ILVRL_H2_UH(b.val, msa_dupq_n_u16(0), b_lo, b_hi); + + return v_uint16x8(msa_packr_u32(msa_mulq_u32(msa_paddlq_u16(a_lo), msa_paddlq_u16(b_lo)), + msa_mulq_u32(msa_paddlq_u16(a_hi), msa_paddlq_u16(b_hi)), 16)); +} + +//////// Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ return v_int32x4(msa_dotp_s_w(a.val, b.val)); } +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_int32x4(msa_dpadd_s_w(c.val , a.val, b.val)); } + +// 32 >> 64 +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b) +{ return v_int64x2(msa_dotp_s_d(a.val, b.val)); } +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ return v_int64x2(msa_dpadd_s_d(c.val , a.val, b.val)); } + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b) +{ + v8u16 even_a = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8), 8); + v8u16 odd_a = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8); + v8u16 even_b = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8), 8); + v8u16 odd_b = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8); + v4u32 prod = msa_dotp_u_w(even_a, even_b); + return v_uint32x4(msa_dpadd_u_w(prod, odd_a, odd_b)); +} +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ + v8u16 even_a = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8), 8); + v8u16 odd_a = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8); + v8u16 even_b = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8), 8); + v8u16 odd_b = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8); + v4u32 prod = msa_dpadd_u_w(c.val, even_a, even_b); + return v_uint32x4(msa_dpadd_u_w(prod, odd_a, odd_b)); +} + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b) +{ + v8i16 prod = msa_dotp_s_h(a.val, b.val); + return v_int32x4(msa_hadd_s32(prod, prod)); +} +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b, + const v_int32x4& c) +{ return v_dotprod_expand(a, b) + c; } + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b) +{ + v4u32 even_a = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16), 16); + v4u32 odd_a = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16); + v4u32 even_b = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16), 16); + v4u32 odd_b = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16); + v2u64 prod = msa_dotp_u_d(even_a, even_b); + return v_uint64x2(msa_dpadd_u_d(prod, odd_a, odd_b)); +} +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, + const v_uint64x2& c) +{ + v4u32 even_a = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16), 16); + v4u32 odd_a = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16); + v4u32 even_b = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16), 16); + v4u32 odd_b = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16); + v2u64 prod = msa_dpadd_u_d(c.val, even_a, even_b); + return v_uint64x2(msa_dpadd_u_d(prod, odd_a, odd_b)); +} + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b) +{ + v4i32 prod = msa_dotp_s_w(a.val, b.val); + return v_int64x2(msa_hadd_s64(prod, prod)); +} +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +// 32 >> 64f +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand(a, b) + c; } + + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) +{ return v_dotprod(a, b); } +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_dotprod(a, b, c); } + +// 32 >> 64 +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_dotprod(a, b); } +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ return v_dotprod(a, b, c); } + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b) +{ return v_dotprod_expand(a, b); } +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ return v_dotprod_expand(a, b, c); } +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b) +{ return v_dotprod_expand(a, b); } +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ return v_dotprod_expand(a, b, c); } + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b) +{ return v_dotprod_expand(a, b); } +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand(a, b, c); } +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b) +{ return v_dotprod_expand(a, b); } +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand(a, b, c); } + +// 32 >> 64f +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_dotprod_expand(a, b); } +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand(a, b, c); } + +#define OPENCV_HAL_IMPL_MSA_LOGIC_OP(_Tpvec, _Tpv, suffix) \ +OPENCV_HAL_IMPL_MSA_BIN_OP(&, _Tpvec, msa_andq_##suffix) \ +OPENCV_HAL_IMPL_MSA_BIN_OP(|, _Tpvec, msa_orrq_##suffix) \ +OPENCV_HAL_IMPL_MSA_BIN_OP(^, _Tpvec, msa_eorq_##suffix) \ +inline _Tpvec operator ~ (const _Tpvec& a) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_mvnq_u8(MSA_TPV_REINTERPRET(v16u8, a.val)))); \ +} + +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint8x16, v16u8, u8) +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int8x16, v16i8, s8) +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint16x8, v8u16, u16) +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int16x8, v8i16, s16) +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint32x4, v4u32, u32) +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int32x4, v4i32, s32) +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint64x2, v2u64, u64) +OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int64x2, v2i64, s64) + +#define OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(bin_op, intrin) \ +inline v_float32x4 operator bin_op (const v_float32x4& a, const v_float32x4& b) \ +{ \ + return v_float32x4(MSA_TPV_REINTERPRET(v4f32, intrin(MSA_TPV_REINTERPRET(v4i32, a.val), MSA_TPV_REINTERPRET(v4i32, b.val)))); \ +} \ +inline v_float32x4& operator bin_op##= (v_float32x4& a, const v_float32x4& b) \ +{ \ + a.val = MSA_TPV_REINTERPRET(v4f32, intrin(MSA_TPV_REINTERPRET(v4i32, a.val), MSA_TPV_REINTERPRET(v4i32, b.val))); \ + return a; \ +} + +OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(&, msa_andq_s32) +OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(|, msa_orrq_s32) +OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(^, msa_eorq_s32) + +inline v_float32x4 operator ~ (const v_float32x4& a) +{ + return v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_mvnq_s32(MSA_TPV_REINTERPRET(v4i32, a.val)))); +} + +/* v_abs */ +#define OPENCV_HAL_IMPL_MSA_ABS(_Tpuvec, _Tpsvec, usuffix, ssuffix) \ +inline _Tpuvec v_abs(const _Tpsvec& a) \ +{ \ + return v_reinterpret_as_##usuffix(_Tpsvec(msa_absq_##ssuffix(a.val))); \ +} + +OPENCV_HAL_IMPL_MSA_ABS(v_uint8x16, v_int8x16, u8, s8) +OPENCV_HAL_IMPL_MSA_ABS(v_uint16x8, v_int16x8, u16, s16) +OPENCV_HAL_IMPL_MSA_ABS(v_uint32x4, v_int32x4, u32, s32) + +/* v_abs(float), v_sqrt, v_invsqrt */ +#define OPENCV_HAL_IMPL_MSA_BASIC_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a) \ +{ \ + return _Tpvec(intrin(a.val)); \ +} + +OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float32x4, v_abs, msa_absq_f32) +OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float64x2, v_abs, msa_absq_f64) +OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float32x4, v_sqrt, msa_sqrtq_f32) +OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float32x4, v_invsqrt, msa_rsqrtq_f32) +OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float64x2, v_sqrt, msa_sqrtq_f64) +OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float64x2, v_invsqrt, msa_rsqrtq_f64) + +#define OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(bin_op, intrin) \ +inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \ +{ \ + return v_float64x2(MSA_TPV_REINTERPRET(v2f64, intrin(MSA_TPV_REINTERPRET(v2i64, a.val), MSA_TPV_REINTERPRET(v2i64, b.val)))); \ +} \ +inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \ +{ \ + a.val = MSA_TPV_REINTERPRET(v2f64, intrin(MSA_TPV_REINTERPRET(v2i64, a.val), MSA_TPV_REINTERPRET(v2i64, b.val))); \ + return a; \ +} + +OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(&, msa_andq_s64) +OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(|, msa_orrq_s64) +OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(^, msa_eorq_s64) + +inline v_float64x2 operator ~ (const v_float64x2& a) +{ + return v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_mvnq_s32(MSA_TPV_REINTERPRET(v4i32, a.val)))); +} + +// TODO: exp, log, sin, cos + +#define OPENCV_HAL_IMPL_MSA_BIN_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_min, msa_minq_u8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_max, msa_maxq_u8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_min, msa_minq_s8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_max, msa_maxq_s8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_min, msa_minq_u16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_max, msa_maxq_u16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_min, msa_minq_s16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_max, msa_maxq_s16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint32x4, v_min, msa_minq_u32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint32x4, v_max, msa_maxq_u32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int32x4, v_min, msa_minq_s32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int32x4, v_max, msa_maxq_s32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float32x4, v_min, msa_minq_f32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float32x4, v_max, msa_maxq_f32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float64x2, v_min, msa_minq_f64) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float64x2, v_max, msa_maxq_f64) + +#define OPENCV_HAL_IMPL_MSA_INT_CMP_OP(_Tpvec, _Tpv, suffix, not_suffix) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_ceqq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_mvnq_##not_suffix(msa_ceqq_##suffix(a.val, b.val)))); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cltq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cgtq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cleq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cgeq_##suffix(a.val, b.val))); } + +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint8x16, v16u8, u8, u8) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int8x16, v16i8, s8, u8) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint16x8, v8u16, u16, u16) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int16x8, v8i16, s16, u16) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint32x4, v4u32, u32, u32) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int32x4, v4i32, s32, u32) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_float32x4, v4f32, f32, u32) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint64x2, v2u64, u64, u64) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int64x2, v2i64, s64, u64) +OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_float64x2, v2f64, f64, u64) + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ceqq_f32(a.val, a.val))); } +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_ceqq_f64(a.val, a.val))); } + +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_add_wrap, msa_addq_u8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_add_wrap, msa_addq_s8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_add_wrap, msa_addq_u16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_add_wrap, msa_addq_s16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_sub_wrap, msa_subq_u8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_sub_wrap, msa_subq_s8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_sub_wrap, msa_subq_u16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_sub_wrap, msa_subq_s16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_mul_wrap, msa_mulq_u8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_mul_wrap, msa_mulq_s8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_mul_wrap, msa_mulq_u16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_mul_wrap, msa_mulq_s16) + +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_absdiff, msa_abdq_u8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_absdiff, msa_abdq_u16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint32x4, v_absdiff, msa_abdq_u32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float32x4, v_absdiff, msa_abdq_f32) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float64x2, v_absdiff, msa_abdq_f64) + +/** Saturating absolute difference **/ +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_absdiffs, msa_qabdq_s8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_absdiffs, msa_qabdq_s16) + +#define OPENCV_HAL_IMPL_MSA_BIN_FUNC2(_Tpvec, _Tpvec2, _Tpv, func, intrin) \ +inline _Tpvec2 func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec2(MSA_TPV_REINTERPRET(_Tpv, intrin(a.val, b.val))); \ +} + +OPENCV_HAL_IMPL_MSA_BIN_FUNC2(v_int8x16, v_uint8x16, v16u8, v_absdiff, msa_abdq_s8) +OPENCV_HAL_IMPL_MSA_BIN_FUNC2(v_int16x8, v_uint16x8, v8u16, v_absdiff, msa_abdq_s16) +OPENCV_HAL_IMPL_MSA_BIN_FUNC2(v_int32x4, v_uint32x4, v4u32, v_absdiff, msa_abdq_s32) + +/* v_magnitude, v_sqr_magnitude, v_fma, v_muladd */ +inline v_float32x4 v_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + v_float32x4 x(msa_mlaq_f32(msa_mulq_f32(a.val, a.val), b.val, b.val)); + return v_sqrt(x); +} + +inline v_float32x4 v_sqr_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + return v_float32x4(msa_mlaq_f32(msa_mulq_f32(a.val, a.val), b.val, b.val)); +} + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return v_float32x4(msa_mlaq_f32(c.val, a.val, b.val)); +} + +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_int32x4(msa_mlaq_s32(c.val, a.val, b.val)); +} + +inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 x(msa_mlaq_f64(msa_mulq_f64(a.val, a.val), b.val, b.val)); + return v_sqrt(x); +} + +inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + return v_float64x2(msa_mlaq_f64(msa_mulq_f64(a.val, a.val), b.val, b.val)); +} + +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_float64x2(msa_mlaq_f64(c.val, a.val, b.val)); +} + +inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_fma(a, b, c); +} + +// trade efficiency for convenience +#define OPENCV_HAL_IMPL_MSA_SHIFT_OP(_Tpvec, suffix, _Tps, ssuffix) \ +inline _Tpvec operator << (const _Tpvec& a, int n) \ +{ return _Tpvec(msa_shlq_##suffix(a.val, msa_dupq_n_##ssuffix((_Tps)n))); } \ +inline _Tpvec operator >> (const _Tpvec& a, int n) \ +{ return _Tpvec(msa_shrq_##suffix(a.val, msa_dupq_n_##ssuffix((_Tps)n))); } \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ return _Tpvec(msa_shlq_n_##suffix(a.val, n)); } \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ return _Tpvec(msa_shrq_n_##suffix(a.val, n)); } \ +template inline _Tpvec v_rshr(const _Tpvec& a) \ +{ return _Tpvec(msa_rshrq_n_##suffix(a.val, n)); } + +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint8x16, u8, schar, s8) +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int8x16, s8, schar, s8) +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint16x8, u16, short, s16) +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int16x8, s16, short, s16) +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint32x4, u32, int, s32) +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int32x4, s32, int, s32) +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint64x2, u64, int64, s64) +OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int64x2, s64, int64, s64) + +/* v_rotate_right, v_rotate_left */ +#define OPENCV_HAL_IMPL_MSA_ROTATE_OP(_Tpvec, _Tpv, _Tpvs, suffix) \ +template inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##suffix(0), n))); \ +} \ +template inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(msa_dupq_n_##suffix(0), MSA_TPV_REINTERPRET(_Tpvs, a.val), _Tpvec::nlanes - n))); \ +} \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a) \ +{ \ + return a; \ +} \ +template inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), MSA_TPV_REINTERPRET(_Tpvs, b.val), n))); \ +} \ +template inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, b.val), MSA_TPV_REINTERPRET(_Tpvs, a.val), _Tpvec::nlanes - n))); \ +} \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a, const _Tpvec& b) \ +{ \ + CV_UNUSED(b); \ + return a; \ +} + +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint8x16, v16u8, v16i8, s8) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int8x16, v16i8, v16i8, s8) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint16x8, v8u16, v8i16, s16) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int16x8, v8i16, v8i16, s16) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint32x4, v4u32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int32x4, v4i32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_float32x4, v4f32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint64x2, v2u64, v2i64, s64) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int64x2, v2i64, v2i64, s64) +OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_float64x2, v2f64, v2i64, s64) + +#define OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(msa_ld1q_##suffix(ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(msa_ld1q_##suffix(ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(msa_combine_##suffix(msa_ld1_##suffix(ptr), msa_dup_n_##suffix((_Tp)0))); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ return _Tpvec(msa_combine_##suffix(msa_ld1_##suffix(ptr0), msa_ld1_##suffix(ptr1))); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ msa_st1q_##suffix(ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ msa_st1q_##suffix(ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ msa_st1q_##suffix(ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \ +{ msa_st1q_##suffix(ptr, a.val); } \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ \ + int n = _Tpvec::nlanes; \ + for( int i = 0; i < (n/2); i++ ) \ + ptr[i] = a.val[i]; \ +} \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ \ + int n = _Tpvec::nlanes; \ + for( int i = 0; i < (n/2); i++ ) \ + ptr[i] = a.val[i+(n/2)]; \ +} + +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int16x8, short, s16) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int32x4, int, s32) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_float32x4, float, f32) +OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_float64x2, double, f64) + + +/** Reverse **/ +inline v_uint8x16 v_reverse(const v_uint8x16 &a) +{ + v_uint8x16 c = v_uint8x16((v16u8)__builtin_msa_vshf_b((v16i8)((v2i64){0x08090A0B0C0D0E0F, 0x0001020304050607}), msa_dupq_n_s8(0), (v16i8)a.val)); + return c; +} + +inline v_int8x16 v_reverse(const v_int8x16 &a) +{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); } + +inline v_uint16x8 v_reverse(const v_uint16x8 &a) +{ + v_uint16x8 c = v_uint16x8((v8u16)__builtin_msa_vshf_h((v8i16)((v2i64){0x0004000500060007, 0x0000000100020003}), msa_dupq_n_s16(0), (v8i16)a.val)); + return c; +} + +inline v_int16x8 v_reverse(const v_int16x8 &a) +{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); } + +inline v_uint32x4 v_reverse(const v_uint32x4 &a) +{ + v_uint32x4 c; + c.val[0] = a.val[3]; + c.val[1] = a.val[2]; + c.val[2] = a.val[1]; + c.val[3] = a.val[0]; + return c; +} + +inline v_int32x4 v_reverse(const v_int32x4 &a) +{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_float32x4 v_reverse(const v_float32x4 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x2 v_reverse(const v_uint64x2 &a) +{ + v_uint64x2 c; + c.val[0] = a.val[1]; + c.val[1] = a.val[0]; + return c; +} + +inline v_int64x2 v_reverse(const v_int64x2 &a) +{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); } + +inline v_float64x2 v_reverse(const v_float64x2 &a) +{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); } + + +#define OPENCV_HAL_IMPL_MSA_REDUCE_OP_8U(func, cfunc) \ +inline unsigned short v_reduce_##func(const v_uint16x8& a) \ +{ \ + v8u16 a_lo, a_hi; \ + ILVRL_H2_UH(a.val, msa_dupq_n_u16(0), a_lo, a_hi); \ + v4u32 b = msa_##func##q_u32(msa_paddlq_u16(a_lo), msa_paddlq_u16(a_hi)); \ + v4u32 b_lo, b_hi; \ + ILVRL_W2_UW(b, msa_dupq_n_u32(0), b_lo, b_hi); \ + v2u64 c = msa_##func##q_u64(msa_paddlq_u32(b_lo), msa_paddlq_u32(b_hi)); \ + return (unsigned short)cfunc(c[0], c[1]); \ +} + +OPENCV_HAL_IMPL_MSA_REDUCE_OP_8U(max, std::max) +OPENCV_HAL_IMPL_MSA_REDUCE_OP_8U(min, std::min) + +#define OPENCV_HAL_IMPL_MSA_REDUCE_OP_8S(func, cfunc) \ +inline short v_reduce_##func(const v_int16x8& a) \ +{ \ + v8i16 a_lo, a_hi; \ + ILVRL_H2_SH(a.val, msa_dupq_n_s16(0), a_lo, a_hi); \ + v4i32 b = msa_##func##q_s32(msa_paddlq_s16(a_lo), msa_paddlq_s16(a_hi)); \ + v4i32 b_lo, b_hi; \ + ILVRL_W2_SW(b, msa_dupq_n_s32(0), b_lo, b_hi); \ + v2i64 c = msa_##func##q_s64(msa_paddlq_s32(b_lo), msa_paddlq_s32(b_hi)); \ + return (short)cfunc(c[0], c[1]); \ +} + +OPENCV_HAL_IMPL_MSA_REDUCE_OP_8S(max, std::max) +OPENCV_HAL_IMPL_MSA_REDUCE_OP_8S(min, std::min) + +#define OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(_Tpvec, scalartype, func, cfunc) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + return (scalartype)cfunc(cfunc(a.val[0], a.val[1]), cfunc(a.val[2], a.val[3])); \ +} + +OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max) +OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min) +OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_int32x4, int, max, std::max) +OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_int32x4, int, min, std::min) +OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_float32x4, float, max, std::max) +OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_float32x4, float, min, std::min) + +#define OPENCV_HAL_IMPL_MSA_REDUCE_SUM(_Tpvec, scalartype, suffix) \ +inline scalartype v_reduce_sum(const _Tpvec& a) \ +{ \ + return (scalartype)msa_sum_##suffix(a.val); \ +} + +OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_uint8x16, unsigned char, u8) +OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_int8x16, char, s8) +OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_uint16x8, unsigned short, u16) +OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_int16x8, short, s16) +OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_int32x4, int, s32) +OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_float32x4, float, f32) + +inline uint64 v_reduce_sum(const v_uint64x2& a) +{ return (uint64)(msa_getq_lane_u64(a.val, 0) + msa_getq_lane_u64(a.val, 1)); } +inline int64 v_reduce_sum(const v_int64x2& a) +{ return (int64)(msa_getq_lane_s64(a.val, 0) + msa_getq_lane_s64(a.val, 1)); } +inline double v_reduce_sum(const v_float64x2& a) +{ + return msa_getq_lane_f64(a.val, 0) + msa_getq_lane_f64(a.val, 1); +} + +/* v_reduce_sum4, v_reduce_sad */ +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + v4f32 u0 = msa_addq_f32(MSA_TPV_REINTERPRET(v4f32, msa_ilvevq_s32(MSA_TPV_REINTERPRET(v4i32, b.val), MSA_TPV_REINTERPRET(v4i32, a.val))), + MSA_TPV_REINTERPRET(v4f32, msa_ilvodq_s32(MSA_TPV_REINTERPRET(v4i32, b.val), MSA_TPV_REINTERPRET(v4i32, a.val)))); // a0+a1 b0+b1 a2+a3 b2+b3 + v4f32 u1 = msa_addq_f32(MSA_TPV_REINTERPRET(v4f32, msa_ilvevq_s32(MSA_TPV_REINTERPRET(v4i32, d.val), MSA_TPV_REINTERPRET(v4i32, c.val))), + MSA_TPV_REINTERPRET(v4f32, msa_ilvodq_s32(MSA_TPV_REINTERPRET(v4i32, d.val), MSA_TPV_REINTERPRET(v4i32, c.val)))); // c0+c1 d0+d1 c2+c3 d2+d3 + + return v_float32x4(msa_addq_f32(MSA_TPV_REINTERPRET(v4f32, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, u1), MSA_TPV_REINTERPRET(v2i64, u0))), + MSA_TPV_REINTERPRET(v4f32, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, u1), MSA_TPV_REINTERPRET(v2i64, u0))))); +} + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + v16u8 t0 = msa_abdq_u8(a.val, b.val); + v8u16 t1 = msa_paddlq_u8(t0); + v4u32 t2 = msa_paddlq_u16(t1); + return msa_sum_u32(t2); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + v16u8 t0 = MSA_TPV_REINTERPRET(v16u8, msa_abdq_s8(a.val, b.val)); + v8u16 t1 = msa_paddlq_u8(t0); + v4u32 t2 = msa_paddlq_u16(t1); + return msa_sum_u32(t2); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + v8u16 t0 = msa_abdq_u16(a.val, b.val); + v4u32 t1 = msa_paddlq_u16(t0); + return msa_sum_u32(t1); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + v8u16 t0 = MSA_TPV_REINTERPRET(v8u16, msa_abdq_s16(a.val, b.val)); + v4u32 t1 = msa_paddlq_u16(t0); + return msa_sum_u32(t1); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + v4u32 t0 = msa_abdq_u32(a.val, b.val); + return msa_sum_u32(t0); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + v4u32 t0 = MSA_TPV_REINTERPRET(v4u32, msa_abdq_s32(a.val, b.val)); + return msa_sum_u32(t0); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + v4f32 t0 = msa_abdq_f32(a.val, b.val); + return msa_sum_f32(t0); +} + +/* v_popcount */ +#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE8(_Tpvec) \ +inline v_uint8x16 v_popcount(const _Tpvec& a) \ +{ \ + v16u8 t = MSA_TPV_REINTERPRET(v16u8, msa_cntq_s8(MSA_TPV_REINTERPRET(v16i8, a.val))); \ + return v_uint8x16(t); \ +} +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE8(v_uint8x16) +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE8(v_int8x16) + +#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE16(_Tpvec) \ +inline v_uint16x8 v_popcount(const _Tpvec& a) \ +{ \ + v8u16 t = MSA_TPV_REINTERPRET(v8u16, msa_cntq_s16(MSA_TPV_REINTERPRET(v8i16, a.val))); \ + return v_uint16x8(t); \ +} +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE16(v_uint16x8) +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE16(v_int16x8) + +#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE32(_Tpvec) \ +inline v_uint32x4 v_popcount(const _Tpvec& a) \ +{ \ + v4u32 t = MSA_TPV_REINTERPRET(v4u32, msa_cntq_s32(MSA_TPV_REINTERPRET(v4i32, a.val))); \ + return v_uint32x4(t); \ +} +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE32(v_uint32x4) +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE32(v_int32x4) + +#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE64(_Tpvec) \ +inline v_uint64x2 v_popcount(const _Tpvec& a) \ +{ \ + v2u64 t = MSA_TPV_REINTERPRET(v2u64, msa_cntq_s64(MSA_TPV_REINTERPRET(v2i64, a.val))); \ + return v_uint64x2(t); \ +} +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE64(v_uint64x2) +OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE64(v_int64x2) + +inline int v_signmask(const v_uint8x16& a) +{ + v8i8 m0 = msa_create_s8(CV_BIG_UINT(0x0706050403020100)); + v16u8 v0 = msa_shlq_u8(msa_shrq_n_u8(a.val, 7), msa_combine_s8(m0, m0)); + v8u16 v1 = msa_paddlq_u8(v0); + v4u32 v2 = msa_paddlq_u16(v1); + v2u64 v3 = msa_paddlq_u32(v2); + return (int)msa_getq_lane_u64(v3, 0) + ((int)msa_getq_lane_u64(v3, 1) << 8); +} +inline int v_signmask(const v_int8x16& a) +{ return v_signmask(v_reinterpret_as_u8(a)); } + +inline int v_signmask(const v_uint16x8& a) +{ + v4i16 m0 = msa_create_s16(CV_BIG_UINT(0x0003000200010000)); + v8u16 v0 = msa_shlq_u16(msa_shrq_n_u16(a.val, 15), msa_combine_s16(m0, m0)); + v4u32 v1 = msa_paddlq_u16(v0); + v2u64 v2 = msa_paddlq_u32(v1); + return (int)msa_getq_lane_u64(v2, 0) + ((int)msa_getq_lane_u64(v2, 1) << 4); +} +inline int v_signmask(const v_int16x8& a) +{ return v_signmask(v_reinterpret_as_u16(a)); } + +inline int v_signmask(const v_uint32x4& a) +{ + v2i32 m0 = msa_create_s32(CV_BIG_UINT(0x0000000100000000)); + v4u32 v0 = msa_shlq_u32(msa_shrq_n_u32(a.val, 31), msa_combine_s32(m0, m0)); + v2u64 v1 = msa_paddlq_u32(v0); + return (int)msa_getq_lane_u64(v1, 0) + ((int)msa_getq_lane_u64(v1, 1) << 2); +} +inline int v_signmask(const v_int32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } +inline int v_signmask(const v_float32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } + +inline int v_signmask(const v_uint64x2& a) +{ + v2u64 v0 = msa_shrq_n_u64(a.val, 63); + return (int)msa_getq_lane_u64(v0, 0) + ((int)msa_getq_lane_u64(v0, 1) << 1); +} +inline int v_signmask(const v_int64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } + +inline int v_scan_forward(const v_int8x16& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint8x16& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int16x8& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint16x8& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_float32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int64x2& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(a)); } + +#define OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(_Tpvec, _Tpvec2, suffix, shift) \ +inline bool v_check_all(const v_##_Tpvec& a) \ +{ \ + _Tpvec2 v0 = msa_shrq_n_##suffix(msa_mvnq_##suffix(a.val), shift); \ + v2u64 v1 = MSA_TPV_REINTERPRET(v2u64, v0); \ + return (msa_getq_lane_u64(v1, 0) | msa_getq_lane_u64(v1, 1)) == 0; \ +} \ +inline bool v_check_any(const v_##_Tpvec& a) \ +{ \ + _Tpvec2 v0 = msa_shrq_n_##suffix(a.val, shift); \ + v2u64 v1 = MSA_TPV_REINTERPRET(v2u64, v0); \ + return (msa_getq_lane_u64(v1, 0) | msa_getq_lane_u64(v1, 1)) != 0; \ +} + +OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint8x16, v16u8, u8, 7) +OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint16x8, v8u16, u16, 15) +OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint32x4, v4u32, u32, 31) +OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint64x2, v2u64, u64, 63) + +inline bool v_check_all(const v_int8x16& a) +{ return v_check_all(v_reinterpret_as_u8(a)); } +inline bool v_check_all(const v_int16x8& a) +{ return v_check_all(v_reinterpret_as_u16(a)); } +inline bool v_check_all(const v_int32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } +inline bool v_check_all(const v_float32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } + +inline bool v_check_any(const v_int8x16& a) +{ return v_check_any(v_reinterpret_as_u8(a)); } +inline bool v_check_any(const v_int16x8& a) +{ return v_check_any(v_reinterpret_as_u16(a)); } +inline bool v_check_any(const v_int32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } +inline bool v_check_any(const v_float32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } + +inline bool v_check_all(const v_int64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_int64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } + +/* v_select */ +#define OPENCV_HAL_IMPL_MSA_SELECT(_Tpvec, _Tpv, _Tpvu) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_bslq_u8(MSA_TPV_REINTERPRET(_Tpvu, mask.val), \ + MSA_TPV_REINTERPRET(_Tpvu, b.val), MSA_TPV_REINTERPRET(_Tpvu, a.val)))); \ +} + +OPENCV_HAL_IMPL_MSA_SELECT(v_uint8x16, v16u8, v16u8) +OPENCV_HAL_IMPL_MSA_SELECT(v_int8x16, v16i8, v16u8) +OPENCV_HAL_IMPL_MSA_SELECT(v_uint16x8, v8u16, v16u8) +OPENCV_HAL_IMPL_MSA_SELECT(v_int16x8, v8i16, v16u8) +OPENCV_HAL_IMPL_MSA_SELECT(v_uint32x4, v4u32, v16u8) +OPENCV_HAL_IMPL_MSA_SELECT(v_int32x4, v4i32, v16u8) +OPENCV_HAL_IMPL_MSA_SELECT(v_float32x4, v4f32, v16u8) +OPENCV_HAL_IMPL_MSA_SELECT(v_float64x2, v2f64, v16u8) + +#define OPENCV_HAL_IMPL_MSA_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix, ssuffix, _Tpv, _Tpvs) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + _Tpv a_lo = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \ + _Tpv a_hi = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \ + b0.val = msa_paddlq_##suffix(a_lo); \ + b1.val = msa_paddlq_##suffix(a_hi); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ \ + _Tpv a_lo = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \ + return _Tpwvec(msa_paddlq_##suffix(a_lo)); \ +} \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ \ + _Tpv a_hi = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \ + return _Tpwvec(msa_paddlq_##suffix(a_hi)); \ +} \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ \ + return _Tpwvec(msa_movl_##suffix(msa_ld1_##suffix(ptr))); \ +} + +OPENCV_HAL_IMPL_MSA_EXPAND(v_uint8x16, v_uint16x8, uchar, u8, s8, v16u8, v16i8) +OPENCV_HAL_IMPL_MSA_EXPAND(v_int8x16, v_int16x8, schar, s8, s8, v16i8, v16i8) +OPENCV_HAL_IMPL_MSA_EXPAND(v_uint16x8, v_uint32x4, ushort, u16, s16, v8u16, v8i16) +OPENCV_HAL_IMPL_MSA_EXPAND(v_int16x8, v_int32x4, short, s16, s16, v8i16, v8i16) +OPENCV_HAL_IMPL_MSA_EXPAND(v_uint32x4, v_uint64x2, uint, u32, s32, v4u32, v4i32) +OPENCV_HAL_IMPL_MSA_EXPAND(v_int32x4, v_int64x2, int, s32, s32, v4i32, v4i32) + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ + return v_uint32x4((v4u32){ptr[0], ptr[1], ptr[2], ptr[3]}); +} + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ + return v_int32x4((v4i32){ptr[0], ptr[1], ptr[2], ptr[3]}); +} + +/* v_zip, v_combine_low, v_combine_high, v_recombine */ +#define OPENCV_HAL_IMPL_MSA_UNPACKS(_Tpvec, _Tpv, _Tpvs, ssuffix) \ +inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) \ +{ \ + b0.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \ + b1.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \ +} \ +inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val)))); \ +} \ +inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val)))); \ +} \ +inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) \ +{ \ + c.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val))); \ + d.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val))); \ +} + +OPENCV_HAL_IMPL_MSA_UNPACKS(v_uint8x16, v16u8, v16i8, s8) +OPENCV_HAL_IMPL_MSA_UNPACKS(v_int8x16, v16i8, v16i8, s8) +OPENCV_HAL_IMPL_MSA_UNPACKS(v_uint16x8, v8u16, v8i16, s16) +OPENCV_HAL_IMPL_MSA_UNPACKS(v_int16x8, v8i16, v8i16, s16) +OPENCV_HAL_IMPL_MSA_UNPACKS(v_uint32x4, v4u32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_UNPACKS(v_int32x4, v4i32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_UNPACKS(v_float32x4, v4f32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_UNPACKS(v_float64x2, v2f64, v2i64, s64) + +/* v_extract */ +#define OPENCV_HAL_IMPL_MSA_EXTRACT(_Tpvec, _Tpv, _Tpvs, suffix) \ +template \ +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), MSA_TPV_REINTERPRET(_Tpvs, b.val), s))); \ +} + +OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint8x16, v16u8, v16i8, s8) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_int8x16, v16i8, v16i8, s8) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint16x8, v8u16, v8i16, s16) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_int16x8, v8i16, v8i16, s16) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint32x4, v4u32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_int32x4, v4i32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint64x2, v2u64, v2i64, s64) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_int64x2, v2i64, v2i64, s64) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_float32x4, v4f32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_EXTRACT(v_float64x2, v2f64, v2i64, s64) + +/* v_round, v_floor, v_ceil, v_trunc */ +inline v_int32x4 v_round(const v_float32x4& a) +{ + return v_int32x4(msa_cvttintq_s32_f32(a.val)); +} + +inline v_int32x4 v_floor(const v_float32x4& a) +{ + v4i32 a1 = msa_cvttintq_s32_f32(a.val); + return v_int32x4(msa_addq_s32(a1, MSA_TPV_REINTERPRET(v4i32, msa_cgtq_f32(msa_cvtfintq_f32_s32(a1), a.val)))); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + v4i32 a1 = msa_cvttintq_s32_f32(a.val); + return v_int32x4(msa_subq_s32(a1, MSA_TPV_REINTERPRET(v4i32, msa_cgtq_f32(a.val, msa_cvtfintq_f32_s32(a1))))); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ + return v_int32x4(msa_cvttruncq_s32_f32(a.val)); +} + +inline v_int32x4 v_round(const v_float64x2& a) +{ + return v_int32x4(msa_pack_s64(msa_cvttintq_s64_f64(a.val), msa_dupq_n_s64(0))); +} + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + return v_int32x4(msa_pack_s64(msa_cvttintq_s64_f64(a.val), msa_cvttintq_s64_f64(b.val))); +} + +inline v_int32x4 v_floor(const v_float64x2& a) +{ + v2f64 a1 = msa_cvtrintq_f64(a.val); + return v_int32x4(msa_pack_s64(msa_addq_s64(msa_cvttruncq_s64_f64(a1), MSA_TPV_REINTERPRET(v2i64, msa_cgtq_f64(a1, a.val))), msa_dupq_n_s64(0))); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + v2f64 a1 = msa_cvtrintq_f64(a.val); + return v_int32x4(msa_pack_s64(msa_subq_s64(msa_cvttruncq_s64_f64(a1), MSA_TPV_REINTERPRET(v2i64, msa_cgtq_f64(a.val, a1))), msa_dupq_n_s64(0))); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ + return v_int32x4(msa_pack_s64(msa_cvttruncq_s64_f64(a.val), msa_dupq_n_s64(0))); +} + +#define OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(_Tpvec, _Tpv, _Tpvs, ssuffix) \ +inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, \ + _Tpvec& b2, _Tpvec& b3) \ +{ \ + _Tpv t00 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \ + _Tpv t01 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \ + _Tpv t10 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a3.val), MSA_TPV_REINTERPRET(_Tpvs, a2.val))); \ + _Tpv t11 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a3.val), MSA_TPV_REINTERPRET(_Tpvs, a2.val))); \ + b0.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, t10), MSA_TPV_REINTERPRET(v2i64, t00))); \ + b1.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, t10), MSA_TPV_REINTERPRET(v2i64, t00))); \ + b2.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, t11), MSA_TPV_REINTERPRET(v2i64, t01))); \ + b3.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, t11), MSA_TPV_REINTERPRET(v2i64, t01))); \ +} + +OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(v_uint32x4, v4u32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(v_int32x4, v4i32, v4i32, s32) +OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(v_float32x4, v4f32, v4i32, s32) + +#define OPENCV_HAL_IMPL_MSA_INTERLEAVED(_Tpvec, _Tp, suffix) \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \ +{ \ + msa_ld2q_##suffix(ptr, &a.val, &b.val); \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, v_##_Tpvec& c) \ +{ \ + msa_ld3q_##suffix(ptr, &a.val, &b.val, &c.val); \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, \ + v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + msa_ld4q_##suffix(ptr, &a.val, &b.val, &c.val, &d.val); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + msa_st2q_##suffix(ptr, a.val, b.val); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + msa_st3q_##suffix(ptr, a.val, b.val, c.val); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, const v_##_Tpvec& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \ +{ \ + msa_st4q_##suffix(ptr, a.val, b.val, c.val, d.val); \ +} + +OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint8x16, uchar, u8) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(int8x16, schar, s8) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint16x8, ushort, u16) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(int16x8, short, s16) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(int32x4, int, s32) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(float32x4, float, f32) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint64x2, uint64, u64) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(int64x2, int64, s64) +OPENCV_HAL_IMPL_MSA_INTERLEAVED(float64x2, double, f64) + +/* v_cvt_f32, v_cvt_f64, v_cvt_f64_high */ +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + return v_float32x4(msa_cvtfintq_f32_s32(a.val)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + return v_float32x4(msa_cvtfq_f32_f64(a.val, msa_dupq_n_f64(0.0f))); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + return v_float32x4(msa_cvtfq_f32_f64(a.val, b.val)); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + return v_float64x2(msa_cvtflq_f64_f32(msa_cvtfintq_f32_s32(a.val))); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + return v_float64x2(msa_cvtfhq_f64_f32(msa_cvtfintq_f32_s32(a.val))); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + return v_float64x2(msa_cvtflq_f64_f32(a.val)); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + return v_float64x2(msa_cvtfhq_f64_f32(a.val)); +} + +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ + return v_float64x2(msa_cvtfintq_f64_s64(a.val)); +} + +////////////// Lookup table access //////////////////// +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[ 0]], + tab[idx[ 1]], + tab[idx[ 2]], + tab[idx[ 3]], + tab[idx[ 4]], + tab[idx[ 5]], + tab[idx[ 6]], + tab[idx[ 7]], + tab[idx[ 8]], + tab[idx[ 9]], + tab[idx[10]], + tab[idx[11]], + tab[idx[12]], + tab[idx[13]], + tab[idx[14]], + tab[idx[15]] + }; + return v_int8x16(msa_ld1q_s8(elems)); +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[4]], + tab[idx[4] + 1], + tab[idx[5]], + tab[idx[5] + 1], + tab[idx[6]], + tab[idx[6] + 1], + tab[idx[7]], + tab[idx[7] + 1] + }; + return v_int8x16(msa_ld1q_s8(elems)); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[0] + 2], + tab[idx[0] + 3], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[1] + 2], + tab[idx[1] + 3], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[2] + 2], + tab[idx[2] + 3], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[3] + 2], + tab[idx[3] + 3] + }; + return v_int8x16(msa_ld1q_s8(elems)); +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); } + + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]], + tab[idx[4]], + tab[idx[5]], + tab[idx[6]], + tab[idx[7]] + }; + return v_int16x8(msa_ld1q_s16(elems)); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1] + }; + return v_int16x8(msa_ld1q_s16(elems)); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_int16x8(msa_combine_s16(msa_ld1_s16(tab + idx[0]), msa_ld1_s16(tab + idx[1]))); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((short*)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((short*)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((short*)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_int32x4(msa_ld1q_s32(elems)); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_int32x4(msa_combine_s32(msa_ld1_s32(tab + idx[0]), msa_ld1_s32(tab + idx[1]))); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(msa_ld1q_s32(tab + idx[0])); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((int*)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((int*)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((int*)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(msa_combine_s64(msa_create_s64(tab[idx[0]]), msa_create_s64(tab[idx[1]]))); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(msa_ld1q_s64(tab + idx[0])); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_float32x4(msa_ld1q_f32(elems)); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) +{ + uint64 CV_DECL_ALIGNED(32) elems[2] = + { + *(uint64*)(tab + idx[0]), + *(uint64*)(tab + idx[1]) + }; + return v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ld1q_u64(elems))); +} +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) +{ + return v_float32x4(msa_ld1q_f32(tab + idx[0])); +} + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + return v_int32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + unsigned CV_DECL_ALIGNED(32) elems[4] = + { + tab[msa_getq_lane_s32(idxvec.val, 0)], + tab[msa_getq_lane_s32(idxvec.val, 1)], + tab[msa_getq_lane_s32(idxvec.val, 2)], + tab[msa_getq_lane_s32(idxvec.val, 3)] + }; + return v_uint32x4(msa_ld1q_u32(elems)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + return v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + v4f32 xy02 = msa_combine_f32(msa_ld1_f32(tab + idx[0]), msa_ld1_f32(tab + idx[2])); + v4f32 xy13 = msa_combine_f32(msa_ld1_f32(tab + idx[1]), msa_ld1_f32(tab + idx[3])); + x = v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ilvevq_s32(MSA_TPV_REINTERPRET(v4i32, xy13), MSA_TPV_REINTERPRET(v4i32, xy02)))); + y = v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ilvodq_s32(MSA_TPV_REINTERPRET(v4i32, xy13), MSA_TPV_REINTERPRET(v4i32, xy02)))); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ + v_int8x16 c = v_int8x16(__builtin_msa_vshf_b((v16i8)((v2i64){0x0705060403010200, 0x0F0D0E0C0B090A08}), msa_dupq_n_s8(0), vec.val)); + return c; +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) +{ return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ + v_int8x16 c = v_int8x16(__builtin_msa_vshf_b((v16i8)((v2i64){0x0703060205010400, 0x0F0B0E0A0D090C08}), msa_dupq_n_s8(0), vec.val)); + return c; +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ + v_int16x8 c = v_int16x8(__builtin_msa_vshf_h((v8i16)((v2i64){0x0003000100020000, 0x0007000500060004}), msa_dupq_n_s16(0), vec.val)); + return c; +} + +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } + +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ + v_int16x8 c = v_int16x8(__builtin_msa_vshf_h((v8i16)((v2i64){0x0005000100040000, 0x0007000300060002}), msa_dupq_n_s16(0), vec.val)); + return c; +} + +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + v_int32x4 c; + c.val[0] = vec.val[0]; + c.val[1] = vec.val[2]; + c.val[2] = vec.val[1]; + c.val[3] = vec.val[3]; + return c; +} + +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ + v_int8x16 c = v_int8x16(__builtin_msa_vshf_b((v16i8)((v2i64){0x0908060504020100, 0x131211100E0D0C0A}), msa_dupq_n_s8(0), vec.val)); + return c; +} + +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ + v_int16x8 c = v_int16x8(__builtin_msa_vshf_h((v8i16)((v2i64){0x0004000200010000, 0x0009000800060005}), msa_dupq_n_s16(0), vec.val)); + return c; +} + +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; } + +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + tab[idx[0]], + tab[idx[1]] + }; + return v_float64x2(msa_ld1q_f64(elems)); +} + +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) +{ + return v_float64x2(msa_ld1q_f64(tab + idx[0])); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + return v_float64x2(tab[idx[0]], tab[idx[1]]); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + v2f64 xy0 = msa_ld1q_f64(tab + idx[0]); + v2f64 xy1 = msa_ld1q_f64(tab + idx[1]); + x = v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_ilvevq_s64(MSA_TPV_REINTERPRET(v2i64, xy1), MSA_TPV_REINTERPRET(v2i64, xy0)))); + y = v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_ilvodq_s64(MSA_TPV_REINTERPRET(v2i64, xy1), MSA_TPV_REINTERPRET(v2i64, xy0)))); +} + +template +inline typename _Tp::lane_type v_extract_n(const _Tp& a) +{ + return v_rotate_right(a).get0(); +} + +template +inline v_uint32x4 v_broadcast_element(const v_uint32x4& a) +{ + return v_setall_u32(v_extract_n(a)); +} +template +inline v_int32x4 v_broadcast_element(const v_int32x4& a) +{ + return v_setall_s32(v_extract_n(a)); +} +template +inline v_float32x4 v_broadcast_element(const v_float32x4& a) +{ + return v_setall_f32(v_extract_n(a)); +} + +////// FP16 suport /////// +#if CV_FP16 +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ +#ifndef msa_ld1_f16 + v4f16 v = (v4f16)msa_ld1_s16((const short*)ptr); +#else + v4f16 v = msa_ld1_f16((const __fp16*)ptr); +#endif + return v_float32x4(msa_cvt_f32_f16(v)); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + v4f16 hv = msa_cvt_f16_f32(v.val); + +#ifndef msa_st1_f16 + msa_st1_s16((short*)ptr, (int16x4_t)hv); +#else + msa_st1_f16((__fp16*)ptr, hv); +#endif +} +#else +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + float buf[4]; + for( int i = 0; i < 4; i++ ) + buf[i] = (float)ptr[i]; + return v_load(buf); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + float buf[4]; + v_store(buf, v); + for( int i = 0; i < 4; i++ ) + ptr[i] = (float16_t)buf[i]; +} +#endif + +inline void v_cleanup() {} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_neon.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_neon.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7411b28d0c9d04be65f642c4f06e856f456cd872 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_neon.hpp @@ -0,0 +1,2330 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_INTRIN_NEON_HPP +#define OPENCV_HAL_INTRIN_NEON_HPP + +#include +#include "opencv2/core/utility.hpp" + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#define CV_SIMD128 1 +#if defined(__aarch64__) || defined(_M_ARM64) +#define CV_SIMD128_64F 1 +#else +#define CV_SIMD128_64F 0 +#endif + +// TODO +#define CV_NEON_DOT 0 + +//////////// Utils //////////// + +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv, _Tpvx2, suffix) \ + inline void _v128_unzip(const _Tpv& a, const _Tpv& b, _Tpv& c, _Tpv& d) \ + { c = vuzp1q_##suffix(a, b); d = vuzp2q_##suffix(a, b); } +#define OPENCV_HAL_IMPL_NEON_UNZIP_L(_Tpv, _Tpvx2, suffix) \ + inline void _v128_unzip(const _Tpv&a, const _Tpv&b, _Tpv& c, _Tpv& d) \ + { c = vuzp1_##suffix(a, b); d = vuzp2_##suffix(a, b); } +#else +#define OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv, _Tpvx2, suffix) \ + inline void _v128_unzip(const _Tpv& a, const _Tpv& b, _Tpv& c, _Tpv& d) \ + { _Tpvx2 ab = vuzpq_##suffix(a, b); c = ab.val[0]; d = ab.val[1]; } +#define OPENCV_HAL_IMPL_NEON_UNZIP_L(_Tpv, _Tpvx2, suffix) \ + inline void _v128_unzip(const _Tpv& a, const _Tpv& b, _Tpv& c, _Tpv& d) \ + { _Tpvx2 ab = vuzp_##suffix(a, b); c = ab.val[0]; d = ab.val[1]; } +#endif + +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv, suffix) \ + template static inline \ + _Tpv vreinterpretq_##suffix##_f64(T a) { return (_Tpv) a; } \ + template static inline \ + float64x2_t vreinterpretq_f64_##suffix(T a) { return (float64x2_t) a; } +#else +#define OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv, suffix) +#endif + +#define OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(_Tpv, _Tpvl, suffix) \ + OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv##_t, _Tpv##x2_t, suffix) \ + OPENCV_HAL_IMPL_NEON_UNZIP_L(_Tpvl##_t, _Tpvl##x2_t, suffix) \ + OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv##_t, suffix) + +#define OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_I64(_Tpv, _Tpvl, suffix) \ + OPENCV_HAL_IMPL_NEON_REINTERPRET(_Tpv##_t, suffix) + +#define OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_F64(_Tpv, _Tpvl, suffix) \ + OPENCV_HAL_IMPL_NEON_UNZIP(_Tpv##_t, _Tpv##x2_t, suffix) + +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(uint8x16, uint8x8, u8) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(int8x16, int8x8, s8) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(uint16x8, uint16x4, u16) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(int16x8, int16x4, s16) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(uint32x4, uint32x2, u32) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(int32x4, int32x2, s32) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX(float32x4, float32x2, f32) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_I64(uint64x2, uint64x1, u64) +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_I64(int64x2, int64x1, s64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_UTILS_SUFFIX_F64(float64x2, float64x1,f64) +#endif + +//////////// Types //////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + + v_uint8x16() {} + explicit v_uint8x16(uint8x16_t v) : val(v) {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = vld1q_u8(v); + } + uchar get0() const + { + return vgetq_lane_u8(val, 0); + } + + uint8x16_t val; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + + v_int8x16() {} + explicit v_int8x16(int8x16_t v) : val(v) {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = vld1q_s8(v); + } + schar get0() const + { + return vgetq_lane_s8(val, 0); + } + + int8x16_t val; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + + v_uint16x8() {} + explicit v_uint16x8(uint16x8_t v) : val(v) {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = vld1q_u16(v); + } + ushort get0() const + { + return vgetq_lane_u16(val, 0); + } + + uint16x8_t val; +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + + v_int16x8() {} + explicit v_int16x8(int16x8_t v) : val(v) {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + short v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = vld1q_s16(v); + } + short get0() const + { + return vgetq_lane_s16(val, 0); + } + + int16x8_t val; +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + enum { nlanes = 4 }; + + v_uint32x4() {} + explicit v_uint32x4(uint32x4_t v) : val(v) {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) + { + unsigned v[] = {v0, v1, v2, v3}; + val = vld1q_u32(v); + } + unsigned get0() const + { + return vgetq_lane_u32(val, 0); + } + + uint32x4_t val; +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + + v_int32x4() {} + explicit v_int32x4(int32x4_t v) : val(v) {} + v_int32x4(int v0, int v1, int v2, int v3) + { + int v[] = {v0, v1, v2, v3}; + val = vld1q_s32(v); + } + int get0() const + { + return vgetq_lane_s32(val, 0); + } + int32x4_t val; +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + + v_float32x4() {} + explicit v_float32x4(float32x4_t v) : val(v) {} + v_float32x4(float v0, float v1, float v2, float v3) + { + float v[] = {v0, v1, v2, v3}; + val = vld1q_f32(v); + } + float get0() const + { + return vgetq_lane_f32(val, 0); + } + float32x4_t val; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + + v_uint64x2() {} + explicit v_uint64x2(uint64x2_t v) : val(v) {} + v_uint64x2(uint64 v0, uint64 v1) + { + uint64 v[] = {v0, v1}; + val = vld1q_u64(v); + } + uint64 get0() const + { + return vgetq_lane_u64(val, 0); + } + uint64x2_t val; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + + v_int64x2() {} + explicit v_int64x2(int64x2_t v) : val(v) {} + v_int64x2(int64 v0, int64 v1) + { + int64 v[] = {v0, v1}; + val = vld1q_s64(v); + } + int64 get0() const + { + return vgetq_lane_s64(val, 0); + } + int64x2_t val; +}; + +#if CV_SIMD128_64F +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + + v_float64x2() {} + explicit v_float64x2(float64x2_t v) : val(v) {} + v_float64x2(double v0, double v1) + { + double v[] = {v0, v1}; + val = vld1q_f64(v); + } + double get0() const + { + return vgetq_lane_f64(val, 0); + } + float64x2_t val; +}; +#endif + +#define OPENCV_HAL_IMPL_NEON_INIT(_Tpv, _Tp, suffix) \ +inline v_##_Tpv v_setzero_##suffix() { return v_##_Tpv(vdupq_n_##suffix((_Tp)0)); } \ +inline v_##_Tpv v_setall_##suffix(_Tp v) { return v_##_Tpv(vdupq_n_##suffix(v)); } \ +inline _Tpv##_t vreinterpretq_##suffix##_##suffix(_Tpv##_t v) { return v; } \ +inline v_uint8x16 v_reinterpret_as_u8(const v_##_Tpv& v) { return v_uint8x16(vreinterpretq_u8_##suffix(v.val)); } \ +inline v_int8x16 v_reinterpret_as_s8(const v_##_Tpv& v) { return v_int8x16(vreinterpretq_s8_##suffix(v.val)); } \ +inline v_uint16x8 v_reinterpret_as_u16(const v_##_Tpv& v) { return v_uint16x8(vreinterpretq_u16_##suffix(v.val)); } \ +inline v_int16x8 v_reinterpret_as_s16(const v_##_Tpv& v) { return v_int16x8(vreinterpretq_s16_##suffix(v.val)); } \ +inline v_uint32x4 v_reinterpret_as_u32(const v_##_Tpv& v) { return v_uint32x4(vreinterpretq_u32_##suffix(v.val)); } \ +inline v_int32x4 v_reinterpret_as_s32(const v_##_Tpv& v) { return v_int32x4(vreinterpretq_s32_##suffix(v.val)); } \ +inline v_uint64x2 v_reinterpret_as_u64(const v_##_Tpv& v) { return v_uint64x2(vreinterpretq_u64_##suffix(v.val)); } \ +inline v_int64x2 v_reinterpret_as_s64(const v_##_Tpv& v) { return v_int64x2(vreinterpretq_s64_##suffix(v.val)); } \ +inline v_float32x4 v_reinterpret_as_f32(const v_##_Tpv& v) { return v_float32x4(vreinterpretq_f32_##suffix(v.val)); } + +OPENCV_HAL_IMPL_NEON_INIT(uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_INIT(int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_INIT(uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_INIT(int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_INIT(uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_NEON_INIT(int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_INIT(uint64x2, uint64, u64) +OPENCV_HAL_IMPL_NEON_INIT(int64x2, int64, s64) +OPENCV_HAL_IMPL_NEON_INIT(float32x4, float, f32) +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_INIT_64(_Tpv, suffix) \ +inline v_float64x2 v_reinterpret_as_f64(const v_##_Tpv& v) { return v_float64x2(vreinterpretq_f64_##suffix(v.val)); } +OPENCV_HAL_IMPL_NEON_INIT(float64x2, double, f64) +OPENCV_HAL_IMPL_NEON_INIT_64(uint8x16, u8) +OPENCV_HAL_IMPL_NEON_INIT_64(int8x16, s8) +OPENCV_HAL_IMPL_NEON_INIT_64(uint16x8, u16) +OPENCV_HAL_IMPL_NEON_INIT_64(int16x8, s16) +OPENCV_HAL_IMPL_NEON_INIT_64(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_INIT_64(int32x4, s32) +OPENCV_HAL_IMPL_NEON_INIT_64(uint64x2, u64) +OPENCV_HAL_IMPL_NEON_INIT_64(int64x2, s64) +OPENCV_HAL_IMPL_NEON_INIT_64(float32x4, f32) +OPENCV_HAL_IMPL_NEON_INIT_64(float64x2, f64) +#endif + +#define OPENCV_HAL_IMPL_NEON_PACK(_Tpvec, _Tp, hreg, suffix, _Tpwvec, pack, mov, rshr) \ +inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + hreg a1 = mov(a.val), b1 = mov(b.val); \ + return _Tpvec(vcombine_##suffix(a1, b1)); \ +} \ +inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + hreg a1 = mov(a.val); \ + vst1_##suffix(ptr, a1); \ +} \ +template inline \ +_Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + hreg a1 = rshr(a.val, n); \ + hreg b1 = rshr(b.val, n); \ + return _Tpvec(vcombine_##suffix(a1, b1)); \ +} \ +template inline \ +void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + hreg a1 = rshr(a.val, n); \ + vst1_##suffix(ptr, a1); \ +} + +OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_uint16x8, pack, vqmovn_u16, vqrshrn_n_u16) +OPENCV_HAL_IMPL_NEON_PACK(v_int8x16, schar, int8x8_t, s8, v_int16x8, pack, vqmovn_s16, vqrshrn_n_s16) +OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_uint32x4, pack, vqmovn_u32, vqrshrn_n_u32) +OPENCV_HAL_IMPL_NEON_PACK(v_int16x8, short, int16x4_t, s16, v_int32x4, pack, vqmovn_s32, vqrshrn_n_s32) +OPENCV_HAL_IMPL_NEON_PACK(v_uint32x4, unsigned, uint32x2_t, u32, v_uint64x2, pack, vmovn_u64, vrshrn_n_u64) +OPENCV_HAL_IMPL_NEON_PACK(v_int32x4, int, int32x2_t, s32, v_int64x2, pack, vmovn_s64, vrshrn_n_s64) + +OPENCV_HAL_IMPL_NEON_PACK(v_uint8x16, uchar, uint8x8_t, u8, v_int16x8, pack_u, vqmovun_s16, vqrshrun_n_s16) +OPENCV_HAL_IMPL_NEON_PACK(v_uint16x8, ushort, uint16x4_t, u16, v_int32x4, pack_u, vqmovun_s32, vqrshrun_n_s32) + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + uint8x16_t ab = vcombine_u8(vmovn_u16(a.val), vmovn_u16(b.val)); + return v_uint8x16(ab); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + uint16x8_t nab = vcombine_u16(vmovn_u32(a.val), vmovn_u32(b.val)); + uint16x8_t ncd = vcombine_u16(vmovn_u32(c.val), vmovn_u32(d.val)); + return v_uint8x16(vcombine_u8(vmovn_u16(nab), vmovn_u16(ncd))); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + uint32x4_t ab = vcombine_u32(vmovn_u64(a.val), vmovn_u64(b.val)); + uint32x4_t cd = vcombine_u32(vmovn_u64(c.val), vmovn_u64(d.val)); + uint32x4_t ef = vcombine_u32(vmovn_u64(e.val), vmovn_u64(f.val)); + uint32x4_t gh = vcombine_u32(vmovn_u64(g.val), vmovn_u64(h.val)); + + uint16x8_t abcd = vcombine_u16(vmovn_u32(ab), vmovn_u32(cd)); + uint16x8_t efgh = vcombine_u16(vmovn_u32(ef), vmovn_u32(gh)); + return v_uint8x16(vcombine_u8(vmovn_u16(abcd), vmovn_u16(efgh))); +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + float32x2_t vl = vget_low_f32(v.val), vh = vget_high_f32(v.val); + float32x4_t res = vmulq_lane_f32(m0.val, vl, 0); + res = vmlaq_lane_f32(res, m1.val, vl, 1); + res = vmlaq_lane_f32(res, m2.val, vh, 0); + res = vmlaq_lane_f32(res, m3.val, vh, 1); + return v_float32x4(res); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + float32x2_t vl = vget_low_f32(v.val), vh = vget_high_f32(v.val); + float32x4_t res = vmulq_lane_f32(m0.val, vl, 0); + res = vmlaq_lane_f32(res, m1.val, vl, 1); + res = vmlaq_lane_f32(res, m2.val, vh, 0); + res = vaddq_f32(res, a.val); + return v_float32x4(res); +} + +#define OPENCV_HAL_IMPL_NEON_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + a.val = intrin(a.val, b.val); \ + return a; \ +} + +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint8x16, vqaddq_u8) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint8x16, vqsubq_u8) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int8x16, vqaddq_s8) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int8x16, vqsubq_s8) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint16x8, vqaddq_u16) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint16x8, vqsubq_u16) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int16x8, vqaddq_s16) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int16x8, vqsubq_s16) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int32x4, vaddq_s32) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int32x4, vsubq_s32) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_int32x4, vmulq_s32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint32x4, vaddq_u32) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint32x4, vsubq_u32) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_uint32x4, vmulq_u32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_float32x4, vaddq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_float32x4, vsubq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_float32x4, vmulq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_int64x2, vaddq_s64) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_int64x2, vsubq_s64) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_uint64x2, vaddq_u64) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_uint64x2, vsubq_u64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float32x4, vdivq_f32) +OPENCV_HAL_IMPL_NEON_BIN_OP(+, v_float64x2, vaddq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(-, v_float64x2, vsubq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(*, v_float64x2, vmulq_f64) +OPENCV_HAL_IMPL_NEON_BIN_OP(/, v_float64x2, vdivq_f64) +#else +inline v_float32x4 operator / (const v_float32x4& a, const v_float32x4& b) +{ + float32x4_t reciprocal = vrecpeq_f32(b.val); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + return v_float32x4(vmulq_f32(a.val, reciprocal)); +} +inline v_float32x4& operator /= (v_float32x4& a, const v_float32x4& b) +{ + float32x4_t reciprocal = vrecpeq_f32(b.val); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + reciprocal = vmulq_f32(vrecpsq_f32(b.val, reciprocal), reciprocal); + a.val = vmulq_f32(a.val, reciprocal); + return a; +} +#endif + +// saturating multiply 8-bit, 16-bit +#define OPENCV_HAL_IMPL_NEON_MUL_SAT(_Tpvec, _Tpwvec) \ + inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ + { \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ + } \ + inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ + { a = a * b; return a; } + +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_int16x8, v_int32x4) +OPENCV_HAL_IMPL_NEON_MUL_SAT(v_uint16x8, v_uint32x4) + +// Multiply and expand +inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, + v_int16x8& c, v_int16x8& d) +{ + c.val = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val)); + d.val = vmull_s8(vget_high_s8(a.val), vget_high_s8(b.val)); +} + +inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, + v_uint16x8& c, v_uint16x8& d) +{ + c.val = vmull_u8(vget_low_u8(a.val), vget_low_u8(b.val)); + d.val = vmull_u8(vget_high_u8(a.val), vget_high_u8(b.val)); +} + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, + v_int32x4& c, v_int32x4& d) +{ + c.val = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); + d.val = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)); +} + +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, + v_uint32x4& c, v_uint32x4& d) +{ + c.val = vmull_u16(vget_low_u16(a.val), vget_low_u16(b.val)); + d.val = vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, + v_uint64x2& c, v_uint64x2& d) +{ + c.val = vmull_u32(vget_low_u32(a.val), vget_low_u32(b.val)); + d.val = vmull_u32(vget_high_u32(a.val), vget_high_u32(b.val)); +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + return v_int16x8(vcombine_s16( + vshrn_n_s32(vmull_s16( vget_low_s16(a.val), vget_low_s16(b.val)), 16), + vshrn_n_s32(vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)), 16) + )); +} +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + return v_uint16x8(vcombine_u16( + vshrn_n_u32(vmull_u16( vget_low_u16(a.val), vget_low_u16(b.val)), 16), + vshrn_n_u32(vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)), 16) + )); +} + +//////// Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ + int16x8_t uzp1, uzp2; + _v128_unzip(a.val, b.val, uzp1, uzp2); + int16x4_t a0 = vget_low_s16(uzp1); + int16x4_t b0 = vget_high_s16(uzp1); + int16x4_t a1 = vget_low_s16(uzp2); + int16x4_t b1 = vget_high_s16(uzp2); + int32x4_t p = vmull_s16(a0, b0); + return v_int32x4(vmlal_s16(p, a1, b1)); +} +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + int16x8_t uzp1, uzp2; + _v128_unzip(a.val, b.val, uzp1, uzp2); + int16x4_t a0 = vget_low_s16(uzp1); + int16x4_t b0 = vget_high_s16(uzp1); + int16x4_t a1 = vget_low_s16(uzp2); + int16x4_t b1 = vget_high_s16(uzp2); + int32x4_t p = vmlal_s16(c.val, a0, b0); + return v_int32x4(vmlal_s16(p, a1, b1)); +} + +// 32 >> 64 +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b) +{ + int32x4_t uzp1, uzp2; + _v128_unzip(a.val, b.val, uzp1, uzp2); + int32x2_t a0 = vget_low_s32(uzp1); + int32x2_t b0 = vget_high_s32(uzp1); + int32x2_t a1 = vget_low_s32(uzp2); + int32x2_t b1 = vget_high_s32(uzp2); + int64x2_t p = vmull_s32(a0, b0); + return v_int64x2(vmlal_s32(p, a1, b1)); +} +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ + int32x4_t uzp1, uzp2; + _v128_unzip(a.val, b.val, uzp1, uzp2); + int32x2_t a0 = vget_low_s32(uzp1); + int32x2_t b0 = vget_high_s32(uzp1); + int32x2_t a1 = vget_low_s32(uzp2); + int32x2_t b1 = vget_high_s32(uzp2); + int64x2_t p = vmlal_s32(c.val, a0, b0); + return v_int64x2(vmlal_s32(p, a1, b1)); +} + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b) +{ +#if CV_NEON_DOT + return v_uint32x4(vdotq_u32(vdupq_n_u32(0), a.val, b.val)); +#else + const uint8x16_t zero = vreinterpretq_u8_u32(vdupq_n_u32(0)); + const uint8x16_t mask = vreinterpretq_u8_u32(vdupq_n_u32(0x00FF00FF)); + const uint16x8_t zero32 = vreinterpretq_u16_u32(vdupq_n_u32(0)); + const uint16x8_t mask32 = vreinterpretq_u16_u32(vdupq_n_u32(0x0000FFFF)); + + uint16x8_t even = vmulq_u16(vreinterpretq_u16_u8(vbslq_u8(mask, a.val, zero)), + vreinterpretq_u16_u8(vbslq_u8(mask, b.val, zero))); + uint16x8_t odd = vmulq_u16(vshrq_n_u16(vreinterpretq_u16_u8(a.val), 8), + vshrq_n_u16(vreinterpretq_u16_u8(b.val), 8)); + + uint32x4_t s0 = vaddq_u32(vreinterpretq_u32_u16(vbslq_u16(mask32, even, zero32)), + vreinterpretq_u32_u16(vbslq_u16(mask32, odd, zero32))); + uint32x4_t s1 = vaddq_u32(vshrq_n_u32(vreinterpretq_u32_u16(even), 16), + vshrq_n_u32(vreinterpretq_u32_u16(odd), 16)); + return v_uint32x4(vaddq_u32(s0, s1)); +#endif +} +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, + const v_uint32x4& c) +{ +#if CV_NEON_DOT + return v_uint32x4(vdotq_u32(c.val, a.val, b.val)); +#else + return v_dotprod_expand(a, b) + c; +#endif +} + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b) +{ +#if CV_NEON_DOT + return v_int32x4(vdotq_s32(vdupq_n_s32(0), a.val, b.val)); +#else + int16x8_t p0 = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val)); + int16x8_t p1 = vmull_s8(vget_high_s8(a.val), vget_high_s8(b.val)); + int16x8_t uzp1, uzp2; + _v128_unzip(p0, p1, uzp1, uzp2); + int16x8_t sum = vaddq_s16(uzp1, uzp2); + int16x4_t uzpl1, uzpl2; + _v128_unzip(vget_low_s16(sum), vget_high_s16(sum), uzpl1, uzpl2); + return v_int32x4(vaddl_s16(uzpl1, uzpl2)); +#endif +} +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b, + const v_int32x4& c) +{ +#if CV_NEON_DOT + return v_int32x4(vdotq_s32(c.val, a.val, b.val)); +#else + return v_dotprod_expand(a, b) + c; +#endif +} + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b) +{ + const uint16x8_t zero = vreinterpretq_u16_u32(vdupq_n_u32(0)); + const uint16x8_t mask = vreinterpretq_u16_u32(vdupq_n_u32(0x0000FFFF)); + + uint32x4_t even = vmulq_u32(vreinterpretq_u32_u16(vbslq_u16(mask, a.val, zero)), + vreinterpretq_u32_u16(vbslq_u16(mask, b.val, zero))); + uint32x4_t odd = vmulq_u32(vshrq_n_u32(vreinterpretq_u32_u16(a.val), 16), + vshrq_n_u32(vreinterpretq_u32_u16(b.val), 16)); + uint32x4_t uzp1, uzp2; + _v128_unzip(even, odd, uzp1, uzp2); + uint64x2_t s0 = vaddl_u32(vget_low_u32(uzp1), vget_high_u32(uzp1)); + uint64x2_t s1 = vaddl_u32(vget_low_u32(uzp2), vget_high_u32(uzp2)); + return v_uint64x2(vaddq_u64(s0, s1)); +} +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b) +{ + int32x4_t p0 = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); + int32x4_t p1 = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)); + + int32x4_t uzp1, uzp2; + _v128_unzip(p0, p1, uzp1, uzp2); + int32x4_t sum = vaddq_s32(uzp1, uzp2); + + int32x2_t uzpl1, uzpl2; + _v128_unzip(vget_low_s32(sum), vget_high_s32(sum), uzpl1, uzpl2); + return v_int64x2(vaddl_s32(uzpl1, uzpl2)); +} +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, + const v_int64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +// 32 >> 64f +#if CV_SIMD128_64F +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, + const v_float64x2& c) +{ return v_dotprod_expand(a, b) + c; } +#endif + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) +{ + int16x4_t a0 = vget_low_s16(a.val); + int16x4_t a1 = vget_high_s16(a.val); + int16x4_t b0 = vget_low_s16(b.val); + int16x4_t b1 = vget_high_s16(b.val); + int32x4_t p = vmull_s16(a0, b0); + return v_int32x4(vmlal_s16(p, a1, b1)); +} +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ + int16x4_t a0 = vget_low_s16(a.val); + int16x4_t a1 = vget_high_s16(a.val); + int16x4_t b0 = vget_low_s16(b.val); + int16x4_t b1 = vget_high_s16(b.val); + int32x4_t p = vmlal_s16(c.val, a0, b0); + return v_int32x4(vmlal_s16(p, a1, b1)); +} + +// 32 >> 64 +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) +{ + int32x2_t a0 = vget_low_s32(a.val); + int32x2_t a1 = vget_high_s32(a.val); + int32x2_t b0 = vget_low_s32(b.val); + int32x2_t b1 = vget_high_s32(b.val); + int64x2_t p = vmull_s32(a0, b0); + return v_int64x2(vmlal_s32(p, a1, b1)); +} +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ + int32x2_t a0 = vget_low_s32(a.val); + int32x2_t a1 = vget_high_s32(a.val); + int32x2_t b0 = vget_low_s32(b.val); + int32x2_t b1 = vget_high_s32(b.val); + int64x2_t p = vmlal_s32(c.val, a0, b0); + return v_int64x2(vmlal_s32(p, a1, b1)); +} + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b) +{ +#if CV_NEON_DOT + return v_uint32x4(vdotq_u32(vdupq_n_u32(0), a.val, b.val)); +#else + uint16x8_t p0 = vmull_u8(vget_low_u8(a.val), vget_low_u8(b.val)); + uint16x8_t p1 = vmull_u8(vget_high_u8(a.val), vget_high_u8(b.val)); + uint32x4_t s0 = vaddl_u16(vget_low_u16(p0), vget_low_u16(p1)); + uint32x4_t s1 = vaddl_u16(vget_high_u16(p0), vget_high_u16(p1)); + return v_uint32x4(vaddq_u32(s0, s1)); +#endif +} +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ +#if CV_NEON_DOT + return v_uint32x4(vdotq_u32(c.val, a.val, b.val)); +#else + return v_dotprod_expand_fast(a, b) + c; +#endif +} + +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b) +{ +#if CV_NEON_DOT + return v_int32x4(vdotq_s32(vdupq_n_s32(0), a.val, b.val)); +#else + int16x8_t prod = vmull_s8(vget_low_s8(a.val), vget_low_s8(b.val)); + prod = vmlal_s8(prod, vget_high_s8(a.val), vget_high_s8(b.val)); + return v_int32x4(vaddl_s16(vget_low_s16(prod), vget_high_s16(prod))); +#endif +} +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ +#if CV_NEON_DOT + return v_int32x4(vdotq_s32(c.val, a.val, b.val)); +#else + return v_dotprod_expand_fast(a, b) + c; +#endif +} + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b) +{ + uint32x4_t p0 = vmull_u16(vget_low_u16(a.val), vget_low_u16(b.val)); + uint32x4_t p1 = vmull_u16(vget_high_u16(a.val), vget_high_u16(b.val)); + uint64x2_t s0 = vaddl_u32(vget_low_u32(p0), vget_high_u32(p0)); + uint64x2_t s1 = vaddl_u32(vget_low_u32(p1), vget_high_u32(p1)); + return v_uint64x2(vaddq_u64(s0, s1)); +} +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b) +{ + int32x4_t prod = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); + prod = vmlal_s16(prod, vget_high_s16(a.val), vget_high_s16(b.val)); + return v_int64x2(vaddl_s32(vget_low_s32(prod), vget_high_s32(prod))); +} +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +// 32 >> 64f +#if CV_SIMD128_64F +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod_fast(a, b)); } +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand_fast(a, b) + c; } +#endif + + +#define OPENCV_HAL_IMPL_NEON_LOGIC_OP(_Tpvec, suffix) \ + OPENCV_HAL_IMPL_NEON_BIN_OP(&, _Tpvec, vandq_##suffix) \ + OPENCV_HAL_IMPL_NEON_BIN_OP(|, _Tpvec, vorrq_##suffix) \ + OPENCV_HAL_IMPL_NEON_BIN_OP(^, _Tpvec, veorq_##suffix) \ + inline _Tpvec operator ~ (const _Tpvec& a) \ + { \ + return _Tpvec(vreinterpretq_##suffix##_u8(vmvnq_u8(vreinterpretq_u8_##suffix(a.val)))); \ + } + +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint8x16, u8) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int8x16, s8) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint16x8, u16) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int16x8, s16) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint32x4, u32) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int32x4, s32) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_uint64x2, u64) +OPENCV_HAL_IMPL_NEON_LOGIC_OP(v_int64x2, s64) + +#define OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(bin_op, intrin) \ +inline v_float32x4 operator bin_op (const v_float32x4& a, const v_float32x4& b) \ +{ \ + return v_float32x4(vreinterpretq_f32_s32(intrin(vreinterpretq_s32_f32(a.val), vreinterpretq_s32_f32(b.val)))); \ +} \ +inline v_float32x4& operator bin_op##= (v_float32x4& a, const v_float32x4& b) \ +{ \ + a.val = vreinterpretq_f32_s32(intrin(vreinterpretq_s32_f32(a.val), vreinterpretq_s32_f32(b.val))); \ + return a; \ +} + +OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(&, vandq_s32) +OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(|, vorrq_s32) +OPENCV_HAL_IMPL_NEON_FLT_BIT_OP(^, veorq_s32) + +inline v_float32x4 operator ~ (const v_float32x4& a) +{ + return v_float32x4(vreinterpretq_f32_s32(vmvnq_s32(vreinterpretq_s32_f32(a.val)))); +} + +#if CV_SIMD128_64F +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ + return v_float32x4(vsqrtq_f32(x.val)); +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + v_float32x4 one = v_setall_f32(1.0f); + return one / v_sqrt(x); +} +#else +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ + float32x4_t x1 = vmaxq_f32(x.val, vdupq_n_f32(FLT_MIN)); + float32x4_t e = vrsqrteq_f32(x1); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); + return v_float32x4(vmulq_f32(x.val, e)); +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + float32x4_t e = vrsqrteq_f32(x.val); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x.val, e), e), e); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x.val, e), e), e); + return v_float32x4(e); +} +#endif + +#define OPENCV_HAL_IMPL_NEON_ABS(_Tpuvec, _Tpsvec, usuffix, ssuffix) \ +inline _Tpuvec v_abs(const _Tpsvec& a) { return v_reinterpret_as_##usuffix(_Tpsvec(vabsq_##ssuffix(a.val))); } + +OPENCV_HAL_IMPL_NEON_ABS(v_uint8x16, v_int8x16, u8, s8) +OPENCV_HAL_IMPL_NEON_ABS(v_uint16x8, v_int16x8, u16, s16) +OPENCV_HAL_IMPL_NEON_ABS(v_uint32x4, v_int32x4, u32, s32) + +inline v_float32x4 v_abs(v_float32x4 x) +{ return v_float32x4(vabsq_f32(x.val)); } + +#if CV_SIMD128_64F +#define OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(bin_op, intrin) \ +inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \ +{ \ + return v_float64x2(vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val)))); \ +} \ +inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \ +{ \ + a.val = vreinterpretq_f64_s64(intrin(vreinterpretq_s64_f64(a.val), vreinterpretq_s64_f64(b.val))); \ + return a; \ +} + +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(&, vandq_s64) +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(|, vorrq_s64) +OPENCV_HAL_IMPL_NEON_DBL_BIT_OP(^, veorq_s64) + +inline v_float64x2 operator ~ (const v_float64x2& a) +{ + return v_float64x2(vreinterpretq_f64_s32(vmvnq_s32(vreinterpretq_s32_f64(a.val)))); +} + +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ + return v_float64x2(vsqrtq_f64(x.val)); +} + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ + v_float64x2 one = v_setall_f64(1.0f); + return one / v_sqrt(x); +} + +inline v_float64x2 v_abs(v_float64x2 x) +{ return v_float64x2(vabsq_f64(x.val)); } +#endif + +// TODO: exp, log, sin, cos + +#define OPENCV_HAL_IMPL_NEON_BIN_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_min, vminq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_max, vmaxq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_min, vminq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_max, vmaxq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_min, vminq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_max, vmaxq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_min, vminq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_max, vmaxq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_min, vminq_u32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_max, vmaxq_u32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_min, vminq_s32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int32x4, v_max, vmaxq_s32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_min, vminq_f32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_max, vmaxq_f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_min, vminq_f64) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_max, vmaxq_f64) +#endif + +#if CV_SIMD128_64F +inline int64x2_t vmvnq_s64(int64x2_t a) +{ + int64x2_t vx = vreinterpretq_s64_u32(vdupq_n_u32(0xFFFFFFFF)); + return veorq_s64(a, vx); +} +inline uint64x2_t vmvnq_u64(uint64x2_t a) +{ + uint64x2_t vx = vreinterpretq_u64_u32(vdupq_n_u32(0xFFFFFFFF)); + return veorq_u64(a, vx); +} +#endif +#define OPENCV_HAL_IMPL_NEON_INT_CMP_OP(_Tpvec, cast, suffix, not_suffix) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vceqq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vmvnq_##not_suffix(vceqq_##suffix(a.val, b.val)))); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcltq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcgtq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcleq_##suffix(a.val, b.val))); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(cast(vcgeq_##suffix(a.val, b.val))); } + +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint8x16, OPENCV_HAL_NOP, u8, u8) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int8x16, vreinterpretq_s8_u8, s8, u8) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint16x8, OPENCV_HAL_NOP, u16, u16) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int16x8, vreinterpretq_s16_u16, s16, u16) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint32x4, OPENCV_HAL_NOP, u32, u32) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int32x4, vreinterpretq_s32_u32, s32, u32) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float32x4, vreinterpretq_f32_u32, f32, u32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_uint64x2, OPENCV_HAL_NOP, u64, u64) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_int64x2, vreinterpretq_s64_u64, s64, u64) +OPENCV_HAL_IMPL_NEON_INT_CMP_OP(v_float64x2, vreinterpretq_f64_u64, f64, u64) +#endif + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return v_float32x4(vreinterpretq_f32_u32(vceqq_f32(a.val, a.val))); } +#if CV_SIMD128_64F +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return v_float64x2(vreinterpretq_f64_u64(vceqq_f64(a.val, a.val))); } +#endif + +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_add_wrap, vaddq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_add_wrap, vaddq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_add_wrap, vaddq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_add_wrap, vaddq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_sub_wrap, vsubq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_sub_wrap, vsubq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_sub_wrap, vsubq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_sub_wrap, vsubq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_mul_wrap, vmulq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int8x16, v_mul_wrap, vmulq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_mul_wrap, vmulq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_int16x8, v_mul_wrap, vmulq_s16) + +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint8x16, v_absdiff, vabdq_u8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint16x8, v_absdiff, vabdq_u16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_uint32x4, v_absdiff, vabdq_u32) +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float32x4, v_absdiff, vabdq_f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BIN_FUNC(v_float64x2, v_absdiff, vabdq_f64) +#endif + +/** Saturating absolute difference **/ +inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b) +{ return v_int8x16(vqabsq_s8(vqsubq_s8(a.val, b.val))); } +inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b) +{ return v_int16x8(vqabsq_s16(vqsubq_s16(a.val, b.val))); } + +#define OPENCV_HAL_IMPL_NEON_BIN_FUNC2(_Tpvec, _Tpvec2, cast, func, intrin) \ +inline _Tpvec2 func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec2(cast(intrin(a.val, b.val))); \ +} + +OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int8x16, v_uint8x16, vreinterpretq_u8_s8, v_absdiff, vabdq_s8) +OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int16x8, v_uint16x8, vreinterpretq_u16_s16, v_absdiff, vabdq_s16) +OPENCV_HAL_IMPL_NEON_BIN_FUNC2(v_int32x4, v_uint32x4, vreinterpretq_u32_s32, v_absdiff, vabdq_s32) + +inline v_float32x4 v_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + v_float32x4 x(vmlaq_f32(vmulq_f32(a.val, a.val), b.val, b.val)); + return v_sqrt(x); +} + +inline v_float32x4 v_sqr_magnitude(const v_float32x4& a, const v_float32x4& b) +{ + return v_float32x4(vmlaq_f32(vmulq_f32(a.val, a.val), b.val, b.val)); +} + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ +#if CV_SIMD128_64F + // ARMv8, which adds support for 64-bit floating-point (so CV_SIMD128_64F is defined), + // also adds FMA support both for single- and double-precision floating-point vectors + return v_float32x4(vfmaq_f32(c.val, a.val, b.val)); +#else + return v_float32x4(vmlaq_f32(c.val, a.val, b.val)); +#endif +} + +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_int32x4(vmlaq_s32(c.val, a.val, b.val)); +} + +inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +#if CV_SIMD128_64F +inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 x(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val))); + return v_sqrt(x); +} + +inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b) +{ + return v_float64x2(vaddq_f64(vmulq_f64(a.val, a.val), vmulq_f64(b.val, b.val))); +} + +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_float64x2(vfmaq_f64(c.val, a.val, b.val)); +} + +inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return v_fma(a, b, c); +} +#endif + +// trade efficiency for convenience +#define OPENCV_HAL_IMPL_NEON_SHIFT_OP(_Tpvec, suffix, _Tps, ssuffix) \ +inline _Tpvec operator << (const _Tpvec& a, int n) \ +{ return _Tpvec(vshlq_##suffix(a.val, vdupq_n_##ssuffix((_Tps)n))); } \ +inline _Tpvec operator >> (const _Tpvec& a, int n) \ +{ return _Tpvec(vshlq_##suffix(a.val, vdupq_n_##ssuffix((_Tps)-n))); } \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ return _Tpvec(vshlq_n_##suffix(a.val, n)); } \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ return _Tpvec(vshrq_n_##suffix(a.val, n)); } \ +template inline _Tpvec v_rshr(const _Tpvec& a) \ +{ return _Tpvec(vrshrq_n_##suffix(a.val, n)); } + +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint8x16, u8, schar, s8) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int8x16, s8, schar, s8) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint16x8, u16, short, s16) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int16x8, s16, short, s16) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint32x4, u32, int, s32) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int32x4, s32, int, s32) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_uint64x2, u64, int64, s64) +OPENCV_HAL_IMPL_NEON_SHIFT_OP(v_int64x2, s64, int64, s64) + +#define OPENCV_HAL_IMPL_NEON_ROTATE_OP(_Tpvec, suffix) \ +template inline _Tpvec v_rotate_right(const _Tpvec& a) \ +{ return _Tpvec(vextq_##suffix(a.val, vdupq_n_##suffix(0), n)); } \ +template inline _Tpvec v_rotate_left(const _Tpvec& a) \ +{ return _Tpvec(vextq_##suffix(vdupq_n_##suffix(0), a.val, _Tpvec::nlanes - n)); } \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a) \ +{ return a; } \ +template inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vextq_##suffix(a.val, b.val, n)); } \ +template inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vextq_##suffix(b.val, a.val, _Tpvec::nlanes - n)); } \ +template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a, const _Tpvec& b) \ +{ CV_UNUSED(b); return a; } + +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint8x16, u8) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int8x16, s8) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint16x8, u16) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int16x8, s16) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint32x4, u32) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int32x4, s32) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_float32x4, f32) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_uint64x2, u64) +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_int64x2, s64) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_ROTATE_OP(v_float64x2, f64) +#endif + +#if defined(__clang__) && defined(__aarch64__) +// avoid LD2 instruction. details: https://github.com/opencv/opencv/issues/14863 +#define OPENCV_HAL_IMPL_NEON_LOAD_LOW_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ \ +typedef uint64 CV_DECL_ALIGNED(1) unaligned_uint64; \ +uint64 v = *(unaligned_uint64*)ptr; \ +return _Tpvec(v_reinterpret_as_##suffix(v_uint64x2(v, (uint64)123456))); \ +} +#else +#define OPENCV_HAL_IMPL_NEON_LOAD_LOW_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr), vdup_n_##suffix((_Tp)0))); } +#endif + +#define OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(vld1q_##suffix(ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(vld1q_##suffix(ptr)); } \ +OPENCV_HAL_IMPL_NEON_LOAD_LOW_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ return _Tpvec(vcombine_##suffix(vld1_##suffix(ptr0), vld1_##suffix(ptr1))); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \ +{ vst1q_##suffix(ptr, a.val); } \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ vst1_##suffix(ptr, vget_low_##suffix(a.val)); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ vst1_##suffix(ptr, vget_high_##suffix(a.val)); } + +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_LOADSTORE_OP(v_float64x2, double, f64) +#endif + +inline unsigned v_reduce_sum(const v_uint8x16& a) +{ + uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(a.val)); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline int v_reduce_sum(const v_int8x16& a) +{ + int32x4_t t0 = vpaddlq_s16(vpaddlq_s8(a.val)); + int32x2_t t1 = vpadd_s32(vget_low_s32(t0), vget_high_s32(t0)); + return vget_lane_s32(vpadd_s32(t1, t1), 0); +} +inline unsigned v_reduce_sum(const v_uint16x8& a) +{ + uint32x4_t t0 = vpaddlq_u16(a.val); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline int v_reduce_sum(const v_int16x8& a) +{ + int32x4_t t0 = vpaddlq_s16(a.val); + int32x2_t t1 = vpadd_s32(vget_low_s32(t0), vget_high_s32(t0)); + return vget_lane_s32(vpadd_s32(t1, t1), 0); +} + +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \ + a0 = vp##vectorfunc##_##suffix(a0, a0); \ + return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, a0),0); \ +} + +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned int, max, max, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_uint16x8, uint16x4, unsigned int, min, min, u16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, int, max, max, s16) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_8(v_int16x8, int16x4, int, min, min, s16) + +#define OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(_Tpvec, _Tpnvec, scalartype, func, vectorfunc, suffix) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + _Tpnvec##_t a0 = vp##vectorfunc##_##suffix(vget_low_##suffix(a.val), vget_high_##suffix(a.val)); \ + return (scalartype)vget_lane_##suffix(vp##vectorfunc##_##suffix(a0, vget_high_##suffix(a.val)),0); \ +} + +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, sum, add, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, max, max, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_uint32x4, uint32x2, unsigned, min, min, u32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, sum, add, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, max, max, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_int32x4, int32x2, int, min, min, s32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, sum, add, f32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, max, max, f32) +OPENCV_HAL_IMPL_NEON_REDUCE_OP_4(v_float32x4, float32x2, float, min, min, f32) + +inline uint64 v_reduce_sum(const v_uint64x2& a) +{ return vget_lane_u64(vadd_u64(vget_low_u64(a.val), vget_high_u64(a.val)),0); } +inline int64 v_reduce_sum(const v_int64x2& a) +{ return vget_lane_s64(vadd_s64(vget_low_s64(a.val), vget_high_s64(a.val)),0); } +#if CV_SIMD128_64F +inline double v_reduce_sum(const v_float64x2& a) +{ + return vgetq_lane_f64(a.val, 0) + vgetq_lane_f64(a.val, 1); +} +#endif + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + float32x4x2_t ab = vtrnq_f32(a.val, b.val); + float32x4x2_t cd = vtrnq_f32(c.val, d.val); + + float32x4_t u0 = vaddq_f32(ab.val[0], ab.val[1]); // a0+a1 b0+b1 a2+a3 b2+b3 + float32x4_t u1 = vaddq_f32(cd.val[0], cd.val[1]); // c0+c1 d0+d1 c2+c3 d2+d3 + + float32x4_t v0 = vcombine_f32(vget_low_f32(u0), vget_low_f32(u1)); + float32x4_t v1 = vcombine_f32(vget_high_f32(u0), vget_high_f32(u1)); + + return v_float32x4(vaddq_f32(v0, v1)); +} + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vabdq_u8(a.val, b.val))); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + uint32x4_t t0 = vpaddlq_u16(vpaddlq_u8(vreinterpretq_u8_s8(vabdq_s8(a.val, b.val)))); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + uint32x4_t t0 = vpaddlq_u16(vabdq_u16(a.val, b.val)); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + uint32x4_t t0 = vpaddlq_u16(vreinterpretq_u16_s16(vabdq_s16(a.val, b.val))); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + uint32x4_t t0 = vabdq_u32(a.val, b.val); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + uint32x4_t t0 = vreinterpretq_u32_s32(vabdq_s32(a.val, b.val)); + uint32x2_t t1 = vpadd_u32(vget_low_u32(t0), vget_high_u32(t0)); + return vget_lane_u32(vpadd_u32(t1, t1), 0); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + float32x4_t t0 = vabdq_f32(a.val, b.val); + float32x2_t t1 = vpadd_f32(vget_low_f32(t0), vget_high_f32(t0)); + return vget_lane_f32(vpadd_f32(t1, t1), 0); +} + +inline v_uint8x16 v_popcount(const v_uint8x16& a) +{ return v_uint8x16(vcntq_u8(a.val)); } +inline v_uint8x16 v_popcount(const v_int8x16& a) +{ return v_uint8x16(vcntq_u8(vreinterpretq_u8_s8(a.val))); } +inline v_uint16x8 v_popcount(const v_uint16x8& a) +{ return v_uint16x8(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_u16(a.val)))); } +inline v_uint16x8 v_popcount(const v_int16x8& a) +{ return v_uint16x8(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_s16(a.val)))); } +inline v_uint32x4 v_popcount(const v_uint32x4& a) +{ return v_uint32x4(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_u32(a.val))))); } +inline v_uint32x4 v_popcount(const v_int32x4& a) +{ return v_uint32x4(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_s32(a.val))))); } +inline v_uint64x2 v_popcount(const v_uint64x2& a) +{ return v_uint64x2(vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_u64(a.val)))))); } +inline v_uint64x2 v_popcount(const v_int64x2& a) +{ return v_uint64x2(vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vcntq_u8(vreinterpretq_u8_s64(a.val)))))); } + +inline int v_signmask(const v_uint8x16& a) +{ + int8x8_t m0 = vcreate_s8(CV_BIG_UINT(0x0706050403020100)); + uint8x16_t v0 = vshlq_u8(vshrq_n_u8(a.val, 7), vcombine_s8(m0, m0)); + uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(v0))); + return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 8); +} +inline int v_signmask(const v_int8x16& a) +{ return v_signmask(v_reinterpret_as_u8(a)); } + +inline int v_signmask(const v_uint16x8& a) +{ + int16x4_t m0 = vcreate_s16(CV_BIG_UINT(0x0003000200010000)); + uint16x8_t v0 = vshlq_u16(vshrq_n_u16(a.val, 15), vcombine_s16(m0, m0)); + uint64x2_t v1 = vpaddlq_u32(vpaddlq_u16(v0)); + return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 4); +} +inline int v_signmask(const v_int16x8& a) +{ return v_signmask(v_reinterpret_as_u16(a)); } + +inline int v_signmask(const v_uint32x4& a) +{ + int32x2_t m0 = vcreate_s32(CV_BIG_UINT(0x0000000100000000)); + uint32x4_t v0 = vshlq_u32(vshrq_n_u32(a.val, 31), vcombine_s32(m0, m0)); + uint64x2_t v1 = vpaddlq_u32(v0); + return (int)vgetq_lane_u64(v1, 0) + ((int)vgetq_lane_u64(v1, 1) << 2); +} +inline int v_signmask(const v_int32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } +inline int v_signmask(const v_float32x4& a) +{ return v_signmask(v_reinterpret_as_u32(a)); } +inline int v_signmask(const v_uint64x2& a) +{ + int64x1_t m0 = vdup_n_s64(0); + uint64x2_t v0 = vshlq_u64(vshrq_n_u64(a.val, 63), vcombine_s64(m0, m0)); + return (int)vgetq_lane_u64(v0, 0) + ((int)vgetq_lane_u64(v0, 1) << 1); +} +inline int v_signmask(const v_int64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +#if CV_SIMD128_64F +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_u64(a)); } +#endif + +inline int v_scan_forward(const v_int8x16& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint8x16& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int16x8& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint16x8& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_float32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int64x2& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signmask(a)); } +#if CV_SIMD128_64F +inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(a)); } +#endif + +#define OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(_Tpvec, suffix, shift) \ +inline bool v_check_all(const v_##_Tpvec& a) \ +{ \ + _Tpvec##_t v0 = vshrq_n_##suffix(vmvnq_##suffix(a.val), shift); \ + uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ + return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) == 0; \ +} \ +inline bool v_check_any(const v_##_Tpvec& a) \ +{ \ + _Tpvec##_t v0 = vshrq_n_##suffix(a.val, shift); \ + uint64x2_t v1 = vreinterpretq_u64_##suffix(v0); \ + return (vgetq_lane_u64(v1, 0) | vgetq_lane_u64(v1, 1)) != 0; \ +} + +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint8x16, u8, 7) +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint16x8, u16, 15) +OPENCV_HAL_IMPL_NEON_CHECK_ALLANY(uint32x4, u32, 31) + +inline bool v_check_all(const v_uint64x2& a) +{ + uint64x2_t v0 = vshrq_n_u64(a.val, 63); + return (vgetq_lane_u64(v0, 0) & vgetq_lane_u64(v0, 1)) == 1; +} +inline bool v_check_any(const v_uint64x2& a) +{ + uint64x2_t v0 = vshrq_n_u64(a.val, 63); + return (vgetq_lane_u64(v0, 0) | vgetq_lane_u64(v0, 1)) != 0; +} + +inline bool v_check_all(const v_int8x16& a) +{ return v_check_all(v_reinterpret_as_u8(a)); } +inline bool v_check_all(const v_int16x8& a) +{ return v_check_all(v_reinterpret_as_u16(a)); } +inline bool v_check_all(const v_int32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } +inline bool v_check_all(const v_float32x4& a) +{ return v_check_all(v_reinterpret_as_u32(a)); } + +inline bool v_check_any(const v_int8x16& a) +{ return v_check_any(v_reinterpret_as_u8(a)); } +inline bool v_check_any(const v_int16x8& a) +{ return v_check_any(v_reinterpret_as_u16(a)); } +inline bool v_check_any(const v_int32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } +inline bool v_check_any(const v_float32x4& a) +{ return v_check_any(v_reinterpret_as_u32(a)); } + +inline bool v_check_all(const v_int64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_int64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +#if CV_SIMD128_64F +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_u64(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_u64(a)); } +#endif + +#define OPENCV_HAL_IMPL_NEON_SELECT(_Tpvec, suffix, usuffix) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(vbslq_##suffix(vreinterpretq_##usuffix##_##suffix(mask.val), a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_NEON_SELECT(v_uint8x16, u8, u8) +OPENCV_HAL_IMPL_NEON_SELECT(v_int8x16, s8, u8) +OPENCV_HAL_IMPL_NEON_SELECT(v_uint16x8, u16, u16) +OPENCV_HAL_IMPL_NEON_SELECT(v_int16x8, s16, u16) +OPENCV_HAL_IMPL_NEON_SELECT(v_uint32x4, u32, u32) +OPENCV_HAL_IMPL_NEON_SELECT(v_int32x4, s32, u32) +OPENCV_HAL_IMPL_NEON_SELECT(v_float32x4, f32, u32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_SELECT(v_float64x2, f64, u64) +#endif + +#define OPENCV_HAL_IMPL_NEON_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + b0.val = vmovl_##suffix(vget_low_##suffix(a.val)); \ + b1.val = vmovl_##suffix(vget_high_##suffix(a.val)); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ \ + return _Tpwvec(vmovl_##suffix(vget_low_##suffix(a.val))); \ +} \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ \ + return _Tpwvec(vmovl_##suffix(vget_high_##suffix(a.val))); \ +} \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ \ + return _Tpwvec(vmovl_##suffix(vld1_##suffix(ptr))); \ +} + +OPENCV_HAL_IMPL_NEON_EXPAND(v_uint8x16, v_uint16x8, uchar, u8) +OPENCV_HAL_IMPL_NEON_EXPAND(v_int8x16, v_int16x8, schar, s8) +OPENCV_HAL_IMPL_NEON_EXPAND(v_uint16x8, v_uint32x4, ushort, u16) +OPENCV_HAL_IMPL_NEON_EXPAND(v_int16x8, v_int32x4, short, s16) +OPENCV_HAL_IMPL_NEON_EXPAND(v_uint32x4, v_uint64x2, uint, u32) +OPENCV_HAL_IMPL_NEON_EXPAND(v_int32x4, v_int64x2, int, s32) + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ + typedef unsigned int CV_DECL_ALIGNED(1) unaligned_uint; + uint8x8_t v0 = vcreate_u8(*(unaligned_uint*)ptr); + uint16x4_t v1 = vget_low_u16(vmovl_u8(v0)); + return v_uint32x4(vmovl_u16(v1)); +} + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ + typedef unsigned int CV_DECL_ALIGNED(1) unaligned_uint; + int8x8_t v0 = vcreate_s8(*(unaligned_uint*)ptr); + int16x4_t v1 = vget_low_s16(vmovl_s8(v0)); + return v_int32x4(vmovl_s16(v1)); +} + +#if defined(__aarch64__) || defined(_M_ARM64) +#define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \ +inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ +{ \ + b0.val = vzip1q_##suffix(a0.val, a1.val); \ + b1.val = vzip2q_##suffix(a0.val, a1.val); \ +} \ +inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val))); \ +} \ +inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val))); \ +} \ +inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \ + d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \ +} +#else +#define OPENCV_HAL_IMPL_NEON_UNPACKS(_Tpvec, suffix) \ +inline void v_zip(const v_##_Tpvec& a0, const v_##_Tpvec& a1, v_##_Tpvec& b0, v_##_Tpvec& b1) \ +{ \ + _Tpvec##x2_t p = vzipq_##suffix(a0.val, a1.val); \ + b0.val = p.val[0]; \ + b1.val = p.val[1]; \ +} \ +inline v_##_Tpvec v_combine_low(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val))); \ +} \ +inline v_##_Tpvec v_combine_high(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val))); \ +} \ +inline void v_recombine(const v_##_Tpvec& a, const v_##_Tpvec& b, v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + c.val = vcombine_##suffix(vget_low_##suffix(a.val), vget_low_##suffix(b.val)); \ + d.val = vcombine_##suffix(vget_high_##suffix(a.val), vget_high_##suffix(b.val)); \ +} +#endif + +OPENCV_HAL_IMPL_NEON_UNPACKS(uint8x16, u8) +OPENCV_HAL_IMPL_NEON_UNPACKS(int8x16, s8) +OPENCV_HAL_IMPL_NEON_UNPACKS(uint16x8, u16) +OPENCV_HAL_IMPL_NEON_UNPACKS(int16x8, s16) +OPENCV_HAL_IMPL_NEON_UNPACKS(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_UNPACKS(int32x4, s32) +OPENCV_HAL_IMPL_NEON_UNPACKS(float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_UNPACKS(float64x2, f64) +#endif + +inline v_uint8x16 v_reverse(const v_uint8x16 &a) +{ + uint8x16_t vec = vrev64q_u8(a.val); + return v_uint8x16(vextq_u8(vec, vec, 8)); +} + +inline v_int8x16 v_reverse(const v_int8x16 &a) +{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); } + +inline v_uint16x8 v_reverse(const v_uint16x8 &a) +{ + uint16x8_t vec = vrev64q_u16(a.val); + return v_uint16x8(vextq_u16(vec, vec, 4)); +} + +inline v_int16x8 v_reverse(const v_int16x8 &a) +{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); } + +inline v_uint32x4 v_reverse(const v_uint32x4 &a) +{ + uint32x4_t vec = vrev64q_u32(a.val); + return v_uint32x4(vextq_u32(vec, vec, 2)); +} + +inline v_int32x4 v_reverse(const v_int32x4 &a) +{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_float32x4 v_reverse(const v_float32x4 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x2 v_reverse(const v_uint64x2 &a) +{ + uint64x2_t vec = a.val; + uint64x1_t vec_lo = vget_low_u64(vec); + uint64x1_t vec_hi = vget_high_u64(vec); + return v_uint64x2(vcombine_u64(vec_hi, vec_lo)); +} + +inline v_int64x2 v_reverse(const v_int64x2 &a) +{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); } + +#if CV_SIMD128_64F +inline v_float64x2 v_reverse(const v_float64x2 &a) +{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); } +#endif + +#define OPENCV_HAL_IMPL_NEON_EXTRACT(_Tpvec, suffix) \ +template \ +inline v_##_Tpvec v_extract(const v_##_Tpvec& a, const v_##_Tpvec& b) \ +{ \ + return v_##_Tpvec(vextq_##suffix(a.val, b.val, s)); \ +} + +OPENCV_HAL_IMPL_NEON_EXTRACT(uint8x16, u8) +OPENCV_HAL_IMPL_NEON_EXTRACT(int8x16, s8) +OPENCV_HAL_IMPL_NEON_EXTRACT(uint16x8, u16) +OPENCV_HAL_IMPL_NEON_EXTRACT(int16x8, s16) +OPENCV_HAL_IMPL_NEON_EXTRACT(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_EXTRACT(int32x4, s32) +OPENCV_HAL_IMPL_NEON_EXTRACT(uint64x2, u64) +OPENCV_HAL_IMPL_NEON_EXTRACT(int64x2, s64) +OPENCV_HAL_IMPL_NEON_EXTRACT(float32x4, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_EXTRACT(float64x2, f64) +#endif + +#define OPENCV_HAL_IMPL_NEON_EXTRACT_N(_Tpvec, _Tp, suffix) \ +template inline _Tp v_extract_n(_Tpvec v) { return vgetq_lane_##suffix(v.val, i); } + +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint32x4, uint, u32) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_EXTRACT_N(v_float64x2, double, f64) +#endif + +#define OPENCV_HAL_IMPL_NEON_BROADCAST(_Tpvec, _Tp, suffix) \ +template inline _Tpvec v_broadcast_element(_Tpvec v) { _Tp t = v_extract_n(v); return v_setall_##suffix(t); } + +OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint32x4, uint, u32) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_int64x2, int64, s64) +OPENCV_HAL_IMPL_NEON_BROADCAST(v_float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_BROADCAST(v_float64x2, double, f64) +#endif + +#if CV_SIMD128_64F +inline v_int32x4 v_round(const v_float32x4& a) +{ + float32x4_t a_ = a.val; + int32x4_t result; + __asm__ ("fcvtns %0.4s, %1.4s" + : "=w"(result) + : "w"(a_) + : /* No clobbers */); + return v_int32x4(result); +} +#else +inline v_int32x4 v_round(const v_float32x4& a) +{ + static const int32x4_t v_sign = vdupq_n_s32(1 << 31), + v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); + + int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(a.val))); + return v_int32x4(vcvtq_s32_f32(vaddq_f32(a.val, vreinterpretq_f32_s32(v_addition)))); +} +#endif +inline v_int32x4 v_floor(const v_float32x4& a) +{ + int32x4_t a1 = vcvtq_s32_f32(a.val); + uint32x4_t mask = vcgtq_f32(vcvtq_f32_s32(a1), a.val); + return v_int32x4(vaddq_s32(a1, vreinterpretq_s32_u32(mask))); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + int32x4_t a1 = vcvtq_s32_f32(a.val); + uint32x4_t mask = vcgtq_f32(a.val, vcvtq_f32_s32(a1)); + return v_int32x4(vsubq_s32(a1, vreinterpretq_s32_u32(mask))); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(vcvtq_s32_f32(a.val)); } + +#if CV_SIMD128_64F +inline v_int32x4 v_round(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero)); +} + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), vmovn_s64(vcvtaq_s64_f64(b.val)))); +} + +inline v_int32x4 v_floor(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + int64x2_t a1 = vcvtq_s64_f64(a.val); + uint64x2_t mask = vcgtq_f64(vcvtq_f64_s64(a1), a.val); + a1 = vaddq_s64(a1, vreinterpretq_s64_u64(mask)); + return v_int32x4(vcombine_s32(vmovn_s64(a1), zero)); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + int64x2_t a1 = vcvtq_s64_f64(a.val); + uint64x2_t mask = vcgtq_f64(a.val, vcvtq_f64_s64(a1)); + a1 = vsubq_s64(a1, vreinterpretq_s64_u64(mask)); + return v_int32x4(vcombine_s32(vmovn_s64(a1), zero)); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ + static const int32x2_t zero = vdup_n_s32(0); + return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero)); +} +#endif + +#define OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(_Tpvec, suffix) \ +inline void v_transpose4x4(const v_##_Tpvec& a0, const v_##_Tpvec& a1, \ + const v_##_Tpvec& a2, const v_##_Tpvec& a3, \ + v_##_Tpvec& b0, v_##_Tpvec& b1, \ + v_##_Tpvec& b2, v_##_Tpvec& b3) \ +{ \ + /* m00 m01 m02 m03 */ \ + /* m10 m11 m12 m13 */ \ + /* m20 m21 m22 m23 */ \ + /* m30 m31 m32 m33 */ \ + _Tpvec##x2_t t0 = vtrnq_##suffix(a0.val, a1.val); \ + _Tpvec##x2_t t1 = vtrnq_##suffix(a2.val, a3.val); \ + /* m00 m10 m02 m12 */ \ + /* m01 m11 m03 m13 */ \ + /* m20 m30 m22 m32 */ \ + /* m21 m31 m23 m33 */ \ + b0.val = vcombine_##suffix(vget_low_##suffix(t0.val[0]), vget_low_##suffix(t1.val[0])); \ + b1.val = vcombine_##suffix(vget_low_##suffix(t0.val[1]), vget_low_##suffix(t1.val[1])); \ + b2.val = vcombine_##suffix(vget_high_##suffix(t0.val[0]), vget_high_##suffix(t1.val[0])); \ + b3.val = vcombine_##suffix(vget_high_##suffix(t0.val[1]), vget_high_##suffix(t1.val[1])); \ +} + +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(uint32x4, u32) +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(int32x4, s32) +OPENCV_HAL_IMPL_NEON_TRANSPOSE4x4(float32x4, f32) + +#define OPENCV_HAL_IMPL_NEON_INTERLEAVED(_Tpvec, _Tp, suffix) \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \ +{ \ + _Tpvec##x2_t v = vld2q_##suffix(ptr); \ + a.val = v.val[0]; \ + b.val = v.val[1]; \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, v_##_Tpvec& c) \ +{ \ + _Tpvec##x3_t v = vld3q_##suffix(ptr); \ + a.val = v.val[0]; \ + b.val = v.val[1]; \ + c.val = v.val[2]; \ +} \ +inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, \ + v_##_Tpvec& c, v_##_Tpvec& d) \ +{ \ + _Tpvec##x4_t v = vld4q_##suffix(ptr); \ + a.val = v.val[0]; \ + b.val = v.val[1]; \ + c.val = v.val[2]; \ + d.val = v.val[3]; \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + _Tpvec##x2_t v; \ + v.val[0] = a.val; \ + v.val[1] = b.val; \ + vst2q_##suffix(ptr, v); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + _Tpvec##x3_t v; \ + v.val[0] = a.val; \ + v.val[1] = b.val; \ + v.val[2] = c.val; \ + vst3q_##suffix(ptr, v); \ +} \ +inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \ + const v_##_Tpvec& c, const v_##_Tpvec& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec##x4_t v; \ + v.val[0] = a.val; \ + v.val[1] = b.val; \ + v.val[2] = c.val; \ + v.val[3] = d.val; \ + vst4q_##suffix(ptr, v); \ +} + +#define OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(tp, suffix) \ +inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, v_##tp##x2& b ) \ +{ \ + tp##x1_t a0 = vld1_##suffix(ptr); \ + tp##x1_t b0 = vld1_##suffix(ptr + 1); \ + tp##x1_t a1 = vld1_##suffix(ptr + 2); \ + tp##x1_t b1 = vld1_##suffix(ptr + 3); \ + a = v_##tp##x2(vcombine_##suffix(a0, a1)); \ + b = v_##tp##x2(vcombine_##suffix(b0, b1)); \ +} \ + \ +inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, \ + v_##tp##x2& b, v_##tp##x2& c ) \ +{ \ + tp##x1_t a0 = vld1_##suffix(ptr); \ + tp##x1_t b0 = vld1_##suffix(ptr + 1); \ + tp##x1_t c0 = vld1_##suffix(ptr + 2); \ + tp##x1_t a1 = vld1_##suffix(ptr + 3); \ + tp##x1_t b1 = vld1_##suffix(ptr + 4); \ + tp##x1_t c1 = vld1_##suffix(ptr + 5); \ + a = v_##tp##x2(vcombine_##suffix(a0, a1)); \ + b = v_##tp##x2(vcombine_##suffix(b0, b1)); \ + c = v_##tp##x2(vcombine_##suffix(c0, c1)); \ +} \ + \ +inline void v_load_deinterleave( const tp* ptr, v_##tp##x2& a, v_##tp##x2& b, \ + v_##tp##x2& c, v_##tp##x2& d ) \ +{ \ + tp##x1_t a0 = vld1_##suffix(ptr); \ + tp##x1_t b0 = vld1_##suffix(ptr + 1); \ + tp##x1_t c0 = vld1_##suffix(ptr + 2); \ + tp##x1_t d0 = vld1_##suffix(ptr + 3); \ + tp##x1_t a1 = vld1_##suffix(ptr + 4); \ + tp##x1_t b1 = vld1_##suffix(ptr + 5); \ + tp##x1_t c1 = vld1_##suffix(ptr + 6); \ + tp##x1_t d1 = vld1_##suffix(ptr + 7); \ + a = v_##tp##x2(vcombine_##suffix(a0, a1)); \ + b = v_##tp##x2(vcombine_##suffix(b0, b1)); \ + c = v_##tp##x2(vcombine_##suffix(c0, c1)); \ + d = v_##tp##x2(vcombine_##suffix(d0, d1)); \ +} \ + \ +inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, const v_##tp##x2& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + vst1_##suffix(ptr, vget_low_##suffix(a.val)); \ + vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \ + vst1_##suffix(ptr + 2, vget_high_##suffix(a.val)); \ + vst1_##suffix(ptr + 3, vget_high_##suffix(b.val)); \ +} \ + \ +inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, \ + const v_##tp##x2& b, const v_##tp##x2& c, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + vst1_##suffix(ptr, vget_low_##suffix(a.val)); \ + vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \ + vst1_##suffix(ptr + 2, vget_low_##suffix(c.val)); \ + vst1_##suffix(ptr + 3, vget_high_##suffix(a.val)); \ + vst1_##suffix(ptr + 4, vget_high_##suffix(b.val)); \ + vst1_##suffix(ptr + 5, vget_high_##suffix(c.val)); \ +} \ + \ +inline void v_store_interleave( tp* ptr, const v_##tp##x2& a, const v_##tp##x2& b, \ + const v_##tp##x2& c, const v_##tp##x2& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ \ + vst1_##suffix(ptr, vget_low_##suffix(a.val)); \ + vst1_##suffix(ptr + 1, vget_low_##suffix(b.val)); \ + vst1_##suffix(ptr + 2, vget_low_##suffix(c.val)); \ + vst1_##suffix(ptr + 3, vget_low_##suffix(d.val)); \ + vst1_##suffix(ptr + 4, vget_high_##suffix(a.val)); \ + vst1_##suffix(ptr + 5, vget_high_##suffix(b.val)); \ + vst1_##suffix(ptr + 6, vget_high_##suffix(c.val)); \ + vst1_##suffix(ptr + 7, vget_high_##suffix(d.val)); \ +} + +OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint8x16, uchar, u8) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(int8x16, schar, s8) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint16x8, ushort, u16) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(int16x8, short, s16) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(int32x4, int, s32) +OPENCV_HAL_IMPL_NEON_INTERLEAVED(float32x4, float, f32) +#if CV_SIMD128_64F +OPENCV_HAL_IMPL_NEON_INTERLEAVED(float64x2, double, f64) +#endif + +OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(int64, s64) +OPENCV_HAL_IMPL_NEON_INTERLEAVED_INT64(uint64, u64) + +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + return v_float32x4(vcvtq_f32_s32(a.val)); +} + +#if CV_SIMD128_64F +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + float32x2_t zero = vdup_n_f32(0.0f); + return v_float32x4(vcombine_f32(vcvt_f32_f64(a.val), zero)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + return v_float32x4(vcombine_f32(vcvt_f32_f64(a.val), vcvt_f32_f64(b.val))); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_low_s32(a.val)))); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vcvt_f32_s32(vget_high_s32(a.val)))); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vget_low_f32(a.val))); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + return v_float64x2(vcvt_f64_f32(vget_high_f32(a.val))); +} + +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ return v_float64x2(vcvtq_f64_s64(a.val)); } + +#endif + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[ 0]], + tab[idx[ 1]], + tab[idx[ 2]], + tab[idx[ 3]], + tab[idx[ 4]], + tab[idx[ 5]], + tab[idx[ 6]], + tab[idx[ 7]], + tab[idx[ 8]], + tab[idx[ 9]], + tab[idx[10]], + tab[idx[11]], + tab[idx[12]], + tab[idx[13]], + tab[idx[14]], + tab[idx[15]] + }; + return v_int8x16(vld1q_s8(elems)); +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[4]], + tab[idx[4] + 1], + tab[idx[5]], + tab[idx[5] + 1], + tab[idx[6]], + tab[idx[6] + 1], + tab[idx[7]], + tab[idx[7] + 1] + }; + return v_int8x16(vld1q_s8(elems)); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + schar CV_DECL_ALIGNED(32) elems[16] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[0] + 2], + tab[idx[0] + 3], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[1] + 2], + tab[idx[1] + 3], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[2] + 2], + tab[idx[2] + 3], + tab[idx[3]], + tab[idx[3] + 1], + tab[idx[3] + 2], + tab[idx[3] + 3] + }; + return v_int8x16(vld1q_s8(elems)); +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]], + tab[idx[4]], + tab[idx[5]], + tab[idx[6]], + tab[idx[7]] + }; + return v_int16x8(vld1q_s16(elems)); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + short CV_DECL_ALIGNED(32) elems[8] = + { + tab[idx[0]], + tab[idx[0] + 1], + tab[idx[1]], + tab[idx[1] + 1], + tab[idx[2]], + tab[idx[2] + 1], + tab[idx[3]], + tab[idx[3] + 1] + }; + return v_int16x8(vld1q_s16(elems)); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_int16x8(vcombine_s16(vld1_s16(tab + idx[0]), vld1_s16(tab + idx[1]))); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((short*)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((short*)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((short*)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_int32x4(vld1q_s32(elems)); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_int32x4(vcombine_s32(vld1_s32(tab + idx[0]), vld1_s32(tab + idx[1]))); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(vld1q_s32(tab + idx[0])); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((int*)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((int*)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((int*)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(vcombine_s64(vcreate_s64(tab[idx[0]]), vcreate_s64(tab[idx[1]]))); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(vld1q_s64(tab + idx[0])); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[idx[0]], + tab[idx[1]], + tab[idx[2]], + tab[idx[3]] + }; + return v_float32x4(vld1q_f32(elems)); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) +{ + uint64 CV_DECL_ALIGNED(32) elems[2] = + { + *(uint64*)(tab + idx[0]), + *(uint64*)(tab + idx[1]) + }; + return v_float32x4(vreinterpretq_f32_u64(vld1q_u64(elems))); +} +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) +{ + return v_float32x4(vld1q_f32(tab + idx[0])); +} + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) elems[4] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + tab[vgetq_lane_s32(idxvec.val, 2)], + tab[vgetq_lane_s32(idxvec.val, 3)] + }; + return v_int32x4(vld1q_s32(elems)); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + unsigned CV_DECL_ALIGNED(32) elems[4] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + tab[vgetq_lane_s32(idxvec.val, 2)], + tab[vgetq_lane_s32(idxvec.val, 3)] + }; + return v_uint32x4(vld1q_u32(elems)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + float CV_DECL_ALIGNED(32) elems[4] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + tab[vgetq_lane_s32(idxvec.val, 2)], + tab[vgetq_lane_s32(idxvec.val, 3)] + }; + return v_float32x4(vld1q_f32(elems)); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + /*int CV_DECL_ALIGNED(32) idx[4]; + v_store(idx, idxvec); + + float32x4_t xy02 = vcombine_f32(vld1_f32(tab + idx[0]), vld1_f32(tab + idx[2])); + float32x4_t xy13 = vcombine_f32(vld1_f32(tab + idx[1]), vld1_f32(tab + idx[3])); + + float32x4x2_t xxyy = vuzpq_f32(xy02, xy13); + x = v_float32x4(xxyy.val[0]); + y = v_float32x4(xxyy.val[1]);*/ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + x = v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); + y = v_float32x4(tab[idx[0]+1], tab[idx[1]+1], tab[idx[2]+1], tab[idx[3]+1]); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ + return v_int8x16(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0705060403010200)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0705060403010200)))); +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ + return v_int8x16(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0703060205010400)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0703060205010400)))); +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ + return v_int16x8(vreinterpretq_s16_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0706030205040100)), vtbl1_s8(vget_high_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0706030205040100))))); +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ + int16x4x2_t res = vzip_s16(vget_low_s16(vec.val), vget_high_s16(vec.val)); + return v_int16x8(vcombine_s16(res.val[0], res.val[1])); +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + int32x2x2_t res = vzip_s32(vget_low_s32(vec.val), vget_high_s32(vec.val)); + return v_int32x4(vcombine_s32(res.val[0], res.val[1])); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ + return v_int8x16(vextq_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vec.val), vcreate_s8(0x0605040201000000)), vtbl1_s8(vget_high_s8(vec.val), vcreate_s8(0x0807060504020100))), vdupq_n_s8(0), 2)); +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ + return v_int16x8(vreinterpretq_s16_s8(vextq_s8(vcombine_s8(vtbl1_s8(vget_low_s8(vreinterpretq_s8_s16(vec.val)), vcreate_s8(0x0504030201000000)), vget_high_s8(vreinterpretq_s8_s16(vec.val))), vdupq_n_s8(0), 2))); +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; } + +#if CV_SIMD128_64F +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + tab[idx[0]], + tab[idx[1]] + }; + return v_float64x2(vld1q_f64(elems)); +} + +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) +{ + return v_float64x2(vld1q_f64(tab + idx[0])); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + double CV_DECL_ALIGNED(32) elems[2] = + { + tab[vgetq_lane_s32(idxvec.val, 0)], + tab[vgetq_lane_s32(idxvec.val, 1)], + }; + return v_float64x2(vld1q_f64(elems)); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + + x = v_float64x2(tab[idx[0]], tab[idx[1]]); + y = v_float64x2(tab[idx[0]+1], tab[idx[1]+1]); +} +#endif + +////// FP16 support /////// +#if CV_FP16 +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + float16x4_t v = + #ifndef vld1_f16 // APPLE compiler defines vld1_f16 as macro + (float16x4_t)vld1_s16((const short*)ptr); + #else + vld1_f16((const __fp16*)ptr); + #endif + return v_float32x4(vcvt_f32_f16(v)); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + float16x4_t hv = vcvt_f16_f32(v.val); + + #ifndef vst1_f16 // APPLE compiler defines vst1_f16 as macro + vst1_s16((short*)ptr, (int16x4_t)hv); + #else + vst1_f16((__fp16*)ptr, hv); + #endif +} +#else +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + const int N = 4; + float buf[N]; + for( int i = 0; i < N; i++ ) buf[i] = (float)ptr[i]; + return v_load(buf); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + const int N = 4; + float buf[N]; + v_store(buf, v); + for( int i = 0; i < N; i++ ) ptr[i] = float16_t(buf[i]); +} +#endif + +inline void v_cleanup() {} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_sse.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_sse.hpp new file mode 100644 index 0000000000000000000000000000000000000000..867ff5534038d5e0e740ba4a89d624f07e7ca937 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_sse.hpp @@ -0,0 +1,3435 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_SSE_HPP +#define OPENCV_HAL_SSE_HPP + +#include +#include "opencv2/core/utility.hpp" + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 +#define CV_SIMD128_FP16 0 // no native operations with FP16 type. + +namespace cv +{ + +//! @cond IGNORED + +// +// Compilation troubleshooting: +// - MSVC: error C2719: 'a': formal parameter with requested alignment of 16 won't be aligned +// Replace parameter declaration to const reference: +// -v_int32x4 a +// +const v_int32x4& a +// + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Types //////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + typedef __m128i vector_type; + enum { nlanes = 16 }; + + v_uint8x16() : val(_mm_setzero_si128()) {} + explicit v_uint8x16(__m128i v) : val(v) {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + val = _mm_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, + (char)v4, (char)v5, (char)v6, (char)v7, + (char)v8, (char)v9, (char)v10, (char)v11, + (char)v12, (char)v13, (char)v14, (char)v15); + } + uchar get0() const + { + return (uchar)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + typedef __m128i vector_type; + enum { nlanes = 16 }; + + v_int8x16() : val(_mm_setzero_si128()) {} + explicit v_int8x16(__m128i v) : val(v) {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + val = _mm_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3, + (char)v4, (char)v5, (char)v6, (char)v7, + (char)v8, (char)v9, (char)v10, (char)v11, + (char)v12, (char)v13, (char)v14, (char)v15); + } + schar get0() const + { + return (schar)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + typedef __m128i vector_type; + enum { nlanes = 8 }; + + v_uint16x8() : val(_mm_setzero_si128()) {} + explicit v_uint16x8(__m128i v) : val(v) {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + val = _mm_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, + (short)v4, (short)v5, (short)v6, (short)v7); + } + ushort get0() const + { + return (ushort)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_int16x8 +{ + typedef short lane_type; + typedef __m128i vector_type; + enum { nlanes = 8 }; + + v_int16x8() : val(_mm_setzero_si128()) {} + explicit v_int16x8(__m128i v) : val(v) {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + val = _mm_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3, + (short)v4, (short)v5, (short)v6, (short)v7); + } + short get0() const + { + return (short)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + typedef __m128i vector_type; + enum { nlanes = 4 }; + + v_uint32x4() : val(_mm_setzero_si128()) {} + explicit v_uint32x4(__m128i v) : val(v) {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) + { + val = _mm_setr_epi32((int)v0, (int)v1, (int)v2, (int)v3); + } + unsigned get0() const + { + return (unsigned)_mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_int32x4 +{ + typedef int lane_type; + typedef __m128i vector_type; + enum { nlanes = 4 }; + + v_int32x4() : val(_mm_setzero_si128()) {} + explicit v_int32x4(__m128i v) : val(v) {} + v_int32x4(int v0, int v1, int v2, int v3) + { + val = _mm_setr_epi32(v0, v1, v2, v3); + } + int get0() const + { + return _mm_cvtsi128_si32(val); + } + + __m128i val; +}; + +struct v_float32x4 +{ + typedef float lane_type; + typedef __m128 vector_type; + enum { nlanes = 4 }; + + v_float32x4() : val(_mm_setzero_ps()) {} + explicit v_float32x4(__m128 v) : val(v) {} + v_float32x4(float v0, float v1, float v2, float v3) + { + val = _mm_setr_ps(v0, v1, v2, v3); + } + float get0() const + { + return _mm_cvtss_f32(val); + } + + __m128 val; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + typedef __m128i vector_type; + enum { nlanes = 2 }; + + v_uint64x2() : val(_mm_setzero_si128()) {} + explicit v_uint64x2(__m128i v) : val(v) {} + v_uint64x2(uint64 v0, uint64 v1) + { + val = _mm_setr_epi32((int)v0, (int)(v0 >> 32), (int)v1, (int)(v1 >> 32)); + } + uint64 get0() const + { + #if !defined(__x86_64__) && !defined(_M_X64) + int a = _mm_cvtsi128_si32(val); + int b = _mm_cvtsi128_si32(_mm_srli_epi64(val, 32)); + return (unsigned)a | ((uint64)(unsigned)b << 32); + #else + return (uint64)_mm_cvtsi128_si64(val); + #endif + } + + __m128i val; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + typedef __m128i vector_type; + enum { nlanes = 2 }; + + v_int64x2() : val(_mm_setzero_si128()) {} + explicit v_int64x2(__m128i v) : val(v) {} + v_int64x2(int64 v0, int64 v1) + { + val = _mm_setr_epi32((int)v0, (int)(v0 >> 32), (int)v1, (int)(v1 >> 32)); + } + int64 get0() const + { + #if !defined(__x86_64__) && !defined(_M_X64) + int a = _mm_cvtsi128_si32(val); + int b = _mm_cvtsi128_si32(_mm_srli_epi64(val, 32)); + return (int64)((unsigned)a | ((uint64)(unsigned)b << 32)); + #else + return _mm_cvtsi128_si64(val); + #endif + } + + __m128i val; +}; + +struct v_float64x2 +{ + typedef double lane_type; + typedef __m128d vector_type; + enum { nlanes = 2 }; + + v_float64x2() : val(_mm_setzero_pd()) {} + explicit v_float64x2(__m128d v) : val(v) {} + v_float64x2(double v0, double v1) + { + val = _mm_setr_pd(v0, v1); + } + double get0() const + { + return _mm_cvtsd_f64(val); + } + + __m128d val; +}; + +namespace hal_sse_internal +{ + template + to_sse_type v_sse_reinterpret_as(const from_sse_type& val); + +#define OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(to_sse_type, from_sse_type, sse_cast_intrin) \ + template<> inline \ + to_sse_type v_sse_reinterpret_as(const from_sse_type& a) \ + { return sse_cast_intrin(a); } + + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128i, OPENCV_HAL_NOP) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128, _mm_castps_si128) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128i, __m128d, _mm_castpd_si128) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128i, _mm_castsi128_ps) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128, OPENCV_HAL_NOP) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128, __m128d, _mm_castpd_ps) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128i, _mm_castsi128_pd) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128, _mm_castps_pd) + OPENCV_HAL_IMPL_SSE_REINTERPRET_RAW(__m128d, __m128d, OPENCV_HAL_NOP) +} + +#define OPENCV_HAL_IMPL_SSE_INITVEC(_Tpvec, _Tp, suffix, zsuffix, ssuffix, _Tps, cast) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec(_mm_setzero_##zsuffix()); } \ +inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec(_mm_set1_##ssuffix((_Tps)v)); } \ +template inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0& a) \ +{ return _Tpvec(cast(a.val)); } + +OPENCV_HAL_IMPL_SSE_INITVEC(v_uint8x16, uchar, u8, si128, epi8, schar, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_int8x16, schar, s8, si128, epi8, schar, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_uint16x8, ushort, u16, si128, epi16, short, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_int16x8, short, s16, si128, epi16, short, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_uint32x4, unsigned, u32, si128, epi32, int, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_int32x4, int, s32, si128, epi32, int, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_INITVEC(v_float32x4, float, f32, ps, ps, float, _mm_castsi128_ps) +OPENCV_HAL_IMPL_SSE_INITVEC(v_float64x2, double, f64, pd, pd, double, _mm_castsi128_pd) + +inline v_uint64x2 v_setzero_u64() { return v_uint64x2(_mm_setzero_si128()); } +inline v_int64x2 v_setzero_s64() { return v_int64x2(_mm_setzero_si128()); } +inline v_uint64x2 v_setall_u64(uint64 val) { return v_uint64x2(val, val); } +inline v_int64x2 v_setall_s64(int64 val) { return v_int64x2(val, val); } + +template inline +v_uint64x2 v_reinterpret_as_u64(const _Tpvec& a) { return v_uint64x2(a.val); } +template inline +v_int64x2 v_reinterpret_as_s64(const _Tpvec& a) { return v_int64x2(a.val); } +inline v_float32x4 v_reinterpret_as_f32(const v_uint64x2& a) +{ return v_float32x4(_mm_castsi128_ps(a.val)); } +inline v_float32x4 v_reinterpret_as_f32(const v_int64x2& a) +{ return v_float32x4(_mm_castsi128_ps(a.val)); } +inline v_float64x2 v_reinterpret_as_f64(const v_uint64x2& a) +{ return v_float64x2(_mm_castsi128_pd(a.val)); } +inline v_float64x2 v_reinterpret_as_f64(const v_int64x2& a) +{ return v_float64x2(_mm_castsi128_pd(a.val)); } + +#define OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(_Tpvec, suffix) \ +inline _Tpvec v_reinterpret_as_##suffix(const v_float32x4& a) \ +{ return _Tpvec(_mm_castps_si128(a.val)); } \ +inline _Tpvec v_reinterpret_as_##suffix(const v_float64x2& a) \ +{ return _Tpvec(_mm_castpd_si128(a.val)); } + +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint8x16, u8) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int8x16, s8) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint16x8, u16) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int16x8, s16) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint32x4, u32) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int32x4, s32) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_uint64x2, u64) +OPENCV_HAL_IMPL_SSE_INIT_FROM_FLT(v_int64x2, s64) + +inline v_float32x4 v_reinterpret_as_f32(const v_float32x4& a) {return a; } +inline v_float64x2 v_reinterpret_as_f64(const v_float64x2& a) {return a; } +inline v_float32x4 v_reinterpret_as_f32(const v_float64x2& a) {return v_float32x4(_mm_castpd_ps(a.val)); } +inline v_float64x2 v_reinterpret_as_f64(const v_float32x4& a) {return v_float64x2(_mm_castps_pd(a.val)); } + +//////////////// PACK /////////////// +inline v_uint8x16 v_pack(const v_uint16x8& a, const v_uint16x8& b) +{ + __m128i delta = _mm_set1_epi16(255); + return v_uint8x16(_mm_packus_epi16(_mm_subs_epu16(a.val, _mm_subs_epu16(a.val, delta)), + _mm_subs_epu16(b.val, _mm_subs_epu16(b.val, delta)))); +} + +inline void v_pack_store(uchar* ptr, const v_uint16x8& a) +{ + __m128i delta = _mm_set1_epi16(255); + __m128i a1 = _mm_subs_epu16(a.val, _mm_subs_epu16(a.val, delta)); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a1, a1)); +} + +inline v_uint8x16 v_pack_u(const v_int16x8& a, const v_int16x8& b) +{ return v_uint8x16(_mm_packus_epi16(a.val, b.val)); } + +inline void v_pack_u_store(uchar* ptr, const v_int16x8& a) +{ _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a.val, a.val)); } + +template inline +v_uint8x16 v_rshr_pack(const v_uint16x8& a, const v_uint16x8& b) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + return v_uint8x16(_mm_packus_epi16(_mm_srli_epi16(_mm_adds_epu16(a.val, delta), n), + _mm_srli_epi16(_mm_adds_epu16(b.val, delta), n))); +} + +template inline +void v_rshr_pack_store(uchar* ptr, const v_uint16x8& a) +{ + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + __m128i a1 = _mm_srli_epi16(_mm_adds_epu16(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a1, a1)); +} + +template inline +v_uint8x16 v_rshr_pack_u(const v_int16x8& a, const v_int16x8& b) +{ + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + return v_uint8x16(_mm_packus_epi16(_mm_srai_epi16(_mm_adds_epi16(a.val, delta), n), + _mm_srai_epi16(_mm_adds_epi16(b.val, delta), n))); +} + +template inline +void v_rshr_pack_u_store(uchar* ptr, const v_int16x8& a) +{ + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + __m128i a1 = _mm_srai_epi16(_mm_adds_epi16(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi16(a1, a1)); +} + +inline v_int8x16 v_pack(const v_int16x8& a, const v_int16x8& b) +{ return v_int8x16(_mm_packs_epi16(a.val, b.val)); } + +inline void v_pack_store(schar* ptr, const v_int16x8& a) +{ _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi16(a.val, a.val)); } + +template inline +v_int8x16 v_rshr_pack(const v_int16x8& a, const v_int16x8& b) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + return v_int8x16(_mm_packs_epi16(_mm_srai_epi16(_mm_adds_epi16(a.val, delta), n), + _mm_srai_epi16(_mm_adds_epi16(b.val, delta), n))); +} +template inline +void v_rshr_pack_store(schar* ptr, const v_int16x8& a) +{ + // we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers. + __m128i delta = _mm_set1_epi16((short)(1 << (n-1))); + __m128i a1 = _mm_srai_epi16(_mm_adds_epi16(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi16(a1, a1)); +} + + +// byte-wise "mask ? a : b" +inline __m128i v_select_si128(__m128i mask, __m128i a, __m128i b) +{ +#if CV_SSE4_1 + return _mm_blendv_epi8(b, a, mask); +#else + return _mm_xor_si128(b, _mm_and_si128(_mm_xor_si128(a, b), mask)); +#endif +} + +inline v_uint16x8 v_pack(const v_uint32x4& a, const v_uint32x4& b) +{ return v_uint16x8(_v128_packs_epu32(a.val, b.val)); } + +inline void v_pack_store(ushort* ptr, const v_uint32x4& a) +{ + __m128i z = _mm_setzero_si128(), maxval32 = _mm_set1_epi32(65535), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(v_select_si128(_mm_cmpgt_epi32(z, a.val), maxval32, a.val), delta32); + __m128i r = _mm_packs_epi32(a1, a1); + _mm_storel_epi64((__m128i*)ptr, _mm_sub_epi16(r, _mm_set1_epi16(-32768))); +} + +template inline +v_uint16x8 v_rshr_pack(const v_uint32x4& a, const v_uint32x4& b) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i b1 = _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(b.val, delta), n), delta32); + return v_uint16x8(_mm_sub_epi16(_mm_packs_epi32(a1, b1), _mm_set1_epi16(-32768))); +} + +template inline +void v_rshr_pack_store(ushort* ptr, const v_uint32x4& a) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srli_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + _mm_storel_epi64((__m128i*)ptr, a2); +} + +inline v_uint16x8 v_pack_u(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + return v_uint16x8(_mm_packus_epi32(a.val, b.val)); +#else + __m128i delta32 = _mm_set1_epi32(32768); + + // preliminary saturate negative values to zero + __m128i a1 = _mm_and_si128(a.val, _mm_cmpgt_epi32(a.val, _mm_set1_epi32(0))); + __m128i b1 = _mm_and_si128(b.val, _mm_cmpgt_epi32(b.val, _mm_set1_epi32(0))); + + __m128i r = _mm_packs_epi32(_mm_sub_epi32(a1, delta32), _mm_sub_epi32(b1, delta32)); + return v_uint16x8(_mm_sub_epi16(r, _mm_set1_epi16(-32768))); +#endif +} + +inline void v_pack_u_store(ushort* ptr, const v_int32x4& a) +{ +#if CV_SSE4_1 + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi32(a.val, a.val)); +#else + __m128i delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(a.val, delta32); + __m128i r = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + _mm_storel_epi64((__m128i*)ptr, r); +#endif +} + +template inline +v_uint16x8 v_rshr_pack_u(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + __m128i delta = _mm_set1_epi32(1 << (n - 1)); + return v_uint16x8(_mm_packus_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), + _mm_srai_epi32(_mm_add_epi32(b.val, delta), n))); +#else + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + __m128i b1 = _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(b.val, delta), n), delta32); + __m128i b2 = _mm_sub_epi16(_mm_packs_epi32(b1, b1), _mm_set1_epi16(-32768)); + return v_uint16x8(_mm_unpacklo_epi64(a2, b2)); +#endif +} + +template inline +void v_rshr_pack_u_store(ushort* ptr, const v_int32x4& a) +{ +#if CV_SSE4_1 + __m128i delta = _mm_set1_epi32(1 << (n - 1)); + __m128i a1 = _mm_srai_epi32(_mm_add_epi32(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packus_epi32(a1, a1)); +#else + __m128i delta = _mm_set1_epi32(1 << (n-1)), delta32 = _mm_set1_epi32(32768); + __m128i a1 = _mm_sub_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), delta32); + __m128i a2 = _mm_sub_epi16(_mm_packs_epi32(a1, a1), _mm_set1_epi16(-32768)); + _mm_storel_epi64((__m128i*)ptr, a2); +#endif +} + +inline v_int16x8 v_pack(const v_int32x4& a, const v_int32x4& b) +{ return v_int16x8(_mm_packs_epi32(a.val, b.val)); } + +inline void v_pack_store(short* ptr, const v_int32x4& a) +{ + _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi32(a.val, a.val)); +} + +template inline +v_int16x8 v_rshr_pack(const v_int32x4& a, const v_int32x4& b) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)); + return v_int16x8(_mm_packs_epi32(_mm_srai_epi32(_mm_add_epi32(a.val, delta), n), + _mm_srai_epi32(_mm_add_epi32(b.val, delta), n))); +} + +template inline +void v_rshr_pack_store(short* ptr, const v_int32x4& a) +{ + __m128i delta = _mm_set1_epi32(1 << (n-1)); + __m128i a1 = _mm_srai_epi32(_mm_add_epi32(a.val, delta), n); + _mm_storel_epi64((__m128i*)ptr, _mm_packs_epi32(a1, a1)); +} + + +// [a0 0 | b0 0] [a1 0 | b1 0] +inline v_uint32x4 v_pack(const v_uint64x2& a, const v_uint64x2& b) +{ + __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); // b0 b1 0 0 + return v_uint32x4(_mm_unpacklo_epi32(v0, v1)); +} + +inline void v_pack_store(unsigned* ptr, const v_uint64x2& a) +{ + __m128i a1 = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a1); +} + +// [a0 0 | b0 0] [a1 0 | b1 0] +inline v_int32x4 v_pack(const v_int64x2& a, const v_int64x2& b) +{ + __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); // b0 b1 0 0 + return v_int32x4(_mm_unpacklo_epi32(v0, v1)); +} + +inline void v_pack_store(int* ptr, const v_int64x2& a) +{ + __m128i a1 = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a1); +} + +template inline +v_uint32x4 v_rshr_pack(const v_uint64x2& a, const v_uint64x2& b) +{ + uint64 delta = (uint64)1 << (n-1); + v_uint64x2 delta2(delta, delta); + __m128i a1 = _mm_srli_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i b1 = _mm_srli_epi64(_mm_add_epi64(b.val, delta2.val), n); + __m128i v0 = _mm_unpacklo_epi32(a1, b1); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a1, b1); // b0 b1 0 0 + return v_uint32x4(_mm_unpacklo_epi32(v0, v1)); +} + +template inline +void v_rshr_pack_store(unsigned* ptr, const v_uint64x2& a) +{ + uint64 delta = (uint64)1 << (n-1); + v_uint64x2 delta2(delta, delta); + __m128i a1 = _mm_srli_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i a2 = _mm_shuffle_epi32(a1, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a2); +} + +inline __m128i v_sign_epi64(__m128i a) +{ + return _mm_shuffle_epi32(_mm_srai_epi32(a, 31), _MM_SHUFFLE(3, 3, 1, 1)); // x m0 | x m1 +} + +inline __m128i v_srai_epi64(__m128i a, int imm) +{ + __m128i smask = v_sign_epi64(a); + return _mm_xor_si128(_mm_srli_epi64(_mm_xor_si128(a, smask), imm), smask); +} + +template inline +v_int32x4 v_rshr_pack(const v_int64x2& a, const v_int64x2& b) +{ + int64 delta = (int64)1 << (n-1); + v_int64x2 delta2(delta, delta); + __m128i a1 = v_srai_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i b1 = v_srai_epi64(_mm_add_epi64(b.val, delta2.val), n); + __m128i v0 = _mm_unpacklo_epi32(a1, b1); // a0 a1 0 0 + __m128i v1 = _mm_unpackhi_epi32(a1, b1); // b0 b1 0 0 + return v_int32x4(_mm_unpacklo_epi32(v0, v1)); +} + +template inline +void v_rshr_pack_store(int* ptr, const v_int64x2& a) +{ + int64 delta = (int64)1 << (n-1); + v_int64x2 delta2(delta, delta); + __m128i a1 = v_srai_epi64(_mm_add_epi64(a.val, delta2.val), n); + __m128i a2 = _mm_shuffle_epi32(a1, _MM_SHUFFLE(0, 2, 2, 0)); + _mm_storel_epi64((__m128i*)ptr, a2); +} + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + __m128i ab = _mm_packs_epi16(a.val, b.val); + return v_uint8x16(ab); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + __m128i ab = _mm_packs_epi32(a.val, b.val); + __m128i cd = _mm_packs_epi32(c.val, d.val); + return v_uint8x16(_mm_packs_epi16(ab, cd)); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + __m128i ab = _mm_packs_epi32(a.val, b.val); + __m128i cd = _mm_packs_epi32(c.val, d.val); + __m128i ef = _mm_packs_epi32(e.val, f.val); + __m128i gh = _mm_packs_epi32(g.val, h.val); + + __m128i abcd = _mm_packs_epi32(ab, cd); + __m128i efgh = _mm_packs_epi32(ef, gh); + return v_uint8x16(_mm_packs_epi16(abcd, efgh)); +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + __m128 v0 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(0, 0, 0, 0)), m0.val); + __m128 v1 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(1, 1, 1, 1)), m1.val); + __m128 v2 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(2, 2, 2, 2)), m2.val); + __m128 v3 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(3, 3, 3, 3)), m3.val); + + return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, v3))); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + __m128 v0 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(0, 0, 0, 0)), m0.val); + __m128 v1 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(1, 1, 1, 1)), m1.val); + __m128 v2 = _mm_mul_ps(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE(2, 2, 2, 2)), m2.val); + + return v_float32x4(_mm_add_ps(_mm_add_ps(v0, v1), _mm_add_ps(v2, a.val))); +} + +#define OPENCV_HAL_IMPL_SSE_BIN_OP(bin_op, _Tpvec, intrin) \ + inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ + { \ + return _Tpvec(intrin(a.val, b.val)); \ + } \ + inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ + { \ + a.val = intrin(a.val, b.val); \ + return a; \ + } + +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint8x16, _mm_adds_epu8) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint8x16, _mm_subs_epu8) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int8x16, _mm_adds_epi8) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int8x16, _mm_subs_epi8) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint16x8, _mm_adds_epu16) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint16x8, _mm_subs_epu16) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int16x8, _mm_adds_epi16) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int16x8, _mm_subs_epi16) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint32x4, _mm_add_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint32x4, _mm_sub_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_uint32x4, _v128_mullo_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int32x4, _mm_add_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int32x4, _mm_sub_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_int32x4, _v128_mullo_epi32) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_float32x4, _mm_add_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_float32x4, _mm_sub_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_float32x4, _mm_mul_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(/, v_float32x4, _mm_div_ps) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_float64x2, _mm_add_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_float64x2, _mm_sub_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(*, v_float64x2, _mm_mul_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(/, v_float64x2, _mm_div_pd) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_uint64x2, _mm_add_epi64) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_uint64x2, _mm_sub_epi64) +OPENCV_HAL_IMPL_SSE_BIN_OP(+, v_int64x2, _mm_add_epi64) +OPENCV_HAL_IMPL_SSE_BIN_OP(-, v_int64x2, _mm_sub_epi64) + +// saturating multiply 8-bit, 16-bit +#define OPENCV_HAL_IMPL_SSE_MUL_SAT(_Tpvec, _Tpwvec) \ + inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ + { \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ + } \ + inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ + { a = a * b; return a; } + +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_uint16x8, v_uint32x4) +OPENCV_HAL_IMPL_SSE_MUL_SAT(v_int16x8, v_int32x4) + +// Multiply and expand +inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, + v_uint16x8& c, v_uint16x8& d) +{ + v_uint16x8 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, + v_int16x8& c, v_int16x8& d) +{ + v_int16x8 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, + v_int32x4& c, v_int32x4& d) +{ + __m128i v0 = _mm_mullo_epi16(a.val, b.val); + __m128i v1 = _mm_mulhi_epi16(a.val, b.val); + c.val = _mm_unpacklo_epi16(v0, v1); + d.val = _mm_unpackhi_epi16(v0, v1); +} + +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, + v_uint32x4& c, v_uint32x4& d) +{ + __m128i v0 = _mm_mullo_epi16(a.val, b.val); + __m128i v1 = _mm_mulhi_epu16(a.val, b.val); + c.val = _mm_unpacklo_epi16(v0, v1); + d.val = _mm_unpackhi_epi16(v0, v1); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, + v_uint64x2& c, v_uint64x2& d) +{ + __m128i c0 = _mm_mul_epu32(a.val, b.val); + __m128i c1 = _mm_mul_epu32(_mm_srli_epi64(a.val, 32), _mm_srli_epi64(b.val, 32)); + c.val = _mm_unpacklo_epi64(c0, c1); + d.val = _mm_unpackhi_epi64(c0, c1); +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) { return v_int16x8(_mm_mulhi_epi16(a.val, b.val)); } +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) { return v_uint16x8(_mm_mulhi_epu16(a.val, b.val)); } + +//////// Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ return v_int32x4(_mm_madd_epi16(a.val, b.val)); } +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_dotprod(a, b) + c; } + +// 32 >> 64 +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + __m128i even = _mm_mul_epi32(a.val, b.val); + __m128i odd = _mm_mul_epi32(_mm_srli_epi64(a.val, 32), _mm_srli_epi64(b.val, 32)); + return v_int64x2(_mm_add_epi64(even, odd)); +#else + __m128i even_u = _mm_mul_epu32(a.val, b.val); + __m128i odd_u = _mm_mul_epu32(_mm_srli_epi64(a.val, 32), _mm_srli_epi64(b.val, 32)); + // convert unsigned to signed high multiplication (from: Agner Fog(veclib) and H S Warren: Hacker's delight, 2003, p. 132) + __m128i a_sign = _mm_srai_epi32(a.val, 31); + __m128i b_sign = _mm_srai_epi32(b.val, 31); + // |x * sign of x + __m128i axb = _mm_and_si128(a.val, b_sign); + __m128i bxa = _mm_and_si128(b.val, a_sign); + // sum of sign corrections + __m128i ssum = _mm_add_epi32(bxa, axb); + __m128i even_ssum = _mm_slli_epi64(ssum, 32); + __m128i odd_ssum = _mm_and_si128(ssum, _mm_set_epi32(-1, 0, -1, 0)); + // convert to signed and prod + return v_int64x2(_mm_add_epi64(_mm_sub_epi64(even_u, even_ssum), _mm_sub_epi64(odd_u, odd_ssum))); +#endif +} +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ return v_dotprod(a, b) + c; } + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b) +{ + __m128i a0 = _mm_srli_epi16(_mm_slli_si128(a.val, 1), 8); // even + __m128i a1 = _mm_srli_epi16(a.val, 8); // odd + __m128i b0 = _mm_srli_epi16(_mm_slli_si128(b.val, 1), 8); + __m128i b1 = _mm_srli_epi16(b.val, 8); + __m128i p0 = _mm_madd_epi16(a0, b0); + __m128i p1 = _mm_madd_epi16(a1, b1); + return v_uint32x4(_mm_add_epi32(p0, p1)); +} +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b) +{ + __m128i a0 = _mm_srai_epi16(_mm_slli_si128(a.val, 1), 8); // even + __m128i a1 = _mm_srai_epi16(a.val, 8); // odd + __m128i b0 = _mm_srai_epi16(_mm_slli_si128(b.val, 1), 8); + __m128i b1 = _mm_srai_epi16(b.val, 8); + __m128i p0 = _mm_madd_epi16(a0, b0); + __m128i p1 = _mm_madd_epi16(a1, b1); + return v_int32x4(_mm_add_epi32(p0, p1)); +} +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ return v_dotprod_expand(a, b) + c; } + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint32x4 c, d; + v_mul_expand(a, b, c, d); + + v_uint64x2 c0, c1, d0, d1; + v_expand(c, c0, c1); + v_expand(d, d0, d1); + + c0 += c1; d0 += d1; + return v_uint64x2(_mm_add_epi64( + _mm_unpacklo_epi64(c0.val, d0.val), + _mm_unpackhi_epi64(c0.val, d0.val) + )); +} +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b) +{ + v_int32x4 prod = v_dotprod(a, b); + v_int64x2 c, d; + v_expand(prod, c, d); + return v_int64x2(_mm_add_epi64( + _mm_unpacklo_epi64(c.val, d.val), + _mm_unpackhi_epi64(c.val, d.val) + )); +} +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +// 32 >> 64f +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + return v_cvt_f64(v_dotprod(a, b)); +#else + v_float64x2 c = v_cvt_f64(a) * v_cvt_f64(b); + v_float64x2 d = v_cvt_f64_high(a) * v_cvt_f64_high(b); + + return v_float64x2(_mm_add_pd( + _mm_unpacklo_pd(c.val, d.val), + _mm_unpackhi_pd(c.val, d.val) + )); +#endif +} +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) +{ return v_dotprod(a, b); } +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_dotprod(a, b) + c; } + +// 32 >> 64 +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_dotprod(a, b); } +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ return v_dotprod_fast(a, b) + c; } + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b) +{ + __m128i a0 = v_expand_low(a).val; + __m128i a1 = v_expand_high(a).val; + __m128i b0 = v_expand_low(b).val; + __m128i b1 = v_expand_high(b).val; + __m128i p0 = _mm_madd_epi16(a0, b0); + __m128i p1 = _mm_madd_epi16(a1, b1); + return v_uint32x4(_mm_add_epi32(p0, p1)); +} +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b) +{ +#if CV_SSE4_1 + __m128i a0 = _mm_cvtepi8_epi16(a.val); + __m128i a1 = v_expand_high(a).val; + __m128i b0 = _mm_cvtepi8_epi16(b.val); + __m128i b1 = v_expand_high(b).val; + __m128i p0 = _mm_madd_epi16(a0, b0); + __m128i p1 = _mm_madd_epi16(a1, b1); + return v_int32x4(_mm_add_epi32(p0, p1)); +#else + return v_dotprod_expand(a, b); +#endif +} +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint32x4 c, d; + v_mul_expand(a, b, c, d); + + v_uint64x2 c0, c1, d0, d1; + v_expand(c, c0, c1); + v_expand(d, d0, d1); + + c0 += c1; d0 += d1; + return c0 + d0; +} +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b) +{ + v_int32x4 prod = v_dotprod(a, b); + v_int64x2 c, d; + v_expand(prod, c, d); + return c + d; +} +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +// 32 >> 64f +v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c); +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_fma(v_cvt_f64(a), v_cvt_f64(b), v_cvt_f64_high(a) * v_cvt_f64_high(b)); } +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_fma(v_cvt_f64(a), v_cvt_f64(b), v_fma(v_cvt_f64_high(a), v_cvt_f64_high(b), c)); } + +#define OPENCV_HAL_IMPL_SSE_LOGIC_OP(_Tpvec, suffix, not_const) \ + OPENCV_HAL_IMPL_SSE_BIN_OP(&, _Tpvec, _mm_and_##suffix) \ + OPENCV_HAL_IMPL_SSE_BIN_OP(|, _Tpvec, _mm_or_##suffix) \ + OPENCV_HAL_IMPL_SSE_BIN_OP(^, _Tpvec, _mm_xor_##suffix) \ + inline _Tpvec operator ~ (const _Tpvec& a) \ + { \ + return _Tpvec(_mm_xor_##suffix(a.val, not_const)); \ + } + +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint8x16, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int8x16, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint16x8, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int16x8, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint32x4, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int32x4, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_uint64x2, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_int64x2, si128, _mm_set1_epi32(-1)) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_float32x4, ps, _mm_castsi128_ps(_mm_set1_epi32(-1))) +OPENCV_HAL_IMPL_SSE_LOGIC_OP(v_float64x2, pd, _mm_castsi128_pd(_mm_set1_epi32(-1))) + +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ return v_float32x4(_mm_sqrt_ps(x.val)); } + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ + const __m128 _0_5 = _mm_set1_ps(0.5f), _1_5 = _mm_set1_ps(1.5f); + __m128 t = x.val; + __m128 h = _mm_mul_ps(t, _0_5); + t = _mm_rsqrt_ps(t); + t = _mm_mul_ps(t, _mm_sub_ps(_1_5, _mm_mul_ps(_mm_mul_ps(t, t), h))); + return v_float32x4(t); +} + +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ return v_float64x2(_mm_sqrt_pd(x.val)); } + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ + const __m128d v_1 = _mm_set1_pd(1.); + return v_float64x2(_mm_div_pd(v_1, _mm_sqrt_pd(x.val))); +} + +#define OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(_Tpuvec, _Tpsvec, func, suffix, subWidth) \ +inline _Tpuvec v_abs(const _Tpsvec& x) \ +{ return _Tpuvec(_mm_##func##_ep##suffix(x.val, _mm_sub_ep##subWidth(_mm_setzero_si128(), x.val))); } + +OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint8x16, v_int8x16, min, u8, i8) +OPENCV_HAL_IMPL_SSE_ABS_INT_FUNC(v_uint16x8, v_int16x8, max, i16, i16) +inline v_uint32x4 v_abs(const v_int32x4& x) +{ + __m128i s = _mm_srli_epi32(x.val, 31); + __m128i f = _mm_srai_epi32(x.val, 31); + return v_uint32x4(_mm_add_epi32(_mm_xor_si128(x.val, f), s)); +} +inline v_float32x4 v_abs(const v_float32x4& x) +{ return v_float32x4(_mm_and_ps(x.val, _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff)))); } +inline v_float64x2 v_abs(const v_float64x2& x) +{ + return v_float64x2(_mm_and_pd(x.val, + _mm_castsi128_pd(_mm_srli_epi64(_mm_set1_epi32(-1), 1)))); +} + +// TODO: exp, log, sin, cos + +#define OPENCV_HAL_IMPL_SSE_BIN_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_min, _mm_min_epu8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_max, _mm_max_epu8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_min, _mm_min_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_max, _mm_max_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float32x4, v_min, _mm_min_ps) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float32x4, v_max, _mm_max_ps) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float64x2, v_min, _mm_min_pd) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_float64x2, v_max, _mm_max_pd) + +inline v_int8x16 v_min(const v_int8x16& a, const v_int8x16& b) +{ +#if CV_SSE4_1 + return v_int8x16(_mm_min_epi8(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi8((char)-128); + return v_int8x16(_mm_xor_si128(delta, _mm_min_epu8(_mm_xor_si128(a.val, delta), + _mm_xor_si128(b.val, delta)))); +#endif +} +inline v_int8x16 v_max(const v_int8x16& a, const v_int8x16& b) +{ +#if CV_SSE4_1 + return v_int8x16(_mm_max_epi8(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi8((char)-128); + return v_int8x16(_mm_xor_si128(delta, _mm_max_epu8(_mm_xor_si128(a.val, delta), + _mm_xor_si128(b.val, delta)))); +#endif +} +inline v_uint16x8 v_min(const v_uint16x8& a, const v_uint16x8& b) +{ +#if CV_SSE4_1 + return v_uint16x8(_mm_min_epu16(a.val, b.val)); +#else + return v_uint16x8(_mm_subs_epu16(a.val, _mm_subs_epu16(a.val, b.val))); +#endif +} +inline v_uint16x8 v_max(const v_uint16x8& a, const v_uint16x8& b) +{ +#if CV_SSE4_1 + return v_uint16x8(_mm_max_epu16(a.val, b.val)); +#else + return v_uint16x8(_mm_adds_epu16(_mm_subs_epu16(a.val, b.val), b.val)); +#endif +} +inline v_uint32x4 v_min(const v_uint32x4& a, const v_uint32x4& b) +{ +#if CV_SSE4_1 + return v_uint32x4(_mm_min_epu32(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi32((int)0x80000000); + __m128i mask = _mm_cmpgt_epi32(_mm_xor_si128(a.val, delta), _mm_xor_si128(b.val, delta)); + return v_uint32x4(v_select_si128(mask, b.val, a.val)); +#endif +} +inline v_uint32x4 v_max(const v_uint32x4& a, const v_uint32x4& b) +{ +#if CV_SSE4_1 + return v_uint32x4(_mm_max_epu32(a.val, b.val)); +#else + __m128i delta = _mm_set1_epi32((int)0x80000000); + __m128i mask = _mm_cmpgt_epi32(_mm_xor_si128(a.val, delta), _mm_xor_si128(b.val, delta)); + return v_uint32x4(v_select_si128(mask, a.val, b.val)); +#endif +} +inline v_int32x4 v_min(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + return v_int32x4(_mm_min_epi32(a.val, b.val)); +#else + return v_int32x4(v_select_si128(_mm_cmpgt_epi32(a.val, b.val), b.val, a.val)); +#endif +} +inline v_int32x4 v_max(const v_int32x4& a, const v_int32x4& b) +{ +#if CV_SSE4_1 + return v_int32x4(_mm_max_epi32(a.val, b.val)); +#else + return v_int32x4(v_select_si128(_mm_cmpgt_epi32(a.val, b.val), a.val, b.val)); +#endif +} + +#define OPENCV_HAL_IMPL_SSE_INT_CMP_OP(_Tpuvec, _Tpsvec, suffix, sbit) \ +inline _Tpuvec operator == (const _Tpuvec& a, const _Tpuvec& b) \ +{ return _Tpuvec(_mm_cmpeq_##suffix(a.val, b.val)); } \ +inline _Tpuvec operator != (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpuvec(_mm_xor_si128(_mm_cmpeq_##suffix(a.val, b.val), not_mask)); \ +} \ +inline _Tpsvec operator == (const _Tpsvec& a, const _Tpsvec& b) \ +{ return _Tpsvec(_mm_cmpeq_##suffix(a.val, b.val)); } \ +inline _Tpsvec operator != (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpsvec(_mm_xor_si128(_mm_cmpeq_##suffix(a.val, b.val), not_mask)); \ +} \ +inline _Tpuvec operator < (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + return _Tpuvec(_mm_cmpgt_##suffix(_mm_xor_si128(b.val, smask), _mm_xor_si128(a.val, smask))); \ +} \ +inline _Tpuvec operator > (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + return _Tpuvec(_mm_cmpgt_##suffix(_mm_xor_si128(a.val, smask), _mm_xor_si128(b.val, smask))); \ +} \ +inline _Tpuvec operator <= (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + __m128i not_mask = _mm_set1_epi32(-1); \ + __m128i res = _mm_cmpgt_##suffix(_mm_xor_si128(a.val, smask), _mm_xor_si128(b.val, smask)); \ + return _Tpuvec(_mm_xor_si128(res, not_mask)); \ +} \ +inline _Tpuvec operator >= (const _Tpuvec& a, const _Tpuvec& b) \ +{ \ + __m128i smask = _mm_set1_##suffix(sbit); \ + __m128i not_mask = _mm_set1_epi32(-1); \ + __m128i res = _mm_cmpgt_##suffix(_mm_xor_si128(b.val, smask), _mm_xor_si128(a.val, smask)); \ + return _Tpuvec(_mm_xor_si128(res, not_mask)); \ +} \ +inline _Tpsvec operator < (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + return _Tpsvec(_mm_cmpgt_##suffix(b.val, a.val)); \ +} \ +inline _Tpsvec operator > (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + return _Tpsvec(_mm_cmpgt_##suffix(a.val, b.val)); \ +} \ +inline _Tpsvec operator <= (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpsvec(_mm_xor_si128(_mm_cmpgt_##suffix(a.val, b.val), not_mask)); \ +} \ +inline _Tpsvec operator >= (const _Tpsvec& a, const _Tpsvec& b) \ +{ \ + __m128i not_mask = _mm_set1_epi32(-1); \ + return _Tpsvec(_mm_xor_si128(_mm_cmpgt_##suffix(b.val, a.val), not_mask)); \ +} + +OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint8x16, v_int8x16, epi8, (char)-128) +OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint16x8, v_int16x8, epi16, (short)-32768) +OPENCV_HAL_IMPL_SSE_INT_CMP_OP(v_uint32x4, v_int32x4, epi32, (int)0x80000000) + +#define OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(_Tpvec, suffix) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpeq_##suffix(a.val, b.val)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpneq_##suffix(a.val, b.val)); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmplt_##suffix(a.val, b.val)); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpgt_##suffix(a.val, b.val)); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmple_##suffix(a.val, b.val)); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpge_##suffix(a.val, b.val)); } + +OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float32x4, ps) +OPENCV_HAL_IMPL_SSE_FLT_CMP_OP(v_float64x2, pd) + +#if CV_SSE4_1 +#define OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(_Tpvec) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(_mm_cmpeq_epi64(a.val, b.val)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return ~(a == b); } +#else +#define OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(_Tpvec) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ __m128i cmp = _mm_cmpeq_epi32(a.val, b.val); \ + return _Tpvec(_mm_and_si128(cmp, _mm_shuffle_epi32(cmp, _MM_SHUFFLE(2, 3, 0, 1)))); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return ~(a == b); } +#endif + +OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_uint64x2) +OPENCV_HAL_IMPL_SSE_64BIT_CMP_OP(v_int64x2) + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return v_float32x4(_mm_cmpord_ps(a.val, a.val)); } +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return v_float64x2(_mm_cmpord_pd(a.val, a.val)); } + +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_add_wrap, _mm_add_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int8x16, v_add_wrap, _mm_add_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_add_wrap, _mm_add_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_add_wrap, _mm_add_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint8x16, v_sub_wrap, _mm_sub_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int8x16, v_sub_wrap, _mm_sub_epi8) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_sub_wrap, _mm_sub_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_sub_wrap, _mm_sub_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_uint16x8, v_mul_wrap, _mm_mullo_epi16) +OPENCV_HAL_IMPL_SSE_BIN_FUNC(v_int16x8, v_mul_wrap, _mm_mullo_epi16) + +inline v_uint8x16 v_mul_wrap(const v_uint8x16& a, const v_uint8x16& b) +{ + __m128i ad = _mm_srai_epi16(a.val, 8); + __m128i bd = _mm_srai_epi16(b.val, 8); + __m128i p0 = _mm_mullo_epi16(a.val, b.val); // even + __m128i p1 = _mm_slli_epi16(_mm_mullo_epi16(ad, bd), 8); // odd + const __m128i b01 = _mm_set1_epi32(0xFF00FF00); + return v_uint8x16(_v128_blendv_epi8(p0, p1, b01)); +} +inline v_int8x16 v_mul_wrap(const v_int8x16& a, const v_int8x16& b) +{ + return v_reinterpret_as_s8(v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b))); +} + +/** Absolute difference **/ + +inline v_uint8x16 v_absdiff(const v_uint8x16& a, const v_uint8x16& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint16x8 v_absdiff(const v_uint16x8& a, const v_uint16x8& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint32x4 v_absdiff(const v_uint32x4& a, const v_uint32x4& b) +{ return v_max(a, b) - v_min(a, b); } + +inline v_uint8x16 v_absdiff(const v_int8x16& a, const v_int8x16& b) +{ + v_int8x16 d = v_sub_wrap(a, b); + v_int8x16 m = a < b; + return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m)); +} +inline v_uint16x8 v_absdiff(const v_int16x8& a, const v_int16x8& b) +{ + return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); +} +inline v_uint32x4 v_absdiff(const v_int32x4& a, const v_int32x4& b) +{ + v_int32x4 d = a - b; + v_int32x4 m = a < b; + return v_reinterpret_as_u32((d ^ m) - m); +} + +/** Saturating absolute difference **/ +inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b) +{ + v_int8x16 d = a - b; + v_int8x16 m = a < b; + return (d ^ m) - m; + } +inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b) +{ return v_max(a, b) - v_min(a, b); } + + +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return a * b + c; +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ +#if CV_FMA3 + return v_float32x4(_mm_fmadd_ps(a.val, b.val, c.val)); +#else + return v_float32x4(_mm_add_ps(_mm_mul_ps(a.val, b.val), c.val)); +#endif +} + +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ +#if CV_FMA3 + return v_float64x2(_mm_fmadd_pd(a.val, b.val, c.val)); +#else + return v_float64x2(_mm_add_pd(_mm_mul_pd(a.val, b.val), c.val)); +#endif +} + +#define OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(_Tpvec, _Tp, _Tpreg, suffix, absmask_vec) \ +inline _Tpvec v_absdiff(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpreg absmask = _mm_castsi128_##suffix(absmask_vec); \ + return _Tpvec(_mm_and_##suffix(_mm_sub_##suffix(a.val, b.val), absmask)); \ +} \ +inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpvec res = v_fma(a, a, b*b); \ + return _Tpvec(_mm_sqrt_##suffix(res.val)); \ +} \ +inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return v_fma(a, a, b*b); \ +} \ +inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ \ + return v_fma(a, b, c); \ +} + +OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(v_float32x4, float, __m128, ps, _mm_set1_epi32((int)0x7fffffff)) +OPENCV_HAL_IMPL_SSE_MISC_FLT_OP(v_float64x2, double, __m128d, pd, _mm_srli_epi64(_mm_set1_epi32(-1), 1)) + +#define OPENCV_HAL_IMPL_SSE_SHIFT_OP(_Tpuvec, _Tpsvec, suffix, srai) \ +inline _Tpuvec operator << (const _Tpuvec& a, int imm) \ +{ \ + return _Tpuvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +inline _Tpsvec operator << (const _Tpsvec& a, int imm) \ +{ \ + return _Tpsvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \ +{ \ + return _Tpuvec(_mm_srli_##suffix(a.val, imm)); \ +} \ +inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \ +{ \ + return _Tpsvec(srai(a.val, imm)); \ +} \ +template \ +inline _Tpuvec v_shl(const _Tpuvec& a) \ +{ \ + return _Tpuvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +template \ +inline _Tpsvec v_shl(const _Tpsvec& a) \ +{ \ + return _Tpsvec(_mm_slli_##suffix(a.val, imm)); \ +} \ +template \ +inline _Tpuvec v_shr(const _Tpuvec& a) \ +{ \ + return _Tpuvec(_mm_srli_##suffix(a.val, imm)); \ +} \ +template \ +inline _Tpsvec v_shr(const _Tpsvec& a) \ +{ \ + return _Tpsvec(srai(a.val, imm)); \ +} + +OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint16x8, v_int16x8, epi16, _mm_srai_epi16) +OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint32x4, v_int32x4, epi32, _mm_srai_epi32) +OPENCV_HAL_IMPL_SSE_SHIFT_OP(v_uint64x2, v_int64x2, epi64, v_srai_epi64) + +namespace hal_sse_internal +{ + template 16)), + bool is_first = (imm == 0), + bool is_half = (imm == 8), + bool is_second = (imm == 16), + bool is_other = (((imm > 0) && (imm < 8)) || ((imm > 8) && (imm < 16)))> + class v_sse_palignr_u8_class; + + template + class v_sse_palignr_u8_class; + + template + class v_sse_palignr_u8_class + { + public: + inline __m128i operator()(const __m128i& a, const __m128i&) const + { + return a; + } + }; + + template + class v_sse_palignr_u8_class + { + public: + inline __m128i operator()(const __m128i& a, const __m128i& b) const + { + return _mm_unpacklo_epi64(_mm_unpackhi_epi64(a, a), b); + } + }; + + template + class v_sse_palignr_u8_class + { + public: + inline __m128i operator()(const __m128i&, const __m128i& b) const + { + return b; + } + }; + + template + class v_sse_palignr_u8_class + { +#if CV_SSSE3 + public: + inline __m128i operator()(const __m128i& a, const __m128i& b) const + { + return _mm_alignr_epi8(b, a, imm); + } +#else + public: + inline __m128i operator()(const __m128i& a, const __m128i& b) const + { + enum { imm2 = (sizeof(__m128i) - imm) }; + return _mm_or_si128(_mm_srli_si128(a, imm), _mm_slli_si128(b, imm2)); + } +#endif + }; + + template + inline __m128i v_sse_palignr_u8(const __m128i& a, const __m128i& b) + { + CV_StaticAssert((imm >= 0) && (imm <= 16), "Invalid imm for v_sse_palignr_u8."); + return v_sse_palignr_u8_class()(a, b); + } +} + +template +inline _Tpvec v_rotate_right(const _Tpvec &a) +{ + using namespace hal_sse_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as( + _mm_srli_si128( + v_sse_reinterpret_as<__m128i>(a.val), imm2))); +} + +template +inline _Tpvec v_rotate_left(const _Tpvec &a) +{ + using namespace hal_sse_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as( + _mm_slli_si128( + v_sse_reinterpret_as<__m128i>(a.val), imm2))); +} + +template +inline _Tpvec v_rotate_right(const _Tpvec &a, const _Tpvec &b) +{ + using namespace hal_sse_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as( + v_sse_palignr_u8( + v_sse_reinterpret_as<__m128i>(a.val), + v_sse_reinterpret_as<__m128i>(b.val)))); +} + +template +inline _Tpvec v_rotate_left(const _Tpvec &a, const _Tpvec &b) +{ + using namespace hal_sse_internal; + enum { imm2 = ((_Tpvec::nlanes - imm) * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_sse_reinterpret_as( + v_sse_palignr_u8( + v_sse_reinterpret_as<__m128i>(b.val), + v_sse_reinterpret_as<__m128i>(a.val)))); +} + +#define OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(_Tpvec, _Tp) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(_mm_loadu_si128((const __m128i*)ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(_mm_load_si128((const __m128i*)ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(_mm_loadl_epi64((const __m128i*)ptr)); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ \ + return _Tpvec(_mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i*)ptr0), \ + _mm_loadl_epi64((const __m128i*)ptr1))); \ +} \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storeu_si128((__m128i*)ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ _mm_store_si128((__m128i*)ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ _mm_stream_si128((__m128i*)ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ +{ \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm_storeu_si128((__m128i*)ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm_stream_si128((__m128i*)ptr, a.val); \ + else \ + _mm_store_si128((__m128i*)ptr, a.val); \ +} \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storel_epi64((__m128i*)ptr, a.val); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storel_epi64((__m128i*)ptr, _mm_unpackhi_epi64(a.val, a.val)); } + +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint8x16, uchar) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int8x16, schar) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint16x8, ushort) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int16x8, short) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int32x4, int) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_uint64x2, uint64) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INT_OP(v_int64x2, int64) + +#define OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(_mm_loadu_##suffix(ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(_mm_load_##suffix(ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(_mm_castsi128_##suffix(_mm_loadl_epi64((const __m128i*)ptr))); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ \ + return _Tpvec(_mm_castsi128_##suffix( \ + _mm_unpacklo_epi64(_mm_loadl_epi64((const __m128i*)ptr0), \ + _mm_loadl_epi64((const __m128i*)ptr1)))); \ +} \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storeu_##suffix(ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ _mm_store_##suffix(ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ _mm_stream_##suffix(ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ +{ \ + if( mode == hal::STORE_UNALIGNED ) \ + _mm_storeu_##suffix(ptr, a.val); \ + else if( mode == hal::STORE_ALIGNED_NOCACHE ) \ + _mm_stream_##suffix(ptr, a.val); \ + else \ + _mm_store_##suffix(ptr, a.val); \ +} \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ _mm_storel_epi64((__m128i*)ptr, _mm_cast##suffix##_si128(a.val)); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ \ + __m128i a1 = _mm_cast##suffix##_si128(a.val); \ + _mm_storel_epi64((__m128i*)ptr, _mm_unpackhi_epi64(a1, a1)); \ +} + +OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float32x4, float, ps) +OPENCV_HAL_IMPL_SSE_LOADSTORE_FLT_OP(v_float64x2, double, pd) + +inline unsigned v_reduce_sum(const v_uint8x16& a) +{ + __m128i half = _mm_sad_epu8(a.val, _mm_setzero_si128()); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(half, _mm_unpackhi_epi64(half, half))); +} +inline int v_reduce_sum(const v_int8x16& a) +{ + __m128i half = _mm_set1_epi8((schar)-128); + half = _mm_sad_epu8(_mm_xor_si128(a.val, half), _mm_setzero_si128()); + return _mm_cvtsi128_si32(_mm_add_epi32(half, _mm_unpackhi_epi64(half, half))) - 2048; +} +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_16(func) \ +inline schar v_reduce_##func(const v_int8x16& a) \ +{ \ + __m128i val = a.val; \ + __m128i smask = _mm_set1_epi8((schar)-128); \ + val = _mm_xor_si128(val, smask); \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,2)); \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,1)); \ + return (schar)_mm_cvtsi128_si32(val) ^ (schar)-128; \ +} \ +inline uchar v_reduce_##func(const v_uint8x16& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,2)); \ + val = _mm_##func##_epu8(val, _mm_srli_si128(val,1)); \ + return (uchar)_mm_cvtsi128_si32(val); \ +} +OPENCV_HAL_IMPL_SSE_REDUCE_OP_16(max) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_16(min) + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(_Tpvec, scalartype, func, suffix, sbit) \ +inline scalartype v_reduce_##func(const v_##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \ + return (scalartype)_mm_cvtsi128_si32(val); \ +} \ +inline unsigned scalartype v_reduce_##func(const v_u##_Tpvec& a) \ +{ \ + __m128i val = a.val; \ + __m128i smask = _mm_set1_epi16(sbit); \ + val = _mm_xor_si128(val, smask); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,8)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,4)); \ + val = _mm_##func##_##suffix(val, _mm_srli_si128(val,2)); \ + return (unsigned scalartype)(_mm_cvtsi128_si32(val) ^ sbit); \ +} +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, max, epi16, (short)-32768) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_8(int16x8, short, min, epi16, (short)-32768) + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(_Tpvec, scalartype, regtype, suffix, cast_from, cast_to, extract) \ +inline scalartype v_reduce_sum(const _Tpvec& a) \ +{ \ + regtype val = a.val; \ + val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 8))); \ + val = _mm_add_##suffix(val, cast_to(_mm_srli_si128(cast_from(val), 4))); \ + return (scalartype)_mm_cvt##extract(val); \ +} + +#define OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(_Tpvec, scalartype, func, scalar_func) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + scalartype CV_DECL_ALIGNED(16) buf[4]; \ + v_store_aligned(buf, a); \ + scalartype s0 = scalar_func(buf[0], buf[1]); \ + scalartype s1 = scalar_func(buf[2], buf[3]); \ + return scalar_func(s0, s1); \ +} + +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_uint32x4, unsigned, __m128i, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_int32x4, int, __m128i, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP, si128_si32) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4_SUM(v_float32x4, float, __m128, ps, _mm_castps_si128, _mm_castsi128_ps, ss_f32) + +inline int v_reduce_sum(const v_int16x8& a) +{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); } +inline unsigned v_reduce_sum(const v_uint16x8& a) +{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); } + +inline uint64 v_reduce_sum(const v_uint64x2& a) +{ + uint64 CV_DECL_ALIGNED(32) idx[2]; + v_store_aligned(idx, a); + return idx[0] + idx[1]; +} +inline int64 v_reduce_sum(const v_int64x2& a) +{ + int64 CV_DECL_ALIGNED(32) idx[2]; + v_store_aligned(idx, a); + return idx[0] + idx[1]; +} +inline double v_reduce_sum(const v_float64x2& a) +{ + double CV_DECL_ALIGNED(32) idx[2]; + v_store_aligned(idx, a); + return idx[0] + idx[1]; +} + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ +#if CV_SSE3 + __m128 ab = _mm_hadd_ps(a.val, b.val); + __m128 cd = _mm_hadd_ps(c.val, d.val); + return v_float32x4(_mm_hadd_ps(ab, cd)); +#else + __m128 ac = _mm_add_ps(_mm_unpacklo_ps(a.val, c.val), _mm_unpackhi_ps(a.val, c.val)); + __m128 bd = _mm_add_ps(_mm_unpacklo_ps(b.val, d.val), _mm_unpackhi_ps(b.val, d.val)); + return v_float32x4(_mm_add_ps(_mm_unpacklo_ps(ac, bd), _mm_unpackhi_ps(ac, bd))); +#endif +} + +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, max, std::max) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_int32x4, int, min, std::min) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, max, std::max) +OPENCV_HAL_IMPL_SSE_REDUCE_OP_4(v_float32x4, float, min, std::min) + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + __m128i half = _mm_sad_epu8(a.val, b.val); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(half, _mm_unpackhi_epi64(half, half))); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + __m128i half = _mm_set1_epi8(0x7f); + half = _mm_sad_epu8(_mm_add_epi8(a.val, half), _mm_add_epi8(b.val, half)); + return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(half, _mm_unpackhi_epi64(half, half))); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint32x4 l, h; + v_expand(v_absdiff(a, b), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + v_uint32x4 l, h; + v_expand(v_absdiff(a, b), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} + +inline v_uint8x16 v_popcount(const v_uint8x16& a) +{ + __m128i m1 = _mm_set1_epi32(0x55555555); + __m128i m2 = _mm_set1_epi32(0x33333333); + __m128i m4 = _mm_set1_epi32(0x0f0f0f0f); + __m128i p = a.val; + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 1), m1), _mm_and_si128(p, m1)); + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 2), m2), _mm_and_si128(p, m2)); + p = _mm_add_epi32(_mm_and_si128(_mm_srli_epi32(p, 4), m4), _mm_and_si128(p, m4)); + return v_uint8x16(p); +} +inline v_uint16x8 v_popcount(const v_uint16x8& a) +{ + v_uint8x16 p = v_popcount(v_reinterpret_as_u8(a)); + p += v_rotate_right<1>(p); + return v_reinterpret_as_u16(p) & v_setall_u16(0x00ff); +} +inline v_uint32x4 v_popcount(const v_uint32x4& a) +{ + v_uint8x16 p = v_popcount(v_reinterpret_as_u8(a)); + p += v_rotate_right<1>(p); + p += v_rotate_right<2>(p); + return v_reinterpret_as_u32(p) & v_setall_u32(0x000000ff); +} +inline v_uint64x2 v_popcount(const v_uint64x2& a) +{ + return v_uint64x2(_mm_sad_epu8(v_popcount(v_reinterpret_as_u8(a)).val, _mm_setzero_si128())); +} +inline v_uint8x16 v_popcount(const v_int8x16& a) +{ return v_popcount(v_reinterpret_as_u8(a)); } +inline v_uint16x8 v_popcount(const v_int16x8& a) +{ return v_popcount(v_reinterpret_as_u16(a)); } +inline v_uint32x4 v_popcount(const v_int32x4& a) +{ return v_popcount(v_reinterpret_as_u32(a)); } +inline v_uint64x2 v_popcount(const v_int64x2& a) +{ return v_popcount(v_reinterpret_as_u64(a)); } + +#define OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(_Tpvec, suffix, cast_op, allmask) \ +inline int v_signmask(const _Tpvec& a) { return _mm_movemask_##suffix(cast_op(a.val)); } \ +inline bool v_check_all(const _Tpvec& a) { return _mm_movemask_##suffix(cast_op(a.val)) == allmask; } \ +inline bool v_check_any(const _Tpvec& a) { return _mm_movemask_##suffix(cast_op(a.val)) != 0; } +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint8x16, epi8, OPENCV_HAL_NOP, 65535) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int8x16, epi8, OPENCV_HAL_NOP, 65535) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint32x4, ps, _mm_castsi128_ps, 15) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int32x4, ps, _mm_castsi128_ps, 15) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_uint64x2, pd, _mm_castsi128_pd, 3) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_int64x2, pd, _mm_castsi128_pd, 3) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_float32x4, ps, OPENCV_HAL_NOP, 15) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS(v_float64x2, pd, OPENCV_HAL_NOP, 3) + +#define OPENCV_HAL_IMPL_SSE_CHECK_SIGNS_SHORT(_Tpvec) \ +inline int v_signmask(const _Tpvec& a) { return _mm_movemask_epi8(_mm_packs_epi16(a.val, a.val)) & 255; } \ +inline bool v_check_all(const _Tpvec& a) { return (_mm_movemask_epi8(a.val) & 0xaaaa) == 0xaaaa; } \ +inline bool v_check_any(const _Tpvec& a) { return (_mm_movemask_epi8(a.val) & 0xaaaa) != 0; } +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS_SHORT(v_uint16x8) +OPENCV_HAL_IMPL_SSE_CHECK_SIGNS_SHORT(v_int16x8) + +inline int v_scan_forward(const v_int8x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); } +inline int v_scan_forward(const v_uint8x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); } +inline int v_scan_forward(const v_int16x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; } +inline int v_scan_forward(const v_uint16x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; } +inline int v_scan_forward(const v_int32x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_uint32x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_float32x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_int64x2& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } +inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } +inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } + +#if CV_SSE4_1 +#define OPENCV_HAL_IMPL_SSE_SELECT(_Tpvec, cast_ret, cast, suffix) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(cast_ret(_mm_blendv_##suffix(cast(b.val), cast(a.val), cast(mask.val)))); \ +} + +OPENCV_HAL_IMPL_SSE_SELECT(v_uint8x16, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_int8x16, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint16x8, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_int16x8, OPENCV_HAL_NOP, OPENCV_HAL_NOP, epi8) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint32x4, _mm_castps_si128, _mm_castsi128_ps, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_int32x4, _mm_castps_si128, _mm_castsi128_ps, ps) +// OPENCV_HAL_IMPL_SSE_SELECT(v_uint64x2, TBD, TBD, pd) +// OPENCV_HAL_IMPL_SSE_SELECT(v_int64x2, TBD, TBD, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_float32x4, OPENCV_HAL_NOP, OPENCV_HAL_NOP, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_float64x2, OPENCV_HAL_NOP, OPENCV_HAL_NOP, pd) + +#else // CV_SSE4_1 + +#define OPENCV_HAL_IMPL_SSE_SELECT(_Tpvec, suffix) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(_mm_xor_##suffix(b.val, _mm_and_##suffix(_mm_xor_##suffix(b.val, a.val), mask.val))); \ +} + +OPENCV_HAL_IMPL_SSE_SELECT(v_uint8x16, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_int8x16, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint16x8, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_int16x8, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_uint32x4, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_int32x4, si128) +// OPENCV_HAL_IMPL_SSE_SELECT(v_uint64x2, si128) +// OPENCV_HAL_IMPL_SSE_SELECT(v_int64x2, si128) +OPENCV_HAL_IMPL_SSE_SELECT(v_float32x4, ps) +OPENCV_HAL_IMPL_SSE_SELECT(v_float64x2, pd) +#endif + +/* Expand */ +#define OPENCV_HAL_IMPL_SSE_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \ + inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ + { \ + b0.val = intrin(a.val); \ + b1.val = __CV_CAT(intrin, _high)(a.val); \ + } \ + inline _Tpwvec v_expand_low(const _Tpvec& a) \ + { return _Tpwvec(intrin(a.val)); } \ + inline _Tpwvec v_expand_high(const _Tpvec& a) \ + { return _Tpwvec(__CV_CAT(intrin, _high)(a.val)); } \ + inline _Tpwvec v_load_expand(const _Tp* ptr) \ + { \ + __m128i a = _mm_loadl_epi64((const __m128i*)ptr); \ + return _Tpwvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_SSE_EXPAND(v_uint8x16, v_uint16x8, uchar, _v128_cvtepu8_epi16) +OPENCV_HAL_IMPL_SSE_EXPAND(v_int8x16, v_int16x8, schar, _v128_cvtepi8_epi16) +OPENCV_HAL_IMPL_SSE_EXPAND(v_uint16x8, v_uint32x4, ushort, _v128_cvtepu16_epi32) +OPENCV_HAL_IMPL_SSE_EXPAND(v_int16x8, v_int32x4, short, _v128_cvtepi16_epi32) +OPENCV_HAL_IMPL_SSE_EXPAND(v_uint32x4, v_uint64x2, unsigned, _v128_cvtepu32_epi64) +OPENCV_HAL_IMPL_SSE_EXPAND(v_int32x4, v_int64x2, int, _v128_cvtepi32_epi64) + +#define OPENCV_HAL_IMPL_SSE_EXPAND_Q(_Tpvec, _Tp, intrin) \ + inline _Tpvec v_load_expand_q(const _Tp* ptr) \ + { \ + __m128i a = _mm_cvtsi32_si128(*(const int*)ptr); \ + return _Tpvec(intrin(a)); \ + } + +OPENCV_HAL_IMPL_SSE_EXPAND_Q(v_uint32x4, uchar, _v128_cvtepu8_epi32) +OPENCV_HAL_IMPL_SSE_EXPAND_Q(v_int32x4, schar, _v128_cvtepi8_epi32) + +#define OPENCV_HAL_IMPL_SSE_UNPACKS(_Tpvec, suffix, cast_from, cast_to) \ +inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) \ +{ \ + b0.val = _mm_unpacklo_##suffix(a0.val, a1.val); \ + b1.val = _mm_unpackhi_##suffix(a0.val, a1.val); \ +} \ +inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ +{ \ + __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \ + return _Tpvec(cast_to(_mm_unpacklo_epi64(a1, b1))); \ +} \ +inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ +{ \ + __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \ + return _Tpvec(cast_to(_mm_unpackhi_epi64(a1, b1))); \ +} \ +inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) \ +{ \ + __m128i a1 = cast_from(a.val), b1 = cast_from(b.val); \ + c.val = cast_to(_mm_unpacklo_epi64(a1, b1)); \ + d.val = cast_to(_mm_unpackhi_epi64(a1, b1)); \ +} + +OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_int8x16, epi8, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint16x8, epi16, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_int16x8, epi16, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_uint32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_int32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_float32x4, ps, _mm_castps_si128, _mm_castsi128_ps) +OPENCV_HAL_IMPL_SSE_UNPACKS(v_float64x2, pd, _mm_castpd_si128, _mm_castsi128_pd) + +inline v_uint8x16 v_reverse(const v_uint8x16 &a) +{ +#if CV_SSSE3 + static const __m128i perm = _mm_setr_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); + return v_uint8x16(_mm_shuffle_epi8(a.val, perm)); +#else + uchar CV_DECL_ALIGNED(32) d[16]; + v_store_aligned(d, a); + return v_uint8x16(d[15], d[14], d[13], d[12], d[11], d[10], d[9], d[8], d[7], d[6], d[5], d[4], d[3], d[2], d[1], d[0]); +#endif +} + +inline v_int8x16 v_reverse(const v_int8x16 &a) +{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); } + +inline v_uint16x8 v_reverse(const v_uint16x8 &a) +{ +#if CV_SSSE3 + static const __m128i perm = _mm_setr_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1); + return v_uint16x8(_mm_shuffle_epi8(a.val, perm)); +#else + __m128i r = _mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 1, 2, 3)); + r = _mm_shufflelo_epi16(r, _MM_SHUFFLE(2, 3, 0, 1)); + r = _mm_shufflehi_epi16(r, _MM_SHUFFLE(2, 3, 0, 1)); + return v_uint16x8(r); +#endif +} + +inline v_int16x8 v_reverse(const v_int16x8 &a) +{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); } + +inline v_uint32x4 v_reverse(const v_uint32x4 &a) +{ + return v_uint32x4(_mm_shuffle_epi32(a.val, _MM_SHUFFLE(0, 1, 2, 3))); +} + +inline v_int32x4 v_reverse(const v_int32x4 &a) +{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_float32x4 v_reverse(const v_float32x4 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x2 v_reverse(const v_uint64x2 &a) +{ + return v_uint64x2(_mm_shuffle_epi32(a.val, _MM_SHUFFLE(1, 0, 3, 2))); +} + +inline v_int64x2 v_reverse(const v_int64x2 &a) +{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); } + +inline v_float64x2 v_reverse(const v_float64x2 &a) +{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); } + +template +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) +{ + return v_rotate_right(a, b); +} + +inline v_int32x4 v_round(const v_float32x4& a) +{ return v_int32x4(_mm_cvtps_epi32(a.val)); } + +inline v_int32x4 v_floor(const v_float32x4& a) +{ + __m128i a1 = _mm_cvtps_epi32(a.val); + __m128i mask = _mm_castps_si128(_mm_cmpgt_ps(_mm_cvtepi32_ps(a1), a.val)); + return v_int32x4(_mm_add_epi32(a1, mask)); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + __m128i a1 = _mm_cvtps_epi32(a.val); + __m128i mask = _mm_castps_si128(_mm_cmpgt_ps(a.val, _mm_cvtepi32_ps(a1))); + return v_int32x4(_mm_sub_epi32(a1, mask)); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(_mm_cvttps_epi32(a.val)); } + +inline v_int32x4 v_round(const v_float64x2& a) +{ return v_int32x4(_mm_cvtpd_epi32(a.val)); } + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + __m128i ai = _mm_cvtpd_epi32(a.val), bi = _mm_cvtpd_epi32(b.val); + return v_int32x4(_mm_unpacklo_epi64(ai, bi)); +} + +inline v_int32x4 v_floor(const v_float64x2& a) +{ + __m128i a1 = _mm_cvtpd_epi32(a.val); + __m128i mask = _mm_castpd_si128(_mm_cmpgt_pd(_mm_cvtepi32_pd(a1), a.val)); + mask = _mm_srli_si128(_mm_slli_si128(mask, 4), 8); // m0 m0 m1 m1 => m0 m1 0 0 + return v_int32x4(_mm_add_epi32(a1, mask)); +} + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ + __m128i a1 = _mm_cvtpd_epi32(a.val); + __m128i mask = _mm_castpd_si128(_mm_cmpgt_pd(a.val, _mm_cvtepi32_pd(a1))); + mask = _mm_srli_si128(_mm_slli_si128(mask, 4), 8); // m0 m0 m1 m1 => m0 m1 0 0 + return v_int32x4(_mm_sub_epi32(a1, mask)); +} + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ return v_int32x4(_mm_cvttpd_epi32(a.val)); } + +#define OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \ +inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, \ + _Tpvec& b2, _Tpvec& b3) \ +{ \ + __m128i t0 = cast_from(_mm_unpacklo_##suffix(a0.val, a1.val)); \ + __m128i t1 = cast_from(_mm_unpacklo_##suffix(a2.val, a3.val)); \ + __m128i t2 = cast_from(_mm_unpackhi_##suffix(a0.val, a1.val)); \ + __m128i t3 = cast_from(_mm_unpackhi_##suffix(a2.val, a3.val)); \ +\ + b0.val = cast_to(_mm_unpacklo_epi64(t0, t1)); \ + b1.val = cast_to(_mm_unpackhi_epi64(t0, t1)); \ + b2.val = cast_to(_mm_unpacklo_epi64(t2, t3)); \ + b3.val = cast_to(_mm_unpackhi_epi64(t2, t3)); \ +} + +OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_uint32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_int32x4, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP) +OPENCV_HAL_IMPL_SSE_TRANSPOSE4x4(v_float32x4, ps, _mm_castps_si128, _mm_castsi128_ps) + +// load deinterleave +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b) +{ + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + + __m128i t10 = _mm_unpacklo_epi8(t00, t01); + __m128i t11 = _mm_unpackhi_epi8(t00, t01); + + __m128i t20 = _mm_unpacklo_epi8(t10, t11); + __m128i t21 = _mm_unpackhi_epi8(t10, t11); + + __m128i t30 = _mm_unpacklo_epi8(t20, t21); + __m128i t31 = _mm_unpackhi_epi8(t20, t21); + + a.val = _mm_unpacklo_epi8(t30, t31); + b.val = _mm_unpackhi_epi8(t30, t31); +} + +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b, v_uint8x16& c) +{ +#if CV_SSE4_1 + const __m128i m0 = _mm_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0); + const __m128i m1 = _mm_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + __m128i s0 = _mm_loadu_si128((const __m128i*)ptr); + __m128i s1 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + __m128i s2 = _mm_loadu_si128((const __m128i*)(ptr + 32)); + __m128i a0 = _mm_blendv_epi8(_mm_blendv_epi8(s0, s1, m0), s2, m1); + __m128i b0 = _mm_blendv_epi8(_mm_blendv_epi8(s1, s2, m0), s0, m1); + __m128i c0 = _mm_blendv_epi8(_mm_blendv_epi8(s2, s0, m0), s1, m1); + const __m128i sh_b = _mm_setr_epi8(0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13); + const __m128i sh_g = _mm_setr_epi8(1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14); + const __m128i sh_r = _mm_setr_epi8(2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15); + a0 = _mm_shuffle_epi8(a0, sh_b); + b0 = _mm_shuffle_epi8(b0, sh_g); + c0 = _mm_shuffle_epi8(c0, sh_r); + a.val = a0; + b.val = b0; + c.val = c0; +#elif CV_SSSE3 + const __m128i m0 = _mm_setr_epi8(0, 3, 6, 9, 12, 15, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14); + const __m128i m1 = _mm_alignr_epi8(m0, m0, 11); + const __m128i m2 = _mm_alignr_epi8(m0, m0, 6); + + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + __m128i t2 = _mm_loadu_si128((const __m128i*)(ptr + 32)); + + __m128i s0 = _mm_shuffle_epi8(t0, m0); + __m128i s1 = _mm_shuffle_epi8(t1, m1); + __m128i s2 = _mm_shuffle_epi8(t2, m2); + + t0 = _mm_alignr_epi8(s1, _mm_slli_si128(s0, 10), 5); + a.val = _mm_alignr_epi8(s2, t0, 5); + + t1 = _mm_alignr_epi8(_mm_srli_si128(s1, 5), _mm_slli_si128(s0, 5), 6); + b.val = _mm_alignr_epi8(_mm_srli_si128(s2, 5), t1, 5); + + t2 = _mm_alignr_epi8(_mm_srli_si128(s2, 10), s1, 11); + c.val = _mm_alignr_epi8(t2, s0, 11); +#else + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + __m128i t02 = _mm_loadu_si128((const __m128i*)(ptr + 32)); + + __m128i t10 = _mm_unpacklo_epi8(t00, _mm_unpackhi_epi64(t01, t01)); + __m128i t11 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t00, t00), t02); + __m128i t12 = _mm_unpacklo_epi8(t01, _mm_unpackhi_epi64(t02, t02)); + + __m128i t20 = _mm_unpacklo_epi8(t10, _mm_unpackhi_epi64(t11, t11)); + __m128i t21 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t10, t10), t12); + __m128i t22 = _mm_unpacklo_epi8(t11, _mm_unpackhi_epi64(t12, t12)); + + __m128i t30 = _mm_unpacklo_epi8(t20, _mm_unpackhi_epi64(t21, t21)); + __m128i t31 = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t20, t20), t22); + __m128i t32 = _mm_unpacklo_epi8(t21, _mm_unpackhi_epi64(t22, t22)); + + a.val = _mm_unpacklo_epi8(t30, _mm_unpackhi_epi64(t31, t31)); + b.val = _mm_unpacklo_epi8(_mm_unpackhi_epi64(t30, t30), t32); + c.val = _mm_unpacklo_epi8(t31, _mm_unpackhi_epi64(t32, t32)); +#endif +} + +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b, v_uint8x16& c, v_uint8x16& d) +{ + __m128i u0 = _mm_loadu_si128((const __m128i*)ptr); // a0 b0 c0 d0 a1 b1 c1 d1 ... + __m128i u1 = _mm_loadu_si128((const __m128i*)(ptr + 16)); // a4 b4 c4 d4 ... + __m128i u2 = _mm_loadu_si128((const __m128i*)(ptr + 32)); // a8 b8 c8 d8 ... + __m128i u3 = _mm_loadu_si128((const __m128i*)(ptr + 48)); // a12 b12 c12 d12 ... + + __m128i v0 = _mm_unpacklo_epi8(u0, u2); // a0 a8 b0 b8 ... + __m128i v1 = _mm_unpackhi_epi8(u0, u2); // a2 a10 b2 b10 ... + __m128i v2 = _mm_unpacklo_epi8(u1, u3); // a4 a12 b4 b12 ... + __m128i v3 = _mm_unpackhi_epi8(u1, u3); // a6 a14 b6 b14 ... + + u0 = _mm_unpacklo_epi8(v0, v2); // a0 a4 a8 a12 ... + u1 = _mm_unpacklo_epi8(v1, v3); // a2 a6 a10 a14 ... + u2 = _mm_unpackhi_epi8(v0, v2); // a1 a5 a9 a13 ... + u3 = _mm_unpackhi_epi8(v1, v3); // a3 a7 a11 a15 ... + + v0 = _mm_unpacklo_epi8(u0, u1); // a0 a2 a4 a6 ... + v1 = _mm_unpacklo_epi8(u2, u3); // a1 a3 a5 a7 ... + v2 = _mm_unpackhi_epi8(u0, u1); // c0 c2 c4 c6 ... + v3 = _mm_unpackhi_epi8(u2, u3); // c1 c3 c5 c7 ... + + a.val = _mm_unpacklo_epi8(v0, v1); + b.val = _mm_unpackhi_epi8(v0, v1); + c.val = _mm_unpacklo_epi8(v2, v3); + d.val = _mm_unpackhi_epi8(v2, v3); +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b) +{ + __m128i v0 = _mm_loadu_si128((__m128i*)(ptr)); // a0 b0 a1 b1 a2 b2 a3 b3 + __m128i v1 = _mm_loadu_si128((__m128i*)(ptr + 8)); // a4 b4 a5 b5 a6 b6 a7 b7 + + __m128i v2 = _mm_unpacklo_epi16(v0, v1); // a0 a4 b0 b4 a1 a5 b1 b5 + __m128i v3 = _mm_unpackhi_epi16(v0, v1); // a2 a6 b2 b6 a3 a7 b3 b7 + __m128i v4 = _mm_unpacklo_epi16(v2, v3); // a0 a2 a4 a6 b0 b2 b4 b6 + __m128i v5 = _mm_unpackhi_epi16(v2, v3); // a1 a3 a5 a7 b1 b3 b5 b7 + + a.val = _mm_unpacklo_epi16(v4, v5); // a0 a1 a2 a3 a4 a5 a6 a7 + b.val = _mm_unpackhi_epi16(v4, v5); // b0 b1 ab b3 b4 b5 b6 b7 +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b, v_uint16x8& c) +{ +#if CV_SSE4_1 + __m128i v0 = _mm_loadu_si128((__m128i*)(ptr)); + __m128i v1 = _mm_loadu_si128((__m128i*)(ptr + 8)); + __m128i v2 = _mm_loadu_si128((__m128i*)(ptr + 16)); + __m128i a0 = _mm_blend_epi16(_mm_blend_epi16(v0, v1, 0x92), v2, 0x24); + __m128i b0 = _mm_blend_epi16(_mm_blend_epi16(v2, v0, 0x92), v1, 0x24); + __m128i c0 = _mm_blend_epi16(_mm_blend_epi16(v1, v2, 0x92), v0, 0x24); + + const __m128i sh_a = _mm_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m128i sh_b = _mm_setr_epi8(2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13); + const __m128i sh_c = _mm_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + a0 = _mm_shuffle_epi8(a0, sh_a); + b0 = _mm_shuffle_epi8(b0, sh_b); + c0 = _mm_shuffle_epi8(c0, sh_c); + + a.val = a0; + b.val = b0; + c.val = c0; +#else + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 8)); + __m128i t02 = _mm_loadu_si128((const __m128i*)(ptr + 16)); + + __m128i t10 = _mm_unpacklo_epi16(t00, _mm_unpackhi_epi64(t01, t01)); + __m128i t11 = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t00, t00), t02); + __m128i t12 = _mm_unpacklo_epi16(t01, _mm_unpackhi_epi64(t02, t02)); + + __m128i t20 = _mm_unpacklo_epi16(t10, _mm_unpackhi_epi64(t11, t11)); + __m128i t21 = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t10, t10), t12); + __m128i t22 = _mm_unpacklo_epi16(t11, _mm_unpackhi_epi64(t12, t12)); + + a.val = _mm_unpacklo_epi16(t20, _mm_unpackhi_epi64(t21, t21)); + b.val = _mm_unpacklo_epi16(_mm_unpackhi_epi64(t20, t20), t22); + c.val = _mm_unpacklo_epi16(t21, _mm_unpackhi_epi64(t22, t22)); +#endif +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b, v_uint16x8& c, v_uint16x8& d) +{ + __m128i u0 = _mm_loadu_si128((const __m128i*)ptr); // a0 b0 c0 d0 a1 b1 c1 d1 + __m128i u1 = _mm_loadu_si128((const __m128i*)(ptr + 8)); // a2 b2 c2 d2 ... + __m128i u2 = _mm_loadu_si128((const __m128i*)(ptr + 16)); // a4 b4 c4 d4 ... + __m128i u3 = _mm_loadu_si128((const __m128i*)(ptr + 24)); // a6 b6 c6 d6 ... + + __m128i v0 = _mm_unpacklo_epi16(u0, u2); // a0 a4 b0 b4 ... + __m128i v1 = _mm_unpackhi_epi16(u0, u2); // a1 a5 b1 b5 ... + __m128i v2 = _mm_unpacklo_epi16(u1, u3); // a2 a6 b2 b6 ... + __m128i v3 = _mm_unpackhi_epi16(u1, u3); // a3 a7 b3 b7 ... + + u0 = _mm_unpacklo_epi16(v0, v2); // a0 a2 a4 a6 ... + u1 = _mm_unpacklo_epi16(v1, v3); // a1 a3 a5 a7 ... + u2 = _mm_unpackhi_epi16(v0, v2); // c0 c2 c4 c6 ... + u3 = _mm_unpackhi_epi16(v1, v3); // c1 c3 c5 c7 ... + + a.val = _mm_unpacklo_epi16(u0, u1); + b.val = _mm_unpackhi_epi16(u0, u1); + c.val = _mm_unpacklo_epi16(u2, u3); + d.val = _mm_unpackhi_epi16(u2, u3); +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b) +{ + __m128i v0 = _mm_loadu_si128((__m128i*)(ptr)); // a0 b0 a1 b1 + __m128i v1 = _mm_loadu_si128((__m128i*)(ptr + 4)); // a2 b2 a3 b3 + + __m128i v2 = _mm_unpacklo_epi32(v0, v1); // a0 a2 b0 b2 + __m128i v3 = _mm_unpackhi_epi32(v0, v1); // a1 a3 b1 b3 + + a.val = _mm_unpacklo_epi32(v2, v3); // a0 a1 a2 a3 + b.val = _mm_unpackhi_epi32(v2, v3); // b0 b1 ab b3 +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b, v_uint32x4& c) +{ + __m128i t00 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t01 = _mm_loadu_si128((const __m128i*)(ptr + 4)); + __m128i t02 = _mm_loadu_si128((const __m128i*)(ptr + 8)); + + __m128i t10 = _mm_unpacklo_epi32(t00, _mm_unpackhi_epi64(t01, t01)); + __m128i t11 = _mm_unpacklo_epi32(_mm_unpackhi_epi64(t00, t00), t02); + __m128i t12 = _mm_unpacklo_epi32(t01, _mm_unpackhi_epi64(t02, t02)); + + a.val = _mm_unpacklo_epi32(t10, _mm_unpackhi_epi64(t11, t11)); + b.val = _mm_unpacklo_epi32(_mm_unpackhi_epi64(t10, t10), t12); + c.val = _mm_unpacklo_epi32(t11, _mm_unpackhi_epi64(t12, t12)); +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b, v_uint32x4& c, v_uint32x4& d) +{ + v_uint32x4 s0(_mm_loadu_si128((const __m128i*)ptr)); // a0 b0 c0 d0 + v_uint32x4 s1(_mm_loadu_si128((const __m128i*)(ptr + 4))); // a1 b1 c1 d1 + v_uint32x4 s2(_mm_loadu_si128((const __m128i*)(ptr + 8))); // a2 b2 c2 d2 + v_uint32x4 s3(_mm_loadu_si128((const __m128i*)(ptr + 12))); // a3 b3 c3 d3 + + v_transpose4x4(s0, s1, s2, s3, a, b, c, d); +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b) +{ + __m128 u0 = _mm_loadu_ps(ptr); // a0 b0 a1 b1 + __m128 u1 = _mm_loadu_ps((ptr + 4)); // a2 b2 a3 b3 + + a.val = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(2, 0, 2, 0)); // a0 a1 a2 a3 + b.val = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(3, 1, 3, 1)); // b0 b1 ab b3 +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b, v_float32x4& c) +{ + __m128 t0 = _mm_loadu_ps(ptr + 0); + __m128 t1 = _mm_loadu_ps(ptr + 4); + __m128 t2 = _mm_loadu_ps(ptr + 8); + + __m128 at12 = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(0, 1, 0, 2)); + a.val = _mm_shuffle_ps(t0, at12, _MM_SHUFFLE(2, 0, 3, 0)); + + __m128 bt01 = _mm_shuffle_ps(t0, t1, _MM_SHUFFLE(0, 0, 0, 1)); + __m128 bt12 = _mm_shuffle_ps(t1, t2, _MM_SHUFFLE(0, 2, 0, 3)); + b.val = _mm_shuffle_ps(bt01, bt12, _MM_SHUFFLE(2, 0, 2, 0)); + + __m128 ct01 = _mm_shuffle_ps(t0, t1, _MM_SHUFFLE(0, 1, 0, 2)); + c.val = _mm_shuffle_ps(ct01, t2, _MM_SHUFFLE(3, 0, 2, 0)); +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b, v_float32x4& c, v_float32x4& d) +{ + __m128 t0 = _mm_loadu_ps(ptr + 0); + __m128 t1 = _mm_loadu_ps(ptr + 4); + __m128 t2 = _mm_loadu_ps(ptr + 8); + __m128 t3 = _mm_loadu_ps(ptr + 12); + __m128 t02lo = _mm_unpacklo_ps(t0, t2); + __m128 t13lo = _mm_unpacklo_ps(t1, t3); + __m128 t02hi = _mm_unpackhi_ps(t0, t2); + __m128 t13hi = _mm_unpackhi_ps(t1, t3); + a.val = _mm_unpacklo_ps(t02lo, t13lo); + b.val = _mm_unpackhi_ps(t02lo, t13lo); + c.val = _mm_unpacklo_ps(t02hi, t13hi); + d.val = _mm_unpackhi_ps(t02hi, t13hi); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, v_uint64x2& b) +{ + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 2)); + + a = v_uint64x2(_mm_unpacklo_epi64(t0, t1)); + b = v_uint64x2(_mm_unpackhi_epi64(t0, t1)); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, v_uint64x2& b, v_uint64x2& c) +{ + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); // a0, b0 + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 2)); // c0, a1 + __m128i t2 = _mm_loadu_si128((const __m128i*)(ptr + 4)); // b1, c1 + + t1 = _mm_shuffle_epi32(t1, 0x4e); // a1, c0 + + a = v_uint64x2(_mm_unpacklo_epi64(t0, t1)); + b = v_uint64x2(_mm_unpacklo_epi64(_mm_unpackhi_epi64(t0, t0), t2)); + c = v_uint64x2(_mm_unpackhi_epi64(t1, t2)); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, + v_uint64x2& b, v_uint64x2& c, v_uint64x2& d) +{ + __m128i t0 = _mm_loadu_si128((const __m128i*)ptr); // a0 b0 + __m128i t1 = _mm_loadu_si128((const __m128i*)(ptr + 2)); // c0 d0 + __m128i t2 = _mm_loadu_si128((const __m128i*)(ptr + 4)); // a1 b1 + __m128i t3 = _mm_loadu_si128((const __m128i*)(ptr + 6)); // c1 d1 + + a = v_uint64x2(_mm_unpacklo_epi64(t0, t2)); + b = v_uint64x2(_mm_unpackhi_epi64(t0, t2)); + c = v_uint64x2(_mm_unpacklo_epi64(t1, t3)); + d = v_uint64x2(_mm_unpackhi_epi64(t1, t3)); +} + +// store interleave + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi8(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi8(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 16), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 16), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 16), v1); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + const v_uint8x16& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ +#if CV_SSE4_1 + const __m128i sh_a = _mm_setr_epi8(0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5); + const __m128i sh_b = _mm_setr_epi8(5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10); + const __m128i sh_c = _mm_setr_epi8(10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15); + __m128i a0 = _mm_shuffle_epi8(a.val, sh_a); + __m128i b0 = _mm_shuffle_epi8(b.val, sh_b); + __m128i c0 = _mm_shuffle_epi8(c.val, sh_c); + + const __m128i m0 = _mm_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0); + const __m128i m1 = _mm_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0); + __m128i v0 = _mm_blendv_epi8(_mm_blendv_epi8(a0, b0, m1), c0, m0); + __m128i v1 = _mm_blendv_epi8(_mm_blendv_epi8(b0, c0, m1), a0, m0); + __m128i v2 = _mm_blendv_epi8(_mm_blendv_epi8(c0, a0, m1), b0, m0); +#elif CV_SSSE3 + const __m128i m0 = _mm_setr_epi8(0, 6, 11, 1, 7, 12, 2, 8, 13, 3, 9, 14, 4, 10, 15, 5); + const __m128i m1 = _mm_setr_epi8(5, 11, 0, 6, 12, 1, 7, 13, 2, 8, 14, 3, 9, 15, 4, 10); + const __m128i m2 = _mm_setr_epi8(10, 0, 5, 11, 1, 6, 12, 2, 7, 13, 3, 8, 14, 4, 9, 15); + + __m128i t0 = _mm_alignr_epi8(b.val, _mm_slli_si128(a.val, 10), 5); + t0 = _mm_alignr_epi8(c.val, t0, 5); + __m128i v0 = _mm_shuffle_epi8(t0, m0); + + __m128i t1 = _mm_alignr_epi8(_mm_srli_si128(b.val, 5), _mm_slli_si128(a.val, 5), 6); + t1 = _mm_alignr_epi8(_mm_srli_si128(c.val, 5), t1, 5); + __m128i v1 = _mm_shuffle_epi8(t1, m1); + + __m128i t2 = _mm_alignr_epi8(_mm_srli_si128(c.val, 10), b.val, 11); + t2 = _mm_alignr_epi8(t2, a.val, 11); + __m128i v2 = _mm_shuffle_epi8(t2, m2); +#else + __m128i z = _mm_setzero_si128(); + __m128i ab0 = _mm_unpacklo_epi8(a.val, b.val); + __m128i ab1 = _mm_unpackhi_epi8(a.val, b.val); + __m128i c0 = _mm_unpacklo_epi8(c.val, z); + __m128i c1 = _mm_unpackhi_epi8(c.val, z); + + __m128i p00 = _mm_unpacklo_epi16(ab0, c0); + __m128i p01 = _mm_unpackhi_epi16(ab0, c0); + __m128i p02 = _mm_unpacklo_epi16(ab1, c1); + __m128i p03 = _mm_unpackhi_epi16(ab1, c1); + + __m128i p10 = _mm_unpacklo_epi32(p00, p01); + __m128i p11 = _mm_unpackhi_epi32(p00, p01); + __m128i p12 = _mm_unpacklo_epi32(p02, p03); + __m128i p13 = _mm_unpackhi_epi32(p02, p03); + + __m128i p20 = _mm_unpacklo_epi64(p10, p11); + __m128i p21 = _mm_unpackhi_epi64(p10, p11); + __m128i p22 = _mm_unpacklo_epi64(p12, p13); + __m128i p23 = _mm_unpackhi_epi64(p12, p13); + + p20 = _mm_slli_si128(p20, 1); + p22 = _mm_slli_si128(p22, 1); + + __m128i p30 = _mm_slli_epi64(_mm_unpacklo_epi32(p20, p21), 8); + __m128i p31 = _mm_srli_epi64(_mm_unpackhi_epi32(p20, p21), 8); + __m128i p32 = _mm_slli_epi64(_mm_unpacklo_epi32(p22, p23), 8); + __m128i p33 = _mm_srli_epi64(_mm_unpackhi_epi32(p22, p23), 8); + + __m128i p40 = _mm_unpacklo_epi64(p30, p31); + __m128i p41 = _mm_unpackhi_epi64(p30, p31); + __m128i p42 = _mm_unpacklo_epi64(p32, p33); + __m128i p43 = _mm_unpackhi_epi64(p32, p33); + + __m128i v0 = _mm_or_si128(_mm_srli_si128(p40, 2), _mm_slli_si128(p41, 10)); + __m128i v1 = _mm_or_si128(_mm_srli_si128(p41, 6), _mm_slli_si128(p42, 6)); + __m128i v2 = _mm_or_si128(_mm_srli_si128(p42, 10), _mm_slli_si128(p43, 2)); +#endif + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 16), v1); + _mm_stream_si128((__m128i*)(ptr + 32), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 16), v1); + _mm_store_si128((__m128i*)(ptr + 32), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 16), v1); + _mm_storeu_si128((__m128i*)(ptr + 32), v2); + } +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + const v_uint8x16& c, const v_uint8x16& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + // a0 a1 a2 a3 .... + // b0 b1 b2 b3 .... + // c0 c1 c2 c3 .... + // d0 d1 d2 d3 .... + __m128i u0 = _mm_unpacklo_epi8(a.val, c.val); // a0 c0 a1 c1 ... + __m128i u1 = _mm_unpackhi_epi8(a.val, c.val); // a8 c8 a9 c9 ... + __m128i u2 = _mm_unpacklo_epi8(b.val, d.val); // b0 d0 b1 d1 ... + __m128i u3 = _mm_unpackhi_epi8(b.val, d.val); // b8 d8 b9 d9 ... + + __m128i v0 = _mm_unpacklo_epi8(u0, u2); // a0 b0 c0 d0 ... + __m128i v1 = _mm_unpackhi_epi8(u0, u2); // a4 b4 c4 d4 ... + __m128i v2 = _mm_unpacklo_epi8(u1, u3); // a8 b8 c8 d8 ... + __m128i v3 = _mm_unpackhi_epi8(u1, u3); // a12 b12 c12 d12 ... + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 16), v1); + _mm_stream_si128((__m128i*)(ptr + 32), v2); + _mm_stream_si128((__m128i*)(ptr + 48), v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 16), v1); + _mm_store_si128((__m128i*)(ptr + 32), v2); + _mm_store_si128((__m128i*)(ptr + 48), v3); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 16), v1); + _mm_storeu_si128((__m128i*)(ptr + 32), v2); + _mm_storeu_si128((__m128i*)(ptr + 48), v3); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, const v_uint16x8& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi16(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi16(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 8), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 8), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 8), v1); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, + const v_uint16x8& b, const v_uint16x8& c, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ +#if CV_SSE4_1 + const __m128i sh_a = _mm_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11); + const __m128i sh_b = _mm_setr_epi8(10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5); + const __m128i sh_c = _mm_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15); + __m128i a0 = _mm_shuffle_epi8(a.val, sh_a); + __m128i b0 = _mm_shuffle_epi8(b.val, sh_b); + __m128i c0 = _mm_shuffle_epi8(c.val, sh_c); + + __m128i v0 = _mm_blend_epi16(_mm_blend_epi16(a0, b0, 0x92), c0, 0x24); + __m128i v1 = _mm_blend_epi16(_mm_blend_epi16(c0, a0, 0x92), b0, 0x24); + __m128i v2 = _mm_blend_epi16(_mm_blend_epi16(b0, c0, 0x92), a0, 0x24); +#else + __m128i z = _mm_setzero_si128(); + __m128i ab0 = _mm_unpacklo_epi16(a.val, b.val); + __m128i ab1 = _mm_unpackhi_epi16(a.val, b.val); + __m128i c0 = _mm_unpacklo_epi16(c.val, z); + __m128i c1 = _mm_unpackhi_epi16(c.val, z); + + __m128i p10 = _mm_unpacklo_epi32(ab0, c0); + __m128i p11 = _mm_unpackhi_epi32(ab0, c0); + __m128i p12 = _mm_unpacklo_epi32(ab1, c1); + __m128i p13 = _mm_unpackhi_epi32(ab1, c1); + + __m128i p20 = _mm_unpacklo_epi64(p10, p11); + __m128i p21 = _mm_unpackhi_epi64(p10, p11); + __m128i p22 = _mm_unpacklo_epi64(p12, p13); + __m128i p23 = _mm_unpackhi_epi64(p12, p13); + + p20 = _mm_slli_si128(p20, 2); + p22 = _mm_slli_si128(p22, 2); + + __m128i p30 = _mm_unpacklo_epi64(p20, p21); + __m128i p31 = _mm_unpackhi_epi64(p20, p21); + __m128i p32 = _mm_unpacklo_epi64(p22, p23); + __m128i p33 = _mm_unpackhi_epi64(p22, p23); + + __m128i v0 = _mm_or_si128(_mm_srli_si128(p30, 2), _mm_slli_si128(p31, 10)); + __m128i v1 = _mm_or_si128(_mm_srli_si128(p31, 6), _mm_slli_si128(p32, 6)); + __m128i v2 = _mm_or_si128(_mm_srli_si128(p32, 10), _mm_slli_si128(p33, 2)); +#endif + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 8), v1); + _mm_stream_si128((__m128i*)(ptr + 16), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 8), v1); + _mm_store_si128((__m128i*)(ptr + 16), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 8), v1); + _mm_storeu_si128((__m128i*)(ptr + 16), v2); + } +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, const v_uint16x8& b, + const v_uint16x8& c, const v_uint16x8& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + // a0 a1 a2 a3 .... + // b0 b1 b2 b3 .... + // c0 c1 c2 c3 .... + // d0 d1 d2 d3 .... + __m128i u0 = _mm_unpacklo_epi16(a.val, c.val); // a0 c0 a1 c1 ... + __m128i u1 = _mm_unpackhi_epi16(a.val, c.val); // a4 c4 a5 c5 ... + __m128i u2 = _mm_unpacklo_epi16(b.val, d.val); // b0 d0 b1 d1 ... + __m128i u3 = _mm_unpackhi_epi16(b.val, d.val); // b4 d4 b5 d5 ... + + __m128i v0 = _mm_unpacklo_epi16(u0, u2); // a0 b0 c0 d0 ... + __m128i v1 = _mm_unpackhi_epi16(u0, u2); // a2 b2 c2 d2 ... + __m128i v2 = _mm_unpacklo_epi16(u1, u3); // a4 b4 c4 d4 ... + __m128i v3 = _mm_unpackhi_epi16(u1, u3); // a6 b6 c6 d6 ... + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 8), v1); + _mm_stream_si128((__m128i*)(ptr + 16), v2); + _mm_stream_si128((__m128i*)(ptr + 24), v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 8), v1); + _mm_store_si128((__m128i*)(ptr + 16), v2); + _mm_store_si128((__m128i*)(ptr + 24), v3); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 8), v1); + _mm_storeu_si128((__m128i*)(ptr + 16), v2); + _mm_storeu_si128((__m128i*)(ptr + 24), v3); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi32(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi32(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 4), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 4), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 4), v1); + } +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + v_uint32x4 z = v_setzero_u32(), u0, u1, u2, u3; + v_transpose4x4(a, b, c, z, u0, u1, u2, u3); + + __m128i v0 = _mm_or_si128(u0.val, _mm_slli_si128(u1.val, 12)); + __m128i v1 = _mm_or_si128(_mm_srli_si128(u1.val, 4), _mm_slli_si128(u2.val, 8)); + __m128i v2 = _mm_or_si128(_mm_srli_si128(u2.val, 8), _mm_slli_si128(u3.val, 4)); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 4), v1); + _mm_stream_si128((__m128i*)(ptr + 8), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 4), v1); + _mm_store_si128((__m128i*)(ptr + 8), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 4), v1); + _mm_storeu_si128((__m128i*)(ptr + 8), v2); + } +} + +inline void v_store_interleave(unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + v_uint32x4 v0, v1, v2, v3; + v_transpose4x4(a, b, c, d, v0, v1, v2, v3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0.val); + _mm_stream_si128((__m128i*)(ptr + 4), v1.val); + _mm_stream_si128((__m128i*)(ptr + 8), v2.val); + _mm_stream_si128((__m128i*)(ptr + 12), v3.val); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0.val); + _mm_store_si128((__m128i*)(ptr + 4), v1.val); + _mm_store_si128((__m128i*)(ptr + 8), v2.val); + _mm_store_si128((__m128i*)(ptr + 12), v3.val); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0.val); + _mm_storeu_si128((__m128i*)(ptr + 4), v1.val); + _mm_storeu_si128((__m128i*)(ptr + 8), v2.val); + _mm_storeu_si128((__m128i*)(ptr + 12), v3.val); + } +} + +// 2-channel, float only +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128 v0 = _mm_unpacklo_ps(a.val, b.val); // a0 b0 a1 b1 + __m128 v1 = _mm_unpackhi_ps(a.val, b.val); // a2 b2 a3 b3 + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_ps(ptr, v0); + _mm_stream_ps(ptr + 4, v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_ps(ptr, v0); + _mm_store_ps(ptr + 4, v1); + } + else + { + _mm_storeu_ps(ptr, v0); + _mm_storeu_ps(ptr + 4, v1); + } +} + +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128 u0 = _mm_shuffle_ps(a.val, b.val, _MM_SHUFFLE(0, 0, 0, 0)); + __m128 u1 = _mm_shuffle_ps(c.val, a.val, _MM_SHUFFLE(1, 1, 0, 0)); + __m128 v0 = _mm_shuffle_ps(u0, u1, _MM_SHUFFLE(2, 0, 2, 0)); + __m128 u2 = _mm_shuffle_ps(b.val, c.val, _MM_SHUFFLE(1, 1, 1, 1)); + __m128 u3 = _mm_shuffle_ps(a.val, b.val, _MM_SHUFFLE(2, 2, 2, 2)); + __m128 v1 = _mm_shuffle_ps(u2, u3, _MM_SHUFFLE(2, 0, 2, 0)); + __m128 u4 = _mm_shuffle_ps(c.val, a.val, _MM_SHUFFLE(3, 3, 2, 2)); + __m128 u5 = _mm_shuffle_ps(b.val, c.val, _MM_SHUFFLE(3, 3, 3, 3)); + __m128 v2 = _mm_shuffle_ps(u4, u5, _MM_SHUFFLE(2, 0, 2, 0)); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_ps(ptr, v0); + _mm_stream_ps(ptr + 4, v1); + _mm_stream_ps(ptr + 8, v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_ps(ptr, v0); + _mm_store_ps(ptr + 4, v1); + _mm_store_ps(ptr + 8, v2); + } + else + { + _mm_storeu_ps(ptr, v0); + _mm_storeu_ps(ptr + 4, v1); + _mm_storeu_ps(ptr + 8, v2); + } +} + +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128 u0 = _mm_unpacklo_ps(a.val, c.val); + __m128 u1 = _mm_unpacklo_ps(b.val, d.val); + __m128 u2 = _mm_unpackhi_ps(a.val, c.val); + __m128 u3 = _mm_unpackhi_ps(b.val, d.val); + __m128 v0 = _mm_unpacklo_ps(u0, u1); + __m128 v2 = _mm_unpacklo_ps(u2, u3); + __m128 v1 = _mm_unpackhi_ps(u0, u1); + __m128 v3 = _mm_unpackhi_ps(u2, u3); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_ps(ptr, v0); + _mm_stream_ps(ptr + 4, v1); + _mm_stream_ps(ptr + 8, v2); + _mm_stream_ps(ptr + 12, v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_ps(ptr, v0); + _mm_store_ps(ptr + 4, v1); + _mm_store_ps(ptr + 8, v2); + _mm_store_ps(ptr + 12, v3); + } + else + { + _mm_storeu_ps(ptr, v0); + _mm_storeu_ps(ptr + 4, v1); + _mm_storeu_ps(ptr + 8, v2); + _mm_storeu_ps(ptr + 12, v3); + } +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi64(a.val, b.val); + __m128i v1 = _mm_unpackhi_epi64(a.val, b.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 2), v1); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 2), v1); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 2), v1); + } +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + const v_uint64x2& c, hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi64(a.val, b.val); + __m128i v1 = _mm_unpacklo_epi64(c.val, _mm_unpackhi_epi64(a.val, a.val)); + __m128i v2 = _mm_unpackhi_epi64(b.val, c.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 2), v1); + _mm_stream_si128((__m128i*)(ptr + 4), v2); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 2), v1); + _mm_store_si128((__m128i*)(ptr + 4), v2); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 2), v1); + _mm_storeu_si128((__m128i*)(ptr + 4), v2); + } +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + const v_uint64x2& c, const v_uint64x2& d, + hal::StoreMode mode = hal::STORE_UNALIGNED) +{ + __m128i v0 = _mm_unpacklo_epi64(a.val, b.val); + __m128i v1 = _mm_unpacklo_epi64(c.val, d.val); + __m128i v2 = _mm_unpackhi_epi64(a.val, b.val); + __m128i v3 = _mm_unpackhi_epi64(c.val, d.val); + + if( mode == hal::STORE_ALIGNED_NOCACHE ) + { + _mm_stream_si128((__m128i*)(ptr), v0); + _mm_stream_si128((__m128i*)(ptr + 2), v1); + _mm_stream_si128((__m128i*)(ptr + 4), v2); + _mm_stream_si128((__m128i*)(ptr + 6), v3); + } + else if( mode == hal::STORE_ALIGNED ) + { + _mm_store_si128((__m128i*)(ptr), v0); + _mm_store_si128((__m128i*)(ptr + 2), v1); + _mm_store_si128((__m128i*)(ptr + 4), v2); + _mm_store_si128((__m128i*)(ptr + 6), v3); + } + else + { + _mm_storeu_si128((__m128i*)(ptr), v0); + _mm_storeu_si128((__m128i*)(ptr + 2), v1); + _mm_storeu_si128((__m128i*)(ptr + 4), v2); + _mm_storeu_si128((__m128i*)(ptr + 6), v3); + } +} + +#define OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \ +{ \ + _Tpvec1 a1, b1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \ +{ \ + _Tpvec1 a1, b1, c1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \ +{ \ + _Tpvec1 a1, b1, c1, d1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ + d0 = v_reinterpret_as_##suffix0(d1); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, const _Tpvec0& d0, \ + hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + _Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \ +} + +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int8x16, schar, s8, v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int16x8, short, s16, v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int32x4, int, s32, v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_int64x2, int64, s64, v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_SSE_LOADSTORE_INTERLEAVE(v_float64x2, double, f64, v_uint64x2, uint64, u64) + +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + return v_float32x4(_mm_cvtepi32_ps(a.val)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + return v_float32x4(_mm_cvtpd_ps(a.val)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + return v_float32x4(_mm_movelh_ps(_mm_cvtpd_ps(a.val), _mm_cvtpd_ps(b.val))); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + return v_float64x2(_mm_cvtepi32_pd(a.val)); +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + return v_float64x2(_mm_cvtepi32_pd(_mm_srli_si128(a.val,8))); +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + return v_float64x2(_mm_cvtps_pd(a.val)); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + return v_float64x2(_mm_cvtps_pd(_mm_movehl_ps(a.val, a.val))); +} + +// from (Mysticial and wim) https://stackoverflow.com/q/41144668 +inline v_float64x2 v_cvt_f64(const v_int64x2& v) +{ + // constants encoded as floating-point + __m128i magic_i_hi32 = _mm_set1_epi64x(0x4530000080000000); // 2^84 + 2^63 + __m128i magic_i_all = _mm_set1_epi64x(0x4530000080100000); // 2^84 + 2^63 + 2^52 + __m128d magic_d_all = _mm_castsi128_pd(magic_i_all); + // Blend the 32 lowest significant bits of v with magic_int_lo +#if CV_SSE4_1 + __m128i magic_i_lo = _mm_set1_epi64x(0x4330000000000000); // 2^52 + __m128i v_lo = _mm_blend_epi16(v.val, magic_i_lo, 0xcc); +#else + __m128i magic_i_lo = _mm_set1_epi32(0x43300000); // 2^52 + __m128i v_lo = _mm_unpacklo_epi32(_mm_shuffle_epi32(v.val, _MM_SHUFFLE(0, 0, 2, 0)), magic_i_lo); +#endif + // Extract the 32 most significant bits of v + __m128i v_hi = _mm_srli_epi64(v.val, 32); + // Flip the msb of v_hi and blend with 0x45300000 + v_hi = _mm_xor_si128(v_hi, magic_i_hi32); + // Compute in double precision + __m128d v_hi_dbl = _mm_sub_pd(_mm_castsi128_pd(v_hi), magic_d_all); + // (v_hi - magic_d_all) + v_lo Do not assume associativity of floating point addition + __m128d result = _mm_add_pd(v_hi_dbl, _mm_castsi128_pd(v_lo)); + return v_float64x2(result); +} + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int8x16(_mm_setr_epi8(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]], + tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]])); +#else + return v_int8x16(_mm_setr_epi64( + _mm_setr_pi8(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]]), + _mm_setr_pi8(tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]]) + )); +#endif +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int8x16(_mm_setr_epi16(*(const short*)(tab + idx[0]), *(const short*)(tab + idx[1]), *(const short*)(tab + idx[2]), *(const short*)(tab + idx[3]), + *(const short*)(tab + idx[4]), *(const short*)(tab + idx[5]), *(const short*)(tab + idx[6]), *(const short*)(tab + idx[7]))); +#else + return v_int8x16(_mm_setr_epi64( + _mm_setr_pi16(*(const short*)(tab + idx[0]), *(const short*)(tab + idx[1]), *(const short*)(tab + idx[2]), *(const short*)(tab + idx[3])), + _mm_setr_pi16(*(const short*)(tab + idx[4]), *(const short*)(tab + idx[5]), *(const short*)(tab + idx[6]), *(const short*)(tab + idx[7])) + )); +#endif +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int8x16(_mm_setr_epi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1]), + *(const int*)(tab + idx[2]), *(const int*)(tab + idx[3]))); +#else + return v_int8x16(_mm_setr_epi64( + _mm_setr_pi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1])), + _mm_setr_pi32(*(const int*)(tab + idx[2]), *(const int*)(tab + idx[3])) + )); +#endif +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((const schar *)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((const schar *)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((const schar *)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int16x8(_mm_setr_epi16(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]], + tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]])); +#else + return v_int16x8(_mm_setr_epi64( + _mm_setr_pi16(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]), + _mm_setr_pi16(tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]) + )); +#endif +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int16x8(_mm_setr_epi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1]), + *(const int*)(tab + idx[2]), *(const int*)(tab + idx[3]))); +#else + return v_int16x8(_mm_setr_epi64( + _mm_setr_pi32(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1])), + _mm_setr_pi32(*(const int*)(tab + idx[2]), *(const int*)(tab + idx[3])) + )); +#endif +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_int16x8(_mm_set_epi64x(*(const int64_t*)(tab + idx[1]), *(const int64_t*)(tab + idx[0]))); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((const short *)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((const short *)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((const short *)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ +#if defined(_MSC_VER) + return v_int32x4(_mm_setr_epi32(tab[idx[0]], tab[idx[1]], + tab[idx[2]], tab[idx[3]])); +#else + return v_int32x4(_mm_setr_epi64( + _mm_setr_pi32(tab[idx[0]], tab[idx[1]]), + _mm_setr_pi32(tab[idx[2]], tab[idx[3]]) + )); +#endif +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_int32x4(_mm_set_epi64x(*(const int64_t*)(tab + idx[1]), *(const int64_t*)(tab + idx[0]))); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(_mm_loadu_si128((const __m128i*)(tab + idx[0]))); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((const int *)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((const int *)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((const int *)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(_mm_set_epi64x(tab[idx[1]], tab[idx[0]])); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(_mm_loadu_si128((const __m128i*)(tab + idx[0]))); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + return v_float32x4(_mm_setr_ps(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]])); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_pairs((const int *)tab, idx)); } +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_quads((const int *)tab, idx)); } + +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + return v_float64x2(_mm_setr_pd(tab[idx[0]], tab[idx[1]])); +} +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) { return v_float64x2(_mm_castsi128_pd(_mm_loadu_si128((const __m128i*)(tab + idx[0])))); } + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + return v_int32x4(_mm_setr_epi32(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]])); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + return v_float32x4(_mm_setr_ps(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]])); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + int idx[2]; + v_store_low(idx, idxvec); + return v_float64x2(_mm_setr_pd(tab[idx[0]], tab[idx[1]])); +} + +// loads pairs from the table and deinterleaves them, e.g. returns: +// x = (tab[idxvec[0], tab[idxvec[1]], tab[idxvec[2]], tab[idxvec[3]]), +// y = (tab[idxvec[0]+1], tab[idxvec[1]+1], tab[idxvec[2]+1], tab[idxvec[3]+1]) +// note that the indices are float's indices, not the float-pair indices. +// in theory, this function can be used to implement bilinear interpolation, +// when idxvec are the offsets within the image. +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + int CV_DECL_ALIGNED(32) idx[4]; + v_store_aligned(idx, idxvec); + __m128 z = _mm_setzero_ps(); + __m128 xy01 = _mm_loadl_pi(z, (__m64*)(tab + idx[0])); + __m128 xy23 = _mm_loadl_pi(z, (__m64*)(tab + idx[2])); + xy01 = _mm_loadh_pi(xy01, (__m64*)(tab + idx[1])); + xy23 = _mm_loadh_pi(xy23, (__m64*)(tab + idx[3])); + __m128 xxyy02 = _mm_unpacklo_ps(xy01, xy23); + __m128 xxyy13 = _mm_unpackhi_ps(xy01, xy23); + x = v_float32x4(_mm_unpacklo_ps(xxyy02, xxyy13)); + y = v_float32x4(_mm_unpackhi_ps(xxyy02, xxyy13)); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + int idx[2]; + v_store_low(idx, idxvec); + __m128d xy0 = _mm_loadu_pd(tab + idx[0]); + __m128d xy1 = _mm_loadu_pd(tab + idx[1]); + x = v_float64x2(_mm_unpacklo_pd(xy0, xy1)); + y = v_float64x2(_mm_unpackhi_pd(xy0, xy1)); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ +#if CV_SSSE3 + return v_int8x16(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0d0e0c0b090a08, 0x0705060403010200))); +#else + __m128i a = _mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(3, 1, 2, 0)); + a = _mm_shufflehi_epi16(a, _MM_SHUFFLE(3, 1, 2, 0)); + a = _mm_shuffle_epi32(a, _MM_SHUFFLE(3, 1, 2, 0)); + return v_int8x16(_mm_unpacklo_epi8(a, _mm_unpackhi_epi64(a, a))); +#endif +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ +#if CV_SSSE3 + return v_int8x16(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0b0e0a0d090c08, 0x0703060205010400))); +#else + __m128i a = _mm_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0)); + return v_int8x16(_mm_unpacklo_epi8(a, _mm_unpackhi_epi64(a, a))); +#endif +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ +#if CV_SSSE3 + return v_int16x8(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0e0b0a0d0c0908, 0x0706030205040100))); +#else + __m128i a = _mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(3, 1, 2, 0)); + return v_int16x8(_mm_shufflehi_epi16(a, _MM_SHUFFLE(3, 1, 2, 0))); +#endif +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ +#if CV_SSSE3 + return v_int16x8(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0x0f0e07060d0c0504, 0x0b0a030209080100))); +#else + return v_int16x8(_mm_unpacklo_epi16(vec.val, _mm_unpackhi_epi64(vec.val, vec.val))); +#endif +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + return v_int32x4(_mm_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0))); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ +#if CV_SSSE3 + return v_int8x16(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0xffffff0f0e0d0c0a, 0x0908060504020100))); +#else + __m128i mask = _mm_set1_epi64x(0x00000000FFFFFFFF); + __m128i a = _mm_srli_si128(_mm_or_si128(_mm_andnot_si128(mask, vec.val), _mm_and_si128(mask, _mm_sll_epi32(vec.val, _mm_set_epi64x(0, 8)))), 1); + return v_int8x16(_mm_srli_si128(_mm_shufflelo_epi16(a, _MM_SHUFFLE(2, 1, 0, 3)), 2)); +#endif +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ +#if CV_SSSE3 + return v_int16x8(_mm_shuffle_epi8(vec.val, _mm_set_epi64x(0xffff0f0e0d0c0b0a, 0x0908050403020100))); +#else + return v_int16x8(_mm_srli_si128(_mm_shufflelo_epi16(vec.val, _MM_SHUFFLE(2, 1, 0, 3)), 2)); +#endif +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; } + +template +inline uchar v_extract_n(const v_uint8x16& v) +{ +#if CV_SSE4_1 + return (uchar)_mm_extract_epi8(v.val, i); +#else + return v_rotate_right(v).get0(); +#endif +} + +template +inline schar v_extract_n(const v_int8x16& v) +{ + return (schar)v_extract_n(v_reinterpret_as_u8(v)); +} + +template +inline ushort v_extract_n(const v_uint16x8& v) +{ + return (ushort)_mm_extract_epi16(v.val, i); +} + +template +inline short v_extract_n(const v_int16x8& v) +{ + return (short)v_extract_n(v_reinterpret_as_u16(v)); +} + +template +inline uint v_extract_n(const v_uint32x4& v) +{ +#if CV_SSE4_1 + return (uint)_mm_extract_epi32(v.val, i); +#else + return v_rotate_right(v).get0(); +#endif +} + +template +inline int v_extract_n(const v_int32x4& v) +{ + return (int)v_extract_n(v_reinterpret_as_u32(v)); +} + +template +inline uint64 v_extract_n(const v_uint64x2& v) +{ +#ifdef CV__SIMD_NATIVE_mm_extract_epi64 + return (uint64)_v128_extract_epi64(v.val); +#else + return v_rotate_right(v).get0(); +#endif +} + +template +inline int64 v_extract_n(const v_int64x2& v) +{ + return (int64)v_extract_n(v_reinterpret_as_u64(v)); +} + +template +inline float v_extract_n(const v_float32x4& v) +{ + union { uint iv; float fv; } d; + d.iv = v_extract_n(v_reinterpret_as_u32(v)); + return d.fv; +} + +template +inline double v_extract_n(const v_float64x2& v) +{ + union { uint64 iv; double dv; } d; + d.iv = v_extract_n(v_reinterpret_as_u64(v)); + return d.dv; +} + +template +inline v_int32x4 v_broadcast_element(const v_int32x4& v) +{ + return v_int32x4(_mm_shuffle_epi32(v.val, _MM_SHUFFLE(i,i,i,i))); +} + +template +inline v_uint32x4 v_broadcast_element(const v_uint32x4& v) +{ + return v_uint32x4(_mm_shuffle_epi32(v.val, _MM_SHUFFLE(i,i,i,i))); +} + +template +inline v_float32x4 v_broadcast_element(const v_float32x4& v) +{ + return v_float32x4(_mm_shuffle_ps(v.val, v.val, _MM_SHUFFLE((char)i,(char)i,(char)i,(char)i))); +} + +////////////// FP16 support /////////////////////////// + +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ +#if CV_FP16 + return v_float32x4(_mm_cvtph_ps(_mm_loadu_si128((const __m128i*)ptr))); +#else + const __m128i z = _mm_setzero_si128(), delta = _mm_set1_epi32(0x38000000); + const __m128i signmask = _mm_set1_epi32(0x80000000), maxexp = _mm_set1_epi32(0x7c000000); + const __m128 deltaf = _mm_castsi128_ps(_mm_set1_epi32(0x38800000)); + __m128i bits = _mm_unpacklo_epi16(z, _mm_loadl_epi64((const __m128i*)ptr)); // h << 16 + __m128i e = _mm_and_si128(bits, maxexp), sign = _mm_and_si128(bits, signmask); + __m128i t = _mm_add_epi32(_mm_srli_epi32(_mm_xor_si128(bits, sign), 3), delta); // ((h & 0x7fff) << 13) + delta + __m128i zt = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(_mm_add_epi32(t, _mm_set1_epi32(1 << 23))), deltaf)); + + t = _mm_add_epi32(t, _mm_and_si128(delta, _mm_cmpeq_epi32(maxexp, e))); + __m128i zmask = _mm_cmpeq_epi32(e, z); + __m128i ft = v_select_si128(zmask, zt, t); + return v_float32x4(_mm_castsi128_ps(_mm_or_si128(ft, sign))); +#endif +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ +#if CV_FP16 + __m128i fp16_value = _mm_cvtps_ph(v.val, 0); + _mm_storel_epi64((__m128i*)ptr, fp16_value); +#else + const __m128i signmask = _mm_set1_epi32(0x80000000); + const __m128i rval = _mm_set1_epi32(0x3f000000); + + __m128i t = _mm_castps_si128(v.val); + __m128i sign = _mm_srai_epi32(_mm_and_si128(t, signmask), 16); + t = _mm_andnot_si128(signmask, t); + + __m128i finitemask = _mm_cmpgt_epi32(_mm_set1_epi32(0x47800000), t); + __m128i isnan = _mm_cmpgt_epi32(t, _mm_set1_epi32(0x7f800000)); + __m128i naninf = v_select_si128(isnan, _mm_set1_epi32(0x7e00), _mm_set1_epi32(0x7c00)); + __m128i tinymask = _mm_cmpgt_epi32(_mm_set1_epi32(0x38800000), t); + __m128i tt = _mm_castps_si128(_mm_add_ps(_mm_castsi128_ps(t), _mm_castsi128_ps(rval))); + tt = _mm_sub_epi32(tt, rval); + __m128i odd = _mm_and_si128(_mm_srli_epi32(t, 13), _mm_set1_epi32(1)); + __m128i nt = _mm_add_epi32(t, _mm_set1_epi32(0xc8000fff)); + nt = _mm_srli_epi32(_mm_add_epi32(nt, odd), 13); + t = v_select_si128(tinymask, tt, nt); + t = v_select_si128(finitemask, t, naninf); + t = _mm_or_si128(t, sign); + t = _mm_packs_epi32(t, t); + _mm_storel_epi64((__m128i*)ptr, t); +#endif +} + +inline void v_cleanup() {} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_sse_em.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_sse_em.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6fb088161a5d039314b67440f4fe1145173218b3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_sse_em.hpp @@ -0,0 +1,180 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_INTRIN_SSE_EM_HPP +#define OPENCV_HAL_INTRIN_SSE_EM_HPP + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#define OPENCV_HAL_SSE_WRAP_1(fun, tp) \ + inline tp _v128_##fun(const tp& a) \ + { return _mm_##fun(a); } + +#define OPENCV_HAL_SSE_WRAP_2(fun, tp) \ + inline tp _v128_##fun(const tp& a, const tp& b) \ + { return _mm_##fun(a, b); } + +#define OPENCV_HAL_SSE_WRAP_3(fun, tp) \ + inline tp _v128_##fun(const tp& a, const tp& b, const tp& c) \ + { return _mm_##fun(a, b, c); } + +///////////////////////////// XOP ///////////////////////////// + +// [todo] define CV_XOP +#if 1 // CV_XOP +inline __m128i _v128_comgt_epu32(const __m128i& a, const __m128i& b) +{ + const __m128i delta = _mm_set1_epi32((int)0x80000000); + return _mm_cmpgt_epi32(_mm_xor_si128(a, delta), _mm_xor_si128(b, delta)); +} +// wrapping XOP +#else +OPENCV_HAL_SSE_WRAP_2(_v128_comgt_epu32, __m128i) +#endif // !CV_XOP + +///////////////////////////// SSE4.1 ///////////////////////////// + +#if !CV_SSE4_1 + +/** Swizzle **/ +inline __m128i _v128_blendv_epi8(const __m128i& a, const __m128i& b, const __m128i& mask) +{ return _mm_xor_si128(a, _mm_and_si128(_mm_xor_si128(b, a), mask)); } + +/** Convert **/ +// 8 >> 16 +inline __m128i _v128_cvtepu8_epi16(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi8(a, z); +} +inline __m128i _v128_cvtepi8_epi16(const __m128i& a) +{ return _mm_srai_epi16(_mm_unpacklo_epi8(a, a), 8); } +// 8 >> 32 +inline __m128i _v128_cvtepu8_epi32(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi16(_mm_unpacklo_epi8(a, z), z); +} +inline __m128i _v128_cvtepi8_epi32(const __m128i& a) +{ + __m128i r = _mm_unpacklo_epi8(a, a); + r = _mm_unpacklo_epi8(r, r); + return _mm_srai_epi32(r, 24); +} +// 16 >> 32 +inline __m128i _v128_cvtepu16_epi32(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi16(a, z); +} +inline __m128i _v128_cvtepi16_epi32(const __m128i& a) +{ return _mm_srai_epi32(_mm_unpacklo_epi16(a, a), 16); } +// 32 >> 64 +inline __m128i _v128_cvtepu32_epi64(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpacklo_epi32(a, z); +} +inline __m128i _v128_cvtepi32_epi64(const __m128i& a) +{ return _mm_unpacklo_epi32(a, _mm_srai_epi32(a, 31)); } + +/** Arithmetic **/ +inline __m128i _v128_mullo_epi32(const __m128i& a, const __m128i& b) +{ + __m128i c0 = _mm_mul_epu32(a, b); + __m128i c1 = _mm_mul_epu32(_mm_srli_epi64(a, 32), _mm_srli_epi64(b, 32)); + __m128i d0 = _mm_unpacklo_epi32(c0, c1); + __m128i d1 = _mm_unpackhi_epi32(c0, c1); + return _mm_unpacklo_epi64(d0, d1); +} + +/** Math **/ +inline __m128i _v128_min_epu32(const __m128i& a, const __m128i& b) +{ return _v128_blendv_epi8(a, b, _v128_comgt_epu32(a, b)); } + +// wrapping SSE4.1 +#else +OPENCV_HAL_SSE_WRAP_1(cvtepu8_epi16, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi8_epi16, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepu8_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi8_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepu16_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi16_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepu32_epi64, __m128i) +OPENCV_HAL_SSE_WRAP_1(cvtepi32_epi64, __m128i) +OPENCV_HAL_SSE_WRAP_2(min_epu32, __m128i) +OPENCV_HAL_SSE_WRAP_2(mullo_epi32, __m128i) +OPENCV_HAL_SSE_WRAP_3(blendv_epi8, __m128i) +#endif // !CV_SSE4_1 + +///////////////////////////// Revolutionary ///////////////////////////// + +/** Convert **/ +// 16 << 8 +inline __m128i _v128_cvtepu8_epi16_high(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpackhi_epi8(a, z); +} +inline __m128i _v128_cvtepi8_epi16_high(const __m128i& a) +{ return _mm_srai_epi16(_mm_unpackhi_epi8(a, a), 8); } +// 32 << 16 +inline __m128i _v128_cvtepu16_epi32_high(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpackhi_epi16(a, z); +} +inline __m128i _v128_cvtepi16_epi32_high(const __m128i& a) +{ return _mm_srai_epi32(_mm_unpackhi_epi16(a, a), 16); } +// 64 << 32 +inline __m128i _v128_cvtepu32_epi64_high(const __m128i& a) +{ + const __m128i z = _mm_setzero_si128(); + return _mm_unpackhi_epi32(a, z); +} +inline __m128i _v128_cvtepi32_epi64_high(const __m128i& a) +{ return _mm_unpackhi_epi32(a, _mm_srai_epi32(a, 31)); } + +/** Miscellaneous **/ +inline __m128i _v128_packs_epu32(const __m128i& a, const __m128i& b) +{ + const __m128i m = _mm_set1_epi32(65535); + __m128i am = _v128_min_epu32(a, m); + __m128i bm = _v128_min_epu32(b, m); +#if CV_SSE4_1 + return _mm_packus_epi32(am, bm); +#else + const __m128i d = _mm_set1_epi32(32768), nd = _mm_set1_epi16(-32768); + am = _mm_sub_epi32(am, d); + bm = _mm_sub_epi32(bm, d); + am = _mm_packs_epi32(am, bm); + return _mm_sub_epi16(am, nd); +#endif +} + +template +inline int64 _v128_extract_epi64(const __m128i& a) +{ +#if defined(CV__SIMD_HAVE_mm_extract_epi64) || (CV_SSE4_1 && (defined(__x86_64__)/*GCC*/ || defined(_M_X64)/*MSVC*/)) +#define CV__SIMD_NATIVE_mm_extract_epi64 1 + return _mm_extract_epi64(a, i); +#else + CV_DECL_ALIGNED(16) int64 tmp[2]; + _mm_store_si128((__m128i*)tmp, a); + return tmp[i]; +#endif +} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} // cv:: + +#endif // OPENCV_HAL_INTRIN_SSE_EM_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_vsx.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_vsx.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bda1d8558f8bec3875d522ff94dc57a608f59a6d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_vsx.hpp @@ -0,0 +1,1649 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_VSX_HPP +#define OPENCV_HAL_VSX_HPP + +#include +#include "opencv2/core/utility.hpp" + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 1 + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +///////// Types //////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + enum { nlanes = 16 }; + vec_uchar16 val; + + explicit v_uint8x16(const vec_uchar16& v) : val(v) + {} + v_uint8x16() : val(vec_uchar16_z) + {} + v_uint8x16(vec_bchar16 v) : val(vec_uchar16_c(v)) + {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + : val(vec_uchar16_set(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)) + {} + uchar get0() const + { return vec_extract(val, 0); } +}; + +struct v_int8x16 +{ + typedef schar lane_type; + enum { nlanes = 16 }; + vec_char16 val; + + explicit v_int8x16(const vec_char16& v) : val(v) + {} + v_int8x16() : val(vec_char16_z) + {} + v_int8x16(vec_bchar16 v) : val(vec_char16_c(v)) + {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + : val(vec_char16_set(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)) + {} + schar get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + enum { nlanes = 8 }; + vec_ushort8 val; + + explicit v_uint16x8(const vec_ushort8& v) : val(v) + {} + v_uint16x8() : val(vec_ushort8_z) + {} + v_uint16x8(vec_bshort8 v) : val(vec_ushort8_c(v)) + {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + : val(vec_ushort8_set(v0, v1, v2, v3, v4, v5, v6, v7)) + {} + ushort get0() const + { return vec_extract(val, 0); } +}; + +struct v_int16x8 +{ + typedef short lane_type; + enum { nlanes = 8 }; + vec_short8 val; + + explicit v_int16x8(const vec_short8& v) : val(v) + {} + v_int16x8() : val(vec_short8_z) + {} + v_int16x8(vec_bshort8 v) : val(vec_short8_c(v)) + {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + : val(vec_short8_set(v0, v1, v2, v3, v4, v5, v6, v7)) + {} + short get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + enum { nlanes = 4 }; + vec_uint4 val; + + explicit v_uint32x4(const vec_uint4& v) : val(v) + {} + v_uint32x4() : val(vec_uint4_z) + {} + v_uint32x4(vec_bint4 v) : val(vec_uint4_c(v)) + {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) : val(vec_uint4_set(v0, v1, v2, v3)) + {} + uint get0() const + { return vec_extract(val, 0); } +}; + +struct v_int32x4 +{ + typedef int lane_type; + enum { nlanes = 4 }; + vec_int4 val; + + explicit v_int32x4(const vec_int4& v) : val(v) + {} + v_int32x4() : val(vec_int4_z) + {} + v_int32x4(vec_bint4 v) : val(vec_int4_c(v)) + {} + v_int32x4(int v0, int v1, int v2, int v3) : val(vec_int4_set(v0, v1, v2, v3)) + {} + int get0() const + { return vec_extract(val, 0); } +}; + +struct v_float32x4 +{ + typedef float lane_type; + enum { nlanes = 4 }; + vec_float4 val; + + explicit v_float32x4(const vec_float4& v) : val(v) + {} + v_float32x4() : val(vec_float4_z) + {} + v_float32x4(vec_bint4 v) : val(vec_float4_c(v)) + {} + v_float32x4(float v0, float v1, float v2, float v3) : val(vec_float4_set(v0, v1, v2, v3)) + {} + float get0() const + { return vec_extract(val, 0); } +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + enum { nlanes = 2 }; + vec_udword2 val; + + explicit v_uint64x2(const vec_udword2& v) : val(v) + {} + v_uint64x2() : val(vec_udword2_z) + {} + v_uint64x2(vec_bdword2 v) : val(vec_udword2_c(v)) + {} + v_uint64x2(uint64 v0, uint64 v1) : val(vec_udword2_set(v0, v1)) + {} + uint64 get0() const + { return vec_extract(val, 0); } +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + enum { nlanes = 2 }; + vec_dword2 val; + + explicit v_int64x2(const vec_dword2& v) : val(v) + {} + v_int64x2() : val(vec_dword2_z) + {} + v_int64x2(vec_bdword2 v) : val(vec_dword2_c(v)) + {} + v_int64x2(int64 v0, int64 v1) : val(vec_dword2_set(v0, v1)) + {} + int64 get0() const + { return vec_extract(val, 0); } +}; + +struct v_float64x2 +{ + typedef double lane_type; + enum { nlanes = 2 }; + vec_double2 val; + + explicit v_float64x2(const vec_double2& v) : val(v) + {} + v_float64x2() : val(vec_double2_z) + {} + v_float64x2(vec_bdword2 v) : val(vec_double2_c(v)) + {} + v_float64x2(double v0, double v1) : val(vec_double2_set(v0, v1)) + {} + double get0() const + { return vec_extract(val, 0); } +}; + +#define OPENCV_HAL_IMPL_VSX_EXTRACT_N(_Tpvec, _Tp) \ +template inline _Tp v_extract_n(VSX_UNUSED(_Tpvec v)) { return vec_extract(v.val, i); } + +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_uint8x16, uchar) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_int8x16, schar) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_uint16x8, ushort) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_int16x8, short) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_uint32x4, uint) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_int32x4, int) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_uint64x2, uint64) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_int64x2, int64) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_float32x4, float) +OPENCV_HAL_IMPL_VSX_EXTRACT_N(v_float64x2, double) + +//////////////// Load and store operations /////////////// + +/* + * clang-5 aborted during parse "vec_xxx_c" only if it's + * inside a function template which is defined by preprocessor macro. + * + * if vec_xxx_c defined as C++ cast, clang-5 will pass it +*/ +#define OPENCV_HAL_IMPL_VSX_INITVEC(_Tpvec, _Tp, suffix, cast) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec(); } \ +inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec(vec_splats((_Tp)v));} \ +template inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0 &a) \ +{ return _Tpvec((cast)a.val); } + +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint8x16, uchar, u8, vec_uchar16) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int8x16, schar, s8, vec_char16) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint16x8, ushort, u16, vec_ushort8) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int16x8, short, s16, vec_short8) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint32x4, uint, u32, vec_uint4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int32x4, int, s32, vec_int4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_uint64x2, uint64, u64, vec_udword2) +OPENCV_HAL_IMPL_VSX_INITVEC(v_int64x2, int64, s64, vec_dword2) +OPENCV_HAL_IMPL_VSX_INITVEC(v_float32x4, float, f32, vec_float4) +OPENCV_HAL_IMPL_VSX_INITVEC(v_float64x2, double, f64, vec_double2) + +#define OPENCV_HAL_IMPL_VSX_LOADSTORE_C(_Tpvec, _Tp, ld, ld_a, st, st_a) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(ld(0, ptr)); } \ +inline _Tpvec v_load_aligned(VSX_UNUSED(const _Tp* ptr)) \ +{ return _Tpvec(ld_a(0, ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ return _Tpvec(vec_ld_l8(ptr)); } \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ return _Tpvec(vec_mergesqh(vec_ld_l8(ptr0), vec_ld_l8(ptr1))); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ st(a.val, 0, ptr); } \ +inline void v_store_aligned(VSX_UNUSED(_Tp* ptr), const _Tpvec& a) \ +{ st_a(a.val, 0, ptr); } \ +inline void v_store_aligned_nocache(VSX_UNUSED(_Tp* ptr), const _Tpvec& a) \ +{ st_a(a.val, 0, ptr); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \ +{ if(mode == hal::STORE_UNALIGNED) st(a.val, 0, ptr); else st_a(a.val, 0, ptr); } \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ vec_st_l8(a.val, ptr); } \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ vec_st_h8(a.val, ptr); } + +// working around gcc bug for aligned ld/st +// if runtime check for vec_ld/st fail we failback to unaligned ld/st +// https://github.com/opencv/opencv/issues/13211 +#ifdef CV_COMPILER_VSX_BROKEN_ALIGNED + #define OPENCV_HAL_IMPL_VSX_LOADSTORE(_Tpvec, _Tp) \ + OPENCV_HAL_IMPL_VSX_LOADSTORE_C(_Tpvec, _Tp, vsx_ld, vsx_ld, vsx_st, vsx_st) +#else + #define OPENCV_HAL_IMPL_VSX_LOADSTORE(_Tpvec, _Tp) \ + OPENCV_HAL_IMPL_VSX_LOADSTORE_C(_Tpvec, _Tp, vsx_ld, vec_ld, vsx_st, vec_st) +#endif + +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_uint8x16, uchar) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_int8x16, schar) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_uint16x8, ushort) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_int16x8, short) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_uint32x4, uint) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_int32x4, int) +OPENCV_HAL_IMPL_VSX_LOADSTORE(v_float32x4, float) + +OPENCV_HAL_IMPL_VSX_LOADSTORE_C(v_float64x2, double, vsx_ld, vsx_ld, vsx_st, vsx_st) +OPENCV_HAL_IMPL_VSX_LOADSTORE_C(v_uint64x2, uint64, vsx_ld2, vsx_ld2, vsx_st2, vsx_st2) +OPENCV_HAL_IMPL_VSX_LOADSTORE_C(v_int64x2, int64, vsx_ld2, vsx_ld2, vsx_st2, vsx_st2) + +//////////////// Value reordering /////////////// + +/* de&interleave */ +#define OPENCV_HAL_IMPL_VSX_INTERLEAVE(_Tp, _Tpvec) \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, _Tpvec& b) \ +{ vec_ld_deinterleave(ptr, a.val, b.val);} \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, \ + _Tpvec& b, _Tpvec& c) \ +{ vec_ld_deinterleave(ptr, a.val, b.val, c.val); } \ +inline void v_load_deinterleave(const _Tp* ptr, _Tpvec& a, _Tpvec& b, \ + _Tpvec& c, _Tpvec& d) \ +{ vec_ld_deinterleave(ptr, a.val, b.val, c.val, d.val); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ vec_st_interleave(a.val, b.val, ptr); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, \ + const _Tpvec& b, const _Tpvec& c, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ vec_st_interleave(a.val, b.val, c.val, ptr); } \ +inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b, \ + const _Tpvec& c, const _Tpvec& d, \ + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \ +{ vec_st_interleave(a.val, b.val, c.val, d.val, ptr); } + +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uchar, v_uint8x16) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(schar, v_int8x16) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(ushort, v_uint16x8) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(short, v_int16x8) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uint, v_uint32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(int, v_int32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(float, v_float32x4) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(double, v_float64x2) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(int64, v_int64x2) +OPENCV_HAL_IMPL_VSX_INTERLEAVE(uint64, v_uint64x2) + +/* Expand */ +#define OPENCV_HAL_IMPL_VSX_EXPAND(_Tpvec, _Tpwvec, _Tp, fl, fh) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + b0.val = fh(a.val); \ + b1.val = fl(a.val); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ return _Tpwvec(fh(a.val)); } \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ return _Tpwvec(fl(a.val)); } \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ return _Tpwvec(fh(vec_ld_l8(ptr))); } + +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint8x16, v_uint16x8, uchar, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int8x16, v_int16x8, schar, vec_unpackl, vec_unpackh) +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint16x8, v_uint32x4, ushort, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int16x8, v_int32x4, short, vec_unpackl, vec_unpackh) +OPENCV_HAL_IMPL_VSX_EXPAND(v_uint32x4, v_uint64x2, uint, vec_unpacklu, vec_unpackhu) +OPENCV_HAL_IMPL_VSX_EXPAND(v_int32x4, v_int64x2, int, vec_unpackl, vec_unpackh) + +/* Load and zero expand a 4 byte value into the second dword, first is don't care. */ +#if !defined(CV_COMPILER_VSX_BROKEN_ASM) + #define _LXSIWZX(out, ptr, T) __asm__ ("lxsiwzx %x0, 0, %1\r\n" : "=wa"(out) : "r" (ptr) : "memory"); +#else + /* This is compiler-agnostic, but will introduce an unneeded splat on the critical path. */ + #define _LXSIWZX(out, ptr, T) out = (T)vec_udword2_sp(*(uint32_t*)(ptr)); +#endif + +inline v_uint32x4 v_load_expand_q(const uchar* ptr) +{ + // Zero-extend the extra 24B instead of unpacking. Usually faster in small kernel + // Likewise note, value is zero extended and upper 4 bytes are zero'ed. + vec_uchar16 pmu = {8, 12, 12, 12, 9, 12, 12, 12, 10, 12, 12, 12, 11, 12, 12, 12}; + vec_uchar16 out; + + _LXSIWZX(out, ptr, vec_uchar16); + out = vec_perm(out, out, pmu); + return v_uint32x4((vec_uint4)out); +} + +inline v_int32x4 v_load_expand_q(const schar* ptr) +{ + vec_char16 out; + vec_short8 outs; + vec_int4 outw; + + _LXSIWZX(out, ptr, vec_char16); + outs = vec_unpackl(out); + outw = vec_unpackh(outs); + return v_int32x4(outw); +} + +/* pack */ +#define OPENCV_HAL_IMPL_VSX_PACK(_Tpvec, _Tp, _Tpwvec, _Tpvn, _Tpdel, sfnc, pkfnc, addfnc, pack) \ +inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + return _Tpvec(pkfnc(a.val, b.val)); \ +} \ +inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + vec_st_l8(pkfnc(a.val, a.val), ptr); \ +} \ +template \ +inline _Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \ +{ \ + const __vector _Tpvn vn = vec_splats((_Tpvn)n); \ + const __vector _Tpdel delta = vec_splats((_Tpdel)((_Tpdel)1 << (n-1))); \ + return _Tpvec(pkfnc(sfnc(addfnc(a.val, delta), vn), sfnc(addfnc(b.val, delta), vn))); \ +} \ +template \ +inline void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \ +{ \ + const __vector _Tpvn vn = vec_splats((_Tpvn)n); \ + const __vector _Tpdel delta = vec_splats((_Tpdel)((_Tpdel)1 << (n-1))); \ + vec_st_l8(pkfnc(sfnc(addfnc(a.val, delta), vn), delta), ptr); \ +} + +OPENCV_HAL_IMPL_VSX_PACK(v_uint8x16, uchar, v_uint16x8, unsigned short, unsigned short, + vec_sr, vec_packs, vec_adds, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int8x16, schar, v_int16x8, unsigned short, short, + vec_sra, vec_packs, vec_adds, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint16x8, ushort, v_uint32x4, unsigned int, unsigned int, + vec_sr, vec_packs, vec_add, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int16x8, short, v_int32x4, unsigned int, int, + vec_sra, vec_packs, vec_add, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint32x4, uint, v_uint64x2, unsigned long long, unsigned long long, + vec_sr, vec_pack, vec_add, pack) +OPENCV_HAL_IMPL_VSX_PACK(v_int32x4, int, v_int64x2, unsigned long long, long long, + vec_sra, vec_pack, vec_add, pack) + +OPENCV_HAL_IMPL_VSX_PACK(v_uint8x16, uchar, v_int16x8, unsigned short, short, + vec_sra, vec_packsu, vec_adds, pack_u) +OPENCV_HAL_IMPL_VSX_PACK(v_uint16x8, ushort, v_int32x4, unsigned int, int, + vec_sra, vec_packsu, vec_add, pack_u) +// Following variant is not implemented on other platforms: +//OPENCV_HAL_IMPL_VSX_PACK(v_uint32x4, uint, v_int64x2, unsigned long long, long long, +// vec_sra, vec_packsu, vec_add, pack_u) + +// pack boolean +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + vec_uchar16 ab = vec_pack(a.val, b.val); + return v_uint8x16(ab); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + vec_ushort8 ab = vec_pack(a.val, b.val); + vec_ushort8 cd = vec_pack(c.val, d.val); + return v_uint8x16(vec_pack(ab, cd)); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + vec_uint4 ab = vec_pack(a.val, b.val); + vec_uint4 cd = vec_pack(c.val, d.val); + vec_uint4 ef = vec_pack(e.val, f.val); + vec_uint4 gh = vec_pack(g.val, h.val); + + vec_ushort8 abcd = vec_pack(ab, cd); + vec_ushort8 efgh = vec_pack(ef, gh); + return v_uint8x16(vec_pack(abcd, efgh)); +} + +/* Recombine */ +template +inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) +{ + b0.val = vec_mergeh(a0.val, a1.val); + b1.val = vec_mergel(a0.val, a1.val); +} + +template +inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(vec_mergesql(a.val, b.val)); } + +template +inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) +{ return _Tpvec(vec_mergesqh(a.val, b.val)); } + +template +inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) +{ + c.val = vec_mergesqh(a.val, b.val); + d.val = vec_mergesql(a.val, b.val); +} + +////////// Arithmetic, bitwise and comparison operations ///////// + +/* Element-wise binary and unary operations */ +/** Arithmetics **/ +#define OPENCV_HAL_IMPL_VSX_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(intrin(a.val, b.val)); } \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ a.val = intrin(a.val, b.val); return a; } + +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint8x16, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint8x16, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int8x16, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int8x16, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint16x8, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint16x8, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int16x8, vec_adds) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int16x8, vec_subs) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_uint32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_int32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_float32x4, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_float32x4, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_float32x4, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(/, v_float32x4, vec_div) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_float64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_float64x2, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(*, v_float64x2, vec_mul) +OPENCV_HAL_IMPL_VSX_BIN_OP(/, v_float64x2, vec_div) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_uint64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_uint64x2, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_OP(+, v_int64x2, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_OP(-, v_int64x2, vec_sub) + +// saturating multiply +#define OPENCV_HAL_IMPL_VSX_MUL_SAT(_Tpvec, _Tpwvec) \ + inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ + { \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ + } \ + inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ + { a = a * b; return a; } + +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_int16x8, v_int32x4) +OPENCV_HAL_IMPL_VSX_MUL_SAT(v_uint16x8, v_uint32x4) + +template +inline void v_mul_expand(const Tvec& a, const Tvec& b, Twvec& c, Twvec& d) +{ + Twvec p0 = Twvec(vec_mule(a.val, b.val)); + Twvec p1 = Twvec(vec_mulo(a.val, b.val)); + v_zip(p0, p1, c, d); +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + vec_int4 p0 = vec_mule(a.val, b.val); + vec_int4 p1 = vec_mulo(a.val, b.val); + static const vec_uchar16 perm = {2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31}; + return v_int16x8(vec_perm(vec_short8_c(p0), vec_short8_c(p1), perm)); +} +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + vec_uint4 p0 = vec_mule(a.val, b.val); + vec_uint4 p1 = vec_mulo(a.val, b.val); + static const vec_uchar16 perm = {2, 3, 18, 19, 6, 7, 22, 23, 10, 11, 26, 27, 14, 15, 30, 31}; + return v_uint16x8(vec_perm(vec_ushort8_c(p0), vec_ushort8_c(p1), perm)); +} + +/** Non-saturating arithmetics **/ +#define OPENCV_HAL_IMPL_VSX_BIN_FUNC(func, intrin) \ +template \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(intrin(a.val, b.val)); } + +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_add_wrap, vec_add) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_sub_wrap, vec_sub) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_mul_wrap, vec_mul) + +/** Bitwise shifts **/ +#define OPENCV_HAL_IMPL_VSX_SHIFT_OP(_Tpvec, shr, splfunc) \ +inline _Tpvec operator << (const _Tpvec& a, int imm) \ +{ return _Tpvec(vec_sl(a.val, splfunc(imm))); } \ +inline _Tpvec operator >> (const _Tpvec& a, int imm) \ +{ return _Tpvec(shr(a.val, splfunc(imm))); } \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ return _Tpvec(vec_sl(a.val, splfunc(imm))); } \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ return _Tpvec(shr(a.val, splfunc(imm))); } + +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint8x16, vec_sr, vec_uchar16_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint16x8, vec_sr, vec_ushort8_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint32x4, vec_sr, vec_uint4_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_uint64x2, vec_sr, vec_udword2_sp) +// algebraic right shift +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int8x16, vec_sra, vec_uchar16_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int16x8, vec_sra, vec_ushort8_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int32x4, vec_sra, vec_uint4_sp) +OPENCV_HAL_IMPL_VSX_SHIFT_OP(v_int64x2, vec_sra, vec_udword2_sp) + +/** Bitwise logic **/ +#define OPENCV_HAL_IMPL_VSX_LOGIC_OP(_Tpvec) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(&, _Tpvec, vec_and) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(|, _Tpvec, vec_or) \ +OPENCV_HAL_IMPL_VSX_BIN_OP(^, _Tpvec, vec_xor) \ +inline _Tpvec operator ~ (const _Tpvec& a) \ +{ return _Tpvec(vec_not(a.val)); } + +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint8x16) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int8x16) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint16x8) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int16x8) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_uint64x2) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_int64x2) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_float32x4) +OPENCV_HAL_IMPL_VSX_LOGIC_OP(v_float64x2) + +/** Bitwise select **/ +#define OPENCV_HAL_IMPL_VSX_SELECT(_Tpvec, cast) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_sel(b.val, a.val, cast(mask.val))); } + +OPENCV_HAL_IMPL_VSX_SELECT(v_uint8x16, vec_bchar16_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int8x16, vec_bchar16_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_uint16x8, vec_bshort8_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int16x8, vec_bshort8_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_uint32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_int32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_float32x4, vec_bint4_c) +OPENCV_HAL_IMPL_VSX_SELECT(v_float64x2, vec_bdword2_c) + +/** Comparison **/ +#define OPENCV_HAL_IMPL_VSX_INT_CMP_OP(_Tpvec) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpeq(a.val, b.val)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpne(a.val, b.val)); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmplt(a.val, b.val)); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpgt(a.val, b.val)); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmple(a.val, b.val)); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_cmpge(a.val, b.val)); } + +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint8x16) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int8x16) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint16x8) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int16x8) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_float32x4) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_float64x2) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_uint64x2) +OPENCV_HAL_IMPL_VSX_INT_CMP_OP(v_int64x2) + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ return v_float32x4(vec_cmpeq(a.val, a.val)); } +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ return v_float64x2(vec_cmpeq(a.val, a.val)); } + +/** min/max **/ +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_min, vec_min) +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_max, vec_max) + +/** Rotate **/ +#define OPENCV_IMPL_VSX_ROTATE(_Tpvec, suffix, shf, cast) \ +template \ +inline _Tpvec v_rotate_##suffix(const _Tpvec& a) \ +{ \ + const int wd = imm * sizeof(typename _Tpvec::lane_type); \ + if (wd > 15) \ + return _Tpvec(); \ + return _Tpvec((cast)shf(vec_uchar16_c(a.val), vec_uchar16_sp(wd << 3))); \ +} + +#define OPENCV_IMPL_VSX_ROTATE_LR(_Tpvec, cast) \ +OPENCV_IMPL_VSX_ROTATE(_Tpvec, left, vec_slo, cast) \ +OPENCV_IMPL_VSX_ROTATE(_Tpvec, right, vec_sro, cast) + +OPENCV_IMPL_VSX_ROTATE_LR(v_uint8x16, vec_uchar16) +OPENCV_IMPL_VSX_ROTATE_LR(v_int8x16, vec_char16) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint16x8, vec_ushort8) +OPENCV_IMPL_VSX_ROTATE_LR(v_int16x8, vec_short8) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint32x4, vec_uint4) +OPENCV_IMPL_VSX_ROTATE_LR(v_int32x4, vec_int4) +OPENCV_IMPL_VSX_ROTATE_LR(v_float32x4, vec_float4) +OPENCV_IMPL_VSX_ROTATE_LR(v_uint64x2, vec_udword2) +OPENCV_IMPL_VSX_ROTATE_LR(v_int64x2, vec_dword2) +OPENCV_IMPL_VSX_ROTATE_LR(v_float64x2, vec_double2) + +template +inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) +{ + enum { CV_SHIFT = 16 - imm * (sizeof(typename _Tpvec::lane_type)) }; + if (CV_SHIFT == 16) + return a; +#ifdef __IBMCPP__ + return _Tpvec(vec_sld(b.val, a.val, CV_SHIFT & 15)); +#else + return _Tpvec(vec_sld(b.val, a.val, CV_SHIFT)); +#endif +} + +template +inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) +{ + enum { CV_SHIFT = imm * (sizeof(typename _Tpvec::lane_type)) }; + if (CV_SHIFT == 16) + return b; + return _Tpvec(vec_sld(a.val, b.val, CV_SHIFT)); +} + +#define OPENCV_IMPL_VSX_ROTATE_64_2RG(_Tpvec, suffix, rg1, rg2) \ +template \ +inline _Tpvec v_rotate_##suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + if (imm == 1) \ + return _Tpvec(vec_permi(rg1.val, rg2.val, 2)); \ + return imm ? b : a; \ +} + +#define OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(_Tpvec) \ +OPENCV_IMPL_VSX_ROTATE_64_2RG(_Tpvec, left, b, a) \ +OPENCV_IMPL_VSX_ROTATE_64_2RG(_Tpvec, right, a, b) + +OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(v_float64x2) +OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(v_uint64x2) +OPENCV_IMPL_VSX_ROTATE_64_2RG_LR(v_int64x2) + +/* Reverse */ +inline v_uint8x16 v_reverse(const v_uint8x16 &a) +{ + static const vec_uchar16 perm = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + vec_uchar16 vec = (vec_uchar16)a.val; + return v_uint8x16(vec_perm(vec, vec, perm)); +} + +inline v_int8x16 v_reverse(const v_int8x16 &a) +{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); } + +inline v_uint16x8 v_reverse(const v_uint16x8 &a) +{ + static const vec_uchar16 perm = {14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1}; + vec_uchar16 vec = (vec_uchar16)a.val; + return v_reinterpret_as_u16(v_uint8x16(vec_perm(vec, vec, perm))); +} + +inline v_int16x8 v_reverse(const v_int16x8 &a) +{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); } + +inline v_uint32x4 v_reverse(const v_uint32x4 &a) +{ + static const vec_uchar16 perm = {12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3}; + vec_uchar16 vec = (vec_uchar16)a.val; + return v_reinterpret_as_u32(v_uint8x16(vec_perm(vec, vec, perm))); +} + +inline v_int32x4 v_reverse(const v_int32x4 &a) +{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_float32x4 v_reverse(const v_float32x4 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x2 v_reverse(const v_uint64x2 &a) +{ + static const vec_uchar16 perm = {8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7}; + vec_uchar16 vec = (vec_uchar16)a.val; + return v_reinterpret_as_u64(v_uint8x16(vec_perm(vec, vec, perm))); +} + +inline v_int64x2 v_reverse(const v_int64x2 &a) +{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); } + +inline v_float64x2 v_reverse(const v_float64x2 &a) +{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); } + +/* Extract */ +template +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) +{ return v_rotate_right(a, b); } + +////////// Reduce and mask ///////// + +/** Reduce **/ +inline uint v_reduce_sum(const v_uint8x16& a) +{ + const vec_uint4 zero4 = vec_uint4_z; + vec_uint4 sum4 = vec_sum4s(a.val, zero4); + return (uint)vec_extract(vec_sums(vec_int4_c(sum4), vec_int4_c(zero4)), 3); +} +inline int v_reduce_sum(const v_int8x16& a) +{ + const vec_int4 zero4 = vec_int4_z; + vec_int4 sum4 = vec_sum4s(a.val, zero4); + return (int)vec_extract(vec_sums(sum4, zero4), 3); +} +inline int v_reduce_sum(const v_int16x8& a) +{ + const vec_int4 zero = vec_int4_z; + return saturate_cast(vec_extract(vec_sums(vec_sum4s(a.val, zero), zero), 3)); +} +inline uint v_reduce_sum(const v_uint16x8& a) +{ + const vec_int4 v4 = vec_int4_c(vec_unpackhu(vec_adds(a.val, vec_sld(a.val, a.val, 8)))); + return saturate_cast(vec_extract(vec_sums(v4, vec_int4_z), 3)); +} + +#define OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(_Tpvec, _Tpvec2, scalartype, suffix, func) \ +inline scalartype v_reduce_##suffix(const _Tpvec& a) \ +{ \ + const _Tpvec2 rs = func(a.val, vec_sld(a.val, a.val, 8)); \ + return vec_extract(func(rs, vec_sld(rs, rs, 4)), 0); \ +} +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_uint32x4, vec_uint4, uint, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_int32x4, vec_int4, int, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, sum, vec_add) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_4(v_float32x4, vec_float4, float, min, vec_min) + +inline uint64 v_reduce_sum(const v_uint64x2& a) +{ + return vec_extract(vec_add(a.val, vec_permi(a.val, a.val, 3)), 0); +} +inline int64 v_reduce_sum(const v_int64x2& a) +{ + return vec_extract(vec_add(a.val, vec_permi(a.val, a.val, 3)), 0); +} +inline double v_reduce_sum(const v_float64x2& a) +{ + return vec_extract(vec_add(a.val, vec_permi(a.val, a.val, 3)), 0); +} + +#define OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(_Tpvec, _Tpvec2, scalartype, suffix, func) \ +inline scalartype v_reduce_##suffix(const _Tpvec& a) \ +{ \ + _Tpvec2 rs = func(a.val, vec_sld(a.val, a.val, 8)); \ + rs = func(rs, vec_sld(rs, rs, 4)); \ + return vec_extract(func(rs, vec_sld(rs, rs, 2)), 0); \ +} +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_uint16x8, vec_ushort8, ushort, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_uint16x8, vec_ushort8, ushort, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_int16x8, vec_short8, short, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_8(v_int16x8, vec_short8, short, min, vec_min) + +#define OPENCV_HAL_IMPL_VSX_REDUCE_OP_16(_Tpvec, _Tpvec2, scalartype, suffix, func) \ +inline scalartype v_reduce_##suffix(const _Tpvec& a) \ +{ \ + _Tpvec2 rs = func(a.val, vec_sld(a.val, a.val, 8)); \ + rs = func(rs, vec_sld(rs, rs, 4)); \ + rs = func(rs, vec_sld(rs, rs, 2)); \ + return vec_extract(func(rs, vec_sld(rs, rs, 1)), 0); \ +} +OPENCV_HAL_IMPL_VSX_REDUCE_OP_16(v_uint8x16, vec_uchar16, uchar, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_16(v_uint8x16, vec_uchar16, uchar, min, vec_min) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_16(v_int8x16, vec_char16, schar, max, vec_max) +OPENCV_HAL_IMPL_VSX_REDUCE_OP_16(v_int8x16, vec_char16, schar, min, vec_min) + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + vec_float4 ac = vec_add(vec_mergel(a.val, c.val), vec_mergeh(a.val, c.val)); + ac = vec_add(ac, vec_sld(ac, ac, 8)); + + vec_float4 bd = vec_add(vec_mergel(b.val, d.val), vec_mergeh(b.val, d.val)); + bd = vec_add(bd, vec_sld(bd, bd, 8)); + return v_float32x4(vec_mergeh(ac, bd)); +} + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + const vec_uint4 zero4 = vec_uint4_z; + vec_uint4 sum4 = vec_sum4s(vec_absd(a.val, b.val), zero4); + return (unsigned)vec_extract(vec_sums(vec_int4_c(sum4), vec_int4_c(zero4)), 3); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + const vec_int4 zero4 = vec_int4_z; + vec_char16 ad = vec_abss(vec_subs(a.val, b.val)); + vec_int4 sum4 = vec_sum4s(ad, zero4); + return (unsigned)vec_extract(vec_sums(sum4, zero4), 3); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + vec_ushort8 ad = vec_absd(a.val, b.val); + VSX_UNUSED(vec_int4) sum = vec_sums(vec_int4_c(vec_unpackhu(ad)) + vec_int4_c(vec_unpacklu(ad)), vec_int4_z); + return (unsigned)vec_extract(sum, 3); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + const vec_int4 zero4 = vec_int4_z; + vec_short8 ad = vec_abss(vec_subs(a.val, b.val)); + vec_int4 sum4 = vec_sum4s(ad, zero4); + return (unsigned)vec_extract(vec_sums(sum4, zero4), 3); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + const vec_uint4 ad = vec_absd(a.val, b.val); + const vec_uint4 rd = vec_add(ad, vec_sld(ad, ad, 8)); + return vec_extract(vec_add(rd, vec_sld(rd, rd, 4)), 0); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + vec_int4 ad = vec_abss(vec_sub(a.val, b.val)); + return (unsigned)vec_extract(vec_sums(ad, vec_int4_z), 3); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + const vec_float4 ad = vec_abs(vec_sub(a.val, b.val)); + const vec_float4 rd = vec_add(ad, vec_sld(ad, ad, 8)); + return vec_extract(vec_add(rd, vec_sld(rd, rd, 4)), 0); +} + +/** Popcount **/ +inline v_uint8x16 v_popcount(const v_uint8x16& a) +{ return v_uint8x16(vec_popcntu(a.val)); } +inline v_uint8x16 v_popcount(const v_int8x16& a) +{ return v_uint8x16(vec_popcntu(a.val)); } +inline v_uint16x8 v_popcount(const v_uint16x8& a) +{ return v_uint16x8(vec_popcntu(a.val)); } +inline v_uint16x8 v_popcount(const v_int16x8& a) +{ return v_uint16x8(vec_popcntu(a.val)); } +inline v_uint32x4 v_popcount(const v_uint32x4& a) +{ return v_uint32x4(vec_popcntu(a.val)); } +inline v_uint32x4 v_popcount(const v_int32x4& a) +{ return v_uint32x4(vec_popcntu(a.val)); } +inline v_uint64x2 v_popcount(const v_uint64x2& a) +{ return v_uint64x2(vec_popcntu(a.val)); } +inline v_uint64x2 v_popcount(const v_int64x2& a) +{ return v_uint64x2(vec_popcntu(a.val)); } + +/** Mask **/ +inline int v_signmask(const v_uint8x16& a) +{ + static const vec_uchar16 qperm = {120, 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0}; + return vec_extract((vec_int4)vec_vbpermq(v_reinterpret_as_u8(a).val, qperm), 2); +} +inline int v_signmask(const v_int8x16& a) +{ return v_signmask(v_reinterpret_as_u8(a)); } + +inline int v_signmask(const v_int16x8& a) +{ + static const vec_uchar16 qperm = {112, 96, 80, 64, 48, 32, 16, 0, 128, 128, 128, 128, 128, 128, 128, 128}; + return vec_extract((vec_int4)vec_vbpermq(v_reinterpret_as_u8(a).val, qperm), 2); +} +inline int v_signmask(const v_uint16x8& a) +{ return v_signmask(v_reinterpret_as_s16(a)); } + +inline int v_signmask(const v_int32x4& a) +{ + static const vec_uchar16 qperm = {96, 64, 32, 0, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}; + return vec_extract((vec_int4)vec_vbpermq(v_reinterpret_as_u8(a).val, qperm), 2); +} +inline int v_signmask(const v_uint32x4& a) +{ return v_signmask(v_reinterpret_as_s32(a)); } +inline int v_signmask(const v_float32x4& a) +{ return v_signmask(v_reinterpret_as_s32(a)); } + +inline int v_signmask(const v_int64x2& a) +{ + VSX_UNUSED(const vec_dword2) sv = vec_sr(a.val, vec_udword2_sp(63)); + return (int)vec_extract(sv, 0) | (int)vec_extract(sv, 1) << 1; +} +inline int v_signmask(const v_uint64x2& a) +{ return v_signmask(v_reinterpret_as_s64(a)); } +inline int v_signmask(const v_float64x2& a) +{ return v_signmask(v_reinterpret_as_s64(a)); } + +inline int v_scan_forward(const v_int8x16& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint8x16& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int16x8& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint16x8& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_float32x4& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_int64x2& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signmask(a)); } +inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(a)); } + +template +inline bool v_check_all(const _Tpvec& a) +{ return vec_all_lt(a.val, _Tpvec().val); } +inline bool v_check_all(const v_uint8x16& a) +{ return v_check_all(v_reinterpret_as_s8(a)); } +inline bool v_check_all(const v_uint16x8& a) +{ return v_check_all(v_reinterpret_as_s16(a)); } +inline bool v_check_all(const v_uint32x4& a) +{ return v_check_all(v_reinterpret_as_s32(a)); } +inline bool v_check_all(const v_uint64x2& a) +{ return v_check_all(v_reinterpret_as_s64(a)); } +inline bool v_check_all(const v_float32x4& a) +{ return v_check_all(v_reinterpret_as_s32(a)); } +inline bool v_check_all(const v_float64x2& a) +{ return v_check_all(v_reinterpret_as_s64(a)); } + +template +inline bool v_check_any(const _Tpvec& a) +{ return vec_any_lt(a.val, _Tpvec().val); } +inline bool v_check_any(const v_uint8x16& a) +{ return v_check_any(v_reinterpret_as_s8(a)); } +inline bool v_check_any(const v_uint16x8& a) +{ return v_check_any(v_reinterpret_as_s16(a)); } +inline bool v_check_any(const v_uint32x4& a) +{ return v_check_any(v_reinterpret_as_s32(a)); } +inline bool v_check_any(const v_uint64x2& a) +{ return v_check_any(v_reinterpret_as_s64(a)); } +inline bool v_check_any(const v_float32x4& a) +{ return v_check_any(v_reinterpret_as_s32(a)); } +inline bool v_check_any(const v_float64x2& a) +{ return v_check_any(v_reinterpret_as_s64(a)); } + +////////// Other math ///////// + +/** Some frequent operations **/ +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ return v_float32x4(vec_sqrt(x.val)); } +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ return v_float64x2(vec_sqrt(x.val)); } + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ return v_float32x4(vec_rsqrt(x.val)); } +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ return v_float64x2(vec_rsqrt(x.val)); } + +#define OPENCV_HAL_IMPL_VSX_MULADD(_Tpvec) \ +inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_sqrt(vec_madd(a.val, a.val, vec_mul(b.val, b.val)))); } \ +inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(vec_madd(a.val, a.val, vec_mul(b.val, b.val))); } \ +inline _Tpvec v_fma(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ return _Tpvec(vec_madd(a.val, b.val, c.val)); } \ +inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ return _Tpvec(vec_madd(a.val, b.val, c.val)); } + +OPENCV_HAL_IMPL_VSX_MULADD(v_float32x4) +OPENCV_HAL_IMPL_VSX_MULADD(v_float64x2) + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ return a * b + c; } + +// TODO: exp, log, sin, cos + +/** Absolute values **/ +inline v_uint8x16 v_abs(const v_int8x16& x) +{ return v_uint8x16(vec_uchar16_c(vec_abs(x.val))); } + +inline v_uint16x8 v_abs(const v_int16x8& x) +{ return v_uint16x8(vec_ushort8_c(vec_abs(x.val))); } + +inline v_uint32x4 v_abs(const v_int32x4& x) +{ return v_uint32x4(vec_uint4_c(vec_abs(x.val))); } + +inline v_float32x4 v_abs(const v_float32x4& x) +{ return v_float32x4(vec_abs(x.val)); } + +inline v_float64x2 v_abs(const v_float64x2& x) +{ return v_float64x2(vec_abs(x.val)); } + +/** Absolute difference **/ +// unsigned +OPENCV_HAL_IMPL_VSX_BIN_FUNC(v_absdiff, vec_absd) + +inline v_uint8x16 v_absdiff(const v_int8x16& a, const v_int8x16& b) +{ return v_reinterpret_as_u8(v_sub_wrap(v_max(a, b), v_min(a, b))); } +inline v_uint16x8 v_absdiff(const v_int16x8& a, const v_int16x8& b) +{ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); } +inline v_uint32x4 v_absdiff(const v_int32x4& a, const v_int32x4& b) +{ return v_reinterpret_as_u32(v_max(a, b) - v_min(a, b)); } + +inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +{ return v_abs(a - b); } +inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +{ return v_abs(a - b); } + +/** Absolute difference for signed integers **/ +inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b) +{ return v_int8x16(vec_abss(vec_subs(a.val, b.val))); } +inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b) +{ return v_int16x8(vec_abss(vec_subs(a.val, b.val))); } + +////////// Conversions ///////// + +/** Rounding **/ +inline v_int32x4 v_round(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_rint(a.val))); } + +inline v_int32x4 v_round(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_rint(a.val)), vec_int4_z)); } + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_rint(a.val)), vec_ctso(vec_rint(b.val)))); } + +inline v_int32x4 v_floor(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_floor(a.val))); } + +inline v_int32x4 v_floor(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_floor(a.val)), vec_int4_z)); } + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ return v_int32x4(vec_cts(vec_ceil(a.val))); } + +inline v_int32x4 v_ceil(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(vec_ceil(a.val)), vec_int4_z)); } + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(vec_cts(a.val)); } + +inline v_int32x4 v_trunc(const v_float64x2& a) +{ return v_int32x4(vec_mergesqo(vec_ctso(a.val), vec_int4_z)); } + +/** To float **/ +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ return v_float32x4(vec_ctf(a.val)); } + +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ return v_float32x4(vec_mergesqo(vec_cvfo(a.val), vec_float4_z)); } + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ return v_float32x4(vec_mergesqo(vec_cvfo(a.val), vec_cvfo(b.val))); } + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ return v_float64x2(vec_ctdo(vec_mergeh(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ return v_float64x2(vec_ctdo(vec_mergel(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ return v_float64x2(vec_cvfo(vec_mergeh(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ return v_float64x2(vec_cvfo(vec_mergel(a.val, a.val))); } + +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ return v_float64x2(vec_ctd(a.val)); } + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ + return v_int8x16(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]], tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]], + tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]]); +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ + return v_reinterpret_as_s8(v_int16x8(*(const short*)(tab+idx[0]), *(const short*)(tab+idx[1]), *(const short*)(tab+idx[2]), *(const short*)(tab+idx[3]), + *(const short*)(tab+idx[4]), *(const short*)(tab+idx[5]), *(const short*)(tab+idx[6]), *(const short*)(tab+idx[7]))); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + return v_reinterpret_as_s8(v_int32x4(*(const int*)(tab+idx[0]), *(const int*)(tab+idx[1]), *(const int*)(tab+idx[2]), *(const int*)(tab+idx[3]))); +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((const schar*)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((const schar*)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((const schar*)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + return v_int16x8(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]], tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + return v_reinterpret_as_s16(v_int32x4(*(const int*)(tab + idx[0]), *(const int*)(tab + idx[1]), *(const int*)(tab + idx[2]), *(const int*)(tab + idx[3]))); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_reinterpret_as_s16(v_int64x2(*(const int64*)(tab + idx[0]), *(const int64*)(tab + idx[1]))); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((const short*)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((const short*)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((const short*)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + return v_int32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_reinterpret_as_s32(v_int64x2(*(const int64*)(tab + idx[0]), *(const int64*)(tab + idx[1]))); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(vsx_ld(0, tab + idx[0])); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((const int*)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((const int*)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((const int*)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(tab[idx[0]], tab[idx[1]]); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(vsx_ld2(0, tab + idx[0])); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + return v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_pairs((const int*)tab, idx)); } +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) { return v_load(tab + *idx); } + +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + return v_float64x2(tab[idx[0]], tab[idx[1]]); +} +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) { return v_load(tab + *idx); } + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + const int idx[4] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1), + vec_extract(idxvec.val, 2), + vec_extract(idxvec.val, 3) + }; + return v_int32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + const int idx[4] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1), + vec_extract(idxvec.val, 2), + vec_extract(idxvec.val, 3) + }; + return v_uint32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + const int idx[4] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1), + vec_extract(idxvec.val, 2), + vec_extract(idxvec.val, 3) + }; + return v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + const int idx[2] = { + vec_extract(idxvec.val, 0), + vec_extract(idxvec.val, 1) + }; + return v_float64x2(tab[idx[0]], tab[idx[1]]); +} + +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + vec_float4 xy0 = vec_ld_l8(tab + vec_extract(idxvec.val, 0)); + vec_float4 xy1 = vec_ld_l8(tab + vec_extract(idxvec.val, 1)); + vec_float4 xy2 = vec_ld_l8(tab + vec_extract(idxvec.val, 2)); + vec_float4 xy3 = vec_ld_l8(tab + vec_extract(idxvec.val, 3)); + vec_float4 xy02 = vec_mergeh(xy0, xy2); // x0, x2, y0, y2 + vec_float4 xy13 = vec_mergeh(xy1, xy3); // x1, x3, y1, y3 + x.val = vec_mergeh(xy02, xy13); + y.val = vec_mergel(xy02, xy13); +} +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + vec_double2 xy0 = vsx_ld(vec_extract(idxvec.val, 0), tab); + vec_double2 xy1 = vsx_ld(vec_extract(idxvec.val, 1), tab); + x.val = vec_mergeh(xy0, xy1); + y.val = vec_mergel(xy0, xy1); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ + static const vec_uchar16 perm = {0, 2, 1, 3, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15}; + return v_int8x16(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) +{ return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } + +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ + static const vec_uchar16 perm = {0, 4, 1, 5, 2, 6, 3, 7, 8, 12, 9, 13, 10, 14, 11, 15}; + return v_int8x16(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) +{ return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ + static const vec_uchar16 perm = {0,1, 4,5, 2,3, 6,7, 8,9, 12,13, 10,11, 14,15}; + return v_int16x8(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) +{ return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } + +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ + static const vec_uchar16 perm = {0,1, 8,9, 2,3, 10,11, 4,5, 12,13, 6,7, 14,15}; + return v_int16x8(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) +{ return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + static const vec_uchar16 perm = {0,1,2,3, 8,9,10,11, 4,5,6,7, 12,13,14,15}; + return v_int32x4(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) +{ return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) +{ return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ + static const vec_uchar16 perm = {0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, 15, 15, 15}; + return v_int8x16(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) +{ return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ + static const vec_uchar16 perm = {0,1, 2,3, 4,5, 8,9, 10,11, 12,13, 14,15, 14,15}; + return v_int16x8(vec_perm(vec.val, vec.val, perm)); +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) +{ return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) +{ return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) +{ return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) +{ return vec; } + +/////// FP16 support //////// + +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + vec_ushort8 vf16 = vec_ld_l8((const ushort*)ptr); +#if CV_VSX3 && defined(vec_extract_fp_from_shorth) + return v_float32x4(vec_extract_fp_from_shorth(vf16)); +#elif CV_VSX3 && !defined(CV_COMPILER_VSX_BROKEN_ASM) + vec_float4 vf32; + __asm__ __volatile__ ("xvcvhpsp %x0,%x1" : "=wf" (vf32) : "wa" (vec_mergeh(vf16, vf16))); + return v_float32x4(vf32); +#else + const vec_int4 z = vec_int4_z, delta = vec_int4_sp(0x38000000); + const vec_int4 signmask = vec_int4_sp(0x80000000); + const vec_int4 maxexp = vec_int4_sp(0x7c000000); + const vec_float4 deltaf = vec_float4_c(vec_int4_sp(0x38800000)); + + vec_int4 bits = vec_int4_c(vec_mergeh(vec_short8_c(z), vec_short8_c(vf16))); + vec_int4 e = vec_and(bits, maxexp), sign = vec_and(bits, signmask); + vec_int4 t = vec_add(vec_sr(vec_xor(bits, sign), vec_uint4_sp(3)), delta); // ((h & 0x7fff) << 13) + delta + vec_int4 zt = vec_int4_c(vec_sub(vec_float4_c(vec_add(t, vec_int4_sp(1 << 23))), deltaf)); + + t = vec_add(t, vec_and(delta, vec_cmpeq(maxexp, e))); + vec_bint4 zmask = vec_cmpeq(e, z); + vec_int4 ft = vec_sel(t, zt, zmask); + return v_float32x4(vec_float4_c(vec_or(ft, sign))); +#endif +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ +// fixme: Is there any builtin op or intrinsic that cover "xvcvsphp"? +#if CV_VSX3 && !defined(CV_COMPILER_VSX_BROKEN_ASM) + vec_ushort8 vf16; + __asm__ __volatile__ ("xvcvsphp %x0,%x1" : "=wa" (vf16) : "wf" (v.val)); + vec_st_l8(vec_mergesqe(vf16, vf16), ptr); +#else + const vec_int4 signmask = vec_int4_sp(0x80000000); + const vec_int4 rval = vec_int4_sp(0x3f000000); + + vec_int4 t = vec_int4_c(v.val); + vec_int4 sign = vec_sra(vec_and(t, signmask), vec_uint4_sp(16)); + t = vec_and(vec_nor(signmask, signmask), t); + + vec_bint4 finitemask = vec_cmpgt(vec_int4_sp(0x47800000), t); + vec_bint4 isnan = vec_cmpgt(t, vec_int4_sp(0x7f800000)); + vec_int4 naninf = vec_sel(vec_int4_sp(0x7c00), vec_int4_sp(0x7e00), isnan); + vec_bint4 tinymask = vec_cmpgt(vec_int4_sp(0x38800000), t); + vec_int4 tt = vec_int4_c(vec_add(vec_float4_c(t), vec_float4_c(rval))); + tt = vec_sub(tt, rval); + vec_int4 odd = vec_and(vec_sr(t, vec_uint4_sp(13)), vec_int4_sp(1)); + vec_int4 nt = vec_add(t, vec_int4_sp(0xc8000fff)); + nt = vec_sr(vec_add(nt, odd), vec_uint4_sp(13)); + t = vec_sel(nt, tt, tinymask); + t = vec_sel(naninf, t, finitemask); + t = vec_or(t, sign); + vec_st_l8(vec_packs(t, t), ptr); +#endif +} + +inline void v_cleanup() {} + + +/** Reinterpret **/ +/** its up there with load and store operations **/ + +////////// Matrix operations ///////// + +//////// Dot Product //////// +// 16 >> 32 +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ return v_int32x4(vec_msum(a.val, b.val, vec_int4_z)); } +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_int32x4(vec_msum(a.val, b.val, c.val)); } + +// 32 >> 64 +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b) +{ + vec_dword2 even = vec_mule(a.val, b.val); + vec_dword2 odd = vec_mulo(a.val, b.val); + return v_int64x2(vec_add(even, odd)); +} +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ return v_dotprod(a, b) + c; } + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ return v_uint32x4(vec_msum(a.val, b.val, c.val)); } +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b) +{ return v_uint32x4(vec_msum(a.val, b.val, vec_uint4_z)); } + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b) +{ + const vec_ushort8 eight = vec_ushort8_sp(8); + vec_short8 a0 = vec_sra((vec_short8)vec_sld(a.val, a.val, 1), eight); // even + vec_short8 a1 = vec_sra((vec_short8)a.val, eight); // odd + vec_short8 b0 = vec_sra((vec_short8)vec_sld(b.val, b.val, 1), eight); + vec_short8 b1 = vec_sra((vec_short8)b.val, eight); + return v_int32x4(vec_msum(a0, b0, vec_msum(a1, b1, vec_int4_z))); +} + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ + const vec_ushort8 eight = vec_ushort8_sp(8); + vec_short8 a0 = vec_sra((vec_short8)vec_sld(a.val, a.val, 1), eight); // even + vec_short8 a1 = vec_sra((vec_short8)a.val, eight); // odd + vec_short8 b0 = vec_sra((vec_short8)vec_sld(b.val, b.val, 1), eight); + vec_short8 b1 = vec_sra((vec_short8)b.val, eight); + return v_int32x4(vec_msum(a0, b0, vec_msum(a1, b1, c.val))); +} + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b) +{ + const vec_uint4 zero = vec_uint4_z; + vec_uint4 even = vec_mule(a.val, b.val); + vec_uint4 odd = vec_mulo(a.val, b.val); + vec_udword2 e0 = (vec_udword2)vec_mergee(even, zero); + vec_udword2 e1 = (vec_udword2)vec_mergeo(even, zero); + vec_udword2 o0 = (vec_udword2)vec_mergee(odd, zero); + vec_udword2 o1 = (vec_udword2)vec_mergeo(odd, zero); + vec_udword2 s0 = vec_add(e0, o0); + vec_udword2 s1 = vec_add(e1, o1); + return v_uint64x2(vec_add(s0, s1)); +} +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b) +{ + v_int32x4 prod = v_dotprod(a, b); + v_int64x2 c, d; + v_expand(prod, c, d); + return v_int64x2(vec_add(vec_mergeh(c.val, d.val), vec_mergel(c.val, d.val))); +} +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +// 32 >> 64f +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) +{ return v_dotprod(a, b); } +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_int32x4(vec_msum(a.val, b.val, vec_int4_z)) + c; } +// 32 >> 64 +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_dotprod(a, b); } +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ return v_dotprod(a, b, c); } + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b) +{ return v_dotprod_expand(a, b); } +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ return v_uint32x4(vec_msum(a.val, b.val, vec_uint4_z)) + c; } + +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b) +{ + vec_short8 a0 = vec_unpackh(a.val); + vec_short8 a1 = vec_unpackl(a.val); + vec_short8 b0 = vec_unpackh(b.val); + vec_short8 b1 = vec_unpackl(b.val); + return v_int32x4(vec_msum(a0, b0, vec_msum(a1, b1, vec_int4_z))); +} +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b) +{ return v_dotprod_expand(a, b); } +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand(a, b, c); } + +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b) +{ + v_int32x4 prod = v_dotprod(a, b); + v_int64x2 c, d; + v_expand(prod, c, d); + return c + d; +} +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand_fast(a, b) + c; } + +// 32 >> 64f +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_dotprod_expand(a, b); } +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand(a, b, c); } + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + const vec_float4 v0 = vec_splat(v.val, 0); + const vec_float4 v1 = vec_splat(v.val, 1); + const vec_float4 v2 = vec_splat(v.val, 2); + VSX_UNUSED(const vec_float4) v3 = vec_splat(v.val, 3); + return v_float32x4(vec_madd(v0, m0.val, vec_madd(v1, m1.val, vec_madd(v2, m2.val, vec_mul(v3, m3.val))))); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + const vec_float4 v0 = vec_splat(v.val, 0); + const vec_float4 v1 = vec_splat(v.val, 1); + const vec_float4 v2 = vec_splat(v.val, 2); + return v_float32x4(vec_madd(v0, m0.val, vec_madd(v1, m1.val, vec_madd(v2, m2.val, a.val)))); +} + +#define OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(_Tpvec, _Tpvec2) \ +inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \ +{ \ + _Tpvec2 a02 = vec_mergeh(a0.val, a2.val); \ + _Tpvec2 a13 = vec_mergeh(a1.val, a3.val); \ + b0.val = vec_mergeh(a02, a13); \ + b1.val = vec_mergel(a02, a13); \ + a02 = vec_mergel(a0.val, a2.val); \ + a13 = vec_mergel(a1.val, a3.val); \ + b2.val = vec_mergeh(a02, a13); \ + b3.val = vec_mergel(a02, a13); \ +} +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_uint32x4, vec_uint4) +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_int32x4, vec_int4) +OPENCV_HAL_IMPL_VSX_TRANSPOSE4x4(v_float32x4, vec_float4) + +template +inline v_int8x16 v_broadcast_element(v_int8x16 v) +{ + return v_int8x16(vec_perm(v.val, v.val, vec_splats((unsigned char)i))); +} + +template +inline v_uint8x16 v_broadcast_element(v_uint8x16 v) +{ + return v_uint8x16(vec_perm(v.val, v.val, vec_splats((unsigned char)i))); +} + +template +inline v_int16x8 v_broadcast_element(v_int16x8 v) +{ + unsigned char t0 = 2*i, t1 = 2*i + 1; + vec_uchar16 p = {t0, t1, t0, t1, t0, t1, t0, t1, t0, t1, t0, t1, t0, t1, t0, t1}; + return v_int16x8(vec_perm(v.val, v.val, p)); +} + +template +inline v_uint16x8 v_broadcast_element(v_uint16x8 v) +{ + unsigned char t0 = 2*i, t1 = 2*i + 1; + vec_uchar16 p = {t0, t1, t0, t1, t0, t1, t0, t1, t0, t1, t0, t1, t0, t1, t0, t1}; + return v_uint16x8(vec_perm(v.val, v.val, p)); +} + +template +inline v_int32x4 v_broadcast_element(v_int32x4 v) +{ + unsigned char t0 = 4*i, t1 = 4*i + 1, t2 = 4*i + 2, t3 = 4*i + 3; + vec_uchar16 p = {t0, t1, t2, t3, t0, t1, t2, t3, t0, t1, t2, t3, t0, t1, t2, t3}; + return v_int32x4(vec_perm(v.val, v.val, p)); +} + +template +inline v_uint32x4 v_broadcast_element(v_uint32x4 v) +{ + unsigned char t0 = 4*i, t1 = 4*i + 1, t2 = 4*i + 2, t3 = 4*i + 3; + vec_uchar16 p = {t0, t1, t2, t3, t0, t1, t2, t3, t0, t1, t2, t3, t0, t1, t2, t3}; + return v_uint32x4(vec_perm(v.val, v.val, p)); +} + +template +inline v_int64x2 v_broadcast_element(v_int64x2 v) +{ + unsigned char t0 = 8*i, t1 = 8*i + 1, t2 = 8*i + 2, t3 = 8*i + 3, t4 = 8*i + 4, t5 = 8*i + 5, t6 = 8*i + 6, t7 = 8*i + 7; + vec_uchar16 p = {t0, t1, t2, t3, t4, t5, t6, t7, t0, t1, t2, t3, t4, t5, t6, t7}; + return v_int64x2(vec_perm(v.val, v.val, p)); +} + +template +inline v_uint64x2 v_broadcast_element(v_uint64x2 v) +{ + unsigned char t0 = 8*i, t1 = 8*i + 1, t2 = 8*i + 2, t3 = 8*i + 3, t4 = 8*i + 4, t5 = 8*i + 5, t6 = 8*i + 6, t7 = 8*i + 7; + vec_uchar16 p = {t0, t1, t2, t3, t4, t5, t6, t7, t0, t1, t2, t3, t4, t5, t6, t7}; + return v_uint64x2(vec_perm(v.val, v.val, p)); +} + +template +inline v_float32x4 v_broadcast_element(v_float32x4 v) +{ + unsigned char t0 = 4*i, t1 = 4*i + 1, t2 = 4*i + 2, t3 = 4*i + 3; + vec_uchar16 p = {t0, t1, t2, t3, t0, t1, t2, t3, t0, t1, t2, t3, t0, t1, t2, t3}; + return v_float32x4(vec_perm(v.val, v.val, p)); +} + +template +inline v_float64x2 v_broadcast_element(v_float64x2 v) +{ + unsigned char t0 = 8*i, t1 = 8*i + 1, t2 = 8*i + 2, t3 = 8*i + 3, t4 = 8*i + 4, t5 = 8*i + 5, t6 = 8*i + 6, t7 = 8*i + 7; + vec_uchar16 p = {t0, t1, t2, t3, t4, t5, t6, t7, t0, t1, t2, t3, t4, t5, t6, t7}; + return v_float64x2(vec_perm(v.val, v.val, p)); +} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif // OPENCV_HAL_VSX_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_wasm.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_wasm.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7b3259f4c0a68387f805bec87a9f572206673a3d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/intrin_wasm.hpp @@ -0,0 +1,4260 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_HAL_INTRIN_WASM_HPP +#define OPENCV_HAL_INTRIN_WASM_HPP + +#include +#include +#include +#include "opencv2/core/saturate.hpp" + +#define CV_SIMD128 1 +#define CV_SIMD128_64F 0 // Now all implementation of f64 use fallback, so disable it. +#define CV_SIMD128_FP16 0 + +namespace cv +{ + +//! @cond IGNORED + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN + +#if (__EMSCRIPTEN_major__ * 1000000 + __EMSCRIPTEN_minor__ * 1000 + __EMSCRIPTEN_tiny__) < (1038046) +// handle renames: https://github.com/emscripten-core/emscripten/pull/9440 (https://github.com/emscripten-core/emscripten/commit/755d5b46cb84d0aa120c10981b11d05646c29673) +#define wasm_i32x4_trunc_saturate_f32x4 wasm_trunc_saturate_i32x4_f32x4 +#define wasm_u32x4_trunc_saturate_f32x4 wasm_trunc_saturate_u32x4_f32x4 +#define wasm_i64x2_trunc_saturate_f64x2 wasm_trunc_saturate_i64x2_f64x2 +#define wasm_u64x2_trunc_saturate_f64x2 wasm_trunc_saturate_u64x2_f64x2 +#define wasm_f32x4_convert_i32x4 wasm_convert_f32x4_i32x4 +#define wasm_f32x4_convert_u32x4 wasm_convert_f32x4_u32x4 +#define wasm_f64x2_convert_i64x2 wasm_convert_f64x2_i64x2 +#define wasm_f64x2_convert_u64x2 wasm_convert_f64x2_u64x2 +#endif // COMPATIBILITY: <1.38.46 + +///////// Types /////////// + +struct v_uint8x16 +{ + typedef uchar lane_type; + typedef v128_t vector_type; + enum { nlanes = 16 }; + + v_uint8x16() : val(wasm_i8x16_splat(0)) {} + explicit v_uint8x16(v128_t v) : val(v) {} + v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7, + uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15) + { + uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = wasm_v128_load(v); + } + uchar get0() const + { + return (uchar)wasm_i8x16_extract_lane(val, 0); + } + + v128_t val; +}; + +struct v_int8x16 +{ + typedef schar lane_type; + typedef v128_t vector_type; + enum { nlanes = 16 }; + + v_int8x16() : val(wasm_i8x16_splat(0)) {} + explicit v_int8x16(v128_t v) : val(v) {} + v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7, + schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15) + { + schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15}; + val = wasm_v128_load(v); + } + schar get0() const + { + return wasm_i8x16_extract_lane(val, 0); + } + + v128_t val; +}; + +struct v_uint16x8 +{ + typedef ushort lane_type; + typedef v128_t vector_type; + enum { nlanes = 8 }; + + v_uint16x8() : val(wasm_i16x8_splat(0)) {} + explicit v_uint16x8(v128_t v) : val(v) {} + v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7) + { + ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = wasm_v128_load(v); + } + ushort get0() const + { + return (ushort)wasm_i16x8_extract_lane(val, 0); // wasm_u16x8_extract_lane() unimplemeted yet + } + + v128_t val; +}; + +struct v_int16x8 +{ + typedef short lane_type; + typedef v128_t vector_type; + enum { nlanes = 8 }; + + v_int16x8() : val(wasm_i16x8_splat(0)) {} + explicit v_int16x8(v128_t v) : val(v) {} + v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7) + { + short v[] = {v0, v1, v2, v3, v4, v5, v6, v7}; + val = wasm_v128_load(v); + } + short get0() const + { + return wasm_i16x8_extract_lane(val, 0); + } + + v128_t val; +}; + +struct v_uint32x4 +{ + typedef unsigned lane_type; + typedef v128_t vector_type; + enum { nlanes = 4 }; + + v_uint32x4() : val(wasm_i32x4_splat(0)) {} + explicit v_uint32x4(v128_t v) : val(v) {} + v_uint32x4(unsigned v0, unsigned v1, unsigned v2, unsigned v3) + { + unsigned v[] = {v0, v1, v2, v3}; + val = wasm_v128_load(v); + } + unsigned get0() const + { + return (unsigned)wasm_i32x4_extract_lane(val, 0); + } + + v128_t val; +}; + +struct v_int32x4 +{ + typedef int lane_type; + typedef v128_t vector_type; + enum { nlanes = 4 }; + + v_int32x4() : val(wasm_i32x4_splat(0)) {} + explicit v_int32x4(v128_t v) : val(v) {} + v_int32x4(int v0, int v1, int v2, int v3) + { + int v[] = {v0, v1, v2, v3}; + val = wasm_v128_load(v); + } + int get0() const + { + return wasm_i32x4_extract_lane(val, 0); + } + + v128_t val; +}; + +struct v_float32x4 +{ + typedef float lane_type; + typedef v128_t vector_type; + enum { nlanes = 4 }; + + v_float32x4() : val(wasm_f32x4_splat(0)) {} + explicit v_float32x4(v128_t v) : val(v) {} + v_float32x4(float v0, float v1, float v2, float v3) + { + float v[] = {v0, v1, v2, v3}; + val = wasm_v128_load(v); + } + float get0() const + { + return wasm_f32x4_extract_lane(val, 0); + } + + v128_t val; +}; + +struct v_uint64x2 +{ + typedef uint64 lane_type; + typedef v128_t vector_type; + enum { nlanes = 2 }; + +#ifdef __wasm_unimplemented_simd128__ + v_uint64x2() : val(wasm_i64x2_splat(0)) {} +#else + v_uint64x2() : val(wasm_i32x4_splat(0)) {} +#endif + explicit v_uint64x2(v128_t v) : val(v) {} + v_uint64x2(uint64 v0, uint64 v1) + { + uint64 v[] = {v0, v1}; + val = wasm_v128_load(v); + } + uint64 get0() const + { +#ifdef __wasm_unimplemented_simd128__ + return (uint64)wasm_i64x2_extract_lane(val, 0); +#else + uint64 des[2]; + wasm_v128_store(des, val); + return des[0]; +#endif + } + + v128_t val; +}; + +struct v_int64x2 +{ + typedef int64 lane_type; + typedef v128_t vector_type; + enum { nlanes = 2 }; + +#ifdef __wasm_unimplemented_simd128__ + v_int64x2() : val(wasm_i64x2_splat(0)) {} +#else + v_int64x2() : val(wasm_i32x4_splat(0)) {} +#endif + explicit v_int64x2(v128_t v) : val(v) {} + v_int64x2(int64 v0, int64 v1) + { + int64 v[] = {v0, v1}; + val = wasm_v128_load(v); + } + int64 get0() const + { +#ifdef __wasm_unimplemented_simd128__ + return wasm_i64x2_extract_lane(val, 0); +#else + int64 des[2]; + wasm_v128_store(des, val); + return des[0]; +#endif + } + + v128_t val; +}; + +struct v_float64x2 +{ + typedef double lane_type; + typedef v128_t vector_type; + enum { nlanes = 2 }; + +#ifdef __wasm_unimplemented_simd128__ + v_float64x2() : val(wasm_f64x2_splat(0)) {} +#else + v_float64x2() : val(wasm_f32x4_splat(0)) {} +#endif + explicit v_float64x2(v128_t v) : val(v) {} + v_float64x2(double v0, double v1) + { + double v[] = {v0, v1}; + val = wasm_v128_load(v); + } + double get0() const + { +#ifdef __wasm_unimplemented_simd128__ + return wasm_f64x2_extract_lane(val, 0); +#else + double des[2]; + wasm_v128_store(des, val); + return des[0]; +#endif + } + + v128_t val; +}; + +namespace fallback +{ + +template struct v_reg +{ + typedef _Tp lane_type; + enum { nlanes = n }; + + explicit v_reg(const _Tp* ptr) { for( int i = 0; i < n; i++ ) s[i] = ptr[i]; } + + v_reg(_Tp s0, _Tp s1) { s[0] = s0; s[1] = s1; } + + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3) { s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; } + + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, + _Tp s4, _Tp s5, _Tp s6, _Tp s7) + { + s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; + s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; + } + + v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3, + _Tp s4, _Tp s5, _Tp s6, _Tp s7, + _Tp s8, _Tp s9, _Tp s10, _Tp s11, + _Tp s12, _Tp s13, _Tp s14, _Tp s15) + { + s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; + s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7; + s[8] = s8; s[9] = s9; s[10] = s10; s[11] = s11; + s[12] = s12; s[13] = s13; s[14] = s14; s[15] = s15; + } + + v_reg() {} + + v_reg(const v_reg<_Tp, n> & r) + { + for( int i = 0; i < n; i++ ) + s[i] = r.s[i]; + } + + _Tp get0() const { return s[0]; } + + _Tp get(const int i) const { return s[i]; } + v_reg<_Tp, n> high() const + { + v_reg<_Tp, n> c; + int i; + for( i = 0; i < n/2; i++ ) + { + c.s[i] = s[i+(n/2)]; + c.s[i+(n/2)] = 0; + } + return c; + } + + static v_reg<_Tp, n> zero() + { + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = (_Tp)0; + return c; + } + + static v_reg<_Tp, n> all(_Tp s) + { + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = s; + return c; + } + + template v_reg<_Tp2, n2> reinterpret_as() const + { + size_t bytes = std::min(sizeof(_Tp2)*n2, sizeof(_Tp)*n); + v_reg<_Tp2, n2> c; + std::memcpy(&c.s[0], &s[0], bytes); + return c; + } + + v_reg(const cv::v_uint8x16& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_int8x16& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_uint16x8& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_int16x8& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_uint32x4& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_int32x4& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_float32x4& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_float64x2& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_uint64x2& v) { wasm_v128_store(&s, v.val); } + v_reg(const cv::v_int64x2& v) { wasm_v128_store(&s, v.val); } + + operator cv::v_uint8x16() const { return cv::v_uint8x16(wasm_v128_load(&s)); } + operator cv::v_int8x16() const { return cv::v_int8x16(wasm_v128_load(&s)); } + operator cv::v_uint16x8() const { return cv::v_uint16x8(wasm_v128_load(&s)); } + operator cv::v_int16x8() const { return cv::v_int16x8(wasm_v128_load(&s)); } + operator cv::v_uint32x4() const { return cv::v_uint32x4(wasm_v128_load(&s)); } + operator cv::v_int32x4() const { return cv::v_int32x4(wasm_v128_load(&s)); } + operator cv::v_float32x4() const { return cv::v_float32x4(wasm_v128_load(&s)); } + operator cv::v_float64x2() const { return cv::v_float64x2(wasm_v128_load(&s)); } + operator cv::v_uint64x2() const { return cv::v_uint64x2(wasm_v128_load(&s)); } + operator cv::v_int64x2() const { return cv::v_int64x2(wasm_v128_load(&s)); } + + _Tp s[n]; +}; + +typedef v_reg v_uint8x16; +typedef v_reg v_int8x16; +typedef v_reg v_uint16x8; +typedef v_reg v_int16x8; +typedef v_reg v_uint32x4; +typedef v_reg v_int32x4; +typedef v_reg v_float32x4; +typedef v_reg v_float64x2; +typedef v_reg v_uint64x2; +typedef v_reg v_int64x2; + +#define OPENCV_HAL_IMPL_BIN_OP(bin_op) \ +template inline v_reg<_Tp, n> \ + operator bin_op (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ + return c; \ +} \ +template inline v_reg<_Tp, n>& \ + operator bin_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + for( int i = 0; i < n; i++ ) \ + a.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \ + return a; \ +} + +OPENCV_HAL_IMPL_BIN_OP(+) +OPENCV_HAL_IMPL_BIN_OP(-) +OPENCV_HAL_IMPL_BIN_OP(*) +OPENCV_HAL_IMPL_BIN_OP(/) + +#define OPENCV_HAL_IMPL_BIT_OP(bit_op) \ +template inline v_reg<_Tp, n> operator bit_op \ + (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ + V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ + return c; \ +} \ +template inline v_reg<_Tp, n>& operator \ + bit_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + for( int i = 0; i < n; i++ ) \ + a.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \ + V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \ + return a; \ +} + +OPENCV_HAL_IMPL_BIT_OP(&) +OPENCV_HAL_IMPL_BIT_OP(|) +OPENCV_HAL_IMPL_BIT_OP(^) + +template inline v_reg<_Tp, n> operator ~ (const v_reg<_Tp, n>& a) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int(~V_TypeTraits<_Tp>::reinterpret_int(a.s[i])); + } + return c; +} + +#define OPENCV_HAL_IMPL_MATH_FUNC(func, cfunc, _Tp2) \ +template inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a) \ +{ \ + v_reg<_Tp2, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cfunc(a.s[i]); \ + return c; \ +} + +OPENCV_HAL_IMPL_MATH_FUNC(v_sqrt, std::sqrt, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_sin, std::sin, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_cos, std::cos, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_exp, std::exp, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_log, std::log, _Tp) +OPENCV_HAL_IMPL_MATH_FUNC(v_abs, (typename V_TypeTraits<_Tp>::abs_type)std::abs, + typename V_TypeTraits<_Tp>::abs_type) +OPENCV_HAL_IMPL_MATH_FUNC(v_round, cvRound, int) +OPENCV_HAL_IMPL_MATH_FUNC(v_floor, cvFloor, int) +OPENCV_HAL_IMPL_MATH_FUNC(v_ceil, cvCeil, int) +OPENCV_HAL_IMPL_MATH_FUNC(v_trunc, int, int) + +#define OPENCV_HAL_IMPL_MINMAX_FUNC(func, cfunc) \ +template inline v_reg<_Tp, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cfunc(a.s[i], b.s[i]); \ + return c; \ +} + +#define OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(func, cfunc) \ +template inline _Tp func(const v_reg<_Tp, n>& a) \ +{ \ + _Tp c = a.s[0]; \ + for( int i = 1; i < n; i++ ) \ + c = cfunc(c, a.s[i]); \ + return c; \ +} + +OPENCV_HAL_IMPL_MINMAX_FUNC(v_min, std::min) +OPENCV_HAL_IMPL_MINMAX_FUNC(v_max, std::max) +OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_min, std::min) +OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_max, std::max) + +static const unsigned char popCountTable[] = +{ + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; + +template +inline v_reg::abs_type, n> v_popcount(const v_reg<_Tp, n>& a) +{ + v_reg::abs_type, n> b = v_reg::abs_type, n>::zero(); + for (int i = 0; i < (int)(n*sizeof(_Tp)); i++) + b.s[i/sizeof(_Tp)] += popCountTable[v_reinterpret_as_u8(a).s[i]]; + return b; +} + +template +inline void v_minmax( const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg<_Tp, n>& minval, v_reg<_Tp, n>& maxval ) +{ + for( int i = 0; i < n; i++ ) + { + minval.s[i] = std::min(a.s[i], b.s[i]); + maxval.s[i] = std::max(a.s[i], b.s[i]); + } +} + +#define OPENCV_HAL_IMPL_CMP_OP(cmp_op) \ +template \ +inline v_reg<_Tp, n> operator cmp_op(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef typename V_TypeTraits<_Tp>::int_type itype; \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)-(int)(a.s[i] cmp_op b.s[i])); \ + return c; \ +} + +OPENCV_HAL_IMPL_CMP_OP(<) +OPENCV_HAL_IMPL_CMP_OP(>) +OPENCV_HAL_IMPL_CMP_OP(<=) +OPENCV_HAL_IMPL_CMP_OP(>=) +OPENCV_HAL_IMPL_CMP_OP(==) +OPENCV_HAL_IMPL_CMP_OP(!=) + +template +inline v_reg v_not_nan(const v_reg& a) +{ + typedef typename V_TypeTraits::int_type itype; + v_reg c; + for (int i = 0; i < n; i++) + c.s[i] = V_TypeTraits::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); + return c; +} +template +inline v_reg v_not_nan(const v_reg& a) +{ + typedef typename V_TypeTraits::int_type itype; + v_reg c; + for (int i = 0; i < n; i++) + c.s[i] = V_TypeTraits::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i])); + return c; +} + +#define OPENCV_HAL_IMPL_ARITHM_OP(func, bin_op, cast_op, _Tp2) \ +template \ +inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + typedef _Tp2 rtype; \ + v_reg c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = cast_op(a.s[i] bin_op b.s[i]); \ + return c; \ +} + +OPENCV_HAL_IMPL_ARITHM_OP(v_add_wrap, +, (_Tp), _Tp) +OPENCV_HAL_IMPL_ARITHM_OP(v_sub_wrap, -, (_Tp), _Tp) +OPENCV_HAL_IMPL_ARITHM_OP(v_mul_wrap, *, (_Tp), _Tp) + +template inline T _absdiff(T a, T b) +{ + return a > b ? a - b : b - a; +} + +template +inline v_reg::abs_type, n> v_absdiff(const v_reg<_Tp, n>& a, const v_reg<_Tp, n> & b) +{ + typedef typename V_TypeTraits<_Tp>::abs_type rtype; + v_reg c; + const rtype mask = (rtype)(std::numeric_limits<_Tp>::is_signed ? (1 << (sizeof(rtype)*8 - 1)) : 0); + for( int i = 0; i < n; i++ ) + { + rtype ua = a.s[i] ^ mask; + rtype ub = b.s[i] ^ mask; + c.s[i] = _absdiff(ua, ub); + } + return c; +} + +inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +{ + v_float32x4 c; + for( int i = 0; i < c.nlanes; i++ ) + c.s[i] = _absdiff(a.s[i], b.s[i]); + return c; +} + +inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +{ + v_float64x2 c; + for( int i = 0; i < c.nlanes; i++ ) + c.s[i] = _absdiff(a.s[i], b.s[i]); + return c; +} + +template +inline v_reg<_Tp, n> v_absdiffs(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++) + c.s[i] = saturate_cast<_Tp>(std::abs(a.s[i] - b.s[i])); + return c; +} + +template +inline v_reg<_Tp, n> v_invsqrt(const v_reg<_Tp, n>& a) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = 1.f/std::sqrt(a.s[i]); + return c; +} + +template +inline v_reg<_Tp, n> v_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = std::sqrt(a.s[i]*a.s[i] + b.s[i]*b.s[i]); + return c; +} + +template +inline v_reg<_Tp, n> v_sqr_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = a.s[i]*a.s[i] + b.s[i]*b.s[i]; + return c; +} + +template +inline v_reg<_Tp, n> v_fma(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg<_Tp, n>& c) +{ + v_reg<_Tp, n> d; + for( int i = 0; i < n; i++ ) + d.s[i] = a.s[i]*b.s[i] + c.s[i]; + return d; +} + +template +inline v_reg<_Tp, n> v_muladd(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg<_Tp, n>& c) +{ + return v_fma(a, b, c); +} + +template inline v_reg::w_type, n/2> + v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg c; + for( int i = 0; i < (n/2); i++ ) + c.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1]; + return c; +} + +template inline v_reg::w_type, n/2> + v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, const v_reg::w_type, n / 2>& c) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg s; + for( int i = 0; i < (n/2); i++ ) + s.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1] + c.s[i]; + return s; +} + +template inline v_reg::q_type, n/4> + v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg s; + for( int i = 0; i < (n/4); i++ ) + s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] + + (q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3]; + return s; +} + +template inline v_reg::q_type, n/4> + v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + const v_reg::q_type, n / 4>& c) +{ + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg s; + for( int i = 0; i < (n/4); i++ ) + s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] + + (q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3] + c.s[i]; + return s; +} + +template inline void v_mul_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg::w_type, n/2>& c, + v_reg::w_type, n/2>& d) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = (w_type)a.s[i]*b.s[i]; + d.s[i] = (w_type)a.s[i+(n/2)]*b.s[i+(n/2)]; + } +} + +template inline v_reg<_Tp, n> v_mul_hi(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg<_Tp, n> c; + for (int i = 0; i < n; i++) + c.s[i] = (_Tp)(((w_type)a.s[i] * b.s[i]) >> sizeof(_Tp)*8); + return c; +} + +template inline void v_hsum(const v_reg<_Tp, n>& a, + v_reg::w_type, n/2>& c) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = (w_type)a.s[i*2] + a.s[i*2+1]; + } +} + +#define OPENCV_HAL_IMPL_SHIFT_OP(shift_op) \ +template inline v_reg<_Tp, n> operator shift_op(const v_reg<_Tp, n>& a, int imm) \ +{ \ + v_reg<_Tp, n> c; \ + for( int i = 0; i < n; i++ ) \ + c.s[i] = (_Tp)(a.s[i] shift_op imm); \ + return c; \ +} + +OPENCV_HAL_IMPL_SHIFT_OP(<< ) +OPENCV_HAL_IMPL_SHIFT_OP(>> ) + +#define OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(suffix,opA,opB) \ +template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a) \ +{ \ + v_reg<_Tp, n> b; \ + for (int i = 0; i < n; i++) \ + { \ + int sIndex = i opA imm; \ + if (0 <= sIndex && sIndex < n) \ + { \ + b.s[i] = a.s[sIndex]; \ + } \ + else \ + { \ + b.s[i] = 0; \ + } \ + } \ + return b; \ +} \ +template inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \ +{ \ + v_reg<_Tp, n> c; \ + for (int i = 0; i < n; i++) \ + { \ + int aIndex = i opA imm; \ + int bIndex = i opA imm opB n; \ + if (0 <= bIndex && bIndex < n) \ + { \ + c.s[i] = b.s[bIndex]; \ + } \ + else if (0 <= aIndex && aIndex < n) \ + { \ + c.s[i] = a.s[aIndex]; \ + } \ + else \ + { \ + c.s[i] = 0; \ + } \ + } \ + return c; \ +} + +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(left, -, +) +OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(right, +, -) + +template inline typename V_TypeTraits<_Tp>::sum_type v_reduce_sum(const v_reg<_Tp, n>& a) +{ + typename V_TypeTraits<_Tp>::sum_type c = a.s[0]; + for( int i = 1; i < n; i++ ) + c += a.s[i]; + return c; +} + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + v_float32x4 r; + r.s[0] = a.s[0] + a.s[1] + a.s[2] + a.s[3]; + r.s[1] = b.s[0] + b.s[1] + b.s[2] + b.s[3]; + r.s[2] = c.s[0] + c.s[1] + c.s[2] + c.s[3]; + r.s[3] = d.s[0] + d.s[1] + d.s[2] + d.s[3]; + return r; +} + +template inline typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type v_reduce_sad(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type c = _absdiff(a.s[0], b.s[0]); + for (int i = 1; i < n; i++) + c += _absdiff(a.s[i], b.s[i]); + return c; +} + +template inline int v_signmask(const v_reg<_Tp, n>& a) +{ + int mask = 0; + for( int i = 0; i < n; i++ ) + mask |= (V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0) << i; + return mask; +} + +template inline bool v_check_all(const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) >= 0 ) + return false; + return true; +} + +template inline bool v_check_any(const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0 ) + return true; + return false; +} + +template inline v_reg<_Tp, n> v_select(const v_reg<_Tp, n>& mask, + const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + typedef V_TypeTraits<_Tp> Traits; + typedef typename Traits::int_type int_type; + v_reg<_Tp, n> c; + for( int i = 0; i < n; i++ ) + { + int_type m = Traits::reinterpret_int(mask.s[i]); + CV_DbgAssert(m == 0 || m == (~(int_type)0)); // restrict mask values: 0 or 0xff/0xffff/etc + c.s[i] = m ? a.s[i] : b.s[i]; + } + return c; +} + +template inline void v_expand(const v_reg<_Tp, n>& a, + v_reg::w_type, n/2>& b0, + v_reg::w_type, n/2>& b1) +{ + for( int i = 0; i < (n/2); i++ ) + { + b0.s[i] = a.s[i]; + b1.s[i] = a.s[i+(n/2)]; + } +} + +template +inline v_reg::w_type, n/2> +v_expand_low(const v_reg<_Tp, n>& a) +{ + v_reg::w_type, n/2> b; + for( int i = 0; i < (n/2); i++ ) + b.s[i] = a.s[i]; + return b; +} + +template +inline v_reg::w_type, n/2> +v_expand_high(const v_reg<_Tp, n>& a) +{ + v_reg::w_type, n/2> b; + for( int i = 0; i < (n/2); i++ ) + b.s[i] = a.s[i+(n/2)]; + return b; +} + +template inline v_reg::int_type, n> + v_reinterpret_as_int(const v_reg<_Tp, n>& a) +{ + v_reg::int_type, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = V_TypeTraits<_Tp>::reinterpret_int(a.s[i]); + return c; +} + +template inline v_reg::uint_type, n> + v_reinterpret_as_uint(const v_reg<_Tp, n>& a) +{ + v_reg::uint_type, n> c; + for( int i = 0; i < n; i++ ) + c.s[i] = V_TypeTraits<_Tp>::reinterpret_uint(a.s[i]); + return c; +} + +template inline void v_zip( const v_reg<_Tp, n>& a0, const v_reg<_Tp, n>& a1, + v_reg<_Tp, n>& b0, v_reg<_Tp, n>& b1 ) +{ + int i; + for( i = 0; i < n/2; i++ ) + { + b0.s[i*2] = a0.s[i]; + b0.s[i*2+1] = a1.s[i]; + } + for( ; i < n; i++ ) + { + b1.s[i*2-n] = a0.s[i]; + b1.s[i*2-n+1] = a1.s[i]; + } +} + +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load(const _Tp* ptr) +{ + return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); +} + +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_aligned(const _Tp* ptr) +{ + return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr); +} + +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for( int i = 0; i < c.nlanes/2; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +template +inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_halves(const _Tp* loptr, const _Tp* hiptr) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for( int i = 0; i < c.nlanes/2; i++ ) + { + c.s[i] = loptr[i]; + c.s[i+c.nlanes/2] = hiptr[i]; + } + return c; +} + +template +inline v_reg::w_type, V_TypeTraits<_Tp>::nlanes128 / 2> +v_load_expand(const _Tp* ptr) +{ + typedef typename V_TypeTraits<_Tp>::w_type w_type; + v_reg::nlanes128> c; + for( int i = 0; i < c.nlanes; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +template +inline v_reg::q_type, V_TypeTraits<_Tp>::nlanes128 / 4> +v_load_expand_q(const _Tp* ptr) +{ + typedef typename V_TypeTraits<_Tp>::q_type q_type; + v_reg::nlanes128> c; + for( int i = 0; i < c.nlanes; i++ ) + { + c.s[i] = ptr[i]; + } + return c; +} + +template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + a.s[i] = ptr[i2]; + b.s[i] = ptr[i2+1]; + } +} + +template inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b, v_reg<_Tp, n>& c) +{ + int i, i3; + for( i = i3 = 0; i < n; i++, i3 += 3 ) + { + a.s[i] = ptr[i3]; + b.s[i] = ptr[i3+1]; + c.s[i] = ptr[i3+2]; + } +} + +template +inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a, + v_reg<_Tp, n>& b, v_reg<_Tp, n>& c, + v_reg<_Tp, n>& d) +{ + int i, i4; + for( i = i4 = 0; i < n; i++, i4 += 4 ) + { + a.s[i] = ptr[i4]; + b.s[i] = ptr[i4+1]; + c.s[i] = ptr[i4+2]; + d.s[i] = ptr[i4+3]; + } +} + +template +inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i2; + for( i = i2 = 0; i < n; i++, i2 += 2 ) + { + ptr[i2] = a.s[i]; + ptr[i2+1] = b.s[i]; + } +} + +template +inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i3; + for( i = i3 = 0; i < n; i++, i3 += 3 ) + { + ptr[i3] = a.s[i]; + ptr[i3+1] = b.s[i]; + ptr[i3+2] = c.s[i]; + } +} + +template inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a, + const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c, + const v_reg<_Tp, n>& d, + hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) +{ + int i, i4; + for( i = i4 = 0; i < n; i++, i4 += 4 ) + { + ptr[i4] = a.s[i]; + ptr[i4+1] = b.s[i]; + ptr[i4+2] = c.s[i]; + ptr[i4+3] = d.s[i]; + } +} + +template +inline void v_store(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template +inline void v_store_low(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < (n/2); i++ ) + ptr[i] = a.s[i]; +} + +template +inline void v_store_high(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < (n/2); i++ ) + ptr[i] = a.s[i+(n/2)]; +} + +template +inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template +inline void v_store_aligned_nocache(_Tp* ptr, const v_reg<_Tp, n>& a) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template +inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/) +{ + for( int i = 0; i < n; i++ ) + ptr[i] = a.s[i]; +} + +template +inline v_reg<_Tp, n> v_combine_low(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = a.s[i]; + c.s[i+(n/2)] = b.s[i]; + } + return c; +} + +template +inline v_reg<_Tp, n> v_combine_high(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> c; + for( int i = 0; i < (n/2); i++ ) + { + c.s[i] = a.s[i+(n/2)]; + c.s[i+(n/2)] = b.s[i+(n/2)]; + } + return c; +} + +template +inline void v_recombine(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b, + v_reg<_Tp, n>& low, v_reg<_Tp, n>& high) +{ + for( int i = 0; i < (n/2); i++ ) + { + low.s[i] = a.s[i]; + low.s[i+(n/2)] = b.s[i]; + high.s[i] = a.s[i+(n/2)]; + high.s[i+(n/2)] = b.s[i+(n/2)]; + } +} + +template +inline v_reg<_Tp, n> v_extract(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + v_reg<_Tp, n> r; + const int shift = n - s; + int i = 0; + for (; i < shift; ++i) + r.s[i] = a.s[i+s]; + for (; i < n; ++i) + r.s[i] = b.s[i-shift]; + return r; +} + +template inline v_reg v_round(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvRound(a.s[i]); + return c; +} + +template inline v_reg v_round(const v_reg& a, const v_reg& b) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvRound(a.s[i]); + c.s[i+n] = cvRound(b.s[i]); + } + return c; +} + +template inline v_reg v_floor(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvFloor(a.s[i]); + return c; +} + +template inline v_reg v_ceil(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = cvCeil(a.s[i]); + return c; +} + +template inline v_reg v_trunc(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = (int)(a.s[i]); + return c; +} + +template inline v_reg v_round(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvRound(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +template inline v_reg v_floor(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvFloor(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +template inline v_reg v_ceil(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = cvCeil(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +template inline v_reg v_trunc(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = (int)(a.s[i]); + c.s[i+n] = 0; + } + return c; +} + +template inline v_reg v_cvt_f32(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = (float)a.s[i]; + return c; +} + +template inline v_reg v_cvt_f32(const v_reg& a) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = (float)a.s[i]; + c.s[i+n] = 0; + } + return c; +} + +template inline v_reg v_cvt_f32(const v_reg& a, const v_reg& b) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + { + c.s[i] = (float)a.s[i]; + c.s[i+n] = (float)b.s[i]; + } + return c; +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ + v_float64x2 c; + for( int i = 0; i < 2; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ + v_float64x2 c; + for( int i = 0; i < 2; i++ ) + c.s[i] = (double)a.s[i+2]; + return c; +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + v_float64x2 c; + for( int i = 0; i < 2; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + v_float64x2 c; + for( int i = 0; i < 2; i++ ) + c.s[i] = (double)a.s[i+2]; + return c; +} + +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ + v_float64x2 c; + for( int i = 0; i < 2; i++ ) + c.s[i] = (double)a.s[i]; + return c; +} + +template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i]]; + return c; +} +template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_pairs(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i / 2] + i % 2]; + return c; +} +template inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_quads(const _Tp* tab, const int* idx) +{ + v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c; + for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++) + c.s[i] = tab[idx[i / 4] + i % 4]; + return c; +} + +template inline v_reg v_lut(const int* tab, const v_reg& idx) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline v_reg v_lut(const unsigned* tab, const v_reg& idx) +{ + v_reg c; + for (int i = 0; i < n; i++) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline v_reg v_lut(const float* tab, const v_reg& idx) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline v_reg v_lut(const double* tab, const v_reg& idx) +{ + v_reg c; + for( int i = 0; i < n; i++ ) + c.s[i] = tab[idx.s[i]]; + return c; +} + +template inline void v_lut_deinterleave(const float* tab, const v_reg& idx, + v_reg& x, v_reg& y) +{ + for( int i = 0; i < n; i++ ) + { + int j = idx.s[i]; + x.s[i] = tab[j]; + y.s[i] = tab[j+1]; + } +} + +template inline void v_lut_deinterleave(const double* tab, const v_reg& idx, + v_reg& x, v_reg& y) +{ + for( int i = 0; i < n; i++ ) + { + int j = idx.s[i]; + x.s[i] = tab[j]; + y.s[i] = tab[j+1]; + } +} + +template inline v_reg<_Tp, n> v_interleave_pairs(const v_reg<_Tp, n>& vec) +{ + v_reg<_Tp, n> c; + for (int i = 0; i < n/4; i++) + { + c.s[4*i ] = vec.s[4*i ]; + c.s[4*i+1] = vec.s[4*i+2]; + c.s[4*i+2] = vec.s[4*i+1]; + c.s[4*i+3] = vec.s[4*i+3]; + } + return c; +} + +template inline v_reg<_Tp, n> v_interleave_quads(const v_reg<_Tp, n>& vec) +{ + v_reg<_Tp, n> c; + for (int i = 0; i < n/8; i++) + { + c.s[8*i ] = vec.s[8*i ]; + c.s[8*i+1] = vec.s[8*i+4]; + c.s[8*i+2] = vec.s[8*i+1]; + c.s[8*i+3] = vec.s[8*i+5]; + c.s[8*i+4] = vec.s[8*i+2]; + c.s[8*i+5] = vec.s[8*i+6]; + c.s[8*i+6] = vec.s[8*i+3]; + c.s[8*i+7] = vec.s[8*i+7]; + } + return c; +} + +template inline v_reg<_Tp, n> v_pack_triplets(const v_reg<_Tp, n>& vec) +{ + v_reg<_Tp, n> c; + for (int i = 0; i < n/4; i++) + { + c.s[3*i ] = vec.s[4*i ]; + c.s[3*i+1] = vec.s[4*i+1]; + c.s[3*i+2] = vec.s[4*i+2]; + } + return c; +} + +template +inline void v_transpose4x4( v_reg<_Tp, 4>& a0, const v_reg<_Tp, 4>& a1, + const v_reg<_Tp, 4>& a2, const v_reg<_Tp, 4>& a3, + v_reg<_Tp, 4>& b0, v_reg<_Tp, 4>& b1, + v_reg<_Tp, 4>& b2, v_reg<_Tp, 4>& b3 ) +{ + b0 = v_reg<_Tp, 4>(a0.s[0], a1.s[0], a2.s[0], a3.s[0]); + b1 = v_reg<_Tp, 4>(a0.s[1], a1.s[1], a2.s[1], a3.s[1]); + b2 = v_reg<_Tp, 4>(a0.s[2], a1.s[2], a2.s[2], a3.s[2]); + b3 = v_reg<_Tp, 4>(a0.s[3], a1.s[3], a2.s[3], a3.s[3]); +} + +#define OPENCV_HAL_IMPL_C_INIT_ZERO(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec::zero(); } + +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x2, int64, s64) + +#define OPENCV_HAL_IMPL_C_INIT_VAL(_Tpvec, _Tp, suffix) \ +inline _Tpvec v_setall_##suffix(_Tp val) { return _Tpvec::all(val); } + +OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x2, int64, s64) + +#define OPENCV_HAL_IMPL_C_REINTERPRET(_Tpvec, _Tp, suffix) \ +template inline _Tpvec \ + v_reinterpret_as_##suffix(const v_reg<_Tp0, n0>& a) \ +{ return a.template reinterpret_as<_Tp, _Tpvec::nlanes>(); } + +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int8x16, schar, s8) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int16x8, short, s16) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int32x4, int, s32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_float32x4, float, f32) +OPENCV_HAL_IMPL_C_REINTERPRET(v_float64x2, double, f64) +OPENCV_HAL_IMPL_C_REINTERPRET(v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_C_REINTERPRET(v_int64x2, int64, s64) + +#define OPENCV_HAL_IMPL_C_SHIFTL(_Tpvec, _Tp) \ +template inline _Tpvec v_shl(const _Tpvec& a) \ +{ return a << n; } + +OPENCV_HAL_IMPL_C_SHIFTL(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_SHIFTL(v_int16x8, short) +OPENCV_HAL_IMPL_C_SHIFTL(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_SHIFTL(v_int32x4, int) +OPENCV_HAL_IMPL_C_SHIFTL(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_SHIFTL(v_int64x2, int64) + +#define OPENCV_HAL_IMPL_C_SHIFTR(_Tpvec, _Tp) \ +template inline _Tpvec v_shr(const _Tpvec& a) \ +{ return a >> n; } + +OPENCV_HAL_IMPL_C_SHIFTR(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_SHIFTR(v_int16x8, short) +OPENCV_HAL_IMPL_C_SHIFTR(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_SHIFTR(v_int32x4, int) +OPENCV_HAL_IMPL_C_SHIFTR(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_SHIFTR(v_int64x2, int64) + +#define OPENCV_HAL_IMPL_C_RSHIFTR(_Tpvec, _Tp) \ +template inline _Tpvec v_rshr(const _Tpvec& a) \ +{ \ + _Tpvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + c.s[i] = (_Tp)((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + return c; \ +} + +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint16x8, ushort) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int16x8, short) +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int32x4, int) +OPENCV_HAL_IMPL_C_RSHIFTR(v_uint64x2, uint64) +OPENCV_HAL_IMPL_C_RSHIFTR(v_int64x2, int64) + +#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix, cast) \ +inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpnvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + { \ + c.s[i] = cast<_Tpn>(a.s[i]); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>(b.s[i]); \ + } \ + return c; \ +} + +OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u, saturate_cast) + +#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +template inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpnvec c; \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + { \ + c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + c.s[i+_Tpvec::nlanes] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \ + } \ + return c; \ +} + +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) + +#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +{ \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + ptr[i] = cast<_Tpn>(a.s[i]); \ +} + +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) + +#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \ +template inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \ +{ \ + for( int i = 0; i < _Tpvec::nlanes; i++ ) \ + ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \ +} + +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast) +OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast) + +template +inline void _pack_b(_Tpm* mptr, const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) +{ + for (int i = 0; i < n; ++i) + { + mptr[i] = (_Tpm)a.s[i]; + mptr[i + n] = (_Tpm)b.s[i]; + } +} + +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + return mask; +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + _pack_b(mask.s + 8, c, d); + return mask; +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ + v_uint8x16 mask; + _pack_b(mask.s, a, b); + _pack_b(mask.s + 4, c, d); + _pack_b(mask.s + 8, e, f); + _pack_b(mask.s + 12, g, h); + return mask; +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + v.s[3]*m3.s[0], + v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + v.s[3]*m3.s[1], + v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + v.s[3]*m3.s[2], + v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + v.s[3]*m3.s[3]); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + m3.s[0], + v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + m3.s[1], + v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + m3.s[2], + v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]); +} + +inline v_reg::nlanes128> +v_load_expand(const float16_t* ptr) +{ + v_reg::nlanes128> v; + for( int i = 0; i < v.nlanes; i++ ) + { + v.s[i] = ptr[i]; + } + return v; +} + +inline void +v_pack_store(float16_t* ptr, const v_reg::nlanes128>& v) +{ + for( int i = 0; i < v.nlanes; i++ ) + { + ptr[i] = float16_t(v.s[i]); + } +} + +inline void v_cleanup() {} +} // namespace fallback + +static v128_t wasm_unpacklo_i8x16(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 0,16,1,17,2,18,3,19,4,20,5,21,6,22,7,23); +} + +static v128_t wasm_unpacklo_i16x8(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 0,1,16,17,2,3,18,19,4,5,20,21,6,7,22,23); +} + +static v128_t wasm_unpacklo_i32x4(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 0,1,2,3,16,17,18,19,4,5,6,7,20,21,22,23); +} + +static v128_t wasm_unpacklo_i64x2(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23); +} + +static v128_t wasm_unpackhi_i8x16(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 8,24,9,25,10,26,11,27,12,28,13,29,14,30,15,31); +} + +static v128_t wasm_unpackhi_i16x8(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 8,9,24,25,10,11,26,27,12,13,28,29,14,15,30,31); +} + +static v128_t wasm_unpackhi_i32x4(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 8,9,10,11,24,25,26,27,12,13,14,15,28,29,30,31); +} + +static v128_t wasm_unpackhi_i64x2(v128_t a, v128_t b) { + return wasm_v8x16_shuffle(a, b, 8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31); +} + +/** Convert **/ +// 8 >> 16 +inline v128_t v128_cvtu8x16_i16x8(const v128_t& a) +{ + const v128_t z = wasm_i8x16_splat(0); + return wasm_unpacklo_i8x16(a, z); +} +inline v128_t v128_cvti8x16_i16x8(const v128_t& a) +{ return wasm_i16x8_shr(wasm_unpacklo_i8x16(a, a), 8); } +// 8 >> 32 +inline v128_t v128_cvtu8x16_i32x4(const v128_t& a) +{ + const v128_t z = wasm_i8x16_splat(0); + return wasm_unpacklo_i16x8(wasm_unpacklo_i8x16(a, z), z); +} +inline v128_t v128_cvti8x16_i32x4(const v128_t& a) +{ + v128_t r = wasm_unpacklo_i8x16(a, a); + r = wasm_unpacklo_i8x16(r, r); + return wasm_i32x4_shr(r, 24); +} +// 16 >> 32 +inline v128_t v128_cvtu16x8_i32x4(const v128_t& a) +{ + const v128_t z = wasm_i8x16_splat(0); + return wasm_unpacklo_i16x8(a, z); +} +inline v128_t v128_cvti16x8_i32x4(const v128_t& a) +{ return wasm_i32x4_shr(wasm_unpacklo_i16x8(a, a), 16); } +// 32 >> 64 +inline v128_t v128_cvtu32x4_i64x2(const v128_t& a) +{ + const v128_t z = wasm_i8x16_splat(0); + return wasm_unpacklo_i32x4(a, z); +} +inline v128_t v128_cvti32x4_i64x2(const v128_t& a) +{ return wasm_unpacklo_i32x4(a, wasm_i32x4_shr(a, 31)); } + +// 16 << 8 +inline v128_t v128_cvtu8x16_i16x8_high(const v128_t& a) +{ + const v128_t z = wasm_i8x16_splat(0); + return wasm_unpackhi_i8x16(a, z); +} +inline v128_t v128_cvti8x16_i16x8_high(const v128_t& a) +{ return wasm_i16x8_shr(wasm_unpackhi_i8x16(a, a), 8); } +// 32 << 16 +inline v128_t v128_cvtu16x8_i32x4_high(const v128_t& a) +{ + const v128_t z = wasm_i8x16_splat(0); + return wasm_unpackhi_i16x8(a, z); +} +inline v128_t v128_cvti16x8_i32x4_high(const v128_t& a) +{ return wasm_i32x4_shr(wasm_unpackhi_i16x8(a, a), 16); } +// 64 << 32 +inline v128_t v128_cvtu32x4_i64x2_high(const v128_t& a) +{ + const v128_t z = wasm_i8x16_splat(0); + return wasm_unpackhi_i32x4(a, z); +} +inline v128_t v128_cvti32x4_i64x2_high(const v128_t& a) +{ return wasm_unpackhi_i32x4(a, wasm_i32x4_shr(a, 31)); } + +#define OPENCV_HAL_IMPL_WASM_INITVEC(_Tpvec, _Tp, suffix, zsuffix, _Tps) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec(wasm_##zsuffix##_splat((_Tps)0)); } \ +inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec(wasm_##zsuffix##_splat((_Tps)v)); } \ +template inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0& a) \ +{ return _Tpvec(a.val); } + +OPENCV_HAL_IMPL_WASM_INITVEC(v_uint8x16, uchar, u8, i8x16, schar) +OPENCV_HAL_IMPL_WASM_INITVEC(v_int8x16, schar, s8, i8x16, schar) +OPENCV_HAL_IMPL_WASM_INITVEC(v_uint16x8, ushort, u16, i16x8, short) +OPENCV_HAL_IMPL_WASM_INITVEC(v_int16x8, short, s16, i16x8, short) +OPENCV_HAL_IMPL_WASM_INITVEC(v_uint32x4, unsigned, u32, i32x4, int) +OPENCV_HAL_IMPL_WASM_INITVEC(v_int32x4, int, s32, i32x4, int) +OPENCV_HAL_IMPL_WASM_INITVEC(v_float32x4, float, f32, f32x4, float) + +#ifdef __wasm_unimplemented_simd128__ +OPENCV_HAL_IMPL_WASM_INITVEC(v_uint64x2, uint64, u64, i64x2, int64) +OPENCV_HAL_IMPL_WASM_INITVEC(v_int64x2, int64, s64, i64x2, int64) +OPENCV_HAL_IMPL_WASM_INITVEC(v_float64x2, double, f64, f64x2, double) +#else +#define OPENCV_HAL_IMPL_FALLBACK_INITVEC(_Tpvec, _Tp, suffix, _Tps) \ +inline _Tpvec v_setzero_##suffix() { return _Tpvec((_Tps)0, (_Tps)0); } \ +inline _Tpvec v_setall_##suffix(_Tp v) { return _Tpvec((_Tps)v, (_Tps)v); } \ +template inline _Tpvec v_reinterpret_as_##suffix(const _Tpvec0& a) \ +{ return _Tpvec(a.val); } + +OPENCV_HAL_IMPL_FALLBACK_INITVEC(v_uint64x2, uint64, u64, int64) +OPENCV_HAL_IMPL_FALLBACK_INITVEC(v_int64x2, int64, s64, int64) +OPENCV_HAL_IMPL_FALLBACK_INITVEC(v_float64x2, double, f64, double) +#endif + +//////////////// PACK /////////////// +inline v_uint8x16 v_pack(const v_uint16x8& a, const v_uint16x8& b) +{ + v128_t maxval = wasm_i16x8_splat(255); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_u16x8_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_u16x8_gt(b.val, maxval)); + return v_uint8x16(wasm_v8x16_shuffle(a1, b1, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)); +} +inline v_int8x16 v_pack(const v_int16x8& a, const v_int16x8& b) +{ + v128_t maxval = wasm_i16x8_splat(127); + v128_t minval = wasm_i16x8_splat(-128); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i16x8_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_i16x8_gt(b.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i16x8_lt(a1, minval)); + v128_t b2 = wasm_v128_bitselect(minval, b1, wasm_i16x8_lt(b1, minval)); + return v_int8x16(wasm_v8x16_shuffle(a2, b2, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)); +} +inline v_uint16x8 v_pack(const v_uint32x4& a, const v_uint32x4& b) +{ + v128_t maxval = wasm_i32x4_splat(65535); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_u32x4_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_u32x4_gt(b.val, maxval)); + return v_uint16x8(wasm_v8x16_shuffle(a1, b1, 0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29)); +} +inline v_int16x8 v_pack(const v_int32x4& a, const v_int32x4& b) +{ + v128_t maxval = wasm_i32x4_splat(32767); + v128_t minval = wasm_i32x4_splat(-32768); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i32x4_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_i32x4_gt(b.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i32x4_lt(a1, minval)); + v128_t b2 = wasm_v128_bitselect(minval, b1, wasm_i32x4_lt(b1, minval)); + return v_int16x8(wasm_v8x16_shuffle(a2, b2, 0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29)); +} +inline v_uint32x4 v_pack(const v_uint64x2& a, const v_uint64x2& b) +{ + return v_uint32x4(wasm_v8x16_shuffle(a.val, b.val, 0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27)); +} +inline v_int32x4 v_pack(const v_int64x2& a, const v_int64x2& b) +{ + return v_int32x4(wasm_v8x16_shuffle(a.val, b.val, 0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27)); +} +inline v_uint8x16 v_pack_u(const v_int16x8& a, const v_int16x8& b) +{ + v128_t maxval = wasm_i16x8_splat(255); + v128_t minval = wasm_i16x8_splat(0); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i16x8_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_i16x8_gt(b.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i16x8_lt(a1, minval)); + v128_t b2 = wasm_v128_bitselect(minval, b1, wasm_i16x8_lt(b1, minval)); + return v_uint8x16(wasm_v8x16_shuffle(a2, b2, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)); +} +inline v_uint16x8 v_pack_u(const v_int32x4& a, const v_int32x4& b) +{ + v128_t maxval = wasm_i32x4_splat(65535); + v128_t minval = wasm_i32x4_splat(0); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i32x4_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_i32x4_gt(b.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i32x4_lt(a1, minval)); + v128_t b2 = wasm_v128_bitselect(minval, b1, wasm_i32x4_lt(b1, minval)); + return v_uint16x8(wasm_v8x16_shuffle(a2, b2, 0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29)); +} + +template +inline v_uint8x16 v_rshr_pack(const v_uint16x8& a, const v_uint16x8& b) +{ + v128_t delta = wasm_i16x8_splat(((short)1 << (n-1))); + v128_t a1 = wasm_u16x8_shr(wasm_i16x8_add(a.val, delta), n); + v128_t b1 = wasm_u16x8_shr(wasm_i16x8_add(b.val, delta), n); + v128_t maxval = wasm_i16x8_splat(255); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_u16x8_gt(a1, maxval)); + v128_t b2 = wasm_v128_bitselect(maxval, b1, wasm_u16x8_gt(b1, maxval)); + return v_uint8x16(wasm_v8x16_shuffle(a2, b2, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)); +} +template +inline v_int8x16 v_rshr_pack(const v_int16x8& a, const v_int16x8& b) +{ + v128_t delta = wasm_i16x8_splat(((short)1 << (n-1))); + v128_t a1 = wasm_i16x8_shr(wasm_i16x8_add(a.val, delta), n); + v128_t b1 = wasm_i16x8_shr(wasm_i16x8_add(b.val, delta), n); + v128_t maxval = wasm_i16x8_splat(127); + v128_t minval = wasm_i16x8_splat(-128); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i16x8_gt(a1, maxval)); + v128_t b2 = wasm_v128_bitselect(maxval, b1, wasm_i16x8_gt(b1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i16x8_lt(a1, minval)); + v128_t b3 = wasm_v128_bitselect(minval, b2, wasm_i16x8_lt(b1, minval)); + return v_int8x16(wasm_v8x16_shuffle(a3, b3, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)); +} +template +inline v_uint16x8 v_rshr_pack(const v_uint32x4& a, const v_uint32x4& b) +{ + v128_t delta = wasm_i32x4_splat(((int)1 << (n-1))); + v128_t a1 = wasm_u32x4_shr(wasm_i32x4_add(a.val, delta), n); + v128_t b1 = wasm_u32x4_shr(wasm_i32x4_add(b.val, delta), n); + v128_t maxval = wasm_i32x4_splat(65535); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_u32x4_gt(a1, maxval)); + v128_t b2 = wasm_v128_bitselect(maxval, b1, wasm_u32x4_gt(b1, maxval)); + return v_uint16x8(wasm_v8x16_shuffle(a2, b2, 0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29)); +} +template +inline v_int16x8 v_rshr_pack(const v_int32x4& a, const v_int32x4& b) +{ + v128_t delta = wasm_i32x4_splat(((int)1 << (n-1))); + v128_t a1 = wasm_i32x4_shr(wasm_i32x4_add(a.val, delta), n); + v128_t b1 = wasm_i32x4_shr(wasm_i32x4_add(b.val, delta), n); + v128_t maxval = wasm_i32x4_splat(32767); + v128_t minval = wasm_i16x8_splat(-32768); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i32x4_gt(a1, maxval)); + v128_t b2 = wasm_v128_bitselect(maxval, b1, wasm_i32x4_gt(b1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i32x4_lt(a1, minval)); + v128_t b3 = wasm_v128_bitselect(minval, b2, wasm_i32x4_lt(b1, minval)); + return v_int16x8(wasm_v8x16_shuffle(a3, b3, 0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29)); +} +template +inline v_uint32x4 v_rshr_pack(const v_uint64x2& a, const v_uint64x2& b) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t delta = wasm_i64x2_splat(((int64)1 << (n-1))); + v128_t a1 = wasm_u64x2_shr(wasm_i64x2_add(a.val, delta), n); + v128_t b1 = wasm_u64x2_shr(wasm_i64x2_add(b.val, delta), n); + return v_uint32x4(wasm_v8x16_shuffle(a1, b1, 0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27)); +#else + fallback::v_uint64x2 a_(a), b_(b); + return fallback::v_rshr_pack(a_, b_); +#endif +} +template +inline v_int32x4 v_rshr_pack(const v_int64x2& a, const v_int64x2& b) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t delta = wasm_i64x2_splat(((int64)1 << (n-1))); + v128_t a1 = wasm_i64x2_shr(wasm_i64x2_add(a.val, delta), n); + v128_t b1 = wasm_i64x2_shr(wasm_i64x2_add(b.val, delta), n); + return v_int32x4(wasm_v8x16_shuffle(a1, b1, 0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27)); +#else + fallback::v_int64x2 a_(a), b_(b); + return fallback::v_rshr_pack(a_, b_); +#endif +} +template +inline v_uint8x16 v_rshr_pack_u(const v_int16x8& a, const v_int16x8& b) +{ + v128_t delta = wasm_i16x8_splat(((short)1 << (n-1))); + v128_t a1 = wasm_i16x8_shr(wasm_i16x8_add(a.val, delta), n); + v128_t b1 = wasm_i16x8_shr(wasm_i16x8_add(b.val, delta), n); + v128_t maxval = wasm_i16x8_splat(255); + v128_t minval = wasm_i16x8_splat(0); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i16x8_gt(a1, maxval)); + v128_t b2 = wasm_v128_bitselect(maxval, b1, wasm_i16x8_gt(b1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i16x8_lt(a1, minval)); + v128_t b3 = wasm_v128_bitselect(minval, b2, wasm_i16x8_lt(b1, minval)); + return v_uint8x16(wasm_v8x16_shuffle(a3, b3, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)); +} +template +inline v_uint16x8 v_rshr_pack_u(const v_int32x4& a, const v_int32x4& b) +{ + v128_t delta = wasm_i32x4_splat(((int)1 << (n-1))); + v128_t a1 = wasm_i32x4_shr(wasm_i32x4_add(a.val, delta), n); + v128_t b1 = wasm_i32x4_shr(wasm_i32x4_add(b.val, delta), n); + v128_t maxval = wasm_i32x4_splat(65535); + v128_t minval = wasm_i16x8_splat(0); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i32x4_gt(a1, maxval)); + v128_t b2 = wasm_v128_bitselect(maxval, b1, wasm_i32x4_gt(b1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i32x4_lt(a1, minval)); + v128_t b3 = wasm_v128_bitselect(minval, b2, wasm_i32x4_lt(b1, minval)); + return v_uint16x8(wasm_v8x16_shuffle(a3, b3, 0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29)); +} + +inline void v_pack_store(uchar* ptr, const v_uint16x8& a) +{ + v128_t maxval = wasm_i16x8_splat(255); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_u16x8_gt(a.val, maxval)); + v128_t r = wasm_v8x16_shuffle(a1, a1, 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14); + uchar t_ptr[16]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<8; ++i) { + ptr[i] = t_ptr[i]; + } +} +inline void v_pack_store(schar* ptr, const v_int16x8& a) +{ + v128_t maxval = wasm_i16x8_splat(127); + v128_t minval = wasm_i16x8_splat(-128); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i16x8_gt(a.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i16x8_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a2, a2, 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14); + schar t_ptr[16]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<8; ++i) { + ptr[i] = t_ptr[i]; + } +} +inline void v_pack_store(ushort* ptr, const v_uint32x4& a) +{ + v128_t maxval = wasm_i32x4_splat(65535); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_u32x4_gt(a.val, maxval)); + v128_t r = wasm_v8x16_shuffle(a1, a1, 0,1,4,5,8,9,12,13,0,1,4,5,8,9,12,13); + ushort t_ptr[8]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<4; ++i) { + ptr[i] = t_ptr[i]; + } +} +inline void v_pack_store(short* ptr, const v_int32x4& a) +{ + v128_t maxval = wasm_i32x4_splat(32767); + v128_t minval = wasm_i32x4_splat(-32768); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i32x4_gt(a.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i32x4_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a2, a2, 0,1,4,5,8,9,12,13,0,1,4,5,8,9,12,13); + short t_ptr[8]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<4; ++i) { + ptr[i] = t_ptr[i]; + } +} +inline void v_pack_store(unsigned* ptr, const v_uint64x2& a) +{ + v128_t r = wasm_v8x16_shuffle(a.val, a.val, 0,1,2,3,8,9,10,11,0,1,2,3,8,9,10,11); + unsigned t_ptr[4]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<2; ++i) { + ptr[i] = t_ptr[i]; + } +} +inline void v_pack_store(int* ptr, const v_int64x2& a) +{ + v128_t r = wasm_v8x16_shuffle(a.val, a.val, 0,1,2,3,8,9,10,11,0,1,2,3,8,9,10,11); + int t_ptr[4]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<2; ++i) { + ptr[i] = t_ptr[i]; + } +} +inline void v_pack_u_store(uchar* ptr, const v_int16x8& a) +{ + v128_t maxval = wasm_i16x8_splat(255); + v128_t minval = wasm_i16x8_splat(0); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i16x8_gt(a.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i16x8_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a2, a2, 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14); + uchar t_ptr[16]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<8; ++i) { + ptr[i] = t_ptr[i]; + } +} +inline void v_pack_u_store(ushort* ptr, const v_int32x4& a) +{ + v128_t maxval = wasm_i32x4_splat(65535); + v128_t minval = wasm_i32x4_splat(0); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_i32x4_gt(a.val, maxval)); + v128_t a2 = wasm_v128_bitselect(minval, a1, wasm_i32x4_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a2, a2, 0,1,4,5,8,9,12,13,0,1,4,5,8,9,12,13); + ushort t_ptr[8]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<4; ++i) { + ptr[i] = t_ptr[i]; + } +} + +template +inline void v_rshr_pack_store(uchar* ptr, const v_uint16x8& a) +{ + v128_t delta = wasm_i16x8_splat((short)(1 << (n-1))); + v128_t a1 = wasm_u16x8_shr(wasm_i16x8_add(a.val, delta), n); + v128_t maxval = wasm_i16x8_splat(255); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_u16x8_gt(a1, maxval)); + v128_t r = wasm_v8x16_shuffle(a2, a2, 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14); + uchar t_ptr[16]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<8; ++i) { + ptr[i] = t_ptr[i]; + } +} +template +inline void v_rshr_pack_store(schar* ptr, const v_int16x8& a) +{ + v128_t delta = wasm_i16x8_splat(((short)1 << (n-1))); + v128_t a1 = wasm_i16x8_shr(wasm_i16x8_add(a.val, delta), n); + v128_t maxval = wasm_i16x8_splat(127); + v128_t minval = wasm_i16x8_splat(-128); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i16x8_gt(a1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i16x8_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a3, a3, 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14); + schar t_ptr[16]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<8; ++i) { + ptr[i] = t_ptr[i]; + } +} +template +inline void v_rshr_pack_store(ushort* ptr, const v_uint32x4& a) +{ + v128_t delta = wasm_i32x4_splat(((int)1 << (n-1))); + v128_t a1 = wasm_u32x4_shr(wasm_i32x4_add(a.val, delta), n); + v128_t maxval = wasm_i32x4_splat(65535); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_u32x4_gt(a1, maxval)); + v128_t r = wasm_v8x16_shuffle(a2, a2, 0,1,4,5,8,9,12,13,0,1,4,5,8,9,12,13); + ushort t_ptr[8]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<4; ++i) { + ptr[i] = t_ptr[i]; + } +} +template +inline void v_rshr_pack_store(short* ptr, const v_int32x4& a) +{ + v128_t delta = wasm_i32x4_splat(((int)1 << (n-1))); + v128_t a1 = wasm_i32x4_shr(wasm_i32x4_add(a.val, delta), n); + v128_t maxval = wasm_i32x4_splat(32767); + v128_t minval = wasm_i32x4_splat(-32768); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i32x4_gt(a1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i32x4_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a3, a3, 0,1,4,5,8,9,12,13,0,1,4,5,8,9,12,13); + short t_ptr[8]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<4; ++i) { + ptr[i] = t_ptr[i]; + } +} +template +inline void v_rshr_pack_store(unsigned* ptr, const v_uint64x2& a) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t delta = wasm_i64x2_splat(((int64)1 << (n-1))); + v128_t a1 = wasm_u64x2_shr(wasm_i64x2_add(a.val, delta), n); + v128_t r = wasm_v8x16_shuffle(a1, a1, 0,1,2,3,8,9,10,11,0,1,2,3,8,9,10,11); + unsigned t_ptr[4]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<2; ++i) { + ptr[i] = t_ptr[i]; + } +#else + fallback::v_uint64x2 _a(a); + fallback::v_rshr_pack_store(ptr, _a); +#endif +} +template +inline void v_rshr_pack_store(int* ptr, const v_int64x2& a) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t delta = wasm_i64x2_splat(((int64)1 << (n-1))); + v128_t a1 = wasm_i64x2_shr(wasm_i64x2_add(a.val, delta), n); + v128_t r = wasm_v8x16_shuffle(a1, a1, 0,1,2,3,8,9,10,11,0,1,2,3,8,9,10,11); + int t_ptr[4]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<2; ++i) { + ptr[i] = t_ptr[i]; + } +#else + fallback::v_int64x2 _a(a); + fallback::v_rshr_pack_store(ptr, _a); +#endif +} +template +inline void v_rshr_pack_u_store(uchar* ptr, const v_int16x8& a) +{ + v128_t delta = wasm_i16x8_splat(((short)1 << (n-1))); + v128_t a1 = wasm_i16x8_shr(wasm_i16x8_add(a.val, delta), n); + v128_t maxval = wasm_i16x8_splat(255); + v128_t minval = wasm_i16x8_splat(0); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i16x8_gt(a1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i16x8_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a3, a3, 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14); + uchar t_ptr[16]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<8; ++i) { + ptr[i] = t_ptr[i]; + } +} +template +inline void v_rshr_pack_u_store(ushort* ptr, const v_int32x4& a) +{ + v128_t delta = wasm_i32x4_splat(((int)1 << (n-1))); + v128_t a1 = wasm_i32x4_shr(wasm_i32x4_add(a.val, delta), n); + v128_t maxval = wasm_i32x4_splat(65535); + v128_t minval = wasm_i32x4_splat(0); + v128_t a2 = wasm_v128_bitselect(maxval, a1, wasm_i32x4_gt(a1, maxval)); + v128_t a3 = wasm_v128_bitselect(minval, a2, wasm_i32x4_lt(a1, minval)); + v128_t r = wasm_v8x16_shuffle(a3, a3, 0,1,4,5,8,9,12,13,0,1,4,5,8,9,12,13); + ushort t_ptr[8]; + wasm_v128_store(t_ptr, r); + for (int i=0; i<4; ++i) { + ptr[i] = t_ptr[i]; + } +} + +inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b) +{ + v128_t maxval = wasm_i16x8_splat(255); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_u16x8_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_u16x8_gt(b.val, maxval)); + return v_uint8x16(wasm_v8x16_shuffle(a1, b1, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)); +} + +inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d) +{ + v128_t maxval = wasm_i32x4_splat(255); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, wasm_u32x4_gt(a.val, maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, wasm_u32x4_gt(b.val, maxval)); + v128_t c1 = wasm_v128_bitselect(maxval, c.val, wasm_u32x4_gt(c.val, maxval)); + v128_t d1 = wasm_v128_bitselect(maxval, d.val, wasm_u32x4_gt(d.val, maxval)); + v128_t ab = wasm_v8x16_shuffle(a1, b1, 0,4,8,12,16,20,24,28,0,4,8,12,16,20,24,28); + v128_t cd = wasm_v8x16_shuffle(c1, d1, 0,4,8,12,16,20,24,28,0,4,8,12,16,20,24,28); + return v_uint8x16(wasm_v8x16_shuffle(ab, cd, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23)); +} + +inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c, + const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f, + const v_uint64x2& g, const v_uint64x2& h) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t maxval = wasm_i32x4_splat(255); + v128_t a1 = wasm_v128_bitselect(maxval, a.val, ((__u64x2)(a.val) > (__u64x2)maxval)); + v128_t b1 = wasm_v128_bitselect(maxval, b.val, ((__u64x2)(b.val) > (__u64x2)maxval)); + v128_t c1 = wasm_v128_bitselect(maxval, c.val, ((__u64x2)(c.val) > (__u64x2)maxval)); + v128_t d1 = wasm_v128_bitselect(maxval, d.val, ((__u64x2)(d.val) > (__u64x2)maxval)); + v128_t e1 = wasm_v128_bitselect(maxval, e.val, ((__u64x2)(e.val) > (__u64x2)maxval)); + v128_t f1 = wasm_v128_bitselect(maxval, f.val, ((__u64x2)(f.val) > (__u64x2)maxval)); + v128_t g1 = wasm_v128_bitselect(maxval, g.val, ((__u64x2)(g.val) > (__u64x2)maxval)); + v128_t h1 = wasm_v128_bitselect(maxval, h.val, ((__u64x2)(h.val) > (__u64x2)maxval)); + v128_t ab = wasm_v8x16_shuffle(a1, b1, 0,8,16,24,0,8,16,24,0,8,16,24,0,8,16,24); + v128_t cd = wasm_v8x16_shuffle(c1, d1, 0,8,16,24,0,8,16,24,0,8,16,24,0,8,16,24); + v128_t ef = wasm_v8x16_shuffle(e1, f1, 0,8,16,24,0,8,16,24,0,8,16,24,0,8,16,24); + v128_t gh = wasm_v8x16_shuffle(g1, h1, 0,8,16,24,0,8,16,24,0,8,16,24,0,8,16,24); + v128_t abcd = wasm_v8x16_shuffle(ab, cd, 0,1,2,3,16,17,18,19,0,1,2,3,16,17,18,19); + v128_t efgh = wasm_v8x16_shuffle(ef, gh, 0,1,2,3,16,17,18,19,0,1,2,3,16,17,18,19); + return v_uint8x16(wasm_v8x16_shuffle(abcd, efgh, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23)); +#else + fallback::v_uint64x2 a_(a), b_(b), c_(c), d_(d), e_(e), f_(f), g_(g), h_(h); + return fallback::v_pack_b(a_, b_, c_, d_, e_, f_, g_, h_); +#endif +} + +inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& m3) +{ + v128_t v0 = wasm_f32x4_splat(wasm_f32x4_extract_lane(v.val, 0)); + v128_t v1 = wasm_f32x4_splat(wasm_f32x4_extract_lane(v.val, 1)); + v128_t v2 = wasm_f32x4_splat(wasm_f32x4_extract_lane(v.val, 2)); + v128_t v3 = wasm_f32x4_splat(wasm_f32x4_extract_lane(v.val, 3)); + v0 = wasm_f32x4_mul(v0, m0.val); + v1 = wasm_f32x4_mul(v1, m1.val); + v2 = wasm_f32x4_mul(v2, m2.val); + v3 = wasm_f32x4_mul(v3, m3.val); + + return v_float32x4(wasm_f32x4_add(wasm_f32x4_add(v0, v1), wasm_f32x4_add(v2, v3))); +} + +inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0, + const v_float32x4& m1, const v_float32x4& m2, + const v_float32x4& a) +{ + v128_t v0 = wasm_f32x4_splat(wasm_f32x4_extract_lane(v.val, 0)); + v128_t v1 = wasm_f32x4_splat(wasm_f32x4_extract_lane(v.val, 1)); + v128_t v2 = wasm_f32x4_splat(wasm_f32x4_extract_lane(v.val, 2)); + v0 = wasm_f32x4_mul(v0, m0.val); + v1 = wasm_f32x4_mul(v1, m1.val); + v2 = wasm_f32x4_mul(v2, m2.val); + + return v_float32x4(wasm_f32x4_add(wasm_f32x4_add(v0, v1), wasm_f32x4_add(v2, a.val))); +} + +#define OPENCV_HAL_IMPL_WASM_BIN_OP(bin_op, _Tpvec, intrin) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + a.val = intrin(a.val, b.val); \ + return a; \ +} + +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_uint8x16, wasm_u8x16_add_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_uint8x16, wasm_u8x16_sub_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_int8x16, wasm_i8x16_add_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_int8x16, wasm_i8x16_sub_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_uint16x8, wasm_u16x8_add_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_uint16x8, wasm_u16x8_sub_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_int16x8, wasm_i16x8_add_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_int16x8, wasm_i16x8_sub_saturate) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_uint32x4, wasm_i32x4_add) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_uint32x4, wasm_i32x4_sub) +OPENCV_HAL_IMPL_WASM_BIN_OP(*, v_uint32x4, wasm_i32x4_mul) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_int32x4, wasm_i32x4_add) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_int32x4, wasm_i32x4_sub) +OPENCV_HAL_IMPL_WASM_BIN_OP(*, v_int32x4, wasm_i32x4_mul) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_float32x4, wasm_f32x4_add) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_float32x4, wasm_f32x4_sub) +OPENCV_HAL_IMPL_WASM_BIN_OP(*, v_float32x4, wasm_f32x4_mul) +OPENCV_HAL_IMPL_WASM_BIN_OP(/, v_float32x4, wasm_f32x4_div) + +#ifdef __wasm_unimplemented_simd128__ +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_uint64x2, wasm_i64x2_add) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_uint64x2, wasm_i64x2_sub) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_int64x2, wasm_i64x2_add) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_int64x2, wasm_i64x2_sub) +OPENCV_HAL_IMPL_WASM_BIN_OP(+, v_float64x2, wasm_f64x2_add) +OPENCV_HAL_IMPL_WASM_BIN_OP(-, v_float64x2, wasm_f64x2_sub) +OPENCV_HAL_IMPL_WASM_BIN_OP(*, v_float64x2, wasm_f64x2_mul) +OPENCV_HAL_IMPL_WASM_BIN_OP(/, v_float64x2, wasm_f64x2_div) +#else +#define OPENCV_HAL_IMPL_FALLBACK_BIN_OP(bin_op, _Tpvec) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + fallback::_Tpvec a_(a), b_(b); \ + return _Tpvec((a_) bin_op (b_)); \ +} \ +inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \ +{ \ + fallback::_Tpvec a_(a), b_(b); \ + a_ bin_op##= b_; \ + a = _Tpvec(a_); \ + return a; \ +} + +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(+, v_uint64x2) +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(-, v_uint64x2) +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(+, v_int64x2) +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(-, v_int64x2) +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(+, v_float64x2) +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(-, v_float64x2) +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(*, v_float64x2) +OPENCV_HAL_IMPL_FALLBACK_BIN_OP(/, v_float64x2) +#endif + +// saturating multiply 8-bit, 16-bit +#define OPENCV_HAL_IMPL_WASM_MUL_SAT(_Tpvec, _Tpwvec) \ +inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \ +{ \ + _Tpwvec c, d; \ + v_mul_expand(a, b, c, d); \ + return v_pack(c, d); \ +} \ +inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \ +{ a = a * b; return a; } + +OPENCV_HAL_IMPL_WASM_MUL_SAT(v_uint8x16, v_uint16x8) +OPENCV_HAL_IMPL_WASM_MUL_SAT(v_int8x16, v_int16x8) +OPENCV_HAL_IMPL_WASM_MUL_SAT(v_uint16x8, v_uint32x4) +OPENCV_HAL_IMPL_WASM_MUL_SAT(v_int16x8, v_int32x4) + +// Multiply and expand +inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b, + v_uint16x8& c, v_uint16x8& d) +{ + v_uint16x8 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b, + v_int16x8& c, v_int16x8& d) +{ + v_int16x8 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c = v_mul_wrap(a0, b0); + d = v_mul_wrap(a1, b1); +} + +inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b, + v_int32x4& c, v_int32x4& d) +{ + v_int32x4 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c.val = wasm_i32x4_mul(a0.val, b0.val); + d.val = wasm_i32x4_mul(a1.val, b1.val); +} + +inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b, + v_uint32x4& c, v_uint32x4& d) +{ + v_uint32x4 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c.val = wasm_i32x4_mul(a0.val, b0.val); + d.val = wasm_i32x4_mul(a1.val, b1.val); +} + +inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b, + v_uint64x2& c, v_uint64x2& d) +{ +#ifdef __wasm_unimplemented_simd128__ + v_uint64x2 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + c.val = ((__u64x2)(a0.val) * (__u64x2)(b0.val)); + d.val = ((__u64x2)(a1.val) * (__u64x2)(b1.val)); +#else + fallback::v_uint32x4 a_(a), b_(b); + fallback::v_uint64x2 c_, d_; + fallback::v_mul_expand(a_, b_, c_, d_); + c = v_uint64x2(c_); + d = v_uint64x2(d_); +#endif +} + +inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b) +{ + v_int32x4 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + v128_t c = wasm_i32x4_mul(a0.val, b0.val); + v128_t d = wasm_i32x4_mul(a1.val, b1.val); + return v_int16x8(wasm_v8x16_shuffle(c, d, 2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31)); +} +inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint32x4 a0, a1, b0, b1; + v_expand(a, a0, a1); + v_expand(b, b0, b1); + v128_t c = wasm_i32x4_mul(a0.val, b0.val); + v128_t d = wasm_i32x4_mul(a1.val, b1.val); + return v_uint16x8(wasm_v8x16_shuffle(c, d, 2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31)); +} + +//////// Dot Product //////// + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b) +{ + v128_t a0 = wasm_i32x4_shr(wasm_i32x4_shl(a.val, 16), 16); + v128_t a1 = wasm_i32x4_shr(a.val, 16); + v128_t b0 = wasm_i32x4_shr(wasm_i32x4_shl(b.val, 16), 16); + v128_t b1 = wasm_i32x4_shr(b.val, 16); + v128_t c = wasm_i32x4_mul(a0, b0); + v128_t d = wasm_i32x4_mul(a1, b1); + return v_int32x4(wasm_i32x4_add(c, d)); +} + +inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_dotprod(a, b) + c; } + +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t a0 = wasm_i64x2_shr(wasm_i64x2_shl(a.val, 32), 32); + v128_t a1 = wasm_i64x2_shr(a.val, 32); + v128_t b0 = wasm_i64x2_shr(wasm_i64x2_shl(b.val, 32), 32); + v128_t b1 = wasm_i64x2_shr(b.val, 32); + v128_t c = (v128_t)((__i64x2)a0 * (__i64x2)b0); + v128_t d = (v128_t)((__i64x2)a1 * (__i64x2)b1); + return v_int64x2(wasm_i64x2_add(c, d)); +#else + fallback::v_int32x4 a_(a); + fallback::v_int32x4 b_(b); + return fallback::v_dotprod(a_, b_); +#endif +} +inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ +#ifdef __wasm_unimplemented_simd128__ + return v_dotprod(a, b) + c; +#else + fallback::v_int32x4 a_(a); + fallback::v_int32x4 b_(b); + fallback::v_int64x2 c_(c); + return fallback::v_dotprod(a_, b_, c_); +#endif +} + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b) +{ + v128_t a0 = wasm_u16x8_shr(wasm_i16x8_shl(a.val, 8), 8); + v128_t a1 = wasm_u16x8_shr(a.val, 8); + v128_t b0 = wasm_u16x8_shr(wasm_i16x8_shl(b.val, 8), 8); + v128_t b1 = wasm_u16x8_shr(b.val, 8); + return v_uint32x4(( + v_dotprod(v_int16x8(a0), v_int16x8(b0)) + + v_dotprod(v_int16x8(a1), v_int16x8(b1))).val + ); +} +inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ return v_dotprod_expand(a, b) + c; } + +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b) +{ + v128_t a0 = wasm_i16x8_shr(wasm_i16x8_shl(a.val, 8), 8); + v128_t a1 = wasm_i16x8_shr(a.val, 8); + v128_t b0 = wasm_i16x8_shr(wasm_i16x8_shl(b.val, 8), 8); + v128_t b1 = wasm_i16x8_shr(b.val, 8); + return v_int32x4( + v_dotprod(v_int16x8(a0), v_int16x8(b0)) + + v_dotprod(v_int16x8(a1), v_int16x8(b1)) + ); +} +inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ return v_dotprod_expand(a, b) + c; } + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b) +{ + fallback::v_uint16x8 a_(a); + fallback::v_uint16x8 b_(b); + return fallback::v_dotprod_expand(a_, b_); +} +inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ + fallback::v_uint16x8 a_(a); + fallback::v_uint16x8 b_(b); + fallback::v_uint64x2 c_(c); + return fallback::v_dotprod_expand(a_, b_, c_); +} + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b) +{ + fallback::v_int16x8 a_(a); + fallback::v_int16x8 b_(b); + return fallback::v_dotprod_expand(a_, b_); +} + +inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ + fallback::v_int16x8 a_(a); + fallback::v_int16x8 b_(b); + fallback::v_int64x2 c_(c); + return fallback::v_dotprod_expand(a_, b_, c_); +} + +// 32 >> 64f +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b) +{ return v_cvt_f64(v_dotprod(a, b)); } +inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand(a, b) + c; } + +//////// Fast Dot Product //////// + +// 16 >> 32 +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b) +{ return v_dotprod(a, b); } +inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) +{ return v_dotprod(a, b, c); } + +// 32 >> 64 +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_dotprod(a, b); } +inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c) +{ return v_dotprod(a, b, c); } + +// 8 >> 32 +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b) +{ return v_dotprod_expand(a, b); } +inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c) +{ return v_dotprod_expand(a, b, c); } +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b) +{ return v_dotprod_expand(a, b); } +inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c) +{ return v_dotprod_expand(a, b, c); } + +// 16 >> 64 +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b) +{ return v_dotprod_expand(a, b); } +inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c) +{ return v_dotprod_expand(a, b, c); } +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b) +{ return v_dotprod_expand(a, b); } +inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c) +{ return v_dotprod_expand(a, b, c); } + +// 32 >> 64f +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b) +{ return v_dotprod_expand(a, b); } +inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c) +{ return v_dotprod_expand(a, b, c); } + +#define OPENCV_HAL_IMPL_WASM_LOGIC_OP(_Tpvec) \ +OPENCV_HAL_IMPL_WASM_BIN_OP(&, _Tpvec, wasm_v128_and) \ +OPENCV_HAL_IMPL_WASM_BIN_OP(|, _Tpvec, wasm_v128_or) \ +OPENCV_HAL_IMPL_WASM_BIN_OP(^, _Tpvec, wasm_v128_xor) \ +inline _Tpvec operator ~ (const _Tpvec& a) \ +{ \ + return _Tpvec(wasm_v128_not(a.val)); \ +} + +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_uint8x16) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_int8x16) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_uint16x8) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_int16x8) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_uint32x4) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_int32x4) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_uint64x2) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_int64x2) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_float32x4) +OPENCV_HAL_IMPL_WASM_LOGIC_OP(v_float64x2) + +inline v_float32x4 v_sqrt(const v_float32x4& x) +{ +#ifdef __wasm_unimplemented_simd128__ + return v_float32x4(wasm_f32x4_sqrt(x.val)); +#else + fallback::v_float32x4 x_(x); + return fallback::v_sqrt(x_); +#endif +} + +inline v_float32x4 v_invsqrt(const v_float32x4& x) +{ +#ifdef __wasm_unimplemented_simd128__ + const v128_t _1_0 = wasm_f32x4_splat(1.0); + return v_float32x4(wasm_f32x4_div(_1_0, wasm_f32x4_sqrt(x.val))); +#else + fallback::v_float32x4 x_(x); + return fallback::v_invsqrt(x_); +#endif +} + +inline v_float64x2 v_sqrt(const v_float64x2& x) +{ +#ifdef __wasm_unimplemented_simd128__ + return v_float64x2(wasm_f64x2_sqrt(x.val)); +#else + fallback::v_float64x2 x_(x); + return fallback::v_sqrt(x_); +#endif +} + +inline v_float64x2 v_invsqrt(const v_float64x2& x) +{ +#ifdef __wasm_unimplemented_simd128__ + const v128_t _1_0 = wasm_f64x2_splat(1.0); + return v_float64x2(wasm_f64x2_div(_1_0, wasm_f64x2_sqrt(x.val))); +#else + fallback::v_float64x2 x_(x); + return fallback::v_invsqrt(x_); +#endif +} + +#define OPENCV_HAL_IMPL_WASM_ABS_INT_FUNC(_Tpuvec, _Tpsvec, suffix, zsuffix, shiftWidth) \ +inline _Tpuvec v_abs(const _Tpsvec& x) \ +{ \ + v128_t s = wasm_##suffix##_shr(x.val, shiftWidth); \ + v128_t f = wasm_##zsuffix##_shr(x.val, shiftWidth); \ + return _Tpuvec(wasm_##zsuffix##_add(wasm_v128_xor(x.val, f), s)); \ +} + +OPENCV_HAL_IMPL_WASM_ABS_INT_FUNC(v_uint8x16, v_int8x16, u8x16, i8x16, 7) +OPENCV_HAL_IMPL_WASM_ABS_INT_FUNC(v_uint16x8, v_int16x8, u16x8, i16x8, 15) +OPENCV_HAL_IMPL_WASM_ABS_INT_FUNC(v_uint32x4, v_int32x4, u32x4, i32x4, 31) + +inline v_float32x4 v_abs(const v_float32x4& x) +{ return v_float32x4(wasm_f32x4_abs(x.val)); } +inline v_float64x2 v_abs(const v_float64x2& x) +{ +#ifdef __wasm_unimplemented_simd128__ + return v_float64x2(wasm_f64x2_abs(x.val)); +#else + fallback::v_float64x2 x_(x); + return fallback::v_abs(x_); +#endif +} + +// TODO: exp, log, sin, cos + +#define OPENCV_HAL_IMPL_WASM_BIN_FUNC(_Tpvec, func, intrin) \ +inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(intrin(a.val, b.val)); \ +} + +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_float32x4, v_min, wasm_f32x4_min) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_float32x4, v_max, wasm_f32x4_max) + +#ifdef __wasm_unimplemented_simd128__ +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_float64x2, v_min, wasm_f64x2_min) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_float64x2, v_max, wasm_f64x2_max) +#else +#define OPENCV_HAL_IMPL_WASM_MINMAX_64f_FUNC(func) \ +inline v_float64x2 func(const v_float64x2& a, const v_float64x2& b) \ +{ \ + fallback::v_float64x2 a_(a), b_(b); \ + return fallback::func(a_, b_); \ +} + +OPENCV_HAL_IMPL_WASM_MINMAX_64f_FUNC(v_min) +OPENCV_HAL_IMPL_WASM_MINMAX_64f_FUNC(v_max) +#endif + +#define OPENCV_HAL_IMPL_WASM_MINMAX_S_INIT_FUNC(_Tpvec, suffix) \ +inline _Tpvec v_min(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(wasm_v128_bitselect(b.val, a.val, wasm_##suffix##_gt(a.val, b.val))); \ +} \ +inline _Tpvec v_max(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(wasm_v128_bitselect(a.val, b.val, wasm_##suffix##_gt(a.val, b.val))); \ +} + +OPENCV_HAL_IMPL_WASM_MINMAX_S_INIT_FUNC(v_int8x16, i8x16) +OPENCV_HAL_IMPL_WASM_MINMAX_S_INIT_FUNC(v_int16x8, i16x8) +OPENCV_HAL_IMPL_WASM_MINMAX_S_INIT_FUNC(v_int32x4, i32x4) + +#define OPENCV_HAL_IMPL_WASM_MINMAX_U_INIT_FUNC(_Tpvec, suffix, deltaNum) \ +inline _Tpvec v_min(const _Tpvec& a, const _Tpvec& b) \ +{ \ + v128_t delta = wasm_##suffix##_splat(deltaNum); \ + v128_t mask = wasm_##suffix##_gt(wasm_v128_xor(a.val, delta), wasm_v128_xor(b.val, delta)); \ + return _Tpvec(wasm_v128_bitselect(b.val, a.val, mask)); \ +} \ +inline _Tpvec v_max(const _Tpvec& a, const _Tpvec& b) \ +{ \ + v128_t delta = wasm_##suffix##_splat(deltaNum); \ + v128_t mask = wasm_##suffix##_gt(wasm_v128_xor(a.val, delta), wasm_v128_xor(b.val, delta)); \ + return _Tpvec(wasm_v128_bitselect(a.val, b.val, mask)); \ +} + +OPENCV_HAL_IMPL_WASM_MINMAX_U_INIT_FUNC(v_uint8x16, i8x16, (schar)0x80) +OPENCV_HAL_IMPL_WASM_MINMAX_U_INIT_FUNC(v_uint16x8, i16x8, (short)0x8000) +OPENCV_HAL_IMPL_WASM_MINMAX_U_INIT_FUNC(v_uint32x4, i32x4, (int)0x80000000) + +#define OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(_Tpvec, suffix, esuffix) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(wasm_##esuffix##_eq(a.val, b.val)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(wasm_##esuffix##_ne(a.val, b.val)); } \ +inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(wasm_##suffix##_lt(a.val, b.val)); } \ +inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(wasm_##suffix##_gt(a.val, b.val)); } \ +inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(wasm_##suffix##_le(a.val, b.val)); } \ +inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \ +{ return _Tpvec(wasm_##suffix##_ge(a.val, b.val)); } + +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_uint8x16, u8x16, i8x16) +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_int8x16, i8x16, i8x16) +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_uint16x8, u16x8, i16x8) +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_int16x8, i16x8, i16x8) +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_uint32x4, u32x4, i32x4) +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_int32x4, i32x4, i32x4) +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_float32x4, f32x4, f32x4) + +#ifdef __wasm_unimplemented_simd128__ +OPENCV_HAL_IMPL_WASM_INIT_CMP_OP(v_float64x2, f64x2, f64x2) +#else +#define OPENCV_HAL_IMPL_INIT_FALLBACK_CMP_OP(_Tpvec, bin_op) \ +inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \ +{ \ + fallback::_Tpvec a_(a), b_(b); \ + return _Tpvec((a_) bin_op (b_));\ +} \ + +OPENCV_HAL_IMPL_INIT_FALLBACK_CMP_OP(v_float64x2, ==) +OPENCV_HAL_IMPL_INIT_FALLBACK_CMP_OP(v_float64x2, !=) +OPENCV_HAL_IMPL_INIT_FALLBACK_CMP_OP(v_float64x2, <) +OPENCV_HAL_IMPL_INIT_FALLBACK_CMP_OP(v_float64x2, >) +OPENCV_HAL_IMPL_INIT_FALLBACK_CMP_OP(v_float64x2, <=) +OPENCV_HAL_IMPL_INIT_FALLBACK_CMP_OP(v_float64x2, >=) +#endif + +#define OPENCV_HAL_IMPL_WASM_64BIT_CMP_OP(_Tpvec, cast) \ +inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \ +{ return cast(v_reinterpret_as_f64(a) == v_reinterpret_as_f64(b)); } \ +inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \ +{ return cast(v_reinterpret_as_f64(a) != v_reinterpret_as_f64(b)); } + +OPENCV_HAL_IMPL_WASM_64BIT_CMP_OP(v_uint64x2, v_reinterpret_as_u64) +OPENCV_HAL_IMPL_WASM_64BIT_CMP_OP(v_int64x2, v_reinterpret_as_s64) + +inline v_float32x4 v_not_nan(const v_float32x4& a) +{ + v128_t z = wasm_i32x4_splat(0x7fffffff); + v128_t t = wasm_i32x4_splat(0x7f800000); + return v_float32x4(wasm_u32x4_lt(wasm_v128_and(a.val, z), t)); +} +inline v_float64x2 v_not_nan(const v_float64x2& a) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t z = wasm_i64x2_splat(0x7fffffffffffffff); + v128_t t = wasm_i64x2_splat(0x7ff0000000000000); + return v_float64x2((__u64x2)(wasm_v128_and(a.val, z)) < (__u64x2)t); +#else + fallback::v_float64x2 a_(a); + return fallback::v_not_nan(a_); +#endif +} + +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint8x16, v_add_wrap, wasm_i8x16_add) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int8x16, v_add_wrap, wasm_i8x16_add) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint16x8, v_add_wrap, wasm_i16x8_add) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int16x8, v_add_wrap, wasm_i16x8_add) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint8x16, v_sub_wrap, wasm_i8x16_sub) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int8x16, v_sub_wrap, wasm_i8x16_sub) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint16x8, v_sub_wrap, wasm_i16x8_sub) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int16x8, v_sub_wrap, wasm_i16x8_sub) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint8x16, v_mul_wrap, wasm_i8x16_mul) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int8x16, v_mul_wrap, wasm_i8x16_mul) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_uint16x8, v_mul_wrap, wasm_i16x8_mul) +OPENCV_HAL_IMPL_WASM_BIN_FUNC(v_int16x8, v_mul_wrap, wasm_i16x8_mul) + + +/** Absolute difference **/ + +inline v_uint8x16 v_absdiff(const v_uint8x16& a, const v_uint8x16& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint16x8 v_absdiff(const v_uint16x8& a, const v_uint16x8& b) +{ return v_add_wrap(a - b, b - a); } +inline v_uint32x4 v_absdiff(const v_uint32x4& a, const v_uint32x4& b) +{ return v_max(a, b) - v_min(a, b); } + +inline v_uint8x16 v_absdiff(const v_int8x16& a, const v_int8x16& b) +{ + v_int8x16 d = v_sub_wrap(a, b); + v_int8x16 m = a < b; + return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m)); +} +inline v_uint16x8 v_absdiff(const v_int16x8& a, const v_int16x8& b) +{ + return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); +} +inline v_uint32x4 v_absdiff(const v_int32x4& a, const v_int32x4& b) +{ + v_int32x4 d = a - b; + v_int32x4 m = a < b; + return v_reinterpret_as_u32((d ^ m) - m); +} + +/** Saturating absolute difference **/ +inline v_int8x16 v_absdiffs(const v_int8x16& a, const v_int8x16& b) +{ + v_int8x16 d = a - b; + v_int8x16 m = a < b; + return (d ^ m) - m; + } +inline v_int16x8 v_absdiffs(const v_int16x8& a, const v_int16x8& b) +{ return v_max(a, b) - v_min(a, b); } + + +inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return a * b + c; +} + +inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c) +{ + return v_fma(a, b, c); +} + +inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c) +{ + return a * b + c; +} + +inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c) +{ + return a * b + c; +} + +inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b) +{ + v128_t absmask_vec = wasm_i32x4_splat(0x7fffffff); + return v_float32x4(wasm_v128_and(wasm_f32x4_sub(a.val, b.val), absmask_vec)); +} +inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t absmask_vec = wasm_u64x2_shr(wasm_i32x4_splat(-1), 1); + return v_float64x2(wasm_v128_and(wasm_f64x2_sub(a.val, b.val), absmask_vec)); +#else + fallback::v_float64x2 a_(a), b_(b); + return fallback::v_absdiff(a_, b_); +#endif +} + +#define OPENCV_HAL_IMPL_WASM_MISC_FLT_OP(_Tpvec) \ +inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ \ + fallback::_Tpvec a_(a), b_(b); \ + return fallback::v_magnitude(a_, b_); \ +} \ +inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return v_fma(a, a, b*b); \ +} \ +inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \ +{ \ + return v_fma(a, b, c); \ +} + +OPENCV_HAL_IMPL_WASM_MISC_FLT_OP(v_float32x4) +OPENCV_HAL_IMPL_WASM_MISC_FLT_OP(v_float64x2) + +#define OPENCV_HAL_IMPL_WASM_SHIFT_OP(_Tpuvec, _Tpsvec, suffix, ssuffix) \ +inline _Tpuvec operator << (const _Tpuvec& a, int imm) \ +{ \ + return _Tpuvec(wasm_##suffix##_shl(a.val, imm)); \ +} \ +inline _Tpsvec operator << (const _Tpsvec& a, int imm) \ +{ \ + return _Tpsvec(wasm_##suffix##_shl(a.val, imm)); \ +} \ +inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \ +{ \ + return _Tpuvec(wasm_##ssuffix##_shr(a.val, imm)); \ +} \ +inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \ +{ \ + return _Tpsvec(wasm_##suffix##_shr(a.val, imm)); \ +} \ +template \ +inline _Tpuvec v_shl(const _Tpuvec& a) \ +{ \ + return _Tpuvec(wasm_##suffix##_shl(a.val, imm)); \ +} \ +template \ +inline _Tpsvec v_shl(const _Tpsvec& a) \ +{ \ + return _Tpsvec(wasm_##suffix##_shl(a.val, imm)); \ +} \ +template \ +inline _Tpuvec v_shr(const _Tpuvec& a) \ +{ \ + return _Tpuvec(wasm_##ssuffix##_shr(a.val, imm)); \ +} \ +template \ +inline _Tpsvec v_shr(const _Tpsvec& a) \ +{ \ + return _Tpsvec(wasm_##suffix##_shr(a.val, imm)); \ +} + +OPENCV_HAL_IMPL_WASM_SHIFT_OP(v_uint8x16, v_int8x16, i8x16, u8x16) +OPENCV_HAL_IMPL_WASM_SHIFT_OP(v_uint16x8, v_int16x8, i16x8, u16x8) +OPENCV_HAL_IMPL_WASM_SHIFT_OP(v_uint32x4, v_int32x4, i32x4, u32x4) + +#ifdef __wasm_unimplemented_simd128__ +OPENCV_HAL_IMPL_WASM_SHIFT_OP(v_uint64x2, v_int64x2, i64x2, u64x2) +#else +#define OPENCV_HAL_IMPL_FALLBACK_SHIFT_OP(_Tpvec) \ +inline _Tpvec operator << (const _Tpvec& a, int imm) \ +{ \ + fallback::_Tpvec a_(a); \ + return a_ << imm; \ +} \ +inline _Tpvec operator >> (const _Tpvec& a, int imm) \ +{ \ + fallback::_Tpvec a_(a); \ + return a_ >> imm; \ +} \ +template \ +inline _Tpvec v_shl(const _Tpvec& a) \ +{ \ + fallback::_Tpvec a_(a); \ + return fallback::v_shl(a_); \ +} \ +template \ +inline _Tpvec v_shr(const _Tpvec& a) \ +{ \ + fallback::_Tpvec a_(a); \ + return fallback::v_shr(a_); \ +} \ + +OPENCV_HAL_IMPL_FALLBACK_SHIFT_OP(v_uint64x2) +OPENCV_HAL_IMPL_FALLBACK_SHIFT_OP(v_int64x2) +#endif + +namespace hal_wasm_internal +{ + template 16)), + bool is_first = (imm == 0), + bool is_second = (imm == 16), + bool is_other = (((imm > 0) && (imm < 16)))> + class v_wasm_palignr_u8_class; + + template + class v_wasm_palignr_u8_class; + + template + class v_wasm_palignr_u8_class + { + public: + inline v128_t operator()(const v128_t& a, const v128_t&) const + { + return a; + } + }; + + template + class v_wasm_palignr_u8_class + { + public: + inline v128_t operator()(const v128_t&, const v128_t& b) const + { + return b; + } + }; + + template + class v_wasm_palignr_u8_class + { + public: + inline v128_t operator()(const v128_t& a, const v128_t& b) const + { + enum { imm2 = (sizeof(v128_t) - imm) }; + return wasm_v8x16_shuffle(a, b, + imm, imm+1, imm+2, imm+3, + imm+4, imm+5, imm+6, imm+7, + imm+8, imm+9, imm+10, imm+11, + imm+12, imm+13, imm+14, imm+15); + } + }; + + template + inline v128_t v_wasm_palignr_u8(const v128_t& a, const v128_t& b) + { + CV_StaticAssert((imm >= 0) && (imm <= 16), "Invalid imm for v_wasm_palignr_u8."); + return v_wasm_palignr_u8_class()(a, b); + } +} + +template +inline _Tpvec v_rotate_right(const _Tpvec &a) +{ + using namespace hal_wasm_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + v128_t z = wasm_i8x16_splat(0); + return _Tpvec(v_wasm_palignr_u8(a.val, z)); +} + +template +inline _Tpvec v_rotate_left(const _Tpvec &a) +{ + using namespace hal_wasm_internal; + enum { imm2 = ((_Tpvec::nlanes - imm) * sizeof(typename _Tpvec::lane_type)) }; + v128_t z = wasm_i8x16_splat(0); + return _Tpvec(v_wasm_palignr_u8(z, a.val)); +} + +template +inline _Tpvec v_rotate_right(const _Tpvec &a, const _Tpvec &b) +{ + using namespace hal_wasm_internal; + enum { imm2 = (imm * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_wasm_palignr_u8(a.val, b.val)); +} + +template +inline _Tpvec v_rotate_left(const _Tpvec &a, const _Tpvec &b) +{ + using namespace hal_wasm_internal; + enum { imm2 = ((_Tpvec::nlanes - imm) * sizeof(typename _Tpvec::lane_type)) }; + return _Tpvec(v_wasm_palignr_u8(b.val, a.val)); +} + +#define OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(_Tpvec, _Tp) \ +inline _Tpvec v_load(const _Tp* ptr) \ +{ return _Tpvec(wasm_v128_load(ptr)); } \ +inline _Tpvec v_load_aligned(const _Tp* ptr) \ +{ return _Tpvec(wasm_v128_load(ptr)); } \ +inline _Tpvec v_load_low(const _Tp* ptr) \ +{ \ + _Tp tmp[_Tpvec::nlanes] = {0}; \ + for (int i=0; i<_Tpvec::nlanes/2; ++i) { \ + tmp[i] = ptr[i]; \ + } \ + return _Tpvec(wasm_v128_load(tmp)); \ +} \ +inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \ +{ \ + _Tp tmp[_Tpvec::nlanes]; \ + for (int i=0; i<_Tpvec::nlanes/2; ++i) { \ + tmp[i] = ptr0[i]; \ + tmp[i+_Tpvec::nlanes/2] = ptr1[i]; \ + } \ + return _Tpvec(wasm_v128_load(tmp)); \ +} \ +inline void v_store(_Tp* ptr, const _Tpvec& a) \ +{ wasm_v128_store(ptr, a.val); } \ +inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \ +{ wasm_v128_store(ptr, a.val); } \ +inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \ +{ wasm_v128_store(ptr, a.val); } \ +inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \ +{ \ + wasm_v128_store(ptr, a.val); \ +} \ +inline void v_store_low(_Tp* ptr, const _Tpvec& a) \ +{ \ + fallback::_Tpvec a_(a); \ + fallback::v_store_low(ptr, a_); \ +} \ +inline void v_store_high(_Tp* ptr, const _Tpvec& a) \ +{ \ + fallback::_Tpvec a_(a); \ + fallback::v_store_high(ptr, a_); \ +} + +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_uint8x16, uchar) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_int8x16, schar) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_uint16x8, ushort) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_int16x8, short) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_uint32x4, unsigned) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_int32x4, int) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_uint64x2, uint64) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_int64x2, int64) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_float32x4, float) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INT_OP(v_float64x2, double) + + +/** Reverse **/ +inline v_uint8x16 v_reverse(const v_uint8x16 &a) +{ return v_uint8x16(wasm_v8x16_shuffle(a.val, a.val, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)); } + +inline v_int8x16 v_reverse(const v_int8x16 &a) +{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); } + +inline v_uint16x8 v_reverse(const v_uint16x8 &a) +{ return v_uint16x8(wasm_v8x16_shuffle(a.val, a.val, 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1)); } + +inline v_int16x8 v_reverse(const v_int16x8 &a) +{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); } + +inline v_uint32x4 v_reverse(const v_uint32x4 &a) +{ return v_uint32x4(wasm_v8x16_shuffle(a.val, a.val, 12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3)); } + +inline v_int32x4 v_reverse(const v_int32x4 &a) +{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_float32x4 v_reverse(const v_float32x4 &a) +{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); } + +inline v_uint64x2 v_reverse(const v_uint64x2 &a) +{ return v_uint64x2(wasm_v8x16_shuffle(a.val, a.val, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7)); } + +inline v_int64x2 v_reverse(const v_int64x2 &a) +{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); } + +inline v_float64x2 v_reverse(const v_float64x2 &a) +{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); } + + +#define OPENCV_HAL_IMPL_WASM_REDUCE_OP_4_SUM(_Tpvec, scalartype, regtype, suffix, esuffix) \ +inline scalartype v_reduce_sum(const _Tpvec& a) \ +{ \ + regtype val = a.val; \ + val = wasm_##suffix##_add(val, wasm_v8x16_shuffle(val, val, 8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7)); \ + val = wasm_##suffix##_add(val, wasm_v8x16_shuffle(val, val, 4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3)); \ + return (scalartype)wasm_##esuffix##_extract_lane(val, 0); \ +} + +OPENCV_HAL_IMPL_WASM_REDUCE_OP_4_SUM(v_uint32x4, unsigned, v128_t, i32x4, i32x4) +OPENCV_HAL_IMPL_WASM_REDUCE_OP_4_SUM(v_int32x4, int, v128_t, i32x4, i32x4) +OPENCV_HAL_IMPL_WASM_REDUCE_OP_4_SUM(v_float32x4, float, v128_t, f32x4, f32x4) + +// To do: Optimize v_reduce_sum with wasm intrin. +// Now use fallback implementation as there is no widening op in wasm intrin. + +#define OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(_Tpvec, scalartype) \ +inline scalartype v_reduce_sum(const _Tpvec& a) \ +{ \ + fallback::_Tpvec a_(a); \ + return fallback::v_reduce_sum(a_); \ +} + +OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_uint8x16, unsigned) +OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_int8x16, int) +OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_uint16x8, unsigned) +OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_int16x8, int) +OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_uint64x2, uint64) +OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_int64x2, int64) +OPENCV_HAL_IMPL_FALLBACK_REDUCE_OP_SUM(v_float64x2, double) + +inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d) +{ + v128_t ac = wasm_f32x4_add(wasm_unpacklo_i32x4(a.val, c.val), wasm_unpackhi_i32x4(a.val, c.val)); + v128_t bd = wasm_f32x4_add(wasm_unpacklo_i32x4(b.val, d.val), wasm_unpackhi_i32x4(b.val, d.val)); + return v_float32x4(wasm_f32x4_add(wasm_unpacklo_i32x4(ac, bd), wasm_unpackhi_i32x4(ac, bd))); +} + +#define OPENCV_HAL_IMPL_WASM_REDUCE_OP(_Tpvec, scalartype, func, scalar_func) \ +inline scalartype v_reduce_##func(const _Tpvec& a) \ +{ \ + scalartype buf[_Tpvec::nlanes]; \ + v_store(buf, a); \ + scalartype tmp = buf[0]; \ + for (int i=1; i<_Tpvec::nlanes; ++i) { \ + tmp = scalar_func(tmp, buf[i]); \ + } \ + return tmp; \ +} + +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_uint8x16, uchar, max, std::max) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_uint8x16, uchar, min, std::min) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_int8x16, schar, max, std::max) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_int8x16, schar, min, std::min) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_uint16x8, ushort, max, std::max) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_uint16x8, ushort, min, std::min) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_int16x8, short, max, std::max) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_int16x8, short, min, std::min) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_uint32x4, unsigned, max, std::max) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_uint32x4, unsigned, min, std::min) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_int32x4, int, max, std::max) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_int32x4, int, min, std::min) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_float32x4, float, max, std::max) +OPENCV_HAL_IMPL_WASM_REDUCE_OP(v_float32x4, float, min, std::min) + +inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b) +{ + v_uint16x8 l16, h16; + v_uint32x4 l16_l32, l16_h32, h16_l32, h16_h32; + v_expand(v_absdiff(a, b), l16, h16); + v_expand(l16, l16_l32, l16_h32); + v_expand(h16, h16_l32, h16_h32); + return v_reduce_sum(l16_l32+l16_h32+h16_l32+h16_h32); +} +inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b) +{ + v_uint16x8 l16, h16; + v_uint32x4 l16_l32, l16_h32, h16_l32, h16_h32; + v_expand(v_absdiff(a, b), l16, h16); + v_expand(l16, l16_l32, l16_h32); + v_expand(h16, h16_l32, h16_h32); + return v_reduce_sum(l16_l32+l16_h32+h16_l32+h16_h32); +} +inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b) +{ + v_uint32x4 l, h; + v_expand(v_absdiff(a, b), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b) +{ + v_uint32x4 l, h; + v_expand(v_absdiff(a, b), l, h); + return v_reduce_sum(l + h); +} +inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} +inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} +inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b) +{ + return v_reduce_sum(v_absdiff(a, b)); +} + +inline v_uint8x16 v_popcount(const v_uint8x16& a) +{ + v128_t m1 = wasm_i32x4_splat(0x55555555); + v128_t m2 = wasm_i32x4_splat(0x33333333); + v128_t m4 = wasm_i32x4_splat(0x0f0f0f0f); + v128_t p = a.val; + p = wasm_i32x4_add(wasm_v128_and(wasm_u32x4_shr(p, 1), m1), wasm_v128_and(p, m1)); + p = wasm_i32x4_add(wasm_v128_and(wasm_u32x4_shr(p, 2), m2), wasm_v128_and(p, m2)); + p = wasm_i32x4_add(wasm_v128_and(wasm_u32x4_shr(p, 4), m4), wasm_v128_and(p, m4)); + return v_uint8x16(p); +} +inline v_uint16x8 v_popcount(const v_uint16x8& a) +{ + v_uint8x16 p = v_popcount(v_reinterpret_as_u8(a)); + p += v_rotate_right<1>(p); + return v_reinterpret_as_u16(p) & v_setall_u16(0x00ff); +} +inline v_uint32x4 v_popcount(const v_uint32x4& a) +{ + v_uint8x16 p = v_popcount(v_reinterpret_as_u8(a)); + p += v_rotate_right<1>(p); + p += v_rotate_right<2>(p); + return v_reinterpret_as_u32(p) & v_setall_u32(0x000000ff); +} +inline v_uint64x2 v_popcount(const v_uint64x2& a) +{ + fallback::v_uint64x2 a_(a); + return fallback::v_popcount(a_); +} +inline v_uint8x16 v_popcount(const v_int8x16& a) +{ return v_popcount(v_reinterpret_as_u8(a)); } +inline v_uint16x8 v_popcount(const v_int16x8& a) +{ return v_popcount(v_reinterpret_as_u16(a)); } +inline v_uint32x4 v_popcount(const v_int32x4& a) +{ return v_popcount(v_reinterpret_as_u32(a)); } +inline v_uint64x2 v_popcount(const v_int64x2& a) +{ return v_popcount(v_reinterpret_as_u64(a)); } + +#define OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(_Tpvec, suffix, scalarType) \ +inline int v_signmask(const _Tpvec& a) \ +{ \ + fallback::_Tpvec a_(a); \ + return fallback::v_signmask(a_); \ +} \ +inline bool v_check_all(const _Tpvec& a) \ +{ return wasm_i8x16_all_true(wasm_##suffix##_lt(a.val, wasm_##suffix##_splat(0))); } \ +inline bool v_check_any(const _Tpvec& a) \ +{ return wasm_i8x16_any_true(wasm_##suffix##_lt(a.val, wasm_##suffix##_splat(0)));; } + +OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(v_uint8x16, i8x16, schar) +OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(v_int8x16, i8x16, schar) +OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(v_uint16x8, i16x8, short) +OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(v_int16x8, i16x8, short) +OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(v_uint32x4, i32x4, int) +OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(v_int32x4, i32x4, int) +OPENCV_HAL_IMPL_WASM_CHECK_SIGNS(v_float32x4, i32x4, float) + +inline int v_signmask(const v_float64x2& a) +{ + fallback::v_float64x2 a_(a); + return fallback::v_signmask(a_); +} +inline bool v_check_all(const v_float64x2& a) +{ +#ifdef __wasm_unimplemented_simd128__ + return wasm_i8x16_all_true((__i64x2)(a.val) < (__i64x2)(wasm_i64x2_splat(0))); +#else + fallback::v_float64x2 a_(a); + return fallback::v_check_all(a_); +#endif +} +inline bool v_check_any(const v_float64x2& a) +{ +#ifdef __wasm_unimplemented_simd128__ + return wasm_i8x16_any_true((__i64x2)(a.val) < (__i64x2)(wasm_i64x2_splat(0)));; +#else + fallback::v_float64x2 a_(a); + return fallback::v_check_any(a_); +#endif +} + +inline int v_scan_forward(const v_int8x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); } +inline int v_scan_forward(const v_uint8x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); } +inline int v_scan_forward(const v_int16x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; } +inline int v_scan_forward(const v_uint16x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; } +inline int v_scan_forward(const v_int32x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_uint32x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_float32x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; } +inline int v_scan_forward(const v_int64x2& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } +inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } +inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; } + +#define OPENCV_HAL_IMPL_WASM_SELECT(_Tpvec) \ +inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(wasm_v128_bitselect(a.val, b.val, mask.val)); \ +} + +OPENCV_HAL_IMPL_WASM_SELECT(v_uint8x16) +OPENCV_HAL_IMPL_WASM_SELECT(v_int8x16) +OPENCV_HAL_IMPL_WASM_SELECT(v_uint16x8) +OPENCV_HAL_IMPL_WASM_SELECT(v_int16x8) +OPENCV_HAL_IMPL_WASM_SELECT(v_uint32x4) +OPENCV_HAL_IMPL_WASM_SELECT(v_int32x4) +// OPENCV_HAL_IMPL_WASM_SELECT(v_uint64x2) +// OPENCV_HAL_IMPL_WASM_SELECT(v_int64x2) +OPENCV_HAL_IMPL_WASM_SELECT(v_float32x4) +OPENCV_HAL_IMPL_WASM_SELECT(v_float64x2) + +#define OPENCV_HAL_IMPL_WASM_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \ +inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \ +{ \ + b0.val = intrin(a.val); \ + b1.val = __CV_CAT(intrin, _high)(a.val); \ +} \ +inline _Tpwvec v_expand_low(const _Tpvec& a) \ +{ return _Tpwvec(intrin(a.val)); } \ +inline _Tpwvec v_expand_high(const _Tpvec& a) \ +{ return _Tpwvec(__CV_CAT(intrin, _high)(a.val)); } \ +inline _Tpwvec v_load_expand(const _Tp* ptr) \ +{ \ + v128_t a = wasm_v128_load(ptr); \ + return _Tpwvec(intrin(a)); \ +} + +OPENCV_HAL_IMPL_WASM_EXPAND(v_uint8x16, v_uint16x8, uchar, v128_cvtu8x16_i16x8) +OPENCV_HAL_IMPL_WASM_EXPAND(v_int8x16, v_int16x8, schar, v128_cvti8x16_i16x8) +OPENCV_HAL_IMPL_WASM_EXPAND(v_uint16x8, v_uint32x4, ushort, v128_cvtu16x8_i32x4) +OPENCV_HAL_IMPL_WASM_EXPAND(v_int16x8, v_int32x4, short, v128_cvti16x8_i32x4) +OPENCV_HAL_IMPL_WASM_EXPAND(v_uint32x4, v_uint64x2, unsigned, v128_cvtu32x4_i64x2) +OPENCV_HAL_IMPL_WASM_EXPAND(v_int32x4, v_int64x2, int, v128_cvti32x4_i64x2) + +#define OPENCV_HAL_IMPL_WASM_EXPAND_Q(_Tpvec, _Tp, intrin) \ +inline _Tpvec v_load_expand_q(const _Tp* ptr) \ +{ \ + v128_t a = wasm_v128_load(ptr); \ + return _Tpvec(intrin(a)); \ +} + +OPENCV_HAL_IMPL_WASM_EXPAND_Q(v_uint32x4, uchar, v128_cvtu8x16_i32x4) +OPENCV_HAL_IMPL_WASM_EXPAND_Q(v_int32x4, schar, v128_cvti8x16_i32x4) + +#define OPENCV_HAL_IMPL_WASM_UNPACKS(_Tpvec, suffix) \ +inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) \ +{ \ + b0.val = wasm_unpacklo_##suffix(a0.val, a1.val); \ + b1.val = wasm_unpackhi_##suffix(a0.val, a1.val); \ +} \ +inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(wasm_unpacklo_i64x2(a.val, b.val)); \ +} \ +inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \ +{ \ + return _Tpvec(wasm_unpackhi_i64x2(a.val, b.val)); \ +} \ +inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) \ +{ \ + c.val = wasm_unpacklo_i64x2(a.val, b.val); \ + d.val = wasm_unpackhi_i64x2(a.val, b.val); \ +} + +OPENCV_HAL_IMPL_WASM_UNPACKS(v_uint8x16, i8x16) +OPENCV_HAL_IMPL_WASM_UNPACKS(v_int8x16, i8x16) +OPENCV_HAL_IMPL_WASM_UNPACKS(v_uint16x8, i16x8) +OPENCV_HAL_IMPL_WASM_UNPACKS(v_int16x8, i16x8) +OPENCV_HAL_IMPL_WASM_UNPACKS(v_uint32x4, i32x4) +OPENCV_HAL_IMPL_WASM_UNPACKS(v_int32x4, i32x4) +OPENCV_HAL_IMPL_WASM_UNPACKS(v_float32x4, i32x4) +OPENCV_HAL_IMPL_WASM_UNPACKS(v_float64x2, i64x2) + +template +inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) +{ + return v_rotate_right(a, b); +} + +inline v_int32x4 v_round(const v_float32x4& a) +{ + v128_t h = wasm_f32x4_splat(0.5); + return v_int32x4(wasm_i32x4_trunc_saturate_f32x4(wasm_f32x4_add(a.val, h))); +} + +inline v_int32x4 v_floor(const v_float32x4& a) +{ + v128_t a1 = wasm_i32x4_trunc_saturate_f32x4(a.val); + v128_t mask = wasm_f32x4_lt(a.val, wasm_f32x4_convert_i32x4(a1)); + return v_int32x4(wasm_i32x4_add(a1, mask)); +} + +inline v_int32x4 v_ceil(const v_float32x4& a) +{ + v128_t a1 = wasm_i32x4_trunc_saturate_f32x4(a.val); + v128_t mask = wasm_f32x4_gt(a.val, wasm_f32x4_convert_i32x4(a1)); + return v_int32x4(wasm_i32x4_sub(a1, mask)); +} + +inline v_int32x4 v_trunc(const v_float32x4& a) +{ return v_int32x4(wasm_i32x4_trunc_saturate_f32x4(a.val)); } + +#define OPENCV_HAL_IMPL_WASM_MATH_FUNC(func, cfunc, _Tpvec, _Tpnvec, _Tp, _Tpn) \ +inline _Tpnvec func(const _Tpvec& a) \ +{ \ + fallback::_Tpvec a_(a); \ + return fallback::func(a_); \ +} + +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_round, cvRound, v_float64x2, v_int32x4, double, int) +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_floor, cvFloor, v_float64x2, v_int32x4, double, int) +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_ceil, cvCeil, v_float64x2, v_int32x4, double, int) +OPENCV_HAL_IMPL_WASM_MATH_FUNC(v_trunc, int, v_float64x2, v_int32x4, double, int) + +inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) +{ + fallback::v_float64x2 a_(a), b_(b); + return fallback::v_round(a_, b_); +} + +#define OPENCV_HAL_IMPL_WASM_TRANSPOSE4x4(_Tpvec, suffix) \ +inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \ + const _Tpvec& a2, const _Tpvec& a3, \ + _Tpvec& b0, _Tpvec& b1, \ + _Tpvec& b2, _Tpvec& b3) \ +{ \ + v128_t t0 = wasm_unpacklo_##suffix(a0.val, a1.val); \ + v128_t t1 = wasm_unpacklo_##suffix(a2.val, a3.val); \ + v128_t t2 = wasm_unpackhi_##suffix(a0.val, a1.val); \ + v128_t t3 = wasm_unpackhi_##suffix(a2.val, a3.val); \ +\ + b0.val = wasm_unpacklo_i64x2(t0, t1); \ + b1.val = wasm_unpackhi_i64x2(t0, t1); \ + b2.val = wasm_unpacklo_i64x2(t2, t3); \ + b3.val = wasm_unpackhi_i64x2(t2, t3); \ +} + +OPENCV_HAL_IMPL_WASM_TRANSPOSE4x4(v_uint32x4, i32x4) +OPENCV_HAL_IMPL_WASM_TRANSPOSE4x4(v_int32x4, i32x4) +OPENCV_HAL_IMPL_WASM_TRANSPOSE4x4(v_float32x4, i32x4) + +// load deinterleave +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b) +{ + v128_t t00 = wasm_v128_load(ptr); + v128_t t01 = wasm_v128_load(ptr + 16); + + a.val = wasm_v8x16_shuffle(t00, t01, 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30); + b.val = wasm_v8x16_shuffle(t00, t01, 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31); +} + +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b, v_uint8x16& c) +{ + v128_t t00 = wasm_v128_load(ptr); + v128_t t01 = wasm_v128_load(ptr + 16); + v128_t t02 = wasm_v128_load(ptr + 32); + + v128_t t10 = wasm_v8x16_shuffle(t00, t01, 0,3,6,9,12,15,18,21,24,27,30,1,2,4,5,7); + v128_t t11 = wasm_v8x16_shuffle(t00, t01, 1,4,7,10,13,16,19,22,25,28,31,0,2,3,5,6); + v128_t t12 = wasm_v8x16_shuffle(t00, t01, 2,5,8,11,14,17,20,23,26,29,0,1,3,4,6,7); + + a.val = wasm_v8x16_shuffle(t10, t02, 0,1,2,3,4,5,6,7,8,9,10,17,20,23,26,29); + b.val = wasm_v8x16_shuffle(t11, t02, 0,1,2,3,4,5,6,7,8,9,10,18,21,24,27,30); + c.val = wasm_v8x16_shuffle(t12, t02, 0,1,2,3,4,5,6,7,8,9,16,19,22,25,28,31); +} + +inline void v_load_deinterleave(const uchar* ptr, v_uint8x16& a, v_uint8x16& b, v_uint8x16& c, v_uint8x16& d) +{ + v128_t u0 = wasm_v128_load(ptr); // a0 b0 c0 d0 a1 b1 c1 d1 ... + v128_t u1 = wasm_v128_load(ptr + 16); // a4 b4 c4 d4 ... + v128_t u2 = wasm_v128_load(ptr + 32); // a8 b8 c8 d8 ... + v128_t u3 = wasm_v128_load(ptr + 48); // a12 b12 c12 d12 ... + + v128_t v0 = wasm_v8x16_shuffle(u0, u1, 0,4,8,12,16,20,24,28,1,5,9,13,17,21,25,29); + v128_t v1 = wasm_v8x16_shuffle(u2, u3, 0,4,8,12,16,20,24,28,1,5,9,13,17,21,25,29); + v128_t v2 = wasm_v8x16_shuffle(u0, u1, 2,6,10,14,18,22,26,30,3,7,11,15,19,23,27,31); + v128_t v3 = wasm_v8x16_shuffle(u2, u3, 2,6,10,14,18,22,26,30,3,7,11,15,19,23,27,31); + + a.val = wasm_v8x16_shuffle(v0, v1, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23); + b.val = wasm_v8x16_shuffle(v0, v1, 8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31); + c.val = wasm_v8x16_shuffle(v2, v3, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23); + d.val = wasm_v8x16_shuffle(v2, v3, 8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31); +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b) +{ + v128_t v0 = wasm_v128_load(ptr); // a0 b0 a1 b1 a2 b2 a3 b3 + v128_t v1 = wasm_v128_load(ptr + 8); // a4 b4 a5 b5 a6 b6 a7 b7 + + a.val = wasm_v8x16_shuffle(v0, v1, 0,1,4,5,8,9,12,13,16,17,20,21,24,25,28,29); // a0 a1 a2 a3 a4 a5 a6 a7 + b.val = wasm_v8x16_shuffle(v0, v1, 2,3,6,7,10,11,14,15,18,19,22,23,26,27,30,31); // b0 b1 ab b3 b4 b5 b6 b7 +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b, v_uint16x8& c) +{ + v128_t t00 = wasm_v128_load(ptr); // a0 b0 c0 a1 b1 c1 a2 b2 + v128_t t01 = wasm_v128_load(ptr + 8); // c2 a3 b3 c3 a4 b4 c4 a5 + v128_t t02 = wasm_v128_load(ptr + 16); // b5 c5 a6 b6 c6 a7 b7 c7 + + v128_t t10 = wasm_v8x16_shuffle(t00, t01, 0,1,6,7,12,13,18,19,24,25,30,31,2,3,4,5); + v128_t t11 = wasm_v8x16_shuffle(t00, t01, 2,3,8,9,14,15,20,21,26,27,0,1,4,5,6,7); + v128_t t12 = wasm_v8x16_shuffle(t00, t01, 4,5,10,11,16,17,22,23,28,29,0,1,2,3,6,7); + + a.val = wasm_v8x16_shuffle(t10, t02, 0,1,2,3,4,5,6,7,8,9,10,11,20,21,26,27); + b.val = wasm_v8x16_shuffle(t11, t02, 0,1,2,3,4,5,6,7,8,9,16,17,22,23,28,29); + c.val = wasm_v8x16_shuffle(t12, t02, 0,1,2,3,4,5,6,7,8,9,18,19,24,25,30,31); +} + +inline void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b, v_uint16x8& c, v_uint16x8& d) +{ + v128_t u0 = wasm_v128_load(ptr); // a0 b0 c0 d0 a1 b1 c1 d1 + v128_t u1 = wasm_v128_load(ptr + 8); // a2 b2 c2 d2 ... + v128_t u2 = wasm_v128_load(ptr + 16); // a4 b4 c4 d4 ... + v128_t u3 = wasm_v128_load(ptr + 24); // a6 b6 c6 d6 ... + + v128_t v0 = wasm_v8x16_shuffle(u0, u1, 0,1,8,9,16,17,24,25,2,3,10,11,18,19,26,27); // a0 a1 a2 a3 b0 b1 b2 b3 + v128_t v1 = wasm_v8x16_shuffle(u2, u3, 0,1,8,9,16,17,24,25,2,3,10,11,18,19,26,27); // a4 a5 a6 a7 b4 b5 b6 b7 + v128_t v2 = wasm_v8x16_shuffle(u0, u1, 4,5,12,13,20,21,28,29,6,7,14,15,22,23,30,31); // c0 c1 c2 c3 d0 d1 d2 d3 + v128_t v3 = wasm_v8x16_shuffle(u2, u3, 4,5,12,13,20,21,28,29,6,7,14,15,22,23,30,31); // c4 c5 c6 c7 d4 d5 d6 d7 + + a.val = wasm_v8x16_shuffle(v0, v1, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23); + b.val = wasm_v8x16_shuffle(v0, v1, 8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31); + c.val = wasm_v8x16_shuffle(v2, v3, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23); + d.val = wasm_v8x16_shuffle(v2, v3, 8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31); +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b) +{ + v128_t v0 = wasm_v128_load(ptr); // a0 b0 a1 b1 + v128_t v1 = wasm_v128_load(ptr + 4); // a2 b2 a3 b3 + + a.val = wasm_v8x16_shuffle(v0, v1, 0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27); // a0 a1 a2 a3 + b.val = wasm_v8x16_shuffle(v0, v1, 4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31); // b0 b1 b2 b3 +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b, v_uint32x4& c) +{ + v128_t t00 = wasm_v128_load(ptr); // a0 b0 c0 a1 + v128_t t01 = wasm_v128_load(ptr + 4); // b2 c2 a3 b3 + v128_t t02 = wasm_v128_load(ptr + 8); // c3 a4 b4 c4 + + v128_t t10 = wasm_v8x16_shuffle(t00, t01, 0,1,2,3,12,13,14,15,24,25,26,27,4,5,6,7); + v128_t t11 = wasm_v8x16_shuffle(t00, t01, 4,5,6,7,16,17,18,19,28,29,30,31,0,1,2,3); + v128_t t12 = wasm_v8x16_shuffle(t00, t01, 8,9,10,11,20,21,22,23,0,1,2,3,4,5,6,7); + + a.val = wasm_v8x16_shuffle(t10, t02, 0,1,2,3,4,5,6,7,8,9,10,11,20,21,22,23); + b.val = wasm_v8x16_shuffle(t11, t02, 0,1,2,3,4,5,6,7,8,9,10,11,24,25,26,27); + c.val = wasm_v8x16_shuffle(t12, t02, 0,1,2,3,4,5,6,7,16,17,18,19,28,29,30,31); +} + +inline void v_load_deinterleave(const unsigned* ptr, v_uint32x4& a, v_uint32x4& b, v_uint32x4& c, v_uint32x4& d) +{ + v_uint32x4 s0(wasm_v128_load(ptr)); // a0 b0 c0 d0 + v_uint32x4 s1(wasm_v128_load(ptr + 4)); // a1 b1 c1 d1 + v_uint32x4 s2(wasm_v128_load(ptr + 8)); // a2 b2 c2 d2 + v_uint32x4 s3(wasm_v128_load(ptr + 12)); // a3 b3 c3 d3 + + v_transpose4x4(s0, s1, s2, s3, a, b, c, d); +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b) +{ + v128_t v0 = wasm_v128_load(ptr); // a0 b0 a1 b1 + v128_t v1 = wasm_v128_load((ptr + 4)); // a2 b2 a3 b3 + + a.val = wasm_v8x16_shuffle(v0, v1, 0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27); // a0 a1 a2 a3 + b.val = wasm_v8x16_shuffle(v0, v1, 4,5,6,7,12,13,14,15,20,21,22,23,28,29,30,31); // b0 b1 b2 b3 +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b, v_float32x4& c) +{ + v128_t t00 = wasm_v128_load(ptr); // a0 b0 c0 a1 + v128_t t01 = wasm_v128_load(ptr + 4); // b2 c2 a3 b3 + v128_t t02 = wasm_v128_load(ptr + 8); // c3 a4 b4 c4 + + v128_t t10 = wasm_v8x16_shuffle(t00, t01, 0,1,2,3,12,13,14,15,24,25,26,27,4,5,6,7); + v128_t t11 = wasm_v8x16_shuffle(t00, t01, 4,5,6,7,16,17,18,19,28,29,30,31,0,1,2,3); + v128_t t12 = wasm_v8x16_shuffle(t00, t01, 8,9,10,11,20,21,22,23,0,1,2,3,4,5,6,7); + + a.val = wasm_v8x16_shuffle(t10, t02, 0,1,2,3,4,5,6,7,8,9,10,11,20,21,22,23); + b.val = wasm_v8x16_shuffle(t11, t02, 0,1,2,3,4,5,6,7,8,9,10,11,24,25,26,27); + c.val = wasm_v8x16_shuffle(t12, t02, 0,1,2,3,4,5,6,7,16,17,18,19,28,29,30,31); +} + +inline void v_load_deinterleave(const float* ptr, v_float32x4& a, v_float32x4& b, v_float32x4& c, v_float32x4& d) +{ + v_float32x4 s0(wasm_v128_load(ptr)); // a0 b0 c0 d0 + v_float32x4 s1(wasm_v128_load(ptr + 4)); // a1 b1 c1 d1 + v_float32x4 s2(wasm_v128_load(ptr + 8)); // a2 b2 c2 d2 + v_float32x4 s3(wasm_v128_load(ptr + 12)); // a3 b3 c3 d3 + + v_transpose4x4(s0, s1, s2, s3, a, b, c, d); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, v_uint64x2& b) +{ + v128_t t0 = wasm_v128_load(ptr); // a0 b0 + v128_t t1 = wasm_v128_load(ptr + 2); // a1 b1 + + a.val = wasm_unpacklo_i64x2(t0, t1); + b.val = wasm_unpackhi_i64x2(t0, t1); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, v_uint64x2& b, v_uint64x2& c) +{ + v128_t t0 = wasm_v128_load(ptr); // a0, b0 + v128_t t1 = wasm_v128_load(ptr + 2); // c0, a1 + v128_t t2 = wasm_v128_load(ptr + 4); // b1, c1 + + a.val = wasm_v8x16_shuffle(t0, t1, 0,1,2,3,4,5,6,7,24,25,26,27,28,29,30,31); + b.val = wasm_v8x16_shuffle(t0, t2, 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23); + c.val = wasm_v8x16_shuffle(t1, t2, 0,1,2,3,4,5,6,7,24,25,26,27,28,29,30,31); +} + +inline void v_load_deinterleave(const uint64 *ptr, v_uint64x2& a, + v_uint64x2& b, v_uint64x2& c, v_uint64x2& d) +{ + v128_t t0 = wasm_v128_load(ptr); // a0 b0 + v128_t t1 = wasm_v128_load(ptr + 2); // c0 d0 + v128_t t2 = wasm_v128_load(ptr + 4); // a1 b1 + v128_t t3 = wasm_v128_load(ptr + 6); // c1 d1 + + a.val = wasm_unpacklo_i64x2(t0, t2); + b.val = wasm_unpackhi_i64x2(t0, t2); + c.val = wasm_unpacklo_i64x2(t1, t3); + d.val = wasm_unpackhi_i64x2(t1, t3); +} + +// store interleave + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t v0 = wasm_unpacklo_i8x16(a.val, b.val); + v128_t v1 = wasm_unpackhi_i8x16(a.val, b.val); + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 16, v1); +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + const v_uint8x16& c, hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t t00 = wasm_v8x16_shuffle(a.val, b.val, 0,16,0,1,17,0,2,18,0,3,19,0,4,20,0,5); + v128_t t01 = wasm_v8x16_shuffle(a.val, b.val, 21,0,6,22,0,7,23,0,8,24,0,9,25,0,10,26); + v128_t t02 = wasm_v8x16_shuffle(a.val, b.val, 0,11,27,0,12,28,0,13,29,0,14,30,0,15,31,0); + + v128_t t10 = wasm_v8x16_shuffle(t00, c.val, 0,1,16,3,4,17,6,7,18,9,10,19,12,13,20,15); + v128_t t11 = wasm_v8x16_shuffle(t01, c.val, 0,21,2,3,22,5,6,23,8,9,24,11,12,25,14,15); + v128_t t12 = wasm_v8x16_shuffle(t02, c.val, 26,1,2,27,4,5,28,7,8,29,10,11,30,13,14,31); + + wasm_v128_store(ptr, t10); + wasm_v128_store(ptr + 16, t11); + wasm_v128_store(ptr + 32, t12); +} + +inline void v_store_interleave( uchar* ptr, const v_uint8x16& a, const v_uint8x16& b, + const v_uint8x16& c, const v_uint8x16& d, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + // a0 a1 a2 a3 .... + // b0 b1 b2 b3 .... + // c0 c1 c2 c3 .... + // d0 d1 d2 d3 .... + v128_t u0 = wasm_unpacklo_i8x16(a.val, c.val); // a0 c0 a1 c1 ... + v128_t u1 = wasm_unpackhi_i8x16(a.val, c.val); // a8 c8 a9 c9 ... + v128_t u2 = wasm_unpacklo_i8x16(b.val, d.val); // b0 d0 b1 d1 ... + v128_t u3 = wasm_unpackhi_i8x16(b.val, d.val); // b8 d8 b9 d9 ... + + v128_t v0 = wasm_unpacklo_i8x16(u0, u2); // a0 b0 c0 d0 ... + v128_t v1 = wasm_unpackhi_i8x16(u0, u2); // a4 b4 c4 d4 ... + v128_t v2 = wasm_unpacklo_i8x16(u1, u3); // a8 b8 c8 d8 ... + v128_t v3 = wasm_unpackhi_i8x16(u1, u3); // a12 b12 c12 d12 ... + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 16, v1); + wasm_v128_store(ptr + 32, v2); + wasm_v128_store(ptr + 48, v3); +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, const v_uint16x8& b, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t v0 = wasm_unpacklo_i16x8(a.val, b.val); + v128_t v1 = wasm_unpackhi_i16x8(a.val, b.val); + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 8, v1); +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, + const v_uint16x8& b, const v_uint16x8& c, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t t00 = wasm_v8x16_shuffle(a.val, b.val, 0,1,16,17,0,0,2,3,18,19,0,0,4,5,20,21); + v128_t t01 = wasm_v8x16_shuffle(a.val, b.val, 0,0,6,7,22,23,0,0,8,9,24,25,0,0,10,11); + v128_t t02 = wasm_v8x16_shuffle(a.val, b.val, 26,27,0,0,12,13,28,29,0,0,14,15,30,31,0,0); + + v128_t t10 = wasm_v8x16_shuffle(t00, c.val, 0,1,2,3,16,17,6,7,8,9,18,19,12,13,14,15); + v128_t t11 = wasm_v8x16_shuffle(t01, c.val, 20,21,2,3,4,5,22,23,8,9,10,11,24,25,14,15); + v128_t t12 = wasm_v8x16_shuffle(t02, c.val, 0,1,26,27,4,5,6,7,28,29,10,11,12,13,30,31); + + wasm_v128_store(ptr, t10); + wasm_v128_store(ptr + 8, t11); + wasm_v128_store(ptr + 16, t12); +} + +inline void v_store_interleave( ushort* ptr, const v_uint16x8& a, const v_uint16x8& b, + const v_uint16x8& c, const v_uint16x8& d, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + // a0 a1 a2 a3 .... + // b0 b1 b2 b3 .... + // c0 c1 c2 c3 .... + // d0 d1 d2 d3 .... + v128_t u0 = wasm_unpacklo_i16x8(a.val, c.val); // a0 c0 a1 c1 ... + v128_t u1 = wasm_unpackhi_i16x8(a.val, c.val); // a4 c4 a5 c5 ... + v128_t u2 = wasm_unpacklo_i16x8(b.val, d.val); // b0 d0 b1 d1 ... + v128_t u3 = wasm_unpackhi_i16x8(b.val, d.val); // b4 d4 b5 d5 ... + + v128_t v0 = wasm_unpacklo_i16x8(u0, u2); // a0 b0 c0 d0 ... + v128_t v1 = wasm_unpackhi_i16x8(u0, u2); // a2 b2 c2 d2 ... + v128_t v2 = wasm_unpacklo_i16x8(u1, u3); // a4 b4 c4 d4 ... + v128_t v3 = wasm_unpackhi_i16x8(u1, u3); // a6 b6 c6 d6 ... + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 8, v1); + wasm_v128_store(ptr + 16, v2); + wasm_v128_store(ptr + 24, v3); +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t v0 = wasm_unpacklo_i32x4(a.val, b.val); + v128_t v1 = wasm_unpackhi_i32x4(a.val, b.val); + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 4, v1); +} + +inline void v_store_interleave( unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t t00 = wasm_v8x16_shuffle(a.val, b.val, 0,1,2,3,16,17,18,19,0,0,0,0,4,5,6,7); + v128_t t01 = wasm_v8x16_shuffle(a.val, b.val, 20,21,22,23,0,0,0,0,8,9,10,11,24,25,26,27); + v128_t t02 = wasm_v8x16_shuffle(a.val, b.val, 0,0,0,0,12,13,14,15,28,29,30,31,0,0,0,0); + + v128_t t10 = wasm_v8x16_shuffle(t00, c.val, 0,1,2,3,4,5,6,7,16,17,18,19,12,13,14,15); + v128_t t11 = wasm_v8x16_shuffle(t01, c.val, 0,1,2,3,20,21,22,23,8,9,10,11,12,13,14,15); + v128_t t12 = wasm_v8x16_shuffle(t02, c.val, 24,25,26,27,4,5,6,7,8,9,10,11,28,29,30,31); + + wasm_v128_store(ptr, t10); + wasm_v128_store(ptr + 4, t11); + wasm_v128_store(ptr + 8, t12); +} + +inline void v_store_interleave(unsigned* ptr, const v_uint32x4& a, const v_uint32x4& b, + const v_uint32x4& c, const v_uint32x4& d, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v_uint32x4 v0, v1, v2, v3; + v_transpose4x4(a, b, c, d, v0, v1, v2, v3); + + wasm_v128_store(ptr, v0.val); + wasm_v128_store(ptr + 4, v1.val); + wasm_v128_store(ptr + 8, v2.val); + wasm_v128_store(ptr + 12, v3.val); +} + +// 2-channel, float only +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t v0 = wasm_unpacklo_i32x4(a.val, b.val); + v128_t v1 = wasm_unpackhi_i32x4(a.val, b.val); + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 4, v1); +} + +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t t00 = wasm_v8x16_shuffle(a.val, b.val, 0,1,2,3,16,17,18,19,0,0,0,0,4,5,6,7); + v128_t t01 = wasm_v8x16_shuffle(a.val, b.val, 20,21,22,23,0,0,0,0,8,9,10,11,24,25,26,27); + v128_t t02 = wasm_v8x16_shuffle(a.val, b.val, 0,0,0,0,12,13,14,15,28,29,30,31,0,0,0,0); + + v128_t t10 = wasm_v8x16_shuffle(t00, c.val, 0,1,2,3,4,5,6,7,16,17,18,19,12,13,14,15); + v128_t t11 = wasm_v8x16_shuffle(t01, c.val, 0,1,2,3,20,21,22,23,8,9,10,11,12,13,14,15); + v128_t t12 = wasm_v8x16_shuffle(t02, c.val, 24,25,26,27,4,5,6,7,8,9,10,11,28,29,30,31); + + wasm_v128_store(ptr, t10); + wasm_v128_store(ptr + 4, t11); + wasm_v128_store(ptr + 8, t12); +} + +inline void v_store_interleave(float* ptr, const v_float32x4& a, const v_float32x4& b, + const v_float32x4& c, const v_float32x4& d, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v_float32x4 v0, v1, v2, v3; + v_transpose4x4(a, b, c, d, v0, v1, v2, v3); + + wasm_v128_store(ptr, v0.val); + wasm_v128_store(ptr + 4, v1.val); + wasm_v128_store(ptr + 8, v2.val); + wasm_v128_store(ptr + 12, v3.val); +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t v0 = wasm_unpacklo_i64x2(a.val, b.val); + v128_t v1 = wasm_unpackhi_i64x2(a.val, b.val); + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 2, v1); +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + const v_uint64x2& c, hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t v0 = wasm_v8x16_shuffle(a.val, b.val, 0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23); + v128_t v1 = wasm_v8x16_shuffle(a.val, c.val, 16,17,18,19,20,21,22,23,8,9,10,11,12,13,14,15); + v128_t v2 = wasm_v8x16_shuffle(b.val, c.val, 8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31); + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 2, v1); + wasm_v128_store(ptr + 4, v2); +} + +inline void v_store_interleave(uint64 *ptr, const v_uint64x2& a, const v_uint64x2& b, + const v_uint64x2& c, const v_uint64x2& d, + hal::StoreMode /*mode*/ = hal::STORE_UNALIGNED) +{ + v128_t v0 = wasm_unpacklo_i64x2(a.val, b.val); + v128_t v1 = wasm_unpacklo_i64x2(c.val, d.val); + v128_t v2 = wasm_unpackhi_i64x2(a.val, b.val); + v128_t v3 = wasm_unpackhi_i64x2(c.val, d.val); + + wasm_v128_store(ptr, v0); + wasm_v128_store(ptr + 2, v1); + wasm_v128_store(ptr + 4, v2); + wasm_v128_store(ptr + 6, v3); +} + +#define OPENCV_HAL_IMPL_WASM_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \ +{ \ + _Tpvec1 a1, b1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \ +{ \ + _Tpvec1 a1, b1, c1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ +} \ +inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \ +{ \ + _Tpvec1 a1, b1, c1, d1; \ + v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \ + a0 = v_reinterpret_as_##suffix0(a1); \ + b0 = v_reinterpret_as_##suffix0(b1); \ + c0 = v_reinterpret_as_##suffix0(c1); \ + d0 = v_reinterpret_as_##suffix0(d1); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \ +} \ +inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \ + const _Tpvec0& c0, const _Tpvec0& d0, \ + hal::StoreMode mode = hal::STORE_UNALIGNED ) \ +{ \ + _Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \ + _Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \ + _Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \ + _Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \ + v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \ +} + +OPENCV_HAL_IMPL_WASM_LOADSTORE_INTERLEAVE(v_int8x16, schar, s8, v_uint8x16, uchar, u8) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INTERLEAVE(v_int16x8, short, s16, v_uint16x8, ushort, u16) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INTERLEAVE(v_int32x4, int, s32, v_uint32x4, unsigned, u32) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INTERLEAVE(v_int64x2, int64, s64, v_uint64x2, uint64, u64) +OPENCV_HAL_IMPL_WASM_LOADSTORE_INTERLEAVE(v_float64x2, double, f64, v_uint64x2, uint64, u64) + +inline v_float32x4 v_cvt_f32(const v_int32x4& a) +{ + return v_float32x4(wasm_f32x4_convert_i32x4(a.val)); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a) +{ + fallback::v_float64x2 a_(a); + return fallback::v_cvt_f32(a_); +} + +inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b) +{ + fallback::v_float64x2 a_(a), b_(b); + return fallback::v_cvt_f32(a_, b_); +} + +inline v_float64x2 v_cvt_f64(const v_int32x4& a) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t p = v128_cvti32x4_i64x2(a.val); + return v_float64x2(wasm_f64x2_convert_i64x2(p)); +#else + fallback::v_int32x4 a_(a); + return fallback::v_cvt_f64(a_); +#endif +} + +inline v_float64x2 v_cvt_f64_high(const v_int32x4& a) +{ +#ifdef __wasm_unimplemented_simd128__ + v128_t p = v128_cvti32x4_i64x2_high(a.val); + return v_float64x2(wasm_f64x2_convert_i64x2(p)); +#else + fallback::v_int32x4 a_(a); + return fallback::v_cvt_f64_high(a_); +#endif +} + +inline v_float64x2 v_cvt_f64(const v_float32x4& a) +{ + fallback::v_float32x4 a_(a); + return fallback::v_cvt_f64(a_); +} + +inline v_float64x2 v_cvt_f64_high(const v_float32x4& a) +{ + fallback::v_float32x4 a_(a); + return fallback::v_cvt_f64_high(a_); +} + +inline v_float64x2 v_cvt_f64(const v_int64x2& a) +{ +#ifdef __wasm_unimplemented_simd128__ + return v_float64x2(wasm_f64x2_convert_i64x2(a.val)); +#else + fallback::v_int64x2 a_(a); + return fallback::v_cvt_f64(a_); +#endif +} + +////////////// Lookup table access //////////////////// + +inline v_int8x16 v_lut(const schar* tab, const int* idx) +{ + return v_int8x16(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]], + tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]]); +} +inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx) +{ + return v_int8x16(tab[idx[0]], tab[idx[0]+1], tab[idx[1]], tab[idx[1]+1], tab[idx[2]], tab[idx[2]+1], tab[idx[3]], tab[idx[3]+1], + tab[idx[4]], tab[idx[4]+1], tab[idx[5]], tab[idx[5]+1], tab[idx[6]], tab[idx[6]+1], tab[idx[7]], tab[idx[7]+1]); +} +inline v_int8x16 v_lut_quads(const schar* tab, const int* idx) +{ + return v_int8x16(tab[idx[0]], tab[idx[0]+1], tab[idx[0]+2], tab[idx[0]+3], tab[idx[1]], tab[idx[1]+1], tab[idx[1]+2], tab[idx[1]+3], + tab[idx[2]], tab[idx[2]+1], tab[idx[2]+2], tab[idx[2]+3], tab[idx[3]], tab[idx[3]+1], tab[idx[3]+2], tab[idx[3]+3]); +} +inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((const schar *)tab, idx)); } +inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((const schar *)tab, idx)); } +inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((const schar *)tab, idx)); } + +inline v_int16x8 v_lut(const short* tab, const int* idx) +{ + return v_int16x8(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]], + tab[idx[4]], tab[idx[5]], tab[idx[6]], tab[idx[7]]); +} +inline v_int16x8 v_lut_pairs(const short* tab, const int* idx) +{ + return v_int16x8(tab[idx[0]], tab[idx[0]+1], tab[idx[1]], tab[idx[1]+1], + tab[idx[2]], tab[idx[2]+1], tab[idx[3]], tab[idx[3]+1]); +} +inline v_int16x8 v_lut_quads(const short* tab, const int* idx) +{ + return v_int16x8(tab[idx[0]], tab[idx[0]+1], tab[idx[0]+2], tab[idx[0]+3], + tab[idx[1]], tab[idx[1]+1], tab[idx[1]+2], tab[idx[1]+3]); +} +inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((const short *)tab, idx)); } +inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((const short *)tab, idx)); } +inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((const short *)tab, idx)); } + +inline v_int32x4 v_lut(const int* tab, const int* idx) +{ + return v_int32x4(tab[idx[0]], tab[idx[1]], + tab[idx[2]], tab[idx[3]]); +} +inline v_int32x4 v_lut_pairs(const int* tab, const int* idx) +{ + return v_int32x4(tab[idx[0]], tab[idx[0]+1], + tab[idx[1]], tab[idx[1]+1]); +} +inline v_int32x4 v_lut_quads(const int* tab, const int* idx) +{ + return v_int32x4(wasm_v128_load(tab + idx[0])); +} +inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((const int *)tab, idx)); } +inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((const int *)tab, idx)); } +inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((const int *)tab, idx)); } + +inline v_int64x2 v_lut(const int64_t* tab, const int* idx) +{ + return v_int64x2(tab[idx[0]], tab[idx[1]]); +} +inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx) +{ + return v_int64x2(wasm_v128_load(tab + idx[0])); +} +inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); } +inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); } + +inline v_float32x4 v_lut(const float* tab, const int* idx) +{ + return v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]); +} +inline v_float32x4 v_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_pairs((const int *)tab, idx)); } +inline v_float32x4 v_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v_lut_quads((const int *)tab, idx)); } + +inline v_float64x2 v_lut(const double* tab, const int* idx) +{ + return v_float64x2(tab[idx[0]], tab[idx[1]]); +} +inline v_float64x2 v_lut_pairs(const double* tab, const int* idx) +{ + return v_float64x2(wasm_v128_load(tab + idx[0])); +} + +inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec) +{ + return v_int32x4(tab[wasm_i32x4_extract_lane(idxvec.val, 0)], + tab[wasm_i32x4_extract_lane(idxvec.val, 1)], + tab[wasm_i32x4_extract_lane(idxvec.val, 2)], + tab[wasm_i32x4_extract_lane(idxvec.val, 3)]); +} + +inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec) +{ + return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec)); +} + +inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec) +{ + return v_float32x4(tab[wasm_i32x4_extract_lane(idxvec.val, 0)], + tab[wasm_i32x4_extract_lane(idxvec.val, 1)], + tab[wasm_i32x4_extract_lane(idxvec.val, 2)], + tab[wasm_i32x4_extract_lane(idxvec.val, 3)]); +} + +inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec) +{ + return v_float64x2(tab[wasm_i32x4_extract_lane(idxvec.val, 0)], + tab[wasm_i32x4_extract_lane(idxvec.val, 1)]); +} + +// loads pairs from the table and deinterleaves them, e.g. returns: +// x = (tab[idxvec[0], tab[idxvec[1]], tab[idxvec[2]], tab[idxvec[3]]), +// y = (tab[idxvec[0]+1], tab[idxvec[1]+1], tab[idxvec[2]+1], tab[idxvec[3]+1]) +// note that the indices are float's indices, not the float-pair indices. +// in theory, this function can be used to implement bilinear interpolation, +// when idxvec are the offsets within the image. +inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y) +{ + x = v_float32x4(tab[wasm_i32x4_extract_lane(idxvec.val, 0)], + tab[wasm_i32x4_extract_lane(idxvec.val, 1)], + tab[wasm_i32x4_extract_lane(idxvec.val, 2)], + tab[wasm_i32x4_extract_lane(idxvec.val, 3)]); + y = v_float32x4(tab[wasm_i32x4_extract_lane(idxvec.val, 0)+1], + tab[wasm_i32x4_extract_lane(idxvec.val, 1)+1], + tab[wasm_i32x4_extract_lane(idxvec.val, 2)+1], + tab[wasm_i32x4_extract_lane(idxvec.val, 3)+1]); +} + +inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y) +{ + v128_t xy0 = wasm_v128_load(tab + wasm_i32x4_extract_lane(idxvec.val, 0)); + v128_t xy1 = wasm_v128_load(tab + wasm_i32x4_extract_lane(idxvec.val, 1)); + x.val = wasm_unpacklo_i64x2(xy0, xy1); + y.val = wasm_unpacklo_i64x2(xy0, xy1); +} + +inline v_int8x16 v_interleave_pairs(const v_int8x16& vec) +{ + return v_int8x16(wasm_v8x16_shuffle(vec.val, vec.val, 0,2,1,3,4,6,5,7,8,10,9,11,12,14,13,15)); +} +inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); } +inline v_int8x16 v_interleave_quads(const v_int8x16& vec) +{ + return v_int8x16(wasm_v8x16_shuffle(vec.val, vec.val, 0,4,1,5,2,6,3,7,8,12,9,13,10,14,11,15)); +} +inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_interleave_pairs(const v_int16x8& vec) +{ + return v_int16x8(wasm_v8x16_shuffle(vec.val, vec.val, 0,1,4,5,2,3,6,7,8,9,12,13,10,11,14,15)); +} +inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); } +inline v_int16x8 v_interleave_quads(const v_int16x8& vec) +{ + return v_int16x8(wasm_v8x16_shuffle(vec.val, vec.val, 0,1,8,9,2,3,10,11,4,5,12,13,6,7,14,15)); +} +inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_interleave_pairs(const v_int32x4& vec) +{ + return v_int32x4(wasm_v8x16_shuffle(vec.val, vec.val, 0,1,2,3,8,9,10,11,4,5,6,7,12,13,14,15)); +} +inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); } +inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) +{ + return v_float32x4(wasm_v8x16_shuffle(vec.val, vec.val, 0,1,2,3,8,9,10,11,4,5,6,7,12,13,14,15)); +} + +inline v_int8x16 v_pack_triplets(const v_int8x16& vec) +{ + return v_int8x16(wasm_v8x16_shuffle(vec.val, vec.val, 0,1,2,4,5,6,8,9,10,12,13,14,16,16,16,16)); +} +inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); } + +inline v_int16x8 v_pack_triplets(const v_int16x8& vec) +{ + return v_int16x8(wasm_v8x16_shuffle(vec.val, vec.val, 0,1,2,3,4,5,8,9,10,11,12,13,14,15,6,7)); +} +inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); } + +inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; } +inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; } +inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; } + +template +inline typename _Tp::lane_type v_extract_n(const _Tp& a) +{ + return v_rotate_right(a).get0(); +} + +template +inline v_uint32x4 v_broadcast_element(const v_uint32x4& a) +{ + return v_setall_u32(v_extract_n(a)); +} +template +inline v_int32x4 v_broadcast_element(const v_int32x4& a) +{ + return v_setall_s32(v_extract_n(a)); +} +template +inline v_float32x4 v_broadcast_element(const v_float32x4& a) +{ + return v_setall_f32(v_extract_n(a)); +} + + +////////////// FP16 support /////////////////////////// + +inline v_float32x4 v_load_expand(const float16_t* ptr) +{ + return fallback::v_load_expand(ptr); +} + +inline void v_pack_store(float16_t* ptr, const v_float32x4& v) +{ + fallback::v_float32x4 v_(v); + fallback::v_pack_store(ptr, v_); +} + +inline void v_cleanup() {} + +CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END + +//! @endcond + +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/msa_macros.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/msa_macros.h new file mode 100644 index 0000000000000000000000000000000000000000..3ed6e58d3c8b79ee98561fba55a31ff20a5b037b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/msa_macros.h @@ -0,0 +1,1558 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_HAL_MSA_MACROS_H +#define OPENCV_CORE_HAL_MSA_MACROS_H + +#ifdef __mips_msa +#include "msa.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Define 64 bits vector types */ +typedef signed char v8i8 __attribute__ ((vector_size(8), aligned(8))); +typedef unsigned char v8u8 __attribute__ ((vector_size(8), aligned(8))); +typedef short v4i16 __attribute__ ((vector_size(8), aligned(8))); +typedef unsigned short v4u16 __attribute__ ((vector_size(8), aligned(8))); +typedef int v2i32 __attribute__ ((vector_size(8), aligned(8))); +typedef unsigned int v2u32 __attribute__ ((vector_size(8), aligned(8))); +typedef long long v1i64 __attribute__ ((vector_size(8), aligned(8))); +typedef unsigned long long v1u64 __attribute__ ((vector_size(8), aligned(8))); +typedef float v2f32 __attribute__ ((vector_size(8), aligned(8))); +typedef double v1f64 __attribute__ ((vector_size(8), aligned(8))); + + +/* Load values from the given memory a 64-bit vector. */ +#define msa_ld1_s8(__a) (*((v8i8*)(__a))) +#define msa_ld1_s16(__a) (*((v4i16*)(__a))) +#define msa_ld1_s32(__a) (*((v2i32*)(__a))) +#define msa_ld1_s64(__a) (*((v1i64*)(__a))) +#define msa_ld1_u8(__a) (*((v8u8*)(__a))) +#define msa_ld1_u16(__a) (*((v4u16*)(__a))) +#define msa_ld1_u32(__a) (*((v2u32*)(__a))) +#define msa_ld1_u64(__a) (*((v1u64*)(__a))) +#define msa_ld1_f32(__a) (*((v2f32*)(__a))) +#define msa_ld1_f64(__a) (*((v1f64*)(__a))) + +/* Load values from the given memory address to a 128-bit vector */ +#define msa_ld1q_s8(__a) ((v16i8)__builtin_msa_ld_b(__a, 0)) +#define msa_ld1q_s16(__a) ((v8i16)__builtin_msa_ld_h(__a, 0)) +#define msa_ld1q_s32(__a) ((v4i32)__builtin_msa_ld_w(__a, 0)) +#define msa_ld1q_s64(__a) ((v2i64)__builtin_msa_ld_d(__a, 0)) +#define msa_ld1q_u8(__a) ((v16u8)__builtin_msa_ld_b(__a, 0)) +#define msa_ld1q_u16(__a) ((v8u16)__builtin_msa_ld_h(__a, 0)) +#define msa_ld1q_u32(__a) ((v4u32)__builtin_msa_ld_w(__a, 0)) +#define msa_ld1q_u64(__a) ((v2u64)__builtin_msa_ld_d(__a, 0)) +#define msa_ld1q_f32(__a) ((v4f32)__builtin_msa_ld_w(__a, 0)) +#define msa_ld1q_f64(__a) ((v2f64)__builtin_msa_ld_d(__a, 0)) + +/* Store 64bits vector elments values to the given memory address. */ +#define msa_st1_s8(__a, __b) (*((v8i8*)(__a)) = __b) +#define msa_st1_s16(__a, __b) (*((v4i16*)(__a)) = __b) +#define msa_st1_s32(__a, __b) (*((v2i32*)(__a)) = __b) +#define msa_st1_s64(__a, __b) (*((v1i64*)(__a)) = __b) +#define msa_st1_u8(__a, __b) (*((v8u8*)(__a)) = __b) +#define msa_st1_u16(__a, __b) (*((v4u16*)(__a)) = __b) +#define msa_st1_u32(__a, __b) (*((v2u32*)(__a)) = __b) +#define msa_st1_u64(__a, __b) (*((v1u64*)(__a)) = __b) +#define msa_st1_f32(__a, __b) (*((v2f32*)(__a)) = __b) +#define msa_st1_f64(__a, __b) (*((v1f64*)(__a)) = __b) + +/* Store the values of elements in the 128 bits vector __a to the given memory address __a. */ +#define msa_st1q_s8(__a, __b) (__builtin_msa_st_b((v16i8)(__b), __a, 0)) +#define msa_st1q_s16(__a, __b) (__builtin_msa_st_h((v8i16)(__b), __a, 0)) +#define msa_st1q_s32(__a, __b) (__builtin_msa_st_w((v4i32)(__b), __a, 0)) +#define msa_st1q_s64(__a, __b) (__builtin_msa_st_d((v2i64)(__b), __a, 0)) +#define msa_st1q_u8(__a, __b) (__builtin_msa_st_b((v16i8)(__b), __a, 0)) +#define msa_st1q_u16(__a, __b) (__builtin_msa_st_h((v8i16)(__b), __a, 0)) +#define msa_st1q_u32(__a, __b) (__builtin_msa_st_w((v4i32)(__b), __a, 0)) +#define msa_st1q_u64(__a, __b) (__builtin_msa_st_d((v2i64)(__b), __a, 0)) +#define msa_st1q_f32(__a, __b) (__builtin_msa_st_w((v4i32)(__b), __a, 0)) +#define msa_st1q_f64(__a, __b) (__builtin_msa_st_d((v2i64)(__b), __a, 0)) + +/* Store the value of the element with the index __c in vector __a to the given memory address __a. */ +#define msa_st1_lane_s8(__a, __b, __c) (*((int8_t*)(__a)) = __b[__c]) +#define msa_st1_lane_s16(__a, __b, __c) (*((int16_t*)(__a)) = __b[__c]) +#define msa_st1_lane_s32(__a, __b, __c) (*((int32_t*)(__a)) = __b[__c]) +#define msa_st1_lane_s64(__a, __b, __c) (*((int64_t*)(__a)) = __b[__c]) +#define msa_st1_lane_u8(__a, __b, __c) (*((uint8_t*)(__a)) = __b[__c]) +#define msa_st1_lane_u16(__a, __b, __c) (*((uint16_t*)(__a)) = __b[__c]) +#define msa_st1_lane_u32(__a, __b, __c) (*((uint32_t*)(__a)) = __b[__c]) +#define msa_st1_lane_u64(__a, __b, __c) (*((uint64_t*)(__a)) = __b[__c]) +#define msa_st1_lane_f32(__a, __b, __c) (*((float*)(__a)) = __b[__c]) +#define msa_st1_lane_f64(__a, __b, __c) (*((double*)(__a)) = __b[__c]) +#define msa_st1q_lane_s8(__a, __b, __c) (*((int8_t*)(__a)) = (int8_t)__builtin_msa_copy_s_b(__b, __c)) +#define msa_st1q_lane_s16(__a, __b, __c) (*((int16_t*)(__a)) = (int16_t)__builtin_msa_copy_s_h(__b, __c)) +#define msa_st1q_lane_s32(__a, __b, __c) (*((int32_t*)(__a)) = __builtin_msa_copy_s_w(__b, __c)) +#define msa_st1q_lane_s64(__a, __b, __c) (*((int64_t*)(__a)) = __builtin_msa_copy_s_d(__b, __c)) +#define msa_st1q_lane_u8(__a, __b, __c) (*((uint8_t*)(__a)) = (uint8_t)__builtin_msa_copy_u_b((v16i8)(__b), __c)) +#define msa_st1q_lane_u16(__a, __b, __c) (*((uint16_t*)(__a)) = (uint16_t)__builtin_msa_copy_u_h((v8i16)(__b), __c)) +#define msa_st1q_lane_u32(__a, __b, __c) (*((uint32_t*)(__a)) = __builtin_msa_copy_u_w((v4i32)(__b), __c)) +#define msa_st1q_lane_u64(__a, __b, __c) (*((uint64_t*)(__a)) = __builtin_msa_copy_u_d((v2i64)(__b), __c)) +#define msa_st1q_lane_f32(__a, __b, __c) (*((float*)(__a)) = __b[__c]) +#define msa_st1q_lane_f64(__a, __b, __c) (*((double*)(__a)) = __b[__c]) + +/* Duplicate elements for 64-bit doubleword vectors */ +#define msa_dup_n_s8(__a) ((v8i8)__builtin_msa_copy_s_d((v2i64)__builtin_msa_fill_b((int32_t)(__a)), 0)) +#define msa_dup_n_s16(__a) ((v4i16)__builtin_msa_copy_s_d((v2i64)__builtin_msa_fill_h((int32_t)(__a)), 0)) +#define msa_dup_n_s32(__a) ((v2i32){__a, __a}) +#define msa_dup_n_s64(__a) ((v1i64){__a}) +#define msa_dup_n_u8(__a) ((v8u8)__builtin_msa_copy_u_d((v2i64)__builtin_msa_fill_b((int32_t)(__a)), 0)) +#define msa_dup_n_u16(__a) ((v4u16)__builtin_msa_copy_u_d((v2i64)__builtin_msa_fill_h((int32_t)(__a)), 0)) +#define msa_dup_n_u32(__a) ((v2u32){__a, __a}) +#define msa_dup_n_u64(__a) ((v1u64){__a}) +#define msa_dup_n_f32(__a) ((v2f32){__a, __a}) +#define msa_dup_n_f64(__a) ((v1f64){__a}) + +/* Duplicate elements for 128-bit quadword vectors */ +#define msa_dupq_n_s8(__a) (__builtin_msa_fill_b((int32_t)(__a))) +#define msa_dupq_n_s16(__a) (__builtin_msa_fill_h((int32_t)(__a))) +#define msa_dupq_n_s32(__a) (__builtin_msa_fill_w((int32_t)(__a))) +#define msa_dupq_n_s64(__a) (__builtin_msa_fill_d((int64_t)(__a))) +#define msa_dupq_n_u8(__a) ((v16u8)__builtin_msa_fill_b((int32_t)(__a))) +#define msa_dupq_n_u16(__a) ((v8u16)__builtin_msa_fill_h((int32_t)(__a))) +#define msa_dupq_n_u32(__a) ((v4u32)__builtin_msa_fill_w((int32_t)(__a))) +#define msa_dupq_n_u64(__a) ((v2u64)__builtin_msa_fill_d((int64_t)(__a))) +#define msa_dupq_n_f32(__a) ((v4f32){__a, __a, __a, __a}) +#define msa_dupq_n_f64(__a) ((v2f64){__a, __a}) +#define msa_dupq_lane_s8(__a, __b) (__builtin_msa_splat_b(__a, __b)) +#define msa_dupq_lane_s16(__a, __b) (__builtin_msa_splat_h(__a, __b)) +#define msa_dupq_lane_s32(__a, __b) (__builtin_msa_splat_w(__a, __b)) +#define msa_dupq_lane_s64(__a, __b) (__builtin_msa_splat_d(__a, __b)) +#define msa_dupq_lane_u8(__a, __b) ((v16u8)__builtin_msa_splat_b((v16i8)(__a), __b)) +#define msa_dupq_lane_u16(__a, __b) ((v8u16)__builtin_msa_splat_h((v8i16)(__a), __b)) +#define msa_dupq_lane_u32(__a, __b) ((v4u32)__builtin_msa_splat_w((v4i32)(__a), __b)) +#define msa_dupq_lane_u64(__a, __b) ((v2u64)__builtin_msa_splat_d((v2i64)(__a), __b)) + +/* Create a 64 bits vector */ +#define msa_create_s8(__a) ((v8i8)((uint64_t)(__a))) +#define msa_create_s16(__a) ((v4i16)((uint64_t)(__a))) +#define msa_create_s32(__a) ((v2i32)((uint64_t)(__a))) +#define msa_create_s64(__a) ((v1i64)((uint64_t)(__a))) +#define msa_create_u8(__a) ((v8u8)((uint64_t)(__a))) +#define msa_create_u16(__a) ((v4u16)((uint64_t)(__a))) +#define msa_create_u32(__a) ((v2u32)((uint64_t)(__a))) +#define msa_create_u64(__a) ((v1u64)((uint64_t)(__a))) +#define msa_create_f32(__a) ((v2f32)((uint64_t)(__a))) +#define msa_create_f64(__a) ((v1f64)((uint64_t)(__a))) + +/* Sign extends or zero extends each element in a 64 bits vector to twice its original length, and places the results in a 128 bits vector. */ +/*Transform v8i8 to v8i16*/ +#define msa_movl_s8(__a) \ +((v8i16){(__a)[0], (__a)[1], (__a)[2], (__a)[3], \ + (__a)[4], (__a)[5], (__a)[6], (__a)[7]}) + +/*Transform v8u8 to v8u16*/ +#define msa_movl_u8(__a) \ +((v8u16){(__a)[0], (__a)[1], (__a)[2], (__a)[3], \ + (__a)[4], (__a)[5], (__a)[6], (__a)[7]}) + +/*Transform v4i16 to v8i16*/ +#define msa_movl_s16(__a) ((v4i32){(__a)[0], (__a)[1], (__a)[2], (__a)[3]}) + +/*Transform v2i32 to v4i32*/ +#define msa_movl_s32(__a) ((v2i64){(__a)[0], (__a)[1]}) + +/*Transform v4u16 to v8u16*/ +#define msa_movl_u16(__a) ((v4u32){(__a)[0], (__a)[1], (__a)[2], (__a)[3]}) + +/*Transform v2u32 to v4u32*/ +#define msa_movl_u32(__a) ((v2u64){(__a)[0], (__a)[1]}) + +/* Copies the least significant half of each element of a 128 bits vector into the corresponding elements of a 64 bits vector. */ +#define msa_movn_s16(__a) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)(__a)); \ + (v8i8)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_movn_s32(__a) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)(__a)); \ + (v4i16)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_movn_s64(__a) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)(__a)); \ + (v2i32)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_movn_u16(__a) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)(__a)); \ + (v8u8)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_movn_u32(__a) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)(__a)); \ + (v4u16)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_movn_u64(__a) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)(__a)); \ + (v2u32)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +/* qmovn */ +#define msa_qmovn_s16(__a) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_sat_s_h((v8i16)(__a), 7)); \ + (v8i8)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_qmovn_s32(__a) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_sat_s_w((v4i32)(__a), 15)); \ + (v4i16)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_qmovn_s64(__a) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_sat_s_d((v2i64)(__a), 31)); \ + (v2i32)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_qmovn_u16(__a) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_sat_u_h((v8u16)(__a), 7)); \ + (v8u8)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_qmovn_u32(__a) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_sat_u_w((v4u32)(__a), 15)); \ + (v4u16)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_qmovn_u64(__a) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_sat_u_d((v2u64)(__a), 31)); \ + (v2u32)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +/* qmovun */ +#define msa_qmovun_s16(__a) \ +({ \ + v8i16 __d = __builtin_msa_max_s_h(__builtin_msa_fill_h(0), (v8i16)(__a)); \ + v16i8 __e = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_sat_u_h((v8u16)__d, 7)); \ + (v8u8)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +#define msa_qmovun_s32(__a) \ +({ \ + v4i32 __d = __builtin_msa_max_s_w(__builtin_msa_fill_w(0), (v4i32)(__a)); \ + v8i16 __e = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_sat_u_w((v4u32)__d, 15)); \ + (v4u16)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +#define msa_qmovun_s64(__a) \ +({ \ + v2i64 __d = __builtin_msa_max_s_d(__builtin_msa_fill_d(0), (v2i64)(__a)); \ + v4i32 __e = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_sat_u_d((v2u64)__d, 31)); \ + (v2u32)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +/* Right shift elements in a 128 bits vector by an immediate value, and places the results in a 64 bits vector. */ +#define msa_shrn_n_s16(__a, __b) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_srai_h((v8i16)(__a), (int)(__b))); \ + (v8i8)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_shrn_n_s32(__a, __b) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_srai_w((v4i32)(__a), (int)(__b))); \ + (v4i16)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_shrn_n_s64(__a, __b) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_srai_d((v2i64)(__a), (int)(__b))); \ + (v2i32)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_shrn_n_u16(__a, __b) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_srli_h((v8i16)(__a), (int)(__b))); \ + (v8u8)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_shrn_n_u32(__a, __b) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_srli_w((v4i32)(__a), (int)(__b))); \ + (v4u16)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_shrn_n_u64(__a, __b) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_srli_d((v2i64)(__a), (int)(__b))); \ + (v2u32)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +/* Right shift elements in a 128 bits vector by an immediate value, and places the results in a 64 bits vector. */ +#define msa_rshrn_n_s16(__a, __b) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_srari_h((v8i16)(__a), (int)__b)); \ + (v8i8)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_rshrn_n_s32(__a, __b) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_srari_w((v4i32)(__a), (int)__b)); \ + (v4i16)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_rshrn_n_s64(__a, __b) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_srari_d((v2i64)(__a), (int)__b)); \ + (v2i32)__builtin_msa_copy_s_d((v2i64)__d, 0); \ +}) + +#define msa_rshrn_n_u16(__a, __b) \ +({ \ + v16i8 __d = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_srlri_h((v8i16)(__a), (int)__b)); \ + (v8u8)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_rshrn_n_u32(__a, __b) \ +({ \ + v8i16 __d = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_srlri_w((v4i32)(__a), (int)__b)); \ + (v4u16)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +#define msa_rshrn_n_u64(__a, __b) \ +({ \ + v4i32 __d = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_srlri_d((v2i64)(__a), (int)__b)); \ + (v2u32)__builtin_msa_copy_u_d((v2i64)__d, 0); \ +}) + +/* Right shift elements in a 128 bits vector by an immediate value, saturate the results and them in a 64 bits vector. */ +#define msa_qrshrn_n_s16(__a, __b) \ +({ \ + v8i16 __d = __builtin_msa_sat_s_h(__builtin_msa_srari_h((v8i16)(__a), (int)(__b)), 7); \ + v16i8 __e = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__d); \ + (v8i8)__builtin_msa_copy_s_d((v2i64)__e, 0); \ +}) + +#define msa_qrshrn_n_s32(__a, __b) \ +({ \ + v4i32 __d = __builtin_msa_sat_s_w(__builtin_msa_srari_w((v4i32)(__a), (int)(__b)), 15); \ + v8i16 __e = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__d); \ + (v4i16)__builtin_msa_copy_s_d((v2i64)__e, 0); \ +}) + +#define msa_qrshrn_n_s64(__a, __b) \ +({ \ + v2i64 __d = __builtin_msa_sat_s_d(__builtin_msa_srari_d((v2i64)(__a), (int)(__b)), 31); \ + v4i32 __e = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__d); \ + (v2i32)__builtin_msa_copy_s_d((v2i64)__e, 0); \ +}) + +#define msa_qrshrn_n_u16(__a, __b) \ +({ \ + v8u16 __d = __builtin_msa_sat_u_h((v8u16)__builtin_msa_srlri_h((v8i16)(__a), (int)(__b)), 7); \ + v16i8 __e = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__d); \ + (v8u8)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +#define msa_qrshrn_n_u32(__a, __b) \ +({ \ + v4u32 __d = __builtin_msa_sat_u_w((v4u32)__builtin_msa_srlri_w((v4i32)(__a), (int)(__b)), 15); \ + v8i16 __e = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__d); \ + (v4u16)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +#define msa_qrshrn_n_u64(__a, __b) \ +({ \ + v2u64 __d = __builtin_msa_sat_u_d((v2u64)__builtin_msa_srlri_d((v2i64)(__a), (int)(__b)), 31); \ + v4i32 __e = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__d); \ + (v2u32)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +/* Right shift elements in a 128 bits vector by an immediate value, saturate the results and them in a 64 bits vector. + Input is signed and outpus is unsigned. */ +#define msa_qrshrun_n_s16(__a, __b) \ +({ \ + v8i16 __d = __builtin_msa_srlri_h(__builtin_msa_max_s_h(__builtin_msa_fill_h(0), (v8i16)(__a)), (int)(__b)); \ + v16i8 __e = __builtin_msa_pckev_b(__builtin_msa_fill_b(0), (v16i8)__builtin_msa_sat_u_h((v8u16)__d, 7)); \ + (v8u8)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +#define msa_qrshrun_n_s32(__a, __b) \ +({ \ + v4i32 __d = __builtin_msa_srlri_w(__builtin_msa_max_s_w(__builtin_msa_fill_w(0), (v4i32)(__a)), (int)(__b)); \ + v8i16 __e = __builtin_msa_pckev_h(__builtin_msa_fill_h(0), (v8i16)__builtin_msa_sat_u_w((v4u32)__d, 15)); \ + (v4u16)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +#define msa_qrshrun_n_s64(__a, __b) \ +({ \ + v2i64 __d = __builtin_msa_srlri_d(__builtin_msa_max_s_d(__builtin_msa_fill_d(0), (v2i64)(__a)), (int)(__b)); \ + v4i32 __e = __builtin_msa_pckev_w(__builtin_msa_fill_w(0), (v4i32)__builtin_msa_sat_u_d((v2u64)__d, 31)); \ + (v2u32)__builtin_msa_copy_u_d((v2i64)__e, 0); \ +}) + +/* pack */ +#define msa_pack_s16(__a, __b) (__builtin_msa_pckev_b((v16i8)(__b), (v16i8)(__a))) +#define msa_pack_s32(__a, __b) (__builtin_msa_pckev_h((v8i16)(__b), (v8i16)(__a))) +#define msa_pack_s64(__a, __b) (__builtin_msa_pckev_w((v4i32)(__b), (v4i32)(__a))) +#define msa_pack_u16(__a, __b) ((v16u8)__builtin_msa_pckev_b((v16i8)(__b), (v16i8)(__a))) +#define msa_pack_u32(__a, __b) ((v8u16)__builtin_msa_pckev_h((v8i16)(__b), (v8i16)(__a))) +#define msa_pack_u64(__a, __b) ((v4u32)__builtin_msa_pckev_w((v4i32)(__b), (v4i32)(__a))) + +/* qpack */ +#define msa_qpack_s16(__a, __b) \ +(__builtin_msa_pckev_b((v16i8)__builtin_msa_sat_s_h((v8i16)(__b), 7), (v16i8)__builtin_msa_sat_s_h((v8i16)(__a), 7))) +#define msa_qpack_s32(__a, __b) \ +(__builtin_msa_pckev_h((v8i16)__builtin_msa_sat_s_w((v4i32)(__b), 15), (v8i16)__builtin_msa_sat_s_w((v4i32)(__a), 15))) +#define msa_qpack_s64(__a, __b) \ +(__builtin_msa_pckev_w((v4i32)__builtin_msa_sat_s_d((v2i64)(__b), 31), (v4i32)__builtin_msa_sat_s_d((v2i64)(__a), 31))) +#define msa_qpack_u16(__a, __b) \ +((v16u8)__builtin_msa_pckev_b((v16i8)__builtin_msa_sat_u_h((v8u16)(__b), 7), (v16i8)__builtin_msa_sat_u_h((v8u16)(__a), 7))) +#define msa_qpack_u32(__a, __b) \ +((v8u16)__builtin_msa_pckev_h((v8i16)__builtin_msa_sat_u_w((v4u32)(__b), 15), (v8i16)__builtin_msa_sat_u_w((v4u32)(__a), 15))) +#define msa_qpack_u64(__a, __b) \ +((v4u32)__builtin_msa_pckev_w((v4i32)__builtin_msa_sat_u_d((v2u64)(__b), 31), (v4i32)__builtin_msa_sat_u_d((v2u64)(__a), 31))) + +/* qpacku */ +#define msa_qpacku_s16(__a, __b) \ +((v16u8)__builtin_msa_pckev_b((v16i8)__builtin_msa_sat_u_h((v8u16)(__builtin_msa_max_s_h(__builtin_msa_fill_h(0), (v8i16)(__b))), 7), \ + (v16i8)__builtin_msa_sat_u_h((v8u16)(__builtin_msa_max_s_h(__builtin_msa_fill_h(0), (v8i16)(__a))), 7))) +#define msa_qpacku_s32(__a, __b) \ +((v8u16)__builtin_msa_pckev_h((v8i16)__builtin_msa_sat_u_w((v4u32)(__builtin_msa_max_s_w(__builtin_msa_fill_w(0), (v4i32)(__b))), 15), \ + (v8i16)__builtin_msa_sat_u_w((v4u32)(__builtin_msa_max_s_w(__builtin_msa_fill_w(0), (v4i32)(__a))), 15))) +#define msa_qpacku_s64(__a, __b) \ +((v4u32)__builtin_msa_pckev_w((v4i32)__builtin_msa_sat_u_d((v2u64)(__builtin_msa_max_s_d(__builtin_msa_fill_d(0), (v2i64)(__b))), 31), \ + (v4i32)__builtin_msa_sat_u_d((v2u64)(__builtin_msa_max_s_d(__builtin_msa_fill_d(0), (v2i64)(__a))), 31))) + +/* packr */ +#define msa_packr_s16(__a, __b, __c) \ +(__builtin_msa_pckev_b((v16i8)__builtin_msa_srai_h((v8i16)(__b), (int)(__c)), (v16i8)__builtin_msa_srai_h((v8i16)(__a), (int)(__c)))) +#define msa_packr_s32(__a, __b, __c) \ +(__builtin_msa_pckev_h((v8i16)__builtin_msa_srai_w((v4i32)(__b), (int)(__c)), (v8i16)__builtin_msa_srai_w((v4i32)(__a), (int)(__c)))) +#define msa_packr_s64(__a, __b, __c) \ +(__builtin_msa_pckev_w((v4i32)__builtin_msa_srai_d((v2i64)(__b), (int)(__c)), (v4i32)__builtin_msa_srai_d((v2i64)(__a), (int)(__c)))) +#define msa_packr_u16(__a, __b, __c) \ +((v16u8)__builtin_msa_pckev_b((v16i8)__builtin_msa_srli_h((v8i16)(__b), (int)(__c)), (v16i8)__builtin_msa_srli_h((v8i16)(__a), (int)(__c)))) +#define msa_packr_u32(__a, __b, __c) \ +((v8u16)__builtin_msa_pckev_h((v8i16)__builtin_msa_srli_w((v4i32)(__b), (int)(__c)), (v8i16)__builtin_msa_srli_w((v4i32)(__a), (int)(__c)))) +#define msa_packr_u64(__a, __b, __c) \ +((v4u32)__builtin_msa_pckev_w((v4i32)__builtin_msa_srli_d((v2i64)(__b), (int)(__c)), (v4i32)__builtin_msa_srli_d((v2i64)(__a), (int)(__c)))) + +/* rpackr */ +#define msa_rpackr_s16(__a, __b, __c) \ +(__builtin_msa_pckev_b((v16i8)__builtin_msa_srari_h((v8i16)(__b), (int)(__c)), (v16i8)__builtin_msa_srari_h((v8i16)(__a), (int)(__c)))) +#define msa_rpackr_s32(__a, __b, __c) \ +(__builtin_msa_pckev_h((v8i16)__builtin_msa_srari_w((v4i32)(__b), (int)(__c)), (v8i16)__builtin_msa_srari_w((v4i32)(__a), (int)(__c)))) +#define msa_rpackr_s64(__a, __b, __c) \ +(__builtin_msa_pckev_w((v4i32)__builtin_msa_srari_d((v2i64)(__b), (int)(__c)), (v4i32)__builtin_msa_srari_d((v2i64)(__a), (int)(__c)))) +#define msa_rpackr_u16(__a, __b, __c) \ +((v16u8)__builtin_msa_pckev_b((v16i8)__builtin_msa_srlri_h((v8i16)(__b), (int)(__c)), (v16i8)__builtin_msa_srlri_h((v8i16)(__a), (int)(__c)))) +#define msa_rpackr_u32(__a, __b, __c) \ +((v8u16)__builtin_msa_pckev_h((v8i16)__builtin_msa_srlri_w((v4i32)(__b), (int)(__c)), (v8i16)__builtin_msa_srlri_w((v4i32)(__a), (int)(__c)))) +#define msa_rpackr_u64(__a, __b, __c) \ +((v4u32)__builtin_msa_pckev_w((v4i32)__builtin_msa_srlri_d((v2i64)(__b), (int)(__c)), (v4i32)__builtin_msa_srlri_d((v2i64)(__a), (int)(__c)))) + +/* qrpackr */ +#define msa_qrpackr_s16(__a, __b, __c) \ +(__builtin_msa_pckev_b((v16i8)__builtin_msa_sat_s_h(__builtin_msa_srari_h((v8i16)(__b), (int)(__c)), 7), \ + (v16i8)__builtin_msa_sat_s_h(__builtin_msa_srari_h((v8i16)(__a), (int)(__c)), 7))) +#define msa_qrpackr_s32(__a, __b, __c) \ +(__builtin_msa_pckev_h((v8i16)__builtin_msa_sat_s_w(__builtin_msa_srari_w((v4i32)(__b), (int)(__c)), 15), \ + (v8i16)__builtin_msa_sat_s_w(__builtin_msa_srari_w((v4i32)(__a), (int)(__c)), 15))) +#define msa_qrpackr_s64(__a, __b, __c) \ +(__builtin_msa_pckev_w((v4i32)__builtin_msa_sat_s_d(__builtin_msa_srari_d((v2i64)(__b), (int)(__c)), 31), \ + (v4i32)__builtin_msa_sat_s_d(__builtin_msa_srari_d((v2i64)(__a), (int)(__c)), 31))) +#define msa_qrpackr_u16(__a, __b, __c) \ +((v16u8)__builtin_msa_pckev_b((v16i8)__builtin_msa_sat_u_h((v8u16)__builtin_msa_srlri_h((v8i16)(__b), (int)(__c)), 7), \ + (v16i8)__builtin_msa_sat_u_h((v8u16)__builtin_msa_srlri_h((v8i16)(__a), (int)(__c)), 7))) +#define msa_qrpackr_u32(__a, __b, __c) \ +((v8u16)__builtin_msa_pckev_h((v8i16)__builtin_msa_sat_u_w((v4u32)__builtin_msa_srlri_w((v4i32)(__b), (int)(__c)), 15), \ + (v8i16)__builtin_msa_sat_u_w((v4u32)__builtin_msa_srlri_w((v4i32)(__a), (int)(__c)), 15))) +#define msa_qrpackr_u64(__a, __b, __c) \ +((v4u32)__builtin_msa_pckev_w((v4i32)__builtin_msa_sat_u_d((v2u64)__builtin_msa_srlri_d((v2i64)(__b), (int)(__c)), 31), \ + (v4i32)__builtin_msa_sat_u_d((v2u64)__builtin_msa_srlri_d((v2i64)(__a), (int)(__c)), 31))) + +/* qrpackru */ +#define msa_qrpackru_s16(__a, __b, __c) \ +({ \ + v8i16 __d = __builtin_msa_srlri_h(__builtin_msa_max_s_h(__builtin_msa_fill_h(0), (v8i16)(__a)), (int)(__c)); \ + v8i16 __e = __builtin_msa_srlri_h(__builtin_msa_max_s_h(__builtin_msa_fill_h(0), (v8i16)(__b)), (int)(__c)); \ + (v16u8)__builtin_msa_pckev_b((v16i8)__builtin_msa_sat_u_h((v8u16)__e, 7), (v16i8)__builtin_msa_sat_u_h((v8u16)__d, 7)); \ +}) + +#define msa_qrpackru_s32(__a, __b, __c) \ +({ \ + v4i32 __d = __builtin_msa_srlri_w(__builtin_msa_max_s_w(__builtin_msa_fill_w(0), (v4i32)(__a)), (int)(__c)); \ + v4i32 __e = __builtin_msa_srlri_w(__builtin_msa_max_s_w(__builtin_msa_fill_w(0), (v4i32)(__b)), (int)(__c)); \ + (v8u16)__builtin_msa_pckev_h((v8i16)__builtin_msa_sat_u_w((v4u32)__e, 15), (v8i16)__builtin_msa_sat_u_w((v4u32)__d, 15)); \ +}) + +#define msa_qrpackru_s64(__a, __b, __c) \ +({ \ + v2i64 __d = __builtin_msa_srlri_d(__builtin_msa_max_s_d(__builtin_msa_fill_d(0), (v2i64)(__a)), (int)(__c)); \ + v2i64 __e = __builtin_msa_srlri_d(__builtin_msa_max_s_d(__builtin_msa_fill_d(0), (v2i64)(__b)), (int)(__c)); \ + (v4u32)__builtin_msa_pckev_w((v4i32)__builtin_msa_sat_u_d((v2u64)__e, 31), (v4i32)__builtin_msa_sat_u_d((v2u64)__d, 31)); \ +}) + +/* Minimum values between corresponding elements in the two vectors are written to the returned vector. */ +#define msa_minq_s8(__a, __b) (__builtin_msa_min_s_b(__a, __b)) +#define msa_minq_s16(__a, __b) (__builtin_msa_min_s_h(__a, __b)) +#define msa_minq_s32(__a, __b) (__builtin_msa_min_s_w(__a, __b)) +#define msa_minq_s64(__a, __b) (__builtin_msa_min_s_d(__a, __b)) +#define msa_minq_u8(__a, __b) ((v16u8)__builtin_msa_min_u_b(__a, __b)) +#define msa_minq_u16(__a, __b) ((v8u16)__builtin_msa_min_u_h(__a, __b)) +#define msa_minq_u32(__a, __b) ((v4u32)__builtin_msa_min_u_w(__a, __b)) +#define msa_minq_u64(__a, __b) ((v2u64)__builtin_msa_min_u_d(__a, __b)) +#define msa_minq_f32(__a, __b) (__builtin_msa_fmin_w(__a, __b)) +#define msa_minq_f64(__a, __b) (__builtin_msa_fmin_d(__a, __b)) + +/* Maximum values between corresponding elements in the two vectors are written to the returned vector. */ +#define msa_maxq_s8(__a, __b) (__builtin_msa_max_s_b(__a, __b)) +#define msa_maxq_s16(__a, __b) (__builtin_msa_max_s_h(__a, __b)) +#define msa_maxq_s32(__a, __b) (__builtin_msa_max_s_w(__a, __b)) +#define msa_maxq_s64(__a, __b) (__builtin_msa_max_s_d(__a, __b)) +#define msa_maxq_u8(__a, __b) ((v16u8)__builtin_msa_max_u_b(__a, __b)) +#define msa_maxq_u16(__a, __b) ((v8u16)__builtin_msa_max_u_h(__a, __b)) +#define msa_maxq_u32(__a, __b) ((v4u32)__builtin_msa_max_u_w(__a, __b)) +#define msa_maxq_u64(__a, __b) ((v2u64)__builtin_msa_max_u_d(__a, __b)) +#define msa_maxq_f32(__a, __b) (__builtin_msa_fmax_w(__a, __b)) +#define msa_maxq_f64(__a, __b) (__builtin_msa_fmax_d(__a, __b)) + +/* Vector type reinterpretion */ +#define MSA_TPV_REINTERPRET(_Tpv, Vec) ((_Tpv)(Vec)) + +/* Add the odd elements in vector __a with the even elements in vector __b to double width elements in the returned vector. */ +/* v8i16 msa_hadd_s16 ((v16i8)__a, (v16i8)__b) */ +#define msa_hadd_s16(__a, __b) (__builtin_msa_hadd_s_h((v16i8)(__a), (v16i8)(__b))) +/* v4i32 msa_hadd_s32 ((v8i16)__a, (v8i16)__b) */ +#define msa_hadd_s32(__a, __b) (__builtin_msa_hadd_s_w((v8i16)(__a), (v8i16)(__b))) +/* v2i64 msa_hadd_s64 ((v4i32)__a, (v4i32)__b) */ +#define msa_hadd_s64(__a, __b) (__builtin_msa_hadd_s_d((v4i32)(__a), (v4i32)(__b))) + +/* Copy even elements in __a to the left half and even elements in __b to the right half and return the result vector. */ +#define msa_pckev_s8(__a, __b) (__builtin_msa_pckev_b((v16i8)(__a), (v16i8)(__b))) +#define msa_pckev_s16(__a, __b) (__builtin_msa_pckev_h((v8i16)(__a), (v8i16)(__b))) +#define msa_pckev_s32(__a, __b) (__builtin_msa_pckev_w((v4i32)(__a), (v4i32)(__b))) +#define msa_pckev_s64(__a, __b) (__builtin_msa_pckev_d((v2i64)(__a), (v2i64)(__b))) + +/* Copy even elements in __a to the left half and even elements in __b to the right half and return the result vector. */ +#define msa_pckod_s8(__a, __b) (__builtin_msa_pckod_b((v16i8)(__a), (v16i8)(__b))) +#define msa_pckod_s16(__a, __b) (__builtin_msa_pckod_h((v8i16)(__a), (v8i16)(__b))) +#define msa_pckod_s32(__a, __b) (__builtin_msa_pckod_w((v4i32)(__a), (v4i32)(__b))) +#define msa_pckod_s64(__a, __b) (__builtin_msa_pckod_d((v2i64)(__a), (v2i64)(__b))) + +#ifdef _MIPSEB +#define LANE_IMM0_1(x) (0b1 - ((x) & 0b1)) +#define LANE_IMM0_3(x) (0b11 - ((x) & 0b11)) +#define LANE_IMM0_7(x) (0b111 - ((x) & 0b111)) +#define LANE_IMM0_15(x) (0b1111 - ((x) & 0b1111)) +#else +#define LANE_IMM0_1(x) ((x) & 0b1) +#define LANE_IMM0_3(x) ((x) & 0b11) +#define LANE_IMM0_7(x) ((x) & 0b111) +#define LANE_IMM0_15(x) ((x) & 0b1111) +#endif + +#define msa_get_lane_u8(__a, __b) ((uint8_t)(__a)[LANE_IMM0_7(__b)]) +#define msa_get_lane_s8(__a, __b) ((int8_t)(__a)[LANE_IMM0_7(__b)]) +#define msa_get_lane_u16(__a, __b) ((uint16_t)(__a)[LANE_IMM0_3(__b)]) +#define msa_get_lane_s16(__a, __b) ((int16_t)(__a)[LANE_IMM0_3(__b)]) +#define msa_get_lane_u32(__a, __b) ((uint32_t)(__a)[LANE_IMM0_1(__b)]) +#define msa_get_lane_s32(__a, __b) ((int32_t)(__a)[LANE_IMM0_1(__b)]) +#define msa_get_lane_f32(__a, __b) ((float)(__a)[LANE_IMM0_3(__b)]) +#define msa_get_lane_s64(__a, __b) ((int64_t)(__a)[LANE_IMM0_1(__b)]) +#define msa_get_lane_u64(__a, __b) ((uint64_t)(__a)[LANE_IMM0_1(__b)]) +#define msa_get_lane_f64(__a, __b) ((double)(__a)[LANE_IMM0_1(__b)]) +#define msa_getq_lane_u8(__a, imm0_15) ((uint8_t)__builtin_msa_copy_u_b((v16i8)(__a), imm0_15)) +#define msa_getq_lane_s8(__a, imm0_15) ((int8_t)__builtin_msa_copy_s_b(__a, imm0_15)) +#define msa_getq_lane_u16(__a, imm0_7) ((uint16_t)__builtin_msa_copy_u_h((v8i16)(__a), imm0_7)) +#define msa_getq_lane_s16(__a, imm0_7) ((int16_t)__builtin_msa_copy_s_h(__a, imm0_7)) +#define msa_getq_lane_u32(__a, imm0_3) __builtin_msa_copy_u_w((v4i32)(__a), imm0_3) +#define msa_getq_lane_s32 __builtin_msa_copy_s_w +#define msa_getq_lane_f32(__a, __b) ((float)(__a)[LANE_IMM0_3(__b)]) +#define msa_getq_lane_f64(__a, __b) ((double)(__a)[LANE_IMM0_1(__b)]) +#if (__mips == 64) +#define msa_getq_lane_u64(__a, imm0_1) __builtin_msa_copy_u_d((v2i64)(__a), imm0_1) +#define msa_getq_lane_s64 __builtin_msa_copy_s_d +#else +#define msa_getq_lane_u64(__a, imm0_1) ((uint64_t)(__a)[LANE_IMM0_1(imm0_1)]) +#define msa_getq_lane_s64(__a, imm0_1) ((int64_t)(__a)[LANE_IMM0_1(imm0_1)]) +#endif + +/* combine */ +#if (__mips == 64) +#define __COMBINE_64_64(__TYPE, a, b) ((__TYPE)((v2u64){((v1u64)(a))[0], ((v1u64)(b))[0]})) +#else +#define __COMBINE_64_64(__TYPE, a, b) ((__TYPE)((v4u32){((v2u32)(a))[0], ((v2u32)(a))[1], \ + ((v2u32)(b))[0], ((v2u32)(b))[1]})) +#endif + +/* v16i8 msa_combine_s8 (v8i8 __a, v8i8 __b) */ +#define msa_combine_s8(__a, __b) __COMBINE_64_64(v16i8, __a, __b) + +/* v8i16 msa_combine_s16(v4i16 __a, v4i16 __b) */ +#define msa_combine_s16(__a, __b) __COMBINE_64_64(v8i16, __a, __b) + +/* v4i32 msa_combine_s32(v2i32 __a, v2i32 __b) */ +#define msa_combine_s32(__a, __b) __COMBINE_64_64(v4i32, __a, __b) + +/* v2i64 msa_combine_s64(v1i64 __a, v1i64 __b) */ +#define msa_combine_s64(__a, __b) __COMBINE_64_64(v2i64, __a, __b) + +/* v4f32 msa_combine_f32(v2f32 __a, v2f32 __b) */ +#define msa_combine_f32(__a, __b) __COMBINE_64_64(v4f32, __a, __b) + +/* v16u8 msa_combine_u8(v8u8 __a, v8u8 __b) */ +#define msa_combine_u8(__a, __b) __COMBINE_64_64(v16u8, __a, __b) + +/* v8u16 msa_combine_u16(v4u16 __a, v4u16 __b) */ +#define msa_combine_u16(__a, __b) __COMBINE_64_64(v8u16, __a, __b) + +/* v4u32 msa_combine_u32(v2u32 __a, v2u32 __b) */ +#define msa_combine_u32(__a, __b) __COMBINE_64_64(v4u32, __a, __b) + +/* v2u64 msa_combine_u64(v1u64 __a, v1u64 __b) */ +#define msa_combine_u64(__a, __b) __COMBINE_64_64(v2u64, __a, __b) + +/* v2f64 msa_combine_f64(v1f64 __a, v1f64 __b) */ +#define msa_combine_f64(__a, __b) __COMBINE_64_64(v2f64, __a, __b) + +/* get_low, get_high */ +#if (__mips == 64) +#define __GET_LOW(__TYPE, a) ((__TYPE)((v1u64)(__builtin_msa_copy_u_d((v2i64)(a), 0)))) +#define __GET_HIGH(__TYPE, a) ((__TYPE)((v1u64)(__builtin_msa_copy_u_d((v2i64)(a), 1)))) +#else +#define __GET_LOW(__TYPE, a) ((__TYPE)(((v2u64)(a))[0])) +#define __GET_HIGH(__TYPE, a) ((__TYPE)(((v2u64)(a))[1])) +#endif + +/* v8i8 msa_get_low_s8(v16i8 __a) */ +#define msa_get_low_s8(__a) __GET_LOW(v8i8, __a) + +/* v4i16 msa_get_low_s16(v8i16 __a) */ +#define msa_get_low_s16(__a) __GET_LOW(v4i16, __a) + +/* v2i32 msa_get_low_s32(v4i32 __a) */ +#define msa_get_low_s32(__a) __GET_LOW(v2i32, __a) + +/* v1i64 msa_get_low_s64(v2i64 __a) */ +#define msa_get_low_s64(__a) __GET_LOW(v1i64, __a) + +/* v8u8 msa_get_low_u8(v16u8 __a) */ +#define msa_get_low_u8(__a) __GET_LOW(v8u8, __a) + +/* v4u16 msa_get_low_u16(v8u16 __a) */ +#define msa_get_low_u16(__a) __GET_LOW(v4u16, __a) + +/* v2u32 msa_get_low_u32(v4u32 __a) */ +#define msa_get_low_u32(__a) __GET_LOW(v2u32, __a) + +/* v1u64 msa_get_low_u64(v2u64 __a) */ +#define msa_get_low_u64(__a) __GET_LOW(v1u64, __a) + +/* v2f32 msa_get_low_f32(v4f32 __a) */ +#define msa_get_low_f32(__a) __GET_LOW(v2f32, __a) + +/* v1f64 msa_get_low_f64(v2f64 __a) */ +#define msa_get_low_f64(__a) __GET_LOW(v1f64, __a) + +/* v8i8 msa_get_high_s8(v16i8 __a) */ +#define msa_get_high_s8(__a) __GET_HIGH(v8i8, __a) + +/* v4i16 msa_get_high_s16(v8i16 __a) */ +#define msa_get_high_s16(__a) __GET_HIGH(v4i16, __a) + +/* v2i32 msa_get_high_s32(v4i32 __a) */ +#define msa_get_high_s32(__a) __GET_HIGH(v2i32, __a) + +/* v1i64 msa_get_high_s64(v2i64 __a) */ +#define msa_get_high_s64(__a) __GET_HIGH(v1i64, __a) + +/* v8u8 msa_get_high_u8(v16u8 __a) */ +#define msa_get_high_u8(__a) __GET_HIGH(v8u8, __a) + +/* v4u16 msa_get_high_u16(v8u16 __a) */ +#define msa_get_high_u16(__a) __GET_HIGH(v4u16, __a) + +/* v2u32 msa_get_high_u32(v4u32 __a) */ +#define msa_get_high_u32(__a) __GET_HIGH(v2u32, __a) + +/* v1u64 msa_get_high_u64(v2u64 __a) */ +#define msa_get_high_u64(__a) __GET_HIGH(v1u64, __a) + +/* v2f32 msa_get_high_f32(v4f32 __a) */ +#define msa_get_high_f32(__a) __GET_HIGH(v2f32, __a) + +/* v1f64 msa_get_high_f64(v2f64 __a) */ +#define msa_get_high_f64(__a) __GET_HIGH(v1f64, __a) + +/* ri = ai * b[lane] */ +/* v4f32 msa_mulq_lane_f32(v4f32 __a, v4f32 __b, const int __lane) */ +#define msa_mulq_lane_f32(__a, __b, __lane) ((__a) * msa_getq_lane_f32(__b, __lane)) + +/* ri = ai + bi * c[lane] */ +/* v4f32 msa_mlaq_lane_f32(v4f32 __a, v4f32 __b, v4f32 __c, const int __lane) */ +#define msa_mlaq_lane_f32(__a, __b, __c, __lane) ((__a) + ((__b) * msa_getq_lane_f32(__c, __lane))) + +/* uint16_t msa_sum_u16(v8u16 __a)*/ +#define msa_sum_u16(__a) \ +({ \ + v4u32 _b; \ + v2u64 _c; \ + _b = __builtin_msa_hadd_u_w(__a, __a); \ + _c = __builtin_msa_hadd_u_d(_b, _b); \ + (uint16_t)(_c[0] + _c[1]); \ +}) + +/* int16_t msa_sum_s16(v8i16 __a) */ +#define msa_sum_s16(__a) \ +({ \ + v4i32 _b; \ + v2i64 _c; \ + _b = __builtin_msa_hadd_s_w(__a, __a); \ + _c = __builtin_msa_hadd_s_d(_b, _b); \ + (int16_t)(_c[0] + _c[1]); \ +}) + + +/* uint32_t msa_sum_u32(v4u32 __a)*/ +#define msa_sum_u32(__a) \ +({ \ + v2u64 _b; \ + _b = __builtin_msa_hadd_u_d(__a, __a); \ + (uint32_t)(_b[0] + _b[1]); \ +}) + +/* int32_t msa_sum_s32(v4i32 __a)*/ +#define msa_sum_s32(__a) \ +({ \ + v2i64 _b; \ + _b = __builtin_msa_hadd_s_d(__a, __a); \ + (int32_t)(_b[0] + _b[1]); \ +}) + +/* uint8_t msa_sum_u8(v16u8 __a)*/ +#define msa_sum_u8(__a) \ +({ \ + v8u16 _b16; \ + v4u32 _c32; \ + _b16 = __builtin_msa_hadd_u_h(__a, __a); \ + _c32 = __builtin_msa_hadd_u_w(_b16, _b16); \ + (uint8_t)msa_sum_u32(_c32); \ +}) + +/* int8_t msa_sum_s8(v16s8 __a)*/ +#define msa_sum_s8(__a) \ +({ \ + v8i16 _b16; \ + v4i32 _c32; \ + _b16 = __builtin_msa_hadd_s_h(__a, __a); \ + _c32 = __builtin_msa_hadd_s_w(_b16, _b16); \ + (int8_t)msa_sum_s32(_c32); \ +}) + +/* float msa_sum_f32(v4f32 __a)*/ +#define msa_sum_f32(__a) ((__a)[0] + (__a)[1] + (__a)[2] + (__a)[3]) + +/* v8u16 msa_paddlq_u8(v16u8 __a) */ +#define msa_paddlq_u8(__a) (__builtin_msa_hadd_u_h(__a, __a)) + +/* v8i16 msa_paddlq_s8(v16i8 __a) */ +#define msa_paddlq_s8(__a) (__builtin_msa_hadd_s_h(__a, __a)) + +/* v4u32 msa_paddlq_u16 (v8u16 __a)*/ +#define msa_paddlq_u16(__a) (__builtin_msa_hadd_u_w(__a, __a)) + +/* v4i32 msa_paddlq_s16 (v8i16 __a)*/ +#define msa_paddlq_s16(__a) (__builtin_msa_hadd_s_w(__a, __a)) + +/* v2u64 msa_paddlq_u32(v4u32 __a) */ +#define msa_paddlq_u32(__a) (__builtin_msa_hadd_u_d(__a, __a)) + +/* v2i64 msa_paddlq_s32(v4i32 __a) */ +#define msa_paddlq_s32(__a) (__builtin_msa_hadd_s_d(__a, __a)) + +#define V8U8_2_V8U16(x) {(uint16_t)x[0], (uint16_t)x[1], (uint16_t)x[2], (uint16_t)x[3], \ + (uint16_t)x[4], (uint16_t)x[5], (uint16_t)x[6], (uint16_t)x[7]} +#define V8U8_2_V8I16(x) {(int16_t)x[0], (int16_t)x[1], (int16_t)x[2], (int16_t)x[3], \ + (int16_t)x[4], (int16_t)x[5], (int16_t)x[6], (int16_t)x[7]} +#define V8I8_2_V8I16(x) {(int16_t)x[0], (int16_t)x[1], (int16_t)x[2], (int16_t)x[3], \ + (int16_t)x[4], (int16_t)x[5], (int16_t)x[6], (int16_t)x[7]} +#define V4U16_2_V4U32(x) {(uint32_t)x[0], (uint32_t)x[1], (uint32_t)x[2], (uint32_t)x[3]} +#define V4U16_2_V4I32(x) {(int32_t)x[0], (int32_t)x[1], (int32_t)x[2], (int32_t)x[3]} +#define V4I16_2_V4I32(x) {(int32_t)x[0], (int32_t)x[1], (int32_t)x[2], (int32_t)x[3]} +#define V2U32_2_V2U64(x) {(uint64_t)x[0], (uint64_t)x[1]} +#define V2U32_2_V2I64(x) {(int64_t)x[0], (int64_t)x[1]} + +/* v8u16 msa_mull_u8(v8u8 __a, v8u8 __b) */ +#define msa_mull_u8(__a, __b) ((v8u16)__builtin_msa_mulv_h((v8i16)V8U8_2_V8I16(__a), (v8i16)V8U8_2_V8I16(__b))) + +/* v8i16 msa_mull_s8(v8i8 __a, v8i8 __b)*/ +#define msa_mull_s8(__a, __b) (__builtin_msa_mulv_h((v8i16)V8I8_2_V8I16(__a), (v8i16)V8I8_2_V8I16(__b))) + +/* v4u32 msa_mull_u16(v4u16 __a, v4u16 __b) */ +#define msa_mull_u16(__a, __b) ((v4u32)__builtin_msa_mulv_w((v4i32)V4U16_2_V4I32(__a), (v4i32)V4U16_2_V4I32(__b))) + +/* v4i32 msa_mull_s16(v4i16 __a, v4i16 __b) */ +#define msa_mull_s16(__a, __b) (__builtin_msa_mulv_w((v4i32)V4I16_2_V4I32(__a), (v4i32)V4I16_2_V4I32(__b))) + +/* v2u64 msa_mull_u32(v2u32 __a, v2u32 __b) */ +#define msa_mull_u32(__a, __b) ((v2u64)__builtin_msa_mulv_d((v2i64)V2U32_2_V2I64(__a), (v2i64)V2U32_2_V2I64(__b))) + +/* bitwise and: __builtin_msa_and_v */ +#define msa_andq_u8(__a, __b) ((v16u8)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) +#define msa_andq_s8(__a, __b) ((v16i8)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) +#define msa_andq_u16(__a, __b) ((v8u16)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) +#define msa_andq_s16(__a, __b) ((v8i16)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) +#define msa_andq_u32(__a, __b) ((v4u32)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) +#define msa_andq_s32(__a, __b) ((v4i32)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) +#define msa_andq_u64(__a, __b) ((v2u64)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) +#define msa_andq_s64(__a, __b) ((v2i64)__builtin_msa_and_v((v16u8)(__a), (v16u8)(__b))) + +/* bitwise or: __builtin_msa_or_v */ +#define msa_orrq_u8(__a, __b) ((v16u8)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) +#define msa_orrq_s8(__a, __b) ((v16i8)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) +#define msa_orrq_u16(__a, __b) ((v8u16)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) +#define msa_orrq_s16(__a, __b) ((v8i16)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) +#define msa_orrq_u32(__a, __b) ((v4u32)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) +#define msa_orrq_s32(__a, __b) ((v4i32)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) +#define msa_orrq_u64(__a, __b) ((v2u64)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) +#define msa_orrq_s64(__a, __b) ((v2i64)__builtin_msa_or_v((v16u8)(__a), (v16u8)(__b))) + +/* bitwise xor: __builtin_msa_xor_v */ +#define msa_eorq_u8(__a, __b) ((v16u8)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) +#define msa_eorq_s8(__a, __b) ((v16i8)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) +#define msa_eorq_u16(__a, __b) ((v8u16)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) +#define msa_eorq_s16(__a, __b) ((v8i16)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) +#define msa_eorq_u32(__a, __b) ((v4u32)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) +#define msa_eorq_s32(__a, __b) ((v4i32)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) +#define msa_eorq_u64(__a, __b) ((v2u64)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) +#define msa_eorq_s64(__a, __b) ((v2i64)__builtin_msa_xor_v((v16u8)(__a), (v16u8)(__b))) + +/* bitwise not: v16u8 __builtin_msa_xori_b (v16u8, 0xff) */ +#define msa_mvnq_u8(__a) ((v16u8)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) +#define msa_mvnq_s8(__a) ((v16i8)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) +#define msa_mvnq_u16(__a) ((v8u16)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) +#define msa_mvnq_s16(__a) ((v8i16)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) +#define msa_mvnq_u32(__a) ((v4u32)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) +#define msa_mvnq_s32(__a) ((v4i32)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) +#define msa_mvnq_u64(__a) ((v2u64)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) +#define msa_mvnq_s64(__a) ((v2i64)__builtin_msa_xori_b((v16u8)(__a), 0xFF)) + +/* compare equal: ceq -> ri = ai == bi ? 1...1:0...0 */ +#define msa_ceqq_u8(__a, __b) ((v16u8)__builtin_msa_ceq_b((v16i8)(__a), (v16i8)(__b))) +#define msa_ceqq_s8(__a, __b) ((v16u8)__builtin_msa_ceq_b((v16i8)(__a), (v16i8)(__b))) +#define msa_ceqq_u16(__a, __b) ((v8u16)__builtin_msa_ceq_h((v8i16)(__a), (v8i16)(__b))) +#define msa_ceqq_s16(__a, __b) ((v8u16)__builtin_msa_ceq_h((v8i16)(__a), (v8i16)(__b))) +#define msa_ceqq_u32(__a, __b) ((v4u32)__builtin_msa_ceq_w((v4i32)(__a), (v4i32)(__b))) +#define msa_ceqq_s32(__a, __b) ((v4u32)__builtin_msa_ceq_w((v4i32)(__a), (v4i32)(__b))) +#define msa_ceqq_f32(__a, __b) ((v4u32)__builtin_msa_fceq_w((v4f32)(__a), (v4f32)(__b))) +#define msa_ceqq_u64(__a, __b) ((v2u64)__builtin_msa_ceq_d((v2i64)(__a), (v2i64)(__b))) +#define msa_ceqq_s64(__a, __b) ((v2u64)__builtin_msa_ceq_d((v2i64)(__a), (v2i64)(__b))) +#define msa_ceqq_f64(__a, __b) ((v2u64)__builtin_msa_fceq_d((v2f64)(__a), (v2f64)(__b))) + +/* Compare less-than: clt -> ri = ai < bi ? 1...1:0...0 */ +#define msa_cltq_u8(__a, __b) ((v16u8)__builtin_msa_clt_u_b((v16u8)(__a), (v16u8)(__b))) +#define msa_cltq_s8(__a, __b) ((v16u8)__builtin_msa_clt_s_b((v16i8)(__a), (v16i8)(__b))) +#define msa_cltq_u16(__a, __b) ((v8u16)__builtin_msa_clt_u_h((v8u16)(__a), (v8u16)(__b))) +#define msa_cltq_s16(__a, __b) ((v8u16)__builtin_msa_clt_s_h((v8i16)(__a), (v8i16)(__b))) +#define msa_cltq_u32(__a, __b) ((v4u32)__builtin_msa_clt_u_w((v4u32)(__a), (v4u32)(__b))) +#define msa_cltq_s32(__a, __b) ((v4u32)__builtin_msa_clt_s_w((v4i32)(__a), (v4i32)(__b))) +#define msa_cltq_f32(__a, __b) ((v4u32)__builtin_msa_fclt_w((v4f32)(__a), (v4f32)(__b))) +#define msa_cltq_u64(__a, __b) ((v2u64)__builtin_msa_clt_u_d((v2u64)(__a), (v2u64)(__b))) +#define msa_cltq_s64(__a, __b) ((v2u64)__builtin_msa_clt_s_d((v2i64)(__a), (v2i64)(__b))) +#define msa_cltq_f64(__a, __b) ((v2u64)__builtin_msa_fclt_d((v2f64)(__a), (v2f64)(__b))) + +/* compare greater-than: cgt -> ri = ai > bi ? 1...1:0...0 */ +#define msa_cgtq_u8(__a, __b) ((v16u8)__builtin_msa_clt_u_b((v16u8)(__b), (v16u8)(__a))) +#define msa_cgtq_s8(__a, __b) ((v16u8)__builtin_msa_clt_s_b((v16i8)(__b), (v16i8)(__a))) +#define msa_cgtq_u16(__a, __b) ((v8u16)__builtin_msa_clt_u_h((v8u16)(__b), (v8u16)(__a))) +#define msa_cgtq_s16(__a, __b) ((v8u16)__builtin_msa_clt_s_h((v8i16)(__b), (v8i16)(__a))) +#define msa_cgtq_u32(__a, __b) ((v4u32)__builtin_msa_clt_u_w((v4u32)(__b), (v4u32)(__a))) +#define msa_cgtq_s32(__a, __b) ((v4u32)__builtin_msa_clt_s_w((v4i32)(__b), (v4i32)(__a))) +#define msa_cgtq_f32(__a, __b) ((v4u32)__builtin_msa_fclt_w((v4f32)(__b), (v4f32)(__a))) +#define msa_cgtq_u64(__a, __b) ((v2u64)__builtin_msa_clt_u_d((v2u64)(__b), (v2u64)(__a))) +#define msa_cgtq_s64(__a, __b) ((v2u64)__builtin_msa_clt_s_d((v2i64)(__b), (v2i64)(__a))) +#define msa_cgtq_f64(__a, __b) ((v2u64)__builtin_msa_fclt_d((v2f64)(__b), (v2f64)(__a))) + +/* compare less-equal: cle -> ri = ai <= bi ? 1...1:0...0 */ +#define msa_cleq_u8(__a, __b) ((v16u8)__builtin_msa_cle_u_b((v16u8)(__a), (v16u8)(__b))) +#define msa_cleq_s8(__a, __b) ((v16u8)__builtin_msa_cle_s_b((v16i8)(__a), (v16i8)(__b))) +#define msa_cleq_u16(__a, __b) ((v8u16)__builtin_msa_cle_u_h((v8u16)(__a), (v8u16)(__b))) +#define msa_cleq_s16(__a, __b) ((v8u16)__builtin_msa_cle_s_h((v8i16)(__a), (v8i16)(__b))) +#define msa_cleq_u32(__a, __b) ((v4u32)__builtin_msa_cle_u_w((v4u32)(__a), (v4u32)(__b))) +#define msa_cleq_s32(__a, __b) ((v4u32)__builtin_msa_cle_s_w((v4i32)(__a), (v4i32)(__b))) +#define msa_cleq_f32(__a, __b) ((v4u32)__builtin_msa_fcle_w((v4f32)(__a), (v4f32)(__b))) +#define msa_cleq_u64(__a, __b) ((v2u64)__builtin_msa_cle_u_d((v2u64)(__a), (v2u64)(__b))) +#define msa_cleq_s64(__a, __b) ((v2u64)__builtin_msa_cle_s_d((v2i64)(__a), (v2i64)(__b))) +#define msa_cleq_f64(__a, __b) ((v2u64)__builtin_msa_fcle_d((v2f64)(__a), (v2f64)(__b))) + +/* compare greater-equal: cge -> ri = ai >= bi ? 1...1:0...0 */ +#define msa_cgeq_u8(__a, __b) ((v16u8)__builtin_msa_cle_u_b((v16u8)(__b), (v16u8)(__a))) +#define msa_cgeq_s8(__a, __b) ((v16u8)__builtin_msa_cle_s_b((v16i8)(__b), (v16i8)(__a))) +#define msa_cgeq_u16(__a, __b) ((v8u16)__builtin_msa_cle_u_h((v8u16)(__b), (v8u16)(__a))) +#define msa_cgeq_s16(__a, __b) ((v8u16)__builtin_msa_cle_s_h((v8i16)(__b), (v8i16)(__a))) +#define msa_cgeq_u32(__a, __b) ((v4u32)__builtin_msa_cle_u_w((v4u32)(__b), (v4u32)(__a))) +#define msa_cgeq_s32(__a, __b) ((v4u32)__builtin_msa_cle_s_w((v4i32)(__b), (v4i32)(__a))) +#define msa_cgeq_f32(__a, __b) ((v4u32)__builtin_msa_fcle_w((v4f32)(__b), (v4f32)(__a))) +#define msa_cgeq_u64(__a, __b) ((v2u64)__builtin_msa_cle_u_d((v2u64)(__b), (v2u64)(__a))) +#define msa_cgeq_s64(__a, __b) ((v2u64)__builtin_msa_cle_s_d((v2i64)(__b), (v2i64)(__a))) +#define msa_cgeq_f64(__a, __b) ((v2u64)__builtin_msa_fcle_d((v2f64)(__b), (v2f64)(__a))) + +/* Shift Left Logical: shl -> ri = ai << bi; */ +#define msa_shlq_u8(__a, __b) ((v16u8)__builtin_msa_sll_b((v16i8)(__a), (v16i8)(__b))) +#define msa_shlq_s8(__a, __b) ((v16i8)__builtin_msa_sll_b((v16i8)(__a), (v16i8)(__b))) +#define msa_shlq_u16(__a, __b) ((v8u16)__builtin_msa_sll_h((v8i16)(__a), (v8i16)(__b))) +#define msa_shlq_s16(__a, __b) ((v8i16)__builtin_msa_sll_h((v8i16)(__a), (v8i16)(__b))) +#define msa_shlq_u32(__a, __b) ((v4u32)__builtin_msa_sll_w((v4i32)(__a), (v4i32)(__b))) +#define msa_shlq_s32(__a, __b) ((v4i32)__builtin_msa_sll_w((v4i32)(__a), (v4i32)(__b))) +#define msa_shlq_u64(__a, __b) ((v2u64)__builtin_msa_sll_d((v2i64)(__a), (v2i64)(__b))) +#define msa_shlq_s64(__a, __b) ((v2i64)__builtin_msa_sll_d((v2i64)(__a), (v2i64)(__b))) + +/* Immediate Shift Left Logical: shl -> ri = ai << imm; */ +#define msa_shlq_n_u8(__a, __imm) ((v16u8)__builtin_msa_slli_b((v16i8)(__a), __imm)) +#define msa_shlq_n_s8(__a, __imm) ((v16i8)__builtin_msa_slli_b((v16i8)(__a), __imm)) +#define msa_shlq_n_u16(__a, __imm) ((v8u16)__builtin_msa_slli_h((v8i16)(__a), __imm)) +#define msa_shlq_n_s16(__a, __imm) ((v8i16)__builtin_msa_slli_h((v8i16)(__a), __imm)) +#define msa_shlq_n_u32(__a, __imm) ((v4u32)__builtin_msa_slli_w((v4i32)(__a), __imm)) +#define msa_shlq_n_s32(__a, __imm) ((v4i32)__builtin_msa_slli_w((v4i32)(__a), __imm)) +#define msa_shlq_n_u64(__a, __imm) ((v2u64)__builtin_msa_slli_d((v2i64)(__a), __imm)) +#define msa_shlq_n_s64(__a, __imm) ((v2i64)__builtin_msa_slli_d((v2i64)(__a), __imm)) + +/* shift right: shrq -> ri = ai >> bi; */ +#define msa_shrq_u8(__a, __b) ((v16u8)__builtin_msa_srl_b((v16i8)(__a), (v16i8)(__b))) +#define msa_shrq_s8(__a, __b) ((v16i8)__builtin_msa_sra_b((v16i8)(__a), (v16i8)(__b))) +#define msa_shrq_u16(__a, __b) ((v8u16)__builtin_msa_srl_h((v8i16)(__a), (v8i16)(__b))) +#define msa_shrq_s16(__a, __b) ((v8i16)__builtin_msa_sra_h((v8i16)(__a), (v8i16)(__b))) +#define msa_shrq_u32(__a, __b) ((v4u32)__builtin_msa_srl_w((v4i32)(__a), (v4i32)(__b))) +#define msa_shrq_s32(__a, __b) ((v4i32)__builtin_msa_sra_w((v4i32)(__a), (v4i32)(__b))) +#define msa_shrq_u64(__a, __b) ((v2u64)__builtin_msa_srl_d((v2i64)(__a), (v2i64)(__b))) +#define msa_shrq_s64(__a, __b) ((v2i64)__builtin_msa_sra_d((v2i64)(__a), (v2i64)(__b))) + +/* Immediate Shift Right: shr -> ri = ai >> imm; */ +#define msa_shrq_n_u8(__a, __imm) ((v16u8)__builtin_msa_srli_b((v16i8)(__a), __imm)) +#define msa_shrq_n_s8(__a, __imm) ((v16i8)__builtin_msa_srai_b((v16i8)(__a), __imm)) +#define msa_shrq_n_u16(__a, __imm) ((v8u16)__builtin_msa_srli_h((v8i16)(__a), __imm)) +#define msa_shrq_n_s16(__a, __imm) ((v8i16)__builtin_msa_srai_h((v8i16)(__a), __imm)) +#define msa_shrq_n_u32(__a, __imm) ((v4u32)__builtin_msa_srli_w((v4i32)(__a), __imm)) +#define msa_shrq_n_s32(__a, __imm) ((v4i32)__builtin_msa_srai_w((v4i32)(__a), __imm)) +#define msa_shrq_n_u64(__a, __imm) ((v2u64)__builtin_msa_srli_d((v2i64)(__a), __imm)) +#define msa_shrq_n_s64(__a, __imm) ((v2i64)__builtin_msa_srai_d((v2i64)(__a), __imm)) + +/* Immediate Shift Right Rounded: shr -> ri = ai >> (rounded)imm; */ +#define msa_rshrq_n_u8(__a, __imm) ((v16u8)__builtin_msa_srlri_b((v16i8)(__a), __imm)) +#define msa_rshrq_n_s8(__a, __imm) ((v16i8)__builtin_msa_srari_b((v16i8)(__a), __imm)) +#define msa_rshrq_n_u16(__a, __imm) ((v8u16)__builtin_msa_srlri_h((v8i16)(__a), __imm)) +#define msa_rshrq_n_s16(__a, __imm) ((v8i16)__builtin_msa_srari_h((v8i16)(__a), __imm)) +#define msa_rshrq_n_u32(__a, __imm) ((v4u32)__builtin_msa_srlri_w((v4i32)(__a), __imm)) +#define msa_rshrq_n_s32(__a, __imm) ((v4i32)__builtin_msa_srari_w((v4i32)(__a), __imm)) +#define msa_rshrq_n_u64(__a, __imm) ((v2u64)__builtin_msa_srlri_d((v2i64)(__a), __imm)) +#define msa_rshrq_n_s64(__a, __imm) ((v2i64)__builtin_msa_srari_d((v2i64)(__a), __imm)) + +/* Vector saturating rounding shift left, qrshl -> ri = ai << bi; */ +#define msa_qrshrq_s32(a, b) ((v4i32)__msa_srar_w((v4i32)(a), (v4i32)(b))) + +/* Rename the msa builtin func to unify the name style for intrin_msa.hpp */ +#define msa_qaddq_u8 __builtin_msa_adds_u_b +#define msa_qaddq_s8 __builtin_msa_adds_s_b +#define msa_qaddq_u16 __builtin_msa_adds_u_h +#define msa_qaddq_s16 __builtin_msa_adds_s_h +#define msa_qaddq_u32 __builtin_msa_adds_u_w +#define msa_qaddq_s32 __builtin_msa_adds_s_w +#define msa_qaddq_u64 __builtin_msa_adds_u_d +#define msa_qaddq_s64 __builtin_msa_adds_s_d +#define msa_addq_u8(a, b) ((v16u8)__builtin_msa_addv_b((v16i8)(a), (v16i8)(b))) +#define msa_addq_s8 __builtin_msa_addv_b +#define msa_addq_u16(a, b) ((v8u16)__builtin_msa_addv_h((v8i16)(a), (v8i16)(b))) +#define msa_addq_s16 __builtin_msa_addv_h +#define msa_addq_u32(a, b) ((v4u32)__builtin_msa_addv_w((v4i32)(a), (v4i32)(b))) +#define msa_addq_s32 __builtin_msa_addv_w +#define msa_addq_f32 __builtin_msa_fadd_w +#define msa_addq_u64(a, b) ((v2u64)__builtin_msa_addv_d((v2i64)(a), (v2i64)(b))) +#define msa_addq_s64 __builtin_msa_addv_d +#define msa_addq_f64 __builtin_msa_fadd_d +#define msa_qsubq_u8 __builtin_msa_subs_u_b +#define msa_qsubq_s8 __builtin_msa_subs_s_b +#define msa_qsubq_u16 __builtin_msa_subs_u_h +#define msa_qsubq_s16 __builtin_msa_subs_s_h +#define msa_subq_u8(a, b) ((v16u8)__builtin_msa_subv_b((v16i8)(a), (v16i8)(b))) +#define msa_subq_s8 __builtin_msa_subv_b +#define msa_subq_u16(a, b) ((v8u16)__builtin_msa_subv_h((v8i16)(a), (v8i16)(b))) +#define msa_subq_s16 __builtin_msa_subv_h +#define msa_subq_u32(a, b) ((v4u32)__builtin_msa_subv_w((v4i32)(a), (v4i32)(b))) +#define msa_subq_s32 __builtin_msa_subv_w +#define msa_subq_f32 __builtin_msa_fsub_w +#define msa_subq_u64(a, b) ((v2u64)__builtin_msa_subv_d((v2i64)(a), (v2i64)(b))) +#define msa_subq_s64 __builtin_msa_subv_d +#define msa_subq_f64 __builtin_msa_fsub_d +#define msa_mulq_u8(a, b) ((v16u8)__builtin_msa_mulv_b((v16i8)(a), (v16i8)(b))) +#define msa_mulq_s8(a, b) ((v16i8)__builtin_msa_mulv_b((v16i8)(a), (v16i8)(b))) +#define msa_mulq_u16(a, b) ((v8u16)__builtin_msa_mulv_h((v8i16)(a), (v8i16)(b))) +#define msa_mulq_s16(a, b) ((v8i16)__builtin_msa_mulv_h((v8i16)(a), (v8i16)(b))) +#define msa_mulq_u32(a, b) ((v4u32)__builtin_msa_mulv_w((v4i32)(a), (v4i32)(b))) +#define msa_mulq_s32(a, b) ((v4i32)__builtin_msa_mulv_w((v4i32)(a), (v4i32)(b))) +#define msa_mulq_u64(a, b) ((v2u64)__builtin_msa_mulv_d((v2i64)(a), (v2i64)(b))) +#define msa_mulq_s64(a, b) ((v2i64)__builtin_msa_mulv_d((v2i64)(a), (v2i64)(b))) +#define msa_mulq_f32 __builtin_msa_fmul_w +#define msa_mulq_f64 __builtin_msa_fmul_d +#define msa_divq_f32 __builtin_msa_fdiv_w +#define msa_divq_f64 __builtin_msa_fdiv_d +#define msa_dotp_s_h __builtin_msa_dotp_s_h +#define msa_dotp_s_w __builtin_msa_dotp_s_w +#define msa_dotp_s_d __builtin_msa_dotp_s_d +#define msa_dotp_u_h __builtin_msa_dotp_u_h +#define msa_dotp_u_w __builtin_msa_dotp_u_w +#define msa_dotp_u_d __builtin_msa_dotp_u_d +#define msa_dpadd_s_h __builtin_msa_dpadd_s_h +#define msa_dpadd_s_w __builtin_msa_dpadd_s_w +#define msa_dpadd_s_d __builtin_msa_dpadd_s_d +#define msa_dpadd_u_h __builtin_msa_dpadd_u_h +#define msa_dpadd_u_w __builtin_msa_dpadd_u_w +#define msa_dpadd_u_d __builtin_msa_dpadd_u_d + +#define ILVRL_B2(RTYPE, in0, in1, low, hi) do { \ + low = (RTYPE)__builtin_msa_ilvr_b((v16i8)(in0), (v16i8)(in1)); \ + hi = (RTYPE)__builtin_msa_ilvl_b((v16i8)(in0), (v16i8)(in1)); \ + } while (0) +#define ILVRL_B2_UB(...) ILVRL_B2(v16u8, __VA_ARGS__) +#define ILVRL_B2_SB(...) ILVRL_B2(v16i8, __VA_ARGS__) +#define ILVRL_B2_UH(...) ILVRL_B2(v8u16, __VA_ARGS__) +#define ILVRL_B2_SH(...) ILVRL_B2(v8i16, __VA_ARGS__) +#define ILVRL_B2_SW(...) ILVRL_B2(v4i32, __VA_ARGS__) + +#define ILVRL_H2(RTYPE, in0, in1, low, hi) do { \ + low = (RTYPE)__builtin_msa_ilvr_h((v8i16)(in0), (v8i16)(in1)); \ + hi = (RTYPE)__builtin_msa_ilvl_h((v8i16)(in0), (v8i16)(in1)); \ + } while (0) +#define ILVRL_H2_UB(...) ILVRL_H2(v16u8, __VA_ARGS__) +#define ILVRL_H2_SB(...) ILVRL_H2(v16i8, __VA_ARGS__) +#define ILVRL_H2_UH(...) ILVRL_H2(v8u16, __VA_ARGS__) +#define ILVRL_H2_SH(...) ILVRL_H2(v8i16, __VA_ARGS__) +#define ILVRL_H2_SW(...) ILVRL_H2(v4i32, __VA_ARGS__) +#define ILVRL_H2_UW(...) ILVRL_H2(v4u32, __VA_ARGS__) + +#define ILVRL_W2(RTYPE, in0, in1, low, hi) do { \ + low = (RTYPE)__builtin_msa_ilvr_w((v4i32)(in0), (v4i32)(in1)); \ + hi = (RTYPE)__builtin_msa_ilvl_w((v4i32)(in0), (v4i32)(in1)); \ + } while (0) +#define ILVRL_W2_UB(...) ILVRL_W2(v16u8, __VA_ARGS__) +#define ILVRL_W2_SH(...) ILVRL_W2(v8i16, __VA_ARGS__) +#define ILVRL_W2_SW(...) ILVRL_W2(v4i32, __VA_ARGS__) +#define ILVRL_W2_UW(...) ILVRL_W2(v4u32, __VA_ARGS__) + +/* absq, qabsq (r = |a|;) */ +#define msa_absq_s8(a) __builtin_msa_add_a_b(a, __builtin_msa_fill_b(0)) +#define msa_absq_s16(a) __builtin_msa_add_a_h(a, __builtin_msa_fill_h(0)) +#define msa_absq_s32(a) __builtin_msa_add_a_w(a, __builtin_msa_fill_w(0)) +#define msa_absq_s64(a) __builtin_msa_add_a_d(a, __builtin_msa_fill_d(0)) +#define msa_absq_f32(a) ((v4f32)__builtin_msa_bclri_w((v4u32)(a), 31)) +#define msa_absq_f64(a) ((v2f64)__builtin_msa_bclri_d((v2u64)(a), 63)) +#define msa_qabsq_s8(a) __builtin_msa_adds_a_b(a, __builtin_msa_fill_b(0)) +#define msa_qabsq_s16(a) __builtin_msa_adds_a_h(a, __builtin_msa_fill_h(0)) +#define msa_qabsq_s32(a) __builtin_msa_adds_a_w(a, __builtin_msa_fill_w(0)) +#define msa_qabsq_s64(a) __builtin_msa_adds_a_d(a, __builtin_msa_fill_d(0)) + +/* abdq, qabdq (r = |a - b|;) */ +#define msa_abdq_u8 __builtin_msa_asub_u_b +#define msa_abdq_s8 __builtin_msa_asub_s_b +#define msa_abdq_u16 __builtin_msa_asub_u_h +#define msa_abdq_s16 __builtin_msa_asub_s_h +#define msa_abdq_u32 __builtin_msa_asub_u_w +#define msa_abdq_s32 __builtin_msa_asub_s_w +#define msa_abdq_u64 __builtin_msa_asub_u_d +#define msa_abdq_s64 __builtin_msa_asub_s_d +#define msa_abdq_f32(a, b) msa_absq_f32(__builtin_msa_fsub_w(a, b)) +#define msa_abdq_f64(a, b) msa_absq_f64(__builtin_msa_fsub_d(a, b)) +#define msa_qabdq_s8(a, b) msa_qabsq_s8(__builtin_msa_subs_s_b(a, b)) +#define msa_qabdq_s16(a, b) msa_qabsq_s16(__builtin_msa_subs_s_h(a, b)) +#define msa_qabdq_s32(a, b) msa_qabsq_s32(__builtin_msa_subs_s_w(a, b)) +#define msa_qabdq_s64(a, b) msa_qabsq_s64(__builtin_msa_subs_s_d(a, b)) + +/* sqrtq, rsqrtq */ +#define msa_sqrtq_f32 __builtin_msa_fsqrt_w +#define msa_sqrtq_f64 __builtin_msa_fsqrt_d +#define msa_rsqrtq_f32 __builtin_msa_frsqrt_w +#define msa_rsqrtq_f64 __builtin_msa_frsqrt_d + + +/* mlaq: r = a + b * c; */ +__extension__ extern __inline v4i32 +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +msa_mlaq_s32(v4i32 __a, v4i32 __b, v4i32 __c) +{ + __asm__ volatile("maddv.w %w[__a], %w[__b], %w[__c]\n" + // Outputs + : [__a] "+f"(__a) + // Inputs + : [__b] "f"(__b), [__c] "f"(__c)); + return __a; +} + +__extension__ extern __inline v2i64 +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +msa_mlaq_s64(v2i64 __a, v2i64 __b, v2i64 __c) +{ + __asm__ volatile("maddv.d %w[__a], %w[__b], %w[__c]\n" + // Outputs + : [__a] "+f"(__a) + // Inputs + : [__b] "f"(__b), [__c] "f"(__c)); + return __a; +} + +__extension__ extern __inline v4f32 +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +msa_mlaq_f32(v4f32 __a, v4f32 __b, v4f32 __c) +{ + __asm__ volatile("fmadd.w %w[__a], %w[__b], %w[__c]\n" + // Outputs + : [__a] "+f"(__a) + // Inputs + : [__b] "f"(__b), [__c] "f"(__c)); + return __a; +} + +__extension__ extern __inline v2f64 +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +msa_mlaq_f64(v2f64 __a, v2f64 __b, v2f64 __c) +{ + __asm__ volatile("fmadd.d %w[__a], %w[__b], %w[__c]\n" + // Outputs + : [__a] "+f"(__a) + // Inputs + : [__b] "f"(__b), [__c] "f"(__c)); + return __a; +} + +/* cntq */ +#define msa_cntq_s8 __builtin_msa_pcnt_b +#define msa_cntq_s16 __builtin_msa_pcnt_h +#define msa_cntq_s32 __builtin_msa_pcnt_w +#define msa_cntq_s64 __builtin_msa_pcnt_d + +/* bslq (a: mask; r = b(if a == 0); r = c(if a == 1);) */ +#define msa_bslq_u8 __builtin_msa_bsel_v + +/* ilvrq, ilvlq (For EL only, ilvrq: b0, a0, b1, a1; ilvlq: b2, a2, b3, a3;) */ +#define msa_ilvrq_s8 __builtin_msa_ilvr_b +#define msa_ilvrq_s16 __builtin_msa_ilvr_h +#define msa_ilvrq_s32 __builtin_msa_ilvr_w +#define msa_ilvrq_s64 __builtin_msa_ilvr_d +#define msa_ilvlq_s8 __builtin_msa_ilvl_b +#define msa_ilvlq_s16 __builtin_msa_ilvl_h +#define msa_ilvlq_s32 __builtin_msa_ilvl_w +#define msa_ilvlq_s64 __builtin_msa_ilvl_d + +/* ilvevq, ilvodq (ilvevq: b0, a0, b2, a2; ilvodq: b1, a1, b3, a3; ) */ +#define msa_ilvevq_s8 __builtin_msa_ilvev_b +#define msa_ilvevq_s16 __builtin_msa_ilvev_h +#define msa_ilvevq_s32 __builtin_msa_ilvev_w +#define msa_ilvevq_s64 __builtin_msa_ilvev_d +#define msa_ilvodq_s8 __builtin_msa_ilvod_b +#define msa_ilvodq_s16 __builtin_msa_ilvod_h +#define msa_ilvodq_s32 __builtin_msa_ilvod_w +#define msa_ilvodq_s64 __builtin_msa_ilvod_d + +/* extq (r = (a || b); a concatenation b and get elements from index c) */ +#ifdef _MIPSEB +#define msa_extq_s8(a, b, c) \ +(__builtin_msa_vshf_b(__builtin_msa_subv_b((v16i8)((v2i64){0x1716151413121110, 0x1F1E1D1C1B1A1918}), __builtin_msa_fill_b(c)), a, b)) +#define msa_extq_s16(a, b, c) \ +(__builtin_msa_vshf_h(__builtin_msa_subv_h((v8i16)((v2i64){0x000B000A00090008, 0x000F000E000D000C}), __builtin_msa_fill_h(c)), a, b)) +#define msa_extq_s32(a, b, c) \ +(__builtin_msa_vshf_w(__builtin_msa_subv_w((v4i32)((v2i64){0x0000000500000004, 0x0000000700000006}), __builtin_msa_fill_w(c)), a, b)) +#define msa_extq_s64(a, b, c) \ +(__builtin_msa_vshf_d(__builtin_msa_subv_d((v2i64){0x0000000000000002, 0x0000000000000003}, __builtin_msa_fill_d(c)), a, b)) +#else +#define msa_extq_s8(a, b, c) \ +(__builtin_msa_vshf_b(__builtin_msa_addv_b((v16i8)((v2i64){0x0706050403020100, 0x0F0E0D0C0B0A0908}), __builtin_msa_fill_b(c)), b, a)) +#define msa_extq_s16(a, b, c) \ +(__builtin_msa_vshf_h(__builtin_msa_addv_h((v8i16)((v2i64){0x0003000200010000, 0x0007000600050004}), __builtin_msa_fill_h(c)), b, a)) +#define msa_extq_s32(a, b, c) \ +(__builtin_msa_vshf_w(__builtin_msa_addv_w((v4i32)((v2i64){0x0000000100000000, 0x0000000300000002}), __builtin_msa_fill_w(c)), b, a)) +#define msa_extq_s64(a, b, c) \ +(__builtin_msa_vshf_d(__builtin_msa_addv_d((v2i64){0x0000000000000000, 0x0000000000000001}, __builtin_msa_fill_d(c)), b, a)) +#endif /* _MIPSEB */ + +/* cvttruncq, cvttintq, cvtrintq */ +#define msa_cvttruncq_u32_f32 __builtin_msa_ftrunc_u_w +#define msa_cvttruncq_s32_f32 __builtin_msa_ftrunc_s_w +#define msa_cvttruncq_u64_f64 __builtin_msa_ftrunc_u_d +#define msa_cvttruncq_s64_f64 __builtin_msa_ftrunc_s_d +#define msa_cvttintq_u32_f32 __builtin_msa_ftint_u_w +#define msa_cvttintq_s32_f32 __builtin_msa_ftint_s_w +#define msa_cvttintq_u64_f64 __builtin_msa_ftint_u_d +#define msa_cvttintq_s64_f64 __builtin_msa_ftint_s_d +#define msa_cvtrintq_f32 __builtin_msa_frint_w +#define msa_cvtrintq_f64 __builtin_msa_frint_d + +/* cvtfintq, cvtfq */ +#define msa_cvtfintq_f32_u32 __builtin_msa_ffint_u_w +#define msa_cvtfintq_f32_s32 __builtin_msa_ffint_s_w +#define msa_cvtfintq_f64_u64 __builtin_msa_ffint_u_d +#define msa_cvtfintq_f64_s64 __builtin_msa_ffint_s_d +#define msa_cvtfq_f32_f64 __builtin_msa_fexdo_w +#define msa_cvtflq_f64_f32 __builtin_msa_fexupr_d +#define msa_cvtfhq_f64_f32 __builtin_msa_fexupl_d + +#define msa_addl_u8(a, b) ((v8u16)__builtin_msa_addv_h((v8i16)V8U8_2_V8I16(a), (v8i16)V8U8_2_V8I16(b))) +#define msa_addl_s8(a, b) (__builtin_msa_addv_h((v8i16)V8I8_2_V8I16(a), (v8i16)V8I8_2_V8I16(b))) +#define msa_addl_u16(a, b) ((v4u32)__builtin_msa_addv_w((v4i32)V4U16_2_V4I32(a), (v4i32)V4U16_2_V4I32(b))) +#define msa_addl_s16(a, b) (__builtin_msa_addv_w((v4i32)V4I16_2_V4I32(a), (v4i32)V4I16_2_V4I32(b))) +#define msa_subl_s16(a, b) (__builtin_msa_subv_w((v4i32)V4I16_2_V4I32(a), (v4i32)V4I16_2_V4I32(b))) +#define msa_recpeq_f32 __builtin_msa_frcp_w +#define msa_recpsq_f32(a, b) (__builtin_msa_fsub_w(msa_dupq_n_f32(2.0f), __builtin_msa_fmul_w(a, b))) + +#define MSA_INTERLEAVED_IMPL_LOAD2_STORE2(_Tp, _Tpv, _Tpvs, suffix, df, nlanes) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld2q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b) \ +{ \ + _Tpv v0 = msa_ld1q_##suffix(ptr); \ + _Tpv v1 = msa_ld1q_##suffix(ptr + nlanes); \ + *a = (_Tpv)__builtin_msa_pckev_##df((_Tpvs)v1, (_Tpvs)v0); \ + *b = (_Tpv)__builtin_msa_pckod_##df((_Tpvs)v1, (_Tpvs)v0); \ +} \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st2q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b) \ +{ \ + msa_st1q_##suffix(ptr, (_Tpv)__builtin_msa_ilvr_##df((_Tpvs)b, (_Tpvs)a)); \ + msa_st1q_##suffix(ptr + nlanes, (_Tpv)__builtin_msa_ilvl_##df((_Tpvs)b, (_Tpvs)a)); \ +} + +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(uint8_t, v16u8, v16i8, u8, b, 16) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(int8_t, v16i8, v16i8, s8, b, 16) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(uint16_t, v8u16, v8i16, u16, h, 8) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(int16_t, v8i16, v8i16, s16, h, 8) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(uint32_t, v4u32, v4i32, u32, w, 4) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(int32_t, v4i32, v4i32, s32, w, 4) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(float, v4f32, v4i32, f32, w, 4) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(uint64_t, v2u64, v2i64, u64, d, 2) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(int64_t, v2i64, v2i64, s64, d, 2) +MSA_INTERLEAVED_IMPL_LOAD2_STORE2(double, v2f64, v2i64, f64, d, 2) + +#ifdef _MIPSEB +#define MSA_INTERLEAVED_IMPL_LOAD3_8(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld3q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c) \ +{ \ + _Tpv v0 = msa_ld1q_##suffix(ptr); \ + _Tpv v1 = msa_ld1q_##suffix(ptr + 16); \ + _Tpv v2 = msa_ld1q_##suffix(ptr + 32); \ + _Tpvs v3 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0704011F1F1F1F1F, 0x1F1C191613100D0A}), (_Tpvs)v0, (_Tpvs)v1); \ + *a = (_Tpv)__builtin_msa_vshf_b((_Tpvs)((v2i64){0x1716150E0B080502, 0x1F1E1D1C1B1A1918}), v3, (_Tpvs)v2); \ + v3 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0603001F1F1F1F1F, 0x1E1B1815120F0C09}), (_Tpvs)v0, (_Tpvs)v1); \ + *b = (_Tpv)__builtin_msa_vshf_b((_Tpvs)((v2i64){0x1716150D0A070401, 0x1F1E1D1C1B1A1918}), v3, (_Tpvs)v2); \ + v3 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x05021F1F1F1F1F1F, 0x1D1A1714110E0B08}), (_Tpvs)v0, (_Tpvs)v1); \ + *c = (_Tpv)__builtin_msa_vshf_b((_Tpvs)((v2i64){0x17160F0C09060300, 0x1F1E1D1C1B1A1918}), v3, (_Tpvs)v2); \ +} +#else +#define MSA_INTERLEAVED_IMPL_LOAD3_8(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld3q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c) \ +{ \ + _Tpv v0 = msa_ld1q_##suffix(ptr); \ + _Tpv v1 = msa_ld1q_##suffix(ptr + 16); \ + _Tpv v2 = msa_ld1q_##suffix(ptr + 32); \ + _Tpvs v3 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x15120F0C09060300, 0x00000000001E1B18}), (_Tpvs)v1, (_Tpvs)v0); \ + *a = (_Tpv)__builtin_msa_vshf_b((_Tpvs)((v2i64){0x0706050403020100, 0x1D1A1714110A0908}), (_Tpvs)v2, v3); \ + v3 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x1613100D0A070401, 0x00000000001F1C19}), (_Tpvs)v1, (_Tpvs)v0); \ + *b = (_Tpv)__builtin_msa_vshf_b((_Tpvs)((v2i64){0x0706050403020100, 0x1E1B1815120A0908}), (_Tpvs)v2, v3); \ + v3 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x1714110E0B080502, 0x0000000000001D1A}), (_Tpvs)v1, (_Tpvs)v0); \ + *c = (_Tpv)__builtin_msa_vshf_b((_Tpvs)((v2i64){0x0706050403020100, 0x1F1C191613100908}), (_Tpvs)v2, v3); \ +} +#endif + +MSA_INTERLEAVED_IMPL_LOAD3_8(uint8_t, v16u8, v16i8, u8) +MSA_INTERLEAVED_IMPL_LOAD3_8(int8_t, v16i8, v16i8, s8) + +#ifdef _MIPSEB +#define MSA_INTERLEAVED_IMPL_LOAD3_16(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld3q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c) \ +{ \ + _Tpv v0 = msa_ld1q_##suffix(ptr); \ + _Tpv v1 = msa_ld1q_##suffix(ptr + 8); \ + _Tpv v2 = msa_ld1q_##suffix(ptr + 16); \ + _Tpvs v3 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x00030000000F000F, 0x000F000C00090006}), (_Tpvs)v1, (_Tpvs)v0); \ + *a = (_Tpv)__builtin_msa_vshf_h((_Tpvs)((v2i64){0x000B000A00050002, 0x000F000E000D000C}), (_Tpvs)v2, v3); \ + v3 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0002000F000F000F, 0x000E000B00080005}), (_Tpvs)v1, (_Tpvs)v0); \ + *b = (_Tpv)__builtin_msa_vshf_h((_Tpvs)((v2i64){0x000B000700040001, 0x000F000E000D000C}), (_Tpvs)v2, v3); \ + v3 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0001000F000F000F, 0x000D000A00070004}), (_Tpvs)v1, (_Tpvs)v0); \ + *c = (_Tpv)__builtin_msa_vshf_h((_Tpvs)((v2i64){0x000B000600030000, 0x000F000E000D000C}), (_Tpvs)v2, v3); \ +} +#else +#define MSA_INTERLEAVED_IMPL_LOAD3_16(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld3q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c) \ +{ \ + _Tpv v0 = msa_ld1q_##suffix(ptr); \ + _Tpv v1 = msa_ld1q_##suffix(ptr + 8); \ + _Tpv v2 = msa_ld1q_##suffix(ptr + 16); \ + _Tpvs v3 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0009000600030000, 0x00000000000F000C}), (_Tpvs)v1, (_Tpvs)v0); \ + *a = (_Tpv)__builtin_msa_vshf_h((_Tpvs)((v2i64){0x0003000200010000, 0x000D000A00050004}), (_Tpvs)v2, v3); \ + v3 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x000A000700040001, 0x000000000000000D}), (_Tpvs)v1, (_Tpvs)v0); \ + *b = (_Tpv)__builtin_msa_vshf_h((_Tpvs)((v2i64){0x0003000200010000, 0x000E000B00080004}), (_Tpvs)v2, v3); \ + v3 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x000B000800050002, 0x000000000000000E}), (_Tpvs)v1, (_Tpvs)v0); \ + *c = (_Tpv)__builtin_msa_vshf_h((_Tpvs)((v2i64){0x0003000200010000, 0x000F000C00090004}), (_Tpvs)v2, v3); \ +} +#endif + +MSA_INTERLEAVED_IMPL_LOAD3_16(uint16_t, v8u16, v8i16, u16) +MSA_INTERLEAVED_IMPL_LOAD3_16(int16_t, v8i16, v8i16, s16) + +#define MSA_INTERLEAVED_IMPL_LOAD3_32(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld3q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c) \ +{ \ + _Tpv v00 = msa_ld1q_##suffix(ptr); \ + _Tpv v01 = msa_ld1q_##suffix(ptr + 4); \ + _Tpv v02 = msa_ld1q_##suffix(ptr + 8); \ + _Tpvs v10 = __builtin_msa_ilvr_w((_Tpvs)__builtin_msa_ilvl_d((v2i64)v01, (v2i64)v01), (_Tpvs)v00); \ + _Tpvs v11 = __builtin_msa_ilvr_w((_Tpvs)v02, (_Tpvs)__builtin_msa_ilvl_d((v2i64)v00, (v2i64)v00)); \ + _Tpvs v12 = __builtin_msa_ilvr_w((_Tpvs)__builtin_msa_ilvl_d((v2i64)v02, (v2i64)v02), (_Tpvs)v01); \ + *a = (_Tpv)__builtin_msa_ilvr_w((_Tpvs)__builtin_msa_ilvl_d((v2i64)v11, (v2i64)v11), v10); \ + *b = (_Tpv)__builtin_msa_ilvr_w(v12, (_Tpvs)__builtin_msa_ilvl_d((v2i64)v10, (v2i64)v10)); \ + *c = (_Tpv)__builtin_msa_ilvr_w((_Tpvs)__builtin_msa_ilvl_d((v2i64)v12, (v2i64)v12), v11); \ +} + +MSA_INTERLEAVED_IMPL_LOAD3_32(uint32_t, v4u32, v4i32, u32) +MSA_INTERLEAVED_IMPL_LOAD3_32(int32_t, v4i32, v4i32, s32) +MSA_INTERLEAVED_IMPL_LOAD3_32(float, v4f32, v4i32, f32) + +#define MSA_INTERLEAVED_IMPL_LOAD3_64(_Tp, _Tpv, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld3q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c) \ +{ \ + *((_Tp*)a) = *ptr; *((_Tp*)b) = *(ptr + 1); *((_Tp*)c) = *(ptr + 2); \ + *((_Tp*)a + 1) = *(ptr + 3); *((_Tp*)b + 1) = *(ptr + 4); *((_Tp*)c + 1) = *(ptr + 5); \ +} + +MSA_INTERLEAVED_IMPL_LOAD3_64(uint64_t, v2u64, u64) +MSA_INTERLEAVED_IMPL_LOAD3_64(int64_t, v2i64, s64) +MSA_INTERLEAVED_IMPL_LOAD3_64(double, v2f64, f64) + +#ifdef _MIPSEB +#define MSA_INTERLEAVED_IMPL_STORE3_8(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st3q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c) \ +{ \ + _Tpvs v0 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0F0E0D0C0B1F1F1F, 0x1F1E1D1C1B1A1F1F}), (_Tpvs)b, (_Tpvs)a); \ + _Tpvs v1 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0D1C140C1B130B1A, 0x1F170F1E160E1D15}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0A09080706051F1F, 0x19181716151F1F1F}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x1D14071C13061B12, 0x170A1F16091E1508}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 16, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x04030201001F1F1F, 0x14131211101F1F1F}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x15021C14011B1300, 0x051F17041E16031D}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 32, (_Tpv)v1); \ +} +#else +#define MSA_INTERLEAVED_IMPL_STORE3_8(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st3q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c) \ +{ \ + _Tpvs v0 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0000050403020100, 0x0000001413121110}), (_Tpvs)b, (_Tpvs)a); \ + _Tpvs v1 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0A02110901100800, 0x05140C04130B0312}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0000000A09080706, 0x00001A1918171615}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x170A011609001508, 0x0D04190C03180B02}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 16, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x0000000F0E0D0C0B, 0x0000001F1E1D1C1B}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_b((_Tpvs)((v2i64){0x021C09011B08001A, 0x1F0C041E0B031D0A}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 32, (_Tpv)v1); \ +} +#endif + +MSA_INTERLEAVED_IMPL_STORE3_8(uint8_t, v16u8, v16i8, u8) +MSA_INTERLEAVED_IMPL_STORE3_8(int8_t, v16i8, v16i8, s8) + +#ifdef _MIPSEB +#define MSA_INTERLEAVED_IMPL_STORE3_16(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st3q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c) \ +{ \ + _Tpvs v0 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x000700060005000F, 0x000F000E000D000F}), (_Tpvs)b, (_Tpvs)a); \ + _Tpvs v1 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x000A0006000D0009, 0x000F000B0007000E}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x00040003000F000F, 0x000C000B000A000F}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x000E000A0003000D, 0x0005000F000B0004}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 8, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x000200010000000F, 0x00090008000F000F}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0001000E00090000, 0x000B0002000F000A}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 16, (_Tpv)v1); \ +} +#else +#define MSA_INTERLEAVED_IMPL_STORE3_16(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st3q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c) \ +{ \ + _Tpvs v0 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0000000200010000, 0x0000000A00090008}), (_Tpvs)b, (_Tpvs)a); \ + _Tpvs v1 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0001000800040000, 0x0006000200090005}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0000000500040003, 0x00000000000C000B}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x000B00040000000A, 0x0002000C00050001}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 8, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x0000000000070006, 0x0000000F000E000D}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_h((_Tpvs)((v2i64){0x00050000000D0004, 0x000F00060001000E}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 16, (_Tpv)v1); \ +} +#endif + +MSA_INTERLEAVED_IMPL_STORE3_16(uint16_t, v8u16, v8i16, u16) +MSA_INTERLEAVED_IMPL_STORE3_16(int16_t, v8i16, v8i16, s16) + +#ifdef _MIPSEB +#define MSA_INTERLEAVED_IMPL_STORE3_32(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st3q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c) \ +{ \ + _Tpvs v0 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000300000007, 0x0000000700000006}), (_Tpvs)b, (_Tpvs)a); \ + _Tpvs v1 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000300000006, 0x0000000700000005}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000200000001, 0x0000000500000007}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000700000004, 0x0000000500000002}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 4, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000000000007, 0x0000000400000007}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000500000000, 0x0000000100000007}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 8, (_Tpv)v1); \ +} +#else +#define MSA_INTERLEAVED_IMPL_STORE3_32(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st3q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c) \ +{ \ + _Tpvs v0 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000100000000, 0x0000000000000004}), (_Tpvs)b, (_Tpvs)a); \ + _Tpvs v1 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000200000000, 0x0000000100000004}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000000000002, 0x0000000600000005}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000500000002, 0x0000000300000000}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 4, (_Tpv)v1); \ + v0 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000000000003, 0x0000000000000007}), (_Tpvs)b, (_Tpvs)a); \ + v1 = __builtin_msa_vshf_w((_Tpvs)((v2i64){0x0000000000000006, 0x0000000700000002}), (_Tpvs)c, (_Tpvs)v0); \ + msa_st1q_##suffix(ptr + 8, (_Tpv)v1); \ +} +#endif + +MSA_INTERLEAVED_IMPL_STORE3_32(uint32_t, v4u32, v4i32, u32) +MSA_INTERLEAVED_IMPL_STORE3_32(int32_t, v4i32, v4i32, s32) +MSA_INTERLEAVED_IMPL_STORE3_32(float, v4f32, v4i32, f32) + +#define MSA_INTERLEAVED_IMPL_STORE3_64(_Tp, _Tpv, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st3q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c) \ +{ \ + *ptr = a[0]; *(ptr + 1) = b[0]; *(ptr + 2) = c[0]; \ + *(ptr + 3) = a[1]; *(ptr + 4) = b[1]; *(ptr + 5) = c[1]; \ +} + +MSA_INTERLEAVED_IMPL_STORE3_64(uint64_t, v2u64, u64) +MSA_INTERLEAVED_IMPL_STORE3_64(int64_t, v2i64, s64) +MSA_INTERLEAVED_IMPL_STORE3_64(double, v2f64, f64) + +#define MSA_INTERLEAVED_IMPL_LOAD4_STORE4(_Tp, _Tpv, _Tpvs, suffix, df, nlanes) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld4q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c, _Tpv* d) \ +{ \ + _Tpv v0 = msa_ld1q_##suffix(ptr); \ + _Tpv v1 = msa_ld1q_##suffix(ptr + nlanes); \ + _Tpv v2 = msa_ld1q_##suffix(ptr + nlanes * 2); \ + _Tpv v3 = msa_ld1q_##suffix(ptr + nlanes * 3); \ + _Tpvs t0 = __builtin_msa_pckev_##df((_Tpvs)v1, (_Tpvs)v0); \ + _Tpvs t1 = __builtin_msa_pckev_##df((_Tpvs)v3, (_Tpvs)v2); \ + _Tpvs t2 = __builtin_msa_pckod_##df((_Tpvs)v1, (_Tpvs)v0); \ + _Tpvs t3 = __builtin_msa_pckod_##df((_Tpvs)v3, (_Tpvs)v2); \ + *a = (_Tpv)__builtin_msa_pckev_##df(t1, t0); \ + *b = (_Tpv)__builtin_msa_pckev_##df(t3, t2); \ + *c = (_Tpv)__builtin_msa_pckod_##df(t1, t0); \ + *d = (_Tpv)__builtin_msa_pckod_##df(t3, t2); \ +} \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st4q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c, const _Tpv d) \ +{ \ + _Tpvs v0 = __builtin_msa_ilvr_##df((_Tpvs)c, (_Tpvs)a); \ + _Tpvs v1 = __builtin_msa_ilvr_##df((_Tpvs)d, (_Tpvs)b); \ + _Tpvs v2 = __builtin_msa_ilvl_##df((_Tpvs)c, (_Tpvs)a); \ + _Tpvs v3 = __builtin_msa_ilvl_##df((_Tpvs)d, (_Tpvs)b); \ + msa_st1q_##suffix(ptr, (_Tpv)__builtin_msa_ilvr_##df(v1, v0)); \ + msa_st1q_##suffix(ptr + nlanes, (_Tpv)__builtin_msa_ilvl_##df(v1, v0)); \ + msa_st1q_##suffix(ptr + 2 * nlanes, (_Tpv)__builtin_msa_ilvr_##df(v3, v2)); \ + msa_st1q_##suffix(ptr + 3 * nlanes, (_Tpv)__builtin_msa_ilvl_##df(v3, v2)); \ +} + +MSA_INTERLEAVED_IMPL_LOAD4_STORE4(uint8_t, v16u8, v16i8, u8, b, 16) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4(int8_t, v16i8, v16i8, s8, b, 16) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4(uint16_t, v8u16, v8i16, u16, h, 8) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4(int16_t, v8i16, v8i16, s16, h, 8) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4(uint32_t, v4u32, v4i32, u32, w, 4) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4(int32_t, v4i32, v4i32, s32, w, 4) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4(float, v4f32, v4i32, f32, w, 4) + +#define MSA_INTERLEAVED_IMPL_LOAD4_STORE4_64(_Tp, _Tpv, _Tpvs, suffix) \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_ld4q_##suffix(const _Tp* ptr, _Tpv* a, _Tpv* b, _Tpv* c, _Tpv* d) \ +{ \ + _Tpv v0 = msa_ld1q_##suffix(ptr); \ + _Tpv v1 = msa_ld1q_##suffix(ptr + 2); \ + _Tpv v2 = msa_ld1q_##suffix(ptr + 4); \ + _Tpv v3 = msa_ld1q_##suffix(ptr + 6); \ + *a = (_Tpv)__builtin_msa_ilvr_d((_Tpvs)v2, (_Tpvs)v0); \ + *b = (_Tpv)__builtin_msa_ilvl_d((_Tpvs)v2, (_Tpvs)v0); \ + *c = (_Tpv)__builtin_msa_ilvr_d((_Tpvs)v3, (_Tpvs)v1); \ + *d = (_Tpv)__builtin_msa_ilvl_d((_Tpvs)v3, (_Tpvs)v1); \ +} \ +__extension__ extern __inline void \ +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) \ +msa_st4q_##suffix(_Tp* ptr, const _Tpv a, const _Tpv b, const _Tpv c, const _Tpv d) \ +{ \ + msa_st1q_##suffix(ptr, (_Tpv)__builtin_msa_ilvr_d((_Tpvs)b, (_Tpvs)a)); \ + msa_st1q_##suffix(ptr + 2, (_Tpv)__builtin_msa_ilvr_d((_Tpvs)d, (_Tpvs)c)); \ + msa_st1q_##suffix(ptr + 4, (_Tpv)__builtin_msa_ilvl_d((_Tpvs)b, (_Tpvs)a)); \ + msa_st1q_##suffix(ptr + 6, (_Tpv)__builtin_msa_ilvl_d((_Tpvs)d, (_Tpvs)c)); \ +} + +MSA_INTERLEAVED_IMPL_LOAD4_STORE4_64(uint64_t, v2u64, v2i64, u64) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4_64(int64_t, v2i64, v2i64, s64) +MSA_INTERLEAVED_IMPL_LOAD4_STORE4_64(double, v2f64, v2i64, f64) + +__extension__ extern __inline v8i16 +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +msa_qdmulhq_n_s16(v8i16 a, int16_t b) +{ + v8i16 a_lo, a_hi; + ILVRL_H2_SH(a, msa_dupq_n_s16(0), a_lo, a_hi); + return msa_packr_s32(msa_shlq_n_s32(msa_mulq_s32(msa_paddlq_s16(a_lo), msa_dupq_n_s32(b)), 1), + msa_shlq_n_s32(msa_mulq_s32(msa_paddlq_s16(a_hi), msa_dupq_n_s32(b)), 1), 16); +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif /*__mips_msa*/ +#endif /* OPENCV_CORE_MSA_MACROS_H */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/simd_utils.impl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/simd_utils.impl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fff8f942b8d78224d045b37766ef70218d145c45 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/hal/simd_utils.impl.hpp @@ -0,0 +1,146 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This header is not standalone. Don't include directly, use "intrin.hpp" instead. +#ifdef OPENCV_HAL_INTRIN_HPP // defined in intrin.hpp + + +#if CV_SIMD128 || CV_SIMD128_CPP + +template struct Type2Vec128_Traits; +#define CV_INTRIN_DEF_TYPE2VEC128_TRAITS(type_, vec_type_) \ + template<> struct Type2Vec128_Traits \ + { \ + typedef vec_type_ vec_type; \ + } + +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(uchar, v_uint8x16); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(schar, v_int8x16); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(ushort, v_uint16x8); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(short, v_int16x8); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(unsigned, v_uint32x4); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(int, v_int32x4); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(float, v_float32x4); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(uint64, v_uint64x2); +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(int64, v_int64x2); +#if CV_SIMD128_64F +CV_INTRIN_DEF_TYPE2VEC128_TRAITS(double, v_float64x2); +#endif + +template static inline +typename Type2Vec128_Traits<_T>::vec_type v_setall(const _T& a); + +template<> inline Type2Vec128_Traits< uchar>::vec_type v_setall< uchar>(const uchar& a) { return v_setall_u8(a); } +template<> inline Type2Vec128_Traits< schar>::vec_type v_setall< schar>(const schar& a) { return v_setall_s8(a); } +template<> inline Type2Vec128_Traits::vec_type v_setall(const ushort& a) { return v_setall_u16(a); } +template<> inline Type2Vec128_Traits< short>::vec_type v_setall< short>(const short& a) { return v_setall_s16(a); } +template<> inline Type2Vec128_Traits< uint>::vec_type v_setall< uint>(const uint& a) { return v_setall_u32(a); } +template<> inline Type2Vec128_Traits< int>::vec_type v_setall< int>(const int& a) { return v_setall_s32(a); } +template<> inline Type2Vec128_Traits::vec_type v_setall(const uint64& a) { return v_setall_u64(a); } +template<> inline Type2Vec128_Traits< int64>::vec_type v_setall< int64>(const int64& a) { return v_setall_s64(a); } +template<> inline Type2Vec128_Traits< float>::vec_type v_setall< float>(const float& a) { return v_setall_f32(a); } +#if CV_SIMD128_64F +template<> inline Type2Vec128_Traits::vec_type v_setall(const double& a) { return v_setall_f64(a); } +#endif + +#endif // SIMD128 + + +#if CV_SIMD256 + +template struct Type2Vec256_Traits; +#define CV_INTRIN_DEF_TYPE2VEC256_TRAITS(type_, vec_type_) \ + template<> struct Type2Vec256_Traits \ + { \ + typedef vec_type_ vec_type; \ + } + +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(uchar, v_uint8x32); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(schar, v_int8x32); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(ushort, v_uint16x16); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(short, v_int16x16); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(unsigned, v_uint32x8); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(int, v_int32x8); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(float, v_float32x8); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(uint64, v_uint64x4); +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(int64, v_int64x4); +#if CV_SIMD256_64F +CV_INTRIN_DEF_TYPE2VEC256_TRAITS(double, v_float64x4); +#endif + +template static inline +typename Type2Vec256_Traits<_T>::vec_type v256_setall(const _T& a); + +template<> inline Type2Vec256_Traits< uchar>::vec_type v256_setall< uchar>(const uchar& a) { return v256_setall_u8(a); } +template<> inline Type2Vec256_Traits< schar>::vec_type v256_setall< schar>(const schar& a) { return v256_setall_s8(a); } +template<> inline Type2Vec256_Traits::vec_type v256_setall(const ushort& a) { return v256_setall_u16(a); } +template<> inline Type2Vec256_Traits< short>::vec_type v256_setall< short>(const short& a) { return v256_setall_s16(a); } +template<> inline Type2Vec256_Traits< uint>::vec_type v256_setall< uint>(const uint& a) { return v256_setall_u32(a); } +template<> inline Type2Vec256_Traits< int>::vec_type v256_setall< int>(const int& a) { return v256_setall_s32(a); } +template<> inline Type2Vec256_Traits::vec_type v256_setall(const uint64& a) { return v256_setall_u64(a); } +template<> inline Type2Vec256_Traits< int64>::vec_type v256_setall< int64>(const int64& a) { return v256_setall_s64(a); } +template<> inline Type2Vec256_Traits< float>::vec_type v256_setall< float>(const float& a) { return v256_setall_f32(a); } +#if CV_SIMD256_64F +template<> inline Type2Vec256_Traits::vec_type v256_setall(const double& a) { return v256_setall_f64(a); } +#endif + +#endif // SIMD256 + + +#if CV_SIMD512 + +template struct Type2Vec512_Traits; +#define CV_INTRIN_DEF_TYPE2VEC512_TRAITS(type_, vec_type_) \ + template<> struct Type2Vec512_Traits \ + { \ + typedef vec_type_ vec_type; \ + } + +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(uchar, v_uint8x64); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(schar, v_int8x64); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(ushort, v_uint16x32); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(short, v_int16x32); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(unsigned, v_uint32x16); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(int, v_int32x16); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(float, v_float32x16); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(uint64, v_uint64x8); +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(int64, v_int64x8); +#if CV_SIMD512_64F +CV_INTRIN_DEF_TYPE2VEC512_TRAITS(double, v_float64x8); +#endif + +template static inline +typename Type2Vec512_Traits<_T>::vec_type v512_setall(const _T& a); + +template<> inline Type2Vec512_Traits< uchar>::vec_type v512_setall< uchar>(const uchar& a) { return v512_setall_u8(a); } +template<> inline Type2Vec512_Traits< schar>::vec_type v512_setall< schar>(const schar& a) { return v512_setall_s8(a); } +template<> inline Type2Vec512_Traits::vec_type v512_setall(const ushort& a) { return v512_setall_u16(a); } +template<> inline Type2Vec512_Traits< short>::vec_type v512_setall< short>(const short& a) { return v512_setall_s16(a); } +template<> inline Type2Vec512_Traits< uint>::vec_type v512_setall< uint>(const uint& a) { return v512_setall_u32(a); } +template<> inline Type2Vec512_Traits< int>::vec_type v512_setall< int>(const int& a) { return v512_setall_s32(a); } +template<> inline Type2Vec512_Traits::vec_type v512_setall(const uint64& a) { return v512_setall_u64(a); } +template<> inline Type2Vec512_Traits< int64>::vec_type v512_setall< int64>(const int64& a) { return v512_setall_s64(a); } +template<> inline Type2Vec512_Traits< float>::vec_type v512_setall< float>(const float& a) { return v512_setall_f32(a); } +#if CV_SIMD512_64F +template<> inline Type2Vec512_Traits::vec_type v512_setall(const double& a) { return v512_setall_f64(a); } +#endif + +#endif // SIMD512 + + +#if CV_SIMD_WIDTH == 16 +template static inline +typename Type2Vec128_Traits<_T>::vec_type vx_setall(const _T& a) { return v_setall(a); } +#elif CV_SIMD_WIDTH == 32 +template static inline +typename Type2Vec256_Traits<_T>::vec_type vx_setall(const _T& a) { return v256_setall(a); } +#elif CV_SIMD_WIDTH == 64 +template static inline +typename Type2Vec512_Traits<_T>::vec_type vx_setall(const _T& a) { return v512_setall(a); } +#else +#error "Build configuration error, unsupported CV_SIMD_WIDTH" +#endif + + +#endif // OPENCV_HAL_INTRIN_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/mat.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/mat.hpp new file mode 100644 index 0000000000000000000000000000000000000000..adabeca25b3833632e371aa37c2e993f42c6f3ee --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/mat.hpp @@ -0,0 +1,3726 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_MAT_HPP +#define OPENCV_CORE_MAT_HPP + +#ifndef __cplusplus +# error mat.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/matx.hpp" +#include "opencv2/core/types.hpp" + +#include "opencv2/core/bufferpool.hpp" + +#include + +namespace cv +{ + +//! @addtogroup core_basic +//! @{ + +enum AccessFlag { ACCESS_READ=1<<24, ACCESS_WRITE=1<<25, + ACCESS_RW=3<<24, ACCESS_MASK=ACCESS_RW, ACCESS_FAST=1<<26 }; +CV_ENUM_FLAGS(AccessFlag) +__CV_ENUM_FLAGS_BITWISE_AND(AccessFlag, int, AccessFlag) + +CV__DEBUG_NS_BEGIN + +class CV_EXPORTS _OutputArray; + +//////////////////////// Input/Output Array Arguments ///////////////////////////////// + +/** @brief This is the proxy class for passing read-only input arrays into OpenCV functions. + +It is defined as: +@code + typedef const _InputArray& InputArray; +@endcode +where _InputArray is a class that can be constructed from `Mat`, `Mat_`, `Matx`, +`std::vector`, `std::vector >`, `std::vector`, `std::vector >`, +`UMat`, `std::vector` or `double`. It can also be constructed from a matrix expression. + +Since this is mostly implementation-level class, and its interface may change in future versions, we +do not describe it in details. There are a few key things, though, that should be kept in mind: + +- When you see in the reference manual or in OpenCV source code a function that takes + InputArray, it means that you can actually pass `Mat`, `Matx`, `vector` etc. (see above the + complete list). +- Optional input arguments: If some of the input arrays may be empty, pass cv::noArray() (or + simply cv::Mat() as you probably did before). +- The class is designed solely for passing parameters. That is, normally you *should not* + declare class members, local and global variables of this type. +- If you want to design your own function or a class method that can operate of arrays of + multiple types, you can use InputArray (or OutputArray) for the respective parameters. Inside + a function you should use _InputArray::getMat() method to construct a matrix header for the + array (without copying data). _InputArray::kind() can be used to distinguish Mat from + `vector<>` etc., but normally it is not needed. + +Here is how you can use a function that takes InputArray : +@code + std::vector vec; + // points or a circle + for( int i = 0; i < 30; i++ ) + vec.push_back(Point2f((float)(100 + 30*cos(i*CV_PI*2/5)), + (float)(100 - 30*sin(i*CV_PI*2/5)))); + cv::transform(vec, vec, cv::Matx23f(0.707, -0.707, 10, 0.707, 0.707, 20)); +@endcode +That is, we form an STL vector containing points, and apply in-place affine transformation to the +vector using the 2x3 matrix created inline as `Matx` instance. + +Here is how such a function can be implemented (for simplicity, we implement a very specific case of +it, according to the assertion statement inside) : +@code + void myAffineTransform(InputArray _src, OutputArray _dst, InputArray _m) + { + // get Mat headers for input arrays. This is O(1) operation, + // unless _src and/or _m are matrix expressions. + Mat src = _src.getMat(), m = _m.getMat(); + CV_Assert( src.type() == CV_32FC2 && m.type() == CV_32F && m.size() == Size(3, 2) ); + + // [re]create the output array so that it has the proper size and type. + // In case of Mat it calls Mat::create, in case of STL vector it calls vector::resize. + _dst.create(src.size(), src.type()); + Mat dst = _dst.getMat(); + + for( int i = 0; i < src.rows; i++ ) + for( int j = 0; j < src.cols; j++ ) + { + Point2f pt = src.at(i, j); + dst.at(i, j) = Point2f(m.at(0, 0)*pt.x + + m.at(0, 1)*pt.y + + m.at(0, 2), + m.at(1, 0)*pt.x + + m.at(1, 1)*pt.y + + m.at(1, 2)); + } + } +@endcode +There is another related type, InputArrayOfArrays, which is currently defined as a synonym for +InputArray: +@code + typedef InputArray InputArrayOfArrays; +@endcode +It denotes function arguments that are either vectors of vectors or vectors of matrices. A separate +synonym is needed to generate Python/Java etc. wrappers properly. At the function implementation +level their use is similar, but _InputArray::getMat(idx) should be used to get header for the +idx-th component of the outer vector and _InputArray::size().area() should be used to find the +number of components (vectors/matrices) of the outer vector. + +In general, type support is limited to cv::Mat types. Other types are forbidden. +But in some cases we need to support passing of custom non-general Mat types, like arrays of cv::KeyPoint, cv::DMatch, etc. +This data is not intended to be interpreted as an image data, or processed somehow like regular cv::Mat. +To pass such custom type use rawIn() / rawOut() / rawInOut() wrappers. +Custom type is wrapped as Mat-compatible `CV_8UC` values (N = sizeof(T), N <= CV_CN_MAX). + */ +class CV_EXPORTS _InputArray +{ +public: + enum KindFlag { + KIND_SHIFT = 16, + FIXED_TYPE = 0x8000 << KIND_SHIFT, + FIXED_SIZE = 0x4000 << KIND_SHIFT, + KIND_MASK = 31 << KIND_SHIFT, + + NONE = 0 << KIND_SHIFT, + MAT = 1 << KIND_SHIFT, + MATX = 2 << KIND_SHIFT, + STD_VECTOR = 3 << KIND_SHIFT, + STD_VECTOR_VECTOR = 4 << KIND_SHIFT, + STD_VECTOR_MAT = 5 << KIND_SHIFT, + EXPR = 6 << KIND_SHIFT, + OPENGL_BUFFER = 7 << KIND_SHIFT, + CUDA_HOST_MEM = 8 << KIND_SHIFT, + CUDA_GPU_MAT = 9 << KIND_SHIFT, + UMAT =10 << KIND_SHIFT, + STD_VECTOR_UMAT =11 << KIND_SHIFT, + STD_BOOL_VECTOR =12 << KIND_SHIFT, + STD_VECTOR_CUDA_GPU_MAT = 13 << KIND_SHIFT, + STD_ARRAY =14 << KIND_SHIFT, + STD_ARRAY_MAT =15 << KIND_SHIFT + }; + + _InputArray(); + _InputArray(int _flags, void* _obj); + _InputArray(const Mat& m); + _InputArray(const MatExpr& expr); + _InputArray(const std::vector& vec); + template _InputArray(const Mat_<_Tp>& m); + template _InputArray(const std::vector<_Tp>& vec); + _InputArray(const std::vector& vec); + template _InputArray(const std::vector >& vec); + _InputArray(const std::vector >&) = delete; // not supported + template _InputArray(const std::vector >& vec); + template _InputArray(const _Tp* vec, int n); + template _InputArray(const Matx<_Tp, m, n>& matx); + _InputArray(const double& val); + _InputArray(const cuda::GpuMat& d_mat); + _InputArray(const std::vector& d_mat_array); + _InputArray(const ogl::Buffer& buf); + _InputArray(const cuda::HostMem& cuda_mem); + template _InputArray(const cudev::GpuMat_<_Tp>& m); + _InputArray(const UMat& um); + _InputArray(const std::vector& umv); + + template _InputArray(const std::array<_Tp, _Nm>& arr); + template _InputArray(const std::array& arr); + + template static _InputArray rawIn(const std::vector<_Tp>& vec); + template static _InputArray rawIn(const std::array<_Tp, _Nm>& arr); + + Mat getMat(int idx=-1) const; + Mat getMat_(int idx=-1) const; + UMat getUMat(int idx=-1) const; + void getMatVector(std::vector& mv) const; + void getUMatVector(std::vector& umv) const; + void getGpuMatVector(std::vector& gpumv) const; + cuda::GpuMat getGpuMat() const; + ogl::Buffer getOGlBuffer() const; + + int getFlags() const; + void* getObj() const; + Size getSz() const; + + _InputArray::KindFlag kind() const; + int dims(int i=-1) const; + int cols(int i=-1) const; + int rows(int i=-1) const; + Size size(int i=-1) const; + int sizend(int* sz, int i=-1) const; + bool sameSize(const _InputArray& arr) const; + size_t total(int i=-1) const; + int type(int i=-1) const; + int depth(int i=-1) const; + int channels(int i=-1) const; + bool isContinuous(int i=-1) const; + bool isSubmatrix(int i=-1) const; + bool empty() const; + void copyTo(const _OutputArray& arr) const; + void copyTo(const _OutputArray& arr, const _InputArray & mask) const; + size_t offset(int i=-1) const; + size_t step(int i=-1) const; + bool isMat() const; + bool isUMat() const; + bool isMatVector() const; + bool isUMatVector() const; + bool isMatx() const; + bool isVector() const; + bool isGpuMat() const; + bool isGpuMatVector() const; + ~_InputArray(); + +protected: + int flags; + void* obj; + Size sz; + + void init(int _flags, const void* _obj); + void init(int _flags, const void* _obj, Size _sz); +}; +CV_ENUM_FLAGS(_InputArray::KindFlag) +__CV_ENUM_FLAGS_BITWISE_AND(_InputArray::KindFlag, int, _InputArray::KindFlag) + +/** @brief This type is very similar to InputArray except that it is used for input/output and output function +parameters. + +Just like with InputArray, OpenCV users should not care about OutputArray, they just pass `Mat`, +`vector` etc. to the functions. The same limitation as for `InputArray`: *Do not explicitly +create OutputArray instances* applies here too. + +If you want to make your function polymorphic (i.e. accept different arrays as output parameters), +it is also not very difficult. Take the sample above as the reference. Note that +_OutputArray::create() needs to be called before _OutputArray::getMat(). This way you guarantee +that the output array is properly allocated. + +Optional output parameters. If you do not need certain output array to be computed and returned to +you, pass cv::noArray(), just like you would in the case of optional input array. At the +implementation level, use _OutputArray::needed() to check if certain output array needs to be +computed or not. + +There are several synonyms for OutputArray that are used to assist automatic Python/Java/... wrapper +generators: +@code + typedef OutputArray OutputArrayOfArrays; + typedef OutputArray InputOutputArray; + typedef OutputArray InputOutputArrayOfArrays; +@endcode + */ +class CV_EXPORTS _OutputArray : public _InputArray +{ +public: + enum DepthMask + { + DEPTH_MASK_8U = 1 << CV_8U, + DEPTH_MASK_8S = 1 << CV_8S, + DEPTH_MASK_16U = 1 << CV_16U, + DEPTH_MASK_16S = 1 << CV_16S, + DEPTH_MASK_32S = 1 << CV_32S, + DEPTH_MASK_32F = 1 << CV_32F, + DEPTH_MASK_64F = 1 << CV_64F, + DEPTH_MASK_16F = 1 << CV_16F, + DEPTH_MASK_ALL = (DEPTH_MASK_64F<<1)-1, + DEPTH_MASK_ALL_BUT_8S = DEPTH_MASK_ALL & ~DEPTH_MASK_8S, + DEPTH_MASK_ALL_16F = (DEPTH_MASK_16F<<1)-1, + DEPTH_MASK_FLT = DEPTH_MASK_32F + DEPTH_MASK_64F + }; + + _OutputArray(); + _OutputArray(int _flags, void* _obj); + _OutputArray(Mat& m); + _OutputArray(std::vector& vec); + _OutputArray(cuda::GpuMat& d_mat); + _OutputArray(std::vector& d_mat); + _OutputArray(ogl::Buffer& buf); + _OutputArray(cuda::HostMem& cuda_mem); + template _OutputArray(cudev::GpuMat_<_Tp>& m); + template _OutputArray(std::vector<_Tp>& vec); + _OutputArray(std::vector& vec) = delete; // not supported + template _OutputArray(std::vector >& vec); + _OutputArray(std::vector >&) = delete; // not supported + template _OutputArray(std::vector >& vec); + template _OutputArray(Mat_<_Tp>& m); + template _OutputArray(_Tp* vec, int n); + template _OutputArray(Matx<_Tp, m, n>& matx); + _OutputArray(UMat& m); + _OutputArray(std::vector& vec); + + _OutputArray(const Mat& m); + _OutputArray(const std::vector& vec); + _OutputArray(const cuda::GpuMat& d_mat); + _OutputArray(const std::vector& d_mat); + _OutputArray(const ogl::Buffer& buf); + _OutputArray(const cuda::HostMem& cuda_mem); + template _OutputArray(const cudev::GpuMat_<_Tp>& m); + template _OutputArray(const std::vector<_Tp>& vec); + template _OutputArray(const std::vector >& vec); + template _OutputArray(const std::vector >& vec); + template _OutputArray(const Mat_<_Tp>& m); + template _OutputArray(const _Tp* vec, int n); + template _OutputArray(const Matx<_Tp, m, n>& matx); + _OutputArray(const UMat& m); + _OutputArray(const std::vector& vec); + + template _OutputArray(std::array<_Tp, _Nm>& arr); + template _OutputArray(const std::array<_Tp, _Nm>& arr); + template _OutputArray(std::array& arr); + template _OutputArray(const std::array& arr); + + template static _OutputArray rawOut(std::vector<_Tp>& vec); + template static _OutputArray rawOut(std::array<_Tp, _Nm>& arr); + + bool fixedSize() const; + bool fixedType() const; + bool needed() const; + Mat& getMatRef(int i=-1) const; + UMat& getUMatRef(int i=-1) const; + cuda::GpuMat& getGpuMatRef() const; + std::vector& getGpuMatVecRef() const; + ogl::Buffer& getOGlBufferRef() const; + cuda::HostMem& getHostMemRef() const; + void create(Size sz, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void create(int rows, int cols, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const; + void createSameSize(const _InputArray& arr, int mtype) const; + void release() const; + void clear() const; + void setTo(const _InputArray& value, const _InputArray & mask = _InputArray()) const; + + void assign(const UMat& u) const; + void assign(const Mat& m) const; + + void assign(const std::vector& v) const; + void assign(const std::vector& v) const; + + void move(UMat& u) const; + void move(Mat& m) const; +}; + + +class CV_EXPORTS _InputOutputArray : public _OutputArray +{ +public: + _InputOutputArray(); + _InputOutputArray(int _flags, void* _obj); + _InputOutputArray(Mat& m); + _InputOutputArray(std::vector& vec); + _InputOutputArray(cuda::GpuMat& d_mat); + _InputOutputArray(ogl::Buffer& buf); + _InputOutputArray(cuda::HostMem& cuda_mem); + template _InputOutputArray(cudev::GpuMat_<_Tp>& m); + template _InputOutputArray(std::vector<_Tp>& vec); + _InputOutputArray(std::vector& vec) = delete; // not supported + template _InputOutputArray(std::vector >& vec); + template _InputOutputArray(std::vector >& vec); + template _InputOutputArray(Mat_<_Tp>& m); + template _InputOutputArray(_Tp* vec, int n); + template _InputOutputArray(Matx<_Tp, m, n>& matx); + _InputOutputArray(UMat& m); + _InputOutputArray(std::vector& vec); + + _InputOutputArray(const Mat& m); + _InputOutputArray(const std::vector& vec); + _InputOutputArray(const cuda::GpuMat& d_mat); + _InputOutputArray(const std::vector& d_mat); + _InputOutputArray(const ogl::Buffer& buf); + _InputOutputArray(const cuda::HostMem& cuda_mem); + template _InputOutputArray(const cudev::GpuMat_<_Tp>& m); + template _InputOutputArray(const std::vector<_Tp>& vec); + template _InputOutputArray(const std::vector >& vec); + template _InputOutputArray(const std::vector >& vec); + template _InputOutputArray(const Mat_<_Tp>& m); + template _InputOutputArray(const _Tp* vec, int n); + template _InputOutputArray(const Matx<_Tp, m, n>& matx); + _InputOutputArray(const UMat& m); + _InputOutputArray(const std::vector& vec); + + template _InputOutputArray(std::array<_Tp, _Nm>& arr); + template _InputOutputArray(const std::array<_Tp, _Nm>& arr); + template _InputOutputArray(std::array& arr); + template _InputOutputArray(const std::array& arr); + + template static _InputOutputArray rawInOut(std::vector<_Tp>& vec); + template _InputOutputArray rawInOut(std::array<_Tp, _Nm>& arr); + +}; + +/** Helper to wrap custom types. @see InputArray */ +template static inline _InputArray rawIn(_Tp& v); +/** Helper to wrap custom types. @see InputArray */ +template static inline _OutputArray rawOut(_Tp& v); +/** Helper to wrap custom types. @see InputArray */ +template static inline _InputOutputArray rawInOut(_Tp& v); + +CV__DEBUG_NS_END + +typedef const _InputArray& InputArray; +typedef InputArray InputArrayOfArrays; +typedef const _OutputArray& OutputArray; +typedef OutputArray OutputArrayOfArrays; +typedef const _InputOutputArray& InputOutputArray; +typedef InputOutputArray InputOutputArrayOfArrays; + +CV_EXPORTS InputOutputArray noArray(); + +/////////////////////////////////// MatAllocator ////////////////////////////////////// + +//! Usage flags for allocator +enum UMatUsageFlags +{ + USAGE_DEFAULT = 0, + + // buffer allocation policy is platform and usage specific + USAGE_ALLOCATE_HOST_MEMORY = 1 << 0, + USAGE_ALLOCATE_DEVICE_MEMORY = 1 << 1, + USAGE_ALLOCATE_SHARED_MEMORY = 1 << 2, // It is not equal to: USAGE_ALLOCATE_HOST_MEMORY | USAGE_ALLOCATE_DEVICE_MEMORY + + __UMAT_USAGE_FLAGS_32BIT = 0x7fffffff // Binary compatibility hint +}; + +struct CV_EXPORTS UMatData; + +/** @brief Custom array allocator +*/ +class CV_EXPORTS MatAllocator +{ +public: + MatAllocator() {} + virtual ~MatAllocator() {} + + // let's comment it off for now to detect and fix all the uses of allocator + //virtual void allocate(int dims, const int* sizes, int type, int*& refcount, + // uchar*& datastart, uchar*& data, size_t* step) = 0; + //virtual void deallocate(int* refcount, uchar* datastart, uchar* data) = 0; + virtual UMatData* allocate(int dims, const int* sizes, int type, + void* data, size_t* step, AccessFlag flags, UMatUsageFlags usageFlags) const = 0; + virtual bool allocate(UMatData* data, AccessFlag accessflags, UMatUsageFlags usageFlags) const = 0; + virtual void deallocate(UMatData* data) const = 0; + virtual void map(UMatData* data, AccessFlag accessflags) const; + virtual void unmap(UMatData* data) const; + virtual void download(UMatData* data, void* dst, int dims, const size_t sz[], + const size_t srcofs[], const size_t srcstep[], + const size_t dststep[]) const; + virtual void upload(UMatData* data, const void* src, int dims, const size_t sz[], + const size_t dstofs[], const size_t dststep[], + const size_t srcstep[]) const; + virtual void copy(UMatData* srcdata, UMatData* dstdata, int dims, const size_t sz[], + const size_t srcofs[], const size_t srcstep[], + const size_t dstofs[], const size_t dststep[], bool sync) const; + + // default implementation returns DummyBufferPoolController + virtual BufferPoolController* getBufferPoolController(const char* id = NULL) const; +}; + + +//////////////////////////////// MatCommaInitializer ////////////////////////////////// + +/** @brief Comma-separated Matrix Initializer + + The class instances are usually not created explicitly. + Instead, they are created on "matrix << firstValue" operator. + + The sample below initializes 2x2 rotation matrix: + + \code + double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180); + Mat R = (Mat_(2,2) << a, -b, b, a); + \endcode +*/ +template class MatCommaInitializer_ +{ +public: + //! the constructor, created by "matrix << firstValue" operator, where matrix is cv::Mat + MatCommaInitializer_(Mat_<_Tp>* _m); + //! the operator that takes the next value and put it to the matrix + template MatCommaInitializer_<_Tp>& operator , (T2 v); + //! another form of conversion operator + operator Mat_<_Tp>() const; +protected: + MatIterator_<_Tp> it; +}; + + +/////////////////////////////////////// Mat /////////////////////////////////////////// + +// note that umatdata might be allocated together +// with the matrix data, not as a separate object. +// therefore, it does not have constructor or destructor; +// it should be explicitly initialized using init(). +struct CV_EXPORTS UMatData +{ + enum MemoryFlag { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2, + DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24, + USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64, + ASYNC_CLEANUP=128 + }; + UMatData(const MatAllocator* allocator); + ~UMatData(); + + // provide atomic access to the structure + void lock(); + void unlock(); + + bool hostCopyObsolete() const; + bool deviceCopyObsolete() const; + bool deviceMemMapped() const; + bool copyOnMap() const; + bool tempUMat() const; + bool tempCopiedUMat() const; + void markHostCopyObsolete(bool flag); + void markDeviceCopyObsolete(bool flag); + void markDeviceMemMapped(bool flag); + + const MatAllocator* prevAllocator; + const MatAllocator* currAllocator; + int urefcount; + int refcount; + uchar* data; + uchar* origdata; + size_t size; + + UMatData::MemoryFlag flags; + void* handle; + void* userdata; + int allocatorFlags_; + int mapcount; + UMatData* originalUMatData; +}; +CV_ENUM_FLAGS(UMatData::MemoryFlag) + + +struct CV_EXPORTS MatSize +{ + explicit MatSize(int* _p); + int dims() const; + Size operator()() const; + const int& operator[](int i) const; + int& operator[](int i); + operator const int*() const; // TODO OpenCV 4.0: drop this + bool operator == (const MatSize& sz) const; + bool operator != (const MatSize& sz) const; + + int* p; +}; + +struct CV_EXPORTS MatStep +{ + MatStep(); + explicit MatStep(size_t s); + const size_t& operator[](int i) const; + size_t& operator[](int i); + operator size_t() const; + MatStep& operator = (size_t s); + + size_t* p; + size_t buf[2]; +protected: + MatStep& operator = (const MatStep&); +}; + +/** @example samples/cpp/cout_mat.cpp +An example demonstrating the serial out capabilities of cv::Mat +*/ + + /** @brief n-dimensional dense array class \anchor CVMat_Details + +The class Mat represents an n-dimensional dense numerical single-channel or multi-channel array. It +can be used to store real or complex-valued vectors and matrices, grayscale or color images, voxel +volumes, vector fields, point clouds, tensors, histograms (though, very high-dimensional histograms +may be better stored in a SparseMat ). The data layout of the array `M` is defined by the array +`M.step[]`, so that the address of element \f$(i_0,...,i_{M.dims-1})\f$, where \f$0\leq i_k= M.step[i+1]` (in fact, `M.step[i] >= M.step[i+1]*M.size[i+1]` ). This means +that 2-dimensional matrices are stored row-by-row, 3-dimensional matrices are stored plane-by-plane, +and so on. M.step[M.dims-1] is minimal and always equal to the element size M.elemSize() . + +So, the data layout in Mat is compatible with the majority of dense array types from the standard +toolkits and SDKs, such as Numpy (ndarray), Win32 (independent device bitmaps), and others, +that is, with any array that uses *steps* (or *strides*) to compute the position of a pixel. +Due to this compatibility, it is possible to make a Mat header for user-allocated data and process +it in-place using OpenCV functions. + +There are many different ways to create a Mat object. The most popular options are listed below: + +- Use the create(nrows, ncols, type) method or the similar Mat(nrows, ncols, type[, fillValue]) +constructor. A new array of the specified size and type is allocated. type has the same meaning as +in the cvCreateMat method. For example, CV_8UC1 means a 8-bit single-channel array, CV_32FC2 +means a 2-channel (complex) floating-point array, and so on. +@code + // make a 7x7 complex matrix filled with 1+3j. + Mat M(7,7,CV_32FC2,Scalar(1,3)); + // and now turn M to a 100x60 15-channel 8-bit matrix. + // The old content will be deallocated + M.create(100,60,CV_8UC(15)); +@endcode +As noted in the introduction to this chapter, create() allocates only a new array when the shape +or type of the current array are different from the specified ones. + +- Create a multi-dimensional array: +@code + // create a 100x100x100 8-bit array + int sz[] = {100, 100, 100}; + Mat bigCube(3, sz, CV_8U, Scalar::all(0)); +@endcode +It passes the number of dimensions =1 to the Mat constructor but the created array will be +2-dimensional with the number of columns set to 1. So, Mat::dims is always \>= 2 (can also be 0 +when the array is empty). + +- Use a copy constructor or assignment operator where there can be an array or expression on the +right side (see below). As noted in the introduction, the array assignment is an O(1) operation +because it only copies the header and increases the reference counter. The Mat::clone() method can +be used to get a full (deep) copy of the array when you need it. + +- Construct a header for a part of another array. It can be a single row, single column, several +rows, several columns, rectangular region in the array (called a *minor* in algebra) or a +diagonal. Such operations are also O(1) because the new header references the same data. You can +actually modify a part of the array using this feature, for example: +@code + // add the 5-th row, multiplied by 3 to the 3rd row + M.row(3) = M.row(3) + M.row(5)*3; + // now copy the 7-th column to the 1-st column + // M.col(1) = M.col(7); // this will not work + Mat M1 = M.col(1); + M.col(7).copyTo(M1); + // create a new 320x240 image + Mat img(Size(320,240),CV_8UC3); + // select a ROI + Mat roi(img, Rect(10,10,100,100)); + // fill the ROI with (0,255,0) (which is green in RGB space); + // the original 320x240 image will be modified + roi = Scalar(0,255,0); +@endcode +Due to the additional datastart and dataend members, it is possible to compute a relative +sub-array position in the main *container* array using locateROI(): +@code + Mat A = Mat::eye(10, 10, CV_32S); + // extracts A columns, 1 (inclusive) to 3 (exclusive). + Mat B = A(Range::all(), Range(1, 3)); + // extracts B rows, 5 (inclusive) to 9 (exclusive). + // that is, C \~ A(Range(5, 9), Range(1, 3)) + Mat C = B(Range(5, 9), Range::all()); + Size size; Point ofs; + C.locateROI(size, ofs); + // size will be (width=10,height=10) and the ofs will be (x=1, y=5) +@endcode +As in case of whole matrices, if you need a deep copy, use the `clone()` method of the extracted +sub-matrices. + +- Make a header for user-allocated data. It can be useful to do the following: + -# Process "foreign" data using OpenCV (for example, when you implement a DirectShow\* filter or + a processing module for gstreamer, and so on). For example: + @code + void process_video_frame(const unsigned char* pixels, + int width, int height, int step) + { + Mat img(height, width, CV_8UC3, pixels, step); + GaussianBlur(img, img, Size(7,7), 1.5, 1.5); + } + @endcode + -# Quickly initialize small matrices and/or get a super-fast element access. + @code + double m[3][3] = {{a, b, c}, {d, e, f}, {g, h, i}}; + Mat M = Mat(3, 3, CV_64F, m).inv(); + @endcode + . + +- Use MATLAB-style array initializers, zeros(), ones(), eye(), for example: +@code + // create a double-precision identity matrix and add it to M. + M += Mat::eye(M.rows, M.cols, CV_64F); +@endcode + +- Use a comma-separated initializer: +@code + // create a 3x3 double-precision identity matrix + Mat M = (Mat_(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1); +@endcode +With this approach, you first call a constructor of the Mat class with the proper parameters, and +then you just put `<< operator` followed by comma-separated values that can be constants, +variables, expressions, and so on. Also, note the extra parentheses required to avoid compilation +errors. + +Once the array is created, it is automatically managed via a reference-counting mechanism. If the +array header is built on top of user-allocated data, you should handle the data by yourself. The +array data is deallocated when no one points to it. If you want to release the data pointed by a +array header before the array destructor is called, use Mat::release(). + +The next important thing to learn about the array class is element access. This manual already +described how to compute an address of each array element. Normally, you are not required to use the +formula directly in the code. If you know the array element type (which can be retrieved using the +method Mat::type() ), you can access the element \f$M_{ij}\f$ of a 2-dimensional array as: +@code + M.at(i,j) += 1.f; +@endcode +assuming that `M` is a double-precision floating-point array. There are several variants of the method +at for a different number of dimensions. + +If you need to process a whole row of a 2D array, the most efficient way is to get the pointer to +the row first, and then just use the plain C operator [] : +@code + // compute sum of positive matrix elements + // (assuming that M is a double-precision matrix) + double sum=0; + for(int i = 0; i < M.rows; i++) + { + const double* Mi = M.ptr(i); + for(int j = 0; j < M.cols; j++) + sum += std::max(Mi[j], 0.); + } +@endcode +Some operations, like the one above, do not actually depend on the array shape. They just process +elements of an array one by one (or elements from multiple arrays that have the same coordinates, +for example, array addition). Such operations are called *element-wise*. It makes sense to check +whether all the input/output arrays are continuous, namely, have no gaps at the end of each row. If +yes, process them as a long single row: +@code + // compute the sum of positive matrix elements, optimized variant + double sum=0; + int cols = M.cols, rows = M.rows; + if(M.isContinuous()) + { + cols *= rows; + rows = 1; + } + for(int i = 0; i < rows; i++) + { + const double* Mi = M.ptr(i); + for(int j = 0; j < cols; j++) + sum += std::max(Mi[j], 0.); + } +@endcode +In case of the continuous matrix, the outer loop body is executed just once. So, the overhead is +smaller, which is especially noticeable in case of small matrices. + +Finally, there are STL-style iterators that are smart enough to skip gaps between successive rows: +@code + // compute sum of positive matrix elements, iterator-based variant + double sum=0; + MatConstIterator_ it = M.begin(), it_end = M.end(); + for(; it != it_end; ++it) + sum += std::max(*it, 0.); +@endcode +The matrix iterators are random-access iterators, so they can be passed to any STL algorithm, +including std::sort(). + +@note Matrix Expressions and arithmetic see MatExpr +*/ +class CV_EXPORTS Mat +{ +public: + /** + These are various constructors that form a matrix. As noted in the AutomaticAllocation, often + the default constructor is enough, and the proper matrix will be allocated by an OpenCV function. + The constructed matrix can further be assigned to another matrix or matrix expression or can be + allocated with Mat::create . In the former case, the old content is de-referenced. + */ + Mat(); + + /** @overload + @param rows Number of rows in a 2D array. + @param cols Number of columns in a 2D array. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(int rows, int cols, int type); + + /** @overload + @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the + number of columns go in the reverse order. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(Size size, int type); + + /** @overload + @param rows Number of rows in a 2D array. + @param cols Number of columns in a 2D array. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(int rows, int cols, int type, const Scalar& s); + + /** @overload + @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the + number of columns go in the reverse order. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(Size size, int type, const Scalar& s); + + /** @overload + @param ndims Array dimensionality. + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(int ndims, const int* sizes, int type); + + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + */ + Mat(const std::vector& sizes, int type); + + /** @overload + @param ndims Array dimensionality. + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(int ndims, const int* sizes, int type, const Scalar& s); + + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param s An optional value to initialize each matrix element with. To set all the matrix elements to + the particular value after the construction, use the assignment operator + Mat::operator=(const Scalar& value) . + */ + Mat(const std::vector& sizes, int type, const Scalar& s); + + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + */ + Mat(const Mat& m); + + /** @overload + @param rows Number of rows in a 2D array. + @param cols Number of columns in a 2D array. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param step Number of bytes each matrix row occupies. The value should include the padding bytes at + the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed + and the actual step is calculated as cols*elemSize(). See Mat::elemSize. + */ + Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP); + + /** @overload + @param size 2D array size: Size(cols, rows) . In the Size() constructor, the number of rows and the + number of columns go in the reverse order. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param step Number of bytes each matrix row occupies. The value should include the padding bytes at + the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed + and the actual step is calculated as cols*elemSize(). See Mat::elemSize. + */ + Mat(Size size, int type, void* data, size_t step=AUTO_STEP); + + /** @overload + @param ndims Array dimensionality. + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always + set to the element size). If not specified, the matrix is assumed to be continuous. + */ + Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0); + + /** @overload + @param sizes Array of integers specifying an n-dimensional array shape. + @param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always + set to the element size). If not specified, the matrix is assumed to be continuous. + */ + Mat(const std::vector& sizes, int type, void* data, const size_t* steps=0); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param rowRange Range of the m rows to take. As usual, the range start is inclusive and the range + end is exclusive. Use Range::all() to take all the rows. + @param colRange Range of the m columns to take. Use Range::all() to take all the columns. + */ + Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all()); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param roi Region of interest. + */ + Mat(const Mat& m, const Rect& roi); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param ranges Array of selected ranges of m along each dimensionality. + */ + Mat(const Mat& m, const Range* ranges); + + /** @overload + @param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied + by these constructors. Instead, the header pointing to m data or its sub-array is constructed and + associated with it. The reference counter, if any, is incremented. So, when you modify the matrix + formed using such a constructor, you also modify the corresponding elements of m . If you want to + have an independent copy of the sub-array, use Mat::clone() . + @param ranges Array of selected ranges of m along each dimensionality. + */ + Mat(const Mat& m, const std::vector& ranges); + + /** @overload + @param vec STL vector whose elements form the matrix. The matrix has a single column and the number + of rows equal to the number of vector elements. Type of the matrix matches the type of vector + elements. The constructor can handle arbitrary types, for which there is a properly declared + DataType . This means that the vector elements must be primitive numbers or uni-type numerical + tuples of numbers. Mixed-type structures are not supported. The corresponding constructor is + explicit. Since STL vectors are not automatically converted to Mat instances, you should write + Mat(vec) explicitly. Unless you copy the data into the matrix ( copyData=true ), no new elements + will be added to the vector because it can potentially yield vector data reallocation, and, thus, + the matrix data pointer will be invalid. + @param copyData Flag to specify whether the underlying data of the STL vector should be copied + to (true) or shared with (false) the newly constructed matrix. When the data is copied, the + allocated buffer is managed using Mat reference counting mechanism. While the data is shared, + the reference counter is NULL, and you should not deallocate the data until the matrix is not + destructed. + */ + template explicit Mat(const std::vector<_Tp>& vec, bool copyData=false); + + /** @overload + */ + template::value>::type> + explicit Mat(const std::initializer_list<_Tp> list); + + /** @overload + */ + template explicit Mat(const std::initializer_list sizes, const std::initializer_list<_Tp> list); + + /** @overload + */ + template explicit Mat(const std::array<_Tp, _Nm>& arr, bool copyData=false); + + /** @overload + */ + template explicit Mat(const Vec<_Tp, n>& vec, bool copyData=true); + + /** @overload + */ + template explicit Mat(const Matx<_Tp, m, n>& mtx, bool copyData=true); + + /** @overload + */ + template explicit Mat(const Point_<_Tp>& pt, bool copyData=true); + + /** @overload + */ + template explicit Mat(const Point3_<_Tp>& pt, bool copyData=true); + + /** @overload + */ + template explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer); + + //! download data from GpuMat + explicit Mat(const cuda::GpuMat& m); + + //! destructor - calls release() + ~Mat(); + + /** @brief assignment operators + + These are available assignment operators. Since they all are very different, make sure to read the + operator parameters description. + @param m Assigned, right-hand-side matrix. Matrix assignment is an O(1) operation. This means that + no data is copied but the data is shared and the reference counter, if any, is incremented. Before + assigning new data, the old data is de-referenced via Mat::release . + */ + Mat& operator = (const Mat& m); + + /** @overload + @param expr Assigned matrix expression object. As opposite to the first form of the assignment + operation, the second form can reuse already allocated matrix if it has the right size and type to + fit the matrix expression result. It is automatically handled by the real function that the matrix + expressions is expanded to. For example, C=A+B is expanded to add(A, B, C), and add takes care of + automatic C reallocation. + */ + Mat& operator = (const MatExpr& expr); + + //! retrieve UMat from Mat + UMat getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags = USAGE_DEFAULT) const; + + /** @brief Creates a matrix header for the specified matrix row. + + The method makes a new header for the specified matrix row and returns it. This is an O(1) + operation, regardless of the matrix size. The underlying data of the new matrix is shared with the + original matrix. Here is the example of one of the classical basic matrix processing operations, + axpy, used by LU and many other algorithms: + @code + inline void matrix_axpy(Mat& A, int i, int j, double alpha) + { + A.row(i) += A.row(j)*alpha; + } + @endcode + @note In the current implementation, the following code does not work as expected: + @code + Mat A; + ... + A.row(i) = A.row(j); // will not work + @endcode + This happens because A.row(i) forms a temporary header that is further assigned to another header. + Remember that each of these operations is O(1), that is, no data is copied. Thus, the above + assignment is not true if you may have expected the j-th row to be copied to the i-th row. To + achieve that, you should either turn this simple assignment into an expression or use the + Mat::copyTo method: + @code + Mat A; + ... + // works, but looks a bit obscure. + A.row(i) = A.row(j) + 0; + // this is a bit longer, but the recommended method. + A.row(j).copyTo(A.row(i)); + @endcode + @param y A 0-based row index. + */ + Mat row(int y) const; + + /** @brief Creates a matrix header for the specified matrix column. + + The method makes a new header for the specified matrix column and returns it. This is an O(1) + operation, regardless of the matrix size. The underlying data of the new matrix is shared with the + original matrix. See also the Mat::row description. + @param x A 0-based column index. + */ + Mat col(int x) const; + + /** @brief Creates a matrix header for the specified row span. + + The method makes a new header for the specified row span of the matrix. Similarly to Mat::row and + Mat::col , this is an O(1) operation. + @param startrow An inclusive 0-based start index of the row span. + @param endrow An exclusive 0-based ending index of the row span. + */ + Mat rowRange(int startrow, int endrow) const; + + /** @overload + @param r Range structure containing both the start and the end indices. + */ + Mat rowRange(const Range& r) const; + + /** @brief Creates a matrix header for the specified column span. + + The method makes a new header for the specified column span of the matrix. Similarly to Mat::row and + Mat::col , this is an O(1) operation. + @param startcol An inclusive 0-based start index of the column span. + @param endcol An exclusive 0-based ending index of the column span. + */ + Mat colRange(int startcol, int endcol) const; + + /** @overload + @param r Range structure containing both the start and the end indices. + */ + Mat colRange(const Range& r) const; + + /** @brief Extracts a diagonal from a matrix + + The method makes a new header for the specified matrix diagonal. The new matrix is represented as a + single-column matrix. Similarly to Mat::row and Mat::col, this is an O(1) operation. + @param d index of the diagonal, with the following values: + - `d=0` is the main diagonal. + - `d<0` is a diagonal from the lower half. For example, d=-1 means the diagonal is set + immediately below the main one. + - `d>0` is a diagonal from the upper half. For example, d=1 means the diagonal is set + immediately above the main one. + For example: + @code + Mat m = (Mat_(3,3) << + 1,2,3, + 4,5,6, + 7,8,9); + Mat d0 = m.diag(0); + Mat d1 = m.diag(1); + Mat d_1 = m.diag(-1); + @endcode + The resulting matrices are + @code + d0 = + [1; + 5; + 9] + d1 = + [2; + 6] + d_1 = + [4; + 8] + @endcode + */ + Mat diag(int d=0) const; + + /** @brief creates a diagonal matrix + + The method creates a square diagonal matrix from specified main diagonal. + @param d One-dimensional matrix that represents the main diagonal. + */ + static Mat diag(const Mat& d); + + /** @brief Creates a full copy of the array and the underlying data. + + The method creates a full copy of the array. The original step[] is not taken into account. So, the + array copy is a continuous array occupying total()*elemSize() bytes. + */ + Mat clone() const CV_NODISCARD; + + /** @brief Copies the matrix to another one. + + The method copies the matrix data to another matrix. Before copying the data, the method invokes : + @code + m.create(this->size(), this->type()); + @endcode + so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the + function does not handle the case of a partial overlap between the source and the destination + matrices. + + When the operation mask is specified, if the Mat::create call shown above reallocates the matrix, + the newly allocated matrix is initialized with all zeros before copying the data. + @param m Destination matrix. If it does not have a proper size or type before the operation, it is + reallocated. + */ + void copyTo( OutputArray m ) const; + + /** @overload + @param m Destination matrix. If it does not have a proper size or type before the operation, it is + reallocated. + @param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix + elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels. + */ + void copyTo( OutputArray m, InputArray mask ) const; + + /** @brief Converts an array to another data type with optional scaling. + + The method converts source pixel values to the target data type. saturate_cast\<\> is applied at + the end to avoid possible overflows: + + \f[m(x,y) = saturate \_ cast( \alpha (*this)(x,y) + \beta )\f] + @param m output matrix; if it does not have a proper size or type before the operation, it is + reallocated. + @param rtype desired output matrix type or, rather, the depth since the number of channels are the + same as the input has; if rtype is negative, the output matrix will have the same type as the input. + @param alpha optional scale factor. + @param beta optional delta added to the scaled values. + */ + void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const; + + /** @brief Provides a functional form of convertTo. + + This is an internally used method called by the @ref MatrixExpressions engine. + @param m Destination array. + @param type Desired destination array depth (or -1 if it should be the same as the source type). + */ + void assignTo( Mat& m, int type=-1 ) const; + + /** @brief Sets all or some of the array elements to the specified value. + @param s Assigned scalar converted to the actual array type. + */ + Mat& operator = (const Scalar& s); + + /** @brief Sets all or some of the array elements to the specified value. + + This is an advanced variant of the Mat::operator=(const Scalar& s) operator. + @param value Assigned scalar converted to the actual array type. + @param mask Operation mask of the same size as \*this. Its non-zero elements indicate which matrix + elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels + */ + Mat& setTo(InputArray value, InputArray mask=noArray()); + + /** @brief Changes the shape and/or the number of channels of a 2D matrix without copying the data. + + The method makes a new matrix header for \*this elements. The new matrix may have a different size + and/or different number of channels. Any combination is possible if: + - No extra elements are included into the new matrix and no elements are excluded. Consequently, + the product rows\*cols\*channels() must stay the same after the transformation. + - No data is copied. That is, this is an O(1) operation. Consequently, if you change the number of + rows, or the operation changes the indices of elements row in some other way, the matrix must be + continuous. See Mat::isContinuous . + + For example, if there is a set of 3D points stored as an STL vector, and you want to represent the + points as a 3xN matrix, do the following: + @code + std::vector vec; + ... + Mat pointMat = Mat(vec). // convert vector to Mat, O(1) operation + reshape(1). // make Nx3 1-channel matrix out of Nx1 3-channel. + // Also, an O(1) operation + t(); // finally, transpose the Nx3 matrix. + // This involves copying all the elements + @endcode + @param cn New number of channels. If the parameter is 0, the number of channels remains the same. + @param rows New number of rows. If the parameter is 0, the number of rows remains the same. + */ + Mat reshape(int cn, int rows=0) const; + + /** @overload */ + Mat reshape(int cn, int newndims, const int* newsz) const; + + /** @overload */ + Mat reshape(int cn, const std::vector& newshape) const; + + /** @brief Transposes a matrix. + + The method performs matrix transposition by means of matrix expressions. It does not perform the + actual transposition but returns a temporary matrix transposition object that can be further used as + a part of more complex matrix expressions or can be assigned to a matrix: + @code + Mat A1 = A + Mat::eye(A.size(), A.type())*lambda; + Mat C = A1.t()*A1; // compute (A + lambda*I)^t * (A + lamda*I) + @endcode + */ + MatExpr t() const; + + /** @brief Inverses a matrix. + + The method performs a matrix inversion by means of matrix expressions. This means that a temporary + matrix inversion object is returned by the method and can be used further as a part of more complex + matrix expressions or can be assigned to a matrix. + @param method Matrix inversion method. One of cv::DecompTypes + */ + MatExpr inv(int method=DECOMP_LU) const; + + /** @brief Performs an element-wise multiplication or division of the two matrices. + + The method returns a temporary object encoding per-element array multiplication, with optional + scale. Note that this is not a matrix multiplication that corresponds to a simpler "\*" operator. + + Example: + @code + Mat C = A.mul(5/B); // equivalent to divide(A, B, C, 5) + @endcode + @param m Another array of the same type and the same size as \*this, or a matrix expression. + @param scale Optional scale factor. + */ + MatExpr mul(InputArray m, double scale=1) const; + + /** @brief Computes a cross-product of two 3-element vectors. + + The method computes a cross-product of two 3-element vectors. The vectors must be 3-element + floating-point vectors of the same shape and size. The result is another 3-element vector of the + same shape and type as operands. + @param m Another cross-product operand. + */ + Mat cross(InputArray m) const; + + /** @brief Computes a dot-product of two vectors. + + The method computes a dot-product of two matrices. If the matrices are not single-column or + single-row vectors, the top-to-bottom left-to-right scan ordering is used to treat them as 1D + vectors. The vectors must have the same size and type. If the matrices have more than one channel, + the dot products from all the channels are summed together. + @param m another dot-product operand. + */ + double dot(InputArray m) const; + + /** @brief Returns a zero array of the specified size and type. + + The method returns a Matlab-style zero array initializer. It can be used to quickly form a constant + array as a function parameter, part of a matrix expression, or as a matrix initializer: + @code + Mat A; + A = Mat::zeros(3, 3, CV_32F); + @endcode + In the example above, a new matrix is allocated only if A is not a 3x3 floating-point matrix. + Otherwise, the existing matrix A is filled with zeros. + @param rows Number of rows. + @param cols Number of columns. + @param type Created matrix type. + */ + static MatExpr zeros(int rows, int cols, int type); + + /** @overload + @param size Alternative to the matrix size specification Size(cols, rows) . + @param type Created matrix type. + */ + static MatExpr zeros(Size size, int type); + + /** @overload + @param ndims Array dimensionality. + @param sz Array of integers specifying the array shape. + @param type Created matrix type. + */ + static MatExpr zeros(int ndims, const int* sz, int type); + + /** @brief Returns an array of all 1's of the specified size and type. + + The method returns a Matlab-style 1's array initializer, similarly to Mat::zeros. Note that using + this method you can initialize an array with an arbitrary value, using the following Matlab idiom: + @code + Mat A = Mat::ones(100, 100, CV_8U)*3; // make 100x100 matrix filled with 3. + @endcode + The above operation does not form a 100x100 matrix of 1's and then multiply it by 3. Instead, it + just remembers the scale factor (3 in this case) and use it when actually invoking the matrix + initializer. + @note In case of multi-channels type, only the first channel will be initialized with 1's, the + others will be set to 0's. + @param rows Number of rows. + @param cols Number of columns. + @param type Created matrix type. + */ + static MatExpr ones(int rows, int cols, int type); + + /** @overload + @param size Alternative to the matrix size specification Size(cols, rows) . + @param type Created matrix type. + */ + static MatExpr ones(Size size, int type); + + /** @overload + @param ndims Array dimensionality. + @param sz Array of integers specifying the array shape. + @param type Created matrix type. + */ + static MatExpr ones(int ndims, const int* sz, int type); + + /** @brief Returns an identity matrix of the specified size and type. + + The method returns a Matlab-style identity matrix initializer, similarly to Mat::zeros. Similarly to + Mat::ones, you can use a scale operation to create a scaled identity matrix efficiently: + @code + // make a 4x4 diagonal matrix with 0.1's on the diagonal. + Mat A = Mat::eye(4, 4, CV_32F)*0.1; + @endcode + @note In case of multi-channels type, identity matrix will be initialized only for the first channel, + the others will be set to 0's + @param rows Number of rows. + @param cols Number of columns. + @param type Created matrix type. + */ + static MatExpr eye(int rows, int cols, int type); + + /** @overload + @param size Alternative matrix size specification as Size(cols, rows) . + @param type Created matrix type. + */ + static MatExpr eye(Size size, int type); + + /** @brief Allocates new array data if needed. + + This is one of the key Mat methods. Most new-style OpenCV functions and methods that produce arrays + call this method for each output array. The method uses the following algorithm: + + -# If the current array shape and the type match the new ones, return immediately. Otherwise, + de-reference the previous data by calling Mat::release. + -# Initialize the new header. + -# Allocate the new data of total()\*elemSize() bytes. + -# Allocate the new, associated with the data, reference counter and set it to 1. + + Such a scheme makes the memory management robust and efficient at the same time and helps avoid + extra typing for you. This means that usually there is no need to explicitly allocate output arrays. + That is, instead of writing: + @code + Mat color; + ... + Mat gray(color.rows, color.cols, color.depth()); + cvtColor(color, gray, COLOR_BGR2GRAY); + @endcode + you can simply write: + @code + Mat color; + ... + Mat gray; + cvtColor(color, gray, COLOR_BGR2GRAY); + @endcode + because cvtColor, as well as the most of OpenCV functions, calls Mat::create() for the output array + internally. + @param rows New number of rows. + @param cols New number of columns. + @param type New matrix type. + */ + void create(int rows, int cols, int type); + + /** @overload + @param size Alternative new matrix size specification: Size(cols, rows) + @param type New matrix type. + */ + void create(Size size, int type); + + /** @overload + @param ndims New array dimensionality. + @param sizes Array of integers specifying a new array shape. + @param type New matrix type. + */ + void create(int ndims, const int* sizes, int type); + + /** @overload + @param sizes Array of integers specifying a new array shape. + @param type New matrix type. + */ + void create(const std::vector& sizes, int type); + + /** @brief Increments the reference counter. + + The method increments the reference counter associated with the matrix data. If the matrix header + points to an external data set (see Mat::Mat ), the reference counter is NULL, and the method has no + effect in this case. Normally, to avoid memory leaks, the method should not be called explicitly. It + is called implicitly by the matrix assignment operator. The reference counter increment is an atomic + operation on the platforms that support it. Thus, it is safe to operate on the same matrices + asynchronously in different threads. + */ + void addref(); + + /** @brief Decrements the reference counter and deallocates the matrix if needed. + + The method decrements the reference counter associated with the matrix data. When the reference + counter reaches 0, the matrix data is deallocated and the data and the reference counter pointers + are set to NULL's. If the matrix header points to an external data set (see Mat::Mat ), the + reference counter is NULL, and the method has no effect in this case. + + This method can be called manually to force the matrix data deallocation. But since this method is + automatically called in the destructor, or by any other method that changes the data pointer, it is + usually not needed. The reference counter decrement and check for 0 is an atomic operation on the + platforms that support it. Thus, it is safe to operate on the same matrices asynchronously in + different threads. + */ + void release(); + + //! internal use function, consider to use 'release' method instead; deallocates the matrix data + void deallocate(); + //! internal use function; properly re-allocates _size, _step arrays + void copySize(const Mat& m); + + /** @brief Reserves space for the certain number of rows. + + The method reserves space for sz rows. If the matrix already has enough space to store sz rows, + nothing happens. If the matrix is reallocated, the first Mat::rows rows are preserved. The method + emulates the corresponding method of the STL vector class. + @param sz Number of rows. + */ + void reserve(size_t sz); + + /** @brief Reserves space for the certain number of bytes. + + The method reserves space for sz bytes. If the matrix already has enough space to store sz bytes, + nothing happens. If matrix has to be reallocated its previous content could be lost. + @param sz Number of bytes. + */ + void reserveBuffer(size_t sz); + + /** @brief Changes the number of matrix rows. + + The methods change the number of matrix rows. If the matrix is reallocated, the first + min(Mat::rows, sz) rows are preserved. The methods emulate the corresponding methods of the STL + vector class. + @param sz New number of rows. + */ + void resize(size_t sz); + + /** @overload + @param sz New number of rows. + @param s Value assigned to the newly added elements. + */ + void resize(size_t sz, const Scalar& s); + + //! internal function + void push_back_(const void* elem); + + /** @brief Adds elements to the bottom of the matrix. + + The methods add one or more elements to the bottom of the matrix. They emulate the corresponding + method of the STL vector class. When elem is Mat , its type and the number of columns must be the + same as in the container matrix. + @param elem Added element(s). + */ + template void push_back(const _Tp& elem); + + /** @overload + @param elem Added element(s). + */ + template void push_back(const Mat_<_Tp>& elem); + + /** @overload + @param elem Added element(s). + */ + template void push_back(const std::vector<_Tp>& elem); + + /** @overload + @param m Added line(s). + */ + void push_back(const Mat& m); + + /** @brief Removes elements from the bottom of the matrix. + + The method removes one or more rows from the bottom of the matrix. + @param nelems Number of removed rows. If it is greater than the total number of rows, an exception + is thrown. + */ + void pop_back(size_t nelems=1); + + /** @brief Locates the matrix header within a parent matrix. + + After you extracted a submatrix from a matrix using Mat::row, Mat::col, Mat::rowRange, + Mat::colRange, and others, the resultant submatrix points just to the part of the original big + matrix. However, each submatrix contains information (represented by datastart and dataend + fields) that helps reconstruct the original matrix size and the position of the extracted + submatrix within the original matrix. The method locateROI does exactly that. + @param wholeSize Output parameter that contains the size of the whole matrix containing *this* + as a part. + @param ofs Output parameter that contains an offset of *this* inside the whole matrix. + */ + void locateROI( Size& wholeSize, Point& ofs ) const; + + /** @brief Adjusts a submatrix size and position within the parent matrix. + + The method is complimentary to Mat::locateROI . The typical use of these functions is to determine + the submatrix position within the parent matrix and then shift the position somehow. Typically, it + can be required for filtering operations when pixels outside of the ROI should be taken into + account. When all the method parameters are positive, the ROI needs to grow in all directions by the + specified amount, for example: + @code + A.adjustROI(2, 2, 2, 2); + @endcode + In this example, the matrix size is increased by 4 elements in each direction. The matrix is shifted + by 2 elements to the left and 2 elements up, which brings in all the necessary pixels for the + filtering with the 5x5 kernel. + + adjustROI forces the adjusted ROI to be inside of the parent matrix that is boundaries of the + adjusted ROI are constrained by boundaries of the parent matrix. For example, if the submatrix A is + located in the first row of a parent matrix and you called A.adjustROI(2, 2, 2, 2) then A will not + be increased in the upward direction. + + The function is used internally by the OpenCV filtering functions, like filter2D , morphological + operations, and so on. + @param dtop Shift of the top submatrix boundary upwards. + @param dbottom Shift of the bottom submatrix boundary downwards. + @param dleft Shift of the left submatrix boundary to the left. + @param dright Shift of the right submatrix boundary to the right. + @sa copyMakeBorder + */ + Mat& adjustROI( int dtop, int dbottom, int dleft, int dright ); + + /** @brief Extracts a rectangular submatrix. + + The operators make a new header for the specified sub-array of \*this . They are the most + generalized forms of Mat::row, Mat::col, Mat::rowRange, and Mat::colRange . For example, + `A(Range(0, 10), Range::all())` is equivalent to `A.rowRange(0, 10)`. Similarly to all of the above, + the operators are O(1) operations, that is, no matrix data is copied. + @param rowRange Start and end row of the extracted submatrix. The upper boundary is not included. To + select all the rows, use Range::all(). + @param colRange Start and end column of the extracted submatrix. The upper boundary is not included. + To select all the columns, use Range::all(). + */ + Mat operator()( Range rowRange, Range colRange ) const; + + /** @overload + @param roi Extracted submatrix specified as a rectangle. + */ + Mat operator()( const Rect& roi ) const; + + /** @overload + @param ranges Array of selected ranges along each array dimension. + */ + Mat operator()( const Range* ranges ) const; + + /** @overload + @param ranges Array of selected ranges along each array dimension. + */ + Mat operator()(const std::vector& ranges) const; + + template operator std::vector<_Tp>() const; + template operator Vec<_Tp, n>() const; + template operator Matx<_Tp, m, n>() const; + + template operator std::array<_Tp, _Nm>() const; + + /** @brief Reports whether the matrix is continuous or not. + + The method returns true if the matrix elements are stored continuously without gaps at the end of + each row. Otherwise, it returns false. Obviously, 1x1 or 1xN matrices are always continuous. + Matrices created with Mat::create are always continuous. But if you extract a part of the matrix + using Mat::col, Mat::diag, and so on, or constructed a matrix header for externally allocated data, + such matrices may no longer have this property. + + The continuity flag is stored as a bit in the Mat::flags field and is computed automatically when + you construct a matrix header. Thus, the continuity check is a very fast operation, though + theoretically it could be done as follows: + @code + // alternative implementation of Mat::isContinuous() + bool myCheckMatContinuity(const Mat& m) + { + //return (m.flags & Mat::CONTINUOUS_FLAG) != 0; + return m.rows == 1 || m.step == m.cols*m.elemSize(); + } + @endcode + The method is used in quite a few of OpenCV functions. The point is that element-wise operations + (such as arithmetic and logical operations, math functions, alpha blending, color space + transformations, and others) do not depend on the image geometry. Thus, if all the input and output + arrays are continuous, the functions can process them as very long single-row vectors. The example + below illustrates how an alpha-blending function can be implemented: + @code + template + void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst) + { + const float alpha_scale = (float)std::numeric_limits::max(), + inv_scale = 1.f/alpha_scale; + + CV_Assert( src1.type() == src2.type() && + src1.type() == CV_MAKETYPE(traits::Depth::value, 4) && + src1.size() == src2.size()); + Size size = src1.size(); + dst.create(size, src1.type()); + + // here is the idiom: check the arrays for continuity and, + // if this is the case, + // treat the arrays as 1D vectors + if( src1.isContinuous() && src2.isContinuous() && dst.isContinuous() ) + { + size.width *= size.height; + size.height = 1; + } + size.width *= 4; + + for( int i = 0; i < size.height; i++ ) + { + // when the arrays are continuous, + // the outer loop is executed only once + const T* ptr1 = src1.ptr(i); + const T* ptr2 = src2.ptr(i); + T* dptr = dst.ptr(i); + + for( int j = 0; j < size.width; j += 4 ) + { + float alpha = ptr1[j+3]*inv_scale, beta = ptr2[j+3]*inv_scale; + dptr[j] = saturate_cast(ptr1[j]*alpha + ptr2[j]*beta); + dptr[j+1] = saturate_cast(ptr1[j+1]*alpha + ptr2[j+1]*beta); + dptr[j+2] = saturate_cast(ptr1[j+2]*alpha + ptr2[j+2]*beta); + dptr[j+3] = saturate_cast((1 - (1-alpha)*(1-beta))*alpha_scale); + } + } + } + @endcode + This approach, while being very simple, can boost the performance of a simple element-operation by + 10-20 percents, especially if the image is rather small and the operation is quite simple. + + Another OpenCV idiom in this function, a call of Mat::create for the destination array, that + allocates the destination array unless it already has the proper size and type. And while the newly + allocated arrays are always continuous, you still need to check the destination array because + Mat::create does not always allocate a new matrix. + */ + bool isContinuous() const; + + //! returns true if the matrix is a submatrix of another matrix + bool isSubmatrix() const; + + /** @brief Returns the matrix element size in bytes. + + The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , + the method returns 3\*sizeof(short) or 6. + */ + size_t elemSize() const; + + /** @brief Returns the size of each matrix element channel in bytes. + + The method returns the matrix element channel size in bytes, that is, it ignores the number of + channels. For example, if the matrix type is CV_16SC3 , the method returns sizeof(short) or 2. + */ + size_t elemSize1() const; + + /** @brief Returns the type of a matrix element. + + The method returns a matrix element type. This is an identifier compatible with the CvMat type + system, like CV_16SC3 or 16-bit signed 3-channel array, and so on. + */ + int type() const; + + /** @brief Returns the depth of a matrix element. + + The method returns the identifier of the matrix element depth (the type of each individual channel). + For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of + matrix types contains the following values: + - CV_8U - 8-bit unsigned integers ( 0..255 ) + - CV_8S - 8-bit signed integers ( -128..127 ) + - CV_16U - 16-bit unsigned integers ( 0..65535 ) + - CV_16S - 16-bit signed integers ( -32768..32767 ) + - CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) + - CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) + - CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN ) + */ + int depth() const; + + /** @brief Returns the number of matrix channels. + + The method returns the number of matrix channels. + */ + int channels() const; + + /** @brief Returns a normalized step. + + The method returns a matrix step divided by Mat::elemSize1() . It can be useful to quickly access an + arbitrary matrix element. + */ + size_t step1(int i=0) const; + + /** @brief Returns true if the array has no elements. + + The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and + resize() methods `M.total() == 0` does not imply that `M.data == NULL`. + */ + bool empty() const; + + /** @brief Returns the total number of array elements. + + The method returns the number of array elements (a number of pixels if the array represents an + image). + */ + size_t total() const; + + /** @brief Returns the total number of array elements. + + The method returns the number of elements within a certain sub-array slice with startDim <= dim < endDim + */ + size_t total(int startDim, int endDim=INT_MAX) const; + + /** + * @param elemChannels Number of channels or number of columns the matrix should have. + * For a 2-D matrix, when the matrix has only 1 column, then it should have + * elemChannels channels; When the matrix has only 1 channel, + * then it should have elemChannels columns. + * For a 3-D matrix, it should have only one channel. Furthermore, + * if the number of planes is not one, then the number of rows + * within every plane has to be 1; if the number of rows within + * every plane is not 1, then the number of planes has to be 1. + * @param depth The depth the matrix should have. Set it to -1 when any depth is fine. + * @param requireContinuous Set it to true to require the matrix to be continuous + * @return -1 if the requirement is not satisfied. + * Otherwise, it returns the number of elements in the matrix. Note + * that an element may have multiple channels. + * + * The following code demonstrates its usage for a 2-d matrix: + * @snippet snippets/core_mat_checkVector.cpp example-2d + * + * The following code demonstrates its usage for a 3-d matrix: + * @snippet snippets/core_mat_checkVector.cpp example-3d + */ + int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; + + /** @brief Returns a pointer to the specified matrix row. + + The methods return `uchar*` or typed pointer to the specified matrix row. See the sample in + Mat::isContinuous to know how to use these methods. + @param i0 A 0-based row index. + */ + uchar* ptr(int i0=0); + /** @overload */ + const uchar* ptr(int i0=0) const; + + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + uchar* ptr(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + const uchar* ptr(int row, int col) const; + + /** @overload */ + uchar* ptr(int i0, int i1, int i2); + /** @overload */ + const uchar* ptr(int i0, int i1, int i2) const; + + /** @overload */ + uchar* ptr(const int* idx); + /** @overload */ + const uchar* ptr(const int* idx) const; + /** @overload */ + template uchar* ptr(const Vec& idx); + /** @overload */ + template const uchar* ptr(const Vec& idx) const; + + /** @overload */ + template _Tp* ptr(int i0=0); + /** @overload */ + template const _Tp* ptr(int i0=0) const; + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template _Tp* ptr(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template const _Tp* ptr(int row, int col) const; + /** @overload */ + template _Tp* ptr(int i0, int i1, int i2); + /** @overload */ + template const _Tp* ptr(int i0, int i1, int i2) const; + /** @overload */ + template _Tp* ptr(const int* idx); + /** @overload */ + template const _Tp* ptr(const int* idx) const; + /** @overload */ + template _Tp* ptr(const Vec& idx); + /** @overload */ + template const _Tp* ptr(const Vec& idx) const; + + /** @brief Returns a reference to the specified array element. + + The template methods return a reference to the specified array element. For the sake of higher + performance, the index range checks are only performed in the Debug configuration. + + Note that the variants with a single index (i) can be used to access elements of single-row or + single-column 2-dimensional arrays. That is, if, for example, A is a 1 x N floating-point matrix and + B is an M x 1 integer matrix, you can simply write `A.at(k+4)` and `B.at(2*i+1)` + instead of `A.at(0,k+4)` and `B.at(2*i+1,0)`, respectively. + + The example below initializes a Hilbert matrix: + @code + Mat H(100, 100, CV_64F); + for(int i = 0; i < H.rows; i++) + for(int j = 0; j < H.cols; j++) + H.at(i,j)=1./(i+j+1); + @endcode + + Keep in mind that the size identifier used in the at operator cannot be chosen at random. It depends + on the image from which you are trying to retrieve the data. The table below gives a better insight in this: + - If matrix is of type `CV_8U` then use `Mat.at(y,x)`. + - If matrix is of type `CV_8S` then use `Mat.at(y,x)`. + - If matrix is of type `CV_16U` then use `Mat.at(y,x)`. + - If matrix is of type `CV_16S` then use `Mat.at(y,x)`. + - If matrix is of type `CV_32S` then use `Mat.at(y,x)`. + - If matrix is of type `CV_32F` then use `Mat.at(y,x)`. + - If matrix is of type `CV_64F` then use `Mat.at(y,x)`. + + @param i0 Index along the dimension 0 + */ + template _Tp& at(int i0=0); + /** @overload + @param i0 Index along the dimension 0 + */ + template const _Tp& at(int i0=0) const; + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template _Tp& at(int row, int col); + /** @overload + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + template const _Tp& at(int row, int col) const; + + /** @overload + @param i0 Index along the dimension 0 + @param i1 Index along the dimension 1 + @param i2 Index along the dimension 2 + */ + template _Tp& at(int i0, int i1, int i2); + /** @overload + @param i0 Index along the dimension 0 + @param i1 Index along the dimension 1 + @param i2 Index along the dimension 2 + */ + template const _Tp& at(int i0, int i1, int i2) const; + + /** @overload + @param idx Array of Mat::dims indices. + */ + template _Tp& at(const int* idx); + /** @overload + @param idx Array of Mat::dims indices. + */ + template const _Tp& at(const int* idx) const; + + /** @overload */ + template _Tp& at(const Vec& idx); + /** @overload */ + template const _Tp& at(const Vec& idx) const; + + /** @overload + special versions for 2D arrays (especially convenient for referencing image pixels) + @param pt Element position specified as Point(j,i) . + */ + template _Tp& at(Point pt); + /** @overload + special versions for 2D arrays (especially convenient for referencing image pixels) + @param pt Element position specified as Point(j,i) . + */ + template const _Tp& at(Point pt) const; + + /** @brief Returns the matrix iterator and sets it to the first matrix element. + + The methods return the matrix read-only or read-write iterators. The use of matrix iterators is very + similar to the use of bi-directional STL iterators. In the example below, the alpha blending + function is rewritten using the matrix iterators: + @code + template + void alphaBlendRGBA(const Mat& src1, const Mat& src2, Mat& dst) + { + typedef Vec VT; + + const float alpha_scale = (float)std::numeric_limits::max(), + inv_scale = 1.f/alpha_scale; + + CV_Assert( src1.type() == src2.type() && + src1.type() == traits::Type::value && + src1.size() == src2.size()); + Size size = src1.size(); + dst.create(size, src1.type()); + + MatConstIterator_ it1 = src1.begin(), it1_end = src1.end(); + MatConstIterator_ it2 = src2.begin(); + MatIterator_ dst_it = dst.begin(); + + for( ; it1 != it1_end; ++it1, ++it2, ++dst_it ) + { + VT pix1 = *it1, pix2 = *it2; + float alpha = pix1[3]*inv_scale, beta = pix2[3]*inv_scale; + *dst_it = VT(saturate_cast(pix1[0]*alpha + pix2[0]*beta), + saturate_cast(pix1[1]*alpha + pix2[1]*beta), + saturate_cast(pix1[2]*alpha + pix2[2]*beta), + saturate_cast((1 - (1-alpha)*(1-beta))*alpha_scale)); + } + } + @endcode + */ + template MatIterator_<_Tp> begin(); + template MatConstIterator_<_Tp> begin() const; + + /** @brief Returns the matrix iterator and sets it to the after-last matrix element. + + The methods return the matrix read-only or read-write iterators, set to the point following the last + matrix element. + */ + template MatIterator_<_Tp> end(); + template MatConstIterator_<_Tp> end() const; + + /** @brief Runs the given functor over all matrix elements in parallel. + + The operation passed as argument has to be a function pointer, a function object or a lambda(C++11). + + Example 1. All of the operations below put 0xFF the first channel of all matrix elements: + @code + Mat image(1920, 1080, CV_8UC3); + typedef cv::Point3_ Pixel; + + // first. raw pointer access. + for (int r = 0; r < image.rows; ++r) { + Pixel* ptr = image.ptr(r, 0); + const Pixel* ptr_end = ptr + image.cols; + for (; ptr != ptr_end; ++ptr) { + ptr->x = 255; + } + } + + // Using MatIterator. (Simple but there are a Iterator's overhead) + for (Pixel &p : cv::Mat_(image)) { + p.x = 255; + } + + // Parallel execution with function object. + struct Operator { + void operator ()(Pixel &pixel, const int * position) { + pixel.x = 255; + } + }; + image.forEach(Operator()); + + // Parallel execution using C++11 lambda. + image.forEach([](Pixel &p, const int * position) -> void { + p.x = 255; + }); + @endcode + Example 2. Using the pixel's position: + @code + // Creating 3D matrix (255 x 255 x 255) typed uint8_t + // and initialize all elements by the value which equals elements position. + // i.e. pixels (x,y,z) = (1,2,3) is (b,g,r) = (1,2,3). + + int sizes[] = { 255, 255, 255 }; + typedef cv::Point3_ Pixel; + + Mat_ image = Mat::zeros(3, sizes, CV_8UC3); + + image.forEach([&](Pixel& pixel, const int position[]) -> void { + pixel.x = position[0]; + pixel.y = position[1]; + pixel.z = position[2]; + }); + @endcode + */ + template void forEach(const Functor& operation); + /** @overload */ + template void forEach(const Functor& operation) const; + + Mat(Mat&& m); + Mat& operator = (Mat&& m); + + enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; + enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; + + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + //! the matrix dimensionality, >= 2 + int dims; + //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions + int rows, cols; + //! pointer to the data + uchar* data; + + //! helper fields used in locateROI and adjustROI + const uchar* datastart; + const uchar* dataend; + const uchar* datalimit; + + //! custom allocator + MatAllocator* allocator; + //! and the standard allocator + static MatAllocator* getStdAllocator(); + static MatAllocator* getDefaultAllocator(); + static void setDefaultAllocator(MatAllocator* allocator); + + //! internal use method: updates the continuity flag + void updateContinuityFlag(); + + //! interaction with UMat + UMatData* u; + + MatSize size; + MatStep step; + +protected: + template void forEach_impl(const Functor& operation); +}; + + +///////////////////////////////// Mat_<_Tp> //////////////////////////////////// + +/** @brief Template matrix class derived from Mat + +@code{.cpp} + template class Mat_ : public Mat + { + public: + // ... some specific methods + // and + // no new extra fields + }; +@endcode +The class `Mat_<_Tp>` is a *thin* template wrapper on top of the Mat class. It does not have any +extra data fields. Nor this class nor Mat has any virtual methods. Thus, references or pointers to +these two classes can be freely but carefully converted one to another. For example: +@code{.cpp} + // create a 100x100 8-bit matrix + Mat M(100,100,CV_8U); + // this will be compiled fine. no any data conversion will be done. + Mat_& M1 = (Mat_&)M; + // the program is likely to crash at the statement below + M1(99,99) = 1.f; +@endcode +While Mat is sufficient in most cases, Mat_ can be more convenient if you use a lot of element +access operations and if you know matrix type at the compilation time. Note that +`Mat::at(int y,int x)` and `Mat_::operator()(int y,int x)` do absolutely the same +and run at the same speed, but the latter is certainly shorter: +@code{.cpp} + Mat_ M(20,20); + for(int i = 0; i < M.rows; i++) + for(int j = 0; j < M.cols; j++) + M(i,j) = 1./(i+j+1); + Mat E, V; + eigen(M,E,V); + cout << E.at(0,0)/E.at(M.rows-1,0); +@endcode +To use Mat_ for multi-channel images/matrices, pass Vec as a Mat_ parameter: +@code{.cpp} + // allocate a 320x240 color image and fill it with green (in RGB space) + Mat_ img(240, 320, Vec3b(0,255,0)); + // now draw a diagonal white line + for(int i = 0; i < 100; i++) + img(i,i)=Vec3b(255,255,255); + // and now scramble the 2nd (red) channel of each pixel + for(int i = 0; i < img.rows; i++) + for(int j = 0; j < img.cols; j++) + img(i,j)[2] ^= (uchar)(i ^ j); +@endcode +Mat_ is fully compatible with C++11 range-based for loop. For example such loop +can be used to safely apply look-up table: +@code{.cpp} +void applyTable(Mat_& I, const uchar* const table) +{ + for(auto& pixel : I) + { + pixel = table[pixel]; + } +} +@endcode + */ +template class Mat_ : public Mat +{ +public: + typedef _Tp value_type; + typedef typename DataType<_Tp>::channel_type channel_type; + typedef MatIterator_<_Tp> iterator; + typedef MatConstIterator_<_Tp> const_iterator; + + //! default constructor + Mat_(); + //! equivalent to Mat(_rows, _cols, DataType<_Tp>::type) + Mat_(int _rows, int _cols); + //! constructor that sets each matrix element to specified value + Mat_(int _rows, int _cols, const _Tp& value); + //! equivalent to Mat(_size, DataType<_Tp>::type) + explicit Mat_(Size _size); + //! constructor that sets each matrix element to specified value + Mat_(Size _size, const _Tp& value); + //! n-dim array constructor + Mat_(int _ndims, const int* _sizes); + //! n-dim array constructor that sets each matrix element to specified value + Mat_(int _ndims, const int* _sizes, const _Tp& value); + //! copy/conversion constructor. If m is of different type, it's converted + Mat_(const Mat& m); + //! copy constructor + Mat_(const Mat_& m); + //! constructs a matrix on top of user-allocated data. step is in bytes(!!!), regardless of the type + Mat_(int _rows, int _cols, _Tp* _data, size_t _step=AUTO_STEP); + //! constructs n-dim matrix on top of user-allocated data. steps are in bytes(!!!), regardless of the type + Mat_(int _ndims, const int* _sizes, _Tp* _data, const size_t* _steps=0); + //! selects a submatrix + Mat_(const Mat_& m, const Range& rowRange, const Range& colRange=Range::all()); + //! selects a submatrix + Mat_(const Mat_& m, const Rect& roi); + //! selects a submatrix, n-dim version + Mat_(const Mat_& m, const Range* ranges); + //! selects a submatrix, n-dim version + Mat_(const Mat_& m, const std::vector& ranges); + //! from a matrix expression + explicit Mat_(const MatExpr& e); + //! makes a matrix out of Vec, std::vector, Point_ or Point3_. The matrix will have a single column + explicit Mat_(const std::vector<_Tp>& vec, bool copyData=false); + template explicit Mat_(const Vec::channel_type, n>& vec, bool copyData=true); + template explicit Mat_(const Matx::channel_type, m, n>& mtx, bool copyData=true); + explicit Mat_(const Point_::channel_type>& pt, bool copyData=true); + explicit Mat_(const Point3_::channel_type>& pt, bool copyData=true); + explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer); + + Mat_(std::initializer_list<_Tp> values); + explicit Mat_(const std::initializer_list sizes, const std::initializer_list<_Tp> values); + + template explicit Mat_(const std::array<_Tp, _Nm>& arr, bool copyData=false); + + Mat_& operator = (const Mat& m); + Mat_& operator = (const Mat_& m); + //! set all the elements to s. + Mat_& operator = (const _Tp& s); + //! assign a matrix expression + Mat_& operator = (const MatExpr& e); + + //! iterators; they are smart enough to skip gaps in the end of rows + iterator begin(); + iterator end(); + const_iterator begin() const; + const_iterator end() const; + + //! template methods for for operation over all matrix elements. + // the operations take care of skipping gaps in the end of rows (if any) + template void forEach(const Functor& operation); + template void forEach(const Functor& operation) const; + + //! equivalent to Mat::create(_rows, _cols, DataType<_Tp>::type) + void create(int _rows, int _cols); + //! equivalent to Mat::create(_size, DataType<_Tp>::type) + void create(Size _size); + //! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type) + void create(int _ndims, const int* _sizes); + //! equivalent to Mat::release() + void release(); + //! cross-product + Mat_ cross(const Mat_& m) const; + //! data type conversion + template operator Mat_() const; + //! overridden forms of Mat::row() etc. + Mat_ row(int y) const; + Mat_ col(int x) const; + Mat_ diag(int d=0) const; + Mat_ clone() const CV_NODISCARD; + + //! overridden forms of Mat::elemSize() etc. + size_t elemSize() const; + size_t elemSize1() const; + int type() const; + int depth() const; + int channels() const; + size_t step1(int i=0) const; + //! returns step()/sizeof(_Tp) + size_t stepT(int i=0) const; + + //! overridden forms of Mat::zeros() etc. Data type is omitted, of course + static MatExpr zeros(int rows, int cols); + static MatExpr zeros(Size size); + static MatExpr zeros(int _ndims, const int* _sizes); + static MatExpr ones(int rows, int cols); + static MatExpr ones(Size size); + static MatExpr ones(int _ndims, const int* _sizes); + static MatExpr eye(int rows, int cols); + static MatExpr eye(Size size); + + //! some more overridden methods + Mat_& adjustROI( int dtop, int dbottom, int dleft, int dright ); + Mat_ operator()( const Range& rowRange, const Range& colRange ) const; + Mat_ operator()( const Rect& roi ) const; + Mat_ operator()( const Range* ranges ) const; + Mat_ operator()(const std::vector& ranges) const; + + //! more convenient forms of row and element access operators + _Tp* operator [](int y); + const _Tp* operator [](int y) const; + + //! returns reference to the specified element + _Tp& operator ()(const int* idx); + //! returns read-only reference to the specified element + const _Tp& operator ()(const int* idx) const; + + //! returns reference to the specified element + template _Tp& operator ()(const Vec& idx); + //! returns read-only reference to the specified element + template const _Tp& operator ()(const Vec& idx) const; + + //! returns reference to the specified element (1D case) + _Tp& operator ()(int idx0); + //! returns read-only reference to the specified element (1D case) + const _Tp& operator ()(int idx0) const; + //! returns reference to the specified element (2D case) + _Tp& operator ()(int row, int col); + //! returns read-only reference to the specified element (2D case) + const _Tp& operator ()(int row, int col) const; + //! returns reference to the specified element (3D case) + _Tp& operator ()(int idx0, int idx1, int idx2); + //! returns read-only reference to the specified element (3D case) + const _Tp& operator ()(int idx0, int idx1, int idx2) const; + + _Tp& operator ()(Point pt); + const _Tp& operator ()(Point pt) const; + + //! conversion to vector. + operator std::vector<_Tp>() const; + + //! conversion to array. + template operator std::array<_Tp, _Nm>() const; + + //! conversion to Vec + template operator Vec::channel_type, n>() const; + //! conversion to Matx + template operator Matx::channel_type, m, n>() const; + + Mat_(Mat_&& m); + Mat_& operator = (Mat_&& m); + + Mat_(Mat&& m); + Mat_& operator = (Mat&& m); + + Mat_(MatExpr&& e); +}; + +typedef Mat_ Mat1b; +typedef Mat_ Mat2b; +typedef Mat_ Mat3b; +typedef Mat_ Mat4b; + +typedef Mat_ Mat1s; +typedef Mat_ Mat2s; +typedef Mat_ Mat3s; +typedef Mat_ Mat4s; + +typedef Mat_ Mat1w; +typedef Mat_ Mat2w; +typedef Mat_ Mat3w; +typedef Mat_ Mat4w; + +typedef Mat_ Mat1i; +typedef Mat_ Mat2i; +typedef Mat_ Mat3i; +typedef Mat_ Mat4i; + +typedef Mat_ Mat1f; +typedef Mat_ Mat2f; +typedef Mat_ Mat3f; +typedef Mat_ Mat4f; + +typedef Mat_ Mat1d; +typedef Mat_ Mat2d; +typedef Mat_ Mat3d; +typedef Mat_ Mat4d; + +/** @todo document */ +class CV_EXPORTS UMat +{ +public: + //! default constructor + UMat(UMatUsageFlags usageFlags = USAGE_DEFAULT); + //! constructs 2D matrix of the specified size and type + // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) + UMat(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + //! constructs 2D matrix and fills it with the specified value _s. + UMat(int rows, int cols, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(Size size, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); + + //! constructs n-dimensional matrix + UMat(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(int ndims, const int* sizes, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); + + //! copy constructor + UMat(const UMat& m); + + //! creates a matrix header for a part of the bigger matrix + UMat(const UMat& m, const Range& rowRange, const Range& colRange=Range::all()); + UMat(const UMat& m, const Rect& roi); + UMat(const UMat& m, const Range* ranges); + UMat(const UMat& m, const std::vector& ranges); + //! builds matrix from std::vector with or without copying the data + template explicit UMat(const std::vector<_Tp>& vec, bool copyData=false); + + //! builds matrix from cv::Vec; the data is copied by default + template explicit UMat(const Vec<_Tp, n>& vec, bool copyData=true); + //! builds matrix from cv::Matx; the data is copied by default + template explicit UMat(const Matx<_Tp, m, n>& mtx, bool copyData=true); + //! builds matrix from a 2D point + template explicit UMat(const Point_<_Tp>& pt, bool copyData=true); + //! builds matrix from a 3D point + template explicit UMat(const Point3_<_Tp>& pt, bool copyData=true); + //! builds matrix from comma initializer + template explicit UMat(const MatCommaInitializer_<_Tp>& commaInitializer); + + //! destructor - calls release() + ~UMat(); + //! assignment operators + UMat& operator = (const UMat& m); + + Mat getMat(AccessFlag flags) const; + + //! returns a new matrix header for the specified row + UMat row(int y) const; + //! returns a new matrix header for the specified column + UMat col(int x) const; + //! ... for the specified row span + UMat rowRange(int startrow, int endrow) const; + UMat rowRange(const Range& r) const; + //! ... for the specified column span + UMat colRange(int startcol, int endcol) const; + UMat colRange(const Range& r) const; + //! ... for the specified diagonal + //! (d=0 - the main diagonal, + //! >0 - a diagonal from the upper half, + //! <0 - a diagonal from the lower half) + UMat diag(int d=0) const; + //! constructs a square diagonal matrix which main diagonal is vector "d" + static UMat diag(const UMat& d); + + //! returns deep copy of the matrix, i.e. the data is copied + UMat clone() const CV_NODISCARD; + //! copies the matrix content to "m". + // It calls m.create(this->size(), this->type()). + void copyTo( OutputArray m ) const; + //! copies those matrix elements to "m" that are marked with non-zero mask elements. + void copyTo( OutputArray m, InputArray mask ) const; + //! converts matrix to another datatype with optional scaling. See cvConvertScale. + void convertTo( OutputArray m, int rtype, double alpha=1, double beta=0 ) const; + + void assignTo( UMat& m, int type=-1 ) const; + + //! sets every matrix element to s + UMat& operator = (const Scalar& s); + //! sets some of the matrix elements to s, according to the mask + UMat& setTo(InputArray value, InputArray mask=noArray()); + //! creates alternative matrix header for the same data, with different + // number of channels and/or different number of rows. see cvReshape. + UMat reshape(int cn, int rows=0) const; + UMat reshape(int cn, int newndims, const int* newsz) const; + + //! matrix transposition by means of matrix expressions + UMat t() const; + //! matrix inversion by means of matrix expressions + UMat inv(int method=DECOMP_LU) const; + //! per-element matrix multiplication by means of matrix expressions + UMat mul(InputArray m, double scale=1) const; + + //! computes dot-product + double dot(InputArray m) const; + + //! Matlab-style matrix initialization + static UMat zeros(int rows, int cols, int type); + static UMat zeros(Size size, int type); + static UMat zeros(int ndims, const int* sz, int type); + static UMat ones(int rows, int cols, int type); + static UMat ones(Size size, int type); + static UMat ones(int ndims, const int* sz, int type); + static UMat eye(int rows, int cols, int type); + static UMat eye(Size size, int type); + + //! allocates new matrix data unless the matrix already has specified size and type. + // previous data is unreferenced if needed. + void create(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + void create(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + void create(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + void create(const std::vector& sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + + //! increases the reference counter; use with care to avoid memleaks + void addref(); + //! decreases reference counter; + // deallocates the data when reference counter reaches 0. + void release(); + + //! deallocates the matrix data + void deallocate(); + //! internal use function; properly re-allocates _size, _step arrays + void copySize(const UMat& m); + + //! locates matrix header within a parent matrix. See below + void locateROI( Size& wholeSize, Point& ofs ) const; + //! moves/resizes the current matrix ROI inside the parent matrix. + UMat& adjustROI( int dtop, int dbottom, int dleft, int dright ); + //! extracts a rectangular sub-matrix + // (this is a generalized form of row, rowRange etc.) + UMat operator()( Range rowRange, Range colRange ) const; + UMat operator()( const Rect& roi ) const; + UMat operator()( const Range* ranges ) const; + UMat operator()(const std::vector& ranges) const; + + //! returns true iff the matrix data is continuous + // (i.e. when there are no gaps between successive rows). + // similar to CV_IS_MAT_CONT(cvmat->type) + bool isContinuous() const; + + //! returns true if the matrix is a submatrix of another matrix + bool isSubmatrix() const; + + //! returns element size in bytes, + // similar to CV_ELEM_SIZE(cvmat->type) + size_t elemSize() const; + //! returns the size of element channel in bytes. + size_t elemSize1() const; + //! returns element type, similar to CV_MAT_TYPE(cvmat->type) + int type() const; + //! returns element type, similar to CV_MAT_DEPTH(cvmat->type) + int depth() const; + //! returns element type, similar to CV_MAT_CN(cvmat->type) + int channels() const; + //! returns step/elemSize1() + size_t step1(int i=0) const; + //! returns true if matrix data is NULL + bool empty() const; + //! returns the total number of matrix elements + size_t total() const; + + //! returns N if the matrix is 1-channel (N x ptdim) or ptdim-channel (1 x N) or (N x 1); negative number otherwise + int checkVector(int elemChannels, int depth=-1, bool requireContinuous=true) const; + + UMat(UMat&& m); + UMat& operator = (UMat&& m); + + /*! Returns the OpenCL buffer handle on which UMat operates on. + The UMat instance should be kept alive during the use of the handle to prevent the buffer to be + returned to the OpenCV buffer pool. + */ + void* handle(AccessFlag accessFlags) const; + void ndoffset(size_t* ofs) const; + + enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; + enum { MAGIC_MASK = 0xFFFF0000, TYPE_MASK = 0x00000FFF, DEPTH_MASK = 7 }; + + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + //! the matrix dimensionality, >= 2 + int dims; + //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions + int rows, cols; + + //! custom allocator + MatAllocator* allocator; + UMatUsageFlags usageFlags; // usage flags for allocator + //! and the standard allocator + static MatAllocator* getStdAllocator(); + + //! internal use method: updates the continuity flag + void updateContinuityFlag(); + + // black-box container of UMat data + UMatData* u; + + // offset of the submatrix (or 0) + size_t offset; + + MatSize size; + MatStep step; + +protected: +}; + + +/////////////////////////// multi-dimensional sparse matrix ////////////////////////// + +/** @brief The class SparseMat represents multi-dimensional sparse numerical arrays. + +Such a sparse array can store elements of any type that Mat can store. *Sparse* means that only +non-zero elements are stored (though, as a result of operations on a sparse matrix, some of its +stored elements can actually become 0. It is up to you to detect such elements and delete them +using SparseMat::erase ). The non-zero elements are stored in a hash table that grows when it is +filled so that the search time is O(1) in average (regardless of whether element is there or not). +Elements can be accessed using the following methods: +- Query operations (SparseMat::ptr and the higher-level SparseMat::ref, SparseMat::value and + SparseMat::find), for example: + @code + const int dims = 5; + int size[5] = {10, 10, 10, 10, 10}; + SparseMat sparse_mat(dims, size, CV_32F); + for(int i = 0; i < 1000; i++) + { + int idx[dims]; + for(int k = 0; k < dims; k++) + idx[k] = rand() % size[k]; + sparse_mat.ref(idx) += 1.f; + } + cout << "nnz = " << sparse_mat.nzcount() << endl; + @endcode +- Sparse matrix iterators. They are similar to MatIterator but different from NAryMatIterator. + That is, the iteration loop is familiar to STL users: + @code + // prints elements of a sparse floating-point matrix + // and the sum of elements. + SparseMatConstIterator_ + it = sparse_mat.begin(), + it_end = sparse_mat.end(); + double s = 0; + int dims = sparse_mat.dims(); + for(; it != it_end; ++it) + { + // print element indices and the element value + const SparseMat::Node* n = it.node(); + printf("("); + for(int i = 0; i < dims; i++) + printf("%d%s", n->idx[i], i < dims-1 ? ", " : ")"); + printf(": %g\n", it.value()); + s += *it; + } + printf("Element sum is %g\n", s); + @endcode + If you run this loop, you will notice that elements are not enumerated in a logical order + (lexicographical, and so on). They come in the same order as they are stored in the hash table + (semi-randomly). You may collect pointers to the nodes and sort them to get the proper ordering. + Note, however, that pointers to the nodes may become invalid when you add more elements to the + matrix. This may happen due to possible buffer reallocation. +- Combination of the above 2 methods when you need to process 2 or more sparse matrices + simultaneously. For example, this is how you can compute unnormalized cross-correlation of the 2 + floating-point sparse matrices: + @code + double cross_corr(const SparseMat& a, const SparseMat& b) + { + const SparseMat *_a = &a, *_b = &b; + // if b contains less elements than a, + // it is faster to iterate through b + if(_a->nzcount() > _b->nzcount()) + std::swap(_a, _b); + SparseMatConstIterator_ it = _a->begin(), + it_end = _a->end(); + double ccorr = 0; + for(; it != it_end; ++it) + { + // take the next element from the first matrix + float avalue = *it; + const Node* anode = it.node(); + // and try to find an element with the same index in the second matrix. + // since the hash value depends only on the element index, + // reuse the hash value stored in the node + float bvalue = _b->value(anode->idx,&anode->hashval); + ccorr += avalue*bvalue; + } + return ccorr; + } + @endcode + */ +class CV_EXPORTS SparseMat +{ +public: + typedef SparseMatIterator iterator; + typedef SparseMatConstIterator const_iterator; + + enum { MAGIC_VAL=0x42FD0000, MAX_DIM=32, HASH_SCALE=0x5bd1e995, HASH_BIT=0x80000000 }; + + //! the sparse matrix header + struct CV_EXPORTS Hdr + { + Hdr(int _dims, const int* _sizes, int _type); + void clear(); + int refcount; + int dims; + int valueOffset; + size_t nodeSize; + size_t nodeCount; + size_t freeList; + std::vector pool; + std::vector hashtab; + int size[MAX_DIM]; + }; + + //! sparse matrix node - element of a hash table + struct CV_EXPORTS Node + { + //! hash value + size_t hashval; + //! index of the next node in the same hash table entry + size_t next; + //! index of the matrix element + int idx[MAX_DIM]; + }; + + /** @brief Various SparseMat constructors. + */ + SparseMat(); + + /** @overload + @param dims Array dimensionality. + @param _sizes Sparce matrix size on all dementions. + @param _type Sparse matrix data type. + */ + SparseMat(int dims, const int* _sizes, int _type); + + /** @overload + @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted + to sparse representation. + */ + SparseMat(const SparseMat& m); + + /** @overload + @param m Source matrix for copy constructor. If m is dense matrix (ocvMat) then it will be converted + to sparse representation. + */ + explicit SparseMat(const Mat& m); + + //! the destructor + ~SparseMat(); + + //! assignment operator. This is O(1) operation, i.e. no data is copied + SparseMat& operator = (const SparseMat& m); + //! equivalent to the corresponding constructor + SparseMat& operator = (const Mat& m); + + //! creates full copy of the matrix + SparseMat clone() const CV_NODISCARD; + + //! copies all the data to the destination matrix. All the previous content of m is erased + void copyTo( SparseMat& m ) const; + //! converts sparse matrix to dense matrix. + void copyTo( Mat& m ) const; + //! multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type + void convertTo( SparseMat& m, int rtype, double alpha=1 ) const; + //! converts sparse matrix to dense n-dim matrix with optional type conversion and scaling. + /*! + @param [out] m - output matrix; if it does not have a proper size or type before the operation, + it is reallocated + @param [in] rtype - desired output matrix type or, rather, the depth since the number of channels + are the same as the input has; if rtype is negative, the output matrix will have the + same type as the input. + @param [in] alpha - optional scale factor + @param [in] beta - optional delta added to the scaled values + */ + void convertTo( Mat& m, int rtype, double alpha=1, double beta=0 ) const; + + // not used now + void assignTo( SparseMat& m, int type=-1 ) const; + + //! reallocates sparse matrix. + /*! + If the matrix already had the proper size and type, + it is simply cleared with clear(), otherwise, + the old matrix is released (using release()) and the new one is allocated. + */ + void create(int dims, const int* _sizes, int _type); + //! sets all the sparse matrix elements to 0, which means clearing the hash table. + void clear(); + //! manually increments the reference counter to the header. + void addref(); + // decrements the header reference counter. When the counter reaches 0, the header and all the underlying data are deallocated. + void release(); + + //! converts sparse matrix to the old-style representation; all the elements are copied. + //operator CvSparseMat*() const; + //! returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements) + size_t elemSize() const; + //! returns elemSize()/channels() + size_t elemSize1() const; + + //! returns type of sparse matrix elements + int type() const; + //! returns the depth of sparse matrix elements + int depth() const; + //! returns the number of channels + int channels() const; + + //! returns the array of sizes, or NULL if the matrix is not allocated + const int* size() const; + //! returns the size of i-th matrix dimension (or 0) + int size(int i) const; + //! returns the matrix dimensionality + int dims() const; + //! returns the number of non-zero elements (=the number of hash table nodes) + size_t nzcount() const; + + //! computes the element hash value (1D case) + size_t hash(int i0) const; + //! computes the element hash value (2D case) + size_t hash(int i0, int i1) const; + //! computes the element hash value (3D case) + size_t hash(int i0, int i1, int i2) const; + //! computes the element hash value (nD case) + size_t hash(const int* idx) const; + + //!@{ + /*! + specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case. + return pointer to the matrix element. + - if the element is there (it's non-zero), the pointer to it is returned + - if it's not there and createMissing=false, NULL pointer is returned + - if it's not there and createMissing=true, then the new element + is created and initialized with 0. Pointer to it is returned + - if the optional hashval pointer is not NULL, the element hash value is + not computed, but *hashval is taken instead. + */ + //! returns pointer to the specified element (1D case) + uchar* ptr(int i0, bool createMissing, size_t* hashval=0); + //! returns pointer to the specified element (2D case) + uchar* ptr(int i0, int i1, bool createMissing, size_t* hashval=0); + //! returns pointer to the specified element (3D case) + uchar* ptr(int i0, int i1, int i2, bool createMissing, size_t* hashval=0); + //! returns pointer to the specified element (nD case) + uchar* ptr(const int* idx, bool createMissing, size_t* hashval=0); + //!@} + + //!@{ + /*! + return read-write reference to the specified sparse matrix element. + + `ref<_Tp>(i0,...[,hashval])` is equivalent to `*(_Tp*)ptr(i0,...,true[,hashval])`. + The methods always return a valid reference. + If the element did not exist, it is created and initialized with 0. + */ + //! returns reference to the specified element (1D case) + template _Tp& ref(int i0, size_t* hashval=0); + //! returns reference to the specified element (2D case) + template _Tp& ref(int i0, int i1, size_t* hashval=0); + //! returns reference to the specified element (3D case) + template _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); + //! returns reference to the specified element (nD case) + template _Tp& ref(const int* idx, size_t* hashval=0); + //!@} + + //!@{ + /*! + return value of the specified sparse matrix element. + + `value<_Tp>(i0,...[,hashval])` is equivalent to + @code + { const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); } + @endcode + + That is, if the element did not exist, the methods return 0. + */ + //! returns value of the specified element (1D case) + template _Tp value(int i0, size_t* hashval=0) const; + //! returns value of the specified element (2D case) + template _Tp value(int i0, int i1, size_t* hashval=0) const; + //! returns value of the specified element (3D case) + template _Tp value(int i0, int i1, int i2, size_t* hashval=0) const; + //! returns value of the specified element (nD case) + template _Tp value(const int* idx, size_t* hashval=0) const; + //!@} + + //!@{ + /*! + Return pointer to the specified sparse matrix element if it exists + + `find<_Tp>(i0,...[,hashval])` is equivalent to `(_const Tp*)ptr(i0,...false[,hashval])`. + + If the specified element does not exist, the methods return NULL. + */ + //! returns pointer to the specified element (1D case) + template const _Tp* find(int i0, size_t* hashval=0) const; + //! returns pointer to the specified element (2D case) + template const _Tp* find(int i0, int i1, size_t* hashval=0) const; + //! returns pointer to the specified element (3D case) + template const _Tp* find(int i0, int i1, int i2, size_t* hashval=0) const; + //! returns pointer to the specified element (nD case) + template const _Tp* find(const int* idx, size_t* hashval=0) const; + //!@} + + //! erases the specified element (2D case) + void erase(int i0, int i1, size_t* hashval=0); + //! erases the specified element (3D case) + void erase(int i0, int i1, int i2, size_t* hashval=0); + //! erases the specified element (nD case) + void erase(const int* idx, size_t* hashval=0); + + //!@{ + /*! + return the sparse matrix iterator pointing to the first sparse matrix element + */ + //! returns the sparse matrix iterator at the matrix beginning + SparseMatIterator begin(); + //! returns the sparse matrix iterator at the matrix beginning + template SparseMatIterator_<_Tp> begin(); + //! returns the read-only sparse matrix iterator at the matrix beginning + SparseMatConstIterator begin() const; + //! returns the read-only sparse matrix iterator at the matrix beginning + template SparseMatConstIterator_<_Tp> begin() const; + //!@} + /*! + return the sparse matrix iterator pointing to the element following the last sparse matrix element + */ + //! returns the sparse matrix iterator at the matrix end + SparseMatIterator end(); + //! returns the read-only sparse matrix iterator at the matrix end + SparseMatConstIterator end() const; + //! returns the typed sparse matrix iterator at the matrix end + template SparseMatIterator_<_Tp> end(); + //! returns the typed read-only sparse matrix iterator at the matrix end + template SparseMatConstIterator_<_Tp> end() const; + + //! returns the value stored in the sparse martix node + template _Tp& value(Node* n); + //! returns the value stored in the sparse martix node + template const _Tp& value(const Node* n) const; + + ////////////// some internal-use methods /////////////// + Node* node(size_t nidx); + const Node* node(size_t nidx) const; + + uchar* newNode(const int* idx, size_t hashval); + void removeNode(size_t hidx, size_t nidx, size_t previdx); + void resizeHashTab(size_t newsize); + + int flags; + Hdr* hdr; +}; + + + +///////////////////////////////// SparseMat_<_Tp> //////////////////////////////////// + +/** @brief Template sparse n-dimensional array class derived from SparseMat + +SparseMat_ is a thin wrapper on top of SparseMat created in the same way as Mat_ . It simplifies +notation of some operations: +@code + int sz[] = {10, 20, 30}; + SparseMat_ M(3, sz); + ... + M.ref(1, 2, 3) = M(4, 5, 6) + M(7, 8, 9); +@endcode + */ +template class SparseMat_ : public SparseMat +{ +public: + typedef SparseMatIterator_<_Tp> iterator; + typedef SparseMatConstIterator_<_Tp> const_iterator; + + //! the default constructor + SparseMat_(); + //! the full constructor equivalent to SparseMat(dims, _sizes, DataType<_Tp>::type) + SparseMat_(int dims, const int* _sizes); + //! the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted + SparseMat_(const SparseMat& m); + //! the copy constructor. This is O(1) operation - no data is copied + SparseMat_(const SparseMat_& m); + //! converts dense matrix to the sparse form + SparseMat_(const Mat& m); + //! converts the old-style sparse matrix to the C++ class. All the elements are copied + //SparseMat_(const CvSparseMat* m); + //! the assignment operator. If DataType<_Tp>.type != m.type(), the m elements are converted + SparseMat_& operator = (const SparseMat& m); + //! the assignment operator. This is O(1) operation - no data is copied + SparseMat_& operator = (const SparseMat_& m); + //! converts dense matrix to the sparse form + SparseMat_& operator = (const Mat& m); + + //! makes full copy of the matrix. All the elements are duplicated + SparseMat_ clone() const CV_NODISCARD; + //! equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type) + void create(int dims, const int* _sizes); + //! converts sparse matrix to the old-style CvSparseMat. All the elements are copied + //operator CvSparseMat*() const; + + //! returns type of the matrix elements + int type() const; + //! returns depth of the matrix elements + int depth() const; + //! returns the number of channels in each matrix element + int channels() const; + + //! equivalent to SparseMat::ref<_Tp>(i0, hashval) + _Tp& ref(int i0, size_t* hashval=0); + //! equivalent to SparseMat::ref<_Tp>(i0, i1, hashval) + _Tp& ref(int i0, int i1, size_t* hashval=0); + //! equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval) + _Tp& ref(int i0, int i1, int i2, size_t* hashval=0); + //! equivalent to SparseMat::ref<_Tp>(idx, hashval) + _Tp& ref(const int* idx, size_t* hashval=0); + + //! equivalent to SparseMat::value<_Tp>(i0, hashval) + _Tp operator()(int i0, size_t* hashval=0) const; + //! equivalent to SparseMat::value<_Tp>(i0, i1, hashval) + _Tp operator()(int i0, int i1, size_t* hashval=0) const; + //! equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval) + _Tp operator()(int i0, int i1, int i2, size_t* hashval=0) const; + //! equivalent to SparseMat::value<_Tp>(idx, hashval) + _Tp operator()(const int* idx, size_t* hashval=0) const; + + //! returns sparse matrix iterator pointing to the first sparse matrix element + SparseMatIterator_<_Tp> begin(); + //! returns read-only sparse matrix iterator pointing to the first sparse matrix element + SparseMatConstIterator_<_Tp> begin() const; + //! returns sparse matrix iterator pointing to the element following the last sparse matrix element + SparseMatIterator_<_Tp> end(); + //! returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element + SparseMatConstIterator_<_Tp> end() const; +}; + + + +////////////////////////////////// MatConstIterator ////////////////////////////////// + +class CV_EXPORTS MatConstIterator +{ +public: + typedef uchar* value_type; + typedef ptrdiff_t difference_type; + typedef const uchar** pointer; + typedef uchar* reference; + + typedef std::random_access_iterator_tag iterator_category; + + //! default constructor + MatConstIterator(); + //! constructor that sets the iterator to the beginning of the matrix + MatConstIterator(const Mat* _m); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator(const Mat* _m, int _row, int _col=0); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator(const Mat* _m, Point _pt); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator(const Mat* _m, const int* _idx); + //! copy constructor + MatConstIterator(const MatConstIterator& it); + + //! copy operator + MatConstIterator& operator = (const MatConstIterator& it); + //! returns the current matrix element + const uchar* operator *() const; + //! returns the i-th matrix element, relative to the current + const uchar* operator [](ptrdiff_t i) const; + + //! shifts the iterator forward by the specified number of elements + MatConstIterator& operator += (ptrdiff_t ofs); + //! shifts the iterator backward by the specified number of elements + MatConstIterator& operator -= (ptrdiff_t ofs); + //! decrements the iterator + MatConstIterator& operator --(); + //! decrements the iterator + MatConstIterator operator --(int); + //! increments the iterator + MatConstIterator& operator ++(); + //! increments the iterator + MatConstIterator operator ++(int); + //! returns the current iterator position + Point pos() const; + //! returns the current iterator position + void pos(int* _idx) const; + + ptrdiff_t lpos() const; + void seek(ptrdiff_t ofs, bool relative = false); + void seek(const int* _idx, bool relative = false); + + const Mat* m; + size_t elemSize; + const uchar* ptr; + const uchar* sliceStart; + const uchar* sliceEnd; +}; + + + +////////////////////////////////// MatConstIterator_ ///////////////////////////////// + +/** @brief Matrix read-only iterator + */ +template +class MatConstIterator_ : public MatConstIterator +{ +public: + typedef _Tp value_type; + typedef ptrdiff_t difference_type; + typedef const _Tp* pointer; + typedef const _Tp& reference; + + typedef std::random_access_iterator_tag iterator_category; + + //! default constructor + MatConstIterator_(); + //! constructor that sets the iterator to the beginning of the matrix + MatConstIterator_(const Mat_<_Tp>* _m); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col=0); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator_(const Mat_<_Tp>* _m, Point _pt); + //! constructor that sets the iterator to the specified element of the matrix + MatConstIterator_(const Mat_<_Tp>* _m, const int* _idx); + //! copy constructor + MatConstIterator_(const MatConstIterator_& it); + + //! copy operator + MatConstIterator_& operator = (const MatConstIterator_& it); + //! returns the current matrix element + const _Tp& operator *() const; + //! returns the i-th matrix element, relative to the current + const _Tp& operator [](ptrdiff_t i) const; + + //! shifts the iterator forward by the specified number of elements + MatConstIterator_& operator += (ptrdiff_t ofs); + //! shifts the iterator backward by the specified number of elements + MatConstIterator_& operator -= (ptrdiff_t ofs); + //! decrements the iterator + MatConstIterator_& operator --(); + //! decrements the iterator + MatConstIterator_ operator --(int); + //! increments the iterator + MatConstIterator_& operator ++(); + //! increments the iterator + MatConstIterator_ operator ++(int); + //! returns the current iterator position + Point pos() const; +}; + + + +//////////////////////////////////// MatIterator_ //////////////////////////////////// + +/** @brief Matrix read-write iterator +*/ +template +class MatIterator_ : public MatConstIterator_<_Tp> +{ +public: + typedef _Tp* pointer; + typedef _Tp& reference; + + typedef std::random_access_iterator_tag iterator_category; + + //! the default constructor + MatIterator_(); + //! constructor that sets the iterator to the beginning of the matrix + MatIterator_(Mat_<_Tp>* _m); + //! constructor that sets the iterator to the specified element of the matrix + MatIterator_(Mat_<_Tp>* _m, int _row, int _col=0); + //! constructor that sets the iterator to the specified element of the matrix + MatIterator_(Mat_<_Tp>* _m, Point _pt); + //! constructor that sets the iterator to the specified element of the matrix + MatIterator_(Mat_<_Tp>* _m, const int* _idx); + //! copy constructor + MatIterator_(const MatIterator_& it); + //! copy operator + MatIterator_& operator = (const MatIterator_<_Tp>& it ); + + //! returns the current matrix element + _Tp& operator *() const; + //! returns the i-th matrix element, relative to the current + _Tp& operator [](ptrdiff_t i) const; + + //! shifts the iterator forward by the specified number of elements + MatIterator_& operator += (ptrdiff_t ofs); + //! shifts the iterator backward by the specified number of elements + MatIterator_& operator -= (ptrdiff_t ofs); + //! decrements the iterator + MatIterator_& operator --(); + //! decrements the iterator + MatIterator_ operator --(int); + //! increments the iterator + MatIterator_& operator ++(); + //! increments the iterator + MatIterator_ operator ++(int); +}; + + + +/////////////////////////////// SparseMatConstIterator /////////////////////////////// + +/** @brief Read-Only Sparse Matrix Iterator. + + Here is how to use the iterator to compute the sum of floating-point sparse matrix elements: + + \code + SparseMatConstIterator it = m.begin(), it_end = m.end(); + double s = 0; + CV_Assert( m.type() == CV_32F ); + for( ; it != it_end; ++it ) + s += it.value(); + \endcode +*/ +class CV_EXPORTS SparseMatConstIterator +{ +public: + //! the default constructor + SparseMatConstIterator(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatConstIterator(const SparseMat* _m); + //! the copy constructor + SparseMatConstIterator(const SparseMatConstIterator& it); + + //! the assignment operator + SparseMatConstIterator& operator = (const SparseMatConstIterator& it); + + //! template method returning the current matrix element + template const _Tp& value() const; + //! returns the current node of the sparse matrix. it.node->idx is the current element index + const SparseMat::Node* node() const; + + //! moves iterator to the previous element + SparseMatConstIterator& operator --(); + //! moves iterator to the previous element + SparseMatConstIterator operator --(int); + //! moves iterator to the next element + SparseMatConstIterator& operator ++(); + //! moves iterator to the next element + SparseMatConstIterator operator ++(int); + + //! moves iterator to the element after the last element + void seekEnd(); + + const SparseMat* m; + size_t hashidx; + uchar* ptr; +}; + + + +////////////////////////////////// SparseMatIterator ///////////////////////////////// + +/** @brief Read-write Sparse Matrix Iterator + + The class is similar to cv::SparseMatConstIterator, + but can be used for in-place modification of the matrix elements. +*/ +class CV_EXPORTS SparseMatIterator : public SparseMatConstIterator +{ +public: + //! the default constructor + SparseMatIterator(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatIterator(SparseMat* _m); + //! the full constructor setting the iterator to the specified sparse matrix element + SparseMatIterator(SparseMat* _m, const int* idx); + //! the copy constructor + SparseMatIterator(const SparseMatIterator& it); + + //! the assignment operator + SparseMatIterator& operator = (const SparseMatIterator& it); + //! returns read-write reference to the current sparse matrix element + template _Tp& value() const; + //! returns pointer to the current sparse matrix node. it.node->idx is the index of the current element (do not modify it!) + SparseMat::Node* node() const; + + //! moves iterator to the next element + SparseMatIterator& operator ++(); + //! moves iterator to the next element + SparseMatIterator operator ++(int); +}; + + + +/////////////////////////////// SparseMatConstIterator_ ////////////////////////////// + +/** @brief Template Read-Only Sparse Matrix Iterator Class. + + This is the derived from SparseMatConstIterator class that + introduces more convenient operator *() for accessing the current element. +*/ +template class SparseMatConstIterator_ : public SparseMatConstIterator +{ +public: + + typedef std::forward_iterator_tag iterator_category; + + //! the default constructor + SparseMatConstIterator_(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatConstIterator_(const SparseMat_<_Tp>* _m); + SparseMatConstIterator_(const SparseMat* _m); + //! the copy constructor + SparseMatConstIterator_(const SparseMatConstIterator_& it); + + //! the assignment operator + SparseMatConstIterator_& operator = (const SparseMatConstIterator_& it); + //! the element access operator + const _Tp& operator *() const; + + //! moves iterator to the next element + SparseMatConstIterator_& operator ++(); + //! moves iterator to the next element + SparseMatConstIterator_ operator ++(int); +}; + + + +///////////////////////////////// SparseMatIterator_ ///////////////////////////////// + +/** @brief Template Read-Write Sparse Matrix Iterator Class. + + This is the derived from cv::SparseMatConstIterator_ class that + introduces more convenient operator *() for accessing the current element. +*/ +template class SparseMatIterator_ : public SparseMatConstIterator_<_Tp> +{ +public: + + typedef std::forward_iterator_tag iterator_category; + + //! the default constructor + SparseMatIterator_(); + //! the full constructor setting the iterator to the first sparse matrix element + SparseMatIterator_(SparseMat_<_Tp>* _m); + SparseMatIterator_(SparseMat* _m); + //! the copy constructor + SparseMatIterator_(const SparseMatIterator_& it); + + //! the assignment operator + SparseMatIterator_& operator = (const SparseMatIterator_& it); + //! returns the reference to the current element + _Tp& operator *() const; + + //! moves the iterator to the next element + SparseMatIterator_& operator ++(); + //! moves the iterator to the next element + SparseMatIterator_ operator ++(int); +}; + + + +/////////////////////////////////// NAryMatIterator ////////////////////////////////// + +/** @brief n-ary multi-dimensional array iterator. + +Use the class to implement unary, binary, and, generally, n-ary element-wise operations on +multi-dimensional arrays. Some of the arguments of an n-ary function may be continuous arrays, some +may be not. It is possible to use conventional MatIterator 's for each array but incrementing all of +the iterators after each small operations may be a big overhead. In this case consider using +NAryMatIterator to iterate through several matrices simultaneously as long as they have the same +geometry (dimensionality and all the dimension sizes are the same). On each iteration `it.planes[0]`, +`it.planes[1]`,... will be the slices of the corresponding matrices. + +The example below illustrates how you can compute a normalized and threshold 3D color histogram: +@code + void computeNormalizedColorHist(const Mat& image, Mat& hist, int N, double minProb) + { + const int histSize[] = {N, N, N}; + + // make sure that the histogram has a proper size and type + hist.create(3, histSize, CV_32F); + + // and clear it + hist = Scalar(0); + + // the loop below assumes that the image + // is a 8-bit 3-channel. check it. + CV_Assert(image.type() == CV_8UC3); + MatConstIterator_ it = image.begin(), + it_end = image.end(); + for( ; it != it_end; ++it ) + { + const Vec3b& pix = *it; + hist.at(pix[0]*N/256, pix[1]*N/256, pix[2]*N/256) += 1.f; + } + + minProb *= image.rows*image.cols; + + // initialize iterator (the style is different from STL). + // after initialization the iterator will contain + // the number of slices or planes the iterator will go through. + // it simultaneously increments iterators for several matrices + // supplied as a null terminated list of pointers + const Mat* arrays[] = {&hist, 0}; + Mat planes[1]; + NAryMatIterator itNAry(arrays, planes, 1); + double s = 0; + // iterate through the matrix. on each iteration + // itNAry.planes[i] (of type Mat) will be set to the current plane + // of the i-th n-dim matrix passed to the iterator constructor. + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) + { + threshold(itNAry.planes[0], itNAry.planes[0], minProb, 0, THRESH_TOZERO); + s += sum(itNAry.planes[0])[0]; + } + + s = 1./s; + itNAry = NAryMatIterator(arrays, planes, 1); + for(int p = 0; p < itNAry.nplanes; p++, ++itNAry) + itNAry.planes[0] *= s; + } +@endcode + */ +class CV_EXPORTS NAryMatIterator +{ +public: + //! the default constructor + NAryMatIterator(); + //! the full constructor taking arbitrary number of n-dim matrices + NAryMatIterator(const Mat** arrays, uchar** ptrs, int narrays=-1); + //! the full constructor taking arbitrary number of n-dim matrices + NAryMatIterator(const Mat** arrays, Mat* planes, int narrays=-1); + //! the separate iterator initialization method + void init(const Mat** arrays, Mat* planes, uchar** ptrs, int narrays=-1); + + //! proceeds to the next plane of every iterated matrix + NAryMatIterator& operator ++(); + //! proceeds to the next plane of every iterated matrix (postfix increment operator) + NAryMatIterator operator ++(int); + + //! the iterated arrays + const Mat** arrays; + //! the current planes + Mat* planes; + //! data pointers + uchar** ptrs; + //! the number of arrays + int narrays; + //! the number of hyper-planes that the iterator steps through + size_t nplanes; + //! the size of each segment (in elements) + size_t size; +protected: + int iterdepth; + size_t idx; +}; + + + +///////////////////////////////// Matrix Expressions ///////////////////////////////// + +class CV_EXPORTS MatOp +{ +public: + MatOp(); + virtual ~MatOp(); + + virtual bool elementWise(const MatExpr& expr) const; + virtual void assign(const MatExpr& expr, Mat& m, int type=-1) const = 0; + virtual void roi(const MatExpr& expr, const Range& rowRange, + const Range& colRange, MatExpr& res) const; + virtual void diag(const MatExpr& expr, int d, MatExpr& res) const; + virtual void augAssignAdd(const MatExpr& expr, Mat& m) const; + virtual void augAssignSubtract(const MatExpr& expr, Mat& m) const; + virtual void augAssignMultiply(const MatExpr& expr, Mat& m) const; + virtual void augAssignDivide(const MatExpr& expr, Mat& m) const; + virtual void augAssignAnd(const MatExpr& expr, Mat& m) const; + virtual void augAssignOr(const MatExpr& expr, Mat& m) const; + virtual void augAssignXor(const MatExpr& expr, Mat& m) const; + + virtual void add(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; + virtual void add(const MatExpr& expr1, const Scalar& s, MatExpr& res) const; + + virtual void subtract(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; + virtual void subtract(const Scalar& s, const MatExpr& expr, MatExpr& res) const; + + virtual void multiply(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const; + virtual void multiply(const MatExpr& expr1, double s, MatExpr& res) const; + + virtual void divide(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res, double scale=1) const; + virtual void divide(double s, const MatExpr& expr, MatExpr& res) const; + + virtual void abs(const MatExpr& expr, MatExpr& res) const; + + virtual void transpose(const MatExpr& expr, MatExpr& res) const; + virtual void matmul(const MatExpr& expr1, const MatExpr& expr2, MatExpr& res) const; + virtual void invert(const MatExpr& expr, int method, MatExpr& res) const; + + virtual Size size(const MatExpr& expr) const; + virtual int type(const MatExpr& expr) const; +}; + +/** @brief Matrix expression representation +@anchor MatrixExpressions +This is a list of implemented matrix operations that can be combined in arbitrary complex +expressions (here A, B stand for matrices ( Mat ), s for a scalar ( Scalar ), alpha for a +real-valued scalar ( double )): +- Addition, subtraction, negation: `A+B`, `A-B`, `A+s`, `A-s`, `s+A`, `s-A`, `-A` +- Scaling: `A*alpha` +- Per-element multiplication and division: `A.mul(B)`, `A/B`, `alpha/A` +- Matrix multiplication: `A*B` +- Transposition: `A.t()` (means AT) +- Matrix inversion and pseudo-inversion, solving linear systems and least-squares problems: + `A.inv([method]) (~ A-1)`, `A.inv([method])*B (~ X: AX=B)` +- Comparison: `A cmpop B`, `A cmpop alpha`, `alpha cmpop A`, where *cmpop* is one of + `>`, `>=`, `==`, `!=`, `<=`, `<`. The result of comparison is an 8-bit single channel mask whose + elements are set to 255 (if the particular element or pair of elements satisfy the condition) or + 0. +- Bitwise logical operations: `A logicop B`, `A logicop s`, `s logicop A`, `~A`, where *logicop* is one of + `&`, `|`, `^`. +- Element-wise minimum and maximum: `min(A, B)`, `min(A, alpha)`, `max(A, B)`, `max(A, alpha)` +- Element-wise absolute value: `abs(A)` +- Cross-product, dot-product: `A.cross(B)`, `A.dot(B)` +- Any function of matrix or matrices and scalars that returns a matrix or a scalar, such as norm, + mean, sum, countNonZero, trace, determinant, repeat, and others. +- Matrix initializers ( Mat::eye(), Mat::zeros(), Mat::ones() ), matrix comma-separated + initializers, matrix constructors and operators that extract sub-matrices (see Mat description). +- Mat_() constructors to cast the result to the proper type. +@note Comma-separated initializers and probably some other operations may require additional +explicit Mat() or Mat_() constructor calls to resolve a possible ambiguity. + +Here are examples of matrix expressions: +@code + // compute pseudo-inverse of A, equivalent to A.inv(DECOMP_SVD) + SVD svd(A); + Mat pinvA = svd.vt.t()*Mat::diag(1./svd.w)*svd.u.t(); + + // compute the new vector of parameters in the Levenberg-Marquardt algorithm + x -= (A.t()*A + lambda*Mat::eye(A.cols,A.cols,A.type())).inv(DECOMP_CHOLESKY)*(A.t()*err); + + // sharpen image using "unsharp mask" algorithm + Mat blurred; double sigma = 1, threshold = 5, amount = 1; + GaussianBlur(img, blurred, Size(), sigma, sigma); + Mat lowContrastMask = abs(img - blurred) < threshold; + Mat sharpened = img*(1+amount) + blurred*(-amount); + img.copyTo(sharpened, lowContrastMask); +@endcode +*/ +class CV_EXPORTS MatExpr +{ +public: + MatExpr(); + explicit MatExpr(const Mat& m); + + MatExpr(const MatOp* _op, int _flags, const Mat& _a = Mat(), const Mat& _b = Mat(), + const Mat& _c = Mat(), double _alpha = 1, double _beta = 1, const Scalar& _s = Scalar()); + + operator Mat() const; + template operator Mat_<_Tp>() const; + + Size size() const; + int type() const; + + MatExpr row(int y) const; + MatExpr col(int x) const; + MatExpr diag(int d = 0) const; + MatExpr operator()( const Range& rowRange, const Range& colRange ) const; + MatExpr operator()( const Rect& roi ) const; + + MatExpr t() const; + MatExpr inv(int method = DECOMP_LU) const; + MatExpr mul(const MatExpr& e, double scale=1) const; + MatExpr mul(const Mat& m, double scale=1) const; + + Mat cross(const Mat& m) const; + double dot(const Mat& m) const; + + const MatOp* op; + int flags; + + Mat a, b, c; + double alpha, beta; + Scalar s; +}; + +//! @} core_basic + +//! @relates cv::MatExpr +//! @{ +CV_EXPORTS MatExpr operator + (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator + (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator + (const Scalar& s, const Mat& a); +CV_EXPORTS MatExpr operator + (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator + (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator + (const MatExpr& e, const Scalar& s); +CV_EXPORTS MatExpr operator + (const Scalar& s, const MatExpr& e); +CV_EXPORTS MatExpr operator + (const MatExpr& e1, const MatExpr& e2); +template static inline +MatExpr operator + (const Mat& a, const Matx<_Tp, m, n>& b) { return a + Mat(b); } +template static inline +MatExpr operator + (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) + b; } + +CV_EXPORTS MatExpr operator - (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator - (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator - (const Scalar& s, const Mat& a); +CV_EXPORTS MatExpr operator - (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator - (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator - (const MatExpr& e, const Scalar& s); +CV_EXPORTS MatExpr operator - (const Scalar& s, const MatExpr& e); +CV_EXPORTS MatExpr operator - (const MatExpr& e1, const MatExpr& e2); +template static inline +MatExpr operator - (const Mat& a, const Matx<_Tp, m, n>& b) { return a - Mat(b); } +template static inline +MatExpr operator - (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) - b; } + +CV_EXPORTS MatExpr operator - (const Mat& m); +CV_EXPORTS MatExpr operator - (const MatExpr& e); + +CV_EXPORTS MatExpr operator * (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator * (const Mat& a, double s); +CV_EXPORTS MatExpr operator * (double s, const Mat& a); +CV_EXPORTS MatExpr operator * (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator * (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator * (const MatExpr& e, double s); +CV_EXPORTS MatExpr operator * (double s, const MatExpr& e); +CV_EXPORTS MatExpr operator * (const MatExpr& e1, const MatExpr& e2); +template static inline +MatExpr operator * (const Mat& a, const Matx<_Tp, m, n>& b) { return a * Mat(b); } +template static inline +MatExpr operator * (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) * b; } + +CV_EXPORTS MatExpr operator / (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator / (const Mat& a, double s); +CV_EXPORTS MatExpr operator / (double s, const Mat& a); +CV_EXPORTS MatExpr operator / (const MatExpr& e, const Mat& m); +CV_EXPORTS MatExpr operator / (const Mat& m, const MatExpr& e); +CV_EXPORTS MatExpr operator / (const MatExpr& e, double s); +CV_EXPORTS MatExpr operator / (double s, const MatExpr& e); +CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2); +template static inline +MatExpr operator / (const Mat& a, const Matx<_Tp, m, n>& b) { return a / Mat(b); } +template static inline +MatExpr operator / (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) / b; } + +CV_EXPORTS MatExpr operator < (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator < (const Mat& a, double s); +CV_EXPORTS MatExpr operator < (double s, const Mat& a); +template static inline +MatExpr operator < (const Mat& a, const Matx<_Tp, m, n>& b) { return a < Mat(b); } +template static inline +MatExpr operator < (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) < b; } + +CV_EXPORTS MatExpr operator <= (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator <= (const Mat& a, double s); +CV_EXPORTS MatExpr operator <= (double s, const Mat& a); +template static inline +MatExpr operator <= (const Mat& a, const Matx<_Tp, m, n>& b) { return a <= Mat(b); } +template static inline +MatExpr operator <= (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) <= b; } + +CV_EXPORTS MatExpr operator == (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator == (const Mat& a, double s); +CV_EXPORTS MatExpr operator == (double s, const Mat& a); +template static inline +MatExpr operator == (const Mat& a, const Matx<_Tp, m, n>& b) { return a == Mat(b); } +template static inline +MatExpr operator == (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) == b; } + +CV_EXPORTS MatExpr operator != (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator != (const Mat& a, double s); +CV_EXPORTS MatExpr operator != (double s, const Mat& a); +template static inline +MatExpr operator != (const Mat& a, const Matx<_Tp, m, n>& b) { return a != Mat(b); } +template static inline +MatExpr operator != (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) != b; } + +CV_EXPORTS MatExpr operator >= (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator >= (const Mat& a, double s); +CV_EXPORTS MatExpr operator >= (double s, const Mat& a); +template static inline +MatExpr operator >= (const Mat& a, const Matx<_Tp, m, n>& b) { return a >= Mat(b); } +template static inline +MatExpr operator >= (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) >= b; } + +CV_EXPORTS MatExpr operator > (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator > (const Mat& a, double s); +CV_EXPORTS MatExpr operator > (double s, const Mat& a); +template static inline +MatExpr operator > (const Mat& a, const Matx<_Tp, m, n>& b) { return a > Mat(b); } +template static inline +MatExpr operator > (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) > b; } + +CV_EXPORTS MatExpr operator & (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator & (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator & (const Scalar& s, const Mat& a); +template static inline +MatExpr operator & (const Mat& a, const Matx<_Tp, m, n>& b) { return a & Mat(b); } +template static inline +MatExpr operator & (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) & b; } + +CV_EXPORTS MatExpr operator | (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator | (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator | (const Scalar& s, const Mat& a); +template static inline +MatExpr operator | (const Mat& a, const Matx<_Tp, m, n>& b) { return a | Mat(b); } +template static inline +MatExpr operator | (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) | b; } + +CV_EXPORTS MatExpr operator ^ (const Mat& a, const Mat& b); +CV_EXPORTS MatExpr operator ^ (const Mat& a, const Scalar& s); +CV_EXPORTS MatExpr operator ^ (const Scalar& s, const Mat& a); +template static inline +MatExpr operator ^ (const Mat& a, const Matx<_Tp, m, n>& b) { return a ^ Mat(b); } +template static inline +MatExpr operator ^ (const Matx<_Tp, m, n>& a, const Mat& b) { return Mat(a) ^ b; } + +CV_EXPORTS MatExpr operator ~(const Mat& m); + +CV_EXPORTS MatExpr min(const Mat& a, const Mat& b); +CV_EXPORTS MatExpr min(const Mat& a, double s); +CV_EXPORTS MatExpr min(double s, const Mat& a); +template static inline +MatExpr min (const Mat& a, const Matx<_Tp, m, n>& b) { return min(a, Mat(b)); } +template static inline +MatExpr min (const Matx<_Tp, m, n>& a, const Mat& b) { return min(Mat(a), b); } + +CV_EXPORTS MatExpr max(const Mat& a, const Mat& b); +CV_EXPORTS MatExpr max(const Mat& a, double s); +CV_EXPORTS MatExpr max(double s, const Mat& a); +template static inline +MatExpr max (const Mat& a, const Matx<_Tp, m, n>& b) { return max(a, Mat(b)); } +template static inline +MatExpr max (const Matx<_Tp, m, n>& a, const Mat& b) { return max(Mat(a), b); } + +/** @brief Calculates an absolute value of each matrix element. + +abs is a meta-function that is expanded to one of absdiff or convertScaleAbs forms: +- C = abs(A-B) is equivalent to `absdiff(A, B, C)` +- C = abs(A) is equivalent to `absdiff(A, Scalar::all(0), C)` +- C = `Mat_ >(abs(A*alpha + beta))` is equivalent to `convertScaleAbs(A, C, alpha, +beta)` + +The output matrix has the same size and the same type as the input one except for the last case, +where C is depth=CV_8U . +@param m matrix. +@sa @ref MatrixExpressions, absdiff, convertScaleAbs + */ +CV_EXPORTS MatExpr abs(const Mat& m); +/** @overload +@param e matrix expression. +*/ +CV_EXPORTS MatExpr abs(const MatExpr& e); +//! @} relates cv::MatExpr + +} // cv + +#include "opencv2/core/mat.inl.hpp" + +#endif // OPENCV_CORE_MAT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/mat.inl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/mat.inl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..44628fae4dbe177fd68cadbecb38f2e1c37fc0c8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/mat.inl.hpp @@ -0,0 +1,3983 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_MATRIX_OPERATIONS_HPP +#define OPENCV_CORE_MATRIX_OPERATIONS_HPP + +#ifndef __cplusplus +# error mat.inl.hpp header must be compiled as C++ +#endif + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4127 ) +#endif + +namespace cv +{ +CV__DEBUG_NS_BEGIN + + +//! @cond IGNORED + +////////////////////////// Custom (raw) type wrapper ////////////////////////// + +template static inline +int rawType() +{ + CV_StaticAssert(sizeof(_Tp) <= CV_CN_MAX, "sizeof(_Tp) is too large"); + const int elemSize = sizeof(_Tp); + return (int)CV_MAKETYPE(CV_8U, elemSize); +} + +//////////////////////// Input/Output Arrays //////////////////////// + +inline void _InputArray::init(int _flags, const void* _obj) +{ flags = _flags; obj = (void*)_obj; } + +inline void _InputArray::init(int _flags, const void* _obj, Size _sz) +{ flags = _flags; obj = (void*)_obj; sz = _sz; } + +inline void* _InputArray::getObj() const { return obj; } +inline int _InputArray::getFlags() const { return flags; } +inline Size _InputArray::getSz() const { return sz; } + +inline _InputArray::_InputArray() { init(0 + NONE, 0); } +inline _InputArray::_InputArray(int _flags, void* _obj) { init(_flags, _obj); } +inline _InputArray::_InputArray(const Mat& m) { init(MAT+ACCESS_READ, &m); } +inline _InputArray::_InputArray(const std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_READ, &vec); } +inline _InputArray::_InputArray(const UMat& m) { init(UMAT+ACCESS_READ, &m); } +inline _InputArray::_InputArray(const std::vector& vec) { init(STD_VECTOR_UMAT+ACCESS_READ, &vec); } + +template inline +_InputArray::_InputArray(const std::vector<_Tp>& vec) +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +template inline +_InputArray::_InputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ, arr.data(), Size(1, _Nm)); } + +template inline +_InputArray::_InputArray(const std::array& arr) +{ init(STD_ARRAY_MAT + ACCESS_READ, arr.data(), Size(1, _Nm)); } + +inline +_InputArray::_InputArray(const std::vector& vec) +{ init(FIXED_TYPE + STD_BOOL_VECTOR + traits::Type::value + ACCESS_READ, &vec); } + +template inline +_InputArray::_InputArray(const std::vector >& vec) +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +template inline +_InputArray::_InputArray(const std::vector >& vec) +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_READ, &vec); } + +template inline +_InputArray::_InputArray(const Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, &mtx, Size(n, m)); } + +template inline +_InputArray::_InputArray(const _Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_READ, vec, Size(n, 1)); } + +template inline +_InputArray::_InputArray(const Mat_<_Tp>& m) +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_READ, &m); } + +inline _InputArray::_InputArray(const double& val) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F + ACCESS_READ, &val, Size(1,1)); } + +inline _InputArray::_InputArray(const MatExpr& expr) +{ init(FIXED_TYPE + FIXED_SIZE + EXPR + ACCESS_READ, &expr); } + +inline _InputArray::_InputArray(const cuda::GpuMat& d_mat) +{ init(CUDA_GPU_MAT + ACCESS_READ, &d_mat); } + +inline _InputArray::_InputArray(const std::vector& d_mat) +{ init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_READ, &d_mat);} + +inline _InputArray::_InputArray(const ogl::Buffer& buf) +{ init(OPENGL_BUFFER + ACCESS_READ, &buf); } + +inline _InputArray::_InputArray(const cuda::HostMem& cuda_mem) +{ init(CUDA_HOST_MEM + ACCESS_READ, &cuda_mem); } + +template inline +_InputArray _InputArray::rawIn(const std::vector<_Tp>& vec) +{ + _InputArray v; + v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_READ; + v.obj = (void*)&vec; + return v; +} + +template inline +_InputArray _InputArray::rawIn(const std::array<_Tp, _Nm>& arr) +{ + _InputArray v; + v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_READ; + v.obj = (void*)arr.data(); + v.sz = Size(1, _Nm); + return v; +} + +inline _InputArray::~_InputArray() {} + +inline Mat _InputArray::getMat(int i) const +{ + if( kind() == MAT && i < 0 ) + return *(const Mat*)obj; + return getMat_(i); +} + +inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; } +inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; } +inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; } +inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; } +inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; } +inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR || + kind() == _InputArray::STD_BOOL_VECTOR || + kind() == _InputArray::STD_ARRAY; } +inline bool _InputArray::isGpuMat() const { return kind() == _InputArray::CUDA_GPU_MAT; } +inline bool _InputArray::isGpuMatVector() const { return kind() == _InputArray::STD_VECTOR_CUDA_GPU_MAT; } + +//////////////////////////////////////////////////////////////////////////////////////// + +inline _OutputArray::_OutputArray() { init(NONE + ACCESS_WRITE, 0); } +inline _OutputArray::_OutputArray(int _flags, void* _obj) { init(_flags + ACCESS_WRITE, _obj); } +inline _OutputArray::_OutputArray(Mat& m) { init(MAT+ACCESS_WRITE, &m); } +inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_MAT + ACCESS_WRITE, &vec); } +inline _OutputArray::_OutputArray(UMat& m) { init(UMAT + ACCESS_WRITE, &m); } +inline _OutputArray::_OutputArray(std::vector& vec) { init(STD_VECTOR_UMAT + ACCESS_WRITE, &vec); } + +template inline +_OutputArray::_OutputArray(std::vector<_Tp>& vec) +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template inline +_OutputArray::_OutputArray(std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template inline +_OutputArray::_OutputArray(std::array& arr) +{ init(STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template inline +_OutputArray::_OutputArray(std::vector >& vec) +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template inline +_OutputArray::_OutputArray(std::vector >& vec) +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template inline +_OutputArray::_OutputArray(Mat_<_Tp>& m) +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); } + +template inline +_OutputArray::_OutputArray(Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); } + +template inline +_OutputArray::_OutputArray(_Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); } + +template inline +_OutputArray::_OutputArray(const std::vector<_Tp>& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template inline +_OutputArray::_OutputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template inline +_OutputArray::_OutputArray(const std::array& arr) +{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_WRITE, arr.data(), Size(1, _Nm)); } + +template inline +_OutputArray::_OutputArray(const std::vector >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template inline +_OutputArray::_OutputArray(const std::vector >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &vec); } + +template inline +_OutputArray::_OutputArray(const Mat_<_Tp>& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_WRITE, &m); } + +template inline +_OutputArray::_OutputArray(const Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, &mtx, Size(n, m)); } + +template inline +_OutputArray::_OutputArray(const _Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_WRITE, vec, Size(n, 1)); } + +inline _OutputArray::_OutputArray(cuda::GpuMat& d_mat) +{ init(CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); } + +inline _OutputArray::_OutputArray(std::vector& d_mat) +{ init(STD_VECTOR_CUDA_GPU_MAT + ACCESS_WRITE, &d_mat);} + +inline _OutputArray::_OutputArray(ogl::Buffer& buf) +{ init(OPENGL_BUFFER + ACCESS_WRITE, &buf); } + +inline _OutputArray::_OutputArray(cuda::HostMem& cuda_mem) +{ init(CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); } + +inline _OutputArray::_OutputArray(const Mat& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_WRITE, &m); } + +inline _OutputArray::_OutputArray(const std::vector& vec) +{ init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_WRITE, &vec); } + +inline _OutputArray::_OutputArray(const UMat& m) +{ init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_WRITE, &m); } + +inline _OutputArray::_OutputArray(const std::vector& vec) +{ init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_WRITE, &vec); } + +inline _OutputArray::_OutputArray(const cuda::GpuMat& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_WRITE, &d_mat); } + + +inline _OutputArray::_OutputArray(const ogl::Buffer& buf) +{ init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_WRITE, &buf); } + +inline _OutputArray::_OutputArray(const cuda::HostMem& cuda_mem) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_WRITE, &cuda_mem); } + +template inline +_OutputArray _OutputArray::rawOut(std::vector<_Tp>& vec) +{ + _OutputArray v; + v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_WRITE; + v.obj = (void*)&vec; + return v; +} + +template inline +_OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr) +{ + _OutputArray v; + v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_WRITE; + v.obj = (void*)arr.data(); + v.sz = Size(1, _Nm); + return v; +} + +/////////////////////////////////////////////////////////////////////////////////////////// + +inline _InputOutputArray::_InputOutputArray() { init(0+ACCESS_RW, 0); } +inline _InputOutputArray::_InputOutputArray(int _flags, void* _obj) { init(_flags+ACCESS_RW, _obj); } +inline _InputOutputArray::_InputOutputArray(Mat& m) { init(MAT+ACCESS_RW, &m); } +inline _InputOutputArray::_InputOutputArray(std::vector& vec) { init(STD_VECTOR_MAT+ACCESS_RW, &vec); } +inline _InputOutputArray::_InputOutputArray(UMat& m) { init(UMAT+ACCESS_RW, &m); } +inline _InputOutputArray::_InputOutputArray(std::vector& vec) { init(STD_VECTOR_UMAT+ACCESS_RW, &vec); } + +template inline +_InputOutputArray::_InputOutputArray(std::vector<_Tp>& vec) +{ init(FIXED_TYPE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template inline +_InputOutputArray::_InputOutputArray(std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template inline +_InputOutputArray::_InputOutputArray(std::array& arr) +{ init(STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template inline +_InputOutputArray::_InputOutputArray(std::vector >& vec) +{ init(FIXED_TYPE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template inline +_InputOutputArray::_InputOutputArray(std::vector >& vec) +{ init(FIXED_TYPE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template inline +_InputOutputArray::_InputOutputArray(Mat_<_Tp>& m) +{ init(FIXED_TYPE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); } + +template inline +_InputOutputArray::_InputOutputArray(Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); } + +template inline +_InputOutputArray::_InputOutputArray(_Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); } + +template inline +_InputOutputArray::_InputOutputArray(const std::vector<_Tp>& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template inline +_InputOutputArray::_InputOutputArray(const std::array<_Tp, _Nm>& arr) +{ init(FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template inline +_InputOutputArray::_InputOutputArray(const std::array& arr) +{ init(FIXED_SIZE + STD_ARRAY_MAT + ACCESS_RW, arr.data(), Size(1, _Nm)); } + +template inline +_InputOutputArray::_InputOutputArray(const std::vector >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_VECTOR + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template inline +_InputOutputArray::_InputOutputArray(const std::vector >& vec) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_MAT + traits::Type<_Tp>::value + ACCESS_RW, &vec); } + +template inline +_InputOutputArray::_InputOutputArray(const Mat_<_Tp>& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + traits::Type<_Tp>::value + ACCESS_RW, &m); } + +template inline +_InputOutputArray::_InputOutputArray(const Matx<_Tp, m, n>& mtx) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, &mtx, Size(n, m)); } + +template inline +_InputOutputArray::_InputOutputArray(const _Tp* vec, int n) +{ init(FIXED_TYPE + FIXED_SIZE + MATX + traits::Type<_Tp>::value + ACCESS_RW, vec, Size(n, 1)); } + +inline _InputOutputArray::_InputOutputArray(cuda::GpuMat& d_mat) +{ init(CUDA_GPU_MAT + ACCESS_RW, &d_mat); } + +inline _InputOutputArray::_InputOutputArray(ogl::Buffer& buf) +{ init(OPENGL_BUFFER + ACCESS_RW, &buf); } + +inline _InputOutputArray::_InputOutputArray(cuda::HostMem& cuda_mem) +{ init(CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); } + +inline _InputOutputArray::_InputOutputArray(const Mat& m) +{ init(FIXED_TYPE + FIXED_SIZE + MAT + ACCESS_RW, &m); } + +inline _InputOutputArray::_InputOutputArray(const std::vector& vec) +{ init(FIXED_SIZE + STD_VECTOR_MAT + ACCESS_RW, &vec); } + +inline _InputOutputArray::_InputOutputArray(const UMat& m) +{ init(FIXED_TYPE + FIXED_SIZE + UMAT + ACCESS_RW, &m); } + +inline _InputOutputArray::_InputOutputArray(const std::vector& vec) +{ init(FIXED_SIZE + STD_VECTOR_UMAT + ACCESS_RW, &vec); } + +inline _InputOutputArray::_InputOutputArray(const cuda::GpuMat& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_GPU_MAT + ACCESS_RW, &d_mat); } + +inline _InputOutputArray::_InputOutputArray(const std::vector& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} + +template<> inline _InputOutputArray::_InputOutputArray(std::vector& d_mat) +{ init(FIXED_TYPE + FIXED_SIZE + STD_VECTOR_CUDA_GPU_MAT + ACCESS_RW, &d_mat);} + +inline _InputOutputArray::_InputOutputArray(const ogl::Buffer& buf) +{ init(FIXED_TYPE + FIXED_SIZE + OPENGL_BUFFER + ACCESS_RW, &buf); } + +inline _InputOutputArray::_InputOutputArray(const cuda::HostMem& cuda_mem) +{ init(FIXED_TYPE + FIXED_SIZE + CUDA_HOST_MEM + ACCESS_RW, &cuda_mem); } + +template inline +_InputOutputArray _InputOutputArray::rawInOut(std::vector<_Tp>& vec) +{ + _InputOutputArray v; + v.flags = _InputArray::FIXED_TYPE + _InputArray::STD_VECTOR + rawType<_Tp>() + ACCESS_RW; + v.obj = (void*)&vec; + return v; +} + +template inline +_InputOutputArray _InputOutputArray::rawInOut(std::array<_Tp, _Nm>& arr) +{ + _InputOutputArray v; + v.flags = FIXED_TYPE + FIXED_SIZE + STD_ARRAY + traits::Type<_Tp>::value + ACCESS_RW; + v.obj = (void*)arr.data(); + v.sz = Size(1, _Nm); + return v; +} + + +template static inline _InputArray rawIn(_Tp& v) { return _InputArray::rawIn(v); } +template static inline _OutputArray rawOut(_Tp& v) { return _OutputArray::rawOut(v); } +template static inline _InputOutputArray rawInOut(_Tp& v) { return _InputOutputArray::rawInOut(v); } + +CV__DEBUG_NS_END + +//////////////////////////////////////////// Mat ////////////////////////////////////////// + +inline +Mat::Mat() + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{} + +inline +Mat::Mat(int _rows, int _cols, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_rows, _cols, _type); +} + +inline +Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_rows, _cols, _type); + *this = _s; +} + +inline +Mat::Mat(Size _sz, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create( _sz.height, _sz.width, _type ); +} + +inline +Mat::Mat(Size _sz, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz.height, _sz.width, _type); + *this = _s; +} + +inline +Mat::Mat(int _dims, const int* _sz, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_dims, _sz, _type); +} + +inline +Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_dims, _sz, _type); + *this = _s; +} + +inline +Mat::Mat(const std::vector& _sz, int _type) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz, _type); +} + +inline +Mat::Mat(const std::vector& _sz, int _type, const Scalar& _s) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), + datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + create(_sz, _type); + *this = _s; +} + +inline +Mat::Mat(const Mat& m) + : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), + datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), + u(m.u), size(&rows), step(0) +{ + if( u ) + CV_XADD(&u->refcount, 1); + if( m.dims <= 2 ) + { + step[0] = m.step[0]; step[1] = m.step[1]; + } + else + { + dims = 0; + copySize(m); + } +} + +inline +Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) + : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_rows), cols(_cols), + data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), + allocator(0), u(0), size(&rows) +{ + CV_Assert(total() == 0 || data != NULL); + + size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); + size_t minstep = cols * esz; + if( _step == AUTO_STEP ) + { + _step = minstep; + } + else + { + CV_DbgAssert( _step >= minstep ); + if (_step % esz1 != 0) + { + CV_Error(Error::BadStep, "Step must be a multiple of esz1"); + } + } + step[0] = _step; + step[1] = esz; + datalimit = datastart + _step * rows; + dataend = datalimit - _step + minstep; + updateContinuityFlag(); +} + +inline +Mat::Mat(Size _sz, int _type, void* _data, size_t _step) + : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_sz.height), cols(_sz.width), + data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), + allocator(0), u(0), size(&rows) +{ + CV_Assert(total() == 0 || data != NULL); + + size_t esz = CV_ELEM_SIZE(_type), esz1 = CV_ELEM_SIZE1(_type); + size_t minstep = cols*esz; + if( _step == AUTO_STEP ) + { + _step = minstep; + } + else + { + CV_DbgAssert( _step >= minstep ); + + if (_step % esz1 != 0) + { + CV_Error(Error::BadStep, "Step must be a multiple of esz1"); + } + } + step[0] = _step; + step[1] = esz; + datalimit = datastart + _step*rows; + dataend = datalimit - _step + minstep; + updateContinuityFlag(); +} + +template inline +Mat::Mat(const std::vector<_Tp>& vec, bool copyData) + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), + cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if(vec.empty()) + return; + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)&vec[0]; + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); +} + +template inline +Mat::Mat(const std::initializer_list<_Tp> list) + : Mat() +{ + CV_Assert(list.size() != 0); + Mat((int)list.size(), 1, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this); +} + +template inline +Mat::Mat(const std::initializer_list sizes, const std::initializer_list<_Tp> list) + : Mat() +{ + size_t size_total = 1; + for(auto s : sizes) + size_total *= s; + CV_Assert(list.size() != 0); + CV_Assert(size_total == list.size()); + Mat((int)sizes.size(), (int*)sizes.begin(), traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this); +} + +template inline +Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()), + cols(1), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if(arr.empty()) + return; + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)arr.data(); + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this); +} + +template inline +Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(n), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)vec.val; + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat(n, 1, traits::Type<_Tp>::value, (void*)vec.val).copyTo(*this); +} + + +template inline +Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = cols * sizeof(_Tp); + step[1] = sizeof(_Tp); + datastart = data = (uchar*)M.val; + datalimit = dataend = datastart + rows * step[0]; + } + else + Mat(m, n, traits::Type<_Tp>::value, (uchar*)M.val).copyTo(*this); +} + +template inline +Mat::Mat(const Point_<_Tp>& pt, bool copyData) + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(2), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)&pt.x; + datalimit = dataend = datastart + rows * step[0]; + } + else + { + create(2, 1, traits::Type<_Tp>::value); + ((_Tp*)data)[0] = pt.x; + ((_Tp*)data)[1] = pt.y; + } +} + +template inline +Mat::Mat(const Point3_<_Tp>& pt, bool copyData) + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) +{ + if( !copyData ) + { + step[0] = step[1] = sizeof(_Tp); + datastart = data = (uchar*)&pt.x; + datalimit = dataend = datastart + rows * step[0]; + } + else + { + create(3, 1, traits::Type<_Tp>::value); + ((_Tp*)data)[0] = pt.x; + ((_Tp*)data)[1] = pt.y; + ((_Tp*)data)[2] = pt.z; + } +} + +template inline +Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer) + : flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), + datastart(0), dataend(0), allocator(0), u(0), size(&rows) +{ + *this = commaInitializer.operator Mat_<_Tp>(); +} + +inline +Mat::~Mat() +{ + release(); + if( step.p != step.buf ) + fastFree(step.p); +} + +inline +Mat& Mat::operator = (const Mat& m) +{ + if( this != &m ) + { + if( m.u ) + CV_XADD(&m.u->refcount, 1); + release(); + flags = m.flags; + if( dims <= 2 && m.dims <= 2 ) + { + dims = m.dims; + rows = m.rows; + cols = m.cols; + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + copySize(m); + data = m.data; + datastart = m.datastart; + dataend = m.dataend; + datalimit = m.datalimit; + allocator = m.allocator; + u = m.u; + } + return *this; +} + +inline +Mat Mat::row(int y) const +{ + return Mat(*this, Range(y, y + 1), Range::all()); +} + +inline +Mat Mat::col(int x) const +{ + return Mat(*this, Range::all(), Range(x, x + 1)); +} + +inline +Mat Mat::rowRange(int startrow, int endrow) const +{ + return Mat(*this, Range(startrow, endrow), Range::all()); +} + +inline +Mat Mat::rowRange(const Range& r) const +{ + return Mat(*this, r, Range::all()); +} + +inline +Mat Mat::colRange(int startcol, int endcol) const +{ + return Mat(*this, Range::all(), Range(startcol, endcol)); +} + +inline +Mat Mat::colRange(const Range& r) const +{ + return Mat(*this, Range::all(), r); +} + +inline +Mat Mat::clone() const +{ + Mat m; + copyTo(m); + return m; +} + +inline +void Mat::assignTo( Mat& m, int _type ) const +{ + if( _type < 0 ) + m = *this; + else + convertTo(m, _type); +} + +inline +void Mat::create(int _rows, int _cols, int _type) +{ + _type &= TYPE_MASK; + if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && data ) + return; + int sz[] = {_rows, _cols}; + create(2, sz, _type); +} + +inline +void Mat::create(Size _sz, int _type) +{ + create(_sz.height, _sz.width, _type); +} + +inline +void Mat::addref() +{ + if( u ) + CV_XADD(&u->refcount, 1); +} + +inline +void Mat::release() +{ + if( u && CV_XADD(&u->refcount, -1) == 1 ) + deallocate(); + u = NULL; + datastart = dataend = datalimit = data = 0; + for(int i = 0; i < dims; i++) + size.p[i] = 0; +#ifdef _DEBUG + flags = MAGIC_VAL; + dims = rows = cols = 0; + if(step.p != step.buf) + { + fastFree(step.p); + step.p = step.buf; + size.p = &rows; + } +#endif +} + +inline +Mat Mat::operator()( Range _rowRange, Range _colRange ) const +{ + return Mat(*this, _rowRange, _colRange); +} + +inline +Mat Mat::operator()( const Rect& roi ) const +{ + return Mat(*this, roi); +} + +inline +Mat Mat::operator()(const Range* ranges) const +{ + return Mat(*this, ranges); +} + +inline +Mat Mat::operator()(const std::vector& ranges) const +{ + return Mat(*this, ranges); +} + +inline +bool Mat::isContinuous() const +{ + return (flags & CONTINUOUS_FLAG) != 0; +} + +inline +bool Mat::isSubmatrix() const +{ + return (flags & SUBMATRIX_FLAG) != 0; +} + +inline +size_t Mat::elemSize() const +{ + size_t res = dims > 0 ? step.p[dims - 1] : 0; + CV_DbgAssert(res != 0); + return res; +} + +inline +size_t Mat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int Mat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int Mat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int Mat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t Mat::step1(int i) const +{ + return step.p[i] / elemSize1(); +} + +inline +bool Mat::empty() const +{ + return data == 0 || total() == 0 || dims == 0; +} + +inline +size_t Mat::total() const +{ + if( dims <= 2 ) + return (size_t)rows * cols; + size_t p = 1; + for( int i = 0; i < dims; i++ ) + p *= size[i]; + return p; +} + +inline +size_t Mat::total(int startDim, int endDim) const +{ + CV_Assert( 0 <= startDim && startDim <= endDim); + size_t p = 1; + int endDim_ = endDim <= dims ? endDim : dims; + for( int i = startDim; i < endDim_; i++ ) + p *= size[i]; + return p; +} + +inline +uchar* Mat::ptr(int y) +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return data + step.p[0] * y; +} + +inline +const uchar* Mat::ptr(int y) const +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return data + step.p[0] * y; +} + +template inline +_Tp* Mat::ptr(int y) +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return (_Tp*)(data + step.p[0] * y); +} + +template inline +const _Tp* Mat::ptr(int y) const +{ + CV_DbgAssert( y == 0 || (data && dims >= 1 && (unsigned)y < (unsigned)size.p[0]) ); + return (const _Tp*)(data + step.p[0] * y); +} + +inline +uchar* Mat::ptr(int i0, int i1) +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return data + i0 * step.p[0] + i1 * step.p[1]; +} + +inline +const uchar* Mat::ptr(int i0, int i1) const +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return data + i0 * step.p[0] + i1 * step.p[1]; +} + +template inline +_Tp* Mat::ptr(int i0, int i1) +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1]); +} + +template inline +const _Tp* Mat::ptr(int i0, int i1) const +{ + CV_DbgAssert(dims >= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1]); +} + +inline +uchar* Mat::ptr(int i0, int i1, int i2) +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]; +} + +inline +const uchar* Mat::ptr(int i0, int i1, int i2) const +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]; +} + +template inline +_Tp* Mat::ptr(int i0, int i1, int i2) +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return (_Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]); +} + +template inline +const _Tp* Mat::ptr(int i0, int i1, int i2) const +{ + CV_DbgAssert(dims >= 3); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert((unsigned)i2 < (unsigned)size.p[2]); + return (const _Tp*)(data + i0 * step.p[0] + i1 * step.p[1] + i2 * step.p[2]); +} + +inline +uchar* Mat::ptr(const int* idx) +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return p; +} + +inline +const uchar* Mat::ptr(const int* idx) const +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return p; +} + +template inline +_Tp* Mat::ptr(const int* idx) +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return (_Tp*)p; +} + +template inline +const _Tp* Mat::ptr(const int* idx) const +{ + int i, d = dims; + uchar* p = data; + CV_DbgAssert( d >= 1 && p ); + for( i = 0; i < d; i++ ) + { + CV_DbgAssert( (unsigned)idx[i] < (unsigned)size.p[i] ); + p += idx[i] * step.p[i]; + } + return (const _Tp*)p; +} + +template inline +_Tp& Mat::at(int i0, int i1) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((_Tp*)(data + step.p[0] * i0))[i1]; +} + +template inline +const _Tp& Mat::at(int i0, int i1) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((const _Tp*)(data + step.p[0] * i0))[i1]; +} + +template inline +_Tp& Mat::at(Point pt) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template inline +const _Tp& Mat::at(Point pt) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())); + CV_DbgAssert(CV_ELEM_SIZE1(traits::Depth<_Tp>::value) == elemSize1()); + return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template inline +_Tp& Mat::at(int i0) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); + CV_DbgAssert(elemSize() == sizeof(_Tp)); + if( isContinuous() || size.p[0] == 1 ) + return ((_Tp*)data)[i0]; + if( size.p[1] == 1 ) + return *(_Tp*)(data + step.p[0] * i0); + int i = i0 / cols, j = i0 - i * cols; + return ((_Tp*)(data + step.p[0] * i))[j]; +} + +template inline +const _Tp& Mat::at(int i0) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1])); + CV_DbgAssert(elemSize() == sizeof(_Tp)); + if( isContinuous() || size.p[0] == 1 ) + return ((const _Tp*)data)[i0]; + if( size.p[1] == 1 ) + return *(const _Tp*)(data + step.p[0] * i0); + int i = i0 / cols, j = i0 - i * cols; + return ((const _Tp*)(data + step.p[0] * i))[j]; +} + +template inline +_Tp& Mat::at(int i0, int i1, int i2) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(_Tp*)ptr(i0, i1, i2); +} + +template inline +const _Tp& Mat::at(int i0, int i1, int i2) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(const _Tp*)ptr(i0, i1, i2); +} + +template inline +_Tp& Mat::at(const int* idx) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(_Tp*)ptr(idx); +} + +template inline +const _Tp& Mat::at(const int* idx) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(const _Tp*)ptr(idx); +} + +template inline +_Tp& Mat::at(const Vec& idx) +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(_Tp*)ptr(idx.val); +} + +template inline +const _Tp& Mat::at(const Vec& idx) const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return *(const _Tp*)ptr(idx.val); +} + +template inline +MatConstIterator_<_Tp> Mat::begin() const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return MatConstIterator_<_Tp>((const Mat_<_Tp>*)this); +} + +template inline +MatConstIterator_<_Tp> Mat::end() const +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + MatConstIterator_<_Tp> it((const Mat_<_Tp>*)this); + it += total(); + return it; +} + +template inline +MatIterator_<_Tp> Mat::begin() +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + return MatIterator_<_Tp>((Mat_<_Tp>*)this); +} + +template inline +MatIterator_<_Tp> Mat::end() +{ + CV_DbgAssert( elemSize() == sizeof(_Tp) ); + MatIterator_<_Tp> it((Mat_<_Tp>*)this); + it += total(); + return it; +} + +template inline +void Mat::forEach(const Functor& operation) { + this->forEach_impl<_Tp>(operation); +} + +template inline +void Mat::forEach(const Functor& operation) const { + // call as not const + (const_cast(this))->forEach<_Tp>(operation); +} + +template inline +Mat::operator std::vector<_Tp>() const +{ + std::vector<_Tp> v; + copyTo(v); + return v; +} + +template inline +Mat::operator std::array<_Tp, _Nm>() const +{ + std::array<_Tp, _Nm> v; + copyTo(v); + return v; +} + +template inline +Mat::operator Vec<_Tp, n>() const +{ + CV_Assert( data && dims <= 2 && (rows == 1 || cols == 1) && + rows + cols - 1 == n && channels() == 1 ); + + if( isContinuous() && type() == traits::Type<_Tp>::value ) + return Vec<_Tp, n>((_Tp*)data); + Vec<_Tp, n> v; + Mat tmp(rows, cols, traits::Type<_Tp>::value, v.val); + convertTo(tmp, tmp.type()); + return v; +} + +template inline +Mat::operator Matx<_Tp, m, n>() const +{ + CV_Assert( data && dims <= 2 && rows == m && cols == n && channels() == 1 ); + + if( isContinuous() && type() == traits::Type<_Tp>::value ) + return Matx<_Tp, m, n>((_Tp*)data); + Matx<_Tp, m, n> mtx; + Mat tmp(rows, cols, traits::Type<_Tp>::value, mtx.val); + convertTo(tmp, tmp.type()); + return mtx; +} + +template inline +void Mat::push_back(const _Tp& elem) +{ + if( !data ) + { + *this = Mat(1, 1, traits::Type<_Tp>::value, (void*)&elem).clone(); + return; + } + CV_Assert(traits::Type<_Tp>::value == type() && cols == 1 + /* && dims == 2 (cols == 1 implies dims == 2) */); + const uchar* tmp = dataend + step[0]; + if( !isSubmatrix() && isContinuous() && tmp <= datalimit ) + { + *(_Tp*)(data + (size.p[0]++) * step.p[0]) = elem; + dataend = tmp; + } + else + push_back_(&elem); +} + +template inline +void Mat::push_back(const Mat_<_Tp>& m) +{ + push_back((const Mat&)m); +} + +template<> inline +void Mat::push_back(const MatExpr& expr) +{ + push_back(static_cast(expr)); +} + + +template inline +void Mat::push_back(const std::vector<_Tp>& v) +{ + push_back(Mat(v)); +} + +inline +Mat::Mat(Mat&& m) + : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), + datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), + u(m.u), size(&rows) +{ + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; + m.allocator = NULL; + m.u = NULL; +} + +inline +Mat& Mat::operator = (Mat&& m) +{ + if (this == &m) + return *this; + + release(); + flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data; + datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator; + u = m.u; + if (step.p != step.buf) // release self step/size + { + fastFree(step.p); + step.p = step.buf; + size.p = &rows; + } + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; + m.allocator = NULL; + m.u = NULL; + return *this; +} + + +///////////////////////////// MatSize //////////////////////////// + +inline +MatSize::MatSize(int* _p) + : p(_p) {} + +inline +int MatSize::dims() const +{ + return (p - 1)[0]; +} + +inline +Size MatSize::operator()() const +{ + CV_DbgAssert(dims() <= 2); + return Size(p[1], p[0]); +} + +inline +const int& MatSize::operator[](int i) const +{ + CV_DbgAssert(i < dims()); +#ifdef __OPENCV_BUILD + CV_DbgAssert(i >= 0); +#endif + return p[i]; +} + +inline +int& MatSize::operator[](int i) +{ + CV_DbgAssert(i < dims()); +#ifdef __OPENCV_BUILD + CV_DbgAssert(i >= 0); +#endif + return p[i]; +} + +inline +MatSize::operator const int*() const +{ + return p; +} + +inline +bool MatSize::operator == (const MatSize& sz) const +{ + int d = dims(); + int dsz = sz.dims(); + if( d != dsz ) + return false; + if( d == 2 ) + return p[0] == sz.p[0] && p[1] == sz.p[1]; + + for( int i = 0; i < d; i++ ) + if( p[i] != sz.p[i] ) + return false; + return true; +} + +inline +bool MatSize::operator != (const MatSize& sz) const +{ + return !(*this == sz); +} + + + +///////////////////////////// MatStep //////////////////////////// + +inline +MatStep::MatStep() +{ + p = buf; p[0] = p[1] = 0; +} + +inline +MatStep::MatStep(size_t s) +{ + p = buf; p[0] = s; p[1] = 0; +} + +inline +const size_t& MatStep::operator[](int i) const +{ + return p[i]; +} + +inline +size_t& MatStep::operator[](int i) +{ + return p[i]; +} + +inline MatStep::operator size_t() const +{ + CV_DbgAssert( p == buf ); + return buf[0]; +} + +inline MatStep& MatStep::operator = (size_t s) +{ + CV_DbgAssert( p == buf ); + buf[0] = s; + return *this; +} + + + +////////////////////////////// Mat_<_Tp> //////////////////////////// + +template inline +Mat_<_Tp>::Mat_() + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; +} + +template inline +Mat_<_Tp>::Mat_(int _rows, int _cols) + : Mat(_rows, _cols, traits::Type<_Tp>::value) +{ +} + +template inline +Mat_<_Tp>::Mat_(int _rows, int _cols, const _Tp& value) + : Mat(_rows, _cols, traits::Type<_Tp>::value) +{ + *this = value; +} + +template inline +Mat_<_Tp>::Mat_(Size _sz) + : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value) +{} + +template inline +Mat_<_Tp>::Mat_(Size _sz, const _Tp& value) + : Mat(_sz.height, _sz.width, traits::Type<_Tp>::value) +{ + *this = value; +} + +template inline +Mat_<_Tp>::Mat_(int _dims, const int* _sz) + : Mat(_dims, _sz, traits::Type<_Tp>::value) +{} + +template inline +Mat_<_Tp>::Mat_(int _dims, const int* _sz, const _Tp& _s) + : Mat(_dims, _sz, traits::Type<_Tp>::value, Scalar(_s)) +{} + +template inline +Mat_<_Tp>::Mat_(int _dims, const int* _sz, _Tp* _data, const size_t* _steps) + : Mat(_dims, _sz, traits::Type<_Tp>::value, _data, _steps) +{} + +template inline +Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const Range* ranges) + : Mat(m, ranges) +{} + +template inline +Mat_<_Tp>::Mat_(const Mat_<_Tp>& m, const std::vector& ranges) + : Mat(m, ranges) +{} + +template inline +Mat_<_Tp>::Mat_(const Mat& m) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; + *this = m; +} + +template inline +Mat_<_Tp>::Mat_(const Mat_& m) + : Mat(m) +{} + +template inline +Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps) + : Mat(_rows, _cols, traits::Type<_Tp>::value, _data, steps) +{} + +template inline +Mat_<_Tp>::Mat_(const Mat_& m, const Range& _rowRange, const Range& _colRange) + : Mat(m, _rowRange, _colRange) +{} + +template inline +Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi) + : Mat(m, roi) +{} + +template template inline +Mat_<_Tp>::Mat_(const Vec::channel_type, n>& vec, bool copyData) + : Mat(n / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&vec) +{ + CV_Assert(n%DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template template inline +Mat_<_Tp>::Mat_(const Matx::channel_type, m, n>& M, bool copyData) + : Mat(m, n / DataType<_Tp>::channels, traits::Type<_Tp>::value, (void*)&M) +{ + CV_Assert(n % DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template inline +Mat_<_Tp>::Mat_(const Point_::channel_type>& pt, bool copyData) + : Mat(2 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt) +{ + CV_Assert(2 % DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template inline +Mat_<_Tp>::Mat_(const Point3_::channel_type>& pt, bool copyData) + : Mat(3 / DataType<_Tp>::channels, 1, traits::Type<_Tp>::value, (void*)&pt) +{ + CV_Assert(3 % DataType<_Tp>::channels == 0); + if( copyData ) + *this = clone(); +} + +template inline +Mat_<_Tp>::Mat_(const MatCommaInitializer_<_Tp>& commaInitializer) + : Mat(commaInitializer) +{} + +template inline +Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData) + : Mat(vec, copyData) +{} + +template inline +Mat_<_Tp>::Mat_(std::initializer_list<_Tp> list) + : Mat(list) +{} + +template inline +Mat_<_Tp>::Mat_(const std::initializer_list sizes, std::initializer_list<_Tp> list) + : Mat(sizes, list) +{} + +template template inline +Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData) + : Mat(arr, copyData) +{} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) +{ + if (m.empty()) + { + release(); + return *this; + } + if( traits::Type<_Tp>::value == m.type() ) + { + Mat::operator = (m); + return *this; + } + if( traits::Depth<_Tp>::value == m.depth() ) + { + return (*this = m.reshape(DataType<_Tp>::channels, m.dims, 0)); + } + CV_Assert(DataType<_Tp>::channels == m.channels() || m.empty()); + m.convertTo(*this, type()); + return *this; +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat_& m) +{ + Mat::operator=(m); + return *this; +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const _Tp& s) +{ + typedef typename DataType<_Tp>::vec_type VT; + Mat::operator=(Scalar((const VT&)s)); + return *this; +} + +template inline +void Mat_<_Tp>::create(int _rows, int _cols) +{ + Mat::create(_rows, _cols, traits::Type<_Tp>::value); +} + +template inline +void Mat_<_Tp>::create(Size _sz) +{ + Mat::create(_sz, traits::Type<_Tp>::value); +} + +template inline +void Mat_<_Tp>::create(int _dims, const int* _sz) +{ + Mat::create(_dims, _sz, traits::Type<_Tp>::value); +} + +template inline +void Mat_<_Tp>::release() +{ + Mat::release(); +#ifdef _DEBUG + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; +#endif +} + +template inline +Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const +{ + return Mat_<_Tp>(Mat::cross(m)); +} + +template template inline +Mat_<_Tp>::operator Mat_() const +{ + return Mat_(static_cast(*this)); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::row(int y) const +{ + return Mat_(*this, Range(y, y+1), Range::all()); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::col(int x) const +{ + return Mat_(*this, Range::all(), Range(x, x+1)); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::diag(int d) const +{ + return Mat_(Mat::diag(d)); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::clone() const +{ + return Mat_(Mat::clone()); +} + +template inline +size_t Mat_<_Tp>::elemSize() const +{ + CV_DbgAssert( Mat::elemSize() == sizeof(_Tp) ); + return sizeof(_Tp); +} + +template inline +size_t Mat_<_Tp>::elemSize1() const +{ + CV_DbgAssert( Mat::elemSize1() == sizeof(_Tp) / DataType<_Tp>::channels ); + return sizeof(_Tp) / DataType<_Tp>::channels; +} + +template inline +int Mat_<_Tp>::type() const +{ + CV_DbgAssert( Mat::type() == traits::Type<_Tp>::value ); + return traits::Type<_Tp>::value; +} + +template inline +int Mat_<_Tp>::depth() const +{ + CV_DbgAssert( Mat::depth() == traits::Depth<_Tp>::value ); + return traits::Depth<_Tp>::value; +} + +template inline +int Mat_<_Tp>::channels() const +{ + CV_DbgAssert( Mat::channels() == DataType<_Tp>::channels ); + return DataType<_Tp>::channels; +} + +template inline +size_t Mat_<_Tp>::stepT(int i) const +{ + return step.p[i] / elemSize(); +} + +template inline +size_t Mat_<_Tp>::step1(int i) const +{ + return step.p[i] / elemSize1(); +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright ) +{ + return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright)); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::operator()( const Range& _rowRange, const Range& _colRange ) const +{ + return Mat_<_Tp>(*this, _rowRange, _colRange); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const +{ + return Mat_<_Tp>(*this, roi); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::operator()( const Range* ranges ) const +{ + return Mat_<_Tp>(*this, ranges); +} + +template inline +Mat_<_Tp> Mat_<_Tp>::operator()(const std::vector& ranges) const +{ + return Mat_<_Tp>(*this, ranges); +} + +template inline +_Tp* Mat_<_Tp>::operator [](int y) +{ + CV_DbgAssert( 0 <= y && y < size.p[0] ); + return (_Tp*)(data + y*step.p[0]); +} + +template inline +const _Tp* Mat_<_Tp>::operator [](int y) const +{ + CV_DbgAssert( 0 <= y && y < size.p[0] ); + return (const _Tp*)(data + y*step.p[0]); +} + +template inline +_Tp& Mat_<_Tp>::operator ()(int i0, int i1) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((_Tp*)(data + step.p[0] * i0))[i1]; +} + +template inline +const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((const _Tp*)(data + step.p[0] * i0))[i1]; +} + +template inline +_Tp& Mat_<_Tp>::operator ()(Point pt) +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((_Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template inline +const _Tp& Mat_<_Tp>::operator ()(Point pt) const +{ + CV_DbgAssert(dims <= 2); + CV_DbgAssert(data); + CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]); + CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]); + CV_DbgAssert(type() == traits::Type<_Tp>::value); + return ((const _Tp*)(data + step.p[0] * pt.y))[pt.x]; +} + +template inline +_Tp& Mat_<_Tp>::operator ()(const int* idx) +{ + return Mat::at<_Tp>(idx); +} + +template inline +const _Tp& Mat_<_Tp>::operator ()(const int* idx) const +{ + return Mat::at<_Tp>(idx); +} + +template template inline +_Tp& Mat_<_Tp>::operator ()(const Vec& idx) +{ + return Mat::at<_Tp>(idx); +} + +template template inline +const _Tp& Mat_<_Tp>::operator ()(const Vec& idx) const +{ + return Mat::at<_Tp>(idx); +} + +template inline +_Tp& Mat_<_Tp>::operator ()(int i0) +{ + return this->at<_Tp>(i0); +} + +template inline +const _Tp& Mat_<_Tp>::operator ()(int i0) const +{ + return this->at<_Tp>(i0); +} + +template inline +_Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) +{ + return this->at<_Tp>(i0, i1, i2); +} + +template inline +const _Tp& Mat_<_Tp>::operator ()(int i0, int i1, int i2) const +{ + return this->at<_Tp>(i0, i1, i2); +} + +template inline +Mat_<_Tp>::operator std::vector<_Tp>() const +{ + std::vector<_Tp> v; + copyTo(v); + return v; +} + +template template inline +Mat_<_Tp>::operator std::array<_Tp, _Nm>() const +{ + std::array<_Tp, _Nm> a; + copyTo(a); + return a; +} + +template template inline +Mat_<_Tp>::operator Vec::channel_type, n>() const +{ + CV_Assert(n % DataType<_Tp>::channels == 0); + +#if defined _MSC_VER + const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround) + return pMat->operator Vec::channel_type, n>(); +#else + return this->Mat::operator Vec::channel_type, n>(); +#endif +} + +template template inline +Mat_<_Tp>::operator Matx::channel_type, m, n>() const +{ + CV_Assert(n % DataType<_Tp>::channels == 0); + +#if defined _MSC_VER + const Mat* pMat = (const Mat*)this; // workaround for MSVS <= 2012 compiler bugs (but GCC 4.6 dislikes this workaround) + Matx::channel_type, m, n> res = pMat->operator Matx::channel_type, m, n>(); + return res; +#else + Matx::channel_type, m, n> res = this->Mat::operator Matx::channel_type, m, n>(); + return res; +#endif +} + +template inline +MatConstIterator_<_Tp> Mat_<_Tp>::begin() const +{ + return Mat::begin<_Tp>(); +} + +template inline +MatConstIterator_<_Tp> Mat_<_Tp>::end() const +{ + return Mat::end<_Tp>(); +} + +template inline +MatIterator_<_Tp> Mat_<_Tp>::begin() +{ + return Mat::begin<_Tp>(); +} + +template inline +MatIterator_<_Tp> Mat_<_Tp>::end() +{ + return Mat::end<_Tp>(); +} + +template template inline +void Mat_<_Tp>::forEach(const Functor& operation) { + Mat::forEach<_Tp, Functor>(operation); +} + +template template inline +void Mat_<_Tp>::forEach(const Functor& operation) const { + Mat::forEach<_Tp, Functor>(operation); +} + +template inline +Mat_<_Tp>::Mat_(Mat_&& m) + : Mat(std::move(m)) +{ +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (Mat_&& m) +{ + Mat::operator = (std::move(m)); + return *this; +} + +template inline +Mat_<_Tp>::Mat_(Mat&& m) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; + *this = std::move(m); +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m) +{ + if (m.empty()) + { + release(); + return *this; + } + if( traits::Type<_Tp>::value == m.type() ) + { + Mat::operator = ((Mat&&)m); + return *this; + } + if( traits::Depth<_Tp>::value == m.depth() ) + { + Mat::operator = ((Mat&&)m.reshape(DataType<_Tp>::channels, m.dims, 0)); + return *this; + } + CV_DbgAssert(DataType<_Tp>::channels == m.channels()); + m.convertTo(*this, type()); + return *this; +} + +template inline +Mat_<_Tp>::Mat_(MatExpr&& e) + : Mat() +{ + flags = (flags & ~CV_MAT_TYPE_MASK) + traits::Type<_Tp>::value; + *this = Mat(e); +} + + +///////////////////////////// SparseMat ///////////////////////////// + +inline +SparseMat::SparseMat() + : flags(MAGIC_VAL), hdr(0) +{} + +inline +SparseMat::SparseMat(int _dims, const int* _sizes, int _type) + : flags(MAGIC_VAL), hdr(0) +{ + create(_dims, _sizes, _type); +} + +inline +SparseMat::SparseMat(const SparseMat& m) + : flags(m.flags), hdr(m.hdr) +{ + addref(); +} + +inline +SparseMat::~SparseMat() +{ + release(); +} + +inline +SparseMat& SparseMat::operator = (const SparseMat& m) +{ + if( this != &m ) + { + if( m.hdr ) + CV_XADD(&m.hdr->refcount, 1); + release(); + flags = m.flags; + hdr = m.hdr; + } + return *this; +} + +inline +SparseMat& SparseMat::operator = (const Mat& m) +{ + return (*this = SparseMat(m)); +} + +inline +SparseMat SparseMat::clone() const +{ + SparseMat temp; + this->copyTo(temp); + return temp; +} + +inline +void SparseMat::assignTo( SparseMat& m, int _type ) const +{ + if( _type < 0 ) + m = *this; + else + convertTo(m, _type); +} + +inline +void SparseMat::addref() +{ + if( hdr ) + CV_XADD(&hdr->refcount, 1); +} + +inline +void SparseMat::release() +{ + if( hdr && CV_XADD(&hdr->refcount, -1) == 1 ) + delete hdr; + hdr = 0; +} + +inline +size_t SparseMat::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} + +inline +size_t SparseMat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int SparseMat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int SparseMat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int SparseMat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +const int* SparseMat::size() const +{ + return hdr ? hdr->size : 0; +} + +inline +int SparseMat::size(int i) const +{ + if( hdr ) + { + CV_DbgAssert((unsigned)i < (unsigned)hdr->dims); + return hdr->size[i]; + } + return 0; +} + +inline +int SparseMat::dims() const +{ + return hdr ? hdr->dims : 0; +} + +inline +size_t SparseMat::nzcount() const +{ + return hdr ? hdr->nodeCount : 0; +} + +inline +size_t SparseMat::hash(int i0) const +{ + return (size_t)i0; +} + +inline +size_t SparseMat::hash(int i0, int i1) const +{ + return (size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1; +} + +inline +size_t SparseMat::hash(int i0, int i1, int i2) const +{ + return ((size_t)(unsigned)i0 * HASH_SCALE + (unsigned)i1) * HASH_SCALE + (unsigned)i2; +} + +inline +size_t SparseMat::hash(const int* idx) const +{ + size_t h = (unsigned)idx[0]; + if( !hdr ) + return 0; + int d = hdr->dims; + for(int i = 1; i < d; i++ ) + h = h * HASH_SCALE + (unsigned)idx[i]; + return h; +} + +template inline +_Tp& SparseMat::ref(int i0, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(i0, true, hashval); +} + +template inline +_Tp& SparseMat::ref(int i0, int i1, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, true, hashval); +} + +template inline +_Tp& SparseMat::ref(int i0, int i1, int i2, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(i0, i1, i2, true, hashval); +} + +template inline +_Tp& SparseMat::ref(const int* idx, size_t* hashval) +{ + return *(_Tp*)((SparseMat*)this)->ptr(idx, true, hashval); +} + +template inline +_Tp SparseMat::value(int i0, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); + return p ? *p : _Tp(); +} + +template inline +_Tp SparseMat::value(int i0, int i1, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval); + return p ? *p : _Tp(); +} + +template inline +_Tp SparseMat::value(int i0, int i1, int i2, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval); + return p ? *p : _Tp(); +} + +template inline +_Tp SparseMat::value(const int* idx, size_t* hashval) const +{ + const _Tp* p = (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval); + return p ? *p : _Tp(); +} + +template inline +const _Tp* SparseMat::find(int i0, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(i0, false, hashval); +} + +template inline +const _Tp* SparseMat::find(int i0, int i1, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, false, hashval); +} + +template inline +const _Tp* SparseMat::find(int i0, int i1, int i2, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(i0, i1, i2, false, hashval); +} + +template inline +const _Tp* SparseMat::find(const int* idx, size_t* hashval) const +{ + return (const _Tp*)((SparseMat*)this)->ptr(idx, false, hashval); +} + +template inline +_Tp& SparseMat::value(Node* n) +{ + return *(_Tp*)((uchar*)n + hdr->valueOffset); +} + +template inline +const _Tp& SparseMat::value(const Node* n) const +{ + return *(const _Tp*)((const uchar*)n + hdr->valueOffset); +} + +inline +SparseMat::Node* SparseMat::node(size_t nidx) +{ + return (Node*)(void*)&hdr->pool[nidx]; +} + +inline +const SparseMat::Node* SparseMat::node(size_t nidx) const +{ + return (const Node*)(const void*)&hdr->pool[nidx]; +} + +inline +SparseMatIterator SparseMat::begin() +{ + return SparseMatIterator(this); +} + +inline +SparseMatConstIterator SparseMat::begin() const +{ + return SparseMatConstIterator(this); +} + +inline +SparseMatIterator SparseMat::end() +{ + SparseMatIterator it(this); + it.seekEnd(); + return it; +} + +inline +SparseMatConstIterator SparseMat::end() const +{ + SparseMatConstIterator it(this); + it.seekEnd(); + return it; +} + +template inline +SparseMatIterator_<_Tp> SparseMat::begin() +{ + return SparseMatIterator_<_Tp>(this); +} + +template inline +SparseMatConstIterator_<_Tp> SparseMat::begin() const +{ + return SparseMatConstIterator_<_Tp>(this); +} + +template inline +SparseMatIterator_<_Tp> SparseMat::end() +{ + SparseMatIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + +template inline +SparseMatConstIterator_<_Tp> SparseMat::end() const +{ + SparseMatConstIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + + + +///////////////////////////// SparseMat_ //////////////////////////// + +template inline +SparseMat_<_Tp>::SparseMat_() +{ + flags = MAGIC_VAL + traits::Type<_Tp>::value; +} + +template inline +SparseMat_<_Tp>::SparseMat_(int _dims, const int* _sizes) + : SparseMat(_dims, _sizes, traits::Type<_Tp>::value) +{} + +template inline +SparseMat_<_Tp>::SparseMat_(const SparseMat& m) +{ + if( m.type() == traits::Type<_Tp>::value ) + *this = (const SparseMat_<_Tp>&)m; + else + m.convertTo(*this, traits::Type<_Tp>::value); +} + +template inline +SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m) +{ + this->flags = m.flags; + this->hdr = m.hdr; + if( this->hdr ) + CV_XADD(&this->hdr->refcount, 1); +} + +template inline +SparseMat_<_Tp>::SparseMat_(const Mat& m) +{ + SparseMat sm(m); + *this = sm; +} + +template inline +SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat_<_Tp>& m) +{ + if( this != &m ) + { + if( m.hdr ) CV_XADD(&m.hdr->refcount, 1); + release(); + flags = m.flags; + hdr = m.hdr; + } + return *this; +} + +template inline +SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const SparseMat& m) +{ + if( m.type() == traits::Type<_Tp>::value ) + return (*this = (const SparseMat_<_Tp>&)m); + m.convertTo(*this, traits::Type<_Tp>::value); + return *this; +} + +template inline +SparseMat_<_Tp>& SparseMat_<_Tp>::operator = (const Mat& m) +{ + return (*this = SparseMat(m)); +} + +template inline +SparseMat_<_Tp> SparseMat_<_Tp>::clone() const +{ + SparseMat_<_Tp> m; + this->copyTo(m); + return m; +} + +template inline +void SparseMat_<_Tp>::create(int _dims, const int* _sizes) +{ + SparseMat::create(_dims, _sizes, traits::Type<_Tp>::value); +} + +template inline +int SparseMat_<_Tp>::type() const +{ + return traits::Type<_Tp>::value; +} + +template inline +int SparseMat_<_Tp>::depth() const +{ + return traits::Depth<_Tp>::value; +} + +template inline +int SparseMat_<_Tp>::channels() const +{ + return DataType<_Tp>::channels; +} + +template inline +_Tp& SparseMat_<_Tp>::ref(int i0, size_t* hashval) +{ + return SparseMat::ref<_Tp>(i0, hashval); +} + +template inline +_Tp SparseMat_<_Tp>::operator()(int i0, size_t* hashval) const +{ + return SparseMat::value<_Tp>(i0, hashval); +} + +template inline +_Tp& SparseMat_<_Tp>::ref(int i0, int i1, size_t* hashval) +{ + return SparseMat::ref<_Tp>(i0, i1, hashval); +} + +template inline +_Tp SparseMat_<_Tp>::operator()(int i0, int i1, size_t* hashval) const +{ + return SparseMat::value<_Tp>(i0, i1, hashval); +} + +template inline +_Tp& SparseMat_<_Tp>::ref(int i0, int i1, int i2, size_t* hashval) +{ + return SparseMat::ref<_Tp>(i0, i1, i2, hashval); +} + +template inline +_Tp SparseMat_<_Tp>::operator()(int i0, int i1, int i2, size_t* hashval) const +{ + return SparseMat::value<_Tp>(i0, i1, i2, hashval); +} + +template inline +_Tp& SparseMat_<_Tp>::ref(const int* idx, size_t* hashval) +{ + return SparseMat::ref<_Tp>(idx, hashval); +} + +template inline +_Tp SparseMat_<_Tp>::operator()(const int* idx, size_t* hashval) const +{ + return SparseMat::value<_Tp>(idx, hashval); +} + +template inline +SparseMatIterator_<_Tp> SparseMat_<_Tp>::begin() +{ + return SparseMatIterator_<_Tp>(this); +} + +template inline +SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::begin() const +{ + return SparseMatConstIterator_<_Tp>(this); +} + +template inline +SparseMatIterator_<_Tp> SparseMat_<_Tp>::end() +{ + SparseMatIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + +template inline +SparseMatConstIterator_<_Tp> SparseMat_<_Tp>::end() const +{ + SparseMatConstIterator_<_Tp> it(this); + it.seekEnd(); + return it; +} + + + +////////////////////////// MatConstIterator ///////////////////////// + +inline +MatConstIterator::MatConstIterator() + : m(0), elemSize(0), ptr(0), sliceStart(0), sliceEnd(0) +{} + +inline +MatConstIterator::MatConstIterator(const Mat* _m) + : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) +{ + if( m && m->isContinuous() ) + { + sliceStart = m->ptr(); + sliceEnd = sliceStart + m->total()*elemSize; + } + seek((const int*)0); +} + +inline +MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col) + : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) +{ + CV_Assert(m && m->dims <= 2); + if( m->isContinuous() ) + { + sliceStart = m->ptr(); + sliceEnd = sliceStart + m->total()*elemSize; + } + int idx[] = {_row, _col}; + seek(idx); +} + +inline +MatConstIterator::MatConstIterator(const Mat* _m, Point _pt) + : m(_m), elemSize(_m->elemSize()), ptr(0), sliceStart(0), sliceEnd(0) +{ + CV_Assert(m && m->dims <= 2); + if( m->isContinuous() ) + { + sliceStart = m->ptr(); + sliceEnd = sliceStart + m->total()*elemSize; + } + int idx[] = {_pt.y, _pt.x}; + seek(idx); +} + +inline +MatConstIterator::MatConstIterator(const MatConstIterator& it) + : m(it.m), elemSize(it.elemSize), ptr(it.ptr), sliceStart(it.sliceStart), sliceEnd(it.sliceEnd) +{} + +inline +MatConstIterator& MatConstIterator::operator = (const MatConstIterator& it ) +{ + m = it.m; elemSize = it.elemSize; ptr = it.ptr; + sliceStart = it.sliceStart; sliceEnd = it.sliceEnd; + return *this; +} + +inline +const uchar* MatConstIterator::operator *() const +{ + return ptr; +} + +inline MatConstIterator& MatConstIterator::operator += (ptrdiff_t ofs) +{ + if( !m || ofs == 0 ) + return *this; + ptrdiff_t ofsb = ofs*elemSize; + ptr += ofsb; + if( ptr < sliceStart || sliceEnd <= ptr ) + { + ptr -= ofsb; + seek(ofs, true); + } + return *this; +} + +inline +MatConstIterator& MatConstIterator::operator -= (ptrdiff_t ofs) +{ + return (*this += -ofs); +} + +inline +MatConstIterator& MatConstIterator::operator --() +{ + if( m && (ptr -= elemSize) < sliceStart ) + { + ptr += elemSize; + seek(-1, true); + } + return *this; +} + +inline +MatConstIterator MatConstIterator::operator --(int) +{ + MatConstIterator b = *this; + *this += -1; + return b; +} + +inline +MatConstIterator& MatConstIterator::operator ++() +{ + if( m && (ptr += elemSize) >= sliceEnd ) + { + ptr -= elemSize; + seek(1, true); + } + return *this; +} + +inline MatConstIterator MatConstIterator::operator ++(int) +{ + MatConstIterator b = *this; + *this += 1; + return b; +} + + +static inline +bool operator == (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.m == b.m && a.ptr == b.ptr; +} + +static inline +bool operator != (const MatConstIterator& a, const MatConstIterator& b) +{ + return !(a == b); +} + +static inline +bool operator < (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr < b.ptr; +} + +static inline +bool operator > (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr > b.ptr; +} + +static inline +bool operator <= (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr <= b.ptr; +} + +static inline +bool operator >= (const MatConstIterator& a, const MatConstIterator& b) +{ + return a.ptr >= b.ptr; +} + +static inline +ptrdiff_t operator - (const MatConstIterator& b, const MatConstIterator& a) +{ + if( a.m != b.m ) + return ((size_t)(-1) >> 1); + if( a.sliceEnd == b.sliceEnd ) + return (b.ptr - a.ptr)/static_cast(b.elemSize); + + return b.lpos() - a.lpos(); +} + +static inline +MatConstIterator operator + (const MatConstIterator& a, ptrdiff_t ofs) +{ + MatConstIterator b = a; + return b += ofs; +} + +static inline +MatConstIterator operator + (ptrdiff_t ofs, const MatConstIterator& a) +{ + MatConstIterator b = a; + return b += ofs; +} + +static inline +MatConstIterator operator - (const MatConstIterator& a, ptrdiff_t ofs) +{ + MatConstIterator b = a; + return b += -ofs; +} + + +inline +const uchar* MatConstIterator::operator [](ptrdiff_t i) const +{ + return *(*this + i); +} + + + +///////////////////////// MatConstIterator_ ///////////////////////// + +template inline +MatConstIterator_<_Tp>::MatConstIterator_() +{} + +template inline +MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m) + : MatConstIterator(_m) +{} + +template inline +MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, int _row, int _col) + : MatConstIterator(_m, _row, _col) +{} + +template inline +MatConstIterator_<_Tp>::MatConstIterator_(const Mat_<_Tp>* _m, Point _pt) + : MatConstIterator(_m, _pt) +{} + +template inline +MatConstIterator_<_Tp>::MatConstIterator_(const MatConstIterator_& it) + : MatConstIterator(it) +{} + +template inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator = (const MatConstIterator_& it ) +{ + MatConstIterator::operator = (it); + return *this; +} + +template inline +const _Tp& MatConstIterator_<_Tp>::operator *() const +{ + return *(_Tp*)(this->ptr); +} + +template inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator += (ptrdiff_t ofs) +{ + MatConstIterator::operator += (ofs); + return *this; +} + +template inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator -= (ptrdiff_t ofs) +{ + return (*this += -ofs); +} + +template inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator --() +{ + MatConstIterator::operator --(); + return *this; +} + +template inline +MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator --(int) +{ + MatConstIterator_ b = *this; + MatConstIterator::operator --(); + return b; +} + +template inline +MatConstIterator_<_Tp>& MatConstIterator_<_Tp>::operator ++() +{ + MatConstIterator::operator ++(); + return *this; +} + +template inline +MatConstIterator_<_Tp> MatConstIterator_<_Tp>::operator ++(int) +{ + MatConstIterator_ b = *this; + MatConstIterator::operator ++(); + return b; +} + + +template inline +Point MatConstIterator_<_Tp>::pos() const +{ + if( !m ) + return Point(); + CV_DbgAssert( m->dims <= 2 ); + if( m->isContinuous() ) + { + ptrdiff_t ofs = (const _Tp*)ptr - (const _Tp*)m->data; + int y = (int)(ofs / m->cols); + int x = (int)(ofs - (ptrdiff_t)y * m->cols); + return Point(x, y); + } + else + { + ptrdiff_t ofs = (uchar*)ptr - m->data; + int y = (int)(ofs / m->step); + int x = (int)((ofs - y * m->step)/sizeof(_Tp)); + return Point(x, y); + } +} + + +template static inline +bool operator == (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b) +{ + return a.m == b.m && a.ptr == b.ptr; +} + +template static inline +bool operator != (const MatConstIterator_<_Tp>& a, const MatConstIterator_<_Tp>& b) +{ + return a.m != b.m || a.ptr != b.ptr; +} + +template static inline +MatConstIterator_<_Tp> operator + (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatConstIterator_<_Tp>&)t; +} + +template static inline +MatConstIterator_<_Tp> operator + (ptrdiff_t ofs, const MatConstIterator_<_Tp>& a) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatConstIterator_<_Tp>&)t; +} + +template static inline +MatConstIterator_<_Tp> operator - (const MatConstIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a - ofs; + return (MatConstIterator_<_Tp>&)t; +} + +template inline +const _Tp& MatConstIterator_<_Tp>::operator [](ptrdiff_t i) const +{ + return *(_Tp*)MatConstIterator::operator [](i); +} + + + +//////////////////////////// MatIterator_ /////////////////////////// + +template inline +MatIterator_<_Tp>::MatIterator_() + : MatConstIterator_<_Tp>() +{} + +template inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m) + : MatConstIterator_<_Tp>(_m) +{} + +template inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, int _row, int _col) + : MatConstIterator_<_Tp>(_m, _row, _col) +{} + +template inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, Point _pt) + : MatConstIterator_<_Tp>(_m, _pt) +{} + +template inline +MatIterator_<_Tp>::MatIterator_(Mat_<_Tp>* _m, const int* _idx) + : MatConstIterator_<_Tp>(_m, _idx) +{} + +template inline +MatIterator_<_Tp>::MatIterator_(const MatIterator_& it) + : MatConstIterator_<_Tp>(it) +{} + +template inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator = (const MatIterator_<_Tp>& it ) +{ + MatConstIterator::operator = (it); + return *this; +} + +template inline +_Tp& MatIterator_<_Tp>::operator *() const +{ + return *(_Tp*)(this->ptr); +} + +template inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator += (ptrdiff_t ofs) +{ + MatConstIterator::operator += (ofs); + return *this; +} + +template inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator -= (ptrdiff_t ofs) +{ + MatConstIterator::operator += (-ofs); + return *this; +} + +template inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator --() +{ + MatConstIterator::operator --(); + return *this; +} + +template inline +MatIterator_<_Tp> MatIterator_<_Tp>::operator --(int) +{ + MatIterator_ b = *this; + MatConstIterator::operator --(); + return b; +} + +template inline +MatIterator_<_Tp>& MatIterator_<_Tp>::operator ++() +{ + MatConstIterator::operator ++(); + return *this; +} + +template inline +MatIterator_<_Tp> MatIterator_<_Tp>::operator ++(int) +{ + MatIterator_ b = *this; + MatConstIterator::operator ++(); + return b; +} + +template inline +_Tp& MatIterator_<_Tp>::operator [](ptrdiff_t i) const +{ + return *(*this + i); +} + + +template static inline +bool operator == (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b) +{ + return a.m == b.m && a.ptr == b.ptr; +} + +template static inline +bool operator != (const MatIterator_<_Tp>& a, const MatIterator_<_Tp>& b) +{ + return a.m != b.m || a.ptr != b.ptr; +} + +template static inline +MatIterator_<_Tp> operator + (const MatIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatIterator_<_Tp>&)t; +} + +template static inline +MatIterator_<_Tp> operator + (ptrdiff_t ofs, const MatIterator_<_Tp>& a) +{ + MatConstIterator t = (const MatConstIterator&)a + ofs; + return (MatIterator_<_Tp>&)t; +} + +template static inline +MatIterator_<_Tp> operator - (const MatIterator_<_Tp>& a, ptrdiff_t ofs) +{ + MatConstIterator t = (const MatConstIterator&)a - ofs; + return (MatIterator_<_Tp>&)t; +} + + + +/////////////////////// SparseMatConstIterator ////////////////////// + +inline +SparseMatConstIterator::SparseMatConstIterator() + : m(0), hashidx(0), ptr(0) +{} + +inline +SparseMatConstIterator::SparseMatConstIterator(const SparseMatConstIterator& it) + : m(it.m), hashidx(it.hashidx), ptr(it.ptr) +{} + +inline SparseMatConstIterator& SparseMatConstIterator::operator = (const SparseMatConstIterator& it) +{ + if( this != &it ) + { + m = it.m; + hashidx = it.hashidx; + ptr = it.ptr; + } + return *this; +} + +template inline +const _Tp& SparseMatConstIterator::value() const +{ + return *(const _Tp*)ptr; +} + +inline +const SparseMat::Node* SparseMatConstIterator::node() const +{ + return (ptr && m && m->hdr) ? (const SparseMat::Node*)(const void*)(ptr - m->hdr->valueOffset) : 0; +} + +inline +SparseMatConstIterator SparseMatConstIterator::operator ++(int) +{ + SparseMatConstIterator it = *this; + ++*this; + return it; +} + +inline +void SparseMatConstIterator::seekEnd() +{ + if( m && m->hdr ) + { + hashidx = m->hdr->hashtab.size(); + ptr = 0; + } +} + + +static inline +bool operator == (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2) +{ + return it1.m == it2.m && it1.ptr == it2.ptr; +} + +static inline +bool operator != (const SparseMatConstIterator& it1, const SparseMatConstIterator& it2) +{ + return !(it1 == it2); +} + + + +///////////////////////// SparseMatIterator ///////////////////////// + +inline +SparseMatIterator::SparseMatIterator() +{} + +inline +SparseMatIterator::SparseMatIterator(SparseMat* _m) + : SparseMatConstIterator(_m) +{} + +inline +SparseMatIterator::SparseMatIterator(const SparseMatIterator& it) + : SparseMatConstIterator(it) +{} + +inline +SparseMatIterator& SparseMatIterator::operator = (const SparseMatIterator& it) +{ + (SparseMatConstIterator&)*this = it; + return *this; +} + +template inline +_Tp& SparseMatIterator::value() const +{ + return *(_Tp*)ptr; +} + +inline +SparseMat::Node* SparseMatIterator::node() const +{ + return (SparseMat::Node*)SparseMatConstIterator::node(); +} + +inline +SparseMatIterator& SparseMatIterator::operator ++() +{ + SparseMatConstIterator::operator ++(); + return *this; +} + +inline +SparseMatIterator SparseMatIterator::operator ++(int) +{ + SparseMatIterator it = *this; + ++*this; + return it; +} + + + +////////////////////// SparseMatConstIterator_ ////////////////////// + +template inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_() +{} + +template inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat_<_Tp>* _m) + : SparseMatConstIterator(_m) +{} + +template inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMat* _m) + : SparseMatConstIterator(_m) +{ + CV_Assert( _m->type() == traits::Type<_Tp>::value ); +} + +template inline +SparseMatConstIterator_<_Tp>::SparseMatConstIterator_(const SparseMatConstIterator_<_Tp>& it) + : SparseMatConstIterator(it) +{} + +template inline +SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator = (const SparseMatConstIterator_<_Tp>& it) +{ + return reinterpret_cast&> + (*reinterpret_cast(this) = + reinterpret_cast(it)); +} + +template inline +const _Tp& SparseMatConstIterator_<_Tp>::operator *() const +{ + return *(const _Tp*)this->ptr; +} + +template inline +SparseMatConstIterator_<_Tp>& SparseMatConstIterator_<_Tp>::operator ++() +{ + SparseMatConstIterator::operator ++(); + return *this; +} + +template inline +SparseMatConstIterator_<_Tp> SparseMatConstIterator_<_Tp>::operator ++(int) +{ + SparseMatConstIterator_<_Tp> it = *this; + SparseMatConstIterator::operator ++(); + return it; +} + + + +///////////////////////// SparseMatIterator_ //////////////////////// + +template inline +SparseMatIterator_<_Tp>::SparseMatIterator_() +{} + +template inline +SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat_<_Tp>* _m) + : SparseMatConstIterator_<_Tp>(_m) +{} + +template inline +SparseMatIterator_<_Tp>::SparseMatIterator_(SparseMat* _m) + : SparseMatConstIterator_<_Tp>(_m) +{} + +template inline +SparseMatIterator_<_Tp>::SparseMatIterator_(const SparseMatIterator_<_Tp>& it) + : SparseMatConstIterator_<_Tp>(it) +{} + +template inline +SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator = (const SparseMatIterator_<_Tp>& it) +{ + return reinterpret_cast&> + (*reinterpret_cast(this) = + reinterpret_cast(it)); +} + +template inline +_Tp& SparseMatIterator_<_Tp>::operator *() const +{ + return *(_Tp*)this->ptr; +} + +template inline +SparseMatIterator_<_Tp>& SparseMatIterator_<_Tp>::operator ++() +{ + SparseMatConstIterator::operator ++(); + return *this; +} + +template inline +SparseMatIterator_<_Tp> SparseMatIterator_<_Tp>::operator ++(int) +{ + SparseMatIterator_<_Tp> it = *this; + SparseMatConstIterator::operator ++(); + return it; +} + + + +//////////////////////// MatCommaInitializer_ /////////////////////// + +template inline +MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m) + : it(_m) +{} + +template template inline +MatCommaInitializer_<_Tp>& MatCommaInitializer_<_Tp>::operator , (T2 v) +{ + CV_DbgAssert( this->it < ((const Mat_<_Tp>*)this->it.m)->end() ); + *this->it = _Tp(v); + ++this->it; + return *this; +} + +template inline +MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const +{ + CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() ); + return Mat_<_Tp>(*this->it.m); +} + + +template static inline +MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val) +{ + MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m); + return (commaInitializer, val); +} + + + +///////////////////////// Matrix Expressions //////////////////////// + +inline +Mat& Mat::operator = (const MatExpr& e) +{ + e.op->assign(e, *this); + return *this; +} + +template inline +Mat_<_Tp>::Mat_(const MatExpr& e) +{ + e.op->assign(e, *this, traits::Type<_Tp>::value); +} + +template inline +Mat_<_Tp>& Mat_<_Tp>::operator = (const MatExpr& e) +{ + e.op->assign(e, *this, traits::Type<_Tp>::value); + return *this; +} + +template inline +MatExpr Mat_<_Tp>::zeros(int rows, int cols) +{ + return Mat::zeros(rows, cols, traits::Type<_Tp>::value); +} + +template inline +MatExpr Mat_<_Tp>::zeros(Size sz) +{ + return Mat::zeros(sz, traits::Type<_Tp>::value); +} + +template inline +MatExpr Mat_<_Tp>::ones(int rows, int cols) +{ + return Mat::ones(rows, cols, traits::Type<_Tp>::value); +} + +template inline +MatExpr Mat_<_Tp>::ones(Size sz) +{ + return Mat::ones(sz, traits::Type<_Tp>::value); +} + +template inline +MatExpr Mat_<_Tp>::eye(int rows, int cols) +{ + return Mat::eye(rows, cols, traits::Type<_Tp>::value); +} + +template inline +MatExpr Mat_<_Tp>::eye(Size sz) +{ + return Mat::eye(sz, traits::Type<_Tp>::value); +} + +inline +MatExpr::MatExpr() + : op(0), flags(0), a(Mat()), b(Mat()), c(Mat()), alpha(0), beta(0), s() +{} + +inline +MatExpr::MatExpr(const MatOp* _op, int _flags, const Mat& _a, const Mat& _b, + const Mat& _c, double _alpha, double _beta, const Scalar& _s) + : op(_op), flags(_flags), a(_a), b(_b), c(_c), alpha(_alpha), beta(_beta), s(_s) +{} + +inline +MatExpr::operator Mat() const +{ + Mat m; + op->assign(*this, m); + return m; +} + +template inline +MatExpr::operator Mat_<_Tp>() const +{ + Mat_<_Tp> m; + op->assign(*this, m, traits::Type<_Tp>::value); + return m; +} + + +template static inline +MatExpr min(const Mat_<_Tp>& a, const Mat_<_Tp>& b) +{ + return cv::min((const Mat&)a, (const Mat&)b); +} + +template static inline +MatExpr min(const Mat_<_Tp>& a, double s) +{ + return cv::min((const Mat&)a, s); +} + +template static inline +MatExpr min(double s, const Mat_<_Tp>& a) +{ + return cv::min((const Mat&)a, s); +} + +template static inline +MatExpr max(const Mat_<_Tp>& a, const Mat_<_Tp>& b) +{ + return cv::max((const Mat&)a, (const Mat&)b); +} + +template static inline +MatExpr max(const Mat_<_Tp>& a, double s) +{ + return cv::max((const Mat&)a, s); +} + +template static inline +MatExpr max(double s, const Mat_<_Tp>& a) +{ + return cv::max((const Mat&)a, s); +} + +template static inline +MatExpr abs(const Mat_<_Tp>& m) +{ + return cv::abs((const Mat&)m); +} + + +static inline +Mat& operator += (Mat& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, a); + return a; +} + +static inline +const Mat& operator += (const Mat& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, (Mat&)a); + return a; +} + +template static inline +Mat_<_Tp>& operator += (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, a); + return a; +} + +template static inline +const Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignAdd(b, (Mat&)a); + return a; +} + +static inline +Mat& operator -= (Mat& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, a); + return a; +} + +static inline +const Mat& operator -= (const Mat& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, (Mat&)a); + return a; +} + +template static inline +Mat_<_Tp>& operator -= (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, a); + return a; +} + +template static inline +const Mat_<_Tp>& operator -= (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignSubtract(b, (Mat&)a); + return a; +} + +static inline +Mat& operator *= (Mat& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, a); + return a; +} + +static inline +const Mat& operator *= (const Mat& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, (Mat&)a); + return a; +} + +template static inline +Mat_<_Tp>& operator *= (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, a); + return a; +} + +template static inline +const Mat_<_Tp>& operator *= (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignMultiply(b, (Mat&)a); + return a; +} + +static inline +Mat& operator /= (Mat& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, a); + return a; +} + +static inline +const Mat& operator /= (const Mat& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, (Mat&)a); + return a; +} + +template static inline +Mat_<_Tp>& operator /= (Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, a); + return a; +} + +template static inline +const Mat_<_Tp>& operator /= (const Mat_<_Tp>& a, const MatExpr& b) +{ + b.op->augAssignDivide(b, (Mat&)a); + return a; +} + + +//////////////////////////////// UMat //////////////////////////////// + +inline +UMat::UMat(UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{} + +inline +UMat::UMat(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_rows, _cols, _type); +} + +inline +UMat::UMat(int _rows, int _cols, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_rows, _cols, _type); + *this = _s; +} + +inline +UMat::UMat(Size _sz, int _type, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create( _sz.height, _sz.width, _type ); +} + +inline +UMat::UMat(Size _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_sz.height, _sz.width, _type); + *this = _s; +} + +inline +UMat::UMat(int _dims, const int* _sz, int _type, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_dims, _sz, _type); +} + +inline +UMat::UMat(int _dims, const int* _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +{ + create(_dims, _sz, _type); + *this = _s; +} + +inline +UMat::UMat(const UMat& m) +: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), + usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) +{ + addref(); + if( m.dims <= 2 ) + { + step[0] = m.step[0]; step[1] = m.step[1]; + } + else + { + dims = 0; + copySize(m); + } +} + + +template inline +UMat::UMat(const std::vector<_Tp>& vec, bool copyData) +: flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()), +cols(1), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) +{ + if(vec.empty()) + return; + if( !copyData ) + { + // !!!TODO!!! + CV_Error(Error::StsNotImplemented, ""); + } + else + Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this); +} + +inline +UMat& UMat::operator = (const UMat& m) +{ + if( this != &m ) + { + const_cast(m).addref(); + release(); + flags = m.flags; + if( dims <= 2 && m.dims <= 2 ) + { + dims = m.dims; + rows = m.rows; + cols = m.cols; + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + copySize(m); + allocator = m.allocator; + if (usageFlags == USAGE_DEFAULT) + usageFlags = m.usageFlags; + u = m.u; + offset = m.offset; + } + return *this; +} + +inline +UMat UMat::row(int y) const +{ + return UMat(*this, Range(y, y + 1), Range::all()); +} + +inline +UMat UMat::col(int x) const +{ + return UMat(*this, Range::all(), Range(x, x + 1)); +} + +inline +UMat UMat::rowRange(int startrow, int endrow) const +{ + return UMat(*this, Range(startrow, endrow), Range::all()); +} + +inline +UMat UMat::rowRange(const Range& r) const +{ + return UMat(*this, r, Range::all()); +} + +inline +UMat UMat::colRange(int startcol, int endcol) const +{ + return UMat(*this, Range::all(), Range(startcol, endcol)); +} + +inline +UMat UMat::colRange(const Range& r) const +{ + return UMat(*this, Range::all(), r); +} + +inline +UMat UMat::clone() const +{ + UMat m; + copyTo(m); + return m; +} + +inline +void UMat::assignTo( UMat& m, int _type ) const +{ + if( _type < 0 ) + m = *this; + else + convertTo(m, _type); +} + +inline +void UMat::create(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags) +{ + _type &= TYPE_MASK; + if( dims <= 2 && rows == _rows && cols == _cols && type() == _type && u ) + return; + int sz[] = {_rows, _cols}; + create(2, sz, _type, _usageFlags); +} + +inline +void UMat::create(Size _sz, int _type, UMatUsageFlags _usageFlags) +{ + create(_sz.height, _sz.width, _type, _usageFlags); +} + +inline +void UMat::addref() +{ + if( u ) + CV_XADD(&(u->urefcount), 1); +} + +inline void UMat::release() +{ + if( u && CV_XADD(&(u->urefcount), -1) == 1 ) + deallocate(); + for(int i = 0; i < dims; i++) + size.p[i] = 0; + u = 0; +} + +inline +UMat UMat::operator()( Range _rowRange, Range _colRange ) const +{ + return UMat(*this, _rowRange, _colRange); +} + +inline +UMat UMat::operator()( const Rect& roi ) const +{ + return UMat(*this, roi); +} + +inline +UMat UMat::operator()(const Range* ranges) const +{ + return UMat(*this, ranges); +} + +inline +UMat UMat::operator()(const std::vector& ranges) const +{ + return UMat(*this, ranges); +} + +inline +bool UMat::isContinuous() const +{ + return (flags & CONTINUOUS_FLAG) != 0; +} + +inline +bool UMat::isSubmatrix() const +{ + return (flags & SUBMATRIX_FLAG) != 0; +} + +inline +size_t UMat::elemSize() const +{ + size_t res = dims > 0 ? step.p[dims - 1] : 0; + CV_DbgAssert(res != 0); + return res; +} + +inline +size_t UMat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} + +inline +int UMat::type() const +{ + return CV_MAT_TYPE(flags); +} + +inline +int UMat::depth() const +{ + return CV_MAT_DEPTH(flags); +} + +inline +int UMat::channels() const +{ + return CV_MAT_CN(flags); +} + +inline +size_t UMat::step1(int i) const +{ + return step.p[i] / elemSize1(); +} + +inline +bool UMat::empty() const +{ + return u == 0 || total() == 0 || dims == 0; +} + +inline +size_t UMat::total() const +{ + if( dims <= 2 ) + return (size_t)rows * cols; + size_t p = 1; + for( int i = 0; i < dims; i++ ) + p *= size[i]; + return p; +} + +inline +UMat::UMat(UMat&& m) +: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), + usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) +{ + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.allocator = NULL; + m.u = NULL; + m.offset = 0; +} + +inline +UMat& UMat::operator = (UMat&& m) +{ + if (this == &m) + return *this; + release(); + flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; + allocator = m.allocator; usageFlags = m.usageFlags; + u = m.u; + offset = m.offset; + if (step.p != step.buf) // release self step/size + { + fastFree(step.p); + step.p = step.buf; + size.p = &rows; + } + if (m.dims <= 2) // move new step/size info + { + step[0] = m.step[0]; + step[1] = m.step[1]; + } + else + { + CV_DbgAssert(m.step.p != m.step.buf); + step.p = m.step.p; + size.p = m.size.p; + m.step.p = m.step.buf; + m.size.p = &m.rows; + } + m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.allocator = NULL; + m.u = NULL; + m.offset = 0; + return *this; +} + + +inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; } +inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; } +inline bool UMatData::deviceMemMapped() const { return (flags & DEVICE_MEM_MAPPED) != 0; } +inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; } +inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; } +inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; } + +inline void UMatData::markDeviceMemMapped(bool flag) +{ + if(flag) + flags |= DEVICE_MEM_MAPPED; + else + flags &= ~DEVICE_MEM_MAPPED; +} + +inline void UMatData::markHostCopyObsolete(bool flag) +{ + if(flag) + flags |= HOST_COPY_OBSOLETE; + else + flags &= ~HOST_COPY_OBSOLETE; +} +inline void UMatData::markDeviceCopyObsolete(bool flag) +{ + if(flag) + flags |= DEVICE_COPY_OBSOLETE; + else + flags &= ~DEVICE_COPY_OBSOLETE; +} + +//! @endcond + +} //cv + +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/matx.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/matx.hpp new file mode 100644 index 0000000000000000000000000000000000000000..de34da45a4992fd2334cb55ff4c41a503aacda76 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/matx.hpp @@ -0,0 +1,1471 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_MATX_HPP +#define OPENCV_CORE_MATX_HPP + +#ifndef __cplusplus +# error matx.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/base.hpp" +#include "opencv2/core/traits.hpp" +#include "opencv2/core/saturate.hpp" + +#include + +namespace cv +{ + +//! @addtogroup core_basic +//! @{ + +////////////////////////////// Small Matrix /////////////////////////// + +//! @cond IGNORED +// FIXIT Remove this (especially CV_EXPORTS modifier) +struct CV_EXPORTS Matx_AddOp { Matx_AddOp() {} Matx_AddOp(const Matx_AddOp&) {} }; +struct CV_EXPORTS Matx_SubOp { Matx_SubOp() {} Matx_SubOp(const Matx_SubOp&) {} }; +struct CV_EXPORTS Matx_ScaleOp { Matx_ScaleOp() {} Matx_ScaleOp(const Matx_ScaleOp&) {} }; +struct CV_EXPORTS Matx_MulOp { Matx_MulOp() {} Matx_MulOp(const Matx_MulOp&) {} }; +struct CV_EXPORTS Matx_DivOp { Matx_DivOp() {} Matx_DivOp(const Matx_DivOp&) {} }; +struct CV_EXPORTS Matx_MatMulOp { Matx_MatMulOp() {} Matx_MatMulOp(const Matx_MatMulOp&) {} }; +struct CV_EXPORTS Matx_TOp { Matx_TOp() {} Matx_TOp(const Matx_TOp&) {} }; +//! @endcond + +/** @brief Template class for small matrices whose type and size are known at compilation time + +If you need a more flexible type, use Mat . The elements of the matrix M are accessible using the +M(i,j) notation. Most of the common matrix operations (see also @ref MatrixExpressions ) are +available. To do an operation on Matx that is not implemented, you can easily convert the matrix to +Mat and backwards: +@code{.cpp} + Matx33f m(1, 2, 3, + 4, 5, 6, + 7, 8, 9); + cout << sum(Mat(m*m.t())) << endl; +@endcode +Except of the plain constructor which takes a list of elements, Matx can be initialized from a C-array: +@code{.cpp} + float values[] = { 1, 2, 3}; + Matx31f m(values); +@endcode +In case if C++11 features are available, std::initializer_list can be also used to initialize Matx: +@code{.cpp} + Matx31f m = { 1, 2, 3}; +@endcode + */ +template class Matx +{ +public: + enum { + rows = m, + cols = n, + channels = rows*cols, +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = traits::Type<_Tp>::value, + type = CV_MAKETYPE(depth, channels), +#endif + shortdim = (m < n ? m : n) + }; + + typedef _Tp value_type; + typedef Matx<_Tp, m, n> mat_type; + typedef Matx<_Tp, shortdim, 1> diag_type; + + //! default constructor + Matx(); + + explicit Matx(_Tp v0); //!< 1x1 matrix + Matx(_Tp v0, _Tp v1); //!< 1x2 or 2x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2); //!< 1x3 or 3x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 1x4, 2x2 or 4x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 1x5 or 5x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 1x6, 2x3, 3x2 or 6x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 1x7 or 7x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 1x8, 2x4, 4x2 or 8x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 1x9, 3x3 or 9x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 1x10, 2x5 or 5x2 or 10x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, + _Tp v4, _Tp v5, _Tp v6, _Tp v7, + _Tp v8, _Tp v9, _Tp v10, _Tp v11); //!< 1x12, 2x6, 3x4, 4x3, 6x2 or 12x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, + _Tp v4, _Tp v5, _Tp v6, _Tp v7, + _Tp v8, _Tp v9, _Tp v10, _Tp v11, + _Tp v12, _Tp v13); //!< 1x14, 2x7, 7x2 or 14x1 matrix + Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, + _Tp v4, _Tp v5, _Tp v6, _Tp v7, + _Tp v8, _Tp v9, _Tp v10, _Tp v11, + _Tp v12, _Tp v13, _Tp v14, _Tp v15); //!< 1x16, 4x4 or 16x1 matrix + explicit Matx(const _Tp* vals); //!< initialize from a plain array + + Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list + + static Matx all(_Tp alpha); + static Matx zeros(); + static Matx ones(); + static Matx eye(); + static Matx diag(const diag_type& d); + static Matx randu(_Tp a, _Tp b); + static Matx randn(_Tp a, _Tp b); + + //! dot product computed with the default precision + _Tp dot(const Matx<_Tp, m, n>& v) const; + + //! dot product computed in double-precision arithmetics + double ddot(const Matx<_Tp, m, n>& v) const; + + //! conversion to another data type + template operator Matx() const; + + //! change the matrix shape + template Matx<_Tp, m1, n1> reshape() const; + + //! extract part of the matrix + template Matx<_Tp, m1, n1> get_minor(int base_row, int base_col) const; + + //! extract the matrix row + Matx<_Tp, 1, n> row(int i) const; + + //! extract the matrix column + Matx<_Tp, m, 1> col(int i) const; + + //! extract the matrix diagonal + diag_type diag() const; + + //! transpose the matrix + Matx<_Tp, n, m> t() const; + + //! invert the matrix + Matx<_Tp, n, m> inv(int method=DECOMP_LU, bool *p_is_ok = NULL) const; + + //! solve linear system + template Matx<_Tp, n, l> solve(const Matx<_Tp, m, l>& rhs, int flags=DECOMP_LU) const; + Vec<_Tp, n> solve(const Vec<_Tp, m>& rhs, int method) const; + + //! multiply two matrices element-wise + Matx<_Tp, m, n> mul(const Matx<_Tp, m, n>& a) const; + + //! divide two matrices element-wise + Matx<_Tp, m, n> div(const Matx<_Tp, m, n>& a) const; + + //! element access + const _Tp& operator ()(int row, int col) const; + _Tp& operator ()(int row, int col); + + //! 1D element access + const _Tp& operator ()(int i) const; + _Tp& operator ()(int i); + + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp); + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp); + template Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp); + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp); + Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp); + template Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp); + Matx(const Matx<_Tp, n, m>& a, Matx_TOp); + + _Tp val[m*n]; //< matrix elements +}; + +typedef Matx Matx12f; +typedef Matx Matx12d; +typedef Matx Matx13f; +typedef Matx Matx13d; +typedef Matx Matx14f; +typedef Matx Matx14d; +typedef Matx Matx16f; +typedef Matx Matx16d; + +typedef Matx Matx21f; +typedef Matx Matx21d; +typedef Matx Matx31f; +typedef Matx Matx31d; +typedef Matx Matx41f; +typedef Matx Matx41d; +typedef Matx Matx61f; +typedef Matx Matx61d; + +typedef Matx Matx22f; +typedef Matx Matx22d; +typedef Matx Matx23f; +typedef Matx Matx23d; +typedef Matx Matx32f; +typedef Matx Matx32d; + +typedef Matx Matx33f; +typedef Matx Matx33d; + +typedef Matx Matx34f; +typedef Matx Matx34d; +typedef Matx Matx43f; +typedef Matx Matx43d; + +typedef Matx Matx44f; +typedef Matx Matx44d; +typedef Matx Matx66f; +typedef Matx Matx66d; + +/*! + traits +*/ +template class DataType< Matx<_Tp, m, n> > +{ +public: + typedef Matx<_Tp, m, n> value_type; + typedef Matx::work_type, m, n> work_type; + typedef _Tp channel_type; + typedef value_type vec_type; + + enum { generic_type = 0, + channels = m * n, + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; +}; + +namespace traits { +template +struct Depth< Matx<_Tp, m, n> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Matx<_Tp, m, n> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, n*m) }; }; +} // namespace + + +/** @brief Comma-separated Matrix Initializer +*/ +template class MatxCommaInitializer +{ +public: + MatxCommaInitializer(Matx<_Tp, m, n>* _mtx); + template MatxCommaInitializer<_Tp, m, n>& operator , (T2 val); + Matx<_Tp, m, n> operator *() const; + + Matx<_Tp, m, n>* dst; + int idx; +}; + +/* + Utility methods +*/ +template static double determinant(const Matx<_Tp, m, m>& a); +template static double trace(const Matx<_Tp, m, n>& a); +template static double norm(const Matx<_Tp, m, n>& M); +template static double norm(const Matx<_Tp, m, n>& M, int normType); + + + +/////////////////////// Vec (used as element of multi-channel images ///////////////////// + +/** @brief Template class for short numerical vectors, a partial case of Matx + +This template class represents short numerical vectors (of 1, 2, 3, 4 ... elements) on which you +can perform basic arithmetical operations, access individual elements using [] operator etc. The +vectors are allocated on stack, as opposite to std::valarray, std::vector, cv::Mat etc., which +elements are dynamically allocated in the heap. + +The template takes 2 parameters: +@tparam _Tp element type +@tparam cn the number of elements + +In addition to the universal notation like Vec, you can use shorter aliases +for the most popular specialized variants of Vec, e.g. Vec3f ~ Vec. + +It is possible to convert Vec\ to/from Point_, Vec\ to/from Point3_ , and Vec\ +to CvScalar or Scalar_. Use operator[] to access the elements of Vec. + +All the expected vector operations are also implemented: +- v1 = v2 + v3 +- v1 = v2 - v3 +- v1 = v2 \* scale +- v1 = scale \* v2 +- v1 = -v2 +- v1 += v2 and other augmenting operations +- v1 == v2, v1 != v2 +- norm(v1) (euclidean norm) +The Vec class is commonly used to describe pixel types of multi-channel arrays. See Mat for details. +*/ +template class Vec : public Matx<_Tp, cn, 1> +{ +public: + typedef _Tp value_type; + enum { + channels = cn, +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = Matx<_Tp, cn, 1>::depth, + type = CV_MAKETYPE(depth, channels), +#endif + _dummy_enum_finalizer = 0 + }; + + //! default constructor + Vec(); + + Vec(_Tp v0); //!< 1-element vector constructor + Vec(_Tp v0, _Tp v1); //!< 2-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2); //!< 3-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 4-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 5-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 6-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 7-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 8-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 9-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 10-element vector constructor + Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13); //!< 14-element vector constructor + explicit Vec(const _Tp* values); + + Vec(std::initializer_list<_Tp>); + + Vec(const Vec<_Tp, cn>& v); + + static Vec all(_Tp alpha); + + //! per-element multiplication + Vec mul(const Vec<_Tp, cn>& v) const; + + //! conjugation (makes sense for complex numbers and quaternions) + Vec conj() const; + + /*! + cross product of the two 3D vectors. + + For other dimensionalities the exception is raised + */ + Vec cross(const Vec& v) const; + //! conversion to another data type + template operator Vec() const; + + /*! element access */ + const _Tp& operator [](int i) const; + _Tp& operator[](int i); + const _Tp& operator ()(int i) const; + _Tp& operator ()(int i); + +#ifdef CV_CXX11 + Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default; +#endif + + Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp); + Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp); + template Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp); +}; + +/** @name Shorter aliases for the most popular specializations of Vec + @{ +*/ +typedef Vec Vec2b; +typedef Vec Vec3b; +typedef Vec Vec4b; + +typedef Vec Vec2s; +typedef Vec Vec3s; +typedef Vec Vec4s; + +typedef Vec Vec2w; +typedef Vec Vec3w; +typedef Vec Vec4w; + +typedef Vec Vec2i; +typedef Vec Vec3i; +typedef Vec Vec4i; +typedef Vec Vec6i; +typedef Vec Vec8i; + +typedef Vec Vec2f; +typedef Vec Vec3f; +typedef Vec Vec4f; +typedef Vec Vec6f; + +typedef Vec Vec2d; +typedef Vec Vec3d; +typedef Vec Vec4d; +typedef Vec Vec6d; +/** @} */ + +/*! + traits +*/ +template class DataType< Vec<_Tp, cn> > +{ +public: + typedef Vec<_Tp, cn> value_type; + typedef Vec::work_type, cn> work_type; + typedef _Tp channel_type; + typedef value_type vec_type; + + enum { generic_type = 0, + channels = cn, + fmt = DataType::fmt + ((channels - 1) << 8), +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + depth = DataType::depth, + type = CV_MAKETYPE(depth, channels), +#endif + _dummy_enum_finalizer = 0 + }; +}; + +namespace traits { +template +struct Depth< Vec<_Tp, cn> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Vec<_Tp, cn> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, cn) }; }; +} // namespace + + +/** @brief Comma-separated Vec Initializer +*/ +template class VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1> +{ +public: + VecCommaInitializer(Vec<_Tp, m>* _vec); + template VecCommaInitializer<_Tp, m>& operator , (T2 val); + Vec<_Tp, m> operator *() const; +}; + +template static Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v); + +//! @} core_basic + +//! @cond IGNORED + +///////////////////////////////////// helper classes ///////////////////////////////////// +namespace internal +{ + +template struct Matx_DetOp +{ + double operator ()(const Matx<_Tp, m, m>& a) const + { + Matx<_Tp, m, m> temp = a; + double p = LU(temp.val, m*sizeof(_Tp), m, 0, 0, 0); + if( p == 0 ) + return p; + for( int i = 0; i < m; i++ ) + p *= temp(i, i); + return p; + } +}; + +template struct Matx_DetOp<_Tp, 1> +{ + double operator ()(const Matx<_Tp, 1, 1>& a) const + { + return a(0,0); + } +}; + +template struct Matx_DetOp<_Tp, 2> +{ + double operator ()(const Matx<_Tp, 2, 2>& a) const + { + return a(0,0)*a(1,1) - a(0,1)*a(1,0); + } +}; + +template struct Matx_DetOp<_Tp, 3> +{ + double operator ()(const Matx<_Tp, 3, 3>& a) const + { + return a(0,0)*(a(1,1)*a(2,2) - a(2,1)*a(1,2)) - + a(0,1)*(a(1,0)*a(2,2) - a(2,0)*a(1,2)) + + a(0,2)*(a(1,0)*a(2,1) - a(2,0)*a(1,1)); + } +}; + +template Vec<_Tp, 2> inline conjugate(const Vec<_Tp, 2>& v) +{ + return Vec<_Tp, 2>(v[0], -v[1]); +} + +template Vec<_Tp, 4> inline conjugate(const Vec<_Tp, 4>& v) +{ + return Vec<_Tp, 4>(v[0], -v[1], -v[2], -v[3]); +} + +} // internal + + + +////////////////////////////////// Matx Implementation /////////////////////////////////// + +template inline +Matx<_Tp, m, n>::Matx() +{ + for(int i = 0; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0) +{ + val[0] = v0; + for(int i = 1; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1) +{ + CV_StaticAssert(channels >= 2, "Matx should have at least 2 elements."); + val[0] = v0; val[1] = v1; + for(int i = 2; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2) +{ + CV_StaticAssert(channels >= 3, "Matx should have at least 3 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; + for(int i = 3; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3) +{ + CV_StaticAssert(channels >= 4, "Matx should have at least 4 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + for(int i = 4; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4) +{ + CV_StaticAssert(channels >= 5, "Matx should have at least 5 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; val[4] = v4; + for(int i = 5; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5) +{ + CV_StaticAssert(channels >= 6, "Matx should have at least 6 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; + for(int i = 6; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6) +{ + CV_StaticAssert(channels >= 7, "Matx should have at least 7 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; + for(int i = 7; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7) +{ + CV_StaticAssert(channels >= 8, "Matx should have at least 8 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + for(int i = 8; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8) +{ + CV_StaticAssert(channels >= 9, "Matx should have at least 9 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; + for(int i = 9; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9) +{ + CV_StaticAssert(channels >= 10, "Matx should have at least 10 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; + for(int i = 10; i < channels; i++) val[i] = _Tp(0); +} + + +template inline +Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11) +{ + CV_StaticAssert(channels >= 12, "Matx should have at least 12 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; + for(int i = 12; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13) +{ + CV_StaticAssert(channels >= 14, "Matx should have at least 14 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; + val[12] = v12; val[13] = v13; + for (int i = 14; i < channels; i++) val[i] = _Tp(0); +} + + +template inline +Matx<_Tp,m,n>::Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13, _Tp v14, _Tp v15) +{ + CV_StaticAssert(channels >= 16, "Matx should have at least 16 elements."); + val[0] = v0; val[1] = v1; val[2] = v2; val[3] = v3; + val[4] = v4; val[5] = v5; val[6] = v6; val[7] = v7; + val[8] = v8; val[9] = v9; val[10] = v10; val[11] = v11; + val[12] = v12; val[13] = v13; val[14] = v14; val[15] = v15; + for(int i = 16; i < channels; i++) val[i] = _Tp(0); +} + +template inline +Matx<_Tp, m, n>::Matx(const _Tp* values) +{ + for( int i = 0; i < channels; i++ ) val[i] = values[i]; +} + +template inline +Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list) +{ + CV_DbgAssert(list.size() == channels); + int i = 0; + for(const auto& elem : list) + { + val[i++] = elem; + } +} + +template inline +Matx<_Tp, m, n> Matx<_Tp, m, n>::all(_Tp alpha) +{ + Matx<_Tp, m, n> M; + for( int i = 0; i < m*n; i++ ) M.val[i] = alpha; + return M; +} + +template inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::zeros() +{ + return all(0); +} + +template inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::ones() +{ + return all(1); +} + +template inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::eye() +{ + Matx<_Tp,m,n> M; + for(int i = 0; i < shortdim; i++) + M(i,i) = 1; + return M; +} + +template inline +_Tp Matx<_Tp, m, n>::dot(const Matx<_Tp, m, n>& M) const +{ + _Tp s = 0; + for( int i = 0; i < channels; i++ ) s += val[i]*M.val[i]; + return s; +} + +template inline +double Matx<_Tp, m, n>::ddot(const Matx<_Tp, m, n>& M) const +{ + double s = 0; + for( int i = 0; i < channels; i++ ) s += (double)val[i]*M.val[i]; + return s; +} + +template inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const typename Matx<_Tp,m,n>::diag_type& d) +{ + Matx<_Tp,m,n> M; + for(int i = 0; i < shortdim; i++) + M(i,i) = d(i, 0); + return M; +} + +template template +inline Matx<_Tp, m, n>::operator Matx() const +{ + Matx M; + for( int i = 0; i < m*n; i++ ) M.val[i] = saturate_cast(val[i]); + return M; +} + +template template inline +Matx<_Tp, m1, n1> Matx<_Tp, m, n>::reshape() const +{ + CV_StaticAssert(m1*n1 == m*n, "Input and destnarion matrices must have the same number of elements"); + return (const Matx<_Tp, m1, n1>&)*this; +} + +template +template inline +Matx<_Tp, m1, n1> Matx<_Tp, m, n>::get_minor(int base_row, int base_col) const +{ + CV_DbgAssert(0 <= base_row && base_row+m1 <= m && 0 <= base_col && base_col+n1 <= n); + Matx<_Tp, m1, n1> s; + for( int di = 0; di < m1; di++ ) + for( int dj = 0; dj < n1; dj++ ) + s(di, dj) = (*this)(base_row+di, base_col+dj); + return s; +} + +template inline +Matx<_Tp, 1, n> Matx<_Tp, m, n>::row(int i) const +{ + CV_DbgAssert((unsigned)i < (unsigned)m); + return Matx<_Tp, 1, n>(&val[i*n]); +} + +template inline +Matx<_Tp, m, 1> Matx<_Tp, m, n>::col(int j) const +{ + CV_DbgAssert((unsigned)j < (unsigned)n); + Matx<_Tp, m, 1> v; + for( int i = 0; i < m; i++ ) + v.val[i] = val[i*n + j]; + return v; +} + +template inline +typename Matx<_Tp, m, n>::diag_type Matx<_Tp, m, n>::diag() const +{ + diag_type d; + for( int i = 0; i < shortdim; i++ ) + d.val[i] = val[i*n + i]; + return d; +} + +template inline +const _Tp& Matx<_Tp, m, n>::operator()(int row_idx, int col_idx) const +{ + CV_DbgAssert( (unsigned)row_idx < (unsigned)m && (unsigned)col_idx < (unsigned)n ); + return this->val[row_idx*n + col_idx]; +} + +template inline +_Tp& Matx<_Tp, m, n>::operator ()(int row_idx, int col_idx) +{ + CV_DbgAssert( (unsigned)row_idx < (unsigned)m && (unsigned)col_idx < (unsigned)n ); + return val[row_idx*n + col_idx]; +} + +template inline +const _Tp& Matx<_Tp, m, n>::operator ()(int i) const +{ + CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row"); + CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) ); + return val[i]; +} + +template inline +_Tp& Matx<_Tp, m, n>::operator ()(int i) +{ + CV_StaticAssert(m == 1 || n == 1, "Single index indexation requires matrix to be a column or a row"); + CV_DbgAssert( (unsigned)i < (unsigned)(m+n-1) ); + return val[i]; +} + +template inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] + b.val[i]); +} + +template inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] - b.val[i]); +} + +template template inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] * alpha); +} + +template inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] * b.val[i]); +} + +template inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp) +{ + for( int i = 0; i < channels; i++ ) + val[i] = saturate_cast<_Tp>(a.val[i] / b.val[i]); +} + +template template inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp) +{ + for( int i = 0; i < m; i++ ) + for( int j = 0; j < n; j++ ) + { + _Tp s = 0; + for( int k = 0; k < l; k++ ) + s += a(i, k) * b(k, j); + val[i*n + j] = s; + } +} + +template inline +Matx<_Tp,m,n>::Matx(const Matx<_Tp, n, m>& a, Matx_TOp) +{ + for( int i = 0; i < m; i++ ) + for( int j = 0; j < n; j++ ) + val[i*n + j] = a(j, i); +} + +template inline +Matx<_Tp, m, n> Matx<_Tp, m, n>::mul(const Matx<_Tp, m, n>& a) const +{ + return Matx<_Tp, m, n>(*this, a, Matx_MulOp()); +} + +template inline +Matx<_Tp, m, n> Matx<_Tp, m, n>::div(const Matx<_Tp, m, n>& a) const +{ + return Matx<_Tp, m, n>(*this, a, Matx_DivOp()); +} + +template inline +Matx<_Tp, n, m> Matx<_Tp, m, n>::t() const +{ + return Matx<_Tp, n, m>(*this, Matx_TOp()); +} + +template inline +Vec<_Tp, n> Matx<_Tp, m, n>::solve(const Vec<_Tp, m>& rhs, int method) const +{ + Matx<_Tp, n, 1> x = solve((const Matx<_Tp, m, 1>&)(rhs), method); + return (Vec<_Tp, n>&)(x); +} + +template static inline +double determinant(const Matx<_Tp, m, m>& a) +{ + return cv::internal::Matx_DetOp<_Tp, m>()(a); +} + +template static inline +double trace(const Matx<_Tp, m, n>& a) +{ + _Tp s = 0; + for( int i = 0; i < std::min(m, n); i++ ) + s += a(i,i); + return s; +} + +template static inline +double norm(const Matx<_Tp, m, n>& M) +{ + return std::sqrt(normL2Sqr<_Tp, double>(M.val, m*n)); +} + +template static inline +double norm(const Matx<_Tp, m, n>& M, int normType) +{ + switch(normType) { + case NORM_INF: + return (double)normInf<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); + case NORM_L1: + return (double)normL1<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); + case NORM_L2SQR: + return (double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n); + default: + case NORM_L2: + return std::sqrt((double)normL2Sqr<_Tp, typename DataType<_Tp>::work_type>(M.val, m*n)); + } +} + + + +//////////////////////////////// matx comma initializer ////////////////////////////////// + +template static inline +MatxCommaInitializer<_Tp, m, n> operator << (const Matx<_Tp, m, n>& mtx, _T2 val) +{ + MatxCommaInitializer<_Tp, m, n> commaInitializer((Matx<_Tp, m, n>*)&mtx); + return (commaInitializer, val); +} + +template inline +MatxCommaInitializer<_Tp, m, n>::MatxCommaInitializer(Matx<_Tp, m, n>* _mtx) + : dst(_mtx), idx(0) +{} + +template template inline +MatxCommaInitializer<_Tp, m, n>& MatxCommaInitializer<_Tp, m, n>::operator , (_T2 value) +{ + CV_DbgAssert( idx < m*n ); + dst->val[idx++] = saturate_cast<_Tp>(value); + return *this; +} + +template inline +Matx<_Tp, m, n> MatxCommaInitializer<_Tp, m, n>::operator *() const +{ + CV_DbgAssert( idx == n*m ); + return *dst; +} + + + +/////////////////////////////////// Vec Implementation /////////////////////////////////// + +template inline +Vec<_Tp, cn>::Vec() {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0) + : Matx<_Tp, cn, 1>(v0) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1) + : Matx<_Tp, cn, 1>(v0, v1) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2) + : Matx<_Tp, cn, 1>(v0, v1, v2) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) {} + +template inline +Vec<_Tp, cn>::Vec(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9, _Tp v10, _Tp v11, _Tp v12, _Tp v13) + : Matx<_Tp, cn, 1>(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) {} + +template inline +Vec<_Tp, cn>::Vec(const _Tp* values) + : Matx<_Tp, cn, 1>(values) {} + +template inline +Vec<_Tp, cn>::Vec(std::initializer_list<_Tp> list) + : Matx<_Tp, cn, 1>(list) {} + +template inline +Vec<_Tp, cn>::Vec(const Vec<_Tp, cn>& m) + : Matx<_Tp, cn, 1>(m.val) {} + +template inline +Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_AddOp op) + : Matx<_Tp, cn, 1>(a, b, op) {} + +template inline +Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, const Matx<_Tp, cn, 1>& b, Matx_SubOp op) + : Matx<_Tp, cn, 1>(a, b, op) {} + +template template inline +Vec<_Tp, cn>::Vec(const Matx<_Tp, cn, 1>& a, _T2 alpha, Matx_ScaleOp op) + : Matx<_Tp, cn, 1>(a, alpha, op) {} + +template inline +Vec<_Tp, cn> Vec<_Tp, cn>::all(_Tp alpha) +{ + Vec v; + for( int i = 0; i < cn; i++ ) v.val[i] = alpha; + return v; +} + +template inline +Vec<_Tp, cn> Vec<_Tp, cn>::mul(const Vec<_Tp, cn>& v) const +{ + Vec<_Tp, cn> w; + for( int i = 0; i < cn; i++ ) w.val[i] = saturate_cast<_Tp>(this->val[i]*v.val[i]); + return w; +} + +template<> inline +Vec Vec::conj() const +{ + return cv::internal::conjugate(*this); +} + +template<> inline +Vec Vec::conj() const +{ + return cv::internal::conjugate(*this); +} + +template<> inline +Vec Vec::conj() const +{ + return cv::internal::conjugate(*this); +} + +template<> inline +Vec Vec::conj() const +{ + return cv::internal::conjugate(*this); +} + +template inline +Vec<_Tp, cn> Vec<_Tp, cn>::cross(const Vec<_Tp, cn>&) const +{ + CV_StaticAssert(cn == 3, "for arbitrary-size vector there is no cross-product defined"); + return Vec<_Tp, cn>(); +} + +template<> inline +Vec Vec::cross(const Vec& v) const +{ + return Vec(this->val[1]*v.val[2] - this->val[2]*v.val[1], + this->val[2]*v.val[0] - this->val[0]*v.val[2], + this->val[0]*v.val[1] - this->val[1]*v.val[0]); +} + +template<> inline +Vec Vec::cross(const Vec& v) const +{ + return Vec(this->val[1]*v.val[2] - this->val[2]*v.val[1], + this->val[2]*v.val[0] - this->val[0]*v.val[2], + this->val[0]*v.val[1] - this->val[1]*v.val[0]); +} + +template template inline +Vec<_Tp, cn>::operator Vec() const +{ + Vec v; + for( int i = 0; i < cn; i++ ) v.val[i] = saturate_cast(this->val[i]); + return v; +} + +template inline +const _Tp& Vec<_Tp, cn>::operator [](int i) const +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template inline +_Tp& Vec<_Tp, cn>::operator [](int i) +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template inline +const _Tp& Vec<_Tp, cn>::operator ()(int i) const +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template inline +_Tp& Vec<_Tp, cn>::operator ()(int i) +{ + CV_DbgAssert( (unsigned)i < (unsigned)cn ); + return this->val[i]; +} + +template inline +Vec<_Tp, cn> normalize(const Vec<_Tp, cn>& v) +{ + double nv = norm(v); + return v * (nv ? 1./nv : 0.); +} + + + +//////////////////////////////// vec comma initializer ////////////////////////////////// + + +template static inline +VecCommaInitializer<_Tp, cn> operator << (const Vec<_Tp, cn>& vec, _T2 val) +{ + VecCommaInitializer<_Tp, cn> commaInitializer((Vec<_Tp, cn>*)&vec); + return (commaInitializer, val); +} + +template inline +VecCommaInitializer<_Tp, cn>::VecCommaInitializer(Vec<_Tp, cn>* _vec) + : MatxCommaInitializer<_Tp, cn, 1>(_vec) +{} + +template template inline +VecCommaInitializer<_Tp, cn>& VecCommaInitializer<_Tp, cn>::operator , (_T2 value) +{ + CV_DbgAssert( this->idx < cn ); + this->dst->val[this->idx++] = saturate_cast<_Tp>(value); + return *this; +} + +template inline +Vec<_Tp, cn> VecCommaInitializer<_Tp, cn>::operator *() const +{ + CV_DbgAssert( this->idx == cn ); + return *this->dst; +} + +//! @endcond + +///////////////////////////// Matx out-of-class operators //////////////////////////////// + +//! @relates cv::Matx +//! @{ + +template static inline +Matx<_Tp1, m, n>& operator += (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); + return a; +} + +template static inline +Matx<_Tp1, m, n>& operator -= (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); + return a; +} + +template static inline +Matx<_Tp, m, n> operator + (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + return Matx<_Tp, m, n>(a, b, Matx_AddOp()); +} + +template static inline +Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + return Matx<_Tp, m, n>(a, b, Matx_SubOp()); +} + +template static inline +Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, int alpha) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); + return a; +} + +template static inline +Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, float alpha) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); + return a; +} + +template static inline +Matx<_Tp, m, n>& operator *= (Matx<_Tp, m, n>& a, double alpha) +{ + for( int i = 0; i < m*n; i++ ) + a.val[i] = saturate_cast<_Tp>(a.val[i] * alpha); + return a; +} + +template static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, int alpha) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, float alpha) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, n>& a, double alpha) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Matx<_Tp, m, n> operator * (int alpha, const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Matx<_Tp, m, n> operator * (float alpha, const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Matx<_Tp, m, n> operator * (double alpha, const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Matx<_Tp, m, n> operator - (const Matx<_Tp, m, n>& a) +{ + return Matx<_Tp, m, n>(a, -1, Matx_ScaleOp()); +} + +template static inline +Matx<_Tp, m, n> operator * (const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b) +{ + return Matx<_Tp, m, n>(a, b, Matx_MatMulOp()); +} + +template static inline +Vec<_Tp, m> operator * (const Matx<_Tp, m, n>& a, const Vec<_Tp, n>& b) +{ + Matx<_Tp, m, 1> c(a, b, Matx_MatMulOp()); + return (const Vec<_Tp, m>&)(c); +} + +template static inline +bool operator == (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + for( int i = 0; i < m*n; i++ ) + if( a.val[i] != b.val[i] ) return false; + return true; +} + +template static inline +bool operator != (const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b) +{ + return !(a == b); +} + +//! @} + +////////////////////////////// Vec out-of-class operators //////////////////////////////// + +//! @relates cv::Vec +//! @{ + +template static inline +Vec<_Tp1, cn>& operator += (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) +{ + for( int i = 0; i < cn; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] + b.val[i]); + return a; +} + +template static inline +Vec<_Tp1, cn>& operator -= (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b) +{ + for( int i = 0; i < cn; i++ ) + a.val[i] = saturate_cast<_Tp1>(a.val[i] - b.val[i]); + return a; +} + +template static inline +Vec<_Tp, cn> operator + (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b) +{ + return Vec<_Tp, cn>(a, b, Matx_AddOp()); +} + +template static inline +Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a, const Vec<_Tp, cn>& b) +{ + return Vec<_Tp, cn>(a, b, Matx_SubOp()); +} + +template static inline +Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, int alpha) +{ + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*alpha); + return a; +} + +template static inline +Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, float alpha) +{ + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*alpha); + return a; +} + +template static inline +Vec<_Tp, cn>& operator *= (Vec<_Tp, cn>& a, double alpha) +{ + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*alpha); + return a; +} + +template static inline +Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, int alpha) +{ + double ialpha = 1./alpha; + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*ialpha); + return a; +} + +template static inline +Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, float alpha) +{ + float ialpha = 1.f/alpha; + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*ialpha); + return a; +} + +template static inline +Vec<_Tp, cn>& operator /= (Vec<_Tp, cn>& a, double alpha) +{ + double ialpha = 1./alpha; + for( int i = 0; i < cn; i++ ) + a[i] = saturate_cast<_Tp>(a[i]*ialpha); + return a; +} + +template static inline +Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, int alpha) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator * (int alpha, const Vec<_Tp, cn>& a) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, float alpha) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator * (float alpha, const Vec<_Tp, cn>& a) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator * (const Vec<_Tp, cn>& a, double alpha) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator * (double alpha, const Vec<_Tp, cn>& a) +{ + return Vec<_Tp, cn>(a, alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, int alpha) +{ + return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, float alpha) +{ + return Vec<_Tp, cn>(a, 1.f/alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator / (const Vec<_Tp, cn>& a, double alpha) +{ + return Vec<_Tp, cn>(a, 1./alpha, Matx_ScaleOp()); +} + +template static inline +Vec<_Tp, cn> operator - (const Vec<_Tp, cn>& a) +{ + Vec<_Tp,cn> t; + for( int i = 0; i < cn; i++ ) t.val[i] = saturate_cast<_Tp>(-a.val[i]); + return t; +} + +template inline Vec<_Tp, 4> operator * (const Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2) +{ + return Vec<_Tp, 4>(saturate_cast<_Tp>(v1[0]*v2[0] - v1[1]*v2[1] - v1[2]*v2[2] - v1[3]*v2[3]), + saturate_cast<_Tp>(v1[0]*v2[1] + v1[1]*v2[0] + v1[2]*v2[3] - v1[3]*v2[2]), + saturate_cast<_Tp>(v1[0]*v2[2] - v1[1]*v2[3] + v1[2]*v2[0] + v1[3]*v2[1]), + saturate_cast<_Tp>(v1[0]*v2[3] + v1[1]*v2[2] - v1[2]*v2[1] + v1[3]*v2[0])); +} + +template inline Vec<_Tp, 4>& operator *= (Vec<_Tp, 4>& v1, const Vec<_Tp, 4>& v2) +{ + v1 = v1 * v2; + return v1; +} + +//! @} + +} // cv + +#endif // OPENCV_CORE_MATX_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/neon_utils.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/neon_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..573ba99ec3569e5dc13b637daf1493b7c1ad6afb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/neon_utils.hpp @@ -0,0 +1,128 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HAL_NEON_UTILS_HPP +#define OPENCV_HAL_NEON_UTILS_HPP + +#include "opencv2/core/cvdef.h" + +//! @addtogroup core_utils_neon +//! @{ + +#if CV_NEON + +inline int32x2_t cv_vrnd_s32_f32(float32x2_t v) +{ + static int32x2_t v_sign = vdup_n_s32(1 << 31), + v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f)); + + int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v))); + return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition))); +} + +inline int32x4_t cv_vrndq_s32_f32(float32x4_t v) +{ + static int32x4_t v_sign = vdupq_n_s32(1 << 31), + v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); + + int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v))); + return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition))); +} + +inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v) +{ + static float32x2_t v_05 = vdup_n_f32(0.5f); + return vcvt_u32_f32(vadd_f32(v, v_05)); +} + +inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v) +{ + static float32x4_t v_05 = vdupq_n_f32(0.5f); + return vcvtq_u32_f32(vaddq_f32(v, v_05)); +} + +inline float32x4_t cv_vrecpq_f32(float32x4_t val) +{ + float32x4_t reciprocal = vrecpeq_f32(val); + reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); + reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); + return reciprocal; +} + +inline float32x2_t cv_vrecp_f32(float32x2_t val) +{ + float32x2_t reciprocal = vrecpe_f32(val); + reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); + reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); + return reciprocal; +} + +inline float32x4_t cv_vrsqrtq_f32(float32x4_t val) +{ + float32x4_t e = vrsqrteq_f32(val); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); + e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); + return e; +} + +inline float32x2_t cv_vrsqrt_f32(float32x2_t val) +{ + float32x2_t e = vrsqrte_f32(val); + e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); + e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); + return e; +} + +inline float32x4_t cv_vsqrtq_f32(float32x4_t val) +{ + return cv_vrecpq_f32(cv_vrsqrtq_f32(val)); +} + +inline float32x2_t cv_vsqrt_f32(float32x2_t val) +{ + return cv_vrecp_f32(cv_vrsqrt_f32(val)); +} + +#endif + +//! @} + +#endif // OPENCV_HAL_NEON_UTILS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ocl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ocl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..115f5d127f389df9a4d4306e28c162a88cd65a6d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ocl.hpp @@ -0,0 +1,710 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_OPENCL_HPP +#define OPENCV_OPENCL_HPP + +#include "opencv2/core.hpp" + +namespace cv { namespace ocl { + +//! @addtogroup core_opencl +//! @{ + +CV_EXPORTS_W bool haveOpenCL(); +CV_EXPORTS_W bool useOpenCL(); +CV_EXPORTS_W bool haveAmdBlas(); +CV_EXPORTS_W bool haveAmdFft(); +CV_EXPORTS_W void setUseOpenCL(bool flag); +CV_EXPORTS_W void finish(); + +CV_EXPORTS bool haveSVM(); + +class CV_EXPORTS Context; +class CV_EXPORTS_W_SIMPLE Device; +class CV_EXPORTS Kernel; +class CV_EXPORTS Program; +class CV_EXPORTS ProgramSource; +class CV_EXPORTS Queue; +class CV_EXPORTS PlatformInfo; +class CV_EXPORTS Image2D; + +class CV_EXPORTS_W_SIMPLE Device +{ +public: + CV_WRAP Device(); + explicit Device(void* d); + Device(const Device& d); + Device& operator = (const Device& d); + CV_WRAP ~Device(); + + void set(void* d); + + enum + { + TYPE_DEFAULT = (1 << 0), + TYPE_CPU = (1 << 1), + TYPE_GPU = (1 << 2), + TYPE_ACCELERATOR = (1 << 3), + TYPE_DGPU = TYPE_GPU + (1 << 16), + TYPE_IGPU = TYPE_GPU + (1 << 17), + TYPE_ALL = 0xFFFFFFFF + }; + + CV_WRAP String name() const; + CV_WRAP String extensions() const; + CV_WRAP bool isExtensionSupported(const String& extensionName) const; + CV_WRAP String version() const; + CV_WRAP String vendorName() const; + CV_WRAP String OpenCL_C_Version() const; + CV_WRAP String OpenCLVersion() const; + CV_WRAP int deviceVersionMajor() const; + CV_WRAP int deviceVersionMinor() const; + CV_WRAP String driverVersion() const; + void* ptr() const; + + CV_WRAP int type() const; + + CV_WRAP int addressBits() const; + CV_WRAP bool available() const; + CV_WRAP bool compilerAvailable() const; + CV_WRAP bool linkerAvailable() const; + + enum + { + FP_DENORM=(1 << 0), + FP_INF_NAN=(1 << 1), + FP_ROUND_TO_NEAREST=(1 << 2), + FP_ROUND_TO_ZERO=(1 << 3), + FP_ROUND_TO_INF=(1 << 4), + FP_FMA=(1 << 5), + FP_SOFT_FLOAT=(1 << 6), + FP_CORRECTLY_ROUNDED_DIVIDE_SQRT=(1 << 7) + }; + CV_WRAP int doubleFPConfig() const; + CV_WRAP int singleFPConfig() const; + CV_WRAP int halfFPConfig() const; + + CV_WRAP bool endianLittle() const; + CV_WRAP bool errorCorrectionSupport() const; + + enum + { + EXEC_KERNEL=(1 << 0), + EXEC_NATIVE_KERNEL=(1 << 1) + }; + CV_WRAP int executionCapabilities() const; + + CV_WRAP size_t globalMemCacheSize() const; + + enum + { + NO_CACHE=0, + READ_ONLY_CACHE=1, + READ_WRITE_CACHE=2 + }; + CV_WRAP int globalMemCacheType() const; + CV_WRAP int globalMemCacheLineSize() const; + CV_WRAP size_t globalMemSize() const; + + CV_WRAP size_t localMemSize() const; + enum + { + NO_LOCAL_MEM=0, + LOCAL_IS_LOCAL=1, + LOCAL_IS_GLOBAL=2 + }; + CV_WRAP int localMemType() const; + CV_WRAP bool hostUnifiedMemory() const; + + CV_WRAP bool imageSupport() const; + + CV_WRAP bool imageFromBufferSupport() const; + uint imagePitchAlignment() const; + uint imageBaseAddressAlignment() const; + + /// deprecated, use isExtensionSupported() method (probably with "cl_khr_subgroups" value) + CV_WRAP bool intelSubgroupsSupport() const; + + CV_WRAP size_t image2DMaxWidth() const; + CV_WRAP size_t image2DMaxHeight() const; + + CV_WRAP size_t image3DMaxWidth() const; + CV_WRAP size_t image3DMaxHeight() const; + CV_WRAP size_t image3DMaxDepth() const; + + CV_WRAP size_t imageMaxBufferSize() const; + CV_WRAP size_t imageMaxArraySize() const; + + enum + { + UNKNOWN_VENDOR=0, + VENDOR_AMD=1, + VENDOR_INTEL=2, + VENDOR_NVIDIA=3 + }; + CV_WRAP int vendorID() const; + // FIXIT + // dev.isAMD() doesn't work for OpenCL CPU devices from AMD OpenCL platform. + // This method should use platform name instead of vendor name. + // After fix restore code in arithm.cpp: ocl_compare() + CV_WRAP inline bool isAMD() const { return vendorID() == VENDOR_AMD; } + CV_WRAP inline bool isIntel() const { return vendorID() == VENDOR_INTEL; } + CV_WRAP inline bool isNVidia() const { return vendorID() == VENDOR_NVIDIA; } + + CV_WRAP int maxClockFrequency() const; + CV_WRAP int maxComputeUnits() const; + CV_WRAP int maxConstantArgs() const; + CV_WRAP size_t maxConstantBufferSize() const; + + CV_WRAP size_t maxMemAllocSize() const; + CV_WRAP size_t maxParameterSize() const; + + CV_WRAP int maxReadImageArgs() const; + CV_WRAP int maxWriteImageArgs() const; + CV_WRAP int maxSamplers() const; + + CV_WRAP size_t maxWorkGroupSize() const; + CV_WRAP int maxWorkItemDims() const; + void maxWorkItemSizes(size_t*) const; + + CV_WRAP int memBaseAddrAlign() const; + + CV_WRAP int nativeVectorWidthChar() const; + CV_WRAP int nativeVectorWidthShort() const; + CV_WRAP int nativeVectorWidthInt() const; + CV_WRAP int nativeVectorWidthLong() const; + CV_WRAP int nativeVectorWidthFloat() const; + CV_WRAP int nativeVectorWidthDouble() const; + CV_WRAP int nativeVectorWidthHalf() const; + + CV_WRAP int preferredVectorWidthChar() const; + CV_WRAP int preferredVectorWidthShort() const; + CV_WRAP int preferredVectorWidthInt() const; + CV_WRAP int preferredVectorWidthLong() const; + CV_WRAP int preferredVectorWidthFloat() const; + CV_WRAP int preferredVectorWidthDouble() const; + CV_WRAP int preferredVectorWidthHalf() const; + + CV_WRAP size_t printfBufferSize() const; + CV_WRAP size_t profilingTimerResolution() const; + + CV_WRAP static const Device& getDefault(); + +protected: + struct Impl; + Impl* p; +}; + + +class CV_EXPORTS Context +{ +public: + Context(); + explicit Context(int dtype); + ~Context(); + Context(const Context& c); + Context& operator = (const Context& c); + + bool create(); + bool create(int dtype); + size_t ndevices() const; + const Device& device(size_t idx) const; + Program getProg(const ProgramSource& prog, + const String& buildopt, String& errmsg); + void unloadProg(Program& prog); + + static Context& getDefault(bool initialize = true); + void* ptr() const; + + friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); + + bool useSVM() const; + void setUseSVM(bool enabled); + + struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } +//protected: + Impl* p; +}; + +class CV_EXPORTS Platform +{ +public: + Platform(); + ~Platform(); + Platform(const Platform& p); + Platform& operator = (const Platform& p); + + void* ptr() const; + static Platform& getDefault(); + + friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); +protected: + struct Impl; + Impl* p; +}; + +/** @brief Attaches OpenCL context to OpenCV +@note + OpenCV will check if available OpenCL platform has platformName name, then assign context to + OpenCV and call `clRetainContext` function. The deviceID device will be used as target device and + new command queue will be created. +@param platformName name of OpenCL platform to attach, this string is used to check if platform is available to OpenCV at runtime +@param platformID ID of platform attached context was created for +@param context OpenCL context to be attached to OpenCV +@param deviceID ID of device, must be created from attached context +*/ +CV_EXPORTS void attachContext(const String& platformName, void* platformID, void* context, void* deviceID); + +/** @brief Convert OpenCL buffer to UMat +@note + OpenCL buffer (cl_mem_buffer) should contain 2D image data, compatible with OpenCV. Memory + content is not copied from `clBuffer` to UMat. Instead, buffer handle assigned to UMat and + `clRetainMemObject` is called. +@param cl_mem_buffer source clBuffer handle +@param step num of bytes in single row +@param rows number of rows +@param cols number of cols +@param type OpenCV type of image +@param dst destination UMat +*/ +CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, int cols, int type, UMat& dst); + +/** @brief Convert OpenCL image2d_t to UMat +@note + OpenCL `image2d_t` (cl_mem_image), should be compatible with OpenCV UMat formats. Memory content + is copied from image to UMat with `clEnqueueCopyImageToBuffer` function. +@param cl_mem_image source image2d_t handle +@param dst destination UMat +*/ +CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst); + +// TODO Move to internal header +void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device); + +class CV_EXPORTS Queue +{ +public: + Queue(); + explicit Queue(const Context& c, const Device& d=Device()); + ~Queue(); + Queue(const Queue& q); + Queue& operator = (const Queue& q); + + bool create(const Context& c=Context(), const Device& d=Device()); + void finish(); + void* ptr() const; + static Queue& getDefault(); + + /// @brief Returns OpenCL command queue with enable profiling mode support + const Queue& getProfilingQueue() const; + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return p; } +protected: + Impl* p; +}; + + +class CV_EXPORTS KernelArg +{ +public: + enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 }; + KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0); + KernelArg(); + + static KernelArg Local(size_t localMemSize) + { return KernelArg(LOCAL, 0, 1, 1, 0, localMemSize); } + static KernelArg PtrWriteOnly(const UMat& m) + { return KernelArg(PTR_ONLY+WRITE_ONLY, (UMat*)&m); } + static KernelArg PtrReadOnly(const UMat& m) + { return KernelArg(PTR_ONLY+READ_ONLY, (UMat*)&m); } + static KernelArg PtrReadWrite(const UMat& m) + { return KernelArg(PTR_ONLY+READ_WRITE, (UMat*)&m); } + static KernelArg ReadWrite(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_WRITE, (UMat*)&m, wscale, iwscale); } + static KernelArg ReadWriteNoSize(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_WRITE+NO_SIZE, (UMat*)&m, wscale, iwscale); } + static KernelArg ReadOnly(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_ONLY, (UMat*)&m, wscale, iwscale); } + static KernelArg WriteOnly(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(WRITE_ONLY, (UMat*)&m, wscale, iwscale); } + static KernelArg ReadOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(READ_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); } + static KernelArg WriteOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1) + { return KernelArg(WRITE_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); } + static KernelArg Constant(const Mat& m); + template static KernelArg Constant(const _Tp* arr, size_t n) + { return KernelArg(CONSTANT, 0, 1, 1, (void*)arr, n); } + + int flags; + UMat* m; + const void* obj; + size_t sz; + int wscale, iwscale; +}; + + +class CV_EXPORTS Kernel +{ +public: + Kernel(); + Kernel(const char* kname, const Program& prog); + Kernel(const char* kname, const ProgramSource& prog, + const String& buildopts = String(), String* errmsg=0); + ~Kernel(); + Kernel(const Kernel& k); + Kernel& operator = (const Kernel& k); + + bool empty() const; + bool create(const char* kname, const Program& prog); + bool create(const char* kname, const ProgramSource& prog, + const String& buildopts, String* errmsg=0); + + int set(int i, const void* value, size_t sz); + int set(int i, const Image2D& image2D); + int set(int i, const UMat& m); + int set(int i, const KernelArg& arg); + template int set(int i, const _Tp& value) + { return set(i, &value, sizeof(value)); } + + +protected: + template inline + int set_args_(int i, const _Tp0& a0) { return set(i, a0); } + template inline + int set_args_(int i, const _Tp0& a0, const _Tps&... rest_args) { i = set(i, a0); return set_args_(i, rest_args...); } +public: + /** @brief Setup OpenCL Kernel arguments. + Avoid direct using of set(i, ...) methods. + @code + bool ok = kernel + .args( + srcUMat, dstUMat, + (float)some_float_param + ).run(ndims, globalSize, localSize); + if (!ok) return false; + @endcode + */ + template inline + Kernel& args(const _Tps&... kernel_args) { set_args_(0, kernel_args...); return *this; } + + + /** @brief Run the OpenCL kernel. + @param dims the work problem dimensions. It is the length of globalsize and localsize. It can be either 1, 2 or 3. + @param globalsize work items for each dimension. It is not the final globalsize passed to + OpenCL. Each dimension will be adjusted to the nearest integer divisible by the corresponding + value in localsize. If localsize is NULL, it will still be adjusted depending on dims. The + adjusted values are greater than or equal to the original values. + @param localsize work-group size for each dimension. + @param sync specify whether to wait for OpenCL computation to finish before return. + @param q command queue + */ + bool run(int dims, size_t globalsize[], + size_t localsize[], bool sync, const Queue& q=Queue()); + bool runTask(bool sync, const Queue& q=Queue()); + + /** @brief Similar to synchronized run() call with returning of kernel execution time + * Separate OpenCL command queue may be used (with CL_QUEUE_PROFILING_ENABLE) + * @return Execution time in nanoseconds or negative number on error + */ + int64 runProfiling(int dims, size_t globalsize[], size_t localsize[], const Queue& q=Queue()); + + size_t workGroupSize() const; + size_t preferedWorkGroupSizeMultiple() const; + bool compileWorkGroupSize(size_t wsz[]) const; + size_t localMemSize() const; + + void* ptr() const; + struct Impl; + +protected: + Impl* p; +}; + +class CV_EXPORTS Program +{ +public: + Program(); + Program(const ProgramSource& src, + const String& buildflags, String& errmsg); + Program(const Program& prog); + + Program& operator = (const Program& prog); + ~Program(); + + bool create(const ProgramSource& src, + const String& buildflags, String& errmsg); + + void* ptr() const; + + /** + * @brief Query device-specific program binary. + * + * Returns RAW OpenCL executable binary without additional attachments. + * + * @sa ProgramSource::fromBinary + * + * @param[out] binary output buffer + */ + void getBinary(std::vector& binary) const; + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } +protected: + Impl* p; +public: +#ifndef OPENCV_REMOVE_DEPRECATED_API + // TODO Remove this + CV_DEPRECATED bool read(const String& buf, const String& buildflags); // removed, use ProgramSource instead + CV_DEPRECATED bool write(String& buf) const; // removed, use getBinary() method instead (RAW OpenCL binary) + CV_DEPRECATED const ProgramSource& source() const; // implementation removed + CV_DEPRECATED String getPrefix() const; // deprecated, implementation replaced + CV_DEPRECATED static String getPrefix(const String& buildflags); // deprecated, implementation replaced +#endif +}; + + +class CV_EXPORTS ProgramSource +{ +public: + typedef uint64 hash_t; // deprecated + + ProgramSource(); + explicit ProgramSource(const String& module, const String& name, const String& codeStr, const String& codeHash); + explicit ProgramSource(const String& prog); // deprecated + explicit ProgramSource(const char* prog); // deprecated + ~ProgramSource(); + ProgramSource(const ProgramSource& prog); + ProgramSource& operator = (const ProgramSource& prog); + + const String& source() const; // deprecated + hash_t hash() const; // deprecated + + + /** @brief Describe OpenCL program binary. + * Do not call clCreateProgramWithBinary() and/or clBuildProgram(). + * + * Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies). + * + * This kind of binary is not portable between platforms in general - it is specific to OpenCL vendor / device / driver version. + * + * @param module name of program owner module + * @param name unique name of program (module+name is used as key for OpenCL program caching) + * @param binary buffer address. See buffer lifetime requirement in description. + * @param size buffer size + * @param buildOptions additional program-related build options passed to clBuildProgram() + * @return created ProgramSource object + */ + static ProgramSource fromBinary(const String& module, const String& name, + const unsigned char* binary, const size_t size, + const cv::String& buildOptions = cv::String()); + + /** @brief Describe OpenCL program in SPIR format. + * Do not call clCreateProgramWithBinary() and/or clBuildProgram(). + * + * Supports SPIR 1.2 by default (pass '-spir-std=X.Y' in buildOptions to override this behavior) + * + * Caller should guarantee binary buffer lifetime greater than ProgramSource object (and any of its copies). + * + * Programs in this format are portable between OpenCL implementations with 'khr_spir' extension: + * https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/cl_khr_spir.html + * (but they are not portable between different platforms: 32-bit / 64-bit) + * + * Note: these programs can't support vendor specific extensions, like 'cl_intel_subgroups'. + * + * @param module name of program owner module + * @param name unique name of program (module+name is used as key for OpenCL program caching) + * @param binary buffer address. See buffer lifetime requirement in description. + * @param size buffer size + * @param buildOptions additional program-related build options passed to clBuildProgram() + * (these options are added automatically: '-x spir' and '-spir-std=1.2') + * @return created ProgramSource object. + */ + static ProgramSource fromSPIR(const String& module, const String& name, + const unsigned char* binary, const size_t size, + const cv::String& buildOptions = cv::String()); + + //OpenCL 2.1+ only + //static Program fromSPIRV(const String& module, const String& name, + // const unsigned char* binary, const size_t size, + // const cv::String& buildOptions = cv::String()); + + struct Impl; friend struct Impl; + inline Impl* getImpl() const { return (Impl*)p; } +protected: + Impl* p; +}; + +class CV_EXPORTS PlatformInfo +{ +public: + PlatformInfo(); + explicit PlatformInfo(void* id); + ~PlatformInfo(); + + PlatformInfo(const PlatformInfo& i); + PlatformInfo& operator =(const PlatformInfo& i); + + String name() const; + String vendor() const; + String version() const; + int deviceNumber() const; + void getDevice(Device& device, int d) const; + +protected: + struct Impl; + Impl* p; +}; + +CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf); +CV_EXPORTS const char* typeToStr(int t); +CV_EXPORTS const char* memopTypeToStr(int t); +CV_EXPORTS const char* vecopTypeToStr(int t); +CV_EXPORTS const char* getOpenCLErrorString(int errorCode); +CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1, const char * name = NULL); +CV_EXPORTS void getPlatfomsInfo(std::vector& platform_info); + + +enum OclVectorStrategy +{ + // all matrices have its own vector width + OCL_VECTOR_OWN = 0, + // all matrices have maximal vector width among all matrices + // (useful for cases when matrices have different data types) + OCL_VECTOR_MAX = 1, + + // default strategy + OCL_VECTOR_DEFAULT = OCL_VECTOR_OWN +}; + +CV_EXPORTS int predictOptimalVectorWidth(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), + InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), + InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(), + OclVectorStrategy strat = OCL_VECTOR_DEFAULT); + +CV_EXPORTS int checkOptimalVectorWidth(const int *vectorWidths, + InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), + InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), + InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(), + OclVectorStrategy strat = OCL_VECTOR_DEFAULT); + +// with OCL_VECTOR_MAX strategy +CV_EXPORTS int predictOptimalVectorWidthMax(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(), + InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(), + InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray()); + +CV_EXPORTS void buildOptionsAddMatrixDescription(String& buildOptions, const String& name, InputArray _m); + +class CV_EXPORTS Image2D +{ +public: + Image2D(); + + /** + @param src UMat object from which to get image properties and data + @param norm flag to enable the use of normalized channel data types + @param alias flag indicating that the image should alias the src UMat. If true, changes to the + image or src will be reflected in both objects. + */ + explicit Image2D(const UMat &src, bool norm = false, bool alias = false); + Image2D(const Image2D & i); + ~Image2D(); + + Image2D & operator = (const Image2D & i); + + /** Indicates if creating an aliased image should succeed. + Depends on the underlying platform and the dimensions of the UMat. + */ + static bool canCreateAlias(const UMat &u); + + /** Indicates if the image format is supported. + */ + static bool isFormatSupported(int depth, int cn, bool norm); + + void* ptr() const; +protected: + struct Impl; + Impl* p; +}; + +class CV_EXPORTS Timer +{ +public: + Timer(const Queue& q); + ~Timer(); + void start(); + void stop(); + + uint64 durationNS() const; //< duration in nanoseconds + +protected: + struct Impl; + Impl* const p; + +private: + Timer(const Timer&); // disabled + Timer& operator=(const Timer&); // disabled +}; + +CV_EXPORTS MatAllocator* getOpenCLAllocator(); + + +#ifdef __OPENCV_BUILD +namespace internal { + +CV_EXPORTS bool isOpenCLForced(); +#define OCL_FORCE_CHECK(condition) (cv::ocl::internal::isOpenCLForced() || (condition)) + +CV_EXPORTS bool isPerformanceCheckBypassed(); +#define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition)) + +CV_EXPORTS bool isCLBuffer(UMat& u); + +} // namespace internal +#endif + +//! @} + +}} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ocl_genbase.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ocl_genbase.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5334cf1f4f2db81ade82e43035396fb8ea9dc1e0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ocl_genbase.hpp @@ -0,0 +1,69 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_OPENCL_GENBASE_HPP +#define OPENCV_OPENCL_GENBASE_HPP + +//! @cond IGNORED + +namespace cv { +namespace ocl { + +class ProgramSource; + +namespace internal { + +struct CV_EXPORTS ProgramEntry +{ + const char* module; + const char* name; + const char* programCode; + const char* programHash; + ProgramSource* pProgramSource; + + operator ProgramSource& () const; +}; + +} } } // namespace + +//! @endcond + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/ocl_defs.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/ocl_defs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..14df750fc7be5b666f82e1f19b539cc0bb7c4669 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/ocl_defs.hpp @@ -0,0 +1,82 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. + +#ifndef OPENCV_CORE_OPENCL_DEFS_HPP +#define OPENCV_CORE_OPENCL_DEFS_HPP + +#include "opencv2/core/utility.hpp" +#include "cvconfig.h" + +namespace cv { namespace ocl { +#ifdef HAVE_OPENCL +/// Call is similar to useOpenCL() but doesn't try to load OpenCL runtime or create OpenCL context +CV_EXPORTS bool isOpenCLActivated(); +#else +static inline bool isOpenCLActivated() { return false; } +#endif +}} // namespace + + +//#define CV_OPENCL_RUN_ASSERT + +#ifdef HAVE_OPENCL + +#ifdef CV_OPENCL_RUN_VERBOSE +#define CV_OCL_RUN_(condition, func, ...) \ + { \ + if (cv::ocl::isOpenCLActivated() && (condition) && func) \ + { \ + printf("%s: OpenCL implementation is running\n", CV_Func); \ + fflush(stdout); \ + CV_IMPL_ADD(CV_IMPL_OCL); \ + return __VA_ARGS__; \ + } \ + else \ + { \ + printf("%s: Plain implementation is running\n", CV_Func); \ + fflush(stdout); \ + } \ + } +#elif defined CV_OPENCL_RUN_ASSERT +#define CV_OCL_RUN_(condition, func, ...) \ + { \ + if (cv::ocl::isOpenCLActivated() && (condition)) \ + { \ + if(func) \ + { \ + CV_IMPL_ADD(CV_IMPL_OCL); \ + } \ + else \ + { \ + CV_Error(cv::Error::StsAssert, #func); \ + } \ + return __VA_ARGS__; \ + } \ + } +#else +#define CV_OCL_RUN_(condition, func, ...) \ +try \ +{ \ + if (cv::ocl::isOpenCLActivated() && (condition) && func) \ + { \ + CV_IMPL_ADD(CV_IMPL_OCL); \ + return __VA_ARGS__; \ + } \ +} \ +catch (const cv::Exception& e) \ +{ \ + CV_UNUSED(e); /* TODO: Add some logging here */ \ +} +#endif + +#else +#define CV_OCL_RUN_(condition, func, ...) +#endif + +#define CV_OCL_RUN(condition, func) CV_OCL_RUN_(condition, func) + +#endif // OPENCV_CORE_OPENCL_DEFS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/opencl_info.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/opencl_info.hpp new file mode 100644 index 0000000000000000000000000000000000000000..21b3672925535c663e7a92f540b74b2488ab0072 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/opencl_info.hpp @@ -0,0 +1,205 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include + +#include +#include + +#ifndef DUMP_CONFIG_PROPERTY +#define DUMP_CONFIG_PROPERTY(...) +#endif + +#ifndef DUMP_MESSAGE_STDOUT +#define DUMP_MESSAGE_STDOUT(...) do { std::cout << __VA_ARGS__ << std::endl; } while (false) +#endif + +namespace cv { + +namespace { +static std::string bytesToStringRepr(size_t value) +{ + size_t b = value % 1024; + value /= 1024; + + size_t kb = value % 1024; + value /= 1024; + + size_t mb = value % 1024; + value /= 1024; + + size_t gb = value; + + std::ostringstream stream; + + if (gb > 0) + stream << gb << " GB "; + if (mb > 0) + stream << mb << " MB "; + if (kb > 0) + stream << kb << " KB "; + if (b > 0) + stream << b << " B"; + + std::string s = stream.str(); + if (s[s.size() - 1] == ' ') + s = s.substr(0, s.size() - 1); + return s; +} + +static String getDeviceTypeString(const cv::ocl::Device& device) +{ + if (device.type() == cv::ocl::Device::TYPE_CPU) { + return "CPU"; + } + + if (device.type() == cv::ocl::Device::TYPE_GPU) { + if (device.hostUnifiedMemory()) { + return "iGPU"; + } else { + return "dGPU"; + } + } + + return "unkown"; +} +} // namespace + +static void dumpOpenCLInformation() +{ + using namespace cv::ocl; + + try + { + if (!haveOpenCL() || !useOpenCL()) + { + DUMP_MESSAGE_STDOUT("OpenCL is disabled"); + DUMP_CONFIG_PROPERTY("cv_ocl", "disabled"); + return; + } + + std::vector platforms; + cv::ocl::getPlatfomsInfo(platforms); + if (platforms.empty()) + { + DUMP_MESSAGE_STDOUT("OpenCL is not available"); + DUMP_CONFIG_PROPERTY("cv_ocl", "not available"); + return; + } + + DUMP_MESSAGE_STDOUT("OpenCL Platforms: "); + for (size_t i = 0; i < platforms.size(); i++) + { + const PlatformInfo* platform = &platforms[i]; + DUMP_MESSAGE_STDOUT(" " << platform->name()); + Device current_device; + for (int j = 0; j < platform->deviceNumber(); j++) + { + platform->getDevice(current_device, j); + String deviceTypeStr = getDeviceTypeString(current_device); + DUMP_MESSAGE_STDOUT( " " << deviceTypeStr << ": " << current_device.name() << " (" << current_device.version() << ")"); + DUMP_CONFIG_PROPERTY( cv::format("cv_ocl_platform_%d_device_%d", (int)i, j ), + cv::format("(Platform=%s)(Type=%s)(Name=%s)(Version=%s)", + platform->name().c_str(), deviceTypeStr.c_str(), current_device.name().c_str(), current_device.version().c_str()) ); + } + } + const Device& device = Device::getDefault(); + if (!device.available()) + CV_Error(Error::OpenCLInitError, "OpenCL device is not available"); + + DUMP_MESSAGE_STDOUT("Current OpenCL device: "); + + String deviceTypeStr = getDeviceTypeString(device); + DUMP_MESSAGE_STDOUT(" Type = " << deviceTypeStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceType", deviceTypeStr); + + DUMP_MESSAGE_STDOUT(" Name = " << device.name()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceName", device.name()); + + DUMP_MESSAGE_STDOUT(" Version = " << device.version()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_deviceVersion", device.version()); + + DUMP_MESSAGE_STDOUT(" Driver version = " << device.driverVersion()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_driverVersion", device.driverVersion()); + + DUMP_MESSAGE_STDOUT(" Address bits = " << device.addressBits()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_addressBits", device.addressBits()); + + DUMP_MESSAGE_STDOUT(" Compute units = " << device.maxComputeUnits()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_maxComputeUnits", device.maxComputeUnits()); + + DUMP_MESSAGE_STDOUT(" Max work group size = " << device.maxWorkGroupSize()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_maxWorkGroupSize", device.maxWorkGroupSize()); + + std::string localMemorySizeStr = bytesToStringRepr(device.localMemSize()); + DUMP_MESSAGE_STDOUT(" Local memory size = " << localMemorySizeStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_localMemSize", device.localMemSize()); + + std::string maxMemAllocSizeStr = bytesToStringRepr(device.maxMemAllocSize()); + DUMP_MESSAGE_STDOUT(" Max memory allocation size = " << maxMemAllocSizeStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_maxMemAllocSize", device.maxMemAllocSize()); + + const char* doubleSupportStr = device.doubleFPConfig() > 0 ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Double support = " << doubleSupportStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_haveDoubleSupport", device.doubleFPConfig() > 0); + + const char* isUnifiedMemoryStr = device.hostUnifiedMemory() ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Host unified memory = " << isUnifiedMemoryStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_hostUnifiedMemory", device.hostUnifiedMemory()); + + DUMP_MESSAGE_STDOUT(" Device extensions:"); + String extensionsStr = device.extensions(); + size_t pos = 0; + while (pos < extensionsStr.size()) + { + size_t pos2 = extensionsStr.find(' ', pos); + if (pos2 == String::npos) + pos2 = extensionsStr.size(); + if (pos2 > pos) + { + String extensionName = extensionsStr.substr(pos, pos2 - pos); + DUMP_MESSAGE_STDOUT(" " << extensionName); + } + pos = pos2 + 1; + } + DUMP_CONFIG_PROPERTY("cv_ocl_current_extensions", extensionsStr); + + const char* haveAmdBlasStr = haveAmdBlas() ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Has AMD Blas = " << haveAmdBlasStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdBlas", haveAmdBlas()); + + const char* haveAmdFftStr = haveAmdFft() ? "Yes" : "No"; + DUMP_MESSAGE_STDOUT(" Has AMD Fft = " << haveAmdFftStr); + DUMP_CONFIG_PROPERTY("cv_ocl_current_AmdFft", haveAmdFft()); + + + DUMP_MESSAGE_STDOUT(" Preferred vector width char = " << device.preferredVectorWidthChar()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthChar", device.preferredVectorWidthChar()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width short = " << device.preferredVectorWidthShort()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthShort", device.preferredVectorWidthShort()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width int = " << device.preferredVectorWidthInt()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthInt", device.preferredVectorWidthInt()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width long = " << device.preferredVectorWidthLong()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthLong", device.preferredVectorWidthLong()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width float = " << device.preferredVectorWidthFloat()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthFloat", device.preferredVectorWidthFloat()); + + DUMP_MESSAGE_STDOUT(" Preferred vector width double = " << device.preferredVectorWidthDouble()); + DUMP_CONFIG_PROPERTY("cv_ocl_current_preferredVectorWidthDouble", device.preferredVectorWidthDouble()); + } + catch (...) + { + DUMP_MESSAGE_STDOUT("Exception. Can't dump OpenCL info"); + DUMP_MESSAGE_STDOUT("OpenCL device not available"); + DUMP_CONFIG_PROPERTY("cv_ocl", "not available"); + } +} +#undef DUMP_MESSAGE_STDOUT +#undef DUMP_CONFIG_PROPERTY + +} // namespace diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/opencl_svm.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/opencl_svm.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7453082a67b374c01591e7480bbf62f595683fa5 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/opencl_svm.hpp @@ -0,0 +1,81 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OPENCL_SVM_HPP +#define OPENCV_CORE_OPENCL_SVM_HPP + +// +// Internal usage only (binary compatibility is not guaranteed) +// +#ifndef __OPENCV_BUILD +#error Internal header file +#endif + +#if defined(HAVE_OPENCL) && defined(HAVE_OPENCL_SVM) +#include "runtime/opencl_core.hpp" +#include "runtime/opencl_svm_20.hpp" +#include "runtime/opencl_svm_hsa_extension.hpp" + +namespace cv { namespace ocl { namespace svm { + +struct SVMCapabilities +{ + enum Value + { + SVM_COARSE_GRAIN_BUFFER = (1 << 0), + SVM_FINE_GRAIN_BUFFER = (1 << 1), + SVM_FINE_GRAIN_SYSTEM = (1 << 2), + SVM_ATOMICS = (1 << 3), + }; + int value_; + + SVMCapabilities(int capabilities = 0) : value_(capabilities) { } + operator int() const { return value_; } + + inline bool isNoSVMSupport() const { return value_ == 0; } + inline bool isSupportCoarseGrainBuffer() const { return (value_ & SVM_COARSE_GRAIN_BUFFER) != 0; } + inline bool isSupportFineGrainBuffer() const { return (value_ & SVM_FINE_GRAIN_BUFFER) != 0; } + inline bool isSupportFineGrainSystem() const { return (value_ & SVM_FINE_GRAIN_SYSTEM) != 0; } + inline bool isSupportAtomics() const { return (value_ & SVM_ATOMICS) != 0; } +}; + +CV_EXPORTS const SVMCapabilities getSVMCapabilitites(const ocl::Context& context); + +struct SVMFunctions +{ + clSVMAllocAMD_fn fn_clSVMAlloc; + clSVMFreeAMD_fn fn_clSVMFree; + clSetKernelArgSVMPointerAMD_fn fn_clSetKernelArgSVMPointer; + //clSetKernelExecInfoAMD_fn fn_clSetKernelExecInfo; + //clEnqueueSVMFreeAMD_fn fn_clEnqueueSVMFree; + clEnqueueSVMMemcpyAMD_fn fn_clEnqueueSVMMemcpy; + clEnqueueSVMMemFillAMD_fn fn_clEnqueueSVMMemFill; + clEnqueueSVMMapAMD_fn fn_clEnqueueSVMMap; + clEnqueueSVMUnmapAMD_fn fn_clEnqueueSVMUnmap; + + inline SVMFunctions() + : fn_clSVMAlloc(NULL), fn_clSVMFree(NULL), + fn_clSetKernelArgSVMPointer(NULL), /*fn_clSetKernelExecInfo(NULL),*/ + /*fn_clEnqueueSVMFree(NULL),*/ fn_clEnqueueSVMMemcpy(NULL), fn_clEnqueueSVMMemFill(NULL), + fn_clEnqueueSVMMap(NULL), fn_clEnqueueSVMUnmap(NULL) + { + // nothing + } + + inline bool isValid() const + { + return fn_clSVMAlloc != NULL && fn_clSVMFree && fn_clSetKernelArgSVMPointer && + /*fn_clSetKernelExecInfo && fn_clEnqueueSVMFree &&*/ fn_clEnqueueSVMMemcpy && + fn_clEnqueueSVMMemFill && fn_clEnqueueSVMMap && fn_clEnqueueSVMUnmap; + } +}; + +// We should guarantee that SVMFunctions lifetime is not less than context's lifetime +CV_EXPORTS const SVMFunctions* getSVMFunctions(const ocl::Context& context); + +CV_EXPORTS bool useSVM(UMatUsageFlags usageFlags); + +}}} //namespace cv::ocl::svm +#endif + +#endif // OPENCV_CORE_OPENCL_SVM_HPP +/* End of file. */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp new file mode 100644 index 0000000000000000000000000000000000000000..65c84935240d3618e0e984eff5102154e3b97a6c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdblas.hpp @@ -0,0 +1,714 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP +#error "Invalid usage" +#endif + +// generated by parser_clamdblas.py +#define clAmdBlasAddScratchImage clAmdBlasAddScratchImage_ +#define clAmdBlasCaxpy clAmdBlasCaxpy_ +#define clAmdBlasCcopy clAmdBlasCcopy_ +#define clAmdBlasCdotc clAmdBlasCdotc_ +#define clAmdBlasCdotu clAmdBlasCdotu_ +#define clAmdBlasCgbmv clAmdBlasCgbmv_ +#define clAmdBlasCgemm clAmdBlasCgemm_ +#define clAmdBlasCgemmEx clAmdBlasCgemmEx_ +#define clAmdBlasCgemv clAmdBlasCgemv_ +#define clAmdBlasCgemvEx clAmdBlasCgemvEx_ +#define clAmdBlasCgerc clAmdBlasCgerc_ +#define clAmdBlasCgeru clAmdBlasCgeru_ +#define clAmdBlasChbmv clAmdBlasChbmv_ +#define clAmdBlasChemm clAmdBlasChemm_ +#define clAmdBlasChemv clAmdBlasChemv_ +#define clAmdBlasCher clAmdBlasCher_ +#define clAmdBlasCher2 clAmdBlasCher2_ +#define clAmdBlasCher2k clAmdBlasCher2k_ +#define clAmdBlasCherk clAmdBlasCherk_ +#define clAmdBlasChpmv clAmdBlasChpmv_ +#define clAmdBlasChpr clAmdBlasChpr_ +#define clAmdBlasChpr2 clAmdBlasChpr2_ +#define clAmdBlasCrotg clAmdBlasCrotg_ +#define clAmdBlasCscal clAmdBlasCscal_ +#define clAmdBlasCsrot clAmdBlasCsrot_ +#define clAmdBlasCsscal clAmdBlasCsscal_ +#define clAmdBlasCswap clAmdBlasCswap_ +#define clAmdBlasCsymm clAmdBlasCsymm_ +#define clAmdBlasCsyr2k clAmdBlasCsyr2k_ +#define clAmdBlasCsyr2kEx clAmdBlasCsyr2kEx_ +#define clAmdBlasCsyrk clAmdBlasCsyrk_ +#define clAmdBlasCsyrkEx clAmdBlasCsyrkEx_ +#define clAmdBlasCtbmv clAmdBlasCtbmv_ +#define clAmdBlasCtbsv clAmdBlasCtbsv_ +#define clAmdBlasCtpmv clAmdBlasCtpmv_ +#define clAmdBlasCtpsv clAmdBlasCtpsv_ +#define clAmdBlasCtrmm clAmdBlasCtrmm_ +#define clAmdBlasCtrmmEx clAmdBlasCtrmmEx_ +#define clAmdBlasCtrmv clAmdBlasCtrmv_ +#define clAmdBlasCtrsm clAmdBlasCtrsm_ +#define clAmdBlasCtrsmEx clAmdBlasCtrsmEx_ +#define clAmdBlasCtrsv clAmdBlasCtrsv_ +#define clAmdBlasDasum clAmdBlasDasum_ +#define clAmdBlasDaxpy clAmdBlasDaxpy_ +#define clAmdBlasDcopy clAmdBlasDcopy_ +#define clAmdBlasDdot clAmdBlasDdot_ +#define clAmdBlasDgbmv clAmdBlasDgbmv_ +#define clAmdBlasDgemm clAmdBlasDgemm_ +#define clAmdBlasDgemmEx clAmdBlasDgemmEx_ +#define clAmdBlasDgemv clAmdBlasDgemv_ +#define clAmdBlasDgemvEx clAmdBlasDgemvEx_ +#define clAmdBlasDger clAmdBlasDger_ +#define clAmdBlasDnrm2 clAmdBlasDnrm2_ +#define clAmdBlasDrot clAmdBlasDrot_ +#define clAmdBlasDrotg clAmdBlasDrotg_ +#define clAmdBlasDrotm clAmdBlasDrotm_ +#define clAmdBlasDrotmg clAmdBlasDrotmg_ +#define clAmdBlasDsbmv clAmdBlasDsbmv_ +#define clAmdBlasDscal clAmdBlasDscal_ +#define clAmdBlasDspmv clAmdBlasDspmv_ +#define clAmdBlasDspr clAmdBlasDspr_ +#define clAmdBlasDspr2 clAmdBlasDspr2_ +#define clAmdBlasDswap clAmdBlasDswap_ +#define clAmdBlasDsymm clAmdBlasDsymm_ +#define clAmdBlasDsymv clAmdBlasDsymv_ +#define clAmdBlasDsymvEx clAmdBlasDsymvEx_ +#define clAmdBlasDsyr clAmdBlasDsyr_ +#define clAmdBlasDsyr2 clAmdBlasDsyr2_ +#define clAmdBlasDsyr2k clAmdBlasDsyr2k_ +#define clAmdBlasDsyr2kEx clAmdBlasDsyr2kEx_ +#define clAmdBlasDsyrk clAmdBlasDsyrk_ +#define clAmdBlasDsyrkEx clAmdBlasDsyrkEx_ +#define clAmdBlasDtbmv clAmdBlasDtbmv_ +#define clAmdBlasDtbsv clAmdBlasDtbsv_ +#define clAmdBlasDtpmv clAmdBlasDtpmv_ +#define clAmdBlasDtpsv clAmdBlasDtpsv_ +#define clAmdBlasDtrmm clAmdBlasDtrmm_ +#define clAmdBlasDtrmmEx clAmdBlasDtrmmEx_ +#define clAmdBlasDtrmv clAmdBlasDtrmv_ +#define clAmdBlasDtrsm clAmdBlasDtrsm_ +#define clAmdBlasDtrsmEx clAmdBlasDtrsmEx_ +#define clAmdBlasDtrsv clAmdBlasDtrsv_ +#define clAmdBlasDzasum clAmdBlasDzasum_ +#define clAmdBlasDznrm2 clAmdBlasDznrm2_ +#define clAmdBlasGetVersion clAmdBlasGetVersion_ +#define clAmdBlasRemoveScratchImage clAmdBlasRemoveScratchImage_ +#define clAmdBlasSasum clAmdBlasSasum_ +#define clAmdBlasSaxpy clAmdBlasSaxpy_ +#define clAmdBlasScasum clAmdBlasScasum_ +#define clAmdBlasScnrm2 clAmdBlasScnrm2_ +#define clAmdBlasScopy clAmdBlasScopy_ +#define clAmdBlasSdot clAmdBlasSdot_ +#define clAmdBlasSetup clAmdBlasSetup_ +#define clAmdBlasSgbmv clAmdBlasSgbmv_ +#define clAmdBlasSgemm clAmdBlasSgemm_ +#define clAmdBlasSgemmEx clAmdBlasSgemmEx_ +#define clAmdBlasSgemv clAmdBlasSgemv_ +#define clAmdBlasSgemvEx clAmdBlasSgemvEx_ +#define clAmdBlasSger clAmdBlasSger_ +#define clAmdBlasSnrm2 clAmdBlasSnrm2_ +#define clAmdBlasSrot clAmdBlasSrot_ +#define clAmdBlasSrotg clAmdBlasSrotg_ +#define clAmdBlasSrotm clAmdBlasSrotm_ +#define clAmdBlasSrotmg clAmdBlasSrotmg_ +#define clAmdBlasSsbmv clAmdBlasSsbmv_ +#define clAmdBlasSscal clAmdBlasSscal_ +#define clAmdBlasSspmv clAmdBlasSspmv_ +#define clAmdBlasSspr clAmdBlasSspr_ +#define clAmdBlasSspr2 clAmdBlasSspr2_ +#define clAmdBlasSswap clAmdBlasSswap_ +#define clAmdBlasSsymm clAmdBlasSsymm_ +#define clAmdBlasSsymv clAmdBlasSsymv_ +#define clAmdBlasSsymvEx clAmdBlasSsymvEx_ +#define clAmdBlasSsyr clAmdBlasSsyr_ +#define clAmdBlasSsyr2 clAmdBlasSsyr2_ +#define clAmdBlasSsyr2k clAmdBlasSsyr2k_ +#define clAmdBlasSsyr2kEx clAmdBlasSsyr2kEx_ +#define clAmdBlasSsyrk clAmdBlasSsyrk_ +#define clAmdBlasSsyrkEx clAmdBlasSsyrkEx_ +#define clAmdBlasStbmv clAmdBlasStbmv_ +#define clAmdBlasStbsv clAmdBlasStbsv_ +#define clAmdBlasStpmv clAmdBlasStpmv_ +#define clAmdBlasStpsv clAmdBlasStpsv_ +#define clAmdBlasStrmm clAmdBlasStrmm_ +#define clAmdBlasStrmmEx clAmdBlasStrmmEx_ +#define clAmdBlasStrmv clAmdBlasStrmv_ +#define clAmdBlasStrsm clAmdBlasStrsm_ +#define clAmdBlasStrsmEx clAmdBlasStrsmEx_ +#define clAmdBlasStrsv clAmdBlasStrsv_ +#define clAmdBlasTeardown clAmdBlasTeardown_ +#define clAmdBlasZaxpy clAmdBlasZaxpy_ +#define clAmdBlasZcopy clAmdBlasZcopy_ +#define clAmdBlasZdotc clAmdBlasZdotc_ +#define clAmdBlasZdotu clAmdBlasZdotu_ +#define clAmdBlasZdrot clAmdBlasZdrot_ +#define clAmdBlasZdscal clAmdBlasZdscal_ +#define clAmdBlasZgbmv clAmdBlasZgbmv_ +#define clAmdBlasZgemm clAmdBlasZgemm_ +#define clAmdBlasZgemmEx clAmdBlasZgemmEx_ +#define clAmdBlasZgemv clAmdBlasZgemv_ +#define clAmdBlasZgemvEx clAmdBlasZgemvEx_ +#define clAmdBlasZgerc clAmdBlasZgerc_ +#define clAmdBlasZgeru clAmdBlasZgeru_ +#define clAmdBlasZhbmv clAmdBlasZhbmv_ +#define clAmdBlasZhemm clAmdBlasZhemm_ +#define clAmdBlasZhemv clAmdBlasZhemv_ +#define clAmdBlasZher clAmdBlasZher_ +#define clAmdBlasZher2 clAmdBlasZher2_ +#define clAmdBlasZher2k clAmdBlasZher2k_ +#define clAmdBlasZherk clAmdBlasZherk_ +#define clAmdBlasZhpmv clAmdBlasZhpmv_ +#define clAmdBlasZhpr clAmdBlasZhpr_ +#define clAmdBlasZhpr2 clAmdBlasZhpr2_ +#define clAmdBlasZrotg clAmdBlasZrotg_ +#define clAmdBlasZscal clAmdBlasZscal_ +#define clAmdBlasZswap clAmdBlasZswap_ +#define clAmdBlasZsymm clAmdBlasZsymm_ +#define clAmdBlasZsyr2k clAmdBlasZsyr2k_ +#define clAmdBlasZsyr2kEx clAmdBlasZsyr2kEx_ +#define clAmdBlasZsyrk clAmdBlasZsyrk_ +#define clAmdBlasZsyrkEx clAmdBlasZsyrkEx_ +#define clAmdBlasZtbmv clAmdBlasZtbmv_ +#define clAmdBlasZtbsv clAmdBlasZtbsv_ +#define clAmdBlasZtpmv clAmdBlasZtpmv_ +#define clAmdBlasZtpsv clAmdBlasZtpsv_ +#define clAmdBlasZtrmm clAmdBlasZtrmm_ +#define clAmdBlasZtrmmEx clAmdBlasZtrmmEx_ +#define clAmdBlasZtrmv clAmdBlasZtrmv_ +#define clAmdBlasZtrsm clAmdBlasZtrsm_ +#define clAmdBlasZtrsmEx clAmdBlasZtrsmEx_ +#define clAmdBlasZtrsv clAmdBlasZtrsv_ +#define clAmdBlasiCamax clAmdBlasiCamax_ +#define clAmdBlasiDamax clAmdBlasiDamax_ +#define clAmdBlasiSamax clAmdBlasiSamax_ +#define clAmdBlasiZamax clAmdBlasiZamax_ + +#include + +// generated by parser_clamdblas.py +#undef clAmdBlasAddScratchImage +//#define clAmdBlasAddScratchImage clAmdBlasAddScratchImage_pfn +#undef clAmdBlasCaxpy +//#define clAmdBlasCaxpy clAmdBlasCaxpy_pfn +#undef clAmdBlasCcopy +//#define clAmdBlasCcopy clAmdBlasCcopy_pfn +#undef clAmdBlasCdotc +//#define clAmdBlasCdotc clAmdBlasCdotc_pfn +#undef clAmdBlasCdotu +//#define clAmdBlasCdotu clAmdBlasCdotu_pfn +#undef clAmdBlasCgbmv +//#define clAmdBlasCgbmv clAmdBlasCgbmv_pfn +#undef clAmdBlasCgemm +//#define clAmdBlasCgemm clAmdBlasCgemm_pfn +#undef clAmdBlasCgemmEx +#define clAmdBlasCgemmEx clAmdBlasCgemmEx_pfn +#undef clAmdBlasCgemv +//#define clAmdBlasCgemv clAmdBlasCgemv_pfn +#undef clAmdBlasCgemvEx +//#define clAmdBlasCgemvEx clAmdBlasCgemvEx_pfn +#undef clAmdBlasCgerc +//#define clAmdBlasCgerc clAmdBlasCgerc_pfn +#undef clAmdBlasCgeru +//#define clAmdBlasCgeru clAmdBlasCgeru_pfn +#undef clAmdBlasChbmv +//#define clAmdBlasChbmv clAmdBlasChbmv_pfn +#undef clAmdBlasChemm +//#define clAmdBlasChemm clAmdBlasChemm_pfn +#undef clAmdBlasChemv +//#define clAmdBlasChemv clAmdBlasChemv_pfn +#undef clAmdBlasCher +//#define clAmdBlasCher clAmdBlasCher_pfn +#undef clAmdBlasCher2 +//#define clAmdBlasCher2 clAmdBlasCher2_pfn +#undef clAmdBlasCher2k +//#define clAmdBlasCher2k clAmdBlasCher2k_pfn +#undef clAmdBlasCherk +//#define clAmdBlasCherk clAmdBlasCherk_pfn +#undef clAmdBlasChpmv +//#define clAmdBlasChpmv clAmdBlasChpmv_pfn +#undef clAmdBlasChpr +//#define clAmdBlasChpr clAmdBlasChpr_pfn +#undef clAmdBlasChpr2 +//#define clAmdBlasChpr2 clAmdBlasChpr2_pfn +#undef clAmdBlasCrotg +//#define clAmdBlasCrotg clAmdBlasCrotg_pfn +#undef clAmdBlasCscal +//#define clAmdBlasCscal clAmdBlasCscal_pfn +#undef clAmdBlasCsrot +//#define clAmdBlasCsrot clAmdBlasCsrot_pfn +#undef clAmdBlasCsscal +//#define clAmdBlasCsscal clAmdBlasCsscal_pfn +#undef clAmdBlasCswap +//#define clAmdBlasCswap clAmdBlasCswap_pfn +#undef clAmdBlasCsymm +//#define clAmdBlasCsymm clAmdBlasCsymm_pfn +#undef clAmdBlasCsyr2k +//#define clAmdBlasCsyr2k clAmdBlasCsyr2k_pfn +#undef clAmdBlasCsyr2kEx +//#define clAmdBlasCsyr2kEx clAmdBlasCsyr2kEx_pfn +#undef clAmdBlasCsyrk +//#define clAmdBlasCsyrk clAmdBlasCsyrk_pfn +#undef clAmdBlasCsyrkEx +//#define clAmdBlasCsyrkEx clAmdBlasCsyrkEx_pfn +#undef clAmdBlasCtbmv +//#define clAmdBlasCtbmv clAmdBlasCtbmv_pfn +#undef clAmdBlasCtbsv +//#define clAmdBlasCtbsv clAmdBlasCtbsv_pfn +#undef clAmdBlasCtpmv +//#define clAmdBlasCtpmv clAmdBlasCtpmv_pfn +#undef clAmdBlasCtpsv +//#define clAmdBlasCtpsv clAmdBlasCtpsv_pfn +#undef clAmdBlasCtrmm +//#define clAmdBlasCtrmm clAmdBlasCtrmm_pfn +#undef clAmdBlasCtrmmEx +//#define clAmdBlasCtrmmEx clAmdBlasCtrmmEx_pfn +#undef clAmdBlasCtrmv +//#define clAmdBlasCtrmv clAmdBlasCtrmv_pfn +#undef clAmdBlasCtrsm +//#define clAmdBlasCtrsm clAmdBlasCtrsm_pfn +#undef clAmdBlasCtrsmEx +//#define clAmdBlasCtrsmEx clAmdBlasCtrsmEx_pfn +#undef clAmdBlasCtrsv +//#define clAmdBlasCtrsv clAmdBlasCtrsv_pfn +#undef clAmdBlasDasum +//#define clAmdBlasDasum clAmdBlasDasum_pfn +#undef clAmdBlasDaxpy +//#define clAmdBlasDaxpy clAmdBlasDaxpy_pfn +#undef clAmdBlasDcopy +//#define clAmdBlasDcopy clAmdBlasDcopy_pfn +#undef clAmdBlasDdot +//#define clAmdBlasDdot clAmdBlasDdot_pfn +#undef clAmdBlasDgbmv +//#define clAmdBlasDgbmv clAmdBlasDgbmv_pfn +#undef clAmdBlasDgemm +//#define clAmdBlasDgemm clAmdBlasDgemm_pfn +#undef clAmdBlasDgemmEx +#define clAmdBlasDgemmEx clAmdBlasDgemmEx_pfn +#undef clAmdBlasDgemv +//#define clAmdBlasDgemv clAmdBlasDgemv_pfn +#undef clAmdBlasDgemvEx +//#define clAmdBlasDgemvEx clAmdBlasDgemvEx_pfn +#undef clAmdBlasDger +//#define clAmdBlasDger clAmdBlasDger_pfn +#undef clAmdBlasDnrm2 +//#define clAmdBlasDnrm2 clAmdBlasDnrm2_pfn +#undef clAmdBlasDrot +//#define clAmdBlasDrot clAmdBlasDrot_pfn +#undef clAmdBlasDrotg +//#define clAmdBlasDrotg clAmdBlasDrotg_pfn +#undef clAmdBlasDrotm +//#define clAmdBlasDrotm clAmdBlasDrotm_pfn +#undef clAmdBlasDrotmg +//#define clAmdBlasDrotmg clAmdBlasDrotmg_pfn +#undef clAmdBlasDsbmv +//#define clAmdBlasDsbmv clAmdBlasDsbmv_pfn +#undef clAmdBlasDscal +//#define clAmdBlasDscal clAmdBlasDscal_pfn +#undef clAmdBlasDspmv +//#define clAmdBlasDspmv clAmdBlasDspmv_pfn +#undef clAmdBlasDspr +//#define clAmdBlasDspr clAmdBlasDspr_pfn +#undef clAmdBlasDspr2 +//#define clAmdBlasDspr2 clAmdBlasDspr2_pfn +#undef clAmdBlasDswap +//#define clAmdBlasDswap clAmdBlasDswap_pfn +#undef clAmdBlasDsymm +//#define clAmdBlasDsymm clAmdBlasDsymm_pfn +#undef clAmdBlasDsymv +//#define clAmdBlasDsymv clAmdBlasDsymv_pfn +#undef clAmdBlasDsymvEx +//#define clAmdBlasDsymvEx clAmdBlasDsymvEx_pfn +#undef clAmdBlasDsyr +//#define clAmdBlasDsyr clAmdBlasDsyr_pfn +#undef clAmdBlasDsyr2 +//#define clAmdBlasDsyr2 clAmdBlasDsyr2_pfn +#undef clAmdBlasDsyr2k +//#define clAmdBlasDsyr2k clAmdBlasDsyr2k_pfn +#undef clAmdBlasDsyr2kEx +//#define clAmdBlasDsyr2kEx clAmdBlasDsyr2kEx_pfn +#undef clAmdBlasDsyrk +//#define clAmdBlasDsyrk clAmdBlasDsyrk_pfn +#undef clAmdBlasDsyrkEx +//#define clAmdBlasDsyrkEx clAmdBlasDsyrkEx_pfn +#undef clAmdBlasDtbmv +//#define clAmdBlasDtbmv clAmdBlasDtbmv_pfn +#undef clAmdBlasDtbsv +//#define clAmdBlasDtbsv clAmdBlasDtbsv_pfn +#undef clAmdBlasDtpmv +//#define clAmdBlasDtpmv clAmdBlasDtpmv_pfn +#undef clAmdBlasDtpsv +//#define clAmdBlasDtpsv clAmdBlasDtpsv_pfn +#undef clAmdBlasDtrmm +//#define clAmdBlasDtrmm clAmdBlasDtrmm_pfn +#undef clAmdBlasDtrmmEx +//#define clAmdBlasDtrmmEx clAmdBlasDtrmmEx_pfn +#undef clAmdBlasDtrmv +//#define clAmdBlasDtrmv clAmdBlasDtrmv_pfn +#undef clAmdBlasDtrsm +//#define clAmdBlasDtrsm clAmdBlasDtrsm_pfn +#undef clAmdBlasDtrsmEx +//#define clAmdBlasDtrsmEx clAmdBlasDtrsmEx_pfn +#undef clAmdBlasDtrsv +//#define clAmdBlasDtrsv clAmdBlasDtrsv_pfn +#undef clAmdBlasDzasum +//#define clAmdBlasDzasum clAmdBlasDzasum_pfn +#undef clAmdBlasDznrm2 +//#define clAmdBlasDznrm2 clAmdBlasDznrm2_pfn +#undef clAmdBlasGetVersion +//#define clAmdBlasGetVersion clAmdBlasGetVersion_pfn +#undef clAmdBlasRemoveScratchImage +//#define clAmdBlasRemoveScratchImage clAmdBlasRemoveScratchImage_pfn +#undef clAmdBlasSasum +//#define clAmdBlasSasum clAmdBlasSasum_pfn +#undef clAmdBlasSaxpy +//#define clAmdBlasSaxpy clAmdBlasSaxpy_pfn +#undef clAmdBlasScasum +//#define clAmdBlasScasum clAmdBlasScasum_pfn +#undef clAmdBlasScnrm2 +//#define clAmdBlasScnrm2 clAmdBlasScnrm2_pfn +#undef clAmdBlasScopy +//#define clAmdBlasScopy clAmdBlasScopy_pfn +#undef clAmdBlasSdot +//#define clAmdBlasSdot clAmdBlasSdot_pfn +#undef clAmdBlasSetup +#define clAmdBlasSetup clAmdBlasSetup_pfn +#undef clAmdBlasSgbmv +//#define clAmdBlasSgbmv clAmdBlasSgbmv_pfn +#undef clAmdBlasSgemm +//#define clAmdBlasSgemm clAmdBlasSgemm_pfn +#undef clAmdBlasSgemmEx +#define clAmdBlasSgemmEx clAmdBlasSgemmEx_pfn +#undef clAmdBlasSgemv +//#define clAmdBlasSgemv clAmdBlasSgemv_pfn +#undef clAmdBlasSgemvEx +//#define clAmdBlasSgemvEx clAmdBlasSgemvEx_pfn +#undef clAmdBlasSger +//#define clAmdBlasSger clAmdBlasSger_pfn +#undef clAmdBlasSnrm2 +//#define clAmdBlasSnrm2 clAmdBlasSnrm2_pfn +#undef clAmdBlasSrot +//#define clAmdBlasSrot clAmdBlasSrot_pfn +#undef clAmdBlasSrotg +//#define clAmdBlasSrotg clAmdBlasSrotg_pfn +#undef clAmdBlasSrotm +//#define clAmdBlasSrotm clAmdBlasSrotm_pfn +#undef clAmdBlasSrotmg +//#define clAmdBlasSrotmg clAmdBlasSrotmg_pfn +#undef clAmdBlasSsbmv +//#define clAmdBlasSsbmv clAmdBlasSsbmv_pfn +#undef clAmdBlasSscal +//#define clAmdBlasSscal clAmdBlasSscal_pfn +#undef clAmdBlasSspmv +//#define clAmdBlasSspmv clAmdBlasSspmv_pfn +#undef clAmdBlasSspr +//#define clAmdBlasSspr clAmdBlasSspr_pfn +#undef clAmdBlasSspr2 +//#define clAmdBlasSspr2 clAmdBlasSspr2_pfn +#undef clAmdBlasSswap +//#define clAmdBlasSswap clAmdBlasSswap_pfn +#undef clAmdBlasSsymm +//#define clAmdBlasSsymm clAmdBlasSsymm_pfn +#undef clAmdBlasSsymv +//#define clAmdBlasSsymv clAmdBlasSsymv_pfn +#undef clAmdBlasSsymvEx +//#define clAmdBlasSsymvEx clAmdBlasSsymvEx_pfn +#undef clAmdBlasSsyr +//#define clAmdBlasSsyr clAmdBlasSsyr_pfn +#undef clAmdBlasSsyr2 +//#define clAmdBlasSsyr2 clAmdBlasSsyr2_pfn +#undef clAmdBlasSsyr2k +//#define clAmdBlasSsyr2k clAmdBlasSsyr2k_pfn +#undef clAmdBlasSsyr2kEx +//#define clAmdBlasSsyr2kEx clAmdBlasSsyr2kEx_pfn +#undef clAmdBlasSsyrk +//#define clAmdBlasSsyrk clAmdBlasSsyrk_pfn +#undef clAmdBlasSsyrkEx +//#define clAmdBlasSsyrkEx clAmdBlasSsyrkEx_pfn +#undef clAmdBlasStbmv +//#define clAmdBlasStbmv clAmdBlasStbmv_pfn +#undef clAmdBlasStbsv +//#define clAmdBlasStbsv clAmdBlasStbsv_pfn +#undef clAmdBlasStpmv +//#define clAmdBlasStpmv clAmdBlasStpmv_pfn +#undef clAmdBlasStpsv +//#define clAmdBlasStpsv clAmdBlasStpsv_pfn +#undef clAmdBlasStrmm +//#define clAmdBlasStrmm clAmdBlasStrmm_pfn +#undef clAmdBlasStrmmEx +//#define clAmdBlasStrmmEx clAmdBlasStrmmEx_pfn +#undef clAmdBlasStrmv +//#define clAmdBlasStrmv clAmdBlasStrmv_pfn +#undef clAmdBlasStrsm +//#define clAmdBlasStrsm clAmdBlasStrsm_pfn +#undef clAmdBlasStrsmEx +//#define clAmdBlasStrsmEx clAmdBlasStrsmEx_pfn +#undef clAmdBlasStrsv +//#define clAmdBlasStrsv clAmdBlasStrsv_pfn +#undef clAmdBlasTeardown +#define clAmdBlasTeardown clAmdBlasTeardown_pfn +#undef clAmdBlasZaxpy +//#define clAmdBlasZaxpy clAmdBlasZaxpy_pfn +#undef clAmdBlasZcopy +//#define clAmdBlasZcopy clAmdBlasZcopy_pfn +#undef clAmdBlasZdotc +//#define clAmdBlasZdotc clAmdBlasZdotc_pfn +#undef clAmdBlasZdotu +//#define clAmdBlasZdotu clAmdBlasZdotu_pfn +#undef clAmdBlasZdrot +//#define clAmdBlasZdrot clAmdBlasZdrot_pfn +#undef clAmdBlasZdscal +//#define clAmdBlasZdscal clAmdBlasZdscal_pfn +#undef clAmdBlasZgbmv +//#define clAmdBlasZgbmv clAmdBlasZgbmv_pfn +#undef clAmdBlasZgemm +//#define clAmdBlasZgemm clAmdBlasZgemm_pfn +#undef clAmdBlasZgemmEx +#define clAmdBlasZgemmEx clAmdBlasZgemmEx_pfn +#undef clAmdBlasZgemv +//#define clAmdBlasZgemv clAmdBlasZgemv_pfn +#undef clAmdBlasZgemvEx +//#define clAmdBlasZgemvEx clAmdBlasZgemvEx_pfn +#undef clAmdBlasZgerc +//#define clAmdBlasZgerc clAmdBlasZgerc_pfn +#undef clAmdBlasZgeru +//#define clAmdBlasZgeru clAmdBlasZgeru_pfn +#undef clAmdBlasZhbmv +//#define clAmdBlasZhbmv clAmdBlasZhbmv_pfn +#undef clAmdBlasZhemm +//#define clAmdBlasZhemm clAmdBlasZhemm_pfn +#undef clAmdBlasZhemv +//#define clAmdBlasZhemv clAmdBlasZhemv_pfn +#undef clAmdBlasZher +//#define clAmdBlasZher clAmdBlasZher_pfn +#undef clAmdBlasZher2 +//#define clAmdBlasZher2 clAmdBlasZher2_pfn +#undef clAmdBlasZher2k +//#define clAmdBlasZher2k clAmdBlasZher2k_pfn +#undef clAmdBlasZherk +//#define clAmdBlasZherk clAmdBlasZherk_pfn +#undef clAmdBlasZhpmv +//#define clAmdBlasZhpmv clAmdBlasZhpmv_pfn +#undef clAmdBlasZhpr +//#define clAmdBlasZhpr clAmdBlasZhpr_pfn +#undef clAmdBlasZhpr2 +//#define clAmdBlasZhpr2 clAmdBlasZhpr2_pfn +#undef clAmdBlasZrotg +//#define clAmdBlasZrotg clAmdBlasZrotg_pfn +#undef clAmdBlasZscal +//#define clAmdBlasZscal clAmdBlasZscal_pfn +#undef clAmdBlasZswap +//#define clAmdBlasZswap clAmdBlasZswap_pfn +#undef clAmdBlasZsymm +//#define clAmdBlasZsymm clAmdBlasZsymm_pfn +#undef clAmdBlasZsyr2k +//#define clAmdBlasZsyr2k clAmdBlasZsyr2k_pfn +#undef clAmdBlasZsyr2kEx +//#define clAmdBlasZsyr2kEx clAmdBlasZsyr2kEx_pfn +#undef clAmdBlasZsyrk +//#define clAmdBlasZsyrk clAmdBlasZsyrk_pfn +#undef clAmdBlasZsyrkEx +//#define clAmdBlasZsyrkEx clAmdBlasZsyrkEx_pfn +#undef clAmdBlasZtbmv +//#define clAmdBlasZtbmv clAmdBlasZtbmv_pfn +#undef clAmdBlasZtbsv +//#define clAmdBlasZtbsv clAmdBlasZtbsv_pfn +#undef clAmdBlasZtpmv +//#define clAmdBlasZtpmv clAmdBlasZtpmv_pfn +#undef clAmdBlasZtpsv +//#define clAmdBlasZtpsv clAmdBlasZtpsv_pfn +#undef clAmdBlasZtrmm +//#define clAmdBlasZtrmm clAmdBlasZtrmm_pfn +#undef clAmdBlasZtrmmEx +//#define clAmdBlasZtrmmEx clAmdBlasZtrmmEx_pfn +#undef clAmdBlasZtrmv +//#define clAmdBlasZtrmv clAmdBlasZtrmv_pfn +#undef clAmdBlasZtrsm +//#define clAmdBlasZtrsm clAmdBlasZtrsm_pfn +#undef clAmdBlasZtrsmEx +//#define clAmdBlasZtrsmEx clAmdBlasZtrsmEx_pfn +#undef clAmdBlasZtrsv +//#define clAmdBlasZtrsv clAmdBlasZtrsv_pfn +#undef clAmdBlasiCamax +//#define clAmdBlasiCamax clAmdBlasiCamax_pfn +#undef clAmdBlasiDamax +//#define clAmdBlasiDamax clAmdBlasiDamax_pfn +#undef clAmdBlasiSamax +//#define clAmdBlasiSamax clAmdBlasiSamax_pfn +#undef clAmdBlasiZamax +//#define clAmdBlasiZamax clAmdBlasiZamax_pfn + +// generated by parser_clamdblas.py +//extern CL_RUNTIME_EXPORT cl_ulong (*clAmdBlasAddScratchImage)(cl_context context, size_t width, size_t height, clAmdBlasStatus* status); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCaxpy)(size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, FloatComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, FloatComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgerc)(clAmdBlasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCgeru)(clAmdBlasOrder order, size_t M, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChemm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChemv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, FloatComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCher2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCherk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, float alpha, const cl_mem A, size_t offa, size_t lda, float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasChpr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCscal)(size_t N, cl_float2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t lda, FloatComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, FloatComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, FloatComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasCtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDaxpy)(size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDger)(clAmdBlasOrder order, size_t M, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotg)(cl_mem DA, size_t offDA, cl_mem DB, size_t offDB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDrotmg)(cl_mem DD1, size_t offDD1, cl_mem DD2, size_t offDD2, cl_mem DX1, size_t offDX1, const cl_mem DY1, size_t offDY1, cl_mem DPARAM, size_t offDparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDspr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsymvEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_double beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t lda, cl_double beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_double beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_double alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDzasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasDznrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasRemoveScratchImage)(cl_ulong imageID); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSaxpy)(size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScasum)(size_t N, cl_mem asum, size_t offAsum, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasScopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSdot)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSetup)(); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSger)(clAmdBlasOrder order, size_t M, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSnrm2)(size_t N, cl_mem NRM2, size_t offNRM2, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_float C, cl_float S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotg)(cl_mem SA, size_t offSA, cl_mem SB, size_t offSB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotm)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, const cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSrotmg)(cl_mem SD1, size_t offSD1, cl_mem SD2, size_t offSD2, cl_mem SX1, size_t offSX1, const cl_mem SY1, size_t offSY1, cl_mem SPARAM, size_t offSparam, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSscal)(size_t N, cl_float alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_float beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSspr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_float beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsymvEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, cl_float beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_float alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t lda, cl_float beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasSsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_float beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, cl_float alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasStrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT void (*clAmdBlasTeardown)(); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZaxpy)(size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZcopy)(size_t N, const cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdotc)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdotu)(size_t N, cl_mem dotProduct, size_t offDP, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdrot)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_double C, cl_double S, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZdscal)(size_t N, cl_double alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgbmv)(clAmdBlasOrder order, clAmdBlasTranspose trans, size_t M, size_t N, size_t KL, size_t KU, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemm)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemmEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, clAmdBlasTranspose transB, size_t M, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemv)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem x, size_t offx, int incx, DoubleComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgemvEx)(clAmdBlasOrder order, clAmdBlasTranspose transA, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem x, size_t offx, int incx, DoubleComplex beta, cl_mem y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgerc)(clAmdBlasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZgeru)(clAmdBlasOrder order, size_t M, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, size_t K, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhemm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhemv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem X, size_t offx, int incx, DoubleComplex beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem A, size_t offa, size_t lda, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZher2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZherk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, double alpha, const cl_mem A, size_t offa, size_t lda, double beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem AP, size_t offa, const cl_mem X, size_t offx, int incx, cl_double2 beta, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpr)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double alpha, const cl_mem X, size_t offx, int incx, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZhpr2)(clAmdBlasOrder order, clAmdBlasUplo uplo, size_t N, cl_double2 alpha, const cl_mem X, size_t offx, int incx, const cl_mem Y, size_t offy, int incy, cl_mem AP, size_t offa, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZrotg)(cl_mem CA, size_t offCA, cl_mem CB, size_t offCB, cl_mem C, size_t offC, cl_mem S, size_t offS, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZscal)(size_t N, cl_double2 alpha, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZswap)(size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsymm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, size_t M, size_t N, cl_double2 alpha, const cl_mem A, size_t offa, size_t lda, const cl_mem B, size_t offb, size_t ldb, cl_double2 beta, cl_mem C, size_t offc, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyr2k)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, const cl_mem B, size_t ldb, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyr2kEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transAB, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, const cl_mem B, size_t offB, size_t ldb, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyrk)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t lda, DoubleComplex beta, cl_mem C, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZsyrkEx)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose transA, size_t N, size_t K, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, DoubleComplex beta, cl_mem C, size_t offC, size_t ldc, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtbmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtbsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, size_t K, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtpmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem AP, size_t offa, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtpsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrmv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsm)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t lda, cl_mem B, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsmEx)(clAmdBlasOrder order, clAmdBlasSide side, clAmdBlasUplo uplo, clAmdBlasTranspose transA, clAmdBlasDiag diag, size_t M, size_t N, DoubleComplex alpha, const cl_mem A, size_t offA, size_t lda, cl_mem B, size_t offB, size_t ldb, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasZtrsv)(clAmdBlasOrder order, clAmdBlasUplo uplo, clAmdBlasTranspose trans, clAmdBlasDiag diag, size_t N, const cl_mem A, size_t offa, size_t lda, cl_mem X, size_t offx, int incx, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiCamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiDamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiSamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); +//extern CL_RUNTIME_EXPORT clAmdBlasStatus (*clAmdBlasiZamax)(size_t N, cl_mem iMax, size_t offiMax, const cl_mem X, size_t offx, int incx, cl_mem scratchBuff, cl_uint numCommandQueues, cl_command_queue* commandQueues, cl_uint numEventsInWaitList, const cl_event* eventWaitList, cl_event* events); diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1457d7eb8d69a56197b8e80430728d571282088f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_clamdfft.hpp @@ -0,0 +1,142 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP +#error "Invalid usage" +#endif + +// generated by parser_clamdfft.py +#define clAmdFftBakePlan clAmdFftBakePlan_ +#define clAmdFftCopyPlan clAmdFftCopyPlan_ +#define clAmdFftCreateDefaultPlan clAmdFftCreateDefaultPlan_ +#define clAmdFftDestroyPlan clAmdFftDestroyPlan_ +#define clAmdFftEnqueueTransform clAmdFftEnqueueTransform_ +#define clAmdFftGetLayout clAmdFftGetLayout_ +#define clAmdFftGetPlanBatchSize clAmdFftGetPlanBatchSize_ +#define clAmdFftGetPlanContext clAmdFftGetPlanContext_ +#define clAmdFftGetPlanDim clAmdFftGetPlanDim_ +#define clAmdFftGetPlanDistance clAmdFftGetPlanDistance_ +#define clAmdFftGetPlanInStride clAmdFftGetPlanInStride_ +#define clAmdFftGetPlanLength clAmdFftGetPlanLength_ +#define clAmdFftGetPlanOutStride clAmdFftGetPlanOutStride_ +#define clAmdFftGetPlanPrecision clAmdFftGetPlanPrecision_ +#define clAmdFftGetPlanScale clAmdFftGetPlanScale_ +#define clAmdFftGetPlanTransposeResult clAmdFftGetPlanTransposeResult_ +#define clAmdFftGetResultLocation clAmdFftGetResultLocation_ +#define clAmdFftGetTmpBufSize clAmdFftGetTmpBufSize_ +#define clAmdFftGetVersion clAmdFftGetVersion_ +#define clAmdFftSetLayout clAmdFftSetLayout_ +#define clAmdFftSetPlanBatchSize clAmdFftSetPlanBatchSize_ +#define clAmdFftSetPlanDim clAmdFftSetPlanDim_ +#define clAmdFftSetPlanDistance clAmdFftSetPlanDistance_ +#define clAmdFftSetPlanInStride clAmdFftSetPlanInStride_ +#define clAmdFftSetPlanLength clAmdFftSetPlanLength_ +#define clAmdFftSetPlanOutStride clAmdFftSetPlanOutStride_ +#define clAmdFftSetPlanPrecision clAmdFftSetPlanPrecision_ +#define clAmdFftSetPlanScale clAmdFftSetPlanScale_ +#define clAmdFftSetPlanTransposeResult clAmdFftSetPlanTransposeResult_ +#define clAmdFftSetResultLocation clAmdFftSetResultLocation_ +#define clAmdFftSetup clAmdFftSetup_ +#define clAmdFftTeardown clAmdFftTeardown_ + +#include + +// generated by parser_clamdfft.py +#undef clAmdFftBakePlan +#define clAmdFftBakePlan clAmdFftBakePlan_pfn +#undef clAmdFftCopyPlan +//#define clAmdFftCopyPlan clAmdFftCopyPlan_pfn +#undef clAmdFftCreateDefaultPlan +#define clAmdFftCreateDefaultPlan clAmdFftCreateDefaultPlan_pfn +#undef clAmdFftDestroyPlan +#define clAmdFftDestroyPlan clAmdFftDestroyPlan_pfn +#undef clAmdFftEnqueueTransform +#define clAmdFftEnqueueTransform clAmdFftEnqueueTransform_pfn +#undef clAmdFftGetLayout +//#define clAmdFftGetLayout clAmdFftGetLayout_pfn +#undef clAmdFftGetPlanBatchSize +//#define clAmdFftGetPlanBatchSize clAmdFftGetPlanBatchSize_pfn +#undef clAmdFftGetPlanContext +//#define clAmdFftGetPlanContext clAmdFftGetPlanContext_pfn +#undef clAmdFftGetPlanDim +//#define clAmdFftGetPlanDim clAmdFftGetPlanDim_pfn +#undef clAmdFftGetPlanDistance +//#define clAmdFftGetPlanDistance clAmdFftGetPlanDistance_pfn +#undef clAmdFftGetPlanInStride +//#define clAmdFftGetPlanInStride clAmdFftGetPlanInStride_pfn +#undef clAmdFftGetPlanLength +//#define clAmdFftGetPlanLength clAmdFftGetPlanLength_pfn +#undef clAmdFftGetPlanOutStride +//#define clAmdFftGetPlanOutStride clAmdFftGetPlanOutStride_pfn +#undef clAmdFftGetPlanPrecision +//#define clAmdFftGetPlanPrecision clAmdFftGetPlanPrecision_pfn +#undef clAmdFftGetPlanScale +//#define clAmdFftGetPlanScale clAmdFftGetPlanScale_pfn +#undef clAmdFftGetPlanTransposeResult +//#define clAmdFftGetPlanTransposeResult clAmdFftGetPlanTransposeResult_pfn +#undef clAmdFftGetResultLocation +//#define clAmdFftGetResultLocation clAmdFftGetResultLocation_pfn +#undef clAmdFftGetTmpBufSize +#define clAmdFftGetTmpBufSize clAmdFftGetTmpBufSize_pfn +#undef clAmdFftGetVersion +#define clAmdFftGetVersion clAmdFftGetVersion_pfn +#undef clAmdFftSetLayout +#define clAmdFftSetLayout clAmdFftSetLayout_pfn +#undef clAmdFftSetPlanBatchSize +#define clAmdFftSetPlanBatchSize clAmdFftSetPlanBatchSize_pfn +#undef clAmdFftSetPlanDim +//#define clAmdFftSetPlanDim clAmdFftSetPlanDim_pfn +#undef clAmdFftSetPlanDistance +#define clAmdFftSetPlanDistance clAmdFftSetPlanDistance_pfn +#undef clAmdFftSetPlanInStride +#define clAmdFftSetPlanInStride clAmdFftSetPlanInStride_pfn +#undef clAmdFftSetPlanLength +//#define clAmdFftSetPlanLength clAmdFftSetPlanLength_pfn +#undef clAmdFftSetPlanOutStride +#define clAmdFftSetPlanOutStride clAmdFftSetPlanOutStride_pfn +#undef clAmdFftSetPlanPrecision +#define clAmdFftSetPlanPrecision clAmdFftSetPlanPrecision_pfn +#undef clAmdFftSetPlanScale +#define clAmdFftSetPlanScale clAmdFftSetPlanScale_pfn +#undef clAmdFftSetPlanTransposeResult +//#define clAmdFftSetPlanTransposeResult clAmdFftSetPlanTransposeResult_pfn +#undef clAmdFftSetResultLocation +#define clAmdFftSetResultLocation clAmdFftSetResultLocation_pfn +#undef clAmdFftSetup +#define clAmdFftSetup clAmdFftSetup_pfn +#undef clAmdFftTeardown +#define clAmdFftTeardown clAmdFftTeardown_pfn + +// generated by parser_clamdfft.py +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftBakePlan)(clAmdFftPlanHandle plHandle, cl_uint numQueues, cl_command_queue* commQueueFFT, void (CL_CALLBACK* pfn_notify) (clAmdFftPlanHandle plHandle, void* user_data), void* user_data); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftCopyPlan)(clAmdFftPlanHandle* out_plHandle, cl_context new_context, clAmdFftPlanHandle in_plHandle); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftCreateDefaultPlan)(clAmdFftPlanHandle* plHandle, cl_context context, const clAmdFftDim dim, const size_t* clLengths); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftDestroyPlan)(clAmdFftPlanHandle* plHandle); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftEnqueueTransform)(clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_uint numQueuesAndEvents, cl_command_queue* commQueues, cl_uint numWaitEvents, const cl_event* waitEvents, cl_event* outEvents, cl_mem* inputBuffers, cl_mem* outputBuffers, cl_mem tmpBuffer); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetLayout)(const clAmdFftPlanHandle plHandle, clAmdFftLayout* iLayout, clAmdFftLayout* oLayout); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanBatchSize)(const clAmdFftPlanHandle plHandle, size_t* batchSize); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanContext)(const clAmdFftPlanHandle plHandle, cl_context* context); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanDim)(const clAmdFftPlanHandle plHandle, clAmdFftDim* dim, cl_uint* size); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanDistance)(const clAmdFftPlanHandle plHandle, size_t* iDist, size_t* oDist); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanInStride)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanLength)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clLengths); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanOutStride)(const clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanPrecision)(const clAmdFftPlanHandle plHandle, clAmdFftPrecision* precision); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanScale)(const clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_float* scale); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetPlanTransposeResult)(const clAmdFftPlanHandle plHandle, clAmdFftResultTransposed* transposed); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetResultLocation)(const clAmdFftPlanHandle plHandle, clAmdFftResultLocation* placeness); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetTmpBufSize)(const clAmdFftPlanHandle plHandle, size_t* buffersize); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftGetVersion)(cl_uint* major, cl_uint* minor, cl_uint* patch); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetLayout)(clAmdFftPlanHandle plHandle, clAmdFftLayout iLayout, clAmdFftLayout oLayout); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanBatchSize)(clAmdFftPlanHandle plHandle, size_t batchSize); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanDim)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanDistance)(clAmdFftPlanHandle plHandle, size_t iDist, size_t oDist); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanInStride)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanLength)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, const size_t* clLengths); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanOutStride)(clAmdFftPlanHandle plHandle, const clAmdFftDim dim, size_t* clStrides); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanPrecision)(clAmdFftPlanHandle plHandle, clAmdFftPrecision precision); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanScale)(clAmdFftPlanHandle plHandle, clAmdFftDirection dir, cl_float scale); +//extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetPlanTransposeResult)(clAmdFftPlanHandle plHandle, clAmdFftResultTransposed transposed); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetResultLocation)(clAmdFftPlanHandle plHandle, clAmdFftResultLocation placeness); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftSetup)(const clAmdFftSetupData* setupData); +extern CL_RUNTIME_EXPORT clAmdFftStatus (*clAmdFftTeardown)(); diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..28618a1f3a6a9e044792d306c6d23233934730fd --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp @@ -0,0 +1,371 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP +#error "Invalid usage" +#endif + +// generated by parser_cl.py +#define clBuildProgram clBuildProgram_ +#define clCompileProgram clCompileProgram_ +#define clCreateBuffer clCreateBuffer_ +#define clCreateCommandQueue clCreateCommandQueue_ +#define clCreateContext clCreateContext_ +#define clCreateContextFromType clCreateContextFromType_ +#define clCreateImage clCreateImage_ +#define clCreateImage2D clCreateImage2D_ +#define clCreateImage3D clCreateImage3D_ +#define clCreateKernel clCreateKernel_ +#define clCreateKernelsInProgram clCreateKernelsInProgram_ +#define clCreateProgramWithBinary clCreateProgramWithBinary_ +#define clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels_ +#define clCreateProgramWithSource clCreateProgramWithSource_ +#define clCreateSampler clCreateSampler_ +#define clCreateSubBuffer clCreateSubBuffer_ +#define clCreateSubDevices clCreateSubDevices_ +#define clCreateUserEvent clCreateUserEvent_ +#define clEnqueueBarrier clEnqueueBarrier_ +#define clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList_ +#define clEnqueueCopyBuffer clEnqueueCopyBuffer_ +#define clEnqueueCopyBufferRect clEnqueueCopyBufferRect_ +#define clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage_ +#define clEnqueueCopyImage clEnqueueCopyImage_ +#define clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer_ +#define clEnqueueFillBuffer clEnqueueFillBuffer_ +#define clEnqueueFillImage clEnqueueFillImage_ +#define clEnqueueMapBuffer clEnqueueMapBuffer_ +#define clEnqueueMapImage clEnqueueMapImage_ +#define clEnqueueMarker clEnqueueMarker_ +#define clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList_ +#define clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects_ +#define clEnqueueNDRangeKernel clEnqueueNDRangeKernel_ +#define clEnqueueNativeKernel clEnqueueNativeKernel_ +#define clEnqueueReadBuffer clEnqueueReadBuffer_ +#define clEnqueueReadBufferRect clEnqueueReadBufferRect_ +#define clEnqueueReadImage clEnqueueReadImage_ +#define clEnqueueTask clEnqueueTask_ +#define clEnqueueUnmapMemObject clEnqueueUnmapMemObject_ +#define clEnqueueWaitForEvents clEnqueueWaitForEvents_ +#define clEnqueueWriteBuffer clEnqueueWriteBuffer_ +#define clEnqueueWriteBufferRect clEnqueueWriteBufferRect_ +#define clEnqueueWriteImage clEnqueueWriteImage_ +#define clFinish clFinish_ +#define clFlush clFlush_ +#define clGetCommandQueueInfo clGetCommandQueueInfo_ +#define clGetContextInfo clGetContextInfo_ +#define clGetDeviceIDs clGetDeviceIDs_ +#define clGetDeviceInfo clGetDeviceInfo_ +#define clGetEventInfo clGetEventInfo_ +#define clGetEventProfilingInfo clGetEventProfilingInfo_ +#define clGetExtensionFunctionAddress clGetExtensionFunctionAddress_ +#define clGetExtensionFunctionAddressForPlatform clGetExtensionFunctionAddressForPlatform_ +#define clGetImageInfo clGetImageInfo_ +#define clGetKernelArgInfo clGetKernelArgInfo_ +#define clGetKernelInfo clGetKernelInfo_ +#define clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo_ +#define clGetMemObjectInfo clGetMemObjectInfo_ +#define clGetPlatformIDs clGetPlatformIDs_ +#define clGetPlatformInfo clGetPlatformInfo_ +#define clGetProgramBuildInfo clGetProgramBuildInfo_ +#define clGetProgramInfo clGetProgramInfo_ +#define clGetSamplerInfo clGetSamplerInfo_ +#define clGetSupportedImageFormats clGetSupportedImageFormats_ +#define clLinkProgram clLinkProgram_ +#define clReleaseCommandQueue clReleaseCommandQueue_ +#define clReleaseContext clReleaseContext_ +#define clReleaseDevice clReleaseDevice_ +#define clReleaseEvent clReleaseEvent_ +#define clReleaseKernel clReleaseKernel_ +#define clReleaseMemObject clReleaseMemObject_ +#define clReleaseProgram clReleaseProgram_ +#define clReleaseSampler clReleaseSampler_ +#define clRetainCommandQueue clRetainCommandQueue_ +#define clRetainContext clRetainContext_ +#define clRetainDevice clRetainDevice_ +#define clRetainEvent clRetainEvent_ +#define clRetainKernel clRetainKernel_ +#define clRetainMemObject clRetainMemObject_ +#define clRetainProgram clRetainProgram_ +#define clRetainSampler clRetainSampler_ +#define clSetEventCallback clSetEventCallback_ +#define clSetKernelArg clSetKernelArg_ +#define clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback_ +#define clSetUserEventStatus clSetUserEventStatus_ +#define clUnloadCompiler clUnloadCompiler_ +#define clUnloadPlatformCompiler clUnloadPlatformCompiler_ +#define clWaitForEvents clWaitForEvents_ + +#if defined __APPLE__ +#define CL_SILENCE_DEPRECATION +#include +#else +#include +#endif + +// generated by parser_cl.py +#undef clBuildProgram +#define clBuildProgram clBuildProgram_pfn +#undef clCompileProgram +#define clCompileProgram clCompileProgram_pfn +#undef clCreateBuffer +#define clCreateBuffer clCreateBuffer_pfn +#undef clCreateCommandQueue +#define clCreateCommandQueue clCreateCommandQueue_pfn +#undef clCreateContext +#define clCreateContext clCreateContext_pfn +#undef clCreateContextFromType +#define clCreateContextFromType clCreateContextFromType_pfn +#undef clCreateImage +#define clCreateImage clCreateImage_pfn +#undef clCreateImage2D +#define clCreateImage2D clCreateImage2D_pfn +#undef clCreateImage3D +#define clCreateImage3D clCreateImage3D_pfn +#undef clCreateKernel +#define clCreateKernel clCreateKernel_pfn +#undef clCreateKernelsInProgram +#define clCreateKernelsInProgram clCreateKernelsInProgram_pfn +#undef clCreateProgramWithBinary +#define clCreateProgramWithBinary clCreateProgramWithBinary_pfn +#undef clCreateProgramWithBuiltInKernels +#define clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels_pfn +#undef clCreateProgramWithSource +#define clCreateProgramWithSource clCreateProgramWithSource_pfn +#undef clCreateSampler +#define clCreateSampler clCreateSampler_pfn +#undef clCreateSubBuffer +#define clCreateSubBuffer clCreateSubBuffer_pfn +#undef clCreateSubDevices +#define clCreateSubDevices clCreateSubDevices_pfn +#undef clCreateUserEvent +#define clCreateUserEvent clCreateUserEvent_pfn +#undef clEnqueueBarrier +#define clEnqueueBarrier clEnqueueBarrier_pfn +#undef clEnqueueBarrierWithWaitList +#define clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList_pfn +#undef clEnqueueCopyBuffer +#define clEnqueueCopyBuffer clEnqueueCopyBuffer_pfn +#undef clEnqueueCopyBufferRect +#define clEnqueueCopyBufferRect clEnqueueCopyBufferRect_pfn +#undef clEnqueueCopyBufferToImage +#define clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage_pfn +#undef clEnqueueCopyImage +#define clEnqueueCopyImage clEnqueueCopyImage_pfn +#undef clEnqueueCopyImageToBuffer +#define clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer_pfn +#undef clEnqueueFillBuffer +#define clEnqueueFillBuffer clEnqueueFillBuffer_pfn +#undef clEnqueueFillImage +#define clEnqueueFillImage clEnqueueFillImage_pfn +#undef clEnqueueMapBuffer +#define clEnqueueMapBuffer clEnqueueMapBuffer_pfn +#undef clEnqueueMapImage +#define clEnqueueMapImage clEnqueueMapImage_pfn +#undef clEnqueueMarker +#define clEnqueueMarker clEnqueueMarker_pfn +#undef clEnqueueMarkerWithWaitList +#define clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList_pfn +#undef clEnqueueMigrateMemObjects +#define clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects_pfn +#undef clEnqueueNDRangeKernel +#define clEnqueueNDRangeKernel clEnqueueNDRangeKernel_pfn +#undef clEnqueueNativeKernel +#define clEnqueueNativeKernel clEnqueueNativeKernel_pfn +#undef clEnqueueReadBuffer +#define clEnqueueReadBuffer clEnqueueReadBuffer_pfn +#undef clEnqueueReadBufferRect +#define clEnqueueReadBufferRect clEnqueueReadBufferRect_pfn +#undef clEnqueueReadImage +#define clEnqueueReadImage clEnqueueReadImage_pfn +#undef clEnqueueTask +#define clEnqueueTask clEnqueueTask_pfn +#undef clEnqueueUnmapMemObject +#define clEnqueueUnmapMemObject clEnqueueUnmapMemObject_pfn +#undef clEnqueueWaitForEvents +#define clEnqueueWaitForEvents clEnqueueWaitForEvents_pfn +#undef clEnqueueWriteBuffer +#define clEnqueueWriteBuffer clEnqueueWriteBuffer_pfn +#undef clEnqueueWriteBufferRect +#define clEnqueueWriteBufferRect clEnqueueWriteBufferRect_pfn +#undef clEnqueueWriteImage +#define clEnqueueWriteImage clEnqueueWriteImage_pfn +#undef clFinish +#define clFinish clFinish_pfn +#undef clFlush +#define clFlush clFlush_pfn +#undef clGetCommandQueueInfo +#define clGetCommandQueueInfo clGetCommandQueueInfo_pfn +#undef clGetContextInfo +#define clGetContextInfo clGetContextInfo_pfn +#undef clGetDeviceIDs +#define clGetDeviceIDs clGetDeviceIDs_pfn +#undef clGetDeviceInfo +#define clGetDeviceInfo clGetDeviceInfo_pfn +#undef clGetEventInfo +#define clGetEventInfo clGetEventInfo_pfn +#undef clGetEventProfilingInfo +#define clGetEventProfilingInfo clGetEventProfilingInfo_pfn +#undef clGetExtensionFunctionAddress +#define clGetExtensionFunctionAddress clGetExtensionFunctionAddress_pfn +#undef clGetExtensionFunctionAddressForPlatform +#define clGetExtensionFunctionAddressForPlatform clGetExtensionFunctionAddressForPlatform_pfn +#undef clGetImageInfo +#define clGetImageInfo clGetImageInfo_pfn +#undef clGetKernelArgInfo +#define clGetKernelArgInfo clGetKernelArgInfo_pfn +#undef clGetKernelInfo +#define clGetKernelInfo clGetKernelInfo_pfn +#undef clGetKernelWorkGroupInfo +#define clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo_pfn +#undef clGetMemObjectInfo +#define clGetMemObjectInfo clGetMemObjectInfo_pfn +#undef clGetPlatformIDs +#define clGetPlatformIDs clGetPlatformIDs_pfn +#undef clGetPlatformInfo +#define clGetPlatformInfo clGetPlatformInfo_pfn +#undef clGetProgramBuildInfo +#define clGetProgramBuildInfo clGetProgramBuildInfo_pfn +#undef clGetProgramInfo +#define clGetProgramInfo clGetProgramInfo_pfn +#undef clGetSamplerInfo +#define clGetSamplerInfo clGetSamplerInfo_pfn +#undef clGetSupportedImageFormats +#define clGetSupportedImageFormats clGetSupportedImageFormats_pfn +#undef clLinkProgram +#define clLinkProgram clLinkProgram_pfn +#undef clReleaseCommandQueue +#define clReleaseCommandQueue clReleaseCommandQueue_pfn +#undef clReleaseContext +#define clReleaseContext clReleaseContext_pfn +#undef clReleaseDevice +#define clReleaseDevice clReleaseDevice_pfn +#undef clReleaseEvent +#define clReleaseEvent clReleaseEvent_pfn +#undef clReleaseKernel +#define clReleaseKernel clReleaseKernel_pfn +#undef clReleaseMemObject +#define clReleaseMemObject clReleaseMemObject_pfn +#undef clReleaseProgram +#define clReleaseProgram clReleaseProgram_pfn +#undef clReleaseSampler +#define clReleaseSampler clReleaseSampler_pfn +#undef clRetainCommandQueue +#define clRetainCommandQueue clRetainCommandQueue_pfn +#undef clRetainContext +#define clRetainContext clRetainContext_pfn +#undef clRetainDevice +#define clRetainDevice clRetainDevice_pfn +#undef clRetainEvent +#define clRetainEvent clRetainEvent_pfn +#undef clRetainKernel +#define clRetainKernel clRetainKernel_pfn +#undef clRetainMemObject +#define clRetainMemObject clRetainMemObject_pfn +#undef clRetainProgram +#define clRetainProgram clRetainProgram_pfn +#undef clRetainSampler +#define clRetainSampler clRetainSampler_pfn +#undef clSetEventCallback +#define clSetEventCallback clSetEventCallback_pfn +#undef clSetKernelArg +#define clSetKernelArg clSetKernelArg_pfn +#undef clSetMemObjectDestructorCallback +#define clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback_pfn +#undef clSetUserEventStatus +#define clSetUserEventStatus clSetUserEventStatus_pfn +#undef clUnloadCompiler +#define clUnloadCompiler clUnloadCompiler_pfn +#undef clUnloadPlatformCompiler +#define clUnloadPlatformCompiler clUnloadPlatformCompiler_pfn +#undef clWaitForEvents +#define clWaitForEvents clWaitForEvents_pfn + +// generated by parser_cl.py +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clBuildProgram)(cl_program, cl_uint, const cl_device_id*, const char*, void (CL_CALLBACK*) (cl_program, void*), void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clCompileProgram)(cl_program, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, const char**, void (CL_CALLBACK*) (cl_program, void*), void*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateBuffer)(cl_context, cl_mem_flags, size_t, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_command_queue (CL_API_CALL*clCreateCommandQueue)(cl_context, cl_device_id, cl_command_queue_properties, cl_int*); +extern CL_RUNTIME_EXPORT cl_context (CL_API_CALL*clCreateContext)(const cl_context_properties*, cl_uint, const cl_device_id*, void (CL_CALLBACK*) (const char*, const void*, size_t, void*), void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_context (CL_API_CALL*clCreateContextFromType)(const cl_context_properties*, cl_device_type, void (CL_CALLBACK*) (const char*, const void*, size_t, void*), void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateImage)(cl_context, cl_mem_flags, const cl_image_format*, const cl_image_desc*, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateImage2D)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateImage3D)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, size_t, size_t, void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_kernel (CL_API_CALL*clCreateKernel)(cl_program, const char*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clCreateKernelsInProgram)(cl_program, cl_uint, cl_kernel*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clCreateProgramWithBinary)(cl_context, cl_uint, const cl_device_id*, const size_t*, const unsigned char**, cl_int*, cl_int*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clCreateProgramWithBuiltInKernels)(cl_context, cl_uint, const cl_device_id*, const char*, cl_int*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clCreateProgramWithSource)(cl_context, cl_uint, const char**, const size_t*, cl_int*); +extern CL_RUNTIME_EXPORT cl_sampler (CL_API_CALL*clCreateSampler)(cl_context, cl_bool, cl_addressing_mode, cl_filter_mode, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateSubBuffer)(cl_mem, cl_mem_flags, cl_buffer_create_type, const void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clCreateSubDevices)(cl_device_id, const cl_device_partition_property*, cl_uint, cl_device_id*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_event (CL_API_CALL*clCreateUserEvent)(cl_context, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueBarrier)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueBarrierWithWaitList)(cl_command_queue, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyBuffer)(cl_command_queue, cl_mem, cl_mem, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyBufferRect)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyBufferToImage)(cl_command_queue, cl_mem, cl_mem, size_t, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyImage)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueCopyImageToBuffer)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueFillBuffer)(cl_command_queue, cl_mem, const void*, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueFillImage)(cl_command_queue, cl_mem, const void*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clEnqueueMapBuffer)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event*, cl_event*, cl_int*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clEnqueueMapImage)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t*, const size_t*, size_t*, size_t*, cl_uint, const cl_event*, cl_event*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueMarker)(cl_command_queue, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueMarkerWithWaitList)(cl_command_queue, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueMigrateMemObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_mem_migration_flags, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueNDRangeKernel)(cl_command_queue, cl_kernel, cl_uint, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueNativeKernel)(cl_command_queue, void (CL_CALLBACK*) (void*), void*, size_t, cl_uint, const cl_mem*, const void**, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReadBuffer)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReadBufferRect)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReadImage)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueTask)(cl_command_queue, cl_kernel, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueUnmapMemObject)(cl_command_queue, cl_mem, void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWaitForEvents)(cl_command_queue, cl_uint, const cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWriteBuffer)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWriteBufferRect)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueWriteImage)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clFinish)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clFlush)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetCommandQueueInfo)(cl_command_queue, cl_command_queue_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetContextInfo)(cl_context, cl_context_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetDeviceIDs)(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetDeviceInfo)(cl_device_id, cl_device_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetEventInfo)(cl_event, cl_event_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetEventProfilingInfo)(cl_event, cl_profiling_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clGetExtensionFunctionAddress)(const char*); +extern CL_RUNTIME_EXPORT void* (CL_API_CALL*clGetExtensionFunctionAddressForPlatform)(cl_platform_id, const char*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetImageInfo)(cl_mem, cl_image_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetKernelArgInfo)(cl_kernel, cl_uint, cl_kernel_arg_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetKernelInfo)(cl_kernel, cl_kernel_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetKernelWorkGroupInfo)(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetMemObjectInfo)(cl_mem, cl_mem_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetPlatformIDs)(cl_uint, cl_platform_id*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetPlatformInfo)(cl_platform_id, cl_platform_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetProgramBuildInfo)(cl_program, cl_device_id, cl_program_build_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetProgramInfo)(cl_program, cl_program_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetSamplerInfo)(cl_sampler, cl_sampler_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetSupportedImageFormats)(cl_context, cl_mem_flags, cl_mem_object_type, cl_uint, cl_image_format*, cl_uint*); +extern CL_RUNTIME_EXPORT cl_program (CL_API_CALL*clLinkProgram)(cl_context, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, void (CL_CALLBACK*) (cl_program, void*), void*, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseCommandQueue)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseContext)(cl_context); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseDevice)(cl_device_id); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseEvent)(cl_event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseKernel)(cl_kernel); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseMemObject)(cl_mem); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseProgram)(cl_program); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clReleaseSampler)(cl_sampler); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainCommandQueue)(cl_command_queue); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainContext)(cl_context); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainDevice)(cl_device_id); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainEvent)(cl_event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainKernel)(cl_kernel); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainMemObject)(cl_mem); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainProgram)(cl_program); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clRetainSampler)(cl_sampler); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetEventCallback)(cl_event, cl_int, void (CL_CALLBACK*) (cl_event, cl_int, void*), void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetKernelArg)(cl_kernel, cl_uint, size_t, const void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetMemObjectDestructorCallback)(cl_mem, void (CL_CALLBACK*) (cl_mem, void*), void*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clSetUserEventStatus)(cl_event, cl_int); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clUnloadCompiler)(); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clUnloadPlatformCompiler)(cl_platform_id); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clWaitForEvents)(cl_uint, const cl_event*); diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp new file mode 100644 index 0000000000000000000000000000000000000000..216b22b8a85c825db0645536bbfcfe392f6b9e3f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp @@ -0,0 +1,272 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP +#error "Invalid usage" +#endif + +// generated by parser_cl.py +#undef clBuildProgram +#define clBuildProgram clBuildProgram_fn +inline cl_int clBuildProgram(cl_program p0, cl_uint p1, const cl_device_id* p2, const char* p3, void (CL_CALLBACK*p4) (cl_program, void*), void* p5) { return clBuildProgram_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCompileProgram +#define clCompileProgram clCompileProgram_fn +inline cl_int clCompileProgram(cl_program p0, cl_uint p1, const cl_device_id* p2, const char* p3, cl_uint p4, const cl_program* p5, const char** p6, void (CL_CALLBACK*p7) (cl_program, void*), void* p8) { return clCompileProgram_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clCreateBuffer +#define clCreateBuffer clCreateBuffer_fn +inline cl_mem clCreateBuffer(cl_context p0, cl_mem_flags p1, size_t p2, void* p3, cl_int* p4) { return clCreateBuffer_pfn(p0, p1, p2, p3, p4); } +#undef clCreateCommandQueue +#define clCreateCommandQueue clCreateCommandQueue_fn +inline cl_command_queue clCreateCommandQueue(cl_context p0, cl_device_id p1, cl_command_queue_properties p2, cl_int* p3) { return clCreateCommandQueue_pfn(p0, p1, p2, p3); } +#undef clCreateContext +#define clCreateContext clCreateContext_fn +inline cl_context clCreateContext(const cl_context_properties* p0, cl_uint p1, const cl_device_id* p2, void (CL_CALLBACK*p3) (const char*, const void*, size_t, void*), void* p4, cl_int* p5) { return clCreateContext_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateContextFromType +#define clCreateContextFromType clCreateContextFromType_fn +inline cl_context clCreateContextFromType(const cl_context_properties* p0, cl_device_type p1, void (CL_CALLBACK*p2) (const char*, const void*, size_t, void*), void* p3, cl_int* p4) { return clCreateContextFromType_pfn(p0, p1, p2, p3, p4); } +#undef clCreateImage +#define clCreateImage clCreateImage_fn +inline cl_mem clCreateImage(cl_context p0, cl_mem_flags p1, const cl_image_format* p2, const cl_image_desc* p3, void* p4, cl_int* p5) { return clCreateImage_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateImage2D +#define clCreateImage2D clCreateImage2D_fn +inline cl_mem clCreateImage2D(cl_context p0, cl_mem_flags p1, const cl_image_format* p2, size_t p3, size_t p4, size_t p5, void* p6, cl_int* p7) { return clCreateImage2D_pfn(p0, p1, p2, p3, p4, p5, p6, p7); } +#undef clCreateImage3D +#define clCreateImage3D clCreateImage3D_fn +inline cl_mem clCreateImage3D(cl_context p0, cl_mem_flags p1, const cl_image_format* p2, size_t p3, size_t p4, size_t p5, size_t p6, size_t p7, void* p8, cl_int* p9) { return clCreateImage3D_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } +#undef clCreateKernel +#define clCreateKernel clCreateKernel_fn +inline cl_kernel clCreateKernel(cl_program p0, const char* p1, cl_int* p2) { return clCreateKernel_pfn(p0, p1, p2); } +#undef clCreateKernelsInProgram +#define clCreateKernelsInProgram clCreateKernelsInProgram_fn +inline cl_int clCreateKernelsInProgram(cl_program p0, cl_uint p1, cl_kernel* p2, cl_uint* p3) { return clCreateKernelsInProgram_pfn(p0, p1, p2, p3); } +#undef clCreateProgramWithBinary +#define clCreateProgramWithBinary clCreateProgramWithBinary_fn +inline cl_program clCreateProgramWithBinary(cl_context p0, cl_uint p1, const cl_device_id* p2, const size_t* p3, const unsigned char** p4, cl_int* p5, cl_int* p6) { return clCreateProgramWithBinary_pfn(p0, p1, p2, p3, p4, p5, p6); } +#undef clCreateProgramWithBuiltInKernels +#define clCreateProgramWithBuiltInKernels clCreateProgramWithBuiltInKernels_fn +inline cl_program clCreateProgramWithBuiltInKernels(cl_context p0, cl_uint p1, const cl_device_id* p2, const char* p3, cl_int* p4) { return clCreateProgramWithBuiltInKernels_pfn(p0, p1, p2, p3, p4); } +#undef clCreateProgramWithSource +#define clCreateProgramWithSource clCreateProgramWithSource_fn +inline cl_program clCreateProgramWithSource(cl_context p0, cl_uint p1, const char** p2, const size_t* p3, cl_int* p4) { return clCreateProgramWithSource_pfn(p0, p1, p2, p3, p4); } +#undef clCreateSampler +#define clCreateSampler clCreateSampler_fn +inline cl_sampler clCreateSampler(cl_context p0, cl_bool p1, cl_addressing_mode p2, cl_filter_mode p3, cl_int* p4) { return clCreateSampler_pfn(p0, p1, p2, p3, p4); } +#undef clCreateSubBuffer +#define clCreateSubBuffer clCreateSubBuffer_fn +inline cl_mem clCreateSubBuffer(cl_mem p0, cl_mem_flags p1, cl_buffer_create_type p2, const void* p3, cl_int* p4) { return clCreateSubBuffer_pfn(p0, p1, p2, p3, p4); } +#undef clCreateSubDevices +#define clCreateSubDevices clCreateSubDevices_fn +inline cl_int clCreateSubDevices(cl_device_id p0, const cl_device_partition_property* p1, cl_uint p2, cl_device_id* p3, cl_uint* p4) { return clCreateSubDevices_pfn(p0, p1, p2, p3, p4); } +#undef clCreateUserEvent +#define clCreateUserEvent clCreateUserEvent_fn +inline cl_event clCreateUserEvent(cl_context p0, cl_int* p1) { return clCreateUserEvent_pfn(p0, p1); } +#undef clEnqueueBarrier +#define clEnqueueBarrier clEnqueueBarrier_fn +inline cl_int clEnqueueBarrier(cl_command_queue p0) { return clEnqueueBarrier_pfn(p0); } +#undef clEnqueueBarrierWithWaitList +#define clEnqueueBarrierWithWaitList clEnqueueBarrierWithWaitList_fn +inline cl_int clEnqueueBarrierWithWaitList(cl_command_queue p0, cl_uint p1, const cl_event* p2, cl_event* p3) { return clEnqueueBarrierWithWaitList_pfn(p0, p1, p2, p3); } +#undef clEnqueueCopyBuffer +#define clEnqueueCopyBuffer clEnqueueCopyBuffer_fn +inline cl_int clEnqueueCopyBuffer(cl_command_queue p0, cl_mem p1, cl_mem p2, size_t p3, size_t p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueCopyBufferRect +#define clEnqueueCopyBufferRect clEnqueueCopyBufferRect_fn +inline cl_int clEnqueueCopyBufferRect(cl_command_queue p0, cl_mem p1, cl_mem p2, const size_t* p3, const size_t* p4, const size_t* p5, size_t p6, size_t p7, size_t p8, size_t p9, cl_uint p10, const cl_event* p11, cl_event* p12) { return clEnqueueCopyBufferRect_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); } +#undef clEnqueueCopyBufferToImage +#define clEnqueueCopyBufferToImage clEnqueueCopyBufferToImage_fn +inline cl_int clEnqueueCopyBufferToImage(cl_command_queue p0, cl_mem p1, cl_mem p2, size_t p3, const size_t* p4, const size_t* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyBufferToImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueCopyImage +#define clEnqueueCopyImage clEnqueueCopyImage_fn +inline cl_int clEnqueueCopyImage(cl_command_queue p0, cl_mem p1, cl_mem p2, const size_t* p3, const size_t* p4, const size_t* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueCopyImageToBuffer +#define clEnqueueCopyImageToBuffer clEnqueueCopyImageToBuffer_fn +inline cl_int clEnqueueCopyImageToBuffer(cl_command_queue p0, cl_mem p1, cl_mem p2, const size_t* p3, const size_t* p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueCopyImageToBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueFillBuffer +#define clEnqueueFillBuffer clEnqueueFillBuffer_fn +inline cl_int clEnqueueFillBuffer(cl_command_queue p0, cl_mem p1, const void* p2, size_t p3, size_t p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueFillBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueFillImage +#define clEnqueueFillImage clEnqueueFillImage_fn +inline cl_int clEnqueueFillImage(cl_command_queue p0, cl_mem p1, const void* p2, const size_t* p3, const size_t* p4, cl_uint p5, const cl_event* p6, cl_event* p7) { return clEnqueueFillImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7); } +#undef clEnqueueMapBuffer +#define clEnqueueMapBuffer clEnqueueMapBuffer_fn +inline void* clEnqueueMapBuffer(cl_command_queue p0, cl_mem p1, cl_bool p2, cl_map_flags p3, size_t p4, size_t p5, cl_uint p6, const cl_event* p7, cl_event* p8, cl_int* p9) { return clEnqueueMapBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } +#undef clEnqueueMapImage +#define clEnqueueMapImage clEnqueueMapImage_fn +inline void* clEnqueueMapImage(cl_command_queue p0, cl_mem p1, cl_bool p2, cl_map_flags p3, const size_t* p4, const size_t* p5, size_t* p6, size_t* p7, cl_uint p8, const cl_event* p9, cl_event* p10, cl_int* p11) { return clEnqueueMapImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); } +#undef clEnqueueMarker +#define clEnqueueMarker clEnqueueMarker_fn +inline cl_int clEnqueueMarker(cl_command_queue p0, cl_event* p1) { return clEnqueueMarker_pfn(p0, p1); } +#undef clEnqueueMarkerWithWaitList +#define clEnqueueMarkerWithWaitList clEnqueueMarkerWithWaitList_fn +inline cl_int clEnqueueMarkerWithWaitList(cl_command_queue p0, cl_uint p1, const cl_event* p2, cl_event* p3) { return clEnqueueMarkerWithWaitList_pfn(p0, p1, p2, p3); } +#undef clEnqueueMigrateMemObjects +#define clEnqueueMigrateMemObjects clEnqueueMigrateMemObjects_fn +inline cl_int clEnqueueMigrateMemObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_mem_migration_flags p3, cl_uint p4, const cl_event* p5, cl_event* p6) { return clEnqueueMigrateMemObjects_pfn(p0, p1, p2, p3, p4, p5, p6); } +#undef clEnqueueNDRangeKernel +#define clEnqueueNDRangeKernel clEnqueueNDRangeKernel_fn +inline cl_int clEnqueueNDRangeKernel(cl_command_queue p0, cl_kernel p1, cl_uint p2, const size_t* p3, const size_t* p4, const size_t* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueNDRangeKernel_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueNativeKernel +#define clEnqueueNativeKernel clEnqueueNativeKernel_fn +inline cl_int clEnqueueNativeKernel(cl_command_queue p0, void (CL_CALLBACK*p1) (void*), void* p2, size_t p3, cl_uint p4, const cl_mem* p5, const void** p6, cl_uint p7, const cl_event* p8, cl_event* p9) { return clEnqueueNativeKernel_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); } +#undef clEnqueueReadBuffer +#define clEnqueueReadBuffer clEnqueueReadBuffer_fn +inline cl_int clEnqueueReadBuffer(cl_command_queue p0, cl_mem p1, cl_bool p2, size_t p3, size_t p4, void* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueReadBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueReadBufferRect +#define clEnqueueReadBufferRect clEnqueueReadBufferRect_fn +inline cl_int clEnqueueReadBufferRect(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, const size_t* p5, size_t p6, size_t p7, size_t p8, size_t p9, void* p10, cl_uint p11, const cl_event* p12, cl_event* p13) { return clEnqueueReadBufferRect_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); } +#undef clEnqueueReadImage +#define clEnqueueReadImage clEnqueueReadImage_fn +inline cl_int clEnqueueReadImage(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, size_t p5, size_t p6, void* p7, cl_uint p8, const cl_event* p9, cl_event* p10) { return clEnqueueReadImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } +#undef clEnqueueTask +#define clEnqueueTask clEnqueueTask_fn +inline cl_int clEnqueueTask(cl_command_queue p0, cl_kernel p1, cl_uint p2, const cl_event* p3, cl_event* p4) { return clEnqueueTask_pfn(p0, p1, p2, p3, p4); } +#undef clEnqueueUnmapMemObject +#define clEnqueueUnmapMemObject clEnqueueUnmapMemObject_fn +inline cl_int clEnqueueUnmapMemObject(cl_command_queue p0, cl_mem p1, void* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueUnmapMemObject_pfn(p0, p1, p2, p3, p4, p5); } +#undef clEnqueueWaitForEvents +#define clEnqueueWaitForEvents clEnqueueWaitForEvents_fn +inline cl_int clEnqueueWaitForEvents(cl_command_queue p0, cl_uint p1, const cl_event* p2) { return clEnqueueWaitForEvents_pfn(p0, p1, p2); } +#undef clEnqueueWriteBuffer +#define clEnqueueWriteBuffer clEnqueueWriteBuffer_fn +inline cl_int clEnqueueWriteBuffer(cl_command_queue p0, cl_mem p1, cl_bool p2, size_t p3, size_t p4, const void* p5, cl_uint p6, const cl_event* p7, cl_event* p8) { return clEnqueueWriteBuffer_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clEnqueueWriteBufferRect +#define clEnqueueWriteBufferRect clEnqueueWriteBufferRect_fn +inline cl_int clEnqueueWriteBufferRect(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, const size_t* p5, size_t p6, size_t p7, size_t p8, size_t p9, const void* p10, cl_uint p11, const cl_event* p12, cl_event* p13) { return clEnqueueWriteBufferRect_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); } +#undef clEnqueueWriteImage +#define clEnqueueWriteImage clEnqueueWriteImage_fn +inline cl_int clEnqueueWriteImage(cl_command_queue p0, cl_mem p1, cl_bool p2, const size_t* p3, const size_t* p4, size_t p5, size_t p6, const void* p7, cl_uint p8, const cl_event* p9, cl_event* p10) { return clEnqueueWriteImage_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); } +#undef clFinish +#define clFinish clFinish_fn +inline cl_int clFinish(cl_command_queue p0) { return clFinish_pfn(p0); } +#undef clFlush +#define clFlush clFlush_fn +inline cl_int clFlush(cl_command_queue p0) { return clFlush_pfn(p0); } +#undef clGetCommandQueueInfo +#define clGetCommandQueueInfo clGetCommandQueueInfo_fn +inline cl_int clGetCommandQueueInfo(cl_command_queue p0, cl_command_queue_info p1, size_t p2, void* p3, size_t* p4) { return clGetCommandQueueInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetContextInfo +#define clGetContextInfo clGetContextInfo_fn +inline cl_int clGetContextInfo(cl_context p0, cl_context_info p1, size_t p2, void* p3, size_t* p4) { return clGetContextInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetDeviceIDs +#define clGetDeviceIDs clGetDeviceIDs_fn +inline cl_int clGetDeviceIDs(cl_platform_id p0, cl_device_type p1, cl_uint p2, cl_device_id* p3, cl_uint* p4) { return clGetDeviceIDs_pfn(p0, p1, p2, p3, p4); } +#undef clGetDeviceInfo +#define clGetDeviceInfo clGetDeviceInfo_fn +inline cl_int clGetDeviceInfo(cl_device_id p0, cl_device_info p1, size_t p2, void* p3, size_t* p4) { return clGetDeviceInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetEventInfo +#define clGetEventInfo clGetEventInfo_fn +inline cl_int clGetEventInfo(cl_event p0, cl_event_info p1, size_t p2, void* p3, size_t* p4) { return clGetEventInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetEventProfilingInfo +#define clGetEventProfilingInfo clGetEventProfilingInfo_fn +inline cl_int clGetEventProfilingInfo(cl_event p0, cl_profiling_info p1, size_t p2, void* p3, size_t* p4) { return clGetEventProfilingInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetExtensionFunctionAddress +#define clGetExtensionFunctionAddress clGetExtensionFunctionAddress_fn +inline void* clGetExtensionFunctionAddress(const char* p0) { return clGetExtensionFunctionAddress_pfn(p0); } +#undef clGetExtensionFunctionAddressForPlatform +#define clGetExtensionFunctionAddressForPlatform clGetExtensionFunctionAddressForPlatform_fn +inline void* clGetExtensionFunctionAddressForPlatform(cl_platform_id p0, const char* p1) { return clGetExtensionFunctionAddressForPlatform_pfn(p0, p1); } +#undef clGetImageInfo +#define clGetImageInfo clGetImageInfo_fn +inline cl_int clGetImageInfo(cl_mem p0, cl_image_info p1, size_t p2, void* p3, size_t* p4) { return clGetImageInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetKernelArgInfo +#define clGetKernelArgInfo clGetKernelArgInfo_fn +inline cl_int clGetKernelArgInfo(cl_kernel p0, cl_uint p1, cl_kernel_arg_info p2, size_t p3, void* p4, size_t* p5) { return clGetKernelArgInfo_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetKernelInfo +#define clGetKernelInfo clGetKernelInfo_fn +inline cl_int clGetKernelInfo(cl_kernel p0, cl_kernel_info p1, size_t p2, void* p3, size_t* p4) { return clGetKernelInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetKernelWorkGroupInfo +#define clGetKernelWorkGroupInfo clGetKernelWorkGroupInfo_fn +inline cl_int clGetKernelWorkGroupInfo(cl_kernel p0, cl_device_id p1, cl_kernel_work_group_info p2, size_t p3, void* p4, size_t* p5) { return clGetKernelWorkGroupInfo_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetMemObjectInfo +#define clGetMemObjectInfo clGetMemObjectInfo_fn +inline cl_int clGetMemObjectInfo(cl_mem p0, cl_mem_info p1, size_t p2, void* p3, size_t* p4) { return clGetMemObjectInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetPlatformIDs +#define clGetPlatformIDs clGetPlatformIDs_fn +inline cl_int clGetPlatformIDs(cl_uint p0, cl_platform_id* p1, cl_uint* p2) { return clGetPlatformIDs_pfn(p0, p1, p2); } +#undef clGetPlatformInfo +#define clGetPlatformInfo clGetPlatformInfo_fn +inline cl_int clGetPlatformInfo(cl_platform_id p0, cl_platform_info p1, size_t p2, void* p3, size_t* p4) { return clGetPlatformInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetProgramBuildInfo +#define clGetProgramBuildInfo clGetProgramBuildInfo_fn +inline cl_int clGetProgramBuildInfo(cl_program p0, cl_device_id p1, cl_program_build_info p2, size_t p3, void* p4, size_t* p5) { return clGetProgramBuildInfo_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetProgramInfo +#define clGetProgramInfo clGetProgramInfo_fn +inline cl_int clGetProgramInfo(cl_program p0, cl_program_info p1, size_t p2, void* p3, size_t* p4) { return clGetProgramInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetSamplerInfo +#define clGetSamplerInfo clGetSamplerInfo_fn +inline cl_int clGetSamplerInfo(cl_sampler p0, cl_sampler_info p1, size_t p2, void* p3, size_t* p4) { return clGetSamplerInfo_pfn(p0, p1, p2, p3, p4); } +#undef clGetSupportedImageFormats +#define clGetSupportedImageFormats clGetSupportedImageFormats_fn +inline cl_int clGetSupportedImageFormats(cl_context p0, cl_mem_flags p1, cl_mem_object_type p2, cl_uint p3, cl_image_format* p4, cl_uint* p5) { return clGetSupportedImageFormats_pfn(p0, p1, p2, p3, p4, p5); } +#undef clLinkProgram +#define clLinkProgram clLinkProgram_fn +inline cl_program clLinkProgram(cl_context p0, cl_uint p1, const cl_device_id* p2, const char* p3, cl_uint p4, const cl_program* p5, void (CL_CALLBACK*p6) (cl_program, void*), void* p7, cl_int* p8) { return clLinkProgram_pfn(p0, p1, p2, p3, p4, p5, p6, p7, p8); } +#undef clReleaseCommandQueue +#define clReleaseCommandQueue clReleaseCommandQueue_fn +inline cl_int clReleaseCommandQueue(cl_command_queue p0) { return clReleaseCommandQueue_pfn(p0); } +#undef clReleaseContext +#define clReleaseContext clReleaseContext_fn +inline cl_int clReleaseContext(cl_context p0) { return clReleaseContext_pfn(p0); } +#undef clReleaseDevice +#define clReleaseDevice clReleaseDevice_fn +inline cl_int clReleaseDevice(cl_device_id p0) { return clReleaseDevice_pfn(p0); } +#undef clReleaseEvent +#define clReleaseEvent clReleaseEvent_fn +inline cl_int clReleaseEvent(cl_event p0) { return clReleaseEvent_pfn(p0); } +#undef clReleaseKernel +#define clReleaseKernel clReleaseKernel_fn +inline cl_int clReleaseKernel(cl_kernel p0) { return clReleaseKernel_pfn(p0); } +#undef clReleaseMemObject +#define clReleaseMemObject clReleaseMemObject_fn +inline cl_int clReleaseMemObject(cl_mem p0) { return clReleaseMemObject_pfn(p0); } +#undef clReleaseProgram +#define clReleaseProgram clReleaseProgram_fn +inline cl_int clReleaseProgram(cl_program p0) { return clReleaseProgram_pfn(p0); } +#undef clReleaseSampler +#define clReleaseSampler clReleaseSampler_fn +inline cl_int clReleaseSampler(cl_sampler p0) { return clReleaseSampler_pfn(p0); } +#undef clRetainCommandQueue +#define clRetainCommandQueue clRetainCommandQueue_fn +inline cl_int clRetainCommandQueue(cl_command_queue p0) { return clRetainCommandQueue_pfn(p0); } +#undef clRetainContext +#define clRetainContext clRetainContext_fn +inline cl_int clRetainContext(cl_context p0) { return clRetainContext_pfn(p0); } +#undef clRetainDevice +#define clRetainDevice clRetainDevice_fn +inline cl_int clRetainDevice(cl_device_id p0) { return clRetainDevice_pfn(p0); } +#undef clRetainEvent +#define clRetainEvent clRetainEvent_fn +inline cl_int clRetainEvent(cl_event p0) { return clRetainEvent_pfn(p0); } +#undef clRetainKernel +#define clRetainKernel clRetainKernel_fn +inline cl_int clRetainKernel(cl_kernel p0) { return clRetainKernel_pfn(p0); } +#undef clRetainMemObject +#define clRetainMemObject clRetainMemObject_fn +inline cl_int clRetainMemObject(cl_mem p0) { return clRetainMemObject_pfn(p0); } +#undef clRetainProgram +#define clRetainProgram clRetainProgram_fn +inline cl_int clRetainProgram(cl_program p0) { return clRetainProgram_pfn(p0); } +#undef clRetainSampler +#define clRetainSampler clRetainSampler_fn +inline cl_int clRetainSampler(cl_sampler p0) { return clRetainSampler_pfn(p0); } +#undef clSetEventCallback +#define clSetEventCallback clSetEventCallback_fn +inline cl_int clSetEventCallback(cl_event p0, cl_int p1, void (CL_CALLBACK*p2) (cl_event, cl_int, void*), void* p3) { return clSetEventCallback_pfn(p0, p1, p2, p3); } +#undef clSetKernelArg +#define clSetKernelArg clSetKernelArg_fn +inline cl_int clSetKernelArg(cl_kernel p0, cl_uint p1, size_t p2, const void* p3) { return clSetKernelArg_pfn(p0, p1, p2, p3); } +#undef clSetMemObjectDestructorCallback +#define clSetMemObjectDestructorCallback clSetMemObjectDestructorCallback_fn +inline cl_int clSetMemObjectDestructorCallback(cl_mem p0, void (CL_CALLBACK*p1) (cl_mem, void*), void* p2) { return clSetMemObjectDestructorCallback_pfn(p0, p1, p2); } +#undef clSetUserEventStatus +#define clSetUserEventStatus clSetUserEventStatus_fn +inline cl_int clSetUserEventStatus(cl_event p0, cl_int p1) { return clSetUserEventStatus_pfn(p0, p1); } +#undef clUnloadCompiler +#define clUnloadCompiler clUnloadCompiler_fn +inline cl_int clUnloadCompiler() { return clUnloadCompiler_pfn(); } +#undef clUnloadPlatformCompiler +#define clUnloadPlatformCompiler clUnloadPlatformCompiler_fn +inline cl_int clUnloadPlatformCompiler(cl_platform_id p0) { return clUnloadPlatformCompiler_pfn(p0); } +#undef clWaitForEvents +#define clWaitForEvents clWaitForEvents_fn +inline cl_int clWaitForEvents(cl_uint p0, const cl_event* p1) { return clWaitForEvents_pfn(p0, p1); } diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0b12aed6c6ce9def83b9fecc15f8be14b4790363 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp @@ -0,0 +1,62 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP +#error "Invalid usage" +#endif + +// generated by parser_cl.py +#define clCreateFromGLBuffer clCreateFromGLBuffer_ +#define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_ +#define clCreateFromGLTexture clCreateFromGLTexture_ +#define clCreateFromGLTexture2D clCreateFromGLTexture2D_ +#define clCreateFromGLTexture3D clCreateFromGLTexture3D_ +#define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_ +#define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_ +#define clGetGLContextInfoKHR clGetGLContextInfoKHR_ +#define clGetGLObjectInfo clGetGLObjectInfo_ +#define clGetGLTextureInfo clGetGLTextureInfo_ + +#if defined __APPLE__ +#include +#else +#include +#endif + +// generated by parser_cl.py +#undef clCreateFromGLBuffer +#define clCreateFromGLBuffer clCreateFromGLBuffer_pfn +#undef clCreateFromGLRenderbuffer +#define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_pfn +#undef clCreateFromGLTexture +#define clCreateFromGLTexture clCreateFromGLTexture_pfn +#undef clCreateFromGLTexture2D +#define clCreateFromGLTexture2D clCreateFromGLTexture2D_pfn +#undef clCreateFromGLTexture3D +#define clCreateFromGLTexture3D clCreateFromGLTexture3D_pfn +#undef clEnqueueAcquireGLObjects +#define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_pfn +#undef clEnqueueReleaseGLObjects +#define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_pfn +#undef clGetGLContextInfoKHR +#define clGetGLContextInfoKHR clGetGLContextInfoKHR_pfn +#undef clGetGLObjectInfo +#define clGetGLObjectInfo clGetGLObjectInfo_pfn +#undef clGetGLTextureInfo +#define clGetGLTextureInfo clGetGLTextureInfo_pfn + +#ifdef cl_khr_gl_sharing + +// generated by parser_cl.py +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLRenderbuffer)(cl_context, cl_mem_flags, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture2D)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture3D)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueAcquireGLObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReleaseGLObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_uint, const cl_event*, cl_event*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLContextInfoKHR)(const cl_context_properties*, cl_gl_context_info, size_t, void*, size_t*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLObjectInfo)(cl_mem, cl_gl_object_type*, cl_GLuint*); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLTextureInfo)(cl_mem, cl_gl_texture_info, size_t, void*, size_t*); + +#endif // cl_khr_gl_sharing diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp new file mode 100644 index 0000000000000000000000000000000000000000..12f342b2e4be18b0bfb3a9fb661d47fdf8bac44c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp @@ -0,0 +1,42 @@ +// +// AUTOGENERATED, DO NOT EDIT +// +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP +#error "Invalid usage" +#endif + +#ifdef cl_khr_gl_sharing + +// generated by parser_cl.py +#undef clCreateFromGLBuffer +#define clCreateFromGLBuffer clCreateFromGLBuffer_fn +inline cl_mem clCreateFromGLBuffer(cl_context p0, cl_mem_flags p1, cl_GLuint p2, int* p3) { return clCreateFromGLBuffer_pfn(p0, p1, p2, p3); } +#undef clCreateFromGLRenderbuffer +#define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_fn +inline cl_mem clCreateFromGLRenderbuffer(cl_context p0, cl_mem_flags p1, cl_GLuint p2, cl_int* p3) { return clCreateFromGLRenderbuffer_pfn(p0, p1, p2, p3); } +#undef clCreateFromGLTexture +#define clCreateFromGLTexture clCreateFromGLTexture_fn +inline cl_mem clCreateFromGLTexture(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateFromGLTexture2D +#define clCreateFromGLTexture2D clCreateFromGLTexture2D_fn +inline cl_mem clCreateFromGLTexture2D(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture2D_pfn(p0, p1, p2, p3, p4, p5); } +#undef clCreateFromGLTexture3D +#define clCreateFromGLTexture3D clCreateFromGLTexture3D_fn +inline cl_mem clCreateFromGLTexture3D(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture3D_pfn(p0, p1, p2, p3, p4, p5); } +#undef clEnqueueAcquireGLObjects +#define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_fn +inline cl_int clEnqueueAcquireGLObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueAcquireGLObjects_pfn(p0, p1, p2, p3, p4, p5); } +#undef clEnqueueReleaseGLObjects +#define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_fn +inline cl_int clEnqueueReleaseGLObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueReleaseGLObjects_pfn(p0, p1, p2, p3, p4, p5); } +#undef clGetGLContextInfoKHR +#define clGetGLContextInfoKHR clGetGLContextInfoKHR_fn +inline cl_int clGetGLContextInfoKHR(const cl_context_properties* p0, cl_gl_context_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLContextInfoKHR_pfn(p0, p1, p2, p3, p4); } +#undef clGetGLObjectInfo +#define clGetGLObjectInfo clGetGLObjectInfo_fn +inline cl_int clGetGLObjectInfo(cl_mem p0, cl_gl_object_type* p1, cl_GLuint* p2) { return clGetGLObjectInfo_pfn(p0, p1, p2); } +#undef clGetGLTextureInfo +#define clGetGLTextureInfo clGetGLTextureInfo_fn +inline cl_int clGetGLTextureInfo(cl_mem p0, cl_gl_texture_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLTextureInfo_pfn(p0, p1, p2, p3, p4); } + +#endif // cl_khr_gl_sharing diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdblas.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdblas.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2ad8ac0b5db8bdd0587f60dd3ed3d2ecd28e7048 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdblas.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP +#define OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP + +#ifdef HAVE_CLAMDBLAS + +#include "opencl_core.hpp" + +#include "autogenerated/opencl_clamdblas.hpp" + +#endif // HAVE_CLAMDBLAS + +#endif // OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdfft.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdfft.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a328f722fccacd8e7491abfd464b8b7c43b51074 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_clamdfft.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP +#define OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP + +#ifdef HAVE_CLAMDFFT + +#include "opencl_core.hpp" + +#include "autogenerated/opencl_clamdfft.hpp" + +#endif // HAVE_CLAMDFFT + +#endif // OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0404b3177a58f51a4137d92803198a17f8ca3ab4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_core.hpp @@ -0,0 +1,84 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP + +#ifdef HAVE_OPENCL + +#ifndef CL_RUNTIME_EXPORT +#if (defined(BUILD_SHARED_LIBS) || defined(OPENCV_CORE_SHARED)) && (defined _WIN32 || defined WINCE) && \ + !(defined(__OPENCV_BUILD) && defined(OPENCV_MODULE_IS_PART_OF_WORLD)) +#define CL_RUNTIME_EXPORT __declspec(dllimport) +#else +#define CL_RUNTIME_EXPORT +#endif +#endif + +#ifdef HAVE_OPENCL_SVM +#define clSVMAlloc clSVMAlloc_ +#define clSVMFree clSVMFree_ +#define clSetKernelArgSVMPointer clSetKernelArgSVMPointer_ +#define clSetKernelExecInfo clSetKernelExecInfo_ +#define clEnqueueSVMFree clEnqueueSVMFree_ +#define clEnqueueSVMMemcpy clEnqueueSVMMemcpy_ +#define clEnqueueSVMMemFill clEnqueueSVMMemFill_ +#define clEnqueueSVMMap clEnqueueSVMMap_ +#define clEnqueueSVMUnmap clEnqueueSVMUnmap_ +#endif + +#include "autogenerated/opencl_core.hpp" + +#ifndef CL_DEVICE_DOUBLE_FP_CONFIG +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#endif + +#ifndef CL_DEVICE_HALF_FP_CONFIG +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 +#endif + +#ifndef CL_VERSION_1_2 +#define CV_REQUIRE_OPENCL_1_2_ERROR CV_Error(cv::Error::OpenCLApiCallError, "OpenCV compiled without OpenCL v1.2 support, so we can't use functionality from OpenCL v1.2") +#endif + +#endif // HAVE_OPENCL + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp new file mode 100644 index 0000000000000000000000000000000000000000..38fcae9952f2838d15f7dbf79549aa9cd30bbe26 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP + +#include "autogenerated/opencl_core_wrappers.hpp" + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_gl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_gl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..659c7d80581489d95c91c5ce844bc574b8c81598 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_gl.hpp @@ -0,0 +1,53 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP + +#if defined HAVE_OPENCL && defined HAVE_OPENGL + +#include "opencl_core.hpp" + +#include "autogenerated/opencl_gl.hpp" + +#endif // defined HAVE_OPENCL && defined HAVE_OPENGL + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9700004cae5ac6e11b76652ce8c78d4430e05688 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP + +#include "autogenerated/opencl_gl_wrappers.hpp" + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_20.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_20.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9636b19b027fcc5ec2ff78c94f28b46919425fda --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_20.hpp @@ -0,0 +1,48 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP + +#if defined(HAVE_OPENCL_SVM) +#include "opencl_core.hpp" + +#include "opencl_svm_definitions.hpp" + +#undef clSVMAlloc +#define clSVMAlloc clSVMAlloc_pfn +#undef clSVMFree +#define clSVMFree clSVMFree_pfn +#undef clSetKernelArgSVMPointer +#define clSetKernelArgSVMPointer clSetKernelArgSVMPointer_pfn +#undef clSetKernelExecInfo +//#define clSetKernelExecInfo clSetKernelExecInfo_pfn +#undef clEnqueueSVMFree +//#define clEnqueueSVMFree clEnqueueSVMFree_pfn +#undef clEnqueueSVMMemcpy +#define clEnqueueSVMMemcpy clEnqueueSVMMemcpy_pfn +#undef clEnqueueSVMMemFill +#define clEnqueueSVMMemFill clEnqueueSVMMemFill_pfn +#undef clEnqueueSVMMap +#define clEnqueueSVMMap clEnqueueSVMMap_pfn +#undef clEnqueueSVMUnmap +#define clEnqueueSVMUnmap clEnqueueSVMUnmap_pfn + +extern CL_RUNTIME_EXPORT void* (CL_API_CALL *clSVMAlloc)(cl_context context, cl_svm_mem_flags flags, size_t size, unsigned int alignment); +extern CL_RUNTIME_EXPORT void (CL_API_CALL *clSVMFree)(cl_context context, void* svm_pointer); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clSetKernelArgSVMPointer)(cl_kernel kernel, cl_uint arg_index, const void* arg_value); +//extern CL_RUNTIME_EXPORT void* (CL_API_CALL *clSetKernelExecInfo)(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void* param_value); +//extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMFree)(cl_command_queue command_queue, cl_uint num_svm_pointers, void* svm_pointers[], +// void (CL_CALLBACK *pfn_free_func)(cl_command_queue queue, cl_uint num_svm_pointers, void* svm_pointers[], void* user_data), void* user_data, +// cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMemcpy)(cl_command_queue command_queue, cl_bool blocking_copy, void* dst_ptr, const void* src_ptr, size_t size, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMemFill)(cl_command_queue command_queue, void* svm_ptr, const void* pattern, size_t pattern_size, size_t size, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMap)(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags map_flags, void* svm_ptr, size_t size, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); +extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMUnmap)(cl_command_queue command_queue, void* svm_ptr, + cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); + +#endif // HAVE_OPENCL_SVM + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp new file mode 100644 index 0000000000000000000000000000000000000000..97c927b44d8cc6310623ad4156ff2aae7b7c193c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp @@ -0,0 +1,42 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP + +#if defined(HAVE_OPENCL_SVM) +#if defined(CL_VERSION_2_0) + +// OpenCL 2.0 contains SVM definitions + +#else + +typedef cl_bitfield cl_device_svm_capabilities; +typedef cl_bitfield cl_svm_mem_flags; +typedef cl_uint cl_kernel_exec_info; + +// +// TODO Add real values after OpenCL 2.0 release +// + +#ifndef CL_DEVICE_SVM_CAPABILITIES +#define CL_DEVICE_SVM_CAPABILITIES 0x1053 + +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) +#define CL_DEVICE_SVM_ATOMICS (1 << 3) +#endif + +#ifndef CL_MEM_SVM_FINE_GRAIN_BUFFER +#define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) +#endif + +#ifndef CL_MEM_SVM_ATOMICS +#define CL_MEM_SVM_ATOMICS (1 << 11) +#endif + + +#endif // CL_VERSION_2_0 +#endif // HAVE_OPENCL_SVM + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp new file mode 100644 index 0000000000000000000000000000000000000000..497bc3de7205d6bad28328772c3b20f48611d63c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp @@ -0,0 +1,166 @@ +/* See LICENSE file in the root OpenCV directory */ + +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_HSA_EXTENSION_HPP +#define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_HSA_EXTENSION_HPP + +#if defined(HAVE_OPENCL_SVM) +#include "opencl_core.hpp" + +#ifndef CL_DEVICE_SVM_CAPABILITIES_AMD +// +// Part of the file is an extract from the cl_ext.h file from AMD APP SDK package. +// Below is the original copyright. +// +/******************************************************************************* + * Copyright (c) 2008-2013 The Khronos Group Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and/or associated documentation files (the + * "Materials"), to deal in the Materials without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Materials, and to + * permit persons to whom the Materials are furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Materials. + * + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + ******************************************************************************/ + +/******************************************* + * Shared Virtual Memory (SVM) extension + *******************************************/ +typedef cl_bitfield cl_device_svm_capabilities_amd; +typedef cl_bitfield cl_svm_mem_flags_amd; +typedef cl_uint cl_kernel_exec_info_amd; + +/* cl_device_info */ +#define CL_DEVICE_SVM_CAPABILITIES_AMD 0x1053 +#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT_AMD 0x1054 + +/* cl_device_svm_capabilities_amd */ +#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER_AMD (1 << 0) +#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER_AMD (1 << 1) +#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM_AMD (1 << 2) +#define CL_DEVICE_SVM_ATOMICS_AMD (1 << 3) + +/* cl_svm_mem_flags_amd */ +#define CL_MEM_SVM_FINE_GRAIN_BUFFER_AMD (1 << 10) +#define CL_MEM_SVM_ATOMICS_AMD (1 << 11) + +/* cl_mem_info */ +#define CL_MEM_USES_SVM_POINTER_AMD 0x1109 + +/* cl_kernel_exec_info_amd */ +#define CL_KERNEL_EXEC_INFO_SVM_PTRS_AMD 0x11B6 +#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM_AMD 0x11B7 + +/* cl_command_type */ +#define CL_COMMAND_SVM_FREE_AMD 0x1209 +#define CL_COMMAND_SVM_MEMCPY_AMD 0x120A +#define CL_COMMAND_SVM_MEMFILL_AMD 0x120B +#define CL_COMMAND_SVM_MAP_AMD 0x120C +#define CL_COMMAND_SVM_UNMAP_AMD 0x120D + +typedef CL_API_ENTRY void* +(CL_API_CALL * clSVMAllocAMD_fn)( + cl_context /* context */, + cl_svm_mem_flags_amd /* flags */, + size_t /* size */, + unsigned int /* alignment */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY void +(CL_API_CALL * clSVMFreeAMD_fn)( + cl_context /* context */, + void* /* svm_pointer */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMFreeAMD_fn)( + cl_command_queue /* command_queue */, + cl_uint /* num_svm_pointers */, + void** /* svm_pointers */, + void (CL_CALLBACK *)( /*pfn_free_func*/ + cl_command_queue /* queue */, + cl_uint /* num_svm_pointers */, + void** /* svm_pointers */, + void* /* user_data */), + void* /* user_data */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMMemcpyAMD_fn)( + cl_command_queue /* command_queue */, + cl_bool /* blocking_copy */, + void* /* dst_ptr */, + const void* /* src_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMMemFillAMD_fn)( + cl_command_queue /* command_queue */, + void* /* svm_ptr */, + const void* /* pattern */, + size_t /* pattern_size */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMMapAMD_fn)( + cl_command_queue /* command_queue */, + cl_bool /* blocking_map */, + cl_map_flags /* map_flags */, + void* /* svm_ptr */, + size_t /* size */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clEnqueueSVMUnmapAMD_fn)( + cl_command_queue /* command_queue */, + void* /* svm_ptr */, + cl_uint /* num_events_in_wait_list */, + const cl_event* /* event_wait_list */, + cl_event* /* event */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clSetKernelArgSVMPointerAMD_fn)( + cl_kernel /* kernel */, + cl_uint /* arg_index */, + const void * /* arg_value */ +) CL_EXT_SUFFIX__VERSION_1_2; + +typedef CL_API_ENTRY cl_int +(CL_API_CALL * clSetKernelExecInfoAMD_fn)( + cl_kernel /* kernel */, + cl_kernel_exec_info_amd /* param_name */, + size_t /* param_value_size */, + const void * /* param_value */ +) CL_EXT_SUFFIX__VERSION_1_2; + +#endif + +#endif // HAVE_OPENCL_SVM + +#endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_HSA_EXTENSION_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opengl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opengl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a311ce25256646fe65b41ad2a31f64e3df98218c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/opengl.hpp @@ -0,0 +1,725 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OPENGL_HPP +#define OPENCV_CORE_OPENGL_HPP + +#ifndef __cplusplus +# error opengl.hpp header must be compiled as C++ +#endif + +#include "opencv2/core.hpp" +#include "ocl.hpp" + +namespace cv { namespace ogl { + +/** @addtogroup core_opengl +This section describes OpenGL interoperability. + +To enable OpenGL support, configure OpenCV using CMake with WITH_OPENGL=ON . Currently OpenGL is +supported only with WIN32, GTK and Qt backends on Windows and Linux (MacOS and Android are not +supported). For GTK backend gtkglext-1.0 library is required. + +To use OpenGL functionality you should first create OpenGL context (window or frame buffer). You can +do this with namedWindow function or with other OpenGL toolkit (GLUT, for example). +*/ +//! @{ + +/////////////////// OpenGL Objects /////////////////// + +/** @brief Smart pointer for OpenGL buffer object with reference counting. + +Buffer Objects are OpenGL objects that store an array of unformatted memory allocated by the OpenGL +context. These can be used to store vertex data, pixel data retrieved from images or the +framebuffer, and a variety of other things. + +ogl::Buffer has interface similar with Mat interface and represents 2D array memory. + +ogl::Buffer supports memory transfers between host and device and also can be mapped to CUDA memory. + */ +class CV_EXPORTS Buffer +{ +public: + /** @brief The target defines how you intend to use the buffer object. + */ + enum Target + { + ARRAY_BUFFER = 0x8892, //!< The buffer will be used as a source for vertex data + ELEMENT_ARRAY_BUFFER = 0x8893, //!< The buffer will be used for indices (in glDrawElements, for example) + PIXEL_PACK_BUFFER = 0x88EB, //!< The buffer will be used for reading from OpenGL textures + PIXEL_UNPACK_BUFFER = 0x88EC //!< The buffer will be used for writing to OpenGL textures + }; + + enum Access + { + READ_ONLY = 0x88B8, + WRITE_ONLY = 0x88B9, + READ_WRITE = 0x88BA + }; + + /** @brief The constructors. + + Creates empty ogl::Buffer object, creates ogl::Buffer object from existed buffer ( abufId + parameter), allocates memory for ogl::Buffer object or copies from host/device memory. + */ + Buffer(); + + /** @overload + @param arows Number of rows in a 2D array. + @param acols Number of columns in a 2D array. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param abufId Buffer object name. + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param abufId Buffer object name. + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false); + + /** @overload + @param arows Number of rows in a 2D array. + @param acols Number of columns in a 2D array. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Buffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ). + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + explicit Buffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @brief Allocates memory for ogl::Buffer object. + + @param arows Number of rows in a 2D array. + @param acols Number of columns in a 2D array. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details. + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @brief Decrements the reference counter and destroys the buffer object if needed. + + The function will call setAutoRelease(true) . + */ + void release(); + + /** @brief Sets auto release mode. + + The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was + bound to a window it could be released at any time (user can close a window). If object's destructor + is called after destruction of the context it will cause an error. Thus ogl::Buffer doesn't destroy + OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL context). + This function can force ogl::Buffer destructor to destroy OpenGL object. + @param flag Auto release mode (if true, release will be called in object's destructor). + */ + void setAutoRelease(bool flag); + + /** @brief Copies from host/device memory to OpenGL buffer. + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ). + @param target Buffer usage. See cv::ogl::Buffer::Target . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @overload */ + void copyFrom(InputArray arr, cuda::Stream& stream, Target target = ARRAY_BUFFER, bool autoRelease = false); + + /** @brief Copies from OpenGL buffer to host/device memory or another OpenGL buffer object. + + @param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , std::vector or + ogl::Buffer ). + */ + void copyTo(OutputArray arr) const; + + /** @overload */ + void copyTo(OutputArray arr, cuda::Stream& stream) const; + + /** @brief Creates a full copy of the buffer object and the underlying data. + + @param target Buffer usage for destination buffer. + @param autoRelease Auto release mode for destination buffer. + */ + Buffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const; + + /** @brief Binds OpenGL buffer to the specified buffer binding point. + + @param target Binding point. See cv::ogl::Buffer::Target . + */ + void bind(Target target) const; + + /** @brief Unbind any buffers from the specified binding point. + + @param target Binding point. See cv::ogl::Buffer::Target . + */ + static void unbind(Target target); + + /** @brief Maps OpenGL buffer to host memory. + + mapHost maps to the client's address space the entire data store of the buffer object. The data can + then be directly read and/or written relative to the returned pointer, depending on the specified + access policy. + + A mapped data store must be unmapped with ogl::Buffer::unmapHost before its buffer object is used. + + This operation can lead to memory transfers between host and device. + + Only one buffer object can be mapped at a time. + @param access Access policy, indicating whether it will be possible to read from, write to, or both + read from and write to the buffer object's mapped data store. The symbolic constant must be + ogl::Buffer::READ_ONLY , ogl::Buffer::WRITE_ONLY or ogl::Buffer::READ_WRITE . + */ + Mat mapHost(Access access); + + /** @brief Unmaps OpenGL buffer. + */ + void unmapHost(); + + //! map to device memory (blocking) + cuda::GpuMat mapDevice(); + void unmapDevice(); + + /** @brief Maps OpenGL buffer to CUDA device memory. + + This operation doesn't copy data. Several buffer objects can be mapped to CUDA memory at a time. + + A mapped data store must be unmapped with ogl::Buffer::unmapDevice before its buffer object is used. + */ + cuda::GpuMat mapDevice(cuda::Stream& stream); + + /** @brief Unmaps OpenGL buffer. + */ + void unmapDevice(cuda::Stream& stream); + + int rows() const; + int cols() const; + Size size() const; + bool empty() const; + + int type() const; + int depth() const; + int channels() const; + int elemSize() const; + int elemSize1() const; + + //! get OpenGL opject id + unsigned int bufId() const; + + class Impl; + +private: + Ptr impl_; + int rows_; + int cols_; + int type_; +}; + +/** @brief Smart pointer for OpenGL 2D texture memory with reference counting. + */ +class CV_EXPORTS Texture2D +{ +public: + /** @brief An Image Format describes the way that the images in Textures store their data. + */ + enum Format + { + NONE = 0, + DEPTH_COMPONENT = 0x1902, //!< Depth + RGB = 0x1907, //!< Red, Green, Blue + RGBA = 0x1908 //!< Red, Green, Blue, Alpha + }; + + /** @brief The constructors. + + Creates empty ogl::Texture2D object, allocates memory for ogl::Texture2D object or copies from + host/device memory. + */ + Texture2D(); + + /** @overload */ + Texture2D(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease = false); + + /** @overload */ + Texture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false); + + /** @overload + @param arows Number of rows. + @param acols Number of columns. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Texture2D(int arows, int acols, Format aformat, bool autoRelease = false); + + /** @overload + @param asize 2D array size. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + Texture2D(Size asize, Format aformat, bool autoRelease = false); + + /** @overload + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ). + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + explicit Texture2D(InputArray arr, bool autoRelease = false); + + /** @brief Allocates memory for ogl::Texture2D object. + + @param arows Number of rows. + @param acols Number of columns. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(int arows, int acols, Format aformat, bool autoRelease = false); + /** @overload + @param asize 2D array size. + @param aformat Image format. See cv::ogl::Texture2D::Format . + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void create(Size asize, Format aformat, bool autoRelease = false); + + /** @brief Decrements the reference counter and destroys the texture object if needed. + + The function will call setAutoRelease(true) . + */ + void release(); + + /** @brief Sets auto release mode. + + @param flag Auto release mode (if true, release will be called in object's destructor). + + The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was + bound to a window it could be released at any time (user can close a window). If object's destructor + is called after destruction of the context it will cause an error. Thus ogl::Texture2D doesn't + destroy OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL + context). This function can force ogl::Texture2D destructor to destroy OpenGL object. + */ + void setAutoRelease(bool flag); + + /** @brief Copies from host/device memory to OpenGL texture. + + @param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ). + @param autoRelease Auto release mode (if true, release will be called in object's destructor). + */ + void copyFrom(InputArray arr, bool autoRelease = false); + + /** @brief Copies from OpenGL texture to host/device memory or another OpenGL texture object. + + @param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , ogl::Buffer or + ogl::Texture2D ). + @param ddepth Destination depth. + @param autoRelease Auto release mode for destination buffer (if arr is OpenGL buffer or texture). + */ + void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const; + + /** @brief Binds texture to current active texture unit for GL_TEXTURE_2D target. + */ + void bind() const; + + int rows() const; + int cols() const; + Size size() const; + bool empty() const; + + Format format() const; + + //! get OpenGL opject id + unsigned int texId() const; + + class Impl; + +private: + Ptr impl_; + int rows_; + int cols_; + Format format_; +}; + +/** @brief Wrapper for OpenGL Client-Side Vertex arrays. + +ogl::Arrays stores vertex data in ogl::Buffer objects. + */ +class CV_EXPORTS Arrays +{ +public: + /** @brief Default constructor + */ + Arrays(); + + /** @brief Sets an array of vertex coordinates. + @param vertex array with vertex coordinates, can be both host and device memory. + */ + void setVertexArray(InputArray vertex); + + /** @brief Resets vertex coordinates. + */ + void resetVertexArray(); + + /** @brief Sets an array of vertex colors. + @param color array with vertex colors, can be both host and device memory. + */ + void setColorArray(InputArray color); + + /** @brief Resets vertex colors. + */ + void resetColorArray(); + + /** @brief Sets an array of vertex normals. + @param normal array with vertex normals, can be both host and device memory. + */ + void setNormalArray(InputArray normal); + + /** @brief Resets vertex normals. + */ + void resetNormalArray(); + + /** @brief Sets an array of vertex texture coordinates. + @param texCoord array with vertex texture coordinates, can be both host and device memory. + */ + void setTexCoordArray(InputArray texCoord); + + /** @brief Resets vertex texture coordinates. + */ + void resetTexCoordArray(); + + /** @brief Releases all inner buffers. + */ + void release(); + + /** @brief Sets auto release mode all inner buffers. + @param flag Auto release mode. + */ + void setAutoRelease(bool flag); + + /** @brief Binds all vertex arrays. + */ + void bind() const; + + /** @brief Returns the vertex count. + */ + int size() const; + bool empty() const; + +private: + int size_; + Buffer vertex_; + Buffer color_; + Buffer normal_; + Buffer texCoord_; +}; + +/////////////////// Render Functions /////////////////// + +//! render mode +enum RenderModes { + POINTS = 0x0000, + LINES = 0x0001, + LINE_LOOP = 0x0002, + LINE_STRIP = 0x0003, + TRIANGLES = 0x0004, + TRIANGLE_STRIP = 0x0005, + TRIANGLE_FAN = 0x0006, + QUADS = 0x0007, + QUAD_STRIP = 0x0008, + POLYGON = 0x0009 +}; + +/** @brief Render OpenGL texture or primitives. +@param tex Texture to draw. +@param wndRect Region of window, where to draw a texture (normalized coordinates). +@param texRect Region of texture to draw (normalized coordinates). + */ +CV_EXPORTS void render(const Texture2D& tex, + Rect_ wndRect = Rect_(0.0, 0.0, 1.0, 1.0), + Rect_ texRect = Rect_(0.0, 0.0, 1.0, 1.0)); + +/** @overload +@param arr Array of privitives vertices. +@param mode Render mode. One of cv::ogl::RenderModes +@param color Color for all vertices. Will be used if arr doesn't contain color array. +*/ +CV_EXPORTS void render(const Arrays& arr, int mode = POINTS, Scalar color = Scalar::all(255)); + +/** @overload +@param arr Array of privitives vertices. +@param indices Array of vertices indices (host or device memory). +@param mode Render mode. One of cv::ogl::RenderModes +@param color Color for all vertices. Will be used if arr doesn't contain color array. +*/ +CV_EXPORTS void render(const Arrays& arr, InputArray indices, int mode = POINTS, Scalar color = Scalar::all(255)); + +/////////////////// CL-GL Interoperability Functions /////////////////// + +namespace ocl { +using namespace cv::ocl; + +// TODO static functions in the Context class +/** @brief Creates OpenCL context from GL. +@return Returns reference to OpenCL Context + */ +CV_EXPORTS Context& initializeContextFromGL(); + +} // namespace cv::ogl::ocl + +/** @brief Converts InputArray to Texture2D object. +@param src - source InputArray. +@param texture - destination Texture2D object. + */ +CV_EXPORTS void convertToGLTexture2D(InputArray src, Texture2D& texture); + +/** @brief Converts Texture2D object to OutputArray. +@param texture - source Texture2D object. +@param dst - destination OutputArray. + */ +CV_EXPORTS void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst); + +/** @brief Maps Buffer object to process on CL side (convert to UMat). + +Function creates CL buffer from GL one, and then constructs UMat that can be used +to process buffer data with OpenCV functions. Note that in current implementation +UMat constructed this way doesn't own corresponding GL buffer object, so it is +the user responsibility to close down CL/GL buffers relationships by explicitly +calling unmapGLBuffer() function. +@param buffer - source Buffer object. +@param accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE). +@return Returns UMat object + */ +CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, AccessFlag accessFlags = ACCESS_READ | ACCESS_WRITE); + +/** @brief Unmaps Buffer object (releases UMat, previously mapped from Buffer). + +Function must be called explicitly by the user for each UMat previously constructed +by the call to mapGLBuffer() function. +@param u - source UMat, created by mapGLBuffer(). + */ +CV_EXPORTS void unmapGLBuffer(UMat& u); + +//! @} +}} // namespace cv::ogl + +namespace cv { namespace cuda { + +/** @brief Sets a CUDA device and initializes it for the current thread with OpenGL interoperability. + +This function should be explicitly called after OpenGL context creation and before any CUDA calls. +@param device System index of a CUDA device starting with 0. +@ingroup core_opengl + */ +CV_EXPORTS void setGlDevice(int device = 0); + +}} + +//! @cond IGNORED + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +inline +cv::ogl::Buffer::Buffer(int arows, int acols, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0) +{ + create(arows, acols, atype, target, autoRelease); +} + +inline +cv::ogl::Buffer::Buffer(Size asize, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0) +{ + create(asize, atype, target, autoRelease); +} + +inline +void cv::ogl::Buffer::create(Size asize, int atype, Target target, bool autoRelease) +{ + create(asize.height, asize.width, atype, target, autoRelease); +} + +inline +int cv::ogl::Buffer::rows() const +{ + return rows_; +} + +inline +int cv::ogl::Buffer::cols() const +{ + return cols_; +} + +inline +cv::Size cv::ogl::Buffer::size() const +{ + return Size(cols_, rows_); +} + +inline +bool cv::ogl::Buffer::empty() const +{ + return rows_ == 0 || cols_ == 0; +} + +inline +int cv::ogl::Buffer::type() const +{ + return type_; +} + +inline +int cv::ogl::Buffer::depth() const +{ + return CV_MAT_DEPTH(type_); +} + +inline +int cv::ogl::Buffer::channels() const +{ + return CV_MAT_CN(type_); +} + +inline +int cv::ogl::Buffer::elemSize() const +{ + return CV_ELEM_SIZE(type_); +} + +inline +int cv::ogl::Buffer::elemSize1() const +{ + return CV_ELEM_SIZE1(type_); +} + +/////// + +inline +cv::ogl::Texture2D::Texture2D(int arows, int acols, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE) +{ + create(arows, acols, aformat, autoRelease); +} + +inline +cv::ogl::Texture2D::Texture2D(Size asize, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE) +{ + create(asize, aformat, autoRelease); +} + +inline +void cv::ogl::Texture2D::create(Size asize, Format aformat, bool autoRelease) +{ + create(asize.height, asize.width, aformat, autoRelease); +} + +inline +int cv::ogl::Texture2D::rows() const +{ + return rows_; +} + +inline +int cv::ogl::Texture2D::cols() const +{ + return cols_; +} + +inline +cv::Size cv::ogl::Texture2D::size() const +{ + return Size(cols_, rows_); +} + +inline +bool cv::ogl::Texture2D::empty() const +{ + return rows_ == 0 || cols_ == 0; +} + +inline +cv::ogl::Texture2D::Format cv::ogl::Texture2D::format() const +{ + return format_; +} + +/////// + +inline +cv::ogl::Arrays::Arrays() : size_(0) +{ +} + +inline +int cv::ogl::Arrays::size() const +{ + return size_; +} + +inline +bool cv::ogl::Arrays::empty() const +{ + return size_ == 0; +} + +//! @endcond + +#endif /* OPENCV_CORE_OPENGL_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/operations.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/operations.hpp new file mode 100644 index 0000000000000000000000000000000000000000..92943a62a8ae93eb403257726b21704f656b9a86 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/operations.hpp @@ -0,0 +1,594 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_OPERATIONS_HPP +#define OPENCV_CORE_OPERATIONS_HPP + +#ifndef __cplusplus +# error operations.hpp header must be compiled as C++ +#endif + +#include + +#if defined(__GNUC__) || defined(__clang__) // at least GCC 3.1+, clang 3.5+ +# if defined(__MINGW_PRINTF_FORMAT) // https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. +# define CV_FORMAT_PRINTF(string_idx, first_to_check) __attribute__ ((format (__MINGW_PRINTF_FORMAT, string_idx, first_to_check))) +# else +# define CV_FORMAT_PRINTF(string_idx, first_to_check) __attribute__ ((format (printf, string_idx, first_to_check))) +# endif +#else +# define CV_FORMAT_PRINTF(A, B) +#endif + +//! @cond IGNORED + +namespace cv +{ + +////////////////////////////// Matx methods depending on core API ///////////////////////////// + +namespace internal +{ + +template struct Matx_FastInvOp +{ + bool operator()(const Matx<_Tp, m, n>& a, Matx<_Tp, n, m>& b, int method) const + { + return invert(a, b, method) != 0; + } +}; + +template struct Matx_FastInvOp<_Tp, m, m> +{ + bool operator()(const Matx<_Tp, m, m>& a, Matx<_Tp, m, m>& b, int method) const + { + if (method == DECOMP_LU || method == DECOMP_CHOLESKY) + { + Matx<_Tp, m, m> temp = a; + + // assume that b is all 0's on input => make it a unity matrix + for (int i = 0; i < m; i++) + b(i, i) = (_Tp)1; + + if (method == DECOMP_CHOLESKY) + return Cholesky(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m); + + return LU(temp.val, m*sizeof(_Tp), m, b.val, m*sizeof(_Tp), m) != 0; + } + else + { + return invert(a, b, method) != 0; + } + } +}; + +template struct Matx_FastInvOp<_Tp, 2, 2> +{ + bool operator()(const Matx<_Tp, 2, 2>& a, Matx<_Tp, 2, 2>& b, int /*method*/) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + b(1,1) = a(0,0)*d; + b(0,0) = a(1,1)*d; + b(0,1) = -a(0,1)*d; + b(1,0) = -a(1,0)*d; + return true; + } +}; + +template struct Matx_FastInvOp<_Tp, 3, 3> +{ + bool operator()(const Matx<_Tp, 3, 3>& a, Matx<_Tp, 3, 3>& b, int /*method*/) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + b(0,0) = (a(1,1) * a(2,2) - a(1,2) * a(2,1)) * d; + b(0,1) = (a(0,2) * a(2,1) - a(0,1) * a(2,2)) * d; + b(0,2) = (a(0,1) * a(1,2) - a(0,2) * a(1,1)) * d; + + b(1,0) = (a(1,2) * a(2,0) - a(1,0) * a(2,2)) * d; + b(1,1) = (a(0,0) * a(2,2) - a(0,2) * a(2,0)) * d; + b(1,2) = (a(0,2) * a(1,0) - a(0,0) * a(1,2)) * d; + + b(2,0) = (a(1,0) * a(2,1) - a(1,1) * a(2,0)) * d; + b(2,1) = (a(0,1) * a(2,0) - a(0,0) * a(2,1)) * d; + b(2,2) = (a(0,0) * a(1,1) - a(0,1) * a(1,0)) * d; + return true; + } +}; + + +template struct Matx_FastSolveOp +{ + bool operator()(const Matx<_Tp, m, l>& a, const Matx<_Tp, m, n>& b, + Matx<_Tp, l, n>& x, int method) const + { + return cv::solve(a, b, x, method); + } +}; + +template struct Matx_FastSolveOp<_Tp, m, m, n> +{ + bool operator()(const Matx<_Tp, m, m>& a, const Matx<_Tp, m, n>& b, + Matx<_Tp, m, n>& x, int method) const + { + if (method == DECOMP_LU || method == DECOMP_CHOLESKY) + { + Matx<_Tp, m, m> temp = a; + x = b; + if( method == DECOMP_CHOLESKY ) + return Cholesky(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n); + + return LU(temp.val, m*sizeof(_Tp), m, x.val, n*sizeof(_Tp), n) != 0; + } + else + { + return cv::solve(a, b, x, method); + } + } +}; + +template struct Matx_FastSolveOp<_Tp, 2, 2, 1> +{ + bool operator()(const Matx<_Tp, 2, 2>& a, const Matx<_Tp, 2, 1>& b, + Matx<_Tp, 2, 1>& x, int) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + x(0) = (b(0)*a(1,1) - b(1)*a(0,1))*d; + x(1) = (b(1)*a(0,0) - b(0)*a(1,0))*d; + return true; + } +}; + +template struct Matx_FastSolveOp<_Tp, 3, 3, 1> +{ + bool operator()(const Matx<_Tp, 3, 3>& a, const Matx<_Tp, 3, 1>& b, + Matx<_Tp, 3, 1>& x, int) const + { + _Tp d = (_Tp)determinant(a); + if (d == 0) + return false; + d = 1/d; + x(0) = d*(b(0)*(a(1,1)*a(2,2) - a(1,2)*a(2,1)) - + a(0,1)*(b(1)*a(2,2) - a(1,2)*b(2)) + + a(0,2)*(b(1)*a(2,1) - a(1,1)*b(2))); + + x(1) = d*(a(0,0)*(b(1)*a(2,2) - a(1,2)*b(2)) - + b(0)*(a(1,0)*a(2,2) - a(1,2)*a(2,0)) + + a(0,2)*(a(1,0)*b(2) - b(1)*a(2,0))); + + x(2) = d*(a(0,0)*(a(1,1)*b(2) - b(1)*a(2,1)) - + a(0,1)*(a(1,0)*b(2) - b(1)*a(2,0)) + + b(0)*(a(1,0)*a(2,1) - a(1,1)*a(2,0))); + return true; + } +}; + +} // internal + +template inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::randu(_Tp a, _Tp b) +{ + Matx<_Tp,m,n> M; + cv::randu(M, Scalar(a), Scalar(b)); + return M; +} + +template inline +Matx<_Tp,m,n> Matx<_Tp,m,n>::randn(_Tp a, _Tp b) +{ + Matx<_Tp,m,n> M; + cv::randn(M, Scalar(a), Scalar(b)); + return M; +} + +template inline +Matx<_Tp, n, m> Matx<_Tp, m, n>::inv(int method, bool *p_is_ok /*= NULL*/) const +{ + Matx<_Tp, n, m> b; + bool ok = cv::internal::Matx_FastInvOp<_Tp, m, n>()(*this, b, method); + if (p_is_ok) *p_is_ok = ok; + return ok ? b : Matx<_Tp, n, m>::zeros(); +} + +template template inline +Matx<_Tp, n, l> Matx<_Tp, m, n>::solve(const Matx<_Tp, m, l>& rhs, int method) const +{ + Matx<_Tp, n, l> x; + bool ok = cv::internal::Matx_FastSolveOp<_Tp, m, n, l>()(*this, rhs, x, method); + return ok ? x : Matx<_Tp, n, l>::zeros(); +} + + + +////////////////////////// Augmenting algebraic & logical operations ////////////////////////// + +#define CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \ + static inline A& operator op (A& a, const B& b) { cvop; return a; } + +#define CV_MAT_AUG_OPERATOR(op, cvop, A, B) \ + CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \ + CV_MAT_AUG_OPERATOR1(op, cvop, const A, B) + +#define CV_MAT_AUG_OPERATOR_T(op, cvop, A, B) \ + template CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \ + template CV_MAT_AUG_OPERATOR1(op, cvop, const A, B) + +#define CV_MAT_AUG_OPERATOR_TN(op, cvop, A) \ + template static inline A& operator op (A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } \ + template static inline const A& operator op (const A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } + +CV_MAT_AUG_OPERATOR (+=, cv::add(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (+=, cv::add(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat) +CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (-=, cv::subtract(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (-=, cv::subtract(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(-=, cv::subtract(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(-=, cv::subtract(a,Mat(b),a), Mat) +CV_MAT_AUG_OPERATOR_TN(-=, cv::subtract(a,Mat(b),a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat, Mat) +CV_MAT_AUG_OPERATOR_T(*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(*=, cv::gemm(a, b, 1, Mat(), 0, a, 0), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR (*=, a.convertTo(a, -1, b), Mat, double) +CV_MAT_AUG_OPERATOR_T(*=, a.convertTo(a, -1, b), Mat_<_Tp>, double) +CV_MAT_AUG_OPERATOR_TN(*=, cv::gemm(a, Mat(b), 1, Mat(), 0, a, 0), Mat) +CV_MAT_AUG_OPERATOR_TN(*=, cv::gemm(a, Mat(b), 1, Mat(), 0, a, 0), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (/=, cv::divide(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR_T(/=, cv::divide(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(/=, cv::divide(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR (/=, a.convertTo((Mat&)a, -1, 1./b), Mat, double) +CV_MAT_AUG_OPERATOR_T(/=, a.convertTo((Mat&)a, -1, 1./b), Mat_<_Tp>, double) +CV_MAT_AUG_OPERATOR_TN(/=, cv::divide(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(/=, cv::divide(a, Mat(b), a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (&=, cv::bitwise_and(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (&=, cv::bitwise_and(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(&=, cv::bitwise_and(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(&=, cv::bitwise_and(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(&=, cv::bitwise_and(a, Mat(b), a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (|=, cv::bitwise_or(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (|=, cv::bitwise_or(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(|=, cv::bitwise_or(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(|=, cv::bitwise_or(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(|=, cv::bitwise_or(a, Mat(b), a), Mat_<_Tp>) + +CV_MAT_AUG_OPERATOR (^=, cv::bitwise_xor(a,b,a), Mat, Mat) +CV_MAT_AUG_OPERATOR (^=, cv::bitwise_xor(a,b,a), Mat, Scalar) +CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Mat) +CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Scalar) +CV_MAT_AUG_OPERATOR_T(^=, cv::bitwise_xor(a,b,a), Mat_<_Tp>, Mat_<_Tp>) +CV_MAT_AUG_OPERATOR_TN(^=, cv::bitwise_xor(a, Mat(b), a), Mat) +CV_MAT_AUG_OPERATOR_TN(^=, cv::bitwise_xor(a, Mat(b), a), Mat_<_Tp>) + +#undef CV_MAT_AUG_OPERATOR_TN +#undef CV_MAT_AUG_OPERATOR_T +#undef CV_MAT_AUG_OPERATOR +#undef CV_MAT_AUG_OPERATOR1 + + + +///////////////////////////////////////////// SVD ///////////////////////////////////////////// + +inline SVD::SVD() {} +inline SVD::SVD( InputArray m, int flags ) { operator ()(m, flags); } +inline void SVD::solveZ( InputArray m, OutputArray _dst ) +{ + Mat mtx = m.getMat(); + SVD svd(mtx, (mtx.rows >= mtx.cols ? 0 : SVD::FULL_UV)); + _dst.create(svd.vt.cols, 1, svd.vt.type()); + Mat dst = _dst.getMat(); + svd.vt.row(svd.vt.rows-1).reshape(1,svd.vt.cols).copyTo(dst); +} + +template inline void + SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w, Matx<_Tp, m, nm>& u, Matx<_Tp, n, nm>& vt ) +{ + CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector."); + Mat _a(a, false), _u(u, false), _w(w, false), _vt(vt, false); + SVD::compute(_a, _w, _u, _vt); + CV_Assert(_w.data == (uchar*)&w.val[0] && _u.data == (uchar*)&u.val[0] && _vt.data == (uchar*)&vt.val[0]); +} + +template inline void +SVD::compute( const Matx<_Tp, m, n>& a, Matx<_Tp, nm, 1>& w ) +{ + CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector."); + Mat _a(a, false), _w(w, false); + SVD::compute(_a, _w); + CV_Assert(_w.data == (uchar*)&w.val[0]); +} + +template inline void +SVD::backSubst( const Matx<_Tp, nm, 1>& w, const Matx<_Tp, m, nm>& u, + const Matx<_Tp, n, nm>& vt, const Matx<_Tp, m, nb>& rhs, + Matx<_Tp, n, nb>& dst ) +{ + CV_StaticAssert( nm == MIN(m, n), "Invalid size of output vector."); + Mat _u(u, false), _w(w, false), _vt(vt, false), _rhs(rhs, false), _dst(dst, false); + SVD::backSubst(_w, _u, _vt, _rhs, _dst); + CV_Assert(_dst.data == (uchar*)&dst.val[0]); +} + + + +/////////////////////////////////// Multiply-with-Carry RNG /////////////////////////////////// + +inline RNG::RNG() { state = 0xffffffff; } +inline RNG::RNG(uint64 _state) { state = _state ? _state : 0xffffffff; } + +inline RNG::operator uchar() { return (uchar)next(); } +inline RNG::operator schar() { return (schar)next(); } +inline RNG::operator ushort() { return (ushort)next(); } +inline RNG::operator short() { return (short)next(); } +inline RNG::operator int() { return (int)next(); } +inline RNG::operator unsigned() { return next(); } +inline RNG::operator float() { return next()*2.3283064365386962890625e-10f; } +inline RNG::operator double() { unsigned t = next(); return (((uint64)t << 32) | next()) * 5.4210108624275221700372640043497e-20; } + +inline unsigned RNG::operator ()(unsigned N) { return (unsigned)uniform(0,N); } +inline unsigned RNG::operator ()() { return next(); } + +inline int RNG::uniform(int a, int b) { return a == b ? a : (int)(next() % (b - a) + a); } +inline float RNG::uniform(float a, float b) { return ((float)*this)*(b - a) + a; } +inline double RNG::uniform(double a, double b) { return ((double)*this)*(b - a) + a; } + +inline bool RNG::operator ==(const RNG& other) const { return state == other.state; } + +inline unsigned RNG::next() +{ + state = (uint64)(unsigned)state* /*CV_RNG_COEFF*/ 4164903690U + (unsigned)(state >> 32); + return (unsigned)state; +} + +//! returns the next uniformly-distributed random number of the specified type +template static inline _Tp randu() +{ + return (_Tp)theRNG(); +} + +///////////////////////////////// Formatted string generation ///////////////////////////////// + +/** @brief Returns a text string formatted using the printf-like expression. + +The function acts like sprintf but forms and returns an STL string. It can be used to form an error +message in the Exception constructor. +@param fmt printf-compatible formatting specifiers. + +**Note**: +|Type|Specifier| +|-|-| +|`const char*`|`%s`| +|`char`|`%c`| +|`float` / `double`|`%f`,`%g`| +|`int`, `long`, `long long`|`%d`, `%ld`, ``%lld`| +|`unsigned`, `unsigned long`, `unsigned long long`|`%u`, `%lu`, `%llu`| +|`uint64` -> `uintmax_t`, `int64` -> `intmax_t`|`%ju`, `%jd`| +|`size_t`|`%zu`| + */ +CV_EXPORTS String format( const char* fmt, ... ) CV_FORMAT_PRINTF(1, 2); + +///////////////////////////////// Formatted output of cv::Mat ///////////////////////////////// + +static inline +Ptr format(InputArray mtx, Formatter::FormatType fmt) +{ + return Formatter::get(fmt)->format(mtx.getMat()); +} + +static inline +int print(Ptr fmtd, FILE* stream = stdout) +{ + int written = 0; + fmtd->reset(); + for(const char* str = fmtd->next(); str; str = fmtd->next()) + written += fputs(str, stream); + + return written; +} + +static inline +int print(const Mat& mtx, FILE* stream = stdout) +{ + return print(Formatter::get()->format(mtx), stream); +} + +static inline +int print(const UMat& mtx, FILE* stream = stdout) +{ + return print(Formatter::get()->format(mtx.getMat(ACCESS_READ)), stream); +} + +template static inline +int print(const std::vector >& vec, FILE* stream = stdout) +{ + return print(Formatter::get()->format(Mat(vec)), stream); +} + +template static inline +int print(const std::vector >& vec, FILE* stream = stdout) +{ + return print(Formatter::get()->format(Mat(vec)), stream); +} + +template static inline +int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout) +{ + return print(Formatter::get()->format(cv::Mat(matx)), stream); +} + +//! @endcond + +/****************************************************************************************\ +* Auxiliary algorithms * +\****************************************************************************************/ + +/** @brief Splits an element set into equivalency classes. + +The generic function partition implements an \f$O(N^2)\f$ algorithm for splitting a set of \f$N\f$ elements +into one or more equivalency classes, as described in + . The function returns the number of +equivalency classes. +@param _vec Set of elements stored as a vector. +@param labels Output vector of labels. It contains as many elements as vec. Each label labels[i] is +a 0-based cluster index of `vec[i]`. +@param predicate Equivalence predicate (pointer to a boolean function of two arguments or an +instance of the class that has the method bool operator()(const _Tp& a, const _Tp& b) ). The +predicate returns true when the elements are certainly in the same class, and returns false if they +may or may not be in the same class. +@ingroup core_cluster +*/ +template int +partition( const std::vector<_Tp>& _vec, std::vector& labels, + _EqPredicate predicate=_EqPredicate()) +{ + int i, j, N = (int)_vec.size(); + const _Tp* vec = &_vec[0]; + + const int PARENT=0; + const int RANK=1; + + std::vector _nodes(N*2); + int (*nodes)[2] = (int(*)[2])&_nodes[0]; + + // The first O(N) pass: create N single-vertex trees + for(i = 0; i < N; i++) + { + nodes[i][PARENT]=-1; + nodes[i][RANK] = 0; + } + + // The main O(N^2) pass: merge connected components + for( i = 0; i < N; i++ ) + { + int root = i; + + // find root + while( nodes[root][PARENT] >= 0 ) + root = nodes[root][PARENT]; + + for( j = 0; j < N; j++ ) + { + if( i == j || !predicate(vec[i], vec[j])) + continue; + int root2 = j; + + while( nodes[root2][PARENT] >= 0 ) + root2 = nodes[root2][PARENT]; + + if( root2 != root ) + { + // unite both trees + int rank = nodes[root][RANK], rank2 = nodes[root2][RANK]; + if( rank > rank2 ) + nodes[root2][PARENT] = root; + else + { + nodes[root][PARENT] = root2; + nodes[root2][RANK] += rank == rank2; + root = root2; + } + CV_Assert( nodes[root][PARENT] < 0 ); + + int k = j, parent; + + // compress the path from node2 to root + while( (parent = nodes[k][PARENT]) >= 0 ) + { + nodes[k][PARENT] = root; + k = parent; + } + + // compress the path from node to root + k = i; + while( (parent = nodes[k][PARENT]) >= 0 ) + { + nodes[k][PARENT] = root; + k = parent; + } + } + } + } + + // Final O(N) pass: enumerate classes + labels.resize(N); + int nclasses = 0; + + for( i = 0; i < N; i++ ) + { + int root = i; + while( nodes[root][PARENT] >= 0 ) + root = nodes[root][PARENT]; + // re-use the rank as the class label + if( nodes[root][RANK] >= 0 ) + nodes[root][RANK] = ~nclasses++; + labels[i] = ~nodes[root][RANK]; + } + + return nclasses; +} + +} // cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/optim.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/optim.hpp new file mode 100644 index 0000000000000000000000000000000000000000..70e037f89edca8a6356e5ec5b54e85ca8f40e4f2 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/optim.hpp @@ -0,0 +1,302 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the OpenCV Foundation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_OPTIM_HPP +#define OPENCV_OPTIM_HPP + +#include "opencv2/core.hpp" + +namespace cv +{ + +/** @addtogroup core_optim +The algorithms in this section minimize or maximize function value within specified constraints or +without any constraints. +@{ +*/ + +/** @brief Basic interface for all solvers + */ +class CV_EXPORTS MinProblemSolver : public Algorithm +{ +public: + /** @brief Represents function being optimized + */ + class CV_EXPORTS Function + { + public: + virtual ~Function() {} + virtual int getDims() const = 0; + virtual double getGradientEps() const; + virtual double calc(const double* x) const = 0; + virtual void getGradient(const double* x,double* grad); + }; + + /** @brief Getter for the optimized function. + + The optimized function is represented by Function interface, which requires derivatives to + implement the calc(double*) and getDim() methods to evaluate the function. + + @return Smart-pointer to an object that implements Function interface - it represents the + function that is being optimized. It can be empty, if no function was given so far. + */ + virtual Ptr getFunction() const = 0; + + /** @brief Setter for the optimized function. + + *It should be called at least once before the call to* minimize(), as default value is not usable. + + @param f The new function to optimize. + */ + virtual void setFunction(const Ptr& f) = 0; + + /** @brief Getter for the previously set terminal criteria for this algorithm. + + @return Deep copy of the terminal criteria used at the moment. + */ + virtual TermCriteria getTermCriteria() const = 0; + + /** @brief Set terminal criteria for solver. + + This method *is not necessary* to be called before the first call to minimize(), as the default + value is sensible. + + Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when + the function values at the vertices of simplex are within termcrit.epsilon range or simplex + becomes so small that it can enclosed in a box with termcrit.epsilon sides, whatever comes + first. + @param termcrit Terminal criteria to be used, represented as cv::TermCriteria structure. + */ + virtual void setTermCriteria(const TermCriteria& termcrit) = 0; + + /** @brief actually runs the algorithm and performs the minimization. + + The sole input parameter determines the centroid of the starting simplex (roughly, it tells + where to start), all the others (terminal criteria, initial step, function to be minimized) are + supposed to be set via the setters before the call to this method or the default values (not + always sensible) will be used. + + @param x The initial point, that will become a centroid of an initial simplex. After the algorithm + will terminate, it will be set to the point where the algorithm stops, the point of possible + minimum. + @return The value of a function at the point found. + */ + virtual double minimize(InputOutputArray x) = 0; +}; + +/** @brief This class is used to perform the non-linear non-constrained minimization of a function, + +defined on an `n`-dimensional Euclidean space, using the **Nelder-Mead method**, also known as +**downhill simplex method**. The basic idea about the method can be obtained from +. + +It should be noted, that this method, although deterministic, is rather a heuristic and therefore +may converge to a local minima, not necessary a global one. It is iterative optimization technique, +which at each step uses an information about the values of a function evaluated only at `n+1` +points, arranged as a *simplex* in `n`-dimensional space (hence the second name of the method). At +each step new point is chosen to evaluate function at, obtained value is compared with previous +ones and based on this information simplex changes it's shape , slowly moving to the local minimum. +Thus this method is using *only* function values to make decision, on contrary to, say, Nonlinear +Conjugate Gradient method (which is also implemented in optim). + +Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when the +function values at the vertices of simplex are within termcrit.epsilon range or simplex becomes so +small that it can enclosed in a box with termcrit.epsilon sides, whatever comes first, for some +defined by user positive integer termcrit.maxCount and positive non-integer termcrit.epsilon. + +@note DownhillSolver is a derivative of the abstract interface +cv::MinProblemSolver, which in turn is derived from the Algorithm interface and is used to +encapsulate the functionality, common to all non-linear optimization algorithms in the optim +module. + +@note term criteria should meet following condition: +@code + termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0 +@endcode + */ +class CV_EXPORTS DownhillSolver : public MinProblemSolver +{ +public: + /** @brief Returns the initial step that will be used in downhill simplex algorithm. + + @param step Initial step that will be used in algorithm. Note, that although corresponding setter + accepts column-vectors as well as row-vectors, this method will return a row-vector. + @see DownhillSolver::setInitStep + */ + virtual void getInitStep(OutputArray step) const=0; + + /** @brief Sets the initial step that will be used in downhill simplex algorithm. + + Step, together with initial point (givin in DownhillSolver::minimize) are two `n`-dimensional + vectors that are used to determine the shape of initial simplex. Roughly said, initial point + determines the position of a simplex (it will become simplex's centroid), while step determines the + spread (size in each dimension) of a simplex. To be more precise, if \f$s,x_0\in\mathbb{R}^n\f$ are + the initial step and initial point respectively, the vertices of a simplex will be: + \f$v_0:=x_0-\frac{1}{2} s\f$ and \f$v_i:=x_0+s_i\f$ for \f$i=1,2,\dots,n\f$ where \f$s_i\f$ denotes + projections of the initial step of *n*-th coordinate (the result of projection is treated to be + vector given by \f$s_i:=e_i\cdot\left\f$, where \f$e_i\f$ form canonical basis) + + @param step Initial step that will be used in algorithm. Roughly said, it determines the spread + (size in each dimension) of an initial simplex. + */ + virtual void setInitStep(InputArray step)=0; + + /** @brief This function returns the reference to the ready-to-use DownhillSolver object. + + All the parameters are optional, so this procedure can be called even without parameters at + all. In this case, the default values will be used. As default value for terminal criteria are + the only sensible ones, MinProblemSolver::setFunction() and DownhillSolver::setInitStep() + should be called upon the obtained object, if the respective parameters were not given to + create(). Otherwise, the two ways (give parameters to createDownhillSolver() or miss them out + and call the MinProblemSolver::setFunction() and DownhillSolver::setInitStep()) are absolutely + equivalent (and will drop the same errors in the same way, should invalid input be detected). + @param f Pointer to the function that will be minimized, similarly to the one you submit via + MinProblemSolver::setFunction. + @param initStep Initial step, that will be used to construct the initial simplex, similarly to the one + you submit via MinProblemSolver::setInitStep. + @param termcrit Terminal criteria to the algorithm, similarly to the one you submit via + MinProblemSolver::setTermCriteria. + */ + static Ptr create(const Ptr& f=Ptr(), + InputArray initStep=Mat_(1,1,0.0), + TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); +}; + +/** @brief This class is used to perform the non-linear non-constrained minimization of a function +with known gradient, + +defined on an *n*-dimensional Euclidean space, using the **Nonlinear Conjugate Gradient method**. +The implementation was done based on the beautifully clear explanatory article [An Introduction to +the Conjugate Gradient Method Without the Agonizing +Pain](http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf) by Jonathan Richard +Shewchuk. The method can be seen as an adaptation of a standard Conjugate Gradient method (see, for +example ) for numerically solving the +systems of linear equations. + +It should be noted, that this method, although deterministic, is rather a heuristic method and +therefore may converge to a local minima, not necessary a global one. What is even more disastrous, +most of its behaviour is ruled by gradient, therefore it essentially cannot distinguish between +local minima and maxima. Therefore, if it starts sufficiently near to the local maximum, it may +converge to it. Another obvious restriction is that it should be possible to compute the gradient of +a function at any point, thus it is preferable to have analytic expression for gradient and +computational burden should be born by the user. + +The latter responsibility is accomplished via the getGradient method of a +MinProblemSolver::Function interface (which represents function being optimized). This method takes +point a point in *n*-dimensional space (first argument represents the array of coordinates of that +point) and compute its gradient (it should be stored in the second argument as an array). + +@note class ConjGradSolver thus does not add any new methods to the basic MinProblemSolver interface. + +@note term criteria should meet following condition: +@code + termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0 + // or + termcrit.type == TermCriteria::MAX_ITER) && termcrit.maxCount > 0 +@endcode + */ +class CV_EXPORTS ConjGradSolver : public MinProblemSolver +{ +public: + /** @brief This function returns the reference to the ready-to-use ConjGradSolver object. + + All the parameters are optional, so this procedure can be called even without parameters at + all. In this case, the default values will be used. As default value for terminal criteria are + the only sensible ones, MinProblemSolver::setFunction() should be called upon the obtained + object, if the function was not given to create(). Otherwise, the two ways (submit it to + create() or miss it out and call the MinProblemSolver::setFunction()) are absolutely equivalent + (and will drop the same errors in the same way, should invalid input be detected). + @param f Pointer to the function that will be minimized, similarly to the one you submit via + MinProblemSolver::setFunction. + @param termcrit Terminal criteria to the algorithm, similarly to the one you submit via + MinProblemSolver::setTermCriteria. + */ + static Ptr create(const Ptr& f=Ptr(), + TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001)); +}; + +//! return codes for cv::solveLP() function +enum SolveLPResult +{ + SOLVELP_UNBOUNDED = -2, //!< problem is unbounded (target function can achieve arbitrary high values) + SOLVELP_UNFEASIBLE = -1, //!< problem is unfeasible (there are no points that satisfy all the constraints imposed) + SOLVELP_SINGLE = 0, //!< there is only one maximum for target function + SOLVELP_MULTI = 1 //!< there are multiple maxima for target function - the arbitrary one is returned +}; + +/** @brief Solve given (non-integer) linear programming problem using the Simplex Algorithm (Simplex Method). + +What we mean here by "linear programming problem" (or LP problem, for short) can be formulated as: + +\f[\mbox{Maximize } c\cdot x\\ + \mbox{Subject to:}\\ + Ax\leq b\\ + x\geq 0\f] + +Where \f$c\f$ is fixed `1`-by-`n` row-vector, \f$A\f$ is fixed `m`-by-`n` matrix, \f$b\f$ is fixed `m`-by-`1` +column vector and \f$x\f$ is an arbitrary `n`-by-`1` column vector, which satisfies the constraints. + +Simplex algorithm is one of many algorithms that are designed to handle this sort of problems +efficiently. Although it is not optimal in theoretical sense (there exist algorithms that can solve +any problem written as above in polynomial time, while simplex method degenerates to exponential +time for some special cases), it is well-studied, easy to implement and is shown to work well for +real-life purposes. + +The particular implementation is taken almost verbatim from **Introduction to Algorithms, third +edition** by T. H. Cormen, C. E. Leiserson, R. L. Rivest and Clifford Stein. In particular, the +Bland's rule is used to prevent cycling. + +@param Func This row-vector corresponds to \f$c\f$ in the LP problem formulation (see above). It should +contain 32- or 64-bit floating point numbers. As a convenience, column-vector may be also submitted, +in the latter case it is understood to correspond to \f$c^T\f$. +@param Constr `m`-by-`n+1` matrix, whose rightmost column corresponds to \f$b\f$ in formulation above +and the remaining to \f$A\f$. It should contain 32- or 64-bit floating point numbers. +@param z The solution will be returned here as a column-vector - it corresponds to \f$c\f$ in the +formulation above. It will contain 64-bit floating point numbers. +@return One of cv::SolveLPResult + */ +CV_EXPORTS_W int solveLP(InputArray Func, InputArray Constr, OutputArray z); + +//! @} + +}// cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ovx.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ovx.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8bb7d54911722ba38212bc1e082aa9281d879af4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/ovx.hpp @@ -0,0 +1,28 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2016, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. + +// OpenVX related definitions and declarations + +#pragma once +#ifndef OPENCV_OVX_HPP +#define OPENCV_OVX_HPP + +#include "cvdef.h" + +namespace cv +{ +/// Check if use of OpenVX is possible +CV_EXPORTS_W bool haveOpenVX(); + +/// Check if use of OpenVX is enabled +CV_EXPORTS_W bool useOpenVX(); + +/// Enable/disable use of OpenVX +CV_EXPORTS_W void setUseOpenVX(bool flag); +} // namespace cv + +#endif // OPENCV_OVX_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/persistence.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/persistence.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5e00e68db94f463b17d09f13c3be2235a4eb4a40 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/persistence.hpp @@ -0,0 +1,1337 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_PERSISTENCE_HPP +#define OPENCV_CORE_PERSISTENCE_HPP + +#ifndef CV_DOXYGEN +/// Define to support persistence legacy formats +#define CV__LEGACY_PERSISTENCE +#endif + +#ifndef __cplusplus +# error persistence.hpp header must be compiled as C++ +#endif + +//! @addtogroup core_c +//! @{ + +/** @brief "black box" representation of the file storage associated with a file on disk. + +Several functions that are described below take CvFileStorage\* as inputs and allow the user to +save or to load hierarchical collections that consist of scalar values, standard CXCore objects +(such as matrices, sequences, graphs), and user-defined objects. + +OpenCV can read and write data in XML (), YAML () or +JSON () formats. Below is an example of 3x3 floating-point identity matrix A, +stored in XML and YAML files +using CXCore functions: +XML: +@code{.xml} + + + + 3 + 3 +
f
+ 1. 0. 0. 0. 1. 0. 0. 0. 1. +
+
+@endcode +YAML: +@code{.yaml} + %YAML:1.0 + A: !!opencv-matrix + rows: 3 + cols: 3 + dt: f + data: [ 1., 0., 0., 0., 1., 0., 0., 0., 1.] +@endcode +As it can be seen from the examples, XML uses nested tags to represent hierarchy, while YAML uses +indentation for that purpose (similar to the Python programming language). + +The same functions can read and write data in both formats; the particular format is determined by +the extension of the opened file, ".xml" for XML files, ".yml" or ".yaml" for YAML and ".json" for +JSON. + */ + +//! @} core_c + +#include "opencv2/core/types.hpp" +#include "opencv2/core/mat.hpp" + +namespace cv { + +/** @addtogroup core_xml + +XML/YAML/JSON file storages. {#xml_storage} +======================= +Writing to a file storage. +-------------------------- +You can store and then restore various OpenCV data structures to/from XML (), +YAML () or JSON () formats. Also, it is possible to store +and load arbitrarily complex data structures, which include OpenCV data structures, as well as +primitive data types (integer and floating-point numbers and text strings) as their elements. + +Use the following procedure to write something to XML, YAML or JSON: +-# Create new FileStorage and open it for writing. It can be done with a single call to +FileStorage::FileStorage constructor that takes a filename, or you can use the default constructor +and then call FileStorage::open. Format of the file (XML, YAML or JSON) is determined from the filename +extension (".xml", ".yml"/".yaml" and ".json", respectively) +-# Write all the data you want using the streaming operator `<<`, just like in the case of STL +streams. +-# Close the file using FileStorage::release. FileStorage destructor also closes the file. + +Here is an example: +@code + #include "opencv2/opencv.hpp" + #include + + using namespace cv; + + int main(int, char** argv) + { + FileStorage fs("test.yml", FileStorage::WRITE); + + fs << "frameCount" << 5; + time_t rawtime; time(&rawtime); + fs << "calibrationDate" << asctime(localtime(&rawtime)); + Mat cameraMatrix = (Mat_(3,3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1); + Mat distCoeffs = (Mat_(5,1) << 0.1, 0.01, -0.001, 0, 0); + fs << "cameraMatrix" << cameraMatrix << "distCoeffs" << distCoeffs; + fs << "features" << "["; + for( int i = 0; i < 3; i++ ) + { + int x = rand() % 640; + int y = rand() % 480; + uchar lbp = rand() % 256; + + fs << "{:" << "x" << x << "y" << y << "lbp" << "[:"; + for( int j = 0; j < 8; j++ ) + fs << ((lbp >> j) & 1); + fs << "]" << "}"; + } + fs << "]"; + fs.release(); + return 0; + } +@endcode +The sample above stores to YML an integer, a text string (calibration date), 2 matrices, and a custom +structure "feature", which includes feature coordinates and LBP (local binary pattern) value. Here +is output of the sample: +@code{.yaml} +%YAML:1.0 +frameCount: 5 +calibrationDate: "Fri Jun 17 14:09:29 2011\n" +cameraMatrix: !!opencv-matrix + rows: 3 + cols: 3 + dt: d + data: [ 1000., 0., 320., 0., 1000., 240., 0., 0., 1. ] +distCoeffs: !!opencv-matrix + rows: 5 + cols: 1 + dt: d + data: [ 1.0000000000000001e-01, 1.0000000000000000e-02, + -1.0000000000000000e-03, 0., 0. ] +features: + - { x:167, y:49, lbp:[ 1, 0, 0, 1, 1, 0, 1, 1 ] } + - { x:298, y:130, lbp:[ 0, 0, 0, 1, 0, 0, 1, 1 ] } + - { x:344, y:158, lbp:[ 1, 1, 0, 0, 0, 0, 1, 0 ] } +@endcode + +As an exercise, you can replace ".yml" with ".xml" or ".json" in the sample above and see, how the +corresponding XML file will look like. + +Several things can be noted by looking at the sample code and the output: + +- The produced YAML (and XML/JSON) consists of heterogeneous collections that can be nested. There are + 2 types of collections: named collections (mappings) and unnamed collections (sequences). In mappings + each element has a name and is accessed by name. This is similar to structures and std::map in + C/C++ and dictionaries in Python. In sequences elements do not have names, they are accessed by + indices. This is similar to arrays and std::vector in C/C++ and lists, tuples in Python. + "Heterogeneous" means that elements of each single collection can have different types. + + Top-level collection in YAML/XML/JSON is a mapping. Each matrix is stored as a mapping, and the matrix + elements are stored as a sequence. Then, there is a sequence of features, where each feature is + represented a mapping, and lbp value in a nested sequence. + +- When you write to a mapping (a structure), you write element name followed by its value. When you + write to a sequence, you simply write the elements one by one. OpenCV data structures (such as + cv::Mat) are written in absolutely the same way as simple C data structures - using `<<` + operator. + +- To write a mapping, you first write the special string `{` to the storage, then write the + elements as pairs (`fs << << `) and then write the closing + `}`. + +- To write a sequence, you first write the special string `[`, then write the elements, then + write the closing `]`. + +- In YAML/JSON (but not XML), mappings and sequences can be written in a compact Python-like inline + form. In the sample above matrix elements, as well as each feature, including its lbp value, is + stored in such inline form. To store a mapping/sequence in a compact form, put `:` after the + opening character, e.g. use `{:` instead of `{` and `[:` instead of `[`. When the + data is written to XML, those extra `:` are ignored. + +Reading data from a file storage. +--------------------------------- +To read the previously written XML, YAML or JSON file, do the following: +-# Open the file storage using FileStorage::FileStorage constructor or FileStorage::open method. + In the current implementation the whole file is parsed and the whole representation of file + storage is built in memory as a hierarchy of file nodes (see FileNode) + +-# Read the data you are interested in. Use FileStorage::operator [], FileNode::operator [] + and/or FileNodeIterator. + +-# Close the storage using FileStorage::release. + +Here is how to read the file created by the code sample above: +@code + FileStorage fs2("test.yml", FileStorage::READ); + + // first method: use (type) operator on FileNode. + int frameCount = (int)fs2["frameCount"]; + + String date; + // second method: use FileNode::operator >> + fs2["calibrationDate"] >> date; + + Mat cameraMatrix2, distCoeffs2; + fs2["cameraMatrix"] >> cameraMatrix2; + fs2["distCoeffs"] >> distCoeffs2; + + cout << "frameCount: " << frameCount << endl + << "calibration date: " << date << endl + << "camera matrix: " << cameraMatrix2 << endl + << "distortion coeffs: " << distCoeffs2 << endl; + + FileNode features = fs2["features"]; + FileNodeIterator it = features.begin(), it_end = features.end(); + int idx = 0; + std::vector lbpval; + + // iterate through a sequence using FileNodeIterator + for( ; it != it_end; ++it, idx++ ) + { + cout << "feature #" << idx << ": "; + cout << "x=" << (int)(*it)["x"] << ", y=" << (int)(*it)["y"] << ", lbp: ("; + // you can also easily read numerical arrays using FileNode >> std::vector operator. + (*it)["lbp"] >> lbpval; + for( int i = 0; i < (int)lbpval.size(); i++ ) + cout << " " << (int)lbpval[i]; + cout << ")" << endl; + } + fs2.release(); +@endcode + +Format specification {#format_spec} +-------------------- +`([count]{u|c|w|s|i|f|d})`... where the characters correspond to fundamental C++ types: +- `u` 8-bit unsigned number +- `c` 8-bit signed number +- `w` 16-bit unsigned number +- `s` 16-bit signed number +- `i` 32-bit signed number +- `f` single precision floating-point number +- `d` double precision floating-point number +- `r` pointer, 32 lower bits of which are written as a signed integer. The type can be used to + store structures with links between the elements. + +`count` is the optional counter of values of a given type. For example, `2if` means that each array +element is a structure of 2 integers, followed by a single-precision floating-point number. The +equivalent notations of the above specification are `iif`, `2i1f` and so forth. Other examples: `u` +means that the array consists of bytes, and `2d` means the array consists of pairs of doubles. + +@see @ref samples/cpp/filestorage.cpp +*/ + +//! @{ + +/** @example samples/cpp/filestorage.cpp +A complete example using the FileStorage interface +*/ + +////////////////////////// XML & YAML I/O ////////////////////////// + +class CV_EXPORTS FileNode; +class CV_EXPORTS FileNodeIterator; + +/** @brief XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or +reading data to/from a file. + */ +class CV_EXPORTS_W FileStorage +{ +public: + //! file storage mode + enum Mode + { + READ = 0, //!< value, open the file for reading + WRITE = 1, //!< value, open the file for writing + APPEND = 2, //!< value, open the file for appending + MEMORY = 4, //!< flag, read data from source or write data to the internal buffer (which is + //!< returned by FileStorage::release) + FORMAT_MASK = (7<<3), //!< mask for format flags + FORMAT_AUTO = 0, //!< flag, auto format + FORMAT_XML = (1<<3), //!< flag, XML format + FORMAT_YAML = (2<<3), //!< flag, YAML format + FORMAT_JSON = (3<<3), //!< flag, JSON format + + BASE64 = 64, //!< flag, write rawdata in Base64 by default. (consider using WRITE_BASE64) + WRITE_BASE64 = BASE64 | WRITE, //!< flag, enable both WRITE and BASE64 + }; + enum State + { + UNDEFINED = 0, + VALUE_EXPECTED = 1, + NAME_EXPECTED = 2, + INSIDE_MAP = 4 + }; + + /** @brief The constructors. + + The full constructor opens the file. Alternatively you can use the default constructor and then + call FileStorage::open. + */ + CV_WRAP FileStorage(); + + /** @overload + @copydoc open() + */ + CV_WRAP FileStorage(const String& filename, int flags, const String& encoding=String()); + + //! the destructor. calls release() + virtual ~FileStorage(); + + /** @brief Opens a file. + + See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release + before opening the file. + @param filename Name of the file to open or the text string to read the data from. + Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON + respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both + FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify + the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. + You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to + FileStorage::BASE64 flag. + @param flags Mode of operation. One of FileStorage::Mode + @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and + you should use 8-bit encoding instead of it. + */ + CV_WRAP virtual bool open(const String& filename, int flags, const String& encoding=String()); + + /** @brief Checks whether the file is opened. + + @returns true if the object is associated with the current file and false otherwise. It is a + good practice to call this method after you tried to open a file. + */ + CV_WRAP virtual bool isOpened() const; + + /** @brief Closes the file and releases all the memory buffers. + + Call this method after all I/O operations with the storage are finished. + */ + CV_WRAP virtual void release(); + + /** @brief Closes the file and releases all the memory buffers. + + Call this method after all I/O operations with the storage are finished. If the storage was + opened for writing data and FileStorage::WRITE was specified + */ + CV_WRAP virtual String releaseAndGetString(); + + /** @brief Returns the first element of the top-level mapping. + @returns The first element of the top-level mapping. + */ + CV_WRAP FileNode getFirstTopLevelNode() const; + + /** @brief Returns the top-level mapping + @param streamidx Zero-based index of the stream. In most cases there is only one stream in the file. + However, YAML supports multiple streams and so there can be several. + @returns The top-level mapping. + */ + CV_WRAP FileNode root(int streamidx=0) const; + + /** @brief Returns the specified element of the top-level mapping. + @param nodename Name of the file node. + @returns Node with the given name. + */ + FileNode operator[](const String& nodename) const; + + /** @overload */ + CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; + + /** + * @brief Simplified writing API to use with bindings. + * @param name Name of the written object + * @param val Value of the written object + */ + CV_WRAP void write(const String& name, int val); + /// @overload + CV_WRAP void write(const String& name, double val); + /// @overload + CV_WRAP void write(const String& name, const String& val); + /// @overload + CV_WRAP void write(const String& name, const Mat& val); + /// @overload + CV_WRAP void write(const String& name, const std::vector& val); + + /** @brief Writes multiple numbers. + + Writes one or more numbers of the specified format to the currently written structure. Usually it is + more convenient to use operator `<<` instead of this method. + @param fmt Specification of each array element, see @ref format_spec "format specification" + @param vec Pointer to the written array. + @param len Number of the uchar elements to write. + */ + void writeRaw( const String& fmt, const void* vec, size_t len ); + + /** @brief Writes a comment. + + The function writes a comment into file storage. The comments are skipped when the storage is read. + @param comment The written comment, single-line or multi-line + @param append If true, the function tries to put the comment at the end of current line. + Else if the comment is multi-line, or if it does not fit at the end of the current + line, the comment starts a new line. + */ + CV_WRAP void writeComment(const String& comment, bool append = false); + + void startWriteStruct(const String& name, int flags, const String& typeName); + void endWriteStruct(); + + /** @brief Returns the normalized object name for the specified name of a file. + @param filename Name of a file + @returns The normalized object name. + */ + static String getDefaultObjectName(const String& filename); + + /** @brief Returns the current format. + * @returns The current format, see FileStorage::Mode + */ + CV_WRAP int getFormat() const; + + int state; + std::string elname; + + class Impl; + Ptr p; +}; + +/** @brief File Storage Node class. + +The node is used to store each and every element of the file storage opened for reading. When +XML/YAML file is read, it is first parsed and stored in the memory as a hierarchical collection of +nodes. Each node can be a "leaf" that is contain a single number or a string, or be a collection of +other nodes. There can be named collections (mappings) where each element has a name and it is +accessed by a name, and ordered collections (sequences) where elements do not have names but rather +accessed by index. Type of the file node can be determined using FileNode::type method. + +Note that file nodes are only used for navigating file storages opened for reading. When a file +storage is opened for writing, no data is stored in memory after it is written. + */ +class CV_EXPORTS_W_SIMPLE FileNode +{ +public: + //! type of the file storage node + enum + { + NONE = 0, //!< empty node + INT = 1, //!< an integer + REAL = 2, //!< floating-point number + FLOAT = REAL, //!< synonym or REAL + STR = 3, //!< text string in UTF-8 encoding + STRING = STR, //!< synonym for STR + SEQ = 4, //!< sequence + MAP = 5, //!< mapping + TYPE_MASK = 7, + + FLOW = 8, //!< compact representation of a sequence or mapping. Used only by YAML writer + UNIFORM = 8, //!< if set, means that all the collection elements are numbers of the same type (real's or int's). + //!< UNIFORM is used only when reading FileStorage; FLOW is used only when writing. So they share the same bit + EMPTY = 16, //!< empty structure (sequence or mapping) + NAMED = 32 //!< the node has a name (i.e. it is element of a mapping). + }; + /** @brief The constructors. + + These constructors are used to create a default file node, construct it from obsolete structures or + from the another file node. + */ + CV_WRAP FileNode(); + + /** @overload + @param fs Pointer to the file storage structure. + @param blockIdx Index of the memory block where the file node is stored + @param ofs Offset in bytes from the beginning of the serialized storage + */ + FileNode(const FileStorage* fs, size_t blockIdx, size_t ofs); + + /** @overload + @param node File node to be used as initialization for the created file node. + */ + FileNode(const FileNode& node); + + FileNode& operator=(const FileNode& node); + + /** @brief Returns element of a mapping node or a sequence node. + @param nodename Name of an element in the mapping node. + @returns Returns the element with the given identifier. + */ + FileNode operator[](const String& nodename) const; + + /** @overload + @param nodename Name of an element in the mapping node. + */ + CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; + + /** @overload + @param i Index of an element in the sequence node. + */ + CV_WRAP_AS(at) FileNode operator[](int i) const; + + /** @brief Returns keys of a mapping node. + @returns Keys of a mapping node. + */ + CV_WRAP std::vector keys() const; + + /** @brief Returns type of the node. + @returns Type of the node. See FileNode::Type + */ + CV_WRAP int type() const; + + //! returns true if the node is empty + CV_WRAP bool empty() const; + //! returns true if the node is a "none" object + CV_WRAP bool isNone() const; + //! returns true if the node is a sequence + CV_WRAP bool isSeq() const; + //! returns true if the node is a mapping + CV_WRAP bool isMap() const; + //! returns true if the node is an integer + CV_WRAP bool isInt() const; + //! returns true if the node is a floating-point number + CV_WRAP bool isReal() const; + //! returns true if the node is a text string + CV_WRAP bool isString() const; + //! returns true if the node has a name + CV_WRAP bool isNamed() const; + //! returns the node name or an empty string if the node is nameless + CV_WRAP std::string name() const; + //! returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise. + CV_WRAP size_t size() const; + //! returns raw size of the FileNode in bytes + CV_WRAP size_t rawSize() const; + //! returns the node content as an integer. If the node stores floating-point number, it is rounded. + operator int() const; + //! returns the node content as float + operator float() const; + //! returns the node content as double + operator double() const; + //! returns the node content as text string + inline operator std::string() const { return this->string(); } + + static bool isMap(int flags); + static bool isSeq(int flags); + static bool isCollection(int flags); + static bool isEmptyCollection(int flags); + static bool isFlow(int flags); + + uchar* ptr(); + const uchar* ptr() const; + + //! returns iterator pointing to the first node element + FileNodeIterator begin() const; + //! returns iterator pointing to the element following the last node element + FileNodeIterator end() const; + + /** @brief Reads node elements to the buffer with the specified format. + + Usually it is more convenient to use operator `>>` instead of this method. + @param fmt Specification of each array element. See @ref format_spec "format specification" + @param vec Pointer to the destination array. + @param len Number of bytes to read (buffer size limit). If it is greater than number of + remaining elements then all of them will be read. + */ + void readRaw( const String& fmt, void* vec, size_t len ) const; + + /** Internal method used when reading FileStorage. + Sets the type (int, real or string) and value of the previously created node. + */ + void setValue( int type, const void* value, int len=-1 ); + + //! Simplified reading API to use with bindings. + CV_WRAP double real() const; + //! Simplified reading API to use with bindings. + CV_WRAP std::string string() const; + //! Simplified reading API to use with bindings. + CV_WRAP Mat mat() const; + + //protected: + const FileStorage* fs; + size_t blockIdx; + size_t ofs; +}; + + +/** @brief used to iterate through sequences and mappings. + + A standard STL notation, with node.begin(), node.end() denoting the beginning and the end of a + sequence, stored in node. See the data reading sample in the beginning of the section. + */ +class CV_EXPORTS FileNodeIterator +{ +public: + /** @brief The constructors. + + These constructors are used to create a default iterator, set it to specific element in a file node + or construct it from another iterator. + */ + FileNodeIterator(); + + /** @overload + @param node File node - the collection to iterate over; + it can be a scalar (equivalent to 1-element collection) or "none" (equivalent to empty collection). + @param seekEnd - true if iterator needs to be set after the last element of the node; + that is: + * node.begin() => FileNodeIterator(node, false) + * node.end() => FileNodeIterator(node, true) + */ + FileNodeIterator(const FileNode& node, bool seekEnd); + + /** @overload + @param it Iterator to be used as initialization for the created iterator. + */ + FileNodeIterator(const FileNodeIterator& it); + + FileNodeIterator& operator=(const FileNodeIterator& it); + + //! returns the currently observed element + FileNode operator *() const; + + //! moves iterator to the next node + FileNodeIterator& operator ++ (); + //! moves iterator to the next node + FileNodeIterator operator ++ (int); + //! moves iterator forward by the specified offset (possibly negative) + FileNodeIterator& operator += (int ofs); + + /** @brief Reads node elements to the buffer with the specified format. + + Usually it is more convenient to use operator `>>` instead of this method. + @param fmt Specification of each array element. See @ref format_spec "format specification" + @param vec Pointer to the destination array. + @param len Number of bytes to read (buffer size limit). If it is greater than number of + remaining elements then all of them will be read. + */ + FileNodeIterator& readRaw( const String& fmt, void* vec, + size_t len=(size_t)INT_MAX ); + + //! returns the number of remaining (not read yet) elements + size_t remaining() const; + + bool equalTo(const FileNodeIterator& it) const; + +protected: + const FileStorage* fs; + size_t blockIdx; + size_t ofs; + size_t blockSize; + size_t nodeNElems; + size_t idx; +}; + +//! @} core_xml + +/////////////////// XML & YAML I/O implementation ////////////////// + +//! @relates cv::FileStorage +//! @{ + +CV_EXPORTS void write( FileStorage& fs, const String& name, int value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, float value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, double value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, const String& value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, const Mat& value ); +CV_EXPORTS void write( FileStorage& fs, const String& name, const SparseMat& value ); +#ifdef CV__LEGACY_PERSISTENCE +CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector& value); +CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector& value); +#endif + +CV_EXPORTS void writeScalar( FileStorage& fs, int value ); +CV_EXPORTS void writeScalar( FileStorage& fs, float value ); +CV_EXPORTS void writeScalar( FileStorage& fs, double value ); +CV_EXPORTS void writeScalar( FileStorage& fs, const String& value ); + +//! @} + +//! @relates cv::FileNode +//! @{ + +CV_EXPORTS void read(const FileNode& node, int& value, int default_value); +CV_EXPORTS void read(const FileNode& node, float& value, float default_value); +CV_EXPORTS void read(const FileNode& node, double& value, double default_value); +CV_EXPORTS void read(const FileNode& node, std::string& value, const std::string& default_value); +CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() ); +CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() ); +#ifdef CV__LEGACY_PERSISTENCE +CV_EXPORTS void read(const FileNode& node, std::vector& keypoints); +CV_EXPORTS void read(const FileNode& node, std::vector& matches); +#endif +CV_EXPORTS void read(const FileNode& node, KeyPoint& value, const KeyPoint& default_value); +CV_EXPORTS void read(const FileNode& node, DMatch& value, const DMatch& default_value); + +template static inline void read(const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Point_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template static inline void read(const FileNode& node, Point3_<_Tp>& value, const Point3_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 3 ? default_value : Point3_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2])); +} + +template static inline void read(const FileNode& node, Size_<_Tp>& value, const Size_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Size_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template static inline void read(const FileNode& node, Complex<_Tp>& value, const Complex<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 2 ? default_value : Complex<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); +} + +template static inline void read(const FileNode& node, Rect_<_Tp>& value, const Rect_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 4 ? default_value : Rect_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); +} + +template static inline void read(const FileNode& node, Vec<_Tp, cn>& value, const Vec<_Tp, cn>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != cn ? default_value : Vec<_Tp, cn>(&temp[0]); +} + +template static inline void read(const FileNode& node, Matx<_Tp, m, n>& value, const Matx<_Tp, m, n>& default_matx = Matx<_Tp, m, n>()) +{ + Mat temp; + read(node, temp); // read as a Mat class + + if (temp.empty()) + value = default_matx; + else + value = Matx<_Tp, m, n>(temp); +} + +template static inline void read(const FileNode& node, Scalar_<_Tp>& value, const Scalar_<_Tp>& default_value) +{ + std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; + value = temp.size() != 4 ? default_value : Scalar_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), + saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); +} + +static inline void read(const FileNode& node, Range& value, const Range& default_value) +{ + Point2i temp(value.start, value.end); const Point2i default_temp = Point2i(default_value.start, default_value.end); + read(node, temp, default_temp); + value.start = temp.x; value.end = temp.y; +} + +//! @} + +/** @brief Writes string to a file storage. +@relates cv::FileStorage + */ +CV_EXPORTS FileStorage& operator << (FileStorage& fs, const String& str); + +//! @cond IGNORED + +namespace internal +{ + class CV_EXPORTS WriteStructContext + { + public: + WriteStructContext(FileStorage& _fs, const String& name, int flags, const String& typeName = String()); + ~WriteStructContext(); + private: + FileStorage* fs; + }; + + template class VecWriterProxy + { + public: + VecWriterProxy( FileStorage* _fs ) : fs(_fs) {} + void operator()(const std::vector<_Tp>& vec) const + { + size_t count = vec.size(); + for (size_t i = 0; i < count; i++) + write(*fs, vec[i]); + } + private: + FileStorage* fs; + }; + + template class VecWriterProxy<_Tp, 1> + { + public: + VecWriterProxy( FileStorage* _fs ) : fs(_fs) {} + void operator()(const std::vector<_Tp>& vec) const + { + int _fmt = traits::SafeFmt<_Tp>::fmt; + char fmt[] = { (char)((_fmt >> 8) + '1'), (char)_fmt, '\0' }; + fs->writeRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, vec.size() * sizeof(_Tp)); + } + private: + FileStorage* fs; + }; + + template class VecReaderProxy + { + public: + VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} + void operator()(std::vector<_Tp>& vec, size_t count) const + { + count = std::min(count, it->remaining()); + vec.resize(count); + for (size_t i = 0; i < count; i++, ++(*it)) + read(**it, vec[i], _Tp()); + } + private: + FileNodeIterator* it; + }; + + template class VecReaderProxy<_Tp, 1> + { + public: + VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} + void operator()(std::vector<_Tp>& vec, size_t count) const + { + size_t remaining = it->remaining(); + size_t cn = DataType<_Tp>::channels; + int _fmt = traits::SafeFmt<_Tp>::fmt; + CV_Assert((_fmt >> 8) < 9); + char fmt[] = { (char)((_fmt >> 8)+'1'), (char)_fmt, '\0' }; + CV_Assert((remaining % cn) == 0); + size_t remaining1 = remaining / cn; + count = count > remaining1 ? remaining1 : count; + vec.resize(count); + it->readRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp)); + } + private: + FileNodeIterator* it; + }; + +} // internal + +//! @endcond + +//! @relates cv::FileStorage +//! @{ + +template static inline +void write(FileStorage& fs, const _Tp& value) +{ + write(fs, String(), value); +} + +template<> inline +void write( FileStorage& fs, const int& value ) +{ + writeScalar(fs, value); +} + +template<> inline +void write( FileStorage& fs, const float& value ) +{ + writeScalar(fs, value); +} + +template<> inline +void write( FileStorage& fs, const double& value ) +{ + writeScalar(fs, value); +} + +template<> inline +void write( FileStorage& fs, const String& value ) +{ + writeScalar(fs, value); +} + +template static inline +void write(FileStorage& fs, const Point_<_Tp>& pt ) +{ + write(fs, pt.x); + write(fs, pt.y); +} + +template static inline +void write(FileStorage& fs, const Point3_<_Tp>& pt ) +{ + write(fs, pt.x); + write(fs, pt.y); + write(fs, pt.z); +} + +template static inline +void write(FileStorage& fs, const Size_<_Tp>& sz ) +{ + write(fs, sz.width); + write(fs, sz.height); +} + +template static inline +void write(FileStorage& fs, const Complex<_Tp>& c ) +{ + write(fs, c.re); + write(fs, c.im); +} + +template static inline +void write(FileStorage& fs, const Rect_<_Tp>& r ) +{ + write(fs, r.x); + write(fs, r.y); + write(fs, r.width); + write(fs, r.height); +} + +template static inline +void write(FileStorage& fs, const Vec<_Tp, cn>& v ) +{ + for(int i = 0; i < cn; i++) + write(fs, v.val[i]); +} + +template static inline +void write(FileStorage& fs, const Matx<_Tp, m, n>& x ) +{ + write(fs, Mat(x)); // write as a Mat class +} + +template static inline +void write(FileStorage& fs, const Scalar_<_Tp>& s ) +{ + write(fs, s.val[0]); + write(fs, s.val[1]); + write(fs, s.val[2]); + write(fs, s.val[3]); +} + +static inline +void write(FileStorage& fs, const Range& r ) +{ + write(fs, r.start); + write(fs, r.end); +} + +template static inline +void write( FileStorage& fs, const std::vector<_Tp>& vec ) +{ + cv::internal::VecWriterProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> w(&fs); + w(vec); +} + +template static inline +void write(FileStorage& fs, const String& name, const Point_<_Tp>& pt ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, pt); +} + +template static inline +void write(FileStorage& fs, const String& name, const Point3_<_Tp>& pt ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, pt); +} + +template static inline +void write(FileStorage& fs, const String& name, const Size_<_Tp>& sz ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, sz); +} + +template static inline +void write(FileStorage& fs, const String& name, const Complex<_Tp>& c ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, c); +} + +template static inline +void write(FileStorage& fs, const String& name, const Rect_<_Tp>& r ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, r); +} + +template static inline +void write(FileStorage& fs, const String& name, const Vec<_Tp, cn>& v ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, v); +} + +template static inline +void write(FileStorage& fs, const String& name, const Matx<_Tp, m, n>& x ) +{ + write(fs, name, Mat(x)); // write as a Mat class +} + +template static inline +void write(FileStorage& fs, const String& name, const Scalar_<_Tp>& s ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, s); +} + +static inline +void write(FileStorage& fs, const String& name, const Range& r ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, r); +} + +static inline +void write(FileStorage& fs, const String& name, const KeyPoint& kpt) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, kpt.pt.x); + write(fs, kpt.pt.y); + write(fs, kpt.size); + write(fs, kpt.angle); + write(fs, kpt.response); + write(fs, kpt.octave); + write(fs, kpt.class_id); +} + +static inline +void write(FileStorage& fs, const String& name, const DMatch& m) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); + write(fs, m.queryIdx); + write(fs, m.trainIdx); + write(fs, m.imgIdx); + write(fs, m.distance); +} + +template::value >::type* = nullptr> +static inline void write( FileStorage& fs, const String& name, const _Tp& val ) +{ + write(fs, name, static_cast(val)); +} + +template static inline +void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); + write(fs, vec); +} + +template static inline +void write( FileStorage& fs, const String& name, const std::vector< std::vector<_Tp> >& vec ) +{ + cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ); + for(size_t i = 0; i < vec.size(); i++) + { + cv::internal::WriteStructContext ws_(fs, name, FileNode::SEQ+(traits::SafeFmt<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); + write(fs, vec[i]); + } +} + +#ifdef CV__LEGACY_PERSISTENCE +// This code is not needed anymore, but it is preserved here to keep source compatibility +// Implementation is similar to templates instantiations +static inline void write(FileStorage& fs, const KeyPoint& kpt) { write(fs, String(), kpt); } +static inline void write(FileStorage& fs, const DMatch& m) { write(fs, String(), m); } +static inline void write(FileStorage& fs, const std::vector& vec) +{ + cv::internal::VecWriterProxy w(&fs); + w(vec); +} +static inline void write(FileStorage& fs, const std::vector& vec) +{ + cv::internal::VecWriterProxy w(&fs); + w(vec); + +} +#endif + +//! @} FileStorage + +//! @relates cv::FileNode +//! @{ + +static inline +void read(const FileNode& node, bool& value, bool default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = temp != 0; +} + +static inline +void read(const FileNode& node, uchar& value, uchar default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast(temp); +} + +static inline +void read(const FileNode& node, schar& value, schar default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast(temp); +} + +static inline +void read(const FileNode& node, ushort& value, ushort default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast(temp); +} + +static inline +void read(const FileNode& node, short& value, short default_value) +{ + int temp; + read(node, temp, (int)default_value); + value = saturate_cast(temp); +} + +template static inline +void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_t)INT_MAX ) +{ + cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it); + r(vec, maxCount); +} + +template::value >::type* = nullptr> +static inline void read(const FileNode& node, _Tp& value, const _Tp& default_value = static_cast<_Tp>(0)) +{ + int temp; + read(node, temp, static_cast(default_value)); + value = static_cast<_Tp>(temp); +} + +template static inline +void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& default_value = std::vector<_Tp>() ) +{ + if(node.empty()) + vec = default_value; + else + { + FileNodeIterator it = node.begin(); + read( it, vec ); + } +} + +static inline +void read( const FileNode& node, std::vector& vec, const std::vector& default_value ) +{ + if(node.empty()) + vec = default_value; + else + read(node, vec); +} + +static inline +void read( const FileNode& node, std::vector& vec, const std::vector& default_value ) +{ + if(node.empty()) + vec = default_value; + else + read(node, vec); +} + +//! @} FileNode + +//! @relates cv::FileStorage +//! @{ + +/** @brief Writes data to a file storage. + */ +template static inline +FileStorage& operator << (FileStorage& fs, const _Tp& value) +{ + if( !fs.isOpened() ) + return fs; + if( fs.state == FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP ) + CV_Error( Error::StsError, "No element name has been given" ); + write( fs, fs.elname, value ); + if( fs.state & FileStorage::INSIDE_MAP ) + fs.state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP; + return fs; +} + +/** @brief Writes data to a file storage. + */ +static inline +FileStorage& operator << (FileStorage& fs, const char* str) +{ + return (fs << String(str)); +} + +/** @brief Writes data to a file storage. + */ +static inline +FileStorage& operator << (FileStorage& fs, char* value) +{ + return (fs << String(value)); +} + +//! @} FileStorage + +//! @relates cv::FileNodeIterator +//! @{ + +/** @brief Reads data from a file storage. + */ +template static inline +FileNodeIterator& operator >> (FileNodeIterator& it, _Tp& value) +{ + read( *it, value, _Tp()); + return ++it; +} + +/** @brief Reads data from a file storage. + */ +template static inline +FileNodeIterator& operator >> (FileNodeIterator& it, std::vector<_Tp>& vec) +{ + cv::internal::VecReaderProxy<_Tp, traits::SafeFmt<_Tp>::fmt != 0> r(&it); + r(vec, (size_t)INT_MAX); + return it; +} + +//! @} FileNodeIterator + +//! @relates cv::FileNode +//! @{ + +/** @brief Reads data from a file storage. + */ +template static inline +void operator >> (const FileNode& n, _Tp& value) +{ + read( n, value, _Tp()); +} + +/** @brief Reads data from a file storage. + */ +template static inline +void operator >> (const FileNode& n, std::vector<_Tp>& vec) +{ + FileNodeIterator it = n.begin(); + it >> vec; +} + +/** @brief Reads KeyPoint from a file storage. +*/ +//It needs special handling because it contains two types of fields, int & float. +static inline +void operator >> (const FileNode& n, KeyPoint& kpt) +{ + FileNodeIterator it = n.begin(); + it >> kpt.pt.x >> kpt.pt.y >> kpt.size >> kpt.angle >> kpt.response >> kpt.octave >> kpt.class_id; +} + +#ifdef CV__LEGACY_PERSISTENCE +static inline +void operator >> (const FileNode& n, std::vector& vec) +{ + read(n, vec); +} +static inline +void operator >> (const FileNode& n, std::vector& vec) +{ + read(n, vec); +} +#endif + +/** @brief Reads DMatch from a file storage. +*/ +//It needs special handling because it contains two types of fields, int & float. +static inline +void operator >> (const FileNode& n, DMatch& m) +{ + FileNodeIterator it = n.begin(); + it >> m.queryIdx >> m.trainIdx >> m.imgIdx >> m.distance; +} + +//! @} FileNode + +//! @relates cv::FileNodeIterator +//! @{ + +CV_EXPORTS bool operator == (const FileNodeIterator& it1, const FileNodeIterator& it2); +CV_EXPORTS bool operator != (const FileNodeIterator& it1, const FileNodeIterator& it2); + +static inline +ptrdiff_t operator - (const FileNodeIterator& it1, const FileNodeIterator& it2) +{ + return it2.remaining() - it1.remaining(); +} + +static inline +bool operator < (const FileNodeIterator& it1, const FileNodeIterator& it2) +{ + return it1.remaining() > it2.remaining(); +} + +//! @} FileNodeIterator + +} // cv + +#endif // OPENCV_CORE_PERSISTENCE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/saturate.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/saturate.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8127e3d9ef2f6ad7c31d932f13548dbd465d94c9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/saturate.hpp @@ -0,0 +1,179 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2014, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_SATURATE_HPP +#define OPENCV_CORE_SATURATE_HPP + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/fast_math.hpp" + +namespace cv +{ + +//! @addtogroup core_utils +//! @{ + +/////////////// saturate_cast (used in image & signal processing) /////////////////// + +/** @brief Template function for accurate conversion from one primitive type to another. + + The function saturate_cast resembles the standard C++ cast operations, such as static_cast\() + and others. It perform an efficient and accurate conversion from one primitive type to another + (see the introduction chapter). saturate in the name means that when the input value v is out of the + range of the target type, the result is not formed just by taking low bits of the input, but instead + the value is clipped. For example: + @code + uchar a = saturate_cast(-100); // a = 0 (UCHAR_MIN) + short b = saturate_cast(33333.33333); // b = 32767 (SHRT_MAX) + @endcode + Such clipping is done when the target type is unsigned char , signed char , unsigned short or + signed short . For 32-bit integers, no clipping is done. + + When the parameter is a floating-point value and the target type is an integer (8-, 16- or 32-bit), + the floating-point value is first rounded to the nearest integer and then clipped if needed (when + the target type is 8- or 16-bit). + + @param v Function parameter. + @sa add, subtract, multiply, divide, Mat::convertTo + */ +template static inline _Tp saturate_cast(uchar v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(schar v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(ushort v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(short v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(unsigned v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(int v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(float v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(double v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(int64 v) { return _Tp(v); } +/** @overload */ +template static inline _Tp saturate_cast(uint64 v) { return _Tp(v); } + +template<> inline uchar saturate_cast(schar v) { return (uchar)std::max((int)v, 0); } +template<> inline uchar saturate_cast(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); } +template<> inline uchar saturate_cast(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } +template<> inline uchar saturate_cast(short v) { return saturate_cast((int)v); } +template<> inline uchar saturate_cast(unsigned v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); } +template<> inline uchar saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline uchar saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline uchar saturate_cast(int64 v) { return (uchar)((uint64)v <= (uint64)UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } +template<> inline uchar saturate_cast(uint64 v) { return (uchar)std::min(v, (uint64)UCHAR_MAX); } + +template<> inline schar saturate_cast(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); } +template<> inline schar saturate_cast(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); } +template<> inline schar saturate_cast(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } +template<> inline schar saturate_cast(short v) { return saturate_cast((int)v); } +template<> inline schar saturate_cast(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); } +template<> inline schar saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline schar saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline schar saturate_cast(int64 v) { return (schar)((uint64)((int64)v-SCHAR_MIN) <= (uint64)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } +template<> inline schar saturate_cast(uint64 v) { return (schar)std::min(v, (uint64)SCHAR_MAX); } + +template<> inline ushort saturate_cast(schar v) { return (ushort)std::max((int)v, 0); } +template<> inline ushort saturate_cast(short v) { return (ushort)std::max((int)v, 0); } +template<> inline ushort saturate_cast(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } +template<> inline ushort saturate_cast(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); } +template<> inline ushort saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline ushort saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline ushort saturate_cast(int64 v) { return (ushort)((uint64)v <= (uint64)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } +template<> inline ushort saturate_cast(uint64 v) { return (ushort)std::min(v, (uint64)USHRT_MAX); } + +template<> inline short saturate_cast(ushort v) { return (short)std::min((int)v, SHRT_MAX); } +template<> inline short saturate_cast(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } +template<> inline short saturate_cast(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); } +template<> inline short saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline short saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline short saturate_cast(int64 v) { return (short)((uint64)((int64)v - SHRT_MIN) <= (uint64)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } +template<> inline short saturate_cast(uint64 v) { return (short)std::min(v, (uint64)SHRT_MAX); } + +template<> inline int saturate_cast(unsigned v) { return (int)std::min(v, (unsigned)INT_MAX); } +template<> inline int saturate_cast(int64 v) { return (int)((uint64)(v - INT_MIN) <= (uint64)UINT_MAX ? v : v > 0 ? INT_MAX : INT_MIN); } +template<> inline int saturate_cast(uint64 v) { return (int)std::min(v, (uint64)INT_MAX); } +template<> inline int saturate_cast(float v) { return cvRound(v); } +template<> inline int saturate_cast(double v) { return cvRound(v); } + +template<> inline unsigned saturate_cast(schar v) { return (unsigned)std::max(v, (schar)0); } +template<> inline unsigned saturate_cast(short v) { return (unsigned)std::max(v, (short)0); } +template<> inline unsigned saturate_cast(int v) { return (unsigned)std::max(v, (int)0); } +template<> inline unsigned saturate_cast(int64 v) { return (unsigned)((uint64)v <= (uint64)UINT_MAX ? v : v > 0 ? UINT_MAX : 0); } +template<> inline unsigned saturate_cast(uint64 v) { return (unsigned)std::min(v, (uint64)UINT_MAX); } +// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. +template<> inline unsigned saturate_cast(float v) { return static_cast(cvRound(v)); } +template<> inline unsigned saturate_cast(double v) { return static_cast(cvRound(v)); } + +template<> inline uint64 saturate_cast(schar v) { return (uint64)std::max(v, (schar)0); } +template<> inline uint64 saturate_cast(short v) { return (uint64)std::max(v, (short)0); } +template<> inline uint64 saturate_cast(int v) { return (uint64)std::max(v, (int)0); } +template<> inline uint64 saturate_cast(int64 v) { return (uint64)std::max(v, (int64)0); } + +template<> inline int64 saturate_cast(uint64 v) { return (int64)std::min(v, (uint64)LLONG_MAX); } + +/** @overload */ +template static inline _Tp saturate_cast(float16_t v) { return saturate_cast<_Tp>((float)v); } + +// in theory, we could use a LUT for 8u/8s->16f conversion, +// but with hardware support for FP32->FP16 conversion the current approach is preferable +template<> inline float16_t saturate_cast(uchar v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(schar v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(ushort v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(short v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(unsigned v){ return float16_t((float)v); } +template<> inline float16_t saturate_cast(int v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(uint64 v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(int64 v) { return float16_t((float)v); } +template<> inline float16_t saturate_cast(float v) { return float16_t(v); } +template<> inline float16_t saturate_cast(double v) { return float16_t((float)v); } + +//! @} + +} // cv + +#endif // OPENCV_CORE_SATURATE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/simd_intrinsics.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/simd_intrinsics.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c50923f0ef8375335d8cc06d1bb40cf4557afd05 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/simd_intrinsics.hpp @@ -0,0 +1,88 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_SIMD_INTRINSICS_HPP +#define OPENCV_CORE_SIMD_INTRINSICS_HPP + +/** +Helper header to support SIMD intrinsics (universal intrinsics) in user code. +Intrinsics documentation: https://docs.opencv.org/master/df/d91/group__core__hal__intrin.html + + +Checks of target CPU instruction set based on compiler definitions don't work well enough. +More reliable solutions require utilization of configuration systems (like CMake). + +So, probably you need to specify your own configuration. + +You can do that via CMake in this way: + add_definitions(/DOPENCV_SIMD_CONFIG_HEADER=opencv_simd_config_custom.hpp) +or + add_definitions(/DOPENCV_SIMD_CONFIG_INCLUDE_DIR=1) + +Additionally you may need to add include directory to your files: + include_directories("${CMAKE_CURRENT_LIST_DIR}/opencv_config_${MYTARGET}") + +These files can be pre-generated for target configurations of your application +or generated by CMake on the fly (use CMAKE_BINARY_DIR for that). + +Notes: +- H/W capability checks are still responsibility of your application +- runtime dispatching is not covered by this helper header +*/ + +#ifdef __OPENCV_BUILD +#error "Use core/hal/intrin.hpp during OpenCV build" +#endif + +#ifdef OPENCV_HAL_INTRIN_HPP +#error "core/simd_intrinsics.hpp must be included before core/hal/intrin.hpp" +#endif + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/version.hpp" + +#ifdef OPENCV_SIMD_CONFIG_HEADER +#include CVAUX_STR(OPENCV_SIMD_CONFIG_HEADER) +#elif defined(OPENCV_SIMD_CONFIG_INCLUDE_DIR) +#include "opencv_simd_config.hpp" // corresponding directory should be added via -I compiler parameter +#else // custom config headers + +#if (!defined(CV_AVX_512F) || !CV_AVX_512F) && (defined(__AVX512__) || defined(__AVX512F__)) +# include +# undef CV_AVX_512F +# define CV_AVX_512F 1 +# ifndef OPENCV_SIMD_DONT_ASSUME_SKX // Skylake-X with AVX-512F/CD/BW/DQ/VL +# undef CV_AVX512_SKX +# define CV_AVX512_SKX 1 +# undef CV_AVX_512CD +# define CV_AVX_512CD 1 +# undef CV_AVX_512BW +# define CV_AVX_512BW 1 +# undef CV_AVX_512DQ +# define CV_AVX_512DQ 1 +# undef CV_AVX_512VL +# define CV_AVX_512VL 1 +# endif +#endif // AVX512 + +// GCC/Clang: -mavx2 +// MSVC: /arch:AVX2 +#if defined __AVX2__ +# include +# undef CV_AVX2 +# define CV_AVX2 1 +# if defined __F16C__ +# undef CV_FP16 +# define CV_FP16 1 +# endif +#endif + +#endif + +// SSE / NEON / VSX is handled by cv_cpu_dispatch.h compatibility block +#include "cv_cpu_dispatch.h" + +#include "hal/intrin.hpp" + +#endif // OPENCV_CORE_SIMD_INTRINSICS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/softfloat.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/softfloat.hpp new file mode 100644 index 0000000000000000000000000000000000000000..485e15c4732608f8522603df512eaaf832b9f957 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/softfloat.hpp @@ -0,0 +1,514 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This file is based on files from package issued with the following license: + +/*============================================================================ + +This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3c, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the +University of California. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions, and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions, and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE +DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================*/ + +#pragma once +#ifndef softfloat_h +#define softfloat_h 1 + +#include "cvdef.h" + +namespace cv +{ + +/** @addtogroup core_utils_softfloat + + [SoftFloat](http://www.jhauser.us/arithmetic/SoftFloat.html) is a software implementation + of floating-point calculations according to IEEE 754 standard. + All calculations are done in integers, that's why they are machine-independent and bit-exact. + This library can be useful in accuracy-critical parts like look-up tables generation, tests, etc. + OpenCV contains a subset of SoftFloat partially rewritten to C++. + + ### Types + + There are two basic types: @ref softfloat and @ref softdouble. + These types are binary compatible with float and double types respectively + and support conversions to/from them. + Other types from original SoftFloat library like fp16 or fp128 were thrown away + as well as quiet/signaling NaN support, on-the-fly rounding mode switch + and exception flags (though exceptions can be implemented in the future). + + ### Operations + + Both types support the following: + - Construction from signed and unsigned 32-bit and 64 integers, + float/double or raw binary representation + - Conversions between each other, to float or double and to int + using @ref cvRound, @ref cvTrunc, @ref cvFloor, @ref cvCeil or a bunch of + saturate_cast functions + - Add, subtract, multiply, divide, remainder, square root, FMA with absolute precision + - Comparison operations + - Explicit sign, exponent and significand manipulation through get/set methods, + number state indicators (isInf, isNan, isSubnormal) + - Type-specific constants like eps, minimum/maximum value, best pi approximation, etc. + - min(), max(), abs(), exp(), log() and pow() functions + +*/ +//! @{ + +struct softfloat; +struct softdouble; + +struct CV_EXPORTS softfloat +{ +public: + /** @brief Default constructor */ + softfloat() { v = 0; } + /** @brief Copy constructor */ + softfloat( const softfloat& c) { v = c.v; } + /** @brief Assign constructor */ + softfloat& operator=( const softfloat& c ) + { + if(&c != this) v = c.v; + return *this; + } + /** @brief Construct from raw + + Builds new value from raw binary representation + */ + static const softfloat fromRaw( const uint32_t a ) { softfloat x; x.v = a; return x; } + + /** @brief Construct from integer */ + explicit softfloat( const uint32_t ); + explicit softfloat( const uint64_t ); + explicit softfloat( const int32_t ); + explicit softfloat( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softfloat( const int a ) { *this = softfloat(static_cast(a)); } +#endif + + /** @brief Construct from float */ + explicit softfloat( const float a ) { Cv32suf s; s.f = a; v = s.u; } + + /** @brief Type casts */ + operator softdouble() const; + operator float() const { Cv32suf s; s.u = v; return s.f; } + + /** @brief Basic arithmetics */ + softfloat operator + (const softfloat&) const; + softfloat operator - (const softfloat&) const; + softfloat operator * (const softfloat&) const; + softfloat operator / (const softfloat&) const; + softfloat operator - () const { softfloat x; x.v = v ^ (1U << 31); return x; } + + /** @brief Remainder operator + + A quote from original SoftFloat manual: + + > The IEEE Standard remainder operation computes the value + > a - n * b, where n is the integer closest to a / b. + > If a / b is exactly halfway between two integers, n is the even integer + > closest to a / b. The IEEE Standard’s remainder operation is always exact and so requires no rounding. + > Depending on the relative magnitudes of the operands, the remainder functions + > can take considerably longer to execute than the other SoftFloat functions. + > This is an inherent characteristic of the remainder operation itself and is not a flaw + > in the SoftFloat implementation. + */ + softfloat operator % (const softfloat&) const; + + softfloat& operator += (const softfloat& a) { *this = *this + a; return *this; } + softfloat& operator -= (const softfloat& a) { *this = *this - a; return *this; } + softfloat& operator *= (const softfloat& a) { *this = *this * a; return *this; } + softfloat& operator /= (const softfloat& a) { *this = *this / a; return *this; } + softfloat& operator %= (const softfloat& a) { *this = *this % a; return *this; } + + /** @brief Comparison operations + + - Any operation with NaN produces false + + The only exception is when x is NaN: x != y for any y. + - Positive and negative zeros are equal + */ + bool operator == ( const softfloat& ) const; + bool operator != ( const softfloat& ) const; + bool operator > ( const softfloat& ) const; + bool operator >= ( const softfloat& ) const; + bool operator < ( const softfloat& ) const; + bool operator <= ( const softfloat& ) const; + + /** @brief NaN state indicator */ + inline bool isNaN() const { return (v & 0x7fffffff) > 0x7f800000; } + /** @brief Inf state indicator */ + inline bool isInf() const { return (v & 0x7fffffff) == 0x7f800000; } + /** @brief Subnormal number indicator */ + inline bool isSubnormal() const { return ((v >> 23) & 0xFF) == 0; } + + /** @brief Get sign bit */ + inline bool getSign() const { return (v >> 31) != 0; } + /** @brief Construct a copy with new sign bit */ + inline softfloat setSign(bool sign) const { softfloat x; x.v = (v & ((1U << 31) - 1)) | ((uint32_t)sign << 31); return x; } + /** @brief Get 0-based exponent */ + inline int getExp() const { return ((v >> 23) & 0xFF) - 127; } + /** @brief Construct a copy with new 0-based exponent */ + inline softfloat setExp(int e) const { softfloat x; x.v = (v & 0x807fffff) | (((e + 127) & 0xFF) << 23 ); return x; } + + /** @brief Get a fraction part + + Returns a number 1 <= x < 2 with the same significand + */ + inline softfloat getFrac() const + { + uint_fast32_t vv = (v & 0x007fffff) | (127 << 23); + return softfloat::fromRaw(vv); + } + /** @brief Construct a copy with provided significand + + Constructs a copy of a number with significand taken from parameter + */ + inline softfloat setFrac(const softfloat& s) const + { + softfloat x; + x.v = (v & 0xff800000) | (s.v & 0x007fffff); + return x; + } + + /** @brief Zero constant */ + static softfloat zero() { return softfloat::fromRaw( 0 ); } + /** @brief Positive infinity constant */ + static softfloat inf() { return softfloat::fromRaw( 0xFF << 23 ); } + /** @brief Default NaN constant */ + static softfloat nan() { return softfloat::fromRaw( 0x7fffffff ); } + /** @brief One constant */ + static softfloat one() { return softfloat::fromRaw( 127 << 23 ); } + /** @brief Smallest normalized value */ + static softfloat min() { return softfloat::fromRaw( 0x01 << 23 ); } + /** @brief Difference between 1 and next representable value */ + static softfloat eps() { return softfloat::fromRaw( (127 - 23) << 23 ); } + /** @brief Biggest finite value */ + static softfloat max() { return softfloat::fromRaw( (0xFF << 23) - 1 ); } + /** @brief Correct pi approximation */ + static softfloat pi() { return softfloat::fromRaw( 0x40490fdb ); } + + uint32_t v; +}; + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ + +struct CV_EXPORTS softdouble +{ +public: + /** @brief Default constructor */ + softdouble() : v(0) { } + /** @brief Copy constructor */ + softdouble( const softdouble& c) { v = c.v; } + /** @brief Assign constructor */ + softdouble& operator=( const softdouble& c ) + { + if(&c != this) v = c.v; + return *this; + } + /** @brief Construct from raw + + Builds new value from raw binary representation + */ + static softdouble fromRaw( const uint64_t a ) { softdouble x; x.v = a; return x; } + + /** @brief Construct from integer */ + explicit softdouble( const uint32_t ); + explicit softdouble( const uint64_t ); + explicit softdouble( const int32_t ); + explicit softdouble( const int64_t ); + +#ifdef CV_INT32_T_IS_LONG_INT + // for platforms with int32_t = long int + explicit softdouble( const int a ) { *this = softdouble(static_cast(a)); } +#endif + + /** @brief Construct from double */ + explicit softdouble( const double a ) { Cv64suf s; s.f = a; v = s.u; } + + /** @brief Type casts */ + operator softfloat() const; + operator double() const { Cv64suf s; s.u = v; return s.f; } + + /** @brief Basic arithmetics */ + softdouble operator + (const softdouble&) const; + softdouble operator - (const softdouble&) const; + softdouble operator * (const softdouble&) const; + softdouble operator / (const softdouble&) const; + softdouble operator - () const { softdouble x; x.v = v ^ (1ULL << 63); return x; } + + /** @brief Remainder operator + + A quote from original SoftFloat manual: + + > The IEEE Standard remainder operation computes the value + > a - n * b, where n is the integer closest to a / b. + > If a / b is exactly halfway between two integers, n is the even integer + > closest to a / b. The IEEE Standard’s remainder operation is always exact and so requires no rounding. + > Depending on the relative magnitudes of the operands, the remainder functions + > can take considerably longer to execute than the other SoftFloat functions. + > This is an inherent characteristic of the remainder operation itself and is not a flaw + > in the SoftFloat implementation. + */ + softdouble operator % (const softdouble&) const; + + softdouble& operator += (const softdouble& a) { *this = *this + a; return *this; } + softdouble& operator -= (const softdouble& a) { *this = *this - a; return *this; } + softdouble& operator *= (const softdouble& a) { *this = *this * a; return *this; } + softdouble& operator /= (const softdouble& a) { *this = *this / a; return *this; } + softdouble& operator %= (const softdouble& a) { *this = *this % a; return *this; } + + /** @brief Comparison operations + + - Any operation with NaN produces false + + The only exception is when x is NaN: x != y for any y. + - Positive and negative zeros are equal + */ + bool operator == ( const softdouble& ) const; + bool operator != ( const softdouble& ) const; + bool operator > ( const softdouble& ) const; + bool operator >= ( const softdouble& ) const; + bool operator < ( const softdouble& ) const; + bool operator <= ( const softdouble& ) const; + + /** @brief NaN state indicator */ + inline bool isNaN() const { return (v & 0x7fffffffffffffff) > 0x7ff0000000000000; } + /** @brief Inf state indicator */ + inline bool isInf() const { return (v & 0x7fffffffffffffff) == 0x7ff0000000000000; } + /** @brief Subnormal number indicator */ + inline bool isSubnormal() const { return ((v >> 52) & 0x7FF) == 0; } + + /** @brief Get sign bit */ + inline bool getSign() const { return (v >> 63) != 0; } + /** @brief Construct a copy with new sign bit */ + softdouble setSign(bool sign) const { softdouble x; x.v = (v & ((1ULL << 63) - 1)) | ((uint_fast64_t)(sign) << 63); return x; } + /** @brief Get 0-based exponent */ + inline int getExp() const { return ((v >> 52) & 0x7FF) - 1023; } + /** @brief Construct a copy with new 0-based exponent */ + inline softdouble setExp(int e) const + { + softdouble x; + x.v = (v & 0x800FFFFFFFFFFFFF) | ((uint_fast64_t)((e + 1023) & 0x7FF) << 52); + return x; + } + + /** @brief Get a fraction part + + Returns a number 1 <= x < 2 with the same significand + */ + inline softdouble getFrac() const + { + uint_fast64_t vv = (v & 0x000FFFFFFFFFFFFF) | ((uint_fast64_t)(1023) << 52); + return softdouble::fromRaw(vv); + } + /** @brief Construct a copy with provided significand + + Constructs a copy of a number with significand taken from parameter + */ + inline softdouble setFrac(const softdouble& s) const + { + softdouble x; + x.v = (v & 0xFFF0000000000000) | (s.v & 0x000FFFFFFFFFFFFF); + return x; + } + + /** @brief Zero constant */ + static softdouble zero() { return softdouble::fromRaw( 0 ); } + /** @brief Positive infinity constant */ + static softdouble inf() { return softdouble::fromRaw( (uint_fast64_t)(0x7FF) << 52 ); } + /** @brief Default NaN constant */ + static softdouble nan() { return softdouble::fromRaw( CV_BIG_INT(0x7FFFFFFFFFFFFFFF) ); } + /** @brief One constant */ + static softdouble one() { return softdouble::fromRaw( (uint_fast64_t)( 1023) << 52 ); } + /** @brief Smallest normalized value */ + static softdouble min() { return softdouble::fromRaw( (uint_fast64_t)( 0x01) << 52 ); } + /** @brief Difference between 1 and next representable value */ + static softdouble eps() { return softdouble::fromRaw( (uint_fast64_t)( 1023 - 52 ) << 52 ); } + /** @brief Biggest finite value */ + static softdouble max() { return softdouble::fromRaw( ((uint_fast64_t)(0x7FF) << 52) - 1 ); } + /** @brief Correct pi approximation */ + static softdouble pi() { return softdouble::fromRaw( CV_BIG_INT(0x400921FB54442D18) ); } + + uint64_t v; +}; + +/*---------------------------------------------------------------------------- +*----------------------------------------------------------------------------*/ + +/** @brief Fused Multiplication and Addition + +Computes (a*b)+c with single rounding +*/ +CV_EXPORTS softfloat mulAdd( const softfloat& a, const softfloat& b, const softfloat & c); +CV_EXPORTS softdouble mulAdd( const softdouble& a, const softdouble& b, const softdouble& c); + +/** @brief Square root */ +CV_EXPORTS softfloat sqrt( const softfloat& a ); +CV_EXPORTS softdouble sqrt( const softdouble& a ); +} + +/*---------------------------------------------------------------------------- +| Ported from OpenCV and added for usability +*----------------------------------------------------------------------------*/ + +/** @brief Truncates number to integer with minimum magnitude */ +CV_EXPORTS int cvTrunc(const cv::softfloat& a); +CV_EXPORTS int cvTrunc(const cv::softdouble& a); + +/** @brief Rounds a number to nearest even integer */ +CV_EXPORTS int cvRound(const cv::softfloat& a); +CV_EXPORTS int cvRound(const cv::softdouble& a); + +/** @brief Rounds a number to nearest even long long integer */ +CV_EXPORTS int64_t cvRound64(const cv::softdouble& a); + +/** @brief Rounds a number down to integer */ +CV_EXPORTS int cvFloor(const cv::softfloat& a); +CV_EXPORTS int cvFloor(const cv::softdouble& a); + +/** @brief Rounds number up to integer */ +CV_EXPORTS int cvCeil(const cv::softfloat& a); +CV_EXPORTS int cvCeil(const cv::softdouble& a); + +namespace cv +{ +/** @brief Saturate casts */ +template static inline _Tp saturate_cast(softfloat a) { return _Tp(a); } +template static inline _Tp saturate_cast(softdouble a) { return _Tp(a); } + +template<> inline uchar saturate_cast(softfloat a) { return (uchar)std::max(std::min(cvRound(a), (int)UCHAR_MAX), 0); } +template<> inline uchar saturate_cast(softdouble a) { return (uchar)std::max(std::min(cvRound(a), (int)UCHAR_MAX), 0); } + +template<> inline schar saturate_cast(softfloat a) { return (schar)std::min(std::max(cvRound(a), (int)SCHAR_MIN), (int)SCHAR_MAX); } +template<> inline schar saturate_cast(softdouble a) { return (schar)std::min(std::max(cvRound(a), (int)SCHAR_MIN), (int)SCHAR_MAX); } + +template<> inline ushort saturate_cast(softfloat a) { return (ushort)std::max(std::min(cvRound(a), (int)USHRT_MAX), 0); } +template<> inline ushort saturate_cast(softdouble a) { return (ushort)std::max(std::min(cvRound(a), (int)USHRT_MAX), 0); } + +template<> inline short saturate_cast(softfloat a) { return (short)std::min(std::max(cvRound(a), (int)SHRT_MIN), (int)SHRT_MAX); } +template<> inline short saturate_cast(softdouble a) { return (short)std::min(std::max(cvRound(a), (int)SHRT_MIN), (int)SHRT_MAX); } + +template<> inline int saturate_cast(softfloat a) { return cvRound(a); } +template<> inline int saturate_cast(softdouble a) { return cvRound(a); } + +template<> inline int64_t saturate_cast(softfloat a) { return cvRound(a); } +template<> inline int64_t saturate_cast(softdouble a) { return cvRound64(a); } + +/** @brief Saturate cast to unsigned integer and unsigned long long integer +We intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. +*/ +template<> inline unsigned saturate_cast(softfloat a) { return cvRound(a); } +template<> inline unsigned saturate_cast(softdouble a) { return cvRound(a); } + +template<> inline uint64_t saturate_cast(softfloat a) { return cvRound(a); } +template<> inline uint64_t saturate_cast(softdouble a) { return cvRound64(a); } + +/** @brief Min and Max functions */ +inline softfloat min(const softfloat& a, const softfloat& b) { return (a > b) ? b : a; } +inline softdouble min(const softdouble& a, const softdouble& b) { return (a > b) ? b : a; } + +inline softfloat max(const softfloat& a, const softfloat& b) { return (a > b) ? a : b; } +inline softdouble max(const softdouble& a, const softdouble& b) { return (a > b) ? a : b; } + +/** @brief Absolute value */ +inline softfloat abs( softfloat a) { softfloat x; x.v = a.v & ((1U << 31) - 1); return x; } +inline softdouble abs( softdouble a) { softdouble x; x.v = a.v & ((1ULL << 63) - 1); return x; } + +/** @brief Exponent + +Special cases: +- exp(NaN) is NaN +- exp(-Inf) == 0 +- exp(+Inf) == +Inf +*/ +CV_EXPORTS softfloat exp( const softfloat& a); +CV_EXPORTS softdouble exp( const softdouble& a); + +/** @brief Natural logarithm + +Special cases: +- log(NaN), log(x < 0) are NaN +- log(0) == -Inf +*/ +CV_EXPORTS softfloat log( const softfloat& a ); +CV_EXPORTS softdouble log( const softdouble& a ); + +/** @brief Raising to the power + +Special cases: +- x**NaN is NaN for any x +- ( |x| == 1 )**Inf is NaN +- ( |x| > 1 )**+Inf or ( |x| < 1 )**-Inf is +Inf +- ( |x| > 1 )**-Inf or ( |x| < 1 )**+Inf is 0 +- x ** 0 == 1 for any x +- x ** 1 == 1 for any x +- NaN ** y is NaN for any other y +- Inf**(y < 0) == 0 +- Inf ** y is +Inf for any other y +- (x < 0)**y is NaN for any other y if x can't be correctly rounded to integer +- 0 ** 0 == 1 +- 0 ** (y < 0) is +Inf +- 0 ** (y > 0) is 0 +*/ +CV_EXPORTS softfloat pow( const softfloat& a, const softfloat& b); +CV_EXPORTS softdouble pow( const softdouble& a, const softdouble& b); + +/** @brief Cube root + +Special cases: +- cbrt(NaN) is NaN +- cbrt(+/-Inf) is +/-Inf +*/ +CV_EXPORTS softfloat cbrt( const softfloat& a ); + +/** @brief Sine + +Special cases: +- sin(Inf) or sin(NaN) is NaN +- sin(x) == x when sin(x) is close to zero +*/ +CV_EXPORTS softdouble sin( const softdouble& a ); + +/** @brief Cosine + * +Special cases: +- cos(Inf) or cos(NaN) is NaN +- cos(x) == +/- 1 when cos(x) is close to +/- 1 +*/ +CV_EXPORTS softdouble cos( const softdouble& a ); + +//! @} core_utils_softfloat + +} // cv:: + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/sse_utils.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/sse_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0906583ea433e289e883270d81f8641985cc3ebb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/sse_utils.hpp @@ -0,0 +1,652 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_SSE_UTILS_HPP +#define OPENCV_CORE_SSE_UTILS_HPP + +#ifndef __cplusplus +# error sse_utils.hpp header must be compiled as C++ +#endif + +#include "opencv2/core/cvdef.h" + +//! @addtogroup core_utils_sse +//! @{ + +#if CV_SSE2 + +inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_g0); + __m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_g0); + __m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_g1); + __m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_g1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk3); + __m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk3); + + __m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk3); + __m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk3); + + __m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk2); + __m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk2); + __m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk3); + __m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk3); + + v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk2); + v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk2); + v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk3); + v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk3); +} + +inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_g1); + __m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_g1); + __m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_b0); + __m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_b0); + __m128i layer1_chunk4 = _mm_unpacklo_epi8(v_g0, v_b1); + __m128i layer1_chunk5 = _mm_unpackhi_epi8(v_g0, v_b1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk4 = _mm_unpacklo_epi8(layer1_chunk2, layer1_chunk5); + __m128i layer2_chunk5 = _mm_unpackhi_epi8(layer1_chunk2, layer1_chunk5); + + __m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk4 = _mm_unpacklo_epi8(layer2_chunk2, layer2_chunk5); + __m128i layer3_chunk5 = _mm_unpackhi_epi8(layer2_chunk2, layer2_chunk5); + + __m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk3); + __m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk3); + __m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk4); + __m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk4); + __m128i layer4_chunk4 = _mm_unpacklo_epi8(layer3_chunk2, layer3_chunk5); + __m128i layer4_chunk5 = _mm_unpackhi_epi8(layer3_chunk2, layer3_chunk5); + + v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk3); + v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk3); + v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk4); + v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk4); + v_b0 = _mm_unpacklo_epi8(layer4_chunk2, layer4_chunk5); + v_b1 = _mm_unpackhi_epi8(layer4_chunk2, layer4_chunk5); +} + +inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_b0); + __m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_b0); + __m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_b1); + __m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_b1); + __m128i layer1_chunk4 = _mm_unpacklo_epi8(v_g0, v_a0); + __m128i layer1_chunk5 = _mm_unpackhi_epi8(v_g0, v_a0); + __m128i layer1_chunk6 = _mm_unpacklo_epi8(v_g1, v_a1); + __m128i layer1_chunk7 = _mm_unpackhi_epi8(v_g1, v_a1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk4 = _mm_unpacklo_epi8(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk5 = _mm_unpackhi_epi8(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk6 = _mm_unpacklo_epi8(layer1_chunk3, layer1_chunk7); + __m128i layer2_chunk7 = _mm_unpackhi_epi8(layer1_chunk3, layer1_chunk7); + + __m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk4 = _mm_unpacklo_epi8(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk5 = _mm_unpackhi_epi8(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk6 = _mm_unpacklo_epi8(layer2_chunk3, layer2_chunk7); + __m128i layer3_chunk7 = _mm_unpackhi_epi8(layer2_chunk3, layer2_chunk7); + + __m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk4); + __m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk4); + __m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk5); + __m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk5); + __m128i layer4_chunk4 = _mm_unpacklo_epi8(layer3_chunk2, layer3_chunk6); + __m128i layer4_chunk5 = _mm_unpackhi_epi8(layer3_chunk2, layer3_chunk6); + __m128i layer4_chunk6 = _mm_unpacklo_epi8(layer3_chunk3, layer3_chunk7); + __m128i layer4_chunk7 = _mm_unpackhi_epi8(layer3_chunk3, layer3_chunk7); + + v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk4); + v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk4); + v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk5); + v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk5); + v_b0 = _mm_unpacklo_epi8(layer4_chunk2, layer4_chunk6); + v_b1 = _mm_unpackhi_epi8(layer4_chunk2, layer4_chunk6); + v_a0 = _mm_unpacklo_epi8(layer4_chunk3, layer4_chunk7); + v_a1 = _mm_unpackhi_epi8(layer4_chunk3, layer4_chunk7); +} + +inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i v_mask = _mm_set1_epi16(0x00ff); + + __m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer4_chunk2 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8)); + __m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer4_chunk3 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8)); + + __m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask)); + __m128i layer3_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8)); + __m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8)); + + __m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8)); + __m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8)); + + __m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8)); + __m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8)); + + v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8)); + v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_g1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8)); +} + +inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i v_mask = _mm_set1_epi16(0x00ff); + + __m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer4_chunk3 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8)); + __m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer4_chunk4 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8)); + __m128i layer4_chunk2 = _mm_packus_epi16(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer4_chunk5 = _mm_packus_epi16(_mm_srli_epi16(v_b0, 8), _mm_srli_epi16(v_b1, 8)); + + __m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8)); + __m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8)); + __m128i layer3_chunk2 = _mm_packus_epi16(_mm_and_si128(layer4_chunk4, v_mask), _mm_and_si128(layer4_chunk5, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk4, 8), _mm_srli_epi16(layer4_chunk5, 8)); + + __m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8)); + __m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8)); + __m128i layer2_chunk2 = _mm_packus_epi16(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk4, 8), _mm_srli_epi16(layer3_chunk5, 8)); + + __m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8)); + __m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8)); + __m128i layer1_chunk2 = _mm_packus_epi16(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk4, 8), _mm_srli_epi16(layer2_chunk5, 8)); + + v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8)); + v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8)); + v_g0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_b1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk4, 8), _mm_srli_epi16(layer1_chunk5, 8)); +} + +inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i v_mask = _mm_set1_epi16(0x00ff); + + __m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer4_chunk4 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8)); + __m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer4_chunk5 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8)); + __m128i layer4_chunk2 = _mm_packus_epi16(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer4_chunk6 = _mm_packus_epi16(_mm_srli_epi16(v_b0, 8), _mm_srli_epi16(v_b1, 8)); + __m128i layer4_chunk3 = _mm_packus_epi16(_mm_and_si128(v_a0, v_mask), _mm_and_si128(v_a1, v_mask)); + __m128i layer4_chunk7 = _mm_packus_epi16(_mm_srli_epi16(v_a0, 8), _mm_srli_epi16(v_a1, 8)); + + __m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8)); + __m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8)); + __m128i layer3_chunk2 = _mm_packus_epi16(_mm_and_si128(layer4_chunk4, v_mask), _mm_and_si128(layer4_chunk5, v_mask)); + __m128i layer3_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk4, 8), _mm_srli_epi16(layer4_chunk5, 8)); + __m128i layer3_chunk3 = _mm_packus_epi16(_mm_and_si128(layer4_chunk6, v_mask), _mm_and_si128(layer4_chunk7, v_mask)); + __m128i layer3_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk6, 8), _mm_srli_epi16(layer4_chunk7, 8)); + + __m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8)); + __m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8)); + __m128i layer2_chunk2 = _mm_packus_epi16(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk4, 8), _mm_srli_epi16(layer3_chunk5, 8)); + __m128i layer2_chunk3 = _mm_packus_epi16(_mm_and_si128(layer3_chunk6, v_mask), _mm_and_si128(layer3_chunk7, v_mask)); + __m128i layer2_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk6, 8), _mm_srli_epi16(layer3_chunk7, 8)); + + __m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8)); + __m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8)); + __m128i layer1_chunk2 = _mm_packus_epi16(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk4, 8), _mm_srli_epi16(layer2_chunk5, 8)); + __m128i layer1_chunk3 = _mm_packus_epi16(_mm_and_si128(layer2_chunk6, v_mask), _mm_and_si128(layer2_chunk7, v_mask)); + __m128i layer1_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk6, 8), _mm_srli_epi16(layer2_chunk7, 8)); + + v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_b0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8)); + v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8)); + v_g0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_a0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk4, 8), _mm_srli_epi16(layer1_chunk5, 8)); + v_g1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk6, v_mask), _mm_and_si128(layer1_chunk7, v_mask)); + v_a1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk6, 8), _mm_srli_epi16(layer1_chunk7, 8)); +} + +inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_g0); + __m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_g0); + __m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_g1); + __m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_g1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk2); + __m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk3); + __m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk3); + + __m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk2); + __m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk3); + __m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk3); + + v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk2); + v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk2); + v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk3); + v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk3); +} + +inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_g1); + __m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_g1); + __m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_b0); + __m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_b0); + __m128i layer1_chunk4 = _mm_unpacklo_epi16(v_g0, v_b1); + __m128i layer1_chunk5 = _mm_unpackhi_epi16(v_g0, v_b1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk3); + __m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk4); + __m128i layer2_chunk4 = _mm_unpacklo_epi16(layer1_chunk2, layer1_chunk5); + __m128i layer2_chunk5 = _mm_unpackhi_epi16(layer1_chunk2, layer1_chunk5); + + __m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk3); + __m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk4); + __m128i layer3_chunk4 = _mm_unpacklo_epi16(layer2_chunk2, layer2_chunk5); + __m128i layer3_chunk5 = _mm_unpackhi_epi16(layer2_chunk2, layer2_chunk5); + + v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk3); + v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk3); + v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk4); + v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk4); + v_b0 = _mm_unpacklo_epi16(layer3_chunk2, layer3_chunk5); + v_b1 = _mm_unpackhi_epi16(layer3_chunk2, layer3_chunk5); +} + +inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_b0); + __m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_b0); + __m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_b1); + __m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_b1); + __m128i layer1_chunk4 = _mm_unpacklo_epi16(v_g0, v_a0); + __m128i layer1_chunk5 = _mm_unpackhi_epi16(v_g0, v_a0); + __m128i layer1_chunk6 = _mm_unpacklo_epi16(v_g1, v_a1); + __m128i layer1_chunk7 = _mm_unpackhi_epi16(v_g1, v_a1); + + __m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk4); + __m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk5); + __m128i layer2_chunk4 = _mm_unpacklo_epi16(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk5 = _mm_unpackhi_epi16(layer1_chunk2, layer1_chunk6); + __m128i layer2_chunk6 = _mm_unpacklo_epi16(layer1_chunk3, layer1_chunk7); + __m128i layer2_chunk7 = _mm_unpackhi_epi16(layer1_chunk3, layer1_chunk7); + + __m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk4); + __m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk5); + __m128i layer3_chunk4 = _mm_unpacklo_epi16(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk5 = _mm_unpackhi_epi16(layer2_chunk2, layer2_chunk6); + __m128i layer3_chunk6 = _mm_unpacklo_epi16(layer2_chunk3, layer2_chunk7); + __m128i layer3_chunk7 = _mm_unpackhi_epi16(layer2_chunk3, layer2_chunk7); + + v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk4); + v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk4); + v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk5); + v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk5); + v_b0 = _mm_unpacklo_epi16(layer3_chunk2, layer3_chunk6); + v_b1 = _mm_unpackhi_epi16(layer3_chunk2, layer3_chunk6); + v_a0 = _mm_unpacklo_epi16(layer3_chunk3, layer3_chunk7); + v_a1 = _mm_unpackhi_epi16(layer3_chunk3, layer3_chunk7); +} + +#if CV_SSE4_1 + +inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1) +{ + __m128i v_mask = _mm_set1_epi32(0x0000ffff); + + __m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer3_chunk2 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16)); + __m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16)); + + __m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk2 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16)); + __m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16)); + + __m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk2 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16)); + __m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16)); + + v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16)); + v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_g1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16)); +} + +inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, + __m128i & v_g1, __m128i & v_b0, __m128i & v_b1) +{ + __m128i v_mask = _mm_set1_epi32(0x0000ffff); + + __m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer3_chunk3 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16)); + __m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16)); + __m128i layer3_chunk2 = _mm_packus_epi32(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi32(_mm_srli_epi32(v_b0, 16), _mm_srli_epi32(v_b1, 16)); + + __m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16)); + __m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16)); + __m128i layer2_chunk2 = _mm_packus_epi32(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk4, 16), _mm_srli_epi32(layer3_chunk5, 16)); + + __m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16)); + __m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16)); + __m128i layer1_chunk2 = _mm_packus_epi32(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk4, 16), _mm_srli_epi32(layer2_chunk5, 16)); + + v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_g1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16)); + v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16)); + v_g0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_b1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk4, 16), _mm_srli_epi32(layer1_chunk5, 16)); +} + +inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1, + __m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1) +{ + __m128i v_mask = _mm_set1_epi32(0x0000ffff); + + __m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask)); + __m128i layer3_chunk4 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16)); + __m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask)); + __m128i layer3_chunk5 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16)); + __m128i layer3_chunk2 = _mm_packus_epi32(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask)); + __m128i layer3_chunk6 = _mm_packus_epi32(_mm_srli_epi32(v_b0, 16), _mm_srli_epi32(v_b1, 16)); + __m128i layer3_chunk3 = _mm_packus_epi32(_mm_and_si128(v_a0, v_mask), _mm_and_si128(v_a1, v_mask)); + __m128i layer3_chunk7 = _mm_packus_epi32(_mm_srli_epi32(v_a0, 16), _mm_srli_epi32(v_a1, 16)); + + __m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask)); + __m128i layer2_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16)); + __m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask)); + __m128i layer2_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16)); + __m128i layer2_chunk2 = _mm_packus_epi32(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask)); + __m128i layer2_chunk6 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk4, 16), _mm_srli_epi32(layer3_chunk5, 16)); + __m128i layer2_chunk3 = _mm_packus_epi32(_mm_and_si128(layer3_chunk6, v_mask), _mm_and_si128(layer3_chunk7, v_mask)); + __m128i layer2_chunk7 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk6, 16), _mm_srli_epi32(layer3_chunk7, 16)); + + __m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask)); + __m128i layer1_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16)); + __m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask)); + __m128i layer1_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16)); + __m128i layer1_chunk2 = _mm_packus_epi32(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask)); + __m128i layer1_chunk6 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk4, 16), _mm_srli_epi32(layer2_chunk5, 16)); + __m128i layer1_chunk3 = _mm_packus_epi32(_mm_and_si128(layer2_chunk6, v_mask), _mm_and_si128(layer2_chunk7, v_mask)); + __m128i layer1_chunk7 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk6, 16), _mm_srli_epi32(layer2_chunk7, 16)); + + v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask)); + v_b0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16)); + v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask)); + v_b1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16)); + v_g0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask)); + v_a0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk4, 16), _mm_srli_epi32(layer1_chunk5, 16)); + v_g1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk6, v_mask), _mm_and_si128(layer1_chunk7, v_mask)); + v_a1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk6, 16), _mm_srli_epi32(layer1_chunk7, 16)); +} + +#endif // CV_SSE4_1 + +inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1) +{ + __m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_g0); + __m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_g0); + __m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_g1); + __m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_g1); + + __m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk2); + __m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk2); + __m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk3); + __m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk3); + + v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk2); + v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk2); + v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk3); + v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk3); +} + +inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, + __m128 & v_g1, __m128 & v_b0, __m128 & v_b1) +{ + __m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_g1); + __m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_g1); + __m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_b0); + __m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_b0); + __m128 layer1_chunk4 = _mm_unpacklo_ps(v_g0, v_b1); + __m128 layer1_chunk5 = _mm_unpackhi_ps(v_g0, v_b1); + + __m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk3); + __m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk3); + __m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk4); + __m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk4); + __m128 layer2_chunk4 = _mm_unpacklo_ps(layer1_chunk2, layer1_chunk5); + __m128 layer2_chunk5 = _mm_unpackhi_ps(layer1_chunk2, layer1_chunk5); + + v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk3); + v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk3); + v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk4); + v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk4); + v_b0 = _mm_unpacklo_ps(layer2_chunk2, layer2_chunk5); + v_b1 = _mm_unpackhi_ps(layer2_chunk2, layer2_chunk5); +} + +inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1, + __m128 & v_b0, __m128 & v_b1, __m128 & v_a0, __m128 & v_a1) +{ + __m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_b0); + __m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_b0); + __m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_b1); + __m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_b1); + __m128 layer1_chunk4 = _mm_unpacklo_ps(v_g0, v_a0); + __m128 layer1_chunk5 = _mm_unpackhi_ps(v_g0, v_a0); + __m128 layer1_chunk6 = _mm_unpacklo_ps(v_g1, v_a1); + __m128 layer1_chunk7 = _mm_unpackhi_ps(v_g1, v_a1); + + __m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk4); + __m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk4); + __m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk5); + __m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk5); + __m128 layer2_chunk4 = _mm_unpacklo_ps(layer1_chunk2, layer1_chunk6); + __m128 layer2_chunk5 = _mm_unpackhi_ps(layer1_chunk2, layer1_chunk6); + __m128 layer2_chunk6 = _mm_unpacklo_ps(layer1_chunk3, layer1_chunk7); + __m128 layer2_chunk7 = _mm_unpackhi_ps(layer1_chunk3, layer1_chunk7); + + v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk4); + v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk4); + v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk5); + v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk5); + v_b0 = _mm_unpacklo_ps(layer2_chunk2, layer2_chunk6); + v_b1 = _mm_unpackhi_ps(layer2_chunk2, layer2_chunk6); + v_a0 = _mm_unpacklo_ps(layer2_chunk3, layer2_chunk7); + v_a1 = _mm_unpackhi_ps(layer2_chunk3, layer2_chunk7); +} + +inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1) +{ + enum { mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1) }; + + __m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo); + __m128 layer2_chunk2 = _mm_shuffle_ps(v_r0, v_r1, mask_hi); + __m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo); + __m128 layer2_chunk3 = _mm_shuffle_ps(v_g0, v_g1, mask_hi); + + __m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo); + __m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi); + __m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo); + __m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi); + + v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo); + v_g0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi); + v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo); + v_g1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi); +} + +inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, + __m128 & v_g1, __m128 & v_b0, __m128 & v_b1) +{ + enum { mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1) }; + + __m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo); + __m128 layer2_chunk3 = _mm_shuffle_ps(v_r0, v_r1, mask_hi); + __m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo); + __m128 layer2_chunk4 = _mm_shuffle_ps(v_g0, v_g1, mask_hi); + __m128 layer2_chunk2 = _mm_shuffle_ps(v_b0, v_b1, mask_lo); + __m128 layer2_chunk5 = _mm_shuffle_ps(v_b0, v_b1, mask_hi); + + __m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo); + __m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi); + __m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo); + __m128 layer1_chunk4 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi); + __m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_lo); + __m128 layer1_chunk5 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_hi); + + v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo); + v_g1 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi); + v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo); + v_b0 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi); + v_g0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_lo); + v_b1 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_hi); +} + +inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1, + __m128 & v_b0, __m128 & v_b1, __m128 & v_a0, __m128 & v_a1) +{ + enum { mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1) }; + + __m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo); + __m128 layer2_chunk4 = _mm_shuffle_ps(v_r0, v_r1, mask_hi); + __m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo); + __m128 layer2_chunk5 = _mm_shuffle_ps(v_g0, v_g1, mask_hi); + __m128 layer2_chunk2 = _mm_shuffle_ps(v_b0, v_b1, mask_lo); + __m128 layer2_chunk6 = _mm_shuffle_ps(v_b0, v_b1, mask_hi); + __m128 layer2_chunk3 = _mm_shuffle_ps(v_a0, v_a1, mask_lo); + __m128 layer2_chunk7 = _mm_shuffle_ps(v_a0, v_a1, mask_hi); + + __m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo); + __m128 layer1_chunk4 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi); + __m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo); + __m128 layer1_chunk5 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi); + __m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_lo); + __m128 layer1_chunk6 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_hi); + __m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk6, layer2_chunk7, mask_lo); + __m128 layer1_chunk7 = _mm_shuffle_ps(layer2_chunk6, layer2_chunk7, mask_hi); + + v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo); + v_b0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi); + v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo); + v_b1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi); + v_g0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_lo); + v_a0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_hi); + v_g1 = _mm_shuffle_ps(layer1_chunk6, layer1_chunk7, mask_lo); + v_a1 = _mm_shuffle_ps(layer1_chunk6, layer1_chunk7, mask_hi); +} + +#endif // CV_SSE2 + +//! @} + +#endif //OPENCV_CORE_SSE_UTILS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/traits.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/traits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..52ab083ca43d3c93ec39e99ce2ce1951c4bab8dc --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/traits.hpp @@ -0,0 +1,417 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_TRAITS_HPP +#define OPENCV_CORE_TRAITS_HPP + +#include "opencv2/core/cvdef.h" + +namespace cv +{ + +//#define OPENCV_TRAITS_ENABLE_DEPRECATED + +//! @addtogroup core_basic +//! @{ + +/** @brief Template "trait" class for OpenCV primitive data types. + +@note Deprecated. This is replaced by "single purpose" traits: traits::Type and traits::Depth + +A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed +short, int, float, double, or a tuple of values of one of these types, where all the values in the +tuple have the same type. Any primitive type from the list can be defined by an identifier in the +form CV_\{U|S|F}C(\), for example: uchar \~ CV_8UC1, 3-element +floating-point tuple \~ CV_32FC3, and so on. A universal OpenCV structure that is able to store a +single instance of such a primitive data type is Vec. Multiple instances of such a type can be +stored in a std::vector, Mat, Mat_, SparseMat, SparseMat_, or any other container that is able to +store Vec instances. + +The DataType class is basically used to provide a description of such primitive data types without +adding any fields or methods to the corresponding classes (and it is actually impossible to add +anything to primitive C/C++ data types). This technique is known in C++ as class traits. It is not +DataType itself that is used but its specialized versions, such as: +@code + template<> class DataType + { + typedef uchar value_type; + typedef int work_type; + typedef uchar channel_type; + enum { channel_type = CV_8U, channels = 1, fmt='u', type = CV_8U }; + }; + ... + template DataType > + { + typedef std::complex<_Tp> value_type; + typedef std::complex<_Tp> work_type; + typedef _Tp channel_type; + // DataDepth is another helper trait class + enum { depth = DataDepth<_Tp>::value, channels=2, + fmt=(channels-1)*256+DataDepth<_Tp>::fmt, + type=CV_MAKETYPE(depth, channels) }; + }; + ... +@endcode +The main purpose of this class is to convert compilation-time type information to an +OpenCV-compatible data type identifier, for example: +@code + // allocates a 30x40 floating-point matrix + Mat A(30, 40, DataType::type); + + Mat B = Mat_ >(3, 3); + // the statement below will print 6, 2 , that is depth == CV_64F, channels == 2 + cout << B.depth() << ", " << B.channels() << endl; +@endcode +So, such traits are used to tell OpenCV which data type you are working with, even if such a type is +not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV +defines the proper specialized template class DataType\ \> . This mechanism is also +useful (and used in OpenCV this way) for generic algorithms implementations. + +@note Default values were dropped to stop confusing developers about using of unsupported types (see #7599) +*/ +template class DataType +{ +public: +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + typedef _Tp value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 1, + depth = -1, + channels = 1, + fmt = 0, + type = CV_MAKETYPE(depth, channels) + }; +#endif +}; + +template<> class DataType +{ +public: + typedef bool value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8U, + channels = 1, + fmt = (int)'u', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef uchar value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8U, + channels = 1, + fmt = (int)'u', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef schar value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8S, + channels = 1, + fmt = (int)'c', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef schar value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_8S, + channels = 1, + fmt = (int)'c', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef ushort value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_16U, + channels = 1, + fmt = (int)'w', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef short value_type; + typedef int work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_16S, + channels = 1, + fmt = (int)'s', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef int value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_32S, + channels = 1, + fmt = (int)'i', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef float value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_32F, + channels = 1, + fmt = (int)'f', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef double value_type; + typedef value_type work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_64F, + channels = 1, + fmt = (int)'d', + type = CV_MAKETYPE(depth, channels) + }; +}; + +template<> class DataType +{ +public: + typedef float16_t value_type; + typedef float work_type; + typedef value_type channel_type; + typedef value_type vec_type; + enum { generic_type = 0, + depth = CV_16F, + channels = 1, + fmt = (int)'h', + type = CV_MAKETYPE(depth, channels) + }; +}; + +/** @brief A helper class for cv::DataType + +The class is specialized for each fundamental numerical data type supported by OpenCV. It provides +DataDepth::value constant. +*/ +template class DataDepth +{ +public: + enum + { + value = DataType<_Tp>::depth, + fmt = DataType<_Tp>::fmt + }; +}; + + +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + +template class TypeDepth +{ +#ifdef OPENCV_TRAITS_ENABLE_LEGACY_DEFAULTS + enum { depth = CV_USRTYPE1 }; + typedef void value_type; +#endif +}; + +template<> class TypeDepth +{ + enum { depth = CV_8U }; + typedef uchar value_type; +}; + +template<> class TypeDepth +{ + enum { depth = CV_8S }; + typedef schar value_type; +}; + +template<> class TypeDepth +{ + enum { depth = CV_16U }; + typedef ushort value_type; +}; + +template<> class TypeDepth +{ + enum { depth = CV_16S }; + typedef short value_type; +}; + +template<> class TypeDepth +{ + enum { depth = CV_32S }; + typedef int value_type; +}; + +template<> class TypeDepth +{ + enum { depth = CV_32F }; + typedef float value_type; +}; + +template<> class TypeDepth +{ + enum { depth = CV_64F }; + typedef double value_type; +}; + +template<> class TypeDepth +{ + enum { depth = CV_16F }; + typedef float16_t value_type; +}; + +#endif + +//! @} + +namespace traits { + +namespace internal { +#define CV_CREATE_MEMBER_CHECK(X) \ +template class CheckMember_##X { \ + struct Fallback { int X; }; \ + struct Derived : T, Fallback { }; \ + template struct Check; \ + typedef char CV_NO[1]; \ + typedef char CV_YES[2]; \ + template static CV_NO & func(Check *); \ + template static CV_YES & func(...); \ +public: \ + typedef CheckMember_##X type; \ + enum { value = sizeof(func(0)) == sizeof(CV_YES) }; \ +}; + +CV_CREATE_MEMBER_CHECK(fmt) +CV_CREATE_MEMBER_CHECK(type) + +} // namespace internal + + +template +struct Depth +{ enum { value = DataType::depth }; }; + +template +struct Type +{ enum { value = DataType::type }; }; + +/** Similar to traits::Type but has value = -1 in case of unknown type (instead of compiler error) */ +template >::value > +struct SafeType {}; + +template +struct SafeType +{ enum { value = -1 }; }; + +template +struct SafeType +{ enum { value = Type::value }; }; + + +template >::value > +struct SafeFmt {}; + +template +struct SafeFmt +{ enum { fmt = 0 }; }; + +template +struct SafeFmt +{ enum { fmt = DataType::fmt }; }; + + +} // namespace + +} // cv + +#endif // OPENCV_CORE_TRAITS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/types.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/types.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b1fa676e5ed3d2473f01e96e5f1ad5e1bbed5b8e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/types.hpp @@ -0,0 +1,2476 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_TYPES_HPP +#define OPENCV_CORE_TYPES_HPP + +#ifndef __cplusplus +# error types.hpp header must be compiled as C++ +#endif + +#include +#include +#include +#include + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/matx.hpp" + +namespace cv +{ + +//! @addtogroup core_basic +//! @{ + +//////////////////////////////// Complex ////////////////////////////// + +/** @brief A complex number class. + + The template class is similar and compatible with std::complex, however it provides slightly + more convenient access to the real and imaginary parts using through the simple field access, as opposite + to std::complex::real() and std::complex::imag(). +*/ +template class Complex +{ +public: + + //! default constructor + Complex(); + Complex( _Tp _re, _Tp _im = 0 ); + + //! conversion to another data type + template operator Complex() const; + //! conjugation + Complex conj() const; + + _Tp re, im; //< the real and the imaginary parts +}; + +typedef Complex Complexf; +typedef Complex Complexd; + +template class DataType< Complex<_Tp> > +{ +public: + typedef Complex<_Tp> value_type; + typedef value_type work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template +struct Depth< Complex<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Complex<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace + + +//////////////////////////////// Point_ //////////////////////////////// + +/** @brief Template class for 2D points specified by its coordinates `x` and `y`. + +An instance of the class is interchangeable with C structures, CvPoint and CvPoint2D32f . There is +also a cast operator to convert point coordinates to the specified type. The conversion from +floating-point coordinates to integer coordinates is done by rounding. Commonly, the conversion +uses this operation for each of the coordinates. Besides the class members listed in the +declaration above, the following operations on points are implemented: +@code + pt1 = pt2 + pt3; + pt1 = pt2 - pt3; + pt1 = pt2 * a; + pt1 = a * pt2; + pt1 = pt2 / a; + pt1 += pt2; + pt1 -= pt2; + pt1 *= a; + pt1 /= a; + double value = norm(pt); // L2 norm + pt1 == pt2; + pt1 != pt2; +@endcode +For your convenience, the following type aliases are defined: +@code + typedef Point_ Point2i; + typedef Point2i Point; + typedef Point_ Point2f; + typedef Point_ Point2d; +@endcode +Example: +@code + Point2f a(0.3f, 0.f), b(0.f, 0.4f); + Point pt = (a + b)*10.f; + cout << pt.x << ", " << pt.y << endl; +@endcode +*/ +template class Point_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Point_(); + Point_(_Tp _x, _Tp _y); + Point_(const Point_& pt); + Point_(Point_&& pt) CV_NOEXCEPT; + Point_(const Size_<_Tp>& sz); + Point_(const Vec<_Tp, 2>& v); + + Point_& operator = (const Point_& pt); + Point_& operator = (Point_&& pt) CV_NOEXCEPT; + //! conversion to another data type + template operator Point_<_Tp2>() const; + + //! conversion to the old-style C structures + operator Vec<_Tp, 2>() const; + + //! dot product + _Tp dot(const Point_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point_& pt) const; + //! cross-product + double cross(const Point_& pt) const; + //! checks whether the point is inside the specified rectangle + bool inside(const Rect_<_Tp>& r) const; + _Tp x; //!< x coordinate of the point + _Tp y; //!< y coordinate of the point +}; + +typedef Point_ Point2i; +typedef Point_ Point2l; +typedef Point_ Point2f; +typedef Point_ Point2d; +typedef Point2i Point; + +template class DataType< Point_<_Tp> > +{ +public: + typedef Point_<_Tp> value_type; + typedef Point_::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template +struct Depth< Point_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Point_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace + + +//////////////////////////////// Point3_ //////////////////////////////// + +/** @brief Template class for 3D points specified by its coordinates `x`, `y` and `z`. + +An instance of the class is interchangeable with the C structure CvPoint2D32f . Similarly to +Point_ , the coordinates of 3D points can be converted to another type. The vector arithmetic and +comparison operations are also supported. + +The following Point3_\<\> aliases are available: +@code + typedef Point3_ Point3i; + typedef Point3_ Point3f; + typedef Point3_ Point3d; +@endcode +@see cv::Point3i, cv::Point3f and cv::Point3d +*/ +template class Point3_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Point3_(); + Point3_(_Tp _x, _Tp _y, _Tp _z); + Point3_(const Point3_& pt); + Point3_(Point3_&& pt) CV_NOEXCEPT; + explicit Point3_(const Point_<_Tp>& pt); + Point3_(const Vec<_Tp, 3>& v); + + Point3_& operator = (const Point3_& pt); + Point3_& operator = (Point3_&& pt) CV_NOEXCEPT; + //! conversion to another data type + template operator Point3_<_Tp2>() const; + //! conversion to cv::Vec<> + operator Vec<_Tp, 3>() const; + + //! dot product + _Tp dot(const Point3_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point3_& pt) const; + //! cross product of the 2 3D points + Point3_ cross(const Point3_& pt) const; + _Tp x; //!< x coordinate of the 3D point + _Tp y; //!< y coordinate of the 3D point + _Tp z; //!< z coordinate of the 3D point +}; + +typedef Point3_ Point3i; +typedef Point3_ Point3f; +typedef Point3_ Point3d; + +template class DataType< Point3_<_Tp> > +{ +public: + typedef Point3_<_Tp> value_type; + typedef Point3_::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 3, + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template +struct Depth< Point3_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Point3_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 3) }; }; +} // namespace + +//////////////////////////////// Size_ //////////////////////////////// + +/** @brief Template class for specifying the size of an image or rectangle. + +The class includes two members called width and height. The structure can be converted to and from +the old OpenCV structures CvSize and CvSize2D32f . The same set of arithmetic and comparison +operations as for Point_ is available. + +OpenCV defines the following Size_\<\> aliases: +@code + typedef Size_ Size2i; + typedef Size2i Size; + typedef Size_ Size2f; +@endcode +*/ +template class Size_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Size_(); + Size_(_Tp _width, _Tp _height); + Size_(const Size_& sz); + Size_(Size_&& sz) CV_NOEXCEPT; + Size_(const Point_<_Tp>& pt); + + Size_& operator = (const Size_& sz); + Size_& operator = (Size_&& sz) CV_NOEXCEPT; + //! the area (width*height) + _Tp area() const; + //! aspect ratio (width/height) + double aspectRatio() const; + //! true if empty + bool empty() const; + + //! conversion of another data type. + template operator Size_<_Tp2>() const; + + _Tp width; //!< the width + _Tp height; //!< the height +}; + +typedef Size_ Size2i; +typedef Size_ Size2l; +typedef Size_ Size2f; +typedef Size_ Size2d; +typedef Size2i Size; + +template class DataType< Size_<_Tp> > +{ +public: + typedef Size_<_Tp> value_type; + typedef Size_::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template +struct Depth< Size_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Size_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; }; +} // namespace + +//////////////////////////////// Rect_ //////////////////////////////// + +/** @brief Template class for 2D rectangles + +described by the following parameters: +- Coordinates of the top-left corner. This is a default interpretation of Rect_::x and Rect_::y + in OpenCV. Though, in your algorithms you may count x and y from the bottom-left corner. +- Rectangle width and height. + +OpenCV typically assumes that the top and left boundary of the rectangle are inclusive, while the +right and bottom boundaries are not. For example, the method Rect_::contains returns true if + +\f[x \leq pt.x < x+width, + y \leq pt.y < y+height\f] + +Virtually every loop over an image ROI in OpenCV (where ROI is specified by Rect_\ ) is +implemented as: +@code + for(int y = roi.y; y < roi.y + roi.height; y++) + for(int x = roi.x; x < roi.x + roi.width; x++) + { + // ... + } +@endcode +In addition to the class members, the following operations on rectangles are implemented: +- \f$\texttt{rect} = \texttt{rect} \pm \texttt{point}\f$ (shifting a rectangle by a certain offset) +- \f$\texttt{rect} = \texttt{rect} \pm \texttt{size}\f$ (expanding or shrinking a rectangle by a + certain amount) +- rect += point, rect -= point, rect += size, rect -= size (augmenting operations) +- rect = rect1 & rect2 (rectangle intersection) +- rect = rect1 | rect2 (minimum area rectangle containing rect1 and rect2 ) +- rect &= rect1, rect |= rect1 (and the corresponding augmenting operations) +- rect == rect1, rect != rect1 (rectangle comparison) + +This is an example how the partial ordering on rectangles can be established (rect1 \f$\subseteq\f$ +rect2): +@code + template inline bool + operator <= (const Rect_<_Tp>& r1, const Rect_<_Tp>& r2) + { + return (r1 & r2) == r1; + } +@endcode +For your convenience, the Rect_\<\> alias is available: cv::Rect +*/ +template class Rect_ +{ +public: + typedef _Tp value_type; + + //! default constructor + Rect_(); + Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); + Rect_(const Rect_& r); + Rect_(Rect_&& r) CV_NOEXCEPT; + Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); + Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); + + Rect_& operator = ( const Rect_& r ); + Rect_& operator = ( Rect_&& r ) CV_NOEXCEPT; + //! the top-left corner + Point_<_Tp> tl() const; + //! the bottom-right corner + Point_<_Tp> br() const; + + //! size (width, height) of the rectangle + Size_<_Tp> size() const; + //! area (width*height) of the rectangle + _Tp area() const; + //! true if empty + bool empty() const; + + //! conversion to another data type + template operator Rect_<_Tp2>() const; + + //! checks whether the rectangle contains the point + bool contains(const Point_<_Tp>& pt) const; + + _Tp x; //!< x coordinate of the top-left corner + _Tp y; //!< y coordinate of the top-left corner + _Tp width; //!< width of the rectangle + _Tp height; //!< height of the rectangle +}; + +typedef Rect_ Rect2i; +typedef Rect_ Rect2f; +typedef Rect_ Rect2d; +typedef Rect2i Rect; + +template class DataType< Rect_<_Tp> > +{ +public: + typedef Rect_<_Tp> value_type; + typedef Rect_::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 4, + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template +struct Depth< Rect_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Rect_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; }; +} // namespace + +///////////////////////////// RotatedRect ///////////////////////////// + +/** @brief The class represents rotated (i.e. not up-right) rectangles on a plane. + +Each rectangle is specified by the center point (mass center), length of each side (represented by +#Size2f structure) and the rotation angle in degrees. + +The sample below demonstrates how to use RotatedRect: +@snippet snippets/core_various.cpp RotatedRect_demo +![image](pics/rotatedrect.png) + +@sa CamShift, fitEllipse, minAreaRect, CvBox2D +*/ +class CV_EXPORTS RotatedRect +{ +public: + //! default constructor + RotatedRect(); + /** full constructor + @param center The rectangle mass center. + @param size Width and height of the rectangle. + @param angle The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., + the rectangle becomes an up-right rectangle. + */ + RotatedRect(const Point2f& center, const Size2f& size, float angle); + /** + Any 3 end points of the RotatedRect. They must be given in order (either clockwise or + anticlockwise). + */ + RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3); + + /** returns 4 vertices of the rectangle + @param pts The points array for storing rectangle vertices. The order is bottomLeft, topLeft, topRight, bottomRight. + */ + void points(Point2f pts[]) const; + //! returns the minimal up-right integer rectangle containing the rotated rectangle + Rect boundingRect() const; + //! returns the minimal (exact) floating point rectangle containing the rotated rectangle, not intended for use with images + Rect_ boundingRect2f() const; + //! returns the rectangle mass center + Point2f center; + //! returns width and height of the rectangle + Size2f size; + //! returns the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle. + float angle; +}; + +template<> class DataType< RotatedRect > +{ +public: + typedef RotatedRect value_type; + typedef value_type work_type; + typedef float channel_type; + + enum { generic_type = 0, + channels = (int)sizeof(value_type)/sizeof(channel_type), // 5 + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template<> +struct Depth< RotatedRect > { enum { value = Depth::value }; }; +template<> +struct Type< RotatedRect > { enum { value = CV_MAKETYPE(Depth::value, (int)sizeof(RotatedRect)/sizeof(float)) }; }; +} // namespace + + +//////////////////////////////// Range ///////////////////////////////// + +/** @brief Template class specifying a continuous subsequence (slice) of a sequence. + +The class is used to specify a row or a column span in a matrix ( Mat ) and for many other purposes. +Range(a,b) is basically the same as a:b in Matlab or a..b in Python. As in Python, start is an +inclusive left boundary of the range and end is an exclusive right boundary of the range. Such a +half-opened interval is usually denoted as \f$[start,end)\f$ . + +The static method Range::all() returns a special variable that means "the whole sequence" or "the +whole range", just like " : " in Matlab or " ... " in Python. All the methods and functions in +OpenCV that take Range support this special Range::all() value. But, of course, in case of your own +custom processing, you will probably have to check and handle it explicitly: +@code + void my_function(..., const Range& r, ....) + { + if(r == Range::all()) { + // process all the data + } + else { + // process [r.start, r.end) + } + } +@endcode +*/ +class CV_EXPORTS Range +{ +public: + Range(); + Range(int _start, int _end); + int size() const; + bool empty() const; + static Range all(); + + int start, end; +}; + +template<> class DataType +{ +public: + typedef Range value_type; + typedef value_type work_type; + typedef int channel_type; + + enum { generic_type = 0, + channels = 2, + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template<> +struct Depth< Range > { enum { value = Depth::value }; }; +template<> +struct Type< Range > { enum { value = CV_MAKETYPE(Depth::value, 2) }; }; +} // namespace + + +//////////////////////////////// Scalar_ /////////////////////////////// + +/** @brief Template class for a 4-element vector derived from Vec. + +Being derived from Vec\<_Tp, 4\> , Scalar\_ and Scalar can be used just as typical 4-element +vectors. In addition, they can be converted to/from CvScalar . The type Scalar is widely used in +OpenCV to pass pixel values. +*/ +template class Scalar_ : public Vec<_Tp, 4> +{ +public: + //! default constructor + Scalar_(); + Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0); + Scalar_(_Tp v0); + + Scalar_(const Scalar_& s); + Scalar_(Scalar_&& s) CV_NOEXCEPT; + + Scalar_& operator=(const Scalar_& s); + Scalar_& operator=(Scalar_&& s) CV_NOEXCEPT; + + template + Scalar_(const Vec<_Tp2, cn>& v); + + //! returns a scalar with all elements set to v0 + static Scalar_<_Tp> all(_Tp v0); + + //! conversion to another data type + template operator Scalar_() const; + + //! per-element product + Scalar_<_Tp> mul(const Scalar_<_Tp>& a, double scale=1 ) const; + + //! returns (v0, -v1, -v2, -v3) + Scalar_<_Tp> conj() const; + + //! returns true iff v1 == v2 == v3 == 0 + bool isReal() const; +}; + +typedef Scalar_ Scalar; + +template class DataType< Scalar_<_Tp> > +{ +public: + typedef Scalar_<_Tp> value_type; + typedef Scalar_::work_type> work_type; + typedef _Tp channel_type; + + enum { generic_type = 0, + channels = 4, + fmt = traits::SafeFmt::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template +struct Depth< Scalar_<_Tp> > { enum { value = Depth<_Tp>::value }; }; +template +struct Type< Scalar_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; }; +} // namespace + + +/////////////////////////////// KeyPoint //////////////////////////////// + +/** @brief Data structure for salient point detectors. + +The class instance stores a keypoint, i.e. a point feature found by one of many available keypoint +detectors, such as Harris corner detector, #FAST, %StarDetector, %SURF, %SIFT etc. + +The keypoint is characterized by the 2D position, scale (proportional to the diameter of the +neighborhood that needs to be taken into account), orientation and some other parameters. The +keypoint neighborhood is then analyzed by another algorithm that builds a descriptor (usually +represented as a feature vector). The keypoints representing the same object in different images +can then be matched using %KDTree or another method. +*/ +class CV_EXPORTS_W_SIMPLE KeyPoint +{ +public: + //! the default constructor + CV_WRAP KeyPoint(); + /** + @param _pt x & y coordinates of the keypoint + @param _size keypoint diameter + @param _angle keypoint orientation + @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param _octave pyramid octave in which the keypoint has been detected + @param _class_id object id + */ + KeyPoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + /** + @param x x-coordinate of the keypoint + @param y y-coordinate of the keypoint + @param _size keypoint diameter + @param _angle keypoint orientation + @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param _octave pyramid octave in which the keypoint has been detected + @param _class_id object id + */ + CV_WRAP KeyPoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + + size_t hash() const; + + /** + This method converts vector of keypoints to vector of points or the reverse, where each keypoint is + assigned the same size and the same orientation. + + @param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB + @param points2f Array of (x,y) coordinates of each keypoint + @param keypointIndexes Array of indexes of keypoints to be converted to points. (Acts like a mask to + convert only specified keypoints) + */ + CV_WRAP static void convert(const std::vector& keypoints, + CV_OUT std::vector& points2f, + const std::vector& keypointIndexes=std::vector()); + /** @overload + @param points2f Array of (x,y) coordinates of each keypoint + @param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB + @param size keypoint diameter + @param response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param octave pyramid octave in which the keypoint has been detected + @param class_id object id + */ + CV_WRAP static void convert(const std::vector& points2f, + CV_OUT std::vector& keypoints, + float size=1, float response=1, int octave=0, int class_id=-1); + + /** + This method computes overlap for pair of keypoints. Overlap is the ratio between area of keypoint + regions' intersection and area of keypoint regions' union (considering keypoint region as circle). + If they don't overlap, we get zero. If they coincide at same location with same size, we get 1. + @param kp1 First keypoint + @param kp2 Second keypoint + */ + CV_WRAP static float overlap(const KeyPoint& kp1, const KeyPoint& kp2); + + CV_PROP_RW Point2f pt; //!< coordinates of the keypoints + CV_PROP_RW float size; //!< diameter of the meaningful keypoint neighborhood + CV_PROP_RW float angle; //!< computed orientation of the keypoint (-1 if not applicable); + //!< it's in [0,360) degrees and measured relative to + //!< image coordinate system, ie in clockwise. + CV_PROP_RW float response; //!< the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling + CV_PROP_RW int octave; //!< octave (pyramid layer) from which the keypoint has been extracted + CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to) +}; + +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED +template<> class DataType +{ +public: + typedef KeyPoint value_type; + typedef float work_type; + typedef float channel_type; + + enum { generic_type = 0, + depth = DataType::depth, + channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 7 + fmt = DataType::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) + }; + + typedef Vec vec_type; +}; +#endif + + +//////////////////////////////// DMatch ///////////////////////////////// + +/** @brief Class for matching keypoint descriptors + +query descriptor index, train descriptor index, train image index, and distance between +descriptors. +*/ +class CV_EXPORTS_W_SIMPLE DMatch +{ +public: + CV_WRAP DMatch(); + CV_WRAP DMatch(int _queryIdx, int _trainIdx, float _distance); + CV_WRAP DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance); + + CV_PROP_RW int queryIdx; //!< query descriptor index + CV_PROP_RW int trainIdx; //!< train descriptor index + CV_PROP_RW int imgIdx; //!< train image index + + CV_PROP_RW float distance; + + // less is better + bool operator<(const DMatch &m) const; +}; + +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED +template<> class DataType +{ +public: + typedef DMatch value_type; + typedef int work_type; + typedef int channel_type; + + enum { generic_type = 0, + depth = DataType::depth, + channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 4 + fmt = DataType::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) + }; + + typedef Vec vec_type; +}; +#endif + + +///////////////////////////// TermCriteria ////////////////////////////// + +/** @brief The class defining termination criteria for iterative algorithms. + +You can initialize it by default constructor and then override any parameters, or the structure may +be fully initialized using the advanced variant of the constructor. +*/ +class CV_EXPORTS TermCriteria +{ +public: + /** + Criteria type, can be one of: COUNT, EPS or COUNT + EPS + */ + enum Type + { + COUNT=1, //!< the maximum number of iterations or elements to compute + MAX_ITER=COUNT, //!< ditto + EPS=2 //!< the desired accuracy or change in parameters at which the iterative algorithm stops + }; + + //! default constructor + TermCriteria(); + /** + @param type The type of termination criteria, one of TermCriteria::Type + @param maxCount The maximum number of iterations or elements to compute. + @param epsilon The desired accuracy or change in parameters at which the iterative algorithm stops. + */ + TermCriteria(int type, int maxCount, double epsilon); + + inline bool isValid() const + { + const bool isCount = (type & COUNT) && maxCount > 0; + const bool isEps = (type & EPS) && !cvIsNaN(epsilon); + return isCount || isEps; + } + + int type; //!< the type of termination criteria: COUNT, EPS or COUNT + EPS + int maxCount; //!< the maximum number of iterations/elements + double epsilon; //!< the desired accuracy +}; + + +//! @} core_basic + +///////////////////////// raster image moments ////////////////////////// + +//! @addtogroup imgproc_shape +//! @{ + +/** @brief struct returned by cv::moments + +The spatial moments \f$\texttt{Moments::m}_{ji}\f$ are computed as: + +\f[\texttt{m} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot x^j \cdot y^i \right )\f] + +The central moments \f$\texttt{Moments::mu}_{ji}\f$ are computed as: + +\f[\texttt{mu} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot (x - \bar{x} )^j \cdot (y - \bar{y} )^i \right )\f] + +where \f$(\bar{x}, \bar{y})\f$ is the mass center: + +\f[\bar{x} = \frac{\texttt{m}_{10}}{\texttt{m}_{00}} , \; \bar{y} = \frac{\texttt{m}_{01}}{\texttt{m}_{00}}\f] + +The normalized central moments \f$\texttt{Moments::nu}_{ij}\f$ are computed as: + +\f[\texttt{nu} _{ji}= \frac{\texttt{mu}_{ji}}{\texttt{m}_{00}^{(i+j)/2+1}} .\f] + +@note +\f$\texttt{mu}_{00}=\texttt{m}_{00}\f$, \f$\texttt{nu}_{00}=1\f$ +\f$\texttt{nu}_{10}=\texttt{mu}_{10}=\texttt{mu}_{01}=\texttt{mu}_{10}=0\f$ , hence the values are not +stored. + +The moments of a contour are defined in the same way but computed using the Green's formula (see +). So, due to a limited raster resolution, the moments +computed for a contour are slightly different from the moments computed for the same rasterized +contour. + +@note +Since the contour moments are computed using Green formula, you may get seemingly odd results for +contours with self-intersections, e.g. a zero area (m00) for butterfly-shaped contours. + */ +class CV_EXPORTS_W_MAP Moments +{ +public: + //! the default constructor + Moments(); + //! the full constructor + Moments(double m00, double m10, double m01, double m20, double m11, + double m02, double m30, double m21, double m12, double m03 ); + ////! the conversion from CvMoments + //Moments( const CvMoments& moments ); + ////! the conversion to CvMoments + //operator CvMoments() const; + + //! @name spatial moments + //! @{ + CV_PROP_RW double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; + //! @} + + //! @name central moments + //! @{ + CV_PROP_RW double mu20, mu11, mu02, mu30, mu21, mu12, mu03; + //! @} + + //! @name central normalized moments + //! @{ + CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03; + //! @} +}; + +template<> class DataType +{ +public: + typedef Moments value_type; + typedef double work_type; + typedef double channel_type; + + enum { generic_type = 0, + channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24 + fmt = DataType::fmt + ((channels - 1) << 8) +#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED + ,depth = DataType::depth + ,type = CV_MAKETYPE(depth, channels) +#endif + }; + + typedef Vec vec_type; +}; + +namespace traits { +template<> +struct Depth< Moments > { enum { value = Depth::value }; }; +template<> +struct Type< Moments > { enum { value = CV_MAKETYPE(Depth::value, (int)(sizeof(Moments)/sizeof(double))) }; }; +} // namespace + +//! @} imgproc_shape + +//! @cond IGNORED + +///////////////////////////////////////////////////////////////////////// +///////////////////////////// Implementation //////////////////////////// +///////////////////////////////////////////////////////////////////////// + +//////////////////////////////// Complex //////////////////////////////// + +template inline +Complex<_Tp>::Complex() + : re(0), im(0) {} + +template inline +Complex<_Tp>::Complex( _Tp _re, _Tp _im ) + : re(_re), im(_im) {} + +template template inline +Complex<_Tp>::operator Complex() const +{ + return Complex(saturate_cast(re), saturate_cast(im)); +} + +template inline +Complex<_Tp> Complex<_Tp>::conj() const +{ + return Complex<_Tp>(re, -im); +} + + +template static inline +bool operator == (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return a.re == b.re && a.im == b.im; +} + +template static inline +bool operator != (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return a.re != b.re || a.im != b.im; +} + +template static inline +Complex<_Tp> operator + (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return Complex<_Tp>( a.re + b.re, a.im + b.im ); +} + +template static inline +Complex<_Tp>& operator += (Complex<_Tp>& a, const Complex<_Tp>& b) +{ + a.re += b.re; a.im += b.im; + return a; +} + +template static inline +Complex<_Tp> operator - (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return Complex<_Tp>( a.re - b.re, a.im - b.im ); +} + +template static inline +Complex<_Tp>& operator -= (Complex<_Tp>& a, const Complex<_Tp>& b) +{ + a.re -= b.re; a.im -= b.im; + return a; +} + +template static inline +Complex<_Tp> operator - (const Complex<_Tp>& a) +{ + return Complex<_Tp>(-a.re, -a.im); +} + +template static inline +Complex<_Tp> operator * (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + return Complex<_Tp>( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re ); +} + +template static inline +Complex<_Tp> operator * (const Complex<_Tp>& a, _Tp b) +{ + return Complex<_Tp>( a.re*b, a.im*b ); +} + +template static inline +Complex<_Tp> operator * (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>( a.re*b, a.im*b ); +} + +template static inline +Complex<_Tp> operator + (const Complex<_Tp>& a, _Tp b) +{ + return Complex<_Tp>( a.re + b, a.im ); +} + +template static inline +Complex<_Tp> operator - (const Complex<_Tp>& a, _Tp b) +{ return Complex<_Tp>( a.re - b, a.im ); } + +template static inline +Complex<_Tp> operator + (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>( a.re + b, a.im ); +} + +template static inline +Complex<_Tp> operator - (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>( b - a.re, -a.im ); +} + +template static inline +Complex<_Tp>& operator += (Complex<_Tp>& a, _Tp b) +{ + a.re += b; return a; +} + +template static inline +Complex<_Tp>& operator -= (Complex<_Tp>& a, _Tp b) +{ + a.re -= b; return a; +} + +template static inline +Complex<_Tp>& operator *= (Complex<_Tp>& a, _Tp b) +{ + a.re *= b; a.im *= b; return a; +} + +template static inline +double abs(const Complex<_Tp>& a) +{ + return std::sqrt( (double)a.re*a.re + (double)a.im*a.im); +} + +template static inline +Complex<_Tp> operator / (const Complex<_Tp>& a, const Complex<_Tp>& b) +{ + double t = 1./((double)b.re*b.re + (double)b.im*b.im); + return Complex<_Tp>( (_Tp)((a.re*b.re + a.im*b.im)*t), + (_Tp)((-a.re*b.im + a.im*b.re)*t) ); +} + +template static inline +Complex<_Tp>& operator /= (Complex<_Tp>& a, const Complex<_Tp>& b) +{ + a = a / b; + return a; +} + +template static inline +Complex<_Tp> operator / (const Complex<_Tp>& a, _Tp b) +{ + _Tp t = (_Tp)1/b; + return Complex<_Tp>( a.re*t, a.im*t ); +} + +template static inline +Complex<_Tp> operator / (_Tp b, const Complex<_Tp>& a) +{ + return Complex<_Tp>(b)/a; +} + +template static inline +Complex<_Tp> operator /= (const Complex<_Tp>& a, _Tp b) +{ + _Tp t = (_Tp)1/b; + a.re *= t; a.im *= t; return a; +} + + + +//////////////////////////////// 2D Point /////////////////////////////// + +template inline +Point_<_Tp>::Point_() + : x(0), y(0) {} + +template inline +Point_<_Tp>::Point_(_Tp _x, _Tp _y) + : x(_x), y(_y) {} + +template inline +Point_<_Tp>::Point_(const Point_& pt) + : x(pt.x), y(pt.y) {} + +template inline +Point_<_Tp>::Point_(Point_&& pt) CV_NOEXCEPT + : x(std::move(pt.x)), y(std::move(pt.y)) {} + +template inline +Point_<_Tp>::Point_(const Size_<_Tp>& sz) + : x(sz.width), y(sz.height) {} + +template inline +Point_<_Tp>::Point_(const Vec<_Tp,2>& v) + : x(v[0]), y(v[1]) {} + +template inline +Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt) +{ + x = pt.x; y = pt.y; + return *this; +} + +template inline +Point_<_Tp>& Point_<_Tp>::operator = (Point_&& pt) CV_NOEXCEPT +{ + x = std::move(pt.x); y = std::move(pt.y); + return *this; +} + +template template inline +Point_<_Tp>::operator Point_<_Tp2>() const +{ + return Point_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y)); +} + +template inline +Point_<_Tp>::operator Vec<_Tp, 2>() const +{ + return Vec<_Tp, 2>(x, y); +} + +template inline +_Tp Point_<_Tp>::dot(const Point_& pt) const +{ + return saturate_cast<_Tp>(x*pt.x + y*pt.y); +} + +template inline +double Point_<_Tp>::ddot(const Point_& pt) const +{ + return (double)x*pt.x + (double)y*pt.y; +} + +template inline +double Point_<_Tp>::cross(const Point_& pt) const +{ + return (double)x*pt.y - (double)y*pt.x; +} + +template inline bool +Point_<_Tp>::inside( const Rect_<_Tp>& r ) const +{ + return r.contains(*this); +} + + +template static inline +Point_<_Tp>& operator += (Point_<_Tp>& a, const Point_<_Tp>& b) +{ + a.x += b.x; + a.y += b.y; + return a; +} + +template static inline +Point_<_Tp>& operator -= (Point_<_Tp>& a, const Point_<_Tp>& b) +{ + a.x -= b.x; + a.y -= b.y; + return a; +} + +template static inline +Point_<_Tp>& operator *= (Point_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + return a; +} + +template static inline +Point_<_Tp>& operator *= (Point_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + return a; +} + +template static inline +Point_<_Tp>& operator *= (Point_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + return a; +} + +template static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template static inline +Point_<_Tp>& operator /= (Point_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + return a; +} + +template static inline +double norm(const Point_<_Tp>& pt) +{ + return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y); +} + +template static inline +bool operator == (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return a.x == b.x && a.y == b.y; +} + +template static inline +bool operator != (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return a.x != b.x || a.y != b.y; +} + +template static inline +Point_<_Tp> operator + (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y) ); +} + +template static inline +Point_<_Tp> operator - (const Point_<_Tp>& a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y) ); +} + +template static inline +Point_<_Tp> operator - (const Point_<_Tp>& a) +{ + return Point_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y) ); +} + +template static inline +Point_<_Tp> operator * (const Point_<_Tp>& a, int b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); +} + +template static inline +Point_<_Tp> operator * (int a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); +} + +template static inline +Point_<_Tp> operator * (const Point_<_Tp>& a, float b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); +} + +template static inline +Point_<_Tp> operator * (float a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); +} + +template static inline +Point_<_Tp> operator * (const Point_<_Tp>& a, double b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) ); +} + +template static inline +Point_<_Tp> operator * (double a, const Point_<_Tp>& b) +{ + return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) ); +} + +template static inline +Point_<_Tp> operator * (const Matx<_Tp, 2, 2>& a, const Point_<_Tp>& b) +{ + Matx<_Tp, 2, 1> tmp = a * Vec<_Tp,2>(b.x, b.y); + return Point_<_Tp>(tmp.val[0], tmp.val[1]); +} + +template static inline +Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point_<_Tp>& b) +{ + Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, 1); + return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]); +} + +template static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, int b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, float b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point_<_Tp> operator / (const Point_<_Tp>& a, double b) +{ + Point_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + + +template static inline _AccTp normL2Sqr(const Point_& pt); +template static inline _AccTp normL2Sqr(const Point_& pt); +template static inline _AccTp normL2Sqr(const Point_& pt); +template static inline _AccTp normL2Sqr(const Point_& pt); + +template<> inline int normL2Sqr(const Point_& pt) { return pt.dot(pt); } +template<> inline int64 normL2Sqr(const Point_& pt) { return pt.dot(pt); } +template<> inline float normL2Sqr(const Point_& pt) { return pt.dot(pt); } +template<> inline double normL2Sqr(const Point_& pt) { return pt.dot(pt); } + +template<> inline double normL2Sqr(const Point_& pt) { return pt.ddot(pt); } +template<> inline double normL2Sqr(const Point_& pt) { return pt.ddot(pt); } + + + +//////////////////////////////// 3D Point /////////////////////////////// + +template inline +Point3_<_Tp>::Point3_() + : x(0), y(0), z(0) {} + +template inline +Point3_<_Tp>::Point3_(_Tp _x, _Tp _y, _Tp _z) + : x(_x), y(_y), z(_z) {} + +template inline +Point3_<_Tp>::Point3_(const Point3_& pt) + : x(pt.x), y(pt.y), z(pt.z) {} + +template inline +Point3_<_Tp>::Point3_(Point3_&& pt) CV_NOEXCEPT + : x(std::move(pt.x)), y(std::move(pt.y)), z(std::move(pt.z)) {} + +template inline +Point3_<_Tp>::Point3_(const Point_<_Tp>& pt) + : x(pt.x), y(pt.y), z(_Tp()) {} + +template inline +Point3_<_Tp>::Point3_(const Vec<_Tp, 3>& v) + : x(v[0]), y(v[1]), z(v[2]) {} + +template template inline +Point3_<_Tp>::operator Point3_<_Tp2>() const +{ + return Point3_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(z)); +} + +template inline +Point3_<_Tp>::operator Vec<_Tp, 3>() const +{ + return Vec<_Tp, 3>(x, y, z); +} + +template inline +Point3_<_Tp>& Point3_<_Tp>::operator = (const Point3_& pt) +{ + x = pt.x; y = pt.y; z = pt.z; + return *this; +} + +template inline +Point3_<_Tp>& Point3_<_Tp>::operator = (Point3_&& pt) CV_NOEXCEPT +{ + x = std::move(pt.x); y = std::move(pt.y); z = std::move(pt.z); + return *this; +} + +template inline +_Tp Point3_<_Tp>::dot(const Point3_& pt) const +{ + return saturate_cast<_Tp>(x*pt.x + y*pt.y + z*pt.z); +} + +template inline +double Point3_<_Tp>::ddot(const Point3_& pt) const +{ + return (double)x*pt.x + (double)y*pt.y + (double)z*pt.z; +} + +template inline +Point3_<_Tp> Point3_<_Tp>::cross(const Point3_<_Tp>& pt) const +{ + return Point3_<_Tp>(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x); +} + + +template static inline +Point3_<_Tp>& operator += (Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + a.x += b.x; + a.y += b.y; + a.z += b.z; + return a; +} + +template static inline +Point3_<_Tp>& operator -= (Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return a; +} + +template static inline +Point3_<_Tp>& operator *= (Point3_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + a.z = saturate_cast<_Tp>(a.z * b); + return a; +} + +template static inline +Point3_<_Tp>& operator *= (Point3_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + a.z = saturate_cast<_Tp>(a.z * b); + return a; +} + +template static inline +Point3_<_Tp>& operator *= (Point3_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x * b); + a.y = saturate_cast<_Tp>(a.y * b); + a.z = saturate_cast<_Tp>(a.z * b); + return a; +} + +template static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, int b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, float b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template static inline +Point3_<_Tp>& operator /= (Point3_<_Tp>& a, double b) +{ + a.x = saturate_cast<_Tp>(a.x / b); + a.y = saturate_cast<_Tp>(a.y / b); + a.z = saturate_cast<_Tp>(a.z / b); + return a; +} + +template static inline +double norm(const Point3_<_Tp>& pt) +{ + return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y + (double)pt.z*pt.z); +} + +template static inline +bool operator == (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return a.x == b.x && a.y == b.y && a.z == b.z; +} + +template static inline +bool operator != (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return a.x != b.x || a.y != b.y || a.z != b.z; +} + +template static inline +Point3_<_Tp> operator + (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y), saturate_cast<_Tp>(a.z + b.z)); +} + +template static inline +Point3_<_Tp> operator - (const Point3_<_Tp>& a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y), saturate_cast<_Tp>(a.z - b.z)); +} + +template static inline +Point3_<_Tp> operator - (const Point3_<_Tp>& a) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y), saturate_cast<_Tp>(-a.z) ); +} + +template static inline +Point3_<_Tp> operator * (const Point3_<_Tp>& a, int b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b), saturate_cast<_Tp>(a.z*b) ); +} + +template static inline +Point3_<_Tp> operator * (int a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) ); +} + +template static inline +Point3_<_Tp> operator * (const Point3_<_Tp>& a, float b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) ); +} + +template static inline +Point3_<_Tp> operator * (float a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) ); +} + +template static inline +Point3_<_Tp> operator * (const Point3_<_Tp>& a, double b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) ); +} + +template static inline +Point3_<_Tp> operator * (double a, const Point3_<_Tp>& b) +{ + return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) ); +} + +template static inline +Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point3_<_Tp>& b) +{ + Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, b.z); + return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]); +} + +template static inline +Matx<_Tp, 4, 1> operator * (const Matx<_Tp, 4, 4>& a, const Point3_<_Tp>& b) +{ + return a * Matx<_Tp, 4, 1>(b.x, b.y, b.z, 1); +} + +template static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, int b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, float b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Point3_<_Tp> operator / (const Point3_<_Tp>& a, double b) +{ + Point3_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + + + +////////////////////////////////// Size ///////////////////////////////// + +template inline +Size_<_Tp>::Size_() + : width(0), height(0) {} + +template inline +Size_<_Tp>::Size_(_Tp _width, _Tp _height) + : width(_width), height(_height) {} + +template inline +Size_<_Tp>::Size_(const Size_& sz) + : width(sz.width), height(sz.height) {} + +template inline +Size_<_Tp>::Size_(Size_&& sz) CV_NOEXCEPT + : width(std::move(sz.width)), height(std::move(sz.height)) {} + +template inline +Size_<_Tp>::Size_(const Point_<_Tp>& pt) + : width(pt.x), height(pt.y) {} + +template template inline +Size_<_Tp>::operator Size_<_Tp2>() const +{ + return Size_<_Tp2>(saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height)); +} + +template inline +Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz) +{ + width = sz.width; height = sz.height; + return *this; +} + +template inline +Size_<_Tp>& Size_<_Tp>::operator = (Size_<_Tp>&& sz) CV_NOEXCEPT +{ + width = std::move(sz.width); height = std::move(sz.height); + return *this; +} + +template inline +_Tp Size_<_Tp>::area() const +{ + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; +} + +template inline +double Size_<_Tp>::aspectRatio() const +{ + return width / static_cast(height); +} + +template inline +bool Size_<_Tp>::empty() const +{ + return width <= 0 || height <= 0; +} + + +template static inline +Size_<_Tp>& operator *= (Size_<_Tp>& a, _Tp b) +{ + a.width *= b; + a.height *= b; + return a; +} + +template static inline +Size_<_Tp> operator * (const Size_<_Tp>& a, _Tp b) +{ + Size_<_Tp> tmp(a); + tmp *= b; + return tmp; +} + +template static inline +Size_<_Tp>& operator /= (Size_<_Tp>& a, _Tp b) +{ + a.width /= b; + a.height /= b; + return a; +} + +template static inline +Size_<_Tp> operator / (const Size_<_Tp>& a, _Tp b) +{ + Size_<_Tp> tmp(a); + tmp /= b; + return tmp; +} + +template static inline +Size_<_Tp>& operator += (Size_<_Tp>& a, const Size_<_Tp>& b) +{ + a.width += b.width; + a.height += b.height; + return a; +} + +template static inline +Size_<_Tp> operator + (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + Size_<_Tp> tmp(a); + tmp += b; + return tmp; +} + +template static inline +Size_<_Tp>& operator -= (Size_<_Tp>& a, const Size_<_Tp>& b) +{ + a.width -= b.width; + a.height -= b.height; + return a; +} + +template static inline +Size_<_Tp> operator - (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + Size_<_Tp> tmp(a); + tmp -= b; + return tmp; +} + +template static inline +bool operator == (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + return a.width == b.width && a.height == b.height; +} + +template static inline +bool operator != (const Size_<_Tp>& a, const Size_<_Tp>& b) +{ + return !(a == b); +} + + + +////////////////////////////////// Rect ///////////////////////////////// + +template inline +Rect_<_Tp>::Rect_() + : x(0), y(0), width(0), height(0) {} + +template inline +Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height) + : x(_x), y(_y), width(_width), height(_height) {} + +template inline +Rect_<_Tp>::Rect_(const Rect_<_Tp>& r) + : x(r.x), y(r.y), width(r.width), height(r.height) {} + +template inline +Rect_<_Tp>::Rect_(Rect_<_Tp>&& r) CV_NOEXCEPT + : x(std::move(r.x)), y(std::move(r.y)), width(std::move(r.width)), height(std::move(r.height)) {} + +template inline +Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz) + : x(org.x), y(org.y), width(sz.width), height(sz.height) {} + +template inline +Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2) +{ + x = std::min(pt1.x, pt2.x); + y = std::min(pt1.y, pt2.y); + width = std::max(pt1.x, pt2.x) - x; + height = std::max(pt1.y, pt2.y) - y; +} + +template inline +Rect_<_Tp>& Rect_<_Tp>::operator = ( const Rect_<_Tp>& r ) +{ + x = r.x; + y = r.y; + width = r.width; + height = r.height; + return *this; +} + +template inline +Rect_<_Tp>& Rect_<_Tp>::operator = ( Rect_<_Tp>&& r ) CV_NOEXCEPT +{ + x = std::move(r.x); + y = std::move(r.y); + width = std::move(r.width); + height = std::move(r.height); + return *this; +} + +template inline +Point_<_Tp> Rect_<_Tp>::tl() const +{ + return Point_<_Tp>(x,y); +} + +template inline +Point_<_Tp> Rect_<_Tp>::br() const +{ + return Point_<_Tp>(x + width, y + height); +} + +template inline +Size_<_Tp> Rect_<_Tp>::size() const +{ + return Size_<_Tp>(width, height); +} + +template inline +_Tp Rect_<_Tp>::area() const +{ + const _Tp result = width * height; + CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer + || width == 0 || result / width == height); // make sure the result fits in the return value + return result; +} + +template inline +bool Rect_<_Tp>::empty() const +{ + return width <= 0 || height <= 0; +} + +template template inline +Rect_<_Tp>::operator Rect_<_Tp2>() const +{ + return Rect_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height)); +} + +template inline +bool Rect_<_Tp>::contains(const Point_<_Tp>& pt) const +{ + return x <= pt.x && pt.x < x + width && y <= pt.y && pt.y < y + height; +} + + +template static inline +Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Point_<_Tp>& b ) +{ + a.x += b.x; + a.y += b.y; + return a; +} + +template static inline +Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Point_<_Tp>& b ) +{ + a.x -= b.x; + a.y -= b.y; + return a; +} + +template static inline +Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Size_<_Tp>& b ) +{ + a.width += b.width; + a.height += b.height; + return a; +} + +template static inline +Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Size_<_Tp>& b ) +{ + const _Tp width = a.width - b.width; + const _Tp height = a.height - b.height; + CV_DbgAssert(width >= 0 && height >= 0); + a.width = width; + a.height = height; + return a; +} + +template static inline +Rect_<_Tp>& operator &= ( Rect_<_Tp>& a, const Rect_<_Tp>& b ) +{ + _Tp x1 = std::max(a.x, b.x); + _Tp y1 = std::max(a.y, b.y); + a.width = std::min(a.x + a.width, b.x + b.width) - x1; + a.height = std::min(a.y + a.height, b.y + b.height) - y1; + a.x = x1; + a.y = y1; + if( a.width <= 0 || a.height <= 0 ) + a = Rect(); + return a; +} + +template static inline +Rect_<_Tp>& operator |= ( Rect_<_Tp>& a, const Rect_<_Tp>& b ) +{ + if (a.empty()) { + a = b; + } + else if (!b.empty()) { + _Tp x1 = std::min(a.x, b.x); + _Tp y1 = std::min(a.y, b.y); + a.width = std::max(a.x + a.width, b.x + b.width) - x1; + a.height = std::max(a.y + a.height, b.y + b.height) - y1; + a.x = x1; + a.y = y1; + } + return a; +} + +template static inline +bool operator == (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; +} + +template static inline +bool operator != (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height; +} + +template static inline +Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Point_<_Tp>& b) +{ + return Rect_<_Tp>( a.x + b.x, a.y + b.y, a.width, a.height ); +} + +template static inline +Rect_<_Tp> operator - (const Rect_<_Tp>& a, const Point_<_Tp>& b) +{ + return Rect_<_Tp>( a.x - b.x, a.y - b.y, a.width, a.height ); +} + +template static inline +Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Size_<_Tp>& b) +{ + return Rect_<_Tp>( a.x, a.y, a.width + b.width, a.height + b.height ); +} + +template static inline +Rect_<_Tp> operator - (const Rect_<_Tp>& a, const Size_<_Tp>& b) +{ + const _Tp width = a.width - b.width; + const _Tp height = a.height - b.height; + CV_DbgAssert(width >= 0 && height >= 0); + return Rect_<_Tp>( a.x, a.y, width, height ); +} + +template static inline +Rect_<_Tp> operator & (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + Rect_<_Tp> c = a; + return c &= b; +} + +template static inline +Rect_<_Tp> operator | (const Rect_<_Tp>& a, const Rect_<_Tp>& b) +{ + Rect_<_Tp> c = a; + return c |= b; +} + +/** + * @brief measure dissimilarity between two sample sets + * + * computes the complement of the Jaccard Index as described in . + * For rectangles this reduces to computing the intersection over the union. + */ +template static inline +double jaccardDistance(const Rect_<_Tp>& a, const Rect_<_Tp>& b) { + _Tp Aa = a.area(); + _Tp Ab = b.area(); + + if ((Aa + Ab) <= std::numeric_limits<_Tp>::epsilon()) { + // jaccard_index = 1 -> distance = 0 + return 0.0; + } + + double Aab = (a & b).area(); + // distance = 1 - jaccard_index + return 1.0 - Aab / (Aa + Ab - Aab); +} + +////////////////////////////// RotatedRect ////////////////////////////// + +inline +RotatedRect::RotatedRect() + : center(), size(), angle(0) {} + +inline +RotatedRect::RotatedRect(const Point2f& _center, const Size2f& _size, float _angle) + : center(_center), size(_size), angle(_angle) {} + +///////////////////////////////// Range ///////////////////////////////// + +inline +Range::Range() + : start(0), end(0) {} + +inline +Range::Range(int _start, int _end) + : start(_start), end(_end) {} + +inline +int Range::size() const +{ + return end - start; +} + +inline +bool Range::empty() const +{ + return start == end; +} + +inline +Range Range::all() +{ + return Range(INT_MIN, INT_MAX); +} + + +static inline +bool operator == (const Range& r1, const Range& r2) +{ + return r1.start == r2.start && r1.end == r2.end; +} + +static inline +bool operator != (const Range& r1, const Range& r2) +{ + return !(r1 == r2); +} + +static inline +bool operator !(const Range& r) +{ + return r.start == r.end; +} + +static inline +Range operator & (const Range& r1, const Range& r2) +{ + Range r(std::max(r1.start, r2.start), std::min(r1.end, r2.end)); + r.end = std::max(r.end, r.start); + return r; +} + +static inline +Range& operator &= (Range& r1, const Range& r2) +{ + r1 = r1 & r2; + return r1; +} + +static inline +Range operator + (const Range& r1, int delta) +{ + return Range(r1.start + delta, r1.end + delta); +} + +static inline +Range operator + (int delta, const Range& r1) +{ + return Range(r1.start + delta, r1.end + delta); +} + +static inline +Range operator - (const Range& r1, int delta) +{ + return r1 + (-delta); +} + + + +///////////////////////////////// Scalar //////////////////////////////// + +template inline +Scalar_<_Tp>::Scalar_() +{ + this->val[0] = this->val[1] = this->val[2] = this->val[3] = 0; +} + +template inline +Scalar_<_Tp>::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3) +{ + this->val[0] = v0; + this->val[1] = v1; + this->val[2] = v2; + this->val[3] = v3; +} + +template inline +Scalar_<_Tp>::Scalar_(const Scalar_<_Tp>& s) : Vec<_Tp, 4>(s) { +} + +template inline +Scalar_<_Tp>::Scalar_(Scalar_<_Tp>&& s) CV_NOEXCEPT { + this->val[0] = std::move(s.val[0]); + this->val[1] = std::move(s.val[1]); + this->val[2] = std::move(s.val[2]); + this->val[3] = std::move(s.val[3]); +} + +template inline +Scalar_<_Tp>& Scalar_<_Tp>::operator=(const Scalar_<_Tp>& s) { + this->val[0] = s.val[0]; + this->val[1] = s.val[1]; + this->val[2] = s.val[2]; + this->val[3] = s.val[3]; + return *this; +} + +template inline +Scalar_<_Tp>& Scalar_<_Tp>::operator=(Scalar_<_Tp>&& s) CV_NOEXCEPT { + this->val[0] = std::move(s.val[0]); + this->val[1] = std::move(s.val[1]); + this->val[2] = std::move(s.val[2]); + this->val[3] = std::move(s.val[3]); + return *this; +} + +template template inline +Scalar_<_Tp>::Scalar_(const Vec<_Tp2, cn>& v) +{ + int i; + for( i = 0; i < (cn < 4 ? cn : 4); i++ ) + this->val[i] = cv::saturate_cast<_Tp>(v.val[i]); + for( ; i < 4; i++ ) + this->val[i] = 0; +} + +template inline +Scalar_<_Tp>::Scalar_(_Tp v0) +{ + this->val[0] = v0; + this->val[1] = this->val[2] = this->val[3] = 0; +} + +template inline +Scalar_<_Tp> Scalar_<_Tp>::all(_Tp v0) +{ + return Scalar_<_Tp>(v0, v0, v0, v0); +} + + +template inline +Scalar_<_Tp> Scalar_<_Tp>::mul(const Scalar_<_Tp>& a, double scale ) const +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(this->val[0] * a.val[0] * scale), + saturate_cast<_Tp>(this->val[1] * a.val[1] * scale), + saturate_cast<_Tp>(this->val[2] * a.val[2] * scale), + saturate_cast<_Tp>(this->val[3] * a.val[3] * scale)); +} + +template inline +Scalar_<_Tp> Scalar_<_Tp>::conj() const +{ + return Scalar_<_Tp>(saturate_cast<_Tp>( this->val[0]), + saturate_cast<_Tp>(-this->val[1]), + saturate_cast<_Tp>(-this->val[2]), + saturate_cast<_Tp>(-this->val[3])); +} + +template inline +bool Scalar_<_Tp>::isReal() const +{ + return this->val[1] == 0 && this->val[2] == 0 && this->val[3] == 0; +} + + +template template inline +Scalar_<_Tp>::operator Scalar_() const +{ + return Scalar_(saturate_cast(this->val[0]), + saturate_cast(this->val[1]), + saturate_cast(this->val[2]), + saturate_cast(this->val[3])); +} + + +template static inline +Scalar_<_Tp>& operator += (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a.val[0] += b.val[0]; + a.val[1] += b.val[1]; + a.val[2] += b.val[2]; + a.val[3] += b.val[3]; + return a; +} + +template static inline +Scalar_<_Tp>& operator -= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a.val[0] -= b.val[0]; + a.val[1] -= b.val[1]; + a.val[2] -= b.val[2]; + a.val[3] -= b.val[3]; + return a; +} + +template static inline +Scalar_<_Tp>& operator *= ( Scalar_<_Tp>& a, _Tp v ) +{ + a.val[0] *= v; + a.val[1] *= v; + a.val[2] *= v; + a.val[3] *= v; + return a; +} + +template static inline +bool operator == ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b ) +{ + return a.val[0] == b.val[0] && a.val[1] == b.val[1] && + a.val[2] == b.val[2] && a.val[3] == b.val[3]; +} + +template static inline +bool operator != ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b ) +{ + return a.val[0] != b.val[0] || a.val[1] != b.val[1] || + a.val[2] != b.val[2] || a.val[3] != b.val[3]; +} + +template static inline +Scalar_<_Tp> operator + (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return Scalar_<_Tp>(a.val[0] + b.val[0], + a.val[1] + b.val[1], + a.val[2] + b.val[2], + a.val[3] + b.val[3]); +} + +template static inline +Scalar_<_Tp> operator - (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(a.val[0] - b.val[0]), + saturate_cast<_Tp>(a.val[1] - b.val[1]), + saturate_cast<_Tp>(a.val[2] - b.val[2]), + saturate_cast<_Tp>(a.val[3] - b.val[3])); +} + +template static inline +Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, _Tp alpha) +{ + return Scalar_<_Tp>(a.val[0] * alpha, + a.val[1] * alpha, + a.val[2] * alpha, + a.val[3] * alpha); +} + +template static inline +Scalar_<_Tp> operator * (_Tp alpha, const Scalar_<_Tp>& a) +{ + return a*alpha; +} + +template static inline +Scalar_<_Tp> operator - (const Scalar_<_Tp>& a) +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(-a.val[0]), + saturate_cast<_Tp>(-a.val[1]), + saturate_cast<_Tp>(-a.val[2]), + saturate_cast<_Tp>(-a.val[3])); +} + + +template static inline +Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return Scalar_<_Tp>(saturate_cast<_Tp>(a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3]), + saturate_cast<_Tp>(a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2]), + saturate_cast<_Tp>(a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1]), + saturate_cast<_Tp>(a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0])); +} + +template static inline +Scalar_<_Tp>& operator *= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a = a * b; + return a; +} + +template static inline +Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, _Tp alpha) +{ + return Scalar_<_Tp>(a.val[0] / alpha, + a.val[1] / alpha, + a.val[2] / alpha, + a.val[3] / alpha); +} + +template static inline +Scalar_ operator / (const Scalar_& a, float alpha) +{ + float s = 1 / alpha; + return Scalar_(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s); +} + +template static inline +Scalar_ operator / (const Scalar_& a, double alpha) +{ + double s = 1 / alpha; + return Scalar_(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s); +} + +template static inline +Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, _Tp alpha) +{ + a = a / alpha; + return a; +} + +template static inline +Scalar_<_Tp> operator / (_Tp a, const Scalar_<_Tp>& b) +{ + _Tp s = a / (b[0]*b[0] + b[1]*b[1] + b[2]*b[2] + b[3]*b[3]); + return b.conj() * s; +} + +template static inline +Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + return a * ((_Tp)1 / b); +} + +template static inline +Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b) +{ + a = a / b; + return a; +} + +template static inline +Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b) +{ + Matx c((Matx)a, b, Matx_MatMulOp()); + return reinterpret_cast(c); +} + +template<> inline +Scalar operator * (const Matx& a, const Scalar& b) +{ + Matx c(a, b, Matx_MatMulOp()); + return reinterpret_cast(c); +} + + + +//////////////////////////////// KeyPoint /////////////////////////////// + +inline +KeyPoint::KeyPoint() + : pt(0,0), size(0), angle(-1), response(0), octave(0), class_id(-1) {} + +inline +KeyPoint::KeyPoint(Point2f _pt, float _size, float _angle, float _response, int _octave, int _class_id) + : pt(_pt), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {} + +inline +KeyPoint::KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id) + : pt(x, y), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {} + + + +///////////////////////////////// DMatch //////////////////////////////// + +inline +DMatch::DMatch() + : queryIdx(-1), trainIdx(-1), imgIdx(-1), distance(FLT_MAX) {} + +inline +DMatch::DMatch(int _queryIdx, int _trainIdx, float _distance) + : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1), distance(_distance) {} + +inline +DMatch::DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) + : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx), distance(_distance) {} + +inline +bool DMatch::operator < (const DMatch &m) const +{ + return distance < m.distance; +} + + + +////////////////////////////// TermCriteria ///////////////////////////// + +inline +TermCriteria::TermCriteria() + : type(0), maxCount(0), epsilon(0) {} + +inline +TermCriteria::TermCriteria(int _type, int _maxCount, double _epsilon) + : type(_type), maxCount(_maxCount), epsilon(_epsilon) {} + +//! @endcond + +} // cv + +#endif //OPENCV_CORE_TYPES_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/types_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/types_c.h new file mode 100644 index 0000000000000000000000000000000000000000..97aeab375ffd8c670680300175a1d02c06731dc1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/types_c.h @@ -0,0 +1,2122 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_TYPES_H +#define OPENCV_CORE_TYPES_H + +#ifdef CV__ENABLE_C_API_CTORS // invalid C API ctors (must be removed) +#if defined(_WIN32) && !defined(CV__SKIP_MESSAGE_MALFORMED_C_API_CTORS) +#error "C API ctors don't work on Win32: https://github.com/opencv/opencv/issues/15990" +#endif +#endif + +//#define CV__VALIDATE_UNUNITIALIZED_VARS 1 // C++11 & GCC only + +#ifdef __cplusplus + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#define CV_STRUCT_INITIALIZER {0,} +#else +#if defined(__GNUC__) && __GNUC__ == 4 // GCC 4.x warns on "= {}" initialization, fixed in GCC 5.0 +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif +#define CV_STRUCT_INITIALIZER {} +#endif + +#else +#define CV_STRUCT_INITIALIZER {0} +#endif + + +#ifdef HAVE_IPL +# ifndef __IPL_H__ +# if defined _WIN32 +# include +# else +# include +# endif +# endif +#elif defined __IPL_H__ +# define HAVE_IPL +#endif + +#include "opencv2/core/cvdef.h" + +#ifndef SKIP_INCLUDES +#include +#include +#include +#include +#endif // SKIP_INCLUDES + +#if defined _WIN32 +# define CV_CDECL __cdecl +# define CV_STDCALL __stdcall +#else +# define CV_CDECL +# define CV_STDCALL +#endif + +#ifndef CV_DEFAULT +# ifdef __cplusplus +# define CV_DEFAULT(val) = val +# else +# define CV_DEFAULT(val) +# endif +#endif + +#ifndef CV_EXTERN_C_FUNCPTR +# ifdef __cplusplus +# define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; } +# else +# define CV_EXTERN_C_FUNCPTR(x) typedef x +# endif +#endif + +#ifndef CVAPI +# define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL +#endif + +#ifndef CV_IMPL +# define CV_IMPL CV_EXTERN_C +#endif + +#ifdef __cplusplus +# include "opencv2/core.hpp" +#endif + +/** @addtogroup core_c + @{ +*/ + +/** @brief This is the "metatype" used *only* as a function parameter. + +It denotes that the function accepts arrays of multiple types, such as IplImage*, CvMat* or even +CvSeq* sometimes. The particular array type is determined at runtime by analyzing the first 4 +bytes of the header. In C++ interface the role of CvArr is played by InputArray and OutputArray. + */ +typedef void CvArr; + +typedef int CVStatus; + +/** @see cv::Error::Code */ +enum { + CV_StsOk= 0, /**< everything is ok */ + CV_StsBackTrace= -1, /**< pseudo error for back trace */ + CV_StsError= -2, /**< unknown /unspecified error */ + CV_StsInternal= -3, /**< internal error (bad state) */ + CV_StsNoMem= -4, /**< insufficient memory */ + CV_StsBadArg= -5, /**< function arg/param is bad */ + CV_StsBadFunc= -6, /**< unsupported function */ + CV_StsNoConv= -7, /**< iter. didn't converge */ + CV_StsAutoTrace= -8, /**< tracing */ + CV_HeaderIsNull= -9, /**< image header is NULL */ + CV_BadImageSize= -10, /**< image size is invalid */ + CV_BadOffset= -11, /**< offset is invalid */ + CV_BadDataPtr= -12, /**/ + CV_BadStep= -13, /**< image step is wrong, this may happen for a non-continuous matrix */ + CV_BadModelOrChSeq= -14, /**/ + CV_BadNumChannels= -15, /**< bad number of channels, for example, some functions accept only single channel matrices */ + CV_BadNumChannel1U= -16, /**/ + CV_BadDepth= -17, /**< input image depth is not supported by the function */ + CV_BadAlphaChannel= -18, /**/ + CV_BadOrder= -19, /**< number of dimensions is out of range */ + CV_BadOrigin= -20, /**< incorrect input origin */ + CV_BadAlign= -21, /**< incorrect input align */ + CV_BadCallBack= -22, /**/ + CV_BadTileSize= -23, /**/ + CV_BadCOI= -24, /**< input COI is not supported */ + CV_BadROISize= -25, /**< incorrect input roi */ + CV_MaskIsTiled= -26, /**/ + CV_StsNullPtr= -27, /**< null pointer */ + CV_StsVecLengthErr= -28, /**< incorrect vector length */ + CV_StsFilterStructContentErr= -29, /**< incorrect filter structure content */ + CV_StsKernelStructContentErr= -30, /**< incorrect transform kernel content */ + CV_StsFilterOffsetErr= -31, /**< incorrect filter offset value */ + CV_StsBadSize= -201, /**< the input/output structure size is incorrect */ + CV_StsDivByZero= -202, /**< division by zero */ + CV_StsInplaceNotSupported= -203, /**< in-place operation is not supported */ + CV_StsObjectNotFound= -204, /**< request can't be completed */ + CV_StsUnmatchedFormats= -205, /**< formats of input/output arrays differ */ + CV_StsBadFlag= -206, /**< flag is wrong or not supported */ + CV_StsBadPoint= -207, /**< bad CvPoint */ + CV_StsBadMask= -208, /**< bad format of mask (neither 8uC1 nor 8sC1)*/ + CV_StsUnmatchedSizes= -209, /**< sizes of input/output structures do not match */ + CV_StsUnsupportedFormat= -210, /**< the data format/type is not supported by the function*/ + CV_StsOutOfRange= -211, /**< some of parameters are out of range */ + CV_StsParseError= -212, /**< invalid syntax/structure of the parsed file */ + CV_StsNotImplemented= -213, /**< the requested function/feature is not implemented */ + CV_StsBadMemBlock= -214, /**< an allocated block has been corrupted */ + CV_StsAssert= -215, /**< assertion failed */ + CV_GpuNotSupported= -216, /**< no CUDA support */ + CV_GpuApiCallError= -217, /**< GPU API call error */ + CV_OpenGlNotSupported= -218, /**< no OpenGL support */ + CV_OpenGlApiCallError= -219, /**< OpenGL API call error */ + CV_OpenCLApiCallError= -220, /**< OpenCL API call error */ + CV_OpenCLDoubleNotSupported= -221, + CV_OpenCLInitError= -222, /**< OpenCL initialization error */ + CV_OpenCLNoAMDBlasFft= -223 +}; + +/****************************************************************************************\ +* Common macros and inline functions * +\****************************************************************************************/ + +#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t)) + +/** min & max without jumps */ +#define CV_IMIN(a, b) ((a) ^ (((a)^(b)) & (((a) < (b)) - 1))) + +#define CV_IMAX(a, b) ((a) ^ (((a)^(b)) & (((a) > (b)) - 1))) + +/** absolute value without jumps */ +#ifndef __cplusplus +# define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0)) +#else +# define CV_IABS(a) abs(a) +#endif +#define CV_CMP(a,b) (((a) > (b)) - ((a) < (b))) +#define CV_SIGN(a) CV_CMP((a),0) + +#define cvInvSqrt(value) ((float)(1./sqrt(value))) +#define cvSqrt(value) ((float)sqrt(value)) + + +/*************** Random number generation *******************/ + +typedef uint64 CvRNG; + +#define CV_RNG_COEFF 4164903690U + +/** @brief Initializes a random number generator state. + +The function initializes a random number generator and returns the state. The pointer to the state +can be then passed to the cvRandInt, cvRandReal and cvRandArr functions. In the current +implementation a multiply-with-carry generator is used. +@param seed 64-bit value used to initiate a random sequence +@sa the C++ class RNG replaced CvRNG. + */ +CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1)) +{ + CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1; + return rng; +} + +/** @brief Returns a 32-bit unsigned integer and updates RNG. + +The function returns a uniformly-distributed random 32-bit unsigned integer and updates the RNG +state. It is similar to the rand() function from the C runtime library, except that OpenCV functions +always generates a 32-bit random number, regardless of the platform. +@param rng CvRNG state initialized by cvRNG. + */ +CV_INLINE unsigned cvRandInt( CvRNG* rng ) +{ + uint64 temp = *rng; + temp = (uint64)(unsigned)temp*CV_RNG_COEFF + (temp >> 32); + *rng = temp; + return (unsigned)temp; +} + +/** @brief Returns a floating-point random number and updates RNG. + +The function returns a uniformly-distributed random floating-point number between 0 and 1 (1 is not +included). +@param rng RNG state initialized by cvRNG + */ +CV_INLINE double cvRandReal( CvRNG* rng ) +{ + return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */; +} + +/****************************************************************************************\ +* Image type (IplImage) * +\****************************************************************************************/ + +#ifndef HAVE_IPL + +/* + * The following definitions (until #endif) + * is an extract from IPL headers. + * Copyright (c) 1995 Intel Corporation. + */ +#define IPL_DEPTH_SIGN 0x80000000 + +#define IPL_DEPTH_1U 1 +#define IPL_DEPTH_8U 8 +#define IPL_DEPTH_16U 16 +#define IPL_DEPTH_32F 32 + +#define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8) +#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16) +#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32) + +#define IPL_DATA_ORDER_PIXEL 0 +#define IPL_DATA_ORDER_PLANE 1 + +#define IPL_ORIGIN_TL 0 +#define IPL_ORIGIN_BL 1 + +#define IPL_ALIGN_4BYTES 4 +#define IPL_ALIGN_8BYTES 8 +#define IPL_ALIGN_16BYTES 16 +#define IPL_ALIGN_32BYTES 32 + +#define IPL_ALIGN_DWORD IPL_ALIGN_4BYTES +#define IPL_ALIGN_QWORD IPL_ALIGN_8BYTES + +#define IPL_BORDER_CONSTANT 0 +#define IPL_BORDER_REPLICATE 1 +#define IPL_BORDER_REFLECT 2 +#define IPL_BORDER_WRAP 3 + +#ifdef __cplusplus +typedef struct _IplImage IplImage; +CV_EXPORTS _IplImage cvIplImage(const cv::Mat& m); +#endif + +/** The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV +only supports a subset of possible IplImage formats, as outlined in the parameter list above. + +In addition to the above restrictions, OpenCV handles ROIs differently. OpenCV functions require +that the image size or ROI size of all source and destination images match exactly. On the other +hand, the Intel Image Processing Library processes the area of intersection between the source and +destination images (or ROIs), allowing them to vary independently. +*/ +typedef struct +_IplImage +{ + int nSize; /**< sizeof(IplImage) */ + int ID; /**< version (=0)*/ + int nChannels; /**< Most of OpenCV functions support 1,2,3 or 4 channels */ + int alphaChannel; /**< Ignored by OpenCV */ + int depth; /**< Pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, + IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported. */ + char colorModel[4]; /**< Ignored by OpenCV */ + char channelSeq[4]; /**< ditto */ + int dataOrder; /**< 0 - interleaved color channels, 1 - separate color channels. + cvCreateImage can only create interleaved images */ + int origin; /**< 0 - top-left origin, + 1 - bottom-left origin (Windows bitmaps style). */ + int align; /**< Alignment of image rows (4 or 8). + OpenCV ignores it and uses widthStep instead. */ + int width; /**< Image width in pixels. */ + int height; /**< Image height in pixels. */ + struct _IplROI *roi; /**< Image ROI. If NULL, the whole image is selected. */ + struct _IplImage *maskROI; /**< Must be NULL. */ + void *imageId; /**< " " */ + struct _IplTileInfo *tileInfo; /**< " " */ + int imageSize; /**< Image data size in bytes + (==image->height*image->widthStep + in case of interleaved data)*/ + char *imageData; /**< Pointer to aligned image data. */ + int widthStep; /**< Size of aligned image row in bytes. */ + int BorderMode[4]; /**< Ignored by OpenCV. */ + int BorderConst[4]; /**< Ditto. */ + char *imageDataOrigin; /**< Pointer to very origin of image data + (not necessarily aligned) - + needed for correct deallocation */ + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + _IplImage() {} + _IplImage(const cv::Mat& m) { *this = cvIplImage(m); } +#endif +} +IplImage; + +CV_INLINE IplImage cvIplImage() +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + IplImage self = CV_STRUCT_INITIALIZER; self.nSize = sizeof(IplImage); return self; +#else + return _IplImage(); +#endif +} + +typedef struct _IplTileInfo IplTileInfo; + +typedef struct _IplROI +{ + int coi; /**< 0 - no COI (all channels are selected), 1 - 0th channel is selected ...*/ + int xOffset; + int yOffset; + int width; + int height; +} +IplROI; + +typedef struct _IplConvKernel +{ + int nCols; + int nRows; + int anchorX; + int anchorY; + int *values; + int nShiftR; +} +IplConvKernel; + +typedef struct _IplConvKernelFP +{ + int nCols; + int nRows; + int anchorX; + int anchorY; + float *values; +} +IplConvKernelFP; + +#define IPL_IMAGE_HEADER 1 +#define IPL_IMAGE_DATA 2 +#define IPL_IMAGE_ROI 4 + +#endif/*HAVE_IPL*/ + +/** extra border mode */ +#define IPL_BORDER_REFLECT_101 4 +#define IPL_BORDER_TRANSPARENT 5 + +#define IPL_IMAGE_MAGIC_VAL ((int)sizeof(IplImage)) +#define CV_TYPE_NAME_IMAGE "opencv-image" + +#define CV_IS_IMAGE_HDR(img) \ + ((img) != NULL && ((const IplImage*)(img))->nSize == sizeof(IplImage)) + +#define CV_IS_IMAGE(img) \ + (CV_IS_IMAGE_HDR(img) && ((IplImage*)img)->imageData != NULL) + +/** for storing double-precision + floating point data in IplImage's */ +#define IPL_DEPTH_64F 64 + +/** get reference to pixel at (col,row), + for multi-channel images (col) should be multiplied by number of channels */ +#define CV_IMAGE_ELEM( image, elemtype, row, col ) \ + (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)]) + +/****************************************************************************************\ +* Matrix type (CvMat) * +\****************************************************************************************/ + +#define CV_AUTO_STEP 0x7fffffff +#define CV_WHOLE_ARR cvSlice( 0, 0x3fffffff ) + +#define CV_MAGIC_MASK 0xFFFF0000 +#define CV_MAT_MAGIC_VAL 0x42420000 +#define CV_TYPE_NAME_MAT "opencv-matrix" + +#ifdef __cplusplus +typedef struct CvMat CvMat; +CV_INLINE CvMat cvMat(const cv::Mat& m); +#endif + +/** Matrix elements are stored row by row. Element (i, j) (i - 0-based row index, j - 0-based column +index) of a matrix can be retrieved or modified using CV_MAT_ELEM macro: + + uchar pixval = CV_MAT_ELEM(grayimg, uchar, i, j) + CV_MAT_ELEM(cameraMatrix, float, 0, 2) = image.width*0.5f; + +To access multiple-channel matrices, you can use +CV_MAT_ELEM(matrix, type, i, j\*nchannels + channel_idx). + +@deprecated CvMat is now obsolete; consider using Mat instead. + */ +typedef struct CvMat +{ + int type; + int step; + + /* for internal use only */ + int* refcount; + int hdr_refcount; + + union + { + uchar* ptr; + short* s; + int* i; + float* fl; + double* db; + } data; + +#ifdef __cplusplus + union + { + int rows; + int height; + }; + + union + { + int cols; + int width; + }; +#else + int rows; + int cols; +#endif + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvMat() {} + CvMat(const cv::Mat& m) { *this = cvMat(m); } +#endif +} +CvMat; + + +#define CV_IS_MAT_HDR(mat) \ + ((mat) != NULL && \ + (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \ + ((const CvMat*)(mat))->cols > 0 && ((const CvMat*)(mat))->rows > 0) + +#define CV_IS_MAT_HDR_Z(mat) \ + ((mat) != NULL && \ + (((const CvMat*)(mat))->type & CV_MAGIC_MASK) == CV_MAT_MAGIC_VAL && \ + ((const CvMat*)(mat))->cols >= 0 && ((const CvMat*)(mat))->rows >= 0) + +#define CV_IS_MAT(mat) \ + (CV_IS_MAT_HDR(mat) && ((const CvMat*)(mat))->data.ptr != NULL) + +#define CV_IS_MASK_ARR(mat) \ + (((mat)->type & (CV_MAT_TYPE_MASK & ~CV_8SC1)) == 0) + +#define CV_ARE_TYPES_EQ(mat1, mat2) \ + ((((mat1)->type ^ (mat2)->type) & CV_MAT_TYPE_MASK) == 0) + +#define CV_ARE_CNS_EQ(mat1, mat2) \ + ((((mat1)->type ^ (mat2)->type) & CV_MAT_CN_MASK) == 0) + +#define CV_ARE_DEPTHS_EQ(mat1, mat2) \ + ((((mat1)->type ^ (mat2)->type) & CV_MAT_DEPTH_MASK) == 0) + +#define CV_ARE_SIZES_EQ(mat1, mat2) \ + ((mat1)->rows == (mat2)->rows && (mat1)->cols == (mat2)->cols) + +#define CV_IS_MAT_CONST(mat) \ + (((mat)->rows|(mat)->cols) == 1) + +#define IPL2CV_DEPTH(depth) \ + ((((CV_8U)+(CV_16U<<4)+(CV_32F<<8)+(CV_64F<<16)+(CV_8S<<20)+ \ + (CV_16S<<24)+(CV_32S<<28)) >> ((((depth) & 0xF0) >> 2) + \ + (((depth) & IPL_DEPTH_SIGN) ? 20 : 0))) & 15) + +/** Inline constructor. No data is allocated internally!!! + * (Use together with cvCreateData, or use cvCreateMat instead to + * get a matrix with allocated data): + */ +CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL)) +{ + CvMat m; + + assert( (unsigned)CV_MAT_DEPTH(type) <= CV_64F ); + type = CV_MAT_TYPE(type); + m.type = CV_MAT_MAGIC_VAL | CV_MAT_CONT_FLAG | type; + m.cols = cols; + m.rows = rows; + m.step = m.cols*CV_ELEM_SIZE(type); + m.data.ptr = (uchar*)data; + m.refcount = NULL; + m.hdr_refcount = 0; + + return m; +} + +#ifdef __cplusplus + +CV_INLINE CvMat cvMat(const cv::Mat& m) +{ + CvMat self; + CV_DbgAssert(m.dims <= 2); + self = cvMat(m.rows, m.dims == 1 ? 1 : m.cols, m.type(), m.data); + self.step = (int)m.step[0]; + self.type = (self.type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG); + return self; +} +CV_INLINE CvMat cvMat() +{ +#if !defined(CV__ENABLE_C_API_CTORS) + CvMat self = CV_STRUCT_INITIALIZER; return self; +#else + return CvMat(); +#endif +} +CV_INLINE CvMat cvMat(const CvMat& m) +{ +#if !defined(CV__ENABLE_C_API_CTORS) + CvMat self = CV_STRUCT_INITIALIZER; memcpy(&self, &m, sizeof(self)); return self; +#else + return CvMat(m); +#endif +} + +#endif // __cplusplus + + +#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \ + (assert( (unsigned)(row) < (unsigned)(mat).rows && \ + (unsigned)(col) < (unsigned)(mat).cols ), \ + (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col)) + +#define CV_MAT_ELEM_PTR( mat, row, col ) \ + CV_MAT_ELEM_PTR_FAST( mat, row, col, CV_ELEM_SIZE((mat).type) ) + +#define CV_MAT_ELEM( mat, elemtype, row, col ) \ + (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype))) + +/** @brief Returns the particular element of single-channel floating-point matrix. + +The function is a fast replacement for cvGetReal2D in the case of single-channel floating-point +matrices. It is faster because it is inline, it does fewer checks for array type and array element +type, and it checks for the row and column ranges only in debug mode. +@param mat Input matrix +@param row The zero-based index of row +@param col The zero-based index of column + */ +CV_INLINE double cvmGet( const CvMat* mat, int row, int col ) +{ + int type; + + type = CV_MAT_TYPE(mat->type); + assert( (unsigned)row < (unsigned)mat->rows && + (unsigned)col < (unsigned)mat->cols ); + + if( type == CV_32FC1 ) + return ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col]; + else + { + assert( type == CV_64FC1 ); + return ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col]; + } +} + +/** @brief Sets a specific element of a single-channel floating-point matrix. + +The function is a fast replacement for cvSetReal2D in the case of single-channel floating-point +matrices. It is faster because it is inline, it does fewer checks for array type and array element +type, and it checks for the row and column ranges only in debug mode. +@param mat The matrix +@param row The zero-based index of row +@param col The zero-based index of column +@param value The new value of the matrix element + */ +CV_INLINE void cvmSet( CvMat* mat, int row, int col, double value ) +{ + int type; + type = CV_MAT_TYPE(mat->type); + assert( (unsigned)row < (unsigned)mat->rows && + (unsigned)col < (unsigned)mat->cols ); + + if( type == CV_32FC1 ) + ((float*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = (float)value; + else + { + assert( type == CV_64FC1 ); + ((double*)(void*)(mat->data.ptr + (size_t)mat->step*row))[col] = value; + } +} + + +CV_INLINE int cvIplDepth( int type ) +{ + int depth = CV_MAT_DEPTH(type); + return CV_ELEM_SIZE1(depth)*8 | (depth == CV_8S || depth == CV_16S || + depth == CV_32S ? IPL_DEPTH_SIGN : 0); +} + + +/****************************************************************************************\ +* Multi-dimensional dense array (CvMatND) * +\****************************************************************************************/ + +#define CV_MATND_MAGIC_VAL 0x42430000 +#define CV_TYPE_NAME_MATND "opencv-nd-matrix" + +#define CV_MAX_DIM 32 + +#ifdef __cplusplus +typedef struct CvMatND CvMatND; +CV_EXPORTS CvMatND cvMatND(const cv::Mat& m); +#endif + +/** + @deprecated consider using cv::Mat instead + */ +typedef struct +CvMatND +{ + int type; + int dims; + + int* refcount; + int hdr_refcount; + + union + { + uchar* ptr; + float* fl; + double* db; + int* i; + short* s; + } data; + + struct + { + int size; + int step; + } + dim[CV_MAX_DIM]; + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvMatND() {} + CvMatND(const cv::Mat& m) { *this = cvMatND(m); } +#endif +} +CvMatND; + + +CV_INLINE CvMatND cvMatND() +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvMatND self = CV_STRUCT_INITIALIZER; return self; +#else + return CvMatND(); +#endif +} + +#define CV_IS_MATND_HDR(mat) \ + ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL) + +#define CV_IS_MATND(mat) \ + (CV_IS_MATND_HDR(mat) && ((const CvMatND*)(mat))->data.ptr != NULL) + + +/****************************************************************************************\ +* Multi-dimensional sparse array (CvSparseMat) * +\****************************************************************************************/ + +#define CV_SPARSE_MAT_MAGIC_VAL 0x42440000 +#define CV_TYPE_NAME_SPARSE_MAT "opencv-sparse-matrix" + +struct CvSet; + +typedef struct CvSparseMat +{ + int type; + int dims; + int* refcount; + int hdr_refcount; + + struct CvSet* heap; + void** hashtable; + int hashsize; + int valoffset; + int idxoffset; + int size[CV_MAX_DIM]; + +#ifdef __cplusplus + CV_EXPORTS void copyToSparseMat(cv::SparseMat& m) const; +#endif +} +CvSparseMat; + +#ifdef __cplusplus +CV_EXPORTS CvSparseMat* cvCreateSparseMat(const cv::SparseMat& m); +#endif + +#define CV_IS_SPARSE_MAT_HDR(mat) \ + ((mat) != NULL && \ + (((const CvSparseMat*)(mat))->type & CV_MAGIC_MASK) == CV_SPARSE_MAT_MAGIC_VAL) + +#define CV_IS_SPARSE_MAT(mat) \ + CV_IS_SPARSE_MAT_HDR(mat) + +/**************** iteration through a sparse array *****************/ + +typedef struct CvSparseNode +{ + unsigned hashval; + struct CvSparseNode* next; +} +CvSparseNode; + +typedef struct CvSparseMatIterator +{ + CvSparseMat* mat; + CvSparseNode* node; + int curidx; +} +CvSparseMatIterator; + +#define CV_NODE_VAL(mat,node) ((void*)((uchar*)(node) + (mat)->valoffset)) +#define CV_NODE_IDX(mat,node) ((int*)((uchar*)(node) + (mat)->idxoffset)) + +/****************************************************************************************\ +* Histogram * +\****************************************************************************************/ + +typedef int CvHistType; + +#define CV_HIST_MAGIC_VAL 0x42450000 +#define CV_HIST_UNIFORM_FLAG (1 << 10) + +/** indicates whether bin ranges are set already or not */ +#define CV_HIST_RANGES_FLAG (1 << 11) + +#define CV_HIST_ARRAY 0 +#define CV_HIST_SPARSE 1 +#define CV_HIST_TREE CV_HIST_SPARSE + +/** should be used as a parameter only, + it turns to CV_HIST_UNIFORM_FLAG of hist->type */ +#define CV_HIST_UNIFORM 1 + +typedef struct CvHistogram +{ + int type; + CvArr* bins; + float thresh[CV_MAX_DIM][2]; /**< For uniform histograms. */ + float** thresh2; /**< For non-uniform histograms. */ + CvMatND mat; /**< Embedded matrix header for array histograms. */ +} +CvHistogram; + +#define CV_IS_HIST( hist ) \ + ((hist) != NULL && \ + (((CvHistogram*)(hist))->type & CV_MAGIC_MASK) == CV_HIST_MAGIC_VAL && \ + (hist)->bins != NULL) + +#define CV_IS_UNIFORM_HIST( hist ) \ + (((hist)->type & CV_HIST_UNIFORM_FLAG) != 0) + +#define CV_IS_SPARSE_HIST( hist ) \ + CV_IS_SPARSE_MAT((hist)->bins) + +#define CV_HIST_HAS_RANGES( hist ) \ + (((hist)->type & CV_HIST_RANGES_FLAG) != 0) + +/****************************************************************************************\ +* Other supplementary data type definitions * +\****************************************************************************************/ + +/*************************************** CvRect *****************************************/ +/** @sa Rect_ */ +typedef struct CvRect +{ + int x; + int y; + int width; + int height; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvRect() __attribute__(( warning("Non-initialized variable") )) {}; + template CvRect(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 4); + x = y = width = height = 0; + if (list.size() == 4) + { + x = list.begin()[0]; y = list.begin()[1]; width = list.begin()[2]; height = list.begin()[3]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvRect(int _x = 0, int _y = 0, int w = 0, int h = 0): x(_x), y(_y), width(w), height(h) {} + template + CvRect(const cv::Rect_<_Tp>& r): x(cv::saturate_cast(r.x)), y(cv::saturate_cast(r.y)), width(cv::saturate_cast(r.width)), height(cv::saturate_cast(r.height)) {} +#endif +#ifdef __cplusplus + template + operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); } +#endif +} +CvRect; + +/** constructs CvRect structure. */ +CV_INLINE CvRect cvRect( int x, int y, int width, int height ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvRect r = {x, y, width, height}; +#else + CvRect r(x, y , width, height); +#endif + return r; +} +#ifdef __cplusplus +CV_INLINE CvRect cvRect(const cv::Rect& rc) { return cvRect(rc.x, rc.y, rc.width, rc.height); } +#endif + +CV_INLINE IplROI cvRectToROI( CvRect rect, int coi ) +{ + IplROI roi; + roi.xOffset = rect.x; + roi.yOffset = rect.y; + roi.width = rect.width; + roi.height = rect.height; + roi.coi = coi; + + return roi; +} + + +CV_INLINE CvRect cvROIToRect( IplROI roi ) +{ + return cvRect( roi.xOffset, roi.yOffset, roi.width, roi.height ); +} + +/*********************************** CvTermCriteria *************************************/ + +#define CV_TERMCRIT_ITER 1 +#define CV_TERMCRIT_NUMBER CV_TERMCRIT_ITER +#define CV_TERMCRIT_EPS 2 + +/** @sa TermCriteria + */ +typedef struct CvTermCriteria +{ + int type; /**< may be combination of + CV_TERMCRIT_ITER + CV_TERMCRIT_EPS */ + int max_iter; + double epsilon; +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvTermCriteria(int _type = 0, int _iter = 0, double _eps = 0) : type(_type), max_iter(_iter), epsilon(_eps) {} + CvTermCriteria(const cv::TermCriteria& t) : type(t.type), max_iter(t.maxCount), epsilon(t.epsilon) {} +#endif +#ifdef __cplusplus + operator cv::TermCriteria() const { return cv::TermCriteria(type, max_iter, epsilon); } +#endif +} +CvTermCriteria; + +CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvTermCriteria t = { type, max_iter, (float)epsilon}; +#else + CvTermCriteria t(type, max_iter, epsilon); +#endif + return t; +} +#ifdef __cplusplus +CV_INLINE CvTermCriteria cvTermCriteria(const cv::TermCriteria& t) { return cvTermCriteria(t.type, t.maxCount, t.epsilon); } +#endif + + +/******************************* CvPoint and variants ***********************************/ + +typedef struct CvPoint +{ + int x; + int y; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint() __attribute__(( warning("Non-initialized variable") )) {} + template CvPoint(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + x = y = 0; + if (list.size() == 2) + { + x = list.begin()[0]; y = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvPoint(int _x = 0, int _y = 0): x(_x), y(_y) {} + template + CvPoint(const cv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {} +#endif +#ifdef __cplusplus + template + operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } +#endif +} +CvPoint; + +/** constructs CvPoint structure. */ +CV_INLINE CvPoint cvPoint( int x, int y ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint p = {x, y}; +#else + CvPoint p(x, y); +#endif + return p; +} +#ifdef __cplusplus +CV_INLINE CvPoint cvPoint(const cv::Point& pt) { return cvPoint(pt.x, pt.y); } +#endif + +typedef struct CvPoint2D32f +{ + float x; + float y; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint2D32f() __attribute__(( warning("Non-initialized variable") )) {} + template CvPoint2D32f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + x = y = 0; + if (list.size() == 2) + { + x = list.begin()[0]; y = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvPoint2D32f(float _x = 0, float _y = 0): x(_x), y(_y) {} + template + CvPoint2D32f(const cv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {} +#endif +#ifdef __cplusplus + template + operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } +#endif +} +CvPoint2D32f; + +/** constructs CvPoint2D32f structure. */ +CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint2D32f p = { (float)x, (float)y }; +#else + CvPoint2D32f p((float)x, (float)y); +#endif + return p; +} + +#ifdef __cplusplus +template +CvPoint2D32f cvPoint2D32f(const cv::Point_<_Tp>& pt) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint2D32f p = { (float)pt.x, (float)pt.y }; +#else + CvPoint2D32f p((float)pt.x, (float)pt.y); +#endif + return p; +} +#endif + +/** converts CvPoint to CvPoint2D32f. */ +CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point ) +{ + return cvPoint2D32f( (float)point.x, (float)point.y ); +} + +/** converts CvPoint2D32f to CvPoint. */ +CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint ipt = { cvRound(point.x), cvRound(point.y) }; +#else + CvPoint ipt(cvRound(point.x), cvRound(point.y)); +#endif + return ipt; +} + + +typedef struct CvPoint3D32f +{ + float x; + float y; + float z; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint3D32f() __attribute__(( warning("Non-initialized variable") )) {} + template CvPoint3D32f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 3); + x = y = z = 0; + if (list.size() == 3) + { + x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvPoint3D32f(float _x = 0, float _y = 0, float _z = 0): x(_x), y(_y), z(_z) {} + template + CvPoint3D32f(const cv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {} +#endif +#ifdef __cplusplus + template + operator cv::Point3_<_Tp>() const { return cv::Point3_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y), cv::saturate_cast<_Tp>(z)); } +#endif +} +CvPoint3D32f; + +/** constructs CvPoint3D32f structure. */ +CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint3D32f p = { (float)x, (float)y, (float)z }; +#else + CvPoint3D32f p((float)x, (float)y, (float)z); +#endif + return p; +} + +#ifdef __cplusplus +template +CvPoint3D32f cvPoint3D32f(const cv::Point3_<_Tp>& pt) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvPoint3D32f p = { (float)pt.x, (float)pt.y, (float)pt.z }; +#else + CvPoint3D32f p((float)pt.x, (float)pt.y, (float)pt.z); +#endif + return p; +} +#endif + + +typedef struct CvPoint2D64f +{ + double x; + double y; +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint2D64f() __attribute__(( warning("Non-initialized variable") )) {} + template CvPoint2D64f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + x = y = 0; + if (list.size() == 2) + { + x = list.begin()[0]; y = list.begin()[1]; + } + }; +#endif +} +CvPoint2D64f; + +/** constructs CvPoint2D64f structure.*/ +CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y ) +{ + CvPoint2D64f p = { x, y }; + return p; +} + + +typedef struct CvPoint3D64f +{ + double x; + double y; + double z; +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvPoint3D64f() __attribute__(( warning("Non-initialized variable") )) {} + template CvPoint3D64f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 3); + x = y = z = 0; + if (list.size() == 3) + { + x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2]; + } + }; +#endif +} +CvPoint3D64f; + +/** constructs CvPoint3D64f structure. */ +CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z ) +{ + CvPoint3D64f p = { x, y, z }; + return p; +} + + +/******************************** CvSize's & CvBox **************************************/ + +typedef struct CvSize +{ + int width; + int height; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvSize() __attribute__(( warning("Non-initialized variable") )) {} + template CvSize(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + width = 0; height = 0; + if (list.size() == 2) + { + width = list.begin()[0]; height = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvSize(int w = 0, int h = 0): width(w), height(h) {} + template + CvSize(const cv::Size_<_Tp>& sz): width(cv::saturate_cast(sz.width)), height(cv::saturate_cast(sz.height)) {} +#endif +#ifdef __cplusplus + template + operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } +#endif +} +CvSize; + +/** constructs CvSize structure. */ +CV_INLINE CvSize cvSize( int width, int height ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize s = { width, height }; +#else + CvSize s(width, height); +#endif + return s; +} + +#ifdef __cplusplus +CV_INLINE CvSize cvSize(const cv::Size& sz) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize s = { sz.width, sz.height }; +#else + CvSize s(sz.width, sz.height); +#endif + return s; +} +#endif + +typedef struct CvSize2D32f +{ + float width; + float height; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvSize2D32f() __attribute__(( warning("Non-initialized variable") )) {} + template CvSize2D32f(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + width = 0; height = 0; + if (list.size() == 2) + { + width = list.begin()[0]; height = list.begin()[1]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvSize2D32f(float w = 0, float h = 0): width(w), height(h) {} + template + CvSize2D32f(const cv::Size_<_Tp>& sz): width(cv::saturate_cast(sz.width)), height(cv::saturate_cast(sz.height)) {} +#endif +#ifdef __cplusplus + template + operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } +#endif +} +CvSize2D32f; + +/** constructs CvSize2D32f structure. */ +CV_INLINE CvSize2D32f cvSize2D32f( double width, double height ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize2D32f s = { (float)width, (float)height }; +#else + CvSize2D32f s((float)width, (float)height); +#endif + return s; +} +#ifdef __cplusplus +template +CvSize2D32f cvSize2D32f(const cv::Size_<_Tp>& sz) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvSize2D32f s = { (float)sz.width, (float)sz.height }; +#else + CvSize2D32f s((float)sz.width, (float)sz.height); +#endif + return s; +} +#endif + +/** @sa RotatedRect + */ +typedef struct CvBox2D +{ + CvPoint2D32f center; /**< Center of the box. */ + CvSize2D32f size; /**< Box width and length. */ + float angle; /**< Angle between the horizontal axis */ + /**< and the first side (i.e. length) in degrees */ + +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) : center(c), size(s), angle(a) {} + CvBox2D(const cv::RotatedRect& rr) : center(rr.center), size(rr.size), angle(rr.angle) {} +#endif +#ifdef __cplusplus + operator cv::RotatedRect() const { return cv::RotatedRect(center, size, angle); } +#endif +} +CvBox2D; + + +#ifdef __cplusplus +CV_INLINE CvBox2D cvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) +{ + CvBox2D self; + self.center = c; + self.size = s; + self.angle = a; + return self; +} +CV_INLINE CvBox2D cvBox2D(const cv::RotatedRect& rr) +{ + CvBox2D self; + self.center = cvPoint2D32f(rr.center); + self.size = cvSize2D32f(rr.size); + self.angle = rr.angle; + return self; +} +#endif + + +/** Line iterator state: */ +typedef struct CvLineIterator +{ + /** Pointer to the current point: */ + uchar* ptr; + + /* Bresenham algorithm state: */ + int err; + int plus_delta; + int minus_delta; + int plus_step; + int minus_step; +} +CvLineIterator; + + + +/************************************* CvSlice ******************************************/ +#define CV_WHOLE_SEQ_END_INDEX 0x3fffffff +#define CV_WHOLE_SEQ cvSlice(0, CV_WHOLE_SEQ_END_INDEX) + +typedef struct CvSlice +{ + int start_index, end_index; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvSlice() __attribute__(( warning("Non-initialized variable") )) {} + template CvSlice(const std::initializer_list<_Tp> list) + { + CV_Assert(list.size() == 0 || list.size() == 2); + start_index = end_index = 0; + if (list.size() == 2) + { + start_index = list.begin()[0]; end_index = list.begin()[1]; + } + }; +#endif +#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) && !defined(__CUDACC__) + CvSlice(int start = 0, int end = 0) : start_index(start), end_index(end) {} + CvSlice(const cv::Range& r) { *this = (r.start != INT_MIN && r.end != INT_MAX) ? CvSlice(r.start, r.end) : CvSlice(0, CV_WHOLE_SEQ_END_INDEX); } + operator cv::Range() const { return (start_index == 0 && end_index == CV_WHOLE_SEQ_END_INDEX ) ? cv::Range::all() : cv::Range(start_index, end_index); } +#endif +} +CvSlice; + +CV_INLINE CvSlice cvSlice( int start, int end ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) && !defined(__CUDACC__)) + CvSlice slice = { start, end }; +#else + CvSlice slice(start, end); +#endif + return slice; +} + +#if defined(__cplusplus) +CV_INLINE CvSlice cvSlice(const cv::Range& r) +{ + CvSlice slice = (r.start != INT_MIN && r.end != INT_MAX) ? cvSlice(r.start, r.end) : cvSlice(0, CV_WHOLE_SEQ_END_INDEX); + return slice; +} +#endif + + +/************************************* CvScalar *****************************************/ +/** @sa Scalar_ + */ +typedef struct CvScalar +{ + double val[4]; + +#ifdef CV__VALIDATE_UNUNITIALIZED_VARS + CvScalar() __attribute__(( warning("Non-initialized variable") )) {} + CvScalar(const std::initializer_list list) + { + CV_Assert(list.size() == 0 || list.size() == 4); + val[0] = val[1] = val[2] = val[3] = 0; + if (list.size() == 4) + { + val[0] = list.begin()[0]; val[1] = list.begin()[1]; val[2] = list.begin()[2]; val[3] = list.begin()[3]; + } + }; +#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) + CvScalar() {} + CvScalar(double d0, double d1 = 0, double d2 = 0, double d3 = 0) { val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3; } + template + CvScalar(const cv::Scalar_<_Tp>& s) { val[0] = s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] = s.val[3]; } + template + CvScalar(const cv::Vec<_Tp, cn>& v) + { + int i; + for( i = 0; i < (cn < 4 ? cn : 4); i++ ) val[i] = v.val[i]; + for( ; i < 4; i++ ) val[i] = 0; + } +#endif +#ifdef __cplusplus + template + operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); } +#endif +} +CvScalar; + +CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0), + double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0)) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = val0; scalar.val[1] = val1; + scalar.val[2] = val2; scalar.val[3] = val3; + return scalar; +} + +#ifdef __cplusplus +CV_INLINE CvScalar cvScalar() +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; + return scalar; +} +CV_INLINE CvScalar cvScalar(const cv::Scalar& s) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = s.val[0]; + scalar.val[1] = s.val[1]; + scalar.val[2] = s.val[2]; + scalar.val[3] = s.val[3]; + return scalar; +} +#endif + +CV_INLINE CvScalar cvRealScalar( double val0 ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = val0; + scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; + return scalar; +} + +CV_INLINE CvScalar cvScalarAll( double val0123 ) +{ +#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)) + CvScalar scalar = CV_STRUCT_INITIALIZER; +#else + CvScalar scalar; +#endif + scalar.val[0] = val0123; + scalar.val[1] = val0123; + scalar.val[2] = val0123; + scalar.val[3] = val0123; + return scalar; +} + +/****************************************************************************************\ +* Dynamic Data structures * +\****************************************************************************************/ + +/******************************** Memory storage ****************************************/ + +typedef struct CvMemBlock +{ + struct CvMemBlock* prev; + struct CvMemBlock* next; +} +CvMemBlock; + +#define CV_STORAGE_MAGIC_VAL 0x42890000 + +typedef struct CvMemStorage +{ + int signature; + CvMemBlock* bottom; /**< First allocated block. */ + CvMemBlock* top; /**< Current memory block - top of the stack. */ + struct CvMemStorage* parent; /**< We get new blocks from parent as needed. */ + int block_size; /**< Block size. */ + int free_space; /**< Remaining free space in current block. */ +} +CvMemStorage; + +#define CV_IS_STORAGE(storage) \ + ((storage) != NULL && \ + (((CvMemStorage*)(storage))->signature & CV_MAGIC_MASK) == CV_STORAGE_MAGIC_VAL) + + +typedef struct CvMemStoragePos +{ + CvMemBlock* top; + int free_space; +} +CvMemStoragePos; + + +/*********************************** Sequence *******************************************/ + +typedef struct CvSeqBlock +{ + struct CvSeqBlock* prev; /**< Previous sequence block. */ + struct CvSeqBlock* next; /**< Next sequence block. */ + int start_index; /**< Index of the first element in the block + */ + /**< sequence->first->start_index. */ + int count; /**< Number of elements in the block. */ + schar* data; /**< Pointer to the first element of the block. */ +} +CvSeqBlock; + + +#define CV_TREE_NODE_FIELDS(node_type) \ + int flags; /**< Miscellaneous flags. */ \ + int header_size; /**< Size of sequence header. */ \ + struct node_type* h_prev; /**< Previous sequence. */ \ + struct node_type* h_next; /**< Next sequence. */ \ + struct node_type* v_prev; /**< 2nd previous sequence. */ \ + struct node_type* v_next /**< 2nd next sequence. */ + +/** + Read/Write sequence. + Elements can be dynamically inserted to or deleted from the sequence. +*/ +#define CV_SEQUENCE_FIELDS() \ + CV_TREE_NODE_FIELDS(CvSeq); \ + int total; /**< Total number of elements. */ \ + int elem_size; /**< Size of sequence element in bytes. */ \ + schar* block_max; /**< Maximal bound of the last block. */ \ + schar* ptr; /**< Current write pointer. */ \ + int delta_elems; /**< Grow seq this many at a time. */ \ + CvMemStorage* storage; /**< Where the seq is stored. */ \ + CvSeqBlock* free_blocks; /**< Free blocks list. */ \ + CvSeqBlock* first; /**< Pointer to the first sequence block. */ + +typedef struct CvSeq +{ + CV_SEQUENCE_FIELDS() +} +CvSeq; + +#define CV_TYPE_NAME_SEQ "opencv-sequence" +#define CV_TYPE_NAME_SEQ_TREE "opencv-sequence-tree" + +/*************************************** Set ********************************************/ +/** @brief Set + Order is not preserved. There can be gaps between sequence elements. + After the element has been inserted it stays in the same place all the time. + The MSB(most-significant or sign bit) of the first field (flags) is 0 iff the element exists. +*/ +#define CV_SET_ELEM_FIELDS(elem_type) \ + int flags; \ + struct elem_type* next_free; + +typedef struct CvSetElem +{ + CV_SET_ELEM_FIELDS(CvSetElem) +} +CvSetElem; + +#define CV_SET_FIELDS() \ + CV_SEQUENCE_FIELDS() \ + CvSetElem* free_elems; \ + int active_count; + +typedef struct CvSet +{ + CV_SET_FIELDS() +} +CvSet; + + +#define CV_SET_ELEM_IDX_MASK ((1 << 26) - 1) +#define CV_SET_ELEM_FREE_FLAG (1 << (sizeof(int)*8-1)) + +/** Checks whether the element pointed by ptr belongs to a set or not */ +#define CV_IS_SET_ELEM( ptr ) (((CvSetElem*)(ptr))->flags >= 0) + +/************************************* Graph ********************************************/ + +/** @name Graph + +We represent a graph as a set of vertices. Vertices contain their adjacency lists (more exactly, +pointers to first incoming or outcoming edge (or 0 if isolated vertex)). Edges are stored in +another set. There is a singly-linked list of incoming/outcoming edges for each vertex. + +Each edge consists of: + +- Two pointers to the starting and ending vertices (vtx[0] and vtx[1] respectively). + + A graph may be oriented or not. In the latter case, edges between vertex i to vertex j are not +distinguished during search operations. + +- Two pointers to next edges for the starting and ending vertices, where next[0] points to the +next edge in the vtx[0] adjacency list and next[1] points to the next edge in the vtx[1] +adjacency list. + +@see CvGraphEdge, CvGraphVtx, CvGraphVtx2D, CvGraph +@{ +*/ +#define CV_GRAPH_EDGE_FIELDS() \ + int flags; \ + float weight; \ + struct CvGraphEdge* next[2]; \ + struct CvGraphVtx* vtx[2]; + + +#define CV_GRAPH_VERTEX_FIELDS() \ + int flags; \ + struct CvGraphEdge* first; + + +typedef struct CvGraphEdge +{ + CV_GRAPH_EDGE_FIELDS() +} +CvGraphEdge; + +typedef struct CvGraphVtx +{ + CV_GRAPH_VERTEX_FIELDS() +} +CvGraphVtx; + +typedef struct CvGraphVtx2D +{ + CV_GRAPH_VERTEX_FIELDS() + CvPoint2D32f* ptr; +} +CvGraphVtx2D; + +/** + Graph is "derived" from the set (this is set a of vertices) + and includes another set (edges) +*/ +#define CV_GRAPH_FIELDS() \ + CV_SET_FIELDS() \ + CvSet* edges; + +typedef struct CvGraph +{ + CV_GRAPH_FIELDS() +} +CvGraph; + +#define CV_TYPE_NAME_GRAPH "opencv-graph" + +/** @} */ + +/*********************************** Chain/Contour *************************************/ + +typedef struct CvChain +{ + CV_SEQUENCE_FIELDS() + CvPoint origin; +} +CvChain; + +#define CV_CONTOUR_FIELDS() \ + CV_SEQUENCE_FIELDS() \ + CvRect rect; \ + int color; \ + int reserved[3]; + +typedef struct CvContour +{ + CV_CONTOUR_FIELDS() +} +CvContour; + +typedef CvContour CvPoint2DSeq; + +/****************************************************************************************\ +* Sequence types * +\****************************************************************************************/ + +#define CV_SEQ_MAGIC_VAL 0x42990000 + +#define CV_IS_SEQ(seq) \ + ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL) + +#define CV_SET_MAGIC_VAL 0x42980000 +#define CV_IS_SET(set) \ + ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL) + +#define CV_SEQ_ELTYPE_BITS 12 +#define CV_SEQ_ELTYPE_MASK ((1 << CV_SEQ_ELTYPE_BITS) - 1) + +#define CV_SEQ_ELTYPE_POINT CV_32SC2 /**< (x,y) */ +#define CV_SEQ_ELTYPE_CODE CV_8UC1 /**< freeman code: 0..7 */ +#define CV_SEQ_ELTYPE_GENERIC 0 +#define CV_SEQ_ELTYPE_PTR CV_MAKE_TYPE(CV_8U, 8 /*sizeof(void*)*/) +#define CV_SEQ_ELTYPE_PPOINT CV_SEQ_ELTYPE_PTR /**< &(x,y) */ +#define CV_SEQ_ELTYPE_INDEX CV_32SC1 /**< #(x,y) */ +#define CV_SEQ_ELTYPE_GRAPH_EDGE 0 /**< &next_o, &next_d, &vtx_o, &vtx_d */ +#define CV_SEQ_ELTYPE_GRAPH_VERTEX 0 /**< first_edge, &(x,y) */ +#define CV_SEQ_ELTYPE_TRIAN_ATR 0 /**< vertex of the binary tree */ +#define CV_SEQ_ELTYPE_CONNECTED_COMP 0 /**< connected component */ +#define CV_SEQ_ELTYPE_POINT3D CV_32FC3 /**< (x,y,z) */ + +#define CV_SEQ_KIND_BITS 2 +#define CV_SEQ_KIND_MASK (((1 << CV_SEQ_KIND_BITS) - 1)<flags & CV_SEQ_ELTYPE_MASK) +#define CV_SEQ_KIND( seq ) ((seq)->flags & CV_SEQ_KIND_MASK ) + +/** flag checking */ +#define CV_IS_SEQ_INDEX( seq ) ((CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_INDEX) && \ + (CV_SEQ_KIND(seq) == CV_SEQ_KIND_GENERIC)) + +#define CV_IS_SEQ_CURVE( seq ) (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE) +#define CV_IS_SEQ_CLOSED( seq ) (((seq)->flags & CV_SEQ_FLAG_CLOSED) != 0) +#define CV_IS_SEQ_CONVEX( seq ) 0 +#define CV_IS_SEQ_HOLE( seq ) (((seq)->flags & CV_SEQ_FLAG_HOLE) != 0) +#define CV_IS_SEQ_SIMPLE( seq ) 1 + +/** type checking macros */ +#define CV_IS_SEQ_POINT_SET( seq ) \ + ((CV_SEQ_ELTYPE(seq) == CV_32SC2 || CV_SEQ_ELTYPE(seq) == CV_32FC2)) + +#define CV_IS_SEQ_POINT_SUBSET( seq ) \ + (CV_IS_SEQ_INDEX( seq ) || CV_SEQ_ELTYPE(seq) == CV_SEQ_ELTYPE_PPOINT) + +#define CV_IS_SEQ_POLYLINE( seq ) \ + (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && CV_IS_SEQ_POINT_SET(seq)) + +#define CV_IS_SEQ_POLYGON( seq ) \ + (CV_IS_SEQ_POLYLINE(seq) && CV_IS_SEQ_CLOSED(seq)) + +#define CV_IS_SEQ_CHAIN( seq ) \ + (CV_SEQ_KIND(seq) == CV_SEQ_KIND_CURVE && (seq)->elem_size == 1) + +#define CV_IS_SEQ_CONTOUR( seq ) \ + (CV_IS_SEQ_CLOSED(seq) && (CV_IS_SEQ_POLYLINE(seq) || CV_IS_SEQ_CHAIN(seq))) + +#define CV_IS_SEQ_CHAIN_CONTOUR( seq ) \ + (CV_IS_SEQ_CHAIN( seq ) && CV_IS_SEQ_CLOSED( seq )) + +#define CV_IS_SEQ_POLYGON_TREE( seq ) \ + (CV_SEQ_ELTYPE (seq) == CV_SEQ_ELTYPE_TRIAN_ATR && \ + CV_SEQ_KIND( seq ) == CV_SEQ_KIND_BIN_TREE ) + +#define CV_IS_GRAPH( seq ) \ + (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_GRAPH) + +#define CV_IS_GRAPH_ORIENTED( seq ) \ + (((seq)->flags & CV_GRAPH_FLAG_ORIENTED) != 0) + +#define CV_IS_SUBDIV2D( seq ) \ + (CV_IS_SET(seq) && CV_SEQ_KIND((CvSet*)(seq)) == CV_SEQ_KIND_SUBDIV2D) + +/****************************************************************************************/ +/* Sequence writer & reader */ +/****************************************************************************************/ + +#define CV_SEQ_WRITER_FIELDS() \ + int header_size; \ + CvSeq* seq; /**< the sequence written */ \ + CvSeqBlock* block; /**< current block */ \ + schar* ptr; /**< pointer to free space */ \ + schar* block_min; /**< pointer to the beginning of block*/\ + schar* block_max; /**< pointer to the end of block */ + +typedef struct CvSeqWriter +{ + CV_SEQ_WRITER_FIELDS() +} +CvSeqWriter; + + +#define CV_SEQ_READER_FIELDS() \ + int header_size; \ + CvSeq* seq; /**< sequence, beign read */ \ + CvSeqBlock* block; /**< current block */ \ + schar* ptr; /**< pointer to element be read next */ \ + schar* block_min; /**< pointer to the beginning of block */\ + schar* block_max; /**< pointer to the end of block */ \ + int delta_index;/**< = seq->first->start_index */ \ + schar* prev_elem; /**< pointer to previous element */ + +typedef struct CvSeqReader +{ + CV_SEQ_READER_FIELDS() +} +CvSeqReader; + +/****************************************************************************************/ +/* Operations on sequences */ +/****************************************************************************************/ + +#define CV_SEQ_ELEM( seq, elem_type, index ) \ +/** assert gives some guarantee that parameter is valid */ \ +( assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && \ + (seq)->elem_size == sizeof(elem_type)), \ + (elem_type*)((seq)->first && (unsigned)index < \ + (unsigned)((seq)->first->count) ? \ + (seq)->first->data + (index) * sizeof(elem_type) : \ + cvGetSeqElem( (CvSeq*)(seq), (index) ))) +#define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) ) + +/** Add element to sequence: */ +#define CV_WRITE_SEQ_ELEM_VAR( elem_ptr, writer ) \ +{ \ + if( (writer).ptr >= (writer).block_max ) \ + { \ + cvCreateSeqBlock( &writer); \ + } \ + memcpy((writer).ptr, elem_ptr, (writer).seq->elem_size);\ + (writer).ptr += (writer).seq->elem_size; \ +} + +#define CV_WRITE_SEQ_ELEM( elem, writer ) \ +{ \ + assert( (writer).seq->elem_size == sizeof(elem)); \ + if( (writer).ptr >= (writer).block_max ) \ + { \ + cvCreateSeqBlock( &writer); \ + } \ + assert( (writer).ptr <= (writer).block_max - sizeof(elem));\ + memcpy((writer).ptr, &(elem), sizeof(elem)); \ + (writer).ptr += sizeof(elem); \ +} + + +/** Move reader position forward: */ +#define CV_NEXT_SEQ_ELEM( elem_size, reader ) \ +{ \ + if( ((reader).ptr += (elem_size)) >= (reader).block_max ) \ + { \ + cvChangeSeqBlock( &(reader), 1 ); \ + } \ +} + + +/** Move reader position backward: */ +#define CV_PREV_SEQ_ELEM( elem_size, reader ) \ +{ \ + if( ((reader).ptr -= (elem_size)) < (reader).block_min ) \ + { \ + cvChangeSeqBlock( &(reader), -1 ); \ + } \ +} + +/** Read element and move read position forward: */ +#define CV_READ_SEQ_ELEM( elem, reader ) \ +{ \ + assert( (reader).seq->elem_size == sizeof(elem)); \ + memcpy( &(elem), (reader).ptr, sizeof((elem))); \ + CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \ +} + +/** Read element and move read position backward: */ +#define CV_REV_READ_SEQ_ELEM( elem, reader ) \ +{ \ + assert( (reader).seq->elem_size == sizeof(elem)); \ + memcpy(&(elem), (reader).ptr, sizeof((elem))); \ + CV_PREV_SEQ_ELEM( sizeof(elem), reader ) \ +} + + +#define CV_READ_CHAIN_POINT( _pt, reader ) \ +{ \ + (_pt) = (reader).pt; \ + if( (reader).ptr ) \ + { \ + CV_READ_SEQ_ELEM( (reader).code, (reader)); \ + assert( ((reader).code & ~7) == 0 ); \ + (reader).pt.x += (reader).deltas[(int)(reader).code][0]; \ + (reader).pt.y += (reader).deltas[(int)(reader).code][1]; \ + } \ +} + +#define CV_CURRENT_POINT( reader ) (*((CvPoint*)((reader).ptr))) +#define CV_PREV_POINT( reader ) (*((CvPoint*)((reader).prev_elem))) + +#define CV_READ_EDGE( pt1, pt2, reader ) \ +{ \ + assert( sizeof(pt1) == sizeof(CvPoint) && \ + sizeof(pt2) == sizeof(CvPoint) && \ + reader.seq->elem_size == sizeof(CvPoint)); \ + (pt1) = CV_PREV_POINT( reader ); \ + (pt2) = CV_CURRENT_POINT( reader ); \ + (reader).prev_elem = (reader).ptr; \ + CV_NEXT_SEQ_ELEM( sizeof(CvPoint), (reader)); \ +} + +/************ Graph macros ************/ + +/** Return next graph edge for given vertex: */ +#define CV_NEXT_GRAPH_EDGE( edge, vertex ) \ + (assert((edge)->vtx[0] == (vertex) || (edge)->vtx[1] == (vertex)), \ + (edge)->next[(edge)->vtx[1] == (vertex)]) + + + +/****************************************************************************************\ +* Data structures for persistence (a.k.a serialization) functionality * +\****************************************************************************************/ + +#if 0 + +/** "black box" file storage */ +typedef struct CvFileStorage CvFileStorage; + +/** Storage flags: */ +#define CV_STORAGE_READ 0 +#define CV_STORAGE_WRITE 1 +#define CV_STORAGE_WRITE_TEXT CV_STORAGE_WRITE +#define CV_STORAGE_WRITE_BINARY CV_STORAGE_WRITE +#define CV_STORAGE_APPEND 2 +#define CV_STORAGE_MEMORY 4 +#define CV_STORAGE_FORMAT_MASK (7<<3) +#define CV_STORAGE_FORMAT_AUTO 0 +#define CV_STORAGE_FORMAT_XML 8 +#define CV_STORAGE_FORMAT_YAML 16 +#define CV_STORAGE_FORMAT_JSON 24 +#define CV_STORAGE_BASE64 64 +#define CV_STORAGE_WRITE_BASE64 (CV_STORAGE_BASE64 | CV_STORAGE_WRITE) + +/** @brief List of attributes. : + +In the current implementation, attributes are used to pass extra parameters when writing user +objects (see cvWrite). XML attributes inside tags are not supported, aside from the object type +specification (type_id attribute). +@see cvAttrList, cvAttrValue + */ +typedef struct CvAttrList +{ + const char** attr; /**< NULL-terminated array of (attribute_name,attribute_value) pairs. */ + struct CvAttrList* next; /**< Pointer to next chunk of the attributes list. */ +} +CvAttrList; + +/** initializes CvAttrList structure */ +CV_INLINE CvAttrList cvAttrList( const char** attr CV_DEFAULT(NULL), + CvAttrList* next CV_DEFAULT(NULL) ) +{ + CvAttrList l; + l.attr = attr; + l.next = next; + + return l; +} + +struct CvTypeInfo; + +#define CV_NODE_NONE 0 +#define CV_NODE_INT 1 +#define CV_NODE_INTEGER CV_NODE_INT +#define CV_NODE_REAL 2 +#define CV_NODE_FLOAT CV_NODE_REAL +#define CV_NODE_STR 3 +#define CV_NODE_STRING CV_NODE_STR +#define CV_NODE_REF 4 /**< not used */ +#define CV_NODE_SEQ 5 +#define CV_NODE_MAP 6 +#define CV_NODE_TYPE_MASK 7 + +#define CV_NODE_TYPE(flags) ((flags) & CV_NODE_TYPE_MASK) + +/** file node flags */ +#define CV_NODE_FLOW 8 /**= CV_NODE_SEQ) +#define CV_NODE_IS_FLOW(flags) (((flags) & CV_NODE_FLOW) != 0) +#define CV_NODE_IS_EMPTY(flags) (((flags) & CV_NODE_EMPTY) != 0) +#define CV_NODE_IS_USER(flags) (((flags) & CV_NODE_USER) != 0) +#define CV_NODE_HAS_NAME(flags) (((flags) & CV_NODE_NAMED) != 0) + +#define CV_NODE_SEQ_SIMPLE 256 +#define CV_NODE_SEQ_IS_SIMPLE(seq) (((seq)->flags & CV_NODE_SEQ_SIMPLE) != 0) + +typedef struct CvString +{ + int len; + char* ptr; +} +CvString; + +/** All the keys (names) of elements in the read file storage + are stored in the hash to speed up the lookup operations: */ +typedef struct CvStringHashNode +{ + unsigned hashval; + CvString str; + struct CvStringHashNode* next; +} +CvStringHashNode; + +typedef struct CvGenericHash CvFileNodeHash; + +/** Basic element of the file storage - scalar or collection: */ +typedef struct CvFileNode +{ + int tag; + struct CvTypeInfo* info; /**< type information + (only for user-defined object, for others it is 0) */ + union + { + double f; /**< scalar floating-point number */ + int i; /**< scalar integer number */ + CvString str; /**< text string */ + CvSeq* seq; /**< sequence (ordered collection of file nodes) */ + CvFileNodeHash* map; /**< map (collection of named file nodes) */ + } data; +} +CvFileNode; + +#ifdef __cplusplus +extern "C" { +#endif +typedef int (CV_CDECL *CvIsInstanceFunc)( const void* struct_ptr ); +typedef void (CV_CDECL *CvReleaseFunc)( void** struct_dblptr ); +typedef void* (CV_CDECL *CvReadFunc)( CvFileStorage* storage, CvFileNode* node ); +typedef void (CV_CDECL *CvWriteFunc)( CvFileStorage* storage, const char* name, + const void* struct_ptr, CvAttrList attributes ); +typedef void* (CV_CDECL *CvCloneFunc)( const void* struct_ptr ); +#ifdef __cplusplus +} +#endif + +/** @brief Type information + +The structure contains information about one of the standard or user-defined types. Instances of the +type may or may not contain a pointer to the corresponding CvTypeInfo structure. In any case, there +is a way to find the type info structure for a given object using the cvTypeOf function. +Alternatively, type info can be found by type name using cvFindType, which is used when an object +is read from file storage. The user can register a new type with cvRegisterType that adds the type +information structure into the beginning of the type list. Thus, it is possible to create +specialized types from generic standard types and override the basic methods. + */ +typedef struct CvTypeInfo +{ + int flags; /**< not used */ + int header_size; /**< sizeof(CvTypeInfo) */ + struct CvTypeInfo* prev; /**< previous registered type in the list */ + struct CvTypeInfo* next; /**< next registered type in the list */ + const char* type_name; /**< type name, written to file storage */ + CvIsInstanceFunc is_instance; /**< checks if the passed object belongs to the type */ + CvReleaseFunc release; /**< releases object (memory etc.) */ + CvReadFunc read; /**< reads object from file storage */ + CvWriteFunc write; /**< writes object to file storage */ + CvCloneFunc clone; /**< creates a copy of the object */ +} +CvTypeInfo; +#endif + +/** @} */ + +#endif /*OPENCV_CORE_TYPES_H*/ + +/* End of file. */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utility.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utility.hpp new file mode 100644 index 0000000000000000000000000000000000000000..311d6f5be53da4255d04843bca957ad0fee214cd --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utility.hpp @@ -0,0 +1,1208 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2015, Itseez Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_CORE_UTILITY_H +#define OPENCV_CORE_UTILITY_H + +#ifndef __cplusplus +# error utility.hpp header must be compiled as C++ +#endif + +#if defined(check) +# warning Detected Apple 'check' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. +#endif + +#include "opencv2/core.hpp" +#include + +#include + +#if !defined(_M_CEE) +#include // std::mutex, std::lock_guard +#endif + +namespace cv +{ + +//! @addtogroup core_utils +//! @{ + +/** @brief Automatically Allocated Buffer Class + + The class is used for temporary buffers in functions and methods. + If a temporary buffer is usually small (a few K's of memory), + but its size depends on the parameters, it makes sense to create a small + fixed-size array on stack and use it if it's large enough. If the required buffer size + is larger than the fixed size, another buffer of sufficient size is allocated dynamically + and released after the processing. Therefore, in typical cases, when the buffer size is small, + there is no overhead associated with malloc()/free(). + At the same time, there is no limit on the size of processed data. + + This is what AutoBuffer does. The template takes 2 parameters - type of the buffer elements and + the number of stack-allocated elements. Here is how the class is used: + + \code + void my_func(const cv::Mat& m) + { + cv::AutoBuffer buf(1000); // create automatic buffer containing 1000 floats + + buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used, + // otherwise the buffer of "m.rows" floats will be allocated + // dynamically and deallocated in cv::AutoBuffer destructor + ... + } + \endcode +*/ +#ifdef OPENCV_ENABLE_MEMORY_SANITIZER +template class AutoBuffer +#else +template class AutoBuffer +#endif +{ +public: + typedef _Tp value_type; + + //! the default constructor + AutoBuffer(); + //! constructor taking the real buffer size + explicit AutoBuffer(size_t _size); + + //! the copy constructor + AutoBuffer(const AutoBuffer<_Tp, fixed_size>& buf); + //! the assignment operator + AutoBuffer<_Tp, fixed_size>& operator = (const AutoBuffer<_Tp, fixed_size>& buf); + + //! destructor. calls deallocate() + ~AutoBuffer(); + + //! allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used + void allocate(size_t _size); + //! deallocates the buffer if it was dynamically allocated + void deallocate(); + //! resizes the buffer and preserves the content + void resize(size_t _size); + //! returns the current buffer size + size_t size() const; + //! returns pointer to the real buffer, stack-allocated or heap-allocated + inline _Tp* data() { return ptr; } + //! returns read-only pointer to the real buffer, stack-allocated or heap-allocated + inline const _Tp* data() const { return ptr; } + +#if !defined(OPENCV_DISABLE_DEPRECATED_COMPATIBILITY) // use to .data() calls instead + //! returns pointer to the real buffer, stack-allocated or heap-allocated + operator _Tp* () { return ptr; } + //! returns read-only pointer to the real buffer, stack-allocated or heap-allocated + operator const _Tp* () const { return ptr; } +#else + //! returns a reference to the element at specified location. No bounds checking is performed in Release builds. + inline _Tp& operator[] (size_t i) { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; } + //! returns a reference to the element at specified location. No bounds checking is performed in Release builds. + inline const _Tp& operator[] (size_t i) const { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; } +#endif + +protected: + //! pointer to the real buffer, can point to buf if the buffer is small enough + _Tp* ptr; + //! size of the real buffer + size_t sz; + //! pre-allocated buffer. At least 1 element to confirm C++ standard requirements + _Tp buf[(fixed_size > 0) ? fixed_size : 1]; +}; + +/** @brief Sets/resets the break-on-error mode. + +When the break-on-error mode is set, the default error handler issues a hardware exception, which +can make debugging more convenient. + +\return the previous state + */ +CV_EXPORTS bool setBreakOnError(bool flag); + +extern "C" typedef int (*ErrorCallback)( int status, const char* func_name, + const char* err_msg, const char* file_name, + int line, void* userdata ); + + +/** @brief Sets the new error handler and the optional user data. + + The function sets the new error handler, called from cv::error(). + + \param errCallback the new error handler. If NULL, the default error handler is used. + \param userdata the optional user data pointer, passed to the callback. + \param prevUserdata the optional output parameter where the previous user data pointer is stored + + \return the previous error handler +*/ +CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, void* userdata=0, void** prevUserdata=0); + +CV_EXPORTS String tempfile( const char* suffix = 0); +CV_EXPORTS void glob(String pattern, std::vector& result, bool recursive = false); + +/** @brief OpenCV will try to set the number of threads for the next parallel region. + +If threads == 0, OpenCV will disable threading optimizations and run all it's functions +sequentially. Passing threads \< 0 will reset threads number to system default. This function must +be called outside of parallel region. + +OpenCV will try to run its functions with specified threads number, but some behaviour differs from +framework: +- `TBB` - User-defined parallel constructions will run with the same threads number, if + another is not specified. If later on user creates his own scheduler, OpenCV will use it. +- `OpenMP` - No special defined behaviour. +- `Concurrency` - If threads == 1, OpenCV will disable threading optimizations and run its + functions sequentially. +- `GCD` - Supports only values \<= 0. +- `C=` - No special defined behaviour. +@param nthreads Number of threads used by OpenCV. +@sa getNumThreads, getThreadNum + */ +CV_EXPORTS_W void setNumThreads(int nthreads); + +/** @brief Returns the number of threads used by OpenCV for parallel regions. + +Always returns 1 if OpenCV is built without threading support. + +The exact meaning of return value depends on the threading framework used by OpenCV library: +- `TBB` - The number of threads, that OpenCV will try to use for parallel regions. If there is + any tbb::thread_scheduler_init in user code conflicting with OpenCV, then function returns + default number of threads used by TBB library. +- `OpenMP` - An upper bound on the number of threads that could be used to form a new team. +- `Concurrency` - The number of threads, that OpenCV will try to use for parallel regions. +- `GCD` - Unsupported; returns the GCD thread pool limit (512) for compatibility. +- `C=` - The number of threads, that OpenCV will try to use for parallel regions, if before + called setNumThreads with threads \> 0, otherwise returns the number of logical CPUs, + available for the process. +@sa setNumThreads, getThreadNum + */ +CV_EXPORTS_W int getNumThreads(); + +/** @brief Returns the index of the currently executed thread within the current parallel region. Always +returns 0 if called outside of parallel region. + +@deprecated Current implementation doesn't corresponding to this documentation. + +The exact meaning of the return value depends on the threading framework used by OpenCV library: +- `TBB` - Unsupported with current 4.1 TBB release. Maybe will be supported in future. +- `OpenMP` - The thread number, within the current team, of the calling thread. +- `Concurrency` - An ID for the virtual processor that the current context is executing on (0 + for master thread and unique number for others, but not necessary 1,2,3,...). +- `GCD` - System calling thread's ID. Never returns 0 inside parallel region. +- `C=` - The index of the current parallel task. +@sa setNumThreads, getNumThreads + */ +CV_EXPORTS_W int getThreadNum(); + +/** @brief Returns full configuration time cmake output. + +Returned value is raw cmake output including version control system revision, compiler version, +compiler flags, enabled modules and third party libraries, etc. Output format depends on target +architecture. + */ +CV_EXPORTS_W const String& getBuildInformation(); + +/** @brief Returns library version string + +For example "3.4.1-dev". + +@sa getMajorVersion, getMinorVersion, getRevisionVersion +*/ +CV_EXPORTS_W String getVersionString(); + +/** @brief Returns major library version */ +CV_EXPORTS_W int getVersionMajor(); + +/** @brief Returns minor library version */ +CV_EXPORTS_W int getVersionMinor(); + +/** @brief Returns revision field of the library version */ +CV_EXPORTS_W int getVersionRevision(); + +/** @brief Returns the number of ticks. + +The function returns the number of ticks after the certain event (for example, when the machine was +turned on). It can be used to initialize RNG or to measure a function execution time by reading the +tick count before and after the function call. +@sa getTickFrequency, TickMeter + */ +CV_EXPORTS_W int64 getTickCount(); + +/** @brief Returns the number of ticks per second. + +The function returns the number of ticks per second. That is, the following code computes the +execution time in seconds: +@code + double t = (double)getTickCount(); + // do something ... + t = ((double)getTickCount() - t)/getTickFrequency(); +@endcode +@sa getTickCount, TickMeter + */ +CV_EXPORTS_W double getTickFrequency(); + +/** @brief a Class to measure passing time. + +The class computes passing time by counting the number of ticks per second. That is, the following code computes the +execution time in seconds: +@code +TickMeter tm; +tm.start(); +// do something ... +tm.stop(); +std::cout << tm.getTimeSec(); +@endcode + +It is also possible to compute the average time over multiple runs: +@code +TickMeter tm; +for (int i = 0; i < 100; i++) +{ + tm.start(); + // do something ... + tm.stop(); +} +double average_time = tm.getTimeSec() / tm.getCounter(); +std::cout << "Average time in second per iteration is: " << average_time << std::endl; +@endcode +@sa getTickCount, getTickFrequency +*/ + +class CV_EXPORTS_W TickMeter +{ +public: + //! the default constructor + CV_WRAP TickMeter() + { + reset(); + } + + /** + starts counting ticks. + */ + CV_WRAP void start() + { + startTime = cv::getTickCount(); + } + + /** + stops counting ticks. + */ + CV_WRAP void stop() + { + int64 time = cv::getTickCount(); + if (startTime == 0) + return; + ++counter; + sumTime += (time - startTime); + startTime = 0; + } + + /** + returns counted ticks. + */ + CV_WRAP int64 getTimeTicks() const + { + return sumTime; + } + + /** + returns passed time in microseconds. + */ + CV_WRAP double getTimeMicro() const + { + return getTimeMilli()*1e3; + } + + /** + returns passed time in milliseconds. + */ + CV_WRAP double getTimeMilli() const + { + return getTimeSec()*1e3; + } + + /** + returns passed time in seconds. + */ + CV_WRAP double getTimeSec() const + { + return (double)getTimeTicks() / getTickFrequency(); + } + + /** + returns internal counter value. + */ + CV_WRAP int64 getCounter() const + { + return counter; + } + + /** + resets internal values. + */ + CV_WRAP void reset() + { + startTime = 0; + sumTime = 0; + counter = 0; + } + +private: + int64 counter; + int64 sumTime; + int64 startTime; +}; + +/** @brief output operator +@code +TickMeter tm; +tm.start(); +// do something ... +tm.stop(); +std::cout << tm; +@endcode +*/ + +static inline +std::ostream& operator << (std::ostream& out, const TickMeter& tm) +{ + return out << tm.getTimeSec() << "sec"; +} + +/** @brief Returns the number of CPU ticks. + +The function returns the current number of CPU ticks on some architectures (such as x86, x64, +PowerPC). On other platforms the function is equivalent to getTickCount. It can also be used for +very accurate time measurements, as well as for RNG initialization. Note that in case of multi-CPU +systems a thread, from which getCPUTickCount is called, can be suspended and resumed at another CPU +with its own counter. So, theoretically (and practically) the subsequent calls to the function do +not necessary return the monotonously increasing values. Also, since a modern CPU varies the CPU +frequency depending on the load, the number of CPU clocks spent in some code cannot be directly +converted to time units. Therefore, getTickCount is generally a preferable solution for measuring +execution time. + */ +CV_EXPORTS_W int64 getCPUTickCount(); + +/** @brief Returns true if the specified feature is supported by the host hardware. + +The function returns true if the host hardware supports the specified feature. When user calls +setUseOptimized(false), the subsequent calls to checkHardwareSupport() will return false until +setUseOptimized(true) is called. This way user can dynamically switch on and off the optimized code +in OpenCV. +@param feature The feature of interest, one of cv::CpuFeatures + */ +CV_EXPORTS_W bool checkHardwareSupport(int feature); + +/** @brief Returns feature name by ID + +Returns empty string if feature is not defined +*/ +CV_EXPORTS_W String getHardwareFeatureName(int feature); + +/** @brief Returns list of CPU features enabled during compilation. + +Returned value is a string containing space separated list of CPU features with following markers: + +- no markers - baseline features +- prefix `*` - features enabled in dispatcher +- suffix `?` - features enabled but not available in HW + +Example: `SSE SSE2 SSE3 *SSE4.1 *SSE4.2 *FP16 *AVX *AVX2 *AVX512-SKX?` +*/ +CV_EXPORTS std::string getCPUFeaturesLine(); + +/** @brief Returns the number of logical CPUs available for the process. + */ +CV_EXPORTS_W int getNumberOfCPUs(); + + +/** @brief Aligns a pointer to the specified number of bytes. + +The function returns the aligned pointer of the same type as the input pointer: +\f[\texttt{(_Tp*)(((size_t)ptr + n-1) & -n)}\f] +@param ptr Aligned pointer. +@param n Alignment size that must be a power of two. + */ +template static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp)) +{ + CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2 + return (_Tp*)(((size_t)ptr + n-1) & -n); +} + +/** @brief Aligns a buffer size to the specified number of bytes. + +The function returns the minimum number that is greater than or equal to sz and is divisible by n : +\f[\texttt{(sz + n-1) & -n}\f] +@param sz Buffer size to align. +@param n Alignment size that must be a power of two. + */ +static inline size_t alignSize(size_t sz, int n) +{ + CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2 + return (sz + n-1) & -n; +} + +/** @brief Integer division with result round up. + +Use this function instead of `ceil((float)a / b)` expressions. + +@sa alignSize +*/ +static inline int divUp(int a, unsigned int b) +{ + CV_DbgAssert(a >= 0); + return (a + b - 1) / b; +} +/** @overload */ +static inline size_t divUp(size_t a, unsigned int b) +{ + return (a + b - 1) / b; +} + +/** @brief Round first value up to the nearest multiple of second value. + +Use this function instead of `ceil((float)a / b) * b` expressions. + +@sa divUp +*/ +static inline int roundUp(int a, unsigned int b) +{ + CV_DbgAssert(a >= 0); + return a + b - 1 - (a + b -1) % b; +} +/** @overload */ +static inline size_t roundUp(size_t a, unsigned int b) +{ + return a + b - 1 - (a + b - 1) % b; +} + +/** @brief Alignment check of passed values + +Usage: `isAligned(...)` + +@note Alignment(N) must be a power of 2 (2**k, 2^k) +*/ +template static inline +bool isAligned(const T& data) +{ + CV_StaticAssert((N & (N - 1)) == 0, ""); // power of 2 + return (((size_t)data) & (N - 1)) == 0; +} +/** @overload */ +template static inline +bool isAligned(const void* p1) +{ + return isAligned((size_t)p1); +} +/** @overload */ +template static inline +bool isAligned(const void* p1, const void* p2) +{ + return isAligned(((size_t)p1)|((size_t)p2)); +} +/** @overload */ +template static inline +bool isAligned(const void* p1, const void* p2, const void* p3) +{ + return isAligned(((size_t)p1)|((size_t)p2)|((size_t)p3)); +} +/** @overload */ +template static inline +bool isAligned(const void* p1, const void* p2, const void* p3, const void* p4) +{ + return isAligned(((size_t)p1)|((size_t)p2)|((size_t)p3)|((size_t)p4)); +} + +/** @brief Enables or disables the optimized code. + +The function can be used to dynamically turn on and off optimized dispatched code (code that uses SSE4.2, AVX/AVX2, +and other instructions on the platforms that support it). It sets a global flag that is further +checked by OpenCV functions. Since the flag is not checked in the inner OpenCV loops, it is only +safe to call the function on the very top level in your application where you can be sure that no +other OpenCV function is currently executed. + +By default, the optimized code is enabled unless you disable it in CMake. The current status can be +retrieved using useOptimized. +@param onoff The boolean flag specifying whether the optimized code should be used (onoff=true) +or not (onoff=false). + */ +CV_EXPORTS_W void setUseOptimized(bool onoff); + +/** @brief Returns the status of optimized code usage. + +The function returns true if the optimized code is enabled. Otherwise, it returns false. + */ +CV_EXPORTS_W bool useOptimized(); + +static inline size_t getElemSize(int type) { return (size_t)CV_ELEM_SIZE(type); } + +/////////////////////////////// Parallel Primitives ////////////////////////////////// + +/** @brief Base class for parallel data processors +*/ +class CV_EXPORTS ParallelLoopBody +{ +public: + virtual ~ParallelLoopBody(); + virtual void operator() (const Range& range) const = 0; +}; + +/** @brief Parallel data processor +*/ +CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.); + +class ParallelLoopBodyLambdaWrapper : public ParallelLoopBody +{ +private: + std::function m_functor; +public: + ParallelLoopBodyLambdaWrapper(std::function functor) : + m_functor(functor) + { } + + virtual void operator() (const cv::Range& range) const CV_OVERRIDE + { + m_functor(range); + } +}; + +inline void parallel_for_(const Range& range, std::function functor, double nstripes=-1.) +{ + parallel_for_(range, ParallelLoopBodyLambdaWrapper(functor), nstripes); +} + +/////////////////////////////// forEach method of cv::Mat //////////////////////////// +template inline +void Mat::forEach_impl(const Functor& operation) { + if (false) { + operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast(0)); + // If your compiler fails in this line. + // Please check that your functor signature is + // (_Tp&, const int*) <- multi-dimensional + // or (_Tp&, void*) <- in case you don't need current idx. + } + + CV_Assert(this->total() / this->size[this->dims - 1] <= INT_MAX); + const int LINES = static_cast(this->total() / this->size[this->dims - 1]); + + class PixelOperationWrapper :public ParallelLoopBody + { + public: + PixelOperationWrapper(Mat_<_Tp>* const frame, const Functor& _operation) + : mat(frame), op(_operation) {} + virtual ~PixelOperationWrapper(){} + // ! Overloaded virtual operator + // convert range call to row call. + virtual void operator()(const Range &range) const CV_OVERRIDE + { + const int DIMS = mat->dims; + const int COLS = mat->size[DIMS - 1]; + if (DIMS <= 2) { + for (int row = range.start; row < range.end; ++row) { + this->rowCall2(row, COLS); + } + } else { + std::vector idx(DIMS); /// idx is modified in this->rowCall + idx[DIMS - 2] = range.start - 1; + + for (int line_num = range.start; line_num < range.end; ++line_num) { + idx[DIMS - 2]++; + for (int i = DIMS - 2; i >= 0; --i) { + if (idx[i] >= mat->size[i]) { + idx[i - 1] += idx[i] / mat->size[i]; + idx[i] %= mat->size[i]; + continue; // carry-over; + } + else { + break; + } + } + this->rowCall(&idx[0], COLS, DIMS); + } + } + } + private: + Mat_<_Tp>* const mat; + const Functor op; + // ! Call operator for each elements in this row. + inline void rowCall(int* const idx, const int COLS, const int DIMS) const { + int &col = idx[DIMS - 1]; + col = 0; + _Tp* pixel = &(mat->template at<_Tp>(idx)); + + while (col < COLS) { + op(*pixel, const_cast(idx)); + pixel++; col++; + } + col = 0; + } + // ! Call operator for each elements in this row. 2d mat special version. + inline void rowCall2(const int row, const int COLS) const { + union Index{ + int body[2]; + operator const int*() const { + return reinterpret_cast(this); + } + int& operator[](const int i) { + return body[i]; + } + } idx = {{row, 0}}; + // Special union is needed to avoid + // "error: array subscript is above array bounds [-Werror=array-bounds]" + // when call the functor `op` such that access idx[3]. + + _Tp* pixel = &(mat->template at<_Tp>(idx)); + const _Tp* const pixel_end = pixel + COLS; + while(pixel < pixel_end) { + op(*pixel++, static_cast(idx)); + idx[1]++; + } + } + PixelOperationWrapper& operator=(const PixelOperationWrapper &) { + CV_Assert(false); + // We can not remove this implementation because Visual Studio warning C4822. + return *this; + } + }; + + parallel_for_(cv::Range(0, LINES), PixelOperationWrapper(reinterpret_cast*>(this), operation)); +} + +/////////////////////////// Synchronization Primitives /////////////////////////////// + +#if !defined(_M_CEE) +typedef std::recursive_mutex Mutex; +typedef std::lock_guard AutoLock; +#endif + + +/** @brief Designed for command line parsing + +The sample below demonstrates how to use CommandLineParser: +@code + CommandLineParser parser(argc, argv, keys); + parser.about("Application name v1.0.0"); + + if (parser.has("help")) + { + parser.printMessage(); + return 0; + } + + int N = parser.get("N"); + double fps = parser.get("fps"); + String path = parser.get("path"); + + use_time_stamp = parser.has("timestamp"); + + String img1 = parser.get(0); + String img2 = parser.get(1); + + int repeat = parser.get(2); + + if (!parser.check()) + { + parser.printErrors(); + return 0; + } +@endcode + +### Keys syntax + +The keys parameter is a string containing several blocks, each one is enclosed in curly braces and +describes one argument. Each argument contains three parts separated by the `|` symbol: + +-# argument names is a space-separated list of option synonyms (to mark argument as positional, prefix it with the `@` symbol) +-# default value will be used if the argument was not provided (can be empty) +-# help message (can be empty) + +For example: + +@code{.cpp} + const String keys = + "{help h usage ? | | print this message }" + "{@image1 | | image1 for compare }" + "{@image2 || image2 for compare }" + "{@repeat |1 | number }" + "{path |. | path to file }" + "{fps | -1.0 | fps for output video }" + "{N count |100 | count of objects }" + "{ts timestamp | | use time stamp }" + ; +} +@endcode + +Note that there are no default values for `help` and `timestamp` so we can check their presence using the `has()` method. +Arguments with default values are considered to be always present. Use the `get()` method in these cases to check their +actual value instead. + +String keys like `get("@image1")` return the empty string `""` by default - even with an empty default value. +Use the special `` default value to enforce that the returned string must not be empty. (like in `get("@image2")`) + +### Usage + +For the described keys: + +@code{.sh} + # Good call (3 positional parameters: image1, image2 and repeat; N is 200, ts is true) + $ ./app -N=200 1.png 2.jpg 19 -ts + + # Bad call + $ ./app -fps=aaa + ERRORS: + Parameter 'fps': can not convert: [aaa] to [double] +@endcode + */ +class CV_EXPORTS CommandLineParser +{ +public: + + /** @brief Constructor + + Initializes command line parser object + + @param argc number of command line arguments (from main()) + @param argv array of command line arguments (from main()) + @param keys string describing acceptable command line parameters (see class description for syntax) + */ + CommandLineParser(int argc, const char* const argv[], const String& keys); + + /** @brief Copy constructor */ + CommandLineParser(const CommandLineParser& parser); + + /** @brief Assignment operator */ + CommandLineParser& operator = (const CommandLineParser& parser); + + /** @brief Destructor */ + ~CommandLineParser(); + + /** @brief Returns application path + + This method returns the path to the executable from the command line (`argv[0]`). + + For example, if the application has been started with such a command: + @code{.sh} + $ ./bin/my-executable + @endcode + this method will return `./bin`. + */ + String getPathToApplication() const; + + /** @brief Access arguments by name + + Returns argument converted to selected type. If the argument is not known or can not be + converted to selected type, the error flag is set (can be checked with @ref check). + + For example, define: + @code{.cpp} + String keys = "{N count||}"; + @endcode + + Call: + @code{.sh} + $ ./my-app -N=20 + # or + $ ./my-app --count=20 + @endcode + + Access: + @code{.cpp} + int N = parser.get("N"); + @endcode + + @param name name of the argument + @param space_delete remove spaces from the left and right of the string + @tparam T the argument will be converted to this type if possible + + @note You can access positional arguments by their `@`-prefixed name: + @code{.cpp} + parser.get("@image"); + @endcode + */ + template + T get(const String& name, bool space_delete = true) const + { + T val = T(); + getByName(name, space_delete, ParamType::type, (void*)&val); + return val; + } + + /** @brief Access positional arguments by index + + Returns argument converted to selected type. Indexes are counted from zero. + + For example, define: + @code{.cpp} + String keys = "{@arg1||}{@arg2||}" + @endcode + + Call: + @code{.sh} + ./my-app abc qwe + @endcode + + Access arguments: + @code{.cpp} + String val_1 = parser.get(0); // returns "abc", arg1 + String val_2 = parser.get(1); // returns "qwe", arg2 + @endcode + + @param index index of the argument + @param space_delete remove spaces from the left and right of the string + @tparam T the argument will be converted to this type if possible + */ + template + T get(int index, bool space_delete = true) const + { + T val = T(); + getByIndex(index, space_delete, ParamType::type, (void*)&val); + return val; + } + + /** @brief Check if field was provided in the command line + + @param name argument name to check + */ + bool has(const String& name) const; + + /** @brief Check for parsing errors + + Returns false if error occurred while accessing the parameters (bad conversion, missing arguments, + etc.). Call @ref printErrors to print error messages list. + */ + bool check() const; + + /** @brief Set the about message + + The about message will be shown when @ref printMessage is called, right before arguments table. + */ + void about(const String& message); + + /** @brief Print help message + + This method will print standard help message containing the about message and arguments description. + + @sa about + */ + void printMessage() const; + + /** @brief Print list of errors occurred + + @sa check + */ + void printErrors() const; + +protected: + void getByName(const String& name, bool space_delete, Param type, void* dst) const; + void getByIndex(int index, bool space_delete, Param type, void* dst) const; + + struct Impl; + Impl* impl; +}; + +//! @} core_utils + +//! @cond IGNORED + +/////////////////////////////// AutoBuffer implementation //////////////////////////////////////// + +template inline +AutoBuffer<_Tp, fixed_size>::AutoBuffer() +{ + ptr = buf; + sz = fixed_size; +} + +template inline +AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size) +{ + ptr = buf; + sz = fixed_size; + allocate(_size); +} + +template inline +AutoBuffer<_Tp, fixed_size>::AutoBuffer(const AutoBuffer<_Tp, fixed_size>& abuf ) +{ + ptr = buf; + sz = fixed_size; + allocate(abuf.size()); + for( size_t i = 0; i < sz; i++ ) + ptr[i] = abuf.ptr[i]; +} + +template inline AutoBuffer<_Tp, fixed_size>& +AutoBuffer<_Tp, fixed_size>::operator = (const AutoBuffer<_Tp, fixed_size>& abuf) +{ + if( this != &abuf ) + { + deallocate(); + allocate(abuf.size()); + for( size_t i = 0; i < sz; i++ ) + ptr[i] = abuf.ptr[i]; + } + return *this; +} + +template inline +AutoBuffer<_Tp, fixed_size>::~AutoBuffer() +{ deallocate(); } + +template inline void +AutoBuffer<_Tp, fixed_size>::allocate(size_t _size) +{ + if(_size <= sz) + { + sz = _size; + return; + } + deallocate(); + sz = _size; + if(_size > fixed_size) + { + ptr = new _Tp[_size]; + } +} + +template inline void +AutoBuffer<_Tp, fixed_size>::deallocate() +{ + if( ptr != buf ) + { + delete[] ptr; + ptr = buf; + sz = fixed_size; + } +} + +template inline void +AutoBuffer<_Tp, fixed_size>::resize(size_t _size) +{ + if(_size <= sz) + { + sz = _size; + return; + } + size_t i, prevsize = sz, minsize = MIN(prevsize, _size); + _Tp* prevptr = ptr; + + ptr = _size > fixed_size ? new _Tp[_size] : buf; + sz = _size; + + if( ptr != prevptr ) + for( i = 0; i < minsize; i++ ) + ptr[i] = prevptr[i]; + for( i = prevsize; i < _size; i++ ) + ptr[i] = _Tp(); + + if( prevptr != buf ) + delete[] prevptr; +} + +template inline size_t +AutoBuffer<_Tp, fixed_size>::size() const +{ return sz; } + +//! @endcond + + +// Basic Node class for tree building +template +class CV_EXPORTS Node +{ +public: + Node() + { + m_pParent = 0; + } + Node(OBJECT& payload) : m_payload(payload) + { + m_pParent = 0; + } + ~Node() + { + removeChilds(); + if (m_pParent) + { + int idx = m_pParent->findChild(this); + if (idx >= 0) + m_pParent->m_childs.erase(m_pParent->m_childs.begin() + idx); + } + } + + Node* findChild(OBJECT& payload) const + { + for(size_t i = 0; i < this->m_childs.size(); i++) + { + if(this->m_childs[i]->m_payload == payload) + return this->m_childs[i]; + } + return NULL; + } + + int findChild(Node *pNode) const + { + for (size_t i = 0; i < this->m_childs.size(); i++) + { + if(this->m_childs[i] == pNode) + return (int)i; + } + return -1; + } + + void addChild(Node *pNode) + { + if(!pNode) + return; + + CV_Assert(pNode->m_pParent == 0); + pNode->m_pParent = this; + this->m_childs.push_back(pNode); + } + + void removeChilds() + { + for(size_t i = 0; i < m_childs.size(); i++) + { + m_childs[i]->m_pParent = 0; // avoid excessive parent vector trimming + delete m_childs[i]; + } + m_childs.clear(); + } + + int getDepth() + { + int count = 0; + Node *pParent = m_pParent; + while(pParent) count++, pParent = pParent->m_pParent; + return count; + } + +public: + OBJECT m_payload; + Node* m_pParent; + std::vector*> m_childs; +}; + + +namespace samples { + +//! @addtogroup core_utils_samples +// This section describes utility functions for OpenCV samples. +// +// @note Implementation of these utilities is not thread-safe. +// +//! @{ + +/** @brief Try to find requested data file + +Search directories: + +1. Directories passed via `addSamplesDataSearchPath()` +2. OPENCV_SAMPLES_DATA_PATH_HINT environment variable +3. OPENCV_SAMPLES_DATA_PATH environment variable + If parameter value is not empty and nothing is found then stop searching. +4. Detects build/install path based on: + a. current working directory (CWD) + b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage) +5. Scan `/{,data,samples/data}` directories if build directory is detected or the current directory is in source tree. +6. Scan `/share/OpenCV` directory if install directory is detected. + +@see cv::utils::findDataFile + +@param relative_path Relative path to data file +@param required Specify "file not found" handling. + If true, function prints information message and raises cv::Exception. + If false, function returns empty result +@param silentMode Disables messages +@return Returns path (absolute or relative to the current directory) or empty string if file is not found +*/ +CV_EXPORTS_W cv::String findFile(const cv::String& relative_path, bool required = true, bool silentMode = false); + +CV_EXPORTS_W cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode = false); + +inline cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode) +{ + cv::String res = findFile(relative_path, false, silentMode); + if (res.empty()) + return relative_path; + return res; +} + +/** @brief Override search data path by adding new search location + +Use this only to override default behavior +Passed paths are used in LIFO order. + +@param path Path to used samples data +*/ +CV_EXPORTS_W void addSamplesDataSearchPath(const cv::String& path); + +/** @brief Append samples search data sub directory + +General usage is to add OpenCV modules name (`/modules//samples/data` -> `/samples/data` + `modules//samples/data`). +Passed subdirectories are used in LIFO order. + +@param subdir samples data sub directory +*/ +CV_EXPORTS_W void addSamplesDataSearchSubDirectory(const cv::String& subdir); + +//! @} +} // namespace samples + +namespace utils { + +CV_EXPORTS int getThreadID(); + +} // namespace + +} //namespace cv + +#ifdef CV_COLLECT_IMPL_DATA +#include "opencv2/core/utils/instrumentation.hpp" +#else +/// Collect implementation data on OpenCV function call. Requires ENABLE_IMPL_COLLECTION build option. +#define CV_IMPL_ADD(impl) +#endif + +#endif //OPENCV_CORE_UTILITY_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/allocator_stats.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/allocator_stats.hpp new file mode 100644 index 0000000000000000000000000000000000000000..79e933820aea0c294ce7ab0060826748ec73ff10 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/allocator_stats.hpp @@ -0,0 +1,29 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_ALLOCATOR_STATS_HPP +#define OPENCV_CORE_ALLOCATOR_STATS_HPP + +#include "../cvdef.h" + +namespace cv { namespace utils { + +class AllocatorStatisticsInterface +{ +protected: + AllocatorStatisticsInterface() {} + virtual ~AllocatorStatisticsInterface() {} +public: + virtual uint64_t getCurrentUsage() const = 0; + virtual uint64_t getTotalUsage() const = 0; + virtual uint64_t getNumberOfAllocations() const = 0; + virtual uint64_t getPeakUsage() const = 0; + + /** set peak usage = current usage */ + virtual void resetPeakUsage() = 0; +}; + +}} // namespace + +#endif // OPENCV_CORE_ALLOCATOR_STATS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/allocator_stats.impl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/allocator_stats.impl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b77493d010f98ff37d1003882de28fe5b80ad704 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/allocator_stats.impl.hpp @@ -0,0 +1,117 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP +#define OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP + +#include "./allocator_stats.hpp" + +#ifdef CV_CXX11 +#include +#endif + +namespace cv { namespace utils { + +#ifdef CV__ALLOCATOR_STATS_LOG +namespace { +#endif + +class AllocatorStatistics : public AllocatorStatisticsInterface +{ +protected: +#ifdef CV_CXX11 + std::atomic curr, total, total_allocs, peak; +#else + volatile long long curr, total, total_allocs, peak; // overflow is possible, CV_XADD operates with 'int' only +#endif + +public: + AllocatorStatistics() +#ifndef CV_CXX11 + : curr(0), total(0), total_allocs(0), peak(0) +#endif + {} + ~AllocatorStatistics() CV_OVERRIDE {} + + // AllocatorStatisticsInterface + +#ifdef CV_CXX11 + uint64_t getCurrentUsage() const CV_OVERRIDE { return (uint64_t)curr.load(); } + uint64_t getTotalUsage() const CV_OVERRIDE { return (uint64_t)total.load(); } + uint64_t getNumberOfAllocations() const CV_OVERRIDE { return (uint64_t)total_allocs.load(); } + uint64_t getPeakUsage() const CV_OVERRIDE { return (uint64_t)peak.load(); } + + /** set peak usage = current usage */ + void resetPeakUsage() CV_OVERRIDE { peak.store(curr.load()); } + + // Controller interface + void onAllocate(size_t sz) + { +#ifdef CV__ALLOCATOR_STATS_LOG + CV__ALLOCATOR_STATS_LOG(cv::format("allocate: %lld (curr=%lld)", (long long int)sz, (long long int)curr.load())); +#endif + + long long new_curr = curr.fetch_add((long long)sz) + (long long)sz; + + // peak = std::max((uint64_t)peak, new_curr); + auto prev_peak = peak.load(); + while (prev_peak < new_curr) + { + if (peak.compare_exchange_weak(prev_peak, new_curr)) + break; + } + // end of peak = max(...) + + total += (long long)sz; + total_allocs++; + } + void onFree(size_t sz) + { +#ifdef CV__ALLOCATOR_STATS_LOG + CV__ALLOCATOR_STATS_LOG(cv::format("free: %lld (curr=%lld)", (long long int)sz, (long long int)curr.load())); +#endif + curr -= (long long)sz; + } + +#else + uint64_t getCurrentUsage() const CV_OVERRIDE { return (uint64_t)curr; } + uint64_t getTotalUsage() const CV_OVERRIDE { return (uint64_t)total; } + uint64_t getNumberOfAllocations() const CV_OVERRIDE { return (uint64_t)total_allocs; } + uint64_t getPeakUsage() const CV_OVERRIDE { return (uint64_t)peak; } + + void resetPeakUsage() CV_OVERRIDE { peak = curr; } + + // Controller interface + void onAllocate(size_t sz) + { +#ifdef CV__ALLOCATOR_STATS_LOG + CV__ALLOCATOR_STATS_LOG(cv::format("allocate: %lld (curr=%lld)", (long long int)sz, (long long int)curr)); +#endif + + uint64_t new_curr = (uint64_t)CV_XADD(&curr, (uint64_t)sz) + sz; + + peak = std::max((uint64_t)peak, new_curr); // non-thread safe + + //CV_XADD(&total, (uint64_t)sz); // overflow with int, non-reliable... + total += sz; + + CV_XADD(&total_allocs, (uint64_t)1); + } + void onFree(size_t sz) + { +#ifdef CV__ALLOCATOR_STATS_LOG + CV__ALLOCATOR_STATS_LOG(cv::format("free: %lld (curr=%lld)", (long long int)sz, (long long int)curr)); +#endif + CV_XADD(&curr, (uint64_t)-sz); + } +#endif +}; + +#ifdef CV__ALLOCATOR_STATS_LOG +} // namespace +#endif + +}} // namespace + +#endif // OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/filesystem.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/filesystem.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a98d2202fc5091b72994f1d262e1607a57dda277 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/filesystem.hpp @@ -0,0 +1,82 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_UTILS_FILESYSTEM_HPP +#define OPENCV_UTILS_FILESYSTEM_HPP + +namespace cv { namespace utils { namespace fs { + + +CV_EXPORTS bool exists(const cv::String& path); +CV_EXPORTS bool isDirectory(const cv::String& path); + +CV_EXPORTS void remove_all(const cv::String& path); + + +CV_EXPORTS cv::String getcwd(); + +/** @brief Converts path p to a canonical absolute path + * Symlinks are processed if there is support for them on running platform. + * + * @param path input path. Target file/directory should exist. + */ +CV_EXPORTS cv::String canonical(const cv::String& path); + +/** Join path components */ +CV_EXPORTS cv::String join(const cv::String& base, const cv::String& path); + +/** Get parent directory */ +CV_EXPORTS cv::String getParent(const cv::String &path); +CV_EXPORTS std::wstring getParent(const std::wstring& path); + +/** + * Generate a list of all files that match the globbing pattern. + * + * Result entries are prefixed by base directory path. + * + * @param directory base directory + * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results + * @param[out] result result of globing. + * @param recursive scan nested directories too + * @param includeDirectories include directories into results list + */ +CV_EXPORTS void glob(const cv::String& directory, const cv::String& pattern, + CV_OUT std::vector& result, + bool recursive = false, bool includeDirectories = false); + +/** + * Generate a list of all files that match the globbing pattern. + * + * @param directory base directory + * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results + * @param[out] result globbing result with relative paths from base directory + * @param recursive scan nested directories too + * @param includeDirectories include directories into results list + */ +CV_EXPORTS void glob_relative(const cv::String& directory, const cv::String& pattern, + CV_OUT std::vector& result, + bool recursive = false, bool includeDirectories = false); + + +CV_EXPORTS bool createDirectory(const cv::String& path); +CV_EXPORTS bool createDirectories(const cv::String& path); + +#ifdef __OPENCV_BUILD +// TODO +//CV_EXPORTS cv::String getTempDirectory(); + +/** + * @brief Returns directory to store OpenCV cache files + * Create sub-directory in common OpenCV cache directory if it doesn't exist. + * @param sub_directory_name name of sub-directory. NULL or "" value asks to return root cache directory. + * @param configuration_name optional name of configuration parameter name which overrides default behavior. + * @return Path to cache directory. Returns empty string if cache directories support is not available. Returns "disabled" if cache disabled by user. + */ +CV_EXPORTS cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name = NULL); + +#endif + +}}} // namespace + +#endif // OPENCV_UTILS_FILESYSTEM_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/instrumentation.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/instrumentation.hpp new file mode 100644 index 0000000000000000000000000000000000000000..363986708050890cc530be68fa7cb5c208b750d8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/instrumentation.hpp @@ -0,0 +1,125 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_UTILS_INSTR_HPP +#define OPENCV_UTILS_INSTR_HPP + +#include +#include + +namespace cv { + +//! @addtogroup core_utils +//! @{ + +#ifdef CV_COLLECT_IMPL_DATA +CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays +CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays +// Get stored implementation flags and functions names arrays +// Each implementation entry correspond to function name entry, so you can find which implementation was executed in which function +CV_EXPORTS int getImpl(std::vector &impl, std::vector &funName); + +CV_EXPORTS bool useCollection(); // return implementation collection state +CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state + +#define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation +#define CV_IMPL_OCL 0x02 // OpenCL implementation +#define CV_IMPL_IPP 0x04 // IPP implementation +#define CV_IMPL_MT 0x10 // multithreaded implementation + +#undef CV_IMPL_ADD +#define CV_IMPL_ADD(impl) \ + if(cv::useCollection()) \ + { \ + cv::addImpl(impl, CV_Func); \ + } +#endif + +// Instrumentation external interface +namespace instr +{ + +#if !defined OPENCV_ABI_CHECK + +enum TYPE +{ + TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function + TYPE_MARKER, // Information marker + TYPE_WRAPPER, // Wrapper function for implementation + TYPE_FUN, // Simple function call +}; + +enum IMPL +{ + IMPL_PLAIN = 0, + IMPL_IPP, + IMPL_OPENCL, +}; + +struct NodeDataTls +{ + NodeDataTls() + { + m_ticksTotal = 0; + } + uint64 m_ticksTotal; +}; + +class CV_EXPORTS NodeData +{ +public: + NodeData(const char* funName = 0, const char* fileName = NULL, int lineNum = 0, void* retAddress = NULL, bool alwaysExpand = false, cv::instr::TYPE instrType = TYPE_GENERAL, cv::instr::IMPL implType = IMPL_PLAIN); + NodeData(NodeData &ref); + ~NodeData(); + NodeData& operator=(const NodeData&); + + cv::String m_funName; + cv::instr::TYPE m_instrType; + cv::instr::IMPL m_implType; + const char* m_fileName; + int m_lineNum; + void* m_retAddress; + bool m_alwaysExpand; + bool m_funError; + + volatile int m_counter; + volatile uint64 m_ticksTotal; + TLSDataAccumulator m_tls; + int m_threads; + + // No synchronization + double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; } + double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; } +}; +bool operator==(const NodeData& lhs, const NodeData& rhs); + +typedef Node InstrNode; + +CV_EXPORTS InstrNode* getTrace(); + +#endif // !defined OPENCV_ABI_CHECK + + +CV_EXPORTS bool useInstrumentation(); +CV_EXPORTS void setUseInstrumentation(bool flag); +CV_EXPORTS void resetTrace(); + +enum FLAGS +{ + FLAGS_NONE = 0, + FLAGS_MAPPING = 0x01, + FLAGS_EXPAND_SAME_NAMES = 0x02, +}; + +CV_EXPORTS void setFlags(FLAGS modeFlags); +static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); } +CV_EXPORTS FLAGS getFlags(); + +} // namespace instr + +//! @} + +} // namespace + +#endif // OPENCV_UTILS_TLS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logger.defines.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logger.defines.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7d73f02b66955c72bbf9184be4e0cd01aa84a3fd --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logger.defines.hpp @@ -0,0 +1,42 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_LOGGER_DEFINES_HPP +#define OPENCV_LOGGER_DEFINES_HPP + +//! @addtogroup core_logging +//! @{ + +// Supported logging levels and their semantic +#define CV_LOG_LEVEL_SILENT 0 //!< for using in setLogLevel() call +#define CV_LOG_LEVEL_FATAL 1 //!< Fatal (critical) error (unrecoverable internal error) +#define CV_LOG_LEVEL_ERROR 2 //!< Error message +#define CV_LOG_LEVEL_WARN 3 //!< Warning message +#define CV_LOG_LEVEL_INFO 4 //!< Info message +#define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build. +#define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. + +namespace cv { +namespace utils { +namespace logging { + +//! Supported logging levels and their semantic +enum LogLevel { + LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call + LOG_LEVEL_FATAL = 1, //!< Fatal (critical) error (unrecoverable internal error) + LOG_LEVEL_ERROR = 2, //!< Error message + LOG_LEVEL_WARNING = 3, //!< Warning message + LOG_LEVEL_INFO = 4, //!< Info message + LOG_LEVEL_DEBUG = 5, //!< Debug message. Disabled in the "Release" build. + LOG_LEVEL_VERBOSE = 6, //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. +#ifndef CV_DOXYGEN + ENUM_LOG_LEVEL_FORCE_INT = INT_MAX +#endif +}; + +}}} // namespace + +//! @} + +#endif // OPENCV_LOGGER_DEFINES_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logger.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logger.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bf73d9ac51f96790469b10d1d89821097c0f5169 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logger.hpp @@ -0,0 +1,153 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_LOGGER_HPP +#define OPENCV_LOGGER_HPP + +#include +#include +#include // INT_MAX + +#include "logger.defines.hpp" +#include "logtag.hpp" + +namespace cv { +namespace utils { +namespace logging { + +//! @addtogroup core_logging +//! @{ + +/** Set global logging level +@return previous logging level +*/ +CV_EXPORTS LogLevel setLogLevel(LogLevel logLevel); +/** Get global logging level */ +CV_EXPORTS LogLevel getLogLevel(); + +CV_EXPORTS void registerLogTag(cv::utils::logging::LogTag* plogtag); + +CV_EXPORTS void setLogTagLevel(const char* tag, cv::utils::logging::LogLevel level); + +CV_EXPORTS cv::utils::logging::LogLevel getLogTagLevel(const char* tag); + +namespace internal { + +/** Get global log tag */ +CV_EXPORTS cv::utils::logging::LogTag* getGlobalLogTag(); + +/** Write log message */ +CV_EXPORTS void writeLogMessage(LogLevel logLevel, const char* message); + +/** Write log message */ +CV_EXPORTS void writeLogMessageEx(LogLevel logLevel, const char* tag, const char* file, int line, const char* func, const char* message); + +} // namespace + +struct LogTagAuto + : public LogTag +{ + inline LogTagAuto(const char* _name, LogLevel _level) + : LogTag(_name, _level) + { + registerLogTag(this); + } +}; + +/** + * \def CV_LOG_STRIP_LEVEL + * + * Define CV_LOG_STRIP_LEVEL=CV_LOG_LEVEL_[DEBUG|INFO|WARN|ERROR|FATAL|SILENT] to compile out anything at that and before that logging level + */ +#ifndef CV_LOG_STRIP_LEVEL +# if defined NDEBUG +# define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_DEBUG +# else +# define CV_LOG_STRIP_LEVEL CV_LOG_LEVEL_VERBOSE +# endif +#endif + +#define CV_LOGTAG_PTR_CAST(expr) static_cast(expr) + +// CV_LOGTAG_EXPAND_NAME is intended to be re-defined (undef and then define again) +// to allows logging users to use a shorter name argument when calling +// CV_LOG_WITH_TAG or its related macros such as CV_LOG_INFO. +// +// This macro is intended to modify the tag argument as a string (token), via +// preprocessor token pasting or metaprogramming techniques. A typical usage +// is to apply a prefix, such as +// ...... #define CV_LOGTAG_EXPAND_NAME(tag) cv_logtag_##tag +// +// It is permitted to re-define to a hard-coded expression, ignoring the tag. +// This would work identically like the CV_LOGTAG_FALLBACK macro. +// +// Important: When the logging macro is called with tag being NULL, a user-defined +// CV_LOGTAG_EXPAND_NAME may expand it into cv_logtag_0, cv_logtag_NULL, or +// cv_logtag_nullptr. Use with care. Also be mindful of C++ symbol redefinitions. +// +// If there is significant amount of logging code with tag being NULL, it is +// recommended to use (re-define) CV_LOGTAG_FALLBACK to inject locally a default +// tag at the beginning of a compilation unit, to minimize lines of code changes. +// +#define CV_LOGTAG_EXPAND_NAME(tag) tag + +// CV_LOGTAG_FALLBACK is intended to be re-defined (undef and then define again) +// by any other compilation units to provide a log tag when the logging statement +// does not specify one. The macro needs to expand into a C++ expression that can +// be static_cast into (cv::utils::logging::LogTag*). Null (nullptr) is permitted. +#define CV_LOGTAG_FALLBACK nullptr + +// CV_LOGTAG_GLOBAL is the tag used when a log tag is not specified in the logging +// statement nor the compilation unit. The macro needs to expand into a C++ +// expression that can be static_cast into (cv::utils::logging::LogTag*). Must be +// non-null. Do not re-define. +#define CV_LOGTAG_GLOBAL cv::utils::logging::internal::getGlobalLogTag() + +#define CV_LOG_WITH_TAG(tag, msgLevel, ...) \ + for(;;) { \ + const auto cv_temp_msglevel = (cv::utils::logging::LogLevel)(msgLevel); \ + if (cv_temp_msglevel >= (CV_LOG_STRIP_LEVEL)) break; \ + auto cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_EXPAND_NAME(tag)); \ + if (!cv_temp_logtagptr) cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_FALLBACK); \ + if (!cv_temp_logtagptr) cv_temp_logtagptr = CV_LOGTAG_PTR_CAST(CV_LOGTAG_GLOBAL); \ + if (cv_temp_logtagptr && (cv_temp_msglevel > cv_temp_logtagptr->level)) break; \ + std::stringstream cv_temp_logstream; \ + cv_temp_logstream << __VA_ARGS__; \ + cv::utils::logging::internal::writeLogMessageEx( \ + cv_temp_msglevel, \ + (cv_temp_logtagptr ? cv_temp_logtagptr->name : nullptr), \ + __FILE__, \ + __LINE__, \ + CV_Func, \ + cv_temp_logstream.str().c_str()); \ + break; \ + } + +#define CV_LOG_FATAL(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_FATAL, __VA_ARGS__) +#define CV_LOG_ERROR(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_ERROR, __VA_ARGS__) +#define CV_LOG_WARNING(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_WARNING, __VA_ARGS__) +#define CV_LOG_INFO(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_INFO, __VA_ARGS__) +#define CV_LOG_DEBUG(tag, ...) CV_LOG_WITH_TAG(tag, cv::utils::logging::LOG_LEVEL_DEBUG, __VA_ARGS__) +#define CV_LOG_VERBOSE(tag, v, ...) CV_LOG_WITH_TAG(tag, (cv::utils::logging::LOG_LEVEL_VERBOSE + (int)(v)), __VA_ARGS__) + +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_INFO +# undef CV_LOG_INFO +# define CV_LOG_INFO(tag, ...) +#endif + +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_DEBUG +# undef CV_LOG_DEBUG +# define CV_LOG_DEBUG(tag, ...) +#endif + +#if CV_LOG_STRIP_LEVEL <= CV_LOG_LEVEL_VERBOSE +# undef CV_LOG_VERBOSE +# define CV_LOG_VERBOSE(tag, v, ...) +#endif + +//! @} + +}}} // namespace + +#endif // OPENCV_LOGGER_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logtag.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logtag.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4089720767de54415e9a7c94eb21e8a08f3d19e5 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/logtag.hpp @@ -0,0 +1,28 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_CORE_LOGTAG_HPP +#define OPENCV_CORE_LOGTAG_HPP + +#include "opencv2/core/cvstd.hpp" +#include "logger.defines.hpp" + +namespace cv { +namespace utils { +namespace logging { + +struct LogTag +{ + const char* name; + LogLevel level; + + inline LogTag(const char* _name, LogLevel _level) + : name(_name) + , level(_level) + {} +}; + +}}} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/tls.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/tls.hpp new file mode 100644 index 0000000000000000000000000000000000000000..697a7b034021d4503fce09130469e2e3c5c9a2ec --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/tls.hpp @@ -0,0 +1,233 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_UTILS_TLS_HPP +#define OPENCV_UTILS_TLS_HPP + +#include + +namespace cv { + +//! @addtogroup core_utils +//! @{ + +namespace details { class TlsStorage; } + +/** TLS container base implementation + * + * Don't use directly. + * + * @sa TLSData, TLSDataAccumulator templates + */ +class CV_EXPORTS TLSDataContainer +{ +protected: + TLSDataContainer(); + virtual ~TLSDataContainer(); + + /// @deprecated use detachData() instead + void gatherData(std::vector &data) const; + /// get TLS data and detach all data from threads (similar to cleanup() call) + void detachData(std::vector& data); + + void* getData() const; + void release(); + +protected: + virtual void* createDataInstance() const = 0; + virtual void deleteDataInstance(void* pData) const = 0; + +private: + int key_; + + friend class cv::details::TlsStorage; // core/src/system.cpp + +public: + void cleanup(); //!< Release created TLS data container objects. It is similar to release() call, but it keeps TLS container valid. + +private: + // Disable copy/assign (noncopyable pattern) + TLSDataContainer(TLSDataContainer &) = delete; + TLSDataContainer& operator =(const TLSDataContainer &) = delete; +}; + + +/** @brief Simple TLS data class + * + * @sa TLSDataAccumulator + */ +template +class TLSData : protected TLSDataContainer +{ +public: + inline TLSData() {} + inline ~TLSData() { release(); } + + inline T* get() const { return (T*)getData(); } //!< Get data associated with key + inline T& getRef() const { T* ptr = (T*)getData(); CV_DbgAssert(ptr); return *ptr; } //!< Get data associated with key + + /// Release associated thread data + inline void cleanup() + { + TLSDataContainer::cleanup(); + } + +protected: + /// Wrapper to allocate data by template + virtual void* createDataInstance() const CV_OVERRIDE { return new T; } + /// Wrapper to release data by template + virtual void deleteDataInstance(void* pData) const CV_OVERRIDE { delete (T*)pData; } +}; + + +/// TLS data accumulator with gathering methods +template +class TLSDataAccumulator : public TLSData +{ + mutable cv::Mutex mutex; + mutable std::vector dataFromTerminatedThreads; + std::vector detachedData; + bool cleanupMode; +public: + TLSDataAccumulator() : cleanupMode(false) {} + ~TLSDataAccumulator() + { + release(); + } + + /** @brief Get data from all threads + * @deprecated replaced by detachData() + * + * Lifetime of vector data is valid until next detachData()/cleanup()/release() calls + * + * @param[out] data result buffer (should be empty) + */ + void gather(std::vector &data) const + { + CV_Assert(cleanupMode == false); // state is not valid + CV_Assert(data.empty()); + { + std::vector &dataVoid = reinterpret_cast&>(data); + TLSDataContainer::gatherData(dataVoid); + } + { + AutoLock lock(mutex); + data.reserve(data.size() + dataFromTerminatedThreads.size()); + for (typename std::vector::const_iterator i = dataFromTerminatedThreads.begin(); i != dataFromTerminatedThreads.end(); ++i) + { + data.push_back((T*)*i); + } + } + } + + /** @brief Get and detach data from all threads + * + * Call cleanupDetachedData() when returned vector is not needed anymore. + * + * @return Vector with associated data. Content is preserved (including lifetime of attached data pointers) until next detachData()/cleanupDetachedData()/cleanup()/release() calls + */ + std::vector& detachData() + { + CV_Assert(cleanupMode == false); // state is not valid + std::vector dataVoid; + { + TLSDataContainer::detachData(dataVoid); + } + { + AutoLock lock(mutex); + detachedData.reserve(dataVoid.size() + dataFromTerminatedThreads.size()); + for (typename std::vector::const_iterator i = dataFromTerminatedThreads.begin(); i != dataFromTerminatedThreads.end(); ++i) + { + detachedData.push_back((T*)*i); + } + dataFromTerminatedThreads.clear(); + for (typename std::vector::const_iterator i = dataVoid.begin(); i != dataVoid.end(); ++i) + { + detachedData.push_back((T*)(void*)*i); + } + } + dataVoid.clear(); + return detachedData; + } + + /// Release associated thread data returned by detachData() call + void cleanupDetachedData() + { + AutoLock lock(mutex); + cleanupMode = true; + _cleanupDetachedData(); + cleanupMode = false; + } + + /// Release associated thread data + void cleanup() + { + cleanupMode = true; + TLSDataContainer::cleanup(); + + AutoLock lock(mutex); + _cleanupDetachedData(); + _cleanupTerminatedData(); + cleanupMode = false; + } + + /// Release associated thread data and free TLS key + void release() + { + cleanupMode = true; + TLSDataContainer::release(); + { + AutoLock lock(mutex); + _cleanupDetachedData(); + _cleanupTerminatedData(); + } + } + +protected: + // synchronized + void _cleanupDetachedData() + { + for (typename std::vector::iterator i = detachedData.begin(); i != detachedData.end(); ++i) + { + deleteDataInstance((T*)*i); + } + detachedData.clear(); + } + + // synchronized + void _cleanupTerminatedData() + { + for (typename std::vector::iterator i = dataFromTerminatedThreads.begin(); i != dataFromTerminatedThreads.end(); ++i) + { + deleteDataInstance((T*)*i); + } + dataFromTerminatedThreads.clear(); + } + +protected: + virtual void* createDataInstance() const CV_OVERRIDE + { + // Note: we can collect all allocated data here, but this would require raced mutex locks + return new T; + } + virtual void deleteDataInstance(void* pData) const CV_OVERRIDE + { + if (cleanupMode) + { + delete (T*)pData; + } + else + { + AutoLock lock(mutex); + dataFromTerminatedThreads.push_back((T*)pData); + } + } +}; + + +//! @} + +} // namespace + +#endif // OPENCV_UTILS_TLS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/trace.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/trace.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ef5d35b4f2bb0a0e1462d309043f97e2ebee3305 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/utils/trace.hpp @@ -0,0 +1,252 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_TRACE_HPP +#define OPENCV_TRACE_HPP + +#include + +namespace cv { +namespace utils { +namespace trace { + +//! @addtogroup core_logging +//! @{ + +//! Macro to trace function +#define CV_TRACE_FUNCTION() + +#define CV_TRACE_FUNCTION_SKIP_NESTED() + +//! Trace code scope. +//! @note Dynamic names are not supported in this macro (on stack or heap). Use string literals here only, like "initialize". +#define CV_TRACE_REGION(name_as_static_string_literal) +//! mark completed of the current opened region and create new one +//! @note Dynamic names are not supported in this macro (on stack or heap). Use string literals here only, like "step1". +#define CV_TRACE_REGION_NEXT(name_as_static_string_literal) + +//! Macro to trace argument value +#define CV_TRACE_ARG(arg_id) + +//! Macro to trace argument value (expanded version) +#define CV_TRACE_ARG_VALUE(arg_id, arg_name, value) + +//! @cond IGNORED +#define CV_TRACE_NS cv::utils::trace + +#if !defined(OPENCV_DISABLE_TRACE) && defined(__EMSCRIPTEN__) +#define OPENCV_DISABLE_TRACE 1 +#endif + +namespace details { + +#ifndef __OPENCV_TRACE +# if defined __OPENCV_BUILD && !defined __OPENCV_TESTS && !defined __OPENCV_APPS +# define __OPENCV_TRACE 1 +# else +# define __OPENCV_TRACE 0 +# endif +#endif + +#ifndef CV_TRACE_FILENAME +# define CV_TRACE_FILENAME __FILE__ +#endif + +#ifndef CV__TRACE_FUNCTION +# if defined _MSC_VER +# define CV__TRACE_FUNCTION __FUNCSIG__ +# elif defined __GNUC__ +# define CV__TRACE_FUNCTION __PRETTY_FUNCTION__ +# else +# define CV__TRACE_FUNCTION "" +# endif +#endif + +//! Thread-local instance (usually allocated on stack) +class CV_EXPORTS Region +{ +public: + struct LocationExtraData; + struct LocationStaticStorage + { + LocationExtraData** ppExtra; //< implementation specific data + const char* name; //< region name (function name or other custom name) + const char* filename; //< source code filename + int line; //< source code line + int flags; //< flags (implementation code path: Plain, IPP, OpenCL) + }; + + Region(const LocationStaticStorage& location); + inline ~Region() + { + if (implFlags != 0) + destroy(); + CV_DbgAssert(implFlags == 0); + CV_DbgAssert(pImpl == NULL); + } + + class Impl; + Impl* pImpl; // NULL if current region is not active + int implFlags; // see RegionFlag, 0 if region is ignored + + bool isActive() const { return pImpl != NULL; } + + void destroy(); +private: + Region(const Region&); // disabled + Region& operator= (const Region&); // disabled +}; + +//! Specify region flags +enum RegionLocationFlag { + REGION_FLAG_FUNCTION = (1 << 0), //< region is function (=1) / nested named region (=0) + REGION_FLAG_APP_CODE = (1 << 1), //< region is Application code (=1) / OpenCV library code (=0) + REGION_FLAG_SKIP_NESTED = (1 << 2), //< avoid processing of nested regions + + REGION_FLAG_IMPL_IPP = (1 << 16), //< region is part of IPP code path + REGION_FLAG_IMPL_OPENCL = (2 << 16), //< region is part of OpenCL code path + REGION_FLAG_IMPL_OPENVX = (3 << 16), //< region is part of OpenVX code path + + REGION_FLAG_IMPL_MASK = (15 << 16), + + REGION_FLAG_REGION_FORCE = (1 << 30), + REGION_FLAG_REGION_NEXT = (1 << 31), //< close previous region (see #CV_TRACE_REGION_NEXT macro) + + ENUM_REGION_FLAG_FORCE_INT = INT_MAX +}; + +struct CV_EXPORTS TraceArg { +public: + struct ExtraData; + ExtraData** ppExtra; + const char* name; + int flags; +}; +/** @brief Add meta information to current region (function) + * See CV_TRACE_ARG macro + * @param arg argument information structure (global static cache) + * @param value argument value (can by dynamic string literal in case of string, static allocation is not required) + */ +CV_EXPORTS void traceArg(const TraceArg& arg, const char* value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, int value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, int64 value); +//! @overload +CV_EXPORTS void traceArg(const TraceArg& arg, double value); + +#define CV__TRACE_LOCATION_VARNAME(loc_id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_trace_location_, loc_id), __LINE__) +#define CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_trace_location_extra_, loc_id) , __LINE__) + +#define CV__TRACE_DEFINE_LOCATION_(loc_id, name, flags) \ + static CV_TRACE_NS::details::Region::LocationExtraData* CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id) = 0; \ + static const CV_TRACE_NS::details::Region::LocationStaticStorage \ + CV__TRACE_LOCATION_VARNAME(loc_id) = { &(CV__TRACE_LOCATION_EXTRA_VARNAME(loc_id)), name, CV_TRACE_FILENAME, __LINE__, flags}; + +#define CV__TRACE_DEFINE_LOCATION_FN(name, flags) CV__TRACE_DEFINE_LOCATION_(fn, name, ((flags) | CV_TRACE_NS::details::REGION_FLAG_FUNCTION)) + + +#define CV__TRACE_OPENCV_FUNCTION() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, 0); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_OPENCV_FUNCTION_NAME(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, 0); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION_NAME(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + + +#define CV__TRACE_OPENCV_FUNCTION_SKIP_NESTED() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_OPENCV_FUNCTION_NAME_SKIP_NESTED(name) \ + CV__TRACE_DEFINE_LOCATION_FN(name, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + +#define CV__TRACE_APP_FUNCTION_SKIP_NESTED() \ + CV__TRACE_DEFINE_LOCATION_FN(CV__TRACE_FUNCTION, CV_TRACE_NS::details::REGION_FLAG_SKIP_NESTED | CV_TRACE_NS::details::REGION_FLAG_APP_CODE); \ + const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn)); + + +#define CV__TRACE_REGION_(name_as_static_string_literal, flags) \ + CV__TRACE_DEFINE_LOCATION_(region, name_as_static_string_literal, flags); \ + CV_TRACE_NS::details::Region CVAUX_CONCAT(__region_, __LINE__)(CV__TRACE_LOCATION_VARNAME(region)); + +#define CV__TRACE_REGION(name_as_static_string_literal) CV__TRACE_REGION_(name_as_static_string_literal, 0) +#define CV__TRACE_REGION_NEXT(name_as_static_string_literal) CV__TRACE_REGION_(name_as_static_string_literal, CV_TRACE_NS::details::REGION_FLAG_REGION_NEXT) + +#define CV__TRACE_ARG_VARNAME(arg_id) CVAUX_CONCAT(__cv_trace_arg_ ## arg_id, __LINE__) +#define CV__TRACE_ARG_EXTRA_VARNAME(arg_id) CVAUX_CONCAT(__cv_trace_arg_extra_ ## arg_id, __LINE__) + +#define CV__TRACE_DEFINE_ARG_(arg_id, name, flags) \ + static CV_TRACE_NS::details::TraceArg::ExtraData* CV__TRACE_ARG_EXTRA_VARNAME(arg_id) = 0; \ + static const CV_TRACE_NS::details::TraceArg \ + CV__TRACE_ARG_VARNAME(arg_id) = { &(CV__TRACE_ARG_EXTRA_VARNAME(arg_id)), name, flags }; + +#define CV__TRACE_ARG_VALUE(arg_id, arg_name, value) \ + CV__TRACE_DEFINE_ARG_(arg_id, arg_name, 0); \ + CV_TRACE_NS::details::traceArg((CV__TRACE_ARG_VARNAME(arg_id)), value); + +#define CV__TRACE_ARG(arg_id) CV_TRACE_ARG_VALUE(arg_id, #arg_id, (arg_id)) + +} // namespace + +#ifndef OPENCV_DISABLE_TRACE +#undef CV_TRACE_FUNCTION +#undef CV_TRACE_FUNCTION_SKIP_NESTED +#if __OPENCV_TRACE +#define CV_TRACE_FUNCTION CV__TRACE_OPENCV_FUNCTION +#define CV_TRACE_FUNCTION_SKIP_NESTED CV__TRACE_OPENCV_FUNCTION_SKIP_NESTED +#else +#define CV_TRACE_FUNCTION CV__TRACE_APP_FUNCTION +#define CV_TRACE_FUNCTION_SKIP_NESTED CV__TRACE_APP_FUNCTION_SKIP_NESTED +#endif + +#undef CV_TRACE_REGION +#define CV_TRACE_REGION CV__TRACE_REGION + +#undef CV_TRACE_REGION_NEXT +#define CV_TRACE_REGION_NEXT CV__TRACE_REGION_NEXT + +#undef CV_TRACE_ARG_VALUE +#define CV_TRACE_ARG_VALUE(arg_id, arg_name, value) \ + if (__region_fn.isActive()) \ + { \ + CV__TRACE_ARG_VALUE(arg_id, arg_name, value); \ + } + +#undef CV_TRACE_ARG +#define CV_TRACE_ARG CV__TRACE_ARG + +#endif // OPENCV_DISABLE_TRACE + +#ifdef OPENCV_TRACE_VERBOSE +#define CV_TRACE_FUNCTION_VERBOSE CV_TRACE_FUNCTION +#define CV_TRACE_REGION_VERBOSE CV_TRACE_REGION +#define CV_TRACE_REGION_NEXT_VERBOSE CV_TRACE_REGION_NEXT +#define CV_TRACE_ARG_VALUE_VERBOSE CV_TRACE_ARG_VALUE +#define CV_TRACE_ARG_VERBOSE CV_TRACE_ARG +#else +#define CV_TRACE_FUNCTION_VERBOSE(...) +#define CV_TRACE_REGION_VERBOSE(...) +#define CV_TRACE_REGION_NEXT_VERBOSE(...) +#define CV_TRACE_ARG_VALUE_VERBOSE(...) +#define CV_TRACE_ARG_VERBOSE(...) +#endif + +//! @endcond + +//! @} + +}}} // namespace + +#endif // OPENCV_TRACE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/va_intel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/va_intel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f66547093e0ad69533af4cceb02bc796448f8db9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/va_intel.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +// Copyright (C) 2015, Itseez, Inc., all rights reserved. +// Third party copyrights are property of their respective owners. + +#ifndef OPENCV_CORE_VA_INTEL_HPP +#define OPENCV_CORE_VA_INTEL_HPP + +#ifndef __cplusplus +# error va_intel.hpp header must be compiled as C++ +#endif + +#include "opencv2/core.hpp" +#include "ocl.hpp" + +#if defined(HAVE_VA) +# include "va/va.h" +#else // HAVE_VA +# if !defined(_VA_H_) + typedef void* VADisplay; + typedef unsigned int VASurfaceID; +# endif // !_VA_H_ +#endif // HAVE_VA + +namespace cv { namespace va_intel { + +/** @addtogroup core_va_intel +This section describes Intel VA-API/OpenCL (CL-VA) interoperability. + +To enable CL-VA interoperability support, configure OpenCV using CMake with WITH_VA_INTEL=ON . Currently VA-API is +supported on Linux only. You should also install Intel Media Server Studio (MSS) to use this feature. You may +have to specify the path(s) to MSS components for cmake in environment variables: + +- VA_INTEL_IOCL_ROOT for Intel OpenCL (default is "/opt/intel/opencl"). + +To use CL-VA interoperability you should first create VADisplay (libva), and then call initializeContextFromVA() +function to create OpenCL context and set up interoperability. +*/ +//! @{ + +/////////////////// CL-VA Interoperability Functions /////////////////// + +namespace ocl { +using namespace cv::ocl; + +// TODO static functions in the Context class +/** @brief Creates OpenCL context from VA. +@param display - VADisplay for which CL interop should be established. +@param tryInterop - try to set up for interoperability, if true; set up for use slow copy if false. +@return Returns reference to OpenCL Context + */ +CV_EXPORTS Context& initializeContextFromVA(VADisplay display, bool tryInterop = true); + +} // namespace cv::va_intel::ocl + +/** @brief Converts InputArray to VASurfaceID object. +@param display - VADisplay object. +@param src - source InputArray. +@param surface - destination VASurfaceID object. +@param size - size of image represented by VASurfaceID object. + */ +CV_EXPORTS void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface, Size size); + +/** @brief Converts VASurfaceID object to OutputArray. +@param display - VADisplay object. +@param surface - source VASurfaceID object. +@param size - size of image represented by VASurfaceID object. +@param dst - destination OutputArray. + */ +CV_EXPORTS void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, OutputArray dst); + +//! @} + +}} // namespace cv::va_intel + +#endif /* OPENCV_CORE_VA_INTEL_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/version.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/version.hpp new file mode 100644 index 0000000000000000000000000000000000000000..29855b17e94eed4cc863f7bb4b808cf60a53e254 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/version.hpp @@ -0,0 +1,26 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_VERSION_HPP +#define OPENCV_VERSION_HPP + +#define CV_VERSION_MAJOR 4 +#define CV_VERSION_MINOR 2 +#define CV_VERSION_REVISION 0 +#define CV_VERSION_STATUS "" + +#define CVAUX_STR_EXP(__A) #__A +#define CVAUX_STR(__A) CVAUX_STR_EXP(__A) + +#define CVAUX_STRW_EXP(__A) L ## #__A +#define CVAUX_STRW(__A) CVAUX_STRW_EXP(__A) + +#define CV_VERSION CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS + +/* old style version constants*/ +#define CV_MAJOR_VERSION CV_VERSION_MAJOR +#define CV_MINOR_VERSION CV_VERSION_MINOR +#define CV_SUBMINOR_VERSION CV_VERSION_REVISION + +#endif // OPENCV_VERSION_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/vsx_utils.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/vsx_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..91669bff31e1136463285e932dbd96251ead3a2c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core/vsx_utils.hpp @@ -0,0 +1,1042 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_HAL_VSX_UTILS_HPP +#define OPENCV_HAL_VSX_UTILS_HPP + +#include "opencv2/core/cvdef.h" + +#ifndef SKIP_INCLUDES +# include +#endif + +//! @addtogroup core_utils_vsx +//! @{ +#if CV_VSX + +#define __VSX_S16__(c, v) (c){v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v} +#define __VSX_S8__(c, v) (c){v, v, v, v, v, v, v, v} +#define __VSX_S4__(c, v) (c){v, v, v, v} +#define __VSX_S2__(c, v) (c){v, v} + +typedef __vector unsigned char vec_uchar16; +#define vec_uchar16_set(...) (vec_uchar16){__VA_ARGS__} +#define vec_uchar16_sp(c) (__VSX_S16__(vec_uchar16, (unsigned char)c)) +#define vec_uchar16_c(v) ((vec_uchar16)(v)) +#define vec_uchar16_z vec_uchar16_sp(0) + +typedef __vector signed char vec_char16; +#define vec_char16_set(...) (vec_char16){__VA_ARGS__} +#define vec_char16_sp(c) (__VSX_S16__(vec_char16, (signed char)c)) +#define vec_char16_c(v) ((vec_char16)(v)) +#define vec_char16_z vec_char16_sp(0) + +typedef __vector unsigned short vec_ushort8; +#define vec_ushort8_set(...) (vec_ushort8){__VA_ARGS__} +#define vec_ushort8_sp(c) (__VSX_S8__(vec_ushort8, (unsigned short)c)) +#define vec_ushort8_c(v) ((vec_ushort8)(v)) +#define vec_ushort8_z vec_ushort8_sp(0) + +typedef __vector signed short vec_short8; +#define vec_short8_set(...) (vec_short8){__VA_ARGS__} +#define vec_short8_sp(c) (__VSX_S8__(vec_short8, (signed short)c)) +#define vec_short8_c(v) ((vec_short8)(v)) +#define vec_short8_z vec_short8_sp(0) + +typedef __vector unsigned int vec_uint4; +#define vec_uint4_set(...) (vec_uint4){__VA_ARGS__} +#define vec_uint4_sp(c) (__VSX_S4__(vec_uint4, (unsigned int)c)) +#define vec_uint4_c(v) ((vec_uint4)(v)) +#define vec_uint4_z vec_uint4_sp(0) + +typedef __vector signed int vec_int4; +#define vec_int4_set(...) (vec_int4){__VA_ARGS__} +#define vec_int4_sp(c) (__VSX_S4__(vec_int4, (signed int)c)) +#define vec_int4_c(v) ((vec_int4)(v)) +#define vec_int4_z vec_int4_sp(0) + +typedef __vector float vec_float4; +#define vec_float4_set(...) (vec_float4){__VA_ARGS__} +#define vec_float4_sp(c) (__VSX_S4__(vec_float4, c)) +#define vec_float4_c(v) ((vec_float4)(v)) +#define vec_float4_z vec_float4_sp(0) + +typedef __vector unsigned long long vec_udword2; +#define vec_udword2_set(...) (vec_udword2){__VA_ARGS__} +#define vec_udword2_sp(c) (__VSX_S2__(vec_udword2, (unsigned long long)c)) +#define vec_udword2_c(v) ((vec_udword2)(v)) +#define vec_udword2_z vec_udword2_sp(0) + +typedef __vector signed long long vec_dword2; +#define vec_dword2_set(...) (vec_dword2){__VA_ARGS__} +#define vec_dword2_sp(c) (__VSX_S2__(vec_dword2, (signed long long)c)) +#define vec_dword2_c(v) ((vec_dword2)(v)) +#define vec_dword2_z vec_dword2_sp(0) + +typedef __vector double vec_double2; +#define vec_double2_set(...) (vec_double2){__VA_ARGS__} +#define vec_double2_c(v) ((vec_double2)(v)) +#define vec_double2_sp(c) (__VSX_S2__(vec_double2, c)) +#define vec_double2_z vec_double2_sp(0) + +#define vec_bchar16 __vector __bool char +#define vec_bchar16_set(...) (vec_bchar16){__VA_ARGS__} +#define vec_bchar16_c(v) ((vec_bchar16)(v)) + +#define vec_bshort8 __vector __bool short +#define vec_bshort8_set(...) (vec_bshort8){__VA_ARGS__} +#define vec_bshort8_c(v) ((vec_bshort8)(v)) + +#define vec_bint4 __vector __bool int +#define vec_bint4_set(...) (vec_bint4){__VA_ARGS__} +#define vec_bint4_c(v) ((vec_bint4)(v)) + +#define vec_bdword2 __vector __bool long long +#define vec_bdword2_set(...) (vec_bdword2){__VA_ARGS__} +#define vec_bdword2_c(v) ((vec_bdword2)(v)) + +#define VSX_FINLINE(tp) extern inline tp __attribute__((always_inline)) + +#define VSX_REDIRECT_1RG(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fn2(a); } + +#define VSX_REDIRECT_2RG(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a, const rg& b) { return fn2(a, b); } + +/* + * GCC VSX compatibility +**/ +#if defined(__GNUG__) && !defined(__clang__) + +// inline asm helper +#define VSX_IMPL_1RG(rt, rto, rg, rgo, opc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ rt rs; __asm__ __volatile__(#opc" %x0,%x1" : "="#rto (rs) : #rgo (a)); return rs; } + +#define VSX_IMPL_1VRG(rt, rg, opc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ rt rs; __asm__ __volatile__(#opc" %0,%1" : "=v" (rs) : "v" (a)); return rs; } + +#define VSX_IMPL_2VRG_F(rt, rg, fopc, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a, const rg& b) \ +{ rt rs; __asm__ __volatile__(fopc : "=v" (rs) : "v" (a), "v" (b)); return rs; } + +#define VSX_IMPL_2VRG(rt, rg, opc, fnm) VSX_IMPL_2VRG_F(rt, rg, #opc" %0,%1,%2", fnm) + +#if __GNUG__ < 8 + + // Support for int4 -> dword2 expanding multiply was added in GCC 8. + #ifdef vec_mule + #undef vec_mule + #endif + #ifdef vec_mulo + #undef vec_mulo + #endif + + VSX_REDIRECT_2RG(vec_ushort8, vec_uchar16, vec_mule, __builtin_vec_mule) + VSX_REDIRECT_2RG(vec_short8, vec_char16, vec_mule, __builtin_vec_mule) + VSX_REDIRECT_2RG(vec_int4, vec_short8, vec_mule, __builtin_vec_mule) + VSX_REDIRECT_2RG(vec_uint4, vec_ushort8, vec_mule, __builtin_vec_mule) + VSX_REDIRECT_2RG(vec_ushort8, vec_uchar16, vec_mulo, __builtin_vec_mulo) + VSX_REDIRECT_2RG(vec_short8, vec_char16, vec_mulo, __builtin_vec_mulo) + VSX_REDIRECT_2RG(vec_int4, vec_short8, vec_mulo, __builtin_vec_mulo) + VSX_REDIRECT_2RG(vec_uint4, vec_ushort8, vec_mulo, __builtin_vec_mulo) + + // dword2 support arrived in ISA 2.07 and GCC 8+ + VSX_IMPL_2VRG(vec_dword2, vec_int4, vmulosw, vec_mule) + VSX_IMPL_2VRG(vec_udword2, vec_uint4, vmulouw, vec_mule) + VSX_IMPL_2VRG(vec_dword2, vec_int4, vmulesw, vec_mulo) + VSX_IMPL_2VRG(vec_udword2, vec_uint4, vmuleuw, vec_mulo) + +#endif + +#if __GNUG__ < 7 +// up to GCC 6 vec_mul only supports precisions and llong +# ifdef vec_mul +# undef vec_mul +# endif +/* + * there's no a direct instruction for supporting 8-bit, 16-bit multiplication in ISA 2.07, + * XLC Implement it by using instruction "multiply even", "multiply odd" and "permute" +**/ +# define VSX_IMPL_MULH(Tvec, cperm) \ + VSX_FINLINE(Tvec) vec_mul(const Tvec& a, const Tvec& b) \ + { \ + static const vec_uchar16 ev_od = {cperm}; \ + return vec_perm((Tvec)vec_mule(a, b), (Tvec)vec_mulo(a, b), ev_od); \ + } + #define VSX_IMPL_MULH_P16 0, 16, 2, 18, 4, 20, 6, 22, 8, 24, 10, 26, 12, 28, 14, 30 + VSX_IMPL_MULH(vec_char16, VSX_IMPL_MULH_P16) + VSX_IMPL_MULH(vec_uchar16, VSX_IMPL_MULH_P16) + #define VSX_IMPL_MULH_P8 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29 + VSX_IMPL_MULH(vec_short8, VSX_IMPL_MULH_P8) + VSX_IMPL_MULH(vec_ushort8, VSX_IMPL_MULH_P8) + // vmuluwm can be used for unsigned or signed integers, that's what they said + VSX_IMPL_2VRG(vec_int4, vec_int4, vmuluwm, vec_mul) + VSX_IMPL_2VRG(vec_uint4, vec_uint4, vmuluwm, vec_mul) + // redirect to GCC builtin vec_mul, since it already supports precisions and llong + VSX_REDIRECT_2RG(vec_float4, vec_float4, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mul, __builtin_vec_mul) + VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mul, __builtin_vec_mul) +#endif // __GNUG__ < 7 + +#if __GNUG__ < 6 +/* + * Instruction "compare greater than or equal" in ISA 2.07 only supports single + * and double precision. + * In XLC and new versions of GCC implement integers by using instruction "greater than" and NOR. +**/ +# ifdef vec_cmpge +# undef vec_cmpge +# endif +# ifdef vec_cmple +# undef vec_cmple +# endif +# define vec_cmple(a, b) vec_cmpge(b, a) +# define VSX_IMPL_CMPGE(rt, rg, opc, fnm) \ + VSX_IMPL_2VRG_F(rt, rg, #opc" %0,%2,%1\n\t xxlnor %x0,%x0,%x0", fnm) + + VSX_IMPL_CMPGE(vec_bchar16, vec_char16, vcmpgtsb, vec_cmpge) + VSX_IMPL_CMPGE(vec_bchar16, vec_uchar16, vcmpgtub, vec_cmpge) + VSX_IMPL_CMPGE(vec_bshort8, vec_short8, vcmpgtsh, vec_cmpge) + VSX_IMPL_CMPGE(vec_bshort8, vec_ushort8, vcmpgtuh, vec_cmpge) + VSX_IMPL_CMPGE(vec_bint4, vec_int4, vcmpgtsw, vec_cmpge) + VSX_IMPL_CMPGE(vec_bint4, vec_uint4, vcmpgtuw, vec_cmpge) + VSX_IMPL_CMPGE(vec_bdword2, vec_dword2, vcmpgtsd, vec_cmpge) + VSX_IMPL_CMPGE(vec_bdword2, vec_udword2, vcmpgtud, vec_cmpge) + +// redirect to GCC builtin cmpge, since it already supports precisions + VSX_REDIRECT_2RG(vec_bint4, vec_float4, vec_cmpge, __builtin_vec_cmpge) + VSX_REDIRECT_2RG(vec_bdword2, vec_double2, vec_cmpge, __builtin_vec_cmpge) + +// up to gcc5 vec_nor doesn't support bool long long +# undef vec_nor + template + VSX_REDIRECT_2RG(T, T, vec_nor, __builtin_vec_nor) + + VSX_FINLINE(vec_bdword2) vec_nor(const vec_bdword2& a, const vec_bdword2& b) + { return vec_bdword2_c(__builtin_vec_nor(vec_dword2_c(a), vec_dword2_c(b))); } + +// vec_packs doesn't support double words in gcc4 and old versions of gcc5 +# undef vec_packs + VSX_REDIRECT_2RG(vec_char16, vec_short8, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_uchar16, vec_ushort8, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_short8, vec_int4, vec_packs, __builtin_vec_packs) + VSX_REDIRECT_2RG(vec_ushort8, vec_uint4, vec_packs, __builtin_vec_packs) + + VSX_IMPL_2VRG_F(vec_int4, vec_dword2, "vpksdss %0,%2,%1", vec_packs) + VSX_IMPL_2VRG_F(vec_uint4, vec_udword2, "vpkudus %0,%2,%1", vec_packs) +#endif // __GNUG__ < 6 + +#if __GNUG__ < 5 +// vec_xxpermdi in gcc4 missing little-endian supports just like clang +# define vec_permi(a, b, c) vec_xxpermdi(b, a, (3 ^ (((c) & 1) << 1 | (c) >> 1))) +#else +# define vec_permi vec_xxpermdi +#endif // __GNUG__ < 5 + +// shift left double by word immediate +#ifndef vec_sldw +# define vec_sldw __builtin_vsx_xxsldwi +#endif + +// vector population count +VSX_IMPL_1VRG(vec_uchar16, vec_uchar16, vpopcntb, vec_popcntu) +VSX_IMPL_1VRG(vec_uchar16, vec_char16, vpopcntb, vec_popcntu) +VSX_IMPL_1VRG(vec_ushort8, vec_ushort8, vpopcnth, vec_popcntu) +VSX_IMPL_1VRG(vec_ushort8, vec_short8, vpopcnth, vec_popcntu) +VSX_IMPL_1VRG(vec_uint4, vec_uint4, vpopcntw, vec_popcntu) +VSX_IMPL_1VRG(vec_uint4, vec_int4, vpopcntw, vec_popcntu) +VSX_IMPL_1VRG(vec_udword2, vec_udword2, vpopcntd, vec_popcntu) +VSX_IMPL_1VRG(vec_udword2, vec_dword2, vpopcntd, vec_popcntu) + +// converts between single and double-precision +VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, __builtin_vsx_xvcvdpsp) +VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, __builtin_vsx_xvcvspdp) + +// converts word and doubleword to double-precision +#ifdef vec_ctd +# undef vec_ctd +#endif +VSX_IMPL_1RG(vec_double2, wd, vec_int4, wa, xvcvsxwdp, vec_ctdo) +VSX_IMPL_1RG(vec_double2, wd, vec_uint4, wa, xvcvuxwdp, vec_ctdo) +VSX_IMPL_1RG(vec_double2, wd, vec_dword2, wi, xvcvsxddp, vec_ctd) +VSX_IMPL_1RG(vec_double2, wd, vec_udword2, wi, xvcvuxddp, vec_ctd) + +// converts word and doubleword to single-precision +#undef vec_ctf +VSX_IMPL_1RG(vec_float4, wf, vec_int4, wa, xvcvsxwsp, vec_ctf) +VSX_IMPL_1RG(vec_float4, wf, vec_uint4, wa, xvcvuxwsp, vec_ctf) +VSX_IMPL_1RG(vec_float4, wf, vec_dword2, wi, xvcvsxdsp, vec_ctfo) +VSX_IMPL_1RG(vec_float4, wf, vec_udword2, wi, xvcvuxdsp, vec_ctfo) + +// converts single and double precision to signed word +#undef vec_cts +VSX_IMPL_1RG(vec_int4, wa, vec_double2, wd, xvcvdpsxws, vec_ctso) +VSX_IMPL_1RG(vec_int4, wa, vec_float4, wf, xvcvspsxws, vec_cts) + +// converts single and double precision to unsigned word +#undef vec_ctu +VSX_IMPL_1RG(vec_uint4, wa, vec_double2, wd, xvcvdpuxws, vec_ctuo) +VSX_IMPL_1RG(vec_uint4, wa, vec_float4, wf, xvcvspuxws, vec_ctu) + +// converts single and double precision to signed doubleword +#ifdef vec_ctsl +# undef vec_ctsl +#endif +VSX_IMPL_1RG(vec_dword2, wi, vec_double2, wd, xvcvdpsxds, vec_ctsl) +VSX_IMPL_1RG(vec_dword2, wi, vec_float4, wf, xvcvspsxds, vec_ctslo) + +// converts single and double precision to unsigned doubleword +#ifdef vec_ctul +# undef vec_ctul +#endif +VSX_IMPL_1RG(vec_udword2, wi, vec_double2, wd, xvcvdpuxds, vec_ctul) +VSX_IMPL_1RG(vec_udword2, wi, vec_float4, wf, xvcvspuxds, vec_ctulo) + +// just in case if GCC doesn't define it +#ifndef vec_xl +# define vec_xl vec_vsx_ld +# define vec_xst vec_vsx_st +#endif + +#endif // GCC VSX compatibility + +/* + * CLANG VSX compatibility +**/ +#if defined(__clang__) && !defined(__IBMCPP__) + +/* + * CLANG doesn't support %x in the inline asm template which fixes register number + * when using any of the register constraints wa, wd, wf + * + * For more explanation checkout PowerPC and IBM RS6000 in https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html + * Also there's already an open bug https://bugs.llvm.org/show_bug.cgi?id=31837 + * + * So we're not able to use inline asm and only use built-in functions that CLANG supports + * and use __builtin_convertvector if clang missng any of vector conversions built-in functions + * + * todo: clang asm template bug is fixed, need to reconsider the current workarounds. +*/ + +// convert vector helper +#define VSX_IMPL_CONVERT(rt, rg, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) { return __builtin_convertvector(a, rt); } + +#if __clang_major__ < 5 +// implement vec_permi in a dirty way +# define VSX_IMPL_CLANG_4_PERMI(Tvec) \ + VSX_FINLINE(Tvec) vec_permi(const Tvec& a, const Tvec& b, unsigned const char c) \ + { \ + switch (c) \ + { \ + case 0: \ + return vec_mergeh(a, b); \ + case 1: \ + return vec_mergel(vec_mergeh(a, a), b); \ + case 2: \ + return vec_mergeh(vec_mergel(a, a), b); \ + default: \ + return vec_mergel(a, b); \ + } \ + } + VSX_IMPL_CLANG_4_PERMI(vec_udword2) + VSX_IMPL_CLANG_4_PERMI(vec_dword2) + VSX_IMPL_CLANG_4_PERMI(vec_double2) + +// vec_xxsldwi is missing in clang 4 +# define vec_xxsldwi(a, b, c) vec_sld(a, b, (c) * 4) +#else +// vec_xxpermdi is missing little-endian supports in clang 4 just like gcc4 +# define vec_permi(a, b, c) vec_xxpermdi(b, a, (3 ^ (((c) & 1) << 1 | (c) >> 1))) +#endif // __clang_major__ < 5 + +// shift left double by word immediate +#ifndef vec_sldw +# define vec_sldw vec_xxsldwi +#endif + +// Implement vec_rsqrt since clang only supports vec_rsqrte +#ifndef vec_rsqrt + VSX_FINLINE(vec_float4) vec_rsqrt(const vec_float4& a) + { return vec_div(vec_float4_sp(1), vec_sqrt(a)); } + + VSX_FINLINE(vec_double2) vec_rsqrt(const vec_double2& a) + { return vec_div(vec_double2_sp(1), vec_sqrt(a)); } +#endif + +// vec_promote missing support for doubleword +VSX_FINLINE(vec_dword2) vec_promote(long long a, int b) +{ + vec_dword2 ret = vec_dword2_z; + ret[b & 1] = a; + return ret; +} + +VSX_FINLINE(vec_udword2) vec_promote(unsigned long long a, int b) +{ + vec_udword2 ret = vec_udword2_z; + ret[b & 1] = a; + return ret; +} + +// vec_popcnt should return unsigned but clang has different thought just like gcc in vec_vpopcnt +#define VSX_IMPL_POPCNTU(Tvec, Tvec2, ucast) \ +VSX_FINLINE(Tvec) vec_popcntu(const Tvec2& a) \ +{ return ucast(vec_popcnt(a)); } +VSX_IMPL_POPCNTU(vec_uchar16, vec_char16, vec_uchar16_c); +VSX_IMPL_POPCNTU(vec_ushort8, vec_short8, vec_ushort8_c); +VSX_IMPL_POPCNTU(vec_uint4, vec_int4, vec_uint4_c); +VSX_IMPL_POPCNTU(vec_udword2, vec_dword2, vec_udword2_c); +// redirect unsigned types +VSX_REDIRECT_1RG(vec_uchar16, vec_uchar16, vec_popcntu, vec_popcnt) +VSX_REDIRECT_1RG(vec_ushort8, vec_ushort8, vec_popcntu, vec_popcnt) +VSX_REDIRECT_1RG(vec_uint4, vec_uint4, vec_popcntu, vec_popcnt) +VSX_REDIRECT_1RG(vec_udword2, vec_udword2, vec_popcntu, vec_popcnt) + +// converts between single and double precision +VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, __builtin_vsx_xvcvdpsp) +VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, __builtin_vsx_xvcvspdp) + +// converts word and doubleword to double-precision +#ifdef vec_ctd +# undef vec_ctd +#endif +VSX_REDIRECT_1RG(vec_double2, vec_int4, vec_ctdo, __builtin_vsx_xvcvsxwdp) +VSX_REDIRECT_1RG(vec_double2, vec_uint4, vec_ctdo, __builtin_vsx_xvcvuxwdp) + +VSX_IMPL_CONVERT(vec_double2, vec_dword2, vec_ctd) +VSX_IMPL_CONVERT(vec_double2, vec_udword2, vec_ctd) + +// converts word and doubleword to single-precision +#if __clang_major__ > 4 +# undef vec_ctf +#endif +VSX_IMPL_CONVERT(vec_float4, vec_int4, vec_ctf) +VSX_IMPL_CONVERT(vec_float4, vec_uint4, vec_ctf) +VSX_REDIRECT_1RG(vec_float4, vec_dword2, vec_ctfo, __builtin_vsx_xvcvsxdsp) +VSX_REDIRECT_1RG(vec_float4, vec_udword2, vec_ctfo, __builtin_vsx_xvcvuxdsp) + +// converts single and double precision to signed word +#if __clang_major__ > 4 +# undef vec_cts +#endif +VSX_REDIRECT_1RG(vec_int4, vec_double2, vec_ctso, __builtin_vsx_xvcvdpsxws) +VSX_IMPL_CONVERT(vec_int4, vec_float4, vec_cts) + +// converts single and double precision to unsigned word +#if __clang_major__ > 4 +# undef vec_ctu +#endif +VSX_REDIRECT_1RG(vec_uint4, vec_double2, vec_ctuo, __builtin_vsx_xvcvdpuxws) +VSX_IMPL_CONVERT(vec_uint4, vec_float4, vec_ctu) + +// converts single and double precision to signed doubleword +#ifdef vec_ctsl +# undef vec_ctsl +#endif +VSX_IMPL_CONVERT(vec_dword2, vec_double2, vec_ctsl) +// __builtin_convertvector unable to convert, xvcvspsxds is missing on it +VSX_FINLINE(vec_dword2) vec_ctslo(const vec_float4& a) +{ return vec_ctsl(vec_cvfo(a)); } + +// converts single and double precision to unsigned doubleword +#ifdef vec_ctul +# undef vec_ctul +#endif +VSX_IMPL_CONVERT(vec_udword2, vec_double2, vec_ctul) +// __builtin_convertvector unable to convert, xvcvspuxds is missing on it +VSX_FINLINE(vec_udword2) vec_ctulo(const vec_float4& a) +{ return vec_ctul(vec_cvfo(a)); } + +#endif // CLANG VSX compatibility + +/* + * Common GCC, CLANG compatibility +**/ +#if defined(__GNUG__) && !defined(__IBMCPP__) + +#ifdef vec_cvf +# undef vec_cvf +#endif + +#define VSX_IMPL_CONV_EVEN_4_2(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ return fn2(vec_sldw(a, a, 1)); } + +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_float4, vec_cvf, vec_cvfo) +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_int4, vec_ctd, vec_ctdo) +VSX_IMPL_CONV_EVEN_4_2(vec_double2, vec_uint4, vec_ctd, vec_ctdo) + +VSX_IMPL_CONV_EVEN_4_2(vec_dword2, vec_float4, vec_ctsl, vec_ctslo) +VSX_IMPL_CONV_EVEN_4_2(vec_udword2, vec_float4, vec_ctul, vec_ctulo) + +#define VSX_IMPL_CONV_EVEN_2_4(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ \ + rt v4 = fn2(a); \ + return vec_sldw(v4, v4, 3); \ +} + +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_double2, vec_cvf, vec_cvfo) +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_dword2, vec_ctf, vec_ctfo) +VSX_IMPL_CONV_EVEN_2_4(vec_float4, vec_udword2, vec_ctf, vec_ctfo) + +VSX_IMPL_CONV_EVEN_2_4(vec_int4, vec_double2, vec_cts, vec_ctso) +VSX_IMPL_CONV_EVEN_2_4(vec_uint4, vec_double2, vec_ctu, vec_ctuo) + +// Only for Eigen! +/* + * changing behavior of conversion intrinsics for gcc has effect on Eigen + * so we redfine old behavior again only on gcc, clang +*/ +#if !defined(__clang__) || __clang_major__ > 4 + // ignoring second arg since Eigen only truncates toward zero +# define VSX_IMPL_CONV_2VARIANT(rt, rg, fnm, fn2) \ + VSX_FINLINE(rt) fnm(const rg& a, int only_truncate) \ + { \ + assert(only_truncate == 0); \ + CV_UNUSED(only_truncate); \ + return fn2(a); \ + } + VSX_IMPL_CONV_2VARIANT(vec_int4, vec_float4, vec_cts, vec_cts) + VSX_IMPL_CONV_2VARIANT(vec_float4, vec_int4, vec_ctf, vec_ctf) + // define vec_cts for converting double precision to signed doubleword + // which isn't combitable with xlc but its okay since Eigen only use it for gcc + VSX_IMPL_CONV_2VARIANT(vec_dword2, vec_double2, vec_cts, vec_ctsl) +#endif // Eigen + +#endif // Common GCC, CLANG compatibility + +/* + * XLC VSX compatibility +**/ +#if defined(__IBMCPP__) + +// vector population count +#define vec_popcntu vec_popcnt + +// overload and redirect with setting second arg to zero +// since we only support conversions without the second arg +#define VSX_IMPL_OVERLOAD_Z2(rt, rg, fnm) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fnm(a, 0); } + +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_int4, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_uint4, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_dword2, vec_ctd) +VSX_IMPL_OVERLOAD_Z2(vec_double2, vec_udword2, vec_ctd) + +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_int4, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_uint4, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_dword2, vec_ctf) +VSX_IMPL_OVERLOAD_Z2(vec_float4, vec_udword2, vec_ctf) + +VSX_IMPL_OVERLOAD_Z2(vec_int4, vec_double2, vec_cts) +VSX_IMPL_OVERLOAD_Z2(vec_int4, vec_float4, vec_cts) + +VSX_IMPL_OVERLOAD_Z2(vec_uint4, vec_double2, vec_ctu) +VSX_IMPL_OVERLOAD_Z2(vec_uint4, vec_float4, vec_ctu) + +VSX_IMPL_OVERLOAD_Z2(vec_dword2, vec_double2, vec_ctsl) +VSX_IMPL_OVERLOAD_Z2(vec_dword2, vec_float4, vec_ctsl) + +VSX_IMPL_OVERLOAD_Z2(vec_udword2, vec_double2, vec_ctul) +VSX_IMPL_OVERLOAD_Z2(vec_udword2, vec_float4, vec_ctul) + +// fixme: implement conversions of odd-numbered elements in a dirty way +// since xlc doesn't support VSX registers operand in inline asm. +#define VSX_IMPL_CONV_ODD_4_2(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) { return fn2(vec_sldw(a, a, 3)); } + +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_float4, vec_cvfo, vec_cvf) +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_int4, vec_ctdo, vec_ctd) +VSX_IMPL_CONV_ODD_4_2(vec_double2, vec_uint4, vec_ctdo, vec_ctd) + +VSX_IMPL_CONV_ODD_4_2(vec_dword2, vec_float4, vec_ctslo, vec_ctsl) +VSX_IMPL_CONV_ODD_4_2(vec_udword2, vec_float4, vec_ctulo, vec_ctul) + +#define VSX_IMPL_CONV_ODD_2_4(rt, rg, fnm, fn2) \ +VSX_FINLINE(rt) fnm(const rg& a) \ +{ \ + rt v4 = fn2(a); \ + return vec_sldw(v4, v4, 1); \ +} + +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_double2, vec_cvfo, vec_cvf) +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_dword2, vec_ctfo, vec_ctf) +VSX_IMPL_CONV_ODD_2_4(vec_float4, vec_udword2, vec_ctfo, vec_ctf) + +VSX_IMPL_CONV_ODD_2_4(vec_int4, vec_double2, vec_ctso, vec_cts) +VSX_IMPL_CONV_ODD_2_4(vec_uint4, vec_double2, vec_ctuo, vec_ctu) + +#endif // XLC VSX compatibility + +// ignore GCC warning that caused by -Wunused-but-set-variable in rare cases +#if defined(__GNUG__) && !defined(__clang__) +# define VSX_UNUSED(Tvec) Tvec __attribute__((__unused__)) +#else // CLANG, XLC +# define VSX_UNUSED(Tvec) Tvec +#endif + +// gcc can find his way in casting log int and XLC, CLANG ambiguous +#if defined(__clang__) || defined(__IBMCPP__) + VSX_FINLINE(vec_udword2) vec_splats(uint64 v) + { return vec_splats((unsigned long long) v); } + + VSX_FINLINE(vec_dword2) vec_splats(int64 v) + { return vec_splats((long long) v); } + + VSX_FINLINE(vec_udword2) vec_promote(uint64 a, int b) + { return vec_promote((unsigned long long) a, b); } + + VSX_FINLINE(vec_dword2) vec_promote(int64 a, int b) + { return vec_promote((long long) a, b); } +#endif + +/* + * implement vsx_ld(offset, pointer), vsx_st(vector, offset, pointer) + * load and set using offset depend on the pointer type + * + * implement vsx_ldf(offset, pointer), vsx_stf(vector, offset, pointer) + * load and set using offset depend on fixed bytes size + * + * Note: In clang vec_xl and vec_xst fails to load unaligned addresses + * so we are using vec_vsx_ld, vec_vsx_st instead +*/ + +#if defined(__clang__) && !defined(__IBMCPP__) +# define vsx_ldf vec_vsx_ld +# define vsx_stf vec_vsx_st +#else // GCC , XLC +# define vsx_ldf vec_xl +# define vsx_stf vec_xst +#endif + +#define VSX_OFFSET(o, p) ((o) * sizeof(*(p))) +#define vsx_ld(o, p) vsx_ldf(VSX_OFFSET(o, p), p) +#define vsx_st(v, o, p) vsx_stf(v, VSX_OFFSET(o, p), p) + +/* + * implement vsx_ld2(offset, pointer), vsx_st2(vector, offset, pointer) to load and store double words + * In GCC vec_xl and vec_xst it maps to vec_vsx_ld, vec_vsx_st which doesn't support long long + * and in CLANG we are using vec_vsx_ld, vec_vsx_st because vec_xl, vec_xst fails to load unaligned addresses + * + * In XLC vec_xl and vec_xst fail to cast int64(long int) to long long +*/ +#if (defined(__GNUG__) || defined(__clang__)) && !defined(__IBMCPP__) + VSX_FINLINE(vec_udword2) vsx_ld2(long o, const uint64* p) + { return vec_udword2_c(vsx_ldf(VSX_OFFSET(o, p), (unsigned int*)p)); } + + VSX_FINLINE(vec_dword2) vsx_ld2(long o, const int64* p) + { return vec_dword2_c(vsx_ldf(VSX_OFFSET(o, p), (int*)p)); } + + VSX_FINLINE(void) vsx_st2(const vec_udword2& vec, long o, uint64* p) + { vsx_stf(vec_uint4_c(vec), VSX_OFFSET(o, p), (unsigned int*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_dword2& vec, long o, int64* p) + { vsx_stf(vec_int4_c(vec), VSX_OFFSET(o, p), (int*)p); } +#else // XLC + VSX_FINLINE(vec_udword2) vsx_ld2(long o, const uint64* p) + { return vsx_ldf(VSX_OFFSET(o, p), (unsigned long long*)p); } + + VSX_FINLINE(vec_dword2) vsx_ld2(long o, const int64* p) + { return vsx_ldf(VSX_OFFSET(o, p), (long long*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_udword2& vec, long o, uint64* p) + { vsx_stf(vec, VSX_OFFSET(o, p), (unsigned long long*)p); } + + VSX_FINLINE(void) vsx_st2(const vec_dword2& vec, long o, int64* p) + { vsx_stf(vec, VSX_OFFSET(o, p), (long long*)p); } +#endif + +// Store lower 8 byte +#define vec_st_l8(v, p) *((uint64*)(p)) = vec_extract(vec_udword2_c(v), 0) + +// Store higher 8 byte +#define vec_st_h8(v, p) *((uint64*)(p)) = vec_extract(vec_udword2_c(v), 1) + +// Load 64-bits of integer data to lower part +#define VSX_IMPL_LOAD_L8(Tvec, Tp) \ +VSX_FINLINE(Tvec) vec_ld_l8(const Tp *p) \ +{ return ((Tvec)vec_promote(*((uint64*)p), 0)); } + +VSX_IMPL_LOAD_L8(vec_uchar16, uchar) +VSX_IMPL_LOAD_L8(vec_char16, schar) +VSX_IMPL_LOAD_L8(vec_ushort8, ushort) +VSX_IMPL_LOAD_L8(vec_short8, short) +VSX_IMPL_LOAD_L8(vec_uint4, uint) +VSX_IMPL_LOAD_L8(vec_int4, int) +VSX_IMPL_LOAD_L8(vec_float4, float) +VSX_IMPL_LOAD_L8(vec_udword2, uint64) +VSX_IMPL_LOAD_L8(vec_dword2, int64) +VSX_IMPL_LOAD_L8(vec_double2, double) + +// logical not +#define vec_not(a) vec_nor(a, a) + +// power9 yaya +// not equal +#ifndef vec_cmpne +# define vec_cmpne(a, b) vec_not(vec_cmpeq(a, b)) +#endif + +// absolute difference +#ifndef vec_absd +# define vec_absd(a, b) vec_sub(vec_max(a, b), vec_min(a, b)) +#endif + +/* + * Implement vec_unpacklu and vec_unpackhu + * since vec_unpackl, vec_unpackh only support signed integers +**/ +#define VSX_IMPL_UNPACKU(rt, rg, zero) \ +VSX_FINLINE(rt) vec_unpacklu(const rg& a) \ +{ return (rt)(vec_mergel(a, zero)); } \ +VSX_FINLINE(rt) vec_unpackhu(const rg& a) \ +{ return (rt)(vec_mergeh(a, zero)); } + +VSX_IMPL_UNPACKU(vec_ushort8, vec_uchar16, vec_uchar16_z) +VSX_IMPL_UNPACKU(vec_uint4, vec_ushort8, vec_ushort8_z) +VSX_IMPL_UNPACKU(vec_udword2, vec_uint4, vec_uint4_z) + +/* + * Implement vec_mergesqe and vec_mergesqo + * Merges the sequence values of even and odd elements of two vectors +*/ +#define VSX_IMPL_PERM(rt, fnm, ...) \ +VSX_FINLINE(rt) fnm(const rt& a, const rt& b) \ +{ static const vec_uchar16 perm = {__VA_ARGS__}; return vec_perm(a, b, perm); } + +// 16 +#define perm16_mergesqe 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 +#define perm16_mergesqo 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 +VSX_IMPL_PERM(vec_uchar16, vec_mergesqe, perm16_mergesqe) +VSX_IMPL_PERM(vec_uchar16, vec_mergesqo, perm16_mergesqo) +VSX_IMPL_PERM(vec_char16, vec_mergesqe, perm16_mergesqe) +VSX_IMPL_PERM(vec_char16, vec_mergesqo, perm16_mergesqo) +// 8 +#define perm8_mergesqe 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 +#define perm8_mergesqo 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31 +VSX_IMPL_PERM(vec_ushort8, vec_mergesqe, perm8_mergesqe) +VSX_IMPL_PERM(vec_ushort8, vec_mergesqo, perm8_mergesqo) +VSX_IMPL_PERM(vec_short8, vec_mergesqe, perm8_mergesqe) +VSX_IMPL_PERM(vec_short8, vec_mergesqo, perm8_mergesqo) +// 4 +#define perm4_mergesqe 0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27 +#define perm4_mergesqo 4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31 +VSX_IMPL_PERM(vec_uint4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_uint4, vec_mergesqo, perm4_mergesqo) +VSX_IMPL_PERM(vec_int4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_int4, vec_mergesqo, perm4_mergesqo) +VSX_IMPL_PERM(vec_float4, vec_mergesqe, perm4_mergesqe) +VSX_IMPL_PERM(vec_float4, vec_mergesqo, perm4_mergesqo) +// 2 +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqo, vec_mergel) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqo, vec_mergel) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqe, vec_mergeh) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqo, vec_mergel) + +/* + * Implement vec_mergesqh and vec_mergesql + * Merges the sequence most and least significant halves of two vectors +*/ +#define VSX_IMPL_MERGESQHL(Tvec) \ +VSX_FINLINE(Tvec) vec_mergesqh(const Tvec& a, const Tvec& b) \ +{ return (Tvec)vec_mergeh(vec_udword2_c(a), vec_udword2_c(b)); } \ +VSX_FINLINE(Tvec) vec_mergesql(const Tvec& a, const Tvec& b) \ +{ return (Tvec)vec_mergel(vec_udword2_c(a), vec_udword2_c(b)); } +VSX_IMPL_MERGESQHL(vec_uchar16) +VSX_IMPL_MERGESQHL(vec_char16) +VSX_IMPL_MERGESQHL(vec_ushort8) +VSX_IMPL_MERGESQHL(vec_short8) +VSX_IMPL_MERGESQHL(vec_uint4) +VSX_IMPL_MERGESQHL(vec_int4) +VSX_IMPL_MERGESQHL(vec_float4) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_udword2, vec_udword2, vec_mergesql, vec_mergel) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_dword2, vec_dword2, vec_mergesql, vec_mergel) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesqh, vec_mergeh) +VSX_REDIRECT_2RG(vec_double2, vec_double2, vec_mergesql, vec_mergel) + + +// 2 and 4 channels interleave for all types except 2 lanes +#define VSX_IMPL_ST_INTERLEAVE(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, Tp* ptr) \ +{ \ + vsx_stf(vec_mergeh(a, b), 0, ptr); \ + vsx_stf(vec_mergel(a, b), 16, ptr); \ +} \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, const Tvec& d, Tp* ptr) \ +{ \ + Tvec ac = vec_mergeh(a, c); \ + Tvec bd = vec_mergeh(b, d); \ + vsx_stf(vec_mergeh(ac, bd), 0, ptr); \ + vsx_stf(vec_mergel(ac, bd), 16, ptr); \ + ac = vec_mergel(a, c); \ + bd = vec_mergel(b, d); \ + vsx_stf(vec_mergeh(ac, bd), 32, ptr); \ + vsx_stf(vec_mergel(ac, bd), 48, ptr); \ +} +VSX_IMPL_ST_INTERLEAVE(uchar, vec_uchar16) +VSX_IMPL_ST_INTERLEAVE(schar, vec_char16) +VSX_IMPL_ST_INTERLEAVE(ushort, vec_ushort8) +VSX_IMPL_ST_INTERLEAVE(short, vec_short8) +VSX_IMPL_ST_INTERLEAVE(uint, vec_uint4) +VSX_IMPL_ST_INTERLEAVE(int, vec_int4) +VSX_IMPL_ST_INTERLEAVE(float, vec_float4) + +// 2 and 4 channels deinterleave for 16 lanes +#define VSX_IMPL_ST_DINTERLEAVE_8(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(16, ptr); \ + a = vec_mergesqe(v0, v1); \ + b = vec_mergesqo(v0, v1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(16, ptr); \ + Tvec v2 = vsx_ld(32, ptr); \ + Tvec v3 = vsx_ld(48, ptr); \ + Tvec m0 = vec_mergesqe(v0, v1); \ + Tvec m1 = vec_mergesqe(v2, v3); \ + a = vec_mergesqe(m0, m1); \ + c = vec_mergesqo(m0, m1); \ + m0 = vec_mergesqo(v0, v1); \ + m1 = vec_mergesqo(v2, v3); \ + b = vec_mergesqe(m0, m1); \ + d = vec_mergesqo(m0, m1); \ +} +VSX_IMPL_ST_DINTERLEAVE_8(uchar, vec_uchar16) +VSX_IMPL_ST_DINTERLEAVE_8(schar, vec_char16) + +// 2 and 4 channels deinterleave for 8 lanes +#define VSX_IMPL_ST_DINTERLEAVE_16(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(8, ptr); \ + a = vec_mergesqe(v0, v1); \ + b = vec_mergesqo(v0, v1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(8, ptr); \ + Tvec m0 = vec_mergeh(v0, v1); \ + Tvec m1 = vec_mergel(v0, v1); \ + Tvec ab0 = vec_mergeh(m0, m1); \ + Tvec cd0 = vec_mergel(m0, m1); \ + v0 = vsx_ld(16, ptr); \ + v1 = vsx_ld(24, ptr); \ + m0 = vec_mergeh(v0, v1); \ + m1 = vec_mergel(v0, v1); \ + Tvec ab1 = vec_mergeh(m0, m1); \ + Tvec cd1 = vec_mergel(m0, m1); \ + a = vec_mergesqh(ab0, ab1); \ + b = vec_mergesql(ab0, ab1); \ + c = vec_mergesqh(cd0, cd1); \ + d = vec_mergesql(cd0, cd1); \ +} +VSX_IMPL_ST_DINTERLEAVE_16(ushort, vec_ushort8) +VSX_IMPL_ST_DINTERLEAVE_16(short, vec_short8) + +// 2 and 4 channels deinterleave for 4 lanes +#define VSX_IMPL_ST_DINTERLEAVE_32(Tp, Tvec) \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + a = vsx_ld(0, ptr); \ + b = vsx_ld(4, ptr); \ + Tvec m0 = vec_mergeh(a, b); \ + Tvec m1 = vec_mergel(a, b); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = vsx_ld(0, ptr); \ + Tvec v1 = vsx_ld(4, ptr); \ + Tvec v2 = vsx_ld(8, ptr); \ + Tvec v3 = vsx_ld(12, ptr); \ + Tvec m0 = vec_mergeh(v0, v2); \ + Tvec m1 = vec_mergeh(v1, v3); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ + m0 = vec_mergel(v0, v2); \ + m1 = vec_mergel(v1, v3); \ + c = vec_mergeh(m0, m1); \ + d = vec_mergel(m0, m1); \ +} +VSX_IMPL_ST_DINTERLEAVE_32(uint, vec_uint4) +VSX_IMPL_ST_DINTERLEAVE_32(int, vec_int4) +VSX_IMPL_ST_DINTERLEAVE_32(float, vec_float4) + +// 2 and 4 channels interleave and deinterleave for 2 lanes +#define VSX_IMPL_ST_D_INTERLEAVE_64(Tp, Tvec, ld_func, st_func) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_mergel(a, b), 2, ptr); \ +} \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, const Tvec& d, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_mergeh(c, d), 2, ptr); \ + st_func(vec_mergel(a, b), 4, ptr); \ + st_func(vec_mergel(c, d), 6, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b) \ +{ \ + Tvec m0 = ld_func(0, ptr); \ + Tvec m1 = ld_func(2, ptr); \ + a = vec_mergeh(m0, m1); \ + b = vec_mergel(m0, m1); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, \ + Tvec& c, Tvec& d) \ +{ \ + Tvec v0 = ld_func(0, ptr); \ + Tvec v1 = ld_func(2, ptr); \ + Tvec v2 = ld_func(4, ptr); \ + Tvec v3 = ld_func(6, ptr); \ + a = vec_mergeh(v0, v2); \ + b = vec_mergel(v0, v2); \ + c = vec_mergeh(v1, v3); \ + d = vec_mergel(v1, v3); \ +} +VSX_IMPL_ST_D_INTERLEAVE_64(int64, vec_dword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_D_INTERLEAVE_64(uint64, vec_udword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_D_INTERLEAVE_64(double, vec_double2, vsx_ld, vsx_st) + +/* 3 channels */ +#define VSX_IMPL_ST_INTERLEAVE_3CH_16(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + static const vec_uchar16 a12 = {0, 16, 0, 1, 17, 0, 2, 18, 0, 3, 19, 0, 4, 20, 0, 5}; \ + static const vec_uchar16 a123 = {0, 1, 16, 3, 4, 17, 6, 7, 18, 9, 10, 19, 12, 13, 20, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, a12), c, a123), 0, ptr); \ + static const vec_uchar16 b12 = {21, 0, 6, 22, 0, 7, 23, 0, 8, 24, 0, 9, 25, 0, 10, 26}; \ + static const vec_uchar16 b123 = {0, 21, 2, 3, 22, 5, 6, 23, 8, 9, 24, 11, 12, 25, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, b12), c, b123), 16, ptr); \ + static const vec_uchar16 c12 = {0, 11, 27, 0, 12, 28, 0, 13, 29, 0, 14, 30, 0, 15, 31, 0}; \ + static const vec_uchar16 c123 = {26, 1, 2, 27, 4, 5, 28, 7, 8, 29, 10, 11, 30, 13, 14, 31}; \ + vsx_st(vec_perm(vec_perm(a, b, c12), c, c123), 32, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(16, ptr); \ + Tvec v3 = vsx_ld(32, ptr); \ + static const vec_uchar16 a12_perm = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 a123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 17, 20, 23, 26, 29}; \ + a = vec_perm(vec_perm(v1, v2, a12_perm), v3, a123_perm); \ + static const vec_uchar16 b12_perm = {1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 b123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 18, 21, 24, 27, 30}; \ + b = vec_perm(vec_perm(v1, v2, b12_perm), v3, b123_perm); \ + static const vec_uchar16 c12_perm = {2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 c123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 19, 22, 25, 28, 31}; \ + c = vec_perm(vec_perm(v1, v2, c12_perm), v3, c123_perm); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_16(uchar, vec_uchar16) +VSX_IMPL_ST_INTERLEAVE_3CH_16(schar, vec_char16) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_8(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + static const vec_uchar16 a12 = {0, 1, 16, 17, 0, 0, 2, 3, 18, 19, 0, 0, 4, 5, 20, 21}; \ + static const vec_uchar16 a123 = {0, 1, 2, 3, 16, 17, 6, 7, 8, 9, 18, 19, 12, 13, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, a12), c, a123), 0, ptr); \ + static const vec_uchar16 b12 = {0, 0, 6, 7, 22, 23, 0, 0, 8, 9, 24, 25, 0, 0, 10, 11}; \ + static const vec_uchar16 b123 = {20, 21, 2, 3, 4, 5, 22, 23, 8, 9, 10, 11, 24, 25, 14, 15}; \ + vsx_st(vec_perm(vec_perm(a, b, b12), c, b123), 8, ptr); \ + static const vec_uchar16 c12 = {26, 27, 0, 0, 12, 13, 28, 29, 0, 0, 14, 15, 30, 31, 0, 0}; \ + static const vec_uchar16 c123 = {0, 1, 26, 27, 4, 5, 6, 7, 28, 29, 10, 11, 12, 13, 30, 31}; \ + vsx_st(vec_perm(vec_perm(a, b, c12), c, c123), 16, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(8, ptr); \ + Tvec v3 = vsx_ld(16, ptr); \ + static const vec_uchar16 a12_perm = {0, 1, 6, 7, 12, 13, 18, 19, 24, 25, 30, 31, 0, 0, 0, 0}; \ + static const vec_uchar16 a123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21, 26, 27}; \ + a = vec_perm(vec_perm(v1, v2, a12_perm), v3, a123_perm); \ + static const vec_uchar16 b12_perm = {2, 3, 8, 9, 14, 15, 20, 21, 26, 27, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 b123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 22, 23, 28, 29}; \ + b = vec_perm(vec_perm(v1, v2, b12_perm), v3, b123_perm); \ + static const vec_uchar16 c12_perm = {4, 5, 10, 11, 16, 17, 22, 23, 28, 29, 0, 0, 0, 0, 0, 0}; \ + static const vec_uchar16 c123_perm = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 18, 19, 24, 25, 30, 31}; \ + c = vec_perm(vec_perm(v1, v2, c12_perm), v3, c123_perm); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_8(ushort, vec_ushort8) +VSX_IMPL_ST_INTERLEAVE_3CH_8(short, vec_short8) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_4(Tp, Tvec) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + Tvec hbc = vec_mergeh(b, c); \ + static const vec_uchar16 ahbc = {0, 1, 2, 3, 16, 17, 18, 19, 20, 21, 22, 23, 4, 5, 6, 7}; \ + vsx_st(vec_perm(a, hbc, ahbc), 0, ptr); \ + Tvec lab = vec_mergel(a, b); \ + vsx_st(vec_sld(lab, hbc, 8), 4, ptr); \ + static const vec_uchar16 clab = {8, 9, 10, 11, 24, 25, 26, 27, 28, 29, 30, 31, 12, 13, 14, 15};\ + vsx_st(vec_perm(c, lab, clab), 8, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = vsx_ld(0, ptr); \ + Tvec v2 = vsx_ld(4, ptr); \ + Tvec v3 = vsx_ld(8, ptr); \ + static const vec_uchar16 flp = {0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19, 28, 29, 30, 31}; \ + a = vec_perm(v1, vec_sld(v3, v2, 8), flp); \ + static const vec_uchar16 flp2 = {28, 29, 30, 31, 0, 1, 2, 3, 12, 13, 14, 15, 16, 17, 18, 19}; \ + b = vec_perm(v2, vec_sld(v1, v3, 8), flp2); \ + c = vec_perm(vec_sld(v2, v1, 8), v3, flp); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_4(uint, vec_uint4) +VSX_IMPL_ST_INTERLEAVE_3CH_4(int, vec_int4) +VSX_IMPL_ST_INTERLEAVE_3CH_4(float, vec_float4) + +#define VSX_IMPL_ST_INTERLEAVE_3CH_2(Tp, Tvec, ld_func, st_func) \ +VSX_FINLINE(void) vec_st_interleave(const Tvec& a, const Tvec& b, \ + const Tvec& c, Tp* ptr) \ +{ \ + st_func(vec_mergeh(a, b), 0, ptr); \ + st_func(vec_permi(c, a, 1), 2, ptr); \ + st_func(vec_mergel(b, c), 4, ptr); \ +} \ +VSX_FINLINE(void) vec_ld_deinterleave(const Tp* ptr, Tvec& a, \ + Tvec& b, Tvec& c) \ +{ \ + Tvec v1 = ld_func(0, ptr); \ + Tvec v2 = ld_func(2, ptr); \ + Tvec v3 = ld_func(4, ptr); \ + a = vec_permi(v1, v2, 1); \ + b = vec_permi(v1, v3, 2); \ + c = vec_permi(v2, v3, 1); \ +} +VSX_IMPL_ST_INTERLEAVE_3CH_2(int64, vec_dword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_INTERLEAVE_3CH_2(uint64, vec_udword2, vsx_ld2, vsx_st2) +VSX_IMPL_ST_INTERLEAVE_3CH_2(double, vec_double2, vsx_ld, vsx_st) + +#endif // CV_VSX + +//! @} + +#endif // OPENCV_HAL_VSX_UTILS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core_detect.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core_detect.hpp new file mode 100644 index 0000000000000000000000000000000000000000..46a5017ea910b668107c876d2dfe06e3a535d0f1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/core_detect.hpp @@ -0,0 +1,149 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#ifndef _OPENCV_DNN_OBJDETECT_CORE_DETECT_HPP_ +#define _OPENCV_DNN_OBJDETECT_CORE_DETECT_HPP_ + +#include +#include + +#include +#include + +/** @defgroup dnn_objdetect DNN used for object detection +*/ + +namespace cv +{ +namespace dnn_objdetect +{ + + //! @addtogroup dnn_objdetect + //! @{ + + /** @brief Structure to hold the details pertaining to a single bounding box + */ + typedef struct + { + int xmin, xmax; + int ymin, ymax; + size_t class_idx; + std::string label_name; + double class_prob; + } object; + + + /** @brief A class to post process model predictions + */ + class CV_EXPORTS InferBbox + { + public: + /** @brief Default constructer + @param _delta_bbox Blob containing relative coordinates of bounding boxes + @param _class_scores Blob containing the probability values of each class + @param _conf_scores Blob containing the confidence scores + */ + InferBbox(Mat _delta_bbox, Mat _class_scores, Mat _conf_scores); + + /** @brief Filters the bounding boxes. + */ + void filter(double thresh = 0.8); + + /** @brief Vector which holds the final detections of the model + */ + std::vector detections; + + protected: + /** @brief Transform relative coordinates from ConvDet to bounding box coordinates + @param bboxes Vector to hold the predicted bounding boxes + */ + void transform_bboxes(std::vector > *bboxes); + + /** @brief Computes final probability values of each bounding box + @param final_probs Vector to hold the probability values + */ + void final_probability_dist(std::vector > *final_probs); + + /** @brief Transform bounding boxes from [x, y, h, w] to [xmin, ymin, xmax, ymax] + @param pre Vector conatining initial co-ordinates + @param post Vector containing the transformed co-ordinates + */ + void transform_bboxes_inv(std::vector > *pre, + std::vector > *post); + + /** @brief Ensures that the bounding box values are within image boundaries + @param min_max_boxes Vector containing bounding boxes of the form [xmin, ymin, xmax, ymax] + */ + void assert_predictions(std::vector > *min_max_boxes); + + /** @brief Filter top `n` predictions + @param probs Final probability values of bounding boxes + @param boxes Predicted bounding box co-ordinates + @param top_n_boxes Contains bounding box co-ordinates of top `n` boxes + @param top_n_idxs Containes class indices of top `n` bounding boxes + @param top_n_probs Contains probability values of top `n` bounding boxes + */ + void filter_top_n(std::vector > *probs, + std::vector > *boxes, + std::vector > &top_n_boxes, + std::vector &top_n_idxs, + std::vector &top_n_probs); + + /** @brief Wrapper to apply Non-Maximal Supression + @param top_n_boxes Contains bounding box co-ordinates of top `n` boxes + @param top_n_idxs Containes class indices of top `n` bounding boxes + @param top_n_probs Contains probability values of top `n` bounding boxes + */ + void nms_wrapper(std::vector > &top_n_boxes, + std::vector &top_n_idxs, + std::vector &top_n_probs); + + /** @brief Applies Non-Maximal Supression + @param boxes Bounding box co-ordinates belonging to one class + @param probs Probability values of boxes belonging to one class + */ + std::vector non_maximal_suppression(std::vector > + *boxes, std::vector *probs); + + /** @brief Computes intersection over union of bounding boxes + @param boxes Vector of bounding box co-ordinates + @param base_box Base box wrt which IOU is calculated + @param iou Vector to store IOU values + */ + void intersection_over_union(std::vector > *boxes, + std::vector *base_box, std::vector *iou); + + static inline bool comparator (std::pair l1, + std::pair l2) + { + return l1.first > l2.first; + } + + private: + Mat delta_bbox; + Mat class_scores; + Mat conf_scores; + + unsigned int image_width; + unsigned int image_height; + + unsigned int W, H; + std::vector > anchors_values; + std::vector > anchor_center; + std::vector > anchor_shapes; + + std::vector label_map; + + unsigned int num_classes; + unsigned int anchors_per_grid; + size_t anchors; + double intersection_thresh; + double nms_intersection_thresh; + size_t n_top_detections; + double epsilon; + }; + + //! @} +} // namespace dnn_objdetect +} // namespace cv +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvconfig.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvconfig.h new file mode 100644 index 0000000000000000000000000000000000000000..47e3ef006e301cfb478fa1492a9e093ac8ab6572 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvconfig.h @@ -0,0 +1,167 @@ +#ifndef OPENCV_CVCONFIG_H_INCLUDED +#define OPENCV_CVCONFIG_H_INCLUDED + +/* OpenCV compiled as static or dynamic libs */ +#define BUILD_SHARED_LIBS + +/* OpenCV intrinsics optimized code */ +#define CV_ENABLE_INTRINSICS + +/* OpenCV additional optimized code */ +/* #undef CV_DISABLE_OPTIMIZATION */ + +/* Compile for 'real' NVIDIA GPU architectures */ +#define CUDA_ARCH_BIN "" + +/* Create PTX or BIN for 1.0 compute capability */ +/* #undef CUDA_ARCH_BIN_OR_PTX_10 */ + +/* NVIDIA GPU features are used */ +#define CUDA_ARCH_FEATURES "" + +/* Compile for 'virtual' NVIDIA PTX architectures */ +#define CUDA_ARCH_PTX "" + +/* AMD's Basic Linear Algebra Subprograms Library*/ +/* #undef HAVE_CLAMDBLAS */ + +/* AMD's OpenCL Fast Fourier Transform Library*/ +/* #undef HAVE_CLAMDFFT */ + +/* Clp support */ +/* #undef HAVE_CLP */ + +/* Cocoa API */ +/* #undef HAVE_COCOA */ + +/* NVIDIA CUDA Runtime API*/ +/* #undef HAVE_CUDA */ + +/* NVIDIA CUDA Basic Linear Algebra Subprograms (BLAS) API*/ +/* #undef HAVE_CUBLAS */ + +/* NVIDIA CUDA Deep Neural Network (cuDNN) API*/ +/* #undef HAVE_CUDNN */ + +/* NVIDIA CUDA Fast Fourier Transform (FFT) API*/ +/* #undef HAVE_CUFFT */ + +/* DirectX */ +/* #undef HAVE_DIRECTX */ +/* #undef HAVE_DIRECTX_NV12 */ +/* #undef HAVE_D3D11 */ +/* #undef HAVE_D3D10 */ +/* #undef HAVE_D3D9 */ + +/* Eigen Matrix & Linear Algebra Library */ +#define HAVE_EIGEN + +/* Geospatial Data Abstraction Library */ +/* #undef HAVE_GDAL */ + +/* GTK+ 2.0 Thread support */ +/* #undef HAVE_GTHREAD */ + +/* GTK+ 2.x toolkit */ +/* #undef HAVE_GTK */ + +/* Halide support */ +/* #undef HAVE_HALIDE */ + +/* Vulkan support */ +/* #undef HAVE_VULKAN */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_INTTYPES_H */ + +/* Intel Integrated Performance Primitives */ +/* #undef HAVE_IPP */ +/* #undef HAVE_IPP_ICV */ +/* #undef HAVE_IPP_IW */ +/* #undef HAVE_IPP_IW_LL */ + +/* JPEG-2000 codec */ +#define HAVE_JASPER + +/* IJG JPEG codec */ +#define HAVE_JPEG + +/* libpng/png.h needs to be included */ +#define HAVE_LIBPNG_PNG_H + +/* GDCM DICOM codec */ +/* #undef HAVE_GDCM */ + +/* NVIDIA Video Decoding API*/ +/* #undef HAVE_NVCUVID */ + +/* NVIDIA Video Encoding API*/ +/* #undef HAVE_NVCUVENC */ + +/* OpenCL Support */ +#define HAVE_OPENCL +/* #undef HAVE_OPENCL_STATIC */ +/* #undef HAVE_OPENCL_SVM */ + +/* NVIDIA OpenCL D3D Extensions support */ +/* #undef HAVE_OPENCL_D3D11_NV */ + +/* OpenEXR codec */ +#define HAVE_OPENEXR + +/* OpenGL support*/ +#define HAVE_OPENGL + +/* PNG codec */ +#define HAVE_PNG + +/* Posix threads (pthreads) */ +#define HAVE_PTHREAD + +/* parallel_for with pthreads */ +#define HAVE_PTHREADS_PF + +/* Qt support */ +#define HAVE_QT + +/* Qt OpenGL support */ +#define HAVE_QT_OPENGL + +/* Intel Threading Building Blocks */ +#define HAVE_TBB + +/* Ste||ar Group High Performance ParallelX */ +/* #undef HAVE_HPX */ + +/* TIFF codec */ +#define HAVE_TIFF + +/* Win32 UI */ +/* #undef HAVE_WIN32UI */ + +/* Define if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). */ +/* #undef WORDS_BIGENDIAN */ + +/* VA library (libva) */ +/* #undef HAVE_VA */ + +/* Intel VA-API/OpenCL */ +/* #undef HAVE_VA_INTEL */ + +/* Lapack */ +/* #undef HAVE_LAPACK */ + +/* Library was compiled with functions instrumentation */ +/* #undef ENABLE_INSTRUMENTATION */ + +/* OpenVX */ +/* #undef HAVE_OPENVX */ + +/* OpenCV trace utilities */ +#define OPENCV_TRACE + +/* Library QR-code decoding */ +#define HAVE_QUIRC + +#endif // OPENCV_CVCONFIG_H_INCLUDED diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv.hpp new file mode 100644 index 0000000000000000000000000000000000000000..38dfadbb1f12d6c5cde0e65d04a8c0ea2deccdaf --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv.hpp @@ -0,0 +1,26 @@ +#ifndef __OPENCV_CVV_HPP__ +#define __OPENCV_CVV_HPP__ + +/** +@defgroup cvv GUI for Interactive Visual Debugging of Computer Vision Programs + +Namespace for all functions is **cvv**, i.e. *cvv::showImage()*. + +Compilation: + +- For development, i.e. for cvv GUI to show up, compile your code using cvv with + *g++ -DCVVISUAL_DEBUGMODE*. +- For release, i.e. cvv calls doing nothing, compile your code without above flag. + +See cvv tutorial for a commented example application using cvv. + +*/ + +#include +#include +#include +#include +#include +#include + +#endif //__OPENCV_CVV_HPP__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/call_meta_data.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/call_meta_data.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f4cf21621bf62c325fc6bb52cb2f81ebe7a622b6 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/call_meta_data.hpp @@ -0,0 +1,67 @@ +#ifndef CVVISUAL_CALL_DATA_HPP +#define CVVISUAL_CALL_DATA_HPP + +#include +#include +#include + +namespace cvv +{ + +//! @addtogroup cvv +//! @{ + +namespace impl +{ + +/** + * @brief Optional information about a location in Code. + */ +struct CallMetaData +{ + public: + /** + * @brief Creates an unknown location. + */ + CallMetaData() + : file(nullptr), line(0), function(nullptr), isKnown(false) + { + } + + /** + * @brief Creates the provided location. + * + * Argument should be self-explaining. + */ + CallMetaData(const char *file, size_t line, const char *function) + : file(file), line(line), function(function), isKnown(true) + { + } + operator bool() + { + return isKnown; + } + + // self-explaining: + const char *file; + const size_t line; + const char *function; + + /** + * @brief Whether *this holds actual data. + */ + const bool isKnown; +}; +} + +//! @} + +} // namespaces + +/** + * @brief Creates an instance of CallMetaData with the location of the macro as + * value. + */ +#define CVVISUAL_LOCATION ::cvv::impl::CallMetaData(__FILE__, __LINE__, CV_Func) + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/cvv.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/cvv.hpp new file mode 100644 index 0000000000000000000000000000000000000000..592096db7f59d9d6ee68fe522d1b39ca7513e3a6 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/cvv.hpp @@ -0,0 +1,5 @@ +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/cvv.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/debug_mode.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/debug_mode.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e23da4d01c50a906ebc16fbfe0c1121ff7da4464 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/debug_mode.hpp @@ -0,0 +1,51 @@ +#ifndef CVVISUAL_DEBUG_MODE_HPP +#define CVVISUAL_DEBUG_MODE_HPP + +#if __cplusplus >= 201103L && defined CVVISUAL_USE_THREAD_LOCAL +#define CVVISUAL_THREAD_LOCAL thread_local +#else +#define CVVISUAL_THREAD_LOCAL +#endif + +namespace cvv +{ + +//! @addtogroup cvv +//! @{ + +namespace impl +{ + +/** + * The debug-flag-singleton + */ +static inline bool &getDebugFlag() +{ + CVVISUAL_THREAD_LOCAL static bool flag = true; + return flag; +} + +} // namespace impl + +/** @brief Returns whether debug-mode is active for this TU and thread. +*/ +static inline bool debugMode() +{ + return impl::getDebugFlag(); +} + +/** @brief Enable or disable cvv for current translation unit and thread + +(disabled this way has higher - but still low - overhead compared to using the compile flags). +@param active + */ +static inline void setDebugFlag(bool active) +{ + impl::getDebugFlag() = active; +} + +//! @} + +} // namespace cvv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/dmatch.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/dmatch.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d152cb43a654a2f335574bed2098acee26610551 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/dmatch.hpp @@ -0,0 +1,100 @@ +#ifndef CVVISUAL_DEBUG_DMATCH_HPP +#define CVVISUAL_DEBUG_DMATCH_HPP + +#include + +#include "opencv2/core.hpp" +#include "opencv2/features2d.hpp" + +#include "call_meta_data.hpp" +#include "debug_mode.hpp" + +#ifdef CV_DOXYGEN +#define CVVISUAL_DEBUGMODE +#endif + +namespace cvv +{ + +//! @addtogroup cvv +//! @{ + +namespace impl +{ +CV_EXPORTS void debugDMatch(cv::InputArray img1, std::vector keypoints1, + cv::InputArray img2, std::vector keypoints2, + std::vector matches, const CallMetaData &data, + const char *description, const char *view, + bool useTrainDescriptor); +} // namespace impl + +#ifdef CVVISUAL_DEBUGMODE +/** @brief Add a filled in DMatch \ to debug GUI. + +The matches can are visualized for interactive inspection in different GUI views (one similar to an +interactive :draw_matches:drawMatches\<\>). + +@param img1 First image used in DMatch \. +@param keypoints1 Keypoints of first image. +@param img2 Second image used in DMatch. +@param keypoints2 Keypoints of second image. +@param matches +@param data See showImage +@param description See showImage +@param view See showImage +@param useTrainDescriptor Use DMatch \'s train descriptor index instead of query +descriptor index. + */ +static inline void +debugDMatch(cv::InputArray img1, std::vector keypoints1, + cv::InputArray img2, std::vector keypoints2, + std::vector matches, const impl::CallMetaData &data, + const char *description = nullptr, const char *view = nullptr, + bool useTrainDescriptor = true) +{ + if (debugMode()) + { + impl::debugDMatch(img1, std::move(keypoints1), img2, + std::move(keypoints2), std::move(matches), + data, description, view, useTrainDescriptor); + } +} +/** @overload */ +static inline void +debugDMatch(cv::InputArray img1, std::vector keypoints1, + cv::InputArray img2, std::vector keypoints2, + std::vector matches, const impl::CallMetaData &data, + const std::string &description, const std::string &view, + bool useTrainDescriptor = true) +{ + if (debugMode()) + { + impl::debugDMatch(img1, std::move(keypoints1), img2, + std::move(keypoints2), std::move(matches), + data, description.c_str(), view.c_str(), + useTrainDescriptor); + } +} +#else +static inline void debugDMatch(cv::InputArray, std::vector, + cv::InputArray, std::vector, + std::vector, + const impl::CallMetaData &, + const char * = nullptr, const char * = nullptr, + bool = true) +{ +} +static inline void debugDMatch(cv::InputArray, std::vector, + cv::InputArray, std::vector, + std::vector, + const impl::CallMetaData &, const std::string &, + const std::string &, bool = true) +{ +} +#endif + +//! @} + +} // namespace cvv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/filter.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/filter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..824df2437275f0b0b5d8b87be3ff726cc254fd52 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/filter.hpp @@ -0,0 +1,76 @@ +#ifndef CVVISUAL_DEBUG_FILTER_HPP +#define CVVISUAL_DEBUG_FILTER_HPP + +#include + +#include "opencv2/core.hpp" + +#include "call_meta_data.hpp" +#include "debug_mode.hpp" + +#ifdef CV_DOXYGEN +#define CVVISUAL_DEBUGMODE +#endif + +namespace cvv +{ + +//! @addtogroup cvv +//! @{ + +namespace impl +{ +// implementation outside API +CV_EXPORTS void debugFilter(cv::InputArray original, cv::InputArray result, + const CallMetaData &data, const char *description, + const char *view); +} // namespace impl + +#ifdef CVVISUAL_DEBUGMODE +/** + * @brief Use the debug-framework to compare two images (from which the second + * is intended to be the result of + * a filter applied to the first). + */ +static inline void +debugFilter(cv::InputArray original, cv::InputArray result, + impl::CallMetaData metaData = impl::CallMetaData(), + const char *description = nullptr, const char *view = nullptr) +{ + if (debugMode()) + { + impl::debugFilter(original, result, metaData, description, + view); + } +} +/** @overload */ +static inline void debugFilter(cv::InputArray original, cv::InputArray result, + impl::CallMetaData metaData, + const ::std::string &description, + const ::std::string &view = "") +{ + if (debugMode()) + { + impl::debugFilter(original, result, metaData, + description.c_str(), view.c_str()); + } +} +#else +static inline void debugFilter(cv::InputArray, cv::InputArray, + impl::CallMetaData = impl::CallMetaData(), + const char * = nullptr, const char * = nullptr) +{ +} + +static inline void debugFilter(cv::InputArray, cv::InputArray, + impl::CallMetaData, const ::std::string &, + const ::std::string &) +{ +} +#endif + +//! @} + +} // namespace cvv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/final_show.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/final_show.hpp new file mode 100644 index 0000000000000000000000000000000000000000..60a096c90988e627487b407b2e49ca42404eb2da --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/final_show.hpp @@ -0,0 +1,52 @@ +#ifndef CVVISUAL_FINAL_SHOW_HPP +#define CVVISUAL_FINAL_SHOW_HPP + +#include "opencv2/core.hpp" +#include "debug_mode.hpp" + +namespace cvv +{ + +//! @addtogroup cvv +//! @{ + +namespace impl +{ +CV_EXPORTS void finalShow(); +} + +/** @brief Passes the control to the debug-window for a last time. + +This function **must** be called *once* *after* all cvv calls if any. As an alternative create an +instance of FinalShowCaller, which calls finalShow() in its destructor (RAII-style). + */ +inline void finalShow() +{ +#ifdef CVVISUAL_DEBUGMODE + if (debugMode()) + { + impl::finalShow(); + } +#endif +} + +/** + * @brief RAII-class to call finalShow() in it's dtor. + */ +class FinalShowCaller +{ +public: + /** + * @brief Calls finalShow(). + */ + ~FinalShowCaller() + { + finalShow(); + } +}; + +//! @} + +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/show_image.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/show_image.hpp new file mode 100644 index 0000000000000000000000000000000000000000..417dfb2ac61938829de12d00d9b6d0f75880a9fc --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/cvv/show_image.hpp @@ -0,0 +1,75 @@ +#ifndef CVVISUAL_DEBUG_SHOW_IMAGE_HPP +#define CVVISUAL_DEBUG_SHOW_IMAGE_HPP + +#include + +#include "opencv2/core.hpp" + +#include "call_meta_data.hpp" +#include "debug_mode.hpp" + +#ifdef CV_DOXYGEN +#define CVVISUAL_DEBUGMODE +#endif + +namespace cvv +{ + +//! @addtogroup cvv +//! @{ + +namespace impl +{ +// implementation outside API +CV_EXPORTS void showImage(cv::InputArray img, const CallMetaData &data, + const char *description, const char *view); +} // namespace impl + +#ifdef CVVISUAL_DEBUGMODE +/** @brief Add a single image to debug GUI (similar to imshow \<\>). + +@param img Image to show in debug GUI. +@param metaData Properly initialized CallMetaData struct, i.e. information about file, line and +function name for GUI. Use CVVISUAL_LOCATION macro. +@param description Human readable description to provide context to image. +@param view Preselect view that will be used to visualize this image in GUI. Other views can still +be selected in GUI later on. + */ +static inline void showImage(cv::InputArray img, + impl::CallMetaData metaData = impl::CallMetaData(), + const char *description = nullptr, + const char *view = nullptr) +{ + if (debugMode()) + { + impl::showImage(img, metaData, description, view); + } +} +/** @overload */ +static inline void showImage(cv::InputArray img, impl::CallMetaData metaData, + const ::std::string &description, + const ::std::string &view = "") +{ + if (debugMode()) + { + impl::showImage(img, metaData, description.c_str(), + view.c_str()); + } +} +#else +static inline void showImage(cv::InputArray, + impl::CallMetaData = impl::CallMetaData(), + const char * = nullptr, const char * = nullptr) +{ +} +static inline void showImage(cv::InputArray, impl::CallMetaData, + const ::std::string &, const ::std::string &) +{ +} +#endif + +//! @} + +} // namespace cvv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ar_hmdb.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ar_hmdb.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fa257ad257220fb300da2f53be80d7f69ebc011d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ar_hmdb.hpp @@ -0,0 +1,80 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_AR_HMDB_HPP +#define OPENCV_DATASETS_AR_HMDB_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ar +//! @{ + +struct AR_hmdbObj : public Object +{ + int id; + std::string name; + std::string videoName; +}; + +class CV_EXPORTS AR_hmdb : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ar_sports.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ar_sports.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cb24e38e7772e961560481e0fb64e54fe94a04fc --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ar_sports.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_AR_SPORTS_HPP +#define OPENCV_DATASETS_AR_SPORTS_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ar +//! @{ + +struct AR_sportsObj : public Object +{ + std::string videoUrl; + std::vector labels; +}; + +class CV_EXPORTS AR_sports : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/dataset.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/dataset.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7b05c10c07cac73241859f8737854c077f3084a6 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/dataset.hpp @@ -0,0 +1,592 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_DATASET_HPP +#define OPENCV_DATASETS_DATASET_HPP + +#include +#include + +#include + +/** @defgroup datasets Framework for working with different datasets + +The datasets module includes classes for working with different datasets: load data, evaluate +different algorithms on them, contains benchmarks, etc. + +It is planned to have: + +- basic: loading code for all datasets to help start work with them. +- next stage: quick benchmarks for all datasets to show how to solve them using OpenCV and +implement evaluation code. +- finally: implement on OpenCV state-of-the-art algorithms, which solve these tasks. + +@{ +@defgroup datasets_ar Action Recognition + +### HMDB: A Large Human Motion Database + +Implements loading dataset: + +"HMDB: A Large Human Motion Database": + +Usage: +-# From link above download dataset files: `hmdb51_org.rar` & `test_train_splits.rar`. +-# Unpack them. Unpack all archives from directory: `hmdb51_org/` and remove them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_ar_hmdb -p=/home/user/path_to_unpacked_folders/ +~~~ + +#### Benchmark + +For this dataset was implemented benchmark with accuracy: 0.107407 (using precomputed HOG/HOF +"STIP" features from site, averaging for 3 splits) + +To run this benchmark execute: +~~~ +./opencv/build/bin/example_datasets_ar_hmdb_benchmark -p=/home/user/path_to_unpacked_folders/ +~~~ + +@note +Precomputed features should be unpacked in the same folder: `/home/user/path_to_unpacked_folders/hmdb51_org_stips/`. +Also unpack all archives from directory: `hmdb51_org_stips/` and remove them. + +### Sports-1M %Dataset + +Implements loading dataset: + +"Sports-1M Dataset": + +Usage: +-# From link above download dataset files (`git clone https://code.google.com/p/sports-1m-dataset/`). +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_ar_sports -p=/home/user/path_to_downloaded_folders/ +~~~ + +@defgroup datasets_fr Face Recognition + +### Adience + +Implements loading dataset: + +"Adience": + +Usage: +-# From link above download any dataset file: `faces.tar.gz\aligned.tar.gz` and files with splits: +`fold_0_data.txt-fold_4_data.txt`, `fold_frontal_0_data.txt-fold_frontal_4_data.txt`. (For +face recognition task another splits should be created) +-# Unpack dataset file to some folder and place split files into the same folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_fr_adience -p=/home/user/path_to_created_folder/ +~~~ + +### Labeled Faces in the Wild + +Implements loading dataset: + +"Labeled Faces in the Wild": + +Usage: +-# From link above download any dataset file: +`lfw.tgz\lfwa.tar.gz\lfw-deepfunneled.tgz\lfw-funneled.tgz` and files with pairs: 10 test +splits: `pairs.txt` and developer train split: `pairsDevTrain.txt`. +-# Unpack dataset file and place `pairs.txt` and `pairsDevTrain.txt` in created folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_fr_lfw -p=/home/user/path_to_unpacked_folder/lfw2/ +~~~ + +#### Benchmark + +For this dataset was implemented benchmark with accuracy: 0.623833 +- 0.005223 (train split: +`pairsDevTrain.txt`, dataset: lfwa) + +To run this benchmark execute: +~~~ +./opencv/build/bin/example_datasets_fr_lfw_benchmark -p=/home/user/path_to_unpacked_folder/lfw2/ +~~~ + +@defgroup datasets_gr Gesture Recognition + +### ChaLearn Looking at People + +Implements loading dataset: + +"ChaLearn Looking at People": + +Usage +-# Follow instruction from site above, download files for dataset "Track 3: Gesture Recognition": +`Train1.zip`-`Train5.zip`, `Validation1.zip`-`Validation3.zip` (Register on site: www.codalab.org and +accept the terms and conditions of competition: + There are three mirrors for +downloading dataset files. When I downloaded data only mirror: "Universitat Oberta de Catalunya" +works). +-# Unpack train archives `Train1.zip`-`Train5.zip` to folder `Train/`, validation archives +`Validation1.zip`-`Validation3.zip` to folder `Validation/` +-# Unpack all archives in `Train/` & `Validation/` in the folders with the same names, for example: +`Sample0001.zip` to `Sample0001/` +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_gr_chalearn -p=/home/user/path_to_unpacked_folders/ +~~~ + +### Sheffield Kinect Gesture Dataset + +Implements loading dataset: + +"Sheffield Kinect Gesture Dataset": + +Usage: +-# From link above download dataset files: `subject1_dep.7z`-`subject6_dep.7z`, `subject1_rgb.7z`-`subject6_rgb.7z`. +-# Unpack them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_gr_skig -p=/home/user/path_to_unpacked_folders/ +~~~ + +@defgroup datasets_hpe Human Pose Estimation + +### HumanEva Dataset + +Implements loading dataset: + +"HumanEva Dataset": + +Usage: +-# From link above download dataset files for `HumanEva-I` (tar) & `HumanEva-II`. +-# Unpack them to `HumanEva_1` & `HumanEva_2` accordingly. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_hpe_humaneva -p=/home/user/path_to_unpacked_folders/ +~~~ + +### PARSE Dataset + +Implements loading dataset: + +"PARSE Dataset": + +Usage: +-# From link above download dataset file: `people.zip`. +-# Unpack it. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_hpe_parse -p=/home/user/path_to_unpacked_folder/people_all/ +~~~ + +@defgroup datasets_ir Image Registration + +### Affine Covariant Regions Datasets + +Implements loading dataset: + +"Affine Covariant Regions Datasets": + +Usage: +-# From link above download dataset files: +`bark\bikes\boat\graf\leuven\trees\ubc\wall.tar.gz`. +-# Unpack them. +-# To load data, for example, for "bark", run: +``` +./opencv/build/bin/example_datasets_ir_affine -p=/home/user/path_to_unpacked_folder/bark/ +``` + +### Robot Data Set + +Implements loading dataset: + +"Robot Data Set, Point Feature Data Set – 2010": + +Usage: +-# From link above download dataset files: `SET001_6.tar.gz`-`SET055_60.tar.gz` +-# Unpack them to one folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_ir_robot -p=/home/user/path_to_unpacked_folder/ +~~~ + +@defgroup datasets_is Image Segmentation + +### The Berkeley Segmentation Dataset and Benchmark + +Implements loading dataset: + +"The Berkeley Segmentation Dataset and Benchmark": + +Usage: +-# From link above download dataset files: `BSDS300-human.tgz` & `BSDS300-images.tgz`. +-# Unpack them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_is_bsds -p=/home/user/path_to_unpacked_folder/BSDS300/ +~~~ + +### Weizmann Segmentation Evaluation Database + +Implements loading dataset: + +"Weizmann Segmentation Evaluation Database": + +Usage: +-# From link above download dataset files: `Weizmann_Seg_DB_1obj.ZIP` & `Weizmann_Seg_DB_2obj.ZIP`. +-# Unpack them. +-# To load data, for example, for `1 object` dataset, run: +~~~ +./opencv/build/bin/example_datasets_is_weizmann -p=/home/user/path_to_unpacked_folder/1obj/ +~~~ + +@defgroup datasets_msm Multiview Stereo Matching + +### EPFL Multi-View Stereo + +Implements loading dataset: + +"EPFL Multi-View Stereo": + +Usage: +-# From link above download dataset files: +`castle_dense\castle_dense_large\castle_entry\fountain\herzjesu_dense\herzjesu_dense_large_bounding\cameras\images\p.tar.gz`. +-# Unpack them in separate folder for each object. For example, for "fountain", in folder `fountain/` : +`fountain_dense_bounding.tar.gz -> bounding/`, +`fountain_dense_cameras.tar.gz -> camera/`, +`fountain_dense_images.tar.gz -> png/`, +`fountain_dense_p.tar.gz -> P/` +-# To load data, for example, for "fountain", run: +~~~ +./opencv/build/bin/example_datasets_msm_epfl -p=/home/user/path_to_unpacked_folder/fountain/ +~~~ + +### Stereo – Middlebury Computer Vision + +Implements loading dataset: + +"Stereo – Middlebury Computer Vision": + +Usage: +-# From link above download dataset files: +`dino\dinoRing\dinoSparseRing\temple\templeRing\templeSparseRing.zip` +-# Unpack them. +-# To load data, for example "temple" dataset, run: +~~~ +./opencv/build/bin/example_datasets_msm_middlebury -p=/home/user/path_to_unpacked_folder/temple/ +~~~ + +@defgroup datasets_or Object Recognition + +### ImageNet + +Implements loading dataset: "ImageNet": + +Usage: +-# From link above download dataset files: +`ILSVRC2010_images_train.tar\ILSVRC2010_images_test.tar\ILSVRC2010_images_val.tar` & devkit: +`ILSVRC2010_devkit-1.0.tar.gz` (Implemented loading of 2010 dataset as only this dataset has ground +truth for test data, but structure for ILSVRC2014 is similar) +-# Unpack them to: `some_folder/train/`, `some_folder/test/`, `some_folder/val` & +`some_folder/ILSVRC2010_validation_ground_truth.txt`, +`some_folder/ILSVRC2010_test_ground_truth.txt`. +-# Create file with labels: `some_folder/labels.txt`, for example, using python script below (each +file's row format: `synset,labelID,description`. For example: "n07751451,18,plum"). +-# Unpack all tar files in train. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_or_imagenet -p=/home/user/some_folder/ +~~~ + +Python script to parse `meta.mat`: +~~~{py} + import scipy.io + meta_mat = scipy.io.loadmat("devkit-1.0/data/meta.mat") + + labels_dic = dict((m[0][1][0], m[0][0][0][0]-1) for m in meta_mat['synsets'] + label_names_dic = dict((m[0][1][0], m[0][2][0]) for m in meta_mat['synsets'] + + for label in labels_dic.keys(): + print "{0},{1},{2}".format(label, labels_dic[label], label_names_dic[label]) +~~~ + +### MNIST + +Implements loading dataset: + +"MNIST": + +Usage: +-# From link above download dataset files: +`t10k-images-idx3-ubyte.gz`, `t10k-labels-idx1-ubyte.gz`, `train-images-idx3-ubyte.gz`, `train-labels-idx1-ubyte.gz`. +-# Unpack them. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_or_mnist -p=/home/user/path_to_unpacked_files/ +~~~ + +### SUN Database + +Implements loading dataset: + +"SUN Database, Scene Recognition Benchmark. SUN397": + +Usage: +-# From link above download dataset file: `SUN397.tar` & file with splits: `Partitions.zip` +-# Unpack `SUN397.tar` into folder: `SUN397/` & `Partitions.zip` into folder: `SUN397/Partitions/` +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_or_sun -p=/home/user/path_to_unpacked_files/SUN397/ +~~~ + +@defgroup datasets_pd Pedestrian Detection + +### Caltech Pedestrian Detection Benchmark + +Implements loading dataset: + +"Caltech Pedestrian Detection Benchmark": + +@note First version of Caltech Pedestrian dataset loading. Code to unpack all frames from seq files +commented as their number is huge! So currently load only meta information without data. Also +ground truth isn't processed, as need to convert it from mat files first. + +Usage: +-# From link above download dataset files: `set00.tar`-`set10.tar`. +-# Unpack them to separate folder. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_pd_caltech -p=/home/user/path_to_unpacked_folders/ +~~~ + +@defgroup datasets_slam SLAM + +### KITTI Vision Benchmark + +Implements loading dataset: + +"KITTI Vision Benchmark": + +Usage: +-# From link above download "Odometry" dataset files: +`data_odometry_gray\data_odometry_color\data_odometry_velodyne\data_odometry_poses\data_odometry_calib.zip`. +-# Unpack `data_odometry_poses.zip`, it creates folder `dataset/poses/`. After that unpack +`data_odometry_gray.zip`, `data_odometry_color.zip`, `data_odometry_velodyne.zip`. Folder +`dataset/sequences/` will be created with folders `00/..21/`. Each of these folders will contain: +`image_0/`, `image_1/`, `image_2/`, `image_3/`, `velodyne/` and files `calib.txt` & `times.txt`. +These two last files will be replaced after unpacking `data_odometry_calib.zip` at the end. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_slam_kitti -p=/home/user/path_to_unpacked_folder/dataset/ +~~~ + +### TUMindoor Dataset + +Implements loading dataset: + +"TUMindoor Dataset": + +Usage: +-# From link above download dataset files: `dslr\info\ladybug\pointcloud.tar.bz2` for each dataset: +`11-11-28 (1st floor)\11-12-13 (1st floor N1)\11-12-17a (4th floor)\11-12-17b (3rd floor)\11-12-17c (Ground I)\11-12-18a (Ground II)\11-12-18b (2nd floor)` +-# Unpack them in separate folder for each dataset. +`dslr.tar.bz2 -> dslr/`, +`info.tar.bz2 -> info/`, +`ladybug.tar.bz2 -> ladybug/`, +`pointcloud.tar.bz2 -> pointcloud/`. +-# To load each dataset run: +~~~ +./opencv/build/bin/example_datasets_slam_tumindoor -p=/home/user/path_to_unpacked_folders/ +~~~ + +@defgroup datasets_sr Super Resolution + +### The Berkeley Segmentation Dataset and Benchmark + +Implements loading dataset: + +"The Berkeley Segmentation Dataset and Benchmark": + +Usage: +-# From link above download `BSDS300-images.tgz`. +-# Unpack. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_sr_bsds -p=/home/user/path_to_unpacked_folder/ +~~~ + +### DIV2K dataset: DIVerse 2K + +Implements loading dataset: + +"DIV2K dataset: DIVerse 2K": + +Usage: +-# From link above download 'Train data (HR images)' or any other of the dataset files. +-# Unpack. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_sr_div2k -p=/home/user/path_to_unpacked_folder/folder_containing_the_images/ +~~~ + +### The General-100 Dataset + +Implements loading dataset: + +"General-100 dataset contains 100 bmp-format images (with no compression). +We used this dataset in our FSRCNN ECCV 2016 paper. The size of these 100 images ranges from 710 x 704 (large) to 131 x 112 (small). +They are all of good quality with clear edges but fewer smooth regions (e.g., sky and ocean), thus are very suitable for the super-resolution training.": + + +Usage: +-# From link above download `General-100.zip`. +-# Unpack. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_sr_general100 -p=/home/user/path_to_unpacked_folder/ +~~~ + +@defgroup datasets_tr Text Recognition + +### The Chars74K Dataset + +Implements loading dataset: + +"The Chars74K Dataset": + +Usage: +-# From link above download dataset files: +`EnglishFnt\EnglishHnd\EnglishImg\KannadaHnd\KannadaImg.tgz`, `ListsTXT.tgz`. +-# Unpack them. +-# Move `.m` files from folder `ListsTXT/` to appropriate folder. For example, +`English/list_English_Img.m` for `EnglishImg.tgz`. +-# To load data, for example "EnglishImg", run: +~~~ +./opencv/build/bin/example_datasets_tr_chars -p=/home/user/path_to_unpacked_folder/English/ +~~~ + +### The Street View Text Dataset + +Implements loading dataset: + +"The Street View Text Dataset": + +Usage: +-# From link above download dataset file: `svt.zip`. +-# Unpack it. +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_tr_svt -p=/home/user/path_to_unpacked_folder/svt/svt1/ +~~~ + +#### Benchmark + +For this dataset was implemented benchmark with accuracy (mean f1): 0.217 + +To run benchmark execute: +~~~ +./opencv/build/bin/example_datasets_tr_svt_benchmark -p=/home/user/path_to_unpacked_folders/svt/svt1/ +~~~ + +@defgroup datasets_track Tracking + +### VOT 2015 Database + +Implements loading dataset: + +"VOT 2015 dataset comprises 60 short sequences showing various objects in challenging backgrounds. +The sequences were chosen from a large pool of sequences including the ALOV dataset, OTB2 dataset, +non-tracking datasets, Computer Vision Online, Professor Bob Fisher's Image Database, Videezy, +Center for Research in Computer Vision, University of Central Florida, USA, NYU Center for Genomics +and Systems Biology, Data Wrangling, Open Access Directory and Learning and Recognition in Vision +Group, INRIA, France. The VOT sequence selection protocol was applied to obtain a representative +set of challenging sequences.": + +Usage: +-# From link above download dataset file: `vot2015.zip` +-# Unpack `vot2015.zip` into folder: `VOT2015/` +-# To load data run: +~~~ +./opencv/build/bin/example_datasets_track_vot -p=/home/user/path_to_unpacked_files/VOT2015/ +~~~ +@} + +*/ + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets +//! @{ + +struct Object +{ +}; + +class CV_EXPORTS Dataset +{ +public: + Dataset() {} + virtual ~Dataset() {} + + virtual void load(const std::string &path) = 0; + + std::vector< Ptr >& getTrain(int splitNum = 0); + std::vector< Ptr >& getTest(int splitNum = 0); + std::vector< Ptr >& getValidation(int splitNum = 0); + + int getNumSplits() const; + +protected: + std::vector< std::vector< Ptr > > train; + std::vector< std::vector< Ptr > > test; + std::vector< std::vector< Ptr > > validation; + +private: + std::vector< Ptr > empty; +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/fr_adience.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/fr_adience.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2df5d8df4844274a15af7182e6eaad18384a332a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/fr_adience.hpp @@ -0,0 +1,98 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_FR_ADIENCE_HPP +#define OPENCV_DATASETS_FR_ADIENCE_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_fr +//! @{ + +enum genderType +{ + male = 0, + female, + none +}; + +struct FR_adienceObj : public Object +{ + std::string user_id; + std::string original_image; + int face_id; + std::string age; + genderType gender; + int x; + int y; + int dx; + int dy; + int tilt_ang; + int fiducial_yaw_angle; + int fiducial_score; +}; + +class CV_EXPORTS FR_adience : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); + + std::vector paths; +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/fr_lfw.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/fr_lfw.hpp new file mode 100644 index 0000000000000000000000000000000000000000..16d63157439789649e316558ed5dadf42e47dc36 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/fr_lfw.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_FR_LFW_HPP +#define OPENCV_DATASETS_FR_LFW_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_fr +//! @{ + +struct FR_lfwObj : public Object +{ + std::string image1, image2; + bool same; +}; + +class CV_EXPORTS FR_lfw : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/gr_chalearn.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/gr_chalearn.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6a5c764127079ffee7eec17ad7714cbefee09436 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/gr_chalearn.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_GR_CHALEARN_HPP +#define OPENCV_DATASETS_GR_CHALEARN_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_gr +//! @{ + +struct groundTruth +{ + int gestureID, initialFrame, lastFrame; +}; + +struct join +{ + double Wx, Wy, Wz, Rx, Ry, Rz, Rw, Px, Py; +}; + +struct skeleton +{ + join s[20]; +}; + +struct GR_chalearnObj : public Object +{ + std::string name, nameColor, nameDepth, nameUser; + int numFrames, fps, depth; + std::vector groundTruths; + std::vector skeletons; +}; + +class CV_EXPORTS GR_chalearn : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/gr_skig.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/gr_skig.hpp new file mode 100644 index 0000000000000000000000000000000000000000..35bc6f4f6bf1576ffe77b85106a1505f4977553f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/gr_skig.hpp @@ -0,0 +1,118 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_GR_SKIG_HPP +#define OPENCV_DATASETS_GR_SKIG_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_gr +//! @{ + +enum actionType +{ + circle = 1, + triangle, + updown, + rightleft, + wave, + z, + cross, + comehere, + turnaround, + pat +}; + +enum poseType +{ + fist = 1, + index, + flat +}; + +enum illuminationType +{ + light = 1, + dark +}; + +enum backgroundType +{ + woodenBoard = 1, + whitePaper, + paperWithCharacters +}; + +struct GR_skigObj : public Object +{ + std::string rgb; + std::string dep; + char person; // 1..6 + backgroundType background; + illuminationType illumination; + poseType pose; + actionType type; +}; + +class CV_EXPORTS GR_skig : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/hpe_humaneva.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/hpe_humaneva.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2eba8cfca78f6139712a1b89a61cc94c0f48016f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/hpe_humaneva.hpp @@ -0,0 +1,90 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_HPE_HUMANEVA_HPP +#define OPENCV_DATASETS_HPE_HUMANEVA_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_hpe +//! @{ + +struct HPE_humanevaObj : public Object +{ + char person; // 1..4 + std::string action; + int type1; + std::string type2; + Matx13d ofs; + std::string fileName; + std::vector imageNames; // for HumanEva_II +}; + +enum datasetType +{ + humaneva_1 = 1, + humaneva_2 +}; + +class CV_EXPORTS HPE_humaneva : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(int num=humaneva_1); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/hpe_parse.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/hpe_parse.hpp new file mode 100644 index 0000000000000000000000000000000000000000..42294df837bef711c8f6a1a0ac50fa8ba79ee26d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/hpe_parse.hpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_HPE_PARSE_HPP +#define OPENCV_DATASETS_HPE_PARSE_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_hpe +//! @{ + +struct HPE_parseObj : public Object +{ + std::string name; +}; + +class CV_EXPORTS HPE_parse : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ir_affine.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ir_affine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7cc0c0908f8d4324c178b935396343ad7d2a660a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ir_affine.hpp @@ -0,0 +1,80 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_IR_AFFINE_HPP +#define OPENCV_DATASETS_IR_AFFINE_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ir +//! @{ + +struct IR_affineObj : public Object +{ + std::string imageName; + Matx33d mat; +}; + +class CV_EXPORTS IR_affine : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ir_robot.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ir_robot.hpp new file mode 100644 index 0000000000000000000000000000000000000000..446e3be6bbed694dd0c67aadf0b3938a9a32c372 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/ir_robot.hpp @@ -0,0 +1,89 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_IR_ROBOT_HPP +#define OPENCV_DATASETS_IR_ROBOT_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_ir +//! @{ + +// calibration matrix from calibrationFile.mat +// 2.8290e+03 0.0000e+00 8.0279e+02 +// 0.0000e+00 2.8285e+03 6.1618e+02 +// 0.0000e+00 0.0000e+00 1.0000e+00 + +struct cameraPos +{ + std::vector images; +}; + +struct IR_robotObj : public Object +{ + std::string name; + std::vector pos; +}; + +class CV_EXPORTS IR_robot : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/is_bsds.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/is_bsds.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b4a3e65789fb8f3d23dba0c611bca26665e86a3f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/is_bsds.hpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_IS_BSDS_HPP +#define OPENCV_DATASETS_IS_BSDS_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_is +//! @{ + +struct IS_bsdsObj : public Object +{ + std::string name; +}; + +class CV_EXPORTS IS_bsds : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/is_weizmann.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/is_weizmann.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4f61578a61c8a42c339db318acdf38de1ebe1521 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/is_weizmann.hpp @@ -0,0 +1,81 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_IS_WEIZMANN_HPP +#define OPENCV_DATASETS_IS_WEIZMANN_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_is +//! @{ + +struct IS_weizmannObj : public Object +{ + std::string imageName; + std::string srcBw; + std::string srcColor; + std::string humanSeg; // TODO: read human segmented +}; + +class CV_EXPORTS IS_weizmann : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/msm_epfl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/msm_epfl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..54aebde926fc2b283ec088aae09a7f9271eec8a0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/msm_epfl.hpp @@ -0,0 +1,90 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_MSM_EPFL_HPP +#define OPENCV_DATASETS_MSM_EPFL_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_msm +//! @{ + +struct cameraParam +{ + Matx33d mat1; + double mat2[3]; + Matx33d mat3; + double mat4[3]; + int imageWidth, imageHeight; +}; + +struct MSM_epflObj : public Object +{ + std::string imageName; + Matx23d bounding; + Matx34d p; + cameraParam camera; +}; + +class CV_EXPORTS MSM_epfl : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/msm_middlebury.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/msm_middlebury.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9b883e59ae29547d8b2e737cd1a05096d56722e8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/msm_middlebury.hpp @@ -0,0 +1,81 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_MSM_MIDDLEBURY_HPP +#define OPENCV_DATASETS_MSM_MIDDLEBURY_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_msm +//! @{ + +struct MSM_middleburyObj : public Object +{ + std::string imageName; + Matx33d k; + Matx33d r; + double t[3]; +}; + +class CV_EXPORTS MSM_middlebury : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_imagenet.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_imagenet.hpp new file mode 100644 index 0000000000000000000000000000000000000000..079165bf934403dbe2ef63426ce14086d7544176 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_imagenet.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_OR_IMAGENET_HPP +#define OPENCV_DATASETS_OR_IMAGENET_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ + +struct OR_imagenetObj : public Object +{ + int id; + std::string image; +}; + +class CV_EXPORTS OR_imagenet : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_mnist.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_mnist.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ac4d838ed5bff131eeee89d72e74e3744bebf5a4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_mnist.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_OR_MNIST_HPP +#define OPENCV_DATASETS_OR_MNIST_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ + +struct OR_mnistObj : public Object +{ + char label; // 0..9 + Mat image; // [28][28] +}; + +class CV_EXPORTS OR_mnist : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_pascal.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_pascal.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c5f27af9fcd6f038d13995876f117928d7c54f41 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_pascal.hpp @@ -0,0 +1,102 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_VOC_PASCAL_HPP +#define OPENCV_DATASETS_VOC_PASCAL_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ +struct PascalPart: public Object +{ + std::string name; + int xmin; + int ymin; + int xmax; + int ymax; +}; + +struct PascalObj: public PascalPart +{ + std::string pose; + bool truncated; + bool difficult; + bool occluded; + + std::vector parts; +}; + +struct OR_pascalObj : public Object +{ + std::string filename; + + int width; + int height; + int depth; + + std::vector objects; +}; + +class CV_EXPORTS OR_pascal : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +}// namespace dataset +}// namespace cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_sun.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_sun.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7d3d8878a4a2e3c3f8077ba48c5f90aa382cda11 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/or_sun.hpp @@ -0,0 +1,81 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_OR_SUN_HPP +#define OPENCV_DATASETS_OR_SUN_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_or +//! @{ + +struct OR_sunObj : public Object +{ + int label; + std::string name; +}; + +class CV_EXPORTS OR_sun : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); + + std::vector paths; +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/pd_caltech.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/pd_caltech.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c8545e2f1ed291cfda10c909e05eb31dc2eca45c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/pd_caltech.hpp @@ -0,0 +1,89 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_PD_CALTECH_HPP +#define OPENCV_DATASETS_PD_CALTECH_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_pd +//! @{ + +struct PD_caltechObj : public Object +{ + //double groundTrue[][]; + //Mat image; + std::string name; + std::vector< std::string > imageNames; +}; + +// +// first version of Caltech Pedestrian dataset loading +// code to unpack all frames from seq files commented as their number is huge +// so currently load only meta information without data +// +// also ground truth isn't processed, as need to convert it from mat files first +// + +class CV_EXPORTS PD_caltech : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/pd_inria.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/pd_inria.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9e1d30b89c38944fd8ca4c39174163ed0c53d30d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/pd_inria.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_PD_INRIA_HPP +#define OPENCV_DATASETS_PD_INRIA_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_pd +//! @{ + +enum sampleType +{ + POS = 0, + NEG = 1 +}; + +struct PD_inriaObj : public Object +{ + // image file name + std::string filename; + + // positive or negative + sampleType sType; + + // image size + int width; + int height; + int depth; + + // bounding boxes + std::vector< Rect > bndboxes; +}; + +class CV_EXPORTS PD_inria : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/slam_kitti.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/slam_kitti.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a004b95f450842417f1d5a921f746ba3691d5b8e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/slam_kitti.hpp @@ -0,0 +1,87 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_SLAM_KITTI_HPP +#define OPENCV_DATASETS_SLAM_KITTI_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_slam +//! @{ + +struct pose +{ + double elem[12]; +}; + +struct SLAM_kittiObj : public Object +{ + std::string name; + std::vector images[4]; + std::vector velodyne; + std::vector times, p[4]; + std::vector posesArray; +}; + +class CV_EXPORTS SLAM_kitti : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/slam_tumindoor.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/slam_tumindoor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..eca07addae952c3b3d6dbd0f53a1f1fa751a8403 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/slam_tumindoor.hpp @@ -0,0 +1,87 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_SLAM_TUMINDOOR_HPP +#define OPENCV_DATASETS_SLAM_TUMINDOOR_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_slam +//! @{ + +enum imageType +{ + LEFT = 0, + RIGHT, + LADYBUG +}; + +struct SLAM_tumindoorObj : public Object +{ + std::string name; + Matx44d transformMat; + imageType type; +}; + +class CV_EXPORTS SLAM_tumindoor : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_bsds.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_bsds.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c319323dd53958e83e6f2121c73f5f61e7b1095d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_bsds.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_DATASETS_SR_BSDS_HPP +#define OPENCV_DATASETS_SR_BSDS_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_sr +//! @{ + +struct SR_bsdsObj : public Object +{ + std::string imageName; +}; + +class CV_EXPORTS SR_bsds : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_div2k.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_div2k.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9e2c0253bea3a00d2513e0342e9394b6d2553db4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_div2k.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_DATASETS_SR_DIV2K_HPP +#define OPENCV_DATASETS_SR_DIV2K_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_sr +//! @{ + +struct SR_div2kObj : public Object +{ + std::string imageName; +}; + +class CV_EXPORTS SR_div2k : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_general100.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_general100.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8b2d18903f816e61552f56cd36d23d1692163c83 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/sr_general100.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_DATASETS_SR_GENERAL100_HPP +#define OPENCV_DATASETS_SR_GENERAL100_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_sr +//! @{ + +struct SR_general100Obj : public Object +{ + std::string imageName; +}; + +class CV_EXPORTS SR_general100 : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_chars.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_chars.hpp new file mode 100644 index 0000000000000000000000000000000000000000..69aab83a24cc92bfabebd89217d5bb11b0e5fe84 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_chars.hpp @@ -0,0 +1,79 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_TR_CHARS_HPP +#define OPENCV_DATASETS_TR_CHARS_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_tr +//! @{ + +struct TR_charsObj : public Object +{ + std::string imgName; + int label; +}; + +class CV_EXPORTS TR_chars : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_icdar.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_icdar.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3b43d697402e8f0e88ce443575669a31436bb898 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_icdar.hpp @@ -0,0 +1,87 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_TR_ICDAR_HPP +#define OPENCV_DATASETS_TR_ICDAR_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_tr +//! @{ + +struct word +{ + std::string value; + int height, width, x, y; +}; + +struct TR_icdarObj : public Object +{ + std::string fileName; + std::vector lex100; + std::vector lexFull; + std::vector words; +}; + +class CV_EXPORTS TR_icdar : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_svt.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_svt.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7b941802e8f1fa3902918d82ff3cc7aaac1dc544 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/tr_svt.hpp @@ -0,0 +1,86 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_TR_SVT_HPP +#define OPENCV_DATASETS_TR_SVT_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_tr +//! @{ + +struct tag +{ + std::string value; + int height, width, x, y; +}; + +struct TR_svtObj : public Object +{ + std::string fileName; + std::vector lex; + std::vector tags; +}; + +class CV_EXPORTS TR_svt : public Dataset +{ +public: + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + static Ptr create(); +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/track_alov.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/track_alov.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a3c5da02364dbed47bad2d8a310ce9c96b795518 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/track_alov.hpp @@ -0,0 +1,107 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_TRACK_ALOV_HPP +#define OPENCV_DATASETS_TRACK_ALOV_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" +#include "opencv2/datasets/util.hpp" + +using namespace std; + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_track +//! @{ + +struct TRACK_alovObj : public Object +{ + int id; + std::string imagePath; + vector gtbb; +}; + +const string sectionNames[] = { "01-Light", "02-SurfaceCover", "03-Specularity", "04-Transparency", "05-Shape", "06-MotionSmoothness", "07-MotionCoherence", +"08-Clutter", "09-Confusion", "10-LowContrast", "11-Occlusion", "12-MovingCamera", "13-ZoomingCamera", "14-LongDuration" }; + +const int sectionSizes[] = { 33, 15, 18, 20, 24, 22, 12, 15, 37, 23, 34, 22, 29, 10 }; + +class CV_EXPORTS TRACK_alov : public Dataset +{ +public: + static Ptr create(); + + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + //Load only frames with annotations (~every 5-th frame) + virtual void loadAnnotatedOnly(const std::string &path) = 0; + + virtual int getDatasetsNum() = 0; + + virtual int getDatasetLength(int id) = 0; + + virtual bool initDataset(int id) = 0; + + virtual bool getNextFrame(Mat &frame) = 0; + virtual vector getNextGT() = 0; + + //Get frame/GT by datasetID (1..N) frameID (1..K) + virtual bool getFrame(Mat &frame, int datasetID, int frameID) = 0; + virtual vector getGT(int datasetID, int frameID) = 0; + +protected: + vector > > data; + int activeDatasetID; + int frameCounter; +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/track_vot.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/track_vot.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a5a9c6fd8c85119662673b4bcd68d936842e446e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/track_vot.hpp @@ -0,0 +1,96 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_TRACK_VOT_HPP +#define OPENCV_DATASETS_TRACK_VOT_HPP + +#include +#include + +#include "opencv2/datasets/dataset.hpp" +#include "opencv2/datasets/util.hpp" + +using namespace std; + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets_track +//! @{ + +struct TRACK_votObj : public Object +{ + int id; + std::string imagePath; + vector gtbb; +}; + +class CV_EXPORTS TRACK_vot : public Dataset +{ +public: + static Ptr create(); + + virtual void load(const std::string &path) CV_OVERRIDE = 0; + + virtual int getDatasetsNum() = 0; + + virtual int getDatasetLength(int id) = 0; + + virtual bool initDataset(int id) = 0; + + virtual bool getNextFrame(Mat &frame) = 0; + + virtual vector getGT() = 0; + +protected: + vector > > data; + int activeDatasetID; + int frameCounter; +}; + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/util.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/util.hpp new file mode 100644 index 0000000000000000000000000000000000000000..316de3a7a90c647355d3bcf68d5c60ed3188666f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/datasets/util.hpp @@ -0,0 +1,74 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DATASETS_UTIL_HPP +#define OPENCV_DATASETS_UTIL_HPP + +#include +#include + +#include +#include // atoi, atof + +#include + +#include + +namespace cv +{ +namespace datasets +{ + +//! @addtogroup datasets +//! @{ + +void CV_EXPORTS split(const std::string &s, std::vector &elems, char delim); + +void CV_EXPORTS createDirectory(const std::string &path); + +void CV_EXPORTS getDirList(const std::string &dirName, std::vector &fileNames); + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn.hpp new file mode 100644 index 0000000000000000000000000000000000000000..97f2fe3ffd8cf60ec40a732768a85c3ab5a1cd73 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn.hpp @@ -0,0 +1,78 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_HPP +#define OPENCV_DNN_HPP + +// This is an umbrella header to include into you project. +// We are free to change headers layout in dnn subfolder, so please include +// this header for future compatibility + + +/** @defgroup dnn Deep Neural Network module + @{ + This module contains: + - API for new layers creation, layers are building bricks of neural networks; + - set of built-in most-useful Layers; + - API to construct and modify comprehensive neural networks from layers; + - functionality for loading serialized networks models from different frameworks. + + Functionality of this module is designed only for forward pass computations (i.e. network testing). + A network training is in principle not supported. + @} +*/ +/** @example samples/dnn/classification.cpp +Check @ref tutorial_dnn_googlenet "the corresponding tutorial" for more details +*/ +/** @example samples/dnn/colorization.cpp +*/ +/** @example samples/dnn/object_detection.cpp +Check @ref tutorial_dnn_yolo "the corresponding tutorial" for more details +*/ +/** @example samples/dnn/openpose.cpp +*/ +/** @example samples/dnn/segmentation.cpp +*/ +/** @example samples/dnn/text_detection.cpp +*/ +#include + +#endif /* OPENCV_DNN_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/all_layers.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/all_layers.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4dcca623bf99a4183e4d7f228bbe9aaa004f5c9b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/all_layers.hpp @@ -0,0 +1,655 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_ALL_LAYERS_HPP +#define OPENCV_DNN_DNN_ALL_LAYERS_HPP +#include + +namespace cv { +namespace dnn { +CV__DNN_INLINE_NS_BEGIN +//! @addtogroup dnn +//! @{ + +/** @defgroup dnnLayerList Partial List of Implemented Layers + @{ + This subsection of dnn module contains information about built-in layers and their descriptions. + + Classes listed here, in fact, provides C++ API for creating instances of built-in layers. + In addition to this way of layers instantiation, there is a more common factory API (see @ref dnnLayerFactory), it allows to create layers dynamically (by name) and register new ones. + You can use both API, but factory API is less convenient for native C++ programming and basically designed for use inside importers (see @ref readNetFromCaffe(), @ref readNetFromTorch(), @ref readNetFromTensorflow()). + + Built-in layers partially reproduce functionality of corresponding Caffe and Torch7 layers. + In particular, the following layers and Caffe importer were tested to reproduce Caffe functionality: + - Convolution + - Deconvolution + - Pooling + - InnerProduct + - TanH, ReLU, Sigmoid, BNLL, Power, AbsVal + - Softmax + - Reshape, Flatten, Slice, Split + - LRN + - MVN + - Dropout (since it does nothing on forward pass -)) +*/ + + class CV_EXPORTS BlankLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + /** + * Constant layer produces the same data blob at an every forward pass. + */ + class CV_EXPORTS ConstLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + //! LSTM recurrent layer + class CV_EXPORTS LSTMLayer : public Layer + { + public: + /** Creates instance of LSTM layer */ + static Ptr create(const LayerParams& params); + + /** @deprecated Use LayerParams::blobs instead. + @brief Set trained weights for LSTM layer. + + LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights. + + Let @f$x_t@f$ be current input, @f$h_t@f$ be current output, @f$c_t@f$ be current state. + Than current output and current cell state is computed as follows: + @f{eqnarray*}{ + h_t &= o_t \odot tanh(c_t), \\ + c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \\ + @f} + where @f$\odot@f$ is per-element multiply operation and @f$i_t, f_t, o_t, g_t@f$ is internal gates that are computed using learned weights. + + Gates are computed as follows: + @f{eqnarray*}{ + i_t &= sigmoid&(W_{xi} x_t + W_{hi} h_{t-1} + b_i), \\ + f_t &= sigmoid&(W_{xf} x_t + W_{hf} h_{t-1} + b_f), \\ + o_t &= sigmoid&(W_{xo} x_t + W_{ho} h_{t-1} + b_o), \\ + g_t &= tanh &(W_{xg} x_t + W_{hg} h_{t-1} + b_g), \\ + @f} + where @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices: + @f$W_{x?} \in R^{N_h \times N_x}@f$, @f$W_{h?} \in R^{N_h \times N_h}@f$, @f$b_? \in R^{N_h}@f$. + + For simplicity and performance purposes we use @f$ W_x = [W_{xi}; W_{xf}; W_{xo}, W_{xg}] @f$ + (i.e. @f$W_x@f$ is vertical concatenation of @f$ W_{x?} @f$), @f$ W_x \in R^{4N_h \times N_x} @f$. + The same for @f$ W_h = [W_{hi}; W_{hf}; W_{ho}, W_{hg}], W_h \in R^{4N_h \times N_h} @f$ + and for @f$ b = [b_i; b_f, b_o, b_g]@f$, @f$b \in R^{4N_h} @f$. + + @param Wh is matrix defining how previous output is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_h @f$) + @param Wx is matrix defining how current input is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_x @f$) + @param b is bias vector (i.e. according to above mentioned notation is @f$ b @f$) + */ + CV_DEPRECATED virtual void setWeights(const Mat &Wh, const Mat &Wx, const Mat &b) = 0; + + /** @brief Specifies shape of output blob which will be [[`T`], `N`] + @p outTailShape. + * @details If this parameter is empty or unset then @p outTailShape = [`Wh`.size(0)] will be used, + * where `Wh` is parameter from setWeights(). + */ + virtual void setOutShape(const MatShape &outTailShape = MatShape()) = 0; + + /** @deprecated Use flag `produce_cell_output` in LayerParams. + * @brief Specifies either interpret first dimension of input blob as timestamp dimenion either as sample. + * + * If flag is set to true then shape of input blob will be interpreted as [`T`, `N`, `[data dims]`] where `T` specifies number of timestamps, `N` is number of independent streams. + * In this case each forward() call will iterate through `T` timestamps and update layer's state `T` times. + * + * If flag is set to false then shape of input blob will be interpreted as [`N`, `[data dims]`]. + * In this case each forward() call will make one iteration and produce one timestamp with shape [`N`, `[out dims]`]. + */ + CV_DEPRECATED virtual void setUseTimstampsDim(bool use = true) = 0; + + /** @deprecated Use flag `use_timestamp_dim` in LayerParams. + * @brief If this flag is set to true then layer will produce @f$ c_t @f$ as second output. + * @details Shape of the second output is the same as first output. + */ + CV_DEPRECATED virtual void setProduceCellOutput(bool produce = false) = 0; + + /* In common case it use single input with @f$x_t@f$ values to compute output(s) @f$h_t@f$ (and @f$c_t@f$). + * @param input should contain packed values @f$x_t@f$ + * @param output contains computed outputs: @f$h_t@f$ (and @f$c_t@f$ if setProduceCellOutput() flag was set to true). + * + * If setUseTimstampsDim() is set to true then @p input[0] should has at least two dimensions with the following shape: [`T`, `N`, `[data dims]`], + * where `T` specifies number of timestamps, `N` is number of independent streams (i.e. @f$ x_{t_0 + t}^{stream} @f$ is stored inside @p input[0][t, stream, ...]). + * + * If setUseTimstampsDim() is set to false then @p input[0] should contain single timestamp, its shape should has form [`N`, `[data dims]`] with at least one dimension. + * (i.e. @f$ x_{t}^{stream} @f$ is stored inside @p input[0][stream, ...]). + */ + + int inputNameToIndex(String inputName) CV_OVERRIDE; + int outputNameToIndex(const String& outputName) CV_OVERRIDE; + }; + + /** @brief Classical recurrent layer + + Accepts two inputs @f$x_t@f$ and @f$h_{t-1}@f$ and compute two outputs @f$o_t@f$ and @f$h_t@f$. + + - input: should contain packed input @f$x_t@f$. + - output: should contain output @f$o_t@f$ (and @f$h_t@f$ if setProduceHiddenOutput() is set to true). + + input[0] should have shape [`T`, `N`, `data_dims`] where `T` and `N` is number of timestamps and number of independent samples of @f$x_t@f$ respectively. + + output[0] will have shape [`T`, `N`, @f$N_o@f$], where @f$N_o@f$ is number of rows in @f$ W_{xo} @f$ matrix. + + If setProduceHiddenOutput() is set to true then @p output[1] will contain a Mat with shape [`T`, `N`, @f$N_h@f$], where @f$N_h@f$ is number of rows in @f$ W_{hh} @f$ matrix. + */ + class CV_EXPORTS RNNLayer : public Layer + { + public: + /** Creates instance of RNNLayer */ + static Ptr create(const LayerParams& params); + + /** Setups learned weights. + + Recurrent-layer behavior on each step is defined by current input @f$ x_t @f$, previous state @f$ h_t @f$ and learned weights as follows: + @f{eqnarray*}{ + h_t &= tanh&(W_{hh} h_{t-1} + W_{xh} x_t + b_h), \\ + o_t &= tanh&(W_{ho} h_t + b_o), + @f} + + @param Wxh is @f$ W_{xh} @f$ matrix + @param bh is @f$ b_{h} @f$ vector + @param Whh is @f$ W_{hh} @f$ matrix + @param Who is @f$ W_{xo} @f$ matrix + @param bo is @f$ b_{o} @f$ vector + */ + virtual void setWeights(const Mat &Wxh, const Mat &bh, const Mat &Whh, const Mat &Who, const Mat &bo) = 0; + + /** @brief If this flag is set to true then layer will produce @f$ h_t @f$ as second output. + * @details Shape of the second output is the same as first output. + */ + virtual void setProduceHiddenOutput(bool produce = false) = 0; + + }; + + class CV_EXPORTS BaseConvolutionLayer : public Layer + { + public: + CV_DEPRECATED_EXTERNAL Size kernel, stride, pad, dilation, adjustPad; + std::vector adjust_pads; + std::vector kernel_size, strides, dilations; + std::vector pads_begin, pads_end; + String padMode; + int numOutput; + }; + + class CV_EXPORTS ConvolutionLayer : public BaseConvolutionLayer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS DeconvolutionLayer : public BaseConvolutionLayer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS LRNLayer : public Layer + { + public: + int type; + + int size; + float alpha, beta, bias; + bool normBySize; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS PoolingLayer : public Layer + { + public: + int type; + std::vector kernel_size, strides; + std::vector pads_begin, pads_end; + CV_DEPRECATED_EXTERNAL Size kernel, stride, pad; + CV_DEPRECATED_EXTERNAL int pad_l, pad_t, pad_r, pad_b; + bool globalPooling; + bool computeMaxIdx; + String padMode; + bool ceilMode; + // If true for average pooling with padding, divide an every output region + // by a whole kernel area. Otherwise exclude zero padded values and divide + // by number of real values. + bool avePoolPaddedArea; + // ROIPooling parameters. + Size pooledSize; + float spatialScale; + // PSROIPooling parameters. + int psRoiOutChannels; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS SoftmaxLayer : public Layer + { + public: + bool logSoftMax; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS InnerProductLayer : public Layer + { + public: + int axis; + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS MVNLayer : public Layer + { + public: + float eps; + bool normVariance, acrossChannels; + + static Ptr create(const LayerParams& params); + }; + + /* Reshaping */ + + class CV_EXPORTS ReshapeLayer : public Layer + { + public: + MatShape newShapeDesc; + Range newShapeRange; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS FlattenLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ConcatLayer : public Layer + { + public: + int axis; + /** + * @brief Add zero padding in case of concatenation of blobs with different + * spatial sizes. + * + * Details: https://github.com/torch/nn/blob/master/doc/containers.md#depthconcat + */ + bool padding; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS SplitLayer : public Layer + { + public: + int outputsCount; //!< Number of copies that will be produced (is ignored when negative). + + static Ptr create(const LayerParams ¶ms); + }; + + /** + * Slice layer has several modes: + * 1. Caffe mode + * @param[in] axis Axis of split operation + * @param[in] slice_point Array of split points + * + * Number of output blobs equals to number of split points plus one. The + * first blob is a slice on input from 0 to @p slice_point[0] - 1 by @p axis, + * the second output blob is a slice of input from @p slice_point[0] to + * @p slice_point[1] - 1 by @p axis and the last output blob is a slice of + * input from @p slice_point[-1] up to the end of @p axis size. + * + * 2. TensorFlow mode + * @param begin Vector of start indices + * @param size Vector of sizes + * + * More convenient numpy-like slice. One and only output blob + * is a slice `input[begin[0]:begin[0]+size[0], begin[1]:begin[1]+size[1], ...]` + * + * 3. Torch mode + * @param axis Axis of split operation + * + * Split input blob on the equal parts by @p axis. + */ + class CV_EXPORTS SliceLayer : public Layer + { + public: + /** + * @brief Vector of slice ranges. + * + * The first dimension equals number of output blobs. + * Inner vector has slice ranges for the first number of input dimensions. + */ + std::vector > sliceRanges; + int axis; + int num_split; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS PermuteLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + /** + * Permute channels of 4-dimensional input blob. + * @param group Number of groups to split input channels and pick in turns + * into output blob. + * + * \f[ groupSize = \frac{number\ of\ channels}{group} \f] + * \f[ output(n, c, h, w) = input(n, groupSize \times (c \% group) + \lfloor \frac{c}{group} \rfloor, h, w) \f] + * Read more at https://arxiv.org/pdf/1707.01083.pdf + */ + class CV_EXPORTS ShuffleChannelLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + + int group; + }; + + /** + * @brief Adds extra values for specific axes. + * @param paddings Vector of paddings in format + * @code + * [ pad_before, pad_after, // [0]th dimension + * pad_before, pad_after, // [1]st dimension + * ... + * pad_before, pad_after ] // [n]th dimension + * @endcode + * that represents number of padded values at every dimension + * starting from the first one. The rest of dimensions won't + * be padded. + * @param value Value to be padded. Defaults to zero. + * @param type Padding type: 'constant', 'reflect' + * @param input_dims Torch's parameter. If @p input_dims is not equal to the + * actual input dimensionality then the `[0]th` dimension + * is considered as a batch dimension and @p paddings are shifted + * to a one dimension. Defaults to `-1` that means padding + * corresponding to @p paddings. + */ + class CV_EXPORTS PaddingLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + /* Activations */ + class CV_EXPORTS ActivationLayer : public Layer + { + public: + virtual void forwardSlice(const float* src, float* dst, int len, + size_t outPlaneSize, int cn0, int cn1) const = 0; + }; + + class CV_EXPORTS ReLULayer : public ActivationLayer + { + public: + float negativeSlope; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ReLU6Layer : public ActivationLayer + { + public: + float minValue, maxValue; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ChannelsPReLULayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ELULayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS TanHLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS SwishLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS MishLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS SigmoidLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS BNLLLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS AbsLayer : public ActivationLayer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS PowerLayer : public ActivationLayer + { + public: + float power, scale, shift; + + static Ptr create(const LayerParams ¶ms); + }; + + /* Layers used in semantic segmentation */ + + class CV_EXPORTS CropLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + /** @brief Element wise operation on inputs + + Extra optional parameters: + - "operation" as string. Values are "sum" (default), "prod", "max", "div" + - "coeff" as float array. Specify weights of inputs for SUM operation + - "output_channels_mode" as string. Values are "same" (default, all input must have the same layout), "input_0", "input_0_truncate", "max_input_channels" + */ + class CV_EXPORTS EltwiseLayer : public Layer + { + public: + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS BatchNormLayer : public ActivationLayer + { + public: + bool hasWeights, hasBias; + float epsilon; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS MaxUnpoolLayer : public Layer + { + public: + Size poolKernel; + Size poolPad; + Size poolStride; + + static Ptr create(const LayerParams ¶ms); + }; + + class CV_EXPORTS ScaleLayer : public Layer + { + public: + bool hasBias; + int axis; + + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ShiftLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS PriorBoxLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ReorgLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS RegionLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS DetectionOutputLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + /** + * @brief \f$ L_p \f$ - normalization layer. + * @param p Normalization factor. The most common `p = 1` for \f$ L_1 \f$ - + * normalization or `p = 2` for \f$ L_2 \f$ - normalization or a custom one. + * @param eps Parameter \f$ \epsilon \f$ to prevent a division by zero. + * @param across_spatial If true, normalize an input across all non-batch dimensions. + * Otherwise normalize an every channel separately. + * + * Across spatial: + * @f[ + * norm = \sqrt[p]{\epsilon + \sum_{x, y, c} |src(x, y, c)|^p } \\ + * dst(x, y, c) = \frac{ src(x, y, c) }{norm} + * @f] + * + * Channel wise normalization: + * @f[ + * norm(c) = \sqrt[p]{\epsilon + \sum_{x, y} |src(x, y, c)|^p } \\ + * dst(x, y, c) = \frac{ src(x, y, c) }{norm(c)} + * @f] + * + * Where `x, y` - spatial coordinates, `c` - channel. + * + * An every sample in the batch is normalized separately. Optionally, + * output is scaled by the trained parameters. + */ + class CV_EXPORTS NormalizeBBoxLayer : public Layer + { + public: + float pnorm, epsilon; + CV_DEPRECATED_EXTERNAL bool acrossSpatial; + + static Ptr create(const LayerParams& params); + }; + + /** + * @brief Resize input 4-dimensional blob by nearest neighbor or bilinear strategy. + * + * Layer is used to support TensorFlow's resize_nearest_neighbor and resize_bilinear ops. + */ + class CV_EXPORTS ResizeLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + /** + * @brief Bilinear resize layer from https://github.com/cdmh/deeplab-public-ver2 + * + * It differs from @ref ResizeLayer in output shape and resize scales computations. + */ + class CV_EXPORTS InterpLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS ProposalLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + + class CV_EXPORTS CropAndResizeLayer : public Layer + { + public: + static Ptr create(const LayerParams& params); + }; + +//! @} +//! @} +CV__DNN_INLINE_NS_END +} +} +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dict.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dict.hpp new file mode 100644 index 0000000000000000000000000000000000000000..463d314bee574e5d98d6a6fc3b54179fe32573e5 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dict.hpp @@ -0,0 +1,160 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include +#include +#include + +#include + +#ifndef OPENCV_DNN_DNN_DICT_HPP +#define OPENCV_DNN_DNN_DICT_HPP + +namespace cv { +namespace dnn { +CV__DNN_INLINE_NS_BEGIN +//! @addtogroup dnn +//! @{ + +/** @brief This struct stores the scalar value (or array) of one of the following type: double, cv::String or int64. + * @todo Maybe int64 is useless because double type exactly stores at least 2^52 integers. + */ +struct CV_EXPORTS_W DictValue +{ + DictValue(const DictValue &r); + DictValue(bool i) : type(Param::INT), pi(new AutoBuffer) { (*pi)[0] = i ? 1 : 0; } //!< Constructs integer scalar + DictValue(int64 i = 0) : type(Param::INT), pi(new AutoBuffer) { (*pi)[0] = i; } //!< Constructs integer scalar + CV_WRAP DictValue(int i) : type(Param::INT), pi(new AutoBuffer) { (*pi)[0] = i; } //!< Constructs integer scalar + DictValue(unsigned p) : type(Param::INT), pi(new AutoBuffer) { (*pi)[0] = p; } //!< Constructs integer scalar + CV_WRAP DictValue(double p) : type(Param::REAL), pd(new AutoBuffer) { (*pd)[0] = p; } //!< Constructs floating point scalar + CV_WRAP DictValue(const String &s) : type(Param::STRING), ps(new AutoBuffer) { (*ps)[0] = s; } //!< Constructs string scalar + DictValue(const char *s) : type(Param::STRING), ps(new AutoBuffer) { (*ps)[0] = s; } //!< @overload + + template + static DictValue arrayInt(TypeIter begin, int size); //!< Constructs integer array + template + static DictValue arrayReal(TypeIter begin, int size); //!< Constructs floating point array + template + static DictValue arrayString(TypeIter begin, int size); //!< Constructs array of strings + + template + T get(int idx = -1) const; //!< Tries to convert array element with specified index to requested type and returns its. + + int size() const; + + CV_WRAP bool isInt() const; + CV_WRAP bool isString() const; + CV_WRAP bool isReal() const; + + CV_WRAP int getIntValue(int idx = -1) const; + CV_WRAP double getRealValue(int idx = -1) const; + CV_WRAP String getStringValue(int idx = -1) const; + + DictValue &operator=(const DictValue &r); + + friend std::ostream &operator<<(std::ostream &stream, const DictValue &dictv); + + ~DictValue(); + +private: + + Param type; + + union + { + AutoBuffer *pi; + AutoBuffer *pd; + AutoBuffer *ps; + void *pv; + }; + + DictValue(Param _type, void *_p) : type(_type), pv(_p) {} + void release(); +}; + +/** @brief This class implements name-value dictionary, values are instances of DictValue. */ +class CV_EXPORTS Dict +{ + typedef std::map _Dict; + _Dict dict; + +public: + + //! Checks a presence of the @p key in the dictionary. + bool has(const String &key) const; + + //! If the @p key in the dictionary then returns pointer to its value, else returns NULL. + DictValue *ptr(const String &key); + + /** @overload */ + const DictValue *ptr(const String &key) const; + + //! If the @p key in the dictionary then returns its value, else an error will be generated. + const DictValue &get(const String &key) const; + + /** @overload */ + template + T get(const String &key) const; + + //! If the @p key in the dictionary then returns its value, else returns @p defaultValue. + template + T get(const String &key, const T &defaultValue) const; + + //! Sets new @p value for the @p key, or adds new key-value pair into the dictionary. + template + const T &set(const String &key, const T &value); + + //! Erase @p key from the dictionary. + void erase(const String &key); + + friend std::ostream &operator<<(std::ostream &stream, const Dict &dict); + + std::map::const_iterator begin() const; + + std::map::const_iterator end() const; +}; + +//! @} +CV__DNN_INLINE_NS_END +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dnn.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dnn.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d25096fbb7cc4d4a64035ecf5ebcc4c52acf43a9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dnn.hpp @@ -0,0 +1,1291 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_HPP +#define OPENCV_DNN_DNN_HPP + +#include +#include +#include "opencv2/core/async.hpp" + +#include "../dnn/version.hpp" + +#include + +namespace cv { +namespace dnn { +CV__DNN_INLINE_NS_BEGIN +//! @addtogroup dnn +//! @{ + + typedef std::vector MatShape; + + /** + * @brief Enum of computation backends supported by layers. + * @see Net::setPreferableBackend + */ + enum Backend + { + //! DNN_BACKEND_DEFAULT equals to DNN_BACKEND_INFERENCE_ENGINE if + //! OpenCV is built with Intel's Inference Engine library or + //! DNN_BACKEND_OPENCV otherwise. + DNN_BACKEND_DEFAULT = 0, + DNN_BACKEND_HALIDE, + DNN_BACKEND_INFERENCE_ENGINE, //!< Intel's Inference Engine computational backend + //!< @sa setInferenceEngineBackendType + DNN_BACKEND_OPENCV, + DNN_BACKEND_VKCOM, + DNN_BACKEND_CUDA, +#ifdef __OPENCV_BUILD + DNN_BACKEND_INFERENCE_ENGINE_NGRAPH = 1000000, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType() + DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType() +#endif + }; + + /** + * @brief Enum of target devices for computations. + * @see Net::setPreferableTarget + */ + enum Target + { + DNN_TARGET_CPU, + DNN_TARGET_OPENCL, + DNN_TARGET_OPENCL_FP16, + DNN_TARGET_MYRIAD, + DNN_TARGET_VULKAN, + DNN_TARGET_FPGA, //!< FPGA device with CPU fallbacks using Inference Engine's Heterogeneous plugin. + DNN_TARGET_CUDA, + DNN_TARGET_CUDA_FP16 + }; + + CV_EXPORTS std::vector< std::pair > getAvailableBackends(); + CV_EXPORTS std::vector getAvailableTargets(Backend be); + + /** @brief This class provides all data needed to initialize layer. + * + * It includes dictionary with scalar params (which can be read by using Dict interface), + * blob params #blobs and optional meta information: #name and #type of layer instance. + */ + class CV_EXPORTS LayerParams : public Dict + { + public: + //TODO: Add ability to name blob params + std::vector blobs; //!< List of learned parameters stored as blobs. + + String name; //!< Name of the layer instance (optional, can be used internal purposes). + String type; //!< Type name which was used for creating layer by layer factory (optional). + }; + + /** + * @brief Derivatives of this class encapsulates functions of certain backends. + */ + class BackendNode + { + public: + BackendNode(int backendId); + + virtual ~BackendNode(); //!< Virtual destructor to make polymorphism. + + int backendId; //!< Backend identifier. + }; + + /** + * @brief Derivatives of this class wraps cv::Mat for different backends and targets. + */ + class BackendWrapper + { + public: + BackendWrapper(int backendId, int targetId); + + /** + * @brief Wrap cv::Mat for specific backend and target. + * @param[in] targetId Target identifier. + * @param[in] m cv::Mat for wrapping. + * + * Make CPU->GPU data transfer if it's require for the target. + */ + BackendWrapper(int targetId, const cv::Mat& m); + + /** + * @brief Make wrapper for reused cv::Mat. + * @param[in] base Wrapper of cv::Mat that will be reused. + * @param[in] shape Specific shape. + * + * Initialize wrapper from another one. It'll wrap the same host CPU + * memory and mustn't allocate memory on device(i.e. GPU). It might + * has different shape. Use in case of CPU memory reusing for reuse + * associated memory on device too. + */ + BackendWrapper(const Ptr& base, const MatShape& shape); + + virtual ~BackendWrapper(); //!< Virtual destructor to make polymorphism. + + /** + * @brief Transfer data to CPU host memory. + */ + virtual void copyToHost() = 0; + + /** + * @brief Indicate that an actual data is on CPU. + */ + virtual void setHostDirty() = 0; + + int backendId; //!< Backend identifier. + int targetId; //!< Target identifier. + }; + + class CV_EXPORTS ActivationLayer; + + /** @brief This interface class allows to build new Layers - are building blocks of networks. + * + * Each class, derived from Layer, must implement allocate() methods to declare own outputs and forward() to compute outputs. + * Also before using the new layer into networks you must register your layer by using one of @ref dnnLayerFactory "LayerFactory" macros. + */ + class CV_EXPORTS_W Layer : public Algorithm + { + public: + + //! List of learned parameters must be stored here to allow read them by using Net::getParam(). + CV_PROP_RW std::vector blobs; + + /** @brief Computes and sets internal parameters according to inputs, outputs and blobs. + * @deprecated Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead + * @param[in] input vector of already allocated input blobs + * @param[out] output vector of already allocated output blobs + * + * If this method is called after network has allocated all memory for input and output blobs + * and before inferencing. + */ + CV_DEPRECATED_EXTERNAL + virtual void finalize(const std::vector &input, std::vector &output); + + /** @brief Computes and sets internal parameters according to inputs, outputs and blobs. + * @param[in] inputs vector of already allocated input blobs + * @param[out] outputs vector of already allocated output blobs + * + * If this method is called after network has allocated all memory for input and output blobs + * and before inferencing. + */ + CV_WRAP virtual void finalize(InputArrayOfArrays inputs, OutputArrayOfArrays outputs); + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @deprecated Use Layer::forward(InputArrayOfArrays, OutputArrayOfArrays, OutputArrayOfArrays) instead + * @param[in] input the input blobs. + * @param[out] output allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + CV_DEPRECATED_EXTERNAL + virtual void forward(std::vector &input, std::vector &output, std::vector &internals); + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @param[in] inputs the input blobs. + * @param[out] outputs allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + virtual void forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals); + + /** @brief Given the @p input blobs, computes the output @p blobs. + * @param[in] inputs the input blobs. + * @param[out] outputs allocated output blobs, which will store results of the computation. + * @param[out] internals allocated internal blobs + */ + void forward_fallback(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals); + + /** @brief + * @overload + * @deprecated Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead + */ + CV_DEPRECATED_EXTERNAL + void finalize(const std::vector &inputs, CV_OUT std::vector &outputs); + + /** @brief + * @overload + * @deprecated Use Layer::finalize(InputArrayOfArrays, OutputArrayOfArrays) instead + */ + CV_DEPRECATED std::vector finalize(const std::vector &inputs); + + /** @brief Allocates layer and computes output. + * @deprecated This method will be removed in the future release. + */ + CV_DEPRECATED CV_WRAP void run(const std::vector &inputs, CV_OUT std::vector &outputs, + CV_IN_OUT std::vector &internals); + + /** @brief Returns index of input blob into the input array. + * @param inputName label of input blob + * + * Each layer input and output can be labeled to easily identify them using "%[.output_name]" notation. + * This method maps label of input blob to its index into input vector. + */ + virtual int inputNameToIndex(String inputName); + /** @brief Returns index of output blob in output array. + * @see inputNameToIndex() + */ + CV_WRAP virtual int outputNameToIndex(const String& outputName); + + /** + * @brief Ask layer if it support specific backend for doing computations. + * @param[in] backendId computation backend identifier. + * @see Backend + */ + virtual bool supportBackend(int backendId); + + /** + * @brief Returns Halide backend node. + * @param[in] inputs Input Halide buffers. + * @see BackendNode, BackendWrapper + * + * Input buffers should be exactly the same that will be used in forward invocations. + * Despite we can use Halide::ImageParam based on input shape only, + * it helps prevent some memory management issues (if something wrong, + * Halide tests will be failed). + */ + virtual Ptr initHalide(const std::vector > &inputs); + + virtual Ptr initInfEngine(const std::vector > &inputs); + + virtual Ptr initNgraph(const std::vector > &inputs, const std::vector >& nodes); + + virtual Ptr initVkCom(const std::vector > &inputs); + + /** + * @brief Returns a CUDA backend node + * + * @param context void pointer to CSLContext object + * @param inputs layer inputs + * @param outputs layer outputs + */ + virtual Ptr initCUDA( + void *context, + const std::vector>& inputs, + const std::vector>& outputs + ); + + /** + * @brief Automatic Halide scheduling based on layer hyper-parameters. + * @param[in] node Backend node with Halide functions. + * @param[in] inputs Blobs that will be used in forward invocations. + * @param[in] outputs Blobs that will be used in forward invocations. + * @param[in] targetId Target identifier + * @see BackendNode, Target + * + * Layer don't use own Halide::Func members because we can have applied + * layers fusing. In this way the fused function should be scheduled. + */ + virtual void applyHalideScheduler(Ptr& node, + const std::vector &inputs, + const std::vector &outputs, + int targetId) const; + + /** + * @brief Implement layers fusing. + * @param[in] node Backend node of bottom layer. + * @see BackendNode + * + * Actual for graph-based backends. If layer attached successfully, + * returns non-empty cv::Ptr to node of the same backend. + * Fuse only over the last function. + */ + virtual Ptr tryAttach(const Ptr& node); + + /** + * @brief Tries to attach to the layer the subsequent activation layer, i.e. do the layer fusion in a partial case. + * @param[in] layer The subsequent activation layer. + * + * Returns true if the activation layer has been attached successfully. + */ + virtual bool setActivation(const Ptr& layer); + + /** + * @brief Try to fuse current layer with a next one + * @param[in] top Next layer to be fused. + * @returns True if fusion was performed. + */ + virtual bool tryFuse(Ptr& top); + + /** + * @brief Returns parameters of layers with channel-wise multiplication and addition. + * @param[out] scale Channel-wise multipliers. Total number of values should + * be equal to number of channels. + * @param[out] shift Channel-wise offsets. Total number of values should + * be equal to number of channels. + * + * Some layers can fuse their transformations with further layers. + * In example, convolution + batch normalization. This way base layer + * use weights from layer after it. Fused layer is skipped. + * By default, @p scale and @p shift are empty that means layer has no + * element-wise multiplications or additions. + */ + virtual void getScaleShift(Mat& scale, Mat& shift) const; + + /** + * @brief "Deattaches" all the layers, attached to particular layer. + */ + virtual void unsetAttached(); + + virtual bool getMemoryShapes(const std::vector &inputs, + const int requiredOutputs, + std::vector &outputs, + std::vector &internals) const; + virtual int64 getFLOPS(const std::vector &inputs, + const std::vector &outputs) const {CV_UNUSED(inputs); CV_UNUSED(outputs); return 0;} + + CV_PROP String name; //!< Name of the layer instance, can be used for logging or other internal purposes. + CV_PROP String type; //!< Type name which was used for creating layer by layer factory. + CV_PROP int preferableTarget; //!< prefer target for layer forwarding + + Layer(); + explicit Layer(const LayerParams ¶ms); //!< Initializes only #name, #type and #blobs fields. + void setParamsFrom(const LayerParams ¶ms); //!< Initializes only #name, #type and #blobs fields. + virtual ~Layer(); + }; + + /** @brief This class allows to create and manipulate comprehensive artificial neural networks. + * + * Neural network is presented as directed acyclic graph (DAG), where vertices are Layer instances, + * and edges specify relationships between layers inputs and outputs. + * + * Each network layer has unique integer id and unique string name inside its network. + * LayerId can store either layer name or layer id. + * + * This class supports reference counting of its instances, i. e. copies point to the same instance. + */ + class CV_EXPORTS_W_SIMPLE Net + { + public: + + CV_WRAP Net(); //!< Default constructor. + CV_WRAP ~Net(); //!< Destructor frees the net only if there aren't references to the net anymore. + + /** @brief Create a network from Intel's Model Optimizer intermediate representation (IR). + * @param[in] xml XML configuration file with network's topology. + * @param[in] bin Binary file with trained weights. + * Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine + * backend. + */ + CV_WRAP static Net readFromModelOptimizer(const String& xml, const String& bin); + + /** @brief Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR). + * @param[in] bufferModelConfig buffer with model's configuration. + * @param[in] bufferWeights buffer with model's trained weights. + * @returns Net object. + */ + CV_WRAP static + Net readFromModelOptimizer(const std::vector& bufferModelConfig, const std::vector& bufferWeights); + + /** @brief Create a network from Intel's Model Optimizer in-memory buffers with intermediate representation (IR). + * @param[in] bufferModelConfigPtr buffer pointer of model's configuration. + * @param[in] bufferModelConfigSize buffer size of model's configuration. + * @param[in] bufferWeightsPtr buffer pointer of model's trained weights. + * @param[in] bufferWeightsSize buffer size of model's trained weights. + * @returns Net object. + */ + static + Net readFromModelOptimizer(const uchar* bufferModelConfigPtr, size_t bufferModelConfigSize, + const uchar* bufferWeightsPtr, size_t bufferWeightsSize); + + /** Returns true if there are no layers in the network. */ + CV_WRAP bool empty() const; + + /** @brief Dump net to String + * @returns String with structure, hyperparameters, backend, target and fusion + * Call method after setInput(). To see correct backend, target and fusion run after forward(). + */ + CV_WRAP String dump(); + /** @brief Dump net structure, hyperparameters, backend, target and fusion to dot file + * @param path path to output file with .dot extension + * @see dump() + */ + CV_WRAP void dumpToFile(const String& path); + /** @brief Adds new layer to the net. + * @param name unique name of the adding layer. + * @param type typename of the adding layer (type must be registered in LayerRegister). + * @param params parameters which will be used to initialize the creating layer. + * @returns unique identifier of created layer, or -1 if a failure will happen. + */ + int addLayer(const String &name, const String &type, LayerParams ¶ms); + /** @brief Adds new layer and connects its first input to the first output of previously added layer. + * @see addLayer() + */ + int addLayerToPrev(const String &name, const String &type, LayerParams ¶ms); + + /** @brief Converts string name of the layer to the integer identifier. + * @returns id of the layer, or -1 if the layer wasn't found. + */ + CV_WRAP int getLayerId(const String &layer); + + CV_WRAP std::vector getLayerNames() const; + + /** @brief Container for strings and integers. */ + typedef DictValue LayerId; + + /** @brief Returns pointer to layer with specified id or name which the network use. */ + CV_WRAP Ptr getLayer(LayerId layerId); + + /** @brief Returns pointers to input layers of specific layer. */ + std::vector > getLayerInputs(LayerId layerId); // FIXIT: CV_WRAP + + /** @brief Connects output of the first layer to input of the second layer. + * @param outPin descriptor of the first layer output. + * @param inpPin descriptor of the second layer input. + * + * Descriptors have the following template <layer_name>[.input_number]: + * - the first part of the template layer_name is string name of the added layer. + * If this part is empty then the network input pseudo layer will be used; + * - the second optional part of the template input_number + * is either number of the layer input, either label one. + * If this part is omitted then the first layer input will be used. + * + * @see setNetInputs(), Layer::inputNameToIndex(), Layer::outputNameToIndex() + */ + CV_WRAP void connect(String outPin, String inpPin); + + /** @brief Connects #@p outNum output of the first layer to #@p inNum input of the second layer. + * @param outLayerId identifier of the first layer + * @param outNum number of the first layer output + * @param inpLayerId identifier of the second layer + * @param inpNum number of the second layer input + */ + void connect(int outLayerId, int outNum, int inpLayerId, int inpNum); + + /** @brief Sets outputs names of the network input pseudo layer. + * + * Each net always has special own the network input pseudo layer with id=0. + * This layer stores the user blobs only and don't make any computations. + * In fact, this layer provides the only way to pass user data into the network. + * As any other layer, this layer can label its outputs and this function provides an easy way to do this. + */ + CV_WRAP void setInputsNames(const std::vector &inputBlobNames); + + /** @brief Runs forward pass to compute output of layer with name @p outputName. + * @param outputName name for layer which output is needed to get + * @return blob for first output of specified layer. + * @details By default runs forward pass for the whole network. + */ + CV_WRAP Mat forward(const String& outputName = String()); + + /** @brief Runs forward pass to compute output of layer with name @p outputName. + * @param outputName name for layer which output is needed to get + * @details By default runs forward pass for the whole network. + * + * This is an asynchronous version of forward(const String&). + * dnn::DNN_BACKEND_INFERENCE_ENGINE backend is required. + */ + CV_WRAP AsyncArray forwardAsync(const String& outputName = String()); + + /** @brief Runs forward pass to compute output of layer with name @p outputName. + * @param outputBlobs contains all output blobs for specified layer. + * @param outputName name for layer which output is needed to get + * @details If @p outputName is empty, runs forward pass for the whole network. + */ + CV_WRAP void forward(OutputArrayOfArrays outputBlobs, const String& outputName = String()); + + /** @brief Runs forward pass to compute outputs of layers listed in @p outBlobNames. + * @param outputBlobs contains blobs for first outputs of specified layers. + * @param outBlobNames names for layers which outputs are needed to get + */ + CV_WRAP void forward(OutputArrayOfArrays outputBlobs, + const std::vector& outBlobNames); + + /** @brief Runs forward pass to compute outputs of layers listed in @p outBlobNames. + * @param outputBlobs contains all output blobs for each layer specified in @p outBlobNames. + * @param outBlobNames names for layers which outputs are needed to get + */ + CV_WRAP_AS(forwardAndRetrieve) void forward(CV_OUT std::vector >& outputBlobs, + const std::vector& outBlobNames); + + /** + * @brief Compile Halide layers. + * @param[in] scheduler Path to YAML file with scheduling directives. + * @see setPreferableBackend + * + * Schedule layers that support Halide backend. Then compile them for + * specific target. For layers that not represented in scheduling file + * or if no manual scheduling used at all, automatic scheduling will be applied. + */ + CV_WRAP void setHalideScheduler(const String& scheduler); + + /** + * @brief Ask network to use specific computation backend where it supported. + * @param[in] backendId backend identifier. + * @see Backend + * + * If OpenCV is compiled with Intel's Inference Engine library, DNN_BACKEND_DEFAULT + * means DNN_BACKEND_INFERENCE_ENGINE. Otherwise it equals to DNN_BACKEND_OPENCV. + */ + CV_WRAP void setPreferableBackend(int backendId); + + /** + * @brief Ask network to make computations on specific target device. + * @param[in] targetId target identifier. + * @see Target + * + * List of supported combinations backend / target: + * | | DNN_BACKEND_OPENCV | DNN_BACKEND_INFERENCE_ENGINE | DNN_BACKEND_HALIDE | DNN_BACKEND_CUDA | + * |------------------------|--------------------|------------------------------|--------------------|-------------------| + * | DNN_TARGET_CPU | + | + | + | | + * | DNN_TARGET_OPENCL | + | + | + | | + * | DNN_TARGET_OPENCL_FP16 | + | + | | | + * | DNN_TARGET_MYRIAD | | + | | | + * | DNN_TARGET_FPGA | | + | | | + * | DNN_TARGET_CUDA | | | | + | + * | DNN_TARGET_CUDA_FP16 | | | | + | + */ + CV_WRAP void setPreferableTarget(int targetId); + + /** @brief Sets the new input value for the network + * @param blob A new blob. Should have CV_32F or CV_8U depth. + * @param name A name of input layer. + * @param scalefactor An optional normalization scale. + * @param mean An optional mean subtraction values. + * @see connect(String, String) to know format of the descriptor. + * + * If scale or mean values are specified, a final input blob is computed + * as: + * \f[input(n,c,h,w) = scalefactor \times (blob(n,c,h,w) - mean_c)\f] + */ + CV_WRAP void setInput(InputArray blob, const String& name = "", + double scalefactor = 1.0, const Scalar& mean = Scalar()); + + /** @brief Sets the new value for the learned param of the layer. + * @param layer name or id of the layer. + * @param numParam index of the layer parameter in the Layer::blobs array. + * @param blob the new value. + * @see Layer::blobs + * @note If shape of the new blob differs from the previous shape, + * then the following forward pass may fail. + */ + CV_WRAP void setParam(LayerId layer, int numParam, const Mat &blob); + + /** @brief Returns parameter blob of the layer. + * @param layer name or id of the layer. + * @param numParam index of the layer parameter in the Layer::blobs array. + * @see Layer::blobs + */ + CV_WRAP Mat getParam(LayerId layer, int numParam = 0); + + /** @brief Returns indexes of layers with unconnected outputs. + */ + CV_WRAP std::vector getUnconnectedOutLayers() const; + + /** @brief Returns names of layers with unconnected outputs. + */ + CV_WRAP std::vector getUnconnectedOutLayersNames() const; + + /** @brief Returns input and output shapes for all layers in loaded model; + * preliminary inferencing isn't necessary. + * @param netInputShapes shapes for all input blobs in net input layer. + * @param layersIds output parameter for layer IDs. + * @param inLayersShapes output parameter for input layers shapes; + * order is the same as in layersIds + * @param outLayersShapes output parameter for output layers shapes; + * order is the same as in layersIds + */ + CV_WRAP void getLayersShapes(const std::vector& netInputShapes, + CV_OUT std::vector& layersIds, + CV_OUT std::vector >& inLayersShapes, + CV_OUT std::vector >& outLayersShapes) const; + + /** @overload */ + CV_WRAP void getLayersShapes(const MatShape& netInputShape, + CV_OUT std::vector& layersIds, + CV_OUT std::vector >& inLayersShapes, + CV_OUT std::vector >& outLayersShapes) const; + + /** @brief Returns input and output shapes for layer with specified + * id in loaded model; preliminary inferencing isn't necessary. + * @param netInputShape shape input blob in net input layer. + * @param layerId id for layer. + * @param inLayerShapes output parameter for input layers shapes; + * order is the same as in layersIds + * @param outLayerShapes output parameter for output layers shapes; + * order is the same as in layersIds + */ + void getLayerShapes(const MatShape& netInputShape, + const int layerId, + CV_OUT std::vector& inLayerShapes, + CV_OUT std::vector& outLayerShapes) const; // FIXIT: CV_WRAP + + /** @overload */ + void getLayerShapes(const std::vector& netInputShapes, + const int layerId, + CV_OUT std::vector& inLayerShapes, + CV_OUT std::vector& outLayerShapes) const; // FIXIT: CV_WRAP + + /** @brief Computes FLOP for whole loaded model with specified input shapes. + * @param netInputShapes vector of shapes for all net inputs. + * @returns computed FLOP. + */ + CV_WRAP int64 getFLOPS(const std::vector& netInputShapes) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const MatShape& netInputShape) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const int layerId, + const std::vector& netInputShapes) const; + /** @overload */ + CV_WRAP int64 getFLOPS(const int layerId, + const MatShape& netInputShape) const; + + /** @brief Returns list of types for layer used in model. + * @param layersTypes output parameter for returning types. + */ + CV_WRAP void getLayerTypes(CV_OUT std::vector& layersTypes) const; + + /** @brief Returns count of layers of specified type. + * @param layerType type. + * @returns count of layers + */ + CV_WRAP int getLayersCount(const String& layerType) const; + + /** @brief Computes bytes number which are required to store + * all weights and intermediate blobs for model. + * @param netInputShapes vector of shapes for all net inputs. + * @param weights output parameter to store resulting bytes for weights. + * @param blobs output parameter to store resulting bytes for intermediate blobs. + */ + void getMemoryConsumption(const std::vector& netInputShapes, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; // FIXIT: CV_WRAP + /** @overload */ + CV_WRAP void getMemoryConsumption(const MatShape& netInputShape, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + /** @overload */ + CV_WRAP void getMemoryConsumption(const int layerId, + const std::vector& netInputShapes, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + /** @overload */ + CV_WRAP void getMemoryConsumption(const int layerId, + const MatShape& netInputShape, + CV_OUT size_t& weights, CV_OUT size_t& blobs) const; + + /** @brief Computes bytes number which are required to store + * all weights and intermediate blobs for each layer. + * @param netInputShapes vector of shapes for all net inputs. + * @param layerIds output vector to save layer IDs. + * @param weights output parameter to store resulting bytes for weights. + * @param blobs output parameter to store resulting bytes for intermediate blobs. + */ + void getMemoryConsumption(const std::vector& netInputShapes, + CV_OUT std::vector& layerIds, + CV_OUT std::vector& weights, + CV_OUT std::vector& blobs) const; // FIXIT: CV_WRAP + /** @overload */ + void getMemoryConsumption(const MatShape& netInputShape, + CV_OUT std::vector& layerIds, + CV_OUT std::vector& weights, + CV_OUT std::vector& blobs) const; // FIXIT: CV_WRAP + + /** @brief Enables or disables layer fusion in the network. + * @param fusion true to enable the fusion, false to disable. The fusion is enabled by default. + */ + CV_WRAP void enableFusion(bool fusion); + + /** @brief Returns overall time for inference and timings (in ticks) for layers. + * Indexes in returned vector correspond to layers ids. Some layers can be fused with others, + * in this case zero ticks count will be return for that skipped layers. + * @param timings vector for tick timings for all layers. + * @return overall ticks for model inference. + */ + CV_WRAP int64 getPerfProfile(CV_OUT std::vector& timings); + + private: + struct Impl; + Ptr impl; + }; + + /** @brief Reads a network model stored in Darknet model files. + * @param cfgFile path to the .cfg file with text description of the network architecture. + * @param darknetModel path to the .weights file with learned network. + * @returns Network object that ready to do forward, throw an exception in failure cases. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromDarknet(const String &cfgFile, const String &darknetModel = String()); + + /** @brief Reads a network model stored in Darknet model files. + * @param bufferCfg A buffer contains a content of .cfg file with text description of the network architecture. + * @param bufferModel A buffer contains a content of .weights file with learned network. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromDarknet(const std::vector& bufferCfg, + const std::vector& bufferModel = std::vector()); + + /** @brief Reads a network model stored in Darknet model files. + * @param bufferCfg A buffer contains a content of .cfg file with text description of the network architecture. + * @param lenCfg Number of bytes to read from bufferCfg + * @param bufferModel A buffer contains a content of .weights file with learned network. + * @param lenModel Number of bytes to read from bufferModel + * @returns Net object. + */ + CV_EXPORTS Net readNetFromDarknet(const char *bufferCfg, size_t lenCfg, + const char *bufferModel = NULL, size_t lenModel = 0); + + /** @brief Reads a network model stored in Caffe framework's format. + * @param prototxt path to the .prototxt file with text description of the network architecture. + * @param caffeModel path to the .caffemodel file with learned network. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromCaffe(const String &prototxt, const String &caffeModel = String()); + + /** @brief Reads a network model stored in Caffe model in memory. + * @param bufferProto buffer containing the content of the .prototxt file + * @param bufferModel buffer containing the content of the .caffemodel file + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromCaffe(const std::vector& bufferProto, + const std::vector& bufferModel = std::vector()); + + /** @brief Reads a network model stored in Caffe model in memory. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param bufferProto buffer containing the content of the .prototxt file + * @param lenProto length of bufferProto + * @param bufferModel buffer containing the content of the .caffemodel file + * @param lenModel length of bufferModel + * @returns Net object. + */ + CV_EXPORTS Net readNetFromCaffe(const char *bufferProto, size_t lenProto, + const char *bufferModel = NULL, size_t lenModel = 0); + + /** @brief Reads a network model stored in TensorFlow framework's format. + * @param model path to the .pb file with binary protobuf description of the network architecture + * @param config path to the .pbtxt file that contains text graph definition in protobuf format. + * Resulting Net object is built by text graph using weights from a binary one that + * let us make it more flexible. + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromTensorflow(const String &model, const String &config = String()); + + /** @brief Reads a network model stored in TensorFlow framework's format. + * @param bufferModel buffer containing the content of the pb file + * @param bufferConfig buffer containing the content of the pbtxt file + * @returns Net object. + */ + CV_EXPORTS_W Net readNetFromTensorflow(const std::vector& bufferModel, + const std::vector& bufferConfig = std::vector()); + + /** @brief Reads a network model stored in TensorFlow framework's format. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param bufferModel buffer containing the content of the pb file + * @param lenModel length of bufferModel + * @param bufferConfig buffer containing the content of the pbtxt file + * @param lenConfig length of bufferConfig + */ + CV_EXPORTS Net readNetFromTensorflow(const char *bufferModel, size_t lenModel, + const char *bufferConfig = NULL, size_t lenConfig = 0); + + /** + * @brief Reads a network model stored in Torch7 framework's format. + * @param model path to the file, dumped from Torch by using torch.save() function. + * @param isBinary specifies whether the network was serialized in ascii mode or binary. + * @param evaluate specifies testing phase of network. If true, it's similar to evaluate() method in Torch. + * @returns Net object. + * + * @note Ascii mode of Torch serializer is more preferable, because binary mode extensively use `long` type of C language, + * which has various bit-length on different systems. + * + * The loading file must contain serialized nn.Module object + * with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors. + * + * List of supported layers (i.e. object instances derived from Torch nn.Module class): + * - nn.Sequential + * - nn.Parallel + * - nn.Concat + * - nn.Linear + * - nn.SpatialConvolution + * - nn.SpatialMaxPooling, nn.SpatialAveragePooling + * - nn.ReLU, nn.TanH, nn.Sigmoid + * - nn.Reshape + * - nn.SoftMax, nn.LogSoftMax + * + * Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported. + */ + CV_EXPORTS_W Net readNetFromTorch(const String &model, bool isBinary = true, bool evaluate = true); + + /** + * @brief Read deep learning network represented in one of the supported formats. + * @param[in] model Binary file contains trained weights. The following file + * extensions are expected for models from different frameworks: + * * `*.caffemodel` (Caffe, http://caffe.berkeleyvision.org/) + * * `*.pb` (TensorFlow, https://www.tensorflow.org/) + * * `*.t7` | `*.net` (Torch, http://torch.ch/) + * * `*.weights` (Darknet, https://pjreddie.com/darknet/) + * * `*.bin` (DLDT, https://software.intel.com/openvino-toolkit) + * * `*.onnx` (ONNX, https://onnx.ai/) + * @param[in] config Text file contains network configuration. It could be a + * file with the following extensions: + * * `*.prototxt` (Caffe, http://caffe.berkeleyvision.org/) + * * `*.pbtxt` (TensorFlow, https://www.tensorflow.org/) + * * `*.cfg` (Darknet, https://pjreddie.com/darknet/) + * * `*.xml` (DLDT, https://software.intel.com/openvino-toolkit) + * @param[in] framework Explicit framework name tag to determine a format. + * @returns Net object. + * + * This function automatically detects an origin framework of trained model + * and calls an appropriate function such @ref readNetFromCaffe, @ref readNetFromTensorflow, + * @ref readNetFromTorch or @ref readNetFromDarknet. An order of @p model and @p config + * arguments does not matter. + */ + CV_EXPORTS_W Net readNet(const String& model, const String& config = "", const String& framework = ""); + + /** + * @brief Read deep learning network represented in one of the supported formats. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + * @param[in] framework Name of origin framework. + * @param[in] bufferModel A buffer with a content of binary file with weights + * @param[in] bufferConfig A buffer with a content of text file contains network configuration. + * @returns Net object. + */ + CV_EXPORTS_W Net readNet(const String& framework, const std::vector& bufferModel, + const std::vector& bufferConfig = std::vector()); + + /** @brief Loads blob which was serialized as torch.Tensor object of Torch7 framework. + * @warning This function has the same limitations as readNetFromTorch(). + */ + CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary = true); + + /** @brief Load a network from Intel's Model Optimizer intermediate representation. + * @param[in] xml XML configuration file with network's topology. + * @param[in] bin Binary file with trained weights. + * @returns Net object. + * Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine + * backend. + */ + CV_EXPORTS_W + Net readNetFromModelOptimizer(const String &xml, const String &bin); + + /** @brief Load a network from Intel's Model Optimizer intermediate representation. + * @param[in] bufferModelConfig Buffer contains XML configuration with network's topology. + * @param[in] bufferWeights Buffer contains binary data with trained weights. + * @returns Net object. + * Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine + * backend. + */ + CV_EXPORTS_W + Net readNetFromModelOptimizer(const std::vector& bufferModelConfig, const std::vector& bufferWeights); + + /** @brief Load a network from Intel's Model Optimizer intermediate representation. + * @param[in] bufferModelConfigPtr Pointer to buffer which contains XML configuration with network's topology. + * @param[in] bufferModelConfigSize Binary size of XML configuration data. + * @param[in] bufferWeightsPtr Pointer to buffer which contains binary data with trained weights. + * @param[in] bufferWeightsSize Binary size of trained weights data. + * @returns Net object. + * Networks imported from Intel's Model Optimizer are launched in Intel's Inference Engine + * backend. + */ + CV_EXPORTS + Net readNetFromModelOptimizer(const uchar* bufferModelConfigPtr, size_t bufferModelConfigSize, + const uchar* bufferWeightsPtr, size_t bufferWeightsSize); + + /** @brief Reads a network model ONNX. + * @param onnxFile path to the .onnx file with text description of the network architecture. + * @returns Network object that ready to do forward, throw an exception in failure cases. + */ + CV_EXPORTS_W Net readNetFromONNX(const String &onnxFile); + + /** @brief Reads a network model from ONNX + * in-memory buffer. + * @param buffer memory address of the first byte of the buffer. + * @param sizeBuffer size of the buffer. + * @returns Network object that ready to do forward, throw an exception + * in failure cases. + */ + CV_EXPORTS Net readNetFromONNX(const char* buffer, size_t sizeBuffer); + + /** @brief Reads a network model from ONNX + * in-memory buffer. + * @param buffer in-memory buffer that stores the ONNX model bytes. + * @returns Network object that ready to do forward, throw an exception + * in failure cases. + */ + CV_EXPORTS_W Net readNetFromONNX(const std::vector& buffer); + + /** @brief Creates blob from .pb file. + * @param path to the .pb file with input tensor. + * @returns Mat. + */ + CV_EXPORTS_W Mat readTensorFromONNX(const String& path); + + /** @brief Creates 4-dimensional blob from image. Optionally resizes and crops @p image from center, + * subtract @p mean values, scales values by @p scalefactor, swap Blue and Red channels. + * @param image input image (with 1-, 3- or 4-channels). + * @param size spatial size for output image + * @param mean scalar with mean values which are subtracted from channels. Values are intended + * to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. + * @param scalefactor multiplier for @p image values. + * @param swapRB flag which indicates that swap first and last channels + * in 3-channel image is necessary. + * @param crop flag which indicates whether image will be cropped after resize or not + * @param ddepth Depth of output blob. Choose CV_32F or CV_8U. + * @details if @p crop is true, input image is resized so one side after resize is equal to corresponding + * dimension in @p size and another one is equal or larger. Then, crop from the center is performed. + * If @p crop is false, direct resize without cropping and preserving aspect ratio is performed. + * @returns 4-dimensional Mat with NCHW dimensions order. + */ + CV_EXPORTS_W Mat blobFromImage(InputArray image, double scalefactor=1.0, const Size& size = Size(), + const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false, + int ddepth=CV_32F); + + /** @brief Creates 4-dimensional blob from image. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + */ + CV_EXPORTS void blobFromImage(InputArray image, OutputArray blob, double scalefactor=1.0, + const Size& size = Size(), const Scalar& mean = Scalar(), + bool swapRB=false, bool crop=false, int ddepth=CV_32F); + + + /** @brief Creates 4-dimensional blob from series of images. Optionally resizes and + * crops @p images from center, subtract @p mean values, scales values by @p scalefactor, + * swap Blue and Red channels. + * @param images input images (all with 1-, 3- or 4-channels). + * @param size spatial size for output image + * @param mean scalar with mean values which are subtracted from channels. Values are intended + * to be in (mean-R, mean-G, mean-B) order if @p image has BGR ordering and @p swapRB is true. + * @param scalefactor multiplier for @p images values. + * @param swapRB flag which indicates that swap first and last channels + * in 3-channel image is necessary. + * @param crop flag which indicates whether image will be cropped after resize or not + * @param ddepth Depth of output blob. Choose CV_32F or CV_8U. + * @details if @p crop is true, input image is resized so one side after resize is equal to corresponding + * dimension in @p size and another one is equal or larger. Then, crop from the center is performed. + * If @p crop is false, direct resize without cropping and preserving aspect ratio is performed. + * @returns 4-dimensional Mat with NCHW dimensions order. + */ + CV_EXPORTS_W Mat blobFromImages(InputArrayOfArrays images, double scalefactor=1.0, + Size size = Size(), const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false, + int ddepth=CV_32F); + + /** @brief Creates 4-dimensional blob from series of images. + * @details This is an overloaded member function, provided for convenience. + * It differs from the above function only in what argument(s) it accepts. + */ + CV_EXPORTS void blobFromImages(InputArrayOfArrays images, OutputArray blob, + double scalefactor=1.0, Size size = Size(), + const Scalar& mean = Scalar(), bool swapRB=false, bool crop=false, + int ddepth=CV_32F); + + /** @brief Parse a 4D blob and output the images it contains as 2D arrays through a simpler data structure + * (std::vector). + * @param[in] blob_ 4 dimensional array (images, channels, height, width) in floating point precision (CV_32F) from + * which you would like to extract the images. + * @param[out] images_ array of 2D Mat containing the images extracted from the blob in floating point precision + * (CV_32F). They are non normalized neither mean added. The number of returned images equals the first dimension + * of the blob (batch size). Every image has a number of channels equals to the second dimension of the blob (depth). + */ + CV_EXPORTS_W void imagesFromBlob(const cv::Mat& blob_, OutputArrayOfArrays images_); + + /** @brief Convert all weights of Caffe network to half precision floating point. + * @param src Path to origin model from Caffe framework contains single + * precision floating point weights (usually has `.caffemodel` extension). + * @param dst Path to destination model with updated weights. + * @param layersTypes Set of layers types which parameters will be converted. + * By default, converts only Convolutional and Fully-Connected layers' + * weights. + * + * @note Shrinked model has no origin float32 weights so it can't be used + * in origin Caffe framework anymore. However the structure of data + * is taken from NVidia's Caffe fork: https://github.com/NVIDIA/caffe. + * So the resulting model may be used there. + */ + CV_EXPORTS_W void shrinkCaffeModel(const String& src, const String& dst, + const std::vector& layersTypes = std::vector()); + + /** @brief Create a text representation for a binary network stored in protocol buffer format. + * @param[in] model A path to binary network. + * @param[in] output A path to output text file to be created. + * + * @note To reduce output file size, trained weights are not included. + */ + CV_EXPORTS_W void writeTextGraph(const String& model, const String& output); + + /** @brief Performs non maximum suppression given boxes and corresponding scores. + + * @param bboxes a set of bounding boxes to apply NMS. + * @param scores a set of corresponding confidences. + * @param score_threshold a threshold used to filter boxes by score. + * @param nms_threshold a threshold used in non maximum suppression. + * @param indices the kept indices of bboxes after NMS. + * @param eta a coefficient in adaptive threshold formula: \f$nms\_threshold_{i+1}=eta\cdot nms\_threshold_i\f$. + * @param top_k if `>0`, keep at most @p top_k picked indices. + */ + CV_EXPORTS_W void NMSBoxes(const std::vector& bboxes, const std::vector& scores, + const float score_threshold, const float nms_threshold, + CV_OUT std::vector& indices, + const float eta = 1.f, const int top_k = 0); + + CV_EXPORTS_W void NMSBoxes(const std::vector& bboxes, const std::vector& scores, + const float score_threshold, const float nms_threshold, + CV_OUT std::vector& indices, + const float eta = 1.f, const int top_k = 0); + + CV_EXPORTS_AS(NMSBoxesRotated) void NMSBoxes(const std::vector& bboxes, const std::vector& scores, + const float score_threshold, const float nms_threshold, + CV_OUT std::vector& indices, + const float eta = 1.f, const int top_k = 0); + + + /** @brief This class is presented high-level API for neural networks. + * + * Model allows to set params for preprocessing input image. + * Model creates net from file with trained weights and config, + * sets preprocessing input and runs forward pass. + */ + class CV_EXPORTS_W_SIMPLE Model : public Net + { + public: + /** + * @brief Default constructor. + */ + Model(); + + /** + * @brief Create model from deep learning network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP Model(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP Model(const Net& network); + + /** @brief Set input size for frame. + * @param[in] size New input size. + * @note If shape of the new blob less than 0, then frame size not change. + */ + CV_WRAP Model& setInputSize(const Size& size); + + /** @brief Set input size for frame. + * @param[in] width New input width. + * @param[in] height New input height. + * @note If shape of the new blob less than 0, + * then frame size not change. + */ + CV_WRAP Model& setInputSize(int width, int height); + + /** @brief Set mean value for frame. + * @param[in] mean Scalar with mean values which are subtracted from channels. + */ + CV_WRAP Model& setInputMean(const Scalar& mean); + + /** @brief Set scalefactor value for frame. + * @param[in] scale Multiplier for frame values. + */ + CV_WRAP Model& setInputScale(double scale); + + /** @brief Set flag crop for frame. + * @param[in] crop Flag which indicates whether image will be cropped after resize or not. + */ + CV_WRAP Model& setInputCrop(bool crop); + + /** @brief Set flag swapRB for frame. + * @param[in] swapRB Flag which indicates that swap first and last channels. + */ + CV_WRAP Model& setInputSwapRB(bool swapRB); + + /** @brief Set preprocessing parameters for frame. + * @param[in] size New input size. + * @param[in] mean Scalar with mean values which are subtracted from channels. + * @param[in] scale Multiplier for frame values. + * @param[in] swapRB Flag which indicates that swap first and last channels. + * @param[in] crop Flag which indicates whether image will be cropped after resize or not. + * blob(n, c, y, x) = scale * resize( frame(y, x, c) ) - mean(c) ) + */ + CV_WRAP void setInputParams(double scale = 1.0, const Size& size = Size(), + const Scalar& mean = Scalar(), bool swapRB = false, bool crop = false); + + /** @brief Given the @p input frame, create input blob, run net and return the output @p blobs. + * @param[in] frame The input image. + * @param[out] outs Allocated output blobs, which will store results of the computation. + */ + CV_WRAP void predict(InputArray frame, OutputArrayOfArrays outs); + + protected: + struct Impl; + Ptr impl; + }; + + /** @brief This class represents high-level API for classification models. + * + * ClassificationModel allows to set params for preprocessing input image. + * ClassificationModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and return top-1 prediction. + */ + class CV_EXPORTS_W_SIMPLE ClassificationModel : public Model + { + public: + /** + * @brief Create classification model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP ClassificationModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP ClassificationModel(const Net& network); + + /** @brief Given the @p input frame, create input blob, run net and return top-1 prediction. + * @param[in] frame The input image. + */ + std::pair classify(InputArray frame); + + /** @overload */ + CV_WRAP void classify(InputArray frame, CV_OUT int& classId, CV_OUT float& conf); + }; + + /** @brief This class represents high-level API for keypoints models + * + * KeypointsModel allows to set params for preprocessing input image. + * KeypointsModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and returns the x and y coordinates of each detected keypoint + */ + class CV_EXPORTS_W KeypointsModel: public Model + { + public: + /** + * @brief Create keypoints model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP KeypointsModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP KeypointsModel(const Net& network); + + /** @brief Given the @p input frame, create input blob, run net + * @param[in] frame The input image. + * @param thresh minimum confidence threshold to select a keypoint + * @returns a vector holding the x and y coordinates of each detected keypoint + * + */ + CV_WRAP std::vector estimate(InputArray frame, float thresh=0.5); + }; + + /** @brief This class represents high-level API for segmentation models + * + * SegmentationModel allows to set params for preprocessing input image. + * SegmentationModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and returns the class prediction for each pixel. + */ + class CV_EXPORTS_W SegmentationModel: public Model + { + public: + /** + * @brief Create segmentation model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP SegmentationModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP SegmentationModel(const Net& network); + + /** @brief Given the @p input frame, create input blob, run net + * @param[in] frame The input image. + * @param[out] mask Allocated class prediction for each pixel + */ + CV_WRAP void segment(InputArray frame, OutputArray mask); + }; + + /** @brief This class represents high-level API for object detection networks. + * + * DetectionModel allows to set params for preprocessing input image. + * DetectionModel creates net from file with trained weights and config, + * sets preprocessing input, runs forward pass and return result detections. + * For DetectionModel SSD, Faster R-CNN, YOLO topologies are supported. + */ + class CV_EXPORTS_W_SIMPLE DetectionModel : public Model + { + public: + /** + * @brief Create detection model from network represented in one of the supported formats. + * An order of @p model and @p config arguments does not matter. + * @param[in] model Binary file contains trained weights. + * @param[in] config Text file contains network configuration. + */ + CV_WRAP DetectionModel(const String& model, const String& config = ""); + + /** + * @brief Create model from deep learning network. + * @param[in] network Net object. + */ + CV_WRAP DetectionModel(const Net& network); + + /** @brief Given the @p input frame, create input blob, run net and return result detections. + * @param[in] frame The input image. + * @param[out] classIds Class indexes in result detection. + * @param[out] confidences A set of corresponding confidences. + * @param[out] boxes A set of bounding boxes. + * @param[in] confThreshold A threshold used to filter boxes by confidences. + * @param[in] nmsThreshold A threshold used in non maximum suppression. + */ + CV_WRAP void detect(InputArray frame, CV_OUT std::vector& classIds, + CV_OUT std::vector& confidences, CV_OUT std::vector& boxes, + float confThreshold = 0.5f, float nmsThreshold = 0.0f); + }; + +//! @} +CV__DNN_INLINE_NS_END +} +} + +#include +#include + +/// @deprecated Include this header directly from application. Automatic inclusion will be removed +#include + +#endif /* OPENCV_DNN_DNN_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dnn.inl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dnn.inl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d6809ce3fdc1a19bb15767a8792fd9ef724135c3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/dnn.inl.hpp @@ -0,0 +1,411 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_INL_HPP +#define OPENCV_DNN_DNN_INL_HPP + +#include + +namespace cv { +namespace dnn { +CV__DNN_INLINE_NS_BEGIN + +template +DictValue DictValue::arrayInt(TypeIter begin, int size) +{ + DictValue res(Param::INT, new AutoBuffer(size)); + for (int j = 0; j < size; begin++, j++) + (*res.pi)[j] = *begin; + return res; +} + +template +DictValue DictValue::arrayReal(TypeIter begin, int size) +{ + DictValue res(Param::REAL, new AutoBuffer(size)); + for (int j = 0; j < size; begin++, j++) + (*res.pd)[j] = *begin; + return res; +} + +template +DictValue DictValue::arrayString(TypeIter begin, int size) +{ + DictValue res(Param::STRING, new AutoBuffer(size)); + for (int j = 0; j < size; begin++, j++) + (*res.ps)[j] = *begin; + return res; +} + +template<> +inline DictValue DictValue::get(int idx) const +{ + CV_Assert(idx == -1); + return *this; +} + +template<> +inline int64 DictValue::get(int idx) const +{ + CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size())); + idx = (idx == -1) ? 0 : idx; + + if (type == Param::INT) + { + return (*pi)[idx]; + } + else if (type == Param::REAL) + { + double doubleValue = (*pd)[idx]; + + double fracpart, intpart; + fracpart = std::modf(doubleValue, &intpart); + CV_Assert(fracpart == 0.0); + + return (int64)doubleValue; + } + else if (type == Param::STRING) + { + return std::atoi((*ps)[idx].c_str()); + } + else + { + CV_Assert(isInt() || isReal() || isString()); + return 0; + } +} + +template<> +inline int DictValue::get(int idx) const +{ + return (int)get(idx); +} + +inline int DictValue::getIntValue(int idx) const +{ + return (int)get(idx); +} + +template<> +inline unsigned DictValue::get(int idx) const +{ + return (unsigned)get(idx); +} + +template<> +inline bool DictValue::get(int idx) const +{ + return (get(idx) != 0); +} + +template<> +inline double DictValue::get(int idx) const +{ + CV_Assert((idx == -1 && size() == 1) || (idx >= 0 && idx < size())); + idx = (idx == -1) ? 0 : idx; + + if (type == Param::REAL) + { + return (*pd)[idx]; + } + else if (type == Param::INT) + { + return (double)(*pi)[idx]; + } + else if (type == Param::STRING) + { + return std::atof((*ps)[idx].c_str()); + } + else + { + CV_Assert(isReal() || isInt() || isString()); + return 0; + } +} + +inline double DictValue::getRealValue(int idx) const +{ + return get(idx); +} + +template<> +inline float DictValue::get(int idx) const +{ + return (float)get(idx); +} + +template<> +inline String DictValue::get(int idx) const +{ + CV_Assert(isString()); + CV_Assert((idx == -1 && ps->size() == 1) || (idx >= 0 && idx < (int)ps->size())); + return (*ps)[(idx == -1) ? 0 : idx]; +} + + +inline String DictValue::getStringValue(int idx) const +{ + return get(idx); +} + +inline void DictValue::release() +{ + switch (type) + { + case Param::INT: + delete pi; + break; + case Param::STRING: + delete ps; + break; + case Param::REAL: + delete pd; + break; + case Param::BOOLEAN: + case Param::MAT: + case Param::MAT_VECTOR: + case Param::ALGORITHM: + case Param::FLOAT: + case Param::UNSIGNED_INT: + case Param::UINT64: + case Param::UCHAR: + case Param::SCALAR: + break; // unhandled + } +} + +inline DictValue::~DictValue() +{ + release(); +} + +inline DictValue & DictValue::operator=(const DictValue &r) +{ + if (&r == this) + return *this; + + if (r.type == Param::INT) + { + AutoBuffer *tmp = new AutoBuffer(*r.pi); + release(); + pi = tmp; + } + else if (r.type == Param::STRING) + { + AutoBuffer *tmp = new AutoBuffer(*r.ps); + release(); + ps = tmp; + } + else if (r.type == Param::REAL) + { + AutoBuffer *tmp = new AutoBuffer(*r.pd); + release(); + pd = tmp; + } + + type = r.type; + + return *this; +} + +inline DictValue::DictValue(const DictValue &r) +{ + type = r.type; + + if (r.type == Param::INT) + pi = new AutoBuffer(*r.pi); + else if (r.type == Param::STRING) + ps = new AutoBuffer(*r.ps); + else if (r.type == Param::REAL) + pd = new AutoBuffer(*r.pd); +} + +inline bool DictValue::isString() const +{ + return (type == Param::STRING); +} + +inline bool DictValue::isInt() const +{ + return (type == Param::INT); +} + +inline bool DictValue::isReal() const +{ + return (type == Param::REAL || type == Param::INT); +} + +inline int DictValue::size() const +{ + switch (type) + { + case Param::INT: + return (int)pi->size(); + case Param::STRING: + return (int)ps->size(); + case Param::REAL: + return (int)pd->size(); + case Param::BOOLEAN: + case Param::MAT: + case Param::MAT_VECTOR: + case Param::ALGORITHM: + case Param::FLOAT: + case Param::UNSIGNED_INT: + case Param::UINT64: + case Param::UCHAR: + case Param::SCALAR: + break; // unhandled + } + CV_Error_(Error::StsInternal, ("Unhandled type (%d)", static_cast(type))); +} + +inline std::ostream &operator<<(std::ostream &stream, const DictValue &dictv) +{ + int i; + + if (dictv.isInt()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << dictv.get(i) << ", "; + stream << dictv.get(i); + } + else if (dictv.isReal()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << dictv.get(i) << ", "; + stream << dictv.get(i); + } + else if (dictv.isString()) + { + for (i = 0; i < dictv.size() - 1; i++) + stream << "\"" << dictv.get(i) << "\", "; + stream << dictv.get(i); + } + + return stream; +} + +///////////////////////////////////////////////////////////////// + +inline bool Dict::has(const String &key) const +{ + return dict.count(key) != 0; +} + +inline DictValue *Dict::ptr(const String &key) +{ + _Dict::iterator i = dict.find(key); + return (i == dict.end()) ? NULL : &i->second; +} + +inline const DictValue *Dict::ptr(const String &key) const +{ + _Dict::const_iterator i = dict.find(key); + return (i == dict.end()) ? NULL : &i->second; +} + +inline const DictValue &Dict::get(const String &key) const +{ + _Dict::const_iterator i = dict.find(key); + if (i == dict.end()) + CV_Error(Error::StsObjectNotFound, "Required argument \"" + key + "\" not found into dictionary"); + return i->second; +} + +template +inline T Dict::get(const String &key) const +{ + return this->get(key).get(); +} + +template +inline T Dict::get(const String &key, const T &defaultValue) const +{ + _Dict::const_iterator i = dict.find(key); + + if (i != dict.end()) + return i->second.get(); + else + return defaultValue; +} + +template +inline const T &Dict::set(const String &key, const T &value) +{ + _Dict::iterator i = dict.find(key); + + if (i != dict.end()) + i->second = DictValue(value); + else + dict.insert(std::make_pair(key, DictValue(value))); + + return value; +} + +inline void Dict::erase(const String &key) +{ + dict.erase(key); +} + +inline std::ostream &operator<<(std::ostream &stream, const Dict &dict) +{ + Dict::_Dict::const_iterator it; + for (it = dict.dict.begin(); it != dict.dict.end(); it++) + stream << it->first << " : " << it->second << "\n"; + + return stream; +} + +inline std::map::const_iterator Dict::begin() const +{ + return dict.begin(); +} + +inline std::map::const_iterator Dict::end() const +{ + return dict.end(); +} + +CV__DNN_INLINE_NS_END +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/layer.details.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/layer.details.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1133da562e2ea9cba86346c505fa0be049c8b0d4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/layer.details.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +#ifndef OPENCV_DNN_LAYER_DETAILS_HPP +#define OPENCV_DNN_LAYER_DETAILS_HPP + +#include + +namespace cv { +namespace dnn { +CV__DNN_INLINE_NS_BEGIN + +/** @brief Registers layer constructor in runtime. +* @param type string, containing type name of the layer. +* @param constructorFunc pointer to the function of type LayerRegister::Constructor, which creates the layer. +* @details This macros must be placed inside the function code. +*/ +#define CV_DNN_REGISTER_LAYER_FUNC(type, constructorFunc) \ + cv::dnn::LayerFactory::registerLayer(#type, constructorFunc); + +/** @brief Registers layer class in runtime. + * @param type string, containing type name of the layer. + * @param class C++ class, derived from Layer. + * @details This macros must be placed inside the function code. + */ +#define CV_DNN_REGISTER_LAYER_CLASS(type, class) \ + cv::dnn::LayerFactory::registerLayer(#type, cv::dnn::details::_layerDynamicRegisterer); + +/** @brief Registers layer constructor on module load time. +* @param type string, containing type name of the layer. +* @param constructorFunc pointer to the function of type LayerRegister::Constructor, which creates the layer. +* @details This macros must be placed outside the function code. +*/ +#define CV_DNN_REGISTER_LAYER_FUNC_STATIC(type, constructorFunc) \ +static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, constructorFunc); + +/** @brief Registers layer class on module load time. + * @param type string, containing type name of the layer. + * @param class C++ class, derived from Layer. + * @details This macros must be placed outside the function code. + */ +#define CV_DNN_REGISTER_LAYER_CLASS_STATIC(type, class) \ +Ptr __LayerStaticRegisterer_func_##type(LayerParams ¶ms) \ + { return Ptr(new class(params)); } \ +static cv::dnn::details::_LayerStaticRegisterer __LayerStaticRegisterer_##type(#type, __LayerStaticRegisterer_func_##type); + +namespace details { + +template +Ptr _layerDynamicRegisterer(LayerParams ¶ms) +{ + return Ptr(LayerClass::create(params)); +} + +//allows automatically register created layer on module load time +class _LayerStaticRegisterer +{ + String type; +public: + + _LayerStaticRegisterer(const String &layerType, LayerFactory::Constructor layerConstructor) + { + this->type = layerType; + LayerFactory::registerLayer(layerType, layerConstructor); + } + + ~_LayerStaticRegisterer() + { + LayerFactory::unregisterLayer(type); + } +}; + +} // namespace +CV__DNN_INLINE_NS_END +}} // namespace + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/layer.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/layer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..85005993716d57cafeccb21ca69649df12c80d59 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/layer.hpp @@ -0,0 +1,85 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_LAYER_HPP +#define OPENCV_DNN_LAYER_HPP +#include + +namespace cv { +namespace dnn { +CV__DNN_INLINE_NS_BEGIN +//! @addtogroup dnn +//! @{ +//! +//! @defgroup dnnLayerFactory Utilities for New Layers Registration +//! @{ + +/** @brief %Layer factory allows to create instances of registered layers. */ +class CV_EXPORTS LayerFactory +{ +public: + + //! Each Layer class must provide this function to the factory + typedef Ptr(*Constructor)(LayerParams ¶ms); + + //! Registers the layer class with typename @p type and specified @p constructor. Thread-safe. + static void registerLayer(const String &type, Constructor constructor); + + //! Unregisters registered layer with specified type name. Thread-safe. + static void unregisterLayer(const String &type); + + /** @brief Creates instance of registered layer. + * @param type type name of creating layer. + * @param params parameters which will be used for layer initialization. + * @note Thread-safe. + */ + static Ptr createLayerInstance(const String &type, LayerParams& params); + +private: + LayerFactory(); +}; + +//! @} +//! @} +CV__DNN_INLINE_NS_END +} +} +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/shape_utils.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/shape_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..98adcc382ddff57990fbb987fce4b4dffb536bdc --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/shape_utils.hpp @@ -0,0 +1,219 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_DNN_DNN_SHAPE_UTILS_HPP +#define OPENCV_DNN_DNN_SHAPE_UTILS_HPP + +#include +#include // CV_MAX_DIM +#include +#include +#include + +namespace cv { +namespace dnn { +CV__DNN_INLINE_NS_BEGIN + +//Slicing + +struct _Range : public cv::Range +{ + _Range(const Range &r) : cv::Range(r) {} + _Range(int start_, int size_ = 1) : cv::Range(start_, start_ + size_) {} +}; + +static inline Mat slice(const Mat &m, const _Range &r0) +{ + Range ranges[CV_MAX_DIM]; + for (int i = 1; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1) +{ + CV_Assert(m.dims >= 2); + Range ranges[CV_MAX_DIM]; + for (int i = 2; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2) +{ + CV_Assert(m.dims >= 3); + Range ranges[CV_MAX_DIM]; + for (int i = 3; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + ranges[2] = r2; + return m(&ranges[0]); +} + +static inline Mat slice(const Mat &m, const _Range &r0, const _Range &r1, const _Range &r2, const _Range &r3) +{ + CV_Assert(m.dims >= 4); + Range ranges[CV_MAX_DIM]; + for (int i = 4; i < m.dims; i++) + ranges[i] = Range::all(); + ranges[0] = r0; + ranges[1] = r1; + ranges[2] = r2; + ranges[3] = r3; + return m(&ranges[0]); +} + +static inline Mat getPlane(const Mat &m, int n, int cn) +{ + CV_Assert(m.dims > 2); + int sz[CV_MAX_DIM]; + for(int i = 2; i < m.dims; i++) + { + sz[i-2] = m.size.p[i]; + } + return Mat(m.dims - 2, sz, m.type(), (void*)m.ptr(n, cn)); +} + +static inline MatShape shape(const int* dims, const int n) +{ + MatShape shape; + shape.assign(dims, dims + n); + return shape; +} + +static inline MatShape shape(const Mat& mat) +{ + return shape(mat.size.p, mat.dims); +} + +static inline MatShape shape(const MatSize& sz) +{ + return shape(sz.p, sz.dims()); +} + +static inline MatShape shape(const UMat& mat) +{ + return shape(mat.size.p, mat.dims); +} + +namespace {inline bool is_neg(int i) { return i < 0; }} + +static inline MatShape shape(int a0, int a1=-1, int a2=-1, int a3=-1) +{ + int dims[] = {a0, a1, a2, a3}; + MatShape s = shape(dims, 4); + s.erase(std::remove_if(s.begin(), s.end(), is_neg), s.end()); + return s; +} + +static inline int total(const MatShape& shape, int start = -1, int end = -1) +{ + if (start == -1) start = 0; + if (end == -1) end = (int)shape.size(); + + if (shape.empty()) + return 0; + + int elems = 1; + CV_Assert(start <= (int)shape.size() && end <= (int)shape.size() && + start <= end); + for(int i = start; i < end; i++) + { + elems *= shape[i]; + } + return elems; +} + +static inline MatShape concat(const MatShape& a, const MatShape& b) +{ + MatShape c = a; + c.insert(c.end(), b.begin(), b.end()); + + return c; +} + +static inline std::string toString(const MatShape& shape, const String& name = "") +{ + std::ostringstream ss; + if (!name.empty()) + ss << name << ' '; + ss << '['; + for(size_t i = 0, n = shape.size(); i < n; ++i) + ss << ' ' << shape[i]; + ss << " ]"; + return ss.str(); +} +static inline void print(const MatShape& shape, const String& name = "") +{ + std::cout << toString(shape, name) << std::endl; +} +static inline std::ostream& operator<<(std::ostream &out, const MatShape& shape) +{ + out << toString(shape); + return out; +} + +inline int clamp(int ax, int dims) +{ + return ax < 0 ? ax + dims : ax; +} + +inline int clamp(int ax, const MatShape& shape) +{ + return clamp(ax, (int)shape.size()); +} + +inline Range clamp(const Range& r, int axisSize) +{ + Range clamped(std::max(r.start, 0), + r.end > 0 ? std::min(r.end, axisSize) : axisSize + r.end + 1); + CV_Assert_N(clamped.start < clamped.end, clamped.end <= axisSize); + return clamped; +} + +CV__DNN_INLINE_NS_END +} +} +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/utils/inference_engine.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/utils/inference_engine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7db93a916d7b96b10ab8ab1b4788f5ab3f81b519 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/utils/inference_engine.hpp @@ -0,0 +1,64 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. + +#ifndef OPENCV_DNN_UTILS_INF_ENGINE_HPP +#define OPENCV_DNN_UTILS_INF_ENGINE_HPP + +#include "../dnn.hpp" + +namespace cv { namespace dnn { +CV__DNN_INLINE_NS_BEGIN + + +/* Values for 'OPENCV_DNN_BACKEND_INFERENCE_ENGINE_TYPE' parameter */ +#define CV_DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_API "NN_BUILDER" +#define CV_DNN_BACKEND_INFERENCE_ENGINE_NGRAPH "NGRAPH" + +/** @brief Returns Inference Engine internal backend API. + * + * See values of `CV_DNN_BACKEND_INFERENCE_ENGINE_*` macros. + * + * Default value is controlled through `OPENCV_DNN_BACKEND_INFERENCE_ENGINE_TYPE` runtime parameter (environment variable). + */ +CV_EXPORTS_W cv::String getInferenceEngineBackendType(); + +/** @brief Specify Inference Engine internal backend API. + * + * See values of `CV_DNN_BACKEND_INFERENCE_ENGINE_*` macros. + * + * @returns previous value of internal backend API + */ +CV_EXPORTS_W cv::String setInferenceEngineBackendType(const cv::String& newBackendType); + + +/** @brief Release a Myriad device (binded by OpenCV). + * + * Single Myriad device cannot be shared across multiple processes which uses + * Inference Engine's Myriad plugin. + */ +CV_EXPORTS_W void resetMyriadDevice(); + + +/* Values for 'OPENCV_DNN_IE_VPU_TYPE' parameter */ +#define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_UNSPECIFIED "" +/// Intel(R) Movidius(TM) Neural Compute Stick, NCS (USB 03e7:2150), Myriad2 (https://software.intel.com/en-us/movidius-ncs) +#define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2 "Myriad2" +/// Intel(R) Neural Compute Stick 2, NCS2 (USB 03e7:2485), MyriadX (https://software.intel.com/ru-ru/neural-compute-stick) +#define CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_X "MyriadX" + + +/** @brief Returns Inference Engine VPU type. + * + * See values of `CV_DNN_INFERENCE_ENGINE_VPU_TYPE_*` macros. + */ +CV_EXPORTS_W cv::String getInferenceEngineVPUType(); + + +CV__DNN_INLINE_NS_END +}} // namespace + +#endif // OPENCV_DNN_UTILS_INF_ENGINE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/version.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/version.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6dd2c39d6917b963a6e3545a08a5ba00f0c03d4a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn/version.hpp @@ -0,0 +1,21 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_DNN_VERSION_HPP +#define OPENCV_DNN_VERSION_HPP + +/// Use with major OpenCV version only. +#define OPENCV_DNN_API_VERSION 20191202 + +#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_INLINE_NS +#define CV__DNN_INLINE_NS __CV_CAT(dnn4_v, OPENCV_DNN_API_VERSION) +#define CV__DNN_INLINE_NS_BEGIN namespace CV__DNN_INLINE_NS { +#define CV__DNN_INLINE_NS_END } +namespace cv { namespace dnn { namespace CV__DNN_INLINE_NS { } using namespace CV__DNN_INLINE_NS; }} +#else +#define CV__DNN_INLINE_NS_BEGIN +#define CV__DNN_INLINE_NS_END +#endif + +#endif // OPENCV_DNN_VERSION_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn_superres.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn_superres.hpp new file mode 100644 index 0000000000000000000000000000000000000000..806f000ab91e74859a69b8d4879cd26986240fca --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dnn_superres.hpp @@ -0,0 +1,125 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef _OPENCV_DNN_SUPERRES_HPP_ +#define _OPENCV_DNN_SUPERRES_HPP_ + +/** @defgroup dnn_superres DNN used for super resolution + +This module contains functionality for upscaling an image via convolutional neural networks. +The following four models are implemented: + +- EDSR +- ESPCN +- FSRCNN +- LapSRN + +*/ + +#include "opencv2/core.hpp" +#include "opencv2/dnn.hpp" + +namespace cv +{ +namespace dnn_superres +{ + +//! @addtogroup dnn_superres +//! @{ + +/** @brief A class to upscale images via convolutional neural networks. +The following four models are implemented: + +- edsr +- espcn +- fsrcnn +- lapsrn + */ + +class CV_EXPORTS DnnSuperResImpl +{ +private: + + /** @brief Net which holds the desired neural network + */ + dnn::Net net; + + std::string alg; //algorithm + + int sc; //scale factor + + void preprocess(InputArray inpImg, OutputArray outpImg); + + void reconstruct_YCrCb(InputArray inpImg, InputArray origImg, OutputArray outpImg, int scale); + + void reconstruct_YCrCb(InputArray inpImg, InputArray origImg, OutputArray outpImg); + + void preprocess_YCrCb(InputArray inpImg, OutputArray outpImg); + +public: + + /** @brief Empty constructor + */ + DnnSuperResImpl(); + + /** @brief Constructor which immediately sets the desired model + @param algo String containing one of the desired models: + - __edsr__ + - __espcn__ + - __fsrcnn__ + - __lapsrn__ + @param scale Integer specifying the upscale factor + */ + DnnSuperResImpl(const std::string& algo, int scale); + + /** @brief Read the model from the given path + @param path Path to the model file. + */ + void readModel(const std::string& path); + + /** @brief Read the model from the given path + @param weights Path to the model weights file. + @param definition Path to the model definition file. + */ + void readModel(const std::string& weights, const std::string& definition); + + /** @brief Set desired model + @param algo String containing one of the desired models: + - __edsr__ + - __espcn__ + - __fsrcnn__ + - __lapsrn__ + @param scale Integer specifying the upscale factor + */ + void setModel(const std::string& algo, int scale); + + /** @brief Upsample via neural network + @param img Image to upscale + @param result Destination upscaled image + */ + void upsample(InputArray img, OutputArray result); + + /** @brief Upsample via neural network of multiple outputs + @param img Image to upscale + @param imgs_new Destination upscaled images + @param scale_factors Scaling factors of the output nodes + @param node_names Names of the output nodes in the neural network + */ + void upsampleMultioutput(InputArray img, std::vector &imgs_new, const std::vector& scale_factors, const std::vector& node_names); + + /** @brief Returns the scale factor of the model: + @return Current scale factor. + */ + int getScale(); + + /** @brief Returns the scale factor of the model: + @return Current algorithm. + */ + std::string getAlgorithm(); +}; + +//! @} dnn_superres + +}} // cv::dnn_superres:: +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dpm.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dpm.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ab604abf3faa20b7fef2a3ac6c34d1ed37e20e76 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/dpm.hpp @@ -0,0 +1,153 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Itseez Inc or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +// Implementation authors: +// Jiaolong Xu - jiaolongxu@gmail.com +// Evgeniy Kozinov - evgeniy.kozinov@gmail.com +// Valentina Kustikova - valentina.kustikova@gmail.com +// Nikolai Zolotykh - Nikolai.Zolotykh@gmail.com +// Iosif Meyerov - meerov@vmk.unn.ru +// Alexey Polovinkin - polovinkin.alexey@gmail.com +// +//M*/ + +#ifndef __OPENCV_LATENTSVM_HPP__ +#define __OPENCV_LATENTSVM_HPP__ + +#include "opencv2/core.hpp" + +#include +#include +#include + +/** @defgroup dpm Deformable Part-based Models + +Discriminatively Trained Part Based Models for Object Detection +--------------------------------------------------------------- + +The object detector described below has been initially proposed by P.F. Felzenszwalb in +@cite Felzenszwalb2010a . It is based on a Dalal-Triggs detector that uses a single filter on histogram +of oriented gradients (HOG) features to represent an object category. This detector uses a sliding +window approach, where a filter is applied at all positions and scales of an image. The first +innovation is enriching the Dalal-Triggs model using a star-structured part-based model defined by a +"root" filter (analogous to the Dalal-Triggs filter) plus a set of parts filters and associated +deformation models. The score of one of star models at a particular position and scale within an +image is the score of the root filter at the given location plus the sum over parts of the maximum, +over placements of that part, of the part filter score on its location minus a deformation cost +easuring the deviation of the part from its ideal location relative to the root. Both root and part +filter scores are defined by the dot product between a filter (a set of weights) and a subwindow of +a feature pyramid computed from the input image. Another improvement is a representation of the +class of models by a mixture of star models. The score of a mixture model at a particular position +and scale is the maximum over components, of the score of that component model at the given +location. + +The detector was dramatically speeded-up with cascade algorithm proposed by P.F. Felzenszwalb in +@cite Felzenszwalb2010b . The algorithm prunes partial hypotheses using thresholds on their scores.The +basic idea of the algorithm is to use a hierarchy of models defined by an ordering of the original +model's parts. For a model with (n+1) parts, including the root, a sequence of (n+1) models is +obtained. The i-th model in this sequence is defined by the first i parts from the original model. +Using this hierarchy, low scoring hypotheses can be pruned after looking at the best configuration +of a subset of the parts. Hypotheses that score high under a weak model are evaluated further using +a richer model. + +In OpenCV there is an C++ implementation of DPM cascade detector. + +*/ + +namespace cv +{ + +namespace dpm +{ + +//! @addtogroup dpm +//! @{ + +/** @brief This is a C++ abstract class, it provides external user API to work with DPM. + */ +class CV_EXPORTS_W DPMDetector +{ +public: + + struct CV_EXPORTS_W ObjectDetection + { + ObjectDetection(); + ObjectDetection( const Rect& rect, float score, int classID=-1 ); + Rect rect; + float score; + int classID; + }; + + virtual bool isEmpty() const = 0; + + /** @brief Find rectangular regions in the given image that are likely to contain objects of loaded classes + (models) and corresponding confidence levels. + @param image An image. + @param objects The detections: rectangulars, scores and class IDs. + */ + virtual void detect(cv::Mat &image, CV_OUT std::vector &objects) = 0; + + /** @brief Return the class (model) names that were passed in constructor or method load or extracted from + models filenames in those methods. + */ + virtual std::vector const& getClassNames() const = 0; + + /** @brief Return a count of loaded models (classes). + */ + virtual size_t getClassCount() const = 0; + + /** @brief Load the trained models from given .xml files and return cv::Ptr\. + @param filenames A set of filenames storing the trained detectors (models). Each file contains one + model. See examples of such files here `/opencv_extra/testdata/cv/dpm/VOC2007_Cascade/`. + @param classNames A set of trained models names. If it's empty then the name of each model will be + constructed from the name of file containing the model. E.g. the model stored in + "/home/user/cat.xml" will get the name "cat". + */ + static cv::Ptr create(std::vector const &filenames, + std::vector const &classNames = std::vector()); + + virtual ~DPMDetector(){} +}; + +//! @} + +} // namespace dpm +} // namespace cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8c4bda37b875c8f8eebacba2dff96754d3128828 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face.hpp @@ -0,0 +1,386 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_FACE_HPP__ +#define __OPENCV_FACE_HPP__ + +/** +@defgroup face Face Analysis + +- @ref face_changelog +- @ref tutorial_face_main + +*/ + +#include "opencv2/core.hpp" +#include "face/predict_collector.hpp" +#include + +namespace cv { namespace face { + +//! @addtogroup face +//! @{ + +/** @brief Abstract base class for all face recognition models + +All face recognition models in OpenCV are derived from the abstract base class FaceRecognizer, which +provides a unified access to all face recongition algorithms in OpenCV. + +### Description + +I'll go a bit more into detail explaining FaceRecognizer, because it doesn't look like a powerful +interface at first sight. But: Every FaceRecognizer is an Algorithm, so you can easily get/set all +model internals (if allowed by the implementation). Algorithm is a relatively new OpenCV concept, +which is available since the 2.4 release. I suggest you take a look at its description. + +Algorithm provides the following features for all derived classes: + +- So called "virtual constructor". That is, each Algorithm derivative is registered at program + start and you can get the list of registered algorithms and create instance of a particular + algorithm by its name (see Algorithm::create). If you plan to add your own algorithms, it is + good practice to add a unique prefix to your algorithms to distinguish them from other + algorithms. +- Setting/Retrieving algorithm parameters by name. If you used video capturing functionality from + OpenCV highgui module, you are probably familar with cv::cvSetCaptureProperty, +ocvcvGetCaptureProperty, VideoCapture::set and VideoCapture::get. Algorithm provides similar + method where instead of integer id's you specify the parameter names as text Strings. See + Algorithm::set and Algorithm::get for details. +- Reading and writing parameters from/to XML or YAML files. Every Algorithm derivative can store + all its parameters and then read them back. There is no need to re-implement it each time. + +Moreover every FaceRecognizer supports the: + +- **Training** of a FaceRecognizer with FaceRecognizer::train on a given set of images (your face + database!). +- **Prediction** of a given sample image, that means a face. The image is given as a Mat. +- **Loading/Saving** the model state from/to a given XML or YAML. +- **Setting/Getting labels info**, that is stored as a string. String labels info is useful for + keeping names of the recognized people. + +@note When using the FaceRecognizer interface in combination with Python, please stick to Python 2. +Some underlying scripts like create_csv will not work in other versions, like Python 3. Setting the +Thresholds +++++++++++++++++++++++ + +Sometimes you run into the situation, when you want to apply a threshold on the prediction. A common +scenario in face recognition is to tell, whether a face belongs to the training dataset or if it is +unknown. You might wonder, why there's no public API in FaceRecognizer to set the threshold for the +prediction, but rest assured: It's supported. It just means there's no generic way in an abstract +class to provide an interface for setting/getting the thresholds of *every possible* FaceRecognizer +algorithm. The appropriate place to set the thresholds is in the constructor of the specific +FaceRecognizer and since every FaceRecognizer is a Algorithm (see above), you can get/set the +thresholds at runtime! + +Here is an example of setting a threshold for the Eigenfaces method, when creating the model: + +@code +// Let's say we want to keep 10 Eigenfaces and have a threshold value of 10.0 +int num_components = 10; +double threshold = 10.0; +// Then if you want to have a cv::FaceRecognizer with a confidence threshold, +// create the concrete implementation with the appropriate parameters: +Ptr model = EigenFaceRecognizer::create(num_components, threshold); +@endcode + +Sometimes it's impossible to train the model, just to experiment with threshold values. Thanks to +Algorithm it's possible to set internal model thresholds during runtime. Let's see how we would +set/get the prediction for the Eigenface model, we've created above: + +@code +// The following line reads the threshold from the Eigenfaces model: +double current_threshold = model->getDouble("threshold"); +// And this line sets the threshold to 0.0: +model->set("threshold", 0.0); +@endcode + +If you've set the threshold to 0.0 as we did above, then: + +@code +// +Mat img = imread("person1/3.jpg", IMREAD_GRAYSCALE); +// Get a prediction from the model. Note: We've set a threshold of 0.0 above, +// since the distance is almost always larger than 0.0, you'll get -1 as +// label, which indicates, this face is unknown +int predicted_label = model->predict(img); +// ... +@endcode + +is going to yield -1 as predicted label, which states this face is unknown. + +### Getting the name of a FaceRecognizer + +Since every FaceRecognizer is a Algorithm, you can use Algorithm::name to get the name of a +FaceRecognizer: + +@code +// Create a FaceRecognizer: +Ptr model = EigenFaceRecognizer::create(); +// And here's how to get its name: +String name = model->name(); +@endcode + + */ +class CV_EXPORTS_W FaceRecognizer : public Algorithm +{ +public: + /** @brief Trains a FaceRecognizer with given data and associated labels. + + @param src The training images, that means the faces you want to learn. The data has to be + given as a vector\. + @param labels The labels corresponding to the images have to be given either as a vector\ + or a Mat of type CV_32SC1. + + The following source code snippet shows you how to learn a Fisherfaces model on a given set of + images. The images are read with imread and pushed into a std::vector\. The labels of each + image are stored within a std::vector\ (you could also use a Mat of type CV_32SC1). Think of + the label as the subject (the person) this image belongs to, so same subjects (persons) should have + the same label. For the available FaceRecognizer you don't have to pay any attention to the order of + the labels, just make sure same persons have the same label: + + @code + // holds images and labels + vector images; + vector labels; + // using Mat of type CV_32SC1 + // Mat labels(number_of_samples, 1, CV_32SC1); + // images for first person + images.push_back(imread("person0/0.jpg", IMREAD_GRAYSCALE)); labels.push_back(0); + images.push_back(imread("person0/1.jpg", IMREAD_GRAYSCALE)); labels.push_back(0); + images.push_back(imread("person0/2.jpg", IMREAD_GRAYSCALE)); labels.push_back(0); + // images for second person + images.push_back(imread("person1/0.jpg", IMREAD_GRAYSCALE)); labels.push_back(1); + images.push_back(imread("person1/1.jpg", IMREAD_GRAYSCALE)); labels.push_back(1); + images.push_back(imread("person1/2.jpg", IMREAD_GRAYSCALE)); labels.push_back(1); + @endcode + + Now that you have read some images, we can create a new FaceRecognizer. In this example I'll create + a Fisherfaces model and decide to keep all of the possible Fisherfaces: + + @code + // Create a new Fisherfaces model and retain all available Fisherfaces, + // this is the most common usage of this specific FaceRecognizer: + // + Ptr model = FisherFaceRecognizer::create(); + @endcode + + And finally train it on the given dataset (the face images and labels): + + @code + // This is the common interface to train all of the available cv::FaceRecognizer + // implementations: + // + model->train(images, labels); + @endcode + */ + CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0; + + /** @brief Updates a FaceRecognizer with given data and associated labels. + + @param src The training images, that means the faces you want to learn. The data has to be given + as a vector\. + @param labels The labels corresponding to the images have to be given either as a vector\ or + a Mat of type CV_32SC1. + + This method updates a (probably trained) FaceRecognizer, but only if the algorithm supports it. The + Local Binary Patterns Histograms (LBPH) recognizer (see createLBPHFaceRecognizer) can be updated. + For the Eigenfaces and Fisherfaces method, this is algorithmically not possible and you have to + re-estimate the model with FaceRecognizer::train. In any case, a call to train empties the existing + model and learns a new model, while update does not delete any model data. + + @code + // Create a new LBPH model (it can be updated) and use the default parameters, + // this is the most common usage of this specific FaceRecognizer: + // + Ptr model = LBPHFaceRecognizer::create(); + // This is the common interface to train all of the available cv::FaceRecognizer + // implementations: + // + model->train(images, labels); + // Some containers to hold new image: + vector newImages; + vector newLabels; + // You should add some images to the containers: + // + // ... + // + // Now updating the model is as easy as calling: + model->update(newImages,newLabels); + // This will preserve the old model data and extend the existing model + // with the new features extracted from newImages! + @endcode + + Calling update on an Eigenfaces model (see EigenFaceRecognizer::create), which doesn't support + updating, will throw an error similar to: + + @code + OpenCV Error: The function/feature is not implemented (This FaceRecognizer (FaceRecognizer.Eigenfaces) does not support updating, you have to use FaceRecognizer::train to update it.) in update, file /home/philipp/git/opencv/modules/contrib/src/facerec.cpp, line 305 + terminate called after throwing an instance of 'cv::Exception' + @endcode + + @note The FaceRecognizer does not store your training images, because this would be very + memory intense and it's not the responsibility of te FaceRecognizer to do so. The caller is + responsible for maintaining the dataset, he want to work with. + */ + CV_WRAP virtual void update(InputArrayOfArrays src, InputArray labels); + + /** @overload */ + CV_WRAP_AS(predict_label) int predict(InputArray src) const; + + + /** @brief Predicts a label and associated confidence (e.g. distance) for a given input image. + + @param src Sample image to get a prediction from. + @param label The predicted label for the given image. + @param confidence Associated confidence (e.g. distance) for the predicted label. + + The suffix const means that prediction does not affect the internal model state, so the method can + be safely called from within different threads. + + The following example shows how to get a prediction from a trained model: + + @code + using namespace cv; + // Do your initialization here (create the cv::FaceRecognizer model) ... + // ... + // Read in a sample image: + Mat img = imread("person1/3.jpg", IMREAD_GRAYSCALE); + // And get a prediction from the cv::FaceRecognizer: + int predicted = model->predict(img); + @endcode + + Or to get a prediction and the associated confidence (e.g. distance): + + @code + using namespace cv; + // Do your initialization here (create the cv::FaceRecognizer model) ... + // ... + Mat img = imread("person1/3.jpg", IMREAD_GRAYSCALE); + // Some variables for the predicted label and associated confidence (e.g. distance): + int predicted_label = -1; + double predicted_confidence = 0.0; + // Get the prediction and associated confidence from the model + model->predict(img, predicted_label, predicted_confidence); + @endcode + */ + CV_WRAP void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const; + + + /** @brief - if implemented - send all result of prediction to collector that can be used for somehow custom result handling + @param src Sample image to get a prediction from. + @param collector User-defined collector object that accepts all results + + To implement this method u just have to do same internal cycle as in predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) but + not try to get "best@ result, just resend it to caller side with given collector + */ + CV_WRAP_AS(predict_collect) virtual void predict(InputArray src, Ptr collector) const = 0; + + /** @brief Saves a FaceRecognizer and its model state. + + Saves this model to a given filename, either as XML or YAML. + @param filename The filename to store this FaceRecognizer to (either XML/YAML). + + Every FaceRecognizer overwrites FaceRecognizer::save(FileStorage& fs) to save the internal model + state. FaceRecognizer::save(const String& filename) saves the state of a model to the given + filename. + + The suffix const means that prediction does not affect the internal model state, so the method can + be safely called from within different threads. + */ + CV_WRAP virtual void write(const String& filename) const; + + /** @brief Loads a FaceRecognizer and its model state. + + Loads a persisted model and state from a given XML or YAML file . Every FaceRecognizer has to + overwrite FaceRecognizer::load(FileStorage& fs) to enable loading the model state. + FaceRecognizer::load(FileStorage& fs) in turn gets called by + FaceRecognizer::load(const String& filename), to ease saving a model. + */ + CV_WRAP virtual void read(const String& filename); + + /** @overload + Saves this model to a given FileStorage. + @param fs The FileStorage to store this FaceRecognizer to. + */ + virtual void write(FileStorage& fs) const CV_OVERRIDE = 0; + + /** @overload */ + virtual void read(const FileNode& fn) CV_OVERRIDE = 0; + + /** @overload */ + virtual bool empty() const CV_OVERRIDE = 0; + + /** @brief Sets string info for the specified model's label. + + The string info is replaced by the provided value if it was set before for the specified label. + */ + CV_WRAP virtual void setLabelInfo(int label, const String& strInfo); + + /** @brief Gets string information by label. + + If an unknown label id is provided or there is no label information associated with the specified + label id the method returns an empty string. + */ + CV_WRAP virtual String getLabelInfo(int label) const; + + /** @brief Gets vector of labels by string. + + The function searches for the labels containing the specified sub-string in the associated string + info. + */ + CV_WRAP virtual std::vector getLabelsByString(const String& str) const; + /** @brief threshold parameter accessor - required for default BestMinDist collector */ + virtual double getThreshold() const = 0; + /** @brief Sets threshold of model */ + virtual void setThreshold(double val) = 0; +protected: + // Stored pairs "label id - string info" + std::map _labelsInfo; +}; + +//! @} + +}} + +#include "opencv2/face/facerec.hpp" +#include "opencv2/face/facemark.hpp" +#include "opencv2/face/facemark_train.hpp" +#include "opencv2/face/facemarkLBF.hpp" +#include "opencv2/face/facemarkAAM.hpp" +#include "opencv2/face/face_alignment.hpp" +#include "opencv2/face/mace.hpp" + +#endif // __OPENCV_FACE_HPP__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/bif.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/bif.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d4f0ec53b3c1e2d65b379c9909ebc3723db9b1a1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/bif.hpp @@ -0,0 +1,83 @@ +/* +By downloading, copying, installing or using the software you agree to this license. +If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. +Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +Copyright (C) 2015, OpenCV Foundation, all rights reserved. +Copyright (C) 2015, Itseez Inc., all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are disclaimed. +In no event shall copyright holders or contributors be liable for any direct, +indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_BIF_HPP__ +#define __OPENCV_BIF_HPP__ + +#include "opencv2/core.hpp" + +namespace cv { +namespace face { + +/** Implementation of bio-inspired features (BIF) from the paper: + * Guo, Guodong, et al. "Human age estimation using bio-inspired features." + * Computer Vision and Pattern Recognition, 2009. CVPR 2009. + */ +class CV_EXPORTS_W BIF : public Algorithm { +public: + /** @returns The number of filter bands used for computing BIF. */ + CV_WRAP virtual int getNumBands() const = 0; + + /** @returns The number of image rotations. */ + CV_WRAP virtual int getNumRotations() const = 0; + + /** Computes features sby input image. + * @param image Input image (CV_32FC1). + * @param features Feature vector (CV_32FC1). + */ + CV_WRAP virtual void compute(InputArray image, + OutputArray features) const = 0; + + /** + * @param num_bands The number of filter bands (<=8) used for computing BIF. + * @param num_rotations The number of image rotations for computing BIF. + * @returns Object for computing BIF. + */ + CV_WRAP static Ptr create(int num_bands = 8, int num_rotations = 12); +}; + +} // namespace cv +} // namespace face + +#endif // #ifndef __OPENCV_FACEREC_HPP__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/face_alignment.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/face_alignment.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e96081c77bbc874a5453cc3d4cc477dc707f02aa --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/face_alignment.hpp @@ -0,0 +1,60 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#ifndef __OPENCV_FACE_ALIGNMENT_HPP__ +#define __OPENCV_FACE_ALIGNMENT_HPP__ + +#include "opencv2/face/facemark_train.hpp" + +namespace cv{ +namespace face{ +class CV_EXPORTS_W FacemarkKazemi : public Facemark +{ +public: + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + /// cascade_depth This stores the deapth of cascade used for training. + unsigned long cascade_depth; + /// tree_depth This stores the max height of the regression tree built. + unsigned long tree_depth; + /// num_trees_per_cascade_level This stores number of trees fit per cascade level. + unsigned long num_trees_per_cascade_level; + /// learning_rate stores the learning rate in gradient boosting, also referred as shrinkage. + float learning_rate; + /// oversampling_amount stores number of initialisations used to create training samples. + unsigned long oversampling_amount; + /// num_test_coordinates stores number of test coordinates. + unsigned long num_test_coordinates; + /// lambda stores a value to calculate probability of closeness of two coordinates. + float lambda; + /// num_test_splits stores number of random test splits generated. + unsigned long num_test_splits; + /// configfile stores the name of the file containing the values of training parameters + String configfile; + }; + static Ptr create(const FacemarkKazemi::Params ¶meters = FacemarkKazemi::Params()); + virtual ~FacemarkKazemi(); + + /** @brief This function is used to train the model using gradient boosting to get a cascade of regressors + *which can then be used to predict shape. + *@param images A vector of type cv::Mat which stores the images which are used in training samples. + *@param landmarks A vector of vectors of type cv::Point2f which stores the landmarks detected in a particular image. + *@param scale A size of type cv::Size to which all images and landmarks have to be scaled to. + *@param configfile A variable of type std::string which stores the name of the file storing parameters for training the model. + *@param modelFilename A variable of type std::string which stores the name of the trained model file that has to be saved. + *@returns A boolean value. The function returns true if the model is trained properly or false if it is not trained. + */ + virtual bool training(std::vector& images, std::vector< std::vector >& landmarks,std::string configfile,Size scale,std::string modelFilename = "face_landmarks.dat")=0; + + /// set the custom face detector + virtual bool setFaceDetector(bool(*f)(InputArray , OutputArray, void*), void* userData)=0; + /// get faces using the custom detector + virtual bool getFaces(InputArray image, OutputArray faces)=0; +}; + +}} // namespace +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemark.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemark.hpp new file mode 100644 index 0000000000000000000000000000000000000000..86e9384342e37a4010dc82e4fa2174d4f8ee4673 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemark.hpp @@ -0,0 +1,95 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +/* +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACELANDMARK_HPP__ +#define __OPENCV_FACELANDMARK_HPP__ + +/** +@defgroup face Face Analysis +- @ref tutorial_table_of_content_facemark +- The Facemark API +*/ + +#include "opencv2/core.hpp" +#include + + +namespace cv { +namespace face { + + +/** @brief Abstract base class for all facemark models + +To utilize this API in your program, please take a look at the @ref tutorial_table_of_content_facemark +### Description + +Facemark is a base class which provides universal access to any specific facemark algorithm. +Therefore, the users should declare a desired algorithm before they can use it in their application. + +Here is an example on how to declare a facemark algorithm: +@code +// Using Facemark in your code: +Ptr facemark = createFacemarkLBF(); +@endcode + +The typical pipeline for facemark detection is as follows: +- Load the trained model using Facemark::loadModel. +- Perform the fitting on an image via Facemark::fit. +*/ +class CV_EXPORTS_W Facemark : public virtual Algorithm +{ +public: + + /** @brief A function to load the trained model before the fitting process. + @param model A string represent the filename of a trained model. + + Example of usage + @code + facemark->loadModel("../data/lbf.model"); + @endcode + */ + CV_WRAP virtual void loadModel( String model ) = 0; + // virtual void saveModel(String fs)=0; + + /** @brief Detect facial landmarks from an image. + @param image Input image. + @param faces Output of the function which represent region of interest of the detected faces. + Each face is stored in cv::Rect container. + @param landmarks The detected landmark points for each faces. + + Example of usage + @code + Mat image = imread("image.jpg"); + std::vector faces; + std::vector > landmarks; + facemark->fit(image, faces, landmarks); + @endcode + */ + CV_WRAP virtual bool fit( InputArray image, + InputArray faces, + OutputArrayOfArrays landmarks) = 0; +}; /* Facemark*/ + + +//! construct an AAM facemark detector +CV_EXPORTS_W Ptr createFacemarkAAM(); + +//! construct an LBF facemark detector +CV_EXPORTS_W Ptr createFacemarkLBF(); + +//! construct a Kazemi facemark detector +CV_EXPORTS_W Ptr createFacemarkKazemi(); + + +} // face +} // cv + +#endif //__OPENCV_FACELANDMARK_HPP__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemarkAAM.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemarkAAM.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6f96e4a22fdb99818ae9081f69e7808e27bff12d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemarkAAM.hpp @@ -0,0 +1,162 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. + +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACEMARK_AAM_HPP__ +#define __OPENCV_FACEMARK_AAM_HPP__ + +#include "opencv2/face/facemark_train.hpp" +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + +class CV_EXPORTS_W FacemarkAAM : public FacemarkTrain +{ +public: + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + + /** + * \brief Read parameters from file, currently unused + */ + void read(const FileNode& /*fn*/); + + /** + * \brief Read parameters from file, currently unused + */ + void write(FileStorage& /*fs*/) const; + + std::string model_filename; + int m; + int n; + int n_iter; + bool verbose; + bool save_model; + int max_m, max_n, texture_max_m; + std::vectorscales; + }; + + /** + * \brief Optional parameter for fitting process. + */ + struct CV_EXPORTS Config + { + Config( Mat rot = Mat::eye(2,2,CV_32F), + Point2f trans = Point2f(0.0f, 0.0f), + float scaling = 1.0f, + int scale_id=0 + ); + + Mat R; + Point2f t; + float scale; + int model_scale_idx; + + }; + + /** + * \brief Data container for the facemark::getData function + */ + struct CV_EXPORTS Data + { + std::vector s0; + }; + + /** + * \brief The model of AAM Algorithm + */ + struct CV_EXPORTS Model + { + std::vectorscales; + //!< defines the scales considered to build the model + + /*warping*/ + std::vector triangles; + //!< each element contains 3 values, represent index of facemarks that construct one triangle (obtained using delaunay triangulation) + + struct Texture{ + int max_m; //!< unused delete + Rect resolution; + //!< resolution of the current scale + Mat A; + //!< gray values from all face region in the dataset, projected in PCA space + Mat A0; + //!< average of gray values from all face region in the dataset + Mat AA; + //!< gray values from all erorded face region in the dataset, projected in PCA space + Mat AA0; + //!< average of gray values from all erorded face region in the dataset + + std::vector > textureIdx; + //!< index for warping of each delaunay triangle region constructed by 3 facemarks + std::vector base_shape; + //!< basic shape, normalized to be fit in an image with current detection resolution + std::vector ind1; + //!< index of pixels for mapping process to obtains the grays values of face region + std::vector ind2; + //!< index of pixels for mapping process to obtains the grays values of eroded face region + }; + std::vector textures; + //!< a container to holds the texture data for each scale of fitting + + /*shape*/ + std::vector s0; + //!< the basic shape obtained from training dataset + Mat S,Q; + //!< the encoded shapes from training data + + }; + + //! overload with additional Config structures + virtual bool fitConfig( InputArray image, InputArray roi, OutputArrayOfArrays _landmarks, const std::vector &runtime_params ) = 0; + + + //! initializer + static Ptr create(const FacemarkAAM::Params ¶meters = FacemarkAAM::Params() ); + virtual ~FacemarkAAM() {} + +}; /* AAM */ + +//! @} + +} /* namespace face */ +} /* namespace cv */ +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemarkLBF.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemarkLBF.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7f4cd325c792d60a0f834b30710ff30f96eccabf --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemarkLBF.hpp @@ -0,0 +1,120 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. + +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACEMARK_LBF_HPP__ +#define __OPENCV_FACEMARK_LBF_HPP__ + +#include "opencv2/face/facemark_train.hpp" + +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + +class CV_EXPORTS_W FacemarkLBF : public FacemarkTrain +{ +public: + struct CV_EXPORTS Params + { + /** + * \brief Constructor + */ + Params(); + + double shape_offset; + //!< offset for the loaded face landmark points + String cascade_face; + //!< filename of the face detector model + bool verbose; + //!< show the training print-out + + int n_landmarks; + //!< number of landmark points + int initShape_n; + //!< multiplier for augment the training data + + int stages_n; + //!< number of refinement stages + int tree_n; + //!< number of tree in the model for each landmark point refinement + int tree_depth; + //!< the depth of decision tree, defines the size of feature + double bagging_overlap; + //!< overlap ratio for training the LBF feature + + std::string model_filename; + //!< filename where the trained model will be saved + bool save_model; //!< flag to save the trained model or not + unsigned int seed; //!< seed for shuffling the training data + + std::vector feats_m; + std::vector radius_m; + std::vector pupils[2]; + //!< index of facemark points on pupils of left and right eye + + Rect detectROI; + + void read(const FileNode& /*fn*/); + void write(FileStorage& /*fs*/) const; + + }; + + class BBox { + public: + BBox(); + ~BBox(); + BBox(double x, double y, double w, double h); + + Mat project(const Mat &shape) const; + Mat reproject(const Mat &shape) const; + + double x, y; + double x_center, y_center; + double x_scale, y_scale; + double width, height; + }; + + static Ptr create(const FacemarkLBF::Params ¶meters = FacemarkLBF::Params() ); + virtual ~FacemarkLBF(){}; +}; /* LBF */ + +//! @} + +} /* namespace face */ +}/* namespace cv */ + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemark_train.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemark_train.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d6e27e9face230482928b49bc9a27e89d9fe3bb0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/facemark_train.hpp @@ -0,0 +1,392 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +/* +This file was part of GSoC Project: Facemark API for OpenCV +Final report: https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc +Student: Laksono Kurnianggoro +Mentor: Delia Passalacqua +*/ + +#ifndef __OPENCV_FACELANDMARKTRAIN_HPP__ +#define __OPENCV_FACELANDMARKTRAIN_HPP__ + +/** +@defgroup face Face Analysis +- @ref tutorial_table_of_content_facemark +- The Facemark API +*/ + +#include "opencv2/face/facemark.hpp" +#include "opencv2/objdetect.hpp" +#include +#include + + +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + +typedef bool(*FN_FaceDetector)(InputArray, OutputArray, void* userData); + +struct CParams{ + String cascade; //!< the face detector + double scaleFactor; //!< Parameter specifying how much the image size is reduced at each image scale. + int minNeighbors; //!< Parameter specifying how many neighbors each candidate rectangle should have to retain it. + Size minSize; //!< Minimum possible object size. + Size maxSize; //!< Maximum possible object size. + + CV_EXPORTS CParams( + String cascade_model, + double sf = 1.1, + int minN = 3, + Size minSz = Size(30, 30), + Size maxSz = Size() + ); + + CascadeClassifier face_cascade; +}; + +/** @brief Default face detector +This function is mainly utilized by the implementation of a Facemark Algorithm. +End users are advised to use function Facemark::getFaces which can be manually defined +and circumvented to the algorithm by Facemark::setFaceDetector. + +@param image The input image to be processed. +@param faces Output of the function which represent region of interest of the detected faces. +Each face is stored in cv::Rect container. +@param params detector parameters + +Example of usage +@code +std::vector faces; +CParams params("haarcascade_frontalface_alt.xml"); +cv::face::getFaces(frame, faces, ¶ms); +for(int j=0;j images_train; +std::vector landmarks_train; +loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train); +@endcode +*/ +CV_EXPORTS_W bool loadDatasetList(String imageList, + String annotationList, + std::vector & images, + std::vector & annotations); + +/** @brief A utility to load facial landmark dataset from a single file. + +@param filename The filename of a file that contains the dataset information. +Each line contains the filename of an image followed by +pairs of x and y values of facial landmarks points separated by a space. +Example +@code +/home/user/ibug/image_003_1.jpg 336.820955 240.864510 334.238298 260.922709 335.266918 ... +/home/user/ibug/image_005_1.jpg 376.158428 230.845712 376.736984 254.924635 383.265403 ... +@endcode +@param images A vector where each element represent the filename of image in the dataset. +Images are not loaded by default to save the memory. +@param facePoints The loaded landmark points for all training data. +@param delim Delimiter between each element, the default value is a whitespace. +@param offset An offset value to adjust the loaded points. + +Example of usage +@code +cv::String imageFiles = "../data/images_train.txt"; +cv::String ptsFiles = "../data/points_train.txt"; +std::vector images; +std::vector > facePoints; +loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f); +@endcode +*/ +CV_EXPORTS_W bool loadTrainingData( String filename , std::vector & images, + OutputArray facePoints, + char delim = ' ', float offset = 0.0f); + +/** @brief A utility to load facial landmark information from the dataset. + +@param imageList A file contains the list of image filenames in the training dataset. +@param groundTruth A file contains the list of filenames +where the landmarks points information are stored. +The content in each file should follow the standard format (see face::loadFacePoints). +@param images A vector where each element represent the filename of image in the dataset. +Images are not loaded by default to save the memory. +@param facePoints The loaded landmark points for all training data. +@param offset An offset value to adjust the loaded points. + +Example of usage +@code +cv::String imageFiles = "../data/images_train.txt"; +cv::String ptsFiles = "../data/points_train.txt"; +std::vector images; +std::vector > facePoints; +loadTrainingData(imageFiles, ptsFiles, images, facePoints, 0.0f); +@endcode + +example of content in the images_train.txt +@code +/home/user/ibug/image_003_1.jpg +/home/user/ibug/image_004_1.jpg +/home/user/ibug/image_005_1.jpg +/home/user/ibug/image_006.jpg +@endcode + +example of content in the points_train.txt +@code +/home/user/ibug/image_003_1.pts +/home/user/ibug/image_004_1.pts +/home/user/ibug/image_005_1.pts +/home/user/ibug/image_006.pts +@endcode +*/ +CV_EXPORTS_W bool loadTrainingData( String imageList, String groundTruth, + std::vector & images, + OutputArray facePoints, + float offset = 0.0f); + +/** @brief This function extracts the data for training from .txt files which contains the corresponding image name and landmarks. +*The first file in each file should give the path of the image whose +*landmarks are being described in the file. Then in the subsequent +*lines there should be coordinates of the landmarks in the image +*i.e each line should be of the form x,y +*where x represents the x coordinate of the landmark and y represents +*the y coordinate of the landmark. +* +*For reference you can see the files as provided in the +*HELEN dataset +* +* @param filename A vector of type cv::String containing name of the .txt files. +* @param trainlandmarks A vector of type cv::Point2f that would store shape or landmarks of all images. +* @param trainimages A vector of type cv::String which stores the name of images whose landmarks are tracked +* @returns A boolean value. It returns true when it reads the data successfully and false otherwise +*/ +CV_EXPORTS_W bool loadTrainingData(std::vector filename,std::vector< std::vector > + &trainlandmarks,std::vector & trainimages); + +/** @brief A utility to load facial landmark information from a given file. + +@param filename The filename of file contains the facial landmarks data. +@param points The loaded facial landmark points. +@param offset An offset value to adjust the loaded points. + +Example of usage +@code +std::vector points; +face::loadFacePoints("filename.txt", points, 0.0f); +@endcode + +The annotation file should follow the default format which is +@code +version: 1 +n_points: 68 +{ +212.716603 499.771793 +230.232816 566.290071 +... +} +@endcode +where n_points is the number of points considered +and each point is represented as its position in x and y. +*/ +CV_EXPORTS_W bool loadFacePoints( String filename, OutputArray points, + float offset = 0.0f); + +/** @brief Utility to draw the detected facial landmark points + +@param image The input image to be processed. +@param points Contains the data of points which will be drawn. +@param color The color of points in BGR format represented by cv::Scalar. + +Example of usage +@code +std::vector faces; +std::vector > landmarks; +facemark->getFaces(img, faces); +facemark->fit(img, faces, landmarks); +for(int j=0;j facemark = FacemarkLBF::create(); +@endcode + + +The typical pipeline for facemark detection is listed as follows: +- (Non-mandatory) Set a user defined face detection using FacemarkTrain::setFaceDetector. + The facemark algorithms are designed to fit the facial points into a face. + Therefore, the face information should be provided to the facemark algorithm. + Some algorithms might provides a default face recognition function. + However, the users might prefer to use their own face detector to obtains the best possible detection result. +- (Non-mandatory) Training the model for a specific algorithm using FacemarkTrain::training. + In this case, the model should be automatically saved by the algorithm. + If the user already have a trained model, then this part can be omitted. +- Load the trained model using Facemark::loadModel. +- Perform the fitting via the Facemark::fit. +*/ +class CV_EXPORTS_W FacemarkTrain : public Facemark +{ +public: + /** @brief Add one training sample to the trainer. + + @param image Input image. + @param landmarks The ground-truth of facial landmarks points corresponds to the image. + + Example of usage + @code + String imageFiles = "../data/images_train.txt"; + String ptsFiles = "../data/points_train.txt"; + std::vector images_train; + std::vector landmarks_train; + + // load the list of dataset: image paths and landmark file paths + loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train); + + Mat image; + std::vector facial_points; + for(size_t i=0;iaddTrainingSample(image, facial_points); + } + @endcode + + The contents in the training files should follows the standard format. + Here are examples for the contents in these files. + example of content in the images_train.txt + @code + /home/user/ibug/image_003_1.jpg + /home/user/ibug/image_004_1.jpg + /home/user/ibug/image_005_1.jpg + /home/user/ibug/image_006.jpg + @endcode + + example of content in the points_train.txt + @code + /home/user/ibug/image_003_1.pts + /home/user/ibug/image_004_1.pts + /home/user/ibug/image_005_1.pts + /home/user/ibug/image_006.pts + @endcode + + */ + virtual bool addTrainingSample(InputArray image, InputArray landmarks)=0; + + /** @brief Trains a Facemark algorithm using the given dataset. + Before the training process, training samples should be added to the trainer + using face::addTrainingSample function. + + @param parameters Optional extra parameters (algorithm dependent). + + Example of usage + @code + FacemarkLBF::Params params; + params.model_filename = "ibug68.model"; // filename to save the trained model + Ptr facemark = FacemarkLBF::create(params); + + // add training samples (see Facemark::addTrainingSample) + + facemark->training(); + @endcode + */ + + virtual void training(void* parameters=0)=0; + + /** @brief Set a user defined face detector for the Facemark algorithm. + @param detector The user defined face detector function + @param userData Detector parameters + + Example of usage + @code + MyDetectorParameters detectorParameters(...); + facemark->setFaceDetector(myDetector, &detectorParameters); + @endcode + + Example of a user defined face detector + @code + bool myDetector( InputArray image, OutputArray faces, void* userData) + { + MyDetectorParameters* params = (MyDetectorParameters*)userData; + // -------- do something -------- + } + @endcode + + TODO Lifetime of detector parameters is uncontrolled. Rework interface design to "Ptr". + */ + virtual bool setFaceDetector(FN_FaceDetector detector, void* userData = 0)=0; + + /** @brief Detect faces from a given image using default or user defined face detector. + Some Algorithm might not provide a default face detector. + + @param image Input image. + @param faces Output of the function which represent region of interest of the detected faces. Each face is stored in cv::Rect container. + + Example of usage + @code + std::vector faces; + facemark->getFaces(img, faces); + for(int j=0;jExample of usage + @code + Ptr facemark = FacemarkAAM::create(); + facemark->loadModel("AAM.yml"); + + FacemarkAAM::Data data; + facemark->getData(&data); + std::vector s0 = data.s0; + + cout<. +// Third party copyrights are property of their respective owners. + +#ifndef __OPENCV_FACEREC_HPP__ +#define __OPENCV_FACEREC_HPP__ + +#include "opencv2/face.hpp" +#include "opencv2/core.hpp" + +namespace cv { namespace face { + +//! @addtogroup face +//! @{ + +// base for two classes +class CV_EXPORTS_W BasicFaceRecognizer : public FaceRecognizer +{ +public: + /** @see setNumComponents */ + CV_WRAP int getNumComponents() const; + /** @copybrief getNumComponents @see getNumComponents */ + CV_WRAP void setNumComponents(int val); + /** @see setThreshold */ + CV_WRAP double getThreshold() const CV_OVERRIDE; + /** @copybrief getThreshold @see getThreshold */ + CV_WRAP void setThreshold(double val) CV_OVERRIDE; + CV_WRAP std::vector getProjections() const; + CV_WRAP cv::Mat getLabels() const; + CV_WRAP cv::Mat getEigenValues() const; + CV_WRAP cv::Mat getEigenVectors() const; + CV_WRAP cv::Mat getMean() const; + + virtual void read(const FileNode& fn) CV_OVERRIDE; + virtual void write(FileStorage& fs) const CV_OVERRIDE; + virtual bool empty() const CV_OVERRIDE; + + using FaceRecognizer::read; + using FaceRecognizer::write; + +protected: + int _num_components; + double _threshold; + std::vector _projections; + Mat _labels; + Mat _eigenvectors; + Mat _eigenvalues; + Mat _mean; +}; + +class CV_EXPORTS_W EigenFaceRecognizer : public BasicFaceRecognizer +{ +public: + /** + @param num_components The number of components (read: Eigenfaces) kept for this Principal + Component Analysis. As a hint: There's no rule how many components (read: Eigenfaces) should be + kept for good reconstruction capabilities. It is based on your input data, so experiment with the + number. Keeping 80 components should almost always be sufficient. + @param threshold The threshold applied in the prediction. + + ### Notes: + + - Training and prediction must be done on grayscale images, use cvtColor to convert between the + color spaces. + - **THE EIGENFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL + SIZE.** (caps-lock, because I got so many mails asking for this). You have to make sure your + input data has the correct shape, else a meaningful exception is thrown. Use resize to resize + the images. + - This model does not support updating. + + ### Model internal data: + + - num_components see EigenFaceRecognizer::create. + - threshold see EigenFaceRecognizer::create. + - eigenvalues The eigenvalues for this Principal Component Analysis (ordered descending). + - eigenvectors The eigenvectors for this Principal Component Analysis (ordered by their + eigenvalue). + - mean The sample mean calculated from the training data. + - projections The projections of the training data. + - labels The threshold applied in the prediction. If the distance to the nearest neighbor is + larger than the threshold, this method returns -1. + */ + CV_WRAP static Ptr create(int num_components = 0, double threshold = DBL_MAX); +}; + +class CV_EXPORTS_W FisherFaceRecognizer : public BasicFaceRecognizer +{ +public: + /** + @param num_components The number of components (read: Fisherfaces) kept for this Linear + Discriminant Analysis with the Fisherfaces criterion. It's useful to keep all components, that + means the number of your classes c (read: subjects, persons you want to recognize). If you leave + this at the default (0) or set it to a value less-equal 0 or greater (c-1), it will be set to the + correct number (c-1) automatically. + @param threshold The threshold applied in the prediction. If the distance to the nearest neighbor + is larger than the threshold, this method returns -1. + + ### Notes: + + - Training and prediction must be done on grayscale images, use cvtColor to convert between the + color spaces. + - **THE FISHERFACES METHOD MAKES THE ASSUMPTION, THAT THE TRAINING AND TEST IMAGES ARE OF EQUAL + SIZE.** (caps-lock, because I got so many mails asking for this). You have to make sure your + input data has the correct shape, else a meaningful exception is thrown. Use resize to resize + the images. + - This model does not support updating. + + ### Model internal data: + + - num_components see FisherFaceRecognizer::create. + - threshold see FisherFaceRecognizer::create. + - eigenvalues The eigenvalues for this Linear Discriminant Analysis (ordered descending). + - eigenvectors The eigenvectors for this Linear Discriminant Analysis (ordered by their + eigenvalue). + - mean The sample mean calculated from the training data. + - projections The projections of the training data. + - labels The labels corresponding to the projections. + */ + CV_WRAP static Ptr create(int num_components = 0, double threshold = DBL_MAX); +}; + + +class CV_EXPORTS_W LBPHFaceRecognizer : public FaceRecognizer +{ +public: + /** @see setGridX */ + CV_WRAP virtual int getGridX() const = 0; + /** @copybrief getGridX @see getGridX */ + CV_WRAP virtual void setGridX(int val) = 0; + /** @see setGridY */ + CV_WRAP virtual int getGridY() const = 0; + /** @copybrief getGridY @see getGridY */ + CV_WRAP virtual void setGridY(int val) = 0; + /** @see setRadius */ + CV_WRAP virtual int getRadius() const = 0; + /** @copybrief getRadius @see getRadius */ + CV_WRAP virtual void setRadius(int val) = 0; + /** @see setNeighbors */ + CV_WRAP virtual int getNeighbors() const = 0; + /** @copybrief getNeighbors @see getNeighbors */ + CV_WRAP virtual void setNeighbors(int val) = 0; + /** @see setThreshold */ + CV_WRAP virtual double getThreshold() const CV_OVERRIDE = 0; + /** @copybrief getThreshold @see getThreshold */ + CV_WRAP virtual void setThreshold(double val) CV_OVERRIDE = 0; + CV_WRAP virtual std::vector getHistograms() const = 0; + CV_WRAP virtual cv::Mat getLabels() const = 0; + + /** + @param radius The radius used for building the Circular Local Binary Pattern. The greater the + radius, the smoother the image but more spatial information you can get. + @param neighbors The number of sample points to build a Circular Local Binary Pattern from. An + appropriate value is to use `8` sample points. Keep in mind: the more sample points you include, + the higher the computational cost. + @param grid_x The number of cells in the horizontal direction, 8 is a common value used in + publications. The more cells, the finer the grid, the higher the dimensionality of the resulting + feature vector. + @param grid_y The number of cells in the vertical direction, 8 is a common value used in + publications. The more cells, the finer the grid, the higher the dimensionality of the resulting + feature vector. + @param threshold The threshold applied in the prediction. If the distance to the nearest neighbor + is larger than the threshold, this method returns -1. + + ### Notes: + + - The Circular Local Binary Patterns (used in training and prediction) expect the data given as + grayscale images, use cvtColor to convert between the color spaces. + - This model supports updating. + + ### Model internal data: + + - radius see LBPHFaceRecognizer::create. + - neighbors see LBPHFaceRecognizer::create. + - grid_x see LLBPHFaceRecognizer::create. + - grid_y see LBPHFaceRecognizer::create. + - threshold see LBPHFaceRecognizer::create. + - histograms Local Binary Patterns Histograms calculated from the given training data (empty if + none was given). + - labels Labels corresponding to the calculated Local Binary Patterns Histograms. + */ + CV_WRAP static Ptr create(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8, double threshold = DBL_MAX); +}; + +//! @} + +}} //namespace cv::face + +#endif //__OPENCV_FACEREC_HPP__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/mace.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/mace.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ba3ec860e6e34b4db65606813af7f46688b1f732 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/mace.hpp @@ -0,0 +1,114 @@ +// This file is part of the OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef __mace_h_onboard__ +#define __mace_h_onboard__ + +#include "opencv2/core.hpp" + + +namespace cv { +namespace face { + +//! @addtogroup face +//! @{ + + +/** +@brief Minimum Average Correlation Energy Filter + useful for authentication with (cancellable) biometrical features. + (does not need many positives to train (10-50), and no negatives at all, also robust to noise/salting) + + see also: @cite Savvides04 + + this implementation is largely based on: https://code.google.com/archive/p/pam-face-authentication (GSOC 2009) + + use it like: + @code + + Ptr mace = face::MACE::create(64); + + vector pos_images = ... + mace->train(pos_images); + + Mat query = ... + bool same = mace->same(query); + + @endcode + + you can also use two-factor authentication, with an additional passphrase: + + @code + String owners_passphrase = "ilikehotdogs"; + Ptr mace = face::MACE::create(64); + mace->salt(owners_passphrase); + vector pos_images = ... + mace->train(pos_images); + + // now, users have to give a valid passphrase, along with the image: + Mat query = ... + cout << "enter passphrase: "; + string pass; + getline(cin, pass); + mace->salt(pass); + bool same = mace->same(query); + @endcode + + save/load your model: + @code + Ptr mace = face::MACE::create(64); + mace->train(pos_images); + mace->save("my_mace.xml"); + + // later: + Ptr reloaded = MACE::load("my_mace.xml"); + reloaded->same(some_image); + @endcode + +*/ + +class CV_EXPORTS_W MACE : public cv::Algorithm +{ +public: + /** + @brief optionally encrypt images with random convolution + @param passphrase a crc64 random seed will get generated from this + */ + CV_WRAP virtual void salt(const cv::String &passphrase) = 0; + + /** + @brief train it on positive features + compute the mace filter: `h = D(-1) * X * (X(+) * D(-1) * X)(-1) * C` + also calculate a minimal threshold for this class, the smallest self-similarity from the train images + @param images a vector with the train images + */ + CV_WRAP virtual void train(cv::InputArrayOfArrays images) = 0; + + /** + @brief correlate query img and threshold to min class value + @param query a Mat with query image + */ + CV_WRAP virtual bool same(cv::InputArray query) const = 0; + + + /** + @brief constructor + @param filename build a new MACE instance from a pre-serialized FileStorage + @param objname (optional) top-level node in the FileStorage + */ + CV_WRAP static cv::Ptr load(const String &filename, const String &objname=String()); + + /** + @brief constructor + @param IMGSIZE images will get resized to this (should be an even number) + */ + CV_WRAP static cv::Ptr create(int IMGSIZE=64); +}; + +//! @} + +}/* namespace face */ +}/* namespace cv */ + +#endif // __mace_h_onboard__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/predict_collector.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/predict_collector.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dba3c7e3be8d34c07eb2ec6944fcf55ad2f2ddc7 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/face/predict_collector.hpp @@ -0,0 +1,127 @@ +/* +By downloading, copying, installing or using the software you agree to this license. +If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2000-2015, Intel Corporation, all rights reserved. +Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. +Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved. +Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. +Copyright (C) 2015, OpenCV Foundation, all rights reserved. +Copyright (C) 2015, Itseez Inc., all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are disclaimed. +In no event shall copyright holders or contributors be liable for any direct, +indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_PREDICT_COLLECTOR_HPP__ +#define __OPENCV_PREDICT_COLLECTOR_HPP__ + +#include +#include +#include +#include + +#include "opencv2/core/base.hpp" + +namespace cv { +namespace face { +//! @addtogroup face +//! @{ +/** @brief Abstract base class for all strategies of prediction result handling +*/ +class CV_EXPORTS_W PredictCollector +{ +public: + virtual ~PredictCollector() {} + + /** @brief Interface method called by face recognizer before results processing + @param size total size of prediction evaluation that recognizer could perform + */ + virtual void init(size_t size) { CV_UNUSED(size); } + + /** @brief Interface method called by face recognizer for each result + @param label current prediction label + @param dist current prediction distance (confidence) + */ + virtual bool collect(int label, double dist) = 0; +}; + +/** @brief Default predict collector + +Trace minimal distance with treshhold checking (that is default behavior for most predict logic) +*/ +class CV_EXPORTS_W StandardCollector : public PredictCollector +{ +public: + struct PredictResult + { + int label; + double distance; + PredictResult(int label_ = -1, double distance_ = DBL_MAX) : label(label_), distance(distance_) {} + }; +protected: + double threshold; + PredictResult minRes; + std::vector data; +public: + /** @brief Constructor + @param threshold_ set threshold + */ + StandardCollector(double threshold_ = DBL_MAX); + /** @brief overloaded interface method */ + void init(size_t size) CV_OVERRIDE; + /** @brief overloaded interface method */ + bool collect(int label, double dist) CV_OVERRIDE; + /** @brief Returns label with minimal distance */ + CV_WRAP int getMinLabel() const; + /** @brief Returns minimal distance value */ + CV_WRAP double getMinDist() const; + /** @brief Return results as vector + @param sorted If set, results will be sorted by distance + Each values is a pair of label and distance. + */ + CV_WRAP std::vector< std::pair > getResults(bool sorted = false) const; + /** @brief Return results as map + Labels are keys, values are minimal distances + */ + std::map getResultsMap() const; + /** @brief Static constructor + @param threshold set threshold + */ + CV_WRAP static Ptr create(double threshold = DBL_MAX); +}; + +//! @} +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7b9f3a6dd91c48d4cef23c3e7b577f2a9e342177 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d.hpp @@ -0,0 +1,1455 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_FEATURES_2D_HPP +#define OPENCV_FEATURES_2D_HPP + +#include "opencv2/opencv_modules.hpp" +#include "opencv2/core.hpp" + +#ifdef HAVE_OPENCV_FLANN +#include "opencv2/flann/miniflann.hpp" +#endif + +/** + @defgroup features2d 2D Features Framework + @{ + @defgroup features2d_main Feature Detection and Description + @defgroup features2d_match Descriptor Matchers + +Matchers of keypoint descriptors in OpenCV have wrappers with a common interface that enables you to +easily switch between different algorithms solving the same problem. This section is devoted to +matching descriptors that are represented as vectors in a multidimensional space. All objects that +implement vector descriptor matchers inherit the DescriptorMatcher interface. + +@note + - An example explaining keypoint matching can be found at + opencv_source_code/samples/cpp/descriptor_extractor_matcher.cpp + - An example on descriptor matching evaluation can be found at + opencv_source_code/samples/cpp/detector_descriptor_matcher_evaluation.cpp + - An example on one to many image matching can be found at + opencv_source_code/samples/cpp/matching_to_many_images.cpp + + @defgroup features2d_draw Drawing Function of Keypoints and Matches + @defgroup features2d_category Object Categorization + +This section describes approaches based on local 2D features and used to categorize objects. + +@note + - A complete Bag-Of-Words sample can be found at + opencv_source_code/samples/cpp/bagofwords_classification.cpp + - (Python) An example using the features2D framework to perform object categorization can be + found at opencv_source_code/samples/python/find_obj.py + + @defgroup feature2d_hal Hardware Acceleration Layer + @{ + @defgroup features2d_hal_interface Interface + @} + @} + */ + +namespace cv +{ + +//! @addtogroup features2d +//! @{ + +// //! writes vector of keypoints to the file storage +// CV_EXPORTS void write(FileStorage& fs, const String& name, const std::vector& keypoints); +// //! reads vector of keypoints from the specified file storage node +// CV_EXPORTS void read(const FileNode& node, CV_OUT std::vector& keypoints); + +/** @brief A class filters a vector of keypoints. + + Because now it is difficult to provide a convenient interface for all usage scenarios of the + keypoints filter class, it has only several needed by now static methods. + */ +class CV_EXPORTS KeyPointsFilter +{ +public: + KeyPointsFilter(){} + + /* + * Remove keypoints within borderPixels of an image edge. + */ + static void runByImageBorder( std::vector& keypoints, Size imageSize, int borderSize ); + /* + * Remove keypoints of sizes out of range. + */ + static void runByKeypointSize( std::vector& keypoints, float minSize, + float maxSize=FLT_MAX ); + /* + * Remove keypoints from some image by mask for pixels of this image. + */ + static void runByPixelsMask( std::vector& keypoints, const Mat& mask ); + /* + * Remove duplicated keypoints. + */ + static void removeDuplicated( std::vector& keypoints ); + /* + * Remove duplicated keypoints and sort the remaining keypoints + */ + static void removeDuplicatedSorted( std::vector& keypoints ); + + /* + * Retain the specified number of the best keypoints (according to the response) + */ + static void retainBest( std::vector& keypoints, int npoints ); +}; + + +/************************************ Base Classes ************************************/ + +/** @brief Abstract base class for 2D image feature detectors and descriptor extractors +*/ +#ifdef __EMSCRIPTEN__ +class CV_EXPORTS_W Feature2D : public Algorithm +#else +class CV_EXPORTS_W Feature2D : public virtual Algorithm +#endif +{ +public: + virtual ~Feature2D(); + + /** @brief Detects keypoints in an image (first variant) or image set (second variant). + + @param image Image. + @param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set + of keypoints detected in images[i] . + @param mask Mask specifying where to look for keypoints (optional). It must be a 8-bit integer + matrix with non-zero values in the region of interest. + */ + CV_WRAP virtual void detect( InputArray image, + CV_OUT std::vector& keypoints, + InputArray mask=noArray() ); + + /** @overload + @param images Image set. + @param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set + of keypoints detected in images[i] . + @param masks Masks for each input image specifying where to look for keypoints (optional). + masks[i] is a mask for images[i]. + */ + CV_WRAP virtual void detect( InputArrayOfArrays images, + CV_OUT std::vector >& keypoints, + InputArrayOfArrays masks=noArray() ); + + /** @brief Computes the descriptors for a set of keypoints detected in an image (first variant) or image set + (second variant). + + @param image Image. + @param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be + computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint + with several dominant orientations (for each orientation). + @param descriptors Computed descriptors. In the second variant of the method descriptors[i] are + descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the + descriptor for keypoint j-th keypoint. + */ + CV_WRAP virtual void compute( InputArray image, + CV_OUT CV_IN_OUT std::vector& keypoints, + OutputArray descriptors ); + + /** @overload + + @param images Image set. + @param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be + computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint + with several dominant orientations (for each orientation). + @param descriptors Computed descriptors. In the second variant of the method descriptors[i] are + descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the + descriptor for keypoint j-th keypoint. + */ + CV_WRAP virtual void compute( InputArrayOfArrays images, + CV_OUT CV_IN_OUT std::vector >& keypoints, + OutputArrayOfArrays descriptors ); + + /** Detects keypoints and computes the descriptors */ + CV_WRAP virtual void detectAndCompute( InputArray image, InputArray mask, + CV_OUT std::vector& keypoints, + OutputArray descriptors, + bool useProvidedKeypoints=false ); + + CV_WRAP virtual int descriptorSize() const; + CV_WRAP virtual int descriptorType() const; + CV_WRAP virtual int defaultNorm() const; + + CV_WRAP void write( const String& fileName ) const; + + CV_WRAP void read( const String& fileName ); + + virtual void write( FileStorage&) const CV_OVERRIDE; + + // see corresponding cv::Algorithm method + CV_WRAP virtual void read( const FileNode&) CV_OVERRIDE; + + //! Return true if detector object is empty + CV_WRAP virtual bool empty() const CV_OVERRIDE; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; + + // see corresponding cv::Algorithm method + CV_WRAP inline void write(const Ptr& fs, const String& name = String()) const { Algorithm::write(fs, name); } +}; + +/** Feature detectors in OpenCV have wrappers with a common interface that enables you to easily switch +between different algorithms solving the same problem. All objects that implement keypoint detectors +inherit the FeatureDetector interface. */ +typedef Feature2D FeatureDetector; + +/** Extractors of keypoint descriptors in OpenCV have wrappers with a common interface that enables you +to easily switch between different algorithms solving the same problem. This section is devoted to +computing descriptors represented as vectors in a multidimensional space. All objects that implement +the vector descriptor extractors inherit the DescriptorExtractor interface. + */ +typedef Feature2D DescriptorExtractor; + +//! @addtogroup features2d_main +//! @{ + +/** @brief Class implementing the BRISK keypoint detector and descriptor extractor, described in @cite LCS11 . + */ +class CV_EXPORTS_W BRISK : public Feature2D +{ +public: + /** @brief The BRISK constructor + + @param thresh AGAST detection threshold score. + @param octaves detection octaves. Use 0 to do single scale. + @param patternScale apply this scale to the pattern used for sampling the neighbourhood of a + keypoint. + */ + CV_WRAP static Ptr create(int thresh=30, int octaves=3, float patternScale=1.0f); + + /** @brief The BRISK constructor for a custom pattern + + @param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for + keypoint scale 1). + @param numberList defines the number of sampling points on the sampling circle. Must be the same + size as radiusList.. + @param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint + scale 1). + @param dMin threshold for the long pairings used for orientation determination (in pixels for + keypoint scale 1). + @param indexChange index remapping of the bits. */ + CV_WRAP static Ptr create(const std::vector &radiusList, const std::vector &numberList, + float dMax=5.85f, float dMin=8.2f, const std::vector& indexChange=std::vector()); + + /** @brief The BRISK constructor for a custom pattern, detection threshold and octaves + + @param thresh AGAST detection threshold score. + @param octaves detection octaves. Use 0 to do single scale. + @param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for + keypoint scale 1). + @param numberList defines the number of sampling points on the sampling circle. Must be the same + size as radiusList.. + @param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint + scale 1). + @param dMin threshold for the long pairings used for orientation determination (in pixels for + keypoint scale 1). + @param indexChange index remapping of the bits. */ + CV_WRAP static Ptr create(int thresh, int octaves, const std::vector &radiusList, + const std::vector &numberList, float dMax=5.85f, float dMin=8.2f, + const std::vector& indexChange=std::vector()); + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; + + /** @brief Set detection threshold. + @param threshold AGAST detection threshold score. + */ + CV_WRAP virtual void setThreshold(int threshold) { CV_UNUSED(threshold); return; } + CV_WRAP virtual int getThreshold() const { return -1; } + + /** @brief Set detection octaves. + @param octaves detection octaves. Use 0 to do single scale. + */ + CV_WRAP virtual void setOctaves(int octaves) { CV_UNUSED(octaves); return; } + CV_WRAP virtual int getOctaves() const { return -1; } +}; + +/** @brief Class implementing the ORB (*oriented BRIEF*) keypoint detector and descriptor extractor + +described in @cite RRKB11 . The algorithm uses FAST in pyramids to detect stable keypoints, selects +the strongest features using FAST or Harris response, finds their orientation using first-order +moments and computes the descriptors using BRIEF (where the coordinates of random point pairs (or +k-tuples) are rotated according to the measured orientation). + */ +class CV_EXPORTS_W ORB : public Feature2D +{ +public: + enum ScoreType { HARRIS_SCORE=0, FAST_SCORE=1 }; + static const int kBytes = 32; + + /** @brief The ORB constructor + + @param nfeatures The maximum number of features to retain. + @param scaleFactor Pyramid decimation ratio, greater than 1. scaleFactor==2 means the classical + pyramid, where each next level has 4x less pixels than the previous, but such a big scale factor + will degrade feature matching scores dramatically. On the other hand, too close to 1 scale factor + will mean that to cover certain scale range you will need more pyramid levels and so the speed + will suffer. + @param nlevels The number of pyramid levels. The smallest level will have linear size equal to + input_image_linear_size/pow(scaleFactor, nlevels - firstLevel). + @param edgeThreshold This is size of the border where the features are not detected. It should + roughly match the patchSize parameter. + @param firstLevel The level of pyramid to put source image to. Previous layers are filled + with upscaled source image. + @param WTA_K The number of points that produce each element of the oriented BRIEF descriptor. The + default value 2 means the BRIEF where we take a random point pair and compare their brightnesses, + so we get 0/1 response. Other possible values are 3 and 4. For example, 3 means that we take 3 + random points (of course, those point coordinates are random, but they are generated from the + pre-defined seed, so each element of BRIEF descriptor is computed deterministically from the pixel + rectangle), find point of maximum brightness and output index of the winner (0, 1 or 2). Such + output will occupy 2 bits, and therefore it will need a special variant of Hamming distance, + denoted as NORM_HAMMING2 (2 bits per bin). When WTA_K=4, we take 4 random points to compute each + bin (that will also occupy 2 bits with possible values 0, 1, 2 or 3). + @param scoreType The default HARRIS_SCORE means that Harris algorithm is used to rank features + (the score is written to KeyPoint::score and is used to retain best nfeatures features); + FAST_SCORE is alternative value of the parameter that produces slightly less stable keypoints, + but it is a little faster to compute. + @param patchSize size of the patch used by the oriented BRIEF descriptor. Of course, on smaller + pyramid layers the perceived image area covered by a feature will be larger. + @param fastThreshold the fast threshold + */ + CV_WRAP static Ptr create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31, + int firstLevel=0, int WTA_K=2, ORB::ScoreType scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20); + + CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; + CV_WRAP virtual int getMaxFeatures() const = 0; + + CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0; + CV_WRAP virtual double getScaleFactor() const = 0; + + CV_WRAP virtual void setNLevels(int nlevels) = 0; + CV_WRAP virtual int getNLevels() const = 0; + + CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0; + CV_WRAP virtual int getEdgeThreshold() const = 0; + + CV_WRAP virtual void setFirstLevel(int firstLevel) = 0; + CV_WRAP virtual int getFirstLevel() const = 0; + + CV_WRAP virtual void setWTA_K(int wta_k) = 0; + CV_WRAP virtual int getWTA_K() const = 0; + + CV_WRAP virtual void setScoreType(ORB::ScoreType scoreType) = 0; + CV_WRAP virtual ORB::ScoreType getScoreType() const = 0; + + CV_WRAP virtual void setPatchSize(int patchSize) = 0; + CV_WRAP virtual int getPatchSize() const = 0; + + CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0; + CV_WRAP virtual int getFastThreshold() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Maximally stable extremal region extractor + +The class encapsulates all the parameters of the %MSER extraction algorithm (see [wiki +article](http://en.wikipedia.org/wiki/Maximally_stable_extremal_regions)). + +- there are two different implementation of %MSER: one for grey image, one for color image + +- the grey image algorithm is taken from: @cite nister2008linear ; the paper claims to be faster +than union-find method; it actually get 1.5~2m/s on my centrino L7200 1.2GHz laptop. + +- the color image algorithm is taken from: @cite forssen2007maximally ; it should be much slower +than grey image method ( 3~4 times ); the chi_table.h file is taken directly from paper's source +code which is distributed under GPL. + +- (Python) A complete example showing the use of the %MSER detector can be found at samples/python/mser.py +*/ +class CV_EXPORTS_W MSER : public Feature2D +{ +public: + /** @brief Full consturctor for %MSER detector + + @param _delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$ + @param _min_area prune the area which smaller than minArea + @param _max_area prune the area which bigger than maxArea + @param _max_variation prune the area have similar size to its children + @param _min_diversity for color image, trace back to cut off mser with diversity less than min_diversity + @param _max_evolution for color image, the evolution steps + @param _area_threshold for color image, the area threshold to cause re-initialize + @param _min_margin for color image, ignore too small margin + @param _edge_blur_size for color image, the aperture size for edge blur + */ + CV_WRAP static Ptr create( int _delta=5, int _min_area=60, int _max_area=14400, + double _max_variation=0.25, double _min_diversity=.2, + int _max_evolution=200, double _area_threshold=1.01, + double _min_margin=0.003, int _edge_blur_size=5 ); + + /** @brief Detect %MSER regions + + @param image input image (8UC1, 8UC3 or 8UC4, must be greater or equal than 3x3) + @param msers resulting list of point sets + @param bboxes resulting bounding boxes + */ + CV_WRAP virtual void detectRegions( InputArray image, + CV_OUT std::vector >& msers, + CV_OUT std::vector& bboxes ) = 0; + + CV_WRAP virtual void setDelta(int delta) = 0; + CV_WRAP virtual int getDelta() const = 0; + + CV_WRAP virtual void setMinArea(int minArea) = 0; + CV_WRAP virtual int getMinArea() const = 0; + + CV_WRAP virtual void setMaxArea(int maxArea) = 0; + CV_WRAP virtual int getMaxArea() const = 0; + + CV_WRAP virtual void setPass2Only(bool f) = 0; + CV_WRAP virtual bool getPass2Only() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Wrapping class for feature detection using the FAST method. : + */ +class CV_EXPORTS_W FastFeatureDetector : public Feature2D +{ +public: + enum DetectorType + { + TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2 + }; + enum + { + THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002 + }; + + + CV_WRAP static Ptr create( int threshold=10, + bool nonmaxSuppression=true, + FastFeatureDetector::DetectorType type=FastFeatureDetector::TYPE_9_16 ); + + CV_WRAP virtual void setThreshold(int threshold) = 0; + CV_WRAP virtual int getThreshold() const = 0; + + CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; + CV_WRAP virtual bool getNonmaxSuppression() const = 0; + + CV_WRAP virtual void setType(FastFeatureDetector::DetectorType type) = 0; + CV_WRAP virtual FastFeatureDetector::DetectorType getType() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @overload */ +CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector& keypoints, + int threshold, bool nonmaxSuppression=true ); + +/** @brief Detects corners using the FAST algorithm + +@param image grayscale image where keypoints (corners) are detected. +@param keypoints keypoints detected on the image. +@param threshold threshold on difference between intensity of the central pixel and pixels of a +circle around this pixel. +@param nonmaxSuppression if true, non-maximum suppression is applied to detected corners +(keypoints). +@param type one of the three neighborhoods as defined in the paper: +FastFeatureDetector::TYPE_9_16, FastFeatureDetector::TYPE_7_12, +FastFeatureDetector::TYPE_5_8 + +Detects corners using the FAST algorithm by @cite Rosten06 . + +@note In Python API, types are given as cv.FAST_FEATURE_DETECTOR_TYPE_5_8, +cv.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv.FAST_FEATURE_DETECTOR_TYPE_9_16. For corner +detection, use cv.FAST.detect() method. + */ +CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector& keypoints, + int threshold, bool nonmaxSuppression, FastFeatureDetector::DetectorType type ); + +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Wrapping class for feature detection using the AGAST method. : + */ +class CV_EXPORTS_W AgastFeatureDetector : public Feature2D +{ +public: + enum DetectorType + { + AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3, + }; + + enum + { + THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001, + }; + + CV_WRAP static Ptr create( int threshold=10, + bool nonmaxSuppression=true, + AgastFeatureDetector::DetectorType type = AgastFeatureDetector::OAST_9_16); + + CV_WRAP virtual void setThreshold(int threshold) = 0; + CV_WRAP virtual int getThreshold() const = 0; + + CV_WRAP virtual void setNonmaxSuppression(bool f) = 0; + CV_WRAP virtual bool getNonmaxSuppression() const = 0; + + CV_WRAP virtual void setType(AgastFeatureDetector::DetectorType type) = 0; + CV_WRAP virtual AgastFeatureDetector::DetectorType getType() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @overload */ +CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector& keypoints, + int threshold, bool nonmaxSuppression=true ); + +/** @brief Detects corners using the AGAST algorithm + +@param image grayscale image where keypoints (corners) are detected. +@param keypoints keypoints detected on the image. +@param threshold threshold on difference between intensity of the central pixel and pixels of a +circle around this pixel. +@param nonmaxSuppression if true, non-maximum suppression is applied to detected corners +(keypoints). +@param type one of the four neighborhoods as defined in the paper: +AgastFeatureDetector::AGAST_5_8, AgastFeatureDetector::AGAST_7_12d, +AgastFeatureDetector::AGAST_7_12s, AgastFeatureDetector::OAST_9_16 + +For non-Intel platforms, there is a tree optimised variant of AGAST with same numerical results. +The 32-bit binary tree tables were generated automatically from original code using perl script. +The perl script and examples of tree generation are placed in features2d/doc folder. +Detects corners using the AGAST algorithm by @cite mair2010_agast . + + */ +CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector& keypoints, + int threshold, bool nonmaxSuppression, AgastFeatureDetector::DetectorType type ); + +/** @brief Wrapping class for feature detection using the goodFeaturesToTrack function. : + */ +class CV_EXPORTS_W GFTTDetector : public Feature2D +{ +public: + CV_WRAP static Ptr create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1, + int blockSize=3, bool useHarrisDetector=false, double k=0.04 ); + CV_WRAP static Ptr create( int maxCorners, double qualityLevel, double minDistance, + int blockSize, int gradiantSize, bool useHarrisDetector=false, double k=0.04 ); + CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0; + CV_WRAP virtual int getMaxFeatures() const = 0; + + CV_WRAP virtual void setQualityLevel(double qlevel) = 0; + CV_WRAP virtual double getQualityLevel() const = 0; + + CV_WRAP virtual void setMinDistance(double minDistance) = 0; + CV_WRAP virtual double getMinDistance() const = 0; + + CV_WRAP virtual void setBlockSize(int blockSize) = 0; + CV_WRAP virtual int getBlockSize() const = 0; + + CV_WRAP virtual void setHarrisDetector(bool val) = 0; + CV_WRAP virtual bool getHarrisDetector() const = 0; + + CV_WRAP virtual void setK(double k) = 0; + CV_WRAP virtual double getK() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Class for extracting blobs from an image. : + +The class implements a simple algorithm for extracting blobs from an image: + +1. Convert the source image to binary images by applying thresholding with several thresholds from + minThreshold (inclusive) to maxThreshold (exclusive) with distance thresholdStep between + neighboring thresholds. +2. Extract connected components from every binary image by findContours and calculate their + centers. +3. Group centers from several binary images by their coordinates. Close centers form one group that + corresponds to one blob, which is controlled by the minDistBetweenBlobs parameter. +4. From the groups, estimate final centers of blobs and their radiuses and return as locations and + sizes of keypoints. + +This class performs several filtrations of returned blobs. You should set filterBy\* to true/false +to turn on/off corresponding filtration. Available filtrations: + +- **By color**. This filter compares the intensity of a binary image at the center of a blob to +blobColor. If they differ, the blob is filtered out. Use blobColor = 0 to extract dark blobs +and blobColor = 255 to extract light blobs. +- **By area**. Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive). +- **By circularity**. Extracted blobs have circularity +(\f$\frac{4*\pi*Area}{perimeter * perimeter}\f$) between minCircularity (inclusive) and +maxCircularity (exclusive). +- **By ratio of the minimum inertia to maximum inertia**. Extracted blobs have this ratio +between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive). +- **By convexity**. Extracted blobs have convexity (area / area of blob convex hull) between +minConvexity (inclusive) and maxConvexity (exclusive). + +Default values of parameters are tuned to extract dark circular blobs. + */ +class CV_EXPORTS_W SimpleBlobDetector : public Feature2D +{ +public: + struct CV_EXPORTS_W_SIMPLE Params + { + CV_WRAP Params(); + CV_PROP_RW float thresholdStep; + CV_PROP_RW float minThreshold; + CV_PROP_RW float maxThreshold; + CV_PROP_RW size_t minRepeatability; + CV_PROP_RW float minDistBetweenBlobs; + + CV_PROP_RW bool filterByColor; + CV_PROP_RW uchar blobColor; + + CV_PROP_RW bool filterByArea; + CV_PROP_RW float minArea, maxArea; + + CV_PROP_RW bool filterByCircularity; + CV_PROP_RW float minCircularity, maxCircularity; + + CV_PROP_RW bool filterByInertia; + CV_PROP_RW float minInertiaRatio, maxInertiaRatio; + + CV_PROP_RW bool filterByConvexity; + CV_PROP_RW float minConvexity, maxConvexity; + + void read( const FileNode& fn ); + void write( FileStorage& fs ) const; + }; + + CV_WRAP static Ptr + create(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params()); + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +//! @} features2d_main + +//! @addtogroup features2d_main +//! @{ + +/** @brief Class implementing the KAZE keypoint detector and descriptor extractor, described in @cite ABD12 . + +@note AKAZE descriptor can only be used with KAZE or AKAZE keypoints .. [ABD12] KAZE Features. Pablo +F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. In European Conference on Computer Vision +(ECCV), Fiorenze, Italy, October 2012. +*/ +class CV_EXPORTS_W KAZE : public Feature2D +{ +public: + enum DiffusivityType + { + DIFF_PM_G1 = 0, + DIFF_PM_G2 = 1, + DIFF_WEICKERT = 2, + DIFF_CHARBONNIER = 3 + }; + + /** @brief The KAZE constructor + + @param extended Set to enable extraction of extended (128-byte) descriptor. + @param upright Set to enable use of upright descriptors (non rotation-invariant). + @param threshold Detector response threshold to accept point + @param nOctaves Maximum octave evolution of the image + @param nOctaveLayers Default number of sublevels per scale level + @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or + DIFF_CHARBONNIER + */ + CV_WRAP static Ptr create(bool extended=false, bool upright=false, + float threshold = 0.001f, + int nOctaves = 4, int nOctaveLayers = 4, + KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2); + + CV_WRAP virtual void setExtended(bool extended) = 0; + CV_WRAP virtual bool getExtended() const = 0; + + CV_WRAP virtual void setUpright(bool upright) = 0; + CV_WRAP virtual bool getUpright() const = 0; + + CV_WRAP virtual void setThreshold(double threshold) = 0; + CV_WRAP virtual double getThreshold() const = 0; + + CV_WRAP virtual void setNOctaves(int octaves) = 0; + CV_WRAP virtual int getNOctaves() const = 0; + + CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; + CV_WRAP virtual int getNOctaveLayers() const = 0; + + CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0; + CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +/** @brief Class implementing the AKAZE keypoint detector and descriptor extractor, described in @cite ANB13. + +@details AKAZE descriptors can only be used with KAZE or AKAZE keypoints. This class is thread-safe. + +@note When you need descriptors use Feature2D::detectAndCompute, which +provides better performance. When using Feature2D::detect followed by +Feature2D::compute scale space pyramid is computed twice. + +@note AKAZE implements T-API. When image is passed as UMat some parts of the algorithm +will use OpenCL. + +@note [ANB13] Fast Explicit Diffusion for Accelerated Features in Nonlinear +Scale Spaces. Pablo F. Alcantarilla, Jesús Nuevo and Adrien Bartoli. In +British Machine Vision Conference (BMVC), Bristol, UK, September 2013. + +*/ +class CV_EXPORTS_W AKAZE : public Feature2D +{ +public: + // AKAZE descriptor type + enum DescriptorType + { + DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation + DESCRIPTOR_KAZE = 3, + DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation + DESCRIPTOR_MLDB = 5 + }; + + /** @brief The AKAZE constructor + + @param descriptor_type Type of the extracted descriptor: DESCRIPTOR_KAZE, + DESCRIPTOR_KAZE_UPRIGHT, DESCRIPTOR_MLDB or DESCRIPTOR_MLDB_UPRIGHT. + @param descriptor_size Size of the descriptor in bits. 0 -\> Full size + @param descriptor_channels Number of channels in the descriptor (1, 2, 3) + @param threshold Detector response threshold to accept point + @param nOctaves Maximum octave evolution of the image + @param nOctaveLayers Default number of sublevels per scale level + @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or + DIFF_CHARBONNIER + */ + CV_WRAP static Ptr create(AKAZE::DescriptorType descriptor_type = AKAZE::DESCRIPTOR_MLDB, + int descriptor_size = 0, int descriptor_channels = 3, + float threshold = 0.001f, int nOctaves = 4, + int nOctaveLayers = 4, KAZE::DiffusivityType diffusivity = KAZE::DIFF_PM_G2); + + CV_WRAP virtual void setDescriptorType(AKAZE::DescriptorType dtype) = 0; + CV_WRAP virtual AKAZE::DescriptorType getDescriptorType() const = 0; + + CV_WRAP virtual void setDescriptorSize(int dsize) = 0; + CV_WRAP virtual int getDescriptorSize() const = 0; + + CV_WRAP virtual void setDescriptorChannels(int dch) = 0; + CV_WRAP virtual int getDescriptorChannels() const = 0; + + CV_WRAP virtual void setThreshold(double threshold) = 0; + CV_WRAP virtual double getThreshold() const = 0; + + CV_WRAP virtual void setNOctaves(int octaves) = 0; + CV_WRAP virtual int getNOctaves() const = 0; + + CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0; + CV_WRAP virtual int getNOctaveLayers() const = 0; + + CV_WRAP virtual void setDiffusivity(KAZE::DiffusivityType diff) = 0; + CV_WRAP virtual KAZE::DiffusivityType getDiffusivity() const = 0; + CV_WRAP virtual String getDefaultName() const CV_OVERRIDE; +}; + +//! @} features2d_main + +/****************************************************************************************\ +* Distance * +\****************************************************************************************/ + +template +struct CV_EXPORTS Accumulator +{ + typedef T Type; +}; + +template<> struct Accumulator { typedef float Type; }; +template<> struct Accumulator { typedef float Type; }; +template<> struct Accumulator { typedef float Type; }; +template<> struct Accumulator { typedef float Type; }; + +/* + * Squared Euclidean distance functor + */ +template +struct CV_EXPORTS SL2 +{ + static const NormTypes normType = NORM_L2SQR; + typedef T ValueType; + typedef typename Accumulator::Type ResultType; + + ResultType operator()( const T* a, const T* b, int size ) const + { + return normL2Sqr(a, b, size); + } +}; + +/* + * Euclidean distance functor + */ +template +struct L2 +{ + static const NormTypes normType = NORM_L2; + typedef T ValueType; + typedef typename Accumulator::Type ResultType; + + ResultType operator()( const T* a, const T* b, int size ) const + { + return (ResultType)std::sqrt((double)normL2Sqr(a, b, size)); + } +}; + +/* + * Manhattan distance (city block distance) functor + */ +template +struct L1 +{ + static const NormTypes normType = NORM_L1; + typedef T ValueType; + typedef typename Accumulator::Type ResultType; + + ResultType operator()( const T* a, const T* b, int size ) const + { + return normL1(a, b, size); + } +}; + +/****************************************************************************************\ +* DescriptorMatcher * +\****************************************************************************************/ + +//! @addtogroup features2d_match +//! @{ + +/** @brief Abstract base class for matching keypoint descriptors. + +It has two groups of match methods: for matching descriptors of an image with another image or with +an image set. + */ +class CV_EXPORTS_W DescriptorMatcher : public Algorithm +{ +public: + enum MatcherType + { + FLANNBASED = 1, + BRUTEFORCE = 2, + BRUTEFORCE_L1 = 3, + BRUTEFORCE_HAMMING = 4, + BRUTEFORCE_HAMMINGLUT = 5, + BRUTEFORCE_SL2 = 6 + }; + + virtual ~DescriptorMatcher(); + + /** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor + collection. + + If the collection is not empty, the new descriptors are added to existing train descriptors. + + @param descriptors Descriptors to add. Each descriptors[i] is a set of descriptors from the same + train image. + */ + CV_WRAP virtual void add( InputArrayOfArrays descriptors ); + + /** @brief Returns a constant link to the train descriptor collection trainDescCollection . + */ + CV_WRAP const std::vector& getTrainDescriptors() const; + + /** @brief Clears the train descriptor collections. + */ + CV_WRAP virtual void clear() CV_OVERRIDE; + + /** @brief Returns true if there are no train descriptors in the both collections. + */ + CV_WRAP virtual bool empty() const CV_OVERRIDE; + + /** @brief Returns true if the descriptor matcher supports masking permissible matches. + */ + CV_WRAP virtual bool isMaskSupported() const = 0; + + /** @brief Trains a descriptor matcher + + Trains a descriptor matcher (for example, the flann index). In all methods to match, the method + train() is run every time before matching. Some descriptor matchers (for example, BruteForceMatcher) + have an empty implementation of this method. Other matchers really train their inner structures (for + example, FlannBasedMatcher trains flann::Index ). + */ + CV_WRAP virtual void train(); + + /** @brief Finds the best match for each descriptor from a query set. + + @param queryDescriptors Query set of descriptors. + @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors + collection stored in the class object. + @param matches Matches. If a query descriptor is masked out in mask , no match is added for this + descriptor. So, matches size may be smaller than the query descriptors count. + @param mask Mask specifying permissible matches between an input query and train matrices of + descriptors. + + In the first variant of this method, the train descriptors are passed as an input argument. In the + second variant of the method, train descriptors collection that was set by DescriptorMatcher::add is + used. Optional mask (or masks) can be passed to specify which query and training descriptors can be + matched. Namely, queryDescriptors[i] can be matched with trainDescriptors[j] only if + mask.at\(i,j) is non-zero. + */ + CV_WRAP void match( InputArray queryDescriptors, InputArray trainDescriptors, + CV_OUT std::vector& matches, InputArray mask=noArray() ) const; + + /** @brief Finds the k best matches for each descriptor from a query set. + + @param queryDescriptors Query set of descriptors. + @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors + collection stored in the class object. + @param mask Mask specifying permissible matches between an input query and train matrices of + descriptors. + @param matches Matches. Each matches[i] is k or less matches for the same query descriptor. + @param k Count of best matches found per each query descriptor or less if a query descriptor has + less than k possible matches in total. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + + These extended variants of DescriptorMatcher::match methods find several best matches for each query + descriptor. The matches are returned in the distance increasing order. See DescriptorMatcher::match + for the details about query and train descriptors. + */ + CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors, + CV_OUT std::vector >& matches, int k, + InputArray mask=noArray(), bool compactResult=false ) const; + + /** @brief For each query descriptor, finds the training descriptors not farther than the specified distance. + + @param queryDescriptors Query set of descriptors. + @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors + collection stored in the class object. + @param matches Found matches. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + @param maxDistance Threshold for the distance between matched descriptors. Distance means here + metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured + in Pixels)! + @param mask Mask specifying permissible matches between an input query and train matrices of + descriptors. + + For each query descriptor, the methods find such training descriptors that the distance between the + query descriptor and the training descriptor is equal or smaller than maxDistance. Found matches are + returned in the distance increasing order. + */ + CV_WRAP void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors, + CV_OUT std::vector >& matches, float maxDistance, + InputArray mask=noArray(), bool compactResult=false ) const; + + /** @overload + @param queryDescriptors Query set of descriptors. + @param matches Matches. If a query descriptor is masked out in mask , no match is added for this + descriptor. So, matches size may be smaller than the query descriptors count. + @param masks Set of masks. Each masks[i] specifies permissible matches between the input query + descriptors and stored train descriptors from the i-th image trainDescCollection[i]. + */ + CV_WRAP void match( InputArray queryDescriptors, CV_OUT std::vector& matches, + InputArrayOfArrays masks=noArray() ); + /** @overload + @param queryDescriptors Query set of descriptors. + @param matches Matches. Each matches[i] is k or less matches for the same query descriptor. + @param k Count of best matches found per each query descriptor or less if a query descriptor has + less than k possible matches in total. + @param masks Set of masks. Each masks[i] specifies permissible matches between the input query + descriptors and stored train descriptors from the i-th image trainDescCollection[i]. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + */ + CV_WRAP void knnMatch( InputArray queryDescriptors, CV_OUT std::vector >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ); + /** @overload + @param queryDescriptors Query set of descriptors. + @param matches Found matches. + @param maxDistance Threshold for the distance between matched descriptors. Distance means here + metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured + in Pixels)! + @param masks Set of masks. Each masks[i] specifies permissible matches between the input query + descriptors and stored train descriptors from the i-th image trainDescCollection[i]. + @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is + false, the matches vector has the same size as queryDescriptors rows. If compactResult is true, + the matches vector does not contain matches for fully masked-out query descriptors. + */ + CV_WRAP void radiusMatch( InputArray queryDescriptors, CV_OUT std::vector >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ); + + + CV_WRAP void write( const String& fileName ) const + { + FileStorage fs(fileName, FileStorage::WRITE); + write(fs); + } + + CV_WRAP void read( const String& fileName ) + { + FileStorage fs(fileName, FileStorage::READ); + read(fs.root()); + } + // Reads matcher object from a file node + // see corresponding cv::Algorithm method + CV_WRAP virtual void read( const FileNode& ) CV_OVERRIDE; + // Writes matcher object to a file storage + virtual void write( FileStorage& ) const CV_OVERRIDE; + + /** @brief Clones the matcher. + + @param emptyTrainData If emptyTrainData is false, the method creates a deep copy of the object, + that is, copies both parameters and train data. If emptyTrainData is true, the method creates an + object copy with the current parameters but with empty train data. + */ + CV_WRAP virtual Ptr clone( bool emptyTrainData=false ) const = 0; + + /** @brief Creates a descriptor matcher of a given type with the default parameters (using default + constructor). + + @param descriptorMatcherType Descriptor matcher type. Now the following matcher types are + supported: + - `BruteForce` (it uses L2 ) + - `BruteForce-L1` + - `BruteForce-Hamming` + - `BruteForce-Hamming(2)` + - `FlannBased` + */ + CV_WRAP static Ptr create( const String& descriptorMatcherType ); + + CV_WRAP static Ptr create( const DescriptorMatcher::MatcherType& matcherType ); + + + // see corresponding cv::Algorithm method + CV_WRAP inline void write(const Ptr& fs, const String& name = String()) const { Algorithm::write(fs, name); } + +protected: + /** + * Class to work with descriptors from several images as with one merged matrix. + * It is used e.g. in FlannBasedMatcher. + */ + class CV_EXPORTS DescriptorCollection + { + public: + DescriptorCollection(); + DescriptorCollection( const DescriptorCollection& collection ); + virtual ~DescriptorCollection(); + + // Vector of matrices "descriptors" will be merged to one matrix "mergedDescriptors" here. + void set( const std::vector& descriptors ); + virtual void clear(); + + const Mat& getDescriptors() const; + const Mat getDescriptor( int imgIdx, int localDescIdx ) const; + const Mat getDescriptor( int globalDescIdx ) const; + void getLocalIdx( int globalDescIdx, int& imgIdx, int& localDescIdx ) const; + + int size() const; + + protected: + Mat mergedDescriptors; + std::vector startIdxs; + }; + + //! In fact the matching is implemented only by the following two methods. These methods suppose + //! that the class object has been trained already. Public match methods call these methods + //! after calling train(). + virtual void knnMatchImpl( InputArray queryDescriptors, std::vector >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0; + virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0; + + static bool isPossibleMatch( InputArray mask, int queryIdx, int trainIdx ); + static bool isMaskedOut( InputArrayOfArrays masks, int queryIdx ); + + static Mat clone_op( Mat m ) { return m.clone(); } + void checkMasks( InputArrayOfArrays masks, int queryDescriptorsCount ) const; + + //! Collection of descriptors from train images. + std::vector trainDescCollection; + std::vector utrainDescCollection; +}; + +/** @brief Brute-force descriptor matcher. + +For each descriptor in the first set, this matcher finds the closest descriptor in the second set +by trying each one. This descriptor matcher supports masking permissible matches of descriptor +sets. + */ +class CV_EXPORTS_W BFMatcher : public DescriptorMatcher +{ +public: + /** @brief Brute-force matcher constructor (obsolete). Please use BFMatcher.create() + * + * + */ + CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false ); + + virtual ~BFMatcher() {} + + virtual bool isMaskSupported() const CV_OVERRIDE { return true; } + + /** @brief Brute-force matcher create method. + @param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are + preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and + BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor + description). + @param crossCheck If it is false, this is will be default BFMatcher behaviour when it finds the k + nearest neighbors for each query descriptor. If crossCheck==true, then the knnMatch() method with + k=1 will only return pairs (i,j) such that for i-th query descriptor the j-th descriptor in the + matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent + pairs. Such technique usually produces best results with minimal number of outliers when there are + enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper. + */ + CV_WRAP static Ptr create( int normType=NORM_L2, bool crossCheck=false ) ; + + virtual Ptr clone( bool emptyTrainData=false ) const CV_OVERRIDE; +protected: + virtual void knnMatchImpl( InputArray queryDescriptors, std::vector >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + + int normType; + bool crossCheck; +}; + +#if defined(HAVE_OPENCV_FLANN) || defined(CV_DOXYGEN) + +/** @brief Flann-based descriptor matcher. + +This matcher trains cv::flann::Index on a train descriptor collection and calls its nearest search +methods to find the best matches. So, this matcher may be faster when matching a large train +collection than the brute force matcher. FlannBasedMatcher does not support masking permissible +matches of descriptor sets because flann::Index does not support this. : + */ +class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher +{ +public: + CV_WRAP FlannBasedMatcher( const Ptr& indexParams=makePtr(), + const Ptr& searchParams=makePtr() ); + + virtual void add( InputArrayOfArrays descriptors ) CV_OVERRIDE; + virtual void clear() CV_OVERRIDE; + + // Reads matcher object from a file node + virtual void read( const FileNode& ) CV_OVERRIDE; + // Writes matcher object to a file storage + virtual void write( FileStorage& ) const CV_OVERRIDE; + + virtual void train() CV_OVERRIDE; + virtual bool isMaskSupported() const CV_OVERRIDE; + + CV_WRAP static Ptr create(); + + virtual Ptr clone( bool emptyTrainData=false ) const CV_OVERRIDE; +protected: + static void convertToDMatches( const DescriptorCollection& descriptors, + const Mat& indices, const Mat& distances, + std::vector >& matches ); + + virtual void knnMatchImpl( InputArray queryDescriptors, std::vector >& matches, int k, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector >& matches, float maxDistance, + InputArrayOfArrays masks=noArray(), bool compactResult=false ) CV_OVERRIDE; + + Ptr indexParams; + Ptr searchParams; + Ptr flannIndex; + + DescriptorCollection mergedDescriptors; + int addedDescCount; +}; + +#endif + +//! @} features2d_match + +/****************************************************************************************\ +* Drawing functions * +\****************************************************************************************/ + +//! @addtogroup features2d_draw +//! @{ + +enum struct DrawMatchesFlags +{ + DEFAULT = 0, //!< Output image matrix will be created (Mat::create), + //!< i.e. existing memory of output image may be reused. + //!< Two source image, matches and single keypoints will be drawn. + //!< For each keypoint only the center point will be drawn (without + //!< the circle around keypoint with keypoint size and orientation). + DRAW_OVER_OUTIMG = 1, //!< Output image matrix will not be created (Mat::create). + //!< Matches will be drawn on existing content of output image. + NOT_DRAW_SINGLE_POINTS = 2, //!< Single keypoints will not be drawn. + DRAW_RICH_KEYPOINTS = 4 //!< For each keypoint the circle around keypoint with keypoint size and + //!< orientation will be drawn. +}; +CV_ENUM_FLAGS(DrawMatchesFlags) + +/** @brief Draws keypoints. + +@param image Source image. +@param keypoints Keypoints from the source image. +@param outImage Output image. Its content depends on the flags value defining what is drawn in the +output image. See possible flags bit values below. +@param color Color of keypoints. +@param flags Flags setting drawing features. Possible flags bit values are defined by +DrawMatchesFlags. See details above in drawMatches . + +@note +For Python API, flags are modified as cv.DRAW_MATCHES_FLAGS_DEFAULT, +cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS, cv.DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG, +cv.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS + */ +CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector& keypoints, InputOutputArray outImage, + const Scalar& color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); + +/** @brief Draws the found matches of keypoints from two images. + +@param img1 First source image. +@param keypoints1 Keypoints from the first source image. +@param img2 Second source image. +@param keypoints2 Keypoints from the second source image. +@param matches1to2 Matches from the first image to the second one, which means that keypoints1[i] +has a corresponding point in keypoints2[matches[i]] . +@param outImg Output image. Its content depends on the flags value defining what is drawn in the +output image. See possible flags bit values below. +@param matchColor Color of matches (lines and connected keypoints). If matchColor==Scalar::all(-1) +, the color is generated randomly. +@param singlePointColor Color of single keypoints (circles), which means that keypoints do not +have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly. +@param matchesMask Mask determining which matches are drawn. If the mask is empty, all matches are +drawn. +@param flags Flags setting drawing features. Possible flags bit values are defined by +DrawMatchesFlags. + +This function draws matches of keypoints from two images in the output image. Match is a line +connecting two keypoints (circles). See cv::DrawMatchesFlags. + */ +CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector& keypoints1, + InputArray img2, const std::vector& keypoints2, + const std::vector& matches1to2, InputOutputArray outImg, + const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), + const std::vector& matchesMask=std::vector(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); + +/** @overload */ +CV_EXPORTS_AS(drawMatchesKnn) void drawMatches( InputArray img1, const std::vector& keypoints1, + InputArray img2, const std::vector& keypoints2, + const std::vector >& matches1to2, InputOutputArray outImg, + const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1), + const std::vector >& matchesMask=std::vector >(), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT ); + +//! @} features2d_draw + +/****************************************************************************************\ +* Functions to evaluate the feature detectors and [generic] descriptor extractors * +\****************************************************************************************/ + +CV_EXPORTS void evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H1to2, + std::vector* keypoints1, std::vector* keypoints2, + float& repeatability, int& correspCount, + const Ptr& fdetector=Ptr() ); + +CV_EXPORTS void computeRecallPrecisionCurve( const std::vector >& matches1to2, + const std::vector >& correctMatches1to2Mask, + std::vector& recallPrecisionCurve ); + +CV_EXPORTS float getRecall( const std::vector& recallPrecisionCurve, float l_precision ); +CV_EXPORTS int getNearestPoint( const std::vector& recallPrecisionCurve, float l_precision ); + +/****************************************************************************************\ +* Bag of visual words * +\****************************************************************************************/ + +//! @addtogroup features2d_category +//! @{ + +/** @brief Abstract base class for training the *bag of visual words* vocabulary from a set of descriptors. + +For details, see, for example, *Visual Categorization with Bags of Keypoints* by Gabriella Csurka, +Christopher R. Dance, Lixin Fan, Jutta Willamowski, Cedric Bray, 2004. : + */ +class CV_EXPORTS_W BOWTrainer +{ +public: + BOWTrainer(); + virtual ~BOWTrainer(); + + /** @brief Adds descriptors to a training set. + + @param descriptors Descriptors to add to a training set. Each row of the descriptors matrix is a + descriptor. + + The training set is clustered using clustermethod to construct the vocabulary. + */ + CV_WRAP void add( const Mat& descriptors ); + + /** @brief Returns a training set of descriptors. + */ + CV_WRAP const std::vector& getDescriptors() const; + + /** @brief Returns the count of all descriptors stored in the training set. + */ + CV_WRAP int descriptorsCount() const; + + CV_WRAP virtual void clear(); + + /** @overload */ + CV_WRAP virtual Mat cluster() const = 0; + + /** @brief Clusters train descriptors. + + @param descriptors Descriptors to cluster. Each row of the descriptors matrix is a descriptor. + Descriptors are not added to the inner train descriptor set. + + The vocabulary consists of cluster centers. So, this method returns the vocabulary. In the first + variant of the method, train descriptors stored in the object are clustered. In the second variant, + input descriptors are clustered. + */ + CV_WRAP virtual Mat cluster( const Mat& descriptors ) const = 0; + +protected: + std::vector descriptors; + int size; +}; + +/** @brief kmeans -based class to train visual vocabulary using the *bag of visual words* approach. : + */ +class CV_EXPORTS_W BOWKMeansTrainer : public BOWTrainer +{ +public: + /** @brief The constructor. + + @see cv::kmeans + */ + CV_WRAP BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(), + int attempts=3, int flags=KMEANS_PP_CENTERS ); + virtual ~BOWKMeansTrainer(); + + // Returns trained vocabulary (i.e. cluster centers). + CV_WRAP virtual Mat cluster() const CV_OVERRIDE; + CV_WRAP virtual Mat cluster( const Mat& descriptors ) const CV_OVERRIDE; + +protected: + + int clusterCount; + TermCriteria termcrit; + int attempts; + int flags; +}; + +/** @brief Class to compute an image descriptor using the *bag of visual words*. + +Such a computation consists of the following steps: + +1. Compute descriptors for a given image and its keypoints set. +2. Find the nearest visual words from the vocabulary for each keypoint descriptor. +3. Compute the bag-of-words image descriptor as is a normalized histogram of vocabulary words +encountered in the image. The i-th bin of the histogram is a frequency of i-th word of the +vocabulary in the given image. + */ +class CV_EXPORTS_W BOWImgDescriptorExtractor +{ +public: + /** @brief The constructor. + + @param dextractor Descriptor extractor that is used to compute descriptors for an input image and + its keypoints. + @param dmatcher Descriptor matcher that is used to find the nearest word of the trained vocabulary + for each keypoint descriptor of the image. + */ + CV_WRAP BOWImgDescriptorExtractor( const Ptr& dextractor, + const Ptr& dmatcher ); + /** @overload */ + BOWImgDescriptorExtractor( const Ptr& dmatcher ); + virtual ~BOWImgDescriptorExtractor(); + + /** @brief Sets a visual vocabulary. + + @param vocabulary Vocabulary (can be trained using the inheritor of BOWTrainer ). Each row of the + vocabulary is a visual word (cluster center). + */ + CV_WRAP void setVocabulary( const Mat& vocabulary ); + + /** @brief Returns the set vocabulary. + */ + CV_WRAP const Mat& getVocabulary() const; + + /** @brief Computes an image descriptor using the set visual vocabulary. + + @param image Image, for which the descriptor is computed. + @param keypoints Keypoints detected in the input image. + @param imgDescriptor Computed output image descriptor. + @param pointIdxsOfClusters Indices of keypoints that belong to the cluster. This means that + pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster (word of vocabulary) + returned if it is non-zero. + @param descriptors Descriptors of the image keypoints that are returned if they are non-zero. + */ + void compute( InputArray image, std::vector& keypoints, OutputArray imgDescriptor, + std::vector >* pointIdxsOfClusters=0, Mat* descriptors=0 ); + /** @overload + @param keypointDescriptors Computed descriptors to match with vocabulary. + @param imgDescriptor Computed output image descriptor. + @param pointIdxsOfClusters Indices of keypoints that belong to the cluster. This means that + pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster (word of vocabulary) + returned if it is non-zero. + */ + void compute( InputArray keypointDescriptors, OutputArray imgDescriptor, + std::vector >* pointIdxsOfClusters=0 ); + // compute() is not constant because DescriptorMatcher::match is not constant + + CV_WRAP_AS(compute) void compute2( const Mat& image, std::vector& keypoints, CV_OUT Mat& imgDescriptor ) + { compute(image,keypoints,imgDescriptor); } + + /** @brief Returns an image descriptor size if the vocabulary is set. Otherwise, it returns 0. + */ + CV_WRAP int descriptorSize() const; + + /** @brief Returns an image descriptor type. + */ + CV_WRAP int descriptorType() const; + +protected: + Mat vocabulary; + Ptr dextractor; + Ptr dmatcher; +}; + +//! @} features2d_category + +//! @} features2d + +} /* namespace cv */ + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d/features2d.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d/features2d.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e81df0ad08c1757800a26376e047b0746b67a2ae --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d/features2d.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/features2d.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d/hal/interface.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d/hal/interface.h new file mode 100644 index 0000000000000000000000000000000000000000..bc3b084264a4191fc63a3d2411c9978d7a5df8de --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/features2d/hal/interface.h @@ -0,0 +1,33 @@ +#ifndef OPENCV_FEATURE2D_HAL_INTERFACE_H +#define OPENCV_FEATURE2D_HAL_INTERFACE_H + +#include "opencv2/core/cvdef.h" +//! @addtogroup features2d_hal_interface +//! @{ + +//! @name Fast feature detector types +//! @sa cv::FastFeatureDetector +//! @{ +#define CV_HAL_TYPE_5_8 0 +#define CV_HAL_TYPE_7_12 1 +#define CV_HAL_TYPE_9_16 2 +//! @} + +//! @name Key point +//! @sa cv::KeyPoint +//! @{ +struct CV_EXPORTS cvhalKeyPoint +{ + float x; + float y; + float size; + float angle; + float response; + int octave; + int class_id; +}; +//! @} + +//! @} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann.hpp new file mode 100644 index 0000000000000000000000000000000000000000..887759e643a829cce2e4ee556141973a7d8d8056 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann.hpp @@ -0,0 +1,597 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_FLANN_HPP +#define OPENCV_FLANN_HPP + +#include "opencv2/core.hpp" +#include "opencv2/flann/miniflann.hpp" +#include "opencv2/flann/flann_base.hpp" + +/** +@defgroup flann Clustering and Search in Multi-Dimensional Spaces + +This section documents OpenCV's interface to the FLANN library. FLANN (Fast Library for Approximate +Nearest Neighbors) is a library that contains a collection of algorithms optimized for fast nearest +neighbor search in large datasets and for high dimensional features. More information about FLANN +can be found in @cite Muja2009 . +*/ + +namespace cvflann +{ + CV_EXPORTS flann_distance_t flann_distance_type(); + CV_DEPRECATED CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order); +} + + +namespace cv +{ +namespace flann +{ + + +//! @addtogroup flann +//! @{ + +template struct CvType {}; +template <> struct CvType { static int type() { return CV_8U; } }; +template <> struct CvType { static int type() { return CV_8S; } }; +template <> struct CvType { static int type() { return CV_16U; } }; +template <> struct CvType { static int type() { return CV_16S; } }; +template <> struct CvType { static int type() { return CV_32S; } }; +template <> struct CvType { static int type() { return CV_32F; } }; +template <> struct CvType { static int type() { return CV_64F; } }; + + +// bring the flann parameters into this namespace +using ::cvflann::get_param; +using ::cvflann::print_params; + +// bring the flann distances into this namespace +using ::cvflann::L2_Simple; +using ::cvflann::L2; +using ::cvflann::L1; +using ::cvflann::MinkowskiDistance; +using ::cvflann::MaxDistance; +using ::cvflann::HammingLUT; +using ::cvflann::Hamming; +using ::cvflann::Hamming2; +using ::cvflann::HistIntersectionDistance; +using ::cvflann::HellingerDistance; +using ::cvflann::ChiSquareDistance; +using ::cvflann::KL_Divergence; + + +/** @brief The FLANN nearest neighbor index class. This class is templated with the type of elements for which +the index is built. + +`Distance` functor specifies the metric to be used to calculate the distance between two points. +There are several `Distance` functors that are readily available: + +cv::cvflann::L2_Simple - Squared Euclidean distance functor. +This is the simpler, unrolled version. This is preferable for very low dimensionality data (eg 3D points) + +cv::flann::L2 - Squared Euclidean distance functor, optimized version. + +cv::flann::L1 - Manhattan distance functor, optimized version. + +cv::flann::MinkowskiDistance - The Minkowsky distance functor. +This is highly optimised with loop unrolling. +The computation of squared root at the end is omitted for efficiency. + +cv::flann::MaxDistance - The max distance functor. It computes the +maximum distance between two vectors. This distance is not a valid kdtree distance, it's not +dimensionwise additive. + +cv::flann::HammingLUT - %Hamming distance functor. It counts the bit +differences between two strings using a lookup table implementation. + +cv::flann::Hamming - %Hamming distance functor. Population count is +performed using library calls, if available. Lookup table implementation is used as a fallback. + +cv::flann::Hamming2 - %Hamming distance functor. Population count is +implemented in 12 arithmetic operations (one of which is multiplication). + +cv::flann::HistIntersectionDistance - The histogram +intersection distance functor. + +cv::flann::HellingerDistance - The Hellinger distance functor. + +cv::flann::ChiSquareDistance - The chi-square distance functor. + +cv::flann::KL_Divergence - The Kullback-Leibler divergence functor. + +Although the provided implementations cover a vast range of cases, it is also possible to use +a custom implementation. The distance functor is a class whose `operator()` computes the distance +between two features. If the distance is also a kd-tree compatible distance, it should also provide an +`accum_dist()` method that computes the distance between individual feature dimensions. + +In addition to `operator()` and `accum_dist()`, a distance functor should also define the +`ElementType` and the `ResultType` as the types of the elements it operates on and the type of the +result it computes. If a distance functor can be used as a kd-tree distance (meaning that the full +distance between a pair of features can be accumulated from the partial distances between the +individual dimensions) a typedef `is_kdtree_distance` should be present inside the distance functor. +If the distance is not a kd-tree distance, but it's a distance in a vector space (the individual +dimensions of the elements it operates on can be accessed independently) a typedef +`is_vector_space_distance` should be defined inside the functor. If neither typedef is defined, the +distance is assumed to be a metric distance and will only be used with indexes operating on +generic metric distances. + */ +template +class GenericIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + /** @brief Constructs a nearest neighbor search index for a given dataset. + + @param features Matrix of containing the features(points) to index. The size of the matrix is + num_features x feature_dimensionality and the data type of the elements in the matrix must + coincide with the type of the index. + @param params Structure containing the index parameters. The type of index that will be + constructed depends on the type of this parameter. See the description. + @param distance + + The method constructs a fast search structure from a set of features using the specified algorithm + with specified parameters, as defined by params. params is a reference to one of the following class + IndexParams descendants: + + - **LinearIndexParams** When passing an object of this type, the index will perform a linear, + brute-force search. : + @code + struct LinearIndexParams : public IndexParams + { + }; + @endcode + - **KDTreeIndexParams** When passing an object of this type the index constructed will consist of + a set of randomized kd-trees which will be searched in parallel. : + @code + struct KDTreeIndexParams : public IndexParams + { + KDTreeIndexParams( int trees = 4 ); + }; + @endcode + - **KMeansIndexParams** When passing an object of this type the index constructed will be a + hierarchical k-means tree. : + @code + struct KMeansIndexParams : public IndexParams + { + KMeansIndexParams( + int branching = 32, + int iterations = 11, + flann_centers_init_t centers_init = CENTERS_RANDOM, + float cb_index = 0.2 ); + }; + @endcode + - **CompositeIndexParams** When using a parameters object of this type the index created + combines the randomized kd-trees and the hierarchical k-means tree. : + @code + struct CompositeIndexParams : public IndexParams + { + CompositeIndexParams( + int trees = 4, + int branching = 32, + int iterations = 11, + flann_centers_init_t centers_init = CENTERS_RANDOM, + float cb_index = 0.2 ); + }; + @endcode + - **LshIndexParams** When using a parameters object of this type the index created uses + multi-probe LSH (by Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search + by Qin Lv, William Josephson, Zhe Wang, Moses Charikar, Kai Li., Proceedings of the 33rd + International Conference on Very Large Data Bases (VLDB). Vienna, Austria. September 2007) : + @code + struct LshIndexParams : public IndexParams + { + LshIndexParams( + unsigned int table_number, + unsigned int key_size, + unsigned int multi_probe_level ); + }; + @endcode + - **AutotunedIndexParams** When passing an object of this type the index created is + automatically tuned to offer the best performance, by choosing the optimal index type + (randomized kd-trees, hierarchical kmeans, linear) and parameters for the dataset provided. : + @code + struct AutotunedIndexParams : public IndexParams + { + AutotunedIndexParams( + float target_precision = 0.9, + float build_weight = 0.01, + float memory_weight = 0, + float sample_fraction = 0.1 ); + }; + @endcode + - **SavedIndexParams** This object type is used for loading a previously saved index from the + disk. : + @code + struct SavedIndexParams : public IndexParams + { + SavedIndexParams( String filename ); + }; + @endcode + */ + GenericIndex(const Mat& features, const ::cvflann::IndexParams& params, Distance distance = Distance()); + + ~GenericIndex(); + + /** @brief Performs a K-nearest neighbor search for a given query point using the index. + + @param query The query point + @param indices Vector that will contain the indices of the K-nearest neighbors found. It must have + at least knn size. + @param dists Vector that will contain the distances to the K-nearest neighbors found. It must have + at least knn size. + @param knn Number of nearest neighbors to search for. + @param params SearchParams + */ + void knnSearch(const std::vector& query, std::vector& indices, + std::vector& dists, int knn, const ::cvflann::SearchParams& params); + void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params); + + /** @brief Performs a radius nearest neighbor search for a given query point using the index. + + @param query The query point. + @param indices Vector that will contain the indices of the nearest neighbors found. + @param dists Vector that will contain the distances to the nearest neighbors found. It has the same + number of elements as indices. + @param radius The search radius. + @param params SearchParams + + This function returns the number of nearest neighbors found. + */ + int radiusSearch(const std::vector& query, std::vector& indices, + std::vector& dists, DistanceType radius, const ::cvflann::SearchParams& params); + int radiusSearch(const Mat& query, Mat& indices, Mat& dists, + DistanceType radius, const ::cvflann::SearchParams& params); + + void save(String filename) { nnIndex->save(filename); } + + int veclen() const { return nnIndex->veclen(); } + + int size() const { return (int)nnIndex->size(); } + + ::cvflann::IndexParams getParameters() { return nnIndex->getParameters(); } + + CV_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() { return nnIndex->getIndexParameters(); } + +private: + ::cvflann::Index* nnIndex; + Mat _dataset; +}; + +//! @cond IGNORED + +#define FLANN_DISTANCE_CHECK \ + if ( ::cvflann::flann_distance_type() != cvflann::FLANN_DIST_L2) { \ + printf("[WARNING] You are using cv::flann::Index (or cv::flann::GenericIndex) and have also changed "\ + "the distance using cvflann::set_distance_type. This is no longer working as expected "\ + "(cv::flann::Index always uses L2). You should create the index templated on the distance, "\ + "for example for L1 distance use: GenericIndex< L1 > \n"); \ + } + + +template +GenericIndex::GenericIndex(const Mat& dataset, const ::cvflann::IndexParams& params, Distance distance) +: _dataset(dataset) +{ + CV_Assert(dataset.type() == CvType::type()); + CV_Assert(dataset.isContinuous()); + ::cvflann::Matrix m_dataset((ElementType*)_dataset.ptr(0), _dataset.rows, _dataset.cols); + + nnIndex = new ::cvflann::Index(m_dataset, params, distance); + + FLANN_DISTANCE_CHECK + + nnIndex->buildIndex(); +} + +template +GenericIndex::~GenericIndex() +{ + delete nnIndex; +} + +template +void GenericIndex::knnSearch(const std::vector& query, std::vector& indices, std::vector& dists, int knn, const ::cvflann::SearchParams& searchParams) +{ + ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); + + FLANN_DISTANCE_CHECK + + nnIndex->knnSearch(m_query,m_indices,m_dists,knn,searchParams); +} + + +template +void GenericIndex::knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams) +{ + CV_Assert(queries.type() == CvType::type()); + CV_Assert(queries.isContinuous()); + ::cvflann::Matrix m_queries((ElementType*)queries.ptr(0), queries.rows, queries.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); + + FLANN_DISTANCE_CHECK + + nnIndex->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); +} + +template +int GenericIndex::radiusSearch(const std::vector& query, std::vector& indices, std::vector& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) +{ + ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); + + FLANN_DISTANCE_CHECK + + return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); +} + +template +int GenericIndex::radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) +{ + CV_Assert(query.type() == CvType::type()); + CV_Assert(query.isContinuous()); + ::cvflann::Matrix m_query((ElementType*)query.ptr(0), query.rows, query.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); + + FLANN_DISTANCE_CHECK + + return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); +} + +/** + * @deprecated Use GenericIndex class instead + */ +template +class Index_ +{ +public: + typedef typename L2::ElementType ElementType; + typedef typename L2::ResultType DistanceType; + + CV_DEPRECATED Index_(const Mat& dataset, const ::cvflann::IndexParams& params) + { + printf("[WARNING] The cv::flann::Index_ class is deperecated, use cv::flann::GenericIndex instead\n"); + + CV_Assert(dataset.type() == CvType::type()); + CV_Assert(dataset.isContinuous()); + ::cvflann::Matrix m_dataset((ElementType*)dataset.ptr(0), dataset.rows, dataset.cols); + + if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) { + nnIndex_L1 = NULL; + nnIndex_L2 = new ::cvflann::Index< L2 >(m_dataset, params); + } + else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) { + nnIndex_L1 = new ::cvflann::Index< L1 >(m_dataset, params); + nnIndex_L2 = NULL; + } + else { + printf("[ERROR] cv::flann::Index_ only provides backwards compatibility for the L1 and L2 distances. " + "For other distance types you must use cv::flann::GenericIndex\n"); + CV_Assert(0); + } + if (nnIndex_L1) nnIndex_L1->buildIndex(); + if (nnIndex_L2) nnIndex_L2->buildIndex(); + } + CV_DEPRECATED ~Index_() + { + if (nnIndex_L1) delete nnIndex_L1; + if (nnIndex_L2) delete nnIndex_L2; + } + + CV_DEPRECATED void knnSearch(const std::vector& query, std::vector& indices, std::vector& dists, int knn, const ::cvflann::SearchParams& searchParams) + { + ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); + + if (nnIndex_L1) nnIndex_L1->knnSearch(m_query,m_indices,m_dists,knn,searchParams); + if (nnIndex_L2) nnIndex_L2->knnSearch(m_query,m_indices,m_dists,knn,searchParams); + } + CV_DEPRECATED void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams) + { + CV_Assert(queries.type() == CvType::type()); + CV_Assert(queries.isContinuous()); + ::cvflann::Matrix m_queries((ElementType*)queries.ptr(0), queries.rows, queries.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); + + if (nnIndex_L1) nnIndex_L1->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); + if (nnIndex_L2) nnIndex_L2->knnSearch(m_queries,m_indices,m_dists,knn, searchParams); + } + + CV_DEPRECATED int radiusSearch(const std::vector& query, std::vector& indices, std::vector& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) + { + ::cvflann::Matrix m_query((ElementType*)&query[0], 1, query.size()); + ::cvflann::Matrix m_indices(&indices[0], 1, indices.size()); + ::cvflann::Matrix m_dists(&dists[0], 1, dists.size()); + + if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + } + + CV_DEPRECATED int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams) + { + CV_Assert(query.type() == CvType::type()); + CV_Assert(query.isContinuous()); + ::cvflann::Matrix m_query((ElementType*)query.ptr(0), query.rows, query.cols); + + CV_Assert(indices.type() == CV_32S); + CV_Assert(indices.isContinuous()); + ::cvflann::Matrix m_indices((int*)indices.ptr(0), indices.rows, indices.cols); + + CV_Assert(dists.type() == CvType::type()); + CV_Assert(dists.isContinuous()); + ::cvflann::Matrix m_dists((DistanceType*)dists.ptr(0), dists.rows, dists.cols); + + if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams); + } + + CV_DEPRECATED void save(String filename) + { + if (nnIndex_L1) nnIndex_L1->save(filename); + if (nnIndex_L2) nnIndex_L2->save(filename); + } + + CV_DEPRECATED int veclen() const + { + if (nnIndex_L1) return nnIndex_L1->veclen(); + if (nnIndex_L2) return nnIndex_L2->veclen(); + } + + CV_DEPRECATED int size() const + { + if (nnIndex_L1) return nnIndex_L1->size(); + if (nnIndex_L2) return nnIndex_L2->size(); + } + + CV_DEPRECATED ::cvflann::IndexParams getParameters() + { + if (nnIndex_L1) return nnIndex_L1->getParameters(); + if (nnIndex_L2) return nnIndex_L2->getParameters(); + + } + + CV_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() + { + if (nnIndex_L1) return nnIndex_L1->getIndexParameters(); + if (nnIndex_L2) return nnIndex_L2->getIndexParameters(); + } + +private: + // providing backwards compatibility for L2 and L1 distances (most common) + ::cvflann::Index< L2 >* nnIndex_L2; + ::cvflann::Index< L1 >* nnIndex_L1; +}; + +//! @endcond + +/** @brief Clusters features using hierarchical k-means algorithm. + +@param features The points to be clustered. The matrix must have elements of type +Distance::ElementType. +@param centers The centers of the clusters obtained. The matrix must have type +Distance::ResultType. The number of rows in this matrix represents the number of clusters desired, +however, because of the way the cut in the hierarchical tree is chosen, the number of clusters +computed will be the highest number of the form (branching-1)\*k+1 that's lower than the number of +clusters desired, where branching is the tree's branching factor (see description of the +KMeansIndexParams). +@param params Parameters used in the construction of the hierarchical k-means tree. +@param d Distance to be used for clustering. + +The method clusters the given feature vectors by constructing a hierarchical k-means tree and +choosing a cut in the tree that minimizes the cluster's variance. It returns the number of clusters +found. + */ +template +int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params, + Distance d = Distance()) +{ + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + CV_Assert(features.type() == CvType::type()); + CV_Assert(features.isContinuous()); + ::cvflann::Matrix m_features((ElementType*)features.ptr(0), features.rows, features.cols); + + CV_Assert(centers.type() == CvType::type()); + CV_Assert(centers.isContinuous()); + ::cvflann::Matrix m_centers((DistanceType*)centers.ptr(0), centers.rows, centers.cols); + + return ::cvflann::hierarchicalClustering(m_features, m_centers, params, d); +} + +//! @cond IGNORED + +template +CV_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params) +{ + printf("[WARNING] cv::flann::hierarchicalClustering is deprecated, use " + "cv::flann::hierarchicalClustering instead\n"); + + if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) { + return hierarchicalClustering< L2 >(features, centers, params); + } + else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) { + return hierarchicalClustering< L1 >(features, centers, params); + } + else { + printf("[ERROR] cv::flann::hierarchicalClustering only provides backwards " + "compatibility for the L1 and L2 distances. " + "For other distance types you must use cv::flann::hierarchicalClustering\n"); + CV_Assert(0); + } +} + +//! @endcond + +//! @} flann + +} } // namespace cv::flann + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/all_indices.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/all_indices.h new file mode 100644 index 0000000000000000000000000000000000000000..ba5a2f2dde6b13089e148d98755aea189353cd3c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/all_indices.h @@ -0,0 +1,159 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_ALL_INDICES_H_ +#define OPENCV_FLANN_ALL_INDICES_H_ + +//! @cond IGNORED + +#include "general.h" + +#include "nn_index.h" +#include "kdtree_index.h" +#include "kdtree_single_index.h" +#include "kmeans_index.h" +#include "composite_index.h" +#include "linear_index.h" +#include "hierarchical_clustering_index.h" +#include "lsh_index.h" +#include "autotuned_index.h" + + +namespace cvflann +{ + +template +struct index_creator +{ + static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) + { + flann_algorithm_t index_type = get_param(params, "algorithm"); + + NNIndex* nnIndex; + switch (index_type) { + case FLANN_INDEX_LINEAR: + nnIndex = new LinearIndex(dataset, params, distance); + break; + case FLANN_INDEX_KDTREE_SINGLE: + nnIndex = new KDTreeSingleIndex(dataset, params, distance); + break; + case FLANN_INDEX_KDTREE: + nnIndex = new KDTreeIndex(dataset, params, distance); + break; + case FLANN_INDEX_KMEANS: + nnIndex = new KMeansIndex(dataset, params, distance); + break; + case FLANN_INDEX_COMPOSITE: + nnIndex = new CompositeIndex(dataset, params, distance); + break; + case FLANN_INDEX_AUTOTUNED: + nnIndex = new AutotunedIndex(dataset, params, distance); + break; + case FLANN_INDEX_HIERARCHICAL: + nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); + break; + case FLANN_INDEX_LSH: + nnIndex = new LshIndex(dataset, params, distance); + break; + default: + throw FLANNException("Unknown index type"); + } + + return nnIndex; + } +}; + +template +struct index_creator +{ + static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) + { + flann_algorithm_t index_type = get_param(params, "algorithm"); + + NNIndex* nnIndex; + switch (index_type) { + case FLANN_INDEX_LINEAR: + nnIndex = new LinearIndex(dataset, params, distance); + break; + case FLANN_INDEX_KMEANS: + nnIndex = new KMeansIndex(dataset, params, distance); + break; + case FLANN_INDEX_HIERARCHICAL: + nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); + break; + case FLANN_INDEX_LSH: + nnIndex = new LshIndex(dataset, params, distance); + break; + default: + throw FLANNException("Unknown index type"); + } + + return nnIndex; + } +}; + +template +struct index_creator +{ + static NNIndex* create(const Matrix& dataset, const IndexParams& params, const Distance& distance) + { + flann_algorithm_t index_type = get_param(params, "algorithm"); + + NNIndex* nnIndex; + switch (index_type) { + case FLANN_INDEX_LINEAR: + nnIndex = new LinearIndex(dataset, params, distance); + break; + case FLANN_INDEX_HIERARCHICAL: + nnIndex = new HierarchicalClusteringIndex(dataset, params, distance); + break; + case FLANN_INDEX_LSH: + nnIndex = new LshIndex(dataset, params, distance); + break; + default: + throw FLANNException("Unknown index type"); + } + + return nnIndex; + } +}; + +template +NNIndex* create_index_by_type(const Matrix& dataset, const IndexParams& params, const Distance& distance) +{ + return index_creator::create(dataset, params,distance); +} + +} + +//! @endcond + +#endif /* OPENCV_FLANN_ALL_INDICES_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/allocator.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/allocator.h new file mode 100644 index 0000000000000000000000000000000000000000..d5870a018161e8c34da8e663b26f57a72fe96585 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/allocator.h @@ -0,0 +1,196 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_ALLOCATOR_H_ +#define OPENCV_FLANN_ALLOCATOR_H_ + +//! @cond IGNORED + +#include +#include + + +namespace cvflann +{ + +/** + * Allocates (using C's malloc) a generic type T. + * + * Params: + * count = number of instances to allocate. + * Returns: pointer (of type T*) to memory buffer + */ +template +T* allocate(size_t count = 1) +{ + T* mem = (T*) ::malloc(sizeof(T)*count); + return mem; +} + + +/** + * Pooled storage allocator + * + * The following routines allow for the efficient allocation of storage in + * small chunks from a specified pool. Rather than allowing each structure + * to be freed individually, an entire pool of storage is freed at once. + * This method has two advantages over just using malloc() and free(). First, + * it is far more efficient for allocating small objects, as there is + * no overhead for remembering all the information needed to free each + * object or consolidating fragmented memory. Second, the decision about + * how long to keep an object is made at the time of allocation, and there + * is no need to track down all the objects to free them. + * + */ + +const size_t WORDSIZE=16; +const size_t BLOCKSIZE=8192; + +class PooledAllocator +{ + /* We maintain memory alignment to word boundaries by requiring that all + allocations be in multiples of the machine wordsize. */ + /* Size of machine word in bytes. Must be power of 2. */ + /* Minimum number of bytes requested at a time from the system. Must be multiple of WORDSIZE. */ + + + int remaining; /* Number of bytes left in current block of storage. */ + void* base; /* Pointer to base of current block of storage. */ + void* loc; /* Current location in block to next allocate memory. */ + int blocksize; + + +public: + int usedMemory; + int wastedMemory; + + /** + Default constructor. Initializes a new pool. + */ + PooledAllocator(int blockSize = BLOCKSIZE) + { + blocksize = blockSize; + remaining = 0; + base = NULL; + loc = NULL; + + usedMemory = 0; + wastedMemory = 0; + } + + /** + * Destructor. Frees all the memory allocated in this pool. + */ + ~PooledAllocator() + { + void* prev; + + while (base != NULL) { + prev = *((void**) base); /* Get pointer to prev block. */ + ::free(base); + base = prev; + } + } + + /** + * Returns a pointer to a piece of new memory of the given size in bytes + * allocated from the pool. + */ + void* allocateMemory(int size) + { + int blockSize; + + /* Round size up to a multiple of wordsize. The following expression + only works for WORDSIZE that is a power of 2, by masking last bits of + incremented size to zero. + */ + size = (size + (WORDSIZE - 1)) & ~(WORDSIZE - 1); + + /* Check whether a new block must be allocated. Note that the first word + of a block is reserved for a pointer to the previous block. + */ + if (size > remaining) { + + wastedMemory += remaining; + + /* Allocate new storage. */ + blockSize = (size + sizeof(void*) + (WORDSIZE-1) > BLOCKSIZE) ? + size + sizeof(void*) + (WORDSIZE-1) : BLOCKSIZE; + + // use the standard C malloc to allocate memory + void* m = ::malloc(blockSize); + if (!m) { + fprintf(stderr,"Failed to allocate memory.\n"); + return NULL; + } + + /* Fill first word of new block with pointer to previous block. */ + ((void**) m)[0] = base; + base = m; + + int shift = 0; + //int shift = (WORDSIZE - ( (((size_t)m) + sizeof(void*)) & (WORDSIZE-1))) & (WORDSIZE-1); + + remaining = blockSize - sizeof(void*) - shift; + loc = ((char*)m + sizeof(void*) + shift); + } + void* rloc = loc; + loc = (char*)loc + size; + remaining -= size; + + usedMemory += size; + + return rloc; + } + + /** + * Allocates (using this pool) a generic type T. + * + * Params: + * count = number of instances to allocate. + * Returns: pointer (of type T*) to memory buffer + */ + template + T* allocate(size_t count = 1) + { + T* mem = (T*) this->allocateMemory((int)(sizeof(T)*count)); + return mem; + } + +private: + PooledAllocator(const PooledAllocator &); // copy disabled + PooledAllocator& operator=(const PooledAllocator &); // assign disabled +}; + +} + +//! @endcond + +#endif //OPENCV_FLANN_ALLOCATOR_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/any.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/any.h new file mode 100644 index 0000000000000000000000000000000000000000..f5684e996256b657b3aa887d9150b7562ae6ad33 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/any.h @@ -0,0 +1,334 @@ +#ifndef OPENCV_FLANN_ANY_H_ +#define OPENCV_FLANN_ANY_H_ +/* + * (C) Copyright Christopher Diggins 2005-2011 + * (C) Copyright Pablo Aguilar 2005 + * (C) Copyright Kevlin Henney 2001 + * + * Distributed under the Boost Software License, Version 1.0. (See + * accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt + * + * Adapted for FLANN by Marius Muja + */ + +//! @cond IGNORED + +#include "defines.h" +#include +#include +#include + +namespace cvflann +{ + +namespace anyimpl +{ + +struct bad_any_cast +{ +}; + +struct empty_any +{ +}; + +inline std::ostream& operator <<(std::ostream& out, const empty_any&) +{ + out << "[empty_any]"; + return out; +} + +struct base_any_policy +{ + virtual void static_delete(void** x) = 0; + virtual void copy_from_value(void const* src, void** dest) = 0; + virtual void clone(void* const* src, void** dest) = 0; + virtual void move(void* const* src, void** dest) = 0; + virtual void* get_value(void** src) = 0; + virtual const void* get_value(void* const * src) = 0; + virtual ::size_t get_size() = 0; + virtual const std::type_info& type() = 0; + virtual void print(std::ostream& out, void* const* src) = 0; + virtual ~base_any_policy() {} +}; + +template +struct typed_base_any_policy : base_any_policy +{ + virtual ::size_t get_size() CV_OVERRIDE { return sizeof(T); } + virtual const std::type_info& type() CV_OVERRIDE { return typeid(T); } + +}; + +template +struct small_any_policy CV_FINAL : typed_base_any_policy +{ + virtual void static_delete(void**) CV_OVERRIDE { } + virtual void copy_from_value(void const* src, void** dest) CV_OVERRIDE + { + new (dest) T(* reinterpret_cast(src)); + } + virtual void clone(void* const* src, void** dest) CV_OVERRIDE { *dest = *src; } + virtual void move(void* const* src, void** dest) CV_OVERRIDE { *dest = *src; } + virtual void* get_value(void** src) CV_OVERRIDE { return reinterpret_cast(src); } + virtual const void* get_value(void* const * src) CV_OVERRIDE { return reinterpret_cast(src); } + virtual void print(std::ostream& out, void* const* src) CV_OVERRIDE { out << *reinterpret_cast(src); } +}; + +template +struct big_any_policy CV_FINAL : typed_base_any_policy +{ + virtual void static_delete(void** x) CV_OVERRIDE + { + if (* x) delete (* reinterpret_cast(x)); + *x = NULL; + } + virtual void copy_from_value(void const* src, void** dest) CV_OVERRIDE + { + *dest = new T(*reinterpret_cast(src)); + } + virtual void clone(void* const* src, void** dest) CV_OVERRIDE + { + *dest = new T(**reinterpret_cast(src)); + } + virtual void move(void* const* src, void** dest) CV_OVERRIDE + { + (*reinterpret_cast(dest))->~T(); + **reinterpret_cast(dest) = **reinterpret_cast(src); + } + virtual void* get_value(void** src) CV_OVERRIDE { return *src; } + virtual const void* get_value(void* const * src) CV_OVERRIDE { return *src; } + virtual void print(std::ostream& out, void* const* src) CV_OVERRIDE { out << *reinterpret_cast(*src); } +}; + +template<> inline void big_any_policy::print(std::ostream& out, void* const* src) +{ + out << int(*reinterpret_cast(*src)); +} + +template<> inline void big_any_policy::print(std::ostream& out, void* const* src) +{ + out << int(*reinterpret_cast(*src)); +} + +template<> inline void big_any_policy::print(std::ostream& out, void* const* src) +{ + out << (*reinterpret_cast(*src)).c_str(); +} + +template +struct choose_policy +{ + typedef big_any_policy type; +}; + +template +struct choose_policy +{ + typedef small_any_policy type; +}; + +struct any; + +/// Choosing the policy for an any type is illegal, but should never happen. +/// This is designed to throw a compiler error. +template<> +struct choose_policy +{ + typedef void type; +}; + +/// Specializations for small types. +#define SMALL_POLICY(TYPE) \ + template<> \ + struct choose_policy { typedef small_any_policy type; \ + } + +SMALL_POLICY(signed char); +SMALL_POLICY(unsigned char); +SMALL_POLICY(signed short); +SMALL_POLICY(unsigned short); +SMALL_POLICY(signed int); +SMALL_POLICY(unsigned int); +SMALL_POLICY(signed long); +SMALL_POLICY(unsigned long); +SMALL_POLICY(float); +SMALL_POLICY(bool); + +#undef SMALL_POLICY + +template +class SinglePolicy +{ + SinglePolicy(); + SinglePolicy(const SinglePolicy& other); + SinglePolicy& operator=(const SinglePolicy& other); + +public: + static base_any_policy* get_policy(); + +private: + static typename choose_policy::type policy; +}; + +template +typename choose_policy::type SinglePolicy::policy; + +/// This function will return a different policy for each type. +template +inline base_any_policy* SinglePolicy::get_policy() { return &policy; } + +} // namespace anyimpl + +struct any +{ +private: + // fields + anyimpl::base_any_policy* policy; + void* object; + +public: + /// Initializing constructor. + template + any(const T& x) + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) + { + assign(x); + } + + /// Empty constructor. + any() + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) + { } + + /// Special initializing constructor for string literals. + any(const char* x) + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) + { + assign(x); + } + + /// Copy constructor. + any(const any& x) + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) + { + assign(x); + } + + /// Destructor. + ~any() + { + policy->static_delete(&object); + } + + /// Assignment function from another any. + any& assign(const any& x) + { + reset(); + policy = x.policy; + policy->clone(&x.object, &object); + return *this; + } + + /// Assignment function. + template + any& assign(const T& x) + { + reset(); + policy = anyimpl::SinglePolicy::get_policy(); + policy->copy_from_value(&x, &object); + return *this; + } + + /// Assignment operator. + template + any& operator=(const T& x) + { + return assign(x); + } + + /// Assignment operator. Template-based version above doesn't work as expected. We need regular assignment operator here. + any& operator=(const any& x) + { + return assign(x); + } + + /// Assignment operator, specialed for literal strings. + /// They have types like const char [6] which don't work as expected. + any& operator=(const char* x) + { + return assign(x); + } + + /// Utility functions + any& swap(any& x) + { + std::swap(policy, x.policy); + std::swap(object, x.object); + return *this; + } + + /// Cast operator. You can only cast to the original type. + template + T& cast() + { + if (policy->type() != typeid(T)) throw anyimpl::bad_any_cast(); + T* r = reinterpret_cast(policy->get_value(&object)); + return *r; + } + + /// Cast operator. You can only cast to the original type. + template + const T& cast() const + { + if (policy->type() != typeid(T)) throw anyimpl::bad_any_cast(); + const T* r = reinterpret_cast(policy->get_value(&object)); + return *r; + } + + /// Returns true if the any contains no value. + bool empty() const + { + return policy->type() == typeid(anyimpl::empty_any); + } + + /// Frees any allocated memory, and sets the value to NULL. + void reset() + { + policy->static_delete(&object); + policy = anyimpl::SinglePolicy::get_policy(); + } + + /// Returns true if the two types are the same. + bool compatible(const any& x) const + { + return policy->type() == x.policy->type(); + } + + /// Returns if the type is compatible with the policy + template + bool has_type() + { + return policy->type() == typeid(T); + } + + const std::type_info& type() const + { + return policy->type(); + } + + friend std::ostream& operator <<(std::ostream& out, const any& any_val); +}; + +inline std::ostream& operator <<(std::ostream& out, const any& any_val) +{ + any_val.policy->print(out,&any_val.object); + return out; +} + +} + +//! @endcond + +#endif // OPENCV_FLANN_ANY_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/autotuned_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/autotuned_index.h new file mode 100644 index 0000000000000000000000000000000000000000..eb4554f077654e1b4a02ce7bddad97ea48eb9216 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/autotuned_index.h @@ -0,0 +1,595 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ +#ifndef OPENCV_FLANN_AUTOTUNED_INDEX_H_ +#define OPENCV_FLANN_AUTOTUNED_INDEX_H_ + +//! @cond IGNORED + +#include + +#include "general.h" +#include "nn_index.h" +#include "ground_truth.h" +#include "index_testing.h" +#include "sampling.h" +#include "kdtree_index.h" +#include "kdtree_single_index.h" +#include "kmeans_index.h" +#include "composite_index.h" +#include "linear_index.h" +#include "logger.h" + +namespace cvflann +{ + +template +NNIndex* create_index_by_type(const Matrix& dataset, const IndexParams& params, const Distance& distance); + + +struct AutotunedIndexParams : public IndexParams +{ + AutotunedIndexParams(float target_precision = 0.8, float build_weight = 0.01, float memory_weight = 0, float sample_fraction = 0.1) + { + (*this)["algorithm"] = FLANN_INDEX_AUTOTUNED; + // precision desired (used for autotuning, -1 otherwise) + (*this)["target_precision"] = target_precision; + // build tree time weighting factor + (*this)["build_weight"] = build_weight; + // index memory weighting factor + (*this)["memory_weight"] = memory_weight; + // what fraction of the dataset to use for autotuning + (*this)["sample_fraction"] = sample_fraction; + } +}; + + +template +class AutotunedIndex : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + AutotunedIndex(const Matrix& inputData, const IndexParams& params = AutotunedIndexParams(), Distance d = Distance()) : + dataset_(inputData), distance_(d) + { + target_precision_ = get_param(params, "target_precision",0.8f); + build_weight_ = get_param(params,"build_weight", 0.01f); + memory_weight_ = get_param(params, "memory_weight", 0.0f); + sample_fraction_ = get_param(params,"sample_fraction", 0.1f); + bestIndex_ = NULL; + speedup_ = 0; + } + + AutotunedIndex(const AutotunedIndex&); + AutotunedIndex& operator=(const AutotunedIndex&); + + virtual ~AutotunedIndex() + { + if (bestIndex_ != NULL) { + delete bestIndex_; + bestIndex_ = NULL; + } + } + + /** + * Method responsible with building the index. + */ + virtual void buildIndex() CV_OVERRIDE + { + std::ostringstream stream; + bestParams_ = estimateBuildParams(); + print_params(bestParams_, stream); + Logger::info("----------------------------------------------------\n"); + Logger::info("Autotuned parameters:\n"); + Logger::info("%s", stream.str().c_str()); + Logger::info("----------------------------------------------------\n"); + + bestIndex_ = create_index_by_type(dataset_, bestParams_, distance_); + bestIndex_->buildIndex(); + speedup_ = estimateSearchParams(bestSearchParams_); + stream.str(std::string()); + print_params(bestSearchParams_, stream); + Logger::info("----------------------------------------------------\n"); + Logger::info("Search parameters:\n"); + Logger::info("%s", stream.str().c_str()); + Logger::info("----------------------------------------------------\n"); + } + + /** + * Saves the index to a stream + */ + virtual void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, (int)bestIndex_->getType()); + bestIndex_->saveIndex(stream); + save_value(stream, get_param(bestSearchParams_, "checks")); + } + + /** + * Loads the index from a stream + */ + virtual void loadIndex(FILE* stream) CV_OVERRIDE + { + int index_type; + + load_value(stream, index_type); + IndexParams params; + params["algorithm"] = (flann_algorithm_t)index_type; + bestIndex_ = create_index_by_type(dataset_, params, distance_); + bestIndex_->loadIndex(stream); + int checks; + load_value(stream, checks); + bestSearchParams_["checks"] = checks; + } + + /** + * Method that searches for nearest-neighbors + */ + virtual void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + int checks = get_param(searchParams,"checks",FLANN_CHECKS_AUTOTUNED); + if (checks == FLANN_CHECKS_AUTOTUNED) { + bestIndex_->findNeighbors(result, vec, bestSearchParams_); + } + else { + bestIndex_->findNeighbors(result, vec, searchParams); + } + } + + + IndexParams getParameters() const CV_OVERRIDE + { + return bestIndex_->getParameters(); + } + + SearchParams getSearchParameters() const + { + return bestSearchParams_; + } + + float getSpeedup() const + { + return speedup_; + } + + + /** + * Number of features in this index. + */ + virtual size_t size() const CV_OVERRIDE + { + return bestIndex_->size(); + } + + /** + * The length of each vector in this index. + */ + virtual size_t veclen() const CV_OVERRIDE + { + return bestIndex_->veclen(); + } + + /** + * The amount of memory (in bytes) this index uses. + */ + virtual int usedMemory() const CV_OVERRIDE + { + return bestIndex_->usedMemory(); + } + + /** + * Algorithm name + */ + virtual flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_AUTOTUNED; + } + +private: + + struct CostData + { + float searchTimeCost; + float buildTimeCost; + float memoryCost; + float totalCost; + IndexParams params; + }; + + void evaluate_kmeans(CostData& cost) + { + StartStopTimer t; + int checks; + const int nn = 1; + + Logger::info("KMeansTree using params: max_iterations=%d, branching=%d\n", + get_param(cost.params,"iterations"), + get_param(cost.params,"branching")); + KMeansIndex kmeans(sampledDataset_, cost.params, distance_); + // measure index build time + t.start(); + kmeans.buildIndex(); + t.stop(); + float buildTime = (float)t.value; + + // measure search time + float searchTime = test_index_precision(kmeans, sampledDataset_, testDataset_, gt_matches_, target_precision_, checks, distance_, nn); + + float datasetMemory = float(sampledDataset_.rows * sampledDataset_.cols * sizeof(float)); + cost.memoryCost = (kmeans.usedMemory() + datasetMemory) / datasetMemory; + cost.searchTimeCost = searchTime; + cost.buildTimeCost = buildTime; + Logger::info("KMeansTree buildTime=%g, searchTime=%g, build_weight=%g\n", buildTime, searchTime, build_weight_); + } + + + void evaluate_kdtree(CostData& cost) + { + StartStopTimer t; + int checks; + const int nn = 1; + + Logger::info("KDTree using params: trees=%d\n", get_param(cost.params,"trees")); + KDTreeIndex kdtree(sampledDataset_, cost.params, distance_); + + t.start(); + kdtree.buildIndex(); + t.stop(); + float buildTime = (float)t.value; + + //measure search time + float searchTime = test_index_precision(kdtree, sampledDataset_, testDataset_, gt_matches_, target_precision_, checks, distance_, nn); + + float datasetMemory = float(sampledDataset_.rows * sampledDataset_.cols * sizeof(float)); + cost.memoryCost = (kdtree.usedMemory() + datasetMemory) / datasetMemory; + cost.searchTimeCost = searchTime; + cost.buildTimeCost = buildTime; + Logger::info("KDTree buildTime=%g, searchTime=%g\n", buildTime, searchTime); + } + + + // struct KMeansSimpleDownhillFunctor { + // + // Autotune& autotuner; + // KMeansSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {} + // + // float operator()(int* params) { + // + // float maxFloat = numeric_limits::max(); + // + // if (params[0]<2) return maxFloat; + // if (params[1]<0) return maxFloat; + // + // CostData c; + // c.params["algorithm"] = KMEANS; + // c.params["centers-init"] = CENTERS_RANDOM; + // c.params["branching"] = params[0]; + // c.params["max-iterations"] = params[1]; + // + // autotuner.evaluate_kmeans(c); + // + // return c.timeCost; + // + // } + // }; + // + // struct KDTreeSimpleDownhillFunctor { + // + // Autotune& autotuner; + // KDTreeSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {} + // + // float operator()(int* params) { + // float maxFloat = numeric_limits::max(); + // + // if (params[0]<1) return maxFloat; + // + // CostData c; + // c.params["algorithm"] = KDTREE; + // c.params["trees"] = params[0]; + // + // autotuner.evaluate_kdtree(c); + // + // return c.timeCost; + // + // } + // }; + + + + void optimizeKMeans(std::vector& costs) + { + Logger::info("KMEANS, Step 1: Exploring parameter space\n"); + + // explore kmeans parameters space using combinations of the parameters below + int maxIterations[] = { 1, 5, 10, 15 }; + int branchingFactors[] = { 16, 32, 64, 128, 256 }; + + int kmeansParamSpaceSize = FLANN_ARRAY_LEN(maxIterations) * FLANN_ARRAY_LEN(branchingFactors); + costs.reserve(costs.size() + kmeansParamSpaceSize); + + // evaluate kmeans for all parameter combinations + for (size_t i = 0; i < FLANN_ARRAY_LEN(maxIterations); ++i) { + for (size_t j = 0; j < FLANN_ARRAY_LEN(branchingFactors); ++j) { + CostData cost; + cost.params["algorithm"] = FLANN_INDEX_KMEANS; + cost.params["centers_init"] = FLANN_CENTERS_RANDOM; + cost.params["iterations"] = maxIterations[i]; + cost.params["branching"] = branchingFactors[j]; + + evaluate_kmeans(cost); + costs.push_back(cost); + } + } + + // Logger::info("KMEANS, Step 2: simplex-downhill optimization\n"); + // + // const int n = 2; + // // choose initial simplex points as the best parameters so far + // int kmeansNMPoints[n*(n+1)]; + // float kmeansVals[n+1]; + // for (int i=0;i& costs) + { + Logger::info("KD-TREE, Step 1: Exploring parameter space\n"); + + // explore kd-tree parameters space using the parameters below + int testTrees[] = { 1, 4, 8, 16, 32 }; + + // evaluate kdtree for all parameter combinations + for (size_t i = 0; i < FLANN_ARRAY_LEN(testTrees); ++i) { + CostData cost; + cost.params["algorithm"] = FLANN_INDEX_KDTREE; + cost.params["trees"] = testTrees[i]; + + evaluate_kdtree(cost); + costs.push_back(cost); + } + + // Logger::info("KD-TREE, Step 2: simplex-downhill optimization\n"); + // + // const int n = 1; + // // choose initial simplex points as the best parameters so far + // int kdtreeNMPoints[n*(n+1)]; + // float kdtreeVals[n+1]; + // for (int i=0;i costs; + + int sampleSize = int(sample_fraction_ * dataset_.rows); + int testSampleSize = std::min(sampleSize / 10, 1000); + + Logger::info("Entering autotuning, dataset size: %d, sampleSize: %d, testSampleSize: %d, target precision: %g\n", dataset_.rows, sampleSize, testSampleSize, target_precision_); + + // For a very small dataset, it makes no sense to build any fancy index, just + // use linear search + if (testSampleSize < 10) { + Logger::info("Choosing linear, dataset too small\n"); + return LinearIndexParams(); + } + + // We use a fraction of the original dataset to speedup the autotune algorithm + sampledDataset_ = random_sample(dataset_, sampleSize); + // We use a cross-validation approach, first we sample a testset from the dataset + testDataset_ = random_sample(sampledDataset_, testSampleSize, true); + + // We compute the ground truth using linear search + Logger::info("Computing ground truth... \n"); + gt_matches_ = Matrix(new int[testDataset_.rows], testDataset_.rows, 1); + StartStopTimer t; + t.start(); + compute_ground_truth(sampledDataset_, testDataset_, gt_matches_, 0, distance_); + t.stop(); + + CostData linear_cost; + linear_cost.searchTimeCost = (float)t.value; + linear_cost.buildTimeCost = 0; + linear_cost.memoryCost = 0; + linear_cost.params["algorithm"] = FLANN_INDEX_LINEAR; + + costs.push_back(linear_cost); + + // Start parameter autotune process + Logger::info("Autotuning parameters...\n"); + + optimizeKMeans(costs); + optimizeKDTree(costs); + + float bestTimeCost = costs[0].searchTimeCost; + for (size_t i = 0; i < costs.size(); ++i) { + float timeCost = costs[i].buildTimeCost * build_weight_ + costs[i].searchTimeCost; + if (timeCost < bestTimeCost) { + bestTimeCost = timeCost; + } + } + + float bestCost = costs[0].searchTimeCost / bestTimeCost; + IndexParams bestParams = costs[0].params; + if (bestTimeCost > 0) { + for (size_t i = 0; i < costs.size(); ++i) { + float crtCost = (costs[i].buildTimeCost * build_weight_ + costs[i].searchTimeCost) / bestTimeCost + + memory_weight_ * costs[i].memoryCost; + if (crtCost < bestCost) { + bestCost = crtCost; + bestParams = costs[i].params; + } + } + } + + delete[] gt_matches_.data; + delete[] testDataset_.data; + delete[] sampledDataset_.data; + + return bestParams; + } + + + + /** + * Estimates the search time parameters needed to get the desired precision. + * Precondition: the index is built + * Postcondition: the searchParams will have the optimum params set, also the speedup obtained over linear search. + */ + float estimateSearchParams(SearchParams& searchParams) + { + const int nn = 1; + const size_t SAMPLE_COUNT = 1000; + + assert(bestIndex_ != NULL); // must have a valid index + + float speedup = 0; + + int samples = (int)std::min(dataset_.rows / 10, SAMPLE_COUNT); + if (samples > 0) { + Matrix testDataset = random_sample(dataset_, samples); + + Logger::info("Computing ground truth\n"); + + // we need to compute the ground truth first + Matrix gt_matches(new int[testDataset.rows], testDataset.rows, 1); + StartStopTimer t; + t.start(); + compute_ground_truth(dataset_, testDataset, gt_matches, 1, distance_); + t.stop(); + float linear = (float)t.value; + + int checks; + Logger::info("Estimating number of checks\n"); + + float searchTime; + float cb_index; + if (bestIndex_->getType() == FLANN_INDEX_KMEANS) { + Logger::info("KMeans algorithm, estimating cluster border factor\n"); + KMeansIndex* kmeans = (KMeansIndex*)bestIndex_; + float bestSearchTime = -1; + float best_cb_index = -1; + int best_checks = -1; + for (cb_index = 0; cb_index < 1.1f; cb_index += 0.2f) { + kmeans->set_cb_index(cb_index); + searchTime = test_index_precision(*kmeans, dataset_, testDataset, gt_matches, target_precision_, checks, distance_, nn, 1); + if ((searchTime < bestSearchTime) || (bestSearchTime == -1)) { + bestSearchTime = searchTime; + best_cb_index = cb_index; + best_checks = checks; + } + } + searchTime = bestSearchTime; + cb_index = best_cb_index; + checks = best_checks; + + kmeans->set_cb_index(best_cb_index); + Logger::info("Optimum cb_index: %g\n", cb_index); + bestParams_["cb_index"] = cb_index; + } + else { + searchTime = test_index_precision(*bestIndex_, dataset_, testDataset, gt_matches, target_precision_, checks, distance_, nn, 1); + } + + Logger::info("Required number of checks: %d \n", checks); + searchParams["checks"] = checks; + + speedup = linear / searchTime; + + delete[] gt_matches.data; + delete[] testDataset.data; + } + + return speedup; + } + +private: + NNIndex* bestIndex_; + + IndexParams bestParams_; + SearchParams bestSearchParams_; + + Matrix sampledDataset_; + Matrix testDataset_; + Matrix gt_matches_; + + float speedup_; + + /** + * The dataset used by this index + */ + const Matrix dataset_; + + /** + * Index parameters + */ + float target_precision_; + float build_weight_; + float memory_weight_; + float sample_fraction_; + + Distance distance_; + + +}; +} + +//! @endcond + +#endif /* OPENCV_FLANN_AUTOTUNED_INDEX_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/composite_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/composite_index.h new file mode 100644 index 0000000000000000000000000000000000000000..bcf0827c9f728eb069ec8184331df37fc39f02fe --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/composite_index.h @@ -0,0 +1,198 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_COMPOSITE_INDEX_H_ +#define OPENCV_FLANN_COMPOSITE_INDEX_H_ + +//! @cond IGNORED + +#include "general.h" +#include "nn_index.h" +#include "kdtree_index.h" +#include "kmeans_index.h" + +namespace cvflann +{ + +/** + * Index parameters for the CompositeIndex. + */ +struct CompositeIndexParams : public IndexParams +{ + CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11, + flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2 ) + { + (*this)["algorithm"] = FLANN_INDEX_KMEANS; + // number of randomized trees to use (for kdtree) + (*this)["trees"] = trees; + // branching factor + (*this)["branching"] = branching; + // max iterations to perform in one kmeans clustering (kmeans tree) + (*this)["iterations"] = iterations; + // algorithm used for picking the initial cluster centers for kmeans tree + (*this)["centers_init"] = centers_init; + // cluster boundary index. Used when searching the kmeans tree + (*this)["cb_index"] = cb_index; + } +}; + + +/** + * This index builds a kd-tree index and a k-means index and performs nearest + * neighbour search both indexes. This gives a slight boost in search performance + * as some of the neighbours that are missed by one index are found by the other. + */ +template +class CompositeIndex : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + /** + * Index constructor + * @param inputData dataset containing the points to index + * @param params Index parameters + * @param d Distance functor + * @return + */ + CompositeIndex(const Matrix& inputData, const IndexParams& params = CompositeIndexParams(), + Distance d = Distance()) : index_params_(params) + { + kdtree_index_ = new KDTreeIndex(inputData, params, d); + kmeans_index_ = new KMeansIndex(inputData, params, d); + + } + + CompositeIndex(const CompositeIndex&); + CompositeIndex& operator=(const CompositeIndex&); + + virtual ~CompositeIndex() + { + delete kdtree_index_; + delete kmeans_index_; + } + + /** + * @return The index type + */ + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_COMPOSITE; + } + + /** + * @return Size of the index + */ + size_t size() const CV_OVERRIDE + { + return kdtree_index_->size(); + } + + /** + * \returns The dimensionality of the features in this index. + */ + size_t veclen() const CV_OVERRIDE + { + return kdtree_index_->veclen(); + } + + /** + * \returns The amount of memory (in bytes) used by the index. + */ + int usedMemory() const CV_OVERRIDE + { + return kmeans_index_->usedMemory() + kdtree_index_->usedMemory(); + } + + /** + * \brief Builds the index + */ + void buildIndex() CV_OVERRIDE + { + Logger::info("Building kmeans tree...\n"); + kmeans_index_->buildIndex(); + Logger::info("Building kdtree tree...\n"); + kdtree_index_->buildIndex(); + } + + /** + * \brief Saves the index to a stream + * \param stream The stream to save the index to + */ + void saveIndex(FILE* stream) CV_OVERRIDE + { + kmeans_index_->saveIndex(stream); + kdtree_index_->saveIndex(stream); + } + + /** + * \brief Loads the index from a stream + * \param stream The stream from which the index is loaded + */ + void loadIndex(FILE* stream) CV_OVERRIDE + { + kmeans_index_->loadIndex(stream); + kdtree_index_->loadIndex(stream); + } + + /** + * \returns The index parameters + */ + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + + /** + * \brief Method that searches for nearest-neighbours + */ + void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + kmeans_index_->findNeighbors(result, vec, searchParams); + kdtree_index_->findNeighbors(result, vec, searchParams); + } + +private: + /** The k-means index */ + KMeansIndex* kmeans_index_; + + /** The kd-tree index */ + KDTreeIndex* kdtree_index_; + + /** The index parameters */ + const IndexParams index_params_; +}; + +} + +//! @endcond + +#endif //OPENCV_FLANN_COMPOSITE_INDEX_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/config.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/config.h new file mode 100644 index 0000000000000000000000000000000000000000..c9342c00c3d723a19144bbfb01be4cac9e039a58 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/config.h @@ -0,0 +1,42 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_CONFIG_H_ +#define OPENCV_FLANN_CONFIG_H_ + +//! @cond IGNORED + +#ifdef FLANN_VERSION_ +#undef FLANN_VERSION_ +#endif +#define FLANN_VERSION_ "1.6.10" + +//! @endcond + +#endif /* OPENCV_FLANN_CONFIG_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/defines.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/defines.h new file mode 100644 index 0000000000000000000000000000000000000000..884c6004d4ac1211f3739b25d27e8f3015799b17 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/defines.h @@ -0,0 +1,168 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_DEFINES_H_ +#define OPENCV_FLANN_DEFINES_H_ + +//! @cond IGNORED + +#include "config.h" + +#ifdef FLANN_EXPORT +#undef FLANN_EXPORT +#endif +#ifdef _WIN32 +/* win32 dll export/import directives */ + #ifdef FLANN_EXPORTS + #define FLANN_EXPORT __declspec(dllexport) + #elif defined(FLANN_STATIC) + #define FLANN_EXPORT + #else + #define FLANN_EXPORT __declspec(dllimport) + #endif +#else +/* unix needs nothing */ + #define FLANN_EXPORT +#endif + + +#undef FLANN_PLATFORM_32_BIT +#undef FLANN_PLATFORM_64_BIT +#if defined __amd64__ || defined __x86_64__ || defined _WIN64 || defined _M_X64 +#define FLANN_PLATFORM_64_BIT +#else +#define FLANN_PLATFORM_32_BIT +#endif + + +#undef FLANN_ARRAY_LEN +#define FLANN_ARRAY_LEN(a) (sizeof(a)/sizeof(a[0])) + +namespace cvflann { + +/* Nearest neighbour index algorithms */ +enum flann_algorithm_t +{ + FLANN_INDEX_LINEAR = 0, + FLANN_INDEX_KDTREE = 1, + FLANN_INDEX_KMEANS = 2, + FLANN_INDEX_COMPOSITE = 3, + FLANN_INDEX_KDTREE_SINGLE = 4, + FLANN_INDEX_HIERARCHICAL = 5, + FLANN_INDEX_LSH = 6, + FLANN_INDEX_SAVED = 254, + FLANN_INDEX_AUTOTUNED = 255, + + // deprecated constants, should use the FLANN_INDEX_* ones instead + LINEAR = 0, + KDTREE = 1, + KMEANS = 2, + COMPOSITE = 3, + KDTREE_SINGLE = 4, + SAVED = 254, + AUTOTUNED = 255 +}; + + + +enum flann_centers_init_t +{ + FLANN_CENTERS_RANDOM = 0, + FLANN_CENTERS_GONZALES = 1, + FLANN_CENTERS_KMEANSPP = 2, + FLANN_CENTERS_GROUPWISE = 3, + + // deprecated constants, should use the FLANN_CENTERS_* ones instead + CENTERS_RANDOM = 0, + CENTERS_GONZALES = 1, + CENTERS_KMEANSPP = 2 +}; + +enum flann_log_level_t +{ + FLANN_LOG_NONE = 0, + FLANN_LOG_FATAL = 1, + FLANN_LOG_ERROR = 2, + FLANN_LOG_WARN = 3, + FLANN_LOG_INFO = 4 +}; + +enum flann_distance_t +{ + FLANN_DIST_EUCLIDEAN = 1, + FLANN_DIST_L2 = 1, + FLANN_DIST_MANHATTAN = 2, + FLANN_DIST_L1 = 2, + FLANN_DIST_MINKOWSKI = 3, + FLANN_DIST_MAX = 4, + FLANN_DIST_HIST_INTERSECT = 5, + FLANN_DIST_HELLINGER = 6, + FLANN_DIST_CHI_SQUARE = 7, + FLANN_DIST_CS = 7, + FLANN_DIST_KULLBACK_LEIBLER = 8, + FLANN_DIST_KL = 8, + FLANN_DIST_HAMMING = 9, + + // deprecated constants, should use the FLANN_DIST_* ones instead + EUCLIDEAN = 1, + MANHATTAN = 2, + MINKOWSKI = 3, + MAX_DIST = 4, + HIST_INTERSECT = 5, + HELLINGER = 6, + CS = 7, + KL = 8, + KULLBACK_LEIBLER = 8 +}; + +enum flann_datatype_t +{ + FLANN_INT8 = 0, + FLANN_INT16 = 1, + FLANN_INT32 = 2, + FLANN_INT64 = 3, + FLANN_UINT8 = 4, + FLANN_UINT16 = 5, + FLANN_UINT32 = 6, + FLANN_UINT64 = 7, + FLANN_FLOAT32 = 8, + FLANN_FLOAT64 = 9 +}; + +enum +{ + FLANN_CHECKS_UNLIMITED = -1, + FLANN_CHECKS_AUTOTUNED = -2 +}; + +} + +//! @endcond + +#endif /* OPENCV_FLANN_DEFINES_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dist.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dist.h new file mode 100644 index 0000000000000000000000000000000000000000..07a1cc29c6e807c177093e0c020f923cea644f87 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dist.h @@ -0,0 +1,908 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_DIST_H_ +#define OPENCV_FLANN_DIST_H_ + +//! @cond IGNORED + +#include +#include +#include +#ifdef _MSC_VER +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#else +#include +#endif + +#include "defines.h" + +#if defined _WIN32 && (defined(_M_ARM) || defined(_M_ARM64)) +# include +#endif + +#if defined(__ARM_NEON__) && !defined(__CUDACC__) +# include "arm_neon.h" +#endif + +namespace cvflann +{ + +template +inline T abs(T x) { return (x<0) ? -x : x; } + +template<> +inline int abs(int x) { return ::abs(x); } + +template<> +inline float abs(float x) { return fabsf(x); } + +template<> +inline double abs(double x) { return fabs(x); } + +template +struct Accumulator { typedef T Type; }; +template<> +struct Accumulator { typedef float Type; }; +template<> +struct Accumulator { typedef float Type; }; +template<> +struct Accumulator { typedef float Type; }; +template<> +struct Accumulator { typedef float Type; }; +template<> +struct Accumulator { typedef float Type; }; +template<> +struct Accumulator { typedef float Type; }; + +#undef True +#undef False + +class True +{ +}; + +class False +{ +}; + + +/** + * Squared Euclidean distance functor. + * + * This is the simpler, unrolled version. This is preferable for + * very low dimensionality data (eg 3D points) + */ +template +struct L2_Simple +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { + ResultType result = ResultType(); + ResultType diff; + for(size_t i = 0; i < size; ++i ) { + diff = (ResultType)(*a++ - *b++); + result += diff*diff; + } + return result; + } + + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return (a-b)*(a-b); + } +}; + + + +/** + * Squared Euclidean distance functor, optimized version + */ +template +struct L2 +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + /** + * Compute the squared Euclidean distance between two vectors. + * + * This is highly optimised, with loop unrolling, as it is one + * of the most expensive inner loops. + * + * The computation of squared root at the end is omitted for + * efficiency. + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = (ResultType)(a[0] - b[0]); + diff1 = (ResultType)(a[1] - b[1]); + diff2 = (ResultType)(a[2] - b[2]); + diff3 = (ResultType)(a[3] - b[3]); + result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3; + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = (ResultType)(*a++ - *b++); + result += diff0 * diff0; + } + return result; + } + + /** + * Partial euclidean distance, using just one dimension. This is used by the + * kd-tree when computing partial distances while traversing the tree. + * + * Squared root is omitted for efficiency. + */ + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return (a-b)*(a-b); + } +}; + + +/* + * Manhattan distance functor, optimized version + */ +template +struct L1 +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + /** + * Compute the Manhattan (L_1) distance between two vectors. + * + * This is highly optimised, with loop unrolling, as it is one + * of the most expensive inner loops. + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = (ResultType)abs(a[0] - b[0]); + diff1 = (ResultType)abs(a[1] - b[1]); + diff2 = (ResultType)abs(a[2] - b[2]); + diff3 = (ResultType)abs(a[3] - b[3]); + result += diff0 + diff1 + diff2 + diff3; + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = (ResultType)abs(*a++ - *b++); + result += diff0; + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return abs(a-b); + } +}; + + + +template +struct MinkowskiDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + int order; + + MinkowskiDistance(int order_) : order(order_) {} + + /** + * Compute the Minkowsky (L_p) distance between two vectors. + * + * This is highly optimised, with loop unrolling, as it is one + * of the most expensive inner loops. + * + * The computation of squared root at the end is omitted for + * efficiency. + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = (ResultType)abs(a[0] - b[0]); + diff1 = (ResultType)abs(a[1] - b[1]); + diff2 = (ResultType)abs(a[2] - b[2]); + diff3 = (ResultType)abs(a[3] - b[3]); + result += pow(diff0,order) + pow(diff1,order) + pow(diff2,order) + pow(diff3,order); + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = (ResultType)abs(*a++ - *b++); + result += pow(diff0,order); + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return pow(static_cast(abs(a-b)),order); + } +}; + + + +template +struct MaxDistance +{ + typedef False is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + /** + * Compute the max distance (L_infinity) between two vectors. + * + * This distance is not a valid kdtree distance, it's not dimensionwise additive. + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = abs(a[0] - b[0]); + diff1 = abs(a[1] - b[1]); + diff2 = abs(a[2] - b[2]); + diff3 = abs(a[3] - b[3]); + if (diff0>result) {result = diff0; } + if (diff1>result) {result = diff1; } + if (diff2>result) {result = diff2; } + if (diff3>result) {result = diff3; } + a += 4; + b += 4; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + diff0 = abs(*a++ - *b++); + result = (diff0>result) ? diff0 : result; + } + return result; + } + + /* This distance functor is not dimension-wise additive, which + * makes it an invalid kd-tree distance, not implementing the accum_dist method */ + +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** + * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor + * bit count of A exclusive XOR'ed with B + */ +struct HammingLUT +{ + typedef False is_kdtree_distance; + typedef False is_vector_space_distance; + + typedef unsigned char ElementType; + typedef int ResultType; + + /** this will count the bits in a ^ b + */ + ResultType operator()(const unsigned char* a, const unsigned char* b, size_t size) const + { + static const uchar popCountTable[] = + { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 + }; + ResultType result = 0; + for (size_t i = 0; i < size; i++) { + result += popCountTable[a[i] ^ b[i]]; + } + return result; + } +}; + +/** + * Hamming distance functor (pop count between two binary vectors, i.e. xor them and count the number of bits set) + * That code was taken from brief.cpp in OpenCV + */ +template +struct Hamming +{ + typedef False is_kdtree_distance; + typedef False is_vector_space_distance; + + + typedef T ElementType; + typedef int ResultType; + + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { + ResultType result = 0; +#if defined(__ARM_NEON__) && !defined(__CUDACC__) + { + uint32x4_t bits = vmovq_n_u32(0); + for (size_t i = 0; i < size; i += 16) { + uint8x16_t A_vec = vld1q_u8 (a + i); + uint8x16_t B_vec = vld1q_u8 (b + i); + uint8x16_t AxorB = veorq_u8 (A_vec, B_vec); + uint8x16_t bitsSet = vcntq_u8 (AxorB); + uint16x8_t bitSet8 = vpaddlq_u8 (bitsSet); + uint32x4_t bitSet4 = vpaddlq_u16 (bitSet8); + bits = vaddq_u32(bits, bitSet4); + } + uint64x2_t bitSet2 = vpaddlq_u32 (bits); + result = vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),0); + result += vgetq_lane_s32 (vreinterpretq_s32_u64(bitSet2),2); + } +#elif defined(__GNUC__) + { + //for portability just use unsigned long -- and use the __builtin_popcountll (see docs for __builtin_popcountll) + typedef unsigned long long pop_t; + const size_t modulo = size % sizeof(pop_t); + const pop_t* a2 = reinterpret_cast (a); + const pop_t* b2 = reinterpret_cast (b); + const pop_t* a2_end = a2 + (size / sizeof(pop_t)); + + for (; a2 != a2_end; ++a2, ++b2) result += __builtin_popcountll((*a2) ^ (*b2)); + + if (modulo) { + //in the case where size is not dividable by sizeof(size_t) + //need to mask off the bits at the end + pop_t a_final = 0, b_final = 0; + memcpy(&a_final, a2, modulo); + memcpy(&b_final, b2, modulo); + result += __builtin_popcountll(a_final ^ b_final); + } + } +#else // NO NEON and NOT GNUC + HammingLUT lut; + result = lut(reinterpret_cast (a), + reinterpret_cast (b), size); +#endif + return result; + } +}; + +template +struct Hamming2 +{ + typedef False is_kdtree_distance; + typedef False is_vector_space_distance; + + typedef T ElementType; + typedef int ResultType; + + /** This is popcount_3() from: + * http://en.wikipedia.org/wiki/Hamming_weight */ + unsigned int popcnt32(uint32_t n) const + { + n -= ((n >> 1) & 0x55555555); + n = (n & 0x33333333) + ((n >> 2) & 0x33333333); + return (((n + (n >> 4))& 0xF0F0F0F)* 0x1010101) >> 24; + } + +#ifdef FLANN_PLATFORM_64_BIT + unsigned int popcnt64(uint64_t n) const + { + n -= ((n >> 1) & 0x5555555555555555); + n = (n & 0x3333333333333333) + ((n >> 2) & 0x3333333333333333); + return (((n + (n >> 4))& 0x0f0f0f0f0f0f0f0f)* 0x0101010101010101) >> 56; + } +#endif + + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { +#ifdef FLANN_PLATFORM_64_BIT + const uint64_t* pa = reinterpret_cast(a); + const uint64_t* pb = reinterpret_cast(b); + ResultType result = 0; + size /= (sizeof(uint64_t)/sizeof(unsigned char)); + for(size_t i = 0; i < size; ++i ) { + result += popcnt64(*pa ^ *pb); + ++pa; + ++pb; + } +#else + const uint32_t* pa = reinterpret_cast(a); + const uint32_t* pb = reinterpret_cast(b); + ResultType result = 0; + size /= (sizeof(uint32_t)/sizeof(unsigned char)); + for(size_t i = 0; i < size; ++i ) { + result += popcnt32(*pa ^ *pb); + ++pa; + ++pb; + } +#endif + return result; + } +}; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +template +struct HistIntersectionDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + /** + * Compute the histogram intersection distance + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType min0, min1, min2, min3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + min0 = (ResultType)(a[0] < b[0] ? a[0] : b[0]); + min1 = (ResultType)(a[1] < b[1] ? a[1] : b[1]); + min2 = (ResultType)(a[2] < b[2] ? a[2] : b[2]); + min3 = (ResultType)(a[3] < b[3] ? a[3] : b[3]); + result += min0 + min1 + min2 + min3; + a += 4; + b += 4; + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + /* Process last 0-3 pixels. Not needed for standard vector lengths. */ + while (a < last) { + min0 = (ResultType)(*a < *b ? *a : *b); + result += min0; + ++a; + ++b; + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + return a +struct HellingerDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + /** + * Compute the Hellinger distance + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const + { + ResultType result = ResultType(); + ResultType diff0, diff1, diff2, diff3; + Iterator1 last = a + size; + Iterator1 lastgroup = last - 3; + + /* Process 4 items with each loop for efficiency. */ + while (a < lastgroup) { + diff0 = sqrt(static_cast(a[0])) - sqrt(static_cast(b[0])); + diff1 = sqrt(static_cast(a[1])) - sqrt(static_cast(b[1])); + diff2 = sqrt(static_cast(a[2])) - sqrt(static_cast(b[2])); + diff3 = sqrt(static_cast(a[3])) - sqrt(static_cast(b[3])); + result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3; + a += 4; + b += 4; + } + while (a < last) { + diff0 = sqrt(static_cast(*a++)) - sqrt(static_cast(*b++)); + result += diff0 * diff0; + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + ResultType diff = sqrt(static_cast(a)) - sqrt(static_cast(b)); + return diff * diff; + } +}; + + +template +struct ChiSquareDistance +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + /** + * Compute the chi-square distance + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + ResultType sum, diff; + Iterator1 last = a + size; + + while (a < last) { + sum = (ResultType)(*a + *b); + if (sum>0) { + diff = (ResultType)(*a - *b); + result += diff*diff/sum; + } + ++a; + ++b; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + ResultType result = ResultType(); + ResultType sum, diff; + + sum = (ResultType)(a+b); + if (sum>0) { + diff = (ResultType)(a-b); + result = diff*diff/sum; + } + return result; + } +}; + + +template +struct KL_Divergence +{ + typedef True is_kdtree_distance; + typedef True is_vector_space_distance; + + typedef T ElementType; + typedef typename Accumulator::Type ResultType; + + /** + * Compute the Kullback-Leibler divergence + */ + template + ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const + { + ResultType result = ResultType(); + Iterator1 last = a + size; + + while (a < last) { + if (* b != 0) { + ResultType ratio = (ResultType)(*a / *b); + if (ratio>0) { + result += *a * log(ratio); + } + } + ++a; + ++b; + + if ((worst_dist>0)&&(result>worst_dist)) { + return result; + } + } + return result; + } + + /** + * Partial distance, used by the kd-tree. + */ + template + inline ResultType accum_dist(const U& a, const V& b, int) const + { + ResultType result = ResultType(); + if( *b != 0 ) { + ResultType ratio = (ResultType)(a / b); + if (ratio>0) { + result = a * log(ratio); + } + } + return result; + } +}; + + + +/* + * This is a "zero iterator". It basically behaves like a zero filled + * array to all algorithms that use arrays as iterators (STL style). + * It's useful when there's a need to compute the distance between feature + * and origin it and allows for better compiler optimisation than using a + * zero-filled array. + */ +template +struct ZeroIterator +{ + + T operator*() + { + return 0; + } + + T operator[](int) + { + return 0; + } + + const ZeroIterator& operator ++() + { + return *this; + } + + ZeroIterator operator ++(int) + { + return *this; + } + + ZeroIterator& operator+=(int) + { + return *this; + } + +}; + + +/* + * Depending on processed distances, some of them are already squared (e.g. L2) + * and some are not (e.g.Hamming). In KMeans++ for instance we want to be sure + * we are working on ^2 distances, thus following templates to ensure that. + */ +template +struct squareDistance +{ + typedef typename Distance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist*dist; } +}; + + +template +struct squareDistance, ElementType> +{ + typedef typename L2_Simple::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template +struct squareDistance, ElementType> +{ + typedef typename L2::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template +struct squareDistance, ElementType> +{ + typedef typename MinkowskiDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template +struct squareDistance, ElementType> +{ + typedef typename HellingerDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + +template +struct squareDistance, ElementType> +{ + typedef typename ChiSquareDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template +typename Distance::ResultType ensureSquareDistance( typename Distance::ResultType dist ) +{ + typedef typename Distance::ElementType ElementType; + + squareDistance dummy; + return dummy( dist ); +} + + +/* + * ...and a template to ensure the user that he will process the normal distance, + * and not squared distance, without losing processing time calling sqrt(ensureSquareDistance) + * that will result in doing actually sqrt(dist*dist) for L1 distance for instance. + */ +template +struct simpleDistance +{ + typedef typename Distance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return dist; } +}; + + +template +struct simpleDistance, ElementType> +{ + typedef typename L2_Simple::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + +template +struct simpleDistance, ElementType> +{ + typedef typename L2::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + + +template +struct simpleDistance, ElementType> +{ + typedef typename MinkowskiDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + +template +struct simpleDistance, ElementType> +{ + typedef typename HellingerDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + +template +struct simpleDistance, ElementType> +{ + typedef typename ChiSquareDistance::ResultType ResultType; + ResultType operator()( ResultType dist ) { return sqrt(dist); } +}; + + +template +typename Distance::ResultType ensureSimpleDistance( typename Distance::ResultType dist ) +{ + typedef typename Distance::ElementType ElementType; + + simpleDistance dummy; + return dummy( dist ); +} + +} + +//! @endcond + +#endif //OPENCV_FLANN_DIST_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dummy.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dummy.h new file mode 100644 index 0000000000000000000000000000000000000000..c176f2e4ef0a664b0d341486aeadd11b93874164 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dummy.h @@ -0,0 +1,16 @@ + +#ifndef OPENCV_FLANN_DUMMY_H_ +#define OPENCV_FLANN_DUMMY_H_ + +//! @cond IGNORED + +namespace cvflann +{ + +CV_DEPRECATED inline void dummyfunc() {} + +} + +//! @endcond + +#endif /* OPENCV_FLANN_DUMMY_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dynamic_bitset.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dynamic_bitset.h new file mode 100644 index 0000000000000000000000000000000000000000..a00ce1bb7e0eceac667e206031b3e57bc000710d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/dynamic_bitset.h @@ -0,0 +1,163 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +/*********************************************************************** + * Author: Vincent Rabaud + *************************************************************************/ + +#ifndef OPENCV_FLANN_DYNAMIC_BITSET_H_ +#define OPENCV_FLANN_DYNAMIC_BITSET_H_ + +//! @cond IGNORED + +#ifndef FLANN_USE_BOOST +# define FLANN_USE_BOOST 0 +#endif +//#define FLANN_USE_BOOST 1 +#if FLANN_USE_BOOST +#include +typedef boost::dynamic_bitset<> DynamicBitset; +#else + +#include + +#include "dist.h" + +namespace cvflann { + +/** Class re-implementing the boost version of it + * This helps not depending on boost, it also does not do the bound checks + * and has a way to reset a block for speed + */ +class DynamicBitset +{ +public: + /** default constructor + */ + DynamicBitset() : size_(0) + { + } + + /** only constructor we use in our code + * @param sz the size of the bitset (in bits) + */ + DynamicBitset(size_t sz) + { + resize(sz); + reset(); + } + + /** Sets all the bits to 0 + */ + void clear() + { + std::fill(bitset_.begin(), bitset_.end(), 0); + } + + /** @brief checks if the bitset is empty + * @return true if the bitset is empty + */ + bool empty() const + { + return bitset_.empty(); + } + + /** set all the bits to 0 + */ + void reset() + { + std::fill(bitset_.begin(), bitset_.end(), 0); + } + + /** @brief set one bit to 0 + * @param index + */ + void reset(size_t index) + { + bitset_[index / cell_bit_size_] &= ~(size_t(1) << (index % cell_bit_size_)); + } + + /** @brief sets a specific bit to 0, and more bits too + * This function is useful when resetting a given set of bits so that the + * whole bitset ends up being 0: if that's the case, we don't care about setting + * other bits to 0 + * @param index + */ + void reset_block(size_t index) + { + bitset_[index / cell_bit_size_] = 0; + } + + /** resize the bitset so that it contains at least sz bits + * @param sz + */ + void resize(size_t sz) + { + size_ = sz; + bitset_.resize(sz / cell_bit_size_ + 1); + } + + /** set a bit to true + * @param index the index of the bit to set to 1 + */ + void set(size_t index) + { + bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_); + } + + /** gives the number of contained bits + */ + size_t size() const + { + return size_; + } + + /** check if a bit is set + * @param index the index of the bit to check + * @return true if the bit is set + */ + bool test(size_t index) const + { + return (bitset_[index / cell_bit_size_] & (size_t(1) << (index % cell_bit_size_))) != 0; + } + +private: + std::vector bitset_; + size_t size_; + static const unsigned int cell_bit_size_ = CHAR_BIT * sizeof(size_t); +}; + +} // namespace cvflann + +#endif + +//! @endcond + +#endif // OPENCV_FLANN_DYNAMIC_BITSET_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/flann.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/flann.hpp new file mode 100644 index 0000000000000000000000000000000000000000..227683f97973dc05911b00936acf91b9bec513a7 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/flann.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/flann.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/flann_base.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/flann_base.hpp new file mode 100644 index 0000000000000000000000000000000000000000..83606d232f5071644842c81b194a7b0e0730c147 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/flann_base.hpp @@ -0,0 +1,300 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_BASE_HPP_ +#define OPENCV_FLANN_BASE_HPP_ + +//! @cond IGNORED + +#include +#include +#include + +#include "general.h" +#include "matrix.h" +#include "params.h" +#include "saving.h" + +#include "all_indices.h" + +namespace cvflann +{ + +/** + * Sets the log level used for all flann functions + * @param level Verbosity level + */ +inline void log_verbosity(int level) +{ + if (level >= 0) { + Logger::setLevel(level); + } +} + +/** + * (Deprecated) Index parameters for creating a saved index. + */ +struct SavedIndexParams : public IndexParams +{ + SavedIndexParams(cv::String filename) + { + (* this)["algorithm"] = FLANN_INDEX_SAVED; + (*this)["filename"] = filename; + } +}; + + +template +NNIndex* load_saved_index(const Matrix& dataset, const cv::String& filename, Distance distance) +{ + typedef typename Distance::ElementType ElementType; + + FILE* fin = fopen(filename.c_str(), "rb"); + if (fin == NULL) { + return NULL; + } + IndexHeader header = load_header(fin); + if (header.data_type != Datatype::type()) { + fclose(fin); + throw FLANNException("Datatype of saved index is different than of the one to be created."); + } + if ((size_t(header.rows) != dataset.rows)||(size_t(header.cols) != dataset.cols)) { + fclose(fin); + throw FLANNException("The index saved belongs to a different dataset"); + } + + IndexParams params; + params["algorithm"] = header.index_type; + NNIndex* nnIndex = create_index_by_type(dataset, params, distance); + nnIndex->loadIndex(fin); + fclose(fin); + + return nnIndex; +} + + +template +class Index : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + Index(const Matrix& features, const IndexParams& params, Distance distance = Distance() ) + : index_params_(params) + { + flann_algorithm_t index_type = get_param(params,"algorithm"); + loaded_ = false; + + if (index_type == FLANN_INDEX_SAVED) { + nnIndex_ = load_saved_index(features, get_param(params,"filename"), distance); + loaded_ = true; + } + else { + nnIndex_ = create_index_by_type(features, params, distance); + } + } + + ~Index() + { + delete nnIndex_; + } + + /** + * Builds the index. + */ + void buildIndex() CV_OVERRIDE + { + if (!loaded_) { + nnIndex_->buildIndex(); + } + } + + void save(cv::String filename) + { + FILE* fout = fopen(filename.c_str(), "wb"); + if (fout == NULL) { + throw FLANNException("Cannot open file"); + } + save_header(fout, *nnIndex_); + saveIndex(fout); + fclose(fout); + } + + /** + * \brief Saves the index to a stream + * \param stream The stream to save the index to + */ + virtual void saveIndex(FILE* stream) CV_OVERRIDE + { + nnIndex_->saveIndex(stream); + } + + /** + * \brief Loads the index from a stream + * \param stream The stream from which the index is loaded + */ + virtual void loadIndex(FILE* stream) CV_OVERRIDE + { + nnIndex_->loadIndex(stream); + } + + /** + * \returns number of features in this index. + */ + size_t veclen() const CV_OVERRIDE + { + return nnIndex_->veclen(); + } + + /** + * \returns The dimensionality of the features in this index. + */ + size_t size() const CV_OVERRIDE + { + return nnIndex_->size(); + } + + /** + * \returns The index type (kdtree, kmeans,...) + */ + flann_algorithm_t getType() const CV_OVERRIDE + { + return nnIndex_->getType(); + } + + /** + * \returns The amount of memory (in bytes) used by the index. + */ + virtual int usedMemory() const CV_OVERRIDE + { + return nnIndex_->usedMemory(); + } + + + /** + * \returns The index parameters + */ + IndexParams getParameters() const CV_OVERRIDE + { + return nnIndex_->getParameters(); + } + + /** + * \brief Perform k-nearest neighbor search + * \param[in] queries The query points for which to find the nearest neighbors + * \param[out] indices The indices of the nearest neighbors found + * \param[out] dists Distances to the nearest neighbors found + * \param[in] knn Number of nearest neighbors to return + * \param[in] params Search parameters + */ + void knnSearch(const Matrix& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) CV_OVERRIDE + { + nnIndex_->knnSearch(queries, indices, dists, knn, params); + } + + /** + * \brief Perform radius search + * \param[in] query The query point + * \param[out] indices The indinces of the neighbors found within the given radius + * \param[out] dists The distances to the nearest neighbors found + * \param[in] radius The radius used for search + * \param[in] params Search parameters + * \returns Number of neighbors found + */ + int radiusSearch(const Matrix& query, Matrix& indices, Matrix& dists, float radius, const SearchParams& params) CV_OVERRIDE + { + return nnIndex_->radiusSearch(query, indices, dists, radius, params); + } + + /** + * \brief Method that searches for nearest-neighbours + */ + void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + nnIndex_->findNeighbors(result, vec, searchParams); + } + + /** + * \brief Returns actual index + */ + CV_DEPRECATED NNIndex* getIndex() + { + return nnIndex_; + } + + /** + * \brief Returns index parameters. + * \deprecated use getParameters() instead. + */ + CV_DEPRECATED const IndexParams* getIndexParameters() + { + return &index_params_; + } + +private: + /** Pointer to actual index class */ + NNIndex* nnIndex_; + /** Indices if the index was loaded from a file */ + bool loaded_; + /** Parameters passed to the index */ + IndexParams index_params_; + + Index(const Index &); // copy disabled + Index& operator=(const Index &); // assign disabled +}; + +/** + * Performs a hierarchical clustering of the points passed as argument and then takes a cut in the + * the clustering tree to return a flat clustering. + * @param[in] points Points to be clustered + * @param centers The computed cluster centres. Matrix should be preallocated and centers.rows is the + * number of clusters requested. + * @param params Clustering parameters (The same as for cvflann::KMeansIndex) + * @param d Distance to be used for clustering (eg: cvflann::L2) + * @return number of clusters computed (can be different than clusters.rows and is the highest number + * of the form (branching-1)*K+1 smaller than clusters.rows). + */ +template +int hierarchicalClustering(const Matrix& points, Matrix& centers, + const KMeansIndexParams& params, Distance d = Distance()) +{ + KMeansIndex kmeans(points, params, d); + kmeans.buildIndex(); + + int clusterNum = kmeans.getClusterCenters(centers); + return clusterNum; +} + +} + +//! @endcond + +#endif /* OPENCV_FLANN_BASE_HPP_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/general.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/general.h new file mode 100644 index 0000000000000000000000000000000000000000..ac848d6230fabadd13fd9fa3373bc38e802ac0fd --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/general.h @@ -0,0 +1,53 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_GENERAL_H_ +#define OPENCV_FLANN_GENERAL_H_ + +//! @cond IGNORED + +#include "opencv2/core.hpp" + +namespace cvflann +{ + +class FLANNException : public cv::Exception +{ +public: + FLANNException(const char* message) : cv::Exception(0, message, "", __FILE__, __LINE__) { } + + FLANNException(const cv::String& message) : cv::Exception(0, message, "", __FILE__, __LINE__) { } +}; + +} + +//! @endcond + +#endif /* OPENCV_FLANN_GENERAL_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/ground_truth.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/ground_truth.h new file mode 100644 index 0000000000000000000000000000000000000000..17f2a8e848c30462d029b885de26d3810f948b0e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/ground_truth.h @@ -0,0 +1,98 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_GROUND_TRUTH_H_ +#define OPENCV_FLANN_GROUND_TRUTH_H_ + +//! @cond IGNORED + +#include "dist.h" +#include "matrix.h" + + +namespace cvflann +{ + +template +void find_nearest(const Matrix& dataset, typename Distance::ElementType* query, int* matches, int nn, + int skip = 0, Distance distance = Distance()) +{ + typedef typename Distance::ResultType DistanceType; + int n = nn + skip; + + std::vector match(n); + std::vector dists(n); + + dists[0] = distance(dataset[0], query, dataset.cols); + match[0] = 0; + int dcnt = 1; + + for (size_t i=1; i=1 && dists[j] +void compute_ground_truth(const Matrix& dataset, const Matrix& testset, Matrix& matches, + int skip=0, Distance d = Distance()) +{ + for (size_t i=0; i(dataset, testset[i], matches[i], (int)matches.cols, skip, d); + } +} + + +} + +//! @endcond + +#endif //OPENCV_FLANN_GROUND_TRUTH_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/hdf5.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/hdf5.h new file mode 100644 index 0000000000000000000000000000000000000000..75543840d60a96d82626429cadef14c1837d2a64 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/hdf5.h @@ -0,0 +1,235 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_HDF5_H_ +#define OPENCV_FLANN_HDF5_H_ + +//! @cond IGNORED + +#include + +#include "matrix.h" + + +namespace cvflann +{ + +namespace +{ + +template +hid_t get_hdf5_type() +{ + throw FLANNException("Unsupported type for IO operations"); +} + +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_CHAR; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_UCHAR; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_SHORT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_USHORT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_INT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_UINT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_LONG; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_ULONG; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_FLOAT; } +template<> +hid_t get_hdf5_type() { return H5T_NATIVE_DOUBLE; } +} + + +#define CHECK_ERROR(x,y) if ((x)<0) throw FLANNException((y)); + +template +void save_to_file(const cvflann::Matrix& dataset, const String& filename, const String& name) +{ + +#if H5Eset_auto_vers == 2 + H5Eset_auto( H5E_DEFAULT, NULL, NULL ); +#else + H5Eset_auto( NULL, NULL ); +#endif + + herr_t status; + hid_t file_id; + file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + if (file_id < 0) { + file_id = H5Fcreate(filename.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); + } + CHECK_ERROR(file_id,"Error creating hdf5 file."); + + hsize_t dimsf[2]; // dataset dimensions + dimsf[0] = dataset.rows; + dimsf[1] = dataset.cols; + + hid_t space_id = H5Screate_simple(2, dimsf, NULL); + hid_t memspace_id = H5Screate_simple(2, dimsf, NULL); + + hid_t dataset_id; +#if H5Dcreate_vers == 2 + dataset_id = H5Dcreate2(file_id, name.c_str(), get_hdf5_type(), space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); +#else + dataset_id = H5Dcreate(file_id, name.c_str(), get_hdf5_type(), space_id, H5P_DEFAULT); +#endif + + if (dataset_id<0) { +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + } + CHECK_ERROR(dataset_id,"Error creating or opening dataset in file."); + + status = H5Dwrite(dataset_id, get_hdf5_type(), memspace_id, space_id, H5P_DEFAULT, dataset.data ); + CHECK_ERROR(status, "Error writing to dataset"); + + H5Sclose(memspace_id); + H5Sclose(space_id); + H5Dclose(dataset_id); + H5Fclose(file_id); + +} + + +template +void load_from_file(cvflann::Matrix& dataset, const String& filename, const String& name) +{ + herr_t status; + hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + CHECK_ERROR(file_id,"Error opening hdf5 file."); + + hid_t dataset_id; +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + CHECK_ERROR(dataset_id,"Error opening dataset in file."); + + hid_t space_id = H5Dget_space(dataset_id); + + hsize_t dims_out[2]; + H5Sget_simple_extent_dims(space_id, dims_out, NULL); + + dataset = cvflann::Matrix(new T[dims_out[0]*dims_out[1]], dims_out[0], dims_out[1]); + + status = H5Dread(dataset_id, get_hdf5_type(), H5S_ALL, H5S_ALL, H5P_DEFAULT, dataset[0]); + CHECK_ERROR(status, "Error reading dataset"); + + H5Sclose(space_id); + H5Dclose(dataset_id); + H5Fclose(file_id); +} + + +#ifdef HAVE_MPI + +namespace mpi +{ +/** + * Loads a the hyperslice corresponding to this processor from a hdf5 file. + * @param flann_dataset Dataset where the data is loaded + * @param filename HDF5 file name + * @param name Name of dataset inside file + */ +template +void load_from_file(cvflann::Matrix& dataset, const String& filename, const String& name) +{ + MPI_Comm comm = MPI_COMM_WORLD; + MPI_Info info = MPI_INFO_NULL; + + int mpi_size, mpi_rank; + MPI_Comm_size(comm, &mpi_size); + MPI_Comm_rank(comm, &mpi_rank); + + herr_t status; + + hid_t plist_id = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_mpio(plist_id, comm, info); + hid_t file_id = H5Fopen(filename.c_str(), H5F_ACC_RDWR, plist_id); + CHECK_ERROR(file_id,"Error opening hdf5 file."); + H5Pclose(plist_id); + hid_t dataset_id; +#if H5Dopen_vers == 2 + dataset_id = H5Dopen2(file_id, name.c_str(), H5P_DEFAULT); +#else + dataset_id = H5Dopen(file_id, name.c_str()); +#endif + CHECK_ERROR(dataset_id,"Error opening dataset in file."); + + hid_t space_id = H5Dget_space(dataset_id); + hsize_t dims[2]; + H5Sget_simple_extent_dims(space_id, dims, NULL); + + hsize_t count[2]; + hsize_t offset[2]; + + hsize_t item_cnt = dims[0]/mpi_size+(dims[0]%mpi_size==0 ? 0 : 1); + hsize_t cnt = (mpi_rank(), memspace_id, space_id, plist_id, dataset.data); + CHECK_ERROR(status, "Error reading dataset"); + + H5Pclose(plist_id); + H5Sclose(space_id); + H5Sclose(memspace_id); + H5Dclose(dataset_id); + H5Fclose(file_id); +} +} +#endif // HAVE_MPI +} // namespace cvflann::mpi + +//! @endcond + +#endif /* OPENCV_FLANN_HDF5_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/heap.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/heap.h new file mode 100644 index 0000000000000000000000000000000000000000..ee1c682cfe98e997619d284d763838ed2313cb23 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/heap.h @@ -0,0 +1,169 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_HEAP_H_ +#define OPENCV_FLANN_HEAP_H_ + +//! @cond IGNORED + +#include +#include + +namespace cvflann +{ + +/** + * Priority Queue Implementation + * + * The priority queue is implemented with a heap. A heap is a complete + * (full) binary tree in which each parent is less than both of its + * children, but the order of the children is unspecified. + */ +template +class Heap +{ + + /** + * Storage array for the heap. + * Type T must be comparable. + */ + std::vector heap; + int length; + + /** + * Number of element in the heap + */ + int count; + + + +public: + /** + * Constructor. + * + * Params: + * sz = heap size + */ + + Heap(int sz) + { + length = sz; + heap.reserve(length); + count = 0; + } + + /** + * + * Returns: heap size + */ + int size() + { + return count; + } + + /** + * Tests if the heap is empty + * + * Returns: true is heap empty, false otherwise + */ + bool empty() + { + return size()==0; + } + + /** + * Clears the heap. + */ + void clear() + { + heap.clear(); + count = 0; + } + + struct CompareT + { + bool operator()(const T& t_1, const T& t_2) const + { + return t_2 < t_1; + } + }; + + /** + * Insert a new element in the heap. + * + * We select the next empty leaf node, and then keep moving any larger + * parents down until the right location is found to store this element. + * + * Params: + * value = the new element to be inserted in the heap + */ + void insert(T value) + { + /* If heap is full, then return without adding this element. */ + if (count == length) { + return; + } + + heap.push_back(value); + static CompareT compareT; + std::push_heap(heap.begin(), heap.end(), compareT); + ++count; + } + + + + /** + * Returns the node of minimum value from the heap (top of the heap). + * + * Params: + * value = out parameter used to return the min element + * Returns: false if heap empty + */ + bool popMin(T& value) + { + if (count == 0) { + return false; + } + + value = heap[0]; + static CompareT compareT; + std::pop_heap(heap.begin(), heap.end(), compareT); + heap.pop_back(); + --count; + + return true; /* Return old last node. */ + } +}; + +} + +//! @endcond + +#endif //OPENCV_FLANN_HEAP_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/hierarchical_clustering_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/hierarchical_clustering_index.h new file mode 100644 index 0000000000000000000000000000000000000000..20304ede73de7b836ad6ea2512c3d669c2165914 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/hierarchical_clustering_index.h @@ -0,0 +1,852 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ +#define OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ + +//! @cond IGNORED + +#include +#include +#include +#include +#include + +#include "general.h" +#include "nn_index.h" +#include "dist.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + + +namespace cvflann +{ + +struct HierarchicalClusteringIndexParams : public IndexParams +{ + HierarchicalClusteringIndexParams(int branching = 32, + flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, + int trees = 4, int leaf_size = 100) + { + (*this)["algorithm"] = FLANN_INDEX_HIERARCHICAL; + // The branching factor used in the hierarchical clustering + (*this)["branching"] = branching; + // Algorithm used for picking the initial cluster centers + (*this)["centers_init"] = centers_init; + // number of parallel trees to build + (*this)["trees"] = trees; + // maximum leaf size + (*this)["leaf_size"] = leaf_size; + } +}; + + +/** + * Hierarchical index + * + * Contains a tree constructed through a hierarchical clustering + * and other information for indexing a set of points for nearest-neighbour matching. + */ +template +class HierarchicalClusteringIndex : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + +private: + + + typedef void (HierarchicalClusteringIndex::* centersAlgFunction)(int, int*, int, int*, int&); + + /** + * The function used for choosing the cluster centers. + */ + centersAlgFunction chooseCenters; + + + + /** + * Chooses the initial centers in the k-means clustering in a random manner. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * indices_length = length of indices vector + * + */ + void chooseCentersRandom(int k, int* dsindices, int indices_length, int* centers, int& centers_length) + { + UniqueRandom r(indices_length); + + int index; + for (index=0; index=0 && rnd < n); + + centers[0] = dsindices[rnd]; + + int index; + for (index=1; indexbest_val) { + best_val = dist; + best_index = j; + } + } + if (best_index!=-1) { + centers[index] = dsindices[best_index]; + } + else { + break; + } + } + centers_length = index; + } + + + /** + * Chooses the initial centers in the k-means using the algorithm + * proposed in the KMeans++ paper: + * Arthur, David; Vassilvitskii, Sergei - k-means++: The Advantages of Careful Seeding + * + * Implementation of this function was converted from the one provided in Arthur's code. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void chooseCentersKMeanspp(int k, int* dsindices, int indices_length, int* centers, int& centers_length) + { + int n = indices_length; + + double currentPot = 0; + DistanceType* closestDistSq = new DistanceType[n]; + + // Choose one random center and set the closestDistSq values + int index = rand_int(n); + assert(index >=0 && index < n); + centers[0] = dsindices[index]; + + // Computing distance^2 will have the advantage of even higher probability further to pick new centers + // far from previous centers (and this complies to "k-means++: the advantages of careful seeding" article) + for (int i = 0; i < n; i++) { + closestDistSq[i] = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + closestDistSq[i] = ensureSquareDistance( closestDistSq[i] ); + currentPot += closestDistSq[i]; + } + + + const int numLocalTries = 1; + + // Choose each center + int centerCount; + for (centerCount = 1; centerCount < k; centerCount++) { + + // Repeat several trials + double bestNewPot = -1; + int bestNewIndex = 0; + for (int localTrial = 0; localTrial < numLocalTries; localTrial++) { + + // Choose our center - have to be slightly careful to return a valid answer even accounting + // for possible rounding errors + double randVal = rand_double(currentPot); + for (index = 0; index < n-1; index++) { + if (randVal <= closestDistSq[index]) break; + else randVal -= closestDistSq[index]; + } + + // Compute the new potential + double newPot = 0; + for (int i = 0; i < n; i++) { + DistanceType dist = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + newPot += std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } + + // Store the best result + if ((bestNewPot < 0)||(newPot < bestNewPot)) { + bestNewPot = newPot; + bestNewIndex = index; + } + } + + // Add the appropriate center + centers[centerCount] = dsindices[bestNewIndex]; + currentPot = bestNewPot; + for (int i = 0; i < n; i++) { + DistanceType dist = distance(dataset[dsindices[i]], dataset[dsindices[bestNewIndex]], dataset.cols); + closestDistSq[i] = std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } + } + + centers_length = centerCount; + + delete[] closestDistSq; + } + + + /** + * Chooses the initial centers in a way inspired by Gonzales (by Pierre-Emmanuel Viel): + * select the first point of the list as a candidate, then parse the points list. If another + * point is further than current candidate from the other centers, test if it is a good center + * of a local aggregation. If it is, replace current candidate by this point. And so on... + * + * Used with KMeansIndex that computes centers coordinates by averaging positions of clusters points, + * this doesn't make a real difference with previous methods. But used with HierarchicalClusteringIndex + * class that pick centers among existing points instead of computing the barycenters, there is a real + * improvement. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void GroupWiseCenterChooser(int k, int* dsindices, int indices_length, int* centers, int& centers_length) + { + const float kSpeedUpFactor = 1.3f; + + int n = indices_length; + + DistanceType* closestDistSq = new DistanceType[n]; + + // Choose one random center and set the closestDistSq values + int index = rand_int(n); + assert(index >=0 && index < n); + centers[0] = dsindices[index]; + + for (int i = 0; i < n; i++) { + closestDistSq[i] = distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols); + } + + + // Choose each center + int centerCount; + for (centerCount = 1; centerCount < k; centerCount++) { + + // Repeat several trials + double bestNewPot = -1; + int bestNewIndex = 0; + DistanceType furthest = 0; + for (index = 0; index < n; index++) { + + // We will test only the potential of the points further than current candidate + if( closestDistSq[index] > kSpeedUpFactor * (float)furthest ) { + + // Compute the new potential + double newPot = 0; + for (int i = 0; i < n; i++) { + newPot += std::min( distance(dataset[dsindices[i]], dataset[dsindices[index]], dataset.cols) + , closestDistSq[i] ); + } + + // Store the best result + if ((bestNewPot < 0)||(newPot <= bestNewPot)) { + bestNewPot = newPot; + bestNewIndex = index; + furthest = closestDistSq[index]; + } + } + } + + // Add the appropriate center + centers[centerCount] = dsindices[bestNewIndex]; + for (int i = 0; i < n; i++) { + closestDistSq[i] = std::min( distance(dataset[dsindices[i]], dataset[dsindices[bestNewIndex]], dataset.cols) + , closestDistSq[i] ); + } + } + + centers_length = centerCount; + + delete[] closestDistSq; + } + + +public: + + + /** + * Index constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the hierarchical k-means algorithm + */ + HierarchicalClusteringIndex(const Matrix& inputData, const IndexParams& index_params = HierarchicalClusteringIndexParams(), + Distance d = Distance()) + : dataset(inputData), params(index_params), root(NULL), indices(NULL), distance(d) + { + memoryCounter = 0; + + size_ = dataset.rows; + veclen_ = dataset.cols; + + branching_ = get_param(params,"branching",32); + centers_init_ = get_param(params,"centers_init", FLANN_CENTERS_RANDOM); + trees_ = get_param(params,"trees",4); + leaf_size_ = get_param(params,"leaf_size",100); + + if (centers_init_==FLANN_CENTERS_RANDOM) { + chooseCenters = &HierarchicalClusteringIndex::chooseCentersRandom; + } + else if (centers_init_==FLANN_CENTERS_GONZALES) { + chooseCenters = &HierarchicalClusteringIndex::chooseCentersGonzales; + } + else if (centers_init_==FLANN_CENTERS_KMEANSPP) { + chooseCenters = &HierarchicalClusteringIndex::chooseCentersKMeanspp; + } + else if (centers_init_==FLANN_CENTERS_GROUPWISE) { + chooseCenters = &HierarchicalClusteringIndex::GroupWiseCenterChooser; + } + else { + throw FLANNException("Unknown algorithm for choosing initial centers."); + } + + trees_ = get_param(params,"trees",4); + root = new NodePtr[trees_]; + indices = new int*[trees_]; + + for (int i=0; i(); + computeClustering(root[i], indices[i], (int)size_, branching_,0); + } + } + + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_HIERARCHICAL; + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, branching_); + save_value(stream, trees_); + save_value(stream, centers_init_); + save_value(stream, leaf_size_); + save_value(stream, memoryCounter); + for (int i=0; i& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + + int maxChecks = get_param(searchParams,"checks",32); + + // Priority queue storing intermediate branches in the best-bin-first search + Heap* heap = new Heap((int)size_); + + std::vector checked(size_,false); + int checks = 0; + for (int i=0; ipopMin(branch) && (checks BranchSt; + + + + void save_tree(FILE* stream, NodePtr node, int num) + { + save_value(stream, *node); + if (node->childs==NULL) { + int indices_offset = (int)(node->indices - indices[num]); + save_value(stream, indices_offset); + } + else { + for(int i=0; ichilds[i], num); + } + } + } + + + void load_tree(FILE* stream, NodePtr& node, int num) + { + node = pool.allocate(); + load_value(stream, *node); + if (node->childs==NULL) { + int indices_offset; + load_value(stream, indices_offset); + node->indices = indices[num] + indices_offset; + } + else { + node->childs = pool.allocate(branching_); + for(int i=0; ichilds[i], num); + } + } + } + + + + + void computeLabels(int* dsindices, int indices_length, int* centers, int centers_length, int* labels, DistanceType& cost) + { + cost = 0; + for (int i=0; inew_dist) { + labels[i] = j; + dist = new_dist; + } + } + cost += dist; + } + } + + /** + * The method responsible with actually doing the recursive hierarchical + * clustering + * + * Params: + * node = the node to cluster + * indices = indices of the points belonging to the current node + * branching = the branching factor to use in the clustering + * + * TODO: for 1-sized clusters don't store a cluster center (it's the same as the single cluster point) + */ + void computeClustering(NodePtr node, int* dsindices, int indices_length, int branching, int level) + { + node->size = indices_length; + node->level = level; + + if (indices_length < leaf_size_) { // leaf node + node->indices = dsindices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + std::vector centers(branching); + std::vector labels(indices_length); + + int centers_length; + (this->*chooseCenters)(branching, dsindices, indices_length, ¢ers[0], centers_length); + + if (centers_lengthindices = dsindices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + + // assign points to clusters + DistanceType cost; + computeLabels(dsindices, indices_length, ¢ers[0], centers_length, &labels[0], cost); + + node->childs = pool.allocate(branching); + int start = 0; + int end = start; + for (int i=0; ichilds[i] = pool.allocate(); + node->childs[i]->pivot = centers[i]; + node->childs[i]->indices = NULL; + computeClustering(node->childs[i],dsindices+start, end-start, branching, level+1); + start=end; + } + } + + + + /** + * Performs one descent in the hierarchical k-means tree. The branches not + * visited are stored in a priority queue. + * + * Params: + * node = node to explore + * result = container for the k-nearest neighbors found + * vec = query points + * checks = how many points in the dataset have been checked so far + * maxChecks = maximum dataset points to checks + */ + + + void findNN(NodePtr node, ResultSet& result, const ElementType* vec, int& checks, int maxChecks, + Heap* heap, std::vector& checked) + { + if (node->childs==NULL) { + if (checks>=maxChecks) { + if (result.full()) return; + } + for (int i=0; isize; ++i) { + int index = node->indices[i]; + if (!checked[index]) { + DistanceType dist = distance(dataset[index], vec, veclen_); + result.addPoint(dist, index); + checked[index] = true; + ++checks; + } + } + } + else { + DistanceType* domain_distances = new DistanceType[branching_]; + int best_index = 0; + domain_distances[best_index] = distance(vec, dataset[node->childs[best_index]->pivot], veclen_); + for (int i=1; ichilds[i]->pivot], veclen_); + if (domain_distances[i]insert(BranchSt(node->childs[i],domain_distances[i])); + } + } + delete[] domain_distances; + findNN(node->childs[best_index],result,vec, checks, maxChecks, heap, checked); + } + } + +private: + + + /** + * The dataset used by this index + */ + const Matrix dataset; + + /** + * Parameters used by this index + */ + IndexParams params; + + + /** + * Number of features in the dataset. + */ + size_t size_; + + /** + * Length of each feature. + */ + size_t veclen_; + + /** + * The root node in the tree. + */ + NodePtr* root; + + /** + * Array of indices to vectors in the dataset. + */ + int** indices; + + + /** + * The distance + */ + Distance distance; + + /** + * Pooled memory allocator. + * + * Using a pooled memory allocator is more efficient + * than allocating memory directly when there is a large + * number small of memory allocations. + */ + PooledAllocator pool; + + /** + * Memory occupied by the index. + */ + int memoryCounter; + + /** index parameters */ + int branching_; + int trees_; + flann_centers_init_t centers_init_; + int leaf_size_; + + +}; + +} + +//! @endcond + +#endif /* OPENCV_FLANN_HIERARCHICAL_CLUSTERING_INDEX_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/index_testing.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/index_testing.h new file mode 100644 index 0000000000000000000000000000000000000000..47b6f0b86f36d91c11d39a2dcc17e007c1d77e4f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/index_testing.h @@ -0,0 +1,322 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_INDEX_TESTING_H_ +#define OPENCV_FLANN_INDEX_TESTING_H_ + +//! @cond IGNORED + +#include +#include +#include + +#include "matrix.h" +#include "nn_index.h" +#include "result_set.h" +#include "logger.h" +#include "timer.h" + + +namespace cvflann +{ + +inline int countCorrectMatches(int* neighbors, int* groundTruth, int n) +{ + int count = 0; + for (int i=0; i +typename Distance::ResultType computeDistanceRaport(const Matrix& inputData, typename Distance::ElementType* target, + int* neighbors, int* groundTruth, int veclen, int n, const Distance& distance) +{ + typedef typename Distance::ResultType DistanceType; + + DistanceType ret = 0; + for (int i=0; i +float search_with_ground_truth(NNIndex& index, const Matrix& inputData, + const Matrix& testData, const Matrix& matches, int nn, int checks, + float& time, typename Distance::ResultType& dist, const Distance& distance, int skipMatches) +{ + typedef typename Distance::ResultType DistanceType; + + if (matches.cols resultSet(nn+skipMatches); + SearchParams searchParams(checks); + + std::vector indices(nn+skipMatches); + std::vector dists(nn+skipMatches); + int* neighbors = &indices[skipMatches]; + + int correct = 0; + DistanceType distR = 0; + StartStopTimer t; + int repeats = 0; + while (t.value<0.2) { + repeats++; + t.start(); + correct = 0; + distR = 0; + for (size_t i = 0; i < testData.rows; i++) { + resultSet.init(&indices[0], &dists[0]); + index.findNeighbors(resultSet, testData[i], searchParams); + + correct += countCorrectMatches(neighbors,matches[i], nn); + distR += computeDistanceRaport(inputData, testData[i], neighbors, matches[i], (int)testData.cols, nn, distance); + } + t.stop(); + } + time = float(t.value/repeats); + + float precicion = (float)correct/(nn*testData.rows); + + dist = distR/(testData.rows*nn); + + Logger::info("%8d %10.4g %10.5g %10.5g %10.5g\n", + checks, precicion, time, 1000.0 * time / testData.rows, dist); + + return precicion; +} + + +template +float test_index_checks(NNIndex& index, const Matrix& inputData, + const Matrix& testData, const Matrix& matches, + int checks, float& precision, const Distance& distance, int nn = 1, int skipMatches = 0) +{ + typedef typename Distance::ResultType DistanceType; + + Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + Logger::info("---------------------------------------------------------\n"); + + float time = 0; + DistanceType dist = 0; + precision = search_with_ground_truth(index, inputData, testData, matches, nn, checks, time, dist, distance, skipMatches); + + return time; +} + +template +float test_index_precision(NNIndex& index, const Matrix& inputData, + const Matrix& testData, const Matrix& matches, + float precision, int& checks, const Distance& distance, int nn = 1, int skipMatches = 0) +{ + typedef typename Distance::ResultType DistanceType; + const float SEARCH_EPS = 0.001f; + + Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + Logger::info("---------------------------------------------------------\n"); + + int c2 = 1; + float p2; + int c1 = 1; + //float p1; + float time; + DistanceType dist; + + p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches); + + if (p2>precision) { + Logger::info("Got as close as I can\n"); + checks = c2; + return time; + } + + while (p2SEARCH_EPS) { + Logger::info("Start linear estimation\n"); + // after we got to values in the vecinity of the desired precision + // use linear approximation get a better estimation + + cx = (c1+c2)/2; + realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches); + while (fabs(realPrecision-precision)>SEARCH_EPS) { + + if (realPrecision +void test_index_precisions(NNIndex& index, const Matrix& inputData, + const Matrix& testData, const Matrix& matches, + float* precisions, int precisions_length, const Distance& distance, int nn = 1, int skipMatches = 0, float maxTime = 0) +{ + typedef typename Distance::ResultType DistanceType; + + const float SEARCH_EPS = 0.001; + + // make sure precisions array is sorted + std::sort(precisions, precisions+precisions_length); + + int pindex = 0; + float precision = precisions[pindex]; + + Logger::info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + Logger::info("---------------------------------------------------------\n"); + + int c2 = 1; + float p2; + + int c1 = 1; + float p1; + + float time; + DistanceType dist; + + p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches); + + // if precision for 1 run down the tree is already + // better then some of the requested precisions, then + // skip those + while (precisions[pindex] 0)&&(time > maxTime)&&(p2SEARCH_EPS) { + Logger::info("Start linear estimation\n"); + // after we got to values in the vecinity of the desired precision + // use linear approximation get a better estimation + + cx = (c1+c2)/2; + realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, distance, skipMatches); + while (fabs(realPrecision-precision)>SEARCH_EPS) { + + if (realPrecision +#include +#include +#include + +#include "general.h" +#include "nn_index.h" +#include "dynamic_bitset.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + + +namespace cvflann +{ + +struct KDTreeIndexParams : public IndexParams +{ + KDTreeIndexParams(int trees = 4) + { + (*this)["algorithm"] = FLANN_INDEX_KDTREE; + (*this)["trees"] = trees; + } +}; + + +/** + * Randomized kd-tree index + * + * Contains the k-d trees and other information for indexing a set of points + * for nearest-neighbor matching. + */ +template +class KDTreeIndex : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + /** + * KDTree constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the kdtree algorithm + */ + KDTreeIndex(const Matrix& inputData, const IndexParams& params = KDTreeIndexParams(), + Distance d = Distance() ) : + dataset_(inputData), index_params_(params), distance_(d) + { + size_ = dataset_.rows; + veclen_ = dataset_.cols; + + trees_ = get_param(index_params_,"trees",4); + tree_roots_ = new NodePtr[trees_]; + + // Create a permutable array of indices to the input vectors. + vind_.resize(size_); + for (size_t i = 0; i < size_; ++i) { + vind_[i] = int(i); + } + + mean_ = new DistanceType[veclen_]; + var_ = new DistanceType[veclen_]; + } + + + KDTreeIndex(const KDTreeIndex&); + KDTreeIndex& operator=(const KDTreeIndex&); + + /** + * Standard destructor + */ + ~KDTreeIndex() + { + if (tree_roots_!=NULL) { + delete[] tree_roots_; + } + delete[] mean_; + delete[] var_; + } + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + /* Construct the randomized trees. */ + for (int i = 0; i < trees_; i++) { + /* Randomize the order of vectors to allow for unbiased sampling. */ +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(vind_); +#else + std::random_shuffle(vind_.begin(), vind_.end()); +#endif + + tree_roots_[i] = divideTree(&vind_[0], int(size_) ); + } + } + + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_KDTREE; + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, trees_); + for (int i=0; i& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + int maxChecks = get_param(searchParams,"checks", 32); + float epsError = 1+get_param(searchParams,"eps",0.0f); + + if (maxChecks==FLANN_CHECKS_UNLIMITED) { + getExactNeighbors(result, vec, epsError); + } + else { + getNeighbors(result, vec, maxChecks, epsError); + } + } + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + +private: + + + /*--------------------- Internal Data Structures --------------------------*/ + struct Node + { + /** + * Dimension used for subdivision. + */ + int divfeat; + /** + * The values used for subdivision. + */ + DistanceType divval; + /** + * The child nodes. + */ + Node* child1, * child2; + }; + typedef Node* NodePtr; + typedef BranchStruct BranchSt; + typedef BranchSt* Branch; + + + + void save_tree(FILE* stream, NodePtr tree) + { + save_value(stream, *tree); + if (tree->child1!=NULL) { + save_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + save_tree(stream, tree->child2); + } + } + + + void load_tree(FILE* stream, NodePtr& tree) + { + tree = pool_.allocate(); + load_value(stream, *tree); + if (tree->child1!=NULL) { + load_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + load_tree(stream, tree->child2); + } + } + + + /** + * Create a tree node that subdivides the list of vecs from vind[first] + * to vind[last]. The routine is called recursively on each sublist. + * Place a pointer to this new tree node in the location pTree. + * + * Params: pTree = the new node to create + * first = index of the first vector + * last = index of the last vector + */ + NodePtr divideTree(int* ind, int count) + { + NodePtr node = pool_.allocate(); // allocate memory + + /* If too few exemplars remain, then make this a leaf node. */ + if ( count == 1) { + node->child1 = node->child2 = NULL; /* Mark as leaf node. */ + node->divfeat = *ind; /* Store index of this vec. */ + } + else { + int idx; + int cutfeat; + DistanceType cutval; + meanSplit(ind, count, idx, cutfeat, cutval); + + node->divfeat = cutfeat; + node->divval = cutval; + node->child1 = divideTree(ind, idx); + node->child2 = divideTree(ind+idx, count-idx); + } + + return node; + } + + + /** + * Choose which feature to use in order to subdivide this set of vectors. + * Make a random choice among those with the highest variance, and use + * its variance as the threshold value. + */ + void meanSplit(int* ind, int count, int& index, int& cutfeat, DistanceType& cutval) + { + memset(mean_,0,veclen_*sizeof(DistanceType)); + memset(var_,0,veclen_*sizeof(DistanceType)); + + /* Compute mean values. Only the first SAMPLE_MEAN values need to be + sampled to get a good estimate. + */ + int cnt = std::min((int)SAMPLE_MEAN+1, count); + for (int j = 0; j < cnt; ++j) { + ElementType* v = dataset_[ind[j]]; + for (size_t k=0; kcount/2) index = lim1; + else if (lim2 v[topind[num-1]])) { + /* Put this element at end of topind. */ + if (num < RAND_DIM) { + topind[num++] = i; /* Add to list. */ + } + else { + topind[num-1] = i; /* Replace last element. */ + } + /* Bubble end value down to right location by repeated swapping. */ + int j = num - 1; + while (j > 0 && v[topind[j]] > v[topind[j-1]]) { + std::swap(topind[j], topind[j-1]); + --j; + } + } + } + /* Select a random integer in range [0,num-1], and return that index. */ + int rnd = rand_int(num); + return (int)topind[rnd]; + } + + + /** + * Subdivide the list of points by a plane perpendicular on axe corresponding + * to the 'cutfeat' dimension at 'cutval' position. + * + * On return: + * dataset[ind[0..lim1-1]][cutfeat]cutval + */ + void planeSplit(int* ind, int count, int cutfeat, DistanceType cutval, int& lim1, int& lim2) + { + /* Move vector indices for left subtree to front of list. */ + int left = 0; + int right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]=cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + lim1 = left; + right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]<=cutval) ++left; + while (left<=right && dataset_[ind[right]][cutfeat]>cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + lim2 = left; + } + + /** + * Performs an exact nearest neighbor search. The exact search performs a full + * traversal of the tree. + */ + void getExactNeighbors(ResultSet& result, const ElementType* vec, float epsError) + { + // checkID -= 1; /* Set a different unique ID for each search. */ + + if (trees_ > 1) { + fprintf(stderr,"It doesn't make any sense to use more than one tree for exact search"); + } + if (trees_>0) { + searchLevelExact(result, vec, tree_roots_[0], 0.0, epsError); + } + assert(result.full()); + } + + /** + * Performs the approximate nearest-neighbor search. The search is approximate + * because the tree traversal is abandoned after a given number of descends in + * the tree. + */ + void getNeighbors(ResultSet& result, const ElementType* vec, int maxCheck, float epsError) + { + int i; + BranchSt branch; + + int checkCount = 0; + Heap* heap = new Heap((int)size_); + DynamicBitset checked(size_); + + /* Search once through each tree down to root. */ + for (i = 0; i < trees_; ++i) { + searchLevel(result, vec, tree_roots_[i], 0, checkCount, maxCheck, epsError, heap, checked); + } + + /* Keep searching other branches from heap until finished. */ + while ( heap->popMin(branch) && (checkCount < maxCheck || !result.full() )) { + searchLevel(result, vec, branch.node, branch.mindist, checkCount, maxCheck, epsError, heap, checked); + } + + delete heap; + + assert(result.full()); + } + + + /** + * Search starting from a given node of the tree. Based on any mismatches at + * higher levels, all exemplars below this level must have a distance of + * at least "mindistsq". + */ + void searchLevel(ResultSet& result_set, const ElementType* vec, NodePtr node, DistanceType mindist, int& checkCount, int maxCheck, + float epsError, Heap* heap, DynamicBitset& checked) + { + if (result_set.worstDist()child1 == NULL)&&(node->child2 == NULL)) { + /* Do not check same node more than once when searching multiple trees. + Once a vector is checked, we set its location in vind to the + current checkID. + */ + int index = node->divfeat; + if ( checked.test(index) || ((checkCount>=maxCheck)&& result_set.full()) ) return; + checked.set(index); + checkCount++; + + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result_set.addPoint(dist,index); + + return; + } + + /* Which child branch should be taken first? */ + ElementType val = vec[node->divfeat]; + DistanceType diff = val - node->divval; + NodePtr bestChild = (diff < 0) ? node->child1 : node->child2; + NodePtr otherChild = (diff < 0) ? node->child2 : node->child1; + + /* Create a branch record for the branch not taken. Add distance + of this feature boundary (we don't attempt to correct for any + use of this feature in a parent node, which is unlikely to + happen and would have only a small effect). Don't bother + adding more branches to heap after halfway point, as cost of + adding exceeds their value. + */ + + DistanceType new_distsq = mindist + distance_.accum_dist(val, node->divval, node->divfeat); + // if (2 * checkCount < maxCheck || !result.full()) { + if ((new_distsq*epsError < result_set.worstDist())|| !result_set.full()) { + heap->insert( BranchSt(otherChild, new_distsq) ); + } + + /* Call recursively to search next level down. */ + searchLevel(result_set, vec, bestChild, mindist, checkCount, maxCheck, epsError, heap, checked); + } + + /** + * Performs an exact search in the tree starting from a node. + */ + void searchLevelExact(ResultSet& result_set, const ElementType* vec, const NodePtr node, DistanceType mindist, const float epsError) + { + /* If this is a leaf node, then do check and return. */ + if ((node->child1 == NULL)&&(node->child2 == NULL)) { + int index = node->divfeat; + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result_set.addPoint(dist,index); + return; + } + + /* Which child branch should be taken first? */ + ElementType val = vec[node->divfeat]; + DistanceType diff = val - node->divval; + NodePtr bestChild = (diff < 0) ? node->child1 : node->child2; + NodePtr otherChild = (diff < 0) ? node->child2 : node->child1; + + /* Create a branch record for the branch not taken. Add distance + of this feature boundary (we don't attempt to correct for any + use of this feature in a parent node, which is unlikely to + happen and would have only a small effect). Don't bother + adding more branches to heap after halfway point, as cost of + adding exceeds their value. + */ + + DistanceType new_distsq = mindist + distance_.accum_dist(val, node->divval, node->divfeat); + + /* Call recursively to search next level down. */ + searchLevelExact(result_set, vec, bestChild, mindist, epsError); + + if (new_distsq*epsError<=result_set.worstDist()) { + searchLevelExact(result_set, vec, otherChild, new_distsq, epsError); + } + } + + +private: + + enum + { + /** + * To improve efficiency, only SAMPLE_MEAN random values are used to + * compute the mean and variance at each level when building a tree. + * A value of 100 seems to perform as well as using all values. + */ + SAMPLE_MEAN = 100, + /** + * Top random dimensions to consider + * + * When creating random trees, the dimension on which to subdivide is + * selected at random from among the top RAND_DIM dimensions with the + * highest variance. A value of 5 works well. + */ + RAND_DIM=5 + }; + + + /** + * Number of randomized trees that are used + */ + int trees_; + + /** + * Array of indices to vectors in the dataset. + */ + std::vector vind_; + + /** + * The dataset used by this index + */ + const Matrix dataset_; + + IndexParams index_params_; + + size_t size_; + size_t veclen_; + + + DistanceType* mean_; + DistanceType* var_; + + + /** + * Array of k-d trees used to find neighbours. + */ + NodePtr* tree_roots_; + + /** + * Pooled memory allocator. + * + * Using a pooled memory allocator is more efficient + * than allocating memory directly when there is a large + * number small of memory allocations. + */ + PooledAllocator pool_; + + Distance distance_; + + +}; // class KDTreeForest + +} + +//! @endcond + +#endif //OPENCV_FLANN_KDTREE_INDEX_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/kdtree_single_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/kdtree_single_index.h new file mode 100644 index 0000000000000000000000000000000000000000..fa38f9f1a2658d454a16710133b6dfc603625886 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/kdtree_single_index.h @@ -0,0 +1,639 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ +#define OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ + +//! @cond IGNORED + +#include +#include +#include +#include + +#include "general.h" +#include "nn_index.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + +namespace cvflann +{ + +struct KDTreeSingleIndexParams : public IndexParams +{ + KDTreeSingleIndexParams(int leaf_max_size = 10, bool reorder = true, int dim = -1) + { + (*this)["algorithm"] = FLANN_INDEX_KDTREE_SINGLE; + (*this)["leaf_max_size"] = leaf_max_size; + (*this)["reorder"] = reorder; + (*this)["dim"] = dim; + } +}; + + +/** + * Randomized kd-tree index + * + * Contains the k-d trees and other information for indexing a set of points + * for nearest-neighbor matching. + */ +template +class KDTreeSingleIndex : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + /** + * KDTree constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the kdtree algorithm + */ + KDTreeSingleIndex(const Matrix& inputData, const IndexParams& params = KDTreeSingleIndexParams(), + Distance d = Distance() ) : + dataset_(inputData), index_params_(params), distance_(d) + { + size_ = dataset_.rows; + dim_ = dataset_.cols; + root_node_ = 0; + int dim_param = get_param(params,"dim",-1); + if (dim_param>0) dim_ = dim_param; + leaf_max_size_ = get_param(params,"leaf_max_size",10); + reorder_ = get_param(params,"reorder",true); + + // Create a permutable array of indices to the input vectors. + vind_.resize(size_); + for (size_t i = 0; i < size_; i++) { + vind_[i] = (int)i; + } + } + + KDTreeSingleIndex(const KDTreeSingleIndex&); + KDTreeSingleIndex& operator=(const KDTreeSingleIndex&); + + /** + * Standard destructor + */ + ~KDTreeSingleIndex() + { + if (reorder_) delete[] data_.data; + } + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + computeBoundingBox(root_bbox_); + root_node_ = divideTree(0, (int)size_, root_bbox_ ); // construct the tree + + if (reorder_) { + delete[] data_.data; + data_ = cvflann::Matrix(new ElementType[size_*dim_], size_, dim_); + for (size_t i=0; i& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) CV_OVERRIDE + { + assert(queries.cols == veclen()); + assert(indices.rows >= queries.rows); + assert(dists.rows >= queries.rows); + assert(int(indices.cols) >= knn); + assert(int(dists.cols) >= knn); + + KNNSimpleResultSet resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.init(indices[i], dists[i]); + findNeighbors(resultSet, queries[i], params); + } + } + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * maxCheck = the maximum number of restarts (in a best-bin-first manner) + */ + void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + float epsError = 1+get_param(searchParams,"eps",0.0f); + + std::vector dists(dim_,0); + DistanceType distsq = computeInitialDistances(vec, dists); + searchLevel(result, vec, root_node_, distsq, dists, epsError); + } + +private: + + + /*--------------------- Internal Data Structures --------------------------*/ + struct Node + { + /** + * Indices of points in leaf node + */ + int left, right; + /** + * Dimension used for subdivision. + */ + int divfeat; + /** + * The values used for subdivision. + */ + DistanceType divlow, divhigh; + /** + * The child nodes. + */ + Node* child1, * child2; + }; + typedef Node* NodePtr; + + + struct Interval + { + DistanceType low, high; + }; + + typedef std::vector BoundingBox; + + typedef BranchStruct BranchSt; + typedef BranchSt* Branch; + + + + + void save_tree(FILE* stream, NodePtr tree) + { + save_value(stream, *tree); + if (tree->child1!=NULL) { + save_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + save_tree(stream, tree->child2); + } + } + + + void load_tree(FILE* stream, NodePtr& tree) + { + tree = pool_.allocate(); + load_value(stream, *tree); + if (tree->child1!=NULL) { + load_tree(stream, tree->child1); + } + if (tree->child2!=NULL) { + load_tree(stream, tree->child2); + } + } + + + void computeBoundingBox(BoundingBox& bbox) + { + bbox.resize(dim_); + for (size_t i=0; ibbox[i].high) bbox[i].high = (DistanceType)dataset_[k][i]; + } + } + } + + + /** + * Create a tree node that subdivides the list of vecs from vind[first] + * to vind[last]. The routine is called recursively on each sublist. + * Place a pointer to this new tree node in the location pTree. + * + * Params: pTree = the new node to create + * first = index of the first vector + * last = index of the last vector + */ + NodePtr divideTree(int left, int right, BoundingBox& bbox) + { + NodePtr node = pool_.allocate(); // allocate memory + + /* If too few exemplars remain, then make this a leaf node. */ + if ( (right-left) <= leaf_max_size_) { + node->child1 = node->child2 = NULL; /* Mark as leaf node. */ + node->left = left; + node->right = right; + + // compute bounding-box of leaf points + for (size_t i=0; idataset_[vind_[k]][i]) bbox[i].low=(DistanceType)dataset_[vind_[k]][i]; + if (bbox[i].highdivfeat = cutfeat; + + BoundingBox left_bbox(bbox); + left_bbox[cutfeat].high = cutval; + node->child1 = divideTree(left, left+idx, left_bbox); + + BoundingBox right_bbox(bbox); + right_bbox[cutfeat].low = cutval; + node->child2 = divideTree(left+idx, right, right_bbox); + + node->divlow = left_bbox[cutfeat].high; + node->divhigh = right_bbox[cutfeat].low; + + for (size_t i=0; imax_elem) max_elem = val; + } + } + + void middleSplit(int* ind, int count, int& index, int& cutfeat, DistanceType& cutval, const BoundingBox& bbox) + { + // find the largest span from the approximate bounding box + ElementType max_span = bbox[0].high-bbox[0].low; + cutfeat = 0; + cutval = (bbox[0].high+bbox[0].low)/2; + for (size_t i=1; imax_span) { + max_span = span; + cutfeat = i; + cutval = (bbox[i].high+bbox[i].low)/2; + } + } + + // compute exact span on the found dimension + ElementType min_elem, max_elem; + computeMinMax(ind, count, cutfeat, min_elem, max_elem); + cutval = (min_elem+max_elem)/2; + max_span = max_elem - min_elem; + + // check if a dimension of a largest span exists + size_t k = cutfeat; + for (size_t i=0; imax_span) { + computeMinMax(ind, count, i, min_elem, max_elem); + span = max_elem - min_elem; + if (span>max_span) { + max_span = span; + cutfeat = i; + cutval = (min_elem+max_elem)/2; + } + } + } + int lim1, lim2; + planeSplit(ind, count, cutfeat, cutval, lim1, lim2); + + if (lim1>count/2) index = lim1; + else if (lim2max_span) { + max_span = span; + } + } + DistanceType max_spread = -1; + cutfeat = 0; + for (size_t i=0; i(DistanceType)((1-EPS)*max_span)) { + ElementType min_elem, max_elem; + computeMinMax(ind, count, cutfeat, min_elem, max_elem); + DistanceType spread = (DistanceType)(max_elem-min_elem); + if (spread>max_spread) { + cutfeat = (int)i; + max_spread = spread; + } + } + } + // split in the middle + DistanceType split_val = (bbox[cutfeat].low+bbox[cutfeat].high)/2; + ElementType min_elem, max_elem; + computeMinMax(ind, count, cutfeat, min_elem, max_elem); + + if (split_valmax_elem) cutval = (DistanceType)max_elem; + else cutval = split_val; + + int lim1, lim2; + planeSplit(ind, count, cutfeat, cutval, lim1, lim2); + + if (lim1>count/2) index = lim1; + else if (lim2cutval + */ + void planeSplit(int* ind, int count, int cutfeat, DistanceType cutval, int& lim1, int& lim2) + { + /* Move vector indices for left subtree to front of list. */ + int left = 0; + int right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]=cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + /* If either list is empty, it means that all remaining features + * are identical. Split in the middle to maintain a balanced tree. + */ + lim1 = left; + right = count-1; + for (;; ) { + while (left<=right && dataset_[ind[left]][cutfeat]<=cutval) ++left; + while (left<=right && dataset_[ind[right]][cutfeat]>cutval) --right; + if (left>right) break; + std::swap(ind[left], ind[right]); ++left; --right; + } + lim2 = left; + } + + DistanceType computeInitialDistances(const ElementType* vec, std::vector& dists) + { + DistanceType distsq = 0.0; + + for (size_t i = 0; i < dim_; ++i) { + if (vec[i] < root_bbox_[i].low) { + dists[i] = distance_.accum_dist(vec[i], root_bbox_[i].low, (int)i); + distsq += dists[i]; + } + if (vec[i] > root_bbox_[i].high) { + dists[i] = distance_.accum_dist(vec[i], root_bbox_[i].high, (int)i); + distsq += dists[i]; + } + } + + return distsq; + } + + /** + * Performs an exact search in the tree starting from a node. + */ + void searchLevel(ResultSet& result_set, const ElementType* vec, const NodePtr node, DistanceType mindistsq, + std::vector& dists, const float epsError) + { + /* If this is a leaf node, then do check and return. */ + if ((node->child1 == NULL)&&(node->child2 == NULL)) { + DistanceType worst_dist = result_set.worstDist(); + for (int i=node->left; iright; ++i) { + int index = reorder_ ? i : vind_[i]; + DistanceType dist = distance_(vec, data_[index], dim_, worst_dist); + if (distdivfeat; + ElementType val = vec[idx]; + DistanceType diff1 = val - node->divlow; + DistanceType diff2 = val - node->divhigh; + + NodePtr bestChild; + NodePtr otherChild; + DistanceType cut_dist; + if ((diff1+diff2)<0) { + bestChild = node->child1; + otherChild = node->child2; + cut_dist = distance_.accum_dist(val, node->divhigh, idx); + } + else { + bestChild = node->child2; + otherChild = node->child1; + cut_dist = distance_.accum_dist( val, node->divlow, idx); + } + + /* Call recursively to search next level down. */ + searchLevel(result_set, vec, bestChild, mindistsq, dists, epsError); + + DistanceType dst = dists[idx]; + mindistsq = mindistsq + cut_dist - dst; + dists[idx] = cut_dist; + if (mindistsq*epsError<=result_set.worstDist()) { + searchLevel(result_set, vec, otherChild, mindistsq, dists, epsError); + } + dists[idx] = dst; + } + +private: + + /** + * The dataset used by this index + */ + const Matrix dataset_; + + IndexParams index_params_; + + int leaf_max_size_; + bool reorder_; + + + /** + * Array of indices to vectors in the dataset. + */ + std::vector vind_; + + Matrix data_; + + size_t size_; + size_t dim_; + + /** + * Array of k-d trees used to find neighbours. + */ + NodePtr root_node_; + + BoundingBox root_bbox_; + + /** + * Pooled memory allocator. + * + * Using a pooled memory allocator is more efficient + * than allocating memory directly when there is a large + * number small of memory allocations. + */ + PooledAllocator pool_; + + Distance distance_; +}; // class KDTree + +} + +//! @endcond + +#endif //OPENCV_FLANN_KDTREE_SINGLE_INDEX_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/kmeans_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/kmeans_index.h new file mode 100644 index 0000000000000000000000000000000000000000..7574e7faf8b03359898cce04ad235f5d19c05573 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/kmeans_index.h @@ -0,0 +1,1176 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_KMEANS_INDEX_H_ +#define OPENCV_FLANN_KMEANS_INDEX_H_ + +//! @cond IGNORED + +#include +#include +#include +#include +#include + +#include "general.h" +#include "nn_index.h" +#include "dist.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" +#include "logger.h" + + +namespace cvflann +{ + +struct KMeansIndexParams : public IndexParams +{ + KMeansIndexParams(int branching = 32, int iterations = 11, + flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM, float cb_index = 0.2 ) + { + (*this)["algorithm"] = FLANN_INDEX_KMEANS; + // branching factor + (*this)["branching"] = branching; + // max iterations to perform in one kmeans clustering (kmeans tree) + (*this)["iterations"] = iterations; + // algorithm used for picking the initial cluster centers for kmeans tree + (*this)["centers_init"] = centers_init; + // cluster boundary index. Used when searching the kmeans tree + (*this)["cb_index"] = cb_index; + } +}; + + +/** + * Hierarchical kmeans index + * + * Contains a tree constructed through a hierarchical kmeans clustering + * and other information for indexing a set of points for nearest-neighbour matching. + */ +template +class KMeansIndex : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + + typedef void (KMeansIndex::* centersAlgFunction)(int, int*, int, int*, int&); + + /** + * The function used for choosing the cluster centers. + */ + centersAlgFunction chooseCenters; + + + + /** + * Chooses the initial centers in the k-means clustering in a random manner. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * indices_length = length of indices vector + * + */ + void chooseCentersRandom(int k, int* indices, int indices_length, int* centers, int& centers_length) + { + UniqueRandom r(indices_length); + + int index; + for (index=0; index=0 && rnd < n); + + centers[0] = indices[rnd]; + + int index; + for (index=1; indexbest_val) { + best_val = dist; + best_index = j; + } + } + if (best_index!=-1) { + centers[index] = indices[best_index]; + } + else { + break; + } + } + centers_length = index; + } + + + /** + * Chooses the initial centers in the k-means using the algorithm + * proposed in the KMeans++ paper: + * Arthur, David; Vassilvitskii, Sergei - k-means++: The Advantages of Careful Seeding + * + * Implementation of this function was converted from the one provided in Arthur's code. + * + * Params: + * k = number of centers + * vecs = the dataset of points + * indices = indices in the dataset + * Returns: + */ + void chooseCentersKMeanspp(int k, int* indices, int indices_length, int* centers, int& centers_length) + { + int n = indices_length; + + double currentPot = 0; + DistanceType* closestDistSq = new DistanceType[n]; + + // Choose one random center and set the closestDistSq values + int index = rand_int(n); + assert(index >=0 && index < n); + centers[0] = indices[index]; + + for (int i = 0; i < n; i++) { + closestDistSq[i] = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols); + closestDistSq[i] = ensureSquareDistance( closestDistSq[i] ); + currentPot += closestDistSq[i]; + } + + + const int numLocalTries = 1; + + // Choose each center + int centerCount; + for (centerCount = 1; centerCount < k; centerCount++) { + + // Repeat several trials + double bestNewPot = -1; + int bestNewIndex = -1; + for (int localTrial = 0; localTrial < numLocalTries; localTrial++) { + + // Choose our center - have to be slightly careful to return a valid answer even accounting + // for possible rounding errors + double randVal = rand_double(currentPot); + for (index = 0; index < n-1; index++) { + if (randVal <= closestDistSq[index]) break; + else randVal -= closestDistSq[index]; + } + + // Compute the new potential + double newPot = 0; + for (int i = 0; i < n; i++) { + DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[index]], dataset_.cols); + newPot += std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } + + // Store the best result + if ((bestNewPot < 0)||(newPot < bestNewPot)) { + bestNewPot = newPot; + bestNewIndex = index; + } + } + + // Add the appropriate center + centers[centerCount] = indices[bestNewIndex]; + currentPot = bestNewPot; + for (int i = 0; i < n; i++) { + DistanceType dist = distance_(dataset_[indices[i]], dataset_[indices[bestNewIndex]], dataset_.cols); + closestDistSq[i] = std::min( ensureSquareDistance(dist), closestDistSq[i] ); + } + } + + centers_length = centerCount; + + delete[] closestDistSq; + } + + + +public: + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_KMEANS; + } + + class KMeansDistanceComputer : public cv::ParallelLoopBody + { + public: + KMeansDistanceComputer(Distance _distance, const Matrix& _dataset, + const int _branching, const int* _indices, const Matrix& _dcenters, const size_t _veclen, + std::vector &_new_centroids, std::vector &_sq_dists) + : distance(_distance) + , dataset(_dataset) + , branching(_branching) + , indices(_indices) + , dcenters(_dcenters) + , veclen(_veclen) + , new_centroids(_new_centroids) + , sq_dists(_sq_dists) + { + } + + void operator()(const cv::Range& range) const CV_OVERRIDE + { + const int begin = range.start; + const int end = range.end; + + for( int i = begin; inew_sq_dist) { + new_centroid = j; + sq_dist = new_sq_dist; + } + } + sq_dists[i] = sq_dist; + new_centroids[i] = new_centroid; + } + } + + private: + Distance distance; + const Matrix& dataset; + const int branching; + const int* indices; + const Matrix& dcenters; + const size_t veclen; + std::vector &new_centroids; + std::vector &sq_dists; + KMeansDistanceComputer& operator=( const KMeansDistanceComputer & ) { return *this; } + }; + + /** + * Index constructor + * + * Params: + * inputData = dataset with the input features + * params = parameters passed to the hierarchical k-means algorithm + */ + KMeansIndex(const Matrix& inputData, const IndexParams& params = KMeansIndexParams(), + Distance d = Distance()) + : dataset_(inputData), index_params_(params), root_(NULL), indices_(NULL), distance_(d) + { + memoryCounter_ = 0; + + size_ = dataset_.rows; + veclen_ = dataset_.cols; + + branching_ = get_param(params,"branching",32); + iterations_ = get_param(params,"iterations",11); + if (iterations_<0) { + iterations_ = (std::numeric_limits::max)(); + } + centers_init_ = get_param(params,"centers_init",FLANN_CENTERS_RANDOM); + + if (centers_init_==FLANN_CENTERS_RANDOM) { + chooseCenters = &KMeansIndex::chooseCentersRandom; + } + else if (centers_init_==FLANN_CENTERS_GONZALES) { + chooseCenters = &KMeansIndex::chooseCentersGonzales; + } + else if (centers_init_==FLANN_CENTERS_KMEANSPP) { + chooseCenters = &KMeansIndex::chooseCentersKMeanspp; + } + else { + throw FLANNException("Unknown algorithm for choosing initial centers."); + } + cb_index_ = 0.4f; + + } + + + KMeansIndex(const KMeansIndex&); + KMeansIndex& operator=(const KMeansIndex&); + + + /** + * Index destructor. + * + * Release the memory used by the index. + */ + virtual ~KMeansIndex() + { + if (root_ != NULL) { + free_centers(root_); + } + if (indices_!=NULL) { + delete[] indices_; + } + } + + /** + * Returns size of index. + */ + size_t size() const CV_OVERRIDE + { + return size_; + } + + /** + * Returns the length of an index feature. + */ + size_t veclen() const CV_OVERRIDE + { + return veclen_; + } + + + void set_cb_index( float index) + { + cb_index_ = index; + } + + /** + * Computes the inde memory usage + * Returns: memory used by the index + */ + int usedMemory() const CV_OVERRIDE + { + return pool_.usedMemory+pool_.wastedMemory+memoryCounter_; + } + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + if (branching_<2) { + throw FLANNException("Branching factor must be at least 2"); + } + + indices_ = new int[size_]; + for (size_t i=0; i(); + std::memset(root_, 0, sizeof(KMeansNode)); + + computeNodeStatistics(root_, indices_, (int)size_); + computeClustering(root_, indices_, (int)size_, branching_,0); + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream, branching_); + save_value(stream, iterations_); + save_value(stream, memoryCounter_); + save_value(stream, cb_index_); + save_value(stream, *indices_, (int)size_); + + save_tree(stream, root_); + } + + + void loadIndex(FILE* stream) CV_OVERRIDE + { + load_value(stream, branching_); + load_value(stream, iterations_); + load_value(stream, memoryCounter_); + load_value(stream, cb_index_); + if (indices_!=NULL) { + delete[] indices_; + } + indices_ = new int[size_]; + load_value(stream, *indices_, size_); + + if (root_!=NULL) { + free_centers(root_); + } + load_tree(stream, root_); + + index_params_["algorithm"] = getType(); + index_params_["branching"] = branching_; + index_params_["iterations"] = iterations_; + index_params_["centers_init"] = centers_init_; + index_params_["cb_index"] = cb_index_; + + } + + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * searchParams = parameters that influence the search algorithm (checks, cb_index) + */ + void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE + { + + int maxChecks = get_param(searchParams,"checks",32); + + if (maxChecks==FLANN_CHECKS_UNLIMITED) { + findExactNN(root_, result, vec); + } + else { + // Priority queue storing intermediate branches in the best-bin-first search + Heap* heap = new Heap((int)size_); + + int checks = 0; + findNN(root_, result, vec, checks, maxChecks, heap); + + BranchSt branch; + while (heap->popMin(branch) && (checks& centers) + { + int numClusters = centers.rows; + if (numClusters<1) { + throw FLANNException("Number of clusters must be at least 1"); + } + + DistanceType variance; + KMeansNodePtr* clusters = new KMeansNodePtr[numClusters]; + + int clusterCount = getMinVarianceClusters(root_, clusters, numClusters, variance); + + Logger::info("Clusters requested: %d, returning %d\n",numClusters, clusterCount); + + for (int i=0; ipivot; + for (size_t j=0; j BranchSt; + + + + + void save_tree(FILE* stream, KMeansNodePtr node) + { + save_value(stream, *node); + save_value(stream, *(node->pivot), (int)veclen_); + if (node->childs==NULL) { + int indices_offset = (int)(node->indices - indices_); + save_value(stream, indices_offset); + } + else { + for(int i=0; ichilds[i]); + } + } + } + + + void load_tree(FILE* stream, KMeansNodePtr& node) + { + node = pool_.allocate(); + load_value(stream, *node); + node->pivot = new DistanceType[veclen_]; + load_value(stream, *(node->pivot), (int)veclen_); + if (node->childs==NULL) { + int indices_offset; + load_value(stream, indices_offset); + node->indices = indices_ + indices_offset; + } + else { + node->childs = pool_.allocate(branching_); + for(int i=0; ichilds[i]); + } + } + } + + + /** + * Helper function + */ + void free_centers(KMeansNodePtr node) + { + delete[] node->pivot; + if (node->childs!=NULL) { + for (int k=0; kchilds[k]); + } + } + } + + /** + * Computes the statistics of a node (mean, radius, variance). + * + * Params: + * node = the node to use + * indices = the indices of the points belonging to the node + */ + void computeNodeStatistics(KMeansNodePtr node, int* indices, int indices_length) + { + + DistanceType radius = 0; + DistanceType variance = 0; + DistanceType* mean = new DistanceType[veclen_]; + memoryCounter_ += int(veclen_*sizeof(DistanceType)); + + memset(mean,0,veclen_*sizeof(DistanceType)); + + for (size_t i=0; i(), veclen_); + } + for (size_t j=0; j(), veclen_); + + DistanceType tmp = 0; + for (int i=0; iradius) { + radius = tmp; + } + } + + node->variance = variance; + node->radius = radius; + node->pivot = mean; + } + + + /** + * The method responsible with actually doing the recursive hierarchical + * clustering + * + * Params: + * node = the node to cluster + * indices = indices of the points belonging to the current node + * branching = the branching factor to use in the clustering + * + * TODO: for 1-sized clusters don't store a cluster center (it's the same as the single cluster point) + */ + void computeClustering(KMeansNodePtr node, int* indices, int indices_length, int branching, int level) + { + node->size = indices_length; + node->level = level; + + if (indices_length < branching) { + node->indices = indices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + cv::AutoBuffer centers_idx_buf(branching); + int* centers_idx = centers_idx_buf.data(); + int centers_length; + (this->*chooseCenters)(branching, indices, indices_length, centers_idx, centers_length); + + if (centers_lengthindices = indices; + std::sort(node->indices,node->indices+indices_length); + node->childs = NULL; + return; + } + + + cv::AutoBuffer dcenters_buf(branching*veclen_); + Matrix dcenters(dcenters_buf.data(), branching, veclen_); + for (int i=0; i radiuses(branching); + cv::AutoBuffer count_buf(branching); + int* count = count_buf.data(); + for (int i=0; i belongs_to_buf(indices_length); + int* belongs_to = belongs_to_buf.data(); + for (int i=0; inew_sq_dist) { + belongs_to[i] = j; + sq_dist = new_sq_dist; + } + } + if (sq_dist>radiuses[belongs_to[i]]) { + radiuses[belongs_to[i]] = sq_dist; + } + count[belongs_to[i]]++; + } + + bool converged = false; + int iteration = 0; + while (!converged && iteration new_centroids(indices_length); + std::vector sq_dists(indices_length); + + // reassign points to clusters + KMeansDistanceComputer invoker(distance_, dataset_, branching, indices, dcenters, veclen_, new_centroids, sq_dists); + parallel_for_(cv::Range(0, (int)indices_length), invoker); + + for (int i=0; i < (int)indices_length; ++i) { + DistanceType sq_dist(sq_dists[i]); + int new_centroid(new_centroids[i]); + if (sq_dist > radiuses[new_centroid]) { + radiuses[new_centroid] = sq_dist; + } + if (new_centroid != belongs_to[i]) { + count[belongs_to[i]]--; + count[new_centroid]++; + belongs_to[i] = new_centroid; + converged = false; + } + } + + for (int i=0; ichilds = pool_.allocate(branching); + int start = 0; + int end = start; + for (int c=0; c(), veclen_); + variance += d; + mean_radius += sqrt(d); + std::swap(indices[i],indices[end]); + std::swap(belongs_to[i],belongs_to[end]); + end++; + } + } + variance /= s; + mean_radius /= s; + variance -= distance_(centers[c], ZeroIterator(), veclen_); + + node->childs[c] = pool_.allocate(); + std::memset(node->childs[c], 0, sizeof(KMeansNode)); + node->childs[c]->radius = radiuses[c]; + node->childs[c]->pivot = centers[c]; + node->childs[c]->variance = variance; + node->childs[c]->mean_radius = mean_radius; + computeClustering(node->childs[c],indices+start, end-start, branching, level+1); + start=end; + } + + delete[] centers; + } + + + + /** + * Performs one descent in the hierarchical k-means tree. The branches not + * visited are stored in a priority queue. + * + * Params: + * node = node to explore + * result = container for the k-nearest neighbors found + * vec = query points + * checks = how many points in the dataset have been checked so far + * maxChecks = maximum dataset points to checks + */ + + + void findNN(KMeansNodePtr node, ResultSet& result, const ElementType* vec, int& checks, int maxChecks, + Heap* heap) + { + // Ignore those clusters that are too far away + { + DistanceType bsq = distance_(vec, node->pivot, veclen_); + DistanceType rsq = node->radius; + DistanceType wsq = result.worstDist(); + + DistanceType val = bsq-rsq-wsq; + DistanceType val2 = val*val-4*rsq*wsq; + + //if (val>0) { + if ((val>0)&&(val2>0)) { + return; + } + } + + if (node->childs==NULL) { + if (checks>=maxChecks) { + if (result.full()) return; + } + checks += node->size; + for (int i=0; isize; ++i) { + int index = node->indices[i]; + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result.addPoint(dist, index); + } + } + else { + DistanceType* domain_distances = new DistanceType[branching_]; + int closest_center = exploreNodeBranches(node, vec, domain_distances, heap); + delete[] domain_distances; + findNN(node->childs[closest_center],result,vec, checks, maxChecks, heap); + } + } + + /** + * Helper function that computes the nearest childs of a node to a given query point. + * Params: + * node = the node + * q = the query point + * distances = array with the distances to each child node. + * Returns: + */ + int exploreNodeBranches(KMeansNodePtr node, const ElementType* q, DistanceType* domain_distances, Heap* heap) + { + + int best_index = 0; + domain_distances[best_index] = distance_(q, node->childs[best_index]->pivot, veclen_); + for (int i=1; ichilds[i]->pivot, veclen_); + if (domain_distances[i]childs[best_index]->pivot; + for (int i=0; ichilds[i]->variance; + + // float dist_to_border = getDistanceToBorder(node.childs[i].pivot,best_center,q); + // if (domain_distances[i]insert(BranchSt(node->childs[i],domain_distances[i])); + } + } + + return best_index; + } + + + /** + * Function the performs exact nearest neighbor search by traversing the entire tree. + */ + void findExactNN(KMeansNodePtr node, ResultSet& result, const ElementType* vec) + { + // Ignore those clusters that are too far away + { + DistanceType bsq = distance_(vec, node->pivot, veclen_); + DistanceType rsq = node->radius; + DistanceType wsq = result.worstDist(); + + DistanceType val = bsq-rsq-wsq; + DistanceType val2 = val*val-4*rsq*wsq; + + // if (val>0) { + if ((val>0)&&(val2>0)) { + return; + } + } + + + if (node->childs==NULL) { + for (int i=0; isize; ++i) { + int index = node->indices[i]; + DistanceType dist = distance_(dataset_[index], vec, veclen_); + result.addPoint(dist, index); + } + } + else { + int* sort_indices = new int[branching_]; + + getCenterOrdering(node, vec, sort_indices); + + for (int i=0; ichilds[sort_indices[i]],result,vec); + } + + delete[] sort_indices; + } + } + + + /** + * Helper function. + * + * I computes the order in which to traverse the child nodes of a particular node. + */ + void getCenterOrdering(KMeansNodePtr node, const ElementType* q, int* sort_indices) + { + DistanceType* domain_distances = new DistanceType[branching_]; + for (int i=0; ichilds[i]->pivot, veclen_); + + int j=0; + while (domain_distances[j]j; --k) { + domain_distances[k] = domain_distances[k-1]; + sort_indices[k] = sort_indices[k-1]; + } + domain_distances[j] = dist; + sort_indices[j] = i; + } + delete[] domain_distances; + } + + /** + * Method that computes the squared distance from the query point q + * from inside region with center c to the border between this + * region and the region with center p + */ + DistanceType getDistanceToBorder(DistanceType* p, DistanceType* c, DistanceType* q) + { + DistanceType sum = 0; + DistanceType sum2 = 0; + + for (int i=0; ivariance*root->size; + + while (clusterCount::max)(); + int splitIndex = -1; + + for (int i=0; ichilds != NULL) { + + DistanceType variance = meanVariance - clusters[i]->variance*clusters[i]->size; + + for (int j=0; jchilds[j]->variance*clusters[i]->childs[j]->size; + } + if (variance clusters_length) break; + + meanVariance = minVariance; + + // split node + KMeansNodePtr toSplit = clusters[splitIndex]; + clusters[splitIndex] = toSplit->childs[0]; + for (int i=1; ichilds[i]; + } + } + + varianceValue = meanVariance/root->size; + return clusterCount; + } + +private: + /** The branching factor used in the hierarchical k-means clustering */ + int branching_; + + /** Maximum number of iterations to use when performing k-means clustering */ + int iterations_; + + /** Algorithm for choosing the cluster centers */ + flann_centers_init_t centers_init_; + + /** + * Cluster border index. This is used in the tree search phase when determining + * the closest cluster to explore next. A zero value takes into account only + * the cluster centres, a value greater then zero also take into account the size + * of the cluster. + */ + float cb_index_; + + /** + * The dataset used by this index + */ + const Matrix dataset_; + + /** Index parameters */ + IndexParams index_params_; + + /** + * Number of features in the dataset. + */ + size_t size_; + + /** + * Length of each feature. + */ + size_t veclen_; + + /** + * The root node in the tree. + */ + KMeansNodePtr root_; + + /** + * Array of indices to vectors in the dataset. + */ + int* indices_; + + /** + * The distance + */ + Distance distance_; + + /** + * Pooled memory allocator. + */ + PooledAllocator pool_; + + /** + * Memory occupied by the index. + */ + int memoryCounter_; +}; + +} + +//! @endcond + +#endif //OPENCV_FLANN_KMEANS_INDEX_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/linear_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/linear_index.h new file mode 100644 index 0000000000000000000000000000000000000000..8a0f10fd86c8a58ef20937a6800240713d9750c8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/linear_index.h @@ -0,0 +1,136 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_LINEAR_INDEX_H_ +#define OPENCV_FLANN_LINEAR_INDEX_H_ + +//! @cond IGNORED + +#include "general.h" +#include "nn_index.h" + +namespace cvflann +{ + +struct LinearIndexParams : public IndexParams +{ + LinearIndexParams() + { + (* this)["algorithm"] = FLANN_INDEX_LINEAR; + } +}; + +template +class LinearIndex : public NNIndex +{ +public: + + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + + LinearIndex(const Matrix& inputData, const IndexParams& params = LinearIndexParams(), + Distance d = Distance()) : + dataset_(inputData), index_params_(params), distance_(d) + { + } + + LinearIndex(const LinearIndex&); + LinearIndex& operator=(const LinearIndex&); + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_LINEAR; + } + + + size_t size() const CV_OVERRIDE + { + return dataset_.rows; + } + + size_t veclen() const CV_OVERRIDE + { + return dataset_.cols; + } + + + int usedMemory() const CV_OVERRIDE + { + return 0; + } + + void buildIndex() CV_OVERRIDE + { + /* nothing to do here for linear search */ + } + + void saveIndex(FILE*) CV_OVERRIDE + { + /* nothing to do here for linear search */ + } + + + void loadIndex(FILE*) CV_OVERRIDE + { + /* nothing to do here for linear search */ + + index_params_["algorithm"] = getType(); + } + + void findNeighbors(ResultSet& resultSet, const ElementType* vec, const SearchParams& /*searchParams*/) CV_OVERRIDE + { + ElementType* data = dataset_.data; + for (size_t i = 0; i < dataset_.rows; ++i, data += dataset_.cols) { + DistanceType dist = distance_(data, vec, dataset_.cols); + resultSet.addPoint(dist, (int)i); + } + } + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + +private: + /** The dataset */ + const Matrix dataset_; + /** Index parameters */ + IndexParams index_params_; + /** Index distance */ + Distance distance_; + +}; + +} + +//! @endcond + +#endif // OPENCV_FLANN_LINEAR_INDEX_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/logger.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/logger.h new file mode 100644 index 0000000000000000000000000000000000000000..8911812a7744ad7e100de82c2d6782c50bc0c122 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/logger.h @@ -0,0 +1,139 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_LOGGER_H +#define OPENCV_FLANN_LOGGER_H + +//! @cond IGNORED + +#include +#include + +#include "defines.h" + + +namespace cvflann +{ + +class Logger +{ + Logger() : stream(stdout), logLevel(FLANN_LOG_WARN) {} + + ~Logger() + { + if ((stream!=NULL)&&(stream!=stdout)) { + fclose(stream); + } + } + + static Logger& instance() + { + static Logger logger; + return logger; + } + + void _setDestination(const char* name) + { + if (name==NULL) { + stream = stdout; + } + else { +#ifdef _MSC_VER + if (fopen_s(&stream, name, "w") != 0) + stream = NULL; +#else + stream = fopen(name,"w"); +#endif + if (stream == NULL) { + stream = stdout; + } + } + } + + int _log(int level, const char* fmt, va_list arglist) + { + if (level > logLevel ) return -1; + int ret = vfprintf(stream, fmt, arglist); + return ret; + } + +public: + /** + * Sets the logging level. All messages with lower priority will be ignored. + * @param level Logging level + */ + static void setLevel(int level) { instance().logLevel = level; } + + /** + * Sets the logging destination + * @param name Filename or NULL for console + */ + static void setDestination(const char* name) { instance()._setDestination(name); } + + /** + * Print log message + * @param level Log level + * @param fmt Message format + * @return + */ + static int log(int level, const char* fmt, ...) + { + va_list arglist; + va_start(arglist, fmt); + int ret = instance()._log(level,fmt,arglist); + va_end(arglist); + return ret; + } + +#define LOG_METHOD(NAME,LEVEL) \ + static int NAME(const char* fmt, ...) \ + { \ + va_list ap; \ + va_start(ap, fmt); \ + int ret = instance()._log(LEVEL, fmt, ap); \ + va_end(ap); \ + return ret; \ + } + + LOG_METHOD(fatal, FLANN_LOG_FATAL) + LOG_METHOD(error, FLANN_LOG_ERROR) + LOG_METHOD(warn, FLANN_LOG_WARN) + LOG_METHOD(info, FLANN_LOG_INFO) + +private: + FILE* stream; + int logLevel; +}; + +} + +//! @endcond + +#endif //OPENCV_FLANN_LOGGER_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/lsh_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/lsh_index.h new file mode 100644 index 0000000000000000000000000000000000000000..ee620dae3e838fe1bcd0ee8ccb16292a3dabe4a7 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/lsh_index.h @@ -0,0 +1,396 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +/*********************************************************************** + * Author: Vincent Rabaud + *************************************************************************/ + +#ifndef OPENCV_FLANN_LSH_INDEX_H_ +#define OPENCV_FLANN_LSH_INDEX_H_ + +//! @cond IGNORED + +#include +#include +#include +#include +#include + +#include "general.h" +#include "nn_index.h" +#include "matrix.h" +#include "result_set.h" +#include "heap.h" +#include "lsh_table.h" +#include "allocator.h" +#include "random.h" +#include "saving.h" + +namespace cvflann +{ + +struct LshIndexParams : public IndexParams +{ + LshIndexParams(unsigned int table_number = 12, unsigned int key_size = 20, unsigned int multi_probe_level = 2) + { + (* this)["algorithm"] = FLANN_INDEX_LSH; + // The number of hash tables to use + (*this)["table_number"] = table_number; + // The length of the key in the hash tables + (*this)["key_size"] = key_size; + // Number of levels to use in multi-probe (0 for standard LSH) + (*this)["multi_probe_level"] = multi_probe_level; + } +}; + +/** + * Randomized kd-tree index + * + * Contains the k-d trees and other information for indexing a set of points + * for nearest-neighbor matching. + */ +template +class LshIndex : public NNIndex +{ +public: + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + + /** Constructor + * @param input_data dataset with the input features + * @param params parameters passed to the LSH algorithm + * @param d the distance used + */ + LshIndex(const Matrix& input_data, const IndexParams& params = LshIndexParams(), + Distance d = Distance()) : + dataset_(input_data), index_params_(params), distance_(d) + { + // cv::flann::IndexParams sets integer params as 'int', so it is used with get_param + // in place of 'unsigned int' + table_number_ = (unsigned int)get_param(index_params_,"table_number",12); + key_size_ = (unsigned int)get_param(index_params_,"key_size",20); + multi_probe_level_ = (unsigned int)get_param(index_params_,"multi_probe_level",2); + + feature_size_ = (unsigned)dataset_.cols; + fill_xor_mask(0, key_size_, multi_probe_level_, xor_masks_); + } + + + LshIndex(const LshIndex&); + LshIndex& operator=(const LshIndex&); + + /** + * Builds the index + */ + void buildIndex() CV_OVERRIDE + { + tables_.resize(table_number_); + for (unsigned int i = 0; i < table_number_; ++i) { + lsh::LshTable& table = tables_[i]; + table = lsh::LshTable(feature_size_, key_size_); + + // Add the features to the table + table.add(dataset_); + } + } + + flann_algorithm_t getType() const CV_OVERRIDE + { + return FLANN_INDEX_LSH; + } + + + void saveIndex(FILE* stream) CV_OVERRIDE + { + save_value(stream,table_number_); + save_value(stream,key_size_); + save_value(stream,multi_probe_level_); + save_value(stream, dataset_); + } + + void loadIndex(FILE* stream) CV_OVERRIDE + { + load_value(stream, table_number_); + load_value(stream, key_size_); + load_value(stream, multi_probe_level_); + load_value(stream, dataset_); + // Building the index is so fast we can afford not storing it + buildIndex(); + + index_params_["algorithm"] = getType(); + index_params_["table_number"] = table_number_; + index_params_["key_size"] = key_size_; + index_params_["multi_probe_level"] = multi_probe_level_; + } + + /** + * Returns size of index. + */ + size_t size() const CV_OVERRIDE + { + return dataset_.rows; + } + + /** + * Returns the length of an index feature. + */ + size_t veclen() const CV_OVERRIDE + { + return feature_size_; + } + + /** + * Computes the index memory usage + * Returns: memory used by the index + */ + int usedMemory() const CV_OVERRIDE + { + return (int)(dataset_.rows * sizeof(int)); + } + + + IndexParams getParameters() const CV_OVERRIDE + { + return index_params_; + } + + /** + * \brief Perform k-nearest neighbor search + * \param[in] queries The query points for which to find the nearest neighbors + * \param[out] indices The indices of the nearest neighbors found + * \param[out] dists Distances to the nearest neighbors found + * \param[in] knn Number of nearest neighbors to return + * \param[in] params Search parameters + */ + virtual void knnSearch(const Matrix& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) CV_OVERRIDE + { + assert(queries.cols == veclen()); + assert(indices.rows >= queries.rows); + assert(dists.rows >= queries.rows); + assert(int(indices.cols) >= knn); + assert(int(dists.cols) >= knn); + + + KNNUniqueResultSet resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.clear(); + std::fill_n(indices[i], knn, -1); + std::fill_n(dists[i], knn, std::numeric_limits::max()); + findNeighbors(resultSet, queries[i], params); + if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices[i], dists[i], knn); + else resultSet.copy(indices[i], dists[i], knn); + } + } + + + /** + * Find set of nearest neighbors to vec. Their indices are stored inside + * the result object. + * + * Params: + * result = the result object in which the indices of the nearest-neighbors are stored + * vec = the vector for which to search the nearest neighbors + * maxCheck = the maximum number of restarts (in a best-bin-first manner) + */ + void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& /*searchParams*/) CV_OVERRIDE + { + getNeighbors(vec, result); + } + +private: + /** Defines the comparator on score and index + */ + typedef std::pair ScoreIndexPair; + struct SortScoreIndexPairOnSecond + { + bool operator()(const ScoreIndexPair& left, const ScoreIndexPair& right) const + { + return left.second < right.second; + } + }; + + /** Fills the different xor masks to use when getting the neighbors in multi-probe LSH + * @param key the key we build neighbors from + * @param lowest_index the lowest index of the bit set + * @param level the multi-probe level we are at + * @param xor_masks all the xor mask + */ + void fill_xor_mask(lsh::BucketKey key, int lowest_index, unsigned int level, + std::vector& xor_masks) + { + xor_masks.push_back(key); + if (level == 0) return; + for (int index = lowest_index - 1; index >= 0; --index) { + // Create a new key + lsh::BucketKey new_key = key | (1 << index); + fill_xor_mask(new_key, index, level - 1, xor_masks); + } + } + + /** Performs the approximate nearest-neighbor search. + * @param vec the feature to analyze + * @param do_radius flag indicating if we check the radius too + * @param radius the radius if it is a radius search + * @param do_k flag indicating if we limit the number of nn + * @param k_nn the number of nearest neighbors + * @param checked_average used for debugging + */ + void getNeighbors(const ElementType* vec, bool /*do_radius*/, float radius, bool do_k, unsigned int k_nn, + float& /*checked_average*/) + { + static std::vector score_index_heap; + + if (do_k) { + unsigned int worst_score = std::numeric_limits::max(); + typename std::vector >::const_iterator table = tables_.begin(); + typename std::vector >::const_iterator table_end = tables_.end(); + for (; table != table_end; ++table) { + size_t key = table->getKey(vec); + std::vector::const_iterator xor_mask = xor_masks_.begin(); + std::vector::const_iterator xor_mask_end = xor_masks_.end(); + for (; xor_mask != xor_mask_end; ++xor_mask) { + size_t sub_key = key ^ (*xor_mask); + const lsh::Bucket* bucket = table->getBucketFromKey(sub_key); + if (bucket == 0) continue; + + // Go over each descriptor index + std::vector::const_iterator training_index = bucket->begin(); + std::vector::const_iterator last_training_index = bucket->end(); + DistanceType hamming_distance; + + // Process the rest of the candidates + for (; training_index < last_training_index; ++training_index) { + hamming_distance = distance_(vec, dataset_[*training_index], dataset_.cols); + + if (hamming_distance < worst_score) { + // Insert the new element + score_index_heap.push_back(ScoreIndexPair(hamming_distance, training_index)); + std::push_heap(score_index_heap.begin(), score_index_heap.end()); + + if (score_index_heap.size() > (unsigned int)k_nn) { + // Remove the highest distance value as we have too many elements + std::pop_heap(score_index_heap.begin(), score_index_heap.end()); + score_index_heap.pop_back(); + // Keep track of the worst score + worst_score = score_index_heap.front().first; + } + } + } + } + } + } + else { + typename std::vector >::const_iterator table = tables_.begin(); + typename std::vector >::const_iterator table_end = tables_.end(); + for (; table != table_end; ++table) { + size_t key = table->getKey(vec); + std::vector::const_iterator xor_mask = xor_masks_.begin(); + std::vector::const_iterator xor_mask_end = xor_masks_.end(); + for (; xor_mask != xor_mask_end; ++xor_mask) { + size_t sub_key = key ^ (*xor_mask); + const lsh::Bucket* bucket = table->getBucketFromKey(sub_key); + if (bucket == 0) continue; + + // Go over each descriptor index + std::vector::const_iterator training_index = bucket->begin(); + std::vector::const_iterator last_training_index = bucket->end(); + DistanceType hamming_distance; + + // Process the rest of the candidates + for (; training_index < last_training_index; ++training_index) { + // Compute the Hamming distance + hamming_distance = distance_(vec, dataset_[*training_index], dataset_.cols); + if (hamming_distance < radius) score_index_heap.push_back(ScoreIndexPair(hamming_distance, training_index)); + } + } + } + } + } + + /** Performs the approximate nearest-neighbor search. + * This is a slower version than the above as it uses the ResultSet + * @param vec the feature to analyze + */ + void getNeighbors(const ElementType* vec, ResultSet& result) + { + typename std::vector >::const_iterator table = tables_.begin(); + typename std::vector >::const_iterator table_end = tables_.end(); + for (; table != table_end; ++table) { + size_t key = table->getKey(vec); + std::vector::const_iterator xor_mask = xor_masks_.begin(); + std::vector::const_iterator xor_mask_end = xor_masks_.end(); + for (; xor_mask != xor_mask_end; ++xor_mask) { + size_t sub_key = key ^ (*xor_mask); + const lsh::Bucket* bucket = table->getBucketFromKey((lsh::BucketKey)sub_key); + if (bucket == 0) continue; + + // Go over each descriptor index + std::vector::const_iterator training_index = bucket->begin(); + std::vector::const_iterator last_training_index = bucket->end(); + DistanceType hamming_distance; + + // Process the rest of the candidates + for (; training_index < last_training_index; ++training_index) { + // Compute the Hamming distance + hamming_distance = distance_(vec, dataset_[*training_index], (int)dataset_.cols); + result.addPoint(hamming_distance, *training_index); + } + } + } + } + + /** The different hash tables */ + std::vector > tables_; + + /** The data the LSH tables where built from */ + Matrix dataset_; + + /** The size of the features (as ElementType[]) */ + unsigned int feature_size_; + + IndexParams index_params_; + + /** table number */ + unsigned int table_number_; + /** key size */ + unsigned int key_size_; + /** How far should we look for neighbors in multi-probe LSH */ + unsigned int multi_probe_level_; + + /** The XOR masks to apply to a key to get the neighboring buckets */ + std::vector xor_masks_; + + Distance distance_; +}; +} + +//! @endcond + +#endif //OPENCV_FLANN_LSH_INDEX_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/lsh_table.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/lsh_table.h new file mode 100644 index 0000000000000000000000000000000000000000..db8b5af946789ce7d0e20885129cb658f11045b8 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/lsh_table.h @@ -0,0 +1,517 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +/*********************************************************************** + * Author: Vincent Rabaud + *************************************************************************/ + +#ifndef OPENCV_FLANN_LSH_TABLE_H_ +#define OPENCV_FLANN_LSH_TABLE_H_ + +//! @cond IGNORED + +#include +#include +#include +#include +// TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP +#ifdef __GXX_EXPERIMENTAL_CXX0X__ +# define USE_UNORDERED_MAP 1 +#else +# define USE_UNORDERED_MAP 0 +#endif +#if USE_UNORDERED_MAP +#include +#else +#include +#endif +#include +#include + +#include "dynamic_bitset.h" +#include "matrix.h" + +namespace cvflann +{ + +namespace lsh +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** What is stored in an LSH bucket + */ +typedef uint32_t FeatureIndex; +/** The id from which we can get a bucket back in an LSH table + */ +typedef unsigned int BucketKey; + +/** A bucket in an LSH table + */ +typedef std::vector Bucket; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** POD for stats about an LSH table + */ +struct LshStats +{ + std::vector bucket_sizes_; + size_t n_buckets_; + size_t bucket_size_mean_; + size_t bucket_size_median_; + size_t bucket_size_min_; + size_t bucket_size_max_; + size_t bucket_size_std_dev; + /** Each contained vector contains three value: beginning/end for interval, number of elements in the bin + */ + std::vector > size_histogram_; +}; + +/** Overload the << operator for LshStats + * @param out the streams + * @param stats the stats to display + * @return the streams + */ +inline std::ostream& operator <<(std::ostream& out, const LshStats& stats) +{ + int w = 20; + out << "Lsh Table Stats:\n" << std::setw(w) << std::setiosflags(std::ios::right) << "N buckets : " + << stats.n_buckets_ << "\n" << std::setw(w) << std::setiosflags(std::ios::right) << "mean size : " + << std::setiosflags(std::ios::left) << stats.bucket_size_mean_ << "\n" << std::setw(w) + << std::setiosflags(std::ios::right) << "median size : " << stats.bucket_size_median_ << "\n" << std::setw(w) + << std::setiosflags(std::ios::right) << "min size : " << std::setiosflags(std::ios::left) + << stats.bucket_size_min_ << "\n" << std::setw(w) << std::setiosflags(std::ios::right) << "max size : " + << std::setiosflags(std::ios::left) << stats.bucket_size_max_; + + // Display the histogram + out << std::endl << std::setw(w) << std::setiosflags(std::ios::right) << "histogram : " + << std::setiosflags(std::ios::left); + for (std::vector >::const_iterator iterator = stats.size_histogram_.begin(), end = + stats.size_histogram_.end(); iterator != end; ++iterator) out << (*iterator)[0] << "-" << (*iterator)[1] << ": " << (*iterator)[2] << ", "; + + return out; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Lsh hash table. As its key is a sub-feature, and as usually + * the size of it is pretty small, we keep it as a continuous memory array. + * The value is an index in the corpus of features (we keep it as an unsigned + * int for pure memory reasons, it could be a size_t) + */ +template +class LshTable +{ +public: + /** A container of all the feature indices. Optimized for space + */ +#if USE_UNORDERED_MAP + typedef std::unordered_map BucketsSpace; +#else + typedef std::map BucketsSpace; +#endif + + /** A container of all the feature indices. Optimized for speed + */ + typedef std::vector BucketsSpeed; + + /** Default constructor + */ + LshTable() + { + key_size_ = 0; + feature_size_ = 0; + speed_level_ = kArray; + } + + /** Default constructor + * Create the mask and allocate the memory + * @param feature_size is the size of the feature (considered as a ElementType[]) + * @param key_size is the number of bits that are turned on in the feature + */ + LshTable(unsigned int feature_size, unsigned int key_size) + { + feature_size_ = feature_size; + CV_UNUSED(key_size); + std::cerr << "LSH is not implemented for that type" << std::endl; + assert(0); + } + + /** Add a feature to the table + * @param value the value to store for that feature + * @param feature the feature itself + */ + void add(unsigned int value, const ElementType* feature) + { + // Add the value to the corresponding bucket + BucketKey key = (lsh::BucketKey)getKey(feature); + + switch (speed_level_) { + case kArray: + // That means we get the buckets from an array + buckets_speed_[key].push_back(value); + break; + case kBitsetHash: + // That means we can check the bitset for the presence of a key + key_bitset_.set(key); + buckets_space_[key].push_back(value); + break; + case kHash: + { + // That means we have to check for the hash table for the presence of a key + buckets_space_[key].push_back(value); + break; + } + } + } + + /** Add a set of features to the table + * @param dataset the values to store + */ + void add(Matrix dataset) + { +#if USE_UNORDERED_MAP + buckets_space_.rehash((buckets_space_.size() + dataset.rows) * 1.2); +#endif + // Add the features to the table + for (unsigned int i = 0; i < dataset.rows; ++i) add(i, dataset[i]); + // Now that the table is full, optimize it for speed/space + optimize(); + } + + /** Get a bucket given the key + * @param key + * @return + */ + inline const Bucket* getBucketFromKey(BucketKey key) const + { + // Generate other buckets + switch (speed_level_) { + case kArray: + // That means we get the buckets from an array + return &buckets_speed_[key]; + break; + case kBitsetHash: + // That means we can check the bitset for the presence of a key + if (key_bitset_.test(key)) return &buckets_space_.find(key)->second; + else return 0; + break; + case kHash: + { + // That means we have to check for the hash table for the presence of a key + BucketsSpace::const_iterator bucket_it, bucket_end = buckets_space_.end(); + bucket_it = buckets_space_.find(key); + // Stop here if that bucket does not exist + if (bucket_it == bucket_end) return 0; + else return &bucket_it->second; + break; + } + } + return 0; + } + + /** Compute the sub-signature of a feature + */ + size_t getKey(const ElementType* /*feature*/) const + { + std::cerr << "LSH is not implemented for that type" << std::endl; + assert(0); + return 1; + } + + /** Get statistics about the table + * @return + */ + LshStats getStats() const; + +private: + /** defines the speed fo the implementation + * kArray uses a vector for storing data + * kBitsetHash uses a hash map but checks for the validity of a key with a bitset + * kHash uses a hash map only + */ + enum SpeedLevel + { + kArray, kBitsetHash, kHash + }; + + /** Initialize some variables + */ + void initialize(size_t key_size) + { + const size_t key_size_lower_bound = 1; + //a value (size_t(1) << key_size) must fit the size_t type so key_size has to be strictly less than size of size_t + const size_t key_size_upper_bound = (std::min)(sizeof(BucketKey) * CHAR_BIT + 1, sizeof(size_t) * CHAR_BIT); + if (key_size < key_size_lower_bound || key_size >= key_size_upper_bound) + { + CV_Error(cv::Error::StsBadArg, cv::format("Invalid key_size (=%d). Valid values for your system are %d <= key_size < %d.", (int)key_size, (int)key_size_lower_bound, (int)key_size_upper_bound)); + } + + speed_level_ = kHash; + key_size_ = (unsigned)key_size; + } + + /** Optimize the table for speed/space + */ + void optimize() + { + // If we are already using the fast storage, no need to do anything + if (speed_level_ == kArray) return; + + // Use an array if it will be more than half full + if (buckets_space_.size() > ((size_t(1) << key_size_) / 2)) { + speed_level_ = kArray; + // Fill the array version of it + buckets_speed_.resize(size_t(1) << key_size_); + for (BucketsSpace::const_iterator key_bucket = buckets_space_.begin(); key_bucket != buckets_space_.end(); ++key_bucket) buckets_speed_[key_bucket->first] = key_bucket->second; + + // Empty the hash table + buckets_space_.clear(); + return; + } + + // If the bitset is going to use less than 10% of the RAM of the hash map (at least 1 size_t for the key and two + // for the vector) or less than 512MB (key_size_ <= 30) + if (((std::max(buckets_space_.size(), buckets_speed_.size()) * CHAR_BIT * 3 * sizeof(BucketKey)) / 10 + >= (size_t(1) << key_size_)) || (key_size_ <= 32)) { + speed_level_ = kBitsetHash; + key_bitset_.resize(size_t(1) << key_size_); + key_bitset_.reset(); + // Try with the BucketsSpace + for (BucketsSpace::const_iterator key_bucket = buckets_space_.begin(); key_bucket != buckets_space_.end(); ++key_bucket) key_bitset_.set(key_bucket->first); + } + else { + speed_level_ = kHash; + key_bitset_.clear(); + } + } + + /** The vector of all the buckets if they are held for speed + */ + BucketsSpeed buckets_speed_; + + /** The hash table of all the buckets in case we cannot use the speed version + */ + BucketsSpace buckets_space_; + + /** What is used to store the data */ + SpeedLevel speed_level_; + + /** If the subkey is small enough, it will keep track of which subkeys are set through that bitset + * That is just a speedup so that we don't look in the hash table (which can be mush slower that checking a bitset) + */ + DynamicBitset key_bitset_; + + /** The size of the sub-signature in bits + */ + unsigned int key_size_; + + unsigned int feature_size_; + + // Members only used for the unsigned char specialization + /** The mask to apply to a feature to get the hash key + * Only used in the unsigned char case + */ + std::vector mask_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Specialization for unsigned char + +template<> +inline LshTable::LshTable(unsigned int feature_size, unsigned int subsignature_size) +{ + feature_size_ = feature_size; + initialize(subsignature_size); + // Allocate the mask + mask_ = std::vector((feature_size * sizeof(char) + sizeof(size_t) - 1) / sizeof(size_t), 0); + + // A bit brutal but fast to code + std::vector indices(feature_size * CHAR_BIT); + for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = (int)i; +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(indices); +#else + std::random_shuffle(indices.begin(), indices.end()); +#endif + + // Generate a random set of order of subsignature_size_ bits + for (unsigned int i = 0; i < key_size_; ++i) { + size_t index = indices[i]; + + // Set that bit in the mask + size_t divisor = CHAR_BIT * sizeof(size_t); + size_t idx = index / divisor; //pick the right size_t index + mask_[idx] |= size_t(1) << (index % divisor); //use modulo to find the bit offset + } + + // Set to 1 if you want to display the mask for debug +#if 0 + { + size_t bcount = 0; + BOOST_FOREACH(size_t mask_block, mask_){ + out << std::setw(sizeof(size_t) * CHAR_BIT / 4) << std::setfill('0') << std::hex << mask_block + << std::endl; + bcount += __builtin_popcountll(mask_block); + } + out << "bit count : " << std::dec << bcount << std::endl; + out << "mask size : " << mask_.size() << std::endl; + return out; + } +#endif +} + +/** Return the Subsignature of a feature + * @param feature the feature to analyze + */ +template<> +inline size_t LshTable::getKey(const unsigned char* feature) const +{ + // no need to check if T is dividable by sizeof(size_t) like in the Hamming + // distance computation as we have a mask + // FIXIT: This is bad assumption, because we reading tail bytes after of the allocated features buffer + const size_t* feature_block_ptr = reinterpret_cast ((const void*)feature); + + // Figure out the subsignature of the feature + // Given the feature ABCDEF, and the mask 001011, the output will be + // 000CEF + size_t subsignature = 0; + size_t bit_index = 1; + + for (unsigned i = 0; i < feature_size_; i += sizeof(size_t)) { + // get the mask and signature blocks + size_t feature_block; + if (i <= feature_size_ - sizeof(size_t)) + { + feature_block = *feature_block_ptr; + } + else + { + size_t tmp = 0; + memcpy(&tmp, feature_block_ptr, feature_size_ - i); // preserve bytes order + feature_block = tmp; + } + size_t mask_block = mask_[i / sizeof(size_t)]; + while (mask_block) { + // Get the lowest set bit in the mask block + size_t lowest_bit = mask_block & (-(ptrdiff_t)mask_block); + // Add it to the current subsignature if necessary + subsignature += (feature_block & lowest_bit) ? bit_index : 0; + // Reset the bit in the mask block + mask_block ^= lowest_bit; + // increment the bit index for the subsignature + bit_index <<= 1; + } + // Check the next feature block + ++feature_block_ptr; + } + return subsignature; +} + +template<> +inline LshStats LshTable::getStats() const +{ + LshStats stats; + stats.bucket_size_mean_ = 0; + if ((buckets_speed_.empty()) && (buckets_space_.empty())) { + stats.n_buckets_ = 0; + stats.bucket_size_median_ = 0; + stats.bucket_size_min_ = 0; + stats.bucket_size_max_ = 0; + return stats; + } + + if (!buckets_speed_.empty()) { + for (BucketsSpeed::const_iterator pbucket = buckets_speed_.begin(); pbucket != buckets_speed_.end(); ++pbucket) { + stats.bucket_sizes_.push_back((lsh::FeatureIndex)pbucket->size()); + stats.bucket_size_mean_ += pbucket->size(); + } + stats.bucket_size_mean_ /= buckets_speed_.size(); + stats.n_buckets_ = buckets_speed_.size(); + } + else { + for (BucketsSpace::const_iterator x = buckets_space_.begin(); x != buckets_space_.end(); ++x) { + stats.bucket_sizes_.push_back((lsh::FeatureIndex)x->second.size()); + stats.bucket_size_mean_ += x->second.size(); + } + stats.bucket_size_mean_ /= buckets_space_.size(); + stats.n_buckets_ = buckets_space_.size(); + } + + std::sort(stats.bucket_sizes_.begin(), stats.bucket_sizes_.end()); + + // BOOST_FOREACH(int size, stats.bucket_sizes_) + // std::cout << size << " "; + // std::cout << std::endl; + stats.bucket_size_median_ = stats.bucket_sizes_[stats.bucket_sizes_.size() / 2]; + stats.bucket_size_min_ = stats.bucket_sizes_.front(); + stats.bucket_size_max_ = stats.bucket_sizes_.back(); + + // TODO compute mean and std + /*float mean, stddev; + stats.bucket_size_mean_ = mean; + stats.bucket_size_std_dev = stddev;*/ + + // Include a histogram of the buckets + unsigned int bin_start = 0; + unsigned int bin_end = 20; + bool is_new_bin = true; + for (std::vector::iterator iterator = stats.bucket_sizes_.begin(), end = stats.bucket_sizes_.end(); iterator + != end; ) + if (*iterator < bin_end) { + if (is_new_bin) { + stats.size_histogram_.push_back(std::vector(3, 0)); + stats.size_histogram_.back()[0] = bin_start; + stats.size_histogram_.back()[1] = bin_end - 1; + is_new_bin = false; + } + ++stats.size_histogram_.back()[2]; + ++iterator; + } + else { + bin_start += 20; + bin_end += 20; + is_new_bin = true; + } + + return stats; +} + +// End the two namespaces +} +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +//! @endcond + +#endif /* OPENCV_FLANN_LSH_TABLE_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/matrix.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/matrix.h new file mode 100644 index 0000000000000000000000000000000000000000..34893b72c3e99bf206ebaea42687ec4ef4259e29 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/matrix.h @@ -0,0 +1,120 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_DATASET_H_ +#define OPENCV_FLANN_DATASET_H_ + +//! @cond IGNORED + +#include + +#include "general.h" + +namespace cvflann +{ + +/** + * Class that implements a simple rectangular matrix stored in a memory buffer and + * provides convenient matrix-like access using the [] operators. + */ +template +class Matrix +{ +public: + typedef T type; + + size_t rows; + size_t cols; + size_t stride; + T* data; + + Matrix() : rows(0), cols(0), stride(0), data(NULL) + { + } + + Matrix(T* data_, size_t rows_, size_t cols_, size_t stride_ = 0) : + rows(rows_), cols(cols_), stride(stride_), data(data_) + { + if (stride==0) stride = cols; + } + + /** + * Convenience function for deallocating the storage data. + */ + CV_DEPRECATED void free() + { + fprintf(stderr, "The cvflann::Matrix::free() method is deprecated " + "and it does not do any memory deallocation any more. You are" + "responsible for deallocating the matrix memory (by doing" + "'delete[] matrix.data' for example)"); + } + + /** + * Operator that return a (pointer to a) row of the data. + */ + T* operator[](size_t index) const + { + return data+index*stride; + } +}; + + +class UntypedMatrix +{ +public: + size_t rows; + size_t cols; + void* data; + flann_datatype_t type; + + UntypedMatrix(void* data_, long rows_, long cols_) : + rows(rows_), cols(cols_), data(data_) + { + } + + ~UntypedMatrix() + { + } + + + template + Matrix as() + { + return Matrix((T*)data, rows, cols); + } +}; + + + +} + +//! @endcond + +#endif //OPENCV_FLANN_DATASET_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/miniflann.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/miniflann.hpp new file mode 100644 index 0000000000000000000000000000000000000000..253290790ea6079a4077821687515d94fc052639 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/miniflann.hpp @@ -0,0 +1,181 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_MINIFLANN_HPP +#define OPENCV_MINIFLANN_HPP + +//! @cond IGNORED + +#include "opencv2/core.hpp" +#include "opencv2/flann/defines.h" + +namespace cv +{ + +namespace flann +{ + +enum FlannIndexType { + FLANN_INDEX_TYPE_8U = CV_8U, + FLANN_INDEX_TYPE_8S = CV_8S, + FLANN_INDEX_TYPE_16U = CV_16U, + FLANN_INDEX_TYPE_16S = CV_16S, + FLANN_INDEX_TYPE_32S = CV_32S, + FLANN_INDEX_TYPE_32F = CV_32F, + FLANN_INDEX_TYPE_64F = CV_64F, + FLANN_INDEX_TYPE_STRING, + FLANN_INDEX_TYPE_BOOL, + FLANN_INDEX_TYPE_ALGORITHM, + LAST_VALUE_FLANN_INDEX_TYPE = FLANN_INDEX_TYPE_ALGORITHM +}; + +struct CV_EXPORTS IndexParams +{ + IndexParams(); + ~IndexParams(); + + String getString(const String& key, const String& defaultVal=String()) const; + int getInt(const String& key, int defaultVal=-1) const; + double getDouble(const String& key, double defaultVal=-1) const; + + void setString(const String& key, const String& value); + void setInt(const String& key, int value); + void setDouble(const String& key, double value); + void setFloat(const String& key, float value); + void setBool(const String& key, bool value); + void setAlgorithm(int value); + + // FIXIT: replace by void write(FileStorage& fs) const + read() + void getAll(std::vector& names, + std::vector& types, + std::vector& strValues, + std::vector& numValues) const; + + void* params; + +private: + IndexParams(const IndexParams &); // copy disabled + IndexParams& operator=(const IndexParams &); // assign disabled +}; + +struct CV_EXPORTS KDTreeIndexParams : public IndexParams +{ + KDTreeIndexParams(int trees=4); +}; + +struct CV_EXPORTS LinearIndexParams : public IndexParams +{ + LinearIndexParams(); +}; + +struct CV_EXPORTS CompositeIndexParams : public IndexParams +{ + CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11, + cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2f ); +}; + +struct CV_EXPORTS AutotunedIndexParams : public IndexParams +{ + AutotunedIndexParams(float target_precision = 0.8f, float build_weight = 0.01f, + float memory_weight = 0, float sample_fraction = 0.1f); +}; + +struct CV_EXPORTS HierarchicalClusteringIndexParams : public IndexParams +{ + HierarchicalClusteringIndexParams(int branching = 32, + cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, int trees = 4, int leaf_size = 100 ); +}; + +struct CV_EXPORTS KMeansIndexParams : public IndexParams +{ + KMeansIndexParams(int branching = 32, int iterations = 11, + cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2f ); +}; + +struct CV_EXPORTS LshIndexParams : public IndexParams +{ + LshIndexParams(int table_number, int key_size, int multi_probe_level); +}; + +struct CV_EXPORTS SavedIndexParams : public IndexParams +{ + SavedIndexParams(const String& filename); +}; + +struct CV_EXPORTS SearchParams : public IndexParams +{ + SearchParams( int checks = 32, float eps = 0, bool sorted = true ); +}; + +class CV_EXPORTS_W Index +{ +public: + CV_WRAP Index(); + CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); + virtual ~Index(); + + CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2); + CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices, + OutputArray dists, int knn, const SearchParams& params=SearchParams()); + + CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices, + OutputArray dists, double radius, int maxResults, + const SearchParams& params=SearchParams()); + + CV_WRAP virtual void save(const String& filename) const; + CV_WRAP virtual bool load(InputArray features, const String& filename); + CV_WRAP virtual void release(); + CV_WRAP cvflann::flann_distance_t getDistance() const; + CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const; + +protected: + cvflann::flann_distance_t distType; + cvflann::flann_algorithm_t algo; + int featureType; + void* index; +}; + +} } // namespace cv::flann + +//! @endcond + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/nn_index.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/nn_index.h new file mode 100644 index 0000000000000000000000000000000000000000..00fe6ec5aebeb4698d7687947495460d16ff54a1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/nn_index.h @@ -0,0 +1,181 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_NNINDEX_H +#define OPENCV_FLANN_NNINDEX_H + +#include "general.h" +#include "matrix.h" +#include "result_set.h" +#include "params.h" + +//! @cond IGNORED + +namespace cvflann +{ + +/** + * Nearest-neighbour index base class + */ +template +class NNIndex +{ + typedef typename Distance::ElementType ElementType; + typedef typename Distance::ResultType DistanceType; + +public: + + virtual ~NNIndex() {} + + /** + * \brief Builds the index + */ + virtual void buildIndex() = 0; + + /** + * \brief Perform k-nearest neighbor search + * \param[in] queries The query points for which to find the nearest neighbors + * \param[out] indices The indices of the nearest neighbors found + * \param[out] dists Distances to the nearest neighbors found + * \param[in] knn Number of nearest neighbors to return + * \param[in] params Search parameters + */ + virtual void knnSearch(const Matrix& queries, Matrix& indices, Matrix& dists, int knn, const SearchParams& params) + { + assert(queries.cols == veclen()); + assert(indices.rows >= queries.rows); + assert(dists.rows >= queries.rows); + assert(int(indices.cols) >= knn); + assert(int(dists.cols) >= knn); + +#if 0 + KNNResultSet resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.init(indices[i], dists[i]); + findNeighbors(resultSet, queries[i], params); + } +#else + KNNUniqueResultSet resultSet(knn); + for (size_t i = 0; i < queries.rows; i++) { + resultSet.clear(); + findNeighbors(resultSet, queries[i], params); + if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices[i], dists[i], knn); + else resultSet.copy(indices[i], dists[i], knn); + } +#endif + } + + /** + * \brief Perform radius search + * \param[in] query The query point + * \param[out] indices The indinces of the neighbors found within the given radius + * \param[out] dists The distances to the nearest neighbors found + * \param[in] radius The radius used for search + * \param[in] params Search parameters + * \returns Number of neighbors found + */ + virtual int radiusSearch(const Matrix& query, Matrix& indices, Matrix& dists, float radius, const SearchParams& params) + { + if (query.rows != 1) { + fprintf(stderr, "I can only search one feature at a time for range search\n"); + return -1; + } + assert(query.cols == veclen()); + assert(indices.cols == dists.cols); + + int n = 0; + int* indices_ptr = NULL; + DistanceType* dists_ptr = NULL; + if (indices.cols > 0) { + n = (int)indices.cols; + indices_ptr = indices[0]; + dists_ptr = dists[0]; + } + + RadiusUniqueResultSet resultSet((DistanceType)radius); + resultSet.clear(); + findNeighbors(resultSet, query[0], params); + if (n>0) { + if (get_param(params,"sorted",true)) resultSet.sortAndCopy(indices_ptr, dists_ptr, n); + else resultSet.copy(indices_ptr, dists_ptr, n); + } + + return (int)resultSet.size(); + } + + /** + * \brief Saves the index to a stream + * \param stream The stream to save the index to + */ + virtual void saveIndex(FILE* stream) = 0; + + /** + * \brief Loads the index from a stream + * \param stream The stream from which the index is loaded + */ + virtual void loadIndex(FILE* stream) = 0; + + /** + * \returns number of features in this index. + */ + virtual size_t size() const = 0; + + /** + * \returns The dimensionality of the features in this index. + */ + virtual size_t veclen() const = 0; + + /** + * \returns The amount of memory (in bytes) used by the index. + */ + virtual int usedMemory() const = 0; + + /** + * \returns The index type (kdtree, kmeans,...) + */ + virtual flann_algorithm_t getType() const = 0; + + /** + * \returns The index parameters + */ + virtual IndexParams getParameters() const = 0; + + + /** + * \brief Method that searches for nearest-neighbours + */ + virtual void findNeighbors(ResultSet& result, const ElementType* vec, const SearchParams& searchParams) = 0; +}; + +} + +//! @endcond + +#endif //OPENCV_FLANN_NNINDEX_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/object_factory.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/object_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..5cc45ad1b34e9d2d666f378d0df6617886f8ea21 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/object_factory.h @@ -0,0 +1,95 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_OBJECT_FACTORY_H_ +#define OPENCV_FLANN_OBJECT_FACTORY_H_ + +//! @cond IGNORED + +#include + +namespace cvflann +{ + +class CreatorNotFound +{ +}; + +template +class ObjectFactory +{ + typedef ObjectFactory ThisClass; + typedef std::map ObjectRegistry; + + // singleton class, private constructor + ObjectFactory() {} + +public: + + bool subscribe(UniqueIdType id, ObjectCreator creator) + { + if (object_registry.find(id) != object_registry.end()) return false; + + object_registry[id] = creator; + return true; + } + + bool unregister(UniqueIdType id) + { + return object_registry.erase(id) == 1; + } + + ObjectCreator create(UniqueIdType id) + { + typename ObjectRegistry::const_iterator iter = object_registry.find(id); + + if (iter == object_registry.end()) { + throw CreatorNotFound(); + } + + return iter->second; + } + + static ThisClass& instance() + { + static ThisClass the_factory; + return the_factory; + } +private: + ObjectRegistry object_registry; +}; + +} + +//! @endcond + +#endif /* OPENCV_FLANN_OBJECT_FACTORY_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/params.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/params.h new file mode 100644 index 0000000000000000000000000000000000000000..b8f7331905543363d0ecaef6ff7922387894d661 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/params.h @@ -0,0 +1,102 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2011 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2011 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_PARAMS_H_ +#define OPENCV_FLANN_PARAMS_H_ + +//! @cond IGNORED + +#include "any.h" +#include "general.h" +#include +#include + + +namespace cvflann +{ + +typedef std::map IndexParams; + +struct SearchParams : public IndexParams +{ + SearchParams(int checks = 32, float eps = 0, bool sorted = true ) + { + // how many leafs to visit when searching for neighbours (-1 for unlimited) + (*this)["checks"] = checks; + // search for eps-approximate neighbours (default: 0) + (*this)["eps"] = eps; + // only for radius search, require neighbours sorted by distance (default: true) + (*this)["sorted"] = sorted; + } +}; + + +template +T get_param(const IndexParams& params, cv::String name, const T& default_value) +{ + IndexParams::const_iterator it = params.find(name); + if (it != params.end()) { + return it->second.cast(); + } + else { + return default_value; + } +} + +template +T get_param(const IndexParams& params, cv::String name) +{ + IndexParams::const_iterator it = params.find(name); + if (it != params.end()) { + return it->second.cast(); + } + else { + throw FLANNException(cv::String("Missing parameter '")+name+cv::String("' in the parameters given")); + } +} + +inline void print_params(const IndexParams& params, std::ostream& stream) +{ + IndexParams::const_iterator it; + + for(it=params.begin(); it!=params.end(); ++it) { + stream << it->first << " : " << it->second << std::endl; + } +} + +inline void print_params(const IndexParams& params) +{ + print_params(params, std::cout); +} + +} + +//! @endcond + +#endif /* OPENCV_FLANN_PARAMS_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/random.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/random.h new file mode 100644 index 0000000000000000000000000000000000000000..3bb48b687bd0d4e3351f6c677570360f11c76273 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/random.h @@ -0,0 +1,159 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_RANDOM_H +#define OPENCV_FLANN_RANDOM_H + +//! @cond IGNORED + +#include +#include +#include + +#include "general.h" + +namespace cvflann +{ + +inline int rand() +{ +#ifndef OPENCV_FLANN_USE_STD_RAND +# if INT_MAX == RAND_MAX + int v = cv::theRNG().next() & INT_MAX; +# else + int v = cv::theRNG().uniform(0, RAND_MAX + 1); +# endif +#else + int v = std::rand(); +#endif // OPENCV_FLANN_USE_STD_RAND + return v; +} + +/** + * Seeds the random number generator + * @param seed Random seed + */ +inline void seed_random(unsigned int seed) +{ +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::theRNG() = cv::RNG(seed); +#else + std::srand(seed); +#endif +} + +/* + * Generates a random double value. + */ +/** + * Generates a random double value. + * @param high Upper limit + * @param low Lower limit + * @return Random double value + */ +inline double rand_double(double high = 1.0, double low = 0) +{ + return low + ((high-low) * (rand() / (RAND_MAX + 1.0))); +} + +/** + * Generates a random integer value. + * @param high Upper limit + * @param low Lower limit + * @return Random integer value + */ +inline int rand_int(int high = RAND_MAX, int low = 0) +{ + return low + (int) ( double(high-low) * (rand() / (RAND_MAX + 1.0))); +} + +/** + * Random number generator that returns a distinct number from + * the [0,n) interval each time. + */ +class UniqueRandom +{ + std::vector vals_; + int size_; + int counter_; + +public: + /** + * Constructor. + * @param n Size of the interval from which to generate + * @return + */ + UniqueRandom(int n) + { + init(n); + } + + /** + * Initializes the number generator. + * @param n the size of the interval from which to generate random numbers. + */ + void init(int n) + { + // create and initialize an array of size n + vals_.resize(n); + size_ = n; + for (int i = 0; i < size_; ++i) vals_[i] = i; + + // shuffle the elements in the array +#ifndef OPENCV_FLANN_USE_STD_RAND + cv::randShuffle(vals_); +#else + std::random_shuffle(vals_.begin(), vals_.end()); +#endif + + counter_ = 0; + } + + /** + * Return a distinct random integer in greater or equal to 0 and less + * than 'n' on each call. It should be called maximum 'n' times. + * Returns: a random integer + */ + int next() + { + if (counter_ == size_) { + return -1; + } + else { + return vals_[counter_++]; + } + } +}; + +} + +//! @endcond + +#endif //OPENCV_FLANN_RANDOM_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/result_set.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/result_set.h new file mode 100644 index 0000000000000000000000000000000000000000..735028fb45e553a56bd57bb9276933b0897d67c2 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/result_set.h @@ -0,0 +1,547 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_RESULTSET_H +#define OPENCV_FLANN_RESULTSET_H + +//! @cond IGNORED + +#include +#include +#include +#include +#include +#include + +namespace cvflann +{ + +/* This record represents a branch point when finding neighbors in + the tree. It contains a record of the minimum distance to the query + point, as well as the node at which the search resumes. + */ + +template +struct BranchStruct +{ + T node; /* Tree node at which search resumes */ + DistanceType mindist; /* Minimum distance to query for all nodes below. */ + + BranchStruct() {} + BranchStruct(const T& aNode, DistanceType dist) : node(aNode), mindist(dist) {} + + bool operator<(const BranchStruct& rhs) const + { + return mindist +class ResultSet +{ +public: + virtual ~ResultSet() {} + + virtual bool full() const = 0; + + virtual void addPoint(DistanceType dist, int index) = 0; + + virtual DistanceType worstDist() const = 0; + +}; + +/** + * KNNSimpleResultSet does not ensure that the element it holds are unique. + * Is used in those cases where the nearest neighbour algorithm used does not + * attempt to insert the same element multiple times. + */ +template +class KNNSimpleResultSet : public ResultSet +{ + int* indices; + DistanceType* dists; + int capacity; + int count; + DistanceType worst_distance_; + +public: + KNNSimpleResultSet(int capacity_) : capacity(capacity_), count(0) + { + } + + void init(int* indices_, DistanceType* dists_) + { + indices = indices_; + dists = dists_; + count = 0; + worst_distance_ = (std::numeric_limits::max)(); + dists[capacity-1] = worst_distance_; + } + + size_t size() const + { + return count; + } + + bool full() const CV_OVERRIDE + { + return count == capacity; + } + + + void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + if (dist >= worst_distance_) return; + int i; + for (i=count; i>0; --i) { +#ifdef FLANN_FIRST_MATCH + if ( (dists[i-1]>dist) || ((dist==dists[i-1])&&(indices[i-1]>index)) ) +#else + if (dists[i-1]>dist) +#endif + { + if (i +class KNNResultSet : public ResultSet +{ + int* indices; + DistanceType* dists; + int capacity; + int count; + DistanceType worst_distance_; + +public: + KNNResultSet(int capacity_) : capacity(capacity_), count(0) + { + } + + void init(int* indices_, DistanceType* dists_) + { + indices = indices_; + dists = dists_; + count = 0; + worst_distance_ = (std::numeric_limits::max)(); + dists[capacity-1] = worst_distance_; + } + + size_t size() const + { + return count; + } + + bool full() const CV_OVERRIDE + { + return count == capacity; + } + + + void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + if (dist >= worst_distance_) return; + int i; + for (i = count; i > 0; --i) { +#ifdef FLANN_FIRST_MATCH + if ( (dists[i-1]<=dist) && ((dist!=dists[i-1])||(indices[i-1]<=index)) ) +#else + if (dists[i-1]<=dist) +#endif + { + // Check for duplicate indices + int j = i - 1; + while ((j >= 0) && (dists[j] == dist)) { + if (indices[j] == index) { + return; + } + --j; + } + break; + } + } + + if (count < capacity) ++count; + for (int j = count-1; j > i; --j) { + dists[j] = dists[j-1]; + indices[j] = indices[j-1]; + } + dists[i] = dist; + indices[i] = index; + worst_distance_ = dists[capacity-1]; + } + + DistanceType worstDist() const CV_OVERRIDE + { + return worst_distance_; + } +}; + + +/** + * A result-set class used when performing a radius based search. + */ +template +class RadiusResultSet : public ResultSet +{ + DistanceType radius; + int* indices; + DistanceType* dists; + size_t capacity; + size_t count; + +public: + RadiusResultSet(DistanceType radius_, int* indices_, DistanceType* dists_, int capacity_) : + radius(radius_), indices(indices_), dists(dists_), capacity(capacity_) + { + init(); + } + + ~RadiusResultSet() + { + } + + void init() + { + count = 0; + } + + size_t size() const + { + return count; + } + + bool full() const + { + return true; + } + + void addPoint(DistanceType dist, int index) + { + if (dist0)&&(count < capacity)) { + dists[count] = dist; + indices[count] = index; + } + count++; + } + } + + DistanceType worstDist() const + { + return radius; + } + +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the k NN neighbors + * Faster than KNNResultSet as it uses a binary heap and does not maintain two arrays + */ +template +class UniqueResultSet : public ResultSet +{ +public: + struct DistIndex + { + DistIndex(DistanceType dist, unsigned int index) : + dist_(dist), index_(index) + { + } + bool operator<(const DistIndex dist_index) const + { + return (dist_ < dist_index.dist_) || ((dist_ == dist_index.dist_) && index_ < dist_index.index_); + } + DistanceType dist_; + unsigned int index_; + }; + + /** Default constructor */ + UniqueResultSet() : + is_full_(false), worst_distance_(std::numeric_limits::max()) + { + } + + /** Check the status of the set + * @return true if we have k NN + */ + inline bool full() const CV_OVERRIDE + { + return is_full_; + } + + /** Remove all elements in the set + */ + virtual void clear() = 0; + + /** Copy the set to two C arrays + * @param indices pointer to a C array of indices + * @param dist pointer to a C array of distances + * @param n_neighbors the number of neighbors to copy + */ + virtual void copy(int* indices, DistanceType* dist, int n_neighbors = -1) const + { + if (n_neighbors < 0) { + for (typename std::set::const_iterator dist_index = dist_indices_.begin(), dist_index_end = + dist_indices_.end(); dist_index != dist_index_end; ++dist_index, ++indices, ++dist) { + *indices = dist_index->index_; + *dist = dist_index->dist_; + } + } + else { + int i = 0; + for (typename std::set::const_iterator dist_index = dist_indices_.begin(), dist_index_end = + dist_indices_.end(); (dist_index != dist_index_end) && (i < n_neighbors); ++dist_index, ++indices, ++dist, ++i) { + *indices = dist_index->index_; + *dist = dist_index->dist_; + } + } + } + + /** Copy the set to two C arrays but sort it according to the distance first + * @param indices pointer to a C array of indices + * @param dist pointer to a C array of distances + * @param n_neighbors the number of neighbors to copy + */ + virtual void sortAndCopy(int* indices, DistanceType* dist, int n_neighbors = -1) const + { + copy(indices, dist, n_neighbors); + } + + /** The number of neighbors in the set + * @return + */ + size_t size() const + { + return dist_indices_.size(); + } + + /** The distance of the furthest neighbor + * If we don't have enough neighbors, it returns the max possible value + * @return + */ + inline DistanceType worstDist() const CV_OVERRIDE + { + return worst_distance_; + } +protected: + /** Flag to say if the set is full */ + bool is_full_; + + /** The worst distance found so far */ + DistanceType worst_distance_; + + /** The best candidates so far */ + std::set dist_indices_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the k NN neighbors + * Faster than KNNResultSet as it uses a binary heap and does not maintain two arrays + */ +template +class KNNUniqueResultSet : public UniqueResultSet +{ +public: + /** Constructor + * @param capacity the number of neighbors to store at max + */ + KNNUniqueResultSet(unsigned int capacity) : capacity_(capacity) + { + this->is_full_ = false; + this->clear(); + } + + /** Add a possible candidate to the best neighbors + * @param dist distance for that neighbor + * @param index index of that neighbor + */ + inline void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + // Don't do anything if we are worse than the worst + if (dist >= worst_distance_) return; + dist_indices_.insert(DistIndex(dist, index)); + + if (is_full_) { + if (dist_indices_.size() > capacity_) { + dist_indices_.erase(*dist_indices_.rbegin()); + worst_distance_ = dist_indices_.rbegin()->dist_; + } + } + else if (dist_indices_.size() == capacity_) { + is_full_ = true; + worst_distance_ = dist_indices_.rbegin()->dist_; + } + } + + /** Remove all elements in the set + */ + void clear() CV_OVERRIDE + { + dist_indices_.clear(); + worst_distance_ = std::numeric_limits::max(); + is_full_ = false; + } + +protected: + typedef typename UniqueResultSet::DistIndex DistIndex; + using UniqueResultSet::is_full_; + using UniqueResultSet::worst_distance_; + using UniqueResultSet::dist_indices_; + + /** The number of neighbors to keep */ + unsigned int capacity_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the radius nearest neighbors + * It is more accurate than RadiusResult as it is not limited in the number of neighbors + */ +template +class RadiusUniqueResultSet : public UniqueResultSet +{ +public: + /** Constructor + * @param radius the maximum distance of a neighbor + */ + RadiusUniqueResultSet(DistanceType radius) : + radius_(radius) + { + is_full_ = true; + } + + /** Add a possible candidate to the best neighbors + * @param dist distance for that neighbor + * @param index index of that neighbor + */ + void addPoint(DistanceType dist, int index) CV_OVERRIDE + { + if (dist <= radius_) dist_indices_.insert(DistIndex(dist, index)); + } + + /** Remove all elements in the set + */ + inline void clear() CV_OVERRIDE + { + dist_indices_.clear(); + } + + + /** Check the status of the set + * @return alwys false + */ + inline bool full() const CV_OVERRIDE + { + return true; + } + + /** The distance of the furthest neighbor + * If we don't have enough neighbors, it returns the max possible value + * @return + */ + inline DistanceType worstDist() const CV_OVERRIDE + { + return radius_; + } +private: + typedef typename UniqueResultSet::DistIndex DistIndex; + using UniqueResultSet::dist_indices_; + using UniqueResultSet::is_full_; + + /** The furthest distance a neighbor can be */ + DistanceType radius_; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** Class that holds the k NN neighbors within a radius distance + */ +template +class KNNRadiusUniqueResultSet : public KNNUniqueResultSet +{ +public: + /** Constructor + * @param capacity the number of neighbors to store at max + * @param radius the maximum distance of a neighbor + */ + KNNRadiusUniqueResultSet(unsigned int capacity, DistanceType radius) + { + this->capacity_ = capacity; + this->radius_ = radius; + this->dist_indices_.reserve(capacity_); + this->clear(); + } + + /** Remove all elements in the set + */ + void clear() + { + dist_indices_.clear(); + worst_distance_ = radius_; + is_full_ = false; + } +private: + using KNNUniqueResultSet::dist_indices_; + using KNNUniqueResultSet::is_full_; + using KNNUniqueResultSet::worst_distance_; + + /** The maximum number of neighbors to consider */ + unsigned int capacity_; + + /** The maximum distance of a neighbor */ + DistanceType radius_; +}; +} + +//! @endcond + +#endif //OPENCV_FLANN_RESULTSET_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/sampling.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/sampling.h new file mode 100644 index 0000000000000000000000000000000000000000..4e452b9bba20e9d98e6cafc1803022a7bfb486a4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/sampling.h @@ -0,0 +1,84 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + + +#ifndef OPENCV_FLANN_SAMPLING_H_ +#define OPENCV_FLANN_SAMPLING_H_ + +//! @cond IGNORED + +#include "matrix.h" +#include "random.h" + +namespace cvflann +{ + +template +Matrix random_sample(Matrix& srcMatrix, long size, bool remove = false) +{ + Matrix newSet(new T[size * srcMatrix.cols], size,srcMatrix.cols); + + T* src,* dest; + for (long i=0; i +Matrix random_sample(const Matrix& srcMatrix, size_t size) +{ + UniqueRandom rand((int)srcMatrix.rows); + Matrix newSet(new T[size * srcMatrix.cols], size,srcMatrix.cols); + + T* src,* dest; + for (size_t i=0; i +#include + +#include "general.h" +#include "nn_index.h" + +#ifdef FLANN_SIGNATURE_ +#undef FLANN_SIGNATURE_ +#endif +#define FLANN_SIGNATURE_ "FLANN_INDEX" + +namespace cvflann +{ + +template +struct Datatype {}; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_INT8; } }; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_INT16; } }; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_INT32; } }; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_UINT8; } }; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_UINT16; } }; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_UINT32; } }; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_FLOAT32; } }; +template<> +struct Datatype { static flann_datatype_t type() { return FLANN_FLOAT64; } }; + + +/** + * Structure representing the index header. + */ +struct IndexHeader +{ + char signature[16]; + char version[16]; + flann_datatype_t data_type; + flann_algorithm_t index_type; + size_t rows; + size_t cols; +}; + +/** + * Saves index header to stream + * + * @param stream - Stream to save to + * @param index - The index to save + */ +template +void save_header(FILE* stream, const NNIndex& index) +{ + IndexHeader header; + memset(header.signature, 0, sizeof(header.signature)); + strcpy(header.signature, FLANN_SIGNATURE_); + memset(header.version, 0, sizeof(header.version)); + strcpy(header.version, FLANN_VERSION_); + header.data_type = Datatype::type(); + header.index_type = index.getType(); + header.rows = index.size(); + header.cols = index.veclen(); + + std::fwrite(&header, sizeof(header),1,stream); +} + + +/** + * + * @param stream - Stream to load from + * @return Index header + */ +inline IndexHeader load_header(FILE* stream) +{ + IndexHeader header; + size_t read_size = fread(&header,sizeof(header),1,stream); + + if (read_size!=(size_t)1) { + throw FLANNException("Invalid index file, cannot read"); + } + + if (strcmp(header.signature,FLANN_SIGNATURE_)!=0) { + throw FLANNException("Invalid index file, wrong signature"); + } + + return header; + +} + + +template +void save_value(FILE* stream, const T& value, size_t count = 1) +{ + fwrite(&value, sizeof(value),count, stream); +} + +template +void save_value(FILE* stream, const cvflann::Matrix& value) +{ + fwrite(&value, sizeof(value),1, stream); + fwrite(value.data, sizeof(T),value.rows*value.cols, stream); +} + +template +void save_value(FILE* stream, const std::vector& value) +{ + size_t size = value.size(); + fwrite(&size, sizeof(size_t), 1, stream); + fwrite(&value[0], sizeof(T), size, stream); +} + +template +void load_value(FILE* stream, T& value, size_t count = 1) +{ + size_t read_cnt = fread(&value, sizeof(value), count, stream); + if (read_cnt != count) { + throw FLANNException("Cannot read from file"); + } +} + +template +void load_value(FILE* stream, cvflann::Matrix& value) +{ + size_t read_cnt = fread(&value, sizeof(value), 1, stream); + if (read_cnt != 1) { + throw FLANNException("Cannot read from file"); + } + value.data = new T[value.rows*value.cols]; + read_cnt = fread(value.data, sizeof(T), value.rows*value.cols, stream); + if (read_cnt != (size_t)(value.rows*value.cols)) { + throw FLANNException("Cannot read from file"); + } +} + + +template +void load_value(FILE* stream, std::vector& value) +{ + size_t size; + size_t read_cnt = fread(&size, sizeof(size_t), 1, stream); + if (read_cnt!=1) { + throw FLANNException("Cannot read from file"); + } + value.resize(size); + read_cnt = fread(&value[0], sizeof(T), size, stream); + if (read_cnt != size) { + throw FLANNException("Cannot read from file"); + } +} + +} + +//! @endcond + +#endif /* OPENCV_FLANN_SAVING_H_ */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/simplex_downhill.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/simplex_downhill.h new file mode 100644 index 0000000000000000000000000000000000000000..9fd84f488cc07782aeda7d2c82fdf90b19d6f28d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/flann/simplex_downhill.h @@ -0,0 +1,190 @@ +/*********************************************************************** + * Software License Agreement (BSD License) + * + * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. + * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. + * + * THE BSD LICENSE + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *************************************************************************/ + +#ifndef OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ +#define OPENCV_FLANN_SIMPLEX_DOWNHILL_H_ + +//! @cond IGNORED + +namespace cvflann +{ + +/** + Adds val to array vals (and point to array points) and keeping the arrays sorted by vals. + */ +template +void addValue(int pos, float val, float* vals, T* point, T* points, int n) +{ + vals[pos] = val; + for (int i=0; i0 && vals[j] +float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL ) +{ + const int MAX_ITERATIONS = 10; + + assert(n>0); + + T* p_o = new T[n]; + T* p_r = new T[n]; + T* p_e = new T[n]; + + int alpha = 1; + + int iterations = 0; + + bool ownVals = false; + if (vals == NULL) { + ownVals = true; + vals = new float[n+1]; + for (int i=0; i MAX_ITERATIONS) break; + + // compute average of simplex points (except the highest point) + for (int j=0; j=vals[0])&&(val_r=vals[n]) { + for (int i=0; i +#include "opencv2/core.hpp" +#include "opencv2/core/utility.hpp" + +namespace cvflann +{ + +/** + * A start-stop timer class. + * + * Can be used to time portions of code. + */ +class StartStopTimer +{ + int64 startTime; + +public: + /** + * Value of the timer. + */ + double value; + + + /** + * Constructor. + */ + StartStopTimer() + { + reset(); + } + + /** + * Starts the timer. + */ + void start() + { + startTime = cv::getTickCount(); + } + + /** + * Stops the timer and updates timer value. + */ + void stop() + { + int64 stopTime = cv::getTickCount(); + value += ( (double)stopTime - startTime) / cv::getTickFrequency(); + } + + /** + * Resets the timer value to 0. + */ + void reset() + { + value = 0; + } + +}; + +} + +//! @endcond + +#endif // FLANN_TIMER_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/freetype.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/freetype.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6e41ec7ff4e4243ac1f123e89a76a2523fdd2017 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/freetype.hpp @@ -0,0 +1,190 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ +//################################################################################ +// +// Created by Kumataro +// +//################################################################################ + +#ifndef _OPENCV_FREETYPE_H_ +#define _OPENCV_FREETYPE_H_ +#ifdef __cplusplus + +#include + +/** +@defgroup freetype Drawing UTF-8 strings with freetype/harfbuzz + +This modules is to draw UTF-8 strings with freetype/harfbuzz. + +1. Install freetype2 and harfbuzz in your system. +2. Create FreeType2 instance with createFreeType2() function. +3. Load font file with loadFontData() function. +4. Draw text with putText() function. + +- If thickness parameter is negative, drawing glyph is filled. +- If thickness parameter is positive, drawing glyph is outlined with thickness. +- If line_type parameter is 16(or CV_AA), drawing glyph is smooth. + +*/ + +namespace cv { +namespace freetype { +//! @addtogroup freetype +//! @{ +class CV_EXPORTS_W FreeType2 : public Algorithm +{ +public: +/** @brief Load font data. + +The function loadFontData loads font data. + +@param fontFileName FontFile Name +@param id face_index to select a font faces in a single file. +*/ + + CV_WRAP virtual void loadFontData(String fontFileName, int id) = 0; + +/** @brief Set Split Number from Bezier-curve to line + +The function setSplitNumber set the number of split points from bezier-curve to line. +If you want to draw large glyph, large is better. +If you want to draw small glyph, small is better. + +@param num number of split points from bezier-curve to line +*/ + + CV_WRAP virtual void setSplitNumber( int num ) = 0; + +/** @brief Draws a text string. + +The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by "Tofu" or non-drawn. + +@param img Image. +@param text Text string to be drawn. +@param org Bottom-left/Top-left corner of the text string in the image. +@param fontHeight Drawing font size by pixel unit. +@param color Text color. +@param thickness Thickness of the lines used to draw a text when negative, the glyph is filled. Otherwise, the glyph is drawn with this thickness. +@param line_type Line type. See the line for details. +@param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner. +*/ + + CV_WRAP virtual void putText( + InputOutputArray img, const String& text, Point org, + int fontHeight, Scalar color, + int thickness, int line_type, bool bottomLeftOrigin + ) = 0; + +/** @brief Calculates the width and height of a text string. + +The function getTextSize calculates and returns the approximate size of a box that contains the specified text. +That is, the following code renders some text, the tight box surrounding it, and the baseline: : +@code + String text = "Funny text inside the box"; + int fontHeight = 60; + int thickness = -1; + int linestyle = 8; + + Mat img(600, 800, CV_8UC3, Scalar::all(0)); + + int baseline=0; + + cv::Ptr ft2; + ft2 = cv::freetype::createFreeType2(); + ft2->loadFontData( "./mplus-1p-regular.ttf", 0 ); + + Size textSize = ft2->getTextSize(text, + fontHeight, + thickness, + &baseline); + + if(thickness > 0){ + baseline += thickness; + } + + // center the text + Point textOrg((img.cols - textSize.width) / 2, + (img.rows + textSize.height) / 2); + + // draw the box + rectangle(img, textOrg + Point(0, baseline), + textOrg + Point(textSize.width, -textSize.height), + Scalar(0,255,0),1,8); + + // ... and the baseline first + line(img, textOrg + Point(0, thickness), + textOrg + Point(textSize.width, thickness), + Scalar(0, 0, 255),1,8); + + // then put the text itself + ft2->putText(img, text, textOrg, fontHeight, + Scalar::all(255), thickness, linestyle, true ); +@endcode + +@param text Input text string. +@param fontHeight Drawing font size by pixel unit. +@param thickness Thickness of lines used to render the text. See putText for details. +@param[out] baseLine y-coordinate of the baseline relative to the bottom-most text +point. +@return The size of a box that contains the specified text. + +@see cv::putText + */ +CV_WRAP virtual Size getTextSize(const String& text, + int fontHeight, int thickness, + CV_OUT int* baseLine) = 0; + +}; + +/** @brief Create FreeType2 Instance + +The function createFreeType2 create instance to draw UTF-8 strings. + +*/ + CV_EXPORTS_W Ptr createFreeType2(); + +//! @} +} } // namespace freetype + +#endif +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d660cc3615c1cf1878df4c607cd1169b4970c7df --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy.hpp @@ -0,0 +1,71 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FUZZY_H__ +#define __OPENCV_FUZZY_H__ + +#include "opencv2/fuzzy/types.hpp" +#include "opencv2/fuzzy/fuzzy_F0_math.hpp" +#include "opencv2/fuzzy/fuzzy_F1_math.hpp" +#include "opencv2/fuzzy/fuzzy_image.hpp" + +/** +@defgroup fuzzy Image processing based on fuzzy mathematics + +Namespace for all functions is `ft`. The module brings implementation of the last image processing algorithms based on fuzzy mathematics. Method are named based on the pattern `FT`_degree_dimension`_`method. + + @{ + @defgroup f0_math Math with F0-transform support + +Fuzzy transform (\f$F^0\f$-transform) of the 0th degree transforms whole image to a matrix of its components. These components are used in latter computation where each of them represents average color of certain subarea. + + @defgroup f1_math Math with F1-transform support + +Fuzzy transform (\f$F^1\f$-transform) of the 1th degree transforms whole image to a matrix of its components. Each component is polynomial of the 1th degree carrying information about average color and average gradient of certain subarea. + + @defgroup f_image Fuzzy image processing + +Image proceesing based on fuzzy mathematics namely F-transform. + @} + +*/ + +#endif // __OPENCV_FUZZY_H__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_F0_math.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_F0_math.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7beeb9bd2f0ba094288941bc2e33448ff79dbaea --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_F0_math.hpp @@ -0,0 +1,121 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FUZZY_F0_MATH_H__ +#define __OPENCV_FUZZY_F0_MATH_H__ + +#include "opencv2/fuzzy/types.hpp" +#include "opencv2/core.hpp" + +namespace cv +{ + +namespace ft +{ + //! @addtogroup f0_math + //! @{ + + /** @brief Computes components of the array using direct \f$F^0\f$-transform. + @param matrix Input array. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param components Output 32-bit float array for the components. + @param mask Mask can be used for unwanted area marking. + + The function computes components using predefined kernel and mask. + */ + CV_EXPORTS_W void FT02D_components(InputArray matrix, InputArray kernel, OutputArray components, InputArray mask = noArray()); + + /** @brief Computes inverse \f$F^0\f$-transfrom. + @param components Input 32-bit float single channel array for the components. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param width Width of the output array. + @param height Height of the output array. + + Computation of inverse F-transform. + */ + CV_EXPORTS_W void FT02D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height); + + /** @brief Computes \f$F^0\f$-transfrom and inverse \f$F^0\f$-transfrom at once. + @param matrix Input matrix. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param mask Mask used for unwanted area marking. + + This function computes F-transfrom and inverse F-transfotm in one step. It is fully sufficient and optimized for `cv::Mat`. + */ + CV_EXPORTS_W void FT02D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray()); + + /** @brief Computes \f$F^0\f$-transfrom and inverse \f$F^0\f$-transfrom at once and return state. + @param matrix Input matrix. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param mask Mask used for unwanted area marking. + @param maskOutput Mask after one iteration. + @param firstStop If **true** function returns -1 when first problem appears. In case of `false` the process is completed and summation of all problems returned. + + This function computes iteration of F-transfrom and inverse F-transfotm and handle image and mask change. The function is used in `ft::inpaint` function. + */ + CV_EXPORTS_W int FT02D_iteration(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask, OutputArray maskOutput, bool firstStop); + + /** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function. + @param matrix Input 3 channels matrix. + @param radius Radius of the `ft::LINEAR` basic function. + @param output Output array. + + This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~10 times faster than `ft::FT02D_process` method. + */ + CV_EXPORTS_W void FT02D_FL_process(InputArray matrix, const int radius, OutputArray output); + + /** @brief Sligtly less accurate version of \f$F^0\f$-transfrom computation optimized for higher speed. The methods counts with linear basic function. + @param matrix Input 3 channels matrix. + @param radius Radius of the `ft::LINEAR` basic function. + @param output Output array. + + This function computes F-transfrom and inverse F-transfotm using linear basic function in one step. It is ~9 times faster then `ft::FT02D_process` method and more accurate than `ft::FT02D_FL_process` method. + */ + CV_EXPORTS_W void FT02D_FL_process_float(InputArray matrix, const int radius, OutputArray output); + + //! @} +} +} + +#endif // __OPENCV_FUZZY_F0_MATH_H__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_F1_math.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_F1_math.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3320e673769dd55ed05b1dbf0aca30ad157037b1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_F1_math.hpp @@ -0,0 +1,124 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FUZZY_F1_MATH_H__ +#define __OPENCV_FUZZY_F1_MATH_H__ + +#include "opencv2/fuzzy/types.hpp" +#include "opencv2/core.hpp" + +namespace cv +{ + +namespace ft +{ + //! @addtogroup f1_math + //! @{ + + /** @brief Computes components of the array using direct \f$F^1\f$-transform. + @param matrix Input array. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param components Output 32-bit float array for the components. + + The function computes linear components using predefined kernel. + */ + CV_EXPORTS_W void FT12D_components(InputArray matrix, InputArray kernel, OutputArray components); + + /** @brief Computes elements of \f$F^1\f$-transform components. + @param matrix Input array. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param c00 Elements represent average color. + @param c10 Elements represent average vertical gradient. + @param c01 Elements represent average horizontal gradient. + @param components Output 32-bit float array for the components. + @param mask Mask can be used for unwanted area marking. + + The function computes components and its elements using predefined kernel and mask. + */ + CV_EXPORTS_W void FT12D_polynomial(InputArray matrix, InputArray kernel, OutputArray c00, OutputArray c10, OutputArray c01, OutputArray components, InputArray mask = noArray()); + + /** @brief Creates vertical matrix for \f$F^1\f$-transform computation. + @param radius Radius of the basic function. + @param matrix The vertical matrix. + @param chn Number of channels. + + The function creates helper vertical matrix for \f$F^1\f$-transfrom processing. It is used for gradient computation. + */ + CV_EXPORTS_W void FT12D_createPolynomMatrixVertical(int radius, OutputArray matrix, const int chn); + + /** @brief Creates horizontal matrix for \f$F^1\f$-transform computation. + @param radius Radius of the basic function. + @param matrix The horizontal matrix. + @param chn Number of channels. + + The function creates helper horizontal matrix for \f$F^1\f$-transfrom processing. It is used for gradient computation. + */ + CV_EXPORTS_W void FT12D_createPolynomMatrixHorizontal(int radius, OutputArray matrix, const int chn); + + /** @brief Computes \f$F^1\f$-transfrom and inverse \f$F^1\f$-transfrom at once. + @param matrix Input matrix. + @param kernel Kernel used for processing. Function `ft::createKernel` can be used. + @param output Output 32-bit float array. + @param mask Mask used for unwanted area marking. + + This function computes \f$F^1\f$-transfrom and inverse \f$F^1\f$-transfotm in one step. It is fully sufficient and optimized for `cv::Mat`. + + @note + F-transform technique of first degreee is described in paper @cite Vlas:FT. + */ + CV_EXPORTS_W void FT12D_process(InputArray matrix, InputArray kernel, OutputArray output, InputArray mask = noArray()); + + /** @brief Computes inverse \f$F^1\f$-transfrom. + @param components Input 32-bit float single channel array for the components. + @param kernel Kernel used for processing. The same kernel as for components computation must be used. + @param output Output 32-bit float array. + @param width Width of the output array. + @param height Height of the output array. + + Computation of inverse \f$F^1\f$-transform. + */ + CV_EXPORTS_W void FT12D_inverseFT(InputArray components, InputArray kernel, OutputArray output, int width, int height); + + //! @} +} +} + +#endif // __OPENCV_FUZZY_F1_MATH_H__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_image.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_image.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9c9eeff3216b1cb56f6b7534cd63660af9f1fbd0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/fuzzy_image.hpp @@ -0,0 +1,109 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FUZZY_IMAGE_H__ +#define __OPENCV_FUZZY_IMAGE_H__ + +#include "types.hpp" +#include "opencv2/core.hpp" + +namespace cv +{ + +namespace ft +{ + //! @addtogroup f_image + //! @{ + + /** @brief Creates kernel from basic functions. + @param A Basic function used in axis **x**. + @param B Basic function used in axis **y**. + @param kernel Final 32-bit kernel derived from **A** and **B**. + @param chn Number of kernel channels. + + The function creates kernel usable for latter fuzzy image processing. + */ + CV_EXPORTS_AS(createKernel1) void createKernel(InputArray A, InputArray B, OutputArray kernel, const int chn); + + /** @brief Creates kernel from general functions. + @param function Function type could be one of the following: + - **LINEAR** Linear basic function. + @param radius Radius of the basic function. + @param kernel Final 32-bit kernel. + @param chn Number of kernel channels. + + The function creates kernel from predefined functions. + */ + CV_EXPORTS_W void createKernel(int function, int radius, OutputArray kernel, const int chn); + + /** @brief Image inpainting + @param image Input image. + @param mask Mask used for unwanted area marking. + @param output Output 32-bit image. + @param radius Radius of the basic function. + @param function Function type could be one of the following: + - `ft::LINEAR` Linear basic function. + @param algorithm Algorithm could be one of the following: + - `ft::ONE_STEP` One step algorithm. + - `ft::MULTI_STEP` This algorithm automaticaly increases radius of the basic function. + - `ft::ITERATIVE` Iterative algorithm running in more steps using partial computations. + + This function provides inpainting technique based on the fuzzy mathematic. + + @note + The algorithms are described in paper @cite Perf:rec. + */ + CV_EXPORTS_W void inpaint(InputArray image, InputArray mask, OutputArray output, int radius, int function, int algorithm); + + /** @brief Image filtering + @param image Input image. + @param kernel Final 32-bit kernel. + @param output Output 32-bit image. + + Filtering of the input image by means of F-transform. + */ + CV_EXPORTS_W void filter(InputArray image, InputArray kernel, OutputArray output); + + //! @} +} +} + +#endif // __OPENCV_FUZZY_IMAGE_H__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/types.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/types.hpp new file mode 100644 index 0000000000000000000000000000000000000000..22e0a0165f769237bfcc088066d60eb38e3d49a6 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/fuzzy/types.hpp @@ -0,0 +1,70 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2015, University of Ostrava, Institute for Research and Applications of Fuzzy Modeling, +// Pavel Vlasanek, all rights reserved. Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef __OPENCV_FUZZY_TYPES_H__ +#define __OPENCV_FUZZY_TYPES_H__ + +namespace cv +{ + +namespace ft +{ + //! @addtogroup fuzzy + //! @{ + + enum + { + LINEAR = 1, //!< linear (triangular) shape + SINUS = 2 //!< sinusoidal shape + }; + + enum + { + ONE_STEP = 1, //!< processing in one step + MULTI_STEP = 2, //!< processing in multiple step + ITERATIVE = 3 //!< processing in several iterations + }; + + //! @} +} +} + +#endif // __OPENCV_FUZZY_TYPES_H__ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2c99c8650d28d13bdcf8b6121bb27079d5423bf1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi.hpp @@ -0,0 +1,33 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_HPP +#define OPENCV_GAPI_HPP + +#include + +/** \defgroup gapi G-API framework +@{ + @defgroup gapi_main_classes G-API Main Classes + @defgroup gapi_data_objects G-API Data Types + @{ + @defgroup gapi_meta_args G-API Metadata Descriptors + @} + @defgroup gapi_std_backends G-API Standard Backends + @defgroup gapi_compile_args G-API Graph Compilation Arguments +@} + */ + +#include +#include +#include +#include +#include +#include +#include + +#endif // OPENCV_GAPI_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..eb6c5dc0d667d034d008fb02ac8997cc6df50ef4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/core.hpp @@ -0,0 +1,1661 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CORE_HPP +#define OPENCV_GAPI_CORE_HPP + +#include + +#include // std::tuple + +#include + +#include +#include +#include + +/** \defgroup gapi_core G-API Core functionality +@{ + @defgroup gapi_math Graph API: Math operations + @defgroup gapi_pixelwise Graph API: Pixelwise operations + @defgroup gapi_matrixop Graph API: Operations on matrices + @defgroup gapi_transform Graph API: Image and channel composition functions +@} + */ +namespace cv { namespace gapi { +namespace core { + using GMat2 = std::tuple; + using GMat3 = std::tuple; // FIXME: how to avoid this? + using GMat4 = std::tuple; + using GMatScalar = std::tuple; + + G_TYPED_KERNEL(GAdd, , "org.opencv.core.math.add") { + static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) { + if (ddepth == -1) + { + // OpenCV: When the input arrays in add/subtract/multiply/divide + // functions have different depths, the output array depth must be + // explicitly specified! + // See artim_op() @ arithm.cpp + GAPI_Assert(a.chan == b.chan); + GAPI_Assert(a.depth == b.depth); + return a; + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GAddC, , "org.opencv.core.math.addC") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSub, , "org.opencv.core.math.sub") { + static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) { + if (ddepth == -1) + { + // This macro should select a larger data depth from a and b + // considering the number of channels in the same + // FIXME!!! Clarify if it is valid for sub() + GAPI_Assert(a.chan == b.chan); + ddepth = std::max(a.depth, b.depth); + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSubC, , "org.opencv.core.math.subC") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSubRC,, "org.opencv.core.math.subRC") { + static GMatDesc outMeta(GScalarDesc, GMatDesc b, int ddepth) { + return b.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMul, , "org.opencv.core.math.mul") { + static GMatDesc outMeta(GMatDesc a, GMatDesc, double, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMulCOld, , "org.opencv.core.math.mulCOld") { + static GMatDesc outMeta(GMatDesc a, double, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMulC, , "org.opencv.core.math.mulC"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMulS, , "org.opencv.core.math.muls") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; // FIXME: Merge with MulC + + G_TYPED_KERNEL(GDiv, , "org.opencv.core.math.div") { + static GMatDesc outMeta(GMatDesc a, GMatDesc b, double, int ddepth) { + if (ddepth == -1) + { + GAPI_Assert(a.depth == b.depth); + return b; + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GDivC, , "org.opencv.core.math.divC") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc, double, int ddepth) { + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GDivRC, , "org.opencv.core.math.divRC") { + static GMatDesc outMeta(GScalarDesc, GMatDesc b, double, int ddepth) { + return b.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GMean, , "org.opencv.core.math.mean") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL_M(GPolarToCart, , "org.opencv.core.math.polarToCart") { + static std::tuple outMeta(GMatDesc, GMatDesc a, bool) { + return std::make_tuple(a, a); + } + }; + + G_TYPED_KERNEL_M(GCartToPolar, , "org.opencv.core.math.cartToPolar") { + static std::tuple outMeta(GMatDesc x, GMatDesc, bool) { + return std::make_tuple(x, x); + } + }; + + G_TYPED_KERNEL(GPhase, , "org.opencv.core.math.phase") { + static GMatDesc outMeta(const GMatDesc &inx, const GMatDesc &, bool) { + return inx; + } + }; + + G_TYPED_KERNEL(GMask, , "org.opencv.core.pixelwise.mask") { + static GMatDesc outMeta(GMatDesc in, GMatDesc) { + return in; + } + }; + + G_TYPED_KERNEL(GCmpGT, , "org.opencv.core.pixelwise.compare.cmpGT") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpGE, , "org.opencv.core.pixelwise.compare.cmpGE") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLE, , "org.opencv.core.pixelwise.compare.cmpLE") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLT, , "org.opencv.core.pixelwise.compare.cmpLT") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpEQ, , "org.opencv.core.pixelwise.compare.cmpEQ") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpNE, , "org.opencv.core.pixelwise.compare.cmpNE") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpGTScalar, , "org.opencv.core.pixelwise.compare.cmpGTScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpGEScalar, , "org.opencv.core.pixelwise.compare.cmpGEScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLEScalar, , "org.opencv.core.pixelwise.compare.cmpLEScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpLTScalar, , "org.opencv.core.pixelwise.compare.cmpLTScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpEQScalar, , "org.opencv.core.pixelwise.compare.cmpEQScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GCmpNEScalar, , "org.opencv.core.pixelwise.compare.cmpNEScalar"){ + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a.withDepth(CV_8U); + } + }; + + G_TYPED_KERNEL(GAnd, , "org.opencv.core.pixelwise.bitwise_and") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GAndS, , "org.opencv.core.pixelwise.bitwise_andS") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GOr, , "org.opencv.core.pixelwise.bitwise_or") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GOrS, , "org.opencv.core.pixelwise.bitwise_orS") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GXor, , "org.opencv.core.pixelwise.bitwise_xor") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GXorS, , "org.opencv.core.pixelwise.bitwise_xorS") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GNot, , "org.opencv.core.pixelwise.bitwise_not") { + static GMatDesc outMeta(GMatDesc a) { + return a; + } + }; + + G_TYPED_KERNEL(GSelect, , "org.opencv.core.pixelwise.select") { + static GMatDesc outMeta(GMatDesc a, GMatDesc, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GMin, , "org.opencv.core.matrixop.min") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GMax, , "org.opencv.core.matrixop.max") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GAbsDiff, , "org.opencv.core.matrixop.absdiff") { + static GMatDesc outMeta(GMatDesc a, GMatDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GAbsDiffC, , "org.opencv.core.matrixop.absdiffC") { + static GMatDesc outMeta(GMatDesc a, GScalarDesc) { + return a; + } + }; + + G_TYPED_KERNEL(GSum, , "org.opencv.core.matrixop.sum") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL(GAddW, , "org.opencv.core.matrixop.addweighted") { + static GMatDesc outMeta(GMatDesc a, double, GMatDesc b, double, double, int ddepth) { + if (ddepth == -1) + { + // OpenCV: When the input arrays in add/subtract/multiply/divide + // functions have different depths, the output array depth must be + // explicitly specified! + // See artim_op() @ arithm.cpp + GAPI_Assert(a.chan == b.chan); + GAPI_Assert(a.depth == b.depth); + return a; + } + return a.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GNormL1, , "org.opencv.core.matrixop.norml1") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL(GNormL2, , "org.opencv.core.matrixop.norml2") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL(GNormInf, , "org.opencv.core.matrixop.norminf") { + static GScalarDesc outMeta(GMatDesc) { + return empty_scalar_desc(); + } + }; + + G_TYPED_KERNEL_M(GIntegral, , "org.opencv.core.matrixop.integral") { + static std::tuple outMeta(GMatDesc in, int sd, int sqd) { + return std::make_tuple(in.withSizeDelta(1,1).withDepth(sd), + in.withSizeDelta(1,1).withDepth(sqd)); + } + }; + + G_TYPED_KERNEL(GThreshold, , "org.opencv.core.matrixop.threshold") { + static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc, int) { + return in; + } + }; + + + G_TYPED_KERNEL_M(GThresholdOT, , "org.opencv.core.matrixop.thresholdOT") { + static std::tuple outMeta(GMatDesc in, GScalarDesc, int) { + return std::make_tuple(in, empty_scalar_desc()); + } + }; + + G_TYPED_KERNEL(GInRange, , "org.opencv.core.matrixop.inrange") { + static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL_M(GSplit3, , "org.opencv.core.transform.split3") { + static std::tuple outMeta(GMatDesc in) { + const auto out_depth = in.depth; + const auto out_desc = in.withType(out_depth, 1); + return std::make_tuple(out_desc, out_desc, out_desc); + } + }; + + G_TYPED_KERNEL_M(GSplit4, ,"org.opencv.core.transform.split4") { + static std::tuple outMeta(GMatDesc in) { + const auto out_depth = in.depth; + const auto out_desc = in.withType(out_depth, 1); + return std::make_tuple(out_desc, out_desc, out_desc, out_desc); + } + }; + + G_TYPED_KERNEL(GResize, , "org.opencv.core.transform.resize") { + static GMatDesc outMeta(GMatDesc in, Size sz, double fx, double fy, int) { + if (sz.width != 0 && sz.height != 0) + { + return in.withSize(sz); + } + else + { + GAPI_Assert(fx != 0. && fy != 0.); + return in.withSize + (Size(static_cast(round(in.size.width * fx)), + static_cast(round(in.size.height * fy)))); + } + } + }; + + G_TYPED_KERNEL(GResizeP, , "org.opencv.core.transform.resizeP") { + static GMatDesc outMeta(GMatDesc in, Size sz, int interp) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 3); + GAPI_Assert(in.planar); + GAPI_Assert(interp == cv::INTER_LINEAR); + return in.withSize(sz); + } + }; + + G_TYPED_KERNEL(GMerge3, , "org.opencv.core.transform.merge3") { + static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc) { + // Preserve depth and add channel component + return in.withType(in.depth, 3); + } + }; + + G_TYPED_KERNEL(GMerge4, , "org.opencv.core.transform.merge4") { + static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc, GMatDesc) { + // Preserve depth and add channel component + return in.withType(in.depth, 4); + } + }; + + G_TYPED_KERNEL(GRemap, , "org.opencv.core.transform.remap") { + static GMatDesc outMeta(GMatDesc in, Mat m1, Mat, int, int, Scalar) { + return in.withSize(m1.size()); + } + }; + + G_TYPED_KERNEL(GFlip, , "org.opencv.core.transform.flip") { + static GMatDesc outMeta(GMatDesc in, int) { + return in; + } + }; + + // TODO: eliminate the need in this kernel (streaming) + G_TYPED_KERNEL(GCrop, , "org.opencv.core.transform.crop") { + static GMatDesc outMeta(GMatDesc in, Rect rc) { + return in.withSize(Size(rc.width, rc.height)); + } + }; + + G_TYPED_KERNEL(GCopy, , "org.opencv.core.transform.copy") { + static GMatDesc outMeta(GMatDesc in) { + return in; + } + }; + + G_TYPED_KERNEL(GConcatHor, , "org.opencv.imgproc.transform.concatHor") { + static GMatDesc outMeta(GMatDesc l, GMatDesc r) { + return l.withSizeDelta(+r.size.width, 0); + } + }; + + G_TYPED_KERNEL(GConcatVert, , "org.opencv.imgproc.transform.concatVert") { + static GMatDesc outMeta(GMatDesc t, GMatDesc b) { + return t.withSizeDelta(0, +b.size.height); + } + }; + + G_TYPED_KERNEL(GLUT, , "org.opencv.core.transform.LUT") { + static GMatDesc outMeta(GMatDesc in, Mat) { + return in; + } + }; + + G_TYPED_KERNEL(GConvertTo, , "org.opencv.core.transform.convertTo") { + static GMatDesc outMeta(GMatDesc in, int rdepth, double, double) { + return rdepth < 0 ? in : in.withDepth(rdepth); + } + }; + + G_TYPED_KERNEL(GSqrt, , "org.opencv.core.math.sqrt") { + static GMatDesc outMeta(GMatDesc in) { + return in; + } + }; + + G_TYPED_KERNEL(GNormalize, , "org.opencv.core.normalize") { + static GMatDesc outMeta(GMatDesc in, double, double, int, int ddepth) { + // unlike opencv doesn't have a mask as a parameter + return (ddepth < 0 ? in : in.withDepth(ddepth)); + } + }; +} + +//! @addtogroup gapi_math +//! @{ + +/** @brief Calculates the per-element sum of two matrices. + +The function add calculates sum of two matrices of the same size and the same number of channels: +\f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f] + +The function can be replaced with matrix expressions: + \f[\texttt{dst} = \texttt{src1} + \texttt{src2}\f] + +The input matrices and the output matrix can all have the same or different depths. For example, you +can add a 16-bit unsigned matrix to a 8-bit signed matrix and store the sum as a 32-bit +floating-point matrix. Depth of the output matrix is determined by the ddepth parameter. +If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have +the same depth as the input matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.add" +@param src1 first input matrix. +@param src2 second input matrix. +@param ddepth optional depth of the output matrix. +@sa sub, addWeighted +*/ +GAPI_EXPORTS GMat add(const GMat& src1, const GMat& src2, int ddepth = -1); + +/** @brief Calculates the per-element sum of matrix and given scalar. + +The function addC adds a given scalar value to each element of given matrix. +The function can be replaced with matrix expressions: + + \f[\texttt{dst} = \texttt{src1} + \texttt{c}\f] + +Depth of the output matrix is determined by the ddepth parameter. +If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. +The matrices can be single or multi channel. Output matrix must have the same size and number of channels as the input matrix. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.addC" +@param src1 first input matrix. +@param c scalar value to be added. +@param ddepth optional depth of the output matrix. +@sa sub, addWeighted +*/ +GAPI_EXPORTS GMat addC(const GMat& src1, const GScalar& c, int ddepth = -1); +//! @overload +GAPI_EXPORTS GMat addC(const GScalar& c, const GMat& src1, int ddepth = -1); + +/** @brief Calculates the per-element difference between two matrices. + +The function sub calculates difference between two matrices, when both matrices have the same size and the same number of +channels: + \f[\texttt{dst}(I) = \texttt{src1}(I) - \texttt{src2}(I)\f] + +The function can be replaced with matrix expressions: +\f[\texttt{dst} = \texttt{src1} - \texttt{src2}\f] + +The input matrices and the output matrix can all have the same or different depths. For example, you +can subtract two 8-bit unsigned matrices store the result as a 16-bit signed matrix. +Depth of the output matrix is determined by the ddepth parameter. +If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have +the same depth as the input matrices. The matrices can be single or multi channel. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.sub" +@param src1 first input matrix. +@param src2 second input matrix. +@param ddepth optional depth of the output matrix. +@sa add, addC + */ +GAPI_EXPORTS GMat sub(const GMat& src1, const GMat& src2, int ddepth = -1); + +/** @brief Calculates the per-element difference between matrix and given scalar. + +The function can be replaced with matrix expressions: + \f[\texttt{dst} = \texttt{src} - \texttt{c}\f] + +Depth of the output matrix is determined by the ddepth parameter. +If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. +The matrices can be single or multi channel. Output matrix must have the same size as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.subC" +@param src first input matrix. +@param c scalar value to subtracted. +@param ddepth optional depth of the output matrix. +@sa add, addC, subRC + */ +GAPI_EXPORTS GMat subC(const GMat& src, const GScalar& c, int ddepth = -1); + +/** @brief Calculates the per-element difference between given scalar and the matrix. + +The function can be replaced with matrix expressions: + \f[\texttt{dst} = \texttt{val} - \texttt{src}\f] + +Depth of the output matrix is determined by the ddepth parameter. +If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. +The matrices can be single or multi channel. Output matrix must have the same size as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.subRC" +@param c scalar value to subtract from. +@param src input matrix to be subtracted. +@param ddepth optional depth of the output matrix. +@sa add, addC, subC + */ +GAPI_EXPORTS GMat subRC(const GScalar& c, const GMat& src, int ddepth = -1); + +/** @brief Calculates the per-element scaled product of two matrices. + +The function mul calculates the per-element product of two matrices: + +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f] + +If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have +the same depth as the input matrices. The matrices can be single or multi channel. +Output matrix must have the same size as input matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.mul" +@param src1 first input matrix. +@param src2 second input matrix of the same size and the same depth as src1. +@param scale optional scale factor. +@param ddepth optional depth of the output matrix. +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat mul(const GMat& src1, const GMat& src2, double scale = 1.0, int ddepth = -1); + +/** @brief Multiplies matrix by scalar. + +The function mulC multiplies each element of matrix src by given scalar value: + +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I) \cdot \texttt{multiplier} )\f] + +The matrices can be single or multi channel. Output matrix must have the same size as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.mulC" +@param src input matrix. +@param multiplier factor to be multiplied. +@param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth. +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat mulC(const GMat& src, double multiplier, int ddepth = -1); +//! @overload +GAPI_EXPORTS GMat mulC(const GMat& src, const GScalar& multiplier, int ddepth = -1); // FIXME: merge with mulc +//! @overload +GAPI_EXPORTS GMat mulC(const GScalar& multiplier, const GMat& src, int ddepth = -1); // FIXME: merge with mulc + +/** @brief Performs per-element division of two matrices. + +The function divides one matrix by another: +\f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f] + +When src2(I) is zero, dst(I) will also be zero. Different channels of +multi-channel matrices are processed independently. +The matrices can be single or multi channel. Output matrix must have the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.div" +@param src1 first input matrix. +@param src2 second input matrix of the same size and depth as src1. +@param scale scalar factor. +@param ddepth optional depth of the output matrix; you can only pass -1 when src1.depth() == src2.depth(). +@sa mul, add, sub +*/ +GAPI_EXPORTS GMat div(const GMat& src1, const GMat& src2, double scale, int ddepth = -1); + +/** @brief Divides matrix by scalar. + +The function divC divides each element of matrix src by given scalar value: + +\f[\texttt{dst(I) = saturate(src(I)*scale/divisor)}\f] + +When divisor is zero, dst(I) will also be zero. Different channels of +multi-channel matrices are processed independently. +The matrices can be single or multi channel. Output matrix must have the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.divC" +@param src input matrix. +@param divisor number to be divided by. +@param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth. +@param scale scale factor. +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat divC(const GMat& src, const GScalar& divisor, double scale, int ddepth = -1); + +/** @brief Divides scalar by matrix. + +The function divRC divides given scalar by each element of matrix src and keep the division result in new matrix of the same size and type as src: + +\f[\texttt{dst(I) = saturate(divident*scale/src(I))}\f] + +When src(I) is zero, dst(I) will also be zero. Different channels of +multi-channel matrices are processed independently. +The matrices can be single or multi channel. Output matrix must have the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.divRC" +@param src input matrix. +@param divident number to be divided. +@param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth. +@param scale scale factor +@sa add, sub, div, addWeighted +*/ +GAPI_EXPORTS GMat divRC(const GScalar& divident, const GMat& src, double scale, int ddepth = -1); + +/** @brief Applies a mask to a matrix. + +The function mask set value from given matrix if the corresponding pixel value in mask matrix set to true, +and set the matrix value to 0 otherwise. + +Supported src matrix data types are @ref CV_8UC1, @ref CV_16SC1, @ref CV_16UC1. Supported mask data type is @ref CV_8UC1. + +@note Function textual ID is "org.opencv.core.math.mask" +@param src input matrix. +@param mask input mask matrix. +*/ +GAPI_EXPORTS GMat mask(const GMat& src, const GMat& mask); + +/** @brief Calculates an average (mean) of matrix elements. + +The function mean calculates the mean value M of matrix elements, +independently for each channel, and return it. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.math.mean" +@param src input matrix. +*/ +GAPI_EXPORTS GScalar mean(const GMat& src); + +/** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle. + +The function polarToCart calculates the Cartesian coordinates of each 2D +vector represented by the corresponding elements of magnitude and angle: +\f[\begin{array}{l} \texttt{x} (I) = \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) = \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f] + +The relative accuracy of the estimated coordinates is about 1e-6. + +First output is a matrix of x-coordinates of 2D vectors. +Second output is a matrix of y-coordinates of 2D vectors. +Both output must have the same size and depth as input matrices. + +@note Function textual ID is "org.opencv.core.math.polarToCart" + +@param magnitude input floating-point @ref CV_32FC1 matrix (1xN) of magnitudes of 2D vectors; +@param angle input floating-point @ref CV_32FC1 matrix (1xN) of angles of 2D vectors. +@param angleInDegrees when true, the input angles are measured in +degrees, otherwise, they are measured in radians. +@sa cartToPolar, exp, log, pow, sqrt +*/ +GAPI_EXPORTS std::tuple polarToCart(const GMat& magnitude, const GMat& angle, + bool angleInDegrees = false); + +/** @brief Calculates the magnitude and angle of 2D vectors. + +The function cartToPolar calculates either the magnitude, angle, or both +for every 2D vector (x(I),y(I)): +\f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f] + +The angles are calculated with accuracy about 0.3 degrees. For the point +(0,0), the angle is set to 0. + +First output is a matrix of magnitudes of the same size and depth as input x. +Second output is a matrix of angles that has the same size and depth as +x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees). + +@note Function textual ID is "org.opencv.core.math.cartToPolar" + +@param x matrix of @ref CV_32FC1 x-coordinates. +@param y array of @ref CV_32FC1 y-coordinates. +@param angleInDegrees a flag, indicating whether the angles are measured +in radians (which is by default), or in degrees. +@sa polarToCart +*/ +GAPI_EXPORTS std::tuple cartToPolar(const GMat& x, const GMat& y, + bool angleInDegrees = false); + +/** @brief Calculates the rotation angle of 2D vectors. + +The function cv::phase calculates the rotation angle of each 2D vector that +is formed from the corresponding elements of x and y : +\f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f] + +The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 , +the corresponding angle(I) is set to 0. +@param x input floating-point array of x-coordinates of 2D vectors. +@param y input array of y-coordinates of 2D vectors; it must have the +same size and the same type as x. +@param angleInDegrees when true, the function calculates the angle in +degrees, otherwise, they are measured in radians. +@return array of vector angles; it has the same size and same type as x. +*/ +GAPI_EXPORTS GMat phase(const GMat& x, const GMat &y, bool angleInDegrees = false); + +/** @brief Calculates a square root of array elements. + +The function cv::gapi::sqrt calculates a square root of each input array element. +In case of multi-channel arrays, each channel is processed +independently. The accuracy is approximately the same as of the built-in +std::sqrt . +@param src input floating-point array. +@return output array of the same size and type as src. +*/ +GAPI_EXPORTS GMat sqrt(const GMat &src); + +//! @} gapi_math +//! +//! @addtogroup gapi_pixelwise +//! @{ + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater compare to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) > \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: +\f[\texttt{dst} = \texttt{src1} > \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices/matrix. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGT" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpLE, cmpGE, cmpLS +*/ +GAPI_EXPORTS GMat cmpGT(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGTScalar" +*/ +GAPI_EXPORTS GMat cmpGT(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less than elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) < \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} < \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices/matrix. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLT" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpLE, cmpGE, cmpGT +*/ +GAPI_EXPORTS GMat cmpLT(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLTScalar" +*/ +GAPI_EXPORTS GMat cmpLT(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater or equal compare to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) >= \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} >= \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGE" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpLE, cmpGT, cmpLS +*/ +GAPI_EXPORTS GMat cmpGE(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLGEcalar" +*/ +GAPI_EXPORTS GMat cmpGE(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less or equal compare to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) <= \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} <= \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLE" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpGT, cmpGE, cmpLS +*/ +GAPI_EXPORTS GMat cmpLE(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLEScalar" +*/ +GAPI_EXPORTS GMat cmpLE(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are equal to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) == \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} == \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQ" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpNE +*/ +GAPI_EXPORTS GMat cmpEQ(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQScalar" +*/ +GAPI_EXPORTS GMat cmpEQ(const GMat& src1, const GScalar& src2); + +/** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are not equal to elements in second. + +The function compares elements of two matrices src1 and src2 of the same size: + \f[\texttt{dst} (I) = \texttt{src1} (I) != \texttt{src2} (I)\f] + +When the comparison result is true, the corresponding element of output +array is set to 255. The comparison operations can be replaced with the +equivalent matrix expressions: + \f[\texttt{dst} = \texttt{src1} != \texttt{src2}\f] + +Output matrix of depth @ref CV_8U must have the same size and the same number of channels as + the input matrices. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNE" +@param src1 first input matrix. +@param src2 second input matrix/scalar of the same depth as first input matrix. +@sa min, max, threshold, cmpEQ +*/ +GAPI_EXPORTS GMat cmpNE(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNEScalar" +*/ +GAPI_EXPORTS GMat cmpNE(const GMat& src1, const GScalar& src2); + +/** @brief computes bitwise conjunction of the two matrixes (src1 & src2) +Calculates the per-element bit-wise logical conjunction of two matrices of the same size. + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_and" + +@param src1 first input matrix. +@param src2 second input matrix. +*/ +GAPI_EXPORTS GMat bitwise_and(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_andS" +@param src1 first input matrix. +@param src2 scalar, which will be per-lemenetly conjuncted with elements of src1. +*/ +GAPI_EXPORTS GMat bitwise_and(const GMat& src1, const GScalar& src2); + +/** @brief computes bitwise disjunction of the two matrixes (src1 | src2) +Calculates the per-element bit-wise logical disjunction of two matrices of the same size. + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_or" + +@param src1 first input matrix. +@param src2 second input matrix. +*/ +GAPI_EXPORTS GMat bitwise_or(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_orS" +@param src1 first input matrix. +@param src2 scalar, which will be per-lemenetly disjuncted with elements of src1. +*/ +GAPI_EXPORTS GMat bitwise_or(const GMat& src1, const GScalar& src2); + + +/** @brief computes bitwise logical "exclusive or" of the two matrixes (src1 ^ src2) +Calculates the per-element bit-wise logical "exclusive or" of two matrices of the same size. + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_xor" + +@param src1 first input matrix. +@param src2 second input matrix. +*/ +GAPI_EXPORTS GMat bitwise_xor(const GMat& src1, const GMat& src2); +/** @overload +@note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_xorS" +@param src1 first input matrix. +@param src2 scalar, for which per-lemenet "logical or" operation on elements of src1 will be performed. +*/ +GAPI_EXPORTS GMat bitwise_xor(const GMat& src1, const GScalar& src2); + + +/** @brief Inverts every bit of an array. +The function bitwise_not calculates per-element bit-wise inversion of the input +matrix: +\f[\texttt{dst} (I) = \neg \texttt{src} (I)\f] + +In case of floating-point matrices, their machine-specific bit +representations (usually IEEE754-compliant) are used for the operation. +In case of multi-channel matrices, each channel is processed +independently. Output matrix must have the same size and depth as the input +matrix. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_not" + +@param src input matrix. +*/ +GAPI_EXPORTS GMat bitwise_not(const GMat& src); + +/** @brief Select values from either first or second of input matrices by given mask. +The function set to the output matrix either the value from the first input matrix if corresponding value of mask matrix is 255, + or value from the second input matrix (if value of mask matrix set to 0). + +Input mask matrix must be of @ref CV_8UC1 type, two other inout matrices and output matrix should be of the same type. The size should +be the same for all input and output matrices. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.pixelwise.select" + +@param src1 first input matrix. +@param src2 second input matrix. +@param mask mask input matrix. +*/ +GAPI_EXPORTS GMat select(const GMat& src1, const GMat& src2, const GMat& mask); + +//! @} gapi_pixelwise + + +//! @addtogroup gapi_matrixop +//! @{ +/** @brief Calculates per-element minimum of two matrices. + +The function min calculates the per-element minimum of two matrices of the same size, number of channels and depth: +\f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f] + where I is a multi-dimensional index of matrix elements. In case of + multi-channel matrices, each channel is processed independently. +Output matrix must be of the same size and depth as src1. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.min" +@param src1 first input matrix. +@param src2 second input matrix of the same size and depth as src1. +@sa max, compareEqual, compareLess, compareLessEqual +*/ +GAPI_EXPORTS GMat min(const GMat& src1, const GMat& src2); + +/** @brief Calculates per-element maximum of two matrices. + +The function max calculates the per-element maximum of two matrices of the same size, number of channels and depth: +\f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f] + where I is a multi-dimensional index of matrix elements. In case of + multi-channel matrices, each channel is processed independently. +Output matrix must be of the same size and depth as src1. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.max" +@param src1 first input matrix. +@param src2 second input matrix of the same size and depth as src1. +@sa min, compare, compareEqual, compareGreater, compareGreaterEqual +*/ +GAPI_EXPORTS GMat max(const GMat& src1, const GMat& src2); + +/** @brief Calculates the per-element absolute difference between two matrices. + +The function absDiff calculates absolute difference between two matrices of the same size and depth: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f] + where I is a multi-dimensional index of matrix elements. In case of + multi-channel matrices, each channel is processed independently. +Output matrix must have the same size and depth as input matrices. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.absdiff" +@param src1 first input matrix. +@param src2 second input matrix. +@sa abs +*/ +GAPI_EXPORTS GMat absDiff(const GMat& src1, const GMat& src2); + +/** @brief Calculates absolute value of matrix elements. + +The function abs calculates absolute difference between matrix elements and given scalar value: + \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{matC}(I)|)\f] + where matC is constructed from given scalar c and has the same sizes and depth as input matrix src. + +Output matrix must be of the same size and depth as src. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.absdiffC" +@param src input matrix. +@param c scalar to be subtracted. +@sa min, max +*/ +GAPI_EXPORTS GMat absDiffC(const GMat& src, const GScalar& c); + +/** @brief Calculates sum of all matrix elements. + +The function sum calculates sum of all matrix elements, independently for each channel. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.sum" +@param src input matrix. +@sa min, max +*/ +GAPI_EXPORTS GScalar sum(const GMat& src); + +/** @brief Calculates the weighted sum of two matrices. + +The function addWeighted calculates the weighted sum of two matrices as follows: +\f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f] +where I is a multi-dimensional index of array elements. In case of multi-channel matrices, each +channel is processed independently. + +The function can be replaced with a matrix expression: + \f[\texttt{dst}(I) = \texttt{alpha} * \texttt{src1}(I) - \texttt{beta} * \texttt{src2}(I) + \texttt{gamma} \f] + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.addweighted" +@param src1 first input matrix. +@param alpha weight of the first matrix elements. +@param src2 second input matrix of the same size and channel number as src1. +@param beta weight of the second matrix elements. +@param gamma scalar added to each sum. +@param ddepth optional depth of the output matrix. +@sa add, sub +*/ +GAPI_EXPORTS GMat addWeighted(const GMat& src1, double alpha, const GMat& src2, double beta, double gamma, int ddepth = -1); + +/** @brief Calculates the absolute L1 norm of a matrix. + +This version of normL1 calculates the absolute L1 norm of src. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{1} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\ +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\ +\f} + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.norml1" +@param src input matrix. +@sa normL2, normInf +*/ +GAPI_EXPORTS GScalar normL1(const GMat& src); + +/** @brief Calculates the absolute L2 norm of a matrix. + +This version of normL2 calculates the absolute L2 norm of src. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{2} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\ +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\ +\f} + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +@note Function textual ID is "org.opencv.core.matrixop.norml2" +@param src input matrix. +@sa normL1, normInf +*/ +GAPI_EXPORTS GScalar normL2(const GMat& src); + +/** @brief Calculates the absolute infinite norm of a matrix. + +This version of normInf calculates the absolute infinite norm of src. + +As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$. +The \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$ +is calculated as follows +\f{align*} + \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2 +\f} +and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is +\f{align*} + \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5. +\f} + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.norminf" +@param src input matrix. +@sa normL1, normL2 +*/ +GAPI_EXPORTS GScalar normInf(const GMat& src); + +/** @brief Calculates the integral of an image. + +The function calculates one or more integral images for the source image as follows: + +\f[\texttt{sum} (X,Y) = \sum _{x integral(const GMat& src, int sdepth = -1, int sqdepth = -1); + +/** @brief Applies a fixed-level threshold to each matrix element. + +The function applies fixed-level thresholding to a single- or multiple-channel matrix. +The function is typically used to get a bi-level (binary) image out of a grayscale image ( cmp functions could be also used for +this purpose) or for removing a noise, that is, filtering out pixels with too small or too large +values. There are several types of thresholding supported by the function. They are determined by +type parameter. + +Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the +above values. In these cases, the function determines the optimal threshold value using the Otsu's +or Triangle algorithm and uses it instead of the specified thresh . The function returns the +computed threshold value in addititon to thresholded matrix. +The Otsu's and Triangle methods are implemented only for 8-bit matrices. + +Input image should be single channel only in case of cv::THRESH_OTSU or cv::THRESH_TRIANGLE flags. +Output matrix must be of the same size and depth as src. + +@note Function textual ID is "org.opencv.core.matrixop.threshold" + +@param src input matrix (@ref CV_8UC1, @ref CV_8UC3, or @ref CV_32FC1). +@param thresh threshold value. +@param maxval maximum value to use with the cv::THRESH_BINARY and cv::THRESH_BINARY_INV thresholding +types. +@param type thresholding type (see the cv::ThresholdTypes). + +@sa min, max, cmpGT, cmpLE, cmpGE, cmpLS + */ +GAPI_EXPORTS GMat threshold(const GMat& src, const GScalar& thresh, const GScalar& maxval, int type); +/** @overload +This function applicable for all threshold types except CV_THRESH_OTSU and CV_THRESH_TRIANGLE +@note Function textual ID is "org.opencv.core.matrixop.thresholdOT" +*/ +GAPI_EXPORTS std::tuple threshold(const GMat& src, const GScalar& maxval, int type); + +/** @brief Applies a range-level threshold to each matrix element. + +The function applies range-level thresholding to a single- or multiple-channel matrix. +It sets output pixel value to OxFF if the corresponding pixel value of input matrix is in specified range,or 0 otherwise. + +Input and output matrices must be CV_8UC1. + +@note Function textual ID is "org.opencv.core.matrixop.inRange" + +@param src input matrix (CV_8UC1). +@param threshLow lower boundary value. +@param threshUp upper boundary value. + +@sa threshold + */ +GAPI_EXPORTS GMat inRange(const GMat& src, const GScalar& threshLow, const GScalar& threshUp); + +//! @} gapi_matrixop + +//! @addtogroup gapi_transform +//! @{ +/** @brief Resizes an image. + +The function resizes the image src down to or up to the specified size. + +Output image size will have the size dsize (when dsize is non-zero) or the size computed from +src.size(), fx, and fy; the depth of output is the same as of src. + +If you want to resize src so that it fits the pre-created dst, +you may call the function as follows: +@code + // explicitly specify dsize=dst.size(); fx and fy will be computed from that. + resize(src, dst, dst.size(), 0, 0, interpolation); +@endcode +If you want to decimate the image by factor of 2 in each direction, you can call the function this +way: +@code + // specify fx and fy and let the function compute the destination image size. + resize(src, dst, Size(), 0.5, 0.5, interpolation); +@endcode +To shrink an image, it will generally look best with cv::INTER_AREA interpolation, whereas to +enlarge an image, it will generally look best with cv::INTER_CUBIC (slow) or cv::INTER_LINEAR +(faster but still looks OK). + +@note Function textual ID is "org.opencv.core.transform.resize" + +@param src input image. +@param dsize output image size; if it equals zero, it is computed as: + \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f] + Either dsize or both fx and fy must be non-zero. +@param fx scale factor along the horizontal axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.width/src.cols}\f] +@param fy scale factor along the vertical axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.height/src.rows}\f] +@param interpolation interpolation method, see cv::InterpolationFlags + +@sa warpAffine, warpPerspective, remap, resizeP + */ +GAPI_EXPORTS GMat resize(const GMat& src, const Size& dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR); + +/** @brief Resizes a planar image. + +The function resizes the image src down to or up to the specified size. +Planar image memory layout is three planes laying in the memory contiguously, +so the image height should be plane_height*plane_number, image type is @ref CV_8UC1. + +Output image size will have the size dsize, the depth of output is the same as of src. + +@note Function textual ID is "org.opencv.core.transform.resizeP" + +@param src input image, must be of @ref CV_8UC1 type; +@param dsize output image size; +@param interpolation interpolation method, only cv::INTER_LINEAR is supported at the moment + +@sa warpAffine, warpPerspective, remap, resize + */ +GAPI_EXPORTS GMatP resizeP(const GMatP& src, const Size& dsize, int interpolation = cv::INTER_LINEAR); + +/** @brief Creates one 3-channel (4-channel) matrix out of 3(4) single-channel ones. + +The function merges several matrices to make a single multi-channel matrix. That is, each +element of the output matrix will be a concatenation of the elements of the input matrices, where +elements of i-th input matrix are treated as mv[i].channels()-element vectors. +Input matrix must be of @ref CV_8UC3 (@ref CV_8UC4) type. + +The function split3/split4 does the reverse operation. + +@note Function textual ID for merge3 is "org.opencv.core.transform.merge3" +@note Function textual ID for merge4 is "org.opencv.core.transform.merge4" + +@param src1 first input matrix to be merged +@param src2 second input matrix to be merged +@param src3 third input matrix to be merged +@param src4 fourth input matrix to be merged +@sa split4, split3 +*/ +GAPI_EXPORTS GMat merge4(const GMat& src1, const GMat& src2, const GMat& src3, const GMat& src4); +GAPI_EXPORTS GMat merge3(const GMat& src1, const GMat& src2, const GMat& src3); + +/** @brief Divides a 3-channel (4-channel) matrix into 3(4) single-channel matrices. + +The function splits a 3-channel (4-channel) matrix into 3(4) single-channel matrices: +\f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f] + +All output matrices must be in @ref CV_8UC1. + +@note Function textual for split3 ID is "org.opencv.core.transform.split3" +@note Function textual for split4 ID is "org.opencv.core.transform.split4" + +@param src input @ref CV_8UC4 (@ref CV_8UC3) matrix. +@sa merge3, merge4 +*/ +GAPI_EXPORTS std::tuple split4(const GMat& src); +GAPI_EXPORTS std::tuple split3(const GMat& src); + +/** @brief Applies a generic geometrical transformation to an image. + +The function remap transforms the source image using the specified map: + +\f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f] + +where values of pixels with non-integer coordinates are computed using one of available +interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps +in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in +\f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to +convert from floating to fixed-point representations of a map is that they can yield much faster +(\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x), +cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients. +Output image must be of the same size and depth as input one. + +@note Function textual ID is "org.opencv.core.transform.remap" + +@param src Source image. +@param map1 The first map of either (x,y) points or just x values having the type CV_16SC2, +CV_32FC1, or CV_32FC2. +@param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map +if map1 is (x,y) points), respectively. +@param interpolation Interpolation method (see cv::InterpolationFlags). The method INTER_AREA is +not supported by this function. +@param borderMode Pixel extrapolation method (see cv::BorderTypes). When +borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that +corresponds to the "outliers" in the source image are not modified by the function. +@param borderValue Value used in case of a constant border. By default, it is 0. +@note +Due to current implementation limitations the size of an input and output images should be less than 32767x32767. + */ +GAPI_EXPORTS GMat remap(const GMat& src, const Mat& map1, const Mat& map2, + int interpolation, int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @brief Flips a 2D matrix around vertical, horizontal, or both axes. + +The function flips the matrix in one of three different ways (row +and column indices are 0-based): +\f[\texttt{dst} _{ij} = +\left\{ +\begin{array}{l l} +\texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\ +\texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\ +\texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\ +\end{array} +\right.\f] +The example scenarios of using the function are the following: +* Vertical flipping of the image (flipCode == 0) to switch between + top-left and bottom-left image origin. This is a typical operation + in video processing on Microsoft Windows\* OS. +* Horizontal flipping of the image with the subsequent horizontal + shift and absolute difference calculation to check for a + vertical-axis symmetry (flipCode \> 0). +* Simultaneous horizontal and vertical flipping of the image with + the subsequent shift and absolute difference calculation to check + for a central symmetry (flipCode \< 0). +* Reversing the order of point arrays (flipCode \> 0 or + flipCode == 0). +Output image must be of the same depth as input one, size should be correct for given flipCode. + +@note Function textual ID is "org.opencv.core.transform.flip" + +@param src input matrix. +@param flipCode a flag to specify how to flip the array; 0 means +flipping around the x-axis and positive value (for example, 1) means +flipping around y-axis. Negative value (for example, -1) means flipping +around both axes. +@sa remap +*/ +GAPI_EXPORTS GMat flip(const GMat& src, int flipCode); + +/** @brief Crops a 2D matrix. + +The function crops the matrix by given cv::Rect. + +Output matrix must be of the same depth as input one, size is specified by given rect size. + +@note Function textual ID is "org.opencv.core.transform.crop" + +@param src input matrix. +@param rect a rect to crop a matrix to +@sa resize +*/ +GAPI_EXPORTS GMat crop(const GMat& src, const Rect& rect); + +/** @brief Copies a matrix. + +Copies an input array. Works as a regular Mat::clone but happens in-graph. +Mainly is used to workaround some existing limitations (e.g. to forward an input frame to outputs +in the streaming mode). Will be deprecated and removed in the future. + +@note Function textual ID is "org.opencv.core.transform.copy" + +@param src input matrix. +@sa crop +*/ +GAPI_EXPORTS GMat copy(const GMat& src); + +/** @brief Applies horizontal concatenation to given matrices. + +The function horizontally concatenates two GMat matrices (with the same number of rows). +@code{.cpp} + GMat A = { 1, 4, + 2, 5, + 3, 6 }; + GMat B = { 7, 10, + 8, 11, + 9, 12 }; + + GMat C = gapi::concatHor(A, B); + //C: + //[1, 4, 7, 10; + // 2, 5, 8, 11; + // 3, 6, 9, 12] +@endcode +Output matrix must the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2. +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.imgproc.transform.concatHor" + +@param src1 first input matrix to be considered for horizontal concatenation. +@param src2 second input matrix to be considered for horizontal concatenation. +@sa concatVert +*/ +GAPI_EXPORTS GMat concatHor(const GMat& src1, const GMat& src2); + +/** @overload +The function horizontally concatenates given number of GMat matrices (with the same number of columns). +Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices. + +@param v vector of input matrices to be concatenated horizontally. +*/ +GAPI_EXPORTS GMat concatHor(const std::vector &v); + +/** @brief Applies vertical concatenation to given matrices. + +The function vertically concatenates two GMat matrices (with the same number of cols). + @code{.cpp} + GMat A = { 1, 7, + 2, 8, + 3, 9 }; + GMat B = { 4, 10, + 5, 11, + 6, 12 }; + + GMat C = gapi::concatVert(A, B); + //C: + //[1, 7; + // 2, 8; + // 3, 9; + // 4, 10; + // 5, 11; + // 6, 12] + @endcode + +Output matrix must the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2. +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.imgproc.transform.concatVert" + +@param src1 first input matrix to be considered for vertical concatenation. +@param src2 second input matrix to be considered for vertical concatenation. +@sa concatHor +*/ +GAPI_EXPORTS GMat concatVert(const GMat& src1, const GMat& src2); + +/** @overload +The function vertically concatenates given number of GMat matrices (with the same number of columns). +Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices. + +@param v vector of input matrices to be concatenated vertically. +*/ +GAPI_EXPORTS GMat concatVert(const std::vector &v); + + +/** @brief Performs a look-up table transform of a matrix. + +The function LUT fills the output matrix with values from the look-up table. Indices of the entries +are taken from the input matrix. That is, the function processes each element of src as follows: +\f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I))}\f] + +Supported matrix data types are @ref CV_8UC1. +Output is a matrix of the same size and number of channels as src, and the same depth as lut. + +@note Function textual ID is "org.opencv.core.transform.LUT" + +@param src input matrix of 8-bit elements. +@param lut look-up table of 256 elements; in case of multi-channel input array, the table should +either have a single channel (in this case the same table is used for all channels) or the same +number of channels as in the input matrix. +*/ +GAPI_EXPORTS GMat LUT(const GMat& src, const Mat& lut); + +/** @brief Converts a matrix to another data depth with optional scaling. + +The method converts source pixel values to the target data depth. saturate_cast\<\> is applied at +the end to avoid possible overflows: + +\f[m(x,y) = saturate \_ cast( \alpha (*this)(x,y) + \beta )\f] +Output matrix must be of the same size as input one. + +@note Function textual ID is "org.opencv.core.transform.convertTo" +@param src input matrix to be converted from. +@param rdepth desired output matrix depth or, rather, the depth since the number of channels are the +same as the input has; if rdepth is negative, the output matrix will have the same depth as the input. +@param alpha optional scale factor. +@param beta optional delta added to the scaled values. + */ +GAPI_EXPORTS GMat convertTo(const GMat& src, int rdepth, double alpha=1, double beta=0); + +/** @brief Normalizes the norm or value range of an array. + +The function normalizes scale and shift the input array elements so that +\f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f] +(where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that +\f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f] +when normType=NORM_MINMAX (for dense arrays only). + +@note Function textual ID is "org.opencv.core.normalize" + +@param src input array. +@param alpha norm value to normalize to or the lower range boundary in case of the range +normalization. +@param beta upper range boundary in case of the range normalization; it is not used for the norm +normalization. +@param norm_type normalization type (see cv::NormTypes). +@param ddepth when negative, the output array has the same type as src; otherwise, it has the same +number of channels as src and the depth =ddepth. +@sa norm, Mat::convertTo +*/ +GAPI_EXPORTS GMat normalize(const GMat& src, double alpha, double beta, + int norm_type, int ddepth = -1); +//! @} gapi_transform + +} //namespace gapi +} //namespace cv + +#endif //OPENCV_GAPI_CORE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ffd3596f5a13bfcdca329a366cffcf928b770d32 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/core.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CPU_CORE_API_HPP +#define OPENCV_GAPI_CPU_CORE_API_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { +namespace gapi { +namespace core { +namespace cpu { + +GAPI_EXPORTS GKernelPackage kernels(); + +} // namespace cpu +} // namespace core +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_CPU_CORE_API_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/gcpukernel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/gcpukernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..079534a98ea7f9a7ea7118a4afaf1a61e2a9c334 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/gcpukernel.hpp @@ -0,0 +1,292 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_GCPUKERNEL_HPP +#define OPENCV_GAPI_GCPUKERNEL_HPP + +#include +#include +#include +#include + +#include +#include +#include +#include +#include //to_ocv +#include //suppress_unused_warning +#include + +// FIXME: namespace scheme for backends? +namespace cv { + +namespace gimpl +{ + // Forward-declare an internal class + class GCPUExecutable; + + namespace render + { + namespace ocv + { + class GRenderExecutable; + } + } +} // namespace gimpl + +namespace gapi +{ +namespace cpu +{ + /** + * \addtogroup gapi_std_backends + * @{ + * + * @brief G-API backends available in this OpenCV version + * + * G-API backends play a corner stone role in G-API execution + * stack. Every backend is hardware-oriented and thus can run its + * kernels efficiently on the target platform. + * + * Backends are usually "black boxes" for G-API users -- on the API + * side, all backends are represented as different objects of the + * same class cv::gapi::GBackend. + * User can manipulate with backends by specifying which kernels to use. + * + * @sa @ref gapi_hld + */ + + /** + * @brief Get a reference to CPU (OpenCV) backend. + * + * This is the default backend in G-API at the moment, providing + * broader functional coverage but losing some graph model + * advantages. Provided mostly for reference and prototyping + * purposes. + * + * @sa gapi_std_backends + */ + GAPI_EXPORTS cv::gapi::GBackend backend(); + /** @} */ +} // namespace cpu +} // namespace gapi + +// Represents arguments which are passed to a wrapped CPU function +// FIXME: put into detail? +class GAPI_EXPORTS GCPUContext +{ +public: + // Generic accessor API + template + const T& inArg(int input) { return m_args.at(input).get(); } + + // Syntax sugar + const cv::gapi::own::Mat& inMat(int input); + cv::gapi::own::Mat& outMatR(int output); // FIXME: Avoid cv::gapi::own::Mat m = ctx.outMatR() + + const cv::gapi::own::Scalar& inVal(int input); + cv::gapi::own::Scalar& outValR(int output); // FIXME: Avoid cv::gapi::own::Scalar s = ctx.outValR() + template std::vector& outVecR(int output) // FIXME: the same issue + { + return outVecRef(output).wref(); + } + +protected: + detail::VectorRef& outVecRef(int output); + + std::vector m_args; + + //FIXME: avoid conversion of arguments from internal representation to OpenCV one on each call + //to OCV kernel. (This can be achieved by a two single time conversions in GCPUExecutable::run, + //once on enter for input and output arguments, and once before return for output arguments only + std::unordered_map m_results; + + friend class gimpl::GCPUExecutable; + friend class gimpl::render::ocv::GRenderExecutable; +}; + +class GAPI_EXPORTS GCPUKernel +{ +public: + // This function is kernel's execution entry point (does the processing work) + using F = std::function; + + GCPUKernel(); + explicit GCPUKernel(const F& f); + + void apply(GCPUContext &ctx); + +protected: + F m_f; +}; + +// FIXME: This is an ugly ad-hoc imlpementation. TODO: refactor + +namespace detail +{ +template struct get_in; +template<> struct get_in +{ + static cv::Mat get(GCPUContext &ctx, int idx) { return to_ocv(ctx.inMat(idx)); } +}; +template<> struct get_in +{ + static cv::Mat get(GCPUContext &ctx, int idx) { return get_in::get(ctx, idx); } +}; +template<> struct get_in +{ + static cv::Scalar get(GCPUContext &ctx, int idx) { return to_ocv(ctx.inVal(idx)); } +}; +template struct get_in > +{ + static const std::vector& get(GCPUContext &ctx, int idx) { return ctx.inArg(idx).rref(); } +}; + +//FIXME(dm): GArray/GArray conversion should be done more gracefully in the system +template<> struct get_in >: public get_in > +{ +}; + +template struct get_in +{ + static T get(GCPUContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +struct tracked_cv_mat{ + tracked_cv_mat(cv::gapi::own::Mat& m) : r{to_ocv(m)}, original_data{m.data} {} + cv::Mat r; + uchar* original_data; + + operator cv::Mat& (){ return r;} + void validate() const{ + if (r.data != original_data) + { + util::throw_error + (std::logic_error + ("OpenCV kernel output parameter was reallocated. \n" + "Incorrect meta data was provided ?")); + } + } +}; + +struct scalar_wrapper +{ + scalar_wrapper(cv::gapi::own::Scalar& s) : m_s{cv::gapi::own::to_ocv(s)}, m_org_s(s) {}; + operator cv::Scalar& () { return m_s; } + void writeBack() const { m_org_s = to_own(m_s); } + + cv::Scalar m_s; + cv::gapi::own::Scalar& m_org_s; +}; + +template +void postprocess(Outputs&... outs) +{ + struct + { + void operator()(tracked_cv_mat* bm) { bm->validate(); } + void operator()(scalar_wrapper* sw) { sw->writeBack(); } + void operator()(...) { } + + } validate; + //dummy array to unfold parameter pack + int dummy[] = { 0, (validate(&outs), 0)... }; + cv::util::suppress_unused_warning(dummy); +} + +template struct get_out; +template<> struct get_out +{ + static tracked_cv_mat get(GCPUContext &ctx, int idx) + { + auto& r = ctx.outMatR(idx); + return {r}; + } +}; +template<> struct get_out +{ + static tracked_cv_mat get(GCPUContext &ctx, int idx) + { + return get_out::get(ctx, idx); + } +}; +template<> struct get_out +{ + static scalar_wrapper get(GCPUContext &ctx, int idx) + { + auto& s = ctx.outValR(idx); + return {s}; + } +}; +template struct get_out> +{ + static std::vector& get(GCPUContext &ctx, int idx) + { + return ctx.outVecR(idx); + } +}; + +template +struct OCVCallHelper; + +// FIXME: probably can be simplified with std::apply or analogue. +template +struct OCVCallHelper, std::tuple > +{ + template + struct call_and_postprocess + { + template + static void call(Inputs&&... ins, Outputs&&... outs) + { + //not using a std::forward on outs is deliberate in order to + //cause compilation error, by trying to bind rvalue references to lvalue references + Impl::run(std::forward(ins)..., outs...); + postprocess(outs...); + } + }; + + template + static void call_impl(GCPUContext &ctx, detail::Seq, detail::Seq) + { + //Make sure that OpenCV kernels do not reallocate memory for output parameters + //by comparing it's state (data ptr) before and after the call. + //This is done by converting each output Mat into tracked_cv_mat object, and binding + //them to parameters of ad-hoc function + //Convert own::Scalar to cv::Scalar before call kernel and run kernel + //convert cv::Scalar to own::Scalar after call kernel and write back results + call_and_postprocess::get(ctx, IIs))...>::call(get_in::get(ctx, IIs)..., get_out::get(ctx, OIs)...); + } + + static void call(GCPUContext &ctx) + { + call_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +} // namespace detail + +template +class GCPUKernelImpl: public cv::detail::OCVCallHelper, + public cv::detail::KernelTag +{ + using P = detail::OCVCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::cpu::backend(); } + static cv::GCPUKernel kernel() { return GCPUKernel(&P::call); } +}; + +#define GAPI_OCV_KERNEL(Name, API) struct Name: public cv::GCPUKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GCPUKERNEL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/imgproc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/imgproc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0b96db08ae18b308ccef80d785a5e002b099b84f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/cpu/imgproc.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CPU_IMGPROC_API_HPP +#define OPENCV_GAPI_CPU_IMGPROC_API_HPP + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace imgproc { +namespace cpu { + +GAPI_EXPORTS GKernelPackage kernels(); + +} // namespace cpu +} // namespace imgproc +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_CPU_IMGPROC_API_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8c21f5760acd1a2951333c448d30e268b78944f1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/core.hpp @@ -0,0 +1,20 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_CORE_HPP +#define OPENCV_GAPI_FLUID_CORE_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { namespace gapi { namespace core { namespace fluid { + +GAPI_EXPORTS GKernelPackage kernels(); + +}}}} + +#endif // OPENCV_GAPI_FLUID_CORE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/gfluidbuffer.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/gfluidbuffer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a5dd4a6f89aab7bc198d271e8944856364abc988 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/gfluidbuffer.hpp @@ -0,0 +1,154 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_BUFFER_HPP +#define OPENCV_GAPI_FLUID_BUFFER_HPP + +#include +#include // accumulate +#include // ostream +#include // uint8_t + +#include +#include +#include + +#include +#include +#include + +namespace cv { +namespace gapi { +namespace fluid { + +struct Border +{ +#if !defined(GAPI_STANDALONE) + // This constructor is required to support existing kernels which are part of G-API + Border(int _type, cv::Scalar _val) : type(_type), value(to_own(_val)) {}; +#endif // !defined(GAPI_STANDALONE) + Border(int _type, cv::gapi::own::Scalar _val) : type(_type), value(_val) {}; + int type; + cv::gapi::own::Scalar value; +}; + +using BorderOpt = util::optional; + +bool operator == (const Border& b1, const Border& b2); + +class GAPI_EXPORTS Buffer; + +class GAPI_EXPORTS View +{ +public: + struct Cache + { + std::vector m_linePtrs; + GMatDesc m_desc; + int m_border_size = 0; + + inline const uint8_t* linePtr(int index) const + { + // "out_of_window" check: + // user must not request the lines which are outside of specified kernel window + GAPI_DbgAssert(index >= -m_border_size + && index < -m_border_size + static_cast(m_linePtrs.size())); + return m_linePtrs[index + m_border_size]; + } + }; + + View() = default; + + const inline uint8_t* InLineB(int index) const // -(w-1)/2...0...+(w-1)/2 for Filters + { + return m_cache->linePtr(index); + } + + template const inline T* InLine(int i) const + { + const uint8_t* ptr = this->InLineB(i); + return reinterpret_cast(ptr); + } + + inline operator bool() const { return m_priv != nullptr; } + bool ready() const; + inline int length() const { return m_cache->m_desc.size.width; } + int y() const; + + inline const GMatDesc& meta() const { return m_cache->m_desc; } + + class GAPI_EXPORTS Priv; // internal use only + Priv& priv(); // internal use only + const Priv& priv() const; // internal use only + + View(Priv* p); + +private: + std::shared_ptr m_priv; + const Cache* m_cache; +}; + +class GAPI_EXPORTS Buffer +{ +public: + struct Cache + { + std::vector m_linePtrs; + GMatDesc m_desc; + }; + + // Default constructor (executable creation stage, + // all following initialization performed in Priv::init()) + Buffer(); + // Scratch constructor (user kernels) + Buffer(const cv::GMatDesc &desc); + + // Constructor for intermediate buffers (for tests) + Buffer(const cv::GMatDesc &desc, + int max_line_consumption, int border_size, + int skew, + int wlpi, + BorderOpt border); + // Constructor for in/out buffers (for tests) + Buffer(const cv::gapi::own::Mat &data, bool is_input); + + inline uint8_t* OutLineB(int index = 0) + { + return m_cache->m_linePtrs[index]; + } + + template inline T* OutLine(int index = 0) + { + uint8_t* ptr = this->OutLineB(index); + return reinterpret_cast(ptr); + } + + int y() const; + + int linesReady() const; + void debug(std::ostream &os) const; + inline int length() const { return m_cache->m_desc.size.width; } + int lpi() const; // LPI for WRITER + + inline const GMatDesc& meta() const { return m_cache->m_desc; } + + View mkView(int borderSize, bool ownStorage); + + class GAPI_EXPORTS Priv; // internal use only + Priv& priv(); // internal use only + const Priv& priv() const; // internal use only + +private: + std::shared_ptr m_priv; + const Cache* m_cache; +}; + +} // namespace cv::gapi::fluid +} // namespace cv::gapi +} // namespace cv + +#endif // OPENCV_GAPI_FLUID_BUFFER_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/gfluidkernel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/gfluidkernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4c6b913561308395a8a21d7daa410763848fc612 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/gfluidkernel.hpp @@ -0,0 +1,439 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_KERNEL_HPP +#define OPENCV_GAPI_FLUID_KERNEL_HPP + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +// FIXME: namespace scheme for backends? +namespace cv { + +namespace gapi +{ +namespace fluid +{ + /** + * \addtogroup gapi_std_backends G-API Standard Backends + * @{ + */ + /** + * @brief Get a reference to Fluid backend. + * + * @sa gapi_std_backends + */ + GAPI_EXPORTS cv::gapi::GBackend backend(); + /** @} */ +} // namespace flud +} // namespace gapi + + +class GAPI_EXPORTS GFluidKernel +{ +public: + enum class Kind + { + Filter, + Resize, + YUV420toRGB //Color conversion of 4:2:0 chroma sub-sampling formats (NV12, I420 ..etc) to RGB + }; + + // This function is a generic "doWork" callback + using F = std::function &)>; + + // This function is a generic "initScratch" callback + using IS = std::function; + + // This function is a generic "resetScratch" callback + using RS = std::function; + + // This function describes kernel metadata inference rule. + using M = std::function; + + // This function is a generic "getBorder" callback (extracts border-related data from kernel's input parameters) + using B = std::function; + + // This function is a generic "getWindow" callback (extracts window-related data from kernel's input parameters) + using GW = std::function; + + // FIXME: move implementations out of header file + GFluidKernel() {} + GFluidKernel(Kind k, int l, bool scratch, const F& f, const IS &is, const RS &rs, const B& b, const GW& win) + : m_kind(k) + , m_lpi(l) + , m_scratch(scratch) + , m_f(f) + , m_is(is) + , m_rs(rs) + , m_b(b) + , m_gw(win) {} + + Kind m_kind; + const int m_lpi = -1; + const bool m_scratch = false; + + const F m_f; + const IS m_is; + const RS m_rs; + const B m_b; + const GW m_gw; +}; + +// FIXME!!! +// This is the temporary and experimental API +// which should be replaced by runtime roi-based scheduling +/** \addtogroup gapi_compile_args + * @{ + */ +/** + * @brief This structure allows to control the output image region + * which Fluid backend will produce in the graph. + * + * This feature is useful for external tiling and parallelism, but + * will be deprecated in the future releases. + */ +struct GFluidOutputRois +{ + std::vector rois; +}; + +/** + * @brief This structure forces Fluid backend to generate multiple + * parallel output regions in the graph. These regions execute in parallel. + * + * This feature may be deprecated in the future releases. + */ +struct GFluidParallelOutputRois +{ + std::vector parallel_rois; +}; + +/** + * @brief This structure allows to customize the way how Fluid executes + * parallel regions. + * + * For example, user can utilize his own threading runtime via this parameter. + * The `parallel_for` member functor is called by the Fluid runtime with the + * following arguments: + * + * @param size Size of the parallel range to process + * @param f A function which should be called for every integer index + * in this range by the specified parallel_for implementation. + * + * This feature may be deprecated in the future releases. + */ +struct GFluidParallelFor +{ + //this function accepts: + // - size of the "parallel" range as the first argument + // - and a function to be called on the range items, designated by item index + std::function)> parallel_for; +}; +/** @} gapi_compile_args */ + +namespace detail +{ +template<> struct CompileArgTag +{ + static const char* tag() { return "gapi.fluid.outputRois"; } +}; + +template<> struct CompileArgTag +{ + static const char* tag() { return "gapi.fluid.parallelFor"; } +}; + +template<> struct CompileArgTag +{ + static const char* tag() { return "gapi.fluid.parallelOutputRois"; } +}; + +} // namespace detail + +namespace detail +{ +template struct fluid_get_in; +template<> struct fluid_get_in +{ + static const cv::gapi::fluid::View& get(const cv::GArgs &in_args, int idx) + { + return in_args[idx].unsafe_get(); + } +}; + +template<> struct fluid_get_in +{ + // FIXME: change to return by reference when moved to own::Scalar +#if !defined(GAPI_STANDALONE) + static const cv::Scalar get(const cv::GArgs &in_args, int idx) + { + return cv::gapi::own::to_ocv(in_args[idx].unsafe_get()); + } +#else + static const cv::gapi::own::Scalar get(const cv::GArgs &in_args, int idx) + { + return in_args[idx].get(); + } +#endif // !defined(GAPI_STANDALONE) +}; + +template struct fluid_get_in> +{ + static const std::vector& get(const cv::GArgs &in_args, int idx) + { + return in_args.at(idx).unsafe_get().rref(); + } +}; + +template struct fluid_get_in +{ + static const T& get(const cv::GArgs &in_args, int idx) + { + return in_args[idx].unsafe_get(); + } +}; + +template +struct scratch_helper; + +template +struct scratch_helper +{ + // Init + template + static void help_init_impl(const cv::GMetaArgs &metas, + const cv::GArgs &in_args, + gapi::fluid::Buffer &scratch_buf, + detail::Seq) + { + Impl::initScratch(get_in_meta(metas, in_args, IIs)..., scratch_buf); + } + + static void help_init(const cv::GMetaArgs &metas, + const cv::GArgs &in_args, + gapi::fluid::Buffer &b) + { + help_init_impl(metas, in_args, b, typename detail::MkSeq::type()); + } + + // Reset + static void help_reset(gapi::fluid::Buffer &b) + { + Impl::resetScratch(b); + } +}; + +template +struct scratch_helper +{ + static void help_init(const cv::GMetaArgs &, + const cv::GArgs &, + gapi::fluid::Buffer &) + { + GAPI_Assert(false); + } + static void help_reset(gapi::fluid::Buffer &) + { + GAPI_Assert(false); + } +}; + +template struct is_gmat_type +{ + static const constexpr bool value = std::is_same::value; +}; + +template +struct get_border_helper; + +template +struct get_border_helper +{ + template + static gapi::fluid::BorderOpt get_border_impl(const GMetaArgs &metas, + const cv::GArgs &in_args, + cv::detail::Seq) + { + return util::make_optional(Impl::getBorder(cv::detail::get_in_meta(metas, in_args, IIs)...)); + } + + static gapi::fluid::BorderOpt help(const GMetaArgs &metas, + const cv::GArgs &in_args) + { + return get_border_impl(metas, in_args, typename detail::MkSeq::type()); + } +}; + +template +struct get_border_helper +{ + static gapi::fluid::BorderOpt help(const cv::GMetaArgs &, + const cv::GArgs &) + { + return {}; + } +}; + +template +struct get_window_helper; + +template +struct get_window_helper +{ + template + static int get_window_impl(const GMetaArgs &metas, + const cv::GArgs &in_args, + cv::detail::Seq) + { + return Impl::getWindow(cv::detail::get_in_meta(metas, in_args, IIs)...); + } + + static int help(const GMetaArgs &metas, const cv::GArgs &in_args) + { + return get_window_impl(metas, in_args, typename detail::MkSeq::type()); + } +}; + +template +struct get_window_helper +{ + static int help(const cv::GMetaArgs &, + const cv::GArgs &) + { + return Impl::Window; + } +}; + +template +struct has_Window +{ +private: + template + static constexpr auto Check(U*) -> typename std::is_same::type; + + template + static constexpr std::false_type Check(...); + + typedef decltype(Check(0)) Result; + +public: + static constexpr bool value = Result::value; +}; + +template +struct callCustomGetBorder; + +template +struct callCustomGetBorder +{ + static constexpr bool value = (Impl::Window != 1); +}; + +template +struct callCustomGetBorder +{ + static constexpr bool value = true; +}; + +template +struct FluidCallHelper; + +template +struct FluidCallHelper, std::tuple, UseScratch> +{ + static_assert(all_satisfy::value, "return type must be GMat"); + static_assert(contains::value, "input must contain at least one GMat"); + + // Execution dispatcher //////////////////////////////////////////////////// + template + static void call_impl(const cv::GArgs &in_args, + const std::vector &out_bufs, + detail::Seq, + detail::Seq) + { + Impl::run(fluid_get_in::get(in_args, IIs)..., *out_bufs[OIs]...); + } + + static void call(const cv::GArgs &in_args, + const std::vector &out_bufs) + { + constexpr int numOuts = (sizeof...(Outs)) + (UseScratch ? 1 : 0); + call_impl(in_args, out_bufs, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } + + // Scratch buffer initialization dispatcher //////////////////////////////// + static void init_scratch(const GMetaArgs &metas, + const cv::GArgs &in_args, + gapi::fluid::Buffer &b) + { + scratch_helper::help_init(metas, in_args, b); + } + + // Scratch buffer reset dispatcher ///////////////////////////////////////// + static void reset_scratch(gapi::fluid::Buffer &scratch_buf) + { + scratch_helper::help_reset(scratch_buf); + } + + static gapi::fluid::BorderOpt getBorder(const GMetaArgs &metas, const cv::GArgs &in_args) + { + constexpr bool hasWindow = has_Window::value; + + // User must provide "init" callback if Window != 1 + // TODO: move to constexpr if when we enable C++17 + return get_border_helper::value, Impl, Ins...>::help(metas, in_args); + } + + static int getWindow(const GMetaArgs &metas, const cv::GArgs &in_args) + { + constexpr bool callCustomGetWindow = !(has_Window::value); + return get_window_helper::help(metas, in_args); + } +}; +} // namespace detail + + +template +class GFluidKernelImpl : public cv::detail::KernelTag +{ + static const int LPI = 1; + static const auto Kind = GFluidKernel::Kind::Filter; + using P = detail::FluidCallHelper; + +public: + using API = K; + + static GFluidKernel kernel() + { + // FIXME: call() and getOutMeta() needs to be renamed so it is clear these + // functions are internal wrappers, not user API + return GFluidKernel(Impl::Kind, Impl::LPI, + UseScratch, + &P::call, &P::init_scratch, &P::reset_scratch, &P::getBorder, &P::getWindow); + } + + static cv::gapi::GBackend backend() { return cv::gapi::fluid::backend(); } +}; + +#define GAPI_FLUID_KERNEL(Name, API, Scratch) struct Name: public cv::GFluidKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GCPUKERNEL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/imgproc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/imgproc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dedfa9dbe1e99d01782995b257fccc030f47c8d0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/fluid/imgproc.hpp @@ -0,0 +1,20 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_FLUID_IMGPROC_HPP +#define OPENCV_GAPI_FLUID_IMGPROC_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { namespace gapi { namespace imgproc { namespace fluid { + +GAPI_EXPORTS GKernelPackage kernels(); + +}}}} + +#endif // OPENCV_GAPI_FLUID_IMGPROC_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/garg.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/garg.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9b835d9567302b89799aab9f1c01c94348cbafee --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/garg.hpp @@ -0,0 +1,147 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GARG_HPP +#define OPENCV_GAPI_GARG_HPP + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace cv { + +class GArg; + +namespace detail { + template + using is_garg = std::is_same::type>; +} + +// Parameter holder class for a node +// Depending on platform capabilities, can either support arbitrary types +// (as `boost::any`) or a limited number of types (as `boot::variant`). +// FIXME: put into "details" as a user shouldn't use it in his code +class GAPI_EXPORTS GArg +{ +public: + GArg() {} + + template::value, int>::type = 0> + explicit GArg(const T &t) + : kind(detail::GTypeTraits::kind) + , value(detail::wrap_gapi_helper::wrap(t)) + { + } + + template::value, int>::type = 0> + explicit GArg(T &&t) + : kind(detail::GTypeTraits::type>::kind) + , value(detail::wrap_gapi_helper::wrap(t)) + { + } + + template inline T& get() + { + return util::any_cast::type>(value); + } + + template inline const T& get() const + { + return util::any_cast::type>(value); + } + + template inline T& unsafe_get() + { + return util::unsafe_any_cast::type>(value); + } + + template inline const T& unsafe_get() const + { + return util::unsafe_any_cast::type>(value); + } + + detail::ArgKind kind = detail::ArgKind::OPAQUE_VAL; + +protected: + util::any value; +}; + +using GArgs = std::vector; + +// FIXME: Express as M::type +// FIXME: Move to a separate file! +using GRunArg = util::variant< +#if !defined(GAPI_STANDALONE) + cv::Mat, + cv::Scalar, + cv::UMat, +#endif // !defined(GAPI_STANDALONE) + cv::gapi::wip::IStreamSource::Ptr, + cv::gapi::own::Mat, + cv::gapi::own::Scalar, + cv::detail::VectorRef + >; +using GRunArgs = std::vector; + +namespace gapi +{ +namespace wip +{ +/** + * @brief This aggregate type represents all types which G-API can handle (via variant). + * + * It only exists to overcome C++ language limitations (where a `using`-defined class can't be forward-declared). + */ +struct Data: public GRunArg +{ + using GRunArg::GRunArg; + template + Data& operator= (const T& t) { GRunArg::operator=(t); return *this; } + template + Data& operator= (T&& t) { GRunArg::operator=(std::move(t)); return *this; } +}; +} // namespace wip +} // namespace gapi + +using GRunArgP = util::variant< +#if !defined(GAPI_STANDALONE) + cv::Mat*, + cv::Scalar*, + cv::UMat*, +#endif // !defined(GAPI_STANDALONE) + cv::gapi::own::Mat*, + cv::gapi::own::Scalar*, + cv::detail::VectorRef + >; +using GRunArgsP = std::vector; + +template inline GRunArgs gin(const Ts&... args) +{ + return GRunArgs{ GRunArg(detail::wrap_host_helper::wrap_in(args))... }; +} + +template inline GRunArgsP gout(Ts&... args) +{ + return GRunArgsP{ GRunArgP(detail::wrap_host_helper::wrap_out(args))... }; +} + +} // namespace cv + +#endif // OPENCV_GAPI_GARG_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/garray.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/garray.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b989071e0e7a2f61477d9e61d91f53fa30d213fa --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/garray.hpp @@ -0,0 +1,319 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GARRAY_HPP +#define OPENCV_GAPI_GARRAY_HPP + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include // flatten_g only! +#include // flatten_g only! + +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; + +template class GArray; + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GArrayDesc +{ + // FIXME: Body + // FIXME: Also implement proper operator== then + bool operator== (const GArrayDesc&) const { return true; } +}; +template GArrayDesc descr_of(const std::vector &) { return {};} +static inline GArrayDesc empty_array_desc() {return {}; } +/** @} */ + +std::ostream& operator<<(std::ostream& os, const cv::GArrayDesc &desc); + +namespace detail +{ + // ConstructVec is a callback which stores information about T and is used by + // G-API runtime to construct arrays in host memory (T remains opaque for G-API). + // ConstructVec is carried into G-API internals by GArrayU. + // Currently it is suitable for Host (CPU) plugins only, real offload may require + // more information for manual memory allocation on-device. + class VectorRef; + using ConstructVec = std::function; + + // This is the base struct for GArrayU type holder + struct TypeHintBase{virtual ~TypeHintBase() = default;}; + + // This class holds type of initial GArray to be checked from GArrayU + template + struct TypeHint final : public TypeHintBase{}; + + // This class strips type information from GArray and makes it usable + // in the G-API graph compiler (expression unrolling, graph generation, etc). + // Part of GProtoArg. + class GAPI_EXPORTS GArrayU + { + public: + GArrayU(const GNode &n, std::size_t out); // Operation result constructor + + template + bool holds() const; // Check if was created from GArray + + GOrigin& priv(); // Internal use only + const GOrigin& priv() const; // Internal use only + + protected: + GArrayU(); // Default constructor + template friend class cv::GArray; // (available to GArray only) + + void setConstructFcn(ConstructVec &&cv); // Store T-aware constructor + + template + void specifyType(); // Store type of initial GArray + + std::shared_ptr m_priv; + std::shared_ptr m_hint; + }; + + template + bool GArrayU::holds() const{ + GAPI_Assert(m_hint != nullptr); + using U = typename std::decay::type; + return dynamic_cast*>(m_hint.get()) != nullptr; + }; + + template + void GArrayU::specifyType(){ + m_hint.reset(new TypeHint::type>); + }; + + // This class represents a typed STL vector reference. + // Depending on origins, this reference may be either "just a" reference to + // an object created externally, OR actually own the underlying object + // (be value holder). + class BasicVectorRef + { + public: + std::size_t m_elemSize = 0ul; + cv::GArrayDesc m_desc; + virtual ~BasicVectorRef() {} + + virtual void mov(BasicVectorRef &ref) = 0; + }; + + template class VectorRefT final: public BasicVectorRef + { + using empty_t = util::monostate; + using ro_ext_t = const std::vector *; + using rw_ext_t = std::vector *; + using rw_own_t = std::vector ; + util::variant m_ref; + + inline bool isEmpty() const { return util::holds_alternative(m_ref); } + inline bool isROExt() const { return util::holds_alternative(m_ref); } + inline bool isRWExt() const { return util::holds_alternative(m_ref); } + inline bool isRWOwn() const { return util::holds_alternative(m_ref); } + + void init(const std::vector* vec = nullptr) + { + m_elemSize = sizeof(T); + if (vec) m_desc = cv::descr_of(*vec); + } + + public: + VectorRefT() { init(); } + virtual ~VectorRefT() {} + + explicit VectorRefT(const std::vector& vec) : m_ref(&vec) { init(&vec); } + explicit VectorRefT(std::vector& vec) : m_ref(&vec) { init(&vec); } + explicit VectorRefT(std::vector&& vec) : m_ref(std::move(vec)) { init(&vec); } + + // Reset a VectorRefT. Called only for objects instantiated + // internally in G-API (e.g. temporary GArray's within a + // computation). Reset here means both initialization + // (creating an object) and reset (discarding its existing + // content before the next execution). Must never be called + // for external VectorRefTs. + void reset() + { + if (isEmpty()) + { + std::vector empty_vector; + m_desc = cv::descr_of(empty_vector); + m_ref = std::move(empty_vector); + GAPI_Assert(isRWOwn()); + } + else if (isRWOwn()) + { + util::get(m_ref).clear(); + } + else GAPI_Assert(false); // shouldn't be called in *EXT modes + } + + // Obtain a WRITE reference to underlying object + // Used by CPU kernel API wrappers when a kernel execution frame + // is created + std::vector& wref() + { + GAPI_Assert(isRWExt() || isRWOwn()); + if (isRWExt()) return *util::get(m_ref); + if (isRWOwn()) return util::get(m_ref); + util::throw_error(std::logic_error("Impossible happened")); + } + + // Obtain a READ reference to underlying object + // Used by CPU kernel API wrappers when a kernel execution frame + // is created + const std::vector& rref() const + { + // ANY vector can be accessed for reading, even if it declared for + // output. Example -- a GComputation from [in] to [out1,out2] + // where [out2] is a result of operation applied to [out1]: + // + // GComputation boundary + // . . . . . . . + // . . + // [in] ----> foo() ----> [out1] + // . . : + // . . . .:. . . + // . V . + // . bar() ---> [out2] + // . . . . . . . . . . . . + // + if (isROExt()) return *util::get(m_ref); + if (isRWExt()) return *util::get(m_ref); + if (isRWOwn()) return util::get(m_ref); + util::throw_error(std::logic_error("Impossible happened")); + } + + virtual void mov(BasicVectorRef &v) override { + VectorRefT *tv = dynamic_cast*>(&v); + GAPI_Assert(tv != nullptr); + wref() = std::move(tv->wref()); + } + }; + + // This class strips type information from VectorRefT<> and makes it usable + // in the G-API executables (carrying run-time data/information to kernels). + // Part of GRunArg. + // Its methods are typed proxies to VectorRefT. + // VectorRef maintains "reference" semantics so two copies of VectoRef refer + // to the same underlying object. + // FIXME: Put a good explanation on why cv::OutputArray doesn't fit this role + class VectorRef + { + std::shared_ptr m_ref; + + template inline void check() const + { + GAPI_DbgAssert(dynamic_cast*>(m_ref.get()) != nullptr); + GAPI_Assert(sizeof(T) == m_ref->m_elemSize); + } + + public: + VectorRef() = default; + template explicit VectorRef(const std::vector& vec) : m_ref(new VectorRefT(vec)) {} + template explicit VectorRef(std::vector& vec) : m_ref(new VectorRefT(vec)) {} + template explicit VectorRef(std::vector&& vec) : m_ref(new VectorRefT(vec)) {} + + template void reset() + { + if (!m_ref) m_ref.reset(new VectorRefT()); + + check(); + static_cast&>(*m_ref).reset(); + } + + template std::vector& wref() + { + check(); + return static_cast&>(*m_ref).wref(); + } + + template const std::vector& rref() const + { + check(); + return static_cast&>(*m_ref).rref(); + } + + void mov(VectorRef &v) + { + m_ref->mov(*v.m_ref); + } + + cv::GArrayDesc descr_of() const + { + return m_ref->m_desc; + } + }; + + // Helper (FIXME: work-around?) + // stripping G types to their host types + // like cv::GArray would still map to std::vector + // but not to std::vector +#if defined(GAPI_STANDALONE) +# define FLATTEN_NS cv::gapi::own +#else +# define FLATTEN_NS cv +#endif + template struct flatten_g; + template<> struct flatten_g { using type = FLATTEN_NS::Mat; }; + template<> struct flatten_g { using type = FLATTEN_NS::Scalar; }; + template struct flatten_g { using type = T; }; +#undef FLATTEN_NS + // FIXME: the above mainly duplicates "ProtoToParam" thing from gtyped.hpp + // but I decided not to include gtyped here - probably worth moving that stuff + // to some common place? (DM) +} // namespace detail + +/** \addtogroup gapi_data_objects + * @{ + */ + +template class GArray +{ +public: + GArray() { putDetails(); } // Empty constructor + explicit GArray(detail::GArrayU &&ref) // GArrayU-based constructor + : m_ref(ref) { putDetails(); } // (used by GCall, not for users) + + detail::GArrayU strip() const { return m_ref; } + +private: + // Host type (or Flat type) - the type this GArray is actually + // specified to. + using HT = typename detail::flatten_g::type>::type; + + static void VCTor(detail::VectorRef& vref) { + vref.reset(); + } + void putDetails() { + m_ref.setConstructFcn(&VCTor); + m_ref.specifyType(); + } + + detail::GArrayU m_ref; +}; + +/** @} */ + +} // namespace cv + +#endif // OPENCV_GAPI_GARRAY_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gasync_context.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gasync_context.hpp new file mode 100644 index 0000000000000000000000000000000000000000..69ce530fc93bbfdd36a8d2c743d68c8237f2e6fe --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gasync_context.hpp @@ -0,0 +1,56 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_GASYNC_CONTEXT_HPP +#define OPENCV_GAPI_GASYNC_CONTEXT_HPP + +#if !defined(GAPI_STANDALONE) +# include +#else // Without OpenCV +# include +#endif // !defined(GAPI_STANDALONE) + +#include + +namespace cv { +namespace gapi{ +namespace wip { + +/** + * @brief A class to group async requests to cancel them in a single shot. + * + * GAsyncContext is passed as an argument to async() and async_apply() functions + */ + +class GAPI_EXPORTS GAsyncContext{ + std::atomic cancelation_requested = {false}; +public: + /** + * @brief Start cancellation process for an associated request. + * + * User still has to wait for each individual request (either via callback or according std::future object) to make sure it actually canceled. + * + * @return true if it was a first request to cancel the context + */ + bool cancel(); + + /** + * @brief Returns true if cancellation was requested for this context. + * + * @return true if cancellation was requested for this context + */ + bool isCanceled() const; +}; + +class GAPI_EXPORTS GAsyncCanceled : public std::exception { +public: + virtual const char* what() const noexcept CV_OVERRIDE; +}; +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif //OPENCV_GAPI_GASYNC_CONTEXT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcall.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcall.hpp new file mode 100644 index 0000000000000000000000000000000000000000..87cba529711d5ca6ac98910f9d9ac897f18e0554 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcall.hpp @@ -0,0 +1,64 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GCALL_HPP +#define OPENCV_GAPI_GCALL_HPP + +#include // GArg +#include // GMat +#include // GScalar +#include // GArray + +namespace cv { + +struct GKernel; + +// The whole idea of this class is to represent an operation +// which is applied to arguments. This is part of public API, +// since it is what users should use to define kernel interfaces. + +class GAPI_EXPORTS GCall final +{ +public: + class Priv; + + explicit GCall(const GKernel &k); + ~GCall(); + + template + GCall& pass(Ts&&... args) + { + setArgs({cv::GArg(std::move(args))...}); + return *this; + } + + // A generic yield method - obtain a link to operator's particular GMat output + GMat yield (int output = 0); + GMatP yieldP (int output = 0); + GScalar yieldScalar(int output = 0); + + template GArray yieldArray(int output = 0) + { + return GArray(yieldArray(output)); + } + + // Internal use only + Priv& priv(); + const Priv& priv() const; + +protected: + std::shared_ptr m_priv; + + void setArgs(std::vector &&args); + + // Public version returns a typed array, this one is implementation detail + detail::GArrayU yieldArray(int output = 0); +}; + +} // namespace cv + +#endif // OPENCV_GAPI_GCALL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcommon.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcommon.hpp new file mode 100644 index 0000000000000000000000000000000000000000..40c6d36af00067d56c2275d0178eb8208c4f04e1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcommon.hpp @@ -0,0 +1,168 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMMON_HPP +#define OPENCV_GAPI_GCOMMON_HPP + +#include // std::hash +#include // std::vector +#include // decay + +#include + +#include +#include +#include + +namespace cv { + +namespace detail +{ + // This is a trait-like structure to mark backend-specific compile arguments + // with tags + template struct CompileArgTag; + + // These structures are tags which separate kernels and transformations + struct KernelTag + {}; + struct TransformTag + {}; +} + +// This definition is here because it is reused by both public(?) and internal +// modules. Keeping it here wouldn't expose public details (e.g., API-level) +// to components which are internal and operate on a lower-level entities +// (e.g., compiler, backends). +// FIXME: merge with ArgKind? +// FIXME: replace with variant[format desc]? +enum class GShape: int +{ + GMAT, + GSCALAR, + GARRAY, +}; + +struct GCompileArg; + +namespace detail { + template + using is_compile_arg = std::is_same::type>; +} +// CompileArg is an unified interface over backend-specific compilation +// information +// FIXME: Move to a separate file? +/** \addtogroup gapi_compile_args + * @{ + * + * @brief Compilation arguments: data structures controlling the + * compilation process + * + * G-API comes with a number of graph compilation options which can be + * passed to cv::GComputation::apply() or + * cv::GComputation::compile(). Known compilation options are listed + * in this page, while extra backends may introduce their own + * compilation options (G-API transparently accepts _everything_ which + * can be passed to cv::compile_args(), it depends on underlying + * backends if an option would be interpreted or not). + * + * For example, if an example computation is executed like this: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_decl_apply + * + * Extra parameter specifying which kernels to compile with can be + * passed like this: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp apply_with_param + */ + +/** + * @brief Represents an arbitrary compilation argument. + * + * Any value can be wrapped into cv::GCompileArg, but only known ones + * (to G-API or its backends) can be interpreted correctly. + * + * Normally objects of this class shouldn't be created manually, use + * cv::compile_args() function which automatically wraps everything + * passed in (a variadic template parameter pack) into a vector of + * cv::GCompileArg objects. + */ +struct GAPI_EXPORTS GCompileArg +{ +public: + std::string tag; + + // FIXME: use decay in GArg/other trait-based wrapper before leg is shot! + template::value, int>::type = 0> + explicit GCompileArg(T &&t) + : tag(detail::CompileArgTag::type>::tag()) + , arg(t) + { + } + + template T& get() + { + return util::any_cast(arg); + } + + template const T& get() const + { + return util::any_cast(arg); + } + +private: + util::any arg; +}; + +using GCompileArgs = std::vector; + +/** + * Wraps a list of arguments (a parameter pack) into a vector of + * compilation arguments (cv::GCompileArg). + */ +template GCompileArgs compile_args(Ts&&... args) +{ + return GCompileArgs{ GCompileArg(args)... }; +} + +/** + * @brief Ask G-API to dump compiled graph in Graphviz format under + * the given file name. + * + * Specifies a graph dump path (path to .dot file to be generated). + * G-API will dump a .dot file under specified path during a + * compilation process if this flag is passed. + */ +struct graph_dump_path +{ + std::string m_dump_path; +}; +/** @} */ + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.graph_dump_path"; } + }; +} + +} // namespace cv + +// std::hash overload for GShape +namespace std +{ +template<> struct hash +{ + size_t operator() (cv::GShape sh) const + { + return std::hash()(static_cast(sh)); + } +}; +} // namespace std + + +#endif // OPENCV_GAPI_GCOMMON_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompiled.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompiled.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0a411126c9fa46dcc99b54983d21ef5063a769fe --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompiled.hpp @@ -0,0 +1,219 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPILED_HPP +#define OPENCV_GAPI_GCOMPILED_HPP + +#include + +#include +#include +#include + +namespace cv { + +// This class represents a compiled computation. +// In theory (and ideally), it can be used w/o the rest of APIs. +// In theory (and ideally), it can be serialized/deserialized. +// It can enable scenarious like deployment to an autonomous devince, FuSa, etc. +// +// Currently GCompiled assumes all GMats you used to pass data to G-API +// are valid and not destroyed while you use a GCompiled object. +// +// FIXME: In future, there should be a way to name I/O objects and specify it +// to GCompiled externally (for example, when it is loaded on the target system). + +/** + * \addtogroup gapi_main_classes + * @{ + */ +/** + * @brief Represents a compiled computation (graph). Can only be used + * with image / data formats & resolutions it was compiled for, with + * some exceptions. + * + * This class represents a product of graph compilation (calling + * cv::GComputation::compile()). Objects of this class actually do + * data processing, and graph execution is incapsulated into objects + * of this class. Execution model itself depends on kernels and + * backends which were using during the compilation, see @ref + * gapi_compile_args for details. + * + * In a general case, GCompiled objects can be applied to data only in + * that formats/resolutions they were compiled for (see @ref + * gapi_meta_args). However, if the underlying backends allow, a + * compiled object can be _reshaped_ to handle data (images) of + * different resolution, though formats and types must remain the same. + * + * GCompiled is very similar to `std::function<>` in its semantics -- + * running it looks like a function call in the user code. + * + * At the moment, GCompiled objects are not reentrant -- generally, + * the objects are stateful since graph execution itself is a stateful + * process and this state is now maintained in GCompiled's own memory + * (not on the process stack). + * + * At the same time, two different GCompiled objects produced from the + * single cv::GComputation are completely independent and can be used + * concurrently. + * + * @sa GStreamingCompiled + */ +class GAPI_EXPORTS GCompiled +{ +public: + /// @private + class GAPI_EXPORTS Priv; + + /** + * @brief Constructs an empty object + */ + GCompiled(); + + /** + * @brief Run the compiled computation, a generic version. + * + * @param ins vector of inputs to process. + * @param outs vector of outputs to produce. + * + * Input/output vectors must have the same number of elements as + * defined in the cv::GComputation protocol (at the moment of its + * construction). Shapes of elements also must conform to protocol + * (e.g. cv::Mat needs to be passed where cv::GMat has been + * declared as input, and so on). Run-time exception is generated + * otherwise. + * + * Objects in output vector may remain empty (like cv::Mat) -- + * G-API will automatically initialize output objects to proper formats. + * + * @note Don't construct GRunArgs/GRunArgsP objects manually, use + * cv::gin()/cv::gout() wrappers instead. + */ + void operator() (GRunArgs &&ins, GRunArgsP &&outs); // Generic arg-to-arg +#if !defined(GAPI_STANDALONE) + + /** + * @brief Execute an unary computation + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Mat for unary computation + * process. + */ + void operator() (cv::Mat in, cv::Mat &out); // Unary overload + + /** + * @brief Execute an unary computation + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Scalar for unary computation + * process. + */ + void operator() (cv::Mat in, cv::Scalar &out); // Unary overload (scalar) + + /** + * @brief Execute a binary computation + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Mat for binary computation + * process. + */ + void operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out); // Binary overload + + /** + * @brief Execute an binary computation + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Scalar for binary computation + * process. + */ + void operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out); // Binary overload (scalar) + + /** + * @brief Execute a computation with arbitrary number of + * inputs/outputs. + * + * @overload + * @param ins vector of input cv::Mat objects to process by the + * computation. + * @param outs vector of output cv::Mat objects to produce by the + * computation. + * + * Numbers of elements in ins/outs vectos must match numbers of + * inputs/outputs which were used to define the source GComputation. + */ + void operator() (const std::vector &ins, // Compatibility overload + const std::vector &outs); +#endif // !defined(GAPI_STANDALONE) + /// @private + Priv& priv(); + + /** + * @brief Check if compiled object is valid (non-empty) + * + * @return true if the object is runnable (valid), false otherwise + */ + explicit operator bool () const; + + /** + * @brief Vector of metadata this graph was compiled for. + * + * @return Unless _reshape_ is not supported, return value is the + * same vector which was passed to cv::GComputation::compile() to + * produce this compiled object. Otherwise, it is the latest + * metadata vector passed to reshape() (if that call was + * successful). + */ + const GMetaArgs& metas() const; // Meta passed to compile() + + /** + * @brief Vector of metadata descriptions of graph outputs + * + * @return vector with formats/resolutions of graph's output + * objects, auto-inferred from input metadata vector by + * operations which form this computation. + * + * @note GCompiled objects produced from the same + * cv::GComputiation graph with different input metas may return + * different values in this vector. + */ + const GMetaArgs& outMetas() const; + + /** + * @brief Check if the underlying backends support reshape or not. + * + * @return true if supported, false otherwise. + */ + bool canReshape() const; + + /** + * @brief Reshape a compiled graph to support new image + * resolutions. + * + * Throws an exception if an error occurs. + * + * @param inMetas new metadata to reshape on. Vector size and + * metadata shapes must match the computation's protocol. + * @param args compilation arguments to use. + */ + // FIXME: Why it requires compile args? + void reshape(const GMetaArgs& inMetas, const GCompileArgs& args); + +protected: + /// @private + std::shared_ptr m_priv; +}; +/** @} */ + +} + +#endif // OPENCV_GAPI_GCOMPILED_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompiled_async.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompiled_async.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a0c2917d6a85b84c4c275a5bf7fed7d9918a438f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompiled_async.hpp @@ -0,0 +1,73 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPILED_ASYNC_HPP +#define OPENCV_GAPI_GCOMPILED_ASYNC_HPP + +#include //for std::future +#include //for std::exception_ptr +#include //for std::function +#include +#include + +namespace cv { + //fwd declaration + class GCompiled; + +namespace gapi{ +namespace wip { + class GAsyncContext; + /** + These functions asynchronously (i.e. probably on a separate thread of execution) call GCompiled::operator() member function of their first argument with copies of rest of arguments (except callback) passed in. + The difference between the function is the way to get the completion notification (via callback or a waiting on std::future object) + If exception is occurred during execution of apply it is transferred to the callback (via function parameter) or passed to future (and will be thrown on call to std::future::get) + + N.B. : + Input arguments are copied on call to async function (actually on call to cv::gin) and thus do not have to outlive the actual completion of asynchronous activity. + While output arguments are "captured" by reference(pointer) and therefore _must_ outlive the asynchronous activity + (i.e. live at least until callback is called or future is unblocked) + + @param gcmpld Compiled computation (graph) to start asynchronously + @param callback Callback to be called when execution of gcmpld is done + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + */ + GAPI_EXPORTS void async(GCompiled& gcmpld, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs); + + /** @overload + @param gcmpld Compiled computation (graph) to run asynchronously + @param callback Callback to be called when execution of gcmpld is done + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + @param ctx Context this request belongs to + @see async GAsyncContext + */ + GAPI_EXPORTS void async(GCompiled& gcmpld, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx); + + /** @overload + @param gcmpld Compiled computation (graph) to run asynchronously + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + @return std::future object to wait for completion of async operation + @see async + */ + GAPI_EXPORTS std::future async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs); + + /** + @param gcmpld Compiled computation (graph) to run asynchronously + @param ins Input parameters for gcmpld + @param outs Output parameters for gcmpld + @param ctx Context this request belongs to + @return std::future object to wait for completion of async operation + @see async GAsyncContext + */ + GAPI_EXPORTS std::future async(GCompiled& gcmpld, GRunArgs &&ins, GRunArgsP &&outs, GAsyncContext& ctx); +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_GCOMPILED_ASYNC_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompoundkernel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompoundkernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..84b8780251e33c44061443ba3abf97917650ea94 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcompoundkernel.hpp @@ -0,0 +1,119 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPOUNDKERNEL_HPP +#define OPENCV_GAPI_GCOMPOUNDKERNEL_HPP + +#include +#include +#include +#include + +namespace cv { +namespace gapi +{ +namespace compound +{ + // FIXME User does not need to know about this function + // Needs that user may define compound kernels(as cpu kernels) + GAPI_EXPORTS cv::gapi::GBackend backend(); +} // namespace compound +} // namespace gapi + +namespace detail +{ + +struct GCompoundContext +{ + explicit GCompoundContext(const GArgs& in_args); + template + const T& inArg(int input) { return m_args.at(input).get(); } + + GArgs m_args; + GArgs m_results; +}; + +class GAPI_EXPORTS GCompoundKernel +{ +// Compound kernel must use all of it's inputs +public: + using F = std::function; + + explicit GCompoundKernel(const F& f); + void apply(GCompoundContext& ctx); + +protected: + F m_f; +}; + +template struct get_compound_in +{ + static T get(GCompoundContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +template struct get_compound_in> +{ + static cv::GArray get(GCompoundContext &ctx, int idx) + { + auto array = cv::GArray(); + ctx.m_args[idx] = GArg(array); + return array; + } +}; + +template +struct GCompoundCallHelper; + +template +struct GCompoundCallHelper, std::tuple > +{ + template + static void expand_impl(GCompoundContext &ctx, detail::Seq, detail::Seq) + { + auto result = Impl::expand(get_compound_in::get(ctx, IIs)...); + auto tuple_return = tuple_wrap_helper::get(std::move(result)); + ctx.m_results = { cv::GArg(std::get(tuple_return))... }; + } + + static void expand(GCompoundContext &ctx) + { + expand_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +template +class GCompoundKernelImpl: public cv::detail::GCompoundCallHelper, + public cv::detail::KernelTag +{ + using P = cv::detail::GCompoundCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::compound::backend(); } + static GCompoundKernel kernel() { return GCompoundKernel(&P::expand); } +}; + +} // namespace detail + + +/** + * Declares a new compound kernel. See this + * [documentation chapter](@ref gapi_kernel_compound) + * on compound kernels for more details. + * + * @param Name type name for new kernel + * @param API the interface this kernel implements + */ +#define GAPI_COMPOUND_KERNEL(Name, API) \ + struct Name: public cv::detail::GCompoundKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GCOMPOUNDKERNEL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcomputation.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcomputation.hpp new file mode 100644 index 0000000000000000000000000000000000000000..678b22d47c0223c925f70eb34ee9af3a850d74db --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcomputation.hpp @@ -0,0 +1,559 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GCOMPUTATION_HPP +#define OPENCV_GAPI_GCOMPUTATION_HPP + +#include + +#include +#include +#include +#include +#include +#include + +namespace cv { + +namespace detail +{ + // FIXME: move to algorithm, cover with separate tests + // FIXME: replace with O(1) version (both memory and compilation time) + template + struct last_type; + + template + struct last_type { using type = T;}; + + template + struct last_type { using type = typename last_type::type; }; + + template + using last_type_t = typename last_type::type; +} + +/** + * \addtogroup gapi_main_classes + * @{ + * + * @brief G-API classes for constructed and compiled graphs. + */ +/** + * @brief GComputation class represents a captured computation + * graph. GComputation objects form boundaries for expression code + * user writes with G-API, allowing to compile and execute it. + * + * G-API computations are defined with input/output data + * objects. G-API will track automatically which operations connect + * specified outputs to the inputs, forming up a call graph to be + * executed. The below example expresses calculation of Sobel operator + * for edge detection (\f$G = \sqrt{G_x^2 + G_y^2}\f$): + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_def + * + * Full pipeline can be now captured with this object declaration: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_cap_full + * + * Input/output data objects on which a call graph should be + * reconstructed are passed using special wrappers cv::GIn and + * cv::GOut. G-API will track automatically which operations form a + * path from inputs to outputs and build the execution graph appropriately. + * + * Note that cv::GComputation doesn't take ownership on data objects + * it is defined. Moreover, multiple GComputation objects may be + * defined on the same expressions, e.g. a smaller pipeline which + * expects that image gradients are already pre-calculated may be + * defined like this: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_cap_sub + * + * The resulting graph would expect two inputs and produce one + * output. In this case, it doesn't matter if gx/gy data objects are + * results of cv::gapi::Sobel operators -- G-API will stop unrolling + * expressions and building the underlying graph one reaching this + * data objects. + * + * The way how GComputation is defined is important as its definition + * specifies graph _protocol_ -- the way how the graph should be + * used. Protocol is defined by number of inputs, number of outputs, + * and shapes of inputs and outputs. + * + * In the above example, sobelEdge expects one Mat on input and + * produces one Mat; while sobelEdgeSub expects two Mats on input and + * produces one Mat. GComputation's protocol defines how other + * computation methods should be used -- cv::GComputation::compile() and + * cv::GComputation::apply(). For example, if a graph is defined on + * two GMat inputs, two cv::Mat objects have to be passed to apply() + * for execution. GComputation checks protocol correctness in runtime + * so passing a different number of objects in apply() or passing + * cv::Scalar instead of cv::Mat there would compile well as a C++ + * source but raise an exception in run-time. G-API also comes with a + * typed wrapper cv::GComputationT<> which introduces this type-checking in + * compile-time. + * + * cv::GComputation itself is a thin object which just captures what + * the graph is. The compiled graph (which actually process data) is + * represented by class GCompiled. Use compile() method to generate a + * compiled graph with given compile options. cv::GComputation can + * also be used to process data with implicit graph compilation + * on-the-fly, see apply() for details. + * + * GComputation is a reference-counted object -- once defined, all its + * copies will refer to the same instance. + * + * @sa GCompiled + */ +class GAPI_EXPORTS GComputation +{ +public: + class Priv; + typedef std::function Generator; + + // Various constructors enable different ways to define a computation: ///// + // 1. Generic constructors + /** + * @brief Define a computation using a generator function. + * + * Graph can be defined in-place directly at the moment of its + * construction with a lambda: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp graph_gen + * + * This may be useful since all temporary objects (cv::GMats) and + * namespaces can be localized to scope of lambda, without + * contaminating the parent scope with probably unnecessary objects + * and information. + * + * @param gen generator function which returns a cv::GComputation, + * see Generator. + */ + GComputation(const Generator& gen); // Generator + // overload + + /** + * @brief Generic GComputation constructor. + * + * Constructs a new graph with a given protocol, specified as a + * flow of operations connecting input/output objects. Throws if + * the passed boundaries are invalid, e.g. if there's no + * functional dependency (path) between given outputs and inputs. + * + * @param ins Input data vector. + * @param outs Output data vector. + * + * @note Don't construct GProtoInputArgs/GProtoOutputArgs objects + * directly, use cv::GIn()/cv::GOut() wrapper functions instead. + * + * @sa @ref gapi_data_objects + */ + GComputation(GProtoInputArgs &&ins, + GProtoOutputArgs &&outs); // Arg-to-arg overload + + // 2. Syntax sugar and compatibility overloads + /** + * @brief Defines an unary (one input -- one output) computation + * + * @overload + * @param in input GMat of the defined unary computation + * @param out output GMat of the defined unary computation + */ + GComputation(GMat in, GMat out); // Unary overload + + /** + * @brief Defines an unary (one input -- one output) computation + * + * @overload + * @param in input GMat of the defined unary computation + * @param out output GScalar of the defined unary computation + */ + GComputation(GMat in, GScalar out); // Unary overload (scalar) + + /** + * @brief Defines a binary (two inputs -- one output) computation + * + * @overload + * @param in1 first input GMat of the defined binary computation + * @param in2 second input GMat of the defined binary computation + * @param out output GMat of the defined binary computation + */ + GComputation(GMat in1, GMat in2, GMat out); // Binary overload + + /** + * @brief Defines a binary (two inputs -- one output) computation + * + * @overload + * @param in1 first input GMat of the defined binary computation + * @param in2 second input GMat of the defined binary computation + * @param out output GScalar of the defined binary computation + */ + GComputation(GMat in1, GMat in2, GScalar out); // Binary + // overload + // (scalar) + + /** + * @brief Defines a computation with arbitrary input/output number. + * + * @overload + * @param ins vector of inputs GMats for this computation + * @param outs vector of outputs GMats for this computation + * + * Use this overload for cases when number of computation + * inputs/outputs is not known in compile-time -- e.g. when graph + * is programmatically generated to build an image pyramid with + * the given number of levels, etc. + */ + GComputation(const std::vector &ins, // Compatibility overload + const std::vector &outs); + + // Various versions of apply(): //////////////////////////////////////////// + // 1. Generic apply() + /** + * @brief Compile graph on-the-fly and immediately execute it on + * the inputs data vectors. + * + * Number of input/output data objects must match GComputation's + * protocol, also types of host data objects (cv::Mat, cv::Scalar) + * must match the shapes of data objects from protocol (cv::GMat, + * cv::GScalar). If there's a mismatch, a run-time exception will + * be generated. + * + * Internally, a cv::GCompiled object is created for the given + * input format configuration, which then is executed on the input + * data immediately. cv::GComputation caches compiled objects + * produced within apply() -- if this method would be called next + * time with the same input parameters (image formats, image + * resolution, etc), the underlying compiled graph will be reused + * without recompilation. If new metadata doesn't match the cached + * one, the underlying compiled graph is regenerated. + * + * @note compile() always triggers a compilation process and + * produces a new GCompiled object regardless if a similar one has + * been cached via apply() or not. + * + * @param ins vector of input data to process. Don't create + * GRunArgs object manually, use cv::gin() wrapper instead. + * @param outs vector of output data to fill results in. cv::Mat + * objects may be empty in this vector, G-API will automatically + * initialize it with the required format & dimensions. Don't + * create GRunArgsP object manually, use cv::gout() wrapper instead. + * @param args a list of compilation arguments to pass to the + * underlying compilation process. Don't create GCompileArgs + * object manually, use cv::compile_args() wrapper instead. + * + * @sa @ref gapi_data_objects, @ref gapi_compile_args + */ + void apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); // Arg-to-arg overload + + /// @private -- Exclude this function from OpenCV documentation + void apply(const std::vector& ins, // Compatibility overload + const std::vector& outs, + GCompileArgs &&args = {}); + + // 2. Syntax sugar and compatibility overloads +#if !defined(GAPI_STANDALONE) + /** + * @brief Execute an unary computation (with compilation on the fly) + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Mat for unary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in, cv::Mat &out, GCompileArgs &&args = {}); // Unary overload + + /** + * @brief Execute an unary computation (with compilation on the fly) + * + * @overload + * @param in input cv::Mat for unary computation + * @param out output cv::Scalar for unary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in, cv::Scalar &out, GCompileArgs &&args = {}); // Unary overload (scalar) + + /** + * @brief Execute a binary computation (with compilation on the fly) + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Mat for binary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in1, cv::Mat in2, cv::Mat &out, GCompileArgs &&args = {}); // Binary overload + + /** + * @brief Execute an binary computation (with compilation on the fly) + * + * @overload + * @param in1 first input cv::Mat for binary computation + * @param in2 second input cv::Mat for binary computation + * @param out output cv::Scalar for binary computation + * @param args compilation arguments for underlying compilation + * process. + */ + void apply(cv::Mat in1, cv::Mat in2, cv::Scalar &out, GCompileArgs &&args = {}); // Binary overload (scalar) + + /** + * @brief Execute a computation with arbitrary number of + * inputs/outputs (with compilation on-the-fly). + * + * @overload + * @param ins vector of input cv::Mat objects to process by the + * computation. + * @param outs vector of output cv::Mat objects to produce by the + * computation. + * @param args compilation arguments for underlying compilation + * process. + * + * Numbers of elements in ins/outs vectos must match numbers of + * inputs/outputs which were used to define this GComputation. + */ + void apply(const std::vector& ins, // Compatibility overload + std::vector& outs, + GCompileArgs &&args = {}); +#endif // !defined(GAPI_STANDALONE) + // Various versions of compile(): ////////////////////////////////////////// + // 1. Generic compile() - requires metas to be passed as vector + /** + * @brief Compile the computation for specific input format(s). + * + * This method triggers compilation process and produces a new + * GCompiled object which then can process data of the given + * format. Passing data with different format to the compiled + * computation will generate a run-time exception. + * + * @param in_metas vector of input metadata configuration. Grab + * metadata from real data objects (like cv::Mat or cv::Scalar) + * using cv::descr_of(), or create it on your own. + * @param args compilation arguments for this compilation + * process. Compilation arguments directly affect what kind of + * executable object would be produced, e.g. which kernels (and + * thus, devices) would be used to execute computation. + * + * @return GCompiled, an executable computation compiled + * specifically for the given input parameters. + * + * @sa @ref gapi_compile_args + */ + GCompiled compile(GMetaArgs &&in_metas, GCompileArgs &&args = {}); + + // 2. Syntax sugar - variadic list of metas, no extra compile args + // FIXME: SFINAE looks ugly in the generated documentation + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced. + * + * @return GCompiled, an executable computation compiled + * specifically for the given input parameters. + */ + template + auto compile(const Ts&... metas) -> + typename std::enable_if::value, GCompiled>::type + { + return compile(GMetaArgs{GMetaArg(metas)...}, GCompileArgs()); + } + + // 3. Syntax sugar - variadic list of metas, extra compile args + // (seems optional parameters don't work well when there's an variadic template + // comes first) + // + // Ideally it should look like: + // + // template + // GCompiled compile(const Ts&... metas, GCompileArgs &&args) + // + // But not all compilers can hande this (and seems they shouldn't be able to). + // FIXME: SFINAE looks ugly in the generated documentation + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced, + * followed by GCompileArgs object representing compilation + * arguments for this process. + * + * @return GCompiled, an executable computation compiled + * specifically for the given input parameters. + */ + template + auto compile(const Ts&... meta_and_compile_args) -> + typename std::enable_if::value + && std::is_same >::value, + GCompiled>::type + { + //FIXME: wrapping meta_and_compile_args into a tuple to unwrap them inside a helper function is the overkill + return compile(std::make_tuple(meta_and_compile_args...), + typename detail::MkSeq::type()); + } + + + // FIXME: Document properly in the Doxygen format + // Video-oriented pipeline compilation: + // 1. A generic version + /** + * @brief Compile the computation for streaming mode. + * + * This method triggers compilation process and produces a new + * GStreamingCompiled object which then can process video stream + * data of the given format. Passing a stream in a different + * format to the compiled computation will generate a run-time + * exception. + * + * @param in_metas vector of input metadata configuration. Grab + * metadata from real data objects (like cv::Mat or cv::Scalar) + * using cv::descr_of(), or create it on your own. + * + * @param args compilation arguments for this compilation + * process. Compilation arguments directly affect what kind of + * executable object would be produced, e.g. which kernels (and + * thus, devices) would be used to execute computation. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled specifically for the given input + * parameters. + * + * @sa @ref gapi_compile_args + */ + GStreamingCompiled compileStreaming(GMetaArgs &&in_metas, GCompileArgs &&args = {}); + + /** + * @brief Compile the computation for streaming mode. + * + * This method triggers compilation process and produces a new + * GStreamingCompiled object which then can process video stream + * data in any format. Underlying mechanisms will be adjusted to + * every new input video stream automatically, but please note that + * _not all_ existing backends support this (see reshape()). + * + * @param args compilation arguments for this compilation + * process. Compilation arguments directly affect what kind of + * executable object would be produced, e.g. which kernels (and + * thus, devices) would be used to execute computation. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled for any input image format. + * + * @sa @ref gapi_compile_args + */ + GStreamingCompiled compileStreaming(GCompileArgs &&args = {}); + + // 2. Direct metadata version + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled specifically for the given input + * parameters. + */ + template + auto compileStreaming(const Ts&... metas) -> + typename std::enable_if::value, GStreamingCompiled>::type + { + return compileStreaming(GMetaArgs{GMetaArg(metas)...}, GCompileArgs()); + } + + // 2. Direct metadata + compile arguments version + /** + * @overload + * + * Takes a variadic parameter pack with metadata + * descriptors for which a compiled object needs to be produced, + * followed by GCompileArgs object representing compilation + * arguments for this process. + * + * @return GStreamingCompiled, a streaming-oriented executable + * computation compiled specifically for the given input + * parameters. + */ + template + auto compileStreaming(const Ts&... meta_and_compile_args) -> + typename std::enable_if::value + && std::is_same >::value, + GStreamingCompiled>::type + { + //FIXME: wrapping meta_and_compile_args into a tuple to unwrap them inside a helper function is the overkill + return compileStreaming(std::make_tuple(meta_and_compile_args...), + typename detail::MkSeq::type()); + } + + // Internal use only + /// @private + Priv& priv(); + /// @private + const Priv& priv() const; + +protected: + + // 4. Helper methods for (3) + /// @private + template + GCompiled compile(const std::tuple &meta_and_compile_args, detail::Seq) + { + GMetaArgs meta_args = {GMetaArg(std::get(meta_and_compile_args))...}; + GCompileArgs comp_args = std::get(meta_and_compile_args); + return compile(std::move(meta_args), std::move(comp_args)); + } + template + GStreamingCompiled compileStreaming(const std::tuple &meta_and_compile_args, detail::Seq) + { + GMetaArgs meta_args = {GMetaArg(std::get(meta_and_compile_args))...}; + GCompileArgs comp_args = std::get(meta_and_compile_args); + return compileStreaming(std::move(meta_args), std::move(comp_args)); + } + /// @private + std::shared_ptr m_priv; +}; +/** @} */ + +namespace gapi +{ + // FIXME: all these standalone functions need to be added to some + // common documentation section + /** + * @brief Define an tagged island (subgraph) within a computation. + * + * Declare an Island tagged with `name` and defined from `ins` to `outs` + * (exclusively, as ins/outs are data objects, and regioning is done on + * operations level). + * Throws if any operation between `ins` and `outs` are already assigned + * to another island. + * + * Islands allow to partition graph into subgraphs, fine-tuning + * the way it is scheduled by the underlying executor. + * + * @param name name of the Island to create + * @param ins vector of input data objects where the subgraph + * begins + * @param outs vector of output data objects where the subgraph + * ends. + * + * The way how an island is defined is similar to how + * cv::GComputation is defined on input/output data objects. + * Same rules apply here as well -- if there's no functional + * dependency between inputs and outputs or there's not enough + * input data objects were specified to properly calculate all + * outputs, an exception is thrown. + * + * Use cv::GIn() / cv::GOut() to specify input/output vectors. + */ + void GAPI_EXPORTS island(const std::string &name, + GProtoInputArgs &&ins, + GProtoOutputArgs &&outs); +} // namespace gapi + +} // namespace cv +#endif // OPENCV_GAPI_GCOMPUTATION_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcomputation_async.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcomputation_async.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8af603efead4656c8b8eba64a80625c1c6a02cae --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gcomputation_async.hpp @@ -0,0 +1,69 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_GCOMPUTATION_ASYNC_HPP +#define OPENCV_GAPI_GCOMPUTATION_ASYNC_HPP + + +#include //for std::future +#include //for std::exception_ptr +#include //for std::function +#include //for GRunArgs, GRunArgsP +#include //for GCompileArgs +#include + + +namespace cv { + //fwd declaration + class GComputation; +namespace gapi { +namespace wip { + class GAsyncContext; + /** In contrast to async() functions, these do call GComputation::apply() member function of the GComputation passed in. + + @param gcomp Computation (graph) to run asynchronously + @param callback Callback to be called when execution of gcomp is done + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @see async + */ + GAPI_EXPORTS void async_apply(GComputation& gcomp, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); + /** @overload + @param gcomp Computation (graph) to run asynchronously + @param callback Callback to be called when execution of gcomp is done + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @param ctx Context this request belongs to + @see async_apply async GAsyncContext + */ + GAPI_EXPORTS void async_apply(GComputation& gcomp, std::function&& callback, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx); + /** @overload + @param gcomp Computation (graph) to run asynchronously + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @return std::future object to wait for completion of async operation + @see async_apply async + */ + GAPI_EXPORTS std::future async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args = {}); + /** @overload + @param gcomp Computation (graph) to run asynchronously + @param ins Input parameters for gcomp + @param outs Output parameters for gcomp + @param args Compile arguments to pass to GComputation::apply() + @param ctx Context this request belongs to + @return std::future object to wait for completion of async operation + @see async_apply async GAsyncContext + */ + GAPI_EXPORTS std::future async_apply(GComputation& gcomp, GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args, GAsyncContext& ctx); +} // namespace wip +} // namespace gapi +} // namespace cv + + +#endif //OPENCV_GAPI_GCOMPUTATION_ASYNC_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gkernel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gkernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..222356ac23a54f1e8569a176346e74c5d2f5c01b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gkernel.hpp @@ -0,0 +1,609 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_GKERNEL_HPP +#define OPENCV_GAPI_GKERNEL_HPP + +#include +#include +#include // string +#include // false_type, true_type +#include // map (for GKernelPackage) +#include // tuple + +#include // CompileArgTag +#include // Seq +#include +#include // GArg +#include // GMetaArg +#include // GTypeTraits +#include //suppress_unused_warning +#include + +namespace cv { + +using GShapes = std::vector; + +// GKernel describes kernel API to the system +// FIXME: add attributes of a kernel, (e.g. number and types +// of inputs, etc) +struct GAPI_EXPORTS GKernel +{ + using M = std::function; + + const std::string name; // kernel ID, defined by its API (signature) + const std::string tag; // some (implementation-specific) tag + const M outMeta; // generic adaptor to API::outMeta(...) + const GShapes outShapes; // types (shapes) kernel's outputs +}; + +// GKernelImpl describes particular kernel implementation to the system +struct GAPI_EXPORTS GKernelImpl +{ + util::any opaque; // backend-specific opaque info +}; + +template class GKernelTypeM; + +namespace detail +{ + //////////////////////////////////////////////////////////////////////////// + // yield() is used in graph construction time as a generic method to obtain + // lazy "return value" of G-API operations + // + namespace + { + template struct Yield; + template<> struct Yield + { + static inline cv::GMat yield(cv::GCall &call, int i) { return call.yield(i); } + }; + template<> struct Yield + { + static inline cv::GMatP yield(cv::GCall &call, int i) { return call.yieldP(i); } + }; + template<> struct Yield + { + static inline cv::GScalar yield(cv::GCall &call, int i) { return call.yieldScalar(i); } + }; + template struct Yield > + { + static inline cv::GArray yield(cv::GCall &call, int i) { return call.yieldArray(i); } + }; + } // anonymous namespace + + //////////////////////////////////////////////////////////////////////////// + // Helper classes which brings outputMeta() marshalling to kernel + // implementations + // + // 1. MetaType establishes G#Type -> G#Meta mapping between G-API dynamic + // types and its metadata descriptor types. + // This mapping is used to transform types to call outMeta() callback. + template struct MetaType; + template<> struct MetaType { using type = GMatDesc; }; + template<> struct MetaType { using type = GMatDesc; }; + template<> struct MetaType { using type = GScalarDesc; }; + template struct MetaType > { using type = GArrayDesc; }; + template struct MetaType { using type = T; }; // opaque args passed as-is + + // 2. Hacky test based on MetaType to check if we operate on G-* type or not + template using is_nongapi_type = std::is_same::type>; + + // 3. Two ways to transform input arguments to its meta - for G-* and non-G* types: + template + typename std::enable_if::value, typename MetaType::type> + ::type get_in_meta(const GMetaArgs &in_meta, const GArgs &, int idx) + { + return util::get::type>(in_meta.at(idx)); + } + + template + typename std::enable_if::value, T> + ::type get_in_meta(const GMetaArgs &, const GArgs &in_args, int idx) + { + return in_args.at(idx).template get(); + } + + // 4. The MetaHelper itself: an entity which generates outMeta() call + // based on kernel signature, with arguments properly substituted. + // 4.1 - case for multiple return values + // FIXME: probably can be simplified with std::apply or analogue. + template + struct MetaHelper; + + template + struct MetaHelper, std::tuple > + { + template + static GMetaArgs getOutMeta_impl(const GMetaArgs &in_meta, + const GArgs &in_args, + detail::Seq, + detail::Seq) + { + // FIXME: decay? + using R = std::tuple::type...>; + const R r = K::outMeta( get_in_meta(in_meta, in_args, IIs)... ); + return GMetaArgs{ GMetaArg(std::get(r))... }; + } + // FIXME: help users identify how outMeta must look like (via default impl w/static_assert?) + + static GMetaArgs getOutMeta(const GMetaArgs &in_meta, + const GArgs &in_args) + { + return getOutMeta_impl(in_meta, + in_args, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } + }; + + // 4.1 - case for a single return value + // FIXME: How to avoid duplication here? + template + struct MetaHelper, Out > + { + template + static GMetaArgs getOutMeta_impl(const GMetaArgs &in_meta, + const GArgs &in_args, + detail::Seq) + { + // FIXME: decay? + using R = typename MetaType::type; + const R r = K::outMeta( get_in_meta(in_meta, in_args, IIs)... ); + return GMetaArgs{ GMetaArg(r) }; + } + // FIXME: help users identify how outMeta must look like (via default impl w/static_assert?) + + static GMetaArgs getOutMeta(const GMetaArgs &in_meta, + const GArgs &in_args) + { + return getOutMeta_impl(in_meta, + in_args, + typename detail::MkSeq::type()); + } + }; + + //////////////////////////////////////////////////////////////////////////// + // Helper class to introduce tags to calls. By default there's no tag + struct NoTag { + static constexpr const char *tag() { return ""; } + }; + +} // namespace detail + +// GKernelType and GKernelTypeM are base classes which implement typed ::on() +// method based on kernel signature. GKernelTypeM stands for multiple-return-value kernels +// +// G_TYPED_KERNEL and G_TYPED_KERNEL_M macros inherit user classes from GKernelType and +// GKernelTypeM respectively. + +template +class GKernelTypeM(Args...)> > + : public detail::MetaHelper, std::tuple> + , public detail::NoTag +{ + template + static std::tuple yield(cv::GCall &call, detail::Seq) + { + return std::make_tuple(detail::Yield::yield(call, IIs)...); + } + +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + static std::tuple on(Args... args) + { + cv::GCall call(GKernel{K::id(), K::tag(), &K::getOutMeta, {detail::GTypeTraits::shape...}}); + call.pass(args...); + return yield(call, typename detail::MkSeq::type()); + } +}; + +template class GKernelType; + +template +class GKernelType > + : public detail::MetaHelper, R> + , public detail::NoTag +{ +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + static R on(Args... args) + { + cv::GCall call(GKernel{K::id(), K::tag(), &K::getOutMeta, {detail::GTypeTraits::shape}}); + call.pass(args...); + return detail::Yield::yield(call, 0); + } +}; + +} // namespace cv + + +// FIXME: I don't know a better way so far. Feel free to suggest one +// The problem is that every typed kernel should have ::id() but body +// of the class is defined by user (with outMeta, other stuff) + +//! @cond IGNORED +#define G_ID_HELPER_CLASS(Class) Class##IdHelper + +#define G_ID_HELPER_BODY(Class, Id) \ + struct G_ID_HELPER_CLASS(Class) \ + { \ + static constexpr const char * id() {return Id;} \ + }; \ +//! @endcond + +/** + * Declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) + * for more details. + * + * @param Class type name for this operation. + * @param API an `std::function<>`-like signature for the operation; + * return type is a single value. + * @param Id string identifier for the operation. Must be unique. + */ +#define G_TYPED_KERNEL(Class, API, Id) \ + G_ID_HELPER_BODY(Class, Id) \ + struct Class final: public cv::GKernelType, \ + public G_ID_HELPER_CLASS(Class) +// {body} is to be defined by user + +/** + * Declares a new G-API Operation. See [Kernel API](@ref gapi_kernel_api) + * for more details. + * + * @param Class type name for this operation. + * @param API an `std::function<>`-like signature for the operation; + * return type is a tuple of multiple values. + * @param Id string identifier for the operation. Must be unique. + */ +#define G_TYPED_KERNEL_M(Class, API, Id) \ + G_ID_HELPER_BODY(Class, Id) \ + struct Class final: public cv::GKernelTypeM, \ + public G_ID_HELPER_CLASS(Class) +// {body} is to be defined by user + +#define G_API_OP G_TYPED_KERNEL +#define G_API_OP_M G_TYPED_KERNEL_M + +namespace cv +{ +namespace gapi +{ + // Prework: model "Device" API before it gets to G-API headers. + // FIXME: Don't mix with internal Backends class! + class GAPI_EXPORTS GBackend + { + public: + class Priv; + + // TODO: make it template (call `new` within??) + GBackend(); + explicit GBackend(std::shared_ptr &&p); + + Priv& priv(); + const Priv& priv() const; + std::size_t hash() const; + + bool operator== (const GBackend &rhs) const; + + private: + std::shared_ptr m_priv; + }; + + inline bool operator != (const GBackend &lhs, const GBackend &rhs) + { + return !(lhs == rhs); + } +} // namespace gapi +} // namespace cv + +namespace std +{ + template<> struct hash + { + std::size_t operator() (const cv::gapi::GBackend &b) const + { + return b.hash(); + } + }; +} // namespace std + + +namespace cv { +namespace gapi { + /** \addtogroup gapi_compile_args + * @{ + */ + + // FIXME: Hide implementation + /** + * @brief A container class for heterogeneous kernel + * implementation collections and graph transformations. + * + * GKernelPackage is a special container class which stores kernel + * _implementations_ and graph _transformations_. Objects of this class + * are created and passed to cv::GComputation::compile() to specify + * which kernels to use and which transformations to apply in the + * compiled graph. GKernelPackage may contain kernels of + * different backends, e.g. be heterogeneous. + * + * The most easy way to create a kernel package is to use function + * cv::gapi::kernels(). This template functions takes kernel + * implementations in form of type list (variadic template) and + * generates a kernel package atop of that. + * + * Kernel packages can be also generated programmatically, starting + * with an empty package (created with the default constructor) + * and then by populating it with kernels via call to + * GKernelPackage::include(). Note this method is also a template + * one since G-API kernel and transformation implementations are _types_, + * not objects. + * + * Finally, two kernel packages can be combined into a new one + * with function cv::gapi::combine(). + */ + class GAPI_EXPORTS GKernelPackage + { + + /// @private + using M = std::unordered_map>; + + /// @private + M m_id_kernels; + + /// @private + std::vector m_transformations; + + protected: + /// @private + // Check if package contains ANY implementation of a kernel API + // by API textual id. + bool includesAPI(const std::string &id) const; + + /// @private + // Remove ALL implementations of the given API (identified by ID) + void removeAPI(const std::string &id); + + /// @private + // Partial include() specialization for kernels + template + typename std::enable_if<(std::is_base_of::value), void>::type + includeHelper() + { + auto backend = KImpl::backend(); + auto kernel_id = KImpl::API::id(); + auto kernel_impl = GKernelImpl{KImpl::kernel()}; + removeAPI(kernel_id); + + m_id_kernels[kernel_id] = std::make_pair(backend, kernel_impl); + } + + /// @private + // Partial include() specialization for transformations + template + typename std::enable_if<(std::is_base_of::value), void>::type + includeHelper() + { + m_transformations.emplace_back(TImpl::transformation()); + } + + public: + /** + * @brief Returns total number of kernels + * in the package (across all backends included) + * + * @return a number of kernels in the package + */ + std::size_t size() const; + + /** + * @brief Returns vector of transformations included in the package + * + * @return vector of transformations included in the package + */ + const std::vector& get_transformations() const; + + /** + * @brief Test if a particular kernel _implementation_ KImpl is + * included in this kernel package. + * + * @sa includesAPI() + * + * @note cannot be applied to transformations + * + * @return true if there is such kernel, false otherwise. + */ + template + bool includes() const + { + static_assert(std::is_base_of::value, + "includes() can be applied to kernels only"); + + auto kernel_it = m_id_kernels.find(KImpl::API::id()); + return kernel_it != m_id_kernels.end() && + kernel_it->second.first == KImpl::backend(); + } + + /** + * @brief Remove all kernels associated with the given backend + * from the package. + * + * Does nothing if there's no kernels of this backend in the package. + * + * @param backend backend which kernels to remove + */ + void remove(const GBackend& backend); + + /** + * @brief Remove all kernels implementing the given API from + * the package. + * + * Does nothing if there's no kernels implementing the given interface. + */ + template + void remove() + { + removeAPI(KAPI::id()); + } + + // FIXME: Rename to includes() and distinguish API/impl case by + // statically? + /** + * Check if package contains ANY implementation of a kernel API + * by API type. + */ + template + bool includesAPI() const + { + return includesAPI(KAPI::id()); + } + + // FIXME: The below comment is wrong, and who needs this function? + /** + * @brief Find a kernel (by its API) + * + * Returns implementation corresponding id. + * Throws if nothing found. + * + * @return Backend which hosts matching kernel implementation. + * + */ + template + GBackend lookup() const + { + return lookup(KAPI::id()).first; + } + + /// @private + std::pair + lookup(const std::string &id) const; + + // FIXME: No overwrites allowed? + /** + * @brief Put a new kernel implementation or a new transformation + * KImpl into the package. + */ + template + void include() + { + includeHelper(); + } + + /** + * @brief Lists all backends which are included into package + * + * @return vector of backends + */ + std::vector backends() const; + + // TODO: Doxygen bug -- it wants me to place this comment + // here, not below. + /** + * @brief Create a new package based on `lhs` and `rhs`. + * + * @param lhs "Left-hand-side" package in the process + * @param rhs "Right-hand-side" package in the process + * @return a new kernel package. + */ + friend GAPI_EXPORTS GKernelPackage combine(const GKernelPackage &lhs, + const GKernelPackage &rhs); + }; + + /** + * @brief Create a kernel package object containing kernels + * and transformations specified in variadic template argument. + * + * In G-API, kernel implementations and transformations are _types_. + * Every backend has its own kernel API (like GAPI_OCV_KERNEL() and + * GAPI_FLUID_KERNEL()) but all of that APIs define a new type for + * each kernel implementation. + * + * Use this function to pass kernel implementations (defined in + * either way) and transformations to the system. Example: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp kernels_snippet + * + * Note that kernels() itself is a function returning object, not + * a type, so having `()` at the end is important -- it must be a + * function call. + */ + template GKernelPackage kernels() + { + // FIXME: currently there is no check that transformations' signatures are unique + // and won't be any intersection in graph compilation stage + static_assert(detail::all_unique::value, "Kernels API must be unique"); + + GKernelPackage pkg; + + // For those who wonder - below is a trick to call a number of + // methods based on parameter pack (zeroes just help hiding these + // calls into a sequence which helps to expand this parameter pack). + // Just note that `f(),a` always equals to `a` (with f() called!) + // and parentheses are used to hide function call in the expanded sequence. + // Leading 0 helps to handle case when KK is an empty list (kernels<>()). + int unused[] = { 0, (pkg.include(), 0)... }; + cv::util::suppress_unused_warning(unused); + return pkg; + }; + + /** @} */ + + // FYI - this function is already commented above + GAPI_EXPORTS GKernelPackage combine(const GKernelPackage &lhs, + const GKernelPackage &rhs); + + /** + * @brief Combines multiple G-API kernel packages into one + * + * @overload + * + * This function successively combines the passed kernel packages using a right fold. + * Calling `combine(a, b, c)` is equal to `combine(a, combine(b, c))`. + * + * @return The resulting kernel package + */ + template + GKernelPackage combine(const GKernelPackage &a, const GKernelPackage &b, Ps&&... rest) + { + return combine(a, combine(b, rest...)); + } + + /** \addtogroup gapi_compile_args + * @{ + */ + /** + * @brief cv::use_only() is a special combinator which hints G-API to use only + * kernels specified in cv::GComputation::compile() (and not to extend kernels available by + * default with that package). + */ + struct GAPI_EXPORTS use_only + { + GKernelPackage pkg; + }; + /** @} */ + +} // namespace gapi + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.kernel_package"; } + }; + + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.use_only"; } + }; +} // namespace detail +} // namespace cv + +#endif // OPENCV_GAPI_GKERNEL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gmat.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gmat.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4f67126a9021495613a29c605e0cc25211d36ba4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gmat.hpp @@ -0,0 +1,237 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GMAT_HPP +#define OPENCV_GAPI_GMAT_HPP + +#include +#include // std::shared_ptr + +#include +#include // GShape + +#include // cv::gapi::own::Size +#include // to_own +#include + +// TODO GAPI_EXPORTS or so +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; + +/** \addtogroup gapi_data_objects + * @{ + * + * @brief G-API data objects used to build G-API expressions. + * + * These objects do not own any particular data (except compile-time + * associated values like with cv::GScalar) and are used to construct + * graphs. + * + * Every graph in G-API starts and ends with data objects. + * + * Once constructed and compiled, G-API operates with regular host-side + * data instead. Refer to the below table to find the mapping between + * G-API and regular data types. + * + * G-API data type | I/O data type + * ------------------ | ------------- + * cv::GMat | cv::Mat + * cv::GScalar | cv::Scalar + * `cv::GArray` | std::vector + */ +class GAPI_EXPORTS GMat +{ +public: + GMat(); // Empty constructor + GMat(const GNode &n, std::size_t out); // Operation result constructor + + GOrigin& priv(); // Internal use only + const GOrigin& priv() const; // Internal use only + +private: + std::shared_ptr m_priv; +}; + +class GAPI_EXPORTS GMatP : public GMat +{ +public: + using GMat::GMat; +}; + +namespace gapi { namespace own { + class Mat; +}}//gapi::own + +/** @} */ + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GAPI_EXPORTS GMatDesc +{ + // FIXME: Default initializers in C++14 + int depth; + int chan; + cv::gapi::own::Size size; // NB.: no multi-dimensional cases covered yet + bool planar; + std::vector dims; // FIXME: Maybe it's real questionable to have it here + + GMatDesc(int d, int c, cv::gapi::own::Size s, bool p = false) + : depth(d), chan(c), size(s), planar(p) {} + + GMatDesc(int d, const std::vector &dd) + : depth(d), chan(-1), size{-1,-1}, planar(false), dims(dd) {} + + GMatDesc(int d, std::vector &&dd) + : depth(d), chan(-1), size{-1,-1}, planar(false), dims(std::move(dd)) {} + + GMatDesc() : GMatDesc(-1, -1, {-1,-1}) {} + + inline bool operator== (const GMatDesc &rhs) const + { + return depth == rhs.depth + && chan == rhs.chan + && size == rhs.size + && planar == rhs.planar + && dims == rhs.dims; + } + + inline bool operator!= (const GMatDesc &rhs) const + { + return !(*this == rhs); + } + + bool isND() const { return !dims.empty(); } + + // Checks if the passed mat can be described by this descriptor + // (it handles the case when + // 1-channel mat can be reinterpreted as is (1-channel mat) + // and as a 3-channel planar mat with height divided by 3) + bool canDescribe(const cv::gapi::own::Mat& mat) const; + + // Meta combinator: return a new GMatDesc which differs in size by delta + // (all other fields are taken unchanged from this GMatDesc) + // FIXME: a better name? + GMatDesc withSizeDelta(cv::gapi::own::Size delta) const + { + GMatDesc desc(*this); + desc.size += delta; + return desc; + } +#if !defined(GAPI_STANDALONE) + GMatDesc withSizeDelta(cv::Size delta) const + { + return withSizeDelta(to_own(delta)); + } + + GMatDesc withSize(cv::Size sz) const + { + return withSize(to_own(sz)); + } + + bool canDescribe(const cv::Mat& mat) const; +#endif // !defined(GAPI_STANDALONE) + // Meta combinator: return a new GMatDesc which differs in size by delta + // (all other fields are taken unchanged from this GMatDesc) + // + // This is an overload. + GMatDesc withSizeDelta(int dx, int dy) const + { + return withSizeDelta(cv::gapi::own::Size{dx,dy}); + } + + GMatDesc withSize(cv::gapi::own::Size sz) const + { + GMatDesc desc(*this); + desc.size = sz; + return desc; + } + + // Meta combinator: return a new GMatDesc with specified data depth. + // (all other fields are taken unchanged from this GMatDesc) + GMatDesc withDepth(int ddepth) const + { + GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1); + GMatDesc desc(*this); + if (ddepth != -1) desc.depth = ddepth; + return desc; + } + + // Meta combinator: return a new GMatDesc with specified data depth + // and number of channels. + // (all other fields are taken unchanged from this GMatDesc) + GMatDesc withType(int ddepth, int dchan) const + { + GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1); + GMatDesc desc = withDepth(ddepth); + desc.chan = dchan; + return desc; + } + + // Meta combinator: return a new GMatDesc with planar flag set + // (no size changes are performed, only channel interpretation is changed + // (interleaved -> planar) + GMatDesc asPlanar() const + { + GAPI_Assert(planar == false); + GMatDesc desc(*this); + desc.planar = true; + return desc; + } + + // Meta combinator: return a new GMatDesc + // reinterpreting 1-channel input as planar image + // (size height is divided by plane number) + GMatDesc asPlanar(int planes) const + { + GAPI_Assert(planar == false); + GAPI_Assert(chan == 1); + GAPI_Assert(planes > 1); + GAPI_Assert(size.height % planes == 0); + GMatDesc desc(*this); + desc.size.height /= planes; + desc.chan = planes; + return desc.asPlanar(); + } + + // Meta combinator: return a new GMatDesc with planar flag set to false + // (no size changes are performed, only channel interpretation is changed + // (planar -> interleaved) + GMatDesc asInterleaved() const + { + GAPI_Assert(planar == true); + GMatDesc desc(*this); + desc.planar = false; + return desc; + } +}; + +static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; } + +#if !defined(GAPI_STANDALONE) +class Mat; +GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat); +GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat); +#endif // !defined(GAPI_STANDALONE) + +/** @} */ + +// FIXME: WHY??? WHY it is under different namespace? +namespace gapi { namespace own { + GAPI_EXPORTS GMatDesc descr_of(const Mat &mat); +}}//gapi::own + +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc); + +} // namespace cv + +#endif // OPENCV_GAPI_GMAT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gmetaarg.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gmetaarg.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0bd6767b7e010e74758e59a1d39bff94f2567151 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gmetaarg.hpp @@ -0,0 +1,77 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GMETAARG_HPP +#define OPENCV_GAPI_GMETAARG_HPP + +#include +#include + +#include +#include + +#include +#include +#include + +namespace cv +{ +// FIXME: Rename to GMeta? +// FIXME: user shouldn't deal with it - put to detail? +// GMetaArg is an union type over descriptions of G-types which can serve as +// GComputation's in/output slots. +// +// GMetaArg objects are passed as arguments to GComputation::compile() +// to specify which data a compiled computation should be specialized on. +// For manual compile(), user must supply this metadata, in case of apply() +// this metadata is taken from arguments computation should operate on. +// +// The first type (monostate) is equal to "uninitialized"/"unresolved" meta. +using GMetaArg = util::variant + < util::monostate + , GMatDesc + , GScalarDesc + , GArrayDesc + >; +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const GMetaArg &); + +using GMetaArgs = std::vector; + +namespace detail +{ + // These traits are used by GComputation::compile() + + // FIXME: is_constructible doesn't work as variant doesn't do any SFINAE + // in its current template constructor + + template struct is_meta_descr : std::false_type {}; + template<> struct is_meta_descr : std::true_type {}; + template<> struct is_meta_descr : std::true_type {}; + template<> struct is_meta_descr : std::true_type {}; + + template + using are_meta_descrs = all_satisfy; + + template + using are_meta_descrs_but_last = all_satisfy::type>; + +} // namespace detail + +// Note: descr_of(std::vector<..>) returns a GArrayDesc, while +// descrs_of(std::vector<..>) returns an array of Meta args! +class Mat; +class UMat; +GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector &vec); +GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector &vec); +namespace gapi { namespace own { + class Mat; + GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector &vec); +}} // namespace gapi::own + +} // namespace cv + +#endif // OPENCV_GAPI_GMETAARG_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gproto.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gproto.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b9e206ac9e0ecfe78a055a770eacb4d8c1378180 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gproto.hpp @@ -0,0 +1,129 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GPROTO_HPP +#define OPENCV_GAPI_GPROTO_HPP + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +namespace cv { + +// FIXME: user shouldn't deal with it - put to detail? +// GProtoArg is an union type over G-types which can serve as +// GComputation's in/output slots. In other words, GProtoArg +// wraps any type which can serve as G-API exchange type. +// +// In Runtime, GProtoArgs are substituted with appropriate GRunArgs. +// +// GProtoArg objects are constructed in-place when user describes +// (captures) computations, user doesn't interact with these types +// directly. +using GProtoArg = util::variant + < GMat + , GMatP + , GScalar + , detail::GArrayU // instead of GArray + >; + +using GProtoArgs = std::vector; + +namespace detail +{ +template inline GProtoArgs packArgs(Ts... args) +{ + return GProtoArgs{ GProtoArg(wrap_gapi_helper::wrap(args))... }; +} + +} + +template +struct GIOProtoArgs +{ +public: + explicit GIOProtoArgs(const GProtoArgs& args) : m_args(args) {} + explicit GIOProtoArgs(GProtoArgs &&args) : m_args(std::move(args)) {} + + GProtoArgs m_args; +}; + +struct In_Tag{}; +struct Out_Tag{}; + +using GProtoInputArgs = GIOProtoArgs; +using GProtoOutputArgs = GIOProtoArgs; + +// Perfect forwarding +template inline GProtoInputArgs GIn(Ts&&... ts) +{ + return GProtoInputArgs(detail::packArgs(std::forward(ts)...)); +} + +template inline GProtoOutputArgs GOut(Ts&&... ts) +{ + return GProtoOutputArgs(detail::packArgs(std::forward(ts)...)); +} + +namespace detail +{ + // Extract elements form tuple + // FIXME: Someday utilize a generic tuple_to_vec<> routine + template + static GProtoOutputArgs getGOut_impl(const std::tuple& ts, detail::Seq) + { + return GProtoOutputArgs{ detail::packArgs(std::get(ts)...)}; + } +} + +template inline GProtoOutputArgs GOut(const std::tuple& ts) +{ + // TODO: think of std::forward(ts) + return detail::getGOut_impl(ts, typename detail::MkSeq::type()); +} + +// Takes rvalue as input arg +template inline GProtoOutputArgs GOut(std::tuple&& ts) +{ + // TODO: think of std::forward(ts) + return detail::getGOut_impl(ts, typename detail::MkSeq::type()); +} + +// Extract run-time arguments from node origin +// Can be used to extract constant values associated with G-objects +// (like GScalar) at graph construction time +GRunArg value_of(const GOrigin &origin); + +// Transform run-time computation arguments into a collection of metadata +// extracted from that arguments +GMetaArg GAPI_EXPORTS descr_of(const GRunArg &arg ); +GMetaArgs GAPI_EXPORTS descr_of(const GRunArgs &args); + +// Transform run-time operation result argument into metadata extracted from that argument +// Used to compare the metadata, which generated at compile time with the metadata result operation in run time +GMetaArg GAPI_EXPORTS descr_of(const GRunArgP& argp); + +// Checks if run-time computation argument can be described by metadata +bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArg& arg); +bool GAPI_EXPORTS can_describe(const GMetaArgs& metas, const GRunArgs& args); + +// Checks if run-time computation result argument can be described by metadata. +// Used to check if the metadata generated at compile time +// coincides with output arguments passed to computation in cpu and ocl backends +bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArgP& argp); + +} // namespace cv + +#endif // OPENCV_GAPI_GPROTO_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a7ee59577ce41ca84cc7f36a3752890534303e23 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/core.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GPU_CORE_API_HPP +#define OPENCV_GAPI_GPU_CORE_API_HPP +/** @file +* @deprecated Use instead. +*/ + +#include + +namespace cv { +namespace gapi { +namespace core { +namespace gpu { + using namespace ocl; +} // namespace gpu +} // namespace core +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_GPU_CORE_API_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/ggpukernel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/ggpukernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b52c21de6bf75876457a426afe21bde7e20fdc45 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/ggpukernel.hpp @@ -0,0 +1,18 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GGPUKERNEL_HPP +#define OPENCV_GAPI_GGPUKERNEL_HPP +/** @file +* @deprecated Use instead. +*/ + +#include +#define GAPI_GPU_KERNEL GAPI_OCL_KERNEL + + +#endif // OPENCV_GAPI_GGPUKERNEL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/imgproc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/imgproc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b0df7ae3315ef17fbd865187e65a390a5243ae16 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gpu/imgproc.hpp @@ -0,0 +1,28 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GPU_IMGPROC_API_HPP +#define OPENCV_GAPI_GPU_IMGPROC_API_HPP +/** @file +* @deprecated Use instead. +*/ + +#include + + +namespace cv { +namespace gapi { +namespace imgproc { +namespace gpu { + using namespace ocl; +} // namespace gpu +} // namespace imgproc +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_GPU_IMGPROC_API_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gscalar.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gscalar.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f65741e61d34852b402eb05a24ef7a1b384bbc8d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gscalar.hpp @@ -0,0 +1,83 @@ +// This file is part of OpenCV project. + +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GSCALAR_HPP +#define OPENCV_GAPI_GSCALAR_HPP + +#include + +#include +#include // GShape +#include +#include + +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; + +/** \addtogroup gapi_data_objects + * @{ + */ + +class GAPI_EXPORTS GScalar +{ +public: + GScalar(); // Empty constructor + explicit GScalar(const cv::gapi::own::Scalar& s); // Constant value constructor from cv::gapi::own::Scalar + explicit GScalar(cv::gapi::own::Scalar&& s); // Constant value move-constructor from cv::gapi::own::Scalar +#if !defined(GAPI_STANDALONE) + explicit GScalar(const cv::Scalar& s); // Constant value constructor from cv::Scalar +#endif // !defined(GAPI_STANDALONE) + GScalar(double v0); // Constant value constructor from double + GScalar(const GNode &n, std::size_t out); // Operation result constructor + + GOrigin& priv(); // Internal use only + const GOrigin& priv() const; // Internal use only + +private: + std::shared_ptr m_priv; +}; + +/** @} */ + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GScalarDesc +{ + // NB.: right now it is empty + + inline bool operator== (const GScalarDesc &) const + { + return true; // NB: implement this method if GScalar meta appears + } + + inline bool operator!= (const GScalarDesc &rhs) const + { + return !(*this == rhs); + } +}; + +static inline GScalarDesc empty_scalar_desc() { return GScalarDesc(); } + +#if !defined(GAPI_STANDALONE) +GAPI_EXPORTS GScalarDesc descr_of(const cv::Scalar &scalar); +#endif // !defined(GAPI_STANDALONE) +/** @} */ + +GAPI_EXPORTS GScalarDesc descr_of(const cv::gapi::own::Scalar &scalar); + +std::ostream& operator<<(std::ostream& os, const cv::GScalarDesc &desc); + +} // namespace cv + +#endif // OPENCV_GAPI_GSCALAR_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gstreaming.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gstreaming.hpp new file mode 100644 index 0000000000000000000000000000000000000000..70790420699435c406531f48df2ac7b000681981 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gstreaming.hpp @@ -0,0 +1,231 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GSTREAMING_COMPILED_HPP +#define OPENCV_GAPI_GSTREAMING_COMPILED_HPP + +#include + +#include +#include +#include +#include + +namespace cv { + +/** + * \addtogroup gapi_main_classes + * @{ + */ +/** + * @brief Represents a computation (graph) compiled for streaming. + * + * This class represents a product of graph compilation (calling + * cv::GComputation::compileStreaming()). Objects of this class + * actually do stream processing, and the whole pipeline execution + * complexity is incapsulated into objects of this class. Execution + * model has two levels: at the very top, the execution of a + * heterogeneous graph is aggressively pipelined; at the very bottom + * the execution of every internal block is determined by its + * associated backend. Backends are selected based on kernel packages + * passed via compilation arguments ( see @ref gapi_compile_args, + * GNetworkPackage, GKernelPackage for details). + * + * GStreamingCompiled objects have a "player" semantics -- there are + * methods like start() and stop(). GStreamingCompiled has a full + * control over a videostream and so is stateful. You need to specify the + * input stream data using setSource() and then call start() to + * actually start processing. After that, use pull() or try_pull() to + * obtain next processed data frame from the graph in a blocking or + * non-blocking way, respectively. + * + * Currently a single GStreamingCompiled can process only one video + * streat at time. Produce multiple GStreamingCompiled objects to run the + * same graph on multiple video streams. + * + * @sa GCompiled + */ +class GAPI_EXPORTS GStreamingCompiled +{ +public: + class GAPI_EXPORTS Priv; + GStreamingCompiled(); + + // FIXME: More overloads? + /** + * @brief Specify the input data to GStreamingCompiled for + * processing, a generic version. + * + * Use gin() to create an input parameter vector. + * + * Input vectors must have the same number of elements as defined + * in the cv::GComputation protocol (at the moment of its + * construction). Shapes of elements also must conform to protocol + * (e.g. cv::Mat needs to be passed where cv::GMat has been + * declared as input, and so on). Run-time exception is generated + * on type mismatch. + * + * In contrast with regular GCompiled, user can also pass an + * object of type GVideoCapture for a GMat parameter of the parent + * GComputation. The compiled pipeline will start fetching data + * from that GVideoCapture and feeding it into the + * pipeline. Pipeline stops when a GVideoCapture marks end of the + * stream (or when stop() is called). + * + * Passing a regular Mat for a GMat parameter makes it "infinite" + * source -- pipeline may run forever feeding with this Mat until + * stopped explicitly. + * + * Currently only a single GVideoCapture is supported as input. If + * the parent GComputation is declared with multiple input GMat's, + * one of those can be specified as GVideoCapture but all others + * must be regular Mat objects. + * + * Throws if pipeline is already running. Use stop() and then + * setSource() to run the graph on a new video stream. + * + * @note This method is not thread-safe (with respect to the user + * side) at the moment. Protect the access if + * start()/stop()/setSource() may be called on the same object in + * multiple threads in your application. + * + * @param ins vector of inputs to process. + * @sa gin + */ + void setSource(GRunArgs &&ins); + + /** + * @brief Specify an input video stream for a single-input + * computation pipeline. + * + * Throws if pipeline is already running. Use stop() and then + * setSource() to run the graph on a new video stream. + * + * @overload + * @param s a shared pointer to IStreamSource representing the + * input video stream. + */ + void setSource(const gapi::wip::IStreamSource::Ptr& s); + + /** + * @brief Start the pipeline execution. + * + * Use pull()/try_pull() to obtain data. Throws an exception if + * a video source was not specified. + * + * setSource() must be called first, even if the pipeline has been + * working already and then stopped (explicitly via stop() or due + * stream completion) + * + * @note This method is not thread-safe (with respect to the user + * side) at the moment. Protect the access if + * start()/stop()/setSource() may be called on the same object in + * multiple threads in your application. + */ + void start(); + + /** + * @brief Get the next processed frame from the pipeline. + * + * Use gout() to create an output parameter vector. + * + * Output vectors must have the same number of elements as defined + * in the cv::GComputation protocol (at the moment of its + * construction). Shapes of elements also must conform to protocol + * (e.g. cv::Mat needs to be passed where cv::GMat has been + * declared as output, and so on). Run-time exception is generated + * on type mismatch. + * + * This method writes new data into objects passed via output + * vector. If there is no data ready yet, this method blocks. Use + * try_pull() if you need a non-blocking version. + * + * @param outs vector of output parameters to obtain. + * @return true if next result has been obtained, + * false marks end of the stream. + */ + bool pull(cv::GRunArgsP &&outs); + + /** + * @brief Try to get the next processed frame from the pipeline. + * + * Use gout() to create an output parameter vector. + * + * This method writes new data into objects passed via output + * vector. If there is no data ready yet, the output vector + * remains unchanged and false is returned. + * + * @return true if data has been obtained, and false if it was + * not. Note: false here doesn't mark the end of the stream. + */ + bool try_pull(cv::GRunArgsP &&outs); + + /** + * @brief Stop (abort) processing the pipeline. + * + * Note - it is not pause but a complete stop. Calling start() + * will cause G-API to start processing the stream from the early beginning. + * + * Throws if the pipeline is not running. + */ + void stop(); + + /** + * @brief Test if the pipeline is running. + * + * @note This method is not thread-safe (with respect to the user + * side) at the moment. Protect the access if + * start()/stop()/setSource() may be called on the same object in + * multiple threads in your application. + * + * @return true if the current stream is not over yet. + */ + bool running() const; + + /// @private + Priv& priv(); + + /** + * @brief Check if compiled object is valid (non-empty) + * + * @return true if the object is runnable (valid), false otherwise + */ + explicit operator bool () const; + + /** + * @brief Vector of metadata this graph was compiled for. + * + * @return Unless _reshape_ is not supported, return value is the + * same vector which was passed to cv::GComputation::compile() to + * produce this compiled object. Otherwise, it is the latest + * metadata vector passed to reshape() (if that call was + * successful). + */ + const GMetaArgs& metas() const; // Meta passed to compile() + + /** + * @brief Vector of metadata descriptions of graph outputs + * + * @return vector with formats/resolutions of graph's output + * objects, auto-inferred from input metadata vector by + * operations which form this computation. + * + * @note GCompiled objects produced from the same + * cv::GComputiation graph with different input metas may return + * different values in this vector. + */ + const GMetaArgs& outMetas() const; + +protected: + /// @private + std::shared_ptr m_priv; +}; +/** @} */ + +} + +#endif // OPENCV_GAPI_GSTREAMING_COMPILED_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtransform.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtransform.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5d1b91b51739ac1f19af9dbc9662b16a29634025 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtransform.hpp @@ -0,0 +1,103 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_GTRANSFORM_HPP +#define OPENCV_GAPI_GTRANSFORM_HPP + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace cv +{ + +struct GAPI_EXPORTS GTransform +{ + // FIXME: consider another simplified + // class instead of GComputation + using F = std::function; + + std::string description; + F pattern; + F substitute; + + GTransform(const std::string& d, const F &p, const F &s) : description(d), pattern(p), substitute(s){}; +}; + +namespace detail +{ + +template +struct TransHelper; + +template +struct TransHelper, Out> +{ + template + static GComputation invoke(Callable f, Seq, Seq) + { + const std::tuple ins; + const auto r = tuple_wrap_helper::get(f(std::get(ins)...)); + return GComputation(cv::GIn(std::get(ins)...), + cv::GOut(std::get(r)...)); + } + + static GComputation get_pattern() + { + return invoke(K::pattern, typename MkSeq::type(), + typename MkSeq::type>::value>::type()); + } + static GComputation get_substitute() + { + return invoke(K::substitute, typename MkSeq::type(), + typename MkSeq::type>::value>::type()); + } +}; +} // namespace detail + +template +class GTransformImpl; + +template +class GTransformImpl> : public cv::detail::TransHelper, R>, + public cv::detail::TransformTag +{ +public: + // FIXME: currently there is no check that transformations' signatures are unique + // and won't be any intersection in graph compilation stage + using API = K; + + static GTransform transformation() + { + return GTransform(K::descr(), &K::get_pattern, &K::get_substitute); + } +}; +} // namespace cv + +#define G_DESCR_HELPER_CLASS(Class) Class##DescrHelper + +#define G_DESCR_HELPER_BODY(Class, Descr) \ + namespace detail \ + { \ + struct G_DESCR_HELPER_CLASS(Class) \ + { \ + static constexpr const char *descr() { return Descr; }; \ + }; \ + } + +#define GAPI_TRANSFORM(Class, API, Descr) \ + G_DESCR_HELPER_BODY(Class, Descr) \ + struct Class final : public cv::GTransformImpl, \ + public detail::G_DESCR_HELPER_CLASS(Class) + +#endif // OPENCV_GAPI_GTRANSFORM_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtype_traits.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtype_traits.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8cea478813fe3ab5a671960c40bd720b80532905 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtype_traits.hpp @@ -0,0 +1,171 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GTYPE_TRAITS_HPP +#define OPENCV_GAPI_GTYPE_TRAITS_HPP + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace cv +{ +namespace detail +{ + // FIXME: These traits and enum and possible numerous switch(kind) + // block may be replaced with a special Handler object or with + // a double dispatch + enum class ArgKind: int + { + OPAQUE_VAL, // Unknown, generic, opaque-to-GAPI data type - STATIC + // Note: OPAQUE is sometimes defined in Win sys headers +#if !defined(OPAQUE) && !defined(CV_DOXYGEN) + OPAQUE = OPAQUE_VAL, // deprecated value used for compatibility, use OPAQUE_VAL instead +#endif + GOBJREF, // reference to object + GMAT, // a cv::GMat + GMATP, // a cv::GMatP + GSCALAR, // a cv::GScalar + GARRAY, // a cv::GArrayU (note - exactly GArrayU, not GArray!) + }; + + // Describe G-API types (G-types) with traits. Mostly used by + // cv::GArg to store meta information about types passed into + // operation arguments. Please note that cv::GComputation is + // defined on GProtoArgs, not GArgs! + template struct GTypeTraits; + template struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::OPAQUE_VAL; + }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GMAT; + static constexpr const GShape shape = GShape::GMAT; + }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GMATP; + static constexpr const GShape shape = GShape::GMAT; + }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GSCALAR; + static constexpr const GShape shape = GShape::GSCALAR; + }; + template struct GTypeTraits > + { + static constexpr const ArgKind kind = ArgKind::GARRAY; + static constexpr const GShape shape = GShape::GARRAY; + using host_type = std::vector; + using strip_type = cv::detail::VectorRef; + static cv::detail::GArrayU wrap_value(const cv::GArray &t) { return t.strip();} + static cv::detail::VectorRef wrap_in (const std::vector &t) { return detail::VectorRef(t); } + static cv::detail::VectorRef wrap_out ( std::vector &t) { return detail::VectorRef(t); } + }; + + // Tests if Trait for type T requires extra marshalling ("custom wrap") or not. + // If Traits has wrap_value() defined, it does. + template struct has_custom_wrap + { + template class check; + template static std::true_type test(check::wrap_value)> *); + template static std::false_type test(...); + using type = decltype(test(nullptr)); + static const constexpr bool value = std::is_same(nullptr))>::value; + }; + + // Resolve a Host type back to its associated G-Type. + // FIXME: Probably it can be avoided + // FIXME: GMatP is not present here. + // (Actually these traits is used only to check + // if associated G-type has custom wrap functions + // and GMat behavior is correct for GMatP) + template struct GTypeOf; +#if !defined(GAPI_STANDALONE) + template<> struct GTypeOf { using type = cv::GMat; }; + template<> struct GTypeOf { using type = cv::GMat; }; + template<> struct GTypeOf { using type = cv::GScalar; }; +#endif // !defined(GAPI_STANDALONE) + template<> struct GTypeOf { using type = cv::GMat; }; + template<> struct GTypeOf { using type = cv::GScalar; }; + template struct GTypeOf > { using type = cv::GArray; }; + // FIXME: This is not quite correct since IStreamSource may produce not only Mat but also Scalar + // and vector data. TODO: Extend the type dispatchig on these types too. + template<> struct GTypeOf { using type = cv::GMat;}; + template using g_type_of_t = typename GTypeOf::type; + + // Marshalling helper for G-types and its Host types. Helps G-API + // to store G types in internal generic containers for further + // processing. Implements the following callbacks: + // + // * wrap() - converts user-facing G-type into an internal one + // for internal storage. + // Used when G-API operation is instantiated (G::on(), + // etc) during expressing a pipeline. Mostly returns input + // value "as is" except the case when G-type is a template. For + // template G-classes, calls custom wrap() from Traits. + // The value returned by wrap() is then wrapped into GArg() and + // stored in G-API metadata. + // + // Example: + // - cv::GMat arguments are passed as-is. + // - integers, pointers, STL containers, user types are passed as-is. + // - cv::GArray is converted to cv::GArrayU. + // + // * wrap_in() / wrap_out() - convert Host type associated with + // G-type to internal representation type. + // + // - For "simple" (non-template) G-types, returns value as-is. + // Example: cv::GMat has host type cv::Mat, when user passes a + // cv::Mat, system stores it internally as cv::Mat. + // + // - For "complex" (template) G-types, utilizes custom + // wrap_in()/wrap_out() as described in Traits. + // Example: cv::GArray has host type std::vector, when + // user passes a std::vector, system stores it + // internally as VectorRef (with stripped away). + template struct WrapValue + { + static auto wrap(const T& t) -> + typename std::remove_reference::type + { + return static_cast::type>(t); + } + + template static U wrap_in (const U &u) { return u; } + template static U* wrap_out(U &u) { return &u; } + }; + template struct WrapValue::value>::type> + { + static auto wrap(const T& t) -> decltype(GTypeTraits::wrap_value(t)) + { + return GTypeTraits::wrap_value(t); + } + template static auto wrap_in (const U &u) -> typename GTypeTraits::strip_type + { + return GTypeTraits::wrap_in(u); + } + template static auto wrap_out(U &u) -> typename GTypeTraits::strip_type + { + return GTypeTraits::wrap_out(u); + } + }; + + template using wrap_gapi_helper = WrapValue::type>; + template using wrap_host_helper = WrapValue >::type>; + +} // namespace detail +} // namespace cv + +#endif // OPENCV_GAPI_GTYPE_TRAITS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtyped.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtyped.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b941c7bb6f9a249a70d290d6df9a89bea8a5a42 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/gtyped.hpp @@ -0,0 +1,227 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GTYPED_HPP +#define OPENCV_GAPI_GTYPED_HPP +#if !defined(GAPI_STANDALONE) + +#include + +#include +#include +#include +#include + +namespace cv { + +namespace detail +{ + // FIXME: How to prevent coolhackers from extending it by their own types? + // FIXME: ...Should we care? + template struct ProtoToParam; + template<> struct ProtoToParam { using type = cv::Mat; }; + template<> struct ProtoToParam { using type = cv::Scalar; }; + template struct ProtoToParam > { using type = std::vector; }; + template using ProtoToParamT = typename ProtoToParam::type; + + template struct ProtoToMeta; + template<> struct ProtoToMeta { using type = cv::GMatDesc; }; + template<> struct ProtoToMeta { using type = cv::GScalarDesc; }; + template struct ProtoToMeta > { using type = cv::GArrayDesc; }; + template using ProtoToMetaT = typename ProtoToMeta::type; + + //workaround for MSVC 19.0 bug + template + auto make_default()->decltype(T{}) {return {};} +}; // detail + +/** + * @brief This class is a typed wrapper over a regular GComputation. + * + * `std::function<>`-like template parameter specifies the graph + * signature so methods so the object's constructor, methods like + * `apply()` and the derived `GCompiledT::operator()` also become + * typed. + * + * There is no need to use cv::gin() or cv::gout() modifiers with + * objects of this class. Instead, all input arguments are followed + * by all output arguments in the order from the template argument + * signature. + * + * Refer to the following example. Regular (untyped) code is written this way: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp Untyped_Example + * + * Here: + * + * - cv::GComputation object is created with a lambda constructor + * where it is defined as a two-input, one-output graph. + * + * - Its method `apply()` in fact takes arbitrary number of arguments + * (as vectors) so user can pass wrong number of inputs/outputs + * here. C++ compiler wouldn't notice that since the cv::GComputation + * API is polymorphic, and only a run-time error will be generated. + * + * Now the same code written with typed API: + * + * @snippet modules/gapi/samples/api_ref_snippets.cpp Typed_Example + * + * The key difference is: + * + * - Now the constructor lambda *must take* parameters and *must + * return* values as defined in the `GComputationT<>` signature. + * - Its method `apply()` does not require any extra specifiers to + * separate input arguments from the output ones + * - A `GCompiledT` (compilation product) takes input/output + * arguments with no extra specifiers as well. + */ +template class GComputationT; + +// Single return value implementation +template class GComputationT +{ +public: + typedef std::function Gen; + + class GCompiledT + { + private: + friend class GComputationT; + + cv::GCompiled m_comp; + + explicit GCompiledT(const cv::GCompiled &comp) : m_comp(comp) {} + + public: + GCompiledT() {} + + void operator()(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT &outArg) + { + m_comp(cv::gin(inArgs...), cv::gout(outArg)); + } + + explicit operator bool() const + { + return static_cast(m_comp); + } + }; + +private: + typedef std::pair Captured; + + Captured capture(const Gen& g, Args... args) + { + return Captured(g(args...), cv::GIn(args...)); + } + + Captured m_capture; + cv::GComputation m_comp; + +public: + GComputationT(const Gen &generator) + : m_capture(capture(generator, detail::make_default()...)) + , m_comp(cv::GProtoInputArgs(std::move(m_capture.second)), + cv::GOut(m_capture.first)) + { + } + + void apply(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT &outArg) + { + m_comp.apply(cv::gin(inArgs...), cv::gout(outArg)); + } + + GCompiledT compile(detail::ProtoToMetaT... inDescs) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), GCompileArgs())); + } + + GCompiledT compile(detail::ProtoToMetaT... inDescs, GCompileArgs &&args) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), std::move(args))); + } +}; + +// Multiple (fixed) return value implementation. FIXME: How to avoid copy-paste? +template class GComputationT(Args...)> +{ +public: + typedef std::function(Args...)> Gen; + + class GCompiledT + { + private: + friend class GComputationT(Args...)>; + + cv::GCompiled m_comp; + explicit GCompiledT(const cv::GCompiled &comp) : m_comp(comp) {} + + public: + GCompiledT() {} + + void operator()(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT&... outArgs) + { + m_comp(cv::gin(inArgs...), cv::gout(outArgs...)); + } + + explicit operator bool() const + { + return static_cast(m_comp); + } + }; + +private: + typedef std::pair Captured; + + template + Captured capture(GProtoArgs &&args, const std::tuple &rr, detail::Seq) + { + return Captured(cv::GOut(std::get(rr)...).m_args, args); + } + + Captured capture(const Gen& g, Args... args) + { + return capture(cv::GIn(args...).m_args, g(args...), typename detail::MkSeq::type()); + } + + Captured m_capture; + cv::GComputation m_comp; + +public: + GComputationT(const Gen &generator) + : m_capture(capture(generator, detail::make_default()...)) + , m_comp(cv::GProtoInputArgs(std::move(m_capture.second)), + cv::GProtoOutputArgs(std::move(m_capture.first))) + { + } + + void apply(detail::ProtoToParamT... inArgs, + detail::ProtoToParamT&... outArgs) + { + m_comp.apply(cv::gin(inArgs...), cv::gout(outArgs...)); + } + + GCompiledT compile(detail::ProtoToMetaT... inDescs) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), GCompileArgs())); + } + + GCompiledT compile(detail::ProtoToMetaT... inDescs, GCompileArgs &&args) + { + GMetaArgs inMetas = { GMetaArg(inDescs)... }; + return GCompiledT(m_comp.compile(std::move(inMetas), std::move(args))); + } +}; + +} // namespace cv +#endif // !defined(GAPI_STANDALONE) +#endif // OPENCV_GAPI_GTYPED_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/imgproc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/imgproc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e1a3aa5eca06340186da8b54c569123713c4b00a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/imgproc.hpp @@ -0,0 +1,919 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_IMGPROC_HPP +#define OPENCV_GAPI_IMGPROC_HPP + +#include + +#include // std::tuple + +#include +#include +#include + + +/** \defgroup gapi_imgproc G-API Image processing functionality +@{ + @defgroup gapi_filters Graph API: Image filters + @defgroup gapi_colorconvert Graph API: Converting image from one color space to another +@} + */ + +namespace cv { namespace gapi { + +namespace imgproc { + using GMat2 = std::tuple; + using GMat3 = std::tuple; // FIXME: how to avoid this? + + G_TYPED_KERNEL(GFilter2D, ,"org.opencv.imgproc.filters.filter2D") { + static GMatDesc outMeta(GMatDesc in, int ddepth, Mat, Point, Scalar, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GSepFilter, , "org.opencv.imgproc.filters.sepfilter") { + static GMatDesc outMeta(GMatDesc in, int ddepth, Mat, Mat, Point, Scalar, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GBoxFilter, , "org.opencv.imgproc.filters.boxfilter") { + static GMatDesc outMeta(GMatDesc in, int ddepth, Size, Point, bool, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL(GBlur, , "org.opencv.imgproc.filters.blur"){ + static GMatDesc outMeta(GMatDesc in, Size, Point, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GGaussBlur, , "org.opencv.imgproc.filters.gaussianBlur") { + static GMatDesc outMeta(GMatDesc in, Size, double, double, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GMedianBlur, , "org.opencv.imgproc.filters.medianBlur") { + static GMatDesc outMeta(GMatDesc in, int) { + return in; + } + }; + + G_TYPED_KERNEL(GErode, , "org.opencv.imgproc.filters.erode") { + static GMatDesc outMeta(GMatDesc in, Mat, Point, int, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GDilate, , "org.opencv.imgproc.filters.dilate") { + static GMatDesc outMeta(GMatDesc in, Mat, Point, int, int, Scalar) { + return in; + } + }; + + G_TYPED_KERNEL(GSobel, , "org.opencv.imgproc.filters.sobel") { + static GMatDesc outMeta(GMatDesc in, int ddepth, int, int, int, double, double, int, Scalar) { + return in.withDepth(ddepth); + } + }; + + G_TYPED_KERNEL_M(GSobelXY, , "org.opencv.imgproc.filters.sobelxy") { + static std::tuple outMeta(GMatDesc in, int ddepth, int, int, double, double, int, Scalar) { + return std::make_tuple(in.withDepth(ddepth), in.withDepth(ddepth)); + } + }; + + G_TYPED_KERNEL(GEqHist, , "org.opencv.imgproc.equalizeHist"){ + static GMatDesc outMeta(GMatDesc in) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GCanny, , "org.opencv.imgproc.canny"){ + static GMatDesc outMeta(GMatDesc in, double, double, int, bool) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GRGB2YUV, , "org.opencv.imgproc.colorconvert.rgb2yuv") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GYUV2RGB, , "org.opencv.imgproc.colorconvert.yuv2rgb") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GNV12toRGB, , "org.opencv.imgproc.colorconvert.nv12torgb") { + static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) { + GAPI_Assert(in_y.chan == 1); + GAPI_Assert(in_uv.chan == 2); + GAPI_Assert(in_y.depth == CV_8U); + GAPI_Assert(in_uv.depth == CV_8U); + // UV size should be aligned with Y + GAPI_Assert(in_y.size.width == 2 * in_uv.size.width); + GAPI_Assert(in_y.size.height == 2 * in_uv.size.height); + return in_y.withType(CV_8U, 3); // type will be CV_8UC3; + } + }; + + G_TYPED_KERNEL(GNV12toBGR, , "org.opencv.imgproc.colorconvert.nv12tobgr") { + static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) { + GAPI_Assert(in_y.chan == 1); + GAPI_Assert(in_uv.chan == 2); + GAPI_Assert(in_y.depth == CV_8U); + GAPI_Assert(in_uv.depth == CV_8U); + // UV size should be aligned with Y + GAPI_Assert(in_y.size.width == 2 * in_uv.size.width); + GAPI_Assert(in_y.size.height == 2 * in_uv.size.height); + return in_y.withType(CV_8U, 3); // type will be CV_8UC3; + } + }; + + G_TYPED_KERNEL(GRGB2Lab, , "org.opencv.imgproc.colorconvert.rgb2lab") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GBGR2LUV, , "org.opencv.imgproc.colorconvert.bgr2luv") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GLUV2BGR, , "org.opencv.imgproc.colorconvert.luv2bgr") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GYUV2BGR, , "org.opencv.imgproc.colorconvert.yuv2bgr") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GBGR2YUV, , "org.opencv.imgproc.colorconvert.bgr2yuv") { + static GMatDesc outMeta(GMatDesc in) { + return in; // type still remains CV_8UC3; + } + }; + + G_TYPED_KERNEL(GRGB2Gray, , "org.opencv.imgproc.colorconvert.rgb2gray") { + static GMatDesc outMeta(GMatDesc in) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GRGB2GrayCustom, , "org.opencv.imgproc.colorconvert.rgb2graycustom") { + static GMatDesc outMeta(GMatDesc in, float, float, float) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GBGR2Gray, , "org.opencv.imgproc.colorconvert.bgr2gray") { + static GMatDesc outMeta(GMatDesc in) { + return in.withType(CV_8U, 1); + } + }; + + G_TYPED_KERNEL(GBayerGR2RGB, , "org.opencv.imgproc.colorconvert.bayergr2rgb") { + static cv::GMatDesc outMeta(cv::GMatDesc in) { + return in.withType(CV_8U, 3); + } + }; + + G_TYPED_KERNEL(GRGB2HSV, , "org.opencv.imgproc.colorconvert.rgb2hsv") { + static cv::GMatDesc outMeta(cv::GMatDesc in) { + return in; + } + }; + + G_TYPED_KERNEL(GRGB2YUV422, , "org.opencv.imgproc.colorconvert.rgb2yuv422") { + static cv::GMatDesc outMeta(cv::GMatDesc in) { + GAPI_Assert(in.depth == CV_8U); + GAPI_Assert(in.chan == 3); + return in.withType(in.depth, 2); + } + }; + + G_TYPED_KERNEL(GNV12toRGBp, , "org.opencv.colorconvert.imgproc.nv12torgbp") { + static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) { + GAPI_Assert(inY.depth == CV_8U); + GAPI_Assert(inUV.depth == CV_8U); + GAPI_Assert(inY.chan == 1); + GAPI_Assert(inY.planar == false); + GAPI_Assert(inUV.chan == 2); + GAPI_Assert(inUV.planar == false); + GAPI_Assert(inY.size.width == 2 * inUV.size.width); + GAPI_Assert(inY.size.height == 2 * inUV.size.height); + return inY.withType(CV_8U, 3).asPlanar(); + } + }; + + G_TYPED_KERNEL(GNV12toBGRp, , "org.opencv.colorconvert.imgproc.nv12tobgrp") { + static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) { + GAPI_Assert(inY.depth == CV_8U); + GAPI_Assert(inUV.depth == CV_8U); + GAPI_Assert(inY.chan == 1); + GAPI_Assert(inY.planar == false); + GAPI_Assert(inUV.chan == 2); + GAPI_Assert(inUV.planar == false); + GAPI_Assert(inY.size.width == 2 * inUV.size.width); + GAPI_Assert(inY.size.height == 2 * inUV.size.height); + return inY.withType(CV_8U, 3).asPlanar(); + } + }; + +} + + +//! @addtogroup gapi_filters +//! @{ +/** @brief Applies a separable linear filter to a matrix(image). + +The function applies a separable linear filter to the matrix. That is, first, every row of src is +filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D +kernel kernelY. The final result is returned. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note In case of floating-point computation, rounding to nearest even is procedeed +if hardware supports it (if not - to nearest value). + +@note Function textual ID is "org.opencv.imgproc.filters.sepfilter" +@param src Source image. +@param ddepth desired depth of the destination image (the following combinations of src.depth() and ddepth are supported: + + src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F + src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F + src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F + src.depth() = CV_64F, ddepth = -1/CV_64F + +when ddepth=-1, the output image will have the same depth as the source) +@param kernelX Coefficients for filtering each row. +@param kernelY Coefficients for filtering each column. +@param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor +is at the kernel center. +@param delta Value added to the filtered results before storing them. +@param borderType Pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa boxFilter, gaussianBlur, medianBlur + */ +GAPI_EXPORTS GMat sepFilter(const GMat& src, int ddepth, const Mat& kernelX, const Mat& kernelY, const Point& anchor /*FIXME: = Point(-1,-1)*/, + const Scalar& delta /*FIXME = GScalar(0)*/, int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Convolves an image with the kernel. + +The function applies an arbitrary linear filter to an image. When +the aperture is partially outside the image, the function interpolates outlier pixel values +according to the specified border mode. + +The function does actually compute correlation, not the convolution: + +\f[\texttt{dst} (x,y) = \sum _{ \stackrel{0\leq x' < \texttt{kernel.cols},}{0\leq y' < \texttt{kernel.rows}} } \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )\f] + +That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip +the kernel using flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows - +anchor.y - 1)`. + +Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same size and number of channels an input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.filter2D" + +@param src input image. +@param ddepth desired depth of the destination image +@param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point +matrix; if you want to apply different kernels to different channels, split the image into +separate color planes using split and process them individually. +@param anchor anchor of the kernel that indicates the relative position of a filtered point within +the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor +is at the kernel center. +@param delta optional value added to the filtered pixels before storing them in dst. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa sepFilter + */ +GAPI_EXPORTS GMat filter2D(const GMat& src, int ddepth, const Mat& kernel, const Point& anchor = Point(-1,-1), const Scalar& delta = Scalar(0), + int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0)); + + +/** @brief Blurs an image using the box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \end{bmatrix}\f] + +where + +\f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f] + +Unnormalized box filter is useful for computing various integral characteristics over each pixel +neighborhood, such as covariance matrices of image derivatives (used in dense optical flow +algorithms, and so on). If you need to compute pixel sums over variable-size windows, use cv::integral. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.boxfilter" + +@param src Source image. +@param dtype the output image depth (-1 to set the input image data type). +@param ksize blurring kernel size. +@param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor +is at the kernel center. +@param normalize flag, specifying whether the kernel is normalized by its area or not. +@param borderType Pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa sepFilter, gaussianBlur, medianBlur, integral + */ +GAPI_EXPORTS GMat boxFilter(const GMat& src, int dtype, const Size& ksize, const Point& anchor = Point(-1,-1), + bool normalize = true, int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Blurs an image using the normalized box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \end{bmatrix}\f] + +The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(), +anchor, true, borderType)`. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.blur" + +@param src Source image. +@param ksize blurring kernel size. +@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel +center. +@param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa boxFilter, bilateralFilter, GaussianBlur, medianBlur + */ +GAPI_EXPORTS GMat blur(const GMat& src, const Size& ksize, const Point& anchor = Point(-1,-1), + int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0)); + + +//GAPI_EXPORTS_W void blur( InputArray src, OutputArray dst, + // Size ksize, Point anchor = Point(-1,-1), + // int borderType = BORDER_DEFAULT ); + + +/** @brief Blurs an image using a Gaussian filter. + +The function filter2Ds the source image with the specified Gaussian kernel. +Output image must have the same type and number of channels an input image. + +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.gaussianBlur" + +@param src input image; +@param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be +positive and odd. Or, they can be zero's and then they are computed from sigma. +@param sigmaX Gaussian kernel standard deviation in X direction. +@param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be +equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, +respectively (see cv::getGaussianKernel for details); to fully control the result regardless of +possible future modifications of all this semantics, it is recommended to specify all of ksize, +sigmaX, and sigmaY. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa sepFilter, boxFilter, medianBlur + */ +GAPI_EXPORTS GMat gaussianBlur(const GMat& src, const Size& ksize, double sigmaX, double sigmaY = 0, + int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0)); + +/** @brief Blurs an image using the median filter. + +The function smoothes an image using the median filter with the \f$\texttt{ksize} \times +\texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. +The median filter uses cv::BORDER_REPLICATE internally to cope with border pixels, see cv::BorderTypes + +@note Function textual ID is "org.opencv.imgproc.filters.medianBlur" + +@param src input matrix (image) +@param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ... +@sa boxFilter, gaussianBlur + */ +GAPI_EXPORTS GMat medianBlur(const GMat& src, int ksize); + +/** @brief Erodes an image by using a specific structuring element. + +The function erodes the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the minimum is taken: + +\f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +Erosion can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.erode" + +@param src input image +@param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular +structuring element is used. Kernel can be created using getStructuringElement. +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times erosion is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa dilate + */ +GAPI_EXPORTS GMat erode(const GMat& src, const Mat& kernel, const Point& anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Erodes an image by using 3 by 3 rectangular structuring element. + +The function erodes the source image using the rectangular structuring element with rectangle center as an anchor. +Erosion can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@param src input image +@param iterations number of times erosion is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa erode, dilate3x3 + */ +GAPI_EXPORTS GMat erode3x3(const GMat& src, int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Dilates an image by using a specific structuring element. + +The function dilates the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the maximum is taken: +\f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +Dilation can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.dilate" + +@param src input image. +@param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular +structuring element is used. Kernel can be created using getStructuringElement +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times dilation is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa erode, morphologyEx, getStructuringElement + */ +GAPI_EXPORTS GMat dilate(const GMat& src, const Mat& kernel, const Point& anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Dilates an image by using 3 by 3 rectangular structuring element. + +The function dilates the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the maximum is taken: +\f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +Dilation can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently. +Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1. +Output image must have the same type, size, and number of channels as the input image. +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.dilate" + +@param src input image. +@param iterations number of times dilation is applied. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of a constant border +@sa dilate, erode3x3 + */ + +GAPI_EXPORTS GMat dilate3x3(const GMat& src, int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue()); + +/** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. + +In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to +calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$ +kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first +or the second x- or y- derivatives. + +There is also the special value `ksize = FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr +filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is + +\f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] + +for the x-derivative, or transposed for the y-derivative. + +The function calculates an image derivative by convolving the image with the appropriate kernel: + +\f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f] + +The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less +resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) +or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first +case corresponds to a kernel of: + +\f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f] + +The second case corresponds to a kernel of: + +\f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f] + +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.sobel" + +@param src input image. +@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of + 8-bit input images it will result in truncated derivatives. +@param dx order of the derivative x. +@param dy order of the derivative y. +@param ksize size of the extended Sobel kernel; it must be odd. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see cv::getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa filter2D, gaussianBlur, cartToPolar + */ +GAPI_EXPORTS GMat Sobel(const GMat& src, int ddepth, int dx, int dy, int ksize = 3, + double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. + +In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to +calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$ +kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first +or the second x- or y- derivatives. + +There is also the special value `ksize = FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr +filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is + +\f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] + +for the x-derivative, or transposed for the y-derivative. + +The function calculates an image derivative by convolving the image with the appropriate kernel: + +\f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f] + +The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less +resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) +or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first +case corresponds to a kernel of: + +\f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f] + +The second case corresponds to a kernel of: + +\f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f] + +@note First returned matrix correspons to dx derivative while the second one to dy. + +@note Rounding to nearest even is procedeed if hardware supports it, if not - to nearest. + +@note Function textual ID is "org.opencv.imgproc.filters.sobelxy" + +@param src input image. +@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of + 8-bit input images it will result in truncated derivatives. +@param order order of the derivatives. +@param ksize size of the extended Sobel kernel; it must be odd. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see cv::getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see cv::BorderTypes +@param borderValue border value in case of constant border type +@sa filter2D, gaussianBlur, cartToPolar + */ +GAPI_EXPORTS std::tuple SobelXY(const GMat& src, int ddepth, int order, int ksize = 3, + double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT, + const Scalar& borderValue = Scalar(0)); + +/** @brief Finds edges in an image using the Canny algorithm. + +The function finds edges in the input image and marks them in the output map edges using the +Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The +largest value is used to find initial segments of strong edges. See + + +@note Function textual ID is "org.opencv.imgproc.filters.canny" + +@param image 8-bit input image. +@param threshold1 first threshold for the hysteresis procedure. +@param threshold2 second threshold for the hysteresis procedure. +@param apertureSize aperture size for the Sobel operator. +@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm +\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude ( +L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( +L2gradient=false ). + */ +GAPI_EXPORTS GMat Canny(const GMat& image, double threshold1, double threshold2, + int apertureSize = 3, bool L2gradient = false); + +/** @brief Equalizes the histogram of a grayscale image. + +The function equalizes the histogram of the input image using the following algorithm: + +- Calculate the histogram \f$H\f$ for src . +- Normalize the histogram so that the sum of histogram bins is 255. +- Compute the integral of the histogram: +\f[H'_i = \sum _{0 \le j < i} H(j)\f] +- Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$ + +The algorithm normalizes the brightness and increases the contrast of the image. +@note The returned image is of the same size and type as input. + +@note Function textual ID is "org.opencv.imgproc.equalizeHist" + +@param src Source 8-bit single channel image. + */ +GAPI_EXPORTS GMat equalizeHist(const GMat& src); + +//! @} gapi_filters + +//! @addtogroup gapi_colorconvert +//! @{ +/** @brief Converts an image from RGB color space to gray-scaled. +The conventional ranges for R, G, and B channel values are 0 to 255. +Resulting gray color value computed as +\f[\texttt{dst} (I)= \texttt{0.299} * \texttt{src}(I).R + \texttt{0.587} * \texttt{src}(I).G + \texttt{0.114} * \texttt{src}(I).B \f] + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2gray" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@sa RGB2YUV + */ +GAPI_EXPORTS GMat RGB2Gray(const GMat& src); + +/** @overload +Resulting gray color value computed as +\f[\texttt{dst} (I)= \texttt{rY} * \texttt{src}(I).R + \texttt{gY} * \texttt{src}(I).G + \texttt{bY} * \texttt{src}(I).B \f] + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2graycustom" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@param rY float multiplier for R channel. +@param gY float multiplier for G channel. +@param bY float multiplier for B channel. +@sa RGB2YUV + */ +GAPI_EXPORTS GMat RGB2Gray(const GMat& src, float rY, float gY, float bY); + +/** @brief Converts an image from BGR color space to gray-scaled. +The conventional ranges for B, G, and R channel values are 0 to 255. +Resulting gray color value computed as +\f[\texttt{dst} (I)= \texttt{0.114} * \texttt{src}(I).B + \texttt{0.587} * \texttt{src}(I).G + \texttt{0.299} * \texttt{src}(I).R \f] + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2gray" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@sa BGR2LUV + */ +GAPI_EXPORTS GMat BGR2Gray(const GMat& src); + +/** @brief Converts an image from RGB color space to YUV color space. + +The function converts an input image from RGB color space to YUV. +The conventional ranges for R, G, and B channel values are 0 to 255. + +In case of linear transformations, the range does not matter. But in case of a non-linear +transformation, an input RGB image should be normalized to the proper value range to get the correct +results, like here, at RGB \f$\rightarrow\f$ Y\*u\*v\* transformation. +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2yuv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa YUV2RGB, RGB2Lab +*/ +GAPI_EXPORTS GMat RGB2YUV(const GMat& src); + +/** @brief Converts an image from BGR color space to LUV color space. + +The function converts an input image from BGR color space to LUV. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2luv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa RGB2Lab, RGB2LUV +*/ +GAPI_EXPORTS GMat BGR2LUV(const GMat& src); + +/** @brief Converts an image from LUV color space to BGR color space. + +The function converts an input image from LUV color space to BGR. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.luv2bgr" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa BGR2LUV +*/ +GAPI_EXPORTS GMat LUV2BGR(const GMat& src); + +/** @brief Converts an image from YUV color space to BGR color space. + +The function converts an input image from YUV color space to BGR. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.yuv2bgr" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa BGR2YUV +*/ +GAPI_EXPORTS GMat YUV2BGR(const GMat& src); + +/** @brief Converts an image from BGR color space to YUV color space. + +The function converts an input image from BGR color space to YUV. +The conventional ranges for B, G, and R channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2yuv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@sa YUV2BGR +*/ +GAPI_EXPORTS GMat BGR2YUV(const GMat& src); + +/** @brief Converts an image from RGB color space to Lab color space. + +The function converts an input image from BGR color space to Lab. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC1. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2lab" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1. +@sa RGB2YUV, RGB2LUV +*/ +GAPI_EXPORTS GMat RGB2Lab(const GMat& src); + +/** @brief Converts an image from YUV color space to RGB. +The function converts an input image from YUV color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.yuv2rgb" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. + +@sa RGB2Lab, RGB2YUV +*/ +GAPI_EXPORTS GMat YUV2RGB(const GMat& src); + +/** @brief Converts an image from NV12 (YUV420p) color space to RGB. +The function converts an input image from NV12 color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgb" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2RGB, NV12toBGR +*/ +GAPI_EXPORTS GMat NV12toRGB(const GMat& src_y, const GMat& src_uv); + +/** @brief Converts an image from NV12 (YUV420p) color space to BGR. +The function converts an input image from NV12 color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12tobgr" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat NV12toBGR(const GMat& src_y, const GMat& src_uv); + +/** @brief Converts an image from BayerGR color space to RGB. +The function converts an input image from BayerGR color space to RGB. +The conventional ranges for G, R, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.bayergr2rgb" + +@param src_gr input image: 8-bit unsigned 1-channel image @ref CV_8UC1. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat BayerGR2RGB(const GMat& src_gr); + +/** @brief Converts an image from RGB color space to HSV. +The function converts an input image from RGB color space to HSV. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2hsv" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat RGB2HSV(const GMat& src); + +/** @brief Converts an image from RGB color space to YUV422. +The function converts an input image from RGB color space to YUV422. +The conventional ranges for R, G, and B channel values are 0 to 255. + +Output image must be 8-bit unsigned 2-channel image @ref CV_8UC2. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2yuv422" + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3. + +@sa YUV2BGR, NV12toRGB +*/ +GAPI_EXPORTS GMat RGB2YUV422(const GMat& src); + +/** @brief Converts an image from NV12 (YUV420p) color space to RGB. +The function converts an input image from NV12 color space to RGB. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned planar 3-channel image @ref CV_8UC1. +Planar image memory layout is three planes laying in the memory contiguously, +so the image height should be plane_height*plane_number, +image type is @ref CV_8UC1. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgbp" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2RGB, NV12toBGRp, NV12toRGB +*/ +GAPI_EXPORTS GMatP NV12toRGBp(const GMat &src_y, const GMat &src_uv); + +/** @brief Converts an image from NV12 (YUV420p) color space to BGR. +The function converts an input image from NV12 color space to BGR. +The conventional ranges for Y, U, and V channel values are 0 to 255. + +Output image must be 8-bit unsigned planar 3-channel image @ref CV_8UC1. +Planar image memory layout is three planes laying in the memory contiguously, +so the image height should be plane_height*plane_number, +image type is @ref CV_8UC1. + +@note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgbp" + +@param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2. + +@sa YUV2RGB, NV12toRGBp, NV12toBGR +*/ +GAPI_EXPORTS GMatP NV12toBGRp(const GMat &src_y, const GMat &src_uv); + +//! @} gapi_colorconvert +} //namespace gapi +} //namespace cv + +#endif // OPENCV_GAPI_IMGPROC_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/infer.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/infer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a6ffb7a9ffba95944935901e1a4e4db8dae23044 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/infer.hpp @@ -0,0 +1,236 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + + +#ifndef OPENCV_GAPI_INFER_HPP +#define OPENCV_GAPI_INFER_HPP + +// FIXME: Inference API is currently only available in full mode +#if !defined(GAPI_STANDALONE) + +#include +#include // string +#include // tuple + +#include // any<> +#include // GKernelType[M], GBackend +#include // GArg +#include // CompileArgTag +#include // GMetaArg + +namespace cv { + +namespace detail { + // This tiny class eliminates the semantic difference between + // GKernelType and GKernelTypeM. + // FIXME: Something similar can be reused for regular kernels + template + struct KernelTypeMedium; + + template + struct KernelTypeMedium(Args...)> >: + public GKernelTypeM(Args...)> > {}; + + template + struct KernelTypeMedium >: + public GKernelType > {}; + +} // namespace detail + +template class GNetworkType; + +// TODO: maybe tuple_wrap_helper from util.hpp may help with this. +// Multiple-return-value network definition (specialized base class) +template +class GNetworkType(Args...)> > +{ +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + using Result = OutArgs; + using API = std::function; + + using ResultL = std::tuple< cv::GArray... >; + using APIList = std::function, Args...)>; +}; + +// Single-return-value network definition (specialized base class) +template +class GNetworkType > +{ +public: + using InArgs = std::tuple; + using OutArgs = std::tuple; + + using Result = R; + using API = std::function; + + using ResultL = cv::GArray; + using APIList = std::function, Args...)>; +}; + +// Base "Infer" kernel. Note - for whatever network, kernel ID +// is always the same. Different inference calls are distinguished by +// network _tag_ (an extra field in GCall) +// +// getOutMeta is a stub callback collected by G-API kernel subsystem +// automatically. This is a rare case when this callback is defined by +// a particular backend, not by a network itself. +struct GInferBase { + static constexpr const char * id() { + return "org.opencv.dnn.infer"; // Universal stub + } + static GMetaArgs getOutMeta(const GMetaArgs &, const GArgs &) { + return GMetaArgs{}; // One more universal stub + } +}; + + +// Base "Infer list" kernel. +// All notes from "Infer" kernel apply here as well. +struct GInferListBase { + static constexpr const char * id() { + return "org.opencv.dnn.infer-roi"; // Universal stub + } + static GMetaArgs getOutMeta(const GMetaArgs &, const GArgs &) { + return GMetaArgs{}; // One more universal stub + } +}; + +// A generic inference kernel. API (::on()) is fully defined by the Net +// template parameter. +// Acts as a regular kernel in graph (via KernelTypeMedium). +template +struct GInfer final + : public GInferBase + , public detail::KernelTypeMedium< GInfer + , typename Net::API > { + using GInferBase::getOutMeta; // FIXME: name lookup conflict workaround? + + static constexpr const char* tag() { return Net::tag(); } +}; + +// A generic roi-list inference kernel. API (::on()) is derived from +// the Net template parameter (see more in infer<> overload). +template +struct GInferList final + : public GInferListBase + , public detail::KernelTypeMedium< GInferList + , typename Net::APIList > { + using GInferListBase::getOutMeta; // FIXME: name lookup conflict workaround? + + static constexpr const char* tag() { return Net::tag(); } +}; + +} // namespace cv + +// FIXME: Probably the signature makes a function/tuple/function round-trip +#define G_API_NET(Class, API, Tag) \ + struct Class final: public cv::GNetworkType { \ + static constexpr const char * tag() { return Tag; } \ + } + +namespace cv { +namespace gapi { + + +/** @brief Calculates responses for the specified network (template + * parameter) for every region in the source image. + * + * @tparam A network type defined with G_API_NET() macro. + * @param roi a list of rectangles describing regions of interest + * in the source image. Usually an output of object detector or tracker. + * @param args network's input parameters as specified in G_API_NET() macro. + * NOTE: verified to work reliably with 1-input topologies only. + * @return a list of objects of return type as defined in G_API_NET(). + * If a network has multiple return values (defined with a tuple), a tuple of + * GArray<> objects is returned with the appropriate types inside. + * @sa G_API_NET() + */ +template +typename Net::ResultL infer(cv::GArray roi, Args&&... args) { + return GInferList::on(roi, std::forward(args)...); +} + +/** + * @brief Calculates response for the specified network (template + * parameter) given the input data. + * + * @tparam A network type defined with G_API_NET() macro. + * @param args network's input parameters as specified in G_API_NET() macro. + * @return an object of return type as defined in G_API_NET(). + * If a network has multiple return values (defined with a tuple), a tuple of + * objects of appropriate type is returned. + * @sa G_API_NET() + */ +template +typename Net::Result infer(Args&&... args) { + return GInfer::on(std::forward(args)...); +} + + +} // namespace gapi +} // namespace cv + +#endif // GAPI_STANDALONE + +namespace cv { +namespace gapi { + +// Note: the below code _is_ part of STANDALONE build, +// just to make our compiler code compileable. + +// A type-erased form of network parameters. +// Similar to how a type-erased GKernel is represented and used. +struct GAPI_EXPORTS GNetParam { + std::string tag; // FIXME: const? + GBackend backend; // Specifies the execution model + util::any params; // Backend-interpreted parameter structure +}; + +/** \addtogroup gapi_compile_args + * @{ + */ +/** + * @brief A container class for network configurations. Similar to + * GKernelPackage.Use cv::gapi::networks() to construct this object. + * + * @sa cv::gapi::networks + */ +struct GAPI_EXPORTS GNetPackage { + GNetPackage() : GNetPackage({}) {} + explicit GNetPackage(std::initializer_list &&ii); + std::vector backends() const; + std::vector networks; +}; +/** @} gapi_compile_args */ +} // namespace gapi + +namespace detail { +template +gapi::GNetParam strip(T&& t) { + return gapi::GNetParam { t.tag() + , t.backend() + , t.params() + }; +} + +template<> struct CompileArgTag { + static const char* tag() { return "gapi.net_package"; } +}; + +} // namespace cv::detail + +namespace gapi { +template +cv::gapi::GNetPackage networks(Args&&... args) { + return cv::gapi::GNetPackage({ cv::detail::strip(args)... }); +} +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_INFER_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/infer/ie.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/infer/ie.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6e8c2c3abdb8ed929c76b48e44ad5369f49db3ee --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/infer/ie.hpp @@ -0,0 +1,123 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_INFER_IE_HPP +#define OPENCV_GAPI_INFER_IE_HPP + +#include +#include +#include +#include // tuple, tuple_size + +#include +#include + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { +// FIXME: introduce a new sub-namespace for NN? +namespace ie { + +GAPI_EXPORTS cv::gapi::GBackend backend(); + +/** + * Specify how G-API and IE should trait input data + * + * In OpenCV, the same cv::Mat is used to represent both + * image and tensor data. Sometimes those are hardly distinguishable, + * so this extra parameter is used to give G-API a hint. + * + * This hint controls how G-API reinterprets the data when converting + * it to IE Blob format (and which layout/etc is assigned to this data). + */ +enum class TraitAs: int +{ + TENSOR, //!< G-API traits an associated cv::Mat as a raw tensor and passes dimensions as-is + IMAGE //!< G-API traits an associated cv::Mat as an image so creates an "image" blob (NCHW/NHWC, etc) +}; + +namespace detail { + struct ParamDesc { + std::string model_path; + std::string weights_path; + std::string device_id; + + // NB: Here order follows the `Net` API + std::vector input_names; + std::vector output_names; + + using ConstInput = std::pair; + std::unordered_map const_inputs; + + // NB: nun_* may differ from topology's real input/output port numbers + // (e.g. topology's partial execution) + std::size_t num_in; // How many inputs are defined in the operation + std::size_t num_out; // How many outputs are defined in the operation + }; +} // namespace detail + +// FIXME: this is probably a shared (reusable) thing +template +struct PortCfg { + using In = std::array + < std::string + , std::tuple_size::value >; + using Out = std::array + < std::string + , std::tuple_size::value >; +}; + +template class Params { +public: + Params(const std::string &model, + const std::string &weights, + const std::string &device) + : desc{ model, weights, device, {}, {}, {} + , std::tuple_size::value + , std::tuple_size::value + } { + }; + + Params& cfgInputLayers(const typename PortCfg::In &ll) { + desc.input_names.clear(); + desc.input_names.reserve(ll.size()); + std::copy(ll.begin(), ll.end(), + std::back_inserter(desc.input_names)); + return *this; + } + + Params& cfgOutputLayers(const typename PortCfg::Out &ll) { + desc.output_names.clear(); + desc.output_names.reserve(ll.size()); + std::copy(ll.begin(), ll.end(), + std::back_inserter(desc.output_names)); + return *this; + } + + Params& constInput(const std::string &layer_name, + const cv::Mat &data, + TraitAs hint = TraitAs::TENSOR) { + desc.const_inputs[layer_name] = {data, hint}; + return *this; + } + + // BEGIN(G-API's network parametrization API) + GBackend backend() const { return cv::gapi::ie::backend(); } + std::string tag() const { return Net::tag(); } + cv::util::any params() const { return { desc }; } + // END(G-API's network parametrization API) + +protected: + detail::ParamDesc desc; +}; + +} // namespace ie +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_INFER_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4ab85e20983e2eb06b76010a1ecac0b368a61d82 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/core.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OCL_CORE_API_HPP +#define OPENCV_GAPI_OCL_CORE_API_HPP + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace core { +namespace ocl { + + GAPI_EXPORTS GKernelPackage kernels(); + +} // namespace ocl +} // namespace core +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_OCL_CORE_API_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/goclkernel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/goclkernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a51fa8ff5df84626a182e5c3b41d8340435aa48a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/goclkernel.hpp @@ -0,0 +1,246 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_GOCLKERNEL_HPP +#define OPENCV_GAPI_GOCLKERNEL_HPP + +#include +#include +#include +#include + +#include +#include +#include +#include + +// FIXME: namespace scheme for backends? +namespace cv { + +namespace gimpl +{ + // Forward-declare an internal class + class GOCLExecutable; +} // namespace gimpl + +namespace gapi +{ +namespace ocl +{ + /** + * \addtogroup gapi_std_backends G-API Standard Backends + * @{ + */ + /** + * @brief Get a reference to OCL backend. + * + * At the moment, the OCL backend is built atop of OpenCV + * "Transparent API" (T-API), see cv::UMat for details. + * + * @sa gapi_std_backends + */ + GAPI_EXPORTS cv::gapi::GBackend backend(); + /** @} */ +} // namespace ocl +} // namespace gapi + + +// Represents arguments which are passed to a wrapped OCL function +// FIXME: put into detail? +class GAPI_EXPORTS GOCLContext +{ +public: + // Generic accessor API + template + const T& inArg(int input) { return m_args.at(input).get(); } + + // Syntax sugar + const cv::UMat& inMat(int input); + cv::UMat& outMatR(int output); // FIXME: Avoid cv::Mat m = ctx.outMatR() + + const cv::gapi::own::Scalar& inVal(int input); + cv::gapi::own::Scalar& outValR(int output); // FIXME: Avoid cv::gapi::own::Scalar s = ctx.outValR() + template std::vector& outVecR(int output) // FIXME: the same issue + { + return outVecRef(output).wref(); + } + +protected: + detail::VectorRef& outVecRef(int output); + + std::vector m_args; + std::unordered_map m_results; + + + friend class gimpl::GOCLExecutable; +}; + +class GAPI_EXPORTS GOCLKernel +{ +public: + // This function is kernel's execution entry point (does the processing work) + using F = std::function; + + GOCLKernel(); + explicit GOCLKernel(const F& f); + + void apply(GOCLContext &ctx); + +protected: + F m_f; +}; + +// FIXME: This is an ugly ad-hoc imlpementation. TODO: refactor + +namespace detail +{ +template struct ocl_get_in; +template<> struct ocl_get_in +{ + static cv::UMat get(GOCLContext &ctx, int idx) { return ctx.inMat(idx); } +}; +template<> struct ocl_get_in +{ + static cv::Scalar get(GOCLContext &ctx, int idx) { return to_ocv(ctx.inVal(idx)); } +}; +template struct ocl_get_in > +{ + static const std::vector& get(GOCLContext &ctx, int idx) { return ctx.inArg(idx).rref(); } +}; +template struct ocl_get_in +{ + static T get(GOCLContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +struct tracked_cv_umat{ + //TODO Think if T - API could reallocate UMat to a proper size - how do we handle this ? + //tracked_cv_umat(cv::UMat& m) : r{(m)}, original_data{m.getMat(ACCESS_RW).data} {} + tracked_cv_umat(cv::UMat& m) : r(m), original_data{ nullptr } {} + cv::UMat &r; // FIXME: It was a value (not a reference) before. + // Actually OCL backend should allocate its internal data! + uchar* original_data; + + operator cv::UMat& (){ return r;} + void validate() const{ + //if (r.getMat(ACCESS_RW).data != original_data) + //{ + // util::throw_error + // (std::logic_error + // ("OpenCV kernel output parameter was reallocated. \n" + // "Incorrect meta data was provided ?")); + //} + + } +}; + +struct scalar_wrapper_ocl +{ + //FIXME reuse CPU (OpenCV) plugin code + scalar_wrapper_ocl(cv::gapi::own::Scalar& s) : m_s{cv::gapi::own::to_ocv(s)}, m_org_s(s) {}; + operator cv::Scalar& () { return m_s; } + void writeBack() const { m_org_s = to_own(m_s); } + + cv::Scalar m_s; + cv::gapi::own::Scalar& m_org_s; +}; + +template +void postprocess_ocl(Outputs&... outs) +{ + struct + { + void operator()(tracked_cv_umat* bm) { bm->validate(); } + void operator()(scalar_wrapper_ocl* sw) { sw->writeBack(); } + void operator()(...) { } + + } validate; + //dummy array to unfold parameter pack + int dummy[] = { 0, (validate(&outs), 0)... }; + cv::util::suppress_unused_warning(dummy); +} + +template struct ocl_get_out; +template<> struct ocl_get_out +{ + static tracked_cv_umat get(GOCLContext &ctx, int idx) + { + auto& r = ctx.outMatR(idx); + return{ r }; + } +}; +template<> struct ocl_get_out +{ + static scalar_wrapper_ocl get(GOCLContext &ctx, int idx) + { + auto& s = ctx.outValR(idx); + return{ s }; + } +}; +template struct ocl_get_out > +{ + static std::vector& get(GOCLContext &ctx, int idx) { return ctx.outVecR(idx); } +}; + +template +struct OCLCallHelper; + +// FIXME: probably can be simplified with std::apply or analogue. +template +struct OCLCallHelper, std::tuple > +{ + template + struct call_and_postprocess + { + template + static void call(Inputs&&... ins, Outputs&&... outs) + { + //not using a std::forward on outs is deliberate in order to + //cause compilation error, by trying to bind rvalue references to lvalue references + Impl::run(std::forward(ins)..., outs...); + + postprocess_ocl(outs...); + } + }; + + template + static void call_impl(GOCLContext &ctx, detail::Seq, detail::Seq) + { + //TODO: Make sure that OpenCV kernels do not reallocate memory for output parameters + //by comparing it's state (data ptr) before and after the call. + //Convert own::Scalar to cv::Scalar before call kernel and run kernel + //convert cv::Scalar to own::Scalar after call kernel and write back results + call_and_postprocess::get(ctx, IIs))...>::call(ocl_get_in::get(ctx, IIs)..., ocl_get_out::get(ctx, OIs)...); + } + + static void call(GOCLContext &ctx) + { + call_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +} // namespace detail + +template +class GOCLKernelImpl: public cv::detail::OCLCallHelper, + public cv::detail::KernelTag +{ + using P = detail::OCLCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::ocl::backend(); } + static cv::GOCLKernel kernel() { return GOCLKernel(&P::call); } +}; + +#define GAPI_OCL_KERNEL(Name, API) struct Name: public cv::GOCLKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GOCLKERNEL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/imgproc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/imgproc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1bb5911b1869de4fdb8d7dd14b5571fbabb6ff1b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/ocl/imgproc.hpp @@ -0,0 +1,27 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OCL_IMGPROC_API_HPP +#define OPENCV_GAPI_OCL_IMGPROC_API_HPP + +#include // GAPI_EXPORTS +#include // GKernelPackage + +namespace cv { +namespace gapi { +namespace imgproc { +namespace ocl { + + GAPI_EXPORTS GKernelPackage kernels(); + +} // namespace ocl +} // namespace imgproc +} // namespace gapi +} // namespace cv + + +#endif // OPENCV_GAPI_OCL_IMGPROC_API_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/opencv_includes.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/opencv_includes.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5acf28023d070a85e32b6b851d5c77e966e55f83 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/opencv_includes.hpp @@ -0,0 +1,21 @@ +// This file is part of OpenCV project. + +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OPENCV_INCLUDES_HPP +#define OPENCV_GAPI_OPENCV_INCLUDES_HPP + +#if !defined(GAPI_STANDALONE) +# include +# include +# include +# include +#else // Without OpenCV +# include +#endif // !defined(GAPI_STANDALONE) + +#endif // OPENCV_GAPI_OPENCV_INCLUDES_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/operators.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/operators.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b20062cfd54806ab9eda47e091373bee60a9a315 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/operators.hpp @@ -0,0 +1,69 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OPERATORS_HPP +#define OPENCV_GAPI_OPERATORS_HPP + +#include +#include + +GAPI_EXPORTS cv::GMat operator+(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator+(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator+(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator-(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator-(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator-(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator*(const cv::GMat& lhs, float rhs); +GAPI_EXPORTS cv::GMat operator*(float lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator*(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator*(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator/(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator/(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator/(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator&(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator|(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator^(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator~(const cv::GMat& lhs); + +GAPI_EXPORTS cv::GMat operator&(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator|(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator^(const cv::GScalar& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator&(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator|(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator^(const cv::GMat& lhs, const cv::GScalar& rhs); + +GAPI_EXPORTS cv::GMat operator>(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator>=(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<=(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator==(const cv::GMat& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator!=(const cv::GMat& lhs, const cv::GMat& rhs); + +GAPI_EXPORTS cv::GMat operator>(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator>=(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator<(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator<=(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator==(const cv::GMat& lhs, const cv::GScalar& rhs); +GAPI_EXPORTS cv::GMat operator!=(const cv::GMat& lhs, const cv::GScalar& rhs); + +GAPI_EXPORTS cv::GMat operator>(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator>=(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator<=(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator==(const cv::GScalar& lhs, const cv::GMat& rhs); +GAPI_EXPORTS cv::GMat operator!=(const cv::GScalar& lhs, const cv::GMat& rhs); + + + +#endif // OPENCV_GAPI_OPERATORS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/assert.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/assert.hpp new file mode 100644 index 0000000000000000000000000000000000000000..92b246ff6d35b2609b3098de71e2bf4734439098 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/assert.hpp @@ -0,0 +1,43 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_ASSERT_HPP +#define OPENCV_GAPI_OWN_ASSERT_HPP + +#if !defined(GAPI_STANDALONE) +#include +#define GAPI_Assert CV_Assert +#define GAPI_DbgAssert CV_DbgAssert + +#else +#include +#include +#include + +namespace detail +{ + inline void assert_abort(const char* str, int line, const char* file, const char* func) + { + std::stringstream ss; + ss << file << ":" << line << ": Assertion " << str << " in function " << func << " failed\n"; + cv::util::throw_error(std::logic_error(ss.str())); + } +} + +#define GAPI_Assert(expr) \ +{ if (!(expr)) ::detail::assert_abort(#expr, __LINE__, __FILE__, __func__); } + + +#ifdef NDEBUG +# define GAPI_DbgAssert(expr) +#else +# define GAPI_DbgAssert(expr) GAPI_Assert(expr) +#endif + +#endif // GAPI_STANDALONE + +#endif // OPENCV_GAPI_OWN_ASSERT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/convert.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/convert.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a3154444569ed3f78a56a0e524b9c07a6b7a8f91 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/convert.hpp @@ -0,0 +1,69 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_CONVERT_HPP +#define OPENCV_GAPI_OWN_CONVERT_HPP + +#if !defined(GAPI_STANDALONE) + +#include +#include +#include +#include + +namespace cv +{ + template + std::vector to_own(const cv::MatSize &sz) { + std::vector result(sz.dims()); + for (int i = 0; i < sz.dims(); i++) { + // Note: cv::MatSize is not iterable + result[i] = static_cast(sz[i]); + } + return result; + } + + cv::gapi::own::Mat to_own(Mat&&) = delete; + + inline cv::gapi::own::Mat to_own(Mat const& m) { + return (m.dims == 2) + ? cv::gapi::own::Mat{m.rows, m.cols, m.type(), m.data, m.step} + : cv::gapi::own::Mat{to_own(m.size), m.type(), m.data}; + }; + + + inline cv::gapi::own::Scalar to_own(const cv::Scalar& s) { return {s[0], s[1], s[2], s[3]}; }; + + inline cv::gapi::own::Size to_own (const Size& s) { return {s.width, s.height}; }; + + inline cv::gapi::own::Rect to_own (const Rect& r) { return {r.x, r.y, r.width, r.height}; }; + + +namespace gapi +{ +namespace own +{ + inline cv::Mat to_ocv(Mat const& m) { + return m.dims.empty() + ? cv::Mat{m.rows, m.cols, m.type(), m.data, m.step} + : cv::Mat{m.dims, m.type(), m.data}; + } + cv::Mat to_ocv(Mat&&) = delete; + + inline cv::Scalar to_ocv(const Scalar& s) { return {s[0], s[1], s[2], s[3]}; }; + + inline cv::Size to_ocv (const Size& s) { return cv::Size(s.width, s.height); }; + + inline cv::Rect to_ocv (const Rect& r) { return cv::Rect(r.x, r.y, r.width, r.height); }; + +} // namespace own +} // namespace gapi +} // namespace cv + +#endif // !defined(GAPI_STANDALONE) + +#endif // OPENCV_GAPI_OWN_CONVERT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/cvdefs.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/cvdefs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..71c2aa8e2d91dfddf12d828448b4d578836e4383 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/cvdefs.hpp @@ -0,0 +1,150 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_CV_DEFS_HPP +#define OPENCV_GAPI_CV_DEFS_HPP + +#if defined(GAPI_STANDALONE) + +// Simulate OpenCV definitions taken from various +// OpenCV interface headers if G-API is built in a +// standalone mode. + +// interface.h: + +typedef unsigned char uchar; +typedef char schar; + +typedef unsigned short ushort; + +#define CV_CN_MAX 512 +#define CV_CN_SHIFT 3 +#define CV_DEPTH_MAX (1 << CV_CN_SHIFT) + + +#define CV_8U 0 +#define CV_8S 1 +#define CV_16U 2 +#define CV_16S 3 +#define CV_32S 4 +#define CV_32F 5 +#define CV_64F 6 +#define CV_USRTYPE1 7 + +#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) +#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) + +#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) +#define CV_MAKE_TYPE CV_MAKETYPE + +#define CV_8UC1 CV_MAKETYPE(CV_8U,1) +#define CV_8UC2 CV_MAKETYPE(CV_8U,2) +#define CV_8UC3 CV_MAKETYPE(CV_8U,3) +#define CV_8UC4 CV_MAKETYPE(CV_8U,4) +#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) + +#define CV_8SC1 CV_MAKETYPE(CV_8S,1) +#define CV_8SC2 CV_MAKETYPE(CV_8S,2) +#define CV_8SC3 CV_MAKETYPE(CV_8S,3) +#define CV_8SC4 CV_MAKETYPE(CV_8S,4) +#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) + +#define CV_16UC1 CV_MAKETYPE(CV_16U,1) +#define CV_16UC2 CV_MAKETYPE(CV_16U,2) +#define CV_16UC3 CV_MAKETYPE(CV_16U,3) +#define CV_16UC4 CV_MAKETYPE(CV_16U,4) +#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) + +#define CV_16SC1 CV_MAKETYPE(CV_16S,1) +#define CV_16SC2 CV_MAKETYPE(CV_16S,2) +#define CV_16SC3 CV_MAKETYPE(CV_16S,3) +#define CV_16SC4 CV_MAKETYPE(CV_16S,4) +#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) + +#define CV_32SC1 CV_MAKETYPE(CV_32S,1) +#define CV_32SC2 CV_MAKETYPE(CV_32S,2) +#define CV_32SC3 CV_MAKETYPE(CV_32S,3) +#define CV_32SC4 CV_MAKETYPE(CV_32S,4) +#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) + +#define CV_32FC1 CV_MAKETYPE(CV_32F,1) +#define CV_32FC2 CV_MAKETYPE(CV_32F,2) +#define CV_32FC3 CV_MAKETYPE(CV_32F,3) +#define CV_32FC4 CV_MAKETYPE(CV_32F,4) +#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) + +#define CV_64FC1 CV_MAKETYPE(CV_64F,1) +#define CV_64FC2 CV_MAKETYPE(CV_64F,2) +#define CV_64FC3 CV_MAKETYPE(CV_64F,3) +#define CV_64FC4 CV_MAKETYPE(CV_64F,4) +#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) + +// cvdef.h: + +#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT) +#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1) +#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1) +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) +#define CV_MAT_CONT_FLAG_SHIFT 14 +#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT) +#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG) +#define CV_IS_CONT_MAT CV_IS_MAT_CONT +#define CV_SUBMAT_FLAG_SHIFT 15 +#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT) +#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG) + +///** Size of each channel item, +// 0x8442211 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */ +//#define CV_ELEM_SIZE1(type) \ +// ((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15) + +#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK) + +/** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */ +#define CV_ELEM_SIZE(type) \ + (CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3)) + +#ifndef CV_OVERRIDE +# define CV_OVERRIDE override +#endif + +// base.h: +namespace cv +{ +enum BorderTypes { + BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i` + BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh` + BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb` + BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg` + BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba` + BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno` + + BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101 + BORDER_ISOLATED = 16 //!< do not look outside of ROI +}; +// imgproc.hpp: +enum InterpolationFlags{ + INTER_NEAREST = 0, + INTER_LINEAR = 1, + INTER_CUBIC = 2, + INTER_AREA = 3, + INTER_LANCZOS4 = 4, + INTER_LINEAR_EXACT = 5, + INTER_MAX = 7, +}; +} // namespace cv + +static inline int cvFloor( double value ) +{ + int i = (int)value; + return i - (i > value); +} + +#endif // defined(GAPI_STANDALONE) + +#endif // OPENCV_GAPI_CV_DEFS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/exports.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/exports.hpp new file mode 100644 index 0000000000000000000000000000000000000000..53bff2aef437553c9bea3b633d7f52bd56dc31df --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/exports.hpp @@ -0,0 +1,31 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_TYPES_HPP +#define OPENCV_GAPI_OWN_TYPES_HPP + +# if defined(__OPENCV_BUILD) +# include +# define GAPI_EXPORTS CV_EXPORTS +# else +# define GAPI_EXPORTS + +#if 0 // Note: the following version currently is not needed for non-OpenCV build +# if defined _WIN32 +# define GAPI_EXPORTS __declspec(dllexport) +# elif defined __GNUC__ && __GNUC__ >= 4 +# define GAPI_EXPORTS __attribute__ ((visibility ("default"))) +# endif + +# ifndef GAPI_EXPORTS +# define GAPI_EXPORTS +# endif +#endif + +# endif + +#endif // OPENCV_GAPI_OWN_TYPES_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/mat.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/mat.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9bf740d2551b0ffb4fa3801cb9b8b71dcf74f597 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/mat.hpp @@ -0,0 +1,341 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_MAT_HPP +#define OPENCV_GAPI_OWN_MAT_HPP + +#include +#include +#include +#include +#include + +#include //std::shared_ptr +#include //std::memcpy +#include //std::accumulate +#include + +namespace cv { namespace gapi { namespace own { + namespace detail { + template + void assign_row(void* ptr, int cols, Scalar const& s) + { + auto p = static_cast(ptr); + for (int c = 0; c < cols; c++) + { + for (int ch = 0; ch < channels; ch++) + { + p[c * channels + ch] = saturate(s[ch], roundd); + } + } + } + + inline size_t default_step(int type, int cols) + { + return CV_ELEM_SIZE(type) * cols; + } + //Matrix header, i.e. fields that are unique to each Mat object. + //Devoted class is needed to implement custom behavior on move (erasing state of moved from object) + struct MatHeader{ + enum { AUTO_STEP = 0}; + enum { TYPE_MASK = 0x00000FFF }; + + MatHeader() = default; + + MatHeader(int _rows, int _cols, int type, void* _data, size_t _step) + : flags((type & TYPE_MASK)), rows(_rows), cols(_cols), data((uchar*)_data), step(_step == AUTO_STEP ? detail::default_step(type, _cols) : _step) + {} + + MatHeader(const std::vector &_dims, int type, void* _data) + : flags((type & TYPE_MASK)), data((uchar*)_data), step(0), dims(_dims) + {} + + MatHeader(const MatHeader& ) = default; + MatHeader(MatHeader&& src) : MatHeader(src) // reuse copy constructor here + { + MatHeader empty; //give it a name to call copy(not move) assignment below + src = empty; + } + MatHeader& operator=(const MatHeader& ) = default; + MatHeader& operator=(MatHeader&& src) + { + *this = src; //calling a copy assignment here, not move one + MatHeader empty; //give it a name to call copy(not move) assignment below + src = empty; + return *this; + } + /*! includes several bit-fields: + - depth + - number of channels + */ + int flags = 0; + + //! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions + int rows = 0, cols = 0; + //! pointer to the data + uchar* data = nullptr; + size_t step = 0; + //! dimensions (ND-case) + std::vector dims; + }; + } // namespace detail + //concise version of cv::Mat suitable for GAPI needs (used when no dependence on OpenCV is required) + class Mat : public detail::MatHeader{ + public: + + Mat() = default; + + /** @overload + @param _rows Number of rows in a 2D array. + @param _cols Number of columns in a 2D array. + @param _type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or + CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices. + @param _data Pointer to the user data. Matrix constructors that take data and step parameters do not + allocate matrix data. Instead, they just initialize the matrix header that points to the specified + data, which means that no data is copied. This operation is very efficient and can be used to + process external data using OpenCV functions. The external data is not automatically deallocated, so + you should take care of it. + @param _step Number of bytes each matrix row occupies. The value should include the padding bytes at + the end of each row, if any. If the parameter is missing (set to AUTO_STEP ), no padding is assumed + and the actual step is calculated as cols*elemSize(). See Mat::elemSize. + */ + Mat(int _rows, int _cols, int _type, void* _data, size_t _step = AUTO_STEP) + : MatHeader (_rows, _cols, _type, _data, _step) + {} + + Mat(const std::vector &_dims, int _type, void* _data) + : MatHeader (_dims, _type, _data) + {} + + Mat(std::vector &&_dims, int _type, void* _data) + : MatHeader (std::move(_dims), _type, _data) + {} + + Mat(Mat const& src, const Rect& roi ) + : Mat(src) + { + rows = roi.height; + cols = roi.width; + data = ptr(roi.y, roi.x); + } + + Mat(Mat const& src) = default; + Mat(Mat&& src) = default; + + Mat& operator=(Mat const& src) = default; + Mat& operator=(Mat&& src) = default; + + /** @brief Sets all or some of the array elements to the specified value. + @param s Assigned scalar converted to the actual array type. + */ + Mat& operator = (const Scalar& s) + { + constexpr unsigned max_channels = 4; //Scalar can't fit more than 4 + using func_p_t = void (*)(void*, int, Scalar const&); + using detail::assign_row; + #define TABLE_ENTRY(type) {assign_row, assign_row, assign_row, assign_row} + static constexpr func_p_t func_tbl[][max_channels] = { + TABLE_ENTRY(uchar), + TABLE_ENTRY(schar), + TABLE_ENTRY(ushort), + TABLE_ENTRY(short), + TABLE_ENTRY(int), + TABLE_ENTRY(float), + TABLE_ENTRY(double) + }; + #undef TABLE_ENTRY + + static_assert(CV_8U == 0 && CV_8S == 1 && CV_16U == 2 && CV_16S == 3 + && CV_32S == 4 && CV_32F == 5 && CV_64F == 6, + "OCV type ids used as indexes to array, thus exact numbers are important!" + ); + + const auto depth = static_cast(this->depth()); + GAPI_Assert(depth < sizeof(func_tbl)/sizeof(func_tbl[0])); + + if (dims.empty()) + { + const auto channels = static_cast(this->channels()); + GAPI_Assert(channels <= max_channels); + + auto* f = func_tbl[depth][channels - 1]; + for (int r = 0; r < rows; ++r) + { + (*f)(static_cast(ptr(r)), cols, s ); + } + } + else + { + auto* f = func_tbl[depth][0]; + // FIXME: better to refactor assign_row to use std::size_t by default + (*f)(static_cast(data), static_cast(total()), s); + } + return *this; + } + + /** @brief Returns the matrix element size in bytes. + + The method returns the matrix element size in bytes. For example, if the matrix type is CV_16SC3 , + the method returns 3\*sizeof(short) or 6. + */ + size_t elemSize() const + { + return CV_ELEM_SIZE(type()); + } + /** @brief Returns the type of a matrix element. + + The method returns a matrix element type. This is an identifier compatible with the CvMat type + system, like CV_16SC3 or 16-bit signed 3-channel array, and so on. + */ + int type() const {return CV_MAT_TYPE(flags);} + + /** @brief Returns the depth of a matrix element. + + The method returns the identifier of the matrix element depth (the type of each individual channel). + For example, for a 16-bit signed element array, the method returns CV_16S . A complete list of + matrix types contains the following values: + - CV_8U - 8-bit unsigned integers ( 0..255 ) + - CV_8S - 8-bit signed integers ( -128..127 ) + - CV_16U - 16-bit unsigned integers ( 0..65535 ) + - CV_16S - 16-bit signed integers ( -32768..32767 ) + - CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) + - CV_32F - 32-bit floating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) + - CV_64F - 64-bit floating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN ) + */ + int depth() const {return CV_MAT_DEPTH(flags);} + + /** @brief Returns the number of matrix channels. + + The method returns the number of matrix channels. + If matrix is N-dimensional, -1 is returned. + */ + int channels() const {return dims.empty() ? CV_MAT_CN(flags) : -1;} + + /** + @param _rows New number of rows. + @param _cols New number of columns. + @param _type New matrix type. + */ + void create(int _rows, int _cols, int _type) + { + create(Size{_cols, _rows}, _type); + } + /** @overload + @param _size Alternative new matrix size specification: Size(cols, rows) + @param _type New matrix type. + */ + void create(Size _size, int _type) + { + if (_size != Size{cols, rows} ) + { + Mat tmp{_size.height, _size.width, _type, nullptr}; + tmp.memory.reset(new uchar[ tmp.step * tmp.rows], [](uchar * p){delete[] p;}); + tmp.data = tmp.memory.get(); + + *this = std::move(tmp); + } + } + + void create(const std::vector &_dims, int _type) + { + // FIXME: make a proper reallocation-on-demands + // WARNING: no tensor views, so no strides + Mat tmp{_dims, _type, nullptr}; + // FIXME: this accumulate duplicates a lot + const auto sz = std::accumulate(_dims.begin(), _dims.end(), 1, std::multiplies()); + tmp.memory.reset(new uchar[CV_ELEM_SIZE(_type)*sz], [](uchar * p){delete[] p;}); + tmp.data = tmp.memory.get(); + *this = std::move(tmp); + } + + /** @brief Copies the matrix to another one. + + The method copies the matrix data to another matrix. Before copying the data, the method invokes : + @code + m.create(this->size(), this->type()); + @endcode + so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the + function does not handle the case of a partial overlap between the source and the destination + matrices. + */ + void copyTo(Mat& dst) const + { + if (dims.empty()) + { + dst.create(rows, cols, type()); + for (int r = 0; r < rows; ++r) + { + std::copy_n(ptr(r), detail::default_step(type(),cols), dst.ptr(r)); + } + } + else + { + dst.create(dims, depth()); + std::copy_n(data, total()*elemSize(), data); + } + } + + /** @brief Returns true if the array has no elements. + + The method returns true if Mat::total() is 0 or if Mat::data is NULL. Because of pop_back() and + resize() methods `M.total() == 0` does not imply that `M.data == NULL`. + */ + bool empty() const + { + return data == 0 || total() == 0; + } + + /** @brief Returns the total number of array elements. + + The method returns the number of array elements (a number of pixels if the array represents an + image). + */ + size_t total() const + { + return static_cast + (dims.empty() + ? (rows * cols) + : std::accumulate(dims.begin(), dims.end(), 1, std::multiplies())); + } + + /** @overload + @param roi Extracted submatrix specified as a rectangle. + */ + Mat operator()( const Rect& roi ) const + { + return Mat{*this, roi}; + } + + + /** @brief Returns a pointer to the specified matrix row. + + The methods return `uchar*` or typed pointer to the specified matrix row. See the sample in + Mat::isContinuous to know how to use these methods. + @param row Index along the dimension 0 + @param col Index along the dimension 1 + */ + uchar* ptr(int row, int col = 0) + { + return const_cast(const_cast(this)->ptr(row,col)); + } + /** @overload */ + const uchar* ptr(int row, int col = 0) const + { + return data + step * row + CV_ELEM_SIZE(type()) * col; + } + + + private: + //actual memory allocated for storage, or nullptr if object is non owning view to over memory + std::shared_ptr memory; + }; + +} //namespace own +} //namespace gapi +} //namespace cv + +#endif /* OPENCV_GAPI_OWN_MAT_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/saturate.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/saturate.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b232479ea53cd3efc293f98bd30d915d460b006 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/saturate.hpp @@ -0,0 +1,90 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_OWN_SATURATE_HPP +#define OPENCV_GAPI_OWN_SATURATE_HPP + +#include + +#include +#include + +#include + +namespace cv { namespace gapi { namespace own { +//----------------------------- +// +// Numeric cast with saturation +// +//----------------------------- + +template +static inline DST saturate(SRC x) +{ + // only integral types please! + GAPI_DbgAssert(std::is_integral::value && + std::is_integral::value); + + if (std::is_same::value) + return static_cast(x); + + if (sizeof(DST) > sizeof(SRC)) + return static_cast(x); + + // compiler must recognize this saturation, + // so compile saturate(a + b) with adds + // instruction (e.g.: _mm_adds_epi16 if x86) + return x < std::numeric_limits::min()? + std::numeric_limits::min(): + x > std::numeric_limits::max()? + std::numeric_limits::max(): + static_cast(x); +} + +// Note, that OpenCV rounds differently: +// - like std::round() for add, subtract +// - like std::rint() for multiply, divide +template +static inline DST saturate(SRC x, R round) +{ + if (std::is_floating_point::value) + { + return static_cast(x); + } + else if (std::is_integral::value) + { + GAPI_DbgAssert(std::is_integral::value && + std::is_integral::value); + return saturate(x); + } + else + { + GAPI_DbgAssert(std::is_integral::value && + std::is_floating_point::value); +#ifdef _WIN32 +// Suppress warning about converting x to floating-point +// Note that x is already floating-point at this point +#pragma warning(disable: 4244) +#endif + int ix = static_cast(round(x)); +#ifdef _WIN32 +#pragma warning(default: 4244) +#endif + return saturate(ix); + } +} + +// explicit suffix 'd' for double type +inline double ceild(double x) { return ceil(x); } +inline double floord(double x) { return floor(x); } +inline double roundd(double x) { return round(x); } +inline double rintd(double x) { return rint(x); } + +} //namespace own +} //namespace gapi +} //namespace cv +#endif /* OPENCV_GAPI_OWN_SATURATE_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/scalar.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/scalar.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bda91c83b58a49597b5859dc94e6737d85bd5ede --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/scalar.hpp @@ -0,0 +1,47 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_GAPI_OWN_SCALAR_HPP +#define OPENCV_GAPI_GAPI_OWN_SCALAR_HPP + +#include + +namespace cv +{ +namespace gapi +{ +namespace own +{ + +class GAPI_EXPORTS Scalar +{ +public: + Scalar() = default; + explicit Scalar(double v0) { val[0] = v0; }; + Scalar(double v0, double v1, double v2 = 0, double v3 = 0) + : val{v0, v1, v2, v3} + { + } + + const double& operator[](int i) const { return val[i]; } + double& operator[](int i) { return val[i]; } + + static Scalar all(double v0) { return Scalar(v0, v0, v0, v0); } + + double val[4] = {0}; +}; + +inline bool operator==(const Scalar& lhs, const Scalar& rhs) +{ + return std::equal(std::begin(lhs.val), std::end(lhs.val), std::begin(rhs.val)); +} + +} // namespace own +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_GAPI_OWN_SCALAR_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/types.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/types.hpp new file mode 100644 index 0000000000000000000000000000000000000000..20445ee0fd4bc4f4f92f434ae2ecc1d48fb42a5b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/own/types.hpp @@ -0,0 +1,135 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_TYPES_HPP +#define OPENCV_GAPI_TYPES_HPP + +#include // std::max, std::min +#include + +namespace cv +{ +namespace gapi +{ +namespace own +{ + +class Point +{ +public: + Point() = default; + Point(int _x, int _y) : x(_x), y(_y) {}; + + int x = 0; + int y = 0; +}; + +class Rect +{ +public: + Rect() = default; + Rect(int _x, int _y, int _width, int _height) : x(_x), y(_y), width(_width), height(_height) {}; +#if !defined(GAPI_STANDALONE) + Rect(const cv::Rect& other) : x(other.x), y(other.y), width(other.width), height(other.height) {}; + inline Rect& operator=(const cv::Rect& other) + { + x = other.x; + y = other.x; + width = other.width; + height = other.height; + return *this; + } +#endif // !defined(GAPI_STANDALONE) + + int x = 0; //!< x coordinate of the top-left corner + int y = 0; //!< y coordinate of the top-left corner + int width = 0; //!< width of the rectangle + int height = 0; //!< height of the rectangle +}; + +inline bool operator==(const Rect& lhs, const Rect& rhs) +{ + return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height; +} + +inline bool operator!=(const Rect& lhs, const Rect& rhs) +{ + return !(lhs == rhs); +} + +inline Rect& operator&=(Rect& lhs, const Rect& rhs) +{ + int x1 = std::max(lhs.x, rhs.x); + int y1 = std::max(lhs.y, rhs.y); + lhs.width = std::min(lhs.x + lhs.width, rhs.x + rhs.width) - x1; + lhs.height = std::min(lhs.y + lhs.height, rhs.y + rhs.height) - y1; + lhs.x = x1; + lhs.y = y1; + if( lhs.width <= 0 || lhs.height <= 0 ) + lhs = Rect(); + return lhs; +} + +inline const Rect operator&(const Rect& lhs, const Rect& rhs) +{ + Rect result = lhs; + return result &= rhs; +} + +inline std::ostream& operator<<(std::ostream& o, const Rect& rect) +{ + return o << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; +} + +class Size +{ +public: + Size() = default; + Size(int _width, int _height) : width(_width), height(_height) {}; +#if !defined(GAPI_STANDALONE) + Size(const cv::Size& other) : width(other.width), height(other.height) {}; + inline Size& operator=(const cv::Size& rhs) + { + width = rhs.width; + height = rhs.height; + return *this; + } +#endif // !defined(GAPI_STANDALONE) + + int width = 0; + int height = 0; +}; + +inline Size& operator+=(Size& lhs, const Size& rhs) +{ + lhs.width += rhs.width; + lhs.height += rhs.height; + return lhs; +} + +inline bool operator==(const Size& lhs, const Size& rhs) +{ + return lhs.width == rhs.width && lhs.height == rhs.height; +} + +inline bool operator!=(const Size& lhs, const Size& rhs) +{ + return !(lhs == rhs); +} + + +inline std::ostream& operator<<(std::ostream& o, const Size& s) +{ + o << "[" << s.width << " x " << s.height << "]"; + return o; +} + +} // namespace own +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_TYPES_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/core.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/core.hpp new file mode 100644 index 0000000000000000000000000000000000000000..47ac486e5cd16217a9d03d28ecdebaf213a6edbb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/core.hpp @@ -0,0 +1,20 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + + +#ifndef OPENCV_GAPI_PLAIDML_CORE_HPP +#define OPENCV_GAPI_PLAIDML_CORE_HPP + +#include // GKernelPackage +#include // GAPI_EXPORTS + +namespace cv { namespace gapi { namespace core { namespace plaidml { + +GAPI_EXPORTS GKernelPackage kernels(); + +}}}} + +#endif // OPENCV_GAPI_PLAIDML_CORE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/gplaidmlkernel.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/gplaidmlkernel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7ce00cfa359b85392ff7d758c869e3bd16f422e4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/gplaidmlkernel.hpp @@ -0,0 +1,140 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation +// + + +#ifndef OPENCV_GAPI_GPLAIDMLKERNEL_HPP +#define OPENCV_GAPI_GPLAIDMLKERNEL_HPP + +#include +#include + +namespace plaidml +{ +namespace edsl +{ + class Tensor; +} // namespace edsl +} // namespace plaidml + +namespace cv +{ +namespace gapi +{ +namespace plaidml +{ + +GAPI_EXPORTS cv::gapi::GBackend backend(); + +} // namespace plaidml +} // namespace gapi + +struct GPlaidMLContext +{ + // Generic accessor API + template + const T& inArg(int input) { return m_args.at(input).get(); } + + // Syntax sugar + const plaidml::edsl::Tensor& inTensor(int input) + { + return inArg(input); + } + + plaidml::edsl::Tensor& outTensor(int output) + { + return *(m_results.at(output).get()); + } + + std::vector m_args; + std::unordered_map m_results; +}; + +class GAPI_EXPORTS GPlaidMLKernel +{ +public: + using F = std::function; + + GPlaidMLKernel() = default; + explicit GPlaidMLKernel(const F& f) : m_f(f) {}; + + void apply(GPlaidMLContext &ctx) const + { + GAPI_Assert(m_f); + m_f(ctx); + } + +protected: + F m_f; +}; + + +namespace detail +{ + +template struct plaidml_get_in; +template<> struct plaidml_get_in +{ + static const plaidml::edsl::Tensor& get(GPlaidMLContext& ctx, int idx) + { + return ctx.inTensor(idx); + } +}; + +template struct plaidml_get_in +{ + static T get(GPlaidMLContext &ctx, int idx) { return ctx.inArg(idx); } +}; + +template struct plaidml_get_out; +template<> struct plaidml_get_out +{ + static plaidml::edsl::Tensor& get(GPlaidMLContext& ctx, int idx) + { + return ctx.outTensor(idx); + } +}; + +template +struct PlaidMLCallHelper; + +template +struct PlaidMLCallHelper, std::tuple > +{ + template + static void call_impl(GPlaidMLContext &ctx, detail::Seq, detail::Seq) + { + Impl::run(plaidml_get_in::get(ctx, IIs)..., plaidml_get_out::get(ctx, OIs)...); + } + + static void call(GPlaidMLContext& ctx) + { + call_impl(ctx, + typename detail::MkSeq::type(), + typename detail::MkSeq::type()); + } +}; + +} // namespace detail + +template +class GPlaidMLKernelImpl: public cv::detail::PlaidMLCallHelper, + public cv::detail::KernelTag +{ + using P = detail::PlaidMLCallHelper; + +public: + using API = K; + + static cv::gapi::GBackend backend() { return cv::gapi::plaidml::backend(); } + static cv::GPlaidMLKernel kernel() { return GPlaidMLKernel(&P::call); } +}; + +#define GAPI_PLAIDML_KERNEL(Name, API) struct Name: public cv::GPlaidMLKernelImpl + +} // namespace cv + +#endif // OPENCV_GAPI_GPLAIDMLKERNEL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/plaidml.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/plaidml.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bd12d2583287b80ac654a212c615f1a5b746101d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/plaidml/plaidml.hpp @@ -0,0 +1,48 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + + +#ifndef OPENCV_GAPI_PLAIDML_PLAIDML_HPP +#define OPENCV_GAPI_PLAIDML_PLAIDML_HPP + +#include +#include // CompileArgTag + +namespace cv +{ +namespace gapi +{ +namespace plaidml +{ + +/** \addtogroup gapi_compile_args + * @{ + */ +/** + * @brief This structure represents the basic parameters for the experimental + * PlaidML backend. + */ +struct config +{ + std::string dev_id; //!< Device ID. Refer to PlaidML documentation for details. + std::string trg_id; //!< Target ID. Refer to PlaidML documentation for details. +}; +/** @} gapi_compile_args */ + +} // namespace plaidml +} // namespace gapi + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.plaidml.config"; } + }; +} // namespace detail + +} // namespace cv + +#endif // OPENCV_GAPI_PLAIDML_PLAIDML_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/render.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/render.hpp new file mode 100644 index 0000000000000000000000000000000000000000..52e55b0d800f7ff76c7308b219ebfd5c86163800 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/render.hpp @@ -0,0 +1,14 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_RENDER_ROOT_HPP +#define OPENCV_GAPI_RENDER_ROOT_HPP + +// This file is just a shortcut to render/render.hpp + +#include + +#endif // OPENCV_GAPI_RENDER_ROOT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/render/render.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/render/render.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3cf2f6bb0c6e933a028306678f13300c359679ea --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/render/render.hpp @@ -0,0 +1,470 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_RENDER_HPP +#define OPENCV_GAPI_RENDER_HPP + +#include +#include + +#include +#include + +#include +#include +#include +#include + + +/** \defgroup gapi_draw G-API Drawing and composition functionality + * @{ + * + * @brief Functions for in-graph drawing. + * + * @note This is a Work in Progress functionality and APIs may + * change in the future releases. + * + * G-API can do some in-graph drawing with a generic operations and a + * set of [rendering primitives](@ref gapi_draw_prims). + * In contrast with traditional OpenCV, in G-API user need to form a + * *rendering list* of primitives to draw. This list can be built + * manually or generated within a graph. This list is passed to + * [special operations or functions](@ref gapi_draw_api) where all + * primitives are interpreted and applied to the image. + * + * For example, in a complex pipeline a list of detected objects + * can be translated in-graph to a list of cv::gapi::wip::draw::Rect + * primitives to highlight those with bounding boxes, or a list of + * detected faces can be translated in-graph to a list of + * cv::gapi::wip::draw::Mosaic primitives to hide sensitive content + * or protect privacy. + * + * Like any other operations, rendering in G-API can be reimplemented + * by different backends. Currently only an OpenCV-based backend is + * available. + * + * In addition to the graph-level operations, there are also regular + * (immediate) OpenCV-like functions are available -- see + * cv::gapi::wip::draw::render(). These functions are just wrappers + * over regular G-API and build the rendering graphs on the fly, so + * take compilation arguments as parameters. + * + * Currently this API is more machine-oriented than human-oriented. + * The main purpose is to translate a set of domain-specific objects + * to a list of primitives to draw. For example, in order to generate + * a picture like this: + * + * ![](modules/gapi/doc/pics/render_example.png) + * + * Rendering list needs to be generated as follows: + * + * @include modules/gapi/samples/draw_example.cpp + * + * @defgroup gapi_draw_prims Drawing primitives + * @defgroup gapi_draw_api Drawing operations and functions + * @} + */ + +namespace cv +{ +namespace gapi +{ +namespace wip +{ +namespace draw +{ + +/** + * @brief This structure specifies which FreeType font to use by FText primitives. + */ +struct freetype_font +{ + /*@{*/ + std::string path; //!< The path to the font file (.ttf) + /*@{*/ +}; + +//! @addtogroup gapi_draw_prims +//! @{ +/** + * @brief This structure represents a text string to draw. + * + * Parameters match cv::putText(). + */ +struct Text +{ + /** + * @brief Text constructor + * + * @param text_ The text string to be drawn + * @param org_ The bottom-left corner of the text string in the image + * @param ff_ The font type, see #HersheyFonts + * @param fs_ The font scale factor that is multiplied by the font-specific base size + * @param color_ The text color + * @param thick_ The thickness of the lines used to draw a text + * @param lt_ The line type. See #LineTypes + * @param bottom_left_origin_ When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner + */ + Text(const std::string& text_, + const cv::Point& org_, + int ff_, + double fs_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = cv::LINE_8, + bool bottom_left_origin_ = false) : + text(text_), org(org_), ff(ff_), fs(fs_), + color(color_), thick(thick_), lt(lt_), bottom_left_origin(bottom_left_origin_) + { + } + + /*@{*/ + std::string text; //!< The text string to be drawn + cv::Point org; //!< The bottom-left corner of the text string in the image + int ff; //!< The font type, see #HersheyFonts + double fs; //!< The font scale factor that is multiplied by the font-specific base size + cv::Scalar color; //!< The text color + int thick; //!< The thickness of the lines used to draw a text + int lt; //!< The line type. See #LineTypes + bool bottom_left_origin; //!< When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner + /*@{*/ +}; + +/** + * @brief This structure represents a text string to draw using + * FreeType renderer. + * + * If OpenCV is built without FreeType support, this primitive will + * fail at the execution stage. + */ +struct FText +{ + /** + * @brief FText constructor + * + * @param text_ The text string to be drawn + * @param org_ The bottom-left corner of the text string in the image + * @param fh_ The height of text + * @param color_ The text color + */ + FText(const std::wstring& text_, + const cv::Point& org_, + int fh_, + const cv::Scalar& color_) : + text(text_), org(org_), fh(fh_), color(color_) + { + } + + /*@{*/ + std::wstring text; //!< The text string to be drawn + cv::Point org; //!< The bottom-left corner of the text string in the image + int fh; //!< The height of text + cv::Scalar color; //!< The text color + /*@{*/ +}; + +/** + * @brief This structure represents a rectangle to draw. + * + * Parameters match cv::rectangle(). + */ +struct Rect +{ + /** + * @brief Rect constructor + * + * @param rect_ Coordinates of the rectangle + * @param color_ The bottom-left corner of the text string in the image + * @param thick_ The thickness of lines that make up the rectangle. Negative values, like #FILLED, mean that the function has to draw a filled rectangle + * @param lt_ The type of the line. See #LineTypes + * @param shift_ The number of fractional bits in the point coordinates + */ + Rect(const cv::Rect& rect_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = cv::LINE_8, + int shift_ = 0) : + rect(rect_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + /*@{*/ + cv::Rect rect; //!< Coordinates of the rectangle + cv::Scalar color; //!< The rectangle color or brightness (grayscale image) + int thick; //!< The thickness of lines that make up the rectangle. Negative values, like #FILLED, mean that the function has to draw a filled rectangle + int lt; //!< The type of the line. See #LineTypes + int shift; //!< The number of fractional bits in the point coordinates + /*@{*/ +}; + +/** + * @brief This structure represents a circle to draw. + * + * Parameters match cv::circle(). + */ +struct Circle +{ + /** + * @brief Circle constructor + * + * @param center_ The center of the circle + * @param radius_ The radius of the circle + * @param color_ The color of the circle + * @param thick_ The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn + * @param lt_ The Type of the circle boundary. See #LineTypes + * @param shift_ The Number of fractional bits in the coordinates of the center and in the radius value + */ + Circle(const cv::Point& center_, + int radius_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = cv::LINE_8, + int shift_ = 0) : + center(center_), radius(radius_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + /*@{*/ + cv::Point center; //!< The center of the circle + int radius; //!< The radius of the circle + cv::Scalar color; //!< The color of the circle + int thick; //!< The thickness of the circle outline, if positive. Negative values, like #FILLED, mean that a filled circle is to be drawn + int lt; //!< The Type of the circle boundary. See #LineTypes + int shift; //!< The Number of fractional bits in the coordinates of the center and in the radius value + /*@{*/ +}; + +/** + * @brief This structure represents a line to draw. + * + * Parameters match cv::line(). + */ +struct Line +{ + /** + * @brief Line constructor + * + * @param pt1_ The first point of the line segment + * @param pt2_ The second point of the line segment + * @param color_ The line color + * @param thick_ The thickness of line + * @param lt_ The Type of the line. See #LineTypes + * @param shift_ The number of fractional bits in the point coordinates + */ + Line(const cv::Point& pt1_, + const cv::Point& pt2_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = cv::LINE_8, + int shift_ = 0) : + pt1(pt1_), pt2(pt2_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + /*@{*/ + cv::Point pt1; //!< The first point of the line segment + cv::Point pt2; //!< The second point of the line segment + cv::Scalar color; //!< The line color + int thick; //!< The thickness of line + int lt; //!< The Type of the line. See #LineTypes + int shift; //!< The number of fractional bits in the point coordinates + /*@{*/ +}; + +/** + * @brief This structure represents a mosaicing operation. + * + * Mosaicing is a very basic method to obfuscate regions in the image. + */ +struct Mosaic +{ + /** + * @brief Mosaic constructor + * + * @param mos_ Coordinates of the mosaic + * @param cellSz_ Cell size (same for X, Y). Note: mos size must be multiple of cell size + * @param decim_ Decimation (0 stands for no decimation) + */ + Mosaic(const cv::Rect& mos_, + int cellSz_, + int decim_) : + mos(mos_), cellSz(cellSz_), decim(decim_) + { + } + + /*@{*/ + cv::Rect mos; //!< Coordinates of the mosaic + int cellSz; //!< Cell size (same for X, Y). Note: mosaic size must be a multiple of cell size + int decim; //!< Decimation (0 stands for no decimation) + /*@{*/ +}; + +/** + * @brief This structure represents an image to draw. + * + * Image is blended on a frame using the specified mask. + */ +struct Image +{ + /** + * @brief Mosaic constructor + * + * @param org_ The bottom-left corner of the image + * @param img_ Image to draw + * @param alpha_ Alpha channel for image to draw (same size and number of channels) + */ + Image(const cv::Point& org_, + const cv::Mat& img_, + const cv::Mat& alpha_) : + org(org_), img(img_), alpha(alpha_) + { + } + + /*@{*/ + cv::Point org; //!< The bottom-left corner of the image + cv::Mat img; //!< Image to draw + cv::Mat alpha; //!< Alpha channel for image to draw (same size and number of channels) + /*@{*/ +}; + +/** + * @brief This structure represents a polygon to draw. + */ +struct Poly +{ + /** + * @brief Mosaic constructor + * + * @param points_ Points to connect + * @param color_ The line color + * @param thick_ The thickness of line + * @param lt_ The Type of the line. See #LineTypes + * @param shift_ The number of fractional bits in the point coordinate + */ + Poly(const std::vector& points_, + const cv::Scalar& color_, + int thick_ = 1, + int lt_ = cv::LINE_8, + int shift_ = 0) : + points(points_), color(color_), thick(thick_), lt(lt_), shift(shift_) + { + } + + /*@{*/ + std::vector points; //!< Points to connect + cv::Scalar color; //!< The line color + int thick; //!< The thickness of line + int lt; //!< The Type of the line. See #LineTypes + int shift; //!< The number of fractional bits in the point coordinate + /*@{*/ +}; + +using Prim = util::variant + < Text + , FText + , Rect + , Circle + , Line + , Mosaic + , Image + , Poly + >; + +using Prims = std::vector; +//! @} gapi_draw_prims + +using GMat2 = std::tuple; +using GMatDesc2 = std::tuple; + + +//! @addtogroup gapi_draw_api +//! @{ +/** @brief The function renders on the input image passed drawing primitivies + +@param bgr input image: 8-bit unsigned 3-channel image @ref CV_8UC3. +@param prims vector of drawing primitivies +@param args graph compile time parameters +*/ +void GAPI_EXPORTS render(cv::Mat& bgr, + const Prims& prims, + cv::GCompileArgs&& args = {}); + +/** @brief The function renders on two NV12 planes passed drawing primitivies + +@param y_plane input image: 8-bit unsigned 1-channel image @ref CV_8UC1. +@param uv_plane input image: 8-bit unsigned 2-channel image @ref CV_8UC2. +@param prims vector of drawing primitivies +@param args graph compile time parameters +*/ +void GAPI_EXPORTS render(cv::Mat& y_plane, + cv::Mat& uv_plane, + const Prims& prims, + cv::GCompileArgs&& args = {}); + +G_TYPED_KERNEL_M(GRenderNV12, )>, "org.opencv.render.nv12") +{ + static GMatDesc2 outMeta(GMatDesc y_plane, GMatDesc uv_plane, GArrayDesc) + { + return std::make_tuple(y_plane, uv_plane); + } +}; + +G_TYPED_KERNEL(GRenderBGR, )>, "org.opencv.render.bgr") +{ + static GMatDesc outMeta(GMatDesc bgr, GArrayDesc) + { + return bgr; + } +}; + +/** @brief Renders on 3 channels input + +Output image must be 8-bit unsigned planar 3-channel image + +@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3 +@param prims draw primitives +*/ +GAPI_EXPORTS GMat render3ch(const GMat& src, const GArray& prims); + +/** @brief Renders on two planes + +Output y image must be 8-bit unsigned planar 1-channel image @ref CV_8UC1 +uv image must be 8-bit unsigned planar 2-channel image @ref CV_8UC2 + +@param y input image: 8-bit unsigned 1-channel image @ref CV_8UC1 +@param uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2 +@param prims draw primitives +*/ +GAPI_EXPORTS GMat2 renderNV12(const GMat& y, + const GMat& uv, + const GArray& prims); +//! @} gapi_draw_api + +} // namespace draw +} // namespace wip + +namespace render +{ +namespace ocv +{ + GAPI_EXPORTS cv::gapi::GKernelPackage kernels(); + +} // namespace ocv +} // namespace render +} // namespace gapi + +namespace detail +{ + template<> struct CompileArgTag + { + static const char* tag() { return "gapi.freetype_font"; } + }; +} // namespace detail + +} // namespace cv + +#endif // OPENCV_GAPI_RENDER_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/streaming/cap.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/streaming/cap.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4168bcca2b0a8bcb7d2e9199ac6bfb7f7abd4efe --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/streaming/cap.hpp @@ -0,0 +1,110 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_STREAMING_CAP_HPP +#define OPENCV_GAPI_STREAMING_CAP_HPP + +/** + * YOUR ATTENTION PLEASE! + * + * This is a header-only implementation of cv::VideoCapture-based + * Stream source. It is not built by default with G-API as G-API + * doesn't depend on videoio module. + * + * If you want to use it in your application, please make sure + * videioio is available in your OpenCV package and is linked to your + * application. + * + * Note for developers: please don't put videoio dependency in G-API + * because of this file. + */ + +#include +#include + +namespace cv { +namespace gapi { +namespace wip { + +/** + * @brief OpenCV's VideoCapture-based streaming source. + * + * This class implements IStreamSource interface. + * Its constructor takes the same parameters as cv::VideoCapture does. + * + * Please make sure that videoio OpenCV module is avaiable before using + * this in your application (G-API doesn't depend on it directly). + * + * @note stream sources are passed to G-API via shared pointers, so + * please gapi::make_src<> to create objects and ptr() to pass a + * GCaptureSource to cv::gin(). + */ +class GCaptureSource: public IStreamSource +{ +public: + explicit GCaptureSource(int id) : cap(id) { prep(); } + explicit GCaptureSource(const std::string &path) : cap(path) { prep(); } + + // TODO: Add more constructor overloads to make it + // fully compatible with VideoCapture's interface. + +protected: + cv::VideoCapture cap; + cv::Mat first; + bool first_pulled = false; + + void prep() + { + // Prepare first frame to report its meta to engine + // when needed + GAPI_Assert(first.empty()); + cv::Mat tmp; + if (!cap.read(tmp)) + { + GAPI_Assert(false && "Couldn't grab the very first frame"); + } + // NOTE: Some decode/media VideoCapture backends continue + // owning the video buffer under cv::Mat so in order to + // process it safely in a highly concurrent pipeline, clone() + // is the only right way. + first = tmp.clone(); + } + + virtual bool pull(cv::gapi::wip::Data &data) override + { + if (!first_pulled) + { + GAPI_Assert(!first.empty()); + first_pulled = true; + data = first; // no need to clone here since it was cloned already + return true; + } + + if (!cap.isOpened()) return false; + + cv::Mat frame; + if (!cap.read(frame)) + { + // end-of-stream happened + return false; + } + // Same reason to clone as in prep() + data = frame.clone(); + return true; + } + + virtual GMetaArg descr_of() const override + { + GAPI_Assert(!first.empty()); + return cv::GMetaArg{cv::descr_of(first)}; + } +}; + +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_STREAMING_CAP_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/streaming/source.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/streaming/source.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6597cad8f8081dd56c19b5f138a6b88d6c9566a3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/streaming/source.hpp @@ -0,0 +1,62 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2019 Intel Corporation + +#ifndef OPENCV_GAPI_STREAMING_SOURCE_HPP +#define OPENCV_GAPI_STREAMING_SOURCE_HPP + +#include // shared_ptr +#include // is_base_of + +#include // GMetaArg + + +namespace cv { +namespace gapi { +namespace wip { + struct Data; // "forward-declaration" of GRunArg + +/** + * @brief Abstract streaming pipeline source. + * + * Implement this interface if you want customize the way how data is + * streaming into GStreamingCompiled. + * + * Objects implementing this interface can be passed to + * GStreamingCompiled using setSource() with cv::gin(). Regular + * compiled graphs (GCompiled) don't support input objects of this + * type. + * + * Default cv::VideoCapture-based implementation is available, see + * cv::gapi::wip::GCaptureSource. + * + * @note stream sources are passed to G-API via shared pointers, so + * please use ptr() when passing a IStreamSource implementation to + * cv::gin(). + */ +class IStreamSource: public std::enable_shared_from_this +{ +public: + using Ptr = std::shared_ptr; + Ptr ptr() { return shared_from_this(); } + virtual bool pull(Data &data) = 0; + virtual GMetaArg descr_of() const = 0; + virtual ~IStreamSource() = default; +}; + +template +IStreamSource::Ptr inline make_src(Args&&... args) +{ + static_assert(std::is_base_of::value, + "T must implement the cv::gapi::IStreamSource interface!"); + auto src_ptr = std::make_shared(std::forward(args)...); + return src_ptr->ptr(); +} + +} // namespace wip +} // namespace gapi +} // namespace cv + +#endif // OPENCV_GAPI_STREAMING_SOURCE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/any.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/any.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5f97e95b08e410a94d9d51ea9ef988ae76caf21b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/any.hpp @@ -0,0 +1,186 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_ANY_HPP +#define OPENCV_GAPI_UTIL_ANY_HPP + +#include +#include +#include +#include + +#include + +#if defined(_MSC_VER) + // disable MSVC warning on "multiple copy constructors specified" +# pragma warning(disable: 4521) +#endif + +namespace cv +{ + +namespace internal +{ + template + T down_cast(Source operand) + { +#if defined(__GXX_RTTI) || defined(_CPPRTTI) + return dynamic_cast(operand); +#else + #warning used static cast instead of dynamic because RTTI is disabled + return static_cast(operand); +#endif + } +} + +namespace util +{ + class bad_any_cast : public std::bad_cast + { + public: + virtual const char* what() const noexcept override + { + return "Bad any cast"; + } + }; + + //modeled against C++17 std::any + + class any + { + private: + struct holder; + using holder_ptr = std::unique_ptr; + struct holder + { + virtual holder_ptr clone() = 0; + virtual ~holder() = default; + }; + + template + struct holder_impl : holder + { + value_t v; + template + holder_impl(arg_t&& a) : v(std::forward(a)) {} + holder_ptr clone() override { return holder_ptr(new holder_impl (v));} + }; + + holder_ptr hldr; + public: + template + any(value_t&& arg) : hldr(new holder_impl::type>( std::forward(arg))) {} + + any(any const& src) : hldr( src.hldr ? src.hldr->clone() : nullptr) {} + //simple hack in order not to write enable_if for the template constructor + any(any & src) : any (const_cast(src)) {} + + any() = default; + any(any&& ) = default; + + any& operator=(any&&) = default; + + any& operator=(any const& src) + { + any copy(src); + swap(*this, copy); + return *this; + } + + template + friend value_t* any_cast(any* operand); + + template + friend const value_t* any_cast(const any* operand); + + template + friend value_t& unsafe_any_cast(any& operand); + + template + friend const value_t& unsafe_any_cast(const any& operand); + + friend void swap(any & lhs, any& rhs) + { + swap(lhs.hldr, rhs.hldr); + } + + }; + + template + value_t* any_cast(any* operand) + { + auto casted = internal::down_cast::type> *>(operand->hldr.get()); + if (casted){ + return & (casted->v); + } + return nullptr; + } + + template + const value_t* any_cast(const any* operand) + { + auto casted = internal::down_cast::type> *>(operand->hldr.get()); + if (casted){ + return & (casted->v); + } + return nullptr; + } + + template + value_t& any_cast(any& operand) + { + auto ptr = any_cast(&operand); + if (ptr) + { + return *ptr; + } + + throw_error(bad_any_cast()); + } + + + template + const value_t& any_cast(const any& operand) + { + auto ptr = any_cast(&operand); + if (ptr) + { + return *ptr; + } + + throw_error(bad_any_cast()); + } + + template + inline value_t& unsafe_any_cast(any& operand) + { +#ifdef DEBUG + return any_cast(operand); +#else + return static_cast::type> *>(operand.hldr.get())->v; +#endif + } + + template + inline const value_t& unsafe_any_cast(const any& operand) + { +#ifdef DEBUG + return any_cast(operand); +#else + return static_cast::type> *>(operand.hldr.get())->v; +#endif + } + +} // namespace util +} // namespace cv + +#if defined(_MSC_VER) + // Enable "multiple copy constructors specified" back +# pragma warning(default: 4521) +#endif + +#endif // OPENCV_GAPI_UTIL_ANY_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/compiler_hints.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/compiler_hints.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a41a97145dc75009486e5e2cc51bd798cb265e03 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/compiler_hints.hpp @@ -0,0 +1,19 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + +#ifndef OPENCV_GAPI_UTIL_COMPILER_HINTS_HPP +#define OPENCV_GAPI_UTIL_COMPILER_HINTS_HPP + +namespace cv +{ +namespace util +{ + //! Utility template function to prevent "unused" warnings by various compilers. + template void suppress_unused_warning( const T& ) {} +} // namespace util +} // namespace cv + +#endif /* OPENCV_GAPI_UTIL_COMPILER_HINTS_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/optional.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/optional.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1aa2b265d9ae8202bd112f011387ae06a4e6e2b3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/optional.hpp @@ -0,0 +1,178 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_OPTIONAL_HPP +#define OPENCV_GAPI_UTIL_OPTIONAL_HPP + +#include + +// A poor man's `optional` implementation, incompletely modeled against C++17 spec. +namespace cv +{ +namespace util +{ + class bad_optional_access: public std::exception + { + public: + virtual const char *what() const noexcept override + { + return "Bad optional access"; + } + }; + + // TODO: nullopt_t + + // Interface /////////////////////////////////////////////////////////////// + template class optional + { + public: + // Constructors + // NB.: there were issues with Clang 3.8 when =default() was used + // instead {} + optional() {}; + optional(const optional&) = default; + explicit optional(T &&value) noexcept; + explicit optional(const T &value) noexcept; + optional(optional &&) noexcept; + // TODO: optional(nullopt_t) noexcept; + // TODO: optional(const optional &) + // TODO: optional(optional &&) + // TODO: optional(Args&&...) + // TODO: optional(initializer_list) + // TODO: optional(U&& value); + + // Assignment + optional& operator=(const optional& rhs) = default; + optional& operator=(optional&& rhs); + + // Observers + T* operator-> (); + const T* operator-> () const; + T& operator* (); + const T& operator* () const; + // TODO: && versions + + operator bool() const noexcept; + bool has_value() const noexcept; + + T& value(); + const T& value() const; + // TODO: && versions + + template + T value_or(U &&default_value) const; + + void swap(optional &other) noexcept; + void reset() noexcept; + // TODO: emplace + + // TODO: operator==, !=, <, <=, >, >= + + private: + struct nothing {}; + util::variant m_holder; + }; + + template + optional::type> make_optional(T&& value); + + // TODO: Args... and initializer_list versions + + // Implementation ////////////////////////////////////////////////////////// + template optional::optional(T &&v) noexcept + : m_holder(v) + { + } + + template optional::optional(const T &v) noexcept + : m_holder(v) + { + } + + template optional::optional(optional&& rhs) noexcept + : m_holder(std::move(rhs.m_holder)) + { + rhs.reset(); + } + + template optional& optional::operator=(optional&& rhs) + { + m_holder = std::move(rhs.m_holder); + rhs.reset(); + return *this; + } + + template T* optional::operator-> () + { + return & *(*this); + } + + template const T* optional::operator-> () const + { + return & *(*this); + } + + template T& optional::operator* () + { + return this->value(); + } + + template const T& optional::operator* () const + { + return this->value(); + } + + template optional::operator bool() const noexcept + { + return this->has_value(); + } + + template bool optional::has_value() const noexcept + { + return util::holds_alternative(m_holder); + } + + template T& optional::value() + { + if (!this->has_value()) + throw_error(bad_optional_access()); + return util::get(m_holder); + } + + template const T& optional::value() const + { + if (!this->has_value()) + throw_error(bad_optional_access()); + return util::get(m_holder); + } + + template + template T optional::value_or(U &&default_value) const + { + return (this->has_value() ? this->value() : T(default_value)); + } + + template void optional::swap(optional &other) noexcept + { + m_holder.swap(other.m_holder); + } + + template void optional::reset() noexcept + { + if (this->has_value()) + m_holder = nothing{}; + } + + template + optional::type> make_optional(T&& value) + { + return optional::type>(std::forward(value)); + } +} // namespace util +} // namespace cv + +#endif // OPENCV_GAPI_UTIL_OPTIONAL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/throw.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/throw.hpp new file mode 100644 index 0000000000000000000000000000000000000000..689bf583cfee9ef25b4e45bbbe96d641b56db9a1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/throw.hpp @@ -0,0 +1,36 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_THROW_HPP +#define OPENCV_GAPI_UTIL_THROW_HPP + +#include // std::forward + +#if !defined(__EXCEPTIONS) +#include +#include +#endif + +namespace cv +{ +namespace util +{ +template +[[noreturn]] void throw_error(ExceptionType &&e) +{ +#if defined(__EXCEPTIONS) || defined(_CPPUNWIND) + throw std::forward(e); +#else + fprintf(stderr, "An exception thrown! %s\n" , e.what()); + fflush(stderr); + abort(); +#endif +} +} // namespace util +} // namespace cv + +#endif // OPENCV_GAPI_UTIL_THROW_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/util.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/util.hpp new file mode 100644 index 0000000000000000000000000000000000000000..afcf5596fd602d9d375d6ca47ee2f7cda847e20b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/util.hpp @@ -0,0 +1,124 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018-2019 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_HPP +#define OPENCV_GAPI_UTIL_HPP + +#include + +// \cond HIDDEN_SYMBOLS +// This header file contains some generic utility functions which are +// used in other G-API Public API headers. +// +// PLEASE don't put any stuff here if it is NOT used in public API headers! + +namespace cv +{ +namespace detail +{ + // Recursive integer sequence type, useful for enumerating elements of + // template parameter packs. + template struct Seq { using next = Seq; }; + template struct MkSeq { using type = typename MkSeq::type::next; }; + template<> struct MkSeq<0>{ using type = Seq<>; }; + + // Checks if elements of variadic template satisfy the given Predicate. + // Implemented via tuple, with an interface to accept plain type lists + template class, typename, typename...> struct all_satisfy; + + template class F, typename T, typename... Ts> + struct all_satisfy > + { + static const constexpr bool value = F::value + && all_satisfy >::value; + }; + template class F, typename T> + struct all_satisfy > + { + static const constexpr bool value = F::value; + }; + + template class F, typename T, typename... Ts> + struct all_satisfy: public all_satisfy > {}; + + // Permute given tuple type C with given integer sequence II + // Sequence may be less than tuple C size. + template struct permute_tuple; + + template + struct permute_tuple > + { + using type = std::tuple< typename std::tuple_element::type... >; + }; + + // Given T..., generates a type sequence of sizeof...(T)-1 elements + // which is T... without its last element + // Implemented via tuple, with an interface to accept plain type lists + template struct all_but_last; + + template + struct all_but_last > + { + using C = std::tuple; + using S = typename MkSeq::value - 1>::type; + using type = typename permute_tuple::type; + }; + + template + struct all_but_last: public all_but_last > {}; + + template + using all_but_last_t = typename all_but_last::type; + + // NB.: This is here because there's no constexpr std::max in C++11 + template struct max_of_t + { + static constexpr const std::size_t rest = max_of_t::value; + static constexpr const std::size_t value = rest > S0 ? rest : S0; + }; + template struct max_of_t + { + static constexpr const std::size_t value = S; + }; + + template + struct contains : std::false_type{}; + + template + struct contains : std::integral_constant::value || + contains::value> {}; + template + struct contains> : std::integral_constant::value> {}; + + template + struct all_unique : std::true_type{}; + + template + struct all_unique : std::integral_constant::value && + all_unique::value> {}; + + template + struct tuple_wrap_helper; + + template struct tuple_wrap_helper + { + using type = std::tuple; + static type get(T&& obj) { return std::make_tuple(std::move(obj)); } + }; + + template + struct tuple_wrap_helper> + { + using type = std::tuple; + static type get(std::tuple&& objs) { return std::forward>(objs); } + }; +} // namespace detail +} // namespace cv + +// \endcond + +#endif // OPENCV_GAPI_UTIL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/variant.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/variant.hpp new file mode 100644 index 0000000000000000000000000000000000000000..134ba66234d0ea41d19aca5d2e38cdcc4d01074b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/gapi/util/variant.hpp @@ -0,0 +1,379 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2018 Intel Corporation + + +#ifndef OPENCV_GAPI_UTIL_VARIANT_HPP +#define OPENCV_GAPI_UTIL_VARIANT_HPP + +#include +#include + +#include +#include // max_of_t + +// A poor man's `variant` implementation, incompletely modeled against C++17 spec. +namespace cv +{ +namespace util +{ + namespace detail + { + template + struct type_list_index_helper + { + static const constexpr bool is_same = std::is_same::value; + static const constexpr std::size_t value = + std::conditional, type_list_index_helper>::type::value; + }; + + template + struct type_list_index_helper + { + static_assert(std::is_same::value, "Type not found"); + static const constexpr std::size_t value = I; + }; + + + template using are_different = + std::enable_if::type, + typename std::decay::type>::value, + V>; + } + + template + struct type_list_index + { + static const constexpr std::size_t value = detail::type_list_index_helper<0, Target, Types...>::value; + }; + + class bad_variant_access: public std::exception + { + public: + virtual const char *what() const noexcept override + { + return "Bad variant access"; + } + }; + + // Interface /////////////////////////////////////////////////////////////// + struct monostate {}; + inline bool operator==(const util::monostate&, const util::monostate&) + { + return true; + } + + template // FIXME: no references, arrays, and void + class variant + { + // FIXME: Replace with std::aligned_union after gcc4.8 support is dropped + static constexpr const std::size_t S = cv::detail::max_of_t::value; + static constexpr const std::size_t A = cv::detail::max_of_t::value; + using Memory = typename std::aligned_storage::type[1]; + + template struct cctr_h { + static void help(Memory memory, const Memory from) { + new (memory) T(*reinterpret_cast(from)); + } + }; + + template struct vctr_h { + static void help(Memory memory, const void* pval) { + new (memory) T(*reinterpret_cast(pval)); + } + }; + + template struct mctr_h { + static void help(Memory memory, void *pval) { + new (memory) T(std::move(*reinterpret_cast(pval))); + } + }; + + template struct copy_h { + static void help(Memory to, const Memory from) { + *reinterpret_cast(to) = *reinterpret_cast(from); + } + }; + + template struct move_h { + static void help(Memory to, const Memory from) { + *reinterpret_cast(to) = std::move(*reinterpret_cast(from)); + } + }; + + template struct swap_h { + static void help(Memory to, Memory from) { + std::swap(*reinterpret_cast(to), *reinterpret_cast(from)); + } + }; + + template struct dtor_h { + static void help(Memory memory) { + (void) memory; // MSCV warning + reinterpret_cast(memory)->~T(); + } + }; + + template struct equal_h { + static bool help(const Memory lhs, const Memory rhs) { + const T& t_lhs = *reinterpret_cast(lhs); + const T& t_rhs = *reinterpret_cast(rhs); + return t_lhs == t_rhs; + } + }; + + typedef void (*CCtr) (Memory, const Memory); // Copy c-tor (variant) + typedef void (*VCtr) (Memory, const void*); // Copy c-tor (value) + typedef void (*MCtr) (Memory, void*); // Generic move c-tor + typedef void (*Copy) (Memory, const Memory); // Copy assignment + typedef void (*Move) (Memory, const Memory); // Move assignment + typedef void (*Swap) (Memory, Memory); // Swap + typedef void (*Dtor) (Memory); // Destructor + + typedef bool (*Equal)(const Memory, const Memory); // Equality test (external) + + static constexpr std::array cctrs(){ return {{(&cctr_h::help)...}};} + static constexpr std::array vctrs(){ return {{(&vctr_h::help)...}};} + static constexpr std::array mctrs(){ return {{(&mctr_h::help)...}};} + static constexpr std::array cpyrs(){ return {{(©_h::help)...}};} + static constexpr std::array mvers(){ return {{(&move_h::help)...}};} + static constexpr std::array swprs(){ return {{(&swap_h::help)...}};} + static constexpr std::array dtors(){ return {{(&dtor_h::help)...}};} + + std::size_t m_index = 0; + + protected: + template friend T& get(variant &v); + template friend const T& get(const variant &v); + template friend bool operator==(const variant &lhs, + const variant &rhs); + Memory memory; + + public: + // Constructors + variant() noexcept; + variant(const variant& other); + variant(variant&& other) noexcept; + template explicit variant(const T& t); + // are_different is a SFINAE trick to avoid variant(T &&t) with T=variant + // for some reason, this version is called instead of variant(variant&& o) when + // variant is used in STL containers (examples: vector assignment) + template explicit variant(T&& t, typename detail::are_different::type = 0); + // template explicit variant(Args&&... args); + // FIXME: other constructors + + // Destructor + ~variant(); + + // Assignment + variant& operator=(const variant& rhs); + variant& operator=(variant &&rhs) noexcept; + + // SFINAE trick to avoid operator=(T&&) with T=variant<>, see comment above + template + typename detail::are_different + ::type operator=(T&& t) noexcept; + + // Observers + std::size_t index() const noexcept; + // FIXME: valueless_by_exception() + + // Modifiers + // FIXME: emplace() + void swap(variant &rhs) noexcept; + + // Non-C++17x! + template static constexpr std::size_t index_of(); + }; + + // FIMXE: visit + + template + T& get(util::variant &v); + + template + const T& get(const util::variant &v); + + template + bool holds_alternative(const util::variant &v) noexcept; + + // FIXME: T&&, const TT&& versions. + + // Implementation ////////////////////////////////////////////////////////// + template + variant::variant() noexcept + { + typedef typename std::tuple_element<0, std::tuple >::type TFirst; + new (memory) TFirst(); + } + + template + variant::variant(const variant &other) + : m_index(other.m_index) + { + (cctrs()[m_index])(memory, other.memory); + } + + template + variant::variant(variant &&other) noexcept + : m_index(other.m_index) + { + (mctrs()[m_index])(memory, other.memory); + } + + template + template + variant::variant(const T& t) + : m_index(util::type_list_index::value) + { + (vctrs()[m_index])(memory, &t); + } + + template + template + variant::variant(T&& t, typename detail::are_different::type) + : m_index(util::type_list_index::type, Ts...>::value) + { + (mctrs()[m_index])(memory, &t); + } + + template + variant::~variant() + { + (dtors()[m_index])(memory); + } + + template + variant& variant::operator=(const variant &rhs) + { + if (m_index != rhs.m_index) + { + (dtors()[ m_index])(memory); + (cctrs()[rhs.m_index])(memory, rhs.memory); + m_index = rhs.m_index; + } + else + { + (cpyrs()[rhs.m_index])(memory, rhs.memory); + } + return *this; + } + + template + variant& variant::operator=(variant &&rhs) noexcept + { + if (m_index != rhs.m_index) + { + (dtors()[ m_index])(memory); + (mctrs()[rhs.m_index])(memory, rhs.memory); + m_index = rhs.m_index; + } + else + { + (mvers()[rhs.m_index])(memory, rhs.memory); + } + return *this; + } + + template + template typename detail::are_different, T, variant&> + ::type variant::operator=(T&& t) noexcept + { + // FIXME: No version with implicit type conversion available! + static const constexpr std::size_t t_index = + util::type_list_index::value; + + if (t_index == m_index) + { + util::get(*this) = std::move(t); + return *this; + } + else return (*this = variant(std::move(t))); + } + + template + std::size_t util::variant::index() const noexcept + { + return m_index; + } + + template + void variant::swap(variant &rhs) noexcept + { + if (m_index == rhs.index()) + { + (swprs()[m_index](memory, rhs.memory)); + } + else + { + variant tmp(std::move(*this)); + *this = std::move(rhs); + rhs = std::move(tmp); + } + } + + template + template + constexpr std::size_t variant::index_of() + { + return util::type_list_index::value; // FIXME: tests! + } + + template + T& get(util::variant &v) + { + const constexpr std::size_t t_index = + util::type_list_index::value; + + if (v.index() == t_index) + return *(T*)(&v.memory); // workaround for ICC 2019 + // original code: return reinterpret_cast(v.memory); + else + throw_error(bad_variant_access()); + } + + template + const T& get(const util::variant &v) + { + const constexpr std::size_t t_index = + util::type_list_index::value; + + if (v.index() == t_index) + return *(const T*)(&v.memory); // workaround for ICC 2019 + // original code: return reinterpret_cast(v.memory); + else + throw_error(bad_variant_access()); + } + + template + bool holds_alternative(const util::variant &v) noexcept + { + return v.index() == util::variant::template index_of(); + } + + template bool operator==(const variant &lhs, + const variant &rhs) + { + using V = variant; + + // Instantiate table only here since it requires operator== for + // should have operator== only if this one is used, not in general + static const std::array eqs = { + {(&V::template equal_h::help)...} + }; + if (lhs.index() != rhs.index()) + return false; + return (eqs[lhs.index()])(lhs.memory, rhs.memory); + } + + template bool operator!=(const variant &lhs, + const variant &rhs) + { + return !(lhs == rhs); + } +} // namespace cv +} // namespace util + +#endif // OPENCV_GAPI_UTIL_VARIANT_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hdf.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hdf.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ff40426ff65c6ab91e0c3ae49a46ddbf768fa89a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hdf.hpp @@ -0,0 +1,57 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2015 + * Balint Cristian + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + +#ifndef __OPENCV_HDF_HPP__ +#define __OPENCV_HDF_HPP__ + +#include "opencv2/hdf/hdf5.hpp" + +/** @defgroup hdf Hierarchical Data Format I/O routines + +This module provides storage routines for Hierarchical Data Format objects. + + @{ + @defgroup hdf5 Hierarchical Data Format version 5 + +Hierarchical Data Format version 5 +-------------------------------------------------------- + +In order to use it, the hdf5 library has to be installed, which +means cmake should find it using `find_package(HDF5)` . + + + @} +*/ + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hdf/hdf5.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hdf/hdf5.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e60cc8791f628aac416f87475ea574d278777e2d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hdf/hdf5.hpp @@ -0,0 +1,808 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2015 + * Balint Cristian + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + +#ifndef __OPENCV_HDF5_HPP__ +#define __OPENCV_HDF5_HPP__ + +#include +#include + +namespace cv +{ +namespace hdf +{ +using namespace std; + +//! @addtogroup hdf5 +//! @{ + + +/** @brief Hierarchical Data Format version 5 interface. + +Notice that this module is compiled only when hdf5 is correctly installed. + + */ +class CV_EXPORTS_W HDF5 +{ +public: + + CV_WRAP enum + { + H5_UNLIMITED = -1, //!< The dimension size is unlimited, @sa dscreate() + H5_NONE = -1, //!< No compression, @sa dscreate() + H5_GETDIMS = 100, //!< Get the dimension information of a dataset. @sa dsgetsize() + H5_GETMAXDIMS = 101, //!< Get the maximum dimension information of a dataset. @sa dsgetsize() + H5_GETCHUNKDIMS = 102, //!< Get the chunk sizes of a dataset. @sa dsgetsize() + }; + + virtual ~HDF5() {} + + /** @brief Close and release hdf5 object. + */ + CV_WRAP virtual void close( ) = 0; + + /** @brief Create a group. + @param grlabel specify the hdf5 group label. + + Create a hdf5 group with default properties. The group is closed automatically after creation. + + @note Groups are useful for better organising multiple datasets. It is possible to create subgroups within any group. + Existence of a particular group can be checked using hlexists(). In case of subgroups, a label would be e.g: 'Group1/SubGroup1' + where SubGroup1 is within the root group Group1. Before creating a subgroup, its parent group MUST be created. + + - In this example, Group1 will have one subgroup called SubGroup1: + + @snippet samples/create_groups.cpp create_group + + The corresponding result visualized using the HDFView tool is + + ![Visualization of groups using the HDFView tool](pics/create_groups.png) + + @note When a dataset is created with dscreate() or kpcreate(), it can be created within a group by specifying the + full path within the label. In our example, it would be: 'Group1/SubGroup1/MyDataSet'. It is not thread safe. + */ + CV_WRAP virtual void grcreate( const String& grlabel ) = 0; + + /** @brief Check if label exists or not. + @param label specify the hdf5 dataset label. + + Returns **true** if dataset exists, and **false** otherwise. + + @note Checks if dataset, group or other object type (hdf5 link) exists under the label name. It is thread safe. + */ + CV_WRAP virtual bool hlexists( const String& label ) const = 0; + + /** + * Check whether a given attribute exits or not in the root group. + * + * @param atlabel the attribute name to be checked. + * @return true if the attribute exists, false otherwise. + * + * @sa atdelete, atwrite, atread + */ + CV_WRAP virtual bool atexists(const String& atlabel) const = 0; + + /** + * Delete an attribute from the root group. + * + * @param atlabel the attribute to be deleted. + * + * @note CV_Error() is called if the given attribute does not exist. Use atexists() + * to check whether it exists or not beforehand. + * + * @sa atexists, atwrite, atread + */ + CV_WRAP virtual void atdelete(const String& atlabel) = 0; + + /** + * Write an attribute inside the root group. + * + * @param value attribute value. + * @param atlabel attribute name. + * + * The following example demonstrates how to write an attribute of type cv::String: + * + * @snippet samples/read_write_attributes.cpp snippets_write_str + * + * @note CV_Error() is called if the given attribute already exists. Use atexists() + * to check whether it exists or not beforehand. And use atdelete() to delete + * it if it already exists. + * + * @sa atexists, atdelete, atread + */ + CV_WRAP virtual void atwrite(const int value, const String& atlabel) = 0; + + /** + * Read an attribute from the root group. + * + * @param value address where the attribute is read into + * @param atlabel attribute name + * + * The following example demonstrates how to read an attribute of type cv::String: + * + * @snippet samples/read_write_attributes.cpp snippets_read_str + * + * @note The attribute MUST exist, otherwise CV_Error() is called. Use atexists() + * to check if it exists beforehand. + * + * @sa atexists, atdelete, atwrite + */ + CV_WRAP virtual void atread(int* value, const String& atlabel) = 0; + + /** @overload */ + CV_WRAP virtual void atwrite(const double value, const String& atlabel) = 0; + + /** @overload */ + CV_WRAP virtual void atread(double* value, const String& atlabel) = 0; + + /** @overload */ + CV_WRAP virtual void atwrite(const String& value, const String& atlabel) = 0; + + /** @overload */ + CV_WRAP virtual void atread(String* value, const String& atlabel) = 0; + + /** + * Write an attribute into the root group. + * + * @param value attribute value. Currently, only n-d continuous multi-channel arrays are supported. + * @param atlabel attribute name. + * + * @note CV_Error() is called if the given attribute already exists. Use atexists() + * to check whether it exists or not beforehand. And use atdelete() to delete + * it if it already exists. + * + * @sa atexists, atdelete, atread. + */ + CV_WRAP virtual void atwrite(InputArray value, const String& atlabel) = 0; + + /** + * Read an attribute from the root group. + * + * @param value attribute value. Currently, only n-d continuous multi-channel arrays are supported. + * @param atlabel attribute name. + * + * @note The attribute MUST exist, otherwise CV_Error() is called. Use atexists() + * to check if it exists beforehand. + * + * @sa atexists, atdelete, atwrite + */ + CV_WRAP virtual void atread(OutputArray value, const String& atlabel) = 0; + + /** @overload */ + CV_WRAP virtual void dscreate( const int rows, const int cols, const int type, + const String& dslabel ) const = 0; + /** @overload */ + CV_WRAP virtual void dscreate( const int rows, const int cols, const int type, + const String& dslabel, const int compresslevel ) const = 0; + /** @overload */ + CV_WRAP virtual void dscreate( const int rows, const int cols, const int type, + const String& dslabel, const int compresslevel, const vector& dims_chunks ) const = 0; + /** @brief Create and allocate storage for two dimensional single or multi channel dataset. + @param rows declare amount of rows + @param cols declare amount of columns + @param type type to be used, e.g, CV_8UC3, CV_32FC1 and etc. + @param dslabel specify the hdf5 dataset label. Existing dataset label will cause an error. + @param compresslevel specify the compression level 0-9 to be used, H5_NONE is the default value and means no compression. + The value 0 also means no compression. + A value 9 indicating the best compression ration. Note + that a higher compression level indicates a higher computational cost. It relies + on GNU gzip for compression. + @param dims_chunks each array member specifies the chunking size to be used for block I/O, + by default NULL means none at all. + + @note If the dataset already exists, an exception will be thrown (CV_Error() is called). + + - Existence of the dataset can be checked using hlexists(), see in this example: + @code{.cpp} + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // create space for 100x50 CV_64FC2 matrix + if ( ! h5io->hlexists( "hilbert" ) ) + h5io->dscreate( 100, 50, CV_64FC2, "hilbert" ); + else + printf("DS already created, skipping\n" ); + // release + h5io->close(); + @endcode + + @note Activating compression requires internal chunking. Chunking can significantly improve access + speed both at read and write time, especially for windowed access logic that shifts offset inside dataset. + If no custom chunking is specified, the default one will be invoked by the size of the **whole** dataset + as a single big chunk of data. + + - See example of level 9 compression using internal default chunking: + @code{.cpp} + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // create level 9 compressed space for CV_64FC2 matrix + if ( ! h5io->hlexists( "hilbert", 9 ) ) + h5io->dscreate( 100, 50, CV_64FC2, "hilbert", 9 ); + else + printf("DS already created, skipping\n" ); + // release + h5io->close(); + @endcode + + @note A value of H5_UNLIMITED for **rows** or **cols** or both means **unlimited** data on the specified dimension, + thus, it is possible to expand anytime such a dataset on row, col or on both directions. Presence of H5_UNLIMITED on any + dimension **requires** to define custom chunking. No default chunking will be defined in the unlimited scenario since + default size on that dimension will be zero, and will grow once dataset is written. Writing into a dataset that has + H5_UNLIMITED on some of its dimensions requires dsinsert() that allows growth on unlimited dimensions, instead of dswrite() + that allows to write only in predefined data space. + + - Example below shows no compression but unlimited dimension on cols using 100x100 internal chunking: + @code{.cpp} + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // create level 9 compressed space for CV_64FC2 matrix + int chunks[2] = { 100, 100 }; + h5io->dscreate( 100, cv::hdf::HDF5::H5_UNLIMITED, CV_64FC2, "hilbert", cv::hdf::HDF5::H5_NONE, chunks ); + // release + h5io->close(); + @endcode + + @note It is **not** thread safe, it must be called only once at dataset creation, otherwise an exception will occur. + Multiple datasets inside a single hdf5 file are allowed. + */ + CV_WRAP virtual void dscreate( const int rows, const int cols, const int type, + const String& dslabel, const int compresslevel, const int* dims_chunks ) const = 0; + + /* @overload */ + CV_WRAP virtual void dscreate( const int n_dims, const int* sizes, const int type, + const String& dslabel ) const = 0; + /* @overload */ + CV_WRAP virtual void dscreate( const int n_dims, const int* sizes, const int type, + const String& dslabel, const int compresslevel ) const = 0; + /* @overload */ + CV_WRAP virtual void dscreate( const vector& sizes, const int type, + const String& dslabel, const int compresslevel = HDF5::H5_NONE, + const vector& dims_chunks = vector() ) const = 0; + /** @brief Create and allocate storage for n-dimensional dataset, single or multichannel type. + @param n_dims declare number of dimensions + @param sizes array containing sizes for each dimensions + @param type type to be used, e.g., CV_8UC3, CV_32FC1, etc. + @param dslabel specify the hdf5 dataset label. Existing dataset label will cause an error. + @param compresslevel specify the compression level 0-9 to be used, H5_NONE is the default value and means no compression. + The value 0 also means no compression. + A value 9 indicating the best compression ration. Note + that a higher compression level indicates a higher computational cost. It relies + on GNU gzip for compression. + @param dims_chunks each array member specifies chunking sizes to be used for block I/O, + by default NULL means none at all. + @note If the dataset already exists, an exception will be thrown. Existence of the dataset can be checked + using hlexists(). + + - See example below that creates a 6 dimensional storage space: + @code{.cpp} + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // create space for 6 dimensional CV_64FC2 matrix + if ( ! h5io->hlexists( "nddata" ) ) + int n_dims = 5; + int dsdims[n_dims] = { 100, 100, 20, 10, 5, 5 }; + h5io->dscreate( n_dims, sizes, CV_64FC2, "nddata" ); + else + printf("DS already created, skipping\n" ); + // release + h5io->close(); + @endcode + + @note Activating compression requires internal chunking. Chunking can significantly improve access + speed both at read and write time, especially for windowed access logic that shifts offset inside dataset. + If no custom chunking is specified, the default one will be invoked by the size of **whole** dataset + as single big chunk of data. + + - See example of level 0 compression (shallow) using chunking against the first + dimension, thus storage will consists of 100 chunks of data: + @code{.cpp} + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // create space for 6 dimensional CV_64FC2 matrix + if ( ! h5io->hlexists( "nddata" ) ) + int n_dims = 5; + int dsdims[n_dims] = { 100, 100, 20, 10, 5, 5 }; + int chunks[n_dims] = { 1, 100, 20, 10, 5, 5 }; + h5io->dscreate( n_dims, dsdims, CV_64FC2, "nddata", 0, chunks ); + else + printf("DS already created, skipping\n" ); + // release + h5io->close(); + @endcode + + @note A value of H5_UNLIMITED inside the **sizes** array means **unlimited** data on that dimension, thus it is + possible to expand anytime such dataset on those unlimited directions. Presence of H5_UNLIMITED on any dimension + **requires** to define custom chunking. No default chunking will be defined in unlimited scenario since the default size + on that dimension will be zero, and will grow once dataset is written. Writing into dataset that has H5_UNLIMITED on + some of its dimension requires dsinsert() instead of dswrite() that allows growth on unlimited dimension instead of + dswrite() that allows to write only in predefined data space. + + - Example below shows a 3 dimensional dataset using no compression with all unlimited sizes and one unit chunking: + @code{.cpp} + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + int n_dims = 3; + int chunks[n_dims] = { 1, 1, 1 }; + int dsdims[n_dims] = { cv::hdf::HDF5::H5_UNLIMITED, cv::hdf::HDF5::H5_UNLIMITED, cv::hdf::HDF5::H5_UNLIMITED }; + h5io->dscreate( n_dims, dsdims, CV_64FC2, "nddata", cv::hdf::HDF5::H5_NONE, chunks ); + // release + h5io->close(); + @endcode + */ + CV_WRAP virtual void dscreate( const int n_dims, const int* sizes, const int type, + const String& dslabel, const int compresslevel, const int* dims_chunks ) const = 0; + + /** @brief Fetch dataset sizes + @param dslabel specify the hdf5 dataset label to be measured. + @param dims_flag will fetch dataset dimensions on H5_GETDIMS, dataset maximum dimensions on H5_GETMAXDIMS, + and chunk sizes on H5_GETCHUNKDIMS. + + Returns vector object containing sizes of dataset on each dimensions. + + @note Resulting vector size will match the amount of dataset dimensions. By default H5_GETDIMS will return + actual dataset dimensions. Using H5_GETMAXDIM flag will get maximum allowed dimension which normally match + actual dataset dimension but can hold H5_UNLIMITED value if dataset was prepared in **unlimited** mode on + some of its dimension. It can be useful to check existing dataset dimensions before overwrite it as whole or subset. + Trying to write with oversized source data into dataset target will thrown exception. The H5_GETCHUNKDIMS will + return the dimension of chunk if dataset was created with chunking options otherwise returned vector size + will be zero. + */ + CV_WRAP virtual vector dsgetsize( const String& dslabel, int dims_flag = HDF5::H5_GETDIMS ) const = 0; + + /** @brief Fetch dataset type + @param dslabel specify the hdf5 dataset label to be checked. + + Returns the stored matrix type. This is an identifier compatible with the CvMat type system, + like e.g. CV_16SC5 (16-bit signed 5-channel array), and so on. + + @note Result can be parsed with CV_MAT_CN() to obtain amount of channels and CV_MAT_DEPTH() to obtain native cvdata type. + It is thread safe. + */ + CV_WRAP virtual int dsgettype( const String& dslabel ) const = 0; + + /* @overload */ + CV_WRAP virtual void dswrite( InputArray Array, const String& dslabel ) const = 0; + /* @overload */ + CV_WRAP virtual void dswrite( InputArray Array, const String& dslabel, + const int* dims_offset ) const = 0; + /* @overload */ + CV_WRAP virtual void dswrite( InputArray Array, const String& dslabel, + const vector& dims_offset, + const vector& dims_counts = vector() ) const = 0; + /** @brief Write or overwrite a Mat object into specified dataset of hdf5 file. + @param Array specify Mat data array to be written. + @param dslabel specify the target hdf5 dataset label. + @param dims_offset each array member specify the offset location + over dataset's each dimensions from where InputArray will be (over)written into dataset. + @param dims_counts each array member specifies the amount of data over dataset's + each dimensions from InputArray that will be written into dataset. + + Writes Mat object into targeted dataset. + + @note If dataset is not created and does not exist it will be created **automatically**. Only Mat is supported and + it must be **continuous**. It is thread safe but it is recommended that writes to happen over separate non-overlapping + regions. Multiple datasets can be written inside a single hdf5 file. + + - Example below writes a 100x100 CV_64FC2 matrix into a dataset. No dataset pre-creation required. If routine + is called multiple times dataset will be just overwritten: + @code{.cpp} + // dual channel hilbert matrix + cv::Mat H(100, 100, CV_64FC2); + for(int i = 0; i < H.rows; i++) + for(int j = 0; j < H.cols; j++) + { + H.at(i,j)[0] = 1./(i+j+1); + H.at(i,j)[1] = -1./(i+j+1); + count++; + } + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // write / overwrite dataset + h5io->dswrite( H, "hilbert" ); + // release + h5io->close(); + @endcode + + - Example below writes a smaller 50x100 matrix into 100x100 compressed space optimised by two 50x100 chunks. + Matrix is written twice into first half (0->50) and second half (50->100) of data space using offset. + @code{.cpp} + // dual channel hilbert matrix + cv::Mat H(50, 100, CV_64FC2); + for(int i = 0; i < H.rows; i++) + for(int j = 0; j < H.cols; j++) + { + H.at(i,j)[0] = 1./(i+j+1); + H.at(i,j)[1] = -1./(i+j+1); + count++; + } + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // optimise dataset by two chunks + int chunks[2] = { 50, 100 }; + // create 100x100 CV_64FC2 compressed space + h5io->dscreate( 100, 100, CV_64FC2, "hilbert", 9, chunks ); + // write into first half + int offset1[2] = { 0, 0 }; + h5io->dswrite( H, "hilbert", offset1 ); + // write into second half + int offset2[2] = { 50, 0 }; + h5io->dswrite( H, "hilbert", offset2 ); + // release + h5io->close(); + @endcode + */ + CV_WRAP virtual void dswrite( InputArray Array, const String& dslabel, + const int* dims_offset, const int* dims_counts ) const = 0; + + /* @overload */ + CV_WRAP virtual void dsinsert( InputArray Array, const String& dslabel ) const = 0; + /* @overload */ + CV_WRAP virtual void dsinsert( InputArray Array, + const String& dslabel, const int* dims_offset ) const = 0; + /* @overload */ + CV_WRAP virtual void dsinsert( InputArray Array, + const String& dslabel, const vector& dims_offset, + const vector& dims_counts = vector() ) const = 0; + /** @brief Insert or overwrite a Mat object into specified dataset and auto expand dataset size if **unlimited** property allows. + @param Array specify Mat data array to be written. + @param dslabel specify the target hdf5 dataset label. + @param dims_offset each array member specify the offset location + over dataset's each dimensions from where InputArray will be (over)written into dataset. + @param dims_counts each array member specify the amount of data over dataset's + each dimensions from InputArray that will be written into dataset. + + Writes Mat object into targeted dataset and **autoexpand** dataset dimension if allowed. + + @note Unlike dswrite(), datasets are **not** created **automatically**. Only Mat is supported and it must be **continuous**. + If dsinsert() happens over outer regions of dataset dimensions and on that dimension of dataset is in **unlimited** mode then + dataset is expanded, otherwise exception is thrown. To create datasets with **unlimited** property on specific or more + dimensions see dscreate() and the optional H5_UNLIMITED flag at creation time. It is not thread safe over same dataset + but multiple datasets can be merged inside a single hdf5 file. + + - Example below creates **unlimited** rows x 100 cols and expands rows 5 times with dsinsert() using single 100x100 CV_64FC2 + over the dataset. Final size will have 5x100 rows and 100 cols, reflecting H matrix five times over row's span. Chunks size is + 100x100 just optimized against the H matrix size having compression disabled. If routine is called multiple times dataset will be + just overwritten: + @code{.cpp} + // dual channel hilbert matrix + cv::Mat H(50, 100, CV_64FC2); + for(int i = 0; i < H.rows; i++) + for(int j = 0; j < H.cols; j++) + { + H.at(i,j)[0] = 1./(i+j+1); + H.at(i,j)[1] = -1./(i+j+1); + count++; + } + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // optimise dataset by chunks + int chunks[2] = { 100, 100 }; + // create Unlimited x 100 CV_64FC2 space + h5io->dscreate( cv::hdf::HDF5::H5_UNLIMITED, 100, CV_64FC2, "hilbert", cv::hdf::HDF5::H5_NONE, chunks ); + // write into first half + int offset[2] = { 0, 0 }; + for ( int t = 0; t < 5; t++ ) + { + offset[0] += 100 * t; + h5io->dsinsert( H, "hilbert", offset ); + } + // release + h5io->close(); + @endcode + */ + CV_WRAP virtual void dsinsert( InputArray Array, const String& dslabel, + const int* dims_offset, const int* dims_counts ) const = 0; + + + /* @overload */ + CV_WRAP virtual void dsread( OutputArray Array, const String& dslabel ) const = 0; + /* @overload */ + CV_WRAP virtual void dsread( OutputArray Array, + const String& dslabel, const int* dims_offset ) const = 0; + /* @overload */ + CV_WRAP virtual void dsread( OutputArray Array, const String& dslabel, + const vector& dims_offset, + const vector& dims_counts = vector() ) const = 0; + /** @brief Read specific dataset from hdf5 file into Mat object. + @param Array Mat container where data reads will be returned. + @param dslabel specify the source hdf5 dataset label. + @param dims_offset each array member specify the offset location over + each dimensions from where dataset starts to read into OutputArray. + @param dims_counts each array member specify the amount over dataset's each + dimensions of dataset to read into OutputArray. + + Reads out Mat object reflecting the stored dataset. + + @note If hdf5 file does not exist an exception will be thrown. Use hlexists() to check dataset presence. + It is thread safe. + + - Example below reads a dataset: + @code{.cpp} + // open hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // blank Mat container + cv::Mat H; + // read hibert dataset + h5io->read( H, "hilbert" ); + // release + h5io->close(); + @endcode + + - Example below perform read of 3x5 submatrix from second row and third element. + @code{.cpp} + // open hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // blank Mat container + cv::Mat H; + int offset[2] = { 1, 2 }; + int counts[2] = { 3, 5 }; + // read hibert dataset + h5io->read( H, "hilbert", offset, counts ); + // release + h5io->close(); + @endcode + */ + CV_WRAP virtual void dsread( OutputArray Array, const String& dslabel, + const int* dims_offset, const int* dims_counts ) const = 0; + + /** @brief Fetch keypoint dataset size + @param kplabel specify the hdf5 dataset label to be measured. + @param dims_flag will fetch dataset dimensions on H5_GETDIMS, and dataset maximum dimensions on H5_GETMAXDIMS. + + Returns size of keypoints dataset. + + @note Resulting size will match the amount of keypoints. By default H5_GETDIMS will return actual dataset dimension. + Using H5_GETMAXDIM flag will get maximum allowed dimension which normally match actual dataset dimension but can hold + H5_UNLIMITED value if dataset was prepared in **unlimited** mode. It can be useful to check existing dataset dimension + before overwrite it as whole or subset. Trying to write with oversized source data into dataset target will thrown + exception. The H5_GETCHUNKDIMS will return the dimension of chunk if dataset was created with chunking options otherwise + returned vector size will be zero. + */ + CV_WRAP virtual int kpgetsize( const String& kplabel, int dims_flag = HDF5::H5_GETDIMS ) const = 0; + + /** @brief Create and allocate special storage for cv::KeyPoint dataset. + @param size declare fixed number of KeyPoints + @param kplabel specify the hdf5 dataset label, any existing dataset with the same label will be overwritten. + @param compresslevel specify the compression level 0-9 to be used, H5_NONE is default and means no compression. + @param chunks each array member specifies chunking sizes to be used for block I/O, + H5_NONE is default and means no compression. + @note If the dataset already exists an exception will be thrown. Existence of the dataset can be checked + using hlexists(). + + - See example below that creates space for 100 keypoints in the dataset: + @code{.cpp} + // open hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + if ( ! h5io->hlexists( "keypoints" ) ) + h5io->kpcreate( 100, "keypoints" ); + else + printf("DS already created, skipping\n" ); + @endcode + + @note A value of H5_UNLIMITED for **size** means **unlimited** keypoints, thus is possible to expand anytime such + dataset by adding or inserting. Presence of H5_UNLIMITED **require** to define custom chunking. No default chunking + will be defined in unlimited scenario since default size on that dimension will be zero, and will grow once dataset + is written. Writing into dataset that have H5_UNLIMITED on some of its dimension requires kpinsert() that allow + growth on unlimited dimension instead of kpwrite() that allows to write only in predefined data space. + + - See example below that creates unlimited space for keypoints chunking size of 100 but no compression: + @code{.cpp} + // open hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + if ( ! h5io->hlexists( "keypoints" ) ) + h5io->kpcreate( cv::hdf::HDF5::H5_UNLIMITED, "keypoints", cv::hdf::HDF5::H5_NONE, 100 ); + else + printf("DS already created, skipping\n" ); + @endcode + */ + virtual void kpcreate( const int size, const String& kplabel, + const int compresslevel = H5_NONE, const int chunks = H5_NONE ) const = 0; + + /** @brief Write or overwrite list of KeyPoint into specified dataset of hdf5 file. + @param keypoints specify keypoints data list to be written. + @param kplabel specify the target hdf5 dataset label. + @param offset specify the offset location on dataset from where keypoints will be (over)written into dataset. + @param counts specify the amount of keypoints that will be written into dataset. + + Writes vector object into targeted dataset. + + @note If dataset is not created and does not exist it will be created **automatically**. It is thread safe but + it is recommended that writes to happen over separate non overlapping regions. Multiple datasets can be written + inside single hdf5 file. + + - Example below writes a 100 keypoints into a dataset. No dataset precreation required. If routine is called multiple + times dataset will be just overwritten: + @code{.cpp} + // generate 100 dummy keypoints + std::vector keypoints; + for(int i = 0; i < 100; i++) + keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) ); + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // write / overwrite dataset + h5io->kpwrite( keypoints, "keypoints" ); + // release + h5io->close(); + @endcode + + - Example below uses smaller set of 50 keypoints and writes into compressed space of 100 keypoints optimised by 10 chunks. + Same keypoint set is written three times, first into first half (0->50) and at second half (50->75) then into remaining slots + (75->99) of data space using offset and count parameters to settle the window for write access.If routine is called multiple times + dataset will be just overwritten: + @code{.cpp} + // generate 50 dummy keypoints + std::vector keypoints; + for(int i = 0; i < 50; i++) + keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) ); + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // create maximum compressed space of size 100 with chunk size 10 + h5io->kpcreate( 100, "keypoints", 9, 10 ); + // write into first half + h5io->kpwrite( keypoints, "keypoints", 0 ); + // write first 25 keypoints into second half + h5io->kpwrite( keypoints, "keypoints", 50, 25 ); + // write first 25 keypoints into remained space of second half + h5io->kpwrite( keypoints, "keypoints", 75, 25 ); + // release + h5io->close(); + @endcode + */ + virtual void kpwrite( const vector keypoints, const String& kplabel, + const int offset = H5_NONE, const int counts = H5_NONE ) const = 0; + + /** @brief Insert or overwrite list of KeyPoint into specified dataset and autoexpand dataset size if **unlimited** property allows. + @param keypoints specify keypoints data list to be written. + @param kplabel specify the target hdf5 dataset label. + @param offset specify the offset location on dataset from where keypoints will be (over)written into dataset. + @param counts specify the amount of keypoints that will be written into dataset. + + Writes vector object into targeted dataset and **autoexpand** dataset dimension if allowed. + + @note Unlike kpwrite(), datasets are **not** created **automatically**. If dsinsert() happen over outer region of dataset + and dataset has been created in **unlimited** mode then dataset is expanded, otherwise exception is thrown. To create datasets + with **unlimited** property see kpcreate() and the optional H5_UNLIMITED flag at creation time. It is not thread safe over same + dataset but multiple datasets can be merged inside single hdf5 file. + + - Example below creates **unlimited** space for keypoints storage, and inserts a list of 10 keypoints ten times into that space. + Final dataset will have 100 keypoints. Chunks size is 10 just optimized against list of keypoints. If routine is called multiple + times dataset will be just overwritten: + @code{.cpp} + // generate 10 dummy keypoints + std::vector keypoints; + for(int i = 0; i < 10; i++) + keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) ); + // open / autocreate hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // create unlimited size space with chunk size of 10 + h5io->kpcreate( cv::hdf::HDF5::H5_UNLIMITED, "keypoints", -1, 10 ); + // insert 10 times same 10 keypoints + for(int i = 0; i < 10; i++) + h5io->kpinsert( keypoints, "keypoints", i * 10 ); + // release + h5io->close(); + @endcode + */ + virtual void kpinsert( const vector keypoints, const String& kplabel, + const int offset = H5_NONE, const int counts = H5_NONE ) const = 0; + + /** @brief Read specific keypoint dataset from hdf5 file into vector object. + @param keypoints vector container where data reads will be returned. + @param kplabel specify the source hdf5 dataset label. + @param offset specify the offset location over dataset from where read starts. + @param counts specify the amount of keypoints from dataset to read. + + Reads out vector object reflecting the stored dataset. + + @note If hdf5 file does not exist an exception will be thrown. Use hlexists() to check dataset presence. + It is thread safe. + + - Example below reads a dataset containing keypoints starting with second entry: + @code{.cpp} + // open hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // blank KeyPoint container + std::vector keypoints; + // read keypoints starting second one + h5io->kpread( keypoints, "keypoints", 1 ); + // release + h5io->close(); + @endcode + + - Example below perform read of 3 keypoints from second entry. + @code{.cpp} + // open hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // blank KeyPoint container + std::vector keypoints; + // read three keypoints starting second one + h5io->kpread( keypoints, "keypoints", 1, 3 ); + // release + h5io->close(); + @endcode + */ + virtual void kpread( vector& keypoints, const String& kplabel, + const int offset = H5_NONE, const int counts = H5_NONE ) const = 0; + +}; + + /** @brief Open or create hdf5 file + @param HDF5Filename specify the HDF5 filename. + + Returns a pointer to the hdf5 object class + + @note If the specified file does not exist, it will be created using default properties. + Otherwise, it is opened in read and write mode with default access properties. + Any operations except dscreate() functions on object + will be thread safe. Multiple datasets can be created inside a single hdf5 file, and can be accessed + from the same hdf5 object from multiple instances as long read or write operations are done over + non-overlapping regions of dataset. Single hdf5 file also can be opened by multiple instances, + reads and writes can be instantiated at the same time as long as non-overlapping regions are involved. Object + is released using close(). + + - Example below opens and then releases the file. + @code{.cpp} + // open / auto create hdf5 file + cv::Ptr h5io = cv::hdf::open( "mytest.h5" ); + // ... + // release + h5io->close(); + @endcode + + ![Visualization of 10x10 CV_64FC2 (Hilbert matrix) using HDFView tool](pics/hdfview_demo.gif) + + - Text dump (3x3 Hilbert matrix) of hdf5 dataset using **h5dump** tool: + @code{.txt} + $ h5dump test.h5 + HDF5 "test.h5" { + GROUP "/" { + DATASET "hilbert" { + DATATYPE H5T_ARRAY { [2] H5T_IEEE_F64LE } + DATASPACE SIMPLE { ( 3, 3 ) / ( 3, 3 ) } + DATA { + (0,0): [ 1, -1 ], [ 0.5, -0.5 ], [ 0.333333, -0.333333 ], + (1,0): [ 0.5, -0.5 ], [ 0.333333, -0.333333 ], [ 0.25, -0.25 ], + (2,0): [ 0.333333, -0.333333 ], [ 0.25, -0.25 ], [ 0.2, -0.2 ] + } + } + } + } + @endcode + */ + CV_EXPORTS_W Ptr open( const String& HDF5Filename ); + +//! @} + +} // end namespace hdf +} // end namespace cv +#endif // _OPENCV_HDF5_HPP_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hfs.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hfs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..948f117c3957c49d5e2fef430d5c0ba470f3614b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/hfs.hpp @@ -0,0 +1,153 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "opencv2/core.hpp" + +namespace cv { namespace hfs { + +/** @defgroup hfs Hierarchical Feature Selection for Efficient Image Segmentation + +The opencv hfs module contains an efficient algorithm to segment an image. +This module is implemented based on the paper Hierarchical Feature Selection for Efficient +Image Segmentation, ECCV 2016. The original project was developed by +Yun Liu(https://github.com/yun-liu/hfs). + + +Introduction to Hierarchical Feature Selection +---------------------------------------------- + + +This algorithm is executed in 3 stages: + +In the first stage, the algorithm uses SLIC (simple linear iterative clustering) algorithm +to obtain the superpixel of the input image. + +In the second stage, the algorithm view each superpixel as a node in the graph. +It will calculate a feature vector for each edge of the graph. It then calculates a weight +for each edge based on the feature vector and trained SVM parameters. After obtaining +weight for each edge, it will exploit EGB (Efficient Graph-based Image Segmentation) +algorithm to merge some nodes in the graph thus obtaining a coarser segmentation +After these operations, a post process will be executed to merge regions that are smaller +then a specific number of pixels into their nearby region. + +In the third stage, the algorithm exploits the similar mechanism to further merge +the small regions obtained in the second stage into even coarser segmentation. + +After these three stages, we can obtain the final segmentation of the image. +For further details about the algorithm, please refer to the original paper: +Hierarchical Feature Selection for Efficient Image Segmentation, ECCV 2016 + +*/ + +//! @addtogroup hfs +//! @{ +class CV_EXPORTS_W HfsSegment : public Algorithm { +public: + +/** @brief: set and get the parameter segEgbThresholdI. +* This parameter is used in the second stage mentioned above. +* It is a constant used to threshold weights of the edge when merging +* adjacent nodes when applying EGB algorithm. The segmentation result +* tends to have more regions remained if this value is large and vice versa. +*/ +CV_WRAP virtual void setSegEgbThresholdI(float c) = 0; +CV_WRAP virtual float getSegEgbThresholdI() = 0; + + +/** @brief: set and get the parameter minRegionSizeI. +* This parameter is used in the second stage +* mentioned above. After the EGB segmentation, regions that have fewer +* pixels then this parameter will be merged into it's adjacent region. +*/ +CV_WRAP virtual void setMinRegionSizeI(int n) = 0; +CV_WRAP virtual int getMinRegionSizeI() = 0; + + +/** @brief: set and get the parameter segEgbThresholdII. +* This parameter is used in the third stage +* mentioned above. It serves the same purpose as segEgbThresholdI. +* The segmentation result tends to have more regions remained if +* this value is large and vice versa. +*/ +CV_WRAP virtual void setSegEgbThresholdII(float c) = 0; +CV_WRAP virtual float getSegEgbThresholdII() = 0; + + +/** @brief: set and get the parameter minRegionSizeII. +* This parameter is used in the third stage +* mentioned above. It serves the same purpose as minRegionSizeI +*/ +CV_WRAP virtual void setMinRegionSizeII(int n) = 0; +CV_WRAP virtual int getMinRegionSizeII() = 0; + + +/** @brief: set and get the parameter spatialWeight. +* This parameter is used in the first stage +* mentioned above(the SLIC stage). It describes how important is the role +* of position when calculating the distance between each pixel and it's +* center. The exact formula to calculate the distance is +* \f$colorDistance + spatialWeight \times spatialDistance\f$. +* The segmentation result tends to have more local consistency +* if this value is larger. +*/ +CV_WRAP virtual void setSpatialWeight(float w) = 0; +CV_WRAP virtual float getSpatialWeight() = 0; + + +/** @brief: set and get the parameter slicSpixelSize. +* This parameter is used in the first stage mentioned +* above(the SLIC stage). It describes the size of each +* superpixel when initializing SLIC. Every superpixel +* approximately has \f$slicSpixelSize \times slicSpixelSize\f$ +* pixels in the beginning. +*/ +CV_WRAP virtual void setSlicSpixelSize(int n) = 0; +CV_WRAP virtual int getSlicSpixelSize() = 0; + + +/** @brief: set and get the parameter numSlicIter. +* This parameter is used in the first stage. It +* describes how many iteration to perform when executing SLIC. +*/ +CV_WRAP virtual void setNumSlicIter(int n) = 0; +CV_WRAP virtual int getNumSlicIter() = 0; + +/** @brief do segmentation gpu +* @param src: the input image +* @param ifDraw: if draw the image in the returned Mat. if this parameter is false, +* then the content of the returned Mat is a matrix of index, describing the region +* each pixel belongs to. And it's data type is CV_16U. If this parameter is true, +* then the returned Mat is a segmented picture, and color of each region is the +* average color of all pixels in that region. And it's data type is the same as +* the input image +*/ +CV_WRAP virtual Mat performSegmentGpu(InputArray src, bool ifDraw = true) = 0; + +/** @brief do segmentation with cpu +* This method is only implemented for reference. +* It is highly NOT recommanded to use it. +*/ +CV_WRAP virtual Mat performSegmentCpu(InputArray src, bool ifDraw = true) = 0; + +/** @brief: create a hfs object +* @param height: the height of the input image +* @param width: the width of the input image +* @param segEgbThresholdI: parameter segEgbThresholdI +* @param minRegionSizeI: parameter minRegionSizeI +* @param segEgbThresholdII: parameter segEgbThresholdII +* @param minRegionSizeII: parameter minRegionSizeII +* @param spatialWeight: parameter spatialWeight +* @param slicSpixelSize: parameter slicSpixelSize +* @param numSlicIter: parameter numSlicIter +*/ +CV_WRAP static Ptr create(int height, int width, + float segEgbThresholdI = 0.08f, int minRegionSizeI = 100, + float segEgbThresholdII = 0.28f, int minRegionSizeII = 200, + float spatialWeight = 0.6f, int slicSpixelSize = 8, int numSlicIter = 5); + +}; + +//! @} + +}} // namespace cv { namespace hfs { diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f109640414903969010d5d21f01d3839b24a81f2 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui.hpp @@ -0,0 +1,842 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HIGHGUI_HPP +#define OPENCV_HIGHGUI_HPP + +#include "opencv2/core.hpp" +#ifdef HAVE_OPENCV_IMGCODECS +#include "opencv2/imgcodecs.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOIO +#include "opencv2/videoio.hpp" +#endif + +/** +@defgroup highgui High-level GUI + +While OpenCV was designed for use in full-scale applications and can be used within functionally +rich UI frameworks (such as Qt\*, WinForms\*, or Cocoa\*) or without any UI at all, sometimes there +it is required to try functionality quickly and visualize the results. This is what the HighGUI +module has been designed for. + +It provides easy interface to: + +- Create and manipulate windows that can display images and "remember" their content (no need to + handle repaint events from OS). +- Add trackbars to the windows, handle simple mouse events as well as keyboard commands. + +@{ + @defgroup highgui_opengl OpenGL support + @defgroup highgui_qt Qt New Functions + + ![image](pics/qtgui.png) + + This figure explains new functionality implemented with Qt\* GUI. The new GUI provides a statusbar, + a toolbar, and a control panel. The control panel can have trackbars and buttonbars attached to it. + If you cannot see the control panel, press Ctrl+P or right-click any Qt window and select **Display + properties window**. + + - To attach a trackbar, the window name parameter must be NULL. + + - To attach a buttonbar, a button must be created. If the last bar attached to the control panel + is a buttonbar, the new button is added to the right of the last button. If the last bar + attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is + created. Then, a new button is attached to it. + + See below the example used to generate the figure: + @code + int main(int argc, char *argv[]) + { + + int value = 50; + int value2 = 0; + + + namedWindow("main1",WINDOW_NORMAL); + namedWindow("main2",WINDOW_AUTOSIZE | CV_GUI_NORMAL); + createTrackbar( "track1", "main1", &value, 255, NULL); + + String nameb1 = "button1"; + String nameb2 = "button2"; + + createButton(nameb1,callbackButton,&nameb1,QT_CHECKBOX,1); + createButton(nameb2,callbackButton,NULL,QT_CHECKBOX,0); + createTrackbar( "track2", NULL, &value2, 255, NULL); + createButton("button5",callbackButton1,NULL,QT_RADIOBOX,0); + createButton("button6",callbackButton2,NULL,QT_RADIOBOX,1); + + setMouseCallback( "main2",on_mouse,NULL ); + + Mat img1 = imread("files/flower.jpg"); + VideoCapture video; + video.open("files/hockey.avi"); + + Mat img2,img3; + + while( waitKey(33) != 27 ) + { + img1.convertTo(img2,-1,1,value); + video >> img3; + + imshow("main1",img2); + imshow("main2",img3); + } + + destroyAllWindows(); + + return 0; + } + @endcode + + + @defgroup highgui_winrt WinRT support + + This figure explains new functionality implemented with WinRT GUI. The new GUI provides an Image control, + and a slider panel. Slider panel holds trackbars attached to it. + + Sliders are attached below the image control. Every new slider is added below the previous one. + + See below the example used to generate the figure: + @code + void sample_app::MainPage::ShowWindow() + { + static cv::String windowName("sample"); + cv::winrt_initContainer(this->cvContainer); + cv::namedWindow(windowName); // not required + + cv::Mat image = cv::imread("Assets/sample.jpg"); + cv::Mat converted = cv::Mat(image.rows, image.cols, CV_8UC4); + cv::cvtColor(image, converted, COLOR_BGR2BGRA); + cv::imshow(windowName, converted); // this will create window if it hasn't been created before + + int state = 42; + cv::TrackbarCallback callback = [](int pos, void* userdata) + { + if (pos == 0) { + cv::destroyWindow(windowName); + } + }; + cv::TrackbarCallback callbackTwin = [](int pos, void* userdata) + { + if (pos >= 70) { + cv::destroyAllWindows(); + } + }; + cv::createTrackbar("Sample trackbar", windowName, &state, 100, callback); + cv::createTrackbar("Twin brother", windowName, &state, 100, callbackTwin); + } + @endcode + + @defgroup highgui_c C API +@} +*/ + +///////////////////////// graphical user interface ////////////////////////// +namespace cv +{ + +//! @addtogroup highgui +//! @{ + +//! Flags for cv::namedWindow +enum WindowFlags { + WINDOW_NORMAL = 0x00000000, //!< the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size. + WINDOW_AUTOSIZE = 0x00000001, //!< the user cannot resize the window, the size is constrainted by the image displayed. + WINDOW_OPENGL = 0x00001000, //!< window with opengl support. + + WINDOW_FULLSCREEN = 1, //!< change the window to fullscreen. + WINDOW_FREERATIO = 0x00000100, //!< the image expends as much as it can (no ratio constraint). + WINDOW_KEEPRATIO = 0x00000000, //!< the ratio of the image is respected. + WINDOW_GUI_EXPANDED=0x00000000, //!< status bar and tool bar + WINDOW_GUI_NORMAL = 0x00000010, //!< old fashious way + }; + +//! Flags for cv::setWindowProperty / cv::getWindowProperty +enum WindowPropertyFlags { + WND_PROP_FULLSCREEN = 0, //!< fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN). + WND_PROP_AUTOSIZE = 1, //!< autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE). + WND_PROP_ASPECT_RATIO = 2, //!< window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO). + WND_PROP_OPENGL = 3, //!< opengl support. + WND_PROP_VISIBLE = 4, //!< checks whether the window exists and is visible + WND_PROP_TOPMOST = 5 //!< property to toggle normal window being topmost or not + }; + +//! Mouse Events see cv::MouseCallback +enum MouseEventTypes { + EVENT_MOUSEMOVE = 0, //!< indicates that the mouse pointer has moved over the window. + EVENT_LBUTTONDOWN = 1, //!< indicates that the left mouse button is pressed. + EVENT_RBUTTONDOWN = 2, //!< indicates that the right mouse button is pressed. + EVENT_MBUTTONDOWN = 3, //!< indicates that the middle mouse button is pressed. + EVENT_LBUTTONUP = 4, //!< indicates that left mouse button is released. + EVENT_RBUTTONUP = 5, //!< indicates that right mouse button is released. + EVENT_MBUTTONUP = 6, //!< indicates that middle mouse button is released. + EVENT_LBUTTONDBLCLK = 7, //!< indicates that left mouse button is double clicked. + EVENT_RBUTTONDBLCLK = 8, //!< indicates that right mouse button is double clicked. + EVENT_MBUTTONDBLCLK = 9, //!< indicates that middle mouse button is double clicked. + EVENT_MOUSEWHEEL = 10,//!< positive and negative values mean forward and backward scrolling, respectively. + EVENT_MOUSEHWHEEL = 11 //!< positive and negative values mean right and left scrolling, respectively. + }; + +//! Mouse Event Flags see cv::MouseCallback +enum MouseEventFlags { + EVENT_FLAG_LBUTTON = 1, //!< indicates that the left mouse button is down. + EVENT_FLAG_RBUTTON = 2, //!< indicates that the right mouse button is down. + EVENT_FLAG_MBUTTON = 4, //!< indicates that the middle mouse button is down. + EVENT_FLAG_CTRLKEY = 8, //!< indicates that CTRL Key is pressed. + EVENT_FLAG_SHIFTKEY = 16,//!< indicates that SHIFT Key is pressed. + EVENT_FLAG_ALTKEY = 32 //!< indicates that ALT Key is pressed. + }; + +//! Qt font weight +enum QtFontWeights { + QT_FONT_LIGHT = 25, //!< Weight of 25 + QT_FONT_NORMAL = 50, //!< Weight of 50 + QT_FONT_DEMIBOLD = 63, //!< Weight of 63 + QT_FONT_BOLD = 75, //!< Weight of 75 + QT_FONT_BLACK = 87 //!< Weight of 87 + }; + +//! Qt font style +enum QtFontStyles { + QT_STYLE_NORMAL = 0, //!< Normal font. + QT_STYLE_ITALIC = 1, //!< Italic font. + QT_STYLE_OBLIQUE = 2 //!< Oblique font. + }; + +//! Qt "button" type +enum QtButtonTypes { + QT_PUSH_BUTTON = 0, //!< Push button. + QT_CHECKBOX = 1, //!< Checkbox button. + QT_RADIOBOX = 2, //!< Radiobox button. + QT_NEW_BUTTONBAR = 1024 //!< Button should create a new buttonbar + }; + +/** @brief Callback function for mouse events. see cv::setMouseCallback +@param event one of the cv::MouseEventTypes constants. +@param x The x-coordinate of the mouse event. +@param y The y-coordinate of the mouse event. +@param flags one of the cv::MouseEventFlags constants. +@param userdata The optional parameter. + */ +typedef void (*MouseCallback)(int event, int x, int y, int flags, void* userdata); + +/** @brief Callback function for Trackbar see cv::createTrackbar +@param pos current position of the specified trackbar. +@param userdata The optional parameter. + */ +typedef void (*TrackbarCallback)(int pos, void* userdata); + +/** @brief Callback function defined to be called every frame. See cv::setOpenGlDrawCallback +@param userdata The optional parameter. + */ +typedef void (*OpenGlDrawCallback)(void* userdata); + +/** @brief Callback function for a button created by cv::createButton +@param state current state of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button. +@param userdata The optional parameter. + */ +typedef void (*ButtonCallback)(int state, void* userdata); + +/** @brief Creates a window. + +The function namedWindow creates a window that can be used as a placeholder for images and +trackbars. Created windows are referred to by their names. + +If a window with the same name already exists, the function does nothing. + +You can call cv::destroyWindow or cv::destroyAllWindows to close the window and de-allocate any associated +memory usage. For a simple program, you do not really have to call these functions because all the +resources and windows of the application are closed automatically by the operating system upon exit. + +@note + +Qt backend supports additional flags: + - **WINDOW_NORMAL or WINDOW_AUTOSIZE:** WINDOW_NORMAL enables you to resize the + window, whereas WINDOW_AUTOSIZE adjusts automatically the window size to fit the + displayed image (see imshow ), and you cannot change the window size manually. + - **WINDOW_FREERATIO or WINDOW_KEEPRATIO:** WINDOW_FREERATIO adjusts the image + with no respect to its ratio, whereas WINDOW_KEEPRATIO keeps the image ratio. + - **WINDOW_GUI_NORMAL or WINDOW_GUI_EXPANDED:** WINDOW_GUI_NORMAL is the old way to draw the window + without statusbar and toolbar, whereas WINDOW_GUI_EXPANDED is a new enhanced GUI. +By default, flags == WINDOW_AUTOSIZE | WINDOW_KEEPRATIO | WINDOW_GUI_EXPANDED + +@param winname Name of the window in the window caption that may be used as a window identifier. +@param flags Flags of the window. The supported flags are: (cv::WindowFlags) + */ +CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE); + +/** @brief Destroys the specified window. + +The function destroyWindow destroys the window with the given name. + +@param winname Name of the window to be destroyed. + */ +CV_EXPORTS_W void destroyWindow(const String& winname); + +/** @brief Destroys all of the HighGUI windows. + +The function destroyAllWindows destroys all of the opened HighGUI windows. + */ +CV_EXPORTS_W void destroyAllWindows(); + +CV_EXPORTS_W int startWindowThread(); + +/** @brief Similar to #waitKey, but returns full key code. + +@note + +Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc + +*/ +CV_EXPORTS_W int waitKeyEx(int delay = 0); + +/** @brief Waits for a pressed key. + +The function waitKey waits for a key event infinitely (when \f$\texttt{delay}\leq 0\f$ ) or for delay +milliseconds, when it is positive. Since the OS has a minimum time between switching threads, the +function will not wait exactly delay ms, it will wait at least delay ms, depending on what else is +running on your computer at that time. It returns the code of the pressed key or -1 if no key was +pressed before the specified time had elapsed. + +@note + +This function is the only method in HighGUI that can fetch and handle events, so it needs to be +called periodically for normal event processing unless HighGUI is used within an environment that +takes care of event processing. + +@note + +The function only works if there is at least one HighGUI window created and the window is active. +If there are several HighGUI windows, any of them can be active. + +@param delay Delay in milliseconds. 0 is the special value that means "forever". + */ +CV_EXPORTS_W int waitKey(int delay = 0); + +/** @brief Displays an image in the specified window. + +The function imshow displays an image in the specified window. If the window was created with the +cv::WINDOW_AUTOSIZE flag, the image is shown with its original size, however it is still limited by the screen resolution. +Otherwise, the image is scaled to fit the window. The function may scale the image, depending on its depth: + +- If the image is 8-bit unsigned, it is displayed as is. +- If the image is 16-bit unsigned or 32-bit integer, the pixels are divided by 256. That is, the + value range [0,255\*256] is mapped to [0,255]. +- If the image is 32-bit or 64-bit floating-point, the pixel values are multiplied by 255. That is, the + value range [0,1] is mapped to [0,255]. + +If window was created with OpenGL support, cv::imshow also support ogl::Buffer , ogl::Texture2D and +cuda::GpuMat as input. + +If the window was not created before this function, it is assumed creating a window with cv::WINDOW_AUTOSIZE. + +If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow. + +@note This function should be followed by cv::waitKey function which displays the image for specified +milliseconds. Otherwise, it won't display the image. For example, **waitKey(0)** will display the window +infinitely until any keypress (it is suitable for image display). **waitKey(25)** will display a frame +for 25 ms, after which display will be automatically closed. (If you put it in a loop to read +videos, it will display the video frame-by-frame) + +@note + +[__Windows Backend Only__] Pressing Ctrl+C will copy the image to the clipboard. + +[__Windows Backend Only__] Pressing Ctrl+S will show a dialog to save the image. + +@param winname Name of the window. +@param mat Image to be shown. + */ +CV_EXPORTS_W void imshow(const String& winname, InputArray mat); + +/** @brief Resizes window to the specified size + +@note + +- The specified window size is for the image area. Toolbars are not counted. +- Only windows created without cv::WINDOW_AUTOSIZE flag can be resized. + +@param winname Window name. +@param width The new window width. +@param height The new window height. + */ +CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height); + +/** @overload +@param winname Window name. +@param size The new window size. +*/ +CV_EXPORTS_W void resizeWindow(const String& winname, const cv::Size& size); + +/** @brief Moves window to the specified position + +@param winname Name of the window. +@param x The new x-coordinate of the window. +@param y The new y-coordinate of the window. + */ +CV_EXPORTS_W void moveWindow(const String& winname, int x, int y); + +/** @brief Changes parameters of a window dynamically. + +The function setWindowProperty enables changing properties of a window. + +@param winname Name of the window. +@param prop_id Window property to edit. The supported operation flags are: (cv::WindowPropertyFlags) +@param prop_value New value of the window property. The supported flags are: (cv::WindowFlags) + */ +CV_EXPORTS_W void setWindowProperty(const String& winname, int prop_id, double prop_value); + +/** @brief Updates window title +@param winname Name of the window. +@param title New title. +*/ +CV_EXPORTS_W void setWindowTitle(const String& winname, const String& title); + +/** @brief Provides parameters of a window. + +The function getWindowProperty returns properties of a window. + +@param winname Name of the window. +@param prop_id Window property to retrieve. The following operation flags are available: (cv::WindowPropertyFlags) + +@sa setWindowProperty + */ +CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id); + +/** @brief Provides rectangle of image in the window. + +The function getWindowImageRect returns the client screen coordinates, width and height of the image rendering area. + +@param winname Name of the window. + +@sa resizeWindow moveWindow + */ +CV_EXPORTS_W Rect getWindowImageRect(const String& winname); + +/** @example samples/cpp/create_mask.cpp +This program demonstrates using mouse events and how to make and use a mask image (black and white) . +*/ +/** @brief Sets mouse handler for the specified window + +@param winname Name of the window. +@param onMouse Callback function for mouse events. See OpenCV samples on how to specify and use the callback. +@param userdata The optional parameter passed to the callback. + */ +CV_EXPORTS void setMouseCallback(const String& winname, MouseCallback onMouse, void* userdata = 0); + +/** @brief Gets the mouse-wheel motion delta, when handling mouse-wheel events cv::EVENT_MOUSEWHEEL and +cv::EVENT_MOUSEHWHEEL. + +For regular mice with a scroll-wheel, delta will be a multiple of 120. The value 120 corresponds to +a one notch rotation of the wheel or the threshold for action to be taken and one such action should +occur for each delta. Some high-precision mice with higher-resolution freely-rotating wheels may +generate smaller values. + +For cv::EVENT_MOUSEWHEEL positive and negative values mean forward and backward scrolling, +respectively. For cv::EVENT_MOUSEHWHEEL, where available, positive and negative values mean right and +left scrolling, respectively. + +With the C API, the macro CV_GET_WHEEL_DELTA(flags) can be used alternatively. + +@note + +Mouse-wheel events are currently supported only on Windows. + +@param flags The mouse callback flags parameter. + */ +CV_EXPORTS int getMouseWheelDelta(int flags); + +/** @brief Selects ROI on the given image. +Function creates a window and allows user to select a ROI using mouse. +Controls: use `space` or `enter` to finish selection, use key `c` to cancel selection (function will return the zero cv::Rect). + +@param windowName name of the window where selection process will be shown. +@param img image to select a ROI. +@param showCrosshair if true crosshair of selection rectangle will be shown. +@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of +selection rectangle will correspont to the initial mouse position. +@return selected ROI or empty rect if selection canceled. + +@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). +After finish of work an empty callback will be set for the used window. + */ +CV_EXPORTS_W Rect selectROI(const String& windowName, InputArray img, bool showCrosshair = true, bool fromCenter = false); + +/** @overload + */ +CV_EXPORTS_W Rect selectROI(InputArray img, bool showCrosshair = true, bool fromCenter = false); + +/** @brief Selects ROIs on the given image. +Function creates a window and allows user to select a ROIs using mouse. +Controls: use `space` or `enter` to finish current selection and start a new one, +use `esc` to terminate multiple ROI selection process. + +@param windowName name of the window where selection process will be shown. +@param img image to select a ROI. +@param boundingBoxes selected ROIs. +@param showCrosshair if true crosshair of selection rectangle will be shown. +@param fromCenter if true center of selection will match initial mouse position. In opposite case a corner of +selection rectangle will correspont to the initial mouse position. + +@note The function sets it's own mouse callback for specified window using cv::setMouseCallback(windowName, ...). +After finish of work an empty callback will be set for the used window. + */ +CV_EXPORTS_W void selectROIs(const String& windowName, InputArray img, + CV_OUT std::vector& boundingBoxes, bool showCrosshair = true, bool fromCenter = false); + +/** @brief Creates a trackbar and attaches it to the specified window. + +The function createTrackbar creates a trackbar (a slider or range control) with the specified name +and range, assigns a variable value to be a position synchronized with the trackbar and specifies +the callback function onChange to be called on the trackbar position change. The created trackbar is +displayed in the specified window winname. + +@note + +[__Qt Backend Only__] winname can be empty if the trackbar should be attached to the +control panel. + +Clicking the label of each trackbar enables editing the trackbar values manually. + +@param trackbarname Name of the created trackbar. +@param winname Name of the window that will be used as a parent of the created trackbar. +@param value Optional pointer to an integer variable whose value reflects the position of the +slider. Upon creation, the slider position is defined by this variable. +@param count Maximal position of the slider. The minimal position is always 0. +@param onChange Pointer to the function to be called every time the slider changes position. This +function should be prototyped as void Foo(int,void\*); , where the first parameter is the trackbar +position and the second parameter is the user data (see the next parameter). If the callback is +the NULL pointer, no callbacks are called, but only value is updated. +@param userdata User data that is passed as is to the callback. It can be used to handle trackbar +events without using global variables. + */ +CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname, + int* value, int count, + TrackbarCallback onChange = 0, + void* userdata = 0); + +/** @brief Returns the trackbar position. + +The function returns the current position of the specified trackbar. + +@note + +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of the trackbar. + */ +CV_EXPORTS_W int getTrackbarPos(const String& trackbarname, const String& winname); + +/** @brief Sets the trackbar position. + +The function sets the position of the specified trackbar in the specified window. + +@note + +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of trackbar. +@param pos New position. + */ +CV_EXPORTS_W void setTrackbarPos(const String& trackbarname, const String& winname, int pos); + +/** @brief Sets the trackbar maximum position. + +The function sets the maximum position of the specified trackbar in the specified window. + +@note + +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of trackbar. +@param maxval New maximum position. + */ +CV_EXPORTS_W void setTrackbarMax(const String& trackbarname, const String& winname, int maxval); + +/** @brief Sets the trackbar minimum position. + +The function sets the minimum position of the specified trackbar in the specified window. + +@note + +[__Qt Backend Only__] winname can be empty if the trackbar is attached to the control +panel. + +@param trackbarname Name of the trackbar. +@param winname Name of the window that is the parent of trackbar. +@param minval New minimum position. + */ +CV_EXPORTS_W void setTrackbarMin(const String& trackbarname, const String& winname, int minval); + +//! @addtogroup highgui_opengl OpenGL support +//! @{ + +/** @brief Displays OpenGL 2D texture in the specified window. + +@param winname Name of the window. +@param tex OpenGL 2D texture data. + */ +CV_EXPORTS void imshow(const String& winname, const ogl::Texture2D& tex); + +/** @brief Sets a callback function to be called to draw on top of displayed image. + +The function setOpenGlDrawCallback can be used to draw 3D data on the window. See the example of +callback function below: +@code + void on_opengl(void* param) + { + glLoadIdentity(); + + glTranslated(0.0, 0.0, -1.0); + + glRotatef( 55, 1, 0, 0 ); + glRotatef( 45, 0, 1, 0 ); + glRotatef( 0, 0, 0, 1 ); + + static const int coords[6][4][3] = { + { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, + { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } }, + { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } }, + { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } }, + { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } }, + { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } + }; + + for (int i = 0; i < 6; ++i) { + glColor3ub( i*20, 100+i*10, i*42 ); + glBegin(GL_QUADS); + for (int j = 0; j < 4; ++j) { + glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]); + } + glEnd(); + } + } +@endcode + +@param winname Name of the window. +@param onOpenGlDraw Pointer to the function to be called every frame. This function should be +prototyped as void Foo(void\*) . +@param userdata Pointer passed to the callback function.(__Optional__) + */ +CV_EXPORTS void setOpenGlDrawCallback(const String& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0); + +/** @brief Sets the specified window as current OpenGL context. + +@param winname Name of the window. + */ +CV_EXPORTS void setOpenGlContext(const String& winname); + +/** @brief Force window to redraw its context and call draw callback ( See cv::setOpenGlDrawCallback ). + +@param winname Name of the window. + */ +CV_EXPORTS void updateWindow(const String& winname); + +//! @} highgui_opengl + +//! @addtogroup highgui_qt +//! @{ + +/** @brief QtFont available only for Qt. See cv::fontQt + */ +struct QtFont +{ + const char* nameFont; //!< Name of the font + Scalar color; //!< Color of the font. Scalar(blue_component, green_component, red_component[, alpha_component]) + int font_face; //!< See cv::QtFontStyles + const int* ascii; //!< font data and metrics + const int* greek; + const int* cyrillic; + float hscale, vscale; + float shear; //!< slope coefficient: 0 - normal, >0 - italic + int thickness; //!< See cv::QtFontWeights + float dx; //!< horizontal interval between letters + int line_type; //!< PointSize +}; + +/** @brief Creates the font to draw a text on an image. + +The function fontQt creates a cv::QtFont object. This cv::QtFont is not compatible with putText . + +A basic usage of this function is the following: : +@code + QtFont font = fontQt("Times"); + addText( img1, "Hello World !", Point(50,50), font); +@endcode + +@param nameFont Name of the font. The name should match the name of a system font (such as +*Times*). If the font is not found, a default one is used. +@param pointSize Size of the font. If not specified, equal zero or negative, the point size of the +font is set to a system-dependent default value. Generally, this is 12 points. +@param color Color of the font in BGRA where A = 255 is fully transparent. Use the macro CV_RGB +for simplicity. +@param weight Font weight. Available operation flags are : cv::QtFontWeights You can also specify a positive integer for better control. +@param style Font style. Available operation flags are : cv::QtFontStyles +@param spacing Spacing between characters. It can be negative or positive. + */ +CV_EXPORTS QtFont fontQt(const String& nameFont, int pointSize = -1, + Scalar color = Scalar::all(0), int weight = QT_FONT_NORMAL, + int style = QT_STYLE_NORMAL, int spacing = 0); + +/** @brief Draws a text on the image. + +The function addText draws *text* on the image *img* using a specific font *font* (see example cv::fontQt +) + +@param img 8-bit 3-channel image where the text should be drawn. +@param text Text to write on an image. +@param org Point(x,y) where the text should start on an image. +@param font Font to use to draw a text. + */ +CV_EXPORTS void addText( const Mat& img, const String& text, Point org, const QtFont& font); + +/** @brief Draws a text on the image. + +@param img 8-bit 3-channel image where the text should be drawn. +@param text Text to write on an image. +@param org Point(x,y) where the text should start on an image. +@param nameFont Name of the font. The name should match the name of a system font (such as +*Times*). If the font is not found, a default one is used. +@param pointSize Size of the font. If not specified, equal zero or negative, the point size of the +font is set to a system-dependent default value. Generally, this is 12 points. +@param color Color of the font in BGRA where A = 255 is fully transparent. +@param weight Font weight. Available operation flags are : cv::QtFontWeights You can also specify a positive integer for better control. +@param style Font style. Available operation flags are : cv::QtFontStyles +@param spacing Spacing between characters. It can be negative or positive. + */ +CV_EXPORTS_W void addText(const Mat& img, const String& text, Point org, const String& nameFont, int pointSize = -1, Scalar color = Scalar::all(0), + int weight = QT_FONT_NORMAL, int style = QT_STYLE_NORMAL, int spacing = 0); + +/** @brief Displays a text on a window image as an overlay for a specified duration. + +The function displayOverlay displays useful information/tips on top of the window for a certain +amount of time *delayms*. The function does not modify the image, displayed in the window, that is, +after the specified delay the original content of the window is restored. + +@param winname Name of the window. +@param text Overlay text to write on a window image. +@param delayms The period (in milliseconds), during which the overlay text is displayed. If this +function is called before the previous overlay text timed out, the timer is restarted and the text +is updated. If this value is zero, the text never disappears. + */ +CV_EXPORTS_W void displayOverlay(const String& winname, const String& text, int delayms = 0); + +/** @brief Displays a text on the window statusbar during the specified period of time. + +The function displayStatusBar displays useful information/tips on top of the window for a certain +amount of time *delayms* . This information is displayed on the window statusbar (the window must be +created with the CV_GUI_EXPANDED flags). + +@param winname Name of the window. +@param text Text to write on the window statusbar. +@param delayms Duration (in milliseconds) to display the text. If this function is called before +the previous text timed out, the timer is restarted and the text is updated. If this value is +zero, the text never disappears. + */ +CV_EXPORTS_W void displayStatusBar(const String& winname, const String& text, int delayms = 0); + +/** @brief Saves parameters of the specified window. + +The function saveWindowParameters saves size, location, flags, trackbars value, zoom and panning +location of the window windowName. + +@param windowName Name of the window. + */ +CV_EXPORTS void saveWindowParameters(const String& windowName); + +/** @brief Loads parameters of the specified window. + +The function loadWindowParameters loads size, location, flags, trackbars value, zoom and panning +location of the window windowName. + +@param windowName Name of the window. + */ +CV_EXPORTS void loadWindowParameters(const String& windowName); + +CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); + +CV_EXPORTS void stopLoop(); + +/** @brief Attaches a button to the control panel. + +The function createButton attaches a button to the control panel. Each button is added to a +buttonbar to the right of the last button. A new buttonbar is created if nothing was attached to the +control panel before, or if the last element attached to the control panel was a trackbar or if the +QT_NEW_BUTTONBAR flag is added to the type. + +See below various examples of the cv::createButton function call: : +@code + createButton("",callbackButton);//create a push button "button 0", that will call callbackButton. + createButton("button2",callbackButton,NULL,QT_CHECKBOX,0); + createButton("button3",callbackButton,&value); + createButton("button5",callbackButton1,NULL,QT_RADIOBOX); + createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON,1); + createButton("button6",callbackButton2,NULL,QT_PUSH_BUTTON|QT_NEW_BUTTONBAR);// create a push button in a new row +@endcode + +@param bar_name Name of the button. +@param on_change Pointer to the function to be called every time the button changes its state. +This function should be prototyped as void Foo(int state,\*void); . *state* is the current state +of the button. It could be -1 for a push button, 0 or 1 for a check/radio box button. +@param userdata Pointer passed to the callback function. +@param type Optional type of the button. Available types are: (cv::QtButtonTypes) +@param initial_button_state Default state of the button. Use for checkbox and radiobox. Its +value could be 0 or 1. (__Optional__) +*/ +CV_EXPORTS int createButton( const String& bar_name, ButtonCallback on_change, + void* userdata = 0, int type = QT_PUSH_BUTTON, + bool initial_button_state = false); + +//! @} highgui_qt + +//! @} highgui + +} // cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui/highgui.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui/highgui.hpp new file mode 100644 index 0000000000000000000000000000000000000000..160c9cf4af245e37dfc705aee5402d1cb365c46a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui/highgui.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/highgui.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui/highgui_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui/highgui_c.h new file mode 100644 index 0000000000000000000000000000000000000000..5d20b9501e75400669a97e76f5984c514452b6d4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/highgui/highgui_c.h @@ -0,0 +1,256 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_HIGHGUI_H +#define OPENCV_HIGHGUI_H + +#include "opencv2/core/core_c.h" +#include "opencv2/imgproc/imgproc_c.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** @addtogroup highgui_c + @{ + */ + +/****************************************************************************************\ +* Basic GUI functions * +\****************************************************************************************/ +//YV +//-----------New for Qt +/* For font */ +enum { CV_FONT_LIGHT = 25,//QFont::Light, + CV_FONT_NORMAL = 50,//QFont::Normal, + CV_FONT_DEMIBOLD = 63,//QFont::DemiBold, + CV_FONT_BOLD = 75,//QFont::Bold, + CV_FONT_BLACK = 87 //QFont::Black +}; + +enum { CV_STYLE_NORMAL = 0,//QFont::StyleNormal, + CV_STYLE_ITALIC = 1,//QFont::StyleItalic, + CV_STYLE_OBLIQUE = 2 //QFont::StyleOblique +}; +/* ---------*/ + +//for color cvScalar(blue_component, green_component, red_component[, alpha_component]) +//and alpha= 0 <-> 0xFF (not transparent <-> transparent) +CVAPI(CvFont) cvFontQt(const char* nameFont, int pointSize CV_DEFAULT(-1), CvScalar color CV_DEFAULT(cvScalarAll(0)), int weight CV_DEFAULT(CV_FONT_NORMAL), int style CV_DEFAULT(CV_STYLE_NORMAL), int spacing CV_DEFAULT(0)); + +CVAPI(void) cvAddText(const CvArr* img, const char* text, CvPoint org, CvFont *arg2); + +CVAPI(void) cvDisplayOverlay(const char* name, const char* text, int delayms CV_DEFAULT(0)); +CVAPI(void) cvDisplayStatusBar(const char* name, const char* text, int delayms CV_DEFAULT(0)); + +CVAPI(void) cvSaveWindowParameters(const char* name); +CVAPI(void) cvLoadWindowParameters(const char* name); +CVAPI(int) cvStartLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); +CVAPI(void) cvStopLoop( void ); + +typedef void (CV_CDECL *CvButtonCallback)(int state, void* userdata); +enum {CV_PUSH_BUTTON = 0, CV_CHECKBOX = 1, CV_RADIOBOX = 2}; +CVAPI(int) cvCreateButton( const char* button_name CV_DEFAULT(NULL),CvButtonCallback on_change CV_DEFAULT(NULL), void* userdata CV_DEFAULT(NULL) , int button_type CV_DEFAULT(CV_PUSH_BUTTON), int initial_button_state CV_DEFAULT(0)); +//---------------------- + + +/* this function is used to set some external parameters in case of X Window */ +CVAPI(int) cvInitSystem( int argc, char** argv ); + +CVAPI(int) cvStartWindowThread( void ); + +// --------- YV --------- +enum +{ + //These 3 flags are used by cvSet/GetWindowProperty + CV_WND_PROP_FULLSCREEN = 0, //to change/get window's fullscreen property + CV_WND_PROP_AUTOSIZE = 1, //to change/get window's autosize property + CV_WND_PROP_ASPECTRATIO= 2, //to change/get window's aspectratio property + CV_WND_PROP_OPENGL = 3, //to change/get window's opengl support + CV_WND_PROP_VISIBLE = 4, + + //These 2 flags are used by cvNamedWindow and cvSet/GetWindowProperty + CV_WINDOW_NORMAL = 0x00000000, //the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size + CV_WINDOW_AUTOSIZE = 0x00000001, //the user cannot resize the window, the size is constrainted by the image displayed + CV_WINDOW_OPENGL = 0x00001000, //window with opengl support + + //Those flags are only for Qt + CV_GUI_EXPANDED = 0x00000000, //status bar and tool bar + CV_GUI_NORMAL = 0x00000010, //old fashious way + + //These 3 flags are used by cvNamedWindow and cvSet/GetWindowProperty + CV_WINDOW_FULLSCREEN = 1,//change the window to fullscreen + CV_WINDOW_FREERATIO = 0x00000100,//the image expends as much as it can (no ratio constraint) + CV_WINDOW_KEEPRATIO = 0x00000000//the ration image is respected. +}; + +/* create window */ +CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) ); + +/* Set and Get Property of the window */ +CVAPI(void) cvSetWindowProperty(const char* name, int prop_id, double prop_value); +CVAPI(double) cvGetWindowProperty(const char* name, int prop_id); + +#ifdef __cplusplus // FIXIT remove in OpenCV 4.0 +/* Get window image rectangle coordinates, width and height */ +CVAPI(cv::Rect)cvGetWindowImageRect(const char* name); +#endif + +/* display image within window (highgui windows remember their content) */ +CVAPI(void) cvShowImage( const char* name, const CvArr* image ); + +/* resize/move window */ +CVAPI(void) cvResizeWindow( const char* name, int width, int height ); +CVAPI(void) cvMoveWindow( const char* name, int x, int y ); + + +/* destroy window and all the trackers associated with it */ +CVAPI(void) cvDestroyWindow( const char* name ); + +CVAPI(void) cvDestroyAllWindows(void); + +/* get native window handle (HWND in case of Win32 and Widget in case of X Window) */ +CVAPI(void*) cvGetWindowHandle( const char* name ); + +/* get name of highgui window given its native handle */ +CVAPI(const char*) cvGetWindowName( void* window_handle ); + + +typedef void (CV_CDECL *CvTrackbarCallback)(int pos); + +/* create trackbar and display it on top of given window, set callback */ +CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name, + int* value, int count, CvTrackbarCallback on_change CV_DEFAULT(NULL)); + +typedef void (CV_CDECL *CvTrackbarCallback2)(int pos, void* userdata); + +CVAPI(int) cvCreateTrackbar2( const char* trackbar_name, const char* window_name, + int* value, int count, CvTrackbarCallback2 on_change, + void* userdata CV_DEFAULT(0)); + +/* retrieve or set trackbar position */ +CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name ); +CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos ); +CVAPI(void) cvSetTrackbarMax(const char* trackbar_name, const char* window_name, int maxval); +CVAPI(void) cvSetTrackbarMin(const char* trackbar_name, const char* window_name, int minval); + +enum +{ + CV_EVENT_MOUSEMOVE =0, + CV_EVENT_LBUTTONDOWN =1, + CV_EVENT_RBUTTONDOWN =2, + CV_EVENT_MBUTTONDOWN =3, + CV_EVENT_LBUTTONUP =4, + CV_EVENT_RBUTTONUP =5, + CV_EVENT_MBUTTONUP =6, + CV_EVENT_LBUTTONDBLCLK =7, + CV_EVENT_RBUTTONDBLCLK =8, + CV_EVENT_MBUTTONDBLCLK =9, + CV_EVENT_MOUSEWHEEL =10, + CV_EVENT_MOUSEHWHEEL =11 +}; + +enum +{ + CV_EVENT_FLAG_LBUTTON =1, + CV_EVENT_FLAG_RBUTTON =2, + CV_EVENT_FLAG_MBUTTON =4, + CV_EVENT_FLAG_CTRLKEY =8, + CV_EVENT_FLAG_SHIFTKEY =16, + CV_EVENT_FLAG_ALTKEY =32 +}; + + +#define CV_GET_WHEEL_DELTA(flags) ((short)((flags >> 16) & 0xffff)) // upper 16 bits + +typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param); + +/* assign callback for mouse events */ +CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse, + void* param CV_DEFAULT(NULL)); + +/* wait for key event infinitely (delay<=0) or for "delay" milliseconds */ +CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0)); + +// OpenGL support + +typedef void (CV_CDECL *CvOpenGlDrawCallback)(void* userdata); +CVAPI(void) cvSetOpenGlDrawCallback(const char* window_name, CvOpenGlDrawCallback callback, void* userdata CV_DEFAULT(NULL)); + +CVAPI(void) cvSetOpenGlContext(const char* window_name); +CVAPI(void) cvUpdateWindow(const char* window_name); + + +/****************************************************************************************\ + +* Obsolete functions/synonyms * +\****************************************************************************************/ + +#define cvAddSearchPath(path) +#define cvvInitSystem cvInitSystem +#define cvvNamedWindow cvNamedWindow +#define cvvShowImage cvShowImage +#define cvvResizeWindow cvResizeWindow +#define cvvDestroyWindow cvDestroyWindow +#define cvvCreateTrackbar cvCreateTrackbar +#define cvvAddSearchPath cvAddSearchPath +#define cvvWaitKey(name) cvWaitKey(0) +#define cvvWaitKeyEx(name,delay) cvWaitKey(delay) +#define HG_AUTOSIZE CV_WINDOW_AUTOSIZE +#define set_preprocess_func cvSetPreprocessFuncWin32 +#define set_postprocess_func cvSetPostprocessFuncWin32 + +#if defined _WIN32 + +CVAPI(void) cvSetPreprocessFuncWin32_(const void* callback); +CVAPI(void) cvSetPostprocessFuncWin32_(const void* callback); +#define cvSetPreprocessFuncWin32(callback) cvSetPreprocessFuncWin32_((const void*)(callback)) +#define cvSetPostprocessFuncWin32(callback) cvSetPostprocessFuncWin32_((const void*)(callback)) + +#endif + +/** @} highgui_c */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5e7a928462e756f8dce2c16e17eaaac831da493f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash.hpp @@ -0,0 +1,78 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMG_HASH_H +#define OPENCV_IMG_HASH_H + +#include "opencv2/img_hash/average_hash.hpp" +#include "opencv2/img_hash/block_mean_hash.hpp" +#include "opencv2/img_hash/color_moment_hash.hpp" +#include "opencv2/img_hash/marr_hildreth_hash.hpp" +#include "opencv2/img_hash/phash.hpp" +#include "opencv2/img_hash/radial_variance_hash.hpp" + +/** +@defgroup img_hash The module brings implementations of different image hashing algorithms. + +Provide algorithms to extract the hash of images and fast way to figure out most similar images in +huge data set. + +Namespace for all functions is cv::img_hash. + +### Supported Algorithms + +- Average hash (also called Different hash) +- PHash (also called Perceptual hash) +- Marr Hildreth Hash +- Radial Variance Hash +- Block Mean Hash (modes 0 and 1) +- Color Moment Hash (this is the one and only hash algorithm resist to rotation attack(-90~90 degree)) + +You can study more about image hashing from following paper and websites: + +- "Implementation and benchmarking of perceptual image hash functions" @cite zauner2010implementation +- "Looks Like It" @cite lookslikeit + +### Code Example + +@include samples/hash_samples.cpp + +### Performance under different attacks + +![Performance chart](img_hash/doc/attack_performance.JPG) + +### Speed comparison with PHash library (100 images from ukbench) + +![Hash Computation chart](img_hash/doc/hash_computation_chart.JPG) +![Hash comparison chart](img_hash/doc/hash_comparison_chart.JPG) + +As you can see, hash computation speed of img_hash module outperform [PHash library](http://www.phash.org/) a lot. + +PS : I do not list out the comparison of Average hash, PHash and Color Moment hash, because I cannot +find them in PHash. + +### Motivation + +Collects useful image hash algorithms into opencv, so we do not need to rewrite them by ourselves +again and again or rely on another 3rd party library(ex : PHash library). BOVW or correlation +matching are good and robust, but they are very slow compare with image hash, if you need to deal +with large scale CBIR(content based image retrieval) problem, image hash is a more reasonable +solution. + +### More info + +You can learn more about img_hash modules from following links, these links show you how to find +similar image from ukbench dataset, provide thorough benchmark of different attacks(contrast, blur, +noise(gaussion,pepper and salt), jpeg compression, watermark, resize). + +* [Introduction to image hash module of opencv](http://qtandopencv.blogspot.my/2016/06/introduction-to-image-hash-module-of.html) +* [Speed up image hashing of opencv(img_hash) and introduce color moment hash](http://qtandopencv.blogspot.my/2016/06/speed-up-image-hashing-of-opencvimghash.html) + +### Contributors + +Tham Ngap Wei, thamngapwei@gmail.com + +*/ + +#endif // OPENCV_IMG_HASH_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/average_hash.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/average_hash.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1204441c3a5f5ba2034aa10ff37e4d010eb872e9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/average_hash.hpp @@ -0,0 +1,39 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_AVERAGE_HASH_HPP +#define OPENCV_AVERAGE_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief Computes average hash value of the input image + +This is a fast image hashing algorithm, but only work on simple case. For more details, please +refer to @cite lookslikeit +*/ +class CV_EXPORTS_W AverageHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr create(); +protected: + AverageHash() {} +}; + +/** @brief Calculates img_hash::AverageHash in one call +@param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. +@param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U +*/ +CV_EXPORTS_W void averageHash(cv::InputArray inputArr, cv::OutputArray outputArr); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_AVERAGE_HASH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/block_mean_hash.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/block_mean_hash.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dbf2a5f861217586eff20e87db876a7aca20adb0 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/block_mean_hash.hpp @@ -0,0 +1,52 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_BLOCK_MEAN_HASH_HPP +#define OPENCV_BLOCK_MEAN_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +enum BlockMeanHashMode +{ + BLOCK_MEAN_HASH_MODE_0 = 0, //!< use fewer block and generate 16*16/8 uchar hash value + BLOCK_MEAN_HASH_MODE_1 = 1, //!< use block blocks(step sizes/2), generate 31*31/8 + 1 uchar hash value +}; + +/** @brief Image hash based on block mean. + +See @cite zauner2010implementation for details. +*/ +class CV_EXPORTS_W BlockMeanHash : public ImgHashBase +{ +public: + /** @brief Create BlockMeanHash object + @param mode the mode + */ + CV_WRAP void setMode(int mode); + CV_WRAP std::vector getMean() const; + CV_WRAP static Ptr create(int mode = BLOCK_MEAN_HASH_MODE_0); +protected: + BlockMeanHash() {} +}; + +/** @brief Computes block mean hash of the input image + @param inputArr input image want to compute hash value, type should be CV_8UC4, CV_8UC3 or CV_8UC1. + @param outputArr Hash value of input, it will contain 16 hex decimal number, return type is CV_8U + @param mode the mode +*/ +CV_EXPORTS_W void blockMeanHash(cv::InputArray inputArr, + cv::OutputArray outputArr, + int mode = BLOCK_MEAN_HASH_MODE_0); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_BLOCK_MEAN_HASH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/color_moment_hash.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/color_moment_hash.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d0a820bd9fcbc0ce38853a4f5c7e40d05829a23f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/color_moment_hash.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_COLOR_MOMENT_HASH_HPP +#define OPENCV_COLOR_MOMENT_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief Image hash based on color moments. + +See @cite tang2012perceptual for details. +*/ +class CV_EXPORTS_W ColorMomentHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr create(); +protected: + ColorMomentHash() {} +}; + +/** @brief Computes color moment hash of the input, the algorithm + is come from the paper "Perceptual Hashing for Color Images + Using Invariant Moments" + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3 or CV_8UC1. + @param outputArr 42 hash values with type CV_64F(double) + */ +CV_EXPORTS_W void colorMomentHash(cv::InputArray inputArr, cv::OutputArray outputArr); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_COLOR_MOMENT_HASH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/img_hash_base.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/img_hash_base.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f0cc451ffdc8369a776ed1e22e2b6d00cdd8bd3c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/img_hash_base.hpp @@ -0,0 +1,46 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMG_HASH_BASE_HPP +#define OPENCV_IMG_HASH_BASE_HPP + +#include "opencv2/core.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief The base class for image hash algorithms + */ +class CV_EXPORTS_W ImgHashBase : public Algorithm +{ +public: + class ImgHashImpl; + + ~ImgHashBase(); + /** @brief Computes hash of the input image + @param inputArr input image want to compute hash value + @param outputArr hash of the image + */ + CV_WRAP void compute(cv::InputArray inputArr, cv::OutputArray outputArr); + /** @brief Compare the hash value between inOne and inTwo + @param hashOne Hash value one + @param hashTwo Hash value two + @return value indicate similarity between inOne and inTwo, the meaning + of the value vary from algorithms to algorithms + */ + CV_WRAP double compare(cv::InputArray hashOne, cv::InputArray hashTwo) const; +protected: + ImgHashBase(); +protected: + Ptr pImpl; +}; + +//! @} + +} } // cv::img_hash:: + +#endif // OPENCV_IMG_HASH_BASE_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/marr_hildreth_hash.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/marr_hildreth_hash.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a9b04f9f9cdc3a6ca97d0e0c2d0e3bcc904a8f96 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/marr_hildreth_hash.hpp @@ -0,0 +1,64 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_MARR_HILDRETH_HASH_HPP +#define OPENCV_MARR_HILDRETH_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief Marr-Hildreth Operator Based Hash, slowest but more discriminative. + +See @cite zauner2010implementation for details. +*/ +class CV_EXPORTS_W MarrHildrethHash : public ImgHashBase +{ +public: + /** + * @brief self explain + */ + CV_WRAP float getAlpha() const; + + /** + * @brief self explain + */ + CV_WRAP float getScale() const; + + /** @brief Set Mh kernel parameters + @param alpha int scale factor for marr wavelet (default=2). + @param scale int level of scale factor (default = 1) + */ + CV_WRAP void setKernelParam(float alpha, float scale); + + /** + @param alpha int scale factor for marr wavelet (default=2). + @param scale int level of scale factor (default = 1) + */ + CV_WRAP static Ptr create(float alpha = 2.0f, float scale = 1.0f); +protected: + MarrHildrethHash() {} +}; + +/** @brief Computes average hash value of the input image + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3, CV_8UC1. + @param outputArr Hash value of input, it will contain 16 hex + decimal number, return type is CV_8U + @param alpha int scale factor for marr wavelet (default=2). + @param scale int level of scale factor (default = 1) +*/ +CV_EXPORTS_W void marrHildrethHash(cv::InputArray inputArr, + cv::OutputArray outputArr, + float alpha = 2.0f, float scale = 1.0f); + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_MARR_HILDRETH_HASH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/phash.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/phash.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d57cd6f3a8f837cf1d2090a495a317ad1aa41f40 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/phash.hpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_PHASH_HPP +#define OPENCV_PHASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + +/** @brief pHash + +Slower than average_hash, but tolerant of minor modifications + +This algorithm can combat more variation than averageHash, for more details please refer to @cite lookslikeit +*/ +class CV_EXPORTS_W PHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr create(); +protected: + PHash() {} +}; + +/** @brief Computes pHash value of the input image + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3, CV_8UC1. + @param outputArr Hash value of input, it will contain 8 uchar value +*/ +CV_EXPORTS_W void pHash(cv::InputArray inputArr, cv::OutputArray outputArr); + +//! @} + +} } // cv::img_hash:: + +#endif // OPENCV_PHASH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/radial_variance_hash.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/radial_variance_hash.hpp new file mode 100644 index 0000000000000000000000000000000000000000..455f2850ebd789a233caeca86135d4283b1c8ebe --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/img_hash/radial_variance_hash.hpp @@ -0,0 +1,58 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_RADIAL_VARIANCE_HASH_HPP +#define OPENCV_RADIAL_VARIANCE_HASH_HPP + +#include "img_hash_base.hpp" + +namespace cv { +namespace img_hash { + +//! @addtogroup img_hash +//! @{ + + +/** @brief Image hash based on Radon transform. + +See @cite tang2012perceptual for details. +*/ +class CV_EXPORTS_W RadialVarianceHash : public ImgHashBase +{ +public: + CV_WRAP static Ptr create(double sigma = 1, int numOfAngleLine = 180); + + CV_WRAP int getNumOfAngleLine() const; + CV_WRAP double getSigma() const; + + CV_WRAP void setNumOfAngleLine(int value); + CV_WRAP void setSigma(double value); + + // internals + std::vector getFeatures(); + cv::Mat getHash(); + Mat getPixPerLine(Mat const &input); + Mat getProjection(); +protected: + RadialVarianceHash() {} +}; + +/** @brief Computes radial variance hash of the input image + @param inputArr input image want to compute hash value, + type should be CV_8UC4, CV_8UC3, CV_8UC1. + @param outputArr Hash value of input + @param sigma Gaussian kernel standard deviation + @param numOfAngleLine The number of angles to consider + */ +CV_EXPORTS_W void radialVarianceHash(cv::InputArray inputArr, + cv::OutputArray outputArr, + double sigma = 1, + int numOfAngleLine = 180); + + +//! @} + +}} // cv::img_hash:: + +#endif // OPENCV_RADIAL_VARIANCE_HASH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..143926b7ba2ec4d59ad0e83f35c2b8011765dd1c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs.hpp @@ -0,0 +1,277 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_IMGCODECS_HPP +#define OPENCV_IMGCODECS_HPP + +#include "opencv2/core.hpp" + +/** + @defgroup imgcodecs Image file reading and writing + @{ + @defgroup imgcodecs_c C API + @defgroup imgcodecs_ios iOS glue + @} +*/ + +//////////////////////////////// image codec //////////////////////////////// +namespace cv +{ + +//! @addtogroup imgcodecs +//! @{ + +//! Imread flags +enum ImreadModes { + IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). + IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion). + IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image. + IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. + IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format. + IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image. + IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2. + IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2. + IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4. + IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. + IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8. + IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. + IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag. + }; + +//! Imwrite flags +enum ImwriteFlags { + IMWRITE_JPEG_QUALITY = 1, //!< For JPEG, it can be a quality from 0 to 100 (the higher is the better). Default value is 95. + IMWRITE_JPEG_PROGRESSIVE = 2, //!< Enable JPEG features, 0 or 1, default is False. + IMWRITE_JPEG_OPTIMIZE = 3, //!< Enable JPEG features, 0 or 1, default is False. + IMWRITE_JPEG_RST_INTERVAL = 4, //!< JPEG restart interval, 0 - 65535, default is 0 - no restart. + IMWRITE_JPEG_LUMA_QUALITY = 5, //!< Separate luma quality level, 0 - 100, default is 0 - don't use. + IMWRITE_JPEG_CHROMA_QUALITY = 6, //!< Separate chroma quality level, 0 - 100, default is 0 - don't use. + IMWRITE_PNG_COMPRESSION = 16, //!< For PNG, it can be the compression level from 0 to 9. A higher value means a smaller size and longer compression time. If specified, strategy is changed to IMWRITE_PNG_STRATEGY_DEFAULT (Z_DEFAULT_STRATEGY). Default value is 1 (best speed setting). + IMWRITE_PNG_STRATEGY = 17, //!< One of cv::ImwritePNGFlags, default is IMWRITE_PNG_STRATEGY_RLE. + IMWRITE_PNG_BILEVEL = 18, //!< Binary level PNG, 0 or 1, default is 0. + IMWRITE_PXM_BINARY = 32, //!< For PPM, PGM, or PBM, it can be a binary format flag, 0 or 1. Default value is 1. + IMWRITE_EXR_TYPE = (3 << 4) + 0, /* 48 */ //!< override EXR storage type (FLOAT (FP32) is default) + IMWRITE_WEBP_QUALITY = 64, //!< For WEBP, it can be a quality from 1 to 100 (the higher is the better). By default (without any parameter) and for quality above 100 the lossless compression is used. + IMWRITE_PAM_TUPLETYPE = 128,//!< For PAM, sets the TUPLETYPE field to the corresponding string value that is defined for the format + IMWRITE_TIFF_RESUNIT = 256,//!< For TIFF, use to specify which DPI resolution unit to set; see libtiff documentation for valid values + IMWRITE_TIFF_XDPI = 257,//!< For TIFF, use to specify the X direction DPI + IMWRITE_TIFF_YDPI = 258, //!< For TIFF, use to specify the Y direction DPI + IMWRITE_TIFF_COMPRESSION = 259, //!< For TIFF, use to specify the image compression scheme. See libtiff for integer constants corresponding to compression formats. Note, for images whose depth is CV_32F, only libtiff's SGILOG compression scheme is used. For other supported depths, the compression scheme can be specified by this flag; LZW compression is the default. + IMWRITE_JPEG2000_COMPRESSION_X1000 = 272 //!< For JPEG2000, use to specify the target compression rate (multiplied by 1000). The value can be from 0 to 1000. Default is 1000. + }; + +enum ImwriteEXRTypeFlags { + /*IMWRITE_EXR_TYPE_UNIT = 0, //!< not supported */ + IMWRITE_EXR_TYPE_HALF = 1, //!< store as HALF (FP16) + IMWRITE_EXR_TYPE_FLOAT = 2 //!< store as FP32 (default) + }; + +//! Imwrite PNG specific flags used to tune the compression algorithm. +/** These flags will be modify the way of PNG image compression and will be passed to the underlying zlib processing stage. + +- The effect of IMWRITE_PNG_STRATEGY_FILTERED is to force more Huffman coding and less string matching; it is somewhat intermediate between IMWRITE_PNG_STRATEGY_DEFAULT and IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY. +- IMWRITE_PNG_STRATEGY_RLE is designed to be almost as fast as IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY, but give better compression for PNG image data. +- The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately. +- IMWRITE_PNG_STRATEGY_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. +*/ +enum ImwritePNGFlags { + IMWRITE_PNG_STRATEGY_DEFAULT = 0, //!< Use this value for normal data. + IMWRITE_PNG_STRATEGY_FILTERED = 1, //!< Use this value for data produced by a filter (or predictor).Filtered data consists mostly of small values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress them better. + IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2, //!< Use this value to force Huffman encoding only (no string match). + IMWRITE_PNG_STRATEGY_RLE = 3, //!< Use this value to limit match distances to one (run-length encoding). + IMWRITE_PNG_STRATEGY_FIXED = 4 //!< Using this value prevents the use of dynamic Huffman codes, allowing for a simpler decoder for special applications. + }; + +//! Imwrite PAM specific tupletype flags used to define the 'TUPETYPE' field of a PAM file. +enum ImwritePAMFlags { + IMWRITE_PAM_FORMAT_NULL = 0, + IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, + IMWRITE_PAM_FORMAT_GRAYSCALE = 2, + IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, + IMWRITE_PAM_FORMAT_RGB = 4, + IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, + }; + +/** @brief Loads an image from a file. + +@anchor imread + +The function imread loads an image from the specified file and returns it. If the image cannot be +read (because of missing file, improper permissions, unsupported or invalid format), the function +returns an empty matrix ( Mat::data==NULL ). + +Currently, the following file formats are supported: + +- Windows bitmaps - \*.bmp, \*.dib (always supported) +- JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section) +- JPEG 2000 files - \*.jp2 (see the *Note* section) +- Portable Network Graphics - \*.png (see the *Note* section) +- WebP - \*.webp (see the *Note* section) +- Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported) +- PFM files - \*.pfm (see the *Note* section) +- Sun rasters - \*.sr, \*.ras (always supported) +- TIFF files - \*.tiff, \*.tif (see the *Note* section) +- OpenEXR Image files - \*.exr (see the *Note* section) +- Radiance HDR - \*.hdr, \*.pic (always supported) +- Raster and Vector geospatial data supported by GDAL (see the *Note* section) + +@note +- The function determines the type of an image by the content, not by the file extension. +- In the case of color images, the decoded images will have the channels stored in **B G R** order. +- When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available. + Results may differ to the output of cvtColor() +- On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg, + libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, + and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware + that currently these native image loaders give images with different pixel values because of + the color management embedded into MacOSX. +- On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for + codecs supplied with an OS image. Install the relevant packages (do not forget the development + files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn + on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake. +- In the case you set *WITH_GDAL* flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image, + then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting + the following formats: [Raster](http://www.gdal.org/formats_list.html), + [Vector](http://www.gdal.org/ogr_formats.html). +- If EXIF information are embedded in the image file, the EXIF orientation will be taken into account + and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed. +- Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image. +- By default number of pixels must be less than 2^30. Limit can be set using system + variable OPENCV_IO_MAX_IMAGE_PIXELS + +@param filename Name of file to be loaded. +@param flags Flag that can take values of cv::ImreadModes +*/ +CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR ); + +/** @brief Loads a multi-page image from a file. + +The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects. +@param filename Name of file to be loaded. +@param flags Flag that can take values of cv::ImreadModes, default with cv::IMREAD_ANYCOLOR. +@param mats A vector of Mat objects holding each page, if more than one. +@sa cv::imread +*/ +CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector& mats, int flags = IMREAD_ANYCOLOR); + +/** @brief Saves an image to a specified file. + +The function imwrite saves the image to the specified file. The image format is chosen based on the +filename extension (see cv::imread for the list of extensions). In general, only 8-bit +single-channel or 3-channel (with 'BGR' channel order) images +can be saved using this function, with these exceptions: + +- 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats +- 32-bit float (CV_32F) images can be saved in PFM, TIFF, OpenEXR, and Radiance HDR formats; + 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding + (4 bytes per pixel) +- PNG images with an alpha channel can be saved using this function. To do this, create +8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels +should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below). + +If the format, depth or channel order is different, use +Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O +functions to save the image to XML or YAML format. + +The sample below shows how to create a BGRA image and save it to a PNG file. It also demonstrates how to set custom +compression parameters: +@include snippets/imgcodecs_imwrite.cpp +@param filename Name of the file. +@param img Image to be saved. +@param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags +*/ +CV_EXPORTS_W bool imwrite( const String& filename, InputArray img, + const std::vector& params = std::vector()); + +/** @brief Reads an image from a buffer in memory. + +The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or +contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). + +See cv::imread for the list of supported formats and flags description. + +@note In the case of color images, the decoded images will have the channels stored in **B G R** order. +@param buf Input array or vector of bytes. +@param flags The same flags as in cv::imread, see cv::ImreadModes. +*/ +CV_EXPORTS_W Mat imdecode( InputArray buf, int flags ); + +/** @overload +@param buf +@param flags +@param dst The optional output placeholder for the decoded matrix. It can save the image +reallocations when the function is called repeatedly for images of the same size. +*/ +CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst); + +/** @brief Encodes an image into a memory buffer. + +The function imencode compresses the image and stores it in the memory buffer that is resized to fit the +result. See cv::imwrite for the list of supported formats and flags description. + +@param ext File extension that defines the output format. +@param img Image to be written. +@param buf Output buffer resized to fit the compressed image. +@param params Format-specific parameters. See cv::imwrite and cv::ImwriteFlags. +*/ +CV_EXPORTS_W bool imencode( const String& ext, InputArray img, + CV_OUT std::vector& buf, + const std::vector& params = std::vector()); + +/** @brief Returns true if the specified image can be decoded by OpenCV + +@param filename File name of the image +*/ +CV_EXPORTS_W bool haveImageReader( const String& filename ); + +/** @brief Returns true if an image with the specified filename can be encoded by OpenCV + + @param filename File name of the image + */ +CV_EXPORTS_W bool haveImageWriter( const String& filename ); + + +//! @} imgcodecs + +} // cv + +#endif //OPENCV_IMGCODECS_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/imgcodecs.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/imgcodecs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a3cd232645465f4c8148d1fcd3d9fde6eddddffb --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/imgcodecs.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/imgcodecs.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/imgcodecs_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/imgcodecs_c.h new file mode 100644 index 0000000000000000000000000000000000000000..c78b3f72faa6b76d480ed3d68545bd369ffa2d9d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/imgcodecs_c.h @@ -0,0 +1 @@ +#error "This header with legacy C API declarations has been removed from OpenCV. Legacy constants are available from legacy/constants_c.h file." diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/ios.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/ios.h new file mode 100644 index 0000000000000000000000000000000000000000..a90c6d37a86c8bd6fd3c93d7b89f3c52b5ffbd96 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/ios.h @@ -0,0 +1,57 @@ + +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#import +#import +#import +#import +#include "opencv2/core/core.hpp" + +//! @addtogroup imgcodecs_ios +//! @{ + +CV_EXPORTS UIImage* MatToUIImage(const cv::Mat& image); +CV_EXPORTS void UIImageToMat(const UIImage* image, + cv::Mat& m, bool alphaExist = false); + +//! @} diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/legacy/constants_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/legacy/constants_c.h new file mode 100644 index 0000000000000000000000000000000000000000..de7be4f74d786fc70cf9041cb03ef704a7ad457b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgcodecs/legacy/constants_c.h @@ -0,0 +1,54 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_IMGCODECS_LEGACY_CONSTANTS_H +#define OPENCV_IMGCODECS_LEGACY_CONSTANTS_H + +/* duplicate of "ImreadModes" enumeration for better compatibility with OpenCV 3.x */ +enum +{ +/* 8bit, color or not */ + CV_LOAD_IMAGE_UNCHANGED =-1, +/* 8bit, gray */ + CV_LOAD_IMAGE_GRAYSCALE =0, +/* ?, color */ + CV_LOAD_IMAGE_COLOR =1, +/* any depth, ? */ + CV_LOAD_IMAGE_ANYDEPTH =2, +/* ?, any color */ + CV_LOAD_IMAGE_ANYCOLOR =4, +/* ?, no rotate */ + CV_LOAD_IMAGE_IGNORE_ORIENTATION =128 +}; + +/* duplicate of "ImwriteFlags" enumeration for better compatibility with OpenCV 3.x */ +enum +{ + CV_IMWRITE_JPEG_QUALITY =1, + CV_IMWRITE_JPEG_PROGRESSIVE =2, + CV_IMWRITE_JPEG_OPTIMIZE =3, + CV_IMWRITE_JPEG_RST_INTERVAL =4, + CV_IMWRITE_JPEG_LUMA_QUALITY =5, + CV_IMWRITE_JPEG_CHROMA_QUALITY =6, + CV_IMWRITE_PNG_COMPRESSION =16, + CV_IMWRITE_PNG_STRATEGY =17, + CV_IMWRITE_PNG_BILEVEL =18, + CV_IMWRITE_PNG_STRATEGY_DEFAULT =0, + CV_IMWRITE_PNG_STRATEGY_FILTERED =1, + CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2, + CV_IMWRITE_PNG_STRATEGY_RLE =3, + CV_IMWRITE_PNG_STRATEGY_FIXED =4, + CV_IMWRITE_PXM_BINARY =32, + CV_IMWRITE_EXR_TYPE = 48, + CV_IMWRITE_WEBP_QUALITY =64, + CV_IMWRITE_PAM_TUPLETYPE = 128, + CV_IMWRITE_PAM_FORMAT_NULL = 0, + CV_IMWRITE_PAM_FORMAT_BLACKANDWHITE = 1, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE = 2, + CV_IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = 3, + CV_IMWRITE_PAM_FORMAT_RGB = 4, + CV_IMWRITE_PAM_FORMAT_RGB_ALPHA = 5, +}; + +#endif // OPENCV_IMGCODECS_LEGACY_CONSTANTS_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e5af81a060a3a8fde62b300872be2476c82f58c3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc.hpp @@ -0,0 +1,4786 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_IMGPROC_HPP +#define OPENCV_IMGPROC_HPP + +#include "opencv2/core.hpp" + +/** + @defgroup imgproc Image Processing + +This module includes image-processing functions. + + @{ + @defgroup imgproc_filter Image Filtering + +Functions and classes described in this section are used to perform various linear or non-linear +filtering operations on 2D images (represented as Mat's). It means that for each pixel location +\f$(x,y)\f$ in the source image (normally, rectangular), its neighborhood is considered and used to +compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of +morphological operations, it is the minimum or maximum values, and so on. The computed response is +stored in the destination image at the same location \f$(x,y)\f$. It means that the output image +will be of the same size as the input image. Normally, the functions support multi-channel arrays, +in which case every channel is processed independently. Therefore, the output image will also have +the same number of channels as the input one. + +Another common feature of the functions and classes described in this section is that, unlike +simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For +example, if you want to smooth an image using a Gaussian \f$3 \times 3\f$ filter, then, when +processing the left-most pixels in each row, you need pixels to the left of them, that is, outside +of the image. You can let these pixels be the same as the left-most image pixels ("replicated +border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant +border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method. +For details, see #BorderTypes + +@anchor filter_depths +### Depth combinations +Input depth (src.depth()) | Output depth (ddepth) +--------------------------|---------------------- +CV_8U | -1/CV_16S/CV_32F/CV_64F +CV_16U/CV_16S | -1/CV_32F/CV_64F +CV_32F | -1/CV_32F/CV_64F +CV_64F | -1/CV_64F + +@note when ddepth=-1, the output image will have the same depth as the source. + + @defgroup imgproc_transform Geometric Image Transformations + +The functions in this section perform various geometrical transformations of 2D images. They do not +change the image content but deform the pixel grid and map this deformed grid to the destination +image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from +destination to the source. That is, for each pixel \f$(x, y)\f$ of the destination image, the +functions compute coordinates of the corresponding "donor" pixel in the source image and copy the +pixel value: + +\f[\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))\f] + +In case when you specify the forward mapping \f$\left: \texttt{src} \rightarrow +\texttt{dst}\f$, the OpenCV functions first compute the corresponding inverse mapping +\f$\left: \texttt{dst} \rightarrow \texttt{src}\f$ and then use the above formula. + +The actual implementations of the geometrical transformations, from the most generic remap and to +the simplest and the fastest resize, need to solve two main problems with the above formula: + +- Extrapolation of non-existing pixels. Similarly to the filtering functions described in the +previous section, for some \f$(x,y)\f$, either one of \f$f_x(x,y)\f$, or \f$f_y(x,y)\f$, or both +of them may fall outside of the image. In this case, an extrapolation method needs to be used. +OpenCV provides the same selection of extrapolation methods as in the filtering functions. In +addition, it provides the method #BORDER_TRANSPARENT. This means that the corresponding pixels in +the destination image will not be modified at all. + +- Interpolation of pixel values. Usually \f$f_x(x,y)\f$ and \f$f_y(x,y)\f$ are floating-point +numbers. This means that \f$\left\f$ can be either an affine or perspective +transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional +coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the +nearest integer coordinates and the corresponding pixel can be used. This is called a +nearest-neighbor interpolation. However, a better result can be achieved by using more +sophisticated [interpolation methods](http://en.wikipedia.org/wiki/Multivariate_interpolation) , +where a polynomial function is fit into some neighborhood of the computed pixel \f$(f_x(x,y), +f_y(x,y))\f$, and then the value of the polynomial at \f$(f_x(x,y), f_y(x,y))\f$ is taken as the +interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See +resize for details. + +@note The geometrical transformations do not work with `CV_8S` or `CV_32S` images. + + @defgroup imgproc_misc Miscellaneous Image Transformations + @defgroup imgproc_draw Drawing Functions + +Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be +rendered with antialiasing (implemented only for 8-bit images for now). All the functions include +the parameter color that uses an RGB value (that may be constructed with the Scalar constructor ) +for color images and brightness for grayscale images. For color images, the channel ordering is +normally *Blue, Green, Red*. This is what imshow, imread, and imwrite expect. So, if you form a +color using the Scalar constructor, it should look like: + +\f[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\f] + +If you are using your own image rendering and I/O functions, you can use any channel ordering. The +drawing functions process each channel independently and do not depend on the channel order or even +on the used color space. The whole image can be converted from BGR to RGB or to a different color +space using cvtColor . + +If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, +many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means +that the coordinates can be passed as fixed-point numbers encoded as integers. The number of +fractional bits is specified by the shift parameter and the real point coordinates are calculated as +\f$\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\f$ . This feature is +especially effective when rendering antialiased shapes. + +@note The functions do not support alpha-transparency when the target image is 4-channel. In this +case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint +semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main +image. + + @defgroup imgproc_color_conversions Color Space Conversions + @defgroup imgproc_colormap ColorMaps in OpenCV + +The human perception isn't built for observing fine changes in grayscale images. Human eyes are more +sensitive to observing changes between colors, so you often need to recolor your grayscale images to +get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your +computer vision application. + +In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample +code reads the path to an image from command line, applies a Jet colormap on it and shows the +result: + +@include snippets/imgproc_applyColorMap.cpp + +@see #ColormapTypes + + @defgroup imgproc_subdiv2d Planar Subdivision + +The Subdiv2D class described in this section is used to perform various planar subdivision on +a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles +using the Delaunay's algorithm, which corresponds to the dual graph of the Voronoi diagram. +In the figure below, the Delaunay's triangulation is marked with black lines and the Voronoi +diagram with red lines. + +![Delaunay triangulation (black) and Voronoi (red)](pics/delaunay_voronoi.png) + +The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast +location of points on the plane, building special graphs (such as NNG,RNG), and so forth. + + @defgroup imgproc_hist Histograms + @defgroup imgproc_shape Structural Analysis and Shape Descriptors + @defgroup imgproc_motion Motion Analysis and Object Tracking + @defgroup imgproc_feature Feature Detection + @defgroup imgproc_object Object Detection + @defgroup imgproc_c C API + @defgroup imgproc_hal Hardware Acceleration Layer + @{ + @defgroup imgproc_hal_functions Functions + @defgroup imgproc_hal_interface Interface + @} + @} +*/ + +namespace cv +{ + +/** @addtogroup imgproc +@{ +*/ + +//! @addtogroup imgproc_filter +//! @{ + +enum SpecialFilter { + FILTER_SCHARR = -1 +}; + +//! type of morphological operation +enum MorphTypes{ + MORPH_ERODE = 0, //!< see #erode + MORPH_DILATE = 1, //!< see #dilate + MORPH_OPEN = 2, //!< an opening operation + //!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f] + MORPH_CLOSE = 3, //!< a closing operation + //!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f] + MORPH_GRADIENT = 4, //!< a morphological gradient + //!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f] + MORPH_TOPHAT = 5, //!< "top hat" + //!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f] + MORPH_BLACKHAT = 6, //!< "black hat" + //!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f] + MORPH_HITMISS = 7 //!< "hit or miss" + //!< .- Only supported for CV_8UC1 binary images. A tutorial can be found in the documentation +}; + +//! shape of the structuring element +enum MorphShapes { + MORPH_RECT = 0, //!< a rectangular structuring element: \f[E_{ij}=1\f] + MORPH_CROSS = 1, //!< a cross-shaped structuring element: + //!< \f[E_{ij} = \fork{1}{if i=\texttt{anchor.y} or j=\texttt{anchor.x}}{0}{otherwise}\f] + MORPH_ELLIPSE = 2 //!< an elliptic structuring element, that is, a filled ellipse inscribed + //!< into the rectangle Rect(0, 0, esize.width, 0.esize.height) +}; + +//! @} imgproc_filter + +//! @addtogroup imgproc_transform +//! @{ + +//! interpolation algorithm +enum InterpolationFlags{ + /** nearest neighbor interpolation */ + INTER_NEAREST = 0, + /** bilinear interpolation */ + INTER_LINEAR = 1, + /** bicubic interpolation */ + INTER_CUBIC = 2, + /** resampling using pixel area relation. It may be a preferred method for image decimation, as + it gives moire'-free results. But when the image is zoomed, it is similar to the INTER_NEAREST + method. */ + INTER_AREA = 3, + /** Lanczos interpolation over 8x8 neighborhood */ + INTER_LANCZOS4 = 4, + /** Bit exact bilinear interpolation */ + INTER_LINEAR_EXACT = 5, + /** mask for interpolation codes */ + INTER_MAX = 7, + /** flag, fills all of the destination image pixels. If some of them correspond to outliers in the + source image, they are set to zero */ + WARP_FILL_OUTLIERS = 8, + /** flag, inverse transformation + + For example, #linearPolar or #logPolar transforms: + - flag is __not__ set: \f$dst( \rho , \phi ) = src(x,y)\f$ + - flag is set: \f$dst(x,y) = src( \rho , \phi )\f$ + */ + WARP_INVERSE_MAP = 16 +}; + +/** \brief Specify the polar mapping mode +@sa warpPolar +*/ +enum WarpPolarMode +{ + WARP_POLAR_LINEAR = 0, ///< Remaps an image to/from polar space. + WARP_POLAR_LOG = 256 ///< Remaps an image to/from semilog-polar space. +}; + +enum InterpolationMasks { + INTER_BITS = 5, + INTER_BITS2 = INTER_BITS * 2, + INTER_TAB_SIZE = 1 << INTER_BITS, + INTER_TAB_SIZE2 = INTER_TAB_SIZE * INTER_TAB_SIZE + }; + +//! @} imgproc_transform + +//! @addtogroup imgproc_misc +//! @{ + +//! Distance types for Distance Transform and M-estimators +//! @see distanceTransform, fitLine +enum DistanceTypes { + DIST_USER = -1, //!< User defined distance + DIST_L1 = 1, //!< distance = |x1-x2| + |y1-y2| + DIST_L2 = 2, //!< the simple euclidean distance + DIST_C = 3, //!< distance = max(|x1-x2|,|y1-y2|) + DIST_L12 = 4, //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) + DIST_FAIR = 5, //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 + DIST_WELSCH = 6, //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 + DIST_HUBER = 7 //!< distance = |x| \texttt{thresh}\)}{0}{otherwise}\f] + THRESH_BINARY_INV = 1, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{maxval}}{otherwise}\f] + THRESH_TRUNC = 2, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{threshold}}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] + THRESH_TOZERO = 3, //!< \f[\texttt{dst} (x,y) = \fork{\texttt{src}(x,y)}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{0}{otherwise}\f] + THRESH_TOZERO_INV = 4, //!< \f[\texttt{dst} (x,y) = \fork{0}{if \(\texttt{src}(x,y) > \texttt{thresh}\)}{\texttt{src}(x,y)}{otherwise}\f] + THRESH_MASK = 7, + THRESH_OTSU = 8, //!< flag, use Otsu algorithm to choose the optimal threshold value + THRESH_TRIANGLE = 16 //!< flag, use Triangle algorithm to choose the optimal threshold value +}; + +//! adaptive threshold algorithm +//! @see adaptiveThreshold +enum AdaptiveThresholdTypes { + /** the threshold value \f$T(x,y)\f$ is a mean of the \f$\texttt{blockSize} \times + \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ minus C */ + ADAPTIVE_THRESH_MEAN_C = 0, + /** the threshold value \f$T(x, y)\f$ is a weighted sum (cross-correlation with a Gaussian + window) of the \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood of \f$(x, y)\f$ + minus C . The default sigma (standard deviation) is used for the specified blockSize . See + #getGaussianKernel*/ + ADAPTIVE_THRESH_GAUSSIAN_C = 1 +}; + +//! class of the pixel in GrabCut algorithm +enum GrabCutClasses { + GC_BGD = 0, //!< an obvious background pixels + GC_FGD = 1, //!< an obvious foreground (object) pixel + GC_PR_BGD = 2, //!< a possible background pixel + GC_PR_FGD = 3 //!< a possible foreground pixel +}; + +//! GrabCut algorithm flags +enum GrabCutModes { + /** The function initializes the state and the mask using the provided rectangle. After that it + runs iterCount iterations of the algorithm. */ + GC_INIT_WITH_RECT = 0, + /** The function initializes the state using the provided mask. Note that GC_INIT_WITH_RECT + and GC_INIT_WITH_MASK can be combined. Then, all the pixels outside of the ROI are + automatically initialized with GC_BGD .*/ + GC_INIT_WITH_MASK = 1, + /** The value means that the algorithm should just resume. */ + GC_EVAL = 2, + /** The value means that the algorithm should just run the grabCut algorithm (a single iteration) with the fixed model */ + GC_EVAL_FREEZE_MODEL = 3 +}; + +//! distanceTransform algorithm flags +enum DistanceTransformLabelTypes { + /** each connected component of zeros in src (as well as all the non-zero pixels closest to the + connected component) will be assigned the same label */ + DIST_LABEL_CCOMP = 0, + /** each zero pixel (and all the non-zero pixels closest to it) gets its own label. */ + DIST_LABEL_PIXEL = 1 +}; + +//! floodfill algorithm flags +enum FloodFillFlags { + /** If set, the difference between the current pixel and seed pixel is considered. Otherwise, + the difference between neighbor pixels is considered (that is, the range is floating). */ + FLOODFILL_FIXED_RANGE = 1 << 16, + /** If set, the function does not change the image ( newVal is ignored), and only fills the + mask with the value specified in bits 8-16 of flags as described above. This option only make + sense in function variants that have the mask parameter. */ + FLOODFILL_MASK_ONLY = 1 << 17 +}; + +//! @} imgproc_misc + +//! @addtogroup imgproc_shape +//! @{ + +//! connected components algorithm output formats +enum ConnectedComponentsTypes { + CC_STAT_LEFT = 0, //!< The leftmost (x) coordinate which is the inclusive start of the bounding + //!< box in the horizontal direction. + CC_STAT_TOP = 1, //!< The topmost (y) coordinate which is the inclusive start of the bounding + //!< box in the vertical direction. + CC_STAT_WIDTH = 2, //!< The horizontal size of the bounding box + CC_STAT_HEIGHT = 3, //!< The vertical size of the bounding box + CC_STAT_AREA = 4, //!< The total area (in pixels) of the connected component +#ifndef CV_DOXYGEN + CC_STAT_MAX = 5 //!< Max enumeration value. Used internally only for memory allocation +#endif +}; + +//! connected components algorithm +enum ConnectedComponentsAlgorithmsTypes { + CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity + CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity +}; + +//! mode of the contour retrieval algorithm +enum RetrievalModes { + /** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for + all the contours. */ + RETR_EXTERNAL = 0, + /** retrieves all of the contours without establishing any hierarchical relationships. */ + RETR_LIST = 1, + /** retrieves all of the contours and organizes them into a two-level hierarchy. At the top + level, there are external boundaries of the components. At the second level, there are + boundaries of the holes. If there is another contour inside a hole of a connected component, it + is still put at the top level. */ + RETR_CCOMP = 2, + /** retrieves all of the contours and reconstructs a full hierarchy of nested contours.*/ + RETR_TREE = 3, + RETR_FLOODFILL = 4 //!< +}; + +//! the contour approximation algorithm +enum ContourApproximationModes { + /** stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and + (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is, + max(abs(x1-x2),abs(y2-y1))==1. */ + CHAIN_APPROX_NONE = 1, + /** compresses horizontal, vertical, and diagonal segments and leaves only their end points. + For example, an up-right rectangular contour is encoded with 4 points. */ + CHAIN_APPROX_SIMPLE = 2, + /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */ + CHAIN_APPROX_TC89_L1 = 3, + /** applies one of the flavors of the Teh-Chin chain approximation algorithm @cite TehChin89 */ + CHAIN_APPROX_TC89_KCOS = 4 +}; + +/** @brief Shape matching methods + +\f$A\f$ denotes object1,\f$B\f$ denotes object2 + +\f$\begin{array}{l} m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i} \\ m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i} \end{array}\f$ + +and \f$h^A_i, h^B_i\f$ are the Hu moments of \f$A\f$ and \f$B\f$ , respectively. +*/ +enum ShapeMatchModes { + CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f] + CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f] + CONTOURS_MATCH_I3 =3 //!< \f[I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }\f] +}; + +//! @} imgproc_shape + +//! @addtogroup imgproc_feature +//! @{ + +//! Variants of a Hough transform +enum HoughModes { + + /** classical or standard Hough transform. Every line is represented by two floating-point + numbers \f$(\rho, \theta)\f$ , where \f$\rho\f$ is a distance between (0,0) point and the line, + and \f$\theta\f$ is the angle between x-axis and the normal to the line. Thus, the matrix must + be (the created sequence will be) of CV_32FC2 type */ + HOUGH_STANDARD = 0, + /** probabilistic Hough transform (more efficient in case if the picture contains a few long + linear segments). It returns line segments rather than the whole line. Each segment is + represented by starting and ending points, and the matrix must be (the created sequence will + be) of the CV_32SC4 type. */ + HOUGH_PROBABILISTIC = 1, + /** multi-scale variant of the classical Hough transform. The lines are encoded the same way as + HOUGH_STANDARD. */ + HOUGH_MULTI_SCALE = 2, + HOUGH_GRADIENT = 3 //!< basically *21HT*, described in @cite Yuen90 +}; + +//! Variants of Line Segment %Detector +enum LineSegmentDetectorModes { + LSD_REFINE_NONE = 0, //!< No refinement applied + LSD_REFINE_STD = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations. + LSD_REFINE_ADV = 2 //!< Advanced refinement. Number of false alarms is calculated, lines are + //!< refined through increase of precision, decrement in size, etc. +}; + +//! @} imgproc_feature + +/** Histogram comparison methods + @ingroup imgproc_hist +*/ +enum HistCompMethods { + /** Correlation + \f[d(H_1,H_2) = \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}\f] + where + \f[\bar{H_k} = \frac{1}{N} \sum _J H_k(J)\f] + and \f$N\f$ is a total number of histogram bins. */ + HISTCMP_CORREL = 0, + /** Chi-Square + \f[d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}\f] */ + HISTCMP_CHISQR = 1, + /** Intersection + \f[d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))\f] */ + HISTCMP_INTERSECT = 2, + /** Bhattacharyya distance + (In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.) + \f[d(H_1,H_2) = \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}\f] */ + HISTCMP_BHATTACHARYYA = 3, + HISTCMP_HELLINGER = HISTCMP_BHATTACHARYYA, //!< Synonym for HISTCMP_BHATTACHARYYA + /** Alternative Chi-Square + \f[d(H_1,H_2) = 2 * \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)+H_2(I)}\f] + This alternative formula is regularly used for texture comparison. See e.g. @cite Puzicha1997 */ + HISTCMP_CHISQR_ALT = 4, + /** Kullback-Leibler divergence + \f[d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)\f] */ + HISTCMP_KL_DIV = 5 +}; + +/** the color conversion codes +@see @ref imgproc_color_conversions +@ingroup imgproc_color_conversions + */ +enum ColorConversionCodes { + COLOR_BGR2BGRA = 0, //!< add alpha channel to RGB or BGR image + COLOR_RGB2RGBA = COLOR_BGR2BGRA, + + COLOR_BGRA2BGR = 1, //!< remove alpha channel from RGB or BGR image + COLOR_RGBA2RGB = COLOR_BGRA2BGR, + + COLOR_BGR2RGBA = 2, //!< convert between RGB and BGR color spaces (with or without alpha channel) + COLOR_RGB2BGRA = COLOR_BGR2RGBA, + + COLOR_RGBA2BGR = 3, + COLOR_BGRA2RGB = COLOR_RGBA2BGR, + + COLOR_BGR2RGB = 4, + COLOR_RGB2BGR = COLOR_BGR2RGB, + + COLOR_BGRA2RGBA = 5, + COLOR_RGBA2BGRA = COLOR_BGRA2RGBA, + + COLOR_BGR2GRAY = 6, //!< convert between RGB/BGR and grayscale, @ref color_convert_rgb_gray "color conversions" + COLOR_RGB2GRAY = 7, + COLOR_GRAY2BGR = 8, + COLOR_GRAY2RGB = COLOR_GRAY2BGR, + COLOR_GRAY2BGRA = 9, + COLOR_GRAY2RGBA = COLOR_GRAY2BGRA, + COLOR_BGRA2GRAY = 10, + COLOR_RGBA2GRAY = 11, + + COLOR_BGR2BGR565 = 12, //!< convert between RGB/BGR and BGR565 (16-bit images) + COLOR_RGB2BGR565 = 13, + COLOR_BGR5652BGR = 14, + COLOR_BGR5652RGB = 15, + COLOR_BGRA2BGR565 = 16, + COLOR_RGBA2BGR565 = 17, + COLOR_BGR5652BGRA = 18, + COLOR_BGR5652RGBA = 19, + + COLOR_GRAY2BGR565 = 20, //!< convert between grayscale to BGR565 (16-bit images) + COLOR_BGR5652GRAY = 21, + + COLOR_BGR2BGR555 = 22, //!< convert between RGB/BGR and BGR555 (16-bit images) + COLOR_RGB2BGR555 = 23, + COLOR_BGR5552BGR = 24, + COLOR_BGR5552RGB = 25, + COLOR_BGRA2BGR555 = 26, + COLOR_RGBA2BGR555 = 27, + COLOR_BGR5552BGRA = 28, + COLOR_BGR5552RGBA = 29, + + COLOR_GRAY2BGR555 = 30, //!< convert between grayscale and BGR555 (16-bit images) + COLOR_BGR5552GRAY = 31, + + COLOR_BGR2XYZ = 32, //!< convert RGB/BGR to CIE XYZ, @ref color_convert_rgb_xyz "color conversions" + COLOR_RGB2XYZ = 33, + COLOR_XYZ2BGR = 34, + COLOR_XYZ2RGB = 35, + + COLOR_BGR2YCrCb = 36, //!< convert RGB/BGR to luma-chroma (aka YCC), @ref color_convert_rgb_ycrcb "color conversions" + COLOR_RGB2YCrCb = 37, + COLOR_YCrCb2BGR = 38, + COLOR_YCrCb2RGB = 39, + + COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions" + COLOR_RGB2HSV = 41, + + COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions" + COLOR_RGB2Lab = 45, + + COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions" + COLOR_RGB2Luv = 51, + COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions" + COLOR_RGB2HLS = 53, + + COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR + COLOR_HSV2RGB = 55, + + COLOR_Lab2BGR = 56, + COLOR_Lab2RGB = 57, + COLOR_Luv2BGR = 58, + COLOR_Luv2RGB = 59, + COLOR_HLS2BGR = 60, + COLOR_HLS2RGB = 61, + + COLOR_BGR2HSV_FULL = 66, + COLOR_RGB2HSV_FULL = 67, + COLOR_BGR2HLS_FULL = 68, + COLOR_RGB2HLS_FULL = 69, + + COLOR_HSV2BGR_FULL = 70, + COLOR_HSV2RGB_FULL = 71, + COLOR_HLS2BGR_FULL = 72, + COLOR_HLS2RGB_FULL = 73, + + COLOR_LBGR2Lab = 74, + COLOR_LRGB2Lab = 75, + COLOR_LBGR2Luv = 76, + COLOR_LRGB2Luv = 77, + + COLOR_Lab2LBGR = 78, + COLOR_Lab2LRGB = 79, + COLOR_Luv2LBGR = 80, + COLOR_Luv2LRGB = 81, + + COLOR_BGR2YUV = 82, //!< convert between RGB/BGR and YUV + COLOR_RGB2YUV = 83, + COLOR_YUV2BGR = 84, + COLOR_YUV2RGB = 85, + + //! YUV 4:2:0 family to RGB + COLOR_YUV2RGB_NV12 = 90, + COLOR_YUV2BGR_NV12 = 91, + COLOR_YUV2RGB_NV21 = 92, + COLOR_YUV2BGR_NV21 = 93, + COLOR_YUV420sp2RGB = COLOR_YUV2RGB_NV21, + COLOR_YUV420sp2BGR = COLOR_YUV2BGR_NV21, + + COLOR_YUV2RGBA_NV12 = 94, + COLOR_YUV2BGRA_NV12 = 95, + COLOR_YUV2RGBA_NV21 = 96, + COLOR_YUV2BGRA_NV21 = 97, + COLOR_YUV420sp2RGBA = COLOR_YUV2RGBA_NV21, + COLOR_YUV420sp2BGRA = COLOR_YUV2BGRA_NV21, + + COLOR_YUV2RGB_YV12 = 98, + COLOR_YUV2BGR_YV12 = 99, + COLOR_YUV2RGB_IYUV = 100, + COLOR_YUV2BGR_IYUV = 101, + COLOR_YUV2RGB_I420 = COLOR_YUV2RGB_IYUV, + COLOR_YUV2BGR_I420 = COLOR_YUV2BGR_IYUV, + COLOR_YUV420p2RGB = COLOR_YUV2RGB_YV12, + COLOR_YUV420p2BGR = COLOR_YUV2BGR_YV12, + + COLOR_YUV2RGBA_YV12 = 102, + COLOR_YUV2BGRA_YV12 = 103, + COLOR_YUV2RGBA_IYUV = 104, + COLOR_YUV2BGRA_IYUV = 105, + COLOR_YUV2RGBA_I420 = COLOR_YUV2RGBA_IYUV, + COLOR_YUV2BGRA_I420 = COLOR_YUV2BGRA_IYUV, + COLOR_YUV420p2RGBA = COLOR_YUV2RGBA_YV12, + COLOR_YUV420p2BGRA = COLOR_YUV2BGRA_YV12, + + COLOR_YUV2GRAY_420 = 106, + COLOR_YUV2GRAY_NV21 = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_NV12 = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_YV12 = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_IYUV = COLOR_YUV2GRAY_420, + COLOR_YUV2GRAY_I420 = COLOR_YUV2GRAY_420, + COLOR_YUV420sp2GRAY = COLOR_YUV2GRAY_420, + COLOR_YUV420p2GRAY = COLOR_YUV2GRAY_420, + + //! YUV 4:2:2 family to RGB + COLOR_YUV2RGB_UYVY = 107, + COLOR_YUV2BGR_UYVY = 108, + //COLOR_YUV2RGB_VYUY = 109, + //COLOR_YUV2BGR_VYUY = 110, + COLOR_YUV2RGB_Y422 = COLOR_YUV2RGB_UYVY, + COLOR_YUV2BGR_Y422 = COLOR_YUV2BGR_UYVY, + COLOR_YUV2RGB_UYNV = COLOR_YUV2RGB_UYVY, + COLOR_YUV2BGR_UYNV = COLOR_YUV2BGR_UYVY, + + COLOR_YUV2RGBA_UYVY = 111, + COLOR_YUV2BGRA_UYVY = 112, + //COLOR_YUV2RGBA_VYUY = 113, + //COLOR_YUV2BGRA_VYUY = 114, + COLOR_YUV2RGBA_Y422 = COLOR_YUV2RGBA_UYVY, + COLOR_YUV2BGRA_Y422 = COLOR_YUV2BGRA_UYVY, + COLOR_YUV2RGBA_UYNV = COLOR_YUV2RGBA_UYVY, + COLOR_YUV2BGRA_UYNV = COLOR_YUV2BGRA_UYVY, + + COLOR_YUV2RGB_YUY2 = 115, + COLOR_YUV2BGR_YUY2 = 116, + COLOR_YUV2RGB_YVYU = 117, + COLOR_YUV2BGR_YVYU = 118, + COLOR_YUV2RGB_YUYV = COLOR_YUV2RGB_YUY2, + COLOR_YUV2BGR_YUYV = COLOR_YUV2BGR_YUY2, + COLOR_YUV2RGB_YUNV = COLOR_YUV2RGB_YUY2, + COLOR_YUV2BGR_YUNV = COLOR_YUV2BGR_YUY2, + + COLOR_YUV2RGBA_YUY2 = 119, + COLOR_YUV2BGRA_YUY2 = 120, + COLOR_YUV2RGBA_YVYU = 121, + COLOR_YUV2BGRA_YVYU = 122, + COLOR_YUV2RGBA_YUYV = COLOR_YUV2RGBA_YUY2, + COLOR_YUV2BGRA_YUYV = COLOR_YUV2BGRA_YUY2, + COLOR_YUV2RGBA_YUNV = COLOR_YUV2RGBA_YUY2, + COLOR_YUV2BGRA_YUNV = COLOR_YUV2BGRA_YUY2, + + COLOR_YUV2GRAY_UYVY = 123, + COLOR_YUV2GRAY_YUY2 = 124, + //CV_YUV2GRAY_VYUY = CV_YUV2GRAY_UYVY, + COLOR_YUV2GRAY_Y422 = COLOR_YUV2GRAY_UYVY, + COLOR_YUV2GRAY_UYNV = COLOR_YUV2GRAY_UYVY, + COLOR_YUV2GRAY_YVYU = COLOR_YUV2GRAY_YUY2, + COLOR_YUV2GRAY_YUYV = COLOR_YUV2GRAY_YUY2, + COLOR_YUV2GRAY_YUNV = COLOR_YUV2GRAY_YUY2, + + //! alpha premultiplication + COLOR_RGBA2mRGBA = 125, + COLOR_mRGBA2RGBA = 126, + + //! RGB to YUV 4:2:0 family + COLOR_RGB2YUV_I420 = 127, + COLOR_BGR2YUV_I420 = 128, + COLOR_RGB2YUV_IYUV = COLOR_RGB2YUV_I420, + COLOR_BGR2YUV_IYUV = COLOR_BGR2YUV_I420, + + COLOR_RGBA2YUV_I420 = 129, + COLOR_BGRA2YUV_I420 = 130, + COLOR_RGBA2YUV_IYUV = COLOR_RGBA2YUV_I420, + COLOR_BGRA2YUV_IYUV = COLOR_BGRA2YUV_I420, + COLOR_RGB2YUV_YV12 = 131, + COLOR_BGR2YUV_YV12 = 132, + COLOR_RGBA2YUV_YV12 = 133, + COLOR_BGRA2YUV_YV12 = 134, + + //! Demosaicing + COLOR_BayerBG2BGR = 46, + COLOR_BayerGB2BGR = 47, + COLOR_BayerRG2BGR = 48, + COLOR_BayerGR2BGR = 49, + + COLOR_BayerBG2RGB = COLOR_BayerRG2BGR, + COLOR_BayerGB2RGB = COLOR_BayerGR2BGR, + COLOR_BayerRG2RGB = COLOR_BayerBG2BGR, + COLOR_BayerGR2RGB = COLOR_BayerGB2BGR, + + COLOR_BayerBG2GRAY = 86, + COLOR_BayerGB2GRAY = 87, + COLOR_BayerRG2GRAY = 88, + COLOR_BayerGR2GRAY = 89, + + //! Demosaicing using Variable Number of Gradients + COLOR_BayerBG2BGR_VNG = 62, + COLOR_BayerGB2BGR_VNG = 63, + COLOR_BayerRG2BGR_VNG = 64, + COLOR_BayerGR2BGR_VNG = 65, + + COLOR_BayerBG2RGB_VNG = COLOR_BayerRG2BGR_VNG, + COLOR_BayerGB2RGB_VNG = COLOR_BayerGR2BGR_VNG, + COLOR_BayerRG2RGB_VNG = COLOR_BayerBG2BGR_VNG, + COLOR_BayerGR2RGB_VNG = COLOR_BayerGB2BGR_VNG, + + //! Edge-Aware Demosaicing + COLOR_BayerBG2BGR_EA = 135, + COLOR_BayerGB2BGR_EA = 136, + COLOR_BayerRG2BGR_EA = 137, + COLOR_BayerGR2BGR_EA = 138, + + COLOR_BayerBG2RGB_EA = COLOR_BayerRG2BGR_EA, + COLOR_BayerGB2RGB_EA = COLOR_BayerGR2BGR_EA, + COLOR_BayerRG2RGB_EA = COLOR_BayerBG2BGR_EA, + COLOR_BayerGR2RGB_EA = COLOR_BayerGB2BGR_EA, + + //! Demosaicing with alpha channel + COLOR_BayerBG2BGRA = 139, + COLOR_BayerGB2BGRA = 140, + COLOR_BayerRG2BGRA = 141, + COLOR_BayerGR2BGRA = 142, + + COLOR_BayerBG2RGBA = COLOR_BayerRG2BGRA, + COLOR_BayerGB2RGBA = COLOR_BayerGR2BGRA, + COLOR_BayerRG2RGBA = COLOR_BayerBG2BGRA, + COLOR_BayerGR2RGBA = COLOR_BayerGB2BGRA, + + COLOR_COLORCVT_MAX = 143 +}; + +//! @addtogroup imgproc_shape +//! @{ + +//! types of intersection between rectangles +enum RectanglesIntersectTypes { + INTERSECT_NONE = 0, //!< No intersection + INTERSECT_PARTIAL = 1, //!< There is a partial intersection + INTERSECT_FULL = 2 //!< One of the rectangle is fully enclosed in the other +}; + +/** types of line +@ingroup imgproc_draw +*/ +enum LineTypes { + FILLED = -1, + LINE_4 = 4, //!< 4-connected line + LINE_8 = 8, //!< 8-connected line + LINE_AA = 16 //!< antialiased line +}; + +/** Only a subset of Hershey fonts are supported +@ingroup imgproc_draw +*/ +enum HersheyFonts { + FONT_HERSHEY_SIMPLEX = 0, //!< normal size sans-serif font + FONT_HERSHEY_PLAIN = 1, //!< small size sans-serif font + FONT_HERSHEY_DUPLEX = 2, //!< normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX) + FONT_HERSHEY_COMPLEX = 3, //!< normal size serif font + FONT_HERSHEY_TRIPLEX = 4, //!< normal size serif font (more complex than FONT_HERSHEY_COMPLEX) + FONT_HERSHEY_COMPLEX_SMALL = 5, //!< smaller version of FONT_HERSHEY_COMPLEX + FONT_HERSHEY_SCRIPT_SIMPLEX = 6, //!< hand-writing style font + FONT_HERSHEY_SCRIPT_COMPLEX = 7, //!< more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX + FONT_ITALIC = 16 //!< flag for italic font +}; + +/** Possible set of marker types used for the cv::drawMarker function +@ingroup imgproc_draw +*/ +enum MarkerTypes +{ + MARKER_CROSS = 0, //!< A crosshair marker shape + MARKER_TILTED_CROSS = 1, //!< A 45 degree tilted crosshair marker shape + MARKER_STAR = 2, //!< A star marker shape, combination of cross and tilted cross + MARKER_DIAMOND = 3, //!< A diamond marker shape + MARKER_SQUARE = 4, //!< A square marker shape + MARKER_TRIANGLE_UP = 5, //!< An upwards pointing triangle marker shape + MARKER_TRIANGLE_DOWN = 6 //!< A downwards pointing triangle marker shape +}; + +/** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform +*/ +class CV_EXPORTS_W GeneralizedHough : public Algorithm +{ +public: + //! set template to search + CV_WRAP virtual void setTemplate(InputArray templ, Point templCenter = Point(-1, -1)) = 0; + CV_WRAP virtual void setTemplate(InputArray edges, InputArray dx, InputArray dy, Point templCenter = Point(-1, -1)) = 0; + + //! find template on image + CV_WRAP virtual void detect(InputArray image, OutputArray positions, OutputArray votes = noArray()) = 0; + CV_WRAP virtual void detect(InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray votes = noArray()) = 0; + + //! Canny low threshold. + CV_WRAP virtual void setCannyLowThresh(int cannyLowThresh) = 0; + CV_WRAP virtual int getCannyLowThresh() const = 0; + + //! Canny high threshold. + CV_WRAP virtual void setCannyHighThresh(int cannyHighThresh) = 0; + CV_WRAP virtual int getCannyHighThresh() const = 0; + + //! Minimum distance between the centers of the detected objects. + CV_WRAP virtual void setMinDist(double minDist) = 0; + CV_WRAP virtual double getMinDist() const = 0; + + //! Inverse ratio of the accumulator resolution to the image resolution. + CV_WRAP virtual void setDp(double dp) = 0; + CV_WRAP virtual double getDp() const = 0; + + //! Maximal size of inner buffers. + CV_WRAP virtual void setMaxBufferSize(int maxBufferSize) = 0; + CV_WRAP virtual int getMaxBufferSize() const = 0; +}; + +/** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform + +Detects position only without translation and rotation @cite Ballard1981 . +*/ +class CV_EXPORTS_W GeneralizedHoughBallard : public GeneralizedHough +{ +public: + //! R-Table levels. + CV_WRAP virtual void setLevels(int levels) = 0; + CV_WRAP virtual int getLevels() const = 0; + + //! The accumulator threshold for the template centers at the detection stage. The smaller it is, the more false positions may be detected. + CV_WRAP virtual void setVotesThreshold(int votesThreshold) = 0; + CV_WRAP virtual int getVotesThreshold() const = 0; +}; + +/** @brief finds arbitrary template in the grayscale image using Generalized Hough Transform + +Detects position, translation and rotation @cite Guil1999 . +*/ +class CV_EXPORTS_W GeneralizedHoughGuil : public GeneralizedHough +{ +public: + //! Angle difference in degrees between two points in feature. + CV_WRAP virtual void setXi(double xi) = 0; + CV_WRAP virtual double getXi() const = 0; + + //! Feature table levels. + CV_WRAP virtual void setLevels(int levels) = 0; + CV_WRAP virtual int getLevels() const = 0; + + //! Maximal difference between angles that treated as equal. + CV_WRAP virtual void setAngleEpsilon(double angleEpsilon) = 0; + CV_WRAP virtual double getAngleEpsilon() const = 0; + + //! Minimal rotation angle to detect in degrees. + CV_WRAP virtual void setMinAngle(double minAngle) = 0; + CV_WRAP virtual double getMinAngle() const = 0; + + //! Maximal rotation angle to detect in degrees. + CV_WRAP virtual void setMaxAngle(double maxAngle) = 0; + CV_WRAP virtual double getMaxAngle() const = 0; + + //! Angle step in degrees. + CV_WRAP virtual void setAngleStep(double angleStep) = 0; + CV_WRAP virtual double getAngleStep() const = 0; + + //! Angle votes threshold. + CV_WRAP virtual void setAngleThresh(int angleThresh) = 0; + CV_WRAP virtual int getAngleThresh() const = 0; + + //! Minimal scale to detect. + CV_WRAP virtual void setMinScale(double minScale) = 0; + CV_WRAP virtual double getMinScale() const = 0; + + //! Maximal scale to detect. + CV_WRAP virtual void setMaxScale(double maxScale) = 0; + CV_WRAP virtual double getMaxScale() const = 0; + + //! Scale step. + CV_WRAP virtual void setScaleStep(double scaleStep) = 0; + CV_WRAP virtual double getScaleStep() const = 0; + + //! Scale votes threshold. + CV_WRAP virtual void setScaleThresh(int scaleThresh) = 0; + CV_WRAP virtual int getScaleThresh() const = 0; + + //! Position votes threshold. + CV_WRAP virtual void setPosThresh(int posThresh) = 0; + CV_WRAP virtual int getPosThresh() const = 0; +}; + +//! @} imgproc_shape + +//! @addtogroup imgproc_hist +//! @{ + +/** @brief Base class for Contrast Limited Adaptive Histogram Equalization. +*/ +class CV_EXPORTS_W CLAHE : public Algorithm +{ +public: + /** @brief Equalizes the histogram of a grayscale image using Contrast Limited Adaptive Histogram Equalization. + + @param src Source image of type CV_8UC1 or CV_16UC1. + @param dst Destination image. + */ + CV_WRAP virtual void apply(InputArray src, OutputArray dst) = 0; + + /** @brief Sets threshold for contrast limiting. + + @param clipLimit threshold value. + */ + CV_WRAP virtual void setClipLimit(double clipLimit) = 0; + + //! Returns threshold value for contrast limiting. + CV_WRAP virtual double getClipLimit() const = 0; + + /** @brief Sets size of grid for histogram equalization. Input image will be divided into + equally sized rectangular tiles. + + @param tileGridSize defines the number of tiles in row and column. + */ + CV_WRAP virtual void setTilesGridSize(Size tileGridSize) = 0; + + //!@brief Returns Size defines the number of tiles in row and column. + CV_WRAP virtual Size getTilesGridSize() const = 0; + + CV_WRAP virtual void collectGarbage() = 0; +}; + +//! @} imgproc_hist + +//! @addtogroup imgproc_subdiv2d +//! @{ + +class CV_EXPORTS_W Subdiv2D +{ +public: + /** Subdiv2D point location cases */ + enum { PTLOC_ERROR = -2, //!< Point location error + PTLOC_OUTSIDE_RECT = -1, //!< Point outside the subdivision bounding rect + PTLOC_INSIDE = 0, //!< Point inside some facet + PTLOC_VERTEX = 1, //!< Point coincides with one of the subdivision vertices + PTLOC_ON_EDGE = 2 //!< Point on some edge + }; + + /** Subdiv2D edge type navigation (see: getEdge()) */ + enum { NEXT_AROUND_ORG = 0x00, + NEXT_AROUND_DST = 0x22, + PREV_AROUND_ORG = 0x11, + PREV_AROUND_DST = 0x33, + NEXT_AROUND_LEFT = 0x13, + NEXT_AROUND_RIGHT = 0x31, + PREV_AROUND_LEFT = 0x20, + PREV_AROUND_RIGHT = 0x02 + }; + + /** creates an empty Subdiv2D object. + To create a new empty Delaunay subdivision you need to use the #initDelaunay function. + */ + CV_WRAP Subdiv2D(); + + /** @overload + + @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision. + + The function creates an empty Delaunay subdivision where 2D points can be added using the function + insert() . All of the points to be added must be within the specified rectangle, otherwise a runtime + error is raised. + */ + CV_WRAP Subdiv2D(Rect rect); + + /** @brief Creates a new empty Delaunay subdivision + + @param rect Rectangle that includes all of the 2D points that are to be added to the subdivision. + + */ + CV_WRAP void initDelaunay(Rect rect); + + /** @brief Insert a single point into a Delaunay triangulation. + + @param pt Point to insert. + + The function inserts a single point into a subdivision and modifies the subdivision topology + appropriately. If a point with the same coordinates exists already, no new point is added. + @returns the ID of the point. + + @note If the point is outside of the triangulation specified rect a runtime error is raised. + */ + CV_WRAP int insert(Point2f pt); + + /** @brief Insert multiple points into a Delaunay triangulation. + + @param ptvec Points to insert. + + The function inserts a vector of points into a subdivision and modifies the subdivision topology + appropriately. + */ + CV_WRAP void insert(const std::vector& ptvec); + + /** @brief Returns the location of a point within a Delaunay triangulation. + + @param pt Point to locate. + @param edge Output edge that the point belongs to or is located to the right of it. + @param vertex Optional output vertex the input point coincides with. + + The function locates the input point within the subdivision and gives one of the triangle edges + or vertices. + + @returns an integer which specify one of the following five cases for point location: + - The point falls into some facet. The function returns #PTLOC_INSIDE and edge will contain one of + edges of the facet. + - The point falls onto the edge. The function returns #PTLOC_ON_EDGE and edge will contain this edge. + - The point coincides with one of the subdivision vertices. The function returns #PTLOC_VERTEX and + vertex will contain a pointer to the vertex. + - The point is outside the subdivision reference rectangle. The function returns #PTLOC_OUTSIDE_RECT + and no pointers are filled. + - One of input arguments is invalid. A runtime error is raised or, if silent or "parent" error + processing mode is selected, #PTLOC_ERROR is returned. + */ + CV_WRAP int locate(Point2f pt, CV_OUT int& edge, CV_OUT int& vertex); + + /** @brief Finds the subdivision vertex closest to the given point. + + @param pt Input point. + @param nearestPt Output subdivision vertex point. + + The function is another function that locates the input point within the subdivision. It finds the + subdivision vertex that is the closest to the input point. It is not necessarily one of vertices + of the facet containing the input point, though the facet (located using locate() ) is used as a + starting point. + + @returns vertex ID. + */ + CV_WRAP int findNearest(Point2f pt, CV_OUT Point2f* nearestPt = 0); + + /** @brief Returns a list of all edges. + + @param edgeList Output vector. + + The function gives each edge as a 4 numbers vector, where each two are one of the edge + vertices. i.e. org_x = v[0], org_y = v[1], dst_x = v[2], dst_y = v[3]. + */ + CV_WRAP void getEdgeList(CV_OUT std::vector& edgeList) const; + + /** @brief Returns a list of the leading edge ID connected to each triangle. + + @param leadingEdgeList Output vector. + + The function gives one edge ID for each triangle. + */ + CV_WRAP void getLeadingEdgeList(CV_OUT std::vector& leadingEdgeList) const; + + /** @brief Returns a list of all triangles. + + @param triangleList Output vector. + + The function gives each triangle as a 6 numbers vector, where each two are one of the triangle + vertices. i.e. p1_x = v[0], p1_y = v[1], p2_x = v[2], p2_y = v[3], p3_x = v[4], p3_y = v[5]. + */ + CV_WRAP void getTriangleList(CV_OUT std::vector& triangleList) const; + + /** @brief Returns a list of all Voronoi facets. + + @param idx Vector of vertices IDs to consider. For all vertices you can pass empty vector. + @param facetList Output vector of the Voronoi facets. + @param facetCenters Output vector of the Voronoi facets center points. + + */ + CV_WRAP void getVoronoiFacetList(const std::vector& idx, CV_OUT std::vector >& facetList, + CV_OUT std::vector& facetCenters); + + /** @brief Returns vertex location from vertex ID. + + @param vertex vertex ID. + @param firstEdge Optional. The first edge ID which is connected to the vertex. + @returns vertex (x,y) + + */ + CV_WRAP Point2f getVertex(int vertex, CV_OUT int* firstEdge = 0) const; + + /** @brief Returns one of the edges related to the given edge. + + @param edge Subdivision edge ID. + @param nextEdgeType Parameter specifying which of the related edges to return. + The following values are possible: + - NEXT_AROUND_ORG next around the edge origin ( eOnext on the picture below if e is the input edge) + - NEXT_AROUND_DST next around the edge vertex ( eDnext ) + - PREV_AROUND_ORG previous around the edge origin (reversed eRnext ) + - PREV_AROUND_DST previous around the edge destination (reversed eLnext ) + - NEXT_AROUND_LEFT next around the left facet ( eLnext ) + - NEXT_AROUND_RIGHT next around the right facet ( eRnext ) + - PREV_AROUND_LEFT previous around the left facet (reversed eOnext ) + - PREV_AROUND_RIGHT previous around the right facet (reversed eDnext ) + + ![sample output](pics/quadedge.png) + + @returns edge ID related to the input edge. + */ + CV_WRAP int getEdge( int edge, int nextEdgeType ) const; + + /** @brief Returns next edge around the edge origin. + + @param edge Subdivision edge ID. + + @returns an integer which is next edge ID around the edge origin: eOnext on the + picture above if e is the input edge). + */ + CV_WRAP int nextEdge(int edge) const; + + /** @brief Returns another edge of the same quad-edge. + + @param edge Subdivision edge ID. + @param rotate Parameter specifying which of the edges of the same quad-edge as the input + one to return. The following values are possible: + - 0 - the input edge ( e on the picture below if e is the input edge) + - 1 - the rotated edge ( eRot ) + - 2 - the reversed edge (reversed e (in green)) + - 3 - the reversed rotated edge (reversed eRot (in green)) + + @returns one of the edges ID of the same quad-edge as the input edge. + */ + CV_WRAP int rotateEdge(int edge, int rotate) const; + CV_WRAP int symEdge(int edge) const; + + /** @brief Returns the edge origin. + + @param edge Subdivision edge ID. + @param orgpt Output vertex location. + + @returns vertex ID. + */ + CV_WRAP int edgeOrg(int edge, CV_OUT Point2f* orgpt = 0) const; + + /** @brief Returns the edge destination. + + @param edge Subdivision edge ID. + @param dstpt Output vertex location. + + @returns vertex ID. + */ + CV_WRAP int edgeDst(int edge, CV_OUT Point2f* dstpt = 0) const; + +protected: + int newEdge(); + void deleteEdge(int edge); + int newPoint(Point2f pt, bool isvirtual, int firstEdge = 0); + void deletePoint(int vtx); + void setEdgePoints( int edge, int orgPt, int dstPt ); + void splice( int edgeA, int edgeB ); + int connectEdges( int edgeA, int edgeB ); + void swapEdges( int edge ); + int isRightOf(Point2f pt, int edge) const; + void calcVoronoi(); + void clearVoronoi(); + void checkSubdiv() const; + + struct CV_EXPORTS Vertex + { + Vertex(); + Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0); + bool isvirtual() const; + bool isfree() const; + + int firstEdge; + int type; + Point2f pt; + }; + + struct CV_EXPORTS QuadEdge + { + QuadEdge(); + QuadEdge(int edgeidx); + bool isfree() const; + + int next[4]; + int pt[4]; + }; + + //! All of the vertices + std::vector vtx; + //! All of the edges + std::vector qedges; + int freeQEdge; + int freePoint; + bool validGeometry; + + int recentEdge; + //! Top left corner of the bounding rect + Point2f topLeft; + //! Bottom right corner of the bounding rect + Point2f bottomRight; +}; + +//! @} imgproc_subdiv2d + +//! @addtogroup imgproc_feature +//! @{ + +/** @brief Line segment detector class + +following the algorithm described at @cite Rafael12 . + +@note Implementation has been removed due original code license conflict + +*/ +class CV_EXPORTS_W LineSegmentDetector : public Algorithm +{ +public: + + /** @brief Finds lines in the input image. + + This is the output of the default parameters of the algorithm on the above shown image. + + ![image](pics/building_lsd.png) + + @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: + `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);` + @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where + Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly + oriented depending on the gradient. + @param width Vector of widths of the regions, where the lines are found. E.g. Width of line. + @param prec Vector of precisions with which the lines are found. + @param nfa Vector containing number of false alarms in the line region, with precision of 10%. The + bigger the value, logarithmically better the detection. + - -1 corresponds to 10 mean false alarms + - 0 corresponds to 1 mean false alarm + - 1 corresponds to 0.1 mean false alarms + This vector will be calculated only when the objects type is #LSD_REFINE_ADV. + */ + CV_WRAP virtual void detect(InputArray _image, OutputArray _lines, + OutputArray width = noArray(), OutputArray prec = noArray(), + OutputArray nfa = noArray()) = 0; + + /** @brief Draws the line segments on a given image. + @param _image The image, where the lines will be drawn. Should be bigger or equal to the image, + where the lines were found. + @param lines A vector of the lines that needed to be drawn. + */ + CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0; + + /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels. + + @param size The size of the image, where lines1 and lines2 were found. + @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color. + @param lines2 The second group of lines. They visualized in red color. + @param _image Optional image, where the lines will be drawn. The image should be color(3-channel) + in order for lines1 and lines2 to be drawn in the above mentioned colors. + */ + CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0; + + virtual ~LineSegmentDetector() { } +}; + +/** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it. + +The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want +to edit those, as to tailor it for their own application. + +@param _refine The way found lines will be refined, see #LineSegmentDetectorModes +@param _scale The scale of the image that will be used to find the lines. Range (0..1]. +@param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale. +@param _quant Bound to the quantization error on the gradient norm. +@param _ang_th Gradient angle tolerance in degrees. +@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement +is chosen. +@param _density_th Minimal density of aligned region points in the enclosing rectangle. +@param _n_bins Number of bins in pseudo-ordering of gradient modulus. + +@note Implementation has been removed due original code license conflict + */ +CV_EXPORTS_W Ptr createLineSegmentDetector( + int _refine = LSD_REFINE_STD, double _scale = 0.8, + double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, + double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); + +//! @} imgproc_feature + +//! @addtogroup imgproc_filter +//! @{ + +/** @brief Returns Gaussian filter coefficients. + +The function computes and returns the \f$\texttt{ksize} \times 1\f$ matrix of Gaussian filter +coefficients: + +\f[G_i= \alpha *e^{-(i-( \texttt{ksize} -1)/2)^2/(2* \texttt{sigma}^2)},\f] + +where \f$i=0..\texttt{ksize}-1\f$ and \f$\alpha\f$ is the scale factor chosen so that \f$\sum_i G_i=1\f$. + +Two of such generated kernels can be passed to sepFilter2D. Those functions automatically recognize +smoothing kernels (a symmetrical kernel with sum of weights equal to 1) and handle them accordingly. +You may also use the higher-level GaussianBlur. +@param ksize Aperture size. It should be odd ( \f$\texttt{ksize} \mod 2 = 1\f$ ) and positive. +@param sigma Gaussian standard deviation. If it is non-positive, it is computed from ksize as +`sigma = 0.3*((ksize-1)*0.5 - 1) + 0.8`. +@param ktype Type of filter coefficients. It can be CV_32F or CV_64F . +@sa sepFilter2D, getDerivKernels, getStructuringElement, GaussianBlur + */ +CV_EXPORTS_W Mat getGaussianKernel( int ksize, double sigma, int ktype = CV_64F ); + +/** @brief Returns filter coefficients for computing spatial image derivatives. + +The function computes and returns the filter coefficients for spatial image derivatives. When +`ksize=FILTER_SCHARR`, the Scharr \f$3 \times 3\f$ kernels are generated (see #Scharr). Otherwise, Sobel +kernels are generated (see #Sobel). The filters are normally passed to #sepFilter2D or to + +@param kx Output matrix of row filter coefficients. It has the type ktype . +@param ky Output matrix of column filter coefficients. It has the type ktype . +@param dx Derivative order in respect of x. +@param dy Derivative order in respect of y. +@param ksize Aperture size. It can be FILTER_SCHARR, 1, 3, 5, or 7. +@param normalize Flag indicating whether to normalize (scale down) the filter coefficients or not. +Theoretically, the coefficients should have the denominator \f$=2^{ksize*2-dx-dy-2}\f$. If you are +going to filter floating-point images, you are likely to use the normalized kernels. But if you +compute derivatives of an 8-bit image, store the results in a 16-bit image, and wish to preserve +all the fractional bits, you may want to set normalize=false . +@param ktype Type of filter coefficients. It can be CV_32f or CV_64F . + */ +CV_EXPORTS_W void getDerivKernels( OutputArray kx, OutputArray ky, + int dx, int dy, int ksize, + bool normalize = false, int ktype = CV_32F ); + +/** @brief Returns Gabor filter coefficients. + +For more details about gabor filter equations and parameters, see: [Gabor +Filter](http://en.wikipedia.org/wiki/Gabor_filter). + +@param ksize Size of the filter returned. +@param sigma Standard deviation of the gaussian envelope. +@param theta Orientation of the normal to the parallel stripes of a Gabor function. +@param lambd Wavelength of the sinusoidal factor. +@param gamma Spatial aspect ratio. +@param psi Phase offset. +@param ktype Type of filter coefficients. It can be CV_32F or CV_64F . + */ +CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd, + double gamma, double psi = CV_PI*0.5, int ktype = CV_64F ); + +//! returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation. +static inline Scalar morphologyDefaultBorderValue() { return Scalar::all(DBL_MAX); } + +/** @brief Returns a structuring element of the specified size and shape for morphological operations. + +The function constructs and returns the structuring element that can be further passed to #erode, +#dilate or #morphologyEx. But you can also construct an arbitrary binary mask yourself and use it as +the structuring element. + +@param shape Element shape that could be one of #MorphShapes +@param ksize Size of the structuring element. +@param anchor Anchor position within the element. The default value \f$(-1, -1)\f$ means that the +anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor +position. In other cases the anchor just regulates how much the result of the morphological +operation is shifted. + */ +CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1)); + +/** @example samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp +Sample code for simple filters +![Sample screenshot](Smoothing_Tutorial_Result_Median_Filter.jpg) +Check @ref tutorial_gausian_median_blur_bilateral_filter "the corresponding tutorial" for more details + */ + +/** @brief Blurs an image using the median filter. + +The function smoothes an image using the median filter with the \f$\texttt{ksize} \times +\texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently. +In-place operation is supported. + +@note The median filter uses #BORDER_REPLICATE internally to cope with border pixels, see #BorderTypes + +@param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be +CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U. +@param dst destination array of the same size and type as src. +@param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ... +@sa bilateralFilter, blur, boxFilter, GaussianBlur + */ +CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize ); + +/** @brief Blurs an image using a Gaussian filter. + +The function convolves the source image with the specified Gaussian kernel. In-place filtering is +supported. + +@param src input image; the image can have any number of channels, which are processed +independently, but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be +positive and odd. Or, they can be zero's and then they are computed from sigma. +@param sigmaX Gaussian kernel standard deviation in X direction. +@param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be +equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, +respectively (see #getGaussianKernel for details); to fully control the result regardless of +possible future modifications of all this semantics, it is recommended to specify all of ksize, +sigmaX, and sigmaY. +@param borderType pixel extrapolation method, see #BorderTypes + +@sa sepFilter2D, filter2D, blur, boxFilter, bilateralFilter, medianBlur + */ +CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize, + double sigmaX, double sigmaY = 0, + int borderType = BORDER_DEFAULT ); + +/** @brief Applies the bilateral filter to an image. + +The function applies bilateral filtering to the input image, as described in +http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html +bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is +very slow compared to most filters. + +_Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\< +10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very +strong effect, making the image look "cartoonish". + +_Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time +applications, and perhaps d=9 for offline applications that need heavy noise filtering. + +This filter does not work inplace. +@param src Source 8-bit or floating-point, 1-channel or 3-channel image. +@param dst Destination image of the same size and type as src . +@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, +it is computed from sigmaSpace. +@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that +farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting +in larger areas of semi-equal color. +@param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that +farther pixels will influence each other as long as their colors are close enough (see sigmaColor +). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is +proportional to sigmaSpace. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes + */ +CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d, + double sigmaColor, double sigmaSpace, + int borderType = BORDER_DEFAULT ); + +/** @brief Blurs an image using the box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \end{bmatrix}\f] + +where + +\f[\alpha = \fork{\frac{1}{\texttt{ksize.width*ksize.height}}}{when \texttt{normalize=true}}{1}{otherwise}\f] + +Unnormalized box filter is useful for computing various integral characteristics over each pixel +neighborhood, such as covariance matrices of image derivatives (used in dense optical flow +algorithms, and so on). If you need to compute pixel sums over variable-size windows, use #integral. + +@param src input image. +@param dst output image of the same size and type as src. +@param ddepth the output image depth (-1 to use src.depth()). +@param ksize blurring kernel size. +@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel +center. +@param normalize flag, specifying whether the kernel is normalized by its area or not. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes +@sa blur, bilateralFilter, GaussianBlur, medianBlur, integral + */ +CV_EXPORTS_W void boxFilter( InputArray src, OutputArray dst, int ddepth, + Size ksize, Point anchor = Point(-1,-1), + bool normalize = true, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates the normalized sum of squares of the pixel values overlapping the filter. + +For every pixel \f$ (x, y) \f$ in the source image, the function calculates the sum of squares of those neighboring +pixel values which overlap the filter placed over the pixel \f$ (x, y) \f$. + +The unnormalized square box filter can be useful in computing local image statistics such as the the local +variance and standard deviation around the neighborhood of a pixel. + +@param src input image +@param dst output image of the same size and type as _src +@param ddepth the output image depth (-1 to use src.depth()) +@param ksize kernel size +@param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel +center. +@param normalize flag, specifying whether the kernel is to be normalized by it's area or not. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes +@sa boxFilter +*/ +CV_EXPORTS_W void sqrBoxFilter( InputArray src, OutputArray dst, int ddepth, + Size ksize, Point anchor = Point(-1, -1), + bool normalize = true, + int borderType = BORDER_DEFAULT ); + +/** @brief Blurs an image using the normalized box filter. + +The function smooths an image using the kernel: + +\f[\texttt{K} = \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \end{bmatrix}\f] + +The call `blur(src, dst, ksize, anchor, borderType)` is equivalent to `boxFilter(src, dst, src.type(), +anchor, true, borderType)`. + +@param src input image; it can have any number of channels, which are processed independently, but +the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param ksize blurring kernel size. +@param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel +center. +@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes +@sa boxFilter, bilateralFilter, GaussianBlur, medianBlur + */ +CV_EXPORTS_W void blur( InputArray src, OutputArray dst, + Size ksize, Point anchor = Point(-1,-1), + int borderType = BORDER_DEFAULT ); + +/** @brief Convolves an image with the kernel. + +The function applies an arbitrary linear filter to an image. In-place operation is supported. When +the aperture is partially outside the image, the function interpolates outlier pixel values +according to the specified border mode. + +The function does actually compute correlation, not the convolution: + +\f[\texttt{dst} (x,y) = \sum _{ \stackrel{0\leq x' < \texttt{kernel.cols},}{0\leq y' < \texttt{kernel.rows}} } \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )\f] + +That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip +the kernel using #flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows - +anchor.y - 1)`. + +The function uses the DFT-based algorithm in case of sufficiently large kernels (~`11 x 11` or +larger) and the direct algorithm for small kernels. + +@param src input image. +@param dst output image of the same size and the same number of channels as src. +@param ddepth desired depth of the destination image, see @ref filter_depths "combinations" +@param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point +matrix; if you want to apply different kernels to different channels, split the image into +separate color planes using split and process them individually. +@param anchor anchor of the kernel that indicates the relative position of a filtered point within +the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor +is at the kernel center. +@param delta optional value added to the filtered pixels before storing them in dst. +@param borderType pixel extrapolation method, see #BorderTypes +@sa sepFilter2D, dft, matchTemplate + */ +CV_EXPORTS_W void filter2D( InputArray src, OutputArray dst, int ddepth, + InputArray kernel, Point anchor = Point(-1,-1), + double delta = 0, int borderType = BORDER_DEFAULT ); + +/** @brief Applies a separable linear filter to an image. + +The function applies a separable linear filter to the image. That is, first, every row of src is +filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D +kernel kernelY. The final result shifted by delta is stored in dst . + +@param src Source image. +@param dst Destination image of the same size and the same number of channels as src . +@param ddepth Destination image depth, see @ref filter_depths "combinations" +@param kernelX Coefficients for filtering each row. +@param kernelY Coefficients for filtering each column. +@param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor +is at the kernel center. +@param delta Value added to the filtered results before storing them. +@param borderType Pixel extrapolation method, see #BorderTypes +@sa filter2D, Sobel, GaussianBlur, boxFilter, blur + */ +CV_EXPORTS_W void sepFilter2D( InputArray src, OutputArray dst, int ddepth, + InputArray kernelX, InputArray kernelY, + Point anchor = Point(-1,-1), + double delta = 0, int borderType = BORDER_DEFAULT ); + +/** @example samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp +Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector +![Sample screenshot](Sobel_Derivatives_Tutorial_Result.jpg) +Check @ref tutorial_sobel_derivatives "the corresponding tutorial" for more details +*/ + +/** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. + +In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to +calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$ +kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first +or the second x- or y- derivatives. + +There is also the special value `ksize = #FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr +filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is + +\f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f] + +for the x-derivative, or transposed for the y-derivative. + +The function calculates an image derivative by convolving the image with the appropriate kernel: + +\f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f] + +The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less +resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) +or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first +case corresponds to a kernel of: + +\f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f] + +The second case corresponds to a kernel of: + +\f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f] + +@param src input image. +@param dst output image of the same size and the same number of channels as src . +@param ddepth output image depth, see @ref filter_depths "combinations"; in the case of + 8-bit input images it will result in truncated derivatives. +@param dx order of the derivative x. +@param dy order of the derivative y. +@param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see #getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see #BorderTypes +@sa Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar + */ +CV_EXPORTS_W void Sobel( InputArray src, OutputArray dst, int ddepth, + int dx, int dy, int ksize = 3, + double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates the first order image derivative in both x and y using a Sobel operator + +Equivalent to calling: + +@code +Sobel( src, dx, CV_16SC1, 1, 0, 3 ); +Sobel( src, dy, CV_16SC1, 0, 1, 3 ); +@endcode + +@param src input image. +@param dx output image with first-order derivative in x. +@param dy output image with first-order derivative in y. +@param ksize size of Sobel kernel. It must be 3. +@param borderType pixel extrapolation method, see #BorderTypes + +@sa Sobel + */ + +CV_EXPORTS_W void spatialGradient( InputArray src, OutputArray dx, + OutputArray dy, int ksize = 3, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates the first x- or y- image derivative using Scharr operator. + +The function computes the first x- or y- spatial image derivative using the Scharr operator. The +call + +\f[\texttt{Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType)}\f] + +is equivalent to + +\f[\texttt{Sobel(src, dst, ddepth, dx, dy, FILTER_SCHARR, scale, delta, borderType)} .\f] + +@param src input image. +@param dst output image of the same size and the same number of channels as src. +@param ddepth output image depth, see @ref filter_depths "combinations" +@param dx order of the derivative x. +@param dy order of the derivative y. +@param scale optional scale factor for the computed derivative values; by default, no scaling is +applied (see #getDerivKernels for details). +@param delta optional delta value that is added to the results prior to storing them in dst. +@param borderType pixel extrapolation method, see #BorderTypes +@sa cartToPolar + */ +CV_EXPORTS_W void Scharr( InputArray src, OutputArray dst, int ddepth, + int dx, int dy, double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT ); + +/** @example samples/cpp/laplace.cpp +An example using Laplace transformations for edge detection +*/ + +/** @brief Calculates the Laplacian of an image. + +The function calculates the Laplacian of the source image by adding up the second x and y +derivatives calculated using the Sobel operator: + +\f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f] + +This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image +with the following \f$3 \times 3\f$ aperture: + +\f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f] + +@param src Source image. +@param dst Destination image of the same size and the same number of channels as src . +@param ddepth Desired depth of the destination image. +@param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for +details. The size must be positive and odd. +@param scale Optional scale factor for the computed Laplacian values. By default, no scaling is +applied. See #getDerivKernels for details. +@param delta Optional delta value that is added to the results prior to storing them in dst . +@param borderType Pixel extrapolation method, see #BorderTypes +@sa Sobel, Scharr + */ +CV_EXPORTS_W void Laplacian( InputArray src, OutputArray dst, int ddepth, + int ksize = 1, double scale = 1, double delta = 0, + int borderType = BORDER_DEFAULT ); + +//! @} imgproc_filter + +//! @addtogroup imgproc_feature +//! @{ + +/** @example samples/cpp/edge.cpp +This program demonstrates usage of the Canny edge detector + +Check @ref tutorial_canny_detector "the corresponding tutorial" for more details +*/ + +/** @brief Finds edges in an image using the Canny algorithm @cite Canny86 . + +The function finds edges in the input image and marks them in the output map edges using the +Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The +largest value is used to find initial segments of strong edges. See + + +@param image 8-bit input image. +@param edges output edge map; single channels 8-bit image, which has the same size as image . +@param threshold1 first threshold for the hysteresis procedure. +@param threshold2 second threshold for the hysteresis procedure. +@param apertureSize aperture size for the Sobel operator. +@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm +\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude ( +L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( +L2gradient=false ). + */ +CV_EXPORTS_W void Canny( InputArray image, OutputArray edges, + double threshold1, double threshold2, + int apertureSize = 3, bool L2gradient = false ); + +/** \overload + +Finds edges in an image using the Canny algorithm with custom image gradient. + +@param dx 16-bit x derivative of input image (CV_16SC1 or CV_16SC3). +@param dy 16-bit y derivative of input image (same type as dx). +@param edges output edge map; single channels 8-bit image, which has the same size as image . +@param threshold1 first threshold for the hysteresis procedure. +@param threshold2 second threshold for the hysteresis procedure. +@param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm +\f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude ( +L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough ( +L2gradient=false ). + */ +CV_EXPORTS_W void Canny( InputArray dx, InputArray dy, + OutputArray edges, + double threshold1, double threshold2, + bool L2gradient = false ); + +/** @brief Calculates the minimal eigenvalue of gradient matrices for corner detection. + +The function is similar to cornerEigenValsAndVecs but it calculates and stores only the minimal +eigenvalue of the covariance matrix of derivatives, that is, \f$\min(\lambda_1, \lambda_2)\f$ in terms +of the formulae in the cornerEigenValsAndVecs description. + +@param src Input single-channel 8-bit or floating-point image. +@param dst Image to store the minimal eigenvalues. It has the type CV_32FC1 and the same size as +src . +@param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ). +@param ksize Aperture parameter for the Sobel operator. +@param borderType Pixel extrapolation method. See #BorderTypes. + */ +CV_EXPORTS_W void cornerMinEigenVal( InputArray src, OutputArray dst, + int blockSize, int ksize = 3, + int borderType = BORDER_DEFAULT ); + +/** @brief Harris corner detector. + +The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and +cornerEigenValsAndVecs , for each pixel \f$(x, y)\f$ it calculates a \f$2\times2\f$ gradient covariance +matrix \f$M^{(x,y)}\f$ over a \f$\texttt{blockSize} \times \texttt{blockSize}\f$ neighborhood. Then, it +computes the following characteristic: + +\f[\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2\f] + +Corners in the image can be found as the local maxima of this response map. + +@param src Input single-channel 8-bit or floating-point image. +@param dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same +size as src . +@param blockSize Neighborhood size (see the details on #cornerEigenValsAndVecs ). +@param ksize Aperture parameter for the Sobel operator. +@param k Harris detector free parameter. See the formula above. +@param borderType Pixel extrapolation method. See #BorderTypes. + */ +CV_EXPORTS_W void cornerHarris( InputArray src, OutputArray dst, int blockSize, + int ksize, double k, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates eigenvalues and eigenvectors of image blocks for corner detection. + +For every pixel \f$p\f$ , the function cornerEigenValsAndVecs considers a blockSize \f$\times\f$ blockSize +neighborhood \f$S(p)\f$ . It calculates the covariation matrix of derivatives over the neighborhood as: + +\f[M = \begin{bmatrix} \sum _{S(p)}(dI/dx)^2 & \sum _{S(p)}dI/dx dI/dy \\ \sum _{S(p)}dI/dx dI/dy & \sum _{S(p)}(dI/dy)^2 \end{bmatrix}\f] + +where the derivatives are computed using the Sobel operator. + +After that, it finds eigenvectors and eigenvalues of \f$M\f$ and stores them in the destination image as +\f$(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)\f$ where + +- \f$\lambda_1, \lambda_2\f$ are the non-sorted eigenvalues of \f$M\f$ +- \f$x_1, y_1\f$ are the eigenvectors corresponding to \f$\lambda_1\f$ +- \f$x_2, y_2\f$ are the eigenvectors corresponding to \f$\lambda_2\f$ + +The output of the function can be used for robust edge or corner detection. + +@param src Input single-channel 8-bit or floating-point image. +@param dst Image to store the results. It has the same size as src and the type CV_32FC(6) . +@param blockSize Neighborhood size (see details below). +@param ksize Aperture parameter for the Sobel operator. +@param borderType Pixel extrapolation method. See #BorderTypes. + +@sa cornerMinEigenVal, cornerHarris, preCornerDetect + */ +CV_EXPORTS_W void cornerEigenValsAndVecs( InputArray src, OutputArray dst, + int blockSize, int ksize, + int borderType = BORDER_DEFAULT ); + +/** @brief Calculates a feature map for corner detection. + +The function calculates the complex spatial derivative-based function of the source image + +\f[\texttt{dst} = (D_x \texttt{src} )^2 \cdot D_{yy} \texttt{src} + (D_y \texttt{src} )^2 \cdot D_{xx} \texttt{src} - 2 D_x \texttt{src} \cdot D_y \texttt{src} \cdot D_{xy} \texttt{src}\f] + +where \f$D_x\f$,\f$D_y\f$ are the first image derivatives, \f$D_{xx}\f$,\f$D_{yy}\f$ are the second image +derivatives, and \f$D_{xy}\f$ is the mixed derivative. + +The corners can be found as local maximums of the functions, as shown below: +@code + Mat corners, dilated_corners; + preCornerDetect(image, corners, 3); + // dilation with 3x3 rectangular structuring element + dilate(corners, dilated_corners, Mat(), 1); + Mat corner_mask = corners == dilated_corners; +@endcode + +@param src Source single-channel 8-bit of floating-point image. +@param dst Output image that has the type CV_32F and the same size as src . +@param ksize %Aperture size of the Sobel . +@param borderType Pixel extrapolation method. See #BorderTypes. + */ +CV_EXPORTS_W void preCornerDetect( InputArray src, OutputArray dst, int ksize, + int borderType = BORDER_DEFAULT ); + +/** @brief Refines the corner locations. + +The function iterates to find the sub-pixel accurate location of corners or radial saddle points, as +shown on the figure below. + +![image](pics/cornersubpix.png) + +Sub-pixel accurate corner locator is based on the observation that every vector from the center \f$q\f$ +to a point \f$p\f$ located within a neighborhood of \f$q\f$ is orthogonal to the image gradient at \f$p\f$ +subject to image and measurement noise. Consider the expression: + +\f[\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)\f] + +where \f${DI_{p_i}}\f$ is an image gradient at one of the points \f$p_i\f$ in a neighborhood of \f$q\f$ . The +value of \f$q\f$ is to be found so that \f$\epsilon_i\f$ is minimized. A system of equations may be set up +with \f$\epsilon_i\f$ set to zero: + +\f[\sum _i(DI_{p_i} \cdot {DI_{p_i}}^T) \cdot q - \sum _i(DI_{p_i} \cdot {DI_{p_i}}^T \cdot p_i)\f] + +where the gradients are summed within a neighborhood ("search window") of \f$q\f$ . Calling the first +gradient term \f$G\f$ and the second gradient term \f$b\f$ gives: + +\f[q = G^{-1} \cdot b\f] + +The algorithm sets the center of the neighborhood window at this new center \f$q\f$ and then iterates +until the center stays within a set threshold. + +@param image Input single-channel, 8-bit or float image. +@param corners Initial coordinates of the input corners and refined coordinates provided for +output. +@param winSize Half of the side length of the search window. For example, if winSize=Size(5,5) , +then a \f$(5*2+1) \times (5*2+1) = 11 \times 11\f$ search window is used. +@param zeroZone Half of the size of the dead region in the middle of the search zone over which +the summation in the formula below is not done. It is used sometimes to avoid possible +singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such +a size. +@param criteria Criteria for termination of the iterative process of corner refinement. That is, +the process of corner position refinement stops either after criteria.maxCount iterations or when +the corner position moves by less than criteria.epsilon on some iteration. + */ +CV_EXPORTS_W void cornerSubPix( InputArray image, InputOutputArray corners, + Size winSize, Size zeroZone, + TermCriteria criteria ); + +/** @brief Determines strong corners on an image. + +The function finds the most prominent corners in the image or in the specified image region, as +described in @cite Shi94 + +- Function calculates the corner quality measure at every source image pixel using the + #cornerMinEigenVal or #cornerHarris . +- Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are + retained). +- The corners with the minimal eigenvalue less than + \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected. +- The remaining corners are sorted by the quality measure in the descending order. +- Function throws away each corner for which there is a stronger corner at a distance less than + maxDistance. + +The function can be used to initialize a point-based tracker of an object. + +@note If the function is called with different values A and B of the parameter qualityLevel , and +A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector +with qualityLevel=B . + +@param image Input 8-bit or floating-point 32-bit, single-channel image. +@param corners Output vector of detected corners. +@param maxCorners Maximum number of corners to return. If there are more corners than are found, +the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set +and all detected corners are returned. +@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The +parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue +(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the +quality measure less than the product are rejected. For example, if the best corner has the +quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure +less than 15 are rejected. +@param minDistance Minimum possible Euclidean distance between the returned corners. +@param mask Optional region of interest. If the image is not empty (it needs to have the type +CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected. +@param blockSize Size of an average block for computing a derivative covariation matrix over each +pixel neighborhood. See cornerEigenValsAndVecs . +@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris) +or #cornerMinEigenVal. +@param k Free parameter of the Harris detector. + +@sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform, + */ + +CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, + int maxCorners, double qualityLevel, double minDistance, + InputArray mask = noArray(), int blockSize = 3, + bool useHarrisDetector = false, double k = 0.04 ); + +CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners, + int maxCorners, double qualityLevel, double minDistance, + InputArray mask, int blockSize, + int gradientSize, bool useHarrisDetector = false, + double k = 0.04 ); +/** @example samples/cpp/tutorial_code/ImgTrans/houghlines.cpp +An example using the Hough line detector +![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg) +*/ + +/** @brief Finds lines in a binary image using the standard Hough transform. + +The function implements the standard or standard multi-scale Hough transform algorithm for line +detection. See for a good explanation of Hough +transform. + +@param image 8-bit, single-channel binary source image. The image may be modified by the function. +@param lines Output vector of lines. Each line is represented by a 2 or 3 element vector +\f$(\rho, \theta)\f$ or \f$(\rho, \theta, \textrm{votes})\f$ . \f$\rho\f$ is the distance from the coordinate origin \f$(0,0)\f$ (top-left corner of +the image). \f$\theta\f$ is the line rotation angle in radians ( +\f$0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}\f$ ). +\f$\textrm{votes}\f$ is the value of accumulator. +@param rho Distance resolution of the accumulator in pixels. +@param theta Angle resolution of the accumulator in radians. +@param threshold Accumulator threshold parameter. Only those lines are returned that get enough +votes ( \f$>\texttt{threshold}\f$ ). +@param srn For the multi-scale Hough transform, it is a divisor for the distance resolution rho . +The coarse accumulator distance resolution is rho and the accurate accumulator resolution is +rho/srn . If both srn=0 and stn=0 , the classical Hough transform is used. Otherwise, both these +parameters should be positive. +@param stn For the multi-scale Hough transform, it is a divisor for the distance resolution theta. +@param min_theta For standard and multi-scale Hough transform, minimum angle to check for lines. +Must fall between 0 and max_theta. +@param max_theta For standard and multi-scale Hough transform, maximum angle to check for lines. +Must fall between min_theta and CV_PI. + */ +CV_EXPORTS_W void HoughLines( InputArray image, OutputArray lines, + double rho, double theta, int threshold, + double srn = 0, double stn = 0, + double min_theta = 0, double max_theta = CV_PI ); + +/** @brief Finds line segments in a binary image using the probabilistic Hough transform. + +The function implements the probabilistic Hough transform algorithm for line detection, described +in @cite Matas00 + +See the line detection example below: +@include snippets/imgproc_HoughLinesP.cpp +This is a sample picture the function parameters have been tuned for: + +![image](pics/building.jpg) + +And this is the output of the above program in case of the probabilistic Hough transform: + +![image](pics/houghp.png) + +@param image 8-bit, single-channel binary source image. The image may be modified by the function. +@param lines Output vector of lines. Each line is represented by a 4-element vector +\f$(x_1, y_1, x_2, y_2)\f$ , where \f$(x_1,y_1)\f$ and \f$(x_2, y_2)\f$ are the ending points of each detected +line segment. +@param rho Distance resolution of the accumulator in pixels. +@param theta Angle resolution of the accumulator in radians. +@param threshold Accumulator threshold parameter. Only those lines are returned that get enough +votes ( \f$>\texttt{threshold}\f$ ). +@param minLineLength Minimum line length. Line segments shorter than that are rejected. +@param maxLineGap Maximum allowed gap between points on the same line to link them. + +@sa LineSegmentDetector + */ +CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines, + double rho, double theta, int threshold, + double minLineLength = 0, double maxLineGap = 0 ); + +/** @brief Finds lines in a set of points using the standard Hough transform. + +The function finds lines in a set of points using a modification of the Hough transform. +@include snippets/imgproc_HoughLinesPointSet.cpp +@param _point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2. +@param _lines Output vector of found lines. Each vector is encoded as a vector \f$(votes, rho, theta)\f$. +The larger the value of 'votes', the higher the reliability of the Hough line. +@param lines_max Max count of hough lines. +@param threshold Accumulator threshold parameter. Only those lines are returned that get enough +votes ( \f$>\texttt{threshold}\f$ ) +@param min_rho Minimum Distance value of the accumulator in pixels. +@param max_rho Maximum Distance value of the accumulator in pixels. +@param rho_step Distance resolution of the accumulator in pixels. +@param min_theta Minimum angle value of the accumulator in radians. +@param max_theta Maximum angle value of the accumulator in radians. +@param theta_step Angle resolution of the accumulator in radians. + */ +CV_EXPORTS_W void HoughLinesPointSet( InputArray _point, OutputArray _lines, int lines_max, int threshold, + double min_rho, double max_rho, double rho_step, + double min_theta, double max_theta, double theta_step ); + +/** @example samples/cpp/tutorial_code/ImgTrans/houghcircles.cpp +An example using the Hough circle detector +*/ + +/** @brief Finds circles in a grayscale image using the Hough transform. + +The function finds circles in a grayscale image using a modification of the Hough transform. + +Example: : +@include snippets/imgproc_HoughLinesCircles.cpp + +@note Usually the function detects the centers of circles well. However, it may fail to find correct +radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if +you know it. Or, you may set maxRadius to a negative number to return centers only without radius +search, and find the correct radius using an additional procedure. + +@param image 8-bit, single-channel, grayscale input image. +@param circles Output vector of found circles. Each vector is encoded as 3 or 4 element +floating-point vector \f$(x, y, radius)\f$ or \f$(x, y, radius, votes)\f$ . +@param method Detection method, see #HoughModes. Currently, the only implemented method is #HOUGH_GRADIENT +@param dp Inverse ratio of the accumulator resolution to the image resolution. For example, if +dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has +half as big width and height. +@param minDist Minimum distance between the centers of the detected circles. If the parameter is +too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is +too large, some circles may be missed. +@param param1 First method-specific parameter. In case of #HOUGH_GRADIENT , it is the higher +threshold of the two passed to the Canny edge detector (the lower one is twice smaller). +@param param2 Second method-specific parameter. In case of #HOUGH_GRADIENT , it is the +accumulator threshold for the circle centers at the detection stage. The smaller it is, the more +false circles may be detected. Circles, corresponding to the larger accumulator values, will be +returned first. +@param minRadius Minimum circle radius. +@param maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, returns +centers without finding the radius. + +@sa fitEllipse, minEnclosingCircle + */ +CV_EXPORTS_W void HoughCircles( InputArray image, OutputArray circles, + int method, double dp, double minDist, + double param1 = 100, double param2 = 100, + int minRadius = 0, int maxRadius = 0 ); + +//! @} imgproc_feature + +//! @addtogroup imgproc_filter +//! @{ + +/** @example samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp +Advanced morphology Transformations sample code +![Sample screenshot](Morphology_2_Tutorial_Result.jpg) +Check @ref tutorial_opening_closing_hats "the corresponding tutorial" for more details +*/ + +/** @brief Erodes an image by using a specific structuring element. + +The function erodes the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the minimum is taken: + +\f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +The function supports the in-place mode. Erosion can be applied several ( iterations ) times. In +case of multi-channel images, each channel is processed independently. + +@param src input image; the number of channels can be arbitrary, but the depth should be one of +CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular +structuring element is used. Kernel can be created using #getStructuringElement. +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times erosion is applied. +@param borderType pixel extrapolation method, see #BorderTypes +@param borderValue border value in case of a constant border +@sa dilate, morphologyEx, getStructuringElement + */ +CV_EXPORTS_W void erode( InputArray src, OutputArray dst, InputArray kernel, + Point anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue() ); + +/** @example samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp +Erosion and Dilation sample code +![Sample Screenshot-Erosion](Morphology_1_Tutorial_Erosion_Result.jpg)![Sample Screenshot-Dilation](Morphology_1_Tutorial_Dilation_Result.jpg) +Check @ref tutorial_erosion_dilatation "the corresponding tutorial" for more details +*/ + +/** @brief Dilates an image by using a specific structuring element. + +The function dilates the source image using the specified structuring element that determines the +shape of a pixel neighborhood over which the maximum is taken: +\f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f] + +The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In +case of multi-channel images, each channel is processed independently. + +@param src input image; the number of channels can be arbitrary, but the depth should be one of +CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst output image of the same size and type as src. +@param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular +structuring element is used. Kernel can be created using #getStructuringElement +@param anchor position of the anchor within the element; default value (-1, -1) means that the +anchor is at the element center. +@param iterations number of times dilation is applied. +@param borderType pixel extrapolation method, see #BorderTypes +@param borderValue border value in case of a constant border +@sa erode, morphologyEx, getStructuringElement + */ +CV_EXPORTS_W void dilate( InputArray src, OutputArray dst, InputArray kernel, + Point anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue() ); + +/** @brief Performs advanced morphological transformations. + +The function cv::morphologyEx can perform advanced morphological transformations using an erosion and dilation as +basic operations. + +Any of the operations can be done in-place. In case of multi-channel images, each channel is +processed independently. + +@param src Source image. The number of channels can be arbitrary. The depth should be one of +CV_8U, CV_16U, CV_16S, CV_32F or CV_64F. +@param dst Destination image of the same size and type as source image. +@param op Type of a morphological operation, see #MorphTypes +@param kernel Structuring element. It can be created using #getStructuringElement. +@param anchor Anchor position with the kernel. Negative values mean that the anchor is at the +kernel center. +@param iterations Number of times erosion and dilation are applied. +@param borderType Pixel extrapolation method, see #BorderTypes +@param borderValue Border value in case of a constant border. The default value has a special +meaning. +@sa dilate, erode, getStructuringElement +@note The number of iterations is the number of times erosion or dilatation operation will be applied. +For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to apply +successively: erode -> erode -> dilate -> dilate (and not erode -> dilate -> erode -> dilate). + */ +CV_EXPORTS_W void morphologyEx( InputArray src, OutputArray dst, + int op, InputArray kernel, + Point anchor = Point(-1,-1), int iterations = 1, + int borderType = BORDER_CONSTANT, + const Scalar& borderValue = morphologyDefaultBorderValue() ); + +//! @} imgproc_filter + +//! @addtogroup imgproc_transform +//! @{ + +/** @brief Resizes an image. + +The function resize resizes the image src down to or up to the specified size. Note that the +initial dst type or size are not taken into account. Instead, the size and type are derived from +the `src`,`dsize`,`fx`, and `fy`. If you want to resize src so that it fits the pre-created dst, +you may call the function as follows: +@code + // explicitly specify dsize=dst.size(); fx and fy will be computed from that. + resize(src, dst, dst.size(), 0, 0, interpolation); +@endcode +If you want to decimate the image by factor of 2 in each direction, you can call the function this +way: +@code + // specify fx and fy and let the function compute the destination image size. + resize(src, dst, Size(), 0.5, 0.5, interpolation); +@endcode +To shrink an image, it will generally look best with #INTER_AREA interpolation, whereas to +enlarge an image, it will generally look best with c#INTER_CUBIC (slow) or #INTER_LINEAR +(faster but still looks OK). + +@param src input image. +@param dst output image; it has the size dsize (when it is non-zero) or the size computed from +src.size(), fx, and fy; the type of dst is the same as of src. +@param dsize output image size; if it equals zero, it is computed as: + \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f] + Either dsize or both fx and fy must be non-zero. +@param fx scale factor along the horizontal axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.width/src.cols}\f] +@param fy scale factor along the vertical axis; when it equals 0, it is computed as +\f[\texttt{(double)dsize.height/src.rows}\f] +@param interpolation interpolation method, see #InterpolationFlags + +@sa warpAffine, warpPerspective, remap + */ +CV_EXPORTS_W void resize( InputArray src, OutputArray dst, + Size dsize, double fx = 0, double fy = 0, + int interpolation = INTER_LINEAR ); + +/** @brief Applies an affine transformation to an image. + +The function warpAffine transforms the source image using the specified matrix: + +\f[\texttt{dst} (x,y) = \texttt{src} ( \texttt{M} _{11} x + \texttt{M} _{12} y + \texttt{M} _{13}, \texttt{M} _{21} x + \texttt{M} _{22} y + \texttt{M} _{23})\f] + +when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted +with #invertAffineTransform and then put in the formula above instead of M. The function cannot +operate in-place. + +@param src input image. +@param dst output image that has the size dsize and the same type as src . +@param M \f$2\times 3\f$ transformation matrix. +@param dsize size of the output image. +@param flags combination of interpolation methods (see #InterpolationFlags) and the optional +flag #WARP_INVERSE_MAP that means that M is the inverse transformation ( +\f$\texttt{dst}\rightarrow\texttt{src}\f$ ). +@param borderMode pixel extrapolation method (see #BorderTypes); when +borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image corresponding to +the "outliers" in the source image are not modified by the function. +@param borderValue value used in case of a constant border; by default, it is 0. + +@sa warpPerspective, resize, remap, getRectSubPix, transform + */ +CV_EXPORTS_W void warpAffine( InputArray src, OutputArray dst, + InputArray M, Size dsize, + int flags = INTER_LINEAR, + int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @example samples/cpp/warpPerspective_demo.cpp +An example program shows using cv::findHomography and cv::warpPerspective for image warping +*/ + +/** @brief Applies a perspective transformation to an image. + +The function warpPerspective transforms the source image using the specified matrix: + +\f[\texttt{dst} (x,y) = \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} , + \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f] + +when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert +and then put in the formula above instead of M. The function cannot operate in-place. + +@param src input image. +@param dst output image that has the size dsize and the same type as src . +@param M \f$3\times 3\f$ transformation matrix. +@param dsize size of the output image. +@param flags combination of interpolation methods (#INTER_LINEAR or #INTER_NEAREST) and the +optional flag #WARP_INVERSE_MAP, that sets M as the inverse transformation ( +\f$\texttt{dst}\rightarrow\texttt{src}\f$ ). +@param borderMode pixel extrapolation method (#BORDER_CONSTANT or #BORDER_REPLICATE). +@param borderValue value used in case of a constant border; by default, it equals 0. + +@sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform + */ +CV_EXPORTS_W void warpPerspective( InputArray src, OutputArray dst, + InputArray M, Size dsize, + int flags = INTER_LINEAR, + int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @brief Applies a generic geometrical transformation to an image. + +The function remap transforms the source image using the specified map: + +\f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f] + +where values of pixels with non-integer coordinates are computed using one of available +interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps +in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in +\f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to +convert from floating to fixed-point representations of a map is that they can yield much faster +(\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x), +cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients. + +This function cannot operate in-place. + +@param src Source image. +@param dst Destination image. It has the same size as map1 and the same type as src . +@param map1 The first map of either (x,y) points or just x values having the type CV_16SC2 , +CV_32FC1, or CV_32FC2. See convertMaps for details on converting a floating point +representation to fixed-point for speed. +@param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map +if map1 is (x,y) points), respectively. +@param interpolation Interpolation method (see #InterpolationFlags). The method #INTER_AREA is +not supported by this function. +@param borderMode Pixel extrapolation method (see #BorderTypes). When +borderMode=#BORDER_TRANSPARENT, it means that the pixels in the destination image that +corresponds to the "outliers" in the source image are not modified by the function. +@param borderValue Value used in case of a constant border. By default, it is 0. +@note +Due to current implementation limitations the size of an input and output images should be less than 32767x32767. + */ +CV_EXPORTS_W void remap( InputArray src, OutputArray dst, + InputArray map1, InputArray map2, + int interpolation, int borderMode = BORDER_CONSTANT, + const Scalar& borderValue = Scalar()); + +/** @brief Converts image transformation maps from one representation to another. + +The function converts a pair of maps for remap from one representation to another. The following +options ( (map1.type(), map2.type()) \f$\rightarrow\f$ (dstmap1.type(), dstmap2.type()) ) are +supported: + +- \f$\texttt{(CV_32FC1, CV_32FC1)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. This is the +most frequently used conversion operation, in which the original floating-point maps (see remap ) +are converted to a more compact and much faster fixed-point representation. The first output array +contains the rounded coordinates and the second array (created only when nninterpolation=false ) +contains indices in the interpolation tables. + +- \f$\texttt{(CV_32FC2)} \rightarrow \texttt{(CV_16SC2, CV_16UC1)}\f$. The same as above but +the original maps are stored in one 2-channel matrix. + +- Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same +as the originals. + +@param map1 The first input map of type CV_16SC2, CV_32FC1, or CV_32FC2 . +@param map2 The second input map of type CV_16UC1, CV_32FC1, or none (empty matrix), +respectively. +@param dstmap1 The first output map that has the type dstmap1type and the same size as src . +@param dstmap2 The second output map. +@param dstmap1type Type of the first output map that should be CV_16SC2, CV_32FC1, or +CV_32FC2 . +@param nninterpolation Flag indicating whether the fixed-point maps are used for the +nearest-neighbor or for a more complex interpolation. + +@sa remap, undistort, initUndistortRectifyMap + */ +CV_EXPORTS_W void convertMaps( InputArray map1, InputArray map2, + OutputArray dstmap1, OutputArray dstmap2, + int dstmap1type, bool nninterpolation = false ); + +/** @brief Calculates an affine matrix of 2D rotation. + +The function calculates the following matrix: + +\f[\begin{bmatrix} \alpha & \beta & (1- \alpha ) \cdot \texttt{center.x} - \beta \cdot \texttt{center.y} \\ - \beta & \alpha & \beta \cdot \texttt{center.x} + (1- \alpha ) \cdot \texttt{center.y} \end{bmatrix}\f] + +where + +\f[\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}\f] + +The transformation maps the rotation center to itself. If this is not the target, adjust the shift. + +@param center Center of the rotation in the source image. +@param angle Rotation angle in degrees. Positive values mean counter-clockwise rotation (the +coordinate origin is assumed to be the top-left corner). +@param scale Isotropic scale factor. + +@sa getAffineTransform, warpAffine, transform + */ +CV_EXPORTS_W Mat getRotationMatrix2D(Point2f center, double angle, double scale); + +/** @sa getRotationMatrix2D */ +CV_EXPORTS Matx23d getRotationMatrix2D_(Point2f center, double angle, double scale); + +inline +Mat getRotationMatrix2D(Point2f center, double angle, double scale) +{ + return Mat(getRotationMatrix2D_(center, angle, scale), true); +} + +/** @brief Calculates an affine transform from three pairs of the corresponding points. + +The function calculates the \f$2 \times 3\f$ matrix of an affine transform so that: + +\f[\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] + +where + +\f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2\f] + +@param src Coordinates of triangle vertices in the source image. +@param dst Coordinates of the corresponding triangle vertices in the destination image. + +@sa warpAffine, transform + */ +CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] ); + +/** @brief Inverts an affine transformation. + +The function computes an inverse affine transformation represented by \f$2 \times 3\f$ matrix M: + +\f[\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}\f] + +The result is also a \f$2 \times 3\f$ matrix of the same type as M. + +@param M Original affine transformation. +@param iM Output reverse affine transformation. + */ +CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM ); + +/** @brief Calculates a perspective transform from four pairs of the corresponding points. + +The function calculates the \f$3 \times 3\f$ matrix of a perspective transform so that: + +\f[\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}\f] + +where + +\f[dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3\f] + +@param src Coordinates of quadrangle vertices in the source image. +@param dst Coordinates of the corresponding quadrangle vertices in the destination image. +@param solveMethod method passed to cv::solve (#DecompTypes) + +@sa findHomography, warpPerspective, perspectiveTransform + */ +CV_EXPORTS_W Mat getPerspectiveTransform(InputArray src, InputArray dst, int solveMethod = DECOMP_LU); + +/** @overload */ +CV_EXPORTS Mat getPerspectiveTransform(const Point2f src[], const Point2f dst[], int solveMethod = DECOMP_LU); + + +CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst ); + +/** @brief Retrieves a pixel rectangle from an image with sub-pixel accuracy. + +The function getRectSubPix extracts pixels from src: + +\f[patch(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)\f] + +where the values of the pixels at non-integer coordinates are retrieved using bilinear +interpolation. Every channel of multi-channel images is processed independently. Also +the image should be a single channel or three channel image. While the center of the +rectangle must be inside the image, parts of the rectangle may be outside. + +@param image Source image. +@param patchSize Size of the extracted patch. +@param center Floating point coordinates of the center of the extracted rectangle within the +source image. The center must be inside the image. +@param patch Extracted patch that has the size patchSize and the same number of channels as src . +@param patchType Depth of the extracted pixels. By default, they have the same depth as src . + +@sa warpAffine, warpPerspective + */ +CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize, + Point2f center, OutputArray patch, int patchType = -1 ); + +/** @example samples/cpp/polar_transforms.cpp +An example using the cv::linearPolar and cv::logPolar operations +*/ + +/** @brief Remaps an image to semilog-polar coordinates space. + +@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags+WARP_POLAR_LOG); + +@internal +Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image d)"): +\f[\begin{array}{l} + dst( \rho , \phi ) = src(x,y) \\ + dst.size() \leftarrow src.size() +\end{array}\f] + +where +\f[\begin{array}{l} + I = (dx,dy) = (x - center.x,y - center.y) \\ + \rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\ + \phi = Kangle \cdot \texttt{angle} (I) \\ +\end{array}\f] + +and +\f[\begin{array}{l} + M = src.cols / log_e(maxRadius) \\ + Kangle = src.rows / 2\Pi \\ +\end{array}\f] + +The function emulates the human "foveal" vision and can be used for fast scale and +rotation-invariant template matching, for object tracking and so forth. +@param src Source image +@param dst Destination image. It will have same size and type as src. +@param center The transformation center; where the output precision is maximal +@param M Magnitude scale parameter. It determines the radius of the bounding circle to transform too. +@param flags A combination of interpolation methods, see #InterpolationFlags + +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. + +@sa cv::linearPolar +@endinternal +*/ +CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst, + Point2f center, double M, int flags ); + +/** @brief Remaps an image to polar coordinates space. + +@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags) + +@internal +Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image c)"): +\f[\begin{array}{l} + dst( \rho , \phi ) = src(x,y) \\ + dst.size() \leftarrow src.size() +\end{array}\f] + +where +\f[\begin{array}{l} + I = (dx,dy) = (x - center.x,y - center.y) \\ + \rho = Kmag \cdot \texttt{magnitude} (I) ,\\ + \phi = angle \cdot \texttt{angle} (I) +\end{array}\f] + +and +\f[\begin{array}{l} + Kx = src.cols / maxRadius \\ + Ky = src.rows / 2\Pi +\end{array}\f] + + +@param src Source image +@param dst Destination image. It will have same size and type as src. +@param center The transformation center; +@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too. +@param flags A combination of interpolation methods, see #InterpolationFlags + +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. + +@sa cv::logPolar +@endinternal +*/ +CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst, + Point2f center, double maxRadius, int flags ); + + +/** \brief Remaps an image to polar or semilog-polar coordinates space + +@anchor polar_remaps_reference_image +![Polar remaps reference](pics/polar_remap_doc.png) + +Transform the source image using the following transformation: +\f[ +dst(\rho , \phi ) = src(x,y) +\f] + +where +\f[ +\begin{array}{l} +\vec{I} = (x - center.x, \;y - center.y) \\ +\phi = Kangle \cdot \texttt{angle} (\vec{I}) \\ +\rho = \left\{\begin{matrix} +Klin \cdot \texttt{magnitude} (\vec{I}) & default \\ +Klog \cdot log_e(\texttt{magnitude} (\vec{I})) & if \; semilog \\ +\end{matrix}\right. +\end{array} +\f] + +and +\f[ +\begin{array}{l} +Kangle = dsize.height / 2\Pi \\ +Klin = dsize.width / maxRadius \\ +Klog = dsize.width / log_e(maxRadius) \\ +\end{array} +\f] + + +\par Linear vs semilog mapping + +Polar mapping can be linear or semi-log. Add one of #WarpPolarMode to `flags` to specify the polar mapping mode. + +Linear is the default mode. + +The semilog mapping emulates the human "foveal" vision that permit very high acuity on the line of sight (central vision) +in contrast to peripheral vision where acuity is minor. + +\par Option on `dsize`: + +- if both values in `dsize <=0 ` (default), +the destination image will have (almost) same area of source bounding circle: +\f[\begin{array}{l} +dsize.area \leftarrow (maxRadius^2 \cdot \Pi) \\ +dsize.width = \texttt{cvRound}(maxRadius) \\ +dsize.height = \texttt{cvRound}(maxRadius \cdot \Pi) \\ +\end{array}\f] + + +- if only `dsize.height <= 0`, +the destination image area will be proportional to the bounding circle area but scaled by `Kx * Kx`: +\f[\begin{array}{l} +dsize.height = \texttt{cvRound}(dsize.width \cdot \Pi) \\ +\end{array} +\f] + +- if both values in `dsize > 0 `, +the destination image will have the given size therefore the area of the bounding circle will be scaled to `dsize`. + + +\par Reverse mapping + +You can get reverse mapping adding #WARP_INVERSE_MAP to `flags` +\snippet polar_transforms.cpp InverseMap + +In addiction, to calculate the original coordinate from a polar mapped coordinate \f$(rho, phi)->(x, y)\f$: +\snippet polar_transforms.cpp InverseCoordinate + +@param src Source image. +@param dst Destination image. It will have same type as src. +@param dsize The destination image size (see description for valid options). +@param center The transformation center. +@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too. +@param flags A combination of interpolation methods, #InterpolationFlags + #WarpPolarMode. + - Add #WARP_POLAR_LINEAR to select linear polar mapping (default) + - Add #WARP_POLAR_LOG to select semilog polar mapping + - Add #WARP_INVERSE_MAP for reverse mapping. +@note +- The function can not operate in-place. +- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees. +- This function uses #remap. Due to current implementation limitations the size of an input and output images should be less than 32767x32767. + +@sa cv::remap +*/ +CV_EXPORTS_W void warpPolar(InputArray src, OutputArray dst, Size dsize, + Point2f center, double maxRadius, int flags); + + +//! @} imgproc_transform + +//! @addtogroup imgproc_misc +//! @{ + +/** @overload */ +CV_EXPORTS_W void integral( InputArray src, OutputArray sum, int sdepth = -1 ); + +/** @overload */ +CV_EXPORTS_AS(integral2) void integral( InputArray src, OutputArray sum, + OutputArray sqsum, int sdepth = -1, int sqdepth = -1 ); + +/** @brief Calculates the integral of an image. + +The function calculates one or more integral images for the source image as follows: + +\f[\texttt{sum} (X,Y) = \sum _{x + +Calculates the cross-power spectrum of two supplied source arrays. The arrays are padded if needed +with getOptimalDFTSize. + +The function performs the following equations: +- First it applies a Hanning window (see ) to each +image to remove possible edge effects. This window is cached until the array size changes to speed +up processing time. +- Next it computes the forward DFTs of each source array: +\f[\mathbf{G}_a = \mathcal{F}\{src_1\}, \; \mathbf{G}_b = \mathcal{F}\{src_2\}\f] +where \f$\mathcal{F}\f$ is the forward DFT. +- It then computes the cross-power spectrum of each frequency domain array: +\f[R = \frac{ \mathbf{G}_a \mathbf{G}_b^*}{|\mathbf{G}_a \mathbf{G}_b^*|}\f] +- Next the cross-correlation is converted back into the time domain via the inverse DFT: +\f[r = \mathcal{F}^{-1}\{R\}\f] +- Finally, it computes the peak location and computes a 5x5 weighted centroid around the peak to +achieve sub-pixel accuracy. +\f[(\Delta x, \Delta y) = \texttt{weightedCentroid} \{\arg \max_{(x, y)}\{r\}\}\f] +- If non-zero, the response parameter is computed as the sum of the elements of r within the 5x5 +centroid around the peak location. It is normalized to a maximum of 1 (meaning there is a single +peak) and will be smaller when there are multiple peaks. + +@param src1 Source floating point array (CV_32FC1 or CV_64FC1) +@param src2 Source floating point array (CV_32FC1 or CV_64FC1) +@param window Floating point array with windowing coefficients to reduce edge effects (optional). +@param response Signal power within the 5x5 centroid around the peak, between 0 and 1 (optional). +@returns detected phase shift (sub-pixel) between the two arrays. + +@sa dft, getOptimalDFTSize, idft, mulSpectrums createHanningWindow + */ +CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, + InputArray window = noArray(), CV_OUT double* response = 0); + +/** @brief This function computes a Hanning window coefficients in two dimensions. + +See (http://en.wikipedia.org/wiki/Hann_function) and (http://en.wikipedia.org/wiki/Window_function) +for more information. + +An example is shown below: +@code + // create hanning window of size 100x100 and type CV_32F + Mat hann; + createHanningWindow(hann, Size(100, 100), CV_32F); +@endcode +@param dst Destination array to place Hann coefficients in +@param winSize The window size specifications (both width and height must be > 1) +@param type Created array type + */ +CV_EXPORTS_W void createHanningWindow(OutputArray dst, Size winSize, int type); + +//! @} imgproc_motion + +//! @addtogroup imgproc_misc +//! @{ + +/** @brief Applies a fixed-level threshold to each array element. + +The function applies fixed-level thresholding to a multiple-channel array. The function is typically +used to get a bi-level (binary) image out of a grayscale image ( #compare could be also used for +this purpose) or for removing a noise, that is, filtering out pixels with too small or too large +values. There are several types of thresholding supported by the function. They are determined by +type parameter. + +Also, the special values #THRESH_OTSU or #THRESH_TRIANGLE may be combined with one of the +above values. In these cases, the function determines the optimal threshold value using the Otsu's +or Triangle algorithm and uses it instead of the specified thresh. + +@note Currently, the Otsu's and Triangle methods are implemented only for 8-bit single-channel images. + +@param src input array (multiple-channel, 8-bit or 32-bit floating point). +@param dst output array of the same size and type and the same number of channels as src. +@param thresh threshold value. +@param maxval maximum value to use with the #THRESH_BINARY and #THRESH_BINARY_INV thresholding +types. +@param type thresholding type (see #ThresholdTypes). +@return the computed threshold value if Otsu's or Triangle methods used. + +@sa adaptiveThreshold, findContours, compare, min, max + */ +CV_EXPORTS_W double threshold( InputArray src, OutputArray dst, + double thresh, double maxval, int type ); + + +/** @brief Applies an adaptive threshold to an array. + +The function transforms a grayscale image to a binary image according to the formulae: +- **THRESH_BINARY** + \f[dst(x,y) = \fork{\texttt{maxValue}}{if \(src(x,y) > T(x,y)\)}{0}{otherwise}\f] +- **THRESH_BINARY_INV** + \f[dst(x,y) = \fork{0}{if \(src(x,y) > T(x,y)\)}{\texttt{maxValue}}{otherwise}\f] +where \f$T(x,y)\f$ is a threshold calculated individually for each pixel (see adaptiveMethod parameter). + +The function can process the image in-place. + +@param src Source 8-bit single-channel image. +@param dst Destination image of the same size and the same type as src. +@param maxValue Non-zero value assigned to the pixels for which the condition is satisfied +@param adaptiveMethod Adaptive thresholding algorithm to use, see #AdaptiveThresholdTypes. +The #BORDER_REPLICATE | #BORDER_ISOLATED is used to process boundaries. +@param thresholdType Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV, +see #ThresholdTypes. +@param blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the +pixel: 3, 5, 7, and so on. +@param C Constant subtracted from the mean or weighted mean (see the details below). Normally, it +is positive but may be zero or negative as well. + +@sa threshold, blur, GaussianBlur + */ +CV_EXPORTS_W void adaptiveThreshold( InputArray src, OutputArray dst, + double maxValue, int adaptiveMethod, + int thresholdType, int blockSize, double C ); + +//! @} imgproc_misc + +//! @addtogroup imgproc_filter +//! @{ + +/** @example samples/cpp/tutorial_code/ImgProc/Pyramids/Pyramids.cpp +An example using pyrDown and pyrUp functions +*/ + +/** @brief Blurs an image and downsamples it. + +By default, size of the output image is computed as `Size((src.cols+1)/2, (src.rows+1)/2)`, but in +any case, the following conditions should be satisfied: + +\f[\begin{array}{l} | \texttt{dstsize.width} *2-src.cols| \leq 2 \\ | \texttt{dstsize.height} *2-src.rows| \leq 2 \end{array}\f] + +The function performs the downsampling step of the Gaussian pyramid construction. First, it +convolves the source image with the kernel: + +\f[\frac{1}{256} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4 & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix}\f] + +Then, it downsamples the image by rejecting even rows and columns. + +@param src input image. +@param dst output image; it has the specified size and the same type as src. +@param dstsize size of the output image. +@param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported) + */ +CV_EXPORTS_W void pyrDown( InputArray src, OutputArray dst, + const Size& dstsize = Size(), int borderType = BORDER_DEFAULT ); + +/** @brief Upsamples an image and then blurs it. + +By default, size of the output image is computed as `Size(src.cols\*2, (src.rows\*2)`, but in any +case, the following conditions should be satisfied: + +\f[\begin{array}{l} | \texttt{dstsize.width} -src.cols*2| \leq ( \texttt{dstsize.width} \mod 2) \\ | \texttt{dstsize.height} -src.rows*2| \leq ( \texttt{dstsize.height} \mod 2) \end{array}\f] + +The function performs the upsampling step of the Gaussian pyramid construction, though it can +actually be used to construct the Laplacian pyramid. First, it upsamples the source image by +injecting even zero rows and columns and then convolves the result with the same kernel as in +pyrDown multiplied by 4. + +@param src input image. +@param dst output image. It has the specified size and the same type as src . +@param dstsize size of the output image. +@param borderType Pixel extrapolation method, see #BorderTypes (only #BORDER_DEFAULT is supported) + */ +CV_EXPORTS_W void pyrUp( InputArray src, OutputArray dst, + const Size& dstsize = Size(), int borderType = BORDER_DEFAULT ); + +/** @brief Constructs the Gaussian pyramid for an image. + +The function constructs a vector of images and builds the Gaussian pyramid by recursively applying +pyrDown to the previously built pyramid layers, starting from `dst[0]==src`. + +@param src Source image. Check pyrDown for the list of supported types. +@param dst Destination vector of maxlevel+1 images of the same type as src. dst[0] will be the +same as src. dst[1] is the next pyramid layer, a smoothed and down-sized src, and so on. +@param maxlevel 0-based index of the last (the smallest) pyramid layer. It must be non-negative. +@param borderType Pixel extrapolation method, see #BorderTypes (#BORDER_CONSTANT isn't supported) + */ +CV_EXPORTS void buildPyramid( InputArray src, OutputArrayOfArrays dst, + int maxlevel, int borderType = BORDER_DEFAULT ); + +//! @} imgproc_filter + +//! @addtogroup imgproc_hist +//! @{ + +/** @example samples/cpp/demhist.cpp +An example for creating histograms of an image +*/ + +/** @brief Calculates a histogram of a set of arrays. + +The function cv::calcHist calculates the histogram of one or more arrays. The elements of a tuple used +to increment a histogram bin are taken from the corresponding input arrays at the same location. The +sample below shows how to compute a 2D Hue-Saturation histogram for a color image. : +@include snippets/imgproc_calcHist.cpp + +@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same +size. Each of them can have an arbitrary number of channels. +@param nimages Number of source images. +@param channels List of the dims channels used to compute the histogram. The first array channels +are numerated from 0 to images[0].channels()-1 , the second array channels are counted from +images[0].channels() to images[0].channels() + images[1].channels()-1, and so on. +@param mask Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size +as images[i] . The non-zero mask elements mark the array elements counted in the histogram. +@param hist Output histogram, which is a dense or sparse dims -dimensional array. +@param dims Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS +(equal to 32 in the current OpenCV version). +@param histSize Array of histogram sizes in each dimension. +@param ranges Array of the dims arrays of the histogram bin boundaries in each dimension. When the +histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower +(inclusive) boundary \f$L_0\f$ of the 0-th histogram bin and the upper (exclusive) boundary +\f$U_{\texttt{histSize}[i]-1}\f$ for the last histogram bin histSize[i]-1 . That is, in case of a +uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform ( +uniform=false ), then each of ranges[i] contains histSize[i]+1 elements: +\f$L_0, U_0=L_1, U_1=L_2, ..., U_{\texttt{histSize[i]}-2}=L_{\texttt{histSize[i]}-1}, U_{\texttt{histSize[i]}-1}\f$ +. The array elements, that are not between \f$L_0\f$ and \f$U_{\texttt{histSize[i]}-1}\f$ , are not +counted in the histogram. +@param uniform Flag indicating whether the histogram is uniform or not (see above). +@param accumulate Accumulation flag. If it is set, the histogram is not cleared in the beginning +when it is allocated. This feature enables you to compute a single histogram from several sets of +arrays, or to update the histogram in time. +*/ +CV_EXPORTS void calcHist( const Mat* images, int nimages, + const int* channels, InputArray mask, + OutputArray hist, int dims, const int* histSize, + const float** ranges, bool uniform = true, bool accumulate = false ); + +/** @overload + +this variant uses %SparseMat for output +*/ +CV_EXPORTS void calcHist( const Mat* images, int nimages, + const int* channels, InputArray mask, + SparseMat& hist, int dims, + const int* histSize, const float** ranges, + bool uniform = true, bool accumulate = false ); + +/** @overload */ +CV_EXPORTS_W void calcHist( InputArrayOfArrays images, + const std::vector& channels, + InputArray mask, OutputArray hist, + const std::vector& histSize, + const std::vector& ranges, + bool accumulate = false ); + +/** @brief Calculates the back projection of a histogram. + +The function cv::calcBackProject calculates the back project of the histogram. That is, similarly to +#calcHist , at each location (x, y) the function collects the values from the selected channels +in the input images and finds the corresponding histogram bin. But instead of incrementing it, the +function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of +statistics, the function computes probability of each element value in respect with the empirical +probability distribution represented by the histogram. See how, for example, you can find and track +a bright-colored object in a scene: + +- Before tracking, show the object to the camera so that it covers almost the whole frame. +Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant +colors in the object. + +- When tracking, calculate a back projection of a hue plane of each input video frame using that +pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make +sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels. + +- Find connected components in the resulting picture and choose, for example, the largest +component. + +This is an approximate algorithm of the CamShift color object tracker. + +@param images Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same +size. Each of them can have an arbitrary number of channels. +@param nimages Number of source images. +@param channels The list of channels used to compute the back projection. The number of channels +must match the histogram dimensionality. The first array channels are numerated from 0 to +images[0].channels()-1 , the second array channels are counted from images[0].channels() to +images[0].channels() + images[1].channels()-1, and so on. +@param hist Input histogram that can be dense or sparse. +@param backProject Destination back projection array that is a single-channel array of the same +size and depth as images[0] . +@param ranges Array of arrays of the histogram bin boundaries in each dimension. See #calcHist . +@param scale Optional scale factor for the output back projection. +@param uniform Flag indicating whether the histogram is uniform or not (see above). + +@sa calcHist, compareHist + */ +CV_EXPORTS void calcBackProject( const Mat* images, int nimages, + const int* channels, InputArray hist, + OutputArray backProject, const float** ranges, + double scale = 1, bool uniform = true ); + +/** @overload */ +CV_EXPORTS void calcBackProject( const Mat* images, int nimages, + const int* channels, const SparseMat& hist, + OutputArray backProject, const float** ranges, + double scale = 1, bool uniform = true ); + +/** @overload */ +CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const std::vector& channels, + InputArray hist, OutputArray dst, + const std::vector& ranges, + double scale ); + +/** @brief Compares two histograms. + +The function cv::compareHist compares two dense or two sparse histograms using the specified method. + +The function returns \f$d(H_1, H_2)\f$ . + +While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable +for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling +problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms +or more general sparse configurations of weighted points, consider using the #EMD function. + +@param H1 First compared histogram. +@param H2 Second compared histogram of the same size as H1 . +@param method Comparison method, see #HistCompMethods + */ +CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method ); + +/** @overload */ +CV_EXPORTS double compareHist( const SparseMat& H1, const SparseMat& H2, int method ); + +/** @brief Equalizes the histogram of a grayscale image. + +The function equalizes the histogram of the input image using the following algorithm: + +- Calculate the histogram \f$H\f$ for src . +- Normalize the histogram so that the sum of histogram bins is 255. +- Compute the integral of the histogram: +\f[H'_i = \sum _{0 \le j < i} H(j)\f] +- Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$ + +The algorithm normalizes the brightness and increases the contrast of the image. + +@param src Source 8-bit single channel image. +@param dst Destination image of the same size and type as src . + */ +CV_EXPORTS_W void equalizeHist( InputArray src, OutputArray dst ); + +/** @brief Creates a smart pointer to a cv::CLAHE class and initializes it. + +@param clipLimit Threshold for contrast limiting. +@param tileGridSize Size of grid for histogram equalization. Input image will be divided into +equally sized rectangular tiles. tileGridSize defines the number of tiles in row and column. + */ +CV_EXPORTS_W Ptr createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8)); + +/** @brief Computes the "minimal work" distance between two weighted point configurations. + +The function computes the earth mover distance and/or a lower boundary of the distance between the +two weighted point configurations. One of the applications described in @cite RubnerSept98, +@cite Rubner2000 is multi-dimensional histogram comparison for image retrieval. EMD is a transportation +problem that is solved using some modification of a simplex algorithm, thus the complexity is +exponential in the worst case, though, on average it is much faster. In the case of a real metric +the lower boundary can be calculated even faster (using linear-time algorithm) and it can be used +to determine roughly whether the two signatures are far enough so that they cannot relate to the +same object. + +@param signature1 First signature, a \f$\texttt{size1}\times \texttt{dims}+1\f$ floating-point matrix. +Each row stores the point weight followed by the point coordinates. The matrix is allowed to have +a single column (weights only) if the user-defined cost matrix is used. The weights must be +non-negative and have at least one non-zero value. +@param signature2 Second signature of the same format as signature1 , though the number of rows +may be different. The total weights may be different. In this case an extra "dummy" point is added +to either signature1 or signature2. The weights must be non-negative and have at least one non-zero +value. +@param distType Used metric. See #DistanceTypes. +@param cost User-defined \f$\texttt{size1}\times \texttt{size2}\f$ cost matrix. Also, if a cost matrix +is used, lower boundary lowerBound cannot be calculated because it needs a metric function. +@param lowerBound Optional input/output parameter: lower boundary of a distance between the two +signatures that is a distance between mass centers. The lower boundary may not be calculated if +the user-defined cost matrix is used, the total weights of point configurations are not equal, or +if the signatures consist of weights only (the signature matrices have a single column). You +**must** initialize \*lowerBound . If the calculated distance between mass centers is greater or +equal to \*lowerBound (it means that the signatures are far enough), the function does not +calculate EMD. In any case \*lowerBound is set to the calculated distance between mass centers on +return. Thus, if you want to calculate both distance between mass centers and EMD, \*lowerBound +should be set to 0. +@param flow Resultant \f$\texttt{size1} \times \texttt{size2}\f$ flow matrix: \f$\texttt{flow}_{i,j}\f$ is +a flow from \f$i\f$ -th point of signature1 to \f$j\f$ -th point of signature2 . + */ +CV_EXPORTS float EMD( InputArray signature1, InputArray signature2, + int distType, InputArray cost=noArray(), + float* lowerBound = 0, OutputArray flow = noArray() ); + +CV_EXPORTS_AS(EMD) float wrapperEMD( InputArray signature1, InputArray signature2, + int distType, InputArray cost=noArray(), + CV_IN_OUT Ptr lowerBound = Ptr(), OutputArray flow = noArray() ); + +//! @} imgproc_hist + +/** @example samples/cpp/watershed.cpp +An example using the watershed algorithm +*/ + +/** @brief Performs a marker-based image segmentation using the watershed algorithm. + +The function implements one of the variants of watershed, non-parametric marker-based segmentation +algorithm, described in @cite Meyer92 . + +Before passing the image to the function, you have to roughly outline the desired regions in the +image markers with positive (\>0) indices. So, every region is represented as one or more connected +components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary +mask using #findContours and #drawContours (see the watershed.cpp demo). The markers are "seeds" of +the future image regions. All the other pixels in markers , whose relation to the outlined regions +is not known and should be defined by the algorithm, should be set to 0's. In the function output, +each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the +regions. + +@note Any two neighbor connected components are not necessarily separated by a watershed boundary +(-1's pixels); for example, they can touch each other in the initial marker image passed to the +function. + +@param image Input 8-bit 3-channel image. +@param markers Input/output 32-bit single-channel image (map) of markers. It should have the same +size as image . + +@sa findContours + +@ingroup imgproc_misc + */ +CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers ); + +//! @addtogroup imgproc_filter +//! @{ + +/** @brief Performs initial step of meanshift segmentation of an image. + +The function implements the filtering stage of meanshift segmentation, that is, the output of the +function is the filtered "posterized" image with color gradients and fine-grain texture flattened. +At every pixel (X,Y) of the input image (or down-sized input image, see below) the function executes +meanshift iterations, that is, the pixel (X,Y) neighborhood in the joint space-color hyperspace is +considered: + +\f[(x,y): X- \texttt{sp} \le x \le X+ \texttt{sp} , Y- \texttt{sp} \le y \le Y+ \texttt{sp} , ||(R,G,B)-(r,g,b)|| \le \texttt{sr}\f] + +where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y), respectively +(though, the algorithm does not depend on the color space used, so any 3-component color space can +be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector +(R',G',B') are found and they act as the neighborhood center on the next iteration: + +\f[(X,Y)~(X',Y'), (R,G,B)~(R',G',B').\f] + +After the iterations over, the color components of the initial pixel (that is, the pixel from where +the iterations started) are set to the final value (average color at the last iteration): + +\f[I(X,Y) <- (R*,G*,B*)\f] + +When maxLevel \> 0, the gaussian pyramid of maxLevel+1 levels is built, and the above procedure is +run on the smallest layer first. After that, the results are propagated to the larger layer and the +iterations are run again only on those pixels where the layer colors differ by more than sr from the +lower-resolution layer of the pyramid. That makes boundaries of color regions sharper. Note that the +results will be actually different from the ones obtained by running the meanshift procedure on the +whole original image (i.e. when maxLevel==0). + +@param src The source 8-bit, 3-channel image. +@param dst The destination image of the same format and the same size as the source. +@param sp The spatial window radius. +@param sr The color window radius. +@param maxLevel Maximum level of the pyramid for the segmentation. +@param termcrit Termination criteria: when to stop meanshift iterations. + */ +CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst, + double sp, double sr, int maxLevel = 1, + TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) ); + +//! @} + +//! @addtogroup imgproc_misc +//! @{ + +/** @example samples/cpp/grabcut.cpp +An example using the GrabCut algorithm +![Sample Screenshot](grabcut_output1.jpg) +*/ + +/** @brief Runs the GrabCut algorithm. + +The function implements the [GrabCut image segmentation algorithm](http://en.wikipedia.org/wiki/GrabCut). + +@param img Input 8-bit 3-channel image. +@param mask Input/output 8-bit single-channel mask. The mask is initialized by the function when +mode is set to #GC_INIT_WITH_RECT. Its elements may have one of the #GrabCutClasses. +@param rect ROI containing a segmented object. The pixels outside of the ROI are marked as +"obvious background". The parameter is only used when mode==#GC_INIT_WITH_RECT . +@param bgdModel Temporary array for the background model. Do not modify it while you are +processing the same image. +@param fgdModel Temporary arrays for the foreground model. Do not modify it while you are +processing the same image. +@param iterCount Number of iterations the algorithm should make before returning the result. Note +that the result can be refined with further calls with mode==#GC_INIT_WITH_MASK or +mode==GC_EVAL . +@param mode Operation mode that could be one of the #GrabCutModes + */ +CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect, + InputOutputArray bgdModel, InputOutputArray fgdModel, + int iterCount, int mode = GC_EVAL ); + +/** @example samples/cpp/distrans.cpp +An example on using the distance transform +*/ + +/** @brief Calculates the distance to the closest zero pixel for each pixel of the source image. + +The function cv::distanceTransform calculates the approximate or precise distance from every binary +image pixel to the nearest zero pixel. For zero image pixels, the distance will obviously be zero. + +When maskSize == #DIST_MASK_PRECISE and distanceType == #DIST_L2 , the function runs the +algorithm described in @cite Felzenszwalb04 . This algorithm is parallelized with the TBB library. + +In other cases, the algorithm @cite Borgefors86 is used. This means that for a pixel the function +finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical, +diagonal, or knight's move (the latest is available for a \f$5\times 5\f$ mask). The overall +distance is calculated as a sum of these basic distances. Since the distance function should be +symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all +the diagonal shifts must have the same cost (denoted as `b`), and all knight's moves must have the +same cost (denoted as `c`). For the #DIST_C and #DIST_L1 types, the distance is calculated +precisely, whereas for #DIST_L2 (Euclidean distance) the distance can be calculated only with a +relative error (a \f$5\times 5\f$ mask gives more accurate results). For `a`,`b`, and `c`, OpenCV +uses the values suggested in the original paper: +- DIST_L1: `a = 1, b = 2` +- DIST_L2: + - `3 x 3`: `a=0.955, b=1.3693` + - `5 x 5`: `a=1, b=1.4, c=2.1969` +- DIST_C: `a = 1, b = 1` + +Typically, for a fast, coarse distance estimation #DIST_L2, a \f$3\times 3\f$ mask is used. For a +more accurate distance estimation #DIST_L2, a \f$5\times 5\f$ mask or the precise algorithm is used. +Note that both the precise and the approximate algorithms are linear on the number of pixels. + +This variant of the function does not only compute the minimum distance for each pixel \f$(x, y)\f$ +but also identifies the nearest connected component consisting of zero pixels +(labelType==#DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==#DIST_LABEL_PIXEL). Index of the +component/pixel is stored in `labels(x, y)`. When labelType==#DIST_LABEL_CCOMP, the function +automatically finds connected components of zero pixels in the input image and marks them with +distinct labels. When labelType==#DIST_LABEL_CCOMP, the function scans through the input image and +marks all the zero pixels with distinct labels. + +In this mode, the complexity is still linear. That is, the function provides a very fast way to +compute the Voronoi diagram for a binary image. Currently, the second variant can use only the +approximate distance transform algorithm, i.e. maskSize=#DIST_MASK_PRECISE is not supported +yet. + +@param src 8-bit, single-channel (binary) source image. +@param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, +single-channel image of the same size as src. +@param labels Output 2D array of labels (the discrete Voronoi diagram). It has the type +CV_32SC1 and the same size as src. +@param distanceType Type of distance, see #DistanceTypes +@param maskSize Size of the distance transform mask, see #DistanceTransformMasks. +#DIST_MASK_PRECISE is not supported by this variant. In case of the #DIST_L1 or #DIST_C distance type, +the parameter is forced to 3 because a \f$3\times 3\f$ mask gives the same result as \f$5\times +5\f$ or any larger aperture. +@param labelType Type of the label array to build, see #DistanceTransformLabelTypes. + */ +CV_EXPORTS_AS(distanceTransformWithLabels) void distanceTransform( InputArray src, OutputArray dst, + OutputArray labels, int distanceType, int maskSize, + int labelType = DIST_LABEL_CCOMP ); + +/** @overload +@param src 8-bit, single-channel (binary) source image. +@param dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, +single-channel image of the same size as src . +@param distanceType Type of distance, see #DistanceTypes +@param maskSize Size of the distance transform mask, see #DistanceTransformMasks. In case of the +#DIST_L1 or #DIST_C distance type, the parameter is forced to 3 because a \f$3\times 3\f$ mask gives +the same result as \f$5\times 5\f$ or any larger aperture. +@param dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for +the first variant of the function and distanceType == #DIST_L1. +*/ +CV_EXPORTS_W void distanceTransform( InputArray src, OutputArray dst, + int distanceType, int maskSize, int dstType=CV_32F); + +/** @example samples/cpp/ffilldemo.cpp +An example using the FloodFill technique +*/ + +/** @overload + +variant without `mask` parameter +*/ +CV_EXPORTS int floodFill( InputOutputArray image, + Point seedPoint, Scalar newVal, CV_OUT Rect* rect = 0, + Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), + int flags = 4 ); + +/** @brief Fills a connected component with the given color. + +The function cv::floodFill fills a connected component starting from the seed point with the specified +color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The +pixel at \f$(x,y)\f$ is considered to belong to the repainted domain if: + +- in case of a grayscale image and floating range +\f[\texttt{src} (x',y')- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} (x',y')+ \texttt{upDiff}\f] + + +- in case of a grayscale image and fixed range +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)+ \texttt{upDiff}\f] + + +- in case of a color image and floating range +\f[\texttt{src} (x',y')_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} (x',y')_r+ \texttt{upDiff} _r,\f] +\f[\texttt{src} (x',y')_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} (x',y')_g+ \texttt{upDiff} _g\f] +and +\f[\texttt{src} (x',y')_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} (x',y')_b+ \texttt{upDiff} _b\f] + + +- in case of a color image and fixed range +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r- \texttt{loDiff} _r \leq \texttt{src} (x,y)_r \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_r+ \texttt{upDiff} _r,\f] +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g- \texttt{loDiff} _g \leq \texttt{src} (x,y)_g \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_g+ \texttt{upDiff} _g\f] +and +\f[\texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} ( \texttt{seedPoint} .x, \texttt{seedPoint} .y)_b+ \texttt{upDiff} _b\f] + + +where \f$src(x',y')\f$ is the value of one of pixel neighbors that is already known to belong to the +component. That is, to be added to the connected component, a color/brightness of the pixel should +be close enough to: +- Color/brightness of one of its neighbors that already belong to the connected component in case +of a floating range. +- Color/brightness of the seed point in case of a fixed range. + +Use these functions to either mark a connected component with the specified color in-place, or build +a mask and then extract the contour, or copy the region to another image, and so on. + +@param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the +function unless the #FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See +the details below. +@param mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels +taller than image. Since this is both an input and output parameter, you must take responsibility +of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, +an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the +mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags +as described below. Additionally, the function fills the border of the mask with ones to simplify +internal processing. It is therefore possible to use the same mask in multiple calls to the function +to make sure the filled areas do not overlap. +@param seedPoint Starting point. +@param newVal New value of the repainted domain pixels. +@param loDiff Maximal lower brightness/color difference between the currently observed pixel and +one of its neighbors belonging to the component, or a seed pixel being added to the component. +@param upDiff Maximal upper brightness/color difference between the currently observed pixel and +one of its neighbors belonging to the component, or a seed pixel being added to the component. +@param rect Optional output parameter set by the function to the minimum bounding rectangle of the +repainted domain. +@param flags Operation flags. The first 8 bits contain a connectivity value. The default value of +4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A +connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) +will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill +the mask (the default value is 1). For example, 4 | ( 255 \<\< 8 ) will consider 4 nearest +neighbours and fill the mask with a value of 255. The following additional options occupy higher +bits and therefore may be further combined with the connectivity and mask fill values using +bit-wise or (|), see #FloodFillFlags. + +@note Since the mask is larger than the filled image, a pixel \f$(x, y)\f$ in image corresponds to the +pixel \f$(x+1, y+1)\f$ in the mask . + +@sa findContours + */ +CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask, + Point seedPoint, Scalar newVal, CV_OUT Rect* rect=0, + Scalar loDiff = Scalar(), Scalar upDiff = Scalar(), + int flags = 4 ); + +//! Performs linear blending of two images: +//! \f[ \texttt{dst}(i,j) = \texttt{weights1}(i,j)*\texttt{src1}(i,j) + \texttt{weights2}(i,j)*\texttt{src2}(i,j) \f] +//! @param src1 It has a type of CV_8UC(n) or CV_32FC(n), where n is a positive integer. +//! @param src2 It has the same type and size as src1. +//! @param weights1 It has a type of CV_32FC1 and the same size with src1. +//! @param weights2 It has a type of CV_32FC1 and the same size with src1. +//! @param dst It is created if it does not have the same size and type with src1. +CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst); + +//! @} imgproc_misc + +//! @addtogroup imgproc_color_conversions +//! @{ + +/** @brief Converts an image from one color space to another. + +The function converts an input image from one color space to another. In case of a transformation +to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note +that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the +bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue +component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and +sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on. + +The conventional ranges for R, G, and B channel values are: +- 0 to 255 for CV_8U images +- 0 to 65535 for CV_16U images +- 0 to 1 for CV_32F images + +In case of linear transformations, the range does not matter. But in case of a non-linear +transformation, an input RGB image should be normalized to the proper value range to get the correct +results, for example, for RGB \f$\rightarrow\f$ L\*u\*v\* transformation. For example, if you have a +32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will +have the 0..255 value range instead of 0..1 assumed by the function. So, before calling #cvtColor , +you need first to scale the image down: +@code + img *= 1./255; + cvtColor(img, img, COLOR_BGR2Luv); +@endcode +If you use #cvtColor with 8-bit images, the conversion will have some information lost. For many +applications, this will not be noticeable but it is recommended to use 32-bit images in applications +that need the full range of colors or that convert an image before an operation and then convert +back. + +If conversion adds the alpha channel, its value will set to the maximum of corresponding channel +range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F. + +@param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision +floating-point. +@param dst output image of the same size and depth as src. +@param code color space conversion code (see #ColorConversionCodes). +@param dstCn number of channels in the destination image; if the parameter is 0, the number of the +channels is derived automatically from src and code. + +@see @ref imgproc_color_conversions + */ +CV_EXPORTS_W void cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 ); + +/** @brief Converts an image from one color space to another where the source image is +stored in two planes. + +This function only supports YUV420 to RGB conversion as of now. + +@param src1: 8-bit image (#CV_8U) of the Y plane. +@param src2: image containing interleaved U/V plane. +@param dst: output image. +@param code: Specifies the type of conversion. It can take any of the following values: +- #COLOR_YUV2BGR_NV12 +- #COLOR_YUV2RGB_NV12 +- #COLOR_YUV2BGRA_NV12 +- #COLOR_YUV2RGBA_NV12 +- #COLOR_YUV2BGR_NV21 +- #COLOR_YUV2RGB_NV21 +- #COLOR_YUV2BGRA_NV21 +- #COLOR_YUV2RGBA_NV21 +*/ +CV_EXPORTS_W void cvtColorTwoPlane( InputArray src1, InputArray src2, OutputArray dst, int code ); + +/** @brief main function for all demosaicing processes + +@param src input image: 8-bit unsigned or 16-bit unsigned. +@param dst output image of the same size and depth as src. +@param code Color space conversion code (see the description below). +@param dstCn number of channels in the destination image; if the parameter is 0, the number of the +channels is derived automatically from src and code. + +The function can do the following transformations: + +- Demosaicing using bilinear interpolation + + #COLOR_BayerBG2BGR , #COLOR_BayerGB2BGR , #COLOR_BayerRG2BGR , #COLOR_BayerGR2BGR + + #COLOR_BayerBG2GRAY , #COLOR_BayerGB2GRAY , #COLOR_BayerRG2GRAY , #COLOR_BayerGR2GRAY + +- Demosaicing using Variable Number of Gradients. + + #COLOR_BayerBG2BGR_VNG , #COLOR_BayerGB2BGR_VNG , #COLOR_BayerRG2BGR_VNG , #COLOR_BayerGR2BGR_VNG + +- Edge-Aware Demosaicing. + + #COLOR_BayerBG2BGR_EA , #COLOR_BayerGB2BGR_EA , #COLOR_BayerRG2BGR_EA , #COLOR_BayerGR2BGR_EA + +- Demosaicing with alpha channel + + #COLOR_BayerBG2BGRA , #COLOR_BayerGB2BGRA , #COLOR_BayerRG2BGRA , #COLOR_BayerGR2BGRA + +@sa cvtColor +*/ +CV_EXPORTS_W void demosaicing(InputArray src, OutputArray dst, int code, int dstCn = 0); + +//! @} imgproc_color_conversions + +//! @addtogroup imgproc_shape +//! @{ + +/** @brief Calculates all of the moments up to the third order of a polygon or rasterized shape. + +The function computes moments, up to the 3rd order, of a vector shape or a rasterized shape. The +results are returned in the structure cv::Moments. + +@param array Raster image (single-channel, 8-bit or floating-point 2D array) or an array ( +\f$1 \times N\f$ or \f$N \times 1\f$ ) of 2D points (Point or Point2f ). +@param binaryImage If it is true, all non-zero image pixels are treated as 1's. The parameter is +used for images only. +@returns moments. + +@note Only applicable to contour moments calculations from Python bindings: Note that the numpy +type for the input array should be either np.int32 or np.float32. + +@sa contourArea, arcLength + */ +CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage = false ); + +/** @brief Calculates seven Hu invariants. + +The function calculates seven Hu invariants (introduced in @cite Hu62; see also +) defined as: + +\f[\begin{array}{l} hu[0]= \eta _{20}+ \eta _{02} \\ hu[1]=( \eta _{20}- \eta _{02})^{2}+4 \eta _{11}^{2} \\ hu[2]=( \eta _{30}-3 \eta _{12})^{2}+ (3 \eta _{21}- \eta _{03})^{2} \\ hu[3]=( \eta _{30}+ \eta _{12})^{2}+ ( \eta _{21}+ \eta _{03})^{2} \\ hu[4]=( \eta _{30}-3 \eta _{12})( \eta _{30}+ \eta _{12})[( \eta _{30}+ \eta _{12})^{2}-3( \eta _{21}+ \eta _{03})^{2}]+(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ hu[5]=( \eta _{20}- \eta _{02})[( \eta _{30}+ \eta _{12})^{2}- ( \eta _{21}+ \eta _{03})^{2}]+4 \eta _{11}( \eta _{30}+ \eta _{12})( \eta _{21}+ \eta _{03}) \\ hu[6]=(3 \eta _{21}- \eta _{03})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}]-( \eta _{30}-3 \eta _{12})( \eta _{21}+ \eta _{03})[3( \eta _{30}+ \eta _{12})^{2}-( \eta _{21}+ \eta _{03})^{2}] \\ \end{array}\f] + +where \f$\eta_{ji}\f$ stands for \f$\texttt{Moments::nu}_{ji}\f$ . + +These values are proved to be invariants to the image scale, rotation, and reflection except the +seventh one, whose sign is changed by reflection. This invariance is proved with the assumption of +infinite image resolution. In case of raster images, the computed Hu invariants for the original and +transformed images are a bit different. + +@param moments Input moments computed with moments . +@param hu Output Hu invariants. + +@sa matchShapes + */ +CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] ); + +/** @overload */ +CV_EXPORTS_W void HuMoments( const Moments& m, OutputArray hu ); + +//! @} imgproc_shape + +//! @addtogroup imgproc_object +//! @{ + +//! type of the template matching operation +enum TemplateMatchModes { + TM_SQDIFF = 0, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2\f] + TM_SQDIFF_NORMED = 1, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] + TM_CCORR = 2, //!< \f[R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))\f] + TM_CCORR_NORMED = 3, //!< \f[R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}\f] + TM_CCOEFF = 4, //!< \f[R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I'(x+x',y+y'))\f] + //!< where + //!< \f[\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}\f] + TM_CCOEFF_NORMED = 5 //!< \f[R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }\f] +}; + +/** @example samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp +An example using Template Matching algorithm +*/ + +/** @brief Compares a template against overlapped image regions. + +The function slides through image , compares the overlapped patches of size \f$w \times h\f$ against +templ using the specified method and stores the comparison results in result . Here are the formulae +for the available comparison methods ( \f$I\f$ denotes image, \f$T\f$ template, \f$R\f$ result ). The summation +is done over template and/or the image patch: \f$x' = 0...w-1, y' = 0...h-1\f$ + +After the function finishes the comparison, the best matches can be found as global minimums (when +#TM_SQDIFF was used) or maximums (when #TM_CCORR or #TM_CCOEFF was used) using the +#minMaxLoc function. In case of a color image, template summation in the numerator and each sum in +the denominator is done over all of the channels and separate mean values are used for each channel. +That is, the function can take a color template and a color image. The result will still be a +single-channel image, which is easier to analyze. + +@param image Image where the search is running. It must be 8-bit or 32-bit floating-point. +@param templ Searched template. It must be not greater than the source image and have the same +data type. +@param result Map of comparison results. It must be single-channel 32-bit floating-point. If image +is \f$W \times H\f$ and templ is \f$w \times h\f$ , then result is \f$(W-w+1) \times (H-h+1)\f$ . +@param method Parameter specifying the comparison method, see #TemplateMatchModes +@param mask Mask of searched template. It must have the same datatype and size with templ. It is +not set by default. Currently, only the #TM_SQDIFF and #TM_CCORR_NORMED methods are supported. + */ +CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ, + OutputArray result, int method, InputArray mask = noArray() ); + +//! @} + +//! @addtogroup imgproc_shape +//! @{ + +/** @example samples/cpp/connected_components.cpp +This program demonstrates connected components and use of the trackbar +*/ + +/** @brief computes the connected components labeled image of boolean image + +image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 +represents the background label. ltype specifies the output label image type, an important +consideration based on the total number of labels or alternatively the total number of pixels in +the source image. ccltype specifies the connected components labeling algorithm to use, currently +Grana (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes +for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. +This function uses parallel version of both Grana and Wu's algorithms if at least one allowed +parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs. + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +@param ccltype connected components algorithm type (see the #ConnectedComponentsAlgorithmsTypes). +*/ +CV_EXPORTS_AS(connectedComponentsWithAlgorithm) int connectedComponents(InputArray image, OutputArray labels, + int connectivity, int ltype, int ccltype); + + +/** @overload + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +*/ +CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels, + int connectivity = 8, int ltype = CV_32S); + + +/** @brief computes the connected components labeled image of boolean image and also produces a statistics output for each label + +image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0 +represents the background label. ltype specifies the output label image type, an important +consideration based on the total number of labels or alternatively the total number of pixels in +the source image. ccltype specifies the connected components labeling algorithm to use, currently +Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes +for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not. +This function uses parallel version of both Grana and Wu's algorithms (statistics included) if at least one allowed +parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs. + +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param stats statistics output for each label, including the background label, see below for +available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of +#ConnectedComponentsTypes. The data type is CV_32S. +@param centroids centroid output for each label, including the background label. Centroids are +accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +@param ccltype connected components algorithm type (see #ConnectedComponentsAlgorithmsTypes). +*/ +CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponentsWithStats(InputArray image, OutputArray labels, + OutputArray stats, OutputArray centroids, + int connectivity, int ltype, int ccltype); + +/** @overload +@param image the 8-bit single-channel image to be labeled +@param labels destination labeled image +@param stats statistics output for each label, including the background label, see below for +available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of +#ConnectedComponentsTypes. The data type is CV_32S. +@param centroids centroid output for each label, including the background label. Centroids are +accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F. +@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively +@param ltype output image label type. Currently CV_32S and CV_16U are supported. +*/ +CV_EXPORTS_W int connectedComponentsWithStats(InputArray image, OutputArray labels, + OutputArray stats, OutputArray centroids, + int connectivity = 8, int ltype = CV_32S); + + +/** @brief Finds contours in a binary image. + +The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours +are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the +OpenCV sample directory. +@note Since opencv 3.2 source image is not modified by this function. + +@param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero +pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold , +#adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one. +If mode equals to #RETR_CCOMP or #RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1). +@param contours Detected contours. Each contour is stored as a vector of points (e.g. +std::vector >). +@param hierarchy Optional output vector (e.g. std::vector), containing information about the image topology. It has +as many elements as the number of contours. For each i-th contour contours[i], the elements +hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices +in contours of the next and previous contours at the same hierarchical level, the first child +contour and the parent contour, respectively. If for the contour i there are no next, previous, +parent, or nested contours, the corresponding elements of hierarchy[i] will be negative. +@param mode Contour retrieval mode, see #RetrievalModes +@param method Contour approximation method, see #ContourApproximationModes +@param offset Optional offset by which every contour point is shifted. This is useful if the +contours are extracted from the image ROI and then they should be analyzed in the whole image +context. + */ +CV_EXPORTS_W void findContours( InputArray image, OutputArrayOfArrays contours, + OutputArray hierarchy, int mode, + int method, Point offset = Point()); + +/** @overload */ +CV_EXPORTS void findContours( InputArray image, OutputArrayOfArrays contours, + int mode, int method, Point offset = Point()); + +/** @example samples/cpp/squares.cpp +A program using pyramid scaling, Canny, contours and contour simplification to find +squares in a list of images (pic1-6.png). Returns sequence of squares detected on the image. +*/ + +/** @example samples/tapi/squares.cpp +A program using pyramid scaling, Canny, contours and contour simplification to find +squares in the input image. +*/ + +/** @brief Approximates a polygonal curve(s) with the specified precision. + +The function cv::approxPolyDP approximates a curve or a polygon with another curve/polygon with less +vertices so that the distance between them is less or equal to the specified precision. It uses the +Douglas-Peucker algorithm + +@param curve Input vector of a 2D point stored in std::vector or Mat +@param approxCurve Result of the approximation. The type should match the type of the input curve. +@param epsilon Parameter specifying the approximation accuracy. This is the maximum distance +between the original curve and its approximation. +@param closed If true, the approximated curve is closed (its first and last vertices are +connected). Otherwise, it is not closed. + */ +CV_EXPORTS_W void approxPolyDP( InputArray curve, + OutputArray approxCurve, + double epsilon, bool closed ); + +/** @brief Calculates a contour perimeter or a curve length. + +The function computes a curve length or a closed contour perimeter. + +@param curve Input vector of 2D points, stored in std::vector or Mat. +@param closed Flag indicating whether the curve is closed or not. + */ +CV_EXPORTS_W double arcLength( InputArray curve, bool closed ); + +/** @brief Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image. + +The function calculates and returns the minimal up-right bounding rectangle for the specified point set or +non-zero pixels of gray-scale image. + +@param array Input gray-scale image or 2D point set, stored in std::vector or Mat. + */ +CV_EXPORTS_W Rect boundingRect( InputArray array ); + +/** @brief Calculates a contour area. + +The function computes a contour area. Similarly to moments , the area is computed using the Green +formula. Thus, the returned area and the number of non-zero pixels, if you draw the contour using +#drawContours or #fillPoly , can be different. Also, the function will most certainly give a wrong +results for contours with self-intersections. + +Example: +@code + vector contour; + contour.push_back(Point2f(0, 0)); + contour.push_back(Point2f(10, 0)); + contour.push_back(Point2f(10, 10)); + contour.push_back(Point2f(5, 4)); + + double area0 = contourArea(contour); + vector approx; + approxPolyDP(contour, approx, 5, true); + double area1 = contourArea(approx); + + cout << "area0 =" << area0 << endl << + "area1 =" << area1 << endl << + "approx poly vertices" << approx.size() << endl; +@endcode +@param contour Input vector of 2D points (contour vertices), stored in std::vector or Mat. +@param oriented Oriented area flag. If it is true, the function returns a signed area value, +depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can +determine orientation of a contour by taking the sign of an area. By default, the parameter is +false, which means that the absolute value is returned. + */ +CV_EXPORTS_W double contourArea( InputArray contour, bool oriented = false ); + +/** @brief Finds a rotated rectangle of the minimum area enclosing the input 2D point set. + +The function calculates and returns the minimum-area bounding rectangle (possibly rotated) for a +specified point set. Developer should keep in mind that the returned RotatedRect can contain negative +indices when data is close to the containing Mat element boundary. + +@param points Input vector of 2D points, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect minAreaRect( InputArray points ); + +/** @brief Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle. + +The function finds the four vertices of a rotated rectangle. This function is useful to draw the +rectangle. In C++, instead of using this function, you can directly use RotatedRect::points method. Please +visit the @ref tutorial_bounding_rotated_ellipses "tutorial on Creating Bounding rotated boxes and ellipses for contours" for more information. + +@param box The input rotated rectangle. It may be the output of +@param points The output array of four vertices of rectangles. + */ +CV_EXPORTS_W void boxPoints(RotatedRect box, OutputArray points); + +/** @brief Finds a circle of the minimum area enclosing a 2D point set. + +The function finds the minimal enclosing circle of a 2D point set using an iterative algorithm. + +@param points Input vector of 2D points, stored in std::vector\<\> or Mat +@param center Output center of the circle. +@param radius Output radius of the circle. + */ +CV_EXPORTS_W void minEnclosingCircle( InputArray points, + CV_OUT Point2f& center, CV_OUT float& radius ); + +/** @example samples/cpp/minarea.cpp +*/ + +/** @brief Finds a triangle of minimum area enclosing a 2D point set and returns its area. + +The function finds a triangle of minimum area enclosing the given set of 2D points and returns its +area. The output for a given 2D point set is shown in the image below. 2D points are depicted in +*red* and the enclosing triangle in *yellow*. + +![Sample output of the minimum enclosing triangle function](pics/minenclosingtriangle.png) + +The implementation of the algorithm is based on O'Rourke's @cite ORourke86 and Klee and Laskowski's +@cite KleeLaskowski85 papers. O'Rourke provides a \f$\theta(n)\f$ algorithm for finding the minimal +enclosing triangle of a 2D convex polygon with n vertices. Since the #minEnclosingTriangle function +takes a 2D point set as input an additional preprocessing step of computing the convex hull of the +2D point set is required. The complexity of the #convexHull function is \f$O(n log(n))\f$ which is higher +than \f$\theta(n)\f$. Thus the overall complexity of the function is \f$O(n log(n))\f$. + +@param points Input vector of 2D points with depth CV_32S or CV_32F, stored in std::vector\<\> or Mat +@param triangle Output vector of three 2D points defining the vertices of the triangle. The depth +of the OutputArray must be CV_32F. + */ +CV_EXPORTS_W double minEnclosingTriangle( InputArray points, CV_OUT OutputArray triangle ); + +/** @brief Compares two shapes. + +The function compares two shapes. All three implemented methods use the Hu invariants (see #HuMoments) + +@param contour1 First contour or grayscale image. +@param contour2 Second contour or grayscale image. +@param method Comparison method, see #ShapeMatchModes +@param parameter Method-specific parameter (not supported now). + */ +CV_EXPORTS_W double matchShapes( InputArray contour1, InputArray contour2, + int method, double parameter ); + +/** @example samples/cpp/convexhull.cpp +An example using the convexHull functionality +*/ + +/** @brief Finds the convex hull of a point set. + +The function cv::convexHull finds the convex hull of a 2D point set using the Sklansky's algorithm @cite Sklansky82 +that has *O(N logN)* complexity in the current implementation. + +@param points Input 2D point set, stored in std::vector or Mat. +@param hull Output convex hull. It is either an integer vector of indices or vector of points. In +the first case, the hull elements are 0-based indices of the convex hull points in the original +array (since the set of convex hull points is a subset of the original point set). In the second +case, hull elements are the convex hull points themselves. +@param clockwise Orientation flag. If it is true, the output convex hull is oriented clockwise. +Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing +to the right, and its Y axis pointing upwards. +@param returnPoints Operation flag. In case of a matrix, when the flag is true, the function +returns convex hull points. Otherwise, it returns indices of the convex hull points. When the +output array is std::vector, the flag is ignored, and the output depends on the type of the +vector: std::vector\ implies returnPoints=false, std::vector\ implies +returnPoints=true. + +@note `points` and `hull` should be different arrays, inplace processing isn't supported. + +Check @ref tutorial_hull "the corresponding tutorial" for more details. + +useful links: + +https://www.learnopencv.com/convex-hull-using-opencv-in-python-and-c/ + */ +CV_EXPORTS_W void convexHull( InputArray points, OutputArray hull, + bool clockwise = false, bool returnPoints = true ); + +/** @brief Finds the convexity defects of a contour. + +The figure below displays convexity defects of a hand contour: + +![image](pics/defects.png) + +@param contour Input contour. +@param convexhull Convex hull obtained using convexHull that should contain indices of the contour +points that make the hull. +@param convexityDefects The output vector of convexity defects. In C++ and the new Python/Java +interface each convexity defect is represented as 4-element integer vector (a.k.a. #Vec4i): +(start_index, end_index, farthest_pt_index, fixpt_depth), where indices are 0-based indices +in the original contour of the convexity defect beginning, end and the farthest point, and +fixpt_depth is fixed-point approximation (with 8 fractional bits) of the distance between the +farthest contour point and the hull. That is, to get the floating-point value of the depth will be +fixpt_depth/256.0. + */ +CV_EXPORTS_W void convexityDefects( InputArray contour, InputArray convexhull, OutputArray convexityDefects ); + +/** @brief Tests a contour convexity. + +The function tests whether the input contour is convex or not. The contour must be simple, that is, +without self-intersections. Otherwise, the function output is undefined. + +@param contour Input vector of 2D points, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W bool isContourConvex( InputArray contour ); + +/** @example samples/cpp/intersectExample.cpp +Examples of how intersectConvexConvex works +*/ + +/** @brief Finds intersection of two convex polygons + +@param _p1 First polygon +@param _p2 Second polygon +@param _p12 Output polygon describing the intersecting area +@param handleNested When true, an intersection is found if one of the polygons is fully enclosed in the other. +When false, no intersection is found. If the polygons share a side or the vertex of one polygon lies on an edge +of the other, they are not considered nested and an intersection will be found regardless of the value of handleNested. + +@returns Absolute value of area of intersecting polygon + +@note intersectConvexConvex doesn't confirm that both polygons are convex and will return invalid results if they aren't. + */ +CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2, + OutputArray _p12, bool handleNested = true ); + +/** @example samples/cpp/fitellipse.cpp +An example using the fitEllipse technique +*/ + +/** @brief Fits an ellipse around a set of 2D points. + +The function calculates the ellipse that fits (in a least-squares sense) a set of 2D points best of +all. It returns the rotated rectangle in which the ellipse is inscribed. The first algorithm described by @cite Fitzgibbon95 +is used. Developer should keep in mind that it is possible that the returned +ellipse/rotatedRect data contains negative indices, due to the data points being close to the +border of the containing Mat element. + +@param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipse( InputArray points ); + +/** @brief Fits an ellipse around a set of 2D points. + + The function calculates the ellipse that fits a set of 2D points. + It returns the rotated rectangle in which the ellipse is inscribed. + The Approximate Mean Square (AMS) proposed by @cite Taubin1991 is used. + + For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$, + which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$. + However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$, + the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines, + quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. + If the fit is found to be a parabolic or hyperbolic function then the standard #fitEllipse method is used. + The AMS method restricts the fit to parabolic, hyperbolic and elliptical curves + by imposing the condition that \f$ A^T ( D_x^T D_x + D_y^T D_y) A = 1 \f$ where + the matrices \f$ Dx \f$ and \f$ Dy \f$ are the partial derivatives of the design matrix \f$ D \f$ with + respect to x and y. The matrices are formed row by row applying the following to + each of the points in the set: + \f{align*}{ + D(i,:)&=\left\{x_i^2, x_i y_i, y_i^2, x_i, y_i, 1\right\} & + D_x(i,:)&=\left\{2 x_i,y_i,0,1,0,0\right\} & + D_y(i,:)&=\left\{0,x_i,2 y_i,0,1,0\right\} + \f} + The AMS method minimizes the cost function + \f{equation*}{ + \epsilon ^2=\frac{ A^T D^T D A }{ A^T (D_x^T D_x + D_y^T D_y) A^T } + \f} + + The minimum cost is found by solving the generalized eigenvalue problem. + + \f{equation*}{ + D^T D A = \lambda \left( D_x^T D_x + D_y^T D_y\right) A + \f} + + @param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipseAMS( InputArray points ); + + +/** @brief Fits an ellipse around a set of 2D points. + + The function calculates the ellipse that fits a set of 2D points. + It returns the rotated rectangle in which the ellipse is inscribed. + The Direct least square (Direct) method by @cite Fitzgibbon1999 is used. + + For an ellipse, this basis set is \f$ \chi= \left(x^2, x y, y^2, x, y, 1\right) \f$, + which is a set of six free coefficients \f$ A^T=\left\{A_{\text{xx}},A_{\text{xy}},A_{\text{yy}},A_x,A_y,A_0\right\} \f$. + However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths \f$ (a,b) \f$, + the position \f$ (x_0,y_0) \f$, and the orientation \f$ \theta \f$. This is because the basis set includes lines, + quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. + The Direct method confines the fit to ellipses by ensuring that \f$ 4 A_{xx} A_{yy}- A_{xy}^2 > 0 \f$. + The condition imposed is that \f$ 4 A_{xx} A_{yy}- A_{xy}^2=1 \f$ which satisfies the inequality + and as the coefficients can be arbitrarily scaled is not overly restrictive. + + \f{equation*}{ + \epsilon ^2= A^T D^T D A \quad \text{with} \quad A^T C A =1 \quad \text{and} \quad C=\left(\begin{matrix} + 0 & 0 & 2 & 0 & 0 & 0 \\ + 0 & -1 & 0 & 0 & 0 & 0 \\ + 2 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 0 + \end{matrix} \right) + \f} + + The minimum cost is found by solving the generalized eigenvalue problem. + + \f{equation*}{ + D^T D A = \lambda \left( C\right) A + \f} + + The system produces only one positive eigenvalue \f$ \lambda\f$ which is chosen as the solution + with its eigenvector \f$\mathbf{u}\f$. These are used to find the coefficients + + \f{equation*}{ + A = \sqrt{\frac{1}{\mathbf{u}^T C \mathbf{u}}} \mathbf{u} + \f} + The scaling factor guarantees that \f$A^T C A =1\f$. + + @param points Input 2D point set, stored in std::vector\<\> or Mat + */ +CV_EXPORTS_W RotatedRect fitEllipseDirect( InputArray points ); + +/** @brief Fits a line to a 2D or 3D point set. + +The function fitLine fits a line to a 2D or 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where +\f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance function, one +of the following: +- DIST_L2 +\f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f] +- DIST_L1 +\f[\rho (r) = r\f] +- DIST_L12 +\f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f] +- DIST_FAIR +\f[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\f] +- DIST_WELSCH +\f[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\f] +- DIST_HUBER +\f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f] + +The algorithm is based on the M-estimator ( ) technique +that iteratively fits the line using the weighted least-squares algorithm. After each iteration the +weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ . + +@param points Input vector of 2D or 3D points, stored in std::vector\<\> or Mat. +@param line Output line parameters. In case of 2D fitting, it should be a vector of 4 elements +(like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and +(x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like +Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line +and (x0, y0, z0) is a point on the line. +@param distType Distance used by the M-estimator, see #DistanceTypes +@param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value +is chosen. +@param reps Sufficient accuracy for the radius (distance between the coordinate origin and the line). +@param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps. + */ +CV_EXPORTS_W void fitLine( InputArray points, OutputArray line, int distType, + double param, double reps, double aeps ); + +/** @brief Performs a point-in-contour test. + +The function determines whether the point is inside a contour, outside, or lies on an edge (or +coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge) +value, correspondingly. When measureDist=false , the return value is +1, -1, and 0, respectively. +Otherwise, the return value is a signed distance between the point and the nearest contour edge. + +See below a sample output of the function where each image pixel is tested against the contour: + +![sample output](pics/pointpolygon.png) + +@param contour Input contour. +@param pt Point tested against the contour. +@param measureDist If true, the function estimates the signed distance from the point to the +nearest contour edge. Otherwise, the function only checks if the point is inside a contour or not. + */ +CV_EXPORTS_W double pointPolygonTest( InputArray contour, Point2f pt, bool measureDist ); + +/** @brief Finds out if there is any intersection between two rotated rectangles. + +If there is then the vertices of the intersecting region are returned as well. + +Below are some examples of intersection configurations. The hatched pattern indicates the +intersecting region and the red vertices are returned by the function. + +![intersection examples](pics/intersection.png) + +@param rect1 First rectangle +@param rect2 Second rectangle +@param intersectingRegion The output array of the vertices of the intersecting region. It returns +at most 8 vertices. Stored as std::vector\ or cv::Mat as Mx1 of type CV_32FC2. +@returns One of #RectanglesIntersectTypes + */ +CV_EXPORTS_W int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& rect2, OutputArray intersectingRegion ); + +/** @brief Creates a smart pointer to a cv::GeneralizedHoughBallard class and initializes it. +*/ +CV_EXPORTS_W Ptr createGeneralizedHoughBallard(); + +/** @brief Creates a smart pointer to a cv::GeneralizedHoughGuil class and initializes it. +*/ +CV_EXPORTS_W Ptr createGeneralizedHoughGuil(); + +//! @} imgproc_shape + +//! @addtogroup imgproc_colormap +//! @{ + +//! GNU Octave/MATLAB equivalent colormaps +enum ColormapTypes +{ + COLORMAP_AUTUMN = 0, //!< ![autumn](pics/colormaps/colorscale_autumn.jpg) + COLORMAP_BONE = 1, //!< ![bone](pics/colormaps/colorscale_bone.jpg) + COLORMAP_JET = 2, //!< ![jet](pics/colormaps/colorscale_jet.jpg) + COLORMAP_WINTER = 3, //!< ![winter](pics/colormaps/colorscale_winter.jpg) + COLORMAP_RAINBOW = 4, //!< ![rainbow](pics/colormaps/colorscale_rainbow.jpg) + COLORMAP_OCEAN = 5, //!< ![ocean](pics/colormaps/colorscale_ocean.jpg) + COLORMAP_SUMMER = 6, //!< ![summer](pics/colormaps/colorscale_summer.jpg) + COLORMAP_SPRING = 7, //!< ![spring](pics/colormaps/colorscale_spring.jpg) + COLORMAP_COOL = 8, //!< ![cool](pics/colormaps/colorscale_cool.jpg) + COLORMAP_HSV = 9, //!< ![HSV](pics/colormaps/colorscale_hsv.jpg) + COLORMAP_PINK = 10, //!< ![pink](pics/colormaps/colorscale_pink.jpg) + COLORMAP_HOT = 11, //!< ![hot](pics/colormaps/colorscale_hot.jpg) + COLORMAP_PARULA = 12, //!< ![parula](pics/colormaps/colorscale_parula.jpg) + COLORMAP_MAGMA = 13, //!< ![magma](pics/colormaps/colorscale_magma.jpg) + COLORMAP_INFERNO = 14, //!< ![inferno](pics/colormaps/colorscale_inferno.jpg) + COLORMAP_PLASMA = 15, //!< ![plasma](pics/colormaps/colorscale_plasma.jpg) + COLORMAP_VIRIDIS = 16, //!< ![viridis](pics/colormaps/colorscale_viridis.jpg) + COLORMAP_CIVIDIS = 17, //!< ![cividis](pics/colormaps/colorscale_cividis.jpg) + COLORMAP_TWILIGHT = 18, //!< ![twilight](pics/colormaps/colorscale_twilight.jpg) + COLORMAP_TWILIGHT_SHIFTED = 19, //!< ![twilight shifted](pics/colormaps/colorscale_twilight_shifted.jpg) + COLORMAP_TURBO = 20 //!< ![turbo](pics/colormaps/colorscale_turbo.jpg) +}; + +/** @example samples/cpp/falsecolor.cpp +An example using applyColorMap function +*/ + +/** @brief Applies a GNU Octave/MATLAB equivalent colormap on a given image. + +@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. +@param dst The result is the colormapped source image. Note: Mat::create is called on dst. +@param colormap The colormap to apply, see #ColormapTypes +*/ +CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap); + +/** @brief Applies a user colormap on a given image. + +@param src The source image, grayscale or colored of type CV_8UC1 or CV_8UC3. +@param dst The result is the colormapped source image. Note: Mat::create is called on dst. +@param userColor The colormap to apply of type CV_8UC1 or CV_8UC3 and size 256 +*/ +CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, InputArray userColor); + +//! @} imgproc_colormap + +//! @addtogroup imgproc_draw +//! @{ + + +/** OpenCV color channel order is BGR[A] */ +#define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0) + +/** @brief Draws a line segment connecting two points. + +The function line draws the line segment between pt1 and pt2 points in the image. The line is +clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected +or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased +lines are drawn using Gaussian filtering. + +@param img Image. +@param pt1 First point of the line segment. +@param pt2 Second point of the line segment. +@param color Line color. +@param thickness Line thickness. +@param lineType Type of the line. See #LineTypes. +@param shift Number of fractional bits in the point coordinates. + */ +CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, + int thickness = 1, int lineType = LINE_8, int shift = 0); + +/** @brief Draws a arrow segment pointing from the first point to the second one. + +The function cv::arrowedLine draws an arrow between pt1 and pt2 points in the image. See also #line. + +@param img Image. +@param pt1 The point the arrow starts from. +@param pt2 The point the arrow points to. +@param color Line color. +@param thickness Line thickness. +@param line_type Type of the line. See #LineTypes +@param shift Number of fractional bits in the point coordinates. +@param tipLength The length of the arrow tip in relation to the arrow length + */ +CV_EXPORTS_W void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, + int thickness=1, int line_type=8, int shift=0, double tipLength=0.1); + +/** @brief Draws a simple, thick, or filled up-right rectangle. + +The function cv::rectangle draws a rectangle outline or a filled rectangle whose two opposite corners +are pt1 and pt2. + +@param img Image. +@param pt1 Vertex of the rectangle. +@param pt2 Vertex of the rectangle opposite to pt1 . +@param color Rectangle color or brightness (grayscale image). +@param thickness Thickness of lines that make up the rectangle. Negative values, like #FILLED, +mean that the function has to draw a filled rectangle. +@param lineType Type of the line. See #LineTypes +@param shift Number of fractional bits in the point coordinates. + */ +CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @overload + +use `rec` parameter as alternative specification of the drawn rectangle: `r.tl() and +r.br()-Point(1,1)` are opposite corners +*/ +CV_EXPORTS_W void rectangle(InputOutputArray img, Rect rec, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_2.cpp +An example using drawing functions +*/ + +/** @brief Draws a circle. + +The function cv::circle draws a simple or filled circle with a given center and radius. +@param img Image where the circle is drawn. +@param center Center of the circle. +@param radius Radius of the circle. +@param color Circle color. +@param thickness Thickness of the circle outline, if positive. Negative values, like #FILLED, +mean that a filled circle is to be drawn. +@param lineType Type of the circle boundary. See #LineTypes +@param shift Number of fractional bits in the coordinates of the center and in the radius value. + */ +CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @brief Draws a simple or thick elliptic arc or fills an ellipse sector. + +The function cv::ellipse with more parameters draws an ellipse outline, a filled ellipse, an elliptic +arc, or a filled ellipse sector. The drawing code uses general parametric form. +A piecewise-linear curve is used to approximate the elliptic arc +boundary. If you need more control of the ellipse rendering, you can retrieve the curve using +#ellipse2Poly and then render it with #polylines or fill it with #fillPoly. If you use the first +variant of the function and want to draw the whole ellipse, not an arc, pass `startAngle=0` and +`endAngle=360`. If `startAngle` is greater than `endAngle`, they are swapped. The figure below explains +the meaning of the parameters to draw the blue arc. + +![Parameters of Elliptic Arc](pics/ellipse.svg) + +@param img Image. +@param center Center of the ellipse. +@param axes Half of the size of the ellipse main axes. +@param angle Ellipse rotation angle in degrees. +@param startAngle Starting angle of the elliptic arc in degrees. +@param endAngle Ending angle of the elliptic arc in degrees. +@param color Ellipse color. +@param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that +a filled ellipse sector is to be drawn. +@param lineType Type of the ellipse boundary. See #LineTypes +@param shift Number of fractional bits in the coordinates of the center and values of axes. + */ +CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes, + double angle, double startAngle, double endAngle, + const Scalar& color, int thickness = 1, + int lineType = LINE_8, int shift = 0); + +/** @overload +@param img Image. +@param box Alternative ellipse representation via RotatedRect. This means that the function draws +an ellipse inscribed in the rotated rectangle. +@param color Ellipse color. +@param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that +a filled ellipse sector is to be drawn. +@param lineType Type of the ellipse boundary. See #LineTypes +*/ +CV_EXPORTS_W void ellipse(InputOutputArray img, const RotatedRect& box, const Scalar& color, + int thickness = 1, int lineType = LINE_8); + +/* ----------------------------------------------------------------------------------------- */ +/* ADDING A SET OF PREDEFINED MARKERS WHICH COULD BE USED TO HIGHLIGHT POSITIONS IN AN IMAGE */ +/* ----------------------------------------------------------------------------------------- */ + +/** @brief Draws a marker on a predefined position in an image. + +The function cv::drawMarker draws a marker on a given position in the image. For the moment several +marker types are supported, see #MarkerTypes for more information. + +@param img Image. +@param position The point where the crosshair is positioned. +@param color Line color. +@param markerType The specific type of marker you want to use, see #MarkerTypes +@param thickness Line thickness. +@param line_type Type of the line, See #LineTypes +@param markerSize The length of the marker axis [default = 20 pixels] + */ +CV_EXPORTS_W void drawMarker(InputOutputArray img, Point position, const Scalar& color, + int markerType = MARKER_CROSS, int markerSize=20, int thickness=1, + int line_type=8); + +/* ----------------------------------------------------------------------------------------- */ +/* END OF MARKER SECTION */ +/* ----------------------------------------------------------------------------------------- */ + +/** @overload */ +CV_EXPORTS void fillConvexPoly(InputOutputArray img, const Point* pts, int npts, + const Scalar& color, int lineType = LINE_8, + int shift = 0); + +/** @brief Fills a convex polygon. + +The function cv::fillConvexPoly draws a filled convex polygon. This function is much faster than the +function #fillPoly . It can fill not only convex polygons but any monotonic polygon without +self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line) +twice at the most (though, its top-most and/or the bottom edge could be horizontal). + +@param img Image. +@param points Polygon vertices. +@param color Polygon color. +@param lineType Type of the polygon boundaries. See #LineTypes +@param shift Number of fractional bits in the vertex coordinates. + */ +CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points, + const Scalar& color, int lineType = LINE_8, + int shift = 0); + +/** @overload */ +CV_EXPORTS void fillPoly(InputOutputArray img, const Point** pts, + const int* npts, int ncontours, + const Scalar& color, int lineType = LINE_8, int shift = 0, + Point offset = Point() ); + +/** @example samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_1.cpp +An example using drawing functions +Check @ref tutorial_random_generator_and_text "the corresponding tutorial" for more details +*/ + +/** @brief Fills the area bounded by one or more polygons. + +The function cv::fillPoly fills an area bounded by several polygonal contours. The function can fill +complex areas, for example, areas with holes, contours with self-intersections (some of their +parts), and so forth. + +@param img Image. +@param pts Array of polygons where each polygon is represented as an array of points. +@param color Polygon color. +@param lineType Type of the polygon boundaries. See #LineTypes +@param shift Number of fractional bits in the vertex coordinates. +@param offset Optional offset of all points of the contours. + */ +CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts, + const Scalar& color, int lineType = LINE_8, int shift = 0, + Point offset = Point() ); + +/** @overload */ +CV_EXPORTS void polylines(InputOutputArray img, const Point* const* pts, const int* npts, + int ncontours, bool isClosed, const Scalar& color, + int thickness = 1, int lineType = LINE_8, int shift = 0 ); + +/** @brief Draws several polygonal curves. + +@param img Image. +@param pts Array of polygonal curves. +@param isClosed Flag indicating whether the drawn polylines are closed or not. If they are closed, +the function draws a line from the last vertex of each curve to its first vertex. +@param color Polyline color. +@param thickness Thickness of the polyline edges. +@param lineType Type of the line segments. See #LineTypes +@param shift Number of fractional bits in the vertex coordinates. + +The function cv::polylines draws one or more polygonal curves. + */ +CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts, + bool isClosed, const Scalar& color, + int thickness = 1, int lineType = LINE_8, int shift = 0 ); + +/** @example samples/cpp/contours2.cpp +An example program illustrates the use of cv::findContours and cv::drawContours +\image html WindowsQtContoursOutput.png "Screenshot of the program" +*/ + +/** @example samples/cpp/segment_objects.cpp +An example using drawContours to clean up a background segmentation result +*/ + +/** @brief Draws contours outlines or filled contours. + +The function draws contour outlines in the image if \f$\texttt{thickness} \ge 0\f$ or fills the area +bounded by the contours if \f$\texttt{thickness}<0\f$ . The example below shows how to retrieve +connected components from the binary image and label them: : +@include snippets/imgproc_drawContours.cpp + +@param image Destination image. +@param contours All the input contours. Each contour is stored as a point vector. +@param contourIdx Parameter indicating a contour to draw. If it is negative, all the contours are drawn. +@param color Color of the contours. +@param thickness Thickness of lines the contours are drawn with. If it is negative (for example, +thickness=#FILLED ), the contour interiors are drawn. +@param lineType Line connectivity. See #LineTypes +@param hierarchy Optional information about hierarchy. It is only needed if you want to draw only +some of the contours (see maxLevel ). +@param maxLevel Maximal level for drawn contours. If it is 0, only the specified contour is drawn. +If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function +draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This +parameter is only taken into account when there is hierarchy available. +@param offset Optional contour shift parameter. Shift all the drawn contours by the specified +\f$\texttt{offset}=(dx,dy)\f$ . +@note When thickness=#FILLED, the function is designed to handle connected components with holes correctly +even when no hierarchy date is provided. This is done by analyzing all the outlines together +using even-odd rule. This may give incorrect results if you have a joint collection of separately retrieved +contours. In order to solve this problem, you need to call #drawContours separately for each sub-group +of contours, or iterate over the collection using contourIdx parameter. + */ +CV_EXPORTS_W void drawContours( InputOutputArray image, InputArrayOfArrays contours, + int contourIdx, const Scalar& color, + int thickness = 1, int lineType = LINE_8, + InputArray hierarchy = noArray(), + int maxLevel = INT_MAX, Point offset = Point() ); + +/** @brief Clips the line against the image rectangle. + +The function cv::clipLine calculates a part of the line segment that is entirely within the specified +rectangle. it returns false if the line segment is completely outside the rectangle. Otherwise, +it returns true . +@param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . +@param pt1 First line point. +@param pt2 Second line point. + */ +CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2); + +/** @overload +@param imgSize Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) . +@param pt1 First line point. +@param pt2 Second line point. +*/ +CV_EXPORTS bool clipLine(Size2l imgSize, CV_IN_OUT Point2l& pt1, CV_IN_OUT Point2l& pt2); + +/** @overload +@param imgRect Image rectangle. +@param pt1 First line point. +@param pt2 Second line point. +*/ +CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2); + +/** @brief Approximates an elliptic arc with a polyline. + +The function ellipse2Poly computes the vertices of a polyline that approximates the specified +elliptic arc. It is used by #ellipse. If `arcStart` is greater than `arcEnd`, they are swapped. + +@param center Center of the arc. +@param axes Half of the size of the ellipse main axes. See #ellipse for details. +@param angle Rotation angle of the ellipse in degrees. See #ellipse for details. +@param arcStart Starting angle of the elliptic arc in degrees. +@param arcEnd Ending angle of the elliptic arc in degrees. +@param delta Angle between the subsequent polyline vertices. It defines the approximation +accuracy. +@param pts Output vector of polyline vertices. + */ +CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle, + int arcStart, int arcEnd, int delta, + CV_OUT std::vector& pts ); + +/** @overload +@param center Center of the arc. +@param axes Half of the size of the ellipse main axes. See #ellipse for details. +@param angle Rotation angle of the ellipse in degrees. See #ellipse for details. +@param arcStart Starting angle of the elliptic arc in degrees. +@param arcEnd Ending angle of the elliptic arc in degrees. +@param delta Angle between the subsequent polyline vertices. It defines the approximation accuracy. +@param pts Output vector of polyline vertices. +*/ +CV_EXPORTS void ellipse2Poly(Point2d center, Size2d axes, int angle, + int arcStart, int arcEnd, int delta, + CV_OUT std::vector& pts); + +/** @brief Draws a text string. + +The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered +using the specified font are replaced by question marks. See #getTextSize for a text rendering code +example. + +@param img Image. +@param text Text string to be drawn. +@param org Bottom-left corner of the text string in the image. +@param fontFace Font type, see #HersheyFonts. +@param fontScale Font scale factor that is multiplied by the font-specific base size. +@param color Text color. +@param thickness Thickness of the lines used to draw a text. +@param lineType Line type. See #LineTypes +@param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, +it is at the top-left corner. + */ +CV_EXPORTS_W void putText( InputOutputArray img, const String& text, Point org, + int fontFace, double fontScale, Scalar color, + int thickness = 1, int lineType = LINE_8, + bool bottomLeftOrigin = false ); + +/** @brief Calculates the width and height of a text string. + +The function cv::getTextSize calculates and returns the size of a box that contains the specified text. +That is, the following code renders some text, the tight box surrounding it, and the baseline: : +@code + String text = "Funny text inside the box"; + int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX; + double fontScale = 2; + int thickness = 3; + + Mat img(600, 800, CV_8UC3, Scalar::all(0)); + + int baseline=0; + Size textSize = getTextSize(text, fontFace, + fontScale, thickness, &baseline); + baseline += thickness; + + // center the text + Point textOrg((img.cols - textSize.width)/2, + (img.rows + textSize.height)/2); + + // draw the box + rectangle(img, textOrg + Point(0, baseline), + textOrg + Point(textSize.width, -textSize.height), + Scalar(0,0,255)); + // ... and the baseline first + line(img, textOrg + Point(0, thickness), + textOrg + Point(textSize.width, thickness), + Scalar(0, 0, 255)); + + // then put the text itself + putText(img, text, textOrg, fontFace, fontScale, + Scalar::all(255), thickness, 8); +@endcode + +@param text Input text string. +@param fontFace Font to use, see #HersheyFonts. +@param fontScale Font scale factor that is multiplied by the font-specific base size. +@param thickness Thickness of lines used to render the text. See #putText for details. +@param[out] baseLine y-coordinate of the baseline relative to the bottom-most text +point. +@return The size of a box that contains the specified text. + +@see putText + */ +CV_EXPORTS_W Size getTextSize(const String& text, int fontFace, + double fontScale, int thickness, + CV_OUT int* baseLine); + + +/** @brief Calculates the font-specific size to use to achieve a given height in pixels. + +@param fontFace Font to use, see cv::HersheyFonts. +@param pixelHeight Pixel height to compute the fontScale for +@param thickness Thickness of lines used to render the text.See putText for details. +@return The fontSize to use for cv::putText + +@see cv::putText +*/ +CV_EXPORTS_W double getFontScaleFromHeight(const int fontFace, + const int pixelHeight, + const int thickness = 1); + +/** @brief Line iterator + +The class is used to iterate over all the pixels on the raster line +segment connecting two specified points. + +The class LineIterator is used to get each pixel of a raster line. It +can be treated as versatile implementation of the Bresenham algorithm +where you can stop at each pixel and do some extra processing, for +example, grab pixel values along the line or draw a line with an effect +(for example, with XOR operation). + +The number of pixels along the line is stored in LineIterator::count. +The method LineIterator::pos returns the current position in the image: + +@code{.cpp} +// grabs pixels along the line (pt1, pt2) +// from 8-bit 3-channel image to the buffer +LineIterator it(img, pt1, pt2, 8); +LineIterator it2 = it; +vector buf(it.count); + +for(int i = 0; i < it.count; i++, ++it) + buf[i] = *(const Vec3b*)*it; + +// alternative way of iterating through the line +for(int i = 0; i < it2.count; i++, ++it2) +{ + Vec3b val = img.at(it2.pos()); + CV_Assert(buf[i] == val); +} +@endcode +*/ +class CV_EXPORTS LineIterator +{ +public: + /** @brief initializes the iterator + + creates iterators for the line connecting pt1 and pt2 + the line will be clipped on the image boundaries + the line is 8-connected or 4-connected + If leftToRight=true, then the iteration is always done + from the left-most point to the right most, + not to depend on the ordering of pt1 and pt2 parameters + */ + LineIterator( const Mat& img, Point pt1, Point pt2, + int connectivity = 8, bool leftToRight = false ); + /** @brief returns pointer to the current pixel + */ + uchar* operator *(); + /** @brief prefix increment operator (++it). shifts iterator to the next pixel + */ + LineIterator& operator ++(); + /** @brief postfix increment operator (it++). shifts iterator to the next pixel + */ + LineIterator operator ++(int); + /** @brief returns coordinates of the current pixel + */ + Point pos() const; + + uchar* ptr; + const uchar* ptr0; + int step, elemSize; + int err, count; + int minusDelta, plusDelta; + int minusStep, plusStep; +}; + +//! @cond IGNORED + +// === LineIterator implementation === + +inline +uchar* LineIterator::operator *() +{ + return ptr; +} + +inline +LineIterator& LineIterator::operator ++() +{ + int mask = err < 0 ? -1 : 0; + err += minusDelta + (plusDelta & mask); + ptr += minusStep + (plusStep & mask); + return *this; +} + +inline +LineIterator LineIterator::operator ++(int) +{ + LineIterator it = *this; + ++(*this); + return it; +} + +inline +Point LineIterator::pos() const +{ + Point p; + p.y = (int)((ptr - ptr0)/step); + p.x = (int)(((ptr - ptr0) - p.y*step)/elemSize); + return p; +} + +//! @endcond + +//! @} imgproc_draw + +//! @} imgproc + +} // cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/detail/gcgraph.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/detail/gcgraph.hpp new file mode 100644 index 0000000000000000000000000000000000000000..db2ea0f61d6da1df893ccd698cecb8d98b38c02a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/detail/gcgraph.hpp @@ -0,0 +1,393 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_IMGPROC_DETAIL_GCGRAPH_HPP +#define OPENCV_IMGPROC_DETAIL_GCGRAPH_HPP + +//! @cond IGNORED + +namespace cv { namespace detail { +template class GCGraph +{ +public: + GCGraph(); + GCGraph( unsigned int vtxCount, unsigned int edgeCount ); + ~GCGraph(); + void create( unsigned int vtxCount, unsigned int edgeCount ); + int addVtx(); + void addEdges( int i, int j, TWeight w, TWeight revw ); + void addTermWeights( int i, TWeight sourceW, TWeight sinkW ); + TWeight maxFlow(); + bool inSourceSegment( int i ); +private: + class Vtx + { + public: + Vtx *next; // initialized and used in maxFlow() only + int parent; + int first; + int ts; + int dist; + TWeight weight; + uchar t; + }; + class Edge + { + public: + int dst; + int next; + TWeight weight; + }; + + std::vector vtcs; + std::vector edges; + TWeight flow; +}; + +template +GCGraph::GCGraph() +{ + flow = 0; +} +template +GCGraph::GCGraph( unsigned int vtxCount, unsigned int edgeCount ) +{ + create( vtxCount, edgeCount ); +} +template +GCGraph::~GCGraph() +{ +} +template +void GCGraph::create( unsigned int vtxCount, unsigned int edgeCount ) +{ + vtcs.reserve( vtxCount ); + edges.reserve( edgeCount + 2 ); + flow = 0; +} + +template +int GCGraph::addVtx() +{ + Vtx v; + memset( &v, 0, sizeof(Vtx)); + vtcs.push_back(v); + return (int)vtcs.size() - 1; +} + +template +void GCGraph::addEdges( int i, int j, TWeight w, TWeight revw ) +{ + CV_Assert( i>=0 && i<(int)vtcs.size() ); + CV_Assert( j>=0 && j<(int)vtcs.size() ); + CV_Assert( w>=0 && revw>=0 ); + CV_Assert( i != j ); + + if( !edges.size() ) + edges.resize( 2 ); + + Edge fromI, toI; + fromI.dst = j; + fromI.next = vtcs[i].first; + fromI.weight = w; + vtcs[i].first = (int)edges.size(); + edges.push_back( fromI ); + + toI.dst = i; + toI.next = vtcs[j].first; + toI.weight = revw; + vtcs[j].first = (int)edges.size(); + edges.push_back( toI ); +} + +template +void GCGraph::addTermWeights( int i, TWeight sourceW, TWeight sinkW ) +{ + CV_Assert( i>=0 && i<(int)vtcs.size() ); + + TWeight dw = vtcs[i].weight; + if( dw > 0 ) + sourceW += dw; + else + sinkW -= dw; + flow += (sourceW < sinkW) ? sourceW : sinkW; + vtcs[i].weight = sourceW - sinkW; +} + +template +TWeight GCGraph::maxFlow() +{ + const int TERMINAL = -1, ORPHAN = -2; + Vtx stub, *nilNode = &stub, *first = nilNode, *last = nilNode; + int curr_ts = 0; + stub.next = nilNode; + Vtx *vtxPtr = &vtcs[0]; + Edge *edgePtr = &edges[0]; + + std::vector orphans; + + // initialize the active queue and the graph vertices + for( int i = 0; i < (int)vtcs.size(); i++ ) + { + Vtx* v = vtxPtr + i; + v->ts = 0; + if( v->weight != 0 ) + { + last = last->next = v; + v->dist = 1; + v->parent = TERMINAL; + v->t = v->weight < 0; + } + else + v->parent = 0; + } + first = first->next; + last->next = nilNode; + nilNode->next = 0; + + // run the search-path -> augment-graph -> restore-trees loop + for(;;) + { + Vtx* v, *u; + int e0 = -1, ei = 0, ej = 0; + TWeight minWeight, weight; + uchar vt; + + // grow S & T search trees, find an edge connecting them + while( first != nilNode ) + { + v = first; + if( v->parent ) + { + vt = v->t; + for( ei = v->first; ei != 0; ei = edgePtr[ei].next ) + { + if( edgePtr[ei^vt].weight == 0 ) + continue; + u = vtxPtr+edgePtr[ei].dst; + if( !u->parent ) + { + u->t = vt; + u->parent = ei ^ 1; + u->ts = v->ts; + u->dist = v->dist + 1; + if( !u->next ) + { + u->next = nilNode; + last = last->next = u; + } + continue; + } + + if( u->t != vt ) + { + e0 = ei ^ vt; + break; + } + + if( u->dist > v->dist+1 && u->ts <= v->ts ) + { + // reassign the parent + u->parent = ei ^ 1; + u->ts = v->ts; + u->dist = v->dist + 1; + } + } + if( e0 > 0 ) + break; + } + // exclude the vertex from the active list + first = first->next; + v->next = 0; + } + + if( e0 <= 0 ) + break; + + // find the minimum edge weight along the path + minWeight = edgePtr[e0].weight; + CV_Assert( minWeight > 0 ); + // k = 1: source tree, k = 0: destination tree + for( int k = 1; k >= 0; k-- ) + { + for( v = vtxPtr+edgePtr[e0^k].dst;; v = vtxPtr+edgePtr[ei].dst ) + { + if( (ei = v->parent) < 0 ) + break; + weight = edgePtr[ei^k].weight; + minWeight = MIN(minWeight, weight); + CV_Assert( minWeight > 0 ); + } + weight = fabs(v->weight); + minWeight = MIN(minWeight, weight); + CV_Assert( minWeight > 0 ); + } + + // modify weights of the edges along the path and collect orphans + edgePtr[e0].weight -= minWeight; + edgePtr[e0^1].weight += minWeight; + flow += minWeight; + + // k = 1: source tree, k = 0: destination tree + for( int k = 1; k >= 0; k-- ) + { + for( v = vtxPtr+edgePtr[e0^k].dst;; v = vtxPtr+edgePtr[ei].dst ) + { + if( (ei = v->parent) < 0 ) + break; + edgePtr[ei^(k^1)].weight += minWeight; + if( (edgePtr[ei^k].weight -= minWeight) == 0 ) + { + orphans.push_back(v); + v->parent = ORPHAN; + } + } + + v->weight = v->weight + minWeight*(1-k*2); + if( v->weight == 0 ) + { + orphans.push_back(v); + v->parent = ORPHAN; + } + } + + // restore the search trees by finding new parents for the orphans + curr_ts++; + while( !orphans.empty() ) + { + Vtx* v2 = orphans.back(); + orphans.pop_back(); + + int d, minDist = INT_MAX; + e0 = 0; + vt = v2->t; + + for( ei = v2->first; ei != 0; ei = edgePtr[ei].next ) + { + if( edgePtr[ei^(vt^1)].weight == 0 ) + continue; + u = vtxPtr+edgePtr[ei].dst; + if( u->t != vt || u->parent == 0 ) + continue; + // compute the distance to the tree root + for( d = 0;; ) + { + if( u->ts == curr_ts ) + { + d += u->dist; + break; + } + ej = u->parent; + d++; + if( ej < 0 ) + { + if( ej == ORPHAN ) + d = INT_MAX-1; + else + { + u->ts = curr_ts; + u->dist = 1; + } + break; + } + u = vtxPtr+edgePtr[ej].dst; + } + + // update the distance + if( ++d < INT_MAX ) + { + if( d < minDist ) + { + minDist = d; + e0 = ei; + } + for( u = vtxPtr+edgePtr[ei].dst; u->ts != curr_ts; u = vtxPtr+edgePtr[u->parent].dst ) + { + u->ts = curr_ts; + u->dist = --d; + } + } + } + + if( (v2->parent = e0) > 0 ) + { + v2->ts = curr_ts; + v2->dist = minDist; + continue; + } + + /* no parent is found */ + v2->ts = 0; + for( ei = v2->first; ei != 0; ei = edgePtr[ei].next ) + { + u = vtxPtr+edgePtr[ei].dst; + ej = u->parent; + if( u->t != vt || !ej ) + continue; + if( edgePtr[ei^(vt^1)].weight && !u->next ) + { + u->next = nilNode; + last = last->next = u; + } + if( ej > 0 && vtxPtr+edgePtr[ej].dst == v2 ) + { + orphans.push_back(u); + u->parent = ORPHAN; + } + } + } + } + return flow; +} + +template +bool GCGraph::inSourceSegment( int i ) +{ + CV_Assert( i>=0 && i<(int)vtcs.size() ); + return vtcs[i].t == 0; +} + +}} // namespace detail, cv + + +//! @endcond + +#endif // OPENCV_IMGPROC_DETAIL_GCGRAPH_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/hal/hal.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/hal/hal.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ac20725e6341aab83963901ba3647452a6d6f528 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/hal/hal.hpp @@ -0,0 +1,241 @@ +#ifndef CV_IMGPROC_HAL_HPP +#define CV_IMGPROC_HAL_HPP + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" +#include "opencv2/core/hal/interface.h" + +namespace cv { namespace hal { + +//! @addtogroup imgproc_hal_functions +//! @{ + +//--------------------------- +//! @cond IGNORED + +struct CV_EXPORTS Filter2D +{ + CV_DEPRECATED static Ptr create(uchar * , size_t , int , + int , int , + int , int , + int , int , + int , double , + int , int , + bool , bool ); + virtual void apply(uchar * , size_t , + uchar * , size_t , + int , int , + int , int , + int , int ) = 0; + virtual ~Filter2D() {} +}; + +struct CV_EXPORTS SepFilter2D +{ + CV_DEPRECATED static Ptr create(int , int , int , + uchar * , int , + uchar * , int , + int , int , + double , int ); + virtual void apply(uchar * , size_t , + uchar * , size_t , + int , int , + int , int , + int , int ) = 0; + virtual ~SepFilter2D() {} +}; + + +struct CV_EXPORTS Morph +{ + CV_DEPRECATED static Ptr create(int , int , int , int , int , + int , uchar * , size_t , + int , int , + int , int , + int , const double *, + int , bool , bool ); + virtual void apply(uchar * , size_t , uchar * , size_t , int , int , + int , int , int , int , + int , int , int , int ) = 0; + virtual ~Morph() {} +}; + +//! @endcond +//--------------------------- + +CV_EXPORTS void filter2D(int stype, int dtype, int kernel_type, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int full_width, int full_height, + int offset_x, int offset_y, + uchar * kernel_data, size_t kernel_step, + int kernel_width, int kernel_height, + int anchor_x, int anchor_y, + double delta, int borderType, + bool isSubmatrix); + +CV_EXPORTS void sepFilter2D(int stype, int dtype, int ktype, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int full_width, int full_height, + int offset_x, int offset_y, + uchar * kernelx_data, int kernelx_len, + uchar * kernely_data, int kernely_len, + int anchor_x, int anchor_y, + double delta, int borderType); + +CV_EXPORTS void morph(int op, int src_type, int dst_type, + uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int roi_width, int roi_height, int roi_x, int roi_y, + int roi_width2, int roi_height2, int roi_x2, int roi_y2, + int kernel_type, uchar * kernel_data, size_t kernel_step, + int kernel_width, int kernel_height, int anchor_x, int anchor_y, + int borderType, const double borderValue[4], + int iterations, bool isSubmatrix); + + +CV_EXPORTS void resize(int src_type, + const uchar * src_data, size_t src_step, int src_width, int src_height, + uchar * dst_data, size_t dst_step, int dst_width, int dst_height, + double inv_scale_x, double inv_scale_y, int interpolation); + +CV_EXPORTS void warpAffine(int src_type, + const uchar * src_data, size_t src_step, int src_width, int src_height, + uchar * dst_data, size_t dst_step, int dst_width, int dst_height, + const double M[6], int interpolation, int borderType, const double borderValue[4]); + +CV_EXPORTS void warpPerspective(int src_type, + const uchar * src_data, size_t src_step, int src_width, int src_height, + uchar * dst_data, size_t dst_step, int dst_width, int dst_height, + const double M[9], int interpolation, int borderType, const double borderValue[4]); + +CV_EXPORTS void cvtBGRtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, int dcn, bool swapBlue); + +CV_EXPORTS void cvtBGRtoBGR5x5(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int greenBits); + +CV_EXPORTS void cvtBGR5x5toBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int dcn, bool swapBlue, int greenBits); + +CV_EXPORTS void cvtBGRtoGray(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue); + +CV_EXPORTS void cvtGraytoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn); + +CV_EXPORTS void cvtBGR5x5toGray(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int greenBits); + +CV_EXPORTS void cvtGraytoBGR5x5(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int greenBits); +CV_EXPORTS void cvtBGRtoYUV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isCbCr); + +CV_EXPORTS void cvtYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isCbCr); + +CV_EXPORTS void cvtBGRtoXYZ(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue); + +CV_EXPORTS void cvtXYZtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue); + +CV_EXPORTS void cvtBGRtoHSV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isFullRange, bool isHSV); + +CV_EXPORTS void cvtHSVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isFullRange, bool isHSV); + +CV_EXPORTS void cvtBGRtoLab(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int scn, bool swapBlue, bool isLab, bool srgb); + +CV_EXPORTS void cvtLabtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int depth, int dcn, bool swapBlue, bool isLab, bool srgb); + +CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +//! Separate Y and UV planes +CV_EXPORTS void cvtTwoPlaneYUVtoBGR(const uchar * y_data, const uchar * uv_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtThreePlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int dst_width, int dst_height, + int dcn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtBGRtoThreePlaneYUV(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int uIdx); + +//! Separate Y and UV planes +CV_EXPORTS void cvtBGRtoTwoPlaneYUV(const uchar * src_data, size_t src_step, + uchar * y_data, uchar * uv_data, size_t dst_step, + int width, int height, + int scn, bool swapBlue, int uIdx); + +CV_EXPORTS void cvtOnePlaneYUVtoBGR(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height, + int dcn, bool swapBlue, int uIdx, int ycn); + +CV_EXPORTS void cvtRGBAtoMultipliedRGBA(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height); + +CV_EXPORTS void cvtMultipliedRGBAtoRGBA(const uchar * src_data, size_t src_step, + uchar * dst_data, size_t dst_step, + int width, int height); + +CV_EXPORTS void integral(int depth, int sdepth, int sqdepth, + const uchar* src, size_t srcstep, + uchar* sum, size_t sumstep, + uchar* sqsum, size_t sqsumstep, + uchar* tilted, size_t tstep, + int width, int height, int cn); + +//! @} + +}} + +#endif // CV_IMGPROC_HAL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/hal/interface.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/hal/interface.h new file mode 100644 index 0000000000000000000000000000000000000000..f8dbcfe791d90fd957cace7b7700d737864990e9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/hal/interface.h @@ -0,0 +1,46 @@ +#ifndef OPENCV_IMGPROC_HAL_INTERFACE_H +#define OPENCV_IMGPROC_HAL_INTERFACE_H + +//! @addtogroup imgproc_hal_interface +//! @{ + +//! @name Interpolation modes +//! @sa cv::InterpolationFlags +//! @{ +#define CV_HAL_INTER_NEAREST 0 +#define CV_HAL_INTER_LINEAR 1 +#define CV_HAL_INTER_CUBIC 2 +#define CV_HAL_INTER_AREA 3 +#define CV_HAL_INTER_LANCZOS4 4 +//! @} + +//! @name Morphology operations +//! @sa cv::MorphTypes +//! @{ +#define CV_HAL_MORPH_ERODE 0 +#define CV_HAL_MORPH_DILATE 1 +//! @} + +//! @name Threshold types +//! @sa cv::ThresholdTypes +//! @{ +#define CV_HAL_THRESH_BINARY 0 +#define CV_HAL_THRESH_BINARY_INV 1 +#define CV_HAL_THRESH_TRUNC 2 +#define CV_HAL_THRESH_TOZERO 3 +#define CV_HAL_THRESH_TOZERO_INV 4 +#define CV_HAL_THRESH_MASK 7 +#define CV_HAL_THRESH_OTSU 8 +#define CV_HAL_THRESH_TRIANGLE 16 +//! @} + +//! @name Adaptive threshold algorithm +//! @sa cv::AdaptiveThresholdTypes +//! @{ +#define CV_HAL_ADAPTIVE_THRESH_MEAN_C 0 +#define CV_HAL_ADAPTIVE_THRESH_GAUSSIAN_C 1 +//! @} + +//! @} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/imgproc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/imgproc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4175bd0bc01e0189abc4c698053c00e28277ef33 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/imgproc.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/imgproc.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/imgproc_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/imgproc_c.h new file mode 100644 index 0000000000000000000000000000000000000000..9f7131f7b838e0e4ac9229d503b35a7ed1fc2532 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/imgproc_c.h @@ -0,0 +1,1177 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_IMGPROC_IMGPROC_C_H +#define OPENCV_IMGPROC_IMGPROC_C_H + +#include "opencv2/imgproc/types_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup imgproc_c +@{ +*/ + +/*********************** Background statistics accumulation *****************************/ + +/** @brief Adds image to accumulator +@see cv::accumulate +*/ +CVAPI(void) cvAcc( const CvArr* image, CvArr* sum, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Adds squared image to accumulator +@see cv::accumulateSquare +*/ +CVAPI(void) cvSquareAcc( const CvArr* image, CvArr* sqsum, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Adds a product of two images to accumulator +@see cv::accumulateProduct +*/ +CVAPI(void) cvMultiplyAcc( const CvArr* image1, const CvArr* image2, CvArr* acc, + const CvArr* mask CV_DEFAULT(NULL) ); + +/** @brief Adds image to accumulator with weights: acc = acc*(1-alpha) + image*alpha +@see cv::accumulateWeighted +*/ +CVAPI(void) cvRunningAvg( const CvArr* image, CvArr* acc, double alpha, + const CvArr* mask CV_DEFAULT(NULL) ); + +/****************************************************************************************\ +* Image Processing * +\****************************************************************************************/ + +/** Copies source 2D array inside of the larger destination array and + makes a border of the specified type (IPL_BORDER_*) around the copied area. */ +CVAPI(void) cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset, + int bordertype, CvScalar value CV_DEFAULT(cvScalarAll(0))); + +/** @brief Smooths the image in one of several ways. + +@param src The source image +@param dst The destination image +@param smoothtype Type of the smoothing, see SmoothMethod_c +@param size1 The first parameter of the smoothing operation, the aperture width. Must be a +positive odd number (1, 3, 5, ...) +@param size2 The second parameter of the smoothing operation, the aperture height. Ignored by +CV_MEDIAN and CV_BILATERAL methods. In the case of simple scaled/non-scaled and Gaussian blur if +size2 is zero, it is set to size1. Otherwise it must be a positive odd number. +@param sigma1 In the case of a Gaussian parameter this parameter may specify Gaussian \f$\sigma\f$ +(standard deviation). If it is zero, it is calculated from the kernel size: +\f[\sigma = 0.3 (n/2 - 1) + 0.8 \quad \text{where} \quad n= \begin{array}{l l} \mbox{\texttt{size1} for horizontal kernel} \\ \mbox{\texttt{size2} for vertical kernel} \end{array}\f] +Using standard sigma for small kernels ( \f$3\times 3\f$ to \f$7\times 7\f$ ) gives better speed. If +sigma1 is not zero, while size1 and size2 are zeros, the kernel size is calculated from the +sigma (to provide accurate enough operation). +@param sigma2 additional parameter for bilateral filtering + +@see cv::GaussianBlur, cv::blur, cv::medianBlur, cv::bilateralFilter. + */ +CVAPI(void) cvSmooth( const CvArr* src, CvArr* dst, + int smoothtype CV_DEFAULT(CV_GAUSSIAN), + int size1 CV_DEFAULT(3), + int size2 CV_DEFAULT(0), + double sigma1 CV_DEFAULT(0), + double sigma2 CV_DEFAULT(0)); + +/** @brief Convolves an image with the kernel. + +@param src input image. +@param dst output image of the same size and the same number of channels as src. +@param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point +matrix; if you want to apply different kernels to different channels, split the image into +separate color planes using split and process them individually. +@param anchor anchor of the kernel that indicates the relative position of a filtered point within +the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor +is at the kernel center. + +@see cv::filter2D + */ +CVAPI(void) cvFilter2D( const CvArr* src, CvArr* dst, const CvMat* kernel, + CvPoint anchor CV_DEFAULT(cvPoint(-1,-1))); + +/** @brief Finds integral image: SUM(X,Y) = sum(x \texttt{hist1}(I)\)}{\frac{\texttt{hist2}(I) \cdot \texttt{scale}}{\texttt{hist1}(I)}}{if \(\texttt{hist1}(I) \ne 0\) and \(\texttt{hist2}(I) \le \texttt{hist1}(I)\)}\f] + +@param hist1 First histogram (the divisor). +@param hist2 Second histogram. +@param dst_hist Destination histogram. +@param scale Scale factor for the destination histogram. + */ +CVAPI(void) cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2, + CvHistogram* dst_hist, double scale CV_DEFAULT(255) ); + +/** @brief equalizes histogram of 8-bit single-channel image +@see cv::equalizeHist +*/ +CVAPI(void) cvEqualizeHist( const CvArr* src, CvArr* dst ); + + +/** @brief Applies distance transform to binary image +@see cv::distanceTransform +*/ +CVAPI(void) cvDistTransform( const CvArr* src, CvArr* dst, + int distance_type CV_DEFAULT(CV_DIST_L2), + int mask_size CV_DEFAULT(3), + const float* mask CV_DEFAULT(NULL), + CvArr* labels CV_DEFAULT(NULL), + int labelType CV_DEFAULT(CV_DIST_LABEL_CCOMP)); + + +/** @brief Applies fixed-level threshold to grayscale image. + + This is a basic operation applied before retrieving contours +@see cv::threshold +*/ +CVAPI(double) cvThreshold( const CvArr* src, CvArr* dst, + double threshold, double max_value, + int threshold_type ); + +/** @brief Applies adaptive threshold to grayscale image. + + The two parameters for methods CV_ADAPTIVE_THRESH_MEAN_C and + CV_ADAPTIVE_THRESH_GAUSSIAN_C are: + neighborhood size (3, 5, 7 etc.), + and a constant subtracted from mean (...,-3,-2,-1,0,1,2,3,...) +@see cv::adaptiveThreshold +*/ +CVAPI(void) cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value, + int adaptive_method CV_DEFAULT(CV_ADAPTIVE_THRESH_MEAN_C), + int threshold_type CV_DEFAULT(CV_THRESH_BINARY), + int block_size CV_DEFAULT(3), + double param1 CV_DEFAULT(5)); + +/** @brief Fills the connected component until the color difference gets large enough +@see cv::floodFill +*/ +CVAPI(void) cvFloodFill( CvArr* image, CvPoint seed_point, + CvScalar new_val, CvScalar lo_diff CV_DEFAULT(cvScalarAll(0)), + CvScalar up_diff CV_DEFAULT(cvScalarAll(0)), + CvConnectedComp* comp CV_DEFAULT(NULL), + int flags CV_DEFAULT(4), + CvArr* mask CV_DEFAULT(NULL)); + +/****************************************************************************************\ +* Feature detection * +\****************************************************************************************/ + +/** @brief Runs canny edge detector +@see cv::Canny +*/ +CVAPI(void) cvCanny( const CvArr* image, CvArr* edges, double threshold1, + double threshold2, int aperture_size CV_DEFAULT(3) ); + +/** @brief Calculates constraint image for corner detection + + Dx^2 * Dyy + Dxx * Dy^2 - 2 * Dx * Dy * Dxy. + Applying threshold to the result gives coordinates of corners +@see cv::preCornerDetect +*/ +CVAPI(void) cvPreCornerDetect( const CvArr* image, CvArr* corners, + int aperture_size CV_DEFAULT(3) ); + +/** @brief Calculates eigen values and vectors of 2x2 + gradient covariation matrix at every image pixel +@see cv::cornerEigenValsAndVecs +*/ +CVAPI(void) cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv, + int block_size, int aperture_size CV_DEFAULT(3) ); + +/** @brief Calculates minimal eigenvalue for 2x2 gradient covariation matrix at + every image pixel +@see cv::cornerMinEigenVal +*/ +CVAPI(void) cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval, + int block_size, int aperture_size CV_DEFAULT(3) ); + +/** @brief Harris corner detector: + + Calculates det(M) - k*(trace(M)^2), where M is 2x2 gradient covariation matrix for each pixel +@see cv::cornerHarris +*/ +CVAPI(void) cvCornerHarris( const CvArr* image, CvArr* harris_response, + int block_size, int aperture_size CV_DEFAULT(3), + double k CV_DEFAULT(0.04) ); + +/** @brief Adjust corner position using some sort of gradient search +@see cv::cornerSubPix +*/ +CVAPI(void) cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners, + int count, CvSize win, CvSize zero_zone, + CvTermCriteria criteria ); + +/** @brief Finds a sparse set of points within the selected region + that seem to be easy to track +@see cv::goodFeaturesToTrack +*/ +CVAPI(void) cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image, + CvArr* temp_image, CvPoint2D32f* corners, + int* corner_count, double quality_level, + double min_distance, + const CvArr* mask CV_DEFAULT(NULL), + int block_size CV_DEFAULT(3), + int use_harris CV_DEFAULT(0), + double k CV_DEFAULT(0.04) ); + +/** @brief Finds lines on binary image using one of several methods. + + line_storage is either memory storage or 1 x _max number of lines_ CvMat, its + number of columns is changed by the function. + method is one of CV_HOUGH_*; + rho, theta and threshold are used for each of those methods; + param1 ~ line length, param2 ~ line gap - for probabilistic, + param1 ~ srn, param2 ~ stn - for multi-scale +@see cv::HoughLines +*/ +CVAPI(CvSeq*) cvHoughLines2( CvArr* image, void* line_storage, int method, + double rho, double theta, int threshold, + double param1 CV_DEFAULT(0), double param2 CV_DEFAULT(0), + double min_theta CV_DEFAULT(0), double max_theta CV_DEFAULT(CV_PI)); + +/** @brief Finds circles in the image +@see cv::HoughCircles +*/ +CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage, + int method, double dp, double min_dist, + double param1 CV_DEFAULT(100), + double param2 CV_DEFAULT(100), + int min_radius CV_DEFAULT(0), + int max_radius CV_DEFAULT(0)); + +/** @brief Fits a line into set of 2d or 3d points in a robust way (M-estimator technique) +@see cv::fitLine +*/ +CVAPI(void) cvFitLine( const CvArr* points, int dist_type, double param, + double reps, double aeps, float* line ); + +/****************************************************************************************\ +* Drawing * +\****************************************************************************************/ + +/****************************************************************************************\ +* Drawing functions work with images/matrices of arbitrary type. * +* For color images the channel order is BGR[A] * +* Antialiasing is supported only for 8-bit image now. * +* All the functions include parameter color that means rgb value (that may be * +* constructed with CV_RGB macro) for color images and brightness * +* for grayscale images. * +* If a drawn figure is partially or completely outside of the image, it is clipped.* +\****************************************************************************************/ + +#define CV_FILLED -1 + +#define CV_AA 16 + +/** @brief Draws 4-connected, 8-connected or antialiased line segment connecting two points +@see cv::line +*/ +CVAPI(void) cvLine( CvArr* img, CvPoint pt1, CvPoint pt2, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ); + +/** @brief Draws a rectangle given two opposite corners of the rectangle (pt1 & pt2) + + if thickness<0 (e.g. thickness == CV_FILLED), the filled box is drawn +@see cv::rectangle +*/ +CVAPI(void) cvRectangle( CvArr* img, CvPoint pt1, CvPoint pt2, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), + int shift CV_DEFAULT(0)); + +/** @brief Draws a rectangle specified by a CvRect structure +@see cv::rectangle +*/ +CVAPI(void) cvRectangleR( CvArr* img, CvRect r, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), + int shift CV_DEFAULT(0)); + + +/** @brief Draws a circle with specified center and radius. + + Thickness works in the same way as with cvRectangle +@see cv::circle +*/ +CVAPI(void) cvCircle( CvArr* img, CvPoint center, int radius, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0)); + +/** @brief Draws ellipse outline, filled ellipse, elliptic arc or filled elliptic sector + + depending on _thickness_, _start_angle_ and _end_angle_ parameters. The resultant figure + is rotated by _angle_. All the angles are in degrees +@see cv::ellipse +*/ +CVAPI(void) cvEllipse( CvArr* img, CvPoint center, CvSize axes, + double angle, double start_angle, double end_angle, + CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0)); + +CV_INLINE void cvEllipseBox( CvArr* img, CvBox2D box, CvScalar color, + int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ) +{ + CvSize axes = cvSize( + cvRound(box.size.width*0.5), + cvRound(box.size.height*0.5) + ); + + cvEllipse( img, cvPointFrom32f( box.center ), axes, box.angle, + 0, 360, color, thickness, line_type, shift ); +} + +/** @brief Fills convex or monotonous polygon. +@see cv::fillConvexPoly +*/ +CVAPI(void) cvFillConvexPoly( CvArr* img, const CvPoint* pts, int npts, CvScalar color, + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0)); + +/** @brief Fills an area bounded by one or more arbitrary polygons +@see cv::fillPoly +*/ +CVAPI(void) cvFillPoly( CvArr* img, CvPoint** pts, const int* npts, + int contours, CvScalar color, + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ); + +/** @brief Draws one or more polygonal curves +@see cv::polylines +*/ +CVAPI(void) cvPolyLine( CvArr* img, CvPoint** pts, const int* npts, int contours, + int is_closed, CvScalar color, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0) ); + +#define cvDrawRect cvRectangle +#define cvDrawLine cvLine +#define cvDrawCircle cvCircle +#define cvDrawEllipse cvEllipse +#define cvDrawPolyLine cvPolyLine + +/** @brief Clips the line segment connecting *pt1 and *pt2 + by the rectangular window + + (0<=xptr will point to pt1 (or pt2, see left_to_right description) location in +the image. Returns the number of pixels on the line between the ending points. +@see cv::LineIterator +*/ +CVAPI(int) cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2, + CvLineIterator* line_iterator, + int connectivity CV_DEFAULT(8), + int left_to_right CV_DEFAULT(0)); + +#define CV_NEXT_LINE_POINT( line_iterator ) \ +{ \ + int _line_iterator_mask = (line_iterator).err < 0 ? -1 : 0; \ + (line_iterator).err += (line_iterator).minus_delta + \ + ((line_iterator).plus_delta & _line_iterator_mask); \ + (line_iterator).ptr += (line_iterator).minus_step + \ + ((line_iterator).plus_step & _line_iterator_mask); \ +} + + +#define CV_FONT_HERSHEY_SIMPLEX 0 +#define CV_FONT_HERSHEY_PLAIN 1 +#define CV_FONT_HERSHEY_DUPLEX 2 +#define CV_FONT_HERSHEY_COMPLEX 3 +#define CV_FONT_HERSHEY_TRIPLEX 4 +#define CV_FONT_HERSHEY_COMPLEX_SMALL 5 +#define CV_FONT_HERSHEY_SCRIPT_SIMPLEX 6 +#define CV_FONT_HERSHEY_SCRIPT_COMPLEX 7 + +#define CV_FONT_ITALIC 16 + +#define CV_FONT_VECTOR0 CV_FONT_HERSHEY_SIMPLEX + + +/** Font structure */ +typedef struct CvFont +{ + const char* nameFont; //Qt:nameFont + CvScalar color; //Qt:ColorFont -> cvScalar(blue_component, green_component, red_component[, alpha_component]) + int font_face; //Qt: bool italic /** =CV_FONT_* */ + const int* ascii; //!< font data and metrics + const int* greek; + const int* cyrillic; + float hscale, vscale; + float shear; //!< slope coefficient: 0 - normal, >0 - italic + int thickness; //!< Qt: weight /** letters thickness */ + float dx; //!< horizontal interval between letters + int line_type; //!< Qt: PointSize +} +CvFont; + +/** @brief Initializes font structure (OpenCV 1.x API). + +The function initializes the font structure that can be passed to text rendering functions. + +@param font Pointer to the font structure initialized by the function +@param font_face Font name identifier. See cv::HersheyFonts and corresponding old CV_* identifiers. +@param hscale Horizontal scale. If equal to 1.0f , the characters have the original width +depending on the font type. If equal to 0.5f , the characters are of half the original width. +@param vscale Vertical scale. If equal to 1.0f , the characters have the original height depending +on the font type. If equal to 0.5f , the characters are of half the original height. +@param shear Approximate tangent of the character slope relative to the vertical line. A zero +value means a non-italic font, 1.0f means about a 45 degree slope, etc. +@param thickness Thickness of the text strokes +@param line_type Type of the strokes, see line description + +@sa cvPutText + */ +CVAPI(void) cvInitFont( CvFont* font, int font_face, + double hscale, double vscale, + double shear CV_DEFAULT(0), + int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8)); + +CV_INLINE CvFont cvFont( double scale, int thickness CV_DEFAULT(1) ) +{ + CvFont font; + cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, scale, scale, 0, thickness, CV_AA ); + return font; +} + +/** @brief Renders text stroke with specified font and color at specified location. + CvFont should be initialized with cvInitFont +@see cvInitFont, cvGetTextSize, cvFont, cv::putText +*/ +CVAPI(void) cvPutText( CvArr* img, const char* text, CvPoint org, + const CvFont* font, CvScalar color ); + +/** @brief Calculates bounding box of text stroke (useful for alignment) +@see cv::getTextSize +*/ +CVAPI(void) cvGetTextSize( const char* text_string, const CvFont* font, + CvSize* text_size, int* baseline ); + +/** @brief Unpacks color value + +if arrtype is CV_8UC?, _color_ is treated as packed color value, otherwise the first channels +(depending on arrtype) of destination scalar are set to the same value = _color_ +*/ +CVAPI(CvScalar) cvColorToScalar( double packed_color, int arrtype ); + +/** @brief Returns the polygon points which make up the given ellipse. + +The ellipse is define by the box of size 'axes' rotated 'angle' around the 'center'. A partial +sweep of the ellipse arc can be done by spcifying arc_start and arc_end to be something other than +0 and 360, respectively. The input array 'pts' must be large enough to hold the result. The total +number of points stored into 'pts' is returned by this function. +@see cv::ellipse2Poly +*/ +CVAPI(int) cvEllipse2Poly( CvPoint center, CvSize axes, + int angle, int arc_start, int arc_end, CvPoint * pts, int delta ); + +/** @brief Draws contour outlines or filled interiors on the image +@see cv::drawContours +*/ +CVAPI(void) cvDrawContours( CvArr *img, CvSeq* contour, + CvScalar external_color, CvScalar hole_color, + int max_level, int thickness CV_DEFAULT(1), + int line_type CV_DEFAULT(8), + CvPoint offset CV_DEFAULT(cvPoint(0,0))); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/types_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/types_c.h new file mode 100644 index 0000000000000000000000000000000000000000..d3e55f576f6e93136d030285f7e753865a34ed41 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/imgproc/types_c.h @@ -0,0 +1,659 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_IMGPROC_TYPES_C_H +#define OPENCV_IMGPROC_TYPES_C_H + +#include "opencv2/core/core_c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @addtogroup imgproc_c + @{ +*/ + +/** Connected component structure */ +typedef struct CvConnectedComp +{ + double area; /** DBL_EPSILON ? 1./std::sqrt(am00) : 0; + } + operator cv::Moments() const + { + return cv::Moments(m00, m10, m01, m20, m11, m02, m30, m21, m12, m03); + } +#endif +} +CvMoments; + +#ifdef __cplusplus +} // extern "C" + +CV_INLINE CvMoments cvMoments() +{ +#if !defined(CV__ENABLE_C_API_CTORS) + CvMoments self = CV_STRUCT_INITIALIZER; return self; +#else + return CvMoments(); +#endif +} + +CV_INLINE CvMoments cvMoments(const cv::Moments& m) +{ +#if !defined(CV__ENABLE_C_API_CTORS) + double am00 = std::abs(m.m00); + CvMoments self = { + m.m00, m.m10, m.m01, m.m20, m.m11, m.m02, m.m30, m.m21, m.m12, m.m03, + m.mu20, m.mu11, m.mu02, m.mu30, m.mu21, m.mu12, m.mu03, + am00 > DBL_EPSILON ? 1./std::sqrt(am00) : 0 + }; + return self; +#else + return CvMoments(m); +#endif +} + +extern "C" { +#endif // __cplusplus + +/** Hu invariants */ +typedef struct CvHuMoments +{ + double hu1, hu2, hu3, hu4, hu5, hu6, hu7; /**< Hu invariants */ +} +CvHuMoments; + +/** Template matching methods */ +enum +{ + CV_TM_SQDIFF =0, + CV_TM_SQDIFF_NORMED =1, + CV_TM_CCORR =2, + CV_TM_CCORR_NORMED =3, + CV_TM_CCOEFF =4, + CV_TM_CCOEFF_NORMED =5 +}; + +typedef float (CV_CDECL * CvDistanceFunction)( const float* a, const float* b, void* user_param ); + +/** Contour retrieval modes */ +enum +{ + CV_RETR_EXTERNAL=0, + CV_RETR_LIST=1, + CV_RETR_CCOMP=2, + CV_RETR_TREE=3, + CV_RETR_FLOODFILL=4 +}; + +/** Contour approximation methods */ +enum +{ + CV_CHAIN_CODE=0, + CV_CHAIN_APPROX_NONE=1, + CV_CHAIN_APPROX_SIMPLE=2, + CV_CHAIN_APPROX_TC89_L1=3, + CV_CHAIN_APPROX_TC89_KCOS=4, + CV_LINK_RUNS=5 +}; + +/* +Internal structure that is used for sequential retrieving contours from the image. +It supports both hierarchical and plane variants of Suzuki algorithm. +*/ +typedef struct _CvContourScanner* CvContourScanner; + +/** Freeman chain reader state */ +typedef struct CvChainPtReader +{ + CV_SEQ_READER_FIELDS() + char code; + CvPoint pt; + schar deltas[8][2]; +} +CvChainPtReader; + +/** initializes 8-element array for fast access to 3x3 neighborhood of a pixel */ +#define CV_INIT_3X3_DELTAS( deltas, step, nch ) \ + ((deltas)[0] = (nch), (deltas)[1] = -(step) + (nch), \ + (deltas)[2] = -(step), (deltas)[3] = -(step) - (nch), \ + (deltas)[4] = -(nch), (deltas)[5] = (step) - (nch), \ + (deltas)[6] = (step), (deltas)[7] = (step) + (nch)) + + +/** Contour approximation algorithms */ +enum +{ + CV_POLY_APPROX_DP = 0 +}; + +/** Shape matching methods */ +enum +{ + CV_CONTOURS_MATCH_I1 =1, //!< \f[I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |\f] + CV_CONTOURS_MATCH_I2 =2, //!< \f[I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |\f] + CV_CONTOURS_MATCH_I3 =3 //!< \f[I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }\f] +}; + +/** Shape orientation */ +enum +{ + CV_CLOCKWISE =1, + CV_COUNTER_CLOCKWISE =2 +}; + + +/** Convexity defect */ +typedef struct CvConvexityDefect +{ + CvPoint* start; /**< point of the contour where the defect begins */ + CvPoint* end; /**< point of the contour where the defect ends */ + CvPoint* depth_point; /**< the farthest from the convex hull point within the defect */ + float depth; /**< distance between the farthest point and the convex hull */ +} CvConvexityDefect; + + +/** Histogram comparison methods */ +enum +{ + CV_COMP_CORREL =0, + CV_COMP_CHISQR =1, + CV_COMP_INTERSECT =2, + CV_COMP_BHATTACHARYYA =3, + CV_COMP_HELLINGER =CV_COMP_BHATTACHARYYA, + CV_COMP_CHISQR_ALT =4, + CV_COMP_KL_DIV =5 +}; + +/** Mask size for distance transform */ +enum +{ + CV_DIST_MASK_3 =3, + CV_DIST_MASK_5 =5, + CV_DIST_MASK_PRECISE =0 +}; + +/** Content of output label array: connected components or pixels */ +enum +{ + CV_DIST_LABEL_CCOMP = 0, + CV_DIST_LABEL_PIXEL = 1 +}; + +/** Distance types for Distance Transform and M-estimators */ +enum +{ + CV_DIST_USER =-1, /**< User defined distance */ + CV_DIST_L1 =1, /**< distance = |x1-x2| + |y1-y2| */ + CV_DIST_L2 =2, /**< the simple euclidean distance */ + CV_DIST_C =3, /**< distance = max(|x1-x2|,|y1-y2|) */ + CV_DIST_L12 =4, /**< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */ + CV_DIST_FAIR =5, /**< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */ + CV_DIST_WELSCH =6, /**< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */ + CV_DIST_HUBER =7 /**< distance = |x| threshold ? max_value : 0 */ + CV_THRESH_BINARY_INV =1, /**< value = value > threshold ? 0 : max_value */ + CV_THRESH_TRUNC =2, /**< value = value > threshold ? threshold : value */ + CV_THRESH_TOZERO =3, /**< value = value > threshold ? value : 0 */ + CV_THRESH_TOZERO_INV =4, /**< value = value > threshold ? 0 : value */ + CV_THRESH_MASK =7, + CV_THRESH_OTSU =8, /**< use Otsu algorithm to choose the optimal threshold value; + combine the flag with one of the above CV_THRESH_* values */ + CV_THRESH_TRIANGLE =16 /**< use Triangle algorithm to choose the optimal threshold value; + combine the flag with one of the above CV_THRESH_* values, but not + with CV_THRESH_OTSU */ +}; + +/** Adaptive threshold methods */ +enum +{ + CV_ADAPTIVE_THRESH_MEAN_C =0, + CV_ADAPTIVE_THRESH_GAUSSIAN_C =1 +}; + +/** FloodFill flags */ +enum +{ + CV_FLOODFILL_FIXED_RANGE =(1 << 16), + CV_FLOODFILL_MASK_ONLY =(1 << 17) +}; + + +/** Canny edge detector flags */ +enum +{ + CV_CANNY_L2_GRADIENT =(1 << 31) +}; + +/** Variants of a Hough transform */ +enum +{ + CV_HOUGH_STANDARD =0, + CV_HOUGH_PROBABILISTIC =1, + CV_HOUGH_MULTI_SCALE =2, + CV_HOUGH_GRADIENT =3 +}; + + +/* Fast search data structures */ +struct CvFeatureTree; +struct CvLSH; +struct CvLSHOperations; + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/line_descriptor.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/line_descriptor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cb2969fd8bd745452b3916ebb2e5f600d7608b41 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/line_descriptor.hpp @@ -0,0 +1,119 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2013, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#ifndef __OPENCV_LINE_DESCRIPTOR_HPP__ +#define __OPENCV_LINE_DESCRIPTOR_HPP__ + +#include "opencv2/line_descriptor/descriptor.hpp" + +/** @defgroup line_descriptor Binary descriptors for lines extracted from an image + +Introduction +------------ + +One of the most challenging activities in computer vision is the extraction of useful information +from a given image. Such information, usually comes in the form of points that preserve some kind of +property (for instance, they are scale-invariant) and are actually representative of input image. + +The goal of this module is seeking a new kind of representative information inside an image and +providing the functionalities for its extraction and representation. In particular, differently from +previous methods for detection of relevant elements inside an image, lines are extracted in place of +points; a new class is defined ad hoc to summarize a line's properties, for reuse and plotting +purposes. + +Computation of binary descriptors +--------------------------------- + +To obtatin a binary descriptor representing a certain line detected from a certain octave of an +image, we first compute a non-binary descriptor as described in @cite LBD . Such algorithm works on +lines extracted using EDLine detector, as explained in @cite EDL . Given a line, we consider a +rectangular region centered at it and called *line support region (LSR)*. Such region is divided +into a set of bands \f$\{B_1, B_2, ..., B_m\}\f$, whose length equals the one of line. + +If we indicate with \f$\bf{d}_L\f$ the direction of line, the orthogonal and clockwise direction to line +\f$\bf{d}_{\perp}\f$ can be determined; these two directions, are used to construct a reference frame +centered in the middle point of line. The gradients of pixels \f$\bf{g'}\f$ inside LSR can be projected +to the newly determined frame, obtaining their local equivalent +\f$\bf{g'} = (\bf{g}^T \cdot \bf{d}_{\perp}, \bf{g}^T \cdot \bf{d}_L)^T \triangleq (\bf{g'}_{d_{\perp}}, \bf{g'}_{d_L})^T\f$. + +Later on, a Gaussian function is applied to all LSR's pixels along \f$\bf{d}_\perp\f$ direction; first, +we assign a global weighting coefficient \f$f_g(i) = (1/\sqrt{2\pi}\sigma_g)e^{-d^2_i/2\sigma^2_g}\f$ to +*i*-th row in LSR, where \f$d_i\f$ is the distance of *i*-th row from the center row in LSR, +\f$\sigma_g = 0.5(m \cdot w - 1)\f$ and \f$w\f$ is the width of bands (the same for every band). Secondly, +considering a band \f$B_j\f$ and its neighbor bands \f$B_{j-1}, B_{j+1}\f$, we assign a local weighting +\f$F_l(k) = (1/\sqrt{2\pi}\sigma_l)e^{-d'^2_k/2\sigma_l^2}\f$, where \f$d'_k\f$ is the distance of *k*-th +row from the center row in \f$B_j\f$ and \f$\sigma_l = w\f$. Using the global and local weights, we obtain, +at the same time, the reduction of role played by gradients far from line and of boundary effect, +respectively. + +Each band \f$B_j\f$ in LSR has an associated *band descriptor(BD)* which is computed considering +previous and next band (top and bottom bands are ignored when computing descriptor for first and +last band). Once each band has been assignen its BD, the LBD descriptor of line is simply given by + +\f[LBD = (BD_1^T, BD_2^T, ... , BD^T_m)^T.\f] + +To compute a band descriptor \f$B_j\f$, each *k*-th row in it is considered and the gradients in such +row are accumulated: + +\f[\begin{matrix} \bf{V1}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}>0}\bf{g}'_{d_\perp}, & \bf{V2}^k_j = \lambda \sum\limits_{\bf{g}'_{d_\perp}<0} -\bf{g}'_{d_\perp}, \\ \bf{V3}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}>0}\bf{g}'_{d_L}, & \bf{V4}^k_j = \lambda \sum\limits_{\bf{g}'_{d_L}<0} -\bf{g}'_{d_L}\end{matrix}.\f] + +with \f$\lambda = f_g(k)f_l(k)\f$. + +By stacking previous results, we obtain the *band description matrix (BDM)* + +\f[BDM_j = \left(\begin{matrix} \bf{V1}_j^1 & \bf{V1}_j^2 & \ldots & \bf{V1}_j^n \\ \bf{V2}_j^1 & \bf{V2}_j^2 & \ldots & \bf{V2}_j^n \\ \bf{V3}_j^1 & \bf{V3}_j^2 & \ldots & \bf{V3}_j^n \\ \bf{V4}_j^1 & \bf{V4}_j^2 & \ldots & \bf{V4}_j^n \end{matrix} \right) \in \mathbb{R}^{4\times n},\f] + +with \f$n\f$ the number of rows in band \f$B_j\f$: + +\f[n = \begin{cases} 2w, & j = 1||m; \\ 3w, & \mbox{else}. \end{cases}\f] + +Each \f$BD_j\f$ can be obtained using the standard deviation vector \f$S_j\f$ and mean vector \f$M_j\f$ of +\f$BDM_J\f$. Thus, finally: + +\f[LBD = (M_1^T, S_1^T, M_2^T, S_2^T, \ldots, M_m^T, S_m^T)^T \in \mathbb{R}^{8m}\f] + +Once the LBD has been obtained, it must be converted into a binary form. For such purpose, we +consider 32 possible pairs of BD inside it; each couple of BD is compared bit by bit and comparison +generates an 8 bit string. Concatenating 32 comparison strings, we get the 256-bit final binary +representation of a single LBD. +*/ + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/line_descriptor/descriptor.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/line_descriptor/descriptor.hpp new file mode 100644 index 0000000000000000000000000000000000000000..15e8fe7b4f7194170b48eaf978619c6db5f12c54 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/line_descriptor/descriptor.hpp @@ -0,0 +1,1205 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2014, Biagio Montesano, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#ifndef __OPENCV_DESCRIPTOR_HPP__ +#define __OPENCV_DESCRIPTOR_HPP__ + +#include +#include +#include + +#if defined _MSC_VER && _MSC_VER <= 1700 +#include +#else +#include +#endif + +#include +#include + +#include "opencv2/core/utility.hpp" +#include +#include "opencv2/core.hpp" + +/* define data types */ +typedef uint64_t UINT64; +typedef uint32_t UINT32; +typedef uint16_t UINT16; +typedef uint8_t UINT8; + +/* define constants */ +#define UINT64_1 ((UINT64)0x01) +#define UINT32_1 ((UINT32)0x01) + +namespace cv +{ +namespace line_descriptor +{ + +//! @addtogroup line_descriptor +//! @{ + +/** @brief A class to represent a line + +As aformentioned, it is been necessary to design a class that fully stores the information needed to +characterize completely a line and plot it on image it was extracted from, when required. + +*KeyLine* class has been created for such goal; it is mainly inspired to Feature2d's KeyPoint class, +since KeyLine shares some of *KeyPoint*'s fields, even if a part of them assumes a different +meaning, when speaking about lines. In particular: + +- the *class_id* field is used to gather lines extracted from different octaves which refer to + same line inside original image (such lines and the one they represent in original image share + the same *class_id* value) +- the *angle* field represents line's slope with respect to (positive) X axis +- the *pt* field represents line's midpoint +- the *response* field is computed as the ratio between the line's length and maximum between + image's width and height +- the *size* field is the area of the smallest rectangle containing line + +Apart from fields inspired to KeyPoint class, KeyLines stores information about extremes of line in +original image and in octave it was extracted from, about line's length and number of pixels it +covers. + */ +struct CV_EXPORTS_W_SIMPLE KeyLine +{ + public: + /** orientation of the line */ + CV_PROP_RW float angle; + + /** object ID, that can be used to cluster keylines by the line they represent */ + CV_PROP_RW int class_id; + + /** octave (pyramid layer), from which the keyline has been extracted */ + CV_PROP_RW int octave; + + /** coordinates of the middlepoint */ + CV_PROP_RW Point2f pt; + + /** the response, by which the strongest keylines have been selected. + It's represented by the ratio between line's length and maximum between + image's width and height */ + CV_PROP_RW float response; + + /** minimum area containing line */ + CV_PROP_RW float size; + + /** lines's extremes in original image */ + CV_PROP_RW float startPointX; + CV_PROP_RW float startPointY; + CV_PROP_RW float endPointX; + CV_PROP_RW float endPointY; + + /** line's extremes in image it was extracted from */ + CV_PROP_RW float sPointInOctaveX; + CV_PROP_RW float sPointInOctaveY; + CV_PROP_RW float ePointInOctaveX; + CV_PROP_RW float ePointInOctaveY; + + /** the length of line */ + CV_PROP_RW float lineLength; + + /** number of pixels covered by the line */ + CV_PROP_RW int numOfPixels; + + /** Returns the start point of the line in the original image */ + CV_WRAP Point2f getStartPoint() const + { + return Point2f(startPointX, startPointY); + } + + /** Returns the end point of the line in the original image */ + CV_WRAP Point2f getEndPoint() const + { + return Point2f(endPointX, endPointY); + } + + /** Returns the start point of the line in the octave it was extracted from */ + CV_WRAP Point2f getStartPointInOctave() const + { + return Point2f(sPointInOctaveX, sPointInOctaveY); + } + + /** Returns the end point of the line in the octave it was extracted from */ + CV_WRAP Point2f getEndPointInOctave() const + { + return Point2f(ePointInOctaveX, ePointInOctaveY); + } + + /** constructor */ + CV_WRAP KeyLine() + { + } +}; + +/** @brief Class implements both functionalities for detection of lines and computation of their +binary descriptor. + +Class' interface is mainly based on the ones of classical detectors and extractors, such as +Feature2d's @ref features2d_main and @ref features2d_match. Retrieved information about lines is +stored in line_descriptor::KeyLine objects. + */ +class CV_EXPORTS_W BinaryDescriptor : public Algorithm +{ + + public: + /** @brief List of BinaryDescriptor parameters: + */ + struct CV_EXPORTS Params + { + /*CV_WRAP*/ + Params(); + + /** the number of image octaves (default = 1) */ + + int numOfOctave_; + + /** the width of band; (default: 7) */ + + int widthOfBand_; + + /** image's reduction ratio in construction of Gaussian pyramids */ + int reductionRatio; + + int ksize_; + + /** read parameters from a FileNode object and store them (struct function) */ + void read( const FileNode& fn ); + + /** store parameters to a FileStorage object (struct function) */ + void write( FileStorage& fs ) const; + + }; + + /** @brief Constructor + + @param parameters configuration parameters BinaryDescriptor::Params + + If no argument is provided, constructor sets default values (see comments in the code snippet in + previous section). Default values are strongly recommended. + */ + BinaryDescriptor( const BinaryDescriptor::Params ¶meters = BinaryDescriptor::Params() ); + + /** @brief Create a BinaryDescriptor object with default parameters (or with the ones provided) + and return a smart pointer to it + */ + CV_WRAP static Ptr createBinaryDescriptor(); + static Ptr createBinaryDescriptor( Params parameters ); + + /** destructor */ + ~BinaryDescriptor(); + + /** @brief Get current number of octaves + */ + CV_WRAP int getNumOfOctaves(); + /** @brief Set number of octaves + @param octaves number of octaves + */ + CV_WRAP void setNumOfOctaves( int octaves ); + /** @brief Get current width of bands + */ + CV_WRAP int getWidthOfBand(); + /** @brief Set width of bands + @param width width of bands + */ + CV_WRAP void setWidthOfBand( int width ); + /** @brief Get current reduction ratio (used in Gaussian pyramids) + */ + CV_WRAP int getReductionRatio(); + /** @brief Set reduction ratio (used in Gaussian pyramids) + @param rRatio reduction ratio + */ + CV_WRAP void setReductionRatio( int rRatio ); + + /** @brief Read parameters from a FileNode object and store them + + @param fn source FileNode file + */ + virtual void read( const cv::FileNode& fn ) CV_OVERRIDE; + + /** @brief Store parameters to a FileStorage object + + @param fs output FileStorage file + */ + virtual void write( cv::FileStorage& fs ) const CV_OVERRIDE; + + /** @brief Requires line detection + + @param image input image + @param keypoints vector that will store extracted lines for one or more images + @param mask mask matrix to detect only KeyLines of interest + */ + CV_WRAP void detect( const Mat& image, CV_OUT std::vector& keypoints, const Mat& mask = Mat() ); + + /** @overload + + @param images input images + @param keylines set of vectors that will store extracted lines for one or more images + @param masks vector of mask matrices to detect only KeyLines of interest from each input image + */ + void detect( const std::vector& images, std::vector >& keylines, const std::vector& masks = + std::vector() ) const; + + /** @brief Requires descriptors computation + + @param image input image + @param keylines vector containing lines for which descriptors must be computed + @param descriptors + @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) + */ + CV_WRAP void compute( const Mat& image, CV_OUT CV_IN_OUT std::vector& keylines, CV_OUT Mat& descriptors, bool returnFloatDescr = false ) const; + + /** @overload + + @param images input images + @param keylines set of vectors containing lines for which descriptors must be computed + @param descriptors + @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) + */ + void compute( const std::vector& images, std::vector >& keylines, std::vector& descriptors, bool returnFloatDescr = + false ) const; + + /** @brief Return descriptor size + */ + int descriptorSize() const; + + /** @brief Return data type + */ + int descriptorType() const; + + /** returns norm mode */ + /*CV_WRAP*/ + int defaultNorm() const; + + /** @brief Define operator '()' to perform detection of KeyLines and computation of descriptors in a row. + + @param image input image + @param mask mask matrix to select which lines in KeyLines must be accepted among the ones + extracted (used when *keylines* is not empty) + @param keylines vector that contains input lines (when filled, the detection part will be skipped + and input lines will be passed as input to the algorithm computing descriptors) + @param descriptors matrix that will store final descriptors + @param useProvidedKeyLines flag (when set to true, detection phase will be skipped and only + computation of descriptors will be executed, using lines provided in *keylines*) + @param returnFloatDescr flag (when set to true, original non-binary descriptors are returned) + */ + virtual void operator()( InputArray image, InputArray mask, CV_OUT std::vector& keylines, OutputArray descriptors, + bool useProvidedKeyLines = false, bool returnFloatDescr = false ) const; + + protected: + /** implementation of line detection */ + virtual void detectImpl( const Mat& imageSrc, std::vector& keylines, const Mat& mask = Mat() ) const; + + /** implementation of descriptors' computation */ + virtual void computeImpl( const Mat& imageSrc, std::vector& keylines, Mat& descriptors, bool returnFloatDescr, + bool useDetectionData ) const; + + private: + /** struct to represent lines extracted from an octave */ + struct OctaveLine + { + unsigned int octaveCount; //the octave which this line is detected + unsigned int lineIDInOctave; //the line ID in that octave image + unsigned int lineIDInScaleLineVec; //the line ID in Scale line vector + float lineLength; //the length of line in original image scale + }; + + // A 2D line (normal equation parameters). + struct SingleLine + { + //note: rho and theta are based on coordinate origin, i.e. the top-left corner of image + double rho; //unit: pixel length + double theta; //unit: rad + double linePointX; // = rho * cos(theta); + double linePointY; // = rho * sin(theta); + //for EndPoints, the coordinate origin is the top-left corner of image. + double startPointX; + double startPointY; + double endPointX; + double endPointY; + //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis. + double direction; + //mean gradient magnitude + double gradientMagnitude; + //mean gray value of pixels in dark side of line + double darkSideGrayValue; + //mean gray value of pixels in light side of line + double lightSideGrayValue; + //the length of line + double lineLength; + //the width of line; + double width; + //number of pixels + int numOfPixels; + //the decriptor of line + std::vector descriptor; + }; + + // Specifies a vector of lines. + typedef std::vector Lines_list; + + struct OctaveSingleLine + { + /*endPoints, the coordinate origin is the top-left corner of the original image. + *startPointX = sPointInOctaveX * (factor)^octaveCount; */ + float startPointX; + float startPointY; + float endPointX; + float endPointY; + //endPoints, the coordinate origin is the top-left corner of the octave image. + float sPointInOctaveX; + float sPointInOctaveY; + float ePointInOctaveX; + float ePointInOctaveY; + //direction of a line, the angle between positive line direction (dark side is in the left) and positive X axis. + float direction; + //the summation of gradient magnitudes of pixels on lines + float salience; + //the length of line + float lineLength; + //number of pixels + unsigned int numOfPixels; + //the octave which this line is detected + unsigned int octaveCount; + //the decriptor of line + std::vector descriptor; + + OctaveSingleLine() : startPointX(0), startPointY(0), endPointX(0), endPointY(0), + sPointInOctaveX(0), sPointInOctaveY(0), ePointInOctaveX(0), ePointInOctaveY(0), + direction(0), salience(0), lineLength(0), numOfPixels(0), octaveCount(0), + descriptor(std::vector()) + {} + }; + + struct Pixel + { + unsigned int x; //X coordinate + unsigned int y; //Y coordinate + }; + struct EdgeChains + { + std::vector xCors; //all the x coordinates of edge points + std::vector yCors; //all the y coordinates of edge points + std::vector sId; //the start index of each edge in the coordinate arrays + unsigned int numOfEdges; //the number of edges whose length are larger than minLineLen; numOfEdges < sId.size; + }; + + struct LineChains + { + std::vector xCors; //all the x coordinates of line points + std::vector yCors; //all the y coordinates of line points + std::vector sId; //the start index of each line in the coordinate arrays + unsigned int numOfLines; //the number of lines whose length are larger than minLineLen; numOfLines < sId.size; + }; + + typedef std::list PixelChain; //each edge is a pixel chain + + struct CV_EXPORTS_W_SIMPLE EDLineParam + { + CV_PROP_RW int ksize; + CV_PROP_RW float sigma; + CV_PROP_RW float gradientThreshold; + CV_PROP_RW float anchorThreshold; + CV_PROP_RW int scanIntervals; + CV_PROP_RW int minLineLen; + CV_PROP_RW double lineFitErrThreshold; + }; + + #define RELATIVE_ERROR_FACTOR 100.0 + #define MLN10 2.30258509299404568402 + #define log_gamma(x) ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x)) + + /** This class is used to detect lines from input image. + * First, edges are extracted from input image following the method presented in Cihan Topal and + * Cuneyt Akinlar's paper:"Edge Drawing: A Heuristic Approach to Robust Real-Time Edge Detection", 2010. + * Then, lines are extracted from the edge image following the method presented in Cuneyt Akinlar and + * Cihan Topal's paper:"EDLines: A real-time line segment detector with a false detection control", 2011 + * PS: The linking step of edge detection has a little bit difference with the Edge drawing algorithm + * described in the paper. The edge chain doesn't stop when the pixel direction is changed. + */ + class CV_EXPORTS_W EDLineDetector + { + public: + CV_WRAP EDLineDetector(); + CV_WRAP_AS(EDLineDetectorWithParams) EDLineDetector( EDLineParam param ); + ~EDLineDetector(); + + /** @brief Creates an EDLineDetector object, using smart pointers. + */ + CV_WRAP static Ptr createEDLineDetector(); + + + CV_WRAP_AS(createEDLineDetectorWithParams) static Ptr createEDLineDetector(EDLineParam params); + /*extract edges from image + *image: In, gray image; + *edges: Out, store the edges, each edge is a pixel chain + *return -1: error happen + */ + int EdgeDrawing( cv::Mat &image, EdgeChains &edgeChains ); + + /*extract lines from image + *image: In, gray image; + *lines: Out, store the extracted lines, + *return -1: error happen + */ + int EDline( cv::Mat &image, LineChains &lines ); + + /** extract line from image, and store them */ + CV_WRAP int EDline( cv::Mat &image ); + + cv::Mat dxImg_; //store the dxImg; + + cv::Mat dyImg_; //store the dyImg; + + cv::Mat gImgWO_; //store the gradient image without threshold; + + LineChains lines_; //store the detected line chains; + + //store the line Equation coefficients, vec3=[w1,w2,w3] for line w1*x + w2*y + w3=0; + std::vector > lineEquations_; + + //store the line endpoints, [x1,y1,x2,y3] + std::vector > lineEndpoints_; + + //store the line direction + std::vector lineDirection_; + + //store the line salience, which is the summation of gradients of pixels on line + std::vector lineSalience_; + + // image sizes + unsigned int imageWidth; + unsigned int imageHeight; + + /*The threshold of line fit error; + *If lineFitErr is large than this threshold, then + *the pixel chain is not accepted as a single line segment.*/ + double lineFitErrThreshold_; + + /*the threshold of pixel gradient magnitude. + *Only those pixel whose gradient magnitude are larger than this threshold will be + *taken as possible edge points. Default value is 36*/ + short gradienThreshold_; + + /*If the pixel's gradient value is bigger than both of its neighbors by a + *certain threshold (ANCHOR_THRESHOLD), the pixel is marked to be an anchor. + *Default value is 8*/ + unsigned char anchorThreshold_; + + /*anchor testing can be performed at different scan intervals, i.e., + *every row/column, every second row/column etc. + *Default value is 2*/ + unsigned int scanIntervals_; + + int minLineLen_; //minimal acceptable line length + + private: + void InitEDLine_(); + + /*For an input edge chain, find the best fit line, the default chain length is minLineLen_ + *xCors: In, pointer to the X coordinates of pixel chain; + *yCors: In, pointer to the Y coordinates of pixel chain; + *offsetS:In, start index of this chain in vector; + *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical); + *return: line fit error; -1:error happens; + */ + double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, std::vector &lineEquation ); + + /*For an input pixel chain, find the best fit line. Only do the update based on new points. + *For A*x=v, Least square estimation of x = Inv(A^T * A) * (A^T * v); + *If some new observations are added, i.e, [A; A'] * x = [v; v'], + *then x' = Inv(A^T * A + (A')^T * A') * (A^T * v + (A')^T * v'); + *xCors: In, pointer to the X coordinates of pixel chain; + *yCors: In, pointer to the Y coordinates of pixel chain; + *offsetS:In, start index of this chain in vector; + *newOffsetS: In, start index of extended part; + *offsetE:In, end index of this chain in vector; + *lineEquation: Out, [a,b] which are the coefficient of lines y=ax+b(horizontal) or x=ay+b(vertical); + *return: line fit error; -1:error happens; + */ + double LeastSquaresLineFit_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int newOffsetS, unsigned int offsetE, + std::vector &lineEquation ); + + /** Validate line based on the Helmholtz principle, which basically states that + * for a structure to be perceptually meaningful, the expectation of this structure + * by chance must be very low. + */ + bool LineValidation_( unsigned int *xCors, unsigned int *yCors, unsigned int offsetS, unsigned int offsetE, std::vector &lineEquation, + float &direction ); + + bool bValidate_; //flag to decide whether line will be validated + + int ksize_; //the size of Gaussian kernel: ksize X ksize, default value is 5. + + float sigma_; //the sigma of Gaussian kernal, default value is 1.0. + + /*For example, there two edges in the image: + *edge1 = [(7,4), (8,5), (9,6),| (10,7)|, (11, 8), (12,9)] and + *edge2 = [(14,9), (15,10), (16,11), (17,12),| (18, 13)|, (19,14)] ; then we store them as following: + *pFirstPartEdgeX_ = [10, 11, 12, 18, 19];//store the first part of each edge[from middle to end] + *pFirstPartEdgeY_ = [7, 8, 9, 13, 14]; + *pFirstPartEdgeS_ = [0,3,5];// the index of start point of first part of each edge + *pSecondPartEdgeX_ = [10, 9, 8, 7, 18, 17, 16, 15, 14];//store the second part of each edge[from middle to front] + *pSecondPartEdgeY_ = [7, 6, 5, 4, 13, 12, 11, 10, 9];//anchor points(10, 7) and (18, 13) are stored again + *pSecondPartEdgeS_ = [0, 4, 9];// the index of start point of second part of each edge + *This type of storage order is because of the order of edge detection process. + *For each edge, start from one anchor point, first go right, then go left or first go down, then go up*/ + + //store the X coordinates of the first part of the pixels for chains + unsigned int *pFirstPartEdgeX_; + + //store the Y coordinates of the first part of the pixels for chains + unsigned int *pFirstPartEdgeY_; + + //store the start index of every edge chain in the first part arrays + unsigned int *pFirstPartEdgeS_; + + //store the X coordinates of the second part of the pixels for chains + unsigned int *pSecondPartEdgeX_; + + //store the Y coordinates of the second part of the pixels for chains + unsigned int *pSecondPartEdgeY_; + + //store the start index of every edge chain in the second part arrays + unsigned int *pSecondPartEdgeS_; + + //store the X coordinates of anchors + unsigned int *pAnchorX_; + + //store the Y coordinates of anchors + unsigned int *pAnchorY_; + + //edges + cv::Mat edgeImage_; + + cv::Mat gImg_; //store the gradient image; + + cv::Mat dirImg_; //store the direction image + + double logNT_; + + cv::Mat_ ATA; //the previous matrix of A^T * A; + + cv::Mat_ ATV; //the previous vector of A^T * V; + + cv::Mat_ fitMatT; //the matrix used in line fit function; + + cv::Mat_ fitVec; //the vector used in line fit function; + + cv::Mat_ tempMatLineFit; //the matrix used in line fit function; + + cv::Mat_ tempVecLineFit; //the vector used in line fit function; + +}; + + // Specifies a vector of lines. +typedef std::vector LinesVec; + +// each element in ScaleLines is a vector of lines +// which corresponds the same line detected in different octave images. +typedef std::vector ScaleLines; + +/* compute Gaussian pyramids */ +void computeGaussianPyramid( const Mat& image, const int numOctaves ); + +/* compute Sobel's derivatives */ +void computeSobel( const Mat& image, const int numOctaves ); + +/* conversion of an LBD descriptor to its binary representation */ +unsigned char binaryConversion( float* f1, float* f2 ); + +/* compute LBD descriptors using EDLine extractor */ +int computeLBD( ScaleLines &keyLines, bool useDetectionData = false ); + +/* gathers lines in groups using EDLine extractor. + Each group contains the same line, detected in different octaves */ +int OctaveKeyLines( cv::Mat& image, ScaleLines &keyLines ); + +/* the local gaussian coefficient applied to the orthogonal line direction within each band */ +std::vector gaussCoefL_; + +/* the global gaussian coefficient applied to each row within line support region */ +std::vector gaussCoefG_; + +/* descriptor parameters */ +Params params; + +/* vector of sizes of downsampled and blurred images */ +std::vector images_sizes; + +/*For each octave of image, we define an EDLineDetector, because we can get gradient images (dxImg, dyImg, gImg) + *from the EDLineDetector class without extra computation cost. Another reason is that, if we use + *a single EDLineDetector to detect lines in different octave of images, then we need to allocate and release + *memory for gradient images (dxImg, dyImg, gImg) repeatedly for their varying size*/ +std::vector > edLineVec_; + +/* Sobel's derivatives */ +std::vector dxImg_vector, dyImg_vector; + +/* Gaussian pyramid */ +std::vector octaveImages; + +}; + +/** +Lines extraction methodology +---------------------------- + +The lines extraction methodology described in the following is mainly based on @cite EDL . The +extraction starts with a Gaussian pyramid generated from an original image, downsampled N-1 times, +blurred N times, to obtain N layers (one for each octave), with layer 0 corresponding to input +image. Then, from each layer (octave) in the pyramid, lines are extracted using LSD algorithm. + +Differently from EDLine lines extractor used in original article, LSD furnishes information only +about lines extremes; thus, additional information regarding slope and equation of line are computed +via analytic methods. The number of pixels is obtained using *LineIterator*. Extracted lines are +returned in the form of KeyLine objects, but since extraction is based on a method different from +the one used in *BinaryDescriptor* class, data associated to a line's extremes in original image and +in octave it was extracted from, coincide. KeyLine's field *class_id* is used as an index to +indicate the order of extraction of a line inside a single octave. +*/ +struct CV_EXPORTS_W_SIMPLE LSDParam +{ + CV_PROP_RW double scale ; + CV_PROP_RW double sigma_scale; + CV_PROP_RW double quant; + CV_PROP_RW double ang_th; + CV_PROP_RW double log_eps; + CV_PROP_RW double density_th ; + CV_PROP_RW int n_bins ; + + +CV_WRAP LSDParam():scale(0.8), + sigma_scale(0.6), + quant(2.0), + ang_th(22.5), + log_eps(0), + density_th(0.7), + n_bins(1024){} + +}; + +class CV_EXPORTS_W LSDDetector : public Algorithm +{ +public: + +/* constructor */ +CV_WRAP LSDDetector() : params() +{ +} +; + +CV_WRAP_AS(LSDDetectorWithParams) LSDDetector(LSDParam _params) : params(_params) +{ +} +; + +/** @brief Creates ad LSDDetector object, using smart pointers. + */ +CV_WRAP static Ptr createLSDDetector(); + + +CV_WRAP_AS(createLSDDetectorWithParams) static Ptr createLSDDetector(LSDParam params); + + +/** @brief Detect lines inside an image. + +@param image input image +@param keypoints vector that will store extracted lines for one or more images +@param scale scale factor used in pyramids generation +@param numOctaves number of octaves inside pyramid +@param mask mask matrix to detect only KeyLines of interest + */ +CV_WRAP void detect( const Mat& image, CV_OUT std::vector& keypoints, int scale, int numOctaves, const Mat& mask = Mat() ); + +/** @overload +@param images input images +@param keylines set of vectors that will store extracted lines for one or more images +@param scale scale factor used in pyramids generation +@param numOctaves number of octaves inside pyramid +@param masks vector of mask matrices to detect only KeyLines of interest from each input image +*/ +CV_WRAP void detect( const std::vector& images, std::vector >& keylines, int scale, int numOctaves, +const std::vector& masks = std::vector() ) const; + +private: +/* compute Gaussian pyramid of input image */ +void computeGaussianPyramid( const Mat& image, int numOctaves, int scale ); + +/* implementation of line detection */ +void detectImpl( const Mat& imageSrc, std::vector& keylines, int numOctaves, int scale, const Mat& mask ) const; + +/* matrices for Gaussian pyramids */ +std::vector gaussianPyrs; + +/* parameters */ +LSDParam params; +}; + +/** @brief furnishes all functionalities for querying a dataset provided by user or internal to +class (that user must, anyway, populate) on the model of @ref features2d_match + + +Once descriptors have been extracted from an image (both they represent lines and points), it +becomes interesting to be able to match a descriptor with another one extracted from a different +image and representing the same line or point, seen from a differente perspective or on a different +scale. In reaching such goal, the main headache is designing an efficient search algorithm to +associate a query descriptor to one extracted from a dataset. In the following, a matching modality +based on *Multi-Index Hashing (MiHashing)* will be described. + +Multi-Index Hashing +------------------- + +The theory described in this section is based on @cite MIH . Given a dataset populated with binary +codes, each code is indexed *m* times into *m* different hash tables, according to *m* substrings it +has been divided into. Thus, given a query code, all the entries close to it at least in one +substring are returned by search as *neighbor candidates*. Returned entries are then checked for +validity by verifying that their full codes are not distant (in Hamming space) more than *r* bits +from query code. In details, each binary code **h** composed of *b* bits is divided into *m* +disjoint substrings \f$\mathbf{h}^{(1)}, ..., \mathbf{h}^{(m)}\f$, each with length +\f$\lfloor b/m \rfloor\f$ or \f$\lceil b/m \rceil\f$ bits. Formally, when two codes **h** and **g** differ +by at the most *r* bits, in at the least one of their *m* substrings they differ by at the most +\f$\lfloor r/m \rfloor\f$ bits. In particular, when \f$||\mathbf{h}-\mathbf{g}||_H \le r\f$ (where \f$||.||_H\f$ +is the Hamming norm), there must exist a substring *k* (with \f$1 \le k \le m\f$) such that + +\f[||\mathbf{h}^{(k)} - \mathbf{g}^{(k)}||_H \le \left\lfloor \frac{r}{m} \right\rfloor .\f] + +That means that if Hamming distance between each of the *m* substring is strictly greater than +\f$\lfloor r/m \rfloor\f$, then \f$||\mathbf{h}-\mathbf{g}||_H\f$ must be larger that *r* and that is a +contradiction. If the codes in dataset are divided into *m* substrings, then *m* tables will be +built. Given a query **q** with substrings \f$\{\mathbf{q}^{(i)}\}^m_{i=1}\f$, *i*-th hash table is +searched for entries distant at the most \f$\lfloor r/m \rfloor\f$ from \f$\mathbf{q}^{(i)}\f$ and a set of +candidates \f$\mathcal{N}_i(\mathbf{q})\f$ is obtained. The union of sets +\f$\mathcal{N}(\mathbf{q}) = \bigcup_i \mathcal{N}_i(\mathbf{q})\f$ is a superset of the *r*-neighbors +of **q**. Then, last step of algorithm is computing the Hamming distance between **q** and each +element in \f$\mathcal{N}(\mathbf{q})\f$, deleting the codes that are distant more that *r* from **q**. +*/ +class CV_EXPORTS_W BinaryDescriptorMatcher : public Algorithm +{ + +public: +/** @brief For every input query descriptor, retrieve the best matching one from a dataset provided from user +or from the one internal to class + +@param queryDescriptors query descriptors +@param trainDescriptors dataset of descriptors furnished by user +@param matches vector to host retrieved matches +@param mask mask to select which input descriptors must be matched to one in dataset + */ +CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector& matches, const Mat& mask = Mat() ) const; + +/** @overload +@param queryDescriptors query descriptors +@param matches vector to host retrieved matches +@param masks vector of masks to select which input descriptors must be matched to one in dataset +(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in +dataset relative to *i*-th image) +*/ +CV_WRAP_AS(matchQuery) void match( const Mat& queryDescriptors, CV_OUT std::vector& matches, const std::vector& masks = std::vector() ); + +/** @brief For every input query descriptor, retrieve the best *k* matching ones from a dataset provided from +user or from the one internal to class + +@param queryDescriptors query descriptors +@param trainDescriptors dataset of descriptors furnished by user +@param matches vector to host retrieved matches +@param k number of the closest descriptors to be returned for every input query +@param mask mask to select which input descriptors must be matched to ones in dataset +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) + */ +CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, CV_OUT std::vector >& matches, int k, const Mat& mask = Mat(), +bool compactResult = false ) const; + +/** @overload +@param queryDescriptors query descriptors +@param matches vector to host retrieved matches +@param k number of the closest descriptors to be returned for every input query +@param masks vector of masks to select which input descriptors must be matched to ones in dataset +(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in +dataset relative to *i*-th image) +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) +*/ +CV_WRAP_AS(knnMatchQuery) void knnMatch( const Mat& queryDescriptors, std::vector >& matches, int k, const std::vector& masks = std::vector(), +bool compactResult = false ); + +/** @brief For every input query descriptor, retrieve, from a dataset provided from user or from the one +internal to class, all the descriptors that are not further than *maxDist* from input query + +@param queryDescriptors query descriptors +@param trainDescriptors dataset of descriptors furnished by user +@param matches vector to host retrieved matches +@param maxDistance search radius +@param mask mask to select which input descriptors must be matched to ones in dataset +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) + */ +void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors, std::vector >& matches, float maxDistance, +const Mat& mask = Mat(), bool compactResult = false ) const; + +/** @overload +@param queryDescriptors query descriptors +@param matches vector to host retrieved matches +@param maxDistance search radius +@param masks vector of masks to select which input descriptors must be matched to ones in dataset +(the *i*-th mask in vector indicates whether each input query can be matched with descriptors in +dataset relative to *i*-th image) +@param compactResult flag to obtain a compact result (if true, a vector that doesn't contain any +matches for a given query is not inserted in final result) +*/ +void radiusMatch( const Mat& queryDescriptors, std::vector >& matches, float maxDistance, const std::vector& masks = +std::vector(), +bool compactResult = false ); + +/** @brief Store locally new descriptors to be inserted in dataset, without updating dataset. + +@param descriptors matrices containing descriptors to be inserted into dataset + +@note Each matrix *i* in **descriptors** should contain descriptors relative to lines extracted from +*i*-th image. + */ +void add( const std::vector& descriptors ); + +/** @brief Update dataset by inserting into it all descriptors that were stored locally by *add* function. + +@note Every time this function is invoked, current dataset is deleted and locally stored descriptors +are inserted into dataset. The locally stored copy of just inserted descriptors is then removed. + */ +void train(); + +/** @brief Create a BinaryDescriptorMatcher object and return a smart pointer to it. + */ +static Ptr createBinaryDescriptorMatcher(); + +/** @brief Clear dataset and internal data + */ +void clear() CV_OVERRIDE; + +/** @brief Constructor. + +The BinaryDescriptorMatcher constructed is able to store and manage 256-bits long entries. + */ +CV_WRAP BinaryDescriptorMatcher(); + +/** destructor */ +~BinaryDescriptorMatcher() +{ +} + +private: +class BucketGroup +{ + +public: +/** constructor */ +BucketGroup(bool needAllocateGroup = true); + +/** destructor */ +~BucketGroup(); + +/** insert data into the bucket */ +void insert( int subindex, UINT32 data ); + +/** perform a query to the bucket */ +UINT32* query( int subindex, int *size ); + +/** utility functions */ +void insert_value( std::vector& vec, int index, UINT32 data ); +void push_value( std::vector& vec, UINT32 Data ); + +/** data fields */ +UINT32 empty; +std::vector group; + + +}; + +class SparseHashtable +{ + +private: + +/** Maximum bits per key before folding the table */ +static const int MAX_B; + +/** Bins (each bin is an Array object for duplicates of the same key) */ +std::vector table; + +public: + +/** constructor */ +SparseHashtable(); + +/** destructor */ +~SparseHashtable(); + +/** initializer */ +int init( int _b ); + +/** insert data */ +void insert( UINT64 index, UINT32 data ); + +/** query data */ +UINT32* query( UINT64 index, int* size ); + +/** Bits per index */ +int b; + +/** Number of bins */ +UINT64 size; + +}; + +/** class defining a sequence of bits */ +class bitarray +{ + +public: +/** pointer to bits sequence and sequence's length */ +UINT32 *arr; +UINT32 length; + +/** constructor setting default values */ +bitarray() +{ +arr = NULL; +length = 0; +} + +/** constructor setting sequence's length */ +bitarray( UINT64 _bits ) +{ +arr = NULL; +init( _bits ); +} + +/** initializer of private fields */ +void init( UINT64 _bits ) +{ +if( arr ) +delete[] arr; +length = (UINT32) ceil( _bits / 32.00 ); +arr = new UINT32[length]; +erase(); +} + +/** destructor */ +~bitarray() +{ +if( arr ) +delete[] arr; +} + +inline void flip( UINT64 index ) +{ +arr[index >> 5] ^= ( (UINT32) 0x01 ) << ( index % 32 ); +} + +inline void set( UINT64 index ) +{ +arr[index >> 5] |= ( (UINT32) 0x01 ) << ( index % 32 ); +} + +inline UINT8 get( UINT64 index ) +{ +return ( arr[index >> 5] & ( ( (UINT32) 0x01 ) << ( index % 32 ) ) ) != 0; +} + +/** reserve menory for an UINT32 */ +inline void erase() +{ +memset( arr, 0, sizeof(UINT32) * length ); +} + +}; + +class Mihasher +{ + +public: +/** Bits per code */ +int B; + +/** B/8 */ +int B_over_8; + +/** Bits per chunk (must be less than 64) */ +int b; + +/** Number of chunks */ +int m; + +/** Number of chunks with b bits (have 1 bit more than others) */ +int mplus; + +/** Maximum hamming search radius (we use B/2 by default) */ +int D; + +/** Maximum hamming search radius per substring */ +int d; + +/** Maximum results to return */ +int K; + +/** Number of codes */ +UINT64 N; + +/** Table of original full-length codes */ +cv::Mat codes; + +/** Counter for eliminating duplicate results (it is not thread safe) */ +Ptr counter; + +/** Array of m hashtables */ +std::vector H; + +/** Volume of a b-bit Hamming ball with radius s (for s = 0 to d) */ +std::vector xornum; + +/** Used within generation of binary codes at a certain Hamming distance */ +int power[100]; + +/** constructor */ +Mihasher(); + +/** desctructor */ +~Mihasher(); + +/** constructor 2 */ +Mihasher( int B, int m ); + +/** K setter */ +void setK( int K ); + +/** populate tables */ +void populate( cv::Mat & codes, UINT32 N, int dim1codes ); + +/** execute a batch query */ +void batchquery( UINT32 * results, UINT32 *numres/*, qstat *stats*/, const cv::Mat & q, UINT32 numq, int dim1queries ); + +private: + +/** execute a single query */ +void query( UINT32 * results, UINT32* numres/*, qstat *stats*/, UINT8 *q, UINT64 * chunks, UINT32 * res ); +}; + +/** retrieve Hamming distances */ +void checkKDistances( UINT32 * numres, int k, std::vector& k_distances, int row, int string_length ) const; + +/** matrix to store new descriptors */ +Mat descriptorsMat; + +/** map storing where each bunch of descriptors benins in DS */ +std::map indexesMap; + +/** internal MiHaser representing dataset */ +Ptr dataset; + +/** index from which next added descriptors' bunch must begin */ +int nextAddedIndex; + +/** number of images whose descriptors are stored in DS */ +int numImages; + +/** number of descriptors in dataset */ +int descrInDS; + +}; + +/* -------------------------------------------------------------------------------------------- + UTILITY FUNCTIONS + -------------------------------------------------------------------------------------------- */ + +/** struct for drawing options */ +struct CV_EXPORTS_W_SIMPLE DrawLinesMatchesFlags +{ +CV_PROP_RW enum +{ +DEFAULT = 0, //!< Output image matrix will be created (Mat::create), + //!< i.e. existing memory of output image may be reused. + //!< Two source images, matches, and single keylines + //!< will be drawn. +DRAW_OVER_OUTIMG = 1,//!< Output image matrix will not be +//!< created (using Mat::create). Matches will be drawn +//!< on existing content of output image. +NOT_DRAW_SINGLE_LINES = 2//!< Single keylines will not be drawn. +}; +}; + +/** @brief Draws the found matches of keylines from two images. + +@param img1 first image +@param keylines1 keylines extracted from first image +@param img2 second image +@param keylines2 keylines extracted from second image +@param matches1to2 vector of matches +@param outImg output matrix to draw on +@param matchColor drawing color for matches (chosen randomly in case of default value) +@param singleLineColor drawing color for keylines (chosen randomly in case of default value) +@param matchesMask mask to indicate which matches must be drawn +@param flags drawing flags, see DrawLinesMatchesFlags + +@note If both *matchColor* and *singleLineColor* are set to their default values, function draws +matched lines and line connecting them with same color + */ +CV_EXPORTS_W void drawLineMatches( const Mat& img1, const std::vector& keylines1, const Mat& img2, const std::vector& keylines2, + const std::vector& matches1to2, CV_OUT Mat& outImg, const Scalar& matchColor = Scalar::all( -1 ), + const Scalar& singleLineColor = Scalar::all( -1 ), const std::vector& matchesMask = std::vector(), + int flags = DrawLinesMatchesFlags::DEFAULT ); + +/** @brief Draws keylines. + +@param image input image +@param keylines keylines to be drawn +@param outImage output image to draw on +@param color color of lines to be drawn (if set to defaul value, color is chosen randomly) +@param flags drawing flags + */ +CV_EXPORTS_W void drawKeylines( const Mat& image, const std::vector& keylines, CV_OUT Mat& outImage, const Scalar& color = Scalar::all( -1 ), + int flags = DrawLinesMatchesFlags::DEFAULT ); + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a92b8f9a90ea24c3e1373649cd1e9de29e276d5d --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml.hpp @@ -0,0 +1,1947 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Copyright (C) 2014, Itseez Inc, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_ML_HPP +#define OPENCV_ML_HPP + +#ifdef __cplusplus +# include "opencv2/core.hpp" +#endif + +#ifdef __cplusplus + +#include +#include +#include + +/** + @defgroup ml Machine Learning + + The Machine Learning Library (MLL) is a set of classes and functions for statistical + classification, regression, and clustering of data. + + Most of the classification and regression algorithms are implemented as C++ classes. As the + algorithms have different sets of features (like an ability to handle missing measurements or + categorical input variables), there is a little common ground between the classes. This common + ground is defined by the class cv::ml::StatModel that all the other ML classes are derived from. + + See detailed overview here: @ref ml_intro. + */ + +namespace cv +{ + +namespace ml +{ + +//! @addtogroup ml +//! @{ + +/** @brief Variable types */ +enum VariableTypes +{ + VAR_NUMERICAL =0, //!< same as VAR_ORDERED + VAR_ORDERED =0, //!< ordered variables + VAR_CATEGORICAL =1 //!< categorical variables +}; + +/** @brief %Error types */ +enum ErrorTypes +{ + TEST_ERROR = 0, + TRAIN_ERROR = 1 +}; + +/** @brief Sample types */ +enum SampleTypes +{ + ROW_SAMPLE = 0, //!< each training sample is a row of samples + COL_SAMPLE = 1 //!< each training sample occupies a column of samples +}; + +/** @brief The structure represents the logarithmic grid range of statmodel parameters. + +It is used for optimizing statmodel accuracy by varying model parameters, the accuracy estimate +being computed by cross-validation. + */ +class CV_EXPORTS_W ParamGrid +{ +public: + /** @brief Default constructor */ + ParamGrid(); + /** @brief Constructor with parameters */ + ParamGrid(double _minVal, double _maxVal, double _logStep); + + CV_PROP_RW double minVal; //!< Minimum value of the statmodel parameter. Default value is 0. + CV_PROP_RW double maxVal; //!< Maximum value of the statmodel parameter. Default value is 0. + /** @brief Logarithmic step for iterating the statmodel parameter. + + The grid determines the following iteration sequence of the statmodel parameter values: + \f[(minVal, minVal*step, minVal*{step}^2, \dots, minVal*{logStep}^n),\f] + where \f$n\f$ is the maximal index satisfying + \f[\texttt{minVal} * \texttt{logStep} ^n < \texttt{maxVal}\f] + The grid is logarithmic, so logStep must always be greater than 1. Default value is 1. + */ + CV_PROP_RW double logStep; + + /** @brief Creates a ParamGrid Ptr that can be given to the %SVM::trainAuto method + + @param minVal minimum value of the parameter grid + @param maxVal maximum value of the parameter grid + @param logstep Logarithmic step for iterating the statmodel parameter + */ + CV_WRAP static Ptr create(double minVal=0., double maxVal=0., double logstep=1.); +}; + +/** @brief Class encapsulating training data. + +Please note that the class only specifies the interface of training data, but not implementation. +All the statistical model classes in _ml_ module accepts Ptr\ as parameter. In other +words, you can create your own class derived from TrainData and pass smart pointer to the instance +of this class into StatModel::train. + +@sa @ref ml_intro_data + */ +class CV_EXPORTS_W TrainData +{ +public: + static inline float missingValue() { return FLT_MAX; } + virtual ~TrainData(); + + CV_WRAP virtual int getLayout() const = 0; + CV_WRAP virtual int getNTrainSamples() const = 0; + CV_WRAP virtual int getNTestSamples() const = 0; + CV_WRAP virtual int getNSamples() const = 0; + CV_WRAP virtual int getNVars() const = 0; + CV_WRAP virtual int getNAllVars() const = 0; + + CV_WRAP virtual void getSample(InputArray varIdx, int sidx, float* buf) const = 0; + CV_WRAP virtual Mat getSamples() const = 0; + CV_WRAP virtual Mat getMissing() const = 0; + + /** @brief Returns matrix of train samples + + @param layout The requested layout. If it's different from the initial one, the matrix is + transposed. See ml::SampleTypes. + @param compressSamples if true, the function returns only the training samples (specified by + sampleIdx) + @param compressVars if true, the function returns the shorter training samples, containing only + the active variables. + + In current implementation the function tries to avoid physical data copying and returns the + matrix stored inside TrainData (unless the transposition or compression is needed). + */ + CV_WRAP virtual Mat getTrainSamples(int layout=ROW_SAMPLE, + bool compressSamples=true, + bool compressVars=true) const = 0; + + /** @brief Returns the vector of responses + + The function returns ordered or the original categorical responses. Usually it's used in + regression algorithms. + */ + CV_WRAP virtual Mat getTrainResponses() const = 0; + + /** @brief Returns the vector of normalized categorical responses + + The function returns vector of responses. Each response is integer from `0` to `-1`. The actual label value can be retrieved then from the class label vector, see + TrainData::getClassLabels. + */ + CV_WRAP virtual Mat getTrainNormCatResponses() const = 0; + CV_WRAP virtual Mat getTestResponses() const = 0; + CV_WRAP virtual Mat getTestNormCatResponses() const = 0; + CV_WRAP virtual Mat getResponses() const = 0; + CV_WRAP virtual Mat getNormCatResponses() const = 0; + CV_WRAP virtual Mat getSampleWeights() const = 0; + CV_WRAP virtual Mat getTrainSampleWeights() const = 0; + CV_WRAP virtual Mat getTestSampleWeights() const = 0; + CV_WRAP virtual Mat getVarIdx() const = 0; + CV_WRAP virtual Mat getVarType() const = 0; + CV_WRAP virtual Mat getVarSymbolFlags() const = 0; + CV_WRAP virtual int getResponseType() const = 0; + CV_WRAP virtual Mat getTrainSampleIdx() const = 0; + CV_WRAP virtual Mat getTestSampleIdx() const = 0; + CV_WRAP virtual void getValues(int vi, InputArray sidx, float* values) const = 0; + virtual void getNormCatValues(int vi, InputArray sidx, int* values) const = 0; + CV_WRAP virtual Mat getDefaultSubstValues() const = 0; + + CV_WRAP virtual int getCatCount(int vi) const = 0; + + /** @brief Returns the vector of class labels + + The function returns vector of unique labels occurred in the responses. + */ + CV_WRAP virtual Mat getClassLabels() const = 0; + + CV_WRAP virtual Mat getCatOfs() const = 0; + CV_WRAP virtual Mat getCatMap() const = 0; + + /** @brief Splits the training data into the training and test parts + @sa TrainData::setTrainTestSplitRatio + */ + CV_WRAP virtual void setTrainTestSplit(int count, bool shuffle=true) = 0; + + /** @brief Splits the training data into the training and test parts + + The function selects a subset of specified relative size and then returns it as the training + set. If the function is not called, all the data is used for training. Please, note that for + each of TrainData::getTrain\* there is corresponding TrainData::getTest\*, so that the test + subset can be retrieved and processed as well. + @sa TrainData::setTrainTestSplit + */ + CV_WRAP virtual void setTrainTestSplitRatio(double ratio, bool shuffle=true) = 0; + CV_WRAP virtual void shuffleTrainTest() = 0; + + /** @brief Returns matrix of test samples */ + CV_WRAP virtual Mat getTestSamples() const = 0; + + /** @brief Returns vector of symbolic names captured in loadFromCSV() */ + CV_WRAP virtual void getNames(std::vector& names) const = 0; + + /** @brief Extract from 1D vector elements specified by passed indexes. + @param vec input vector (supported types: CV_32S, CV_32F, CV_64F) + @param idx 1D index vector + */ + static CV_WRAP Mat getSubVector(const Mat& vec, const Mat& idx); + + /** @brief Extract from matrix rows/cols specified by passed indexes. + @param matrix input matrix (supported types: CV_32S, CV_32F, CV_64F) + @param idx 1D index vector + @param layout specifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES) + */ + static CV_WRAP Mat getSubMatrix(const Mat& matrix, const Mat& idx, int layout); + + /** @brief Reads the dataset from a .csv file and returns the ready-to-use training data. + + @param filename The input file name + @param headerLineCount The number of lines in the beginning to skip; besides the header, the + function also skips empty lines and lines staring with `#` + @param responseStartIdx Index of the first output variable. If -1, the function considers the + last variable as the response + @param responseEndIdx Index of the last output variable + 1. If -1, then there is single + response variable at responseStartIdx. + @param varTypeSpec The optional text string that specifies the variables' types. It has the + format `ord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...]`. That is, variables from `n1 to n2` + (inclusive range), `n3`, `n4 to n5` ... are considered ordered and `n6`, `n7 to n8` ... are + considered as categorical. The range `[n1..n2] + [n3] + [n4..n5] + ... + [n6] + [n7..n8]` + should cover all the variables. If varTypeSpec is not specified, then algorithm uses the + following rules: + - all input variables are considered ordered by default. If some column contains has non- + numerical values, e.g. 'apple', 'pear', 'apple', 'apple', 'mango', the corresponding + variable is considered categorical. + - if there are several output variables, they are all considered as ordered. Error is + reported when non-numerical values are used. + - if there is a single output variable, then if its values are non-numerical or are all + integers, then it's considered categorical. Otherwise, it's considered ordered. + @param delimiter The character used to separate values in each line. + @param missch The character used to specify missing measurements. It should not be a digit. + Although it's a non-numerical value, it surely does not affect the decision of whether the + variable ordered or categorical. + @note If the dataset only contains input variables and no responses, use responseStartIdx = -2 + and responseEndIdx = 0. The output variables vector will just contain zeros. + */ + static Ptr loadFromCSV(const String& filename, + int headerLineCount, + int responseStartIdx=-1, + int responseEndIdx=-1, + const String& varTypeSpec=String(), + char delimiter=',', + char missch='?'); + + /** @brief Creates training data from in-memory arrays. + + @param samples matrix of samples. It should have CV_32F type. + @param layout see ml::SampleTypes. + @param responses matrix of responses. If the responses are scalar, they should be stored as a + single row or as a single column. The matrix should have type CV_32F or CV_32S (in the + former case the responses are considered as ordered by default; in the latter case - as + categorical) + @param varIdx vector specifying which variables to use for training. It can be an integer vector + (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of + active variables. + @param sampleIdx vector specifying which samples to use for training. It can be an integer + vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask + of training samples. + @param sampleWeights optional vector with weights for each sample. It should have CV_32F type. + @param varType optional vector of type CV_8U and size ` + + `, containing types of each input and output variable. See + ml::VariableTypes. + */ + CV_WRAP static Ptr create(InputArray samples, int layout, InputArray responses, + InputArray varIdx=noArray(), InputArray sampleIdx=noArray(), + InputArray sampleWeights=noArray(), InputArray varType=noArray()); +}; + +/** @brief Base class for statistical models in OpenCV ML. + */ +class CV_EXPORTS_W StatModel : public Algorithm +{ +public: + /** Predict options */ + enum Flags { + UPDATE_MODEL = 1, + RAW_OUTPUT=1, //!< makes the method return the raw results (the sum), not the class label + COMPRESSED_INPUT=2, + PREPROCESSED_INPUT=4 + }; + + /** @brief Returns the number of variables in training samples */ + CV_WRAP virtual int getVarCount() const = 0; + + CV_WRAP virtual bool empty() const CV_OVERRIDE; + + /** @brief Returns true if the model is trained */ + CV_WRAP virtual bool isTrained() const = 0; + /** @brief Returns true if the model is classifier */ + CV_WRAP virtual bool isClassifier() const = 0; + + /** @brief Trains the statistical model + + @param trainData training data that can be loaded from file using TrainData::loadFromCSV or + created with TrainData::create. + @param flags optional flags, depending on the model. Some of the models can be updated with the + new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP). + */ + CV_WRAP virtual bool train( const Ptr& trainData, int flags=0 ); + + /** @brief Trains the statistical model + + @param samples training samples + @param layout See ml::SampleTypes. + @param responses vector of responses associated with the training samples. + */ + CV_WRAP virtual bool train( InputArray samples, int layout, InputArray responses ); + + /** @brief Computes error on the training or test dataset + + @param data the training data + @param test if true, the error is computed over the test subset of the data, otherwise it's + computed over the training subset of the data. Please note that if you loaded a completely + different dataset to evaluate already trained classifier, you will probably want not to set + the test subset at all with TrainData::setTrainTestSplitRatio and specify test=false, so + that the error is computed for the whole new set. Yes, this sounds a bit confusing. + @param resp the optional output responses. + + The method uses StatModel::predict to compute the error. For regression models the error is + computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%). + */ + CV_WRAP virtual float calcError( const Ptr& data, bool test, OutputArray resp ) const; + + /** @brief Predicts response(s) for the provided sample(s) + + @param samples The input samples, floating-point matrix + @param results The optional output matrix of results. + @param flags The optional flags, model-dependent. See cv::ml::StatModel::Flags. + */ + CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const = 0; + + /** @brief Create and train model with default parameters + + The class must implement static `create()` method with no parameters or with all default parameter values + */ + template static Ptr<_Tp> train(const Ptr& data, int flags=0) + { + Ptr<_Tp> model = _Tp::create(); + return !model.empty() && model->train(data, flags) ? model : Ptr<_Tp>(); + } +}; + +/****************************************************************************************\ +* Normal Bayes Classifier * +\****************************************************************************************/ + +/** @brief Bayes classifier for normally distributed data. + +@sa @ref ml_intro_bayes + */ +class CV_EXPORTS_W NormalBayesClassifier : public StatModel +{ +public: + /** @brief Predicts the response for sample(s). + + The method estimates the most probable classes for input vectors. Input vectors (one or more) + are stored as rows of the matrix inputs. In case of multiple input vectors, there should be one + output vector outputs. The predicted class for a single input vector is returned by the method. + The vector outputProbs contains the output probabilities corresponding to each element of + result. + */ + CV_WRAP virtual float predictProb( InputArray inputs, OutputArray outputs, + OutputArray outputProbs, int flags=0 ) const = 0; + + /** Creates empty model + Use StatModel::train to train the model after creation. */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized NormalBayesClassifier from a file + * + * Use NormalBayesClassifier::save to serialize and store an NormalBayesClassifier to disk. + * Load the NormalBayesClassifier from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized NormalBayesClassifier + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* K-Nearest Neighbour Classifier * +\****************************************************************************************/ + +/** @brief The class implements K-Nearest Neighbors model + +@sa @ref ml_intro_knn + */ +class CV_EXPORTS_W KNearest : public StatModel +{ +public: + + /** Default number of neighbors to use in predict method. */ + /** @see setDefaultK */ + CV_WRAP virtual int getDefaultK() const = 0; + /** @copybrief getDefaultK @see getDefaultK */ + CV_WRAP virtual void setDefaultK(int val) = 0; + + /** Whether classification or regression model should be trained. */ + /** @see setIsClassifier */ + CV_WRAP virtual bool getIsClassifier() const = 0; + /** @copybrief getIsClassifier @see getIsClassifier */ + CV_WRAP virtual void setIsClassifier(bool val) = 0; + + /** Parameter for KDTree implementation. */ + /** @see setEmax */ + CV_WRAP virtual int getEmax() const = 0; + /** @copybrief getEmax @see getEmax */ + CV_WRAP virtual void setEmax(int val) = 0; + + /** %Algorithm type, one of KNearest::Types. */ + /** @see setAlgorithmType */ + CV_WRAP virtual int getAlgorithmType() const = 0; + /** @copybrief getAlgorithmType @see getAlgorithmType */ + CV_WRAP virtual void setAlgorithmType(int val) = 0; + + /** @brief Finds the neighbors and predicts responses for input vectors. + + @param samples Input samples stored by rows. It is a single-precision floating-point matrix of + ` * k` size. + @param k Number of used nearest neighbors. Should be greater than 1. + @param results Vector with results of prediction (regression or classification) for each input + sample. It is a single-precision floating-point vector with `` elements. + @param neighborResponses Optional output values for corresponding neighbors. It is a single- + precision floating-point matrix of ` * k` size. + @param dist Optional output distances from the input vectors to the corresponding neighbors. It + is a single-precision floating-point matrix of ` * k` size. + + For each input vector (a row of the matrix samples), the method finds the k nearest neighbors. + In case of regression, the predicted result is a mean value of the particular vector's neighbor + responses. In case of classification, the class is determined by voting. + + For each input vector, the neighbors are sorted by their distances to the vector. + + In case of C++ interface you can use output pointers to empty matrices and the function will + allocate memory itself. + + If only a single input vector is passed, all output matrices are optional and the predicted + value is returned by the method. + + The function is parallelized with the TBB library. + */ + CV_WRAP virtual float findNearest( InputArray samples, int k, + OutputArray results, + OutputArray neighborResponses=noArray(), + OutputArray dist=noArray() ) const = 0; + + /** @brief Implementations of KNearest algorithm + */ + enum Types + { + BRUTE_FORCE=1, + KDTREE=2 + }; + + /** @brief Creates the empty model + + The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method. + */ + CV_WRAP static Ptr create(); + /** @brief Loads and creates a serialized knearest from a file + * + * Use KNearest::save to serialize and store an KNearest to disk. + * Load the KNearest from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized KNearest + */ + CV_WRAP static Ptr load(const String& filepath); +}; + +/****************************************************************************************\ +* Support Vector Machines * +\****************************************************************************************/ + +/** @brief Support Vector Machines. + +@sa @ref ml_intro_svm + */ +class CV_EXPORTS_W SVM : public StatModel +{ +public: + + class CV_EXPORTS Kernel : public Algorithm + { + public: + virtual int getType() const = 0; + virtual void calc( int vcount, int n, const float* vecs, const float* another, float* results ) = 0; + }; + + /** Type of a %SVM formulation. + See SVM::Types. Default value is SVM::C_SVC. */ + /** @see setType */ + CV_WRAP virtual int getType() const = 0; + /** @copybrief getType @see getType */ + CV_WRAP virtual void setType(int val) = 0; + + /** Parameter \f$\gamma\f$ of a kernel function. + For SVM::POLY, SVM::RBF, SVM::SIGMOID or SVM::CHI2. Default value is 1. */ + /** @see setGamma */ + CV_WRAP virtual double getGamma() const = 0; + /** @copybrief getGamma @see getGamma */ + CV_WRAP virtual void setGamma(double val) = 0; + + /** Parameter _coef0_ of a kernel function. + For SVM::POLY or SVM::SIGMOID. Default value is 0.*/ + /** @see setCoef0 */ + CV_WRAP virtual double getCoef0() const = 0; + /** @copybrief getCoef0 @see getCoef0 */ + CV_WRAP virtual void setCoef0(double val) = 0; + + /** Parameter _degree_ of a kernel function. + For SVM::POLY. Default value is 0. */ + /** @see setDegree */ + CV_WRAP virtual double getDegree() const = 0; + /** @copybrief getDegree @see getDegree */ + CV_WRAP virtual void setDegree(double val) = 0; + + /** Parameter _C_ of a %SVM optimization problem. + For SVM::C_SVC, SVM::EPS_SVR or SVM::NU_SVR. Default value is 0. */ + /** @see setC */ + CV_WRAP virtual double getC() const = 0; + /** @copybrief getC @see getC */ + CV_WRAP virtual void setC(double val) = 0; + + /** Parameter \f$\nu\f$ of a %SVM optimization problem. + For SVM::NU_SVC, SVM::ONE_CLASS or SVM::NU_SVR. Default value is 0. */ + /** @see setNu */ + CV_WRAP virtual double getNu() const = 0; + /** @copybrief getNu @see getNu */ + CV_WRAP virtual void setNu(double val) = 0; + + /** Parameter \f$\epsilon\f$ of a %SVM optimization problem. + For SVM::EPS_SVR. Default value is 0. */ + /** @see setP */ + CV_WRAP virtual double getP() const = 0; + /** @copybrief getP @see getP */ + CV_WRAP virtual void setP(double val) = 0; + + /** Optional weights in the SVM::C_SVC problem, assigned to particular classes. + They are multiplied by _C_ so the parameter _C_ of class _i_ becomes `classWeights(i) * C`. Thus + these weights affect the misclassification penalty for different classes. The larger weight, + the larger penalty on misclassification of data from the corresponding class. Default value is + empty Mat. */ + /** @see setClassWeights */ + CV_WRAP virtual cv::Mat getClassWeights() const = 0; + /** @copybrief getClassWeights @see getClassWeights */ + CV_WRAP virtual void setClassWeights(const cv::Mat &val) = 0; + + /** Termination criteria of the iterative %SVM training procedure which solves a partial + case of constrained quadratic optimization problem. + You can specify tolerance and/or the maximum number of iterations. Default value is + `TermCriteria( TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, FLT_EPSILON )`; */ + /** @see setTermCriteria */ + CV_WRAP virtual cv::TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const cv::TermCriteria &val) = 0; + + /** Type of a %SVM kernel. + See SVM::KernelTypes. Default value is SVM::RBF. */ + CV_WRAP virtual int getKernelType() const = 0; + + /** Initialize with one of predefined kernels. + See SVM::KernelTypes. */ + CV_WRAP virtual void setKernel(int kernelType) = 0; + + /** Initialize with custom kernel. + See SVM::Kernel class for implementation details */ + virtual void setCustomKernel(const Ptr &_kernel) = 0; + + //! %SVM type + enum Types { + /** C-Support Vector Classification. n-class classification (n \f$\geq\f$ 2), allows + imperfect separation of classes with penalty multiplier C for outliers. */ + C_SVC=100, + /** \f$\nu\f$-Support Vector Classification. n-class classification with possible + imperfect separation. Parameter \f$\nu\f$ (in the range 0..1, the larger the value, the smoother + the decision boundary) is used instead of C. */ + NU_SVC=101, + /** Distribution Estimation (One-class %SVM). All the training data are from + the same class, %SVM builds a boundary that separates the class from the rest of the feature + space. */ + ONE_CLASS=102, + /** \f$\epsilon\f$-Support Vector Regression. The distance between feature vectors + from the training set and the fitting hyper-plane must be less than p. For outliers the + penalty multiplier C is used. */ + EPS_SVR=103, + /** \f$\nu\f$-Support Vector Regression. \f$\nu\f$ is used instead of p. + See @cite LibSVM for details. */ + NU_SVR=104 + }; + + /** @brief %SVM kernel type + + A comparison of different kernels on the following 2D test case with four classes. Four + SVM::C_SVC SVMs have been trained (one against rest) with auto_train. Evaluation on three + different kernels (SVM::CHI2, SVM::INTER, SVM::RBF). The color depicts the class with max score. + Bright means max-score \> 0, dark means max-score \< 0. + ![image](pics/SVM_Comparison.png) + */ + enum KernelTypes { + /** Returned by SVM::getKernelType in case when custom kernel has been set */ + CUSTOM=-1, + /** Linear kernel. No mapping is done, linear discrimination (or regression) is + done in the original feature space. It is the fastest option. \f$K(x_i, x_j) = x_i^T x_j\f$. */ + LINEAR=0, + /** Polynomial kernel: + \f$K(x_i, x_j) = (\gamma x_i^T x_j + coef0)^{degree}, \gamma > 0\f$. */ + POLY=1, + /** Radial basis function (RBF), a good choice in most cases. + \f$K(x_i, x_j) = e^{-\gamma ||x_i - x_j||^2}, \gamma > 0\f$. */ + RBF=2, + /** Sigmoid kernel: \f$K(x_i, x_j) = \tanh(\gamma x_i^T x_j + coef0)\f$. */ + SIGMOID=3, + /** Exponential Chi2 kernel, similar to the RBF kernel: + \f$K(x_i, x_j) = e^{-\gamma \chi^2(x_i,x_j)}, \chi^2(x_i,x_j) = (x_i-x_j)^2/(x_i+x_j), \gamma > 0\f$. */ + CHI2=4, + /** Histogram intersection kernel. A fast kernel. \f$K(x_i, x_j) = min(x_i,x_j)\f$. */ + INTER=5 + }; + + //! %SVM params type + enum ParamTypes { + C=0, + GAMMA=1, + P=2, + NU=3, + COEF=4, + DEGREE=5 + }; + + /** @brief Trains an %SVM with optimal parameters. + + @param data the training data that can be constructed using TrainData::create or + TrainData::loadFromCSV. + @param kFold Cross-validation parameter. The training set is divided into kFold subsets. One + subset is used to test the model, the others form the train set. So, the %SVM algorithm is + executed kFold times. + @param Cgrid grid for C + @param gammaGrid grid for gamma + @param pGrid grid for p + @param nuGrid grid for nu + @param coeffGrid grid for coeff + @param degreeGrid grid for degree + @param balanced If true and the problem is 2-class classification then the method creates more + balanced cross-validation subsets that is proportions between classes in subsets are close + to such proportion in the whole train dataset. + + The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, + nu, coef0, degree. Parameters are considered optimal when the cross-validation + estimate of the test set error is minimal. + + If there is no need to optimize a parameter, the corresponding grid step should be set to any + value less than or equal to 1. For example, to avoid optimization in gamma, set `gammaGrid.step + = 0`, `gammaGrid.minVal`, `gamma_grid.maxVal` as arbitrary numbers. In this case, the value + `Gamma` is taken for gamma. + + And, finally, if the optimization in a parameter is required but the corresponding grid is + unknown, you may call the function SVM::getDefaultGrid. To generate a grid, for example, for + gamma, call `SVM::getDefaultGrid(SVM::GAMMA)`. + + This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the + regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and + the usual %SVM with parameters specified in params is executed. + */ + virtual bool trainAuto( const Ptr& data, int kFold = 10, + ParamGrid Cgrid = getDefaultGrid(C), + ParamGrid gammaGrid = getDefaultGrid(GAMMA), + ParamGrid pGrid = getDefaultGrid(P), + ParamGrid nuGrid = getDefaultGrid(NU), + ParamGrid coeffGrid = getDefaultGrid(COEF), + ParamGrid degreeGrid = getDefaultGrid(DEGREE), + bool balanced=false) = 0; + + /** @brief Trains an %SVM with optimal parameters + + @param samples training samples + @param layout See ml::SampleTypes. + @param responses vector of responses associated with the training samples. + @param kFold Cross-validation parameter. The training set is divided into kFold subsets. One + subset is used to test the model, the others form the train set. So, the %SVM algorithm is + @param Cgrid grid for C + @param gammaGrid grid for gamma + @param pGrid grid for p + @param nuGrid grid for nu + @param coeffGrid grid for coeff + @param degreeGrid grid for degree + @param balanced If true and the problem is 2-class classification then the method creates more + balanced cross-validation subsets that is proportions between classes in subsets are close + to such proportion in the whole train dataset. + + The method trains the %SVM model automatically by choosing the optimal parameters C, gamma, p, + nu, coef0, degree. Parameters are considered optimal when the cross-validation + estimate of the test set error is minimal. + + This function only makes use of SVM::getDefaultGrid for parameter optimization and thus only + offers rudimentary parameter options. + + This function works for the classification (SVM::C_SVC or SVM::NU_SVC) as well as for the + regression (SVM::EPS_SVR or SVM::NU_SVR). If it is SVM::ONE_CLASS, no optimization is made and + the usual %SVM with parameters specified in params is executed. + */ + CV_WRAP virtual bool trainAuto(InputArray samples, + int layout, + InputArray responses, + int kFold = 10, + Ptr Cgrid = SVM::getDefaultGridPtr(SVM::C), + Ptr gammaGrid = SVM::getDefaultGridPtr(SVM::GAMMA), + Ptr pGrid = SVM::getDefaultGridPtr(SVM::P), + Ptr nuGrid = SVM::getDefaultGridPtr(SVM::NU), + Ptr coeffGrid = SVM::getDefaultGridPtr(SVM::COEF), + Ptr degreeGrid = SVM::getDefaultGridPtr(SVM::DEGREE), + bool balanced=false) = 0; + + /** @brief Retrieves all the support vectors + + The method returns all the support vectors as a floating-point matrix, where support vectors are + stored as matrix rows. + */ + CV_WRAP virtual Mat getSupportVectors() const = 0; + + /** @brief Retrieves all the uncompressed support vectors of a linear %SVM + + The method returns all the uncompressed support vectors of a linear %SVM that the compressed + support vector, used for prediction, was derived from. They are returned in a floating-point + matrix, where the support vectors are stored as matrix rows. + */ + CV_WRAP virtual Mat getUncompressedSupportVectors() const = 0; + + /** @brief Retrieves the decision function + + @param i the index of the decision function. If the problem solved is regression, 1-class or + 2-class classification, then there will be just one decision function and the index should + always be 0. Otherwise, in the case of N-class classification, there will be \f$N(N-1)/2\f$ + decision functions. + @param alpha the optional output vector for weights, corresponding to different support vectors. + In the case of linear %SVM all the alpha's will be 1's. + @param svidx the optional output vector of indices of support vectors within the matrix of + support vectors (which can be retrieved by SVM::getSupportVectors). In the case of linear + %SVM each decision function consists of a single "compressed" support vector. + + The method returns rho parameter of the decision function, a scalar subtracted from the weighted + sum of kernel responses. + */ + CV_WRAP virtual double getDecisionFunction(int i, OutputArray alpha, OutputArray svidx) const = 0; + + /** @brief Generates a grid for %SVM parameters. + + @param param_id %SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is + generated for the parameter with this ID. + + The function generates a grid for the specified parameter of the %SVM algorithm. The grid may be + passed to the function SVM::trainAuto. + */ + static ParamGrid getDefaultGrid( int param_id ); + + /** @brief Generates a grid for %SVM parameters. + + @param param_id %SVM parameters IDs that must be one of the SVM::ParamTypes. The grid is + generated for the parameter with this ID. + + The function generates a grid pointer for the specified parameter of the %SVM algorithm. + The grid may be passed to the function SVM::trainAuto. + */ + CV_WRAP static Ptr getDefaultGridPtr( int param_id ); + + /** Creates empty model. + Use StatModel::train to train the model. Since %SVM has several parameters, you may want to + find the best parameters for your problem, it can be done with SVM::trainAuto. */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized svm from a file + * + * Use SVM::save to serialize and store an SVM to disk. + * Load the SVM from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized svm + */ + CV_WRAP static Ptr load(const String& filepath); +}; + +/****************************************************************************************\ +* Expectation - Maximization * +\****************************************************************************************/ + +/** @brief The class implements the Expectation Maximization algorithm. + +@sa @ref ml_intro_em + */ +class CV_EXPORTS_W EM : public StatModel +{ +public: + //! Type of covariation matrices + enum Types { + /** A scaled identity matrix \f$\mu_k * I\f$. There is the only + parameter \f$\mu_k\f$ to be estimated for each matrix. The option may be used in special cases, + when the constraint is relevant, or as a first step in the optimization (for example in case + when the data is preprocessed with PCA). The results of such preliminary estimation may be + passed again to the optimization procedure, this time with + covMatType=EM::COV_MAT_DIAGONAL. */ + COV_MAT_SPHERICAL=0, + /** A diagonal matrix with positive diagonal elements. The number of + free parameters is d for each matrix. This is most commonly used option yielding good + estimation results. */ + COV_MAT_DIAGONAL=1, + /** A symmetric positively defined matrix. The number of free + parameters in each matrix is about \f$d^2/2\f$. It is not recommended to use this option, unless + there is pretty accurate initial estimation of the parameters and/or a huge number of + training samples. */ + COV_MAT_GENERIC=2, + COV_MAT_DEFAULT=COV_MAT_DIAGONAL + }; + + //! Default parameters + enum {DEFAULT_NCLUSTERS=5, DEFAULT_MAX_ITERS=100}; + + //! The initial step + enum {START_E_STEP=1, START_M_STEP=2, START_AUTO_STEP=0}; + + /** The number of mixture components in the Gaussian mixture model. + Default value of the parameter is EM::DEFAULT_NCLUSTERS=5. Some of %EM implementation could + determine the optimal number of mixtures within a specified value range, but that is not the + case in ML yet. */ + /** @see setClustersNumber */ + CV_WRAP virtual int getClustersNumber() const = 0; + /** @copybrief getClustersNumber @see getClustersNumber */ + CV_WRAP virtual void setClustersNumber(int val) = 0; + + /** Constraint on covariance matrices which defines type of matrices. + See EM::Types. */ + /** @see setCovarianceMatrixType */ + CV_WRAP virtual int getCovarianceMatrixType() const = 0; + /** @copybrief getCovarianceMatrixType @see getCovarianceMatrixType */ + CV_WRAP virtual void setCovarianceMatrixType(int val) = 0; + + /** The termination criteria of the %EM algorithm. + The %EM algorithm can be terminated by the number of iterations termCrit.maxCount (number of + M-steps) or when relative change of likelihood logarithm is less than termCrit.epsilon. Default + maximum number of iterations is EM::DEFAULT_MAX_ITERS=100. */ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const TermCriteria &val) = 0; + + /** @brief Returns weights of the mixtures + + Returns vector with the number of elements equal to the number of mixtures. + */ + CV_WRAP virtual Mat getWeights() const = 0; + /** @brief Returns the cluster centers (means of the Gaussian mixture) + + Returns matrix with the number of rows equal to the number of mixtures and number of columns + equal to the space dimensionality. + */ + CV_WRAP virtual Mat getMeans() const = 0; + /** @brief Returns covariation matrices + + Returns vector of covariation matrices. Number of matrices is the number of gaussian mixtures, + each matrix is a square floating-point matrix NxN, where N is the space dimensionality. + */ + CV_WRAP virtual void getCovs(CV_OUT std::vector& covs) const = 0; + + /** @brief Returns posterior probabilities for the provided samples + + @param samples The input samples, floating-point matrix + @param results The optional output \f$ nSamples \times nClusters\f$ matrix of results. It contains + posterior probabilities for each sample from the input + @param flags This parameter will be ignored + */ + CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const CV_OVERRIDE = 0; + + /** @brief Returns a likelihood logarithm value and an index of the most probable mixture component + for the given sample. + + @param sample A sample for classification. It should be a one-channel matrix of + \f$1 \times dims\f$ or \f$dims \times 1\f$ size. + @param probs Optional output matrix that contains posterior probabilities of each component + given the sample. It has \f$1 \times nclusters\f$ size and CV_64FC1 type. + + The method returns a two-element double vector. Zero element is a likelihood logarithm value for + the sample. First element is an index of the most probable mixture component for the given + sample. + */ + CV_WRAP virtual Vec2d predict2(InputArray sample, OutputArray probs) const = 0; + + /** @brief Estimate the Gaussian mixture parameters from a samples set. + + This variation starts with Expectation step. Initial values of the model parameters will be + estimated by the k-means algorithm. + + Unlike many of the ML models, %EM is an unsupervised learning algorithm and it does not take + responses (class labels or function values) as input. Instead, it computes the *Maximum + Likelihood Estimate* of the Gaussian mixture parameters from an input sample set, stores all the + parameters inside the structure: \f$p_{i,k}\f$ in probs, \f$a_k\f$ in means , \f$S_k\f$ in + covs[k], \f$\pi_k\f$ in weights , and optionally computes the output "class label" for each + sample: \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most + probable mixture component for each sample). + + The trained model can be used further for prediction, just like any other classifier. The + trained model is similar to the NormalBayesClassifier. + + @param samples Samples from which the Gaussian mixture model will be estimated. It should be a + one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type + it will be converted to the inner matrix of such type for the further computing. + @param logLikelihoods The optional output matrix that contains a likelihood logarithm value for + each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. + @param labels The optional output "class label" for each sample: + \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most probable + mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. + @param probs The optional output matrix that contains posterior probabilities of each Gaussian + mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and + CV_64FC1 type. + */ + CV_WRAP virtual bool trainEM(InputArray samples, + OutputArray logLikelihoods=noArray(), + OutputArray labels=noArray(), + OutputArray probs=noArray()) = 0; + + /** @brief Estimate the Gaussian mixture parameters from a samples set. + + This variation starts with Expectation step. You need to provide initial means \f$a_k\f$ of + mixture components. Optionally you can pass initial weights \f$\pi_k\f$ and covariance matrices + \f$S_k\f$ of mixture components. + + @param samples Samples from which the Gaussian mixture model will be estimated. It should be a + one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type + it will be converted to the inner matrix of such type for the further computing. + @param means0 Initial means \f$a_k\f$ of mixture components. It is a one-channel matrix of + \f$nclusters \times dims\f$ size. If the matrix does not have CV_64F type it will be + converted to the inner matrix of such type for the further computing. + @param covs0 The vector of initial covariance matrices \f$S_k\f$ of mixture components. Each of + covariance matrices is a one-channel matrix of \f$dims \times dims\f$ size. If the matrices + do not have CV_64F type they will be converted to the inner matrices of such type for the + further computing. + @param weights0 Initial weights \f$\pi_k\f$ of mixture components. It should be a one-channel + floating-point matrix with \f$1 \times nclusters\f$ or \f$nclusters \times 1\f$ size. + @param logLikelihoods The optional output matrix that contains a likelihood logarithm value for + each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. + @param labels The optional output "class label" for each sample: + \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most probable + mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. + @param probs The optional output matrix that contains posterior probabilities of each Gaussian + mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and + CV_64FC1 type. + */ + CV_WRAP virtual bool trainE(InputArray samples, InputArray means0, + InputArray covs0=noArray(), + InputArray weights0=noArray(), + OutputArray logLikelihoods=noArray(), + OutputArray labels=noArray(), + OutputArray probs=noArray()) = 0; + + /** @brief Estimate the Gaussian mixture parameters from a samples set. + + This variation starts with Maximization step. You need to provide initial probabilities + \f$p_{i,k}\f$ to use this option. + + @param samples Samples from which the Gaussian mixture model will be estimated. It should be a + one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type + it will be converted to the inner matrix of such type for the further computing. + @param probs0 the probabilities + @param logLikelihoods The optional output matrix that contains a likelihood logarithm value for + each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type. + @param labels The optional output "class label" for each sample: + \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most probable + mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type. + @param probs The optional output matrix that contains posterior probabilities of each Gaussian + mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and + CV_64FC1 type. + */ + CV_WRAP virtual bool trainM(InputArray samples, InputArray probs0, + OutputArray logLikelihoods=noArray(), + OutputArray labels=noArray(), + OutputArray probs=noArray()) = 0; + + /** Creates empty %EM model. + The model should be trained then using StatModel::train(traindata, flags) method. Alternatively, you + can use one of the EM::train\* methods or load it from file using Algorithm::load\(filename). + */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized EM from a file + * + * Use EM::save to serialize and store an EM to disk. + * Load the EM from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized EM + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Decision Tree * +\****************************************************************************************/ + +/** @brief The class represents a single decision tree or a collection of decision trees. + +The current public interface of the class allows user to train only a single decision tree, however +the class is capable of storing multiple decision trees and using them for prediction (by summing +responses or using a voting schemes), and the derived from DTrees classes (such as RTrees and Boost) +use this capability to implement decision tree ensembles. + +@sa @ref ml_intro_trees +*/ +class CV_EXPORTS_W DTrees : public StatModel +{ +public: + /** Predict options */ + enum Flags { PREDICT_AUTO=0, PREDICT_SUM=(1<<8), PREDICT_MAX_VOTE=(2<<8), PREDICT_MASK=(3<<8) }; + + /** Cluster possible values of a categorical variable into K\<=maxCategories clusters to + find a suboptimal split. + If a discrete variable, on which the training procedure tries to make a split, takes more than + maxCategories values, the precise best subset estimation may take a very long time because the + algorithm is exponential. Instead, many decision trees engines (including our implementation) + try to find sub-optimal split in this case by clustering all the samples into maxCategories + clusters that is some categories are merged together. The clustering is applied only in n \> + 2-class classification problems for categorical variables with N \> max_categories possible + values. In case of regression and 2-class classification the optimal split can be found + efficiently without employing clustering, thus the parameter is not used in these cases. + Default value is 10.*/ + /** @see setMaxCategories */ + CV_WRAP virtual int getMaxCategories() const = 0; + /** @copybrief getMaxCategories @see getMaxCategories */ + CV_WRAP virtual void setMaxCategories(int val) = 0; + + /** The maximum possible depth of the tree. + That is the training algorithms attempts to split a node while its depth is less than maxDepth. + The root node has zero depth. The actual depth may be smaller if the other termination criteria + are met (see the outline of the training procedure @ref ml_intro_trees "here"), and/or if the + tree is pruned. Default value is INT_MAX.*/ + /** @see setMaxDepth */ + CV_WRAP virtual int getMaxDepth() const = 0; + /** @copybrief getMaxDepth @see getMaxDepth */ + CV_WRAP virtual void setMaxDepth(int val) = 0; + + /** If the number of samples in a node is less than this parameter then the node will not be split. + + Default value is 10.*/ + /** @see setMinSampleCount */ + CV_WRAP virtual int getMinSampleCount() const = 0; + /** @copybrief getMinSampleCount @see getMinSampleCount */ + CV_WRAP virtual void setMinSampleCount(int val) = 0; + + /** If CVFolds \> 1 then algorithms prunes the built decision tree using K-fold + cross-validation procedure where K is equal to CVFolds. + Default value is 10.*/ + /** @see setCVFolds */ + CV_WRAP virtual int getCVFolds() const = 0; + /** @copybrief getCVFolds @see getCVFolds */ + CV_WRAP virtual void setCVFolds(int val) = 0; + + /** If true then surrogate splits will be built. + These splits allow to work with missing data and compute variable importance correctly. + Default value is false. + @note currently it's not implemented.*/ + /** @see setUseSurrogates */ + CV_WRAP virtual bool getUseSurrogates() const = 0; + /** @copybrief getUseSurrogates @see getUseSurrogates */ + CV_WRAP virtual void setUseSurrogates(bool val) = 0; + + /** If true then a pruning will be harsher. + This will make a tree more compact and more resistant to the training data noise but a bit less + accurate. Default value is true.*/ + /** @see setUse1SERule */ + CV_WRAP virtual bool getUse1SERule() const = 0; + /** @copybrief getUse1SERule @see getUse1SERule */ + CV_WRAP virtual void setUse1SERule(bool val) = 0; + + /** If true then pruned branches are physically removed from the tree. + Otherwise they are retained and it is possible to get results from the original unpruned (or + pruned less aggressively) tree. Default value is true.*/ + /** @see setTruncatePrunedTree */ + CV_WRAP virtual bool getTruncatePrunedTree() const = 0; + /** @copybrief getTruncatePrunedTree @see getTruncatePrunedTree */ + CV_WRAP virtual void setTruncatePrunedTree(bool val) = 0; + + /** Termination criteria for regression trees. + If all absolute differences between an estimated value in a node and values of train samples + in this node are less than this parameter then the node will not be split further. Default + value is 0.01f*/ + /** @see setRegressionAccuracy */ + CV_WRAP virtual float getRegressionAccuracy() const = 0; + /** @copybrief getRegressionAccuracy @see getRegressionAccuracy */ + CV_WRAP virtual void setRegressionAccuracy(float val) = 0; + + /** @brief The array of a priori class probabilities, sorted by the class label value. + + The parameter can be used to tune the decision tree preferences toward a certain class. For + example, if you want to detect some rare anomaly occurrence, the training base will likely + contain much more normal cases than anomalies, so a very good classification performance + will be achieved just by considering every case as normal. To avoid this, the priors can be + specified, where the anomaly probability is artificially increased (up to 0.5 or even + greater), so the weight of the misclassified anomalies becomes much bigger, and the tree is + adjusted properly. + + You can also think about this parameter as weights of prediction categories which determine + relative weights that you give to misclassification. That is, if the weight of the first + category is 1 and the weight of the second category is 10, then each mistake in predicting + the second category is equivalent to making 10 mistakes in predicting the first category. + Default value is empty Mat.*/ + /** @see setPriors */ + CV_WRAP virtual cv::Mat getPriors() const = 0; + /** @copybrief getPriors @see getPriors */ + CV_WRAP virtual void setPriors(const cv::Mat &val) = 0; + + /** @brief The class represents a decision tree node. + */ + class CV_EXPORTS Node + { + public: + Node(); + double value; //!< Value at the node: a class label in case of classification or estimated + //!< function value in case of regression. + int classIdx; //!< Class index normalized to 0..class_count-1 range and assigned to the + //!< node. It is used internally in classification trees and tree ensembles. + int parent; //!< Index of the parent node + int left; //!< Index of the left child node + int right; //!< Index of right child node + int defaultDir; //!< Default direction where to go (-1: left or +1: right). It helps in the + //!< case of missing values. + int split; //!< Index of the first split + }; + + /** @brief The class represents split in a decision tree. + */ + class CV_EXPORTS Split + { + public: + Split(); + int varIdx; //!< Index of variable on which the split is created. + bool inversed; //!< If true, then the inverse split rule is used (i.e. left and right + //!< branches are exchanged in the rule expressions below). + float quality; //!< The split quality, a positive number. It is used to choose the best split. + int next; //!< Index of the next split in the list of splits for the node + float c; /**< The threshold value in case of split on an ordered variable. + The rule is: + @code{.none} + if var_value < c + then next_node <- left + else next_node <- right + @endcode */ + int subsetOfs; /**< Offset of the bitset used by the split on a categorical variable. + The rule is: + @code{.none} + if bitset[var_value] == 1 + then next_node <- left + else next_node <- right + @endcode */ + }; + + /** @brief Returns indices of root nodes + */ + virtual const std::vector& getRoots() const = 0; + /** @brief Returns all the nodes + + all the node indices are indices in the returned vector + */ + virtual const std::vector& getNodes() const = 0; + /** @brief Returns all the splits + + all the split indices are indices in the returned vector + */ + virtual const std::vector& getSplits() const = 0; + /** @brief Returns all the bitsets for categorical splits + + Split::subsetOfs is an offset in the returned vector + */ + virtual const std::vector& getSubsets() const = 0; + + /** @brief Creates the empty model + + The static method creates empty decision tree with the specified parameters. It should be then + trained using train method (see StatModel::train). Alternatively, you can load the model from + file using Algorithm::load\(filename). + */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized DTrees from a file + * + * Use DTree::save to serialize and store an DTree to disk. + * Load the DTree from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized DTree + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Random Trees Classifier * +\****************************************************************************************/ + +/** @brief The class implements the random forest predictor. + +@sa @ref ml_intro_rtrees + */ +class CV_EXPORTS_W RTrees : public DTrees +{ +public: + + /** If true then variable importance will be calculated and then it can be retrieved by RTrees::getVarImportance. + Default value is false.*/ + /** @see setCalculateVarImportance */ + CV_WRAP virtual bool getCalculateVarImportance() const = 0; + /** @copybrief getCalculateVarImportance @see getCalculateVarImportance */ + CV_WRAP virtual void setCalculateVarImportance(bool val) = 0; + + /** The size of the randomly selected subset of features at each tree node and that are used + to find the best split(s). + If you set it to 0 then the size will be set to the square root of the total number of + features. Default value is 0.*/ + /** @see setActiveVarCount */ + CV_WRAP virtual int getActiveVarCount() const = 0; + /** @copybrief getActiveVarCount @see getActiveVarCount */ + CV_WRAP virtual void setActiveVarCount(int val) = 0; + + /** The termination criteria that specifies when the training algorithm stops. + Either when the specified number of trees is trained and added to the ensemble or when + sufficient accuracy (measured as OOB error) is achieved. Typically the more trees you have the + better the accuracy. However, the improvement in accuracy generally diminishes and asymptotes + pass a certain number of trees. Also to keep in mind, the number of tree increases the + prediction time linearly. Default value is TermCriteria(TermCriteria::MAX_ITERS + + TermCriteria::EPS, 50, 0.1)*/ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const TermCriteria &val) = 0; + + /** Returns the variable importance array. + The method returns the variable importance vector, computed at the training stage when + CalculateVarImportance is set to true. If this flag was set to false, the empty matrix is + returned. + */ + CV_WRAP virtual Mat getVarImportance() const = 0; + + /** Returns the result of each individual tree in the forest. + In case the model is a regression problem, the method will return each of the trees' + results for each of the sample cases. If the model is a classifier, it will return + a Mat with samples + 1 rows, where the first row gives the class number and the + following rows return the votes each class had for each sample. + @param samples Array containing the samples for which votes will be calculated. + @param results Array where the result of the calculation will be written. + @param flags Flags for defining the type of RTrees. + */ + CV_WRAP virtual void getVotes(InputArray samples, OutputArray results, int flags) const = 0; + + /** Creates the empty model. + Use StatModel::train to train the model, StatModel::train to create and train the model, + Algorithm::load to load the pre-trained model. + */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized RTree from a file + * + * Use RTree::save to serialize and store an RTree to disk. + * Load the RTree from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized RTree + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Boosted tree classifier * +\****************************************************************************************/ + +/** @brief Boosted tree classifier derived from DTrees + +@sa @ref ml_intro_boost + */ +class CV_EXPORTS_W Boost : public DTrees +{ +public: + /** Type of the boosting algorithm. + See Boost::Types. Default value is Boost::REAL. */ + /** @see setBoostType */ + CV_WRAP virtual int getBoostType() const = 0; + /** @copybrief getBoostType @see getBoostType */ + CV_WRAP virtual void setBoostType(int val) = 0; + + /** The number of weak classifiers. + Default value is 100. */ + /** @see setWeakCount */ + CV_WRAP virtual int getWeakCount() const = 0; + /** @copybrief getWeakCount @see getWeakCount */ + CV_WRAP virtual void setWeakCount(int val) = 0; + + /** A threshold between 0 and 1 used to save computational time. + Samples with summary weight \f$\leq 1 - weight_trim_rate\f$ do not participate in the *next* + iteration of training. Set this parameter to 0 to turn off this functionality. Default value is 0.95.*/ + /** @see setWeightTrimRate */ + CV_WRAP virtual double getWeightTrimRate() const = 0; + /** @copybrief getWeightTrimRate @see getWeightTrimRate */ + CV_WRAP virtual void setWeightTrimRate(double val) = 0; + + /** Boosting type. + Gentle AdaBoost and Real AdaBoost are often the preferable choices. */ + enum Types { + DISCRETE=0, //!< Discrete AdaBoost. + REAL=1, //!< Real AdaBoost. It is a technique that utilizes confidence-rated predictions + //!< and works well with categorical data. + LOGIT=2, //!< LogitBoost. It can produce good regression fits. + GENTLE=3 //!< Gentle AdaBoost. It puts less weight on outlier data points and for that + //!(filename) to load the pre-trained model. */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized Boost from a file + * + * Use Boost::save to serialize and store an RTree to disk. + * Load the Boost from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized Boost + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); +}; + +/****************************************************************************************\ +* Gradient Boosted Trees * +\****************************************************************************************/ + +/*class CV_EXPORTS_W GBTrees : public DTrees +{ +public: + struct CV_EXPORTS_W_MAP Params : public DTrees::Params + { + CV_PROP_RW int weakCount; + CV_PROP_RW int lossFunctionType; + CV_PROP_RW float subsamplePortion; + CV_PROP_RW float shrinkage; + + Params(); + Params( int lossFunctionType, int weakCount, float shrinkage, + float subsamplePortion, int maxDepth, bool useSurrogates ); + }; + + enum {SQUARED_LOSS=0, ABSOLUTE_LOSS, HUBER_LOSS=3, DEVIANCE_LOSS}; + + virtual void setK(int k) = 0; + + virtual float predictSerial( InputArray samples, + OutputArray weakResponses, int flags) const = 0; + + static Ptr create(const Params& p); +};*/ + +/****************************************************************************************\ +* Artificial Neural Networks (ANN) * +\****************************************************************************************/ + +/////////////////////////////////// Multi-Layer Perceptrons ////////////////////////////// + +/** @brief Artificial Neural Networks - Multi-Layer Perceptrons. + +Unlike many other models in ML that are constructed and trained at once, in the MLP model these +steps are separated. First, a network with the specified topology is created using the non-default +constructor or the method ANN_MLP::create. All the weights are set to zeros. Then, the network is +trained using a set of input and output vectors. The training procedure can be repeated more than +once, that is, the weights can be adjusted based on the new training data. + +Additional flags for StatModel::train are available: ANN_MLP::TrainFlags. + +@sa @ref ml_intro_ann + */ +class CV_EXPORTS_W ANN_MLP : public StatModel +{ +public: + /** Available training methods */ + enum TrainingMethods { + BACKPROP=0, //!< The back-propagation algorithm. + RPROP = 1, //!< The RPROP algorithm. See @cite RPROP93 for details. + ANNEAL = 2 //!< The simulated annealing algorithm. See @cite Kirkpatrick83 for details. + }; + + /** Sets training method and common parameters. + @param method Default value is ANN_MLP::RPROP. See ANN_MLP::TrainingMethods. + @param param1 passed to setRpropDW0 for ANN_MLP::RPROP and to setBackpropWeightScale for ANN_MLP::BACKPROP and to initialT for ANN_MLP::ANNEAL. + @param param2 passed to setRpropDWMin for ANN_MLP::RPROP and to setBackpropMomentumScale for ANN_MLP::BACKPROP and to finalT for ANN_MLP::ANNEAL. + */ + CV_WRAP virtual void setTrainMethod(int method, double param1 = 0, double param2 = 0) = 0; + + /** Returns current training method */ + CV_WRAP virtual int getTrainMethod() const = 0; + + /** Initialize the activation function for each neuron. + Currently the default and the only fully supported activation function is ANN_MLP::SIGMOID_SYM. + @param type The type of activation function. See ANN_MLP::ActivationFunctions. + @param param1 The first parameter of the activation function, \f$\alpha\f$. Default value is 0. + @param param2 The second parameter of the activation function, \f$\beta\f$. Default value is 0. + */ + CV_WRAP virtual void setActivationFunction(int type, double param1 = 0, double param2 = 0) = 0; + + /** Integer vector specifying the number of neurons in each layer including the input and output layers. + The very first element specifies the number of elements in the input layer. + The last element - number of elements in the output layer. Default value is empty Mat. + @sa getLayerSizes */ + CV_WRAP virtual void setLayerSizes(InputArray _layer_sizes) = 0; + + /** Integer vector specifying the number of neurons in each layer including the input and output layers. + The very first element specifies the number of elements in the input layer. + The last element - number of elements in the output layer. + @sa setLayerSizes */ + CV_WRAP virtual cv::Mat getLayerSizes() const = 0; + + /** Termination criteria of the training algorithm. + You can specify the maximum number of iterations (maxCount) and/or how much the error could + change between the iterations to make the algorithm continue (epsilon). Default value is + TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, 0.01).*/ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(TermCriteria val) = 0; + + /** BPROP: Strength of the weight gradient term. + The recommended value is about 0.1. Default value is 0.1.*/ + /** @see setBackpropWeightScale */ + CV_WRAP virtual double getBackpropWeightScale() const = 0; + /** @copybrief getBackpropWeightScale @see getBackpropWeightScale */ + CV_WRAP virtual void setBackpropWeightScale(double val) = 0; + + /** BPROP: Strength of the momentum term (the difference between weights on the 2 previous iterations). + This parameter provides some inertia to smooth the random fluctuations of the weights. It can + vary from 0 (the feature is disabled) to 1 and beyond. The value 0.1 or so is good enough. + Default value is 0.1.*/ + /** @see setBackpropMomentumScale */ + CV_WRAP virtual double getBackpropMomentumScale() const = 0; + /** @copybrief getBackpropMomentumScale @see getBackpropMomentumScale */ + CV_WRAP virtual void setBackpropMomentumScale(double val) = 0; + + /** RPROP: Initial value \f$\Delta_0\f$ of update-values \f$\Delta_{ij}\f$. + Default value is 0.1.*/ + /** @see setRpropDW0 */ + CV_WRAP virtual double getRpropDW0() const = 0; + /** @copybrief getRpropDW0 @see getRpropDW0 */ + CV_WRAP virtual void setRpropDW0(double val) = 0; + + /** RPROP: Increase factor \f$\eta^+\f$. + It must be \>1. Default value is 1.2.*/ + /** @see setRpropDWPlus */ + CV_WRAP virtual double getRpropDWPlus() const = 0; + /** @copybrief getRpropDWPlus @see getRpropDWPlus */ + CV_WRAP virtual void setRpropDWPlus(double val) = 0; + + /** RPROP: Decrease factor \f$\eta^-\f$. + It must be \<1. Default value is 0.5.*/ + /** @see setRpropDWMinus */ + CV_WRAP virtual double getRpropDWMinus() const = 0; + /** @copybrief getRpropDWMinus @see getRpropDWMinus */ + CV_WRAP virtual void setRpropDWMinus(double val) = 0; + + /** RPROP: Update-values lower limit \f$\Delta_{min}\f$. + It must be positive. Default value is FLT_EPSILON.*/ + /** @see setRpropDWMin */ + CV_WRAP virtual double getRpropDWMin() const = 0; + /** @copybrief getRpropDWMin @see getRpropDWMin */ + CV_WRAP virtual void setRpropDWMin(double val) = 0; + + /** RPROP: Update-values upper limit \f$\Delta_{max}\f$. + It must be \>1. Default value is 50.*/ + /** @see setRpropDWMax */ + CV_WRAP virtual double getRpropDWMax() const = 0; + /** @copybrief getRpropDWMax @see getRpropDWMax */ + CV_WRAP virtual void setRpropDWMax(double val) = 0; + + /** ANNEAL: Update initial temperature. + It must be \>=0. Default value is 10.*/ + /** @see setAnnealInitialT */ + CV_WRAP virtual double getAnnealInitialT() const = 0; + /** @copybrief getAnnealInitialT @see getAnnealInitialT */ + CV_WRAP virtual void setAnnealInitialT(double val) = 0; + + /** ANNEAL: Update final temperature. + It must be \>=0 and less than initialT. Default value is 0.1.*/ + /** @see setAnnealFinalT */ + CV_WRAP virtual double getAnnealFinalT() const = 0; + /** @copybrief getAnnealFinalT @see getAnnealFinalT */ + CV_WRAP virtual void setAnnealFinalT(double val) = 0; + + /** ANNEAL: Update cooling ratio. + It must be \>0 and less than 1. Default value is 0.95.*/ + /** @see setAnnealCoolingRatio */ + CV_WRAP virtual double getAnnealCoolingRatio() const = 0; + /** @copybrief getAnnealCoolingRatio @see getAnnealCoolingRatio */ + CV_WRAP virtual void setAnnealCoolingRatio(double val) = 0; + + /** ANNEAL: Update iteration per step. + It must be \>0 . Default value is 10.*/ + /** @see setAnnealItePerStep */ + CV_WRAP virtual int getAnnealItePerStep() const = 0; + /** @copybrief getAnnealItePerStep @see getAnnealItePerStep */ + CV_WRAP virtual void setAnnealItePerStep(int val) = 0; + + /** @brief Set/initialize anneal RNG */ + virtual void setAnnealEnergyRNG(const RNG& rng) = 0; + + /** possible activation functions */ + enum ActivationFunctions { + /** Identity function: \f$f(x)=x\f$ */ + IDENTITY = 0, + /** Symmetrical sigmoid: \f$f(x)=\beta*(1-e^{-\alpha x})/(1+e^{-\alpha x})\f$ + @note + If you are using the default sigmoid activation function with the default parameter values + fparam1=0 and fparam2=0 then the function used is y = 1.7159\*tanh(2/3 \* x), so the output + will range from [-1.7159, 1.7159], instead of [0,1].*/ + SIGMOID_SYM = 1, + /** Gaussian function: \f$f(x)=\beta e^{-\alpha x*x}\f$ */ + GAUSSIAN = 2, + /** ReLU function: \f$f(x)=max(0,x)\f$ */ + RELU = 3, + /** Leaky ReLU function: for x>0 \f$f(x)=x \f$ and x<=0 \f$f(x)=\alpha x \f$*/ + LEAKYRELU= 4 + }; + + /** Train options */ + enum TrainFlags { + /** Update the network weights, rather than compute them from scratch. In the latter case + the weights are initialized using the Nguyen-Widrow algorithm. */ + UPDATE_WEIGHTS = 1, + /** Do not normalize the input vectors. If this flag is not set, the training algorithm + normalizes each input feature independently, shifting its mean value to 0 and making the + standard deviation equal to 1. If the network is assumed to be updated frequently, the new + training data could be much different from original one. In this case, you should take care + of proper normalization. */ + NO_INPUT_SCALE = 2, + /** Do not normalize the output vectors. If the flag is not set, the training algorithm + normalizes each output feature independently, by transforming it to the certain range + depending on the used activation function. */ + NO_OUTPUT_SCALE = 4 + }; + + CV_WRAP virtual Mat getWeights(int layerIdx) const = 0; + + /** @brief Creates empty model + + Use StatModel::train to train the model, Algorithm::load\(filename) to load the pre-trained model. + Note that the train method has optional flags: ANN_MLP::TrainFlags. + */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized ANN from a file + * + * Use ANN::save to serialize and store an ANN to disk. + * Load the ANN from this file again, by calling this function with the path to the file. + * + * @param filepath path to serialized ANN + */ + CV_WRAP static Ptr load(const String& filepath); + +}; + +#ifndef DISABLE_OPENCV_3_COMPATIBILITY +typedef ANN_MLP ANN_MLP_ANNEAL; +#endif + +/****************************************************************************************\ +* Logistic Regression * +\****************************************************************************************/ + +/** @brief Implements Logistic Regression classifier. + +@sa @ref ml_intro_lr + */ +class CV_EXPORTS_W LogisticRegression : public StatModel +{ +public: + + /** Learning rate. */ + /** @see setLearningRate */ + CV_WRAP virtual double getLearningRate() const = 0; + /** @copybrief getLearningRate @see getLearningRate */ + CV_WRAP virtual void setLearningRate(double val) = 0; + + /** Number of iterations. */ + /** @see setIterations */ + CV_WRAP virtual int getIterations() const = 0; + /** @copybrief getIterations @see getIterations */ + CV_WRAP virtual void setIterations(int val) = 0; + + /** Kind of regularization to be applied. See LogisticRegression::RegKinds. */ + /** @see setRegularization */ + CV_WRAP virtual int getRegularization() const = 0; + /** @copybrief getRegularization @see getRegularization */ + CV_WRAP virtual void setRegularization(int val) = 0; + + /** Kind of training method used. See LogisticRegression::Methods. */ + /** @see setTrainMethod */ + CV_WRAP virtual int getTrainMethod() const = 0; + /** @copybrief getTrainMethod @see getTrainMethod */ + CV_WRAP virtual void setTrainMethod(int val) = 0; + + /** Specifies the number of training samples taken in each step of Mini-Batch Gradient + Descent. Will only be used if using LogisticRegression::MINI_BATCH training algorithm. It + has to take values less than the total number of training samples. */ + /** @see setMiniBatchSize */ + CV_WRAP virtual int getMiniBatchSize() const = 0; + /** @copybrief getMiniBatchSize @see getMiniBatchSize */ + CV_WRAP virtual void setMiniBatchSize(int val) = 0; + + /** Termination criteria of the algorithm. */ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(TermCriteria val) = 0; + + //! Regularization kinds + enum RegKinds { + REG_DISABLE = -1, //!< Regularization disabled + REG_L1 = 0, //!< %L1 norm + REG_L2 = 1 //!< %L2 norm + }; + + //! Training methods + enum Methods { + BATCH = 0, + MINI_BATCH = 1 //!< Set MiniBatchSize to a positive integer when using this method. + }; + + /** @brief Predicts responses for input samples and returns a float type. + + @param samples The input data for the prediction algorithm. Matrix [m x n], where each row + contains variables (features) of one object being classified. Should have data type CV_32F. + @param results Predicted labels as a column matrix of type CV_32S. + @param flags Not used. + */ + CV_WRAP virtual float predict( InputArray samples, OutputArray results=noArray(), int flags=0 ) const CV_OVERRIDE = 0; + + /** @brief This function returns the trained parameters arranged across rows. + + For a two class classifcation problem, it returns a row matrix. It returns learnt parameters of + the Logistic Regression as a matrix of type CV_32F. + */ + CV_WRAP virtual Mat get_learnt_thetas() const = 0; + + /** @brief Creates empty model. + + Creates Logistic Regression model with parameters given. + */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized LogisticRegression from a file + * + * Use LogisticRegression::save to serialize and store an LogisticRegression to disk. + * Load the LogisticRegression from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized LogisticRegression + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); +}; + + +/****************************************************************************************\ +* Stochastic Gradient Descent SVM Classifier * +\****************************************************************************************/ + +/*! +@brief Stochastic Gradient Descent SVM classifier + +SVMSGD provides a fast and easy-to-use implementation of the SVM classifier using the Stochastic Gradient Descent approach, +as presented in @cite bottou2010large. + +The classifier has following parameters: +- model type, +- margin type, +- margin regularization (\f$\lambda\f$), +- initial step size (\f$\gamma_0\f$), +- step decreasing power (\f$c\f$), +- and termination criteria. + +The model type may have one of the following values: \ref SGD and \ref ASGD. + +- \ref SGD is the classic version of SVMSGD classifier: every next step is calculated by the formula + \f[w_{t+1} = w_t - \gamma(t) \frac{dQ_i}{dw} |_{w = w_t}\f] + where + - \f$w_t\f$ is the weights vector for decision function at step \f$t\f$, + - \f$\gamma(t)\f$ is the step size of model parameters at the iteration \f$t\f$, it is decreased on each step by the formula + \f$\gamma(t) = \gamma_0 (1 + \lambda \gamma_0 t) ^ {-c}\f$ + - \f$Q_i\f$ is the target functional from SVM task for sample with number \f$i\f$, this sample is chosen stochastically on each step of the algorithm. + +- \ref ASGD is Average Stochastic Gradient Descent SVM Classifier. ASGD classifier averages weights vector on each step of algorithm by the formula +\f$\widehat{w}_{t+1} = \frac{t}{1+t}\widehat{w}_{t} + \frac{1}{1+t}w_{t+1}\f$ + +The recommended model type is ASGD (following @cite bottou2010large). + +The margin type may have one of the following values: \ref SOFT_MARGIN or \ref HARD_MARGIN. + +- You should use \ref HARD_MARGIN type, if you have linearly separable sets. +- You should use \ref SOFT_MARGIN type, if you have non-linearly separable sets or sets with outliers. +- In the general case (if you know nothing about linear separability of your sets), use SOFT_MARGIN. + +The other parameters may be described as follows: +- Margin regularization parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers + (the less the parameter, the less probability that an outlier will be ignored). + Recommended value for SGD model is 0.0001, for ASGD model is 0.00001. + +- Initial step size parameter is the initial value for the step size \f$\gamma(t)\f$. + You will have to find the best initial step for your problem. + +- Step decreasing power is the power parameter for \f$\gamma(t)\f$ decreasing by the formula, mentioned above. + Recommended value for SGD model is 1, for ASGD model is 0.75. + +- Termination criteria can be TermCriteria::COUNT, TermCriteria::EPS or TermCriteria::COUNT + TermCriteria::EPS. + You will have to find the best termination criteria for your problem. + +Note that the parameters margin regularization, initial step size, and step decreasing power should be positive. + +To use SVMSGD algorithm do as follows: + +- first, create the SVMSGD object. The algorithm will set optimal parameters by default, but you can set your own parameters via functions setSvmsgdType(), + setMarginType(), setMarginRegularization(), setInitialStepSize(), and setStepDecreasingPower(). + +- then the SVM model can be trained using the train features and the correspondent labels by the method train(). + +- after that, the label of a new feature vector can be predicted using the method predict(). + +@code +// Create empty object +cv::Ptr svmsgd = SVMSGD::create(); + +// Train the Stochastic Gradient Descent SVM +svmsgd->train(trainData); + +// Predict labels for the new samples +svmsgd->predict(samples, responses); +@endcode + +*/ + +class CV_EXPORTS_W SVMSGD : public cv::ml::StatModel +{ +public: + + /** SVMSGD type. + ASGD is often the preferable choice. */ + enum SvmsgdType + { + SGD, //!< Stochastic Gradient Descent + ASGD //!< Average Stochastic Gradient Descent + }; + + /** Margin type.*/ + enum MarginType + { + SOFT_MARGIN, //!< General case, suits to the case of non-linearly separable sets, allows outliers. + HARD_MARGIN //!< More accurate for the case of linearly separable sets. + }; + + /** + * @return the weights of the trained model (decision function f(x) = weights * x + shift). + */ + CV_WRAP virtual Mat getWeights() = 0; + + /** + * @return the shift of the trained model (decision function f(x) = weights * x + shift). + */ + CV_WRAP virtual float getShift() = 0; + + /** @brief Creates empty model. + * Use StatModel::train to train the model. Since %SVMSGD has several parameters, you may want to + * find the best parameters for your problem or use setOptimalParameters() to set some default parameters. + */ + CV_WRAP static Ptr create(); + + /** @brief Loads and creates a serialized SVMSGD from a file + * + * Use SVMSGD::save to serialize and store an SVMSGD to disk. + * Load the SVMSGD from this file again, by calling this function with the path to the file. + * Optionally specify the node for the file containing the classifier + * + * @param filepath path to serialized SVMSGD + * @param nodeName name of node containing the classifier + */ + CV_WRAP static Ptr load(const String& filepath , const String& nodeName = String()); + + /** @brief Function sets optimal parameters values for chosen SVM SGD model. + * @param svmsgdType is the type of SVMSGD classifier. + * @param marginType is the type of margin constraint. + */ + CV_WRAP virtual void setOptimalParameters(int svmsgdType = SVMSGD::ASGD, int marginType = SVMSGD::SOFT_MARGIN) = 0; + + /** @brief %Algorithm type, one of SVMSGD::SvmsgdType. */ + /** @see setSvmsgdType */ + CV_WRAP virtual int getSvmsgdType() const = 0; + /** @copybrief getSvmsgdType @see getSvmsgdType */ + CV_WRAP virtual void setSvmsgdType(int svmsgdType) = 0; + + /** @brief %Margin type, one of SVMSGD::MarginType. */ + /** @see setMarginType */ + CV_WRAP virtual int getMarginType() const = 0; + /** @copybrief getMarginType @see getMarginType */ + CV_WRAP virtual void setMarginType(int marginType) = 0; + + /** @brief Parameter marginRegularization of a %SVMSGD optimization problem. */ + /** @see setMarginRegularization */ + CV_WRAP virtual float getMarginRegularization() const = 0; + /** @copybrief getMarginRegularization @see getMarginRegularization */ + CV_WRAP virtual void setMarginRegularization(float marginRegularization) = 0; + + /** @brief Parameter initialStepSize of a %SVMSGD optimization problem. */ + /** @see setInitialStepSize */ + CV_WRAP virtual float getInitialStepSize() const = 0; + /** @copybrief getInitialStepSize @see getInitialStepSize */ + CV_WRAP virtual void setInitialStepSize(float InitialStepSize) = 0; + + /** @brief Parameter stepDecreasingPower of a %SVMSGD optimization problem. */ + /** @see setStepDecreasingPower */ + CV_WRAP virtual float getStepDecreasingPower() const = 0; + /** @copybrief getStepDecreasingPower @see getStepDecreasingPower */ + CV_WRAP virtual void setStepDecreasingPower(float stepDecreasingPower) = 0; + + /** @brief Termination criteria of the training algorithm. + You can specify the maximum number of iterations (maxCount) and/or how much the error could + change between the iterations to make the algorithm continue (epsilon).*/ + /** @see setTermCriteria */ + CV_WRAP virtual TermCriteria getTermCriteria() const = 0; + /** @copybrief getTermCriteria @see getTermCriteria */ + CV_WRAP virtual void setTermCriteria(const cv::TermCriteria &val) = 0; +}; + + +/****************************************************************************************\ +* Auxiliary functions declarations * +\****************************************************************************************/ + +/** @brief Generates _sample_ from multivariate normal distribution + +@param mean an average row vector +@param cov symmetric covariation matrix +@param nsamples returned samples count +@param samples returned samples array +*/ +CV_EXPORTS void randMVNormal( InputArray mean, InputArray cov, int nsamples, OutputArray samples); + +/** @brief Creates test set */ +CV_EXPORTS void createConcentricSpheresTestSet( int nsamples, int nfeatures, int nclasses, + OutputArray samples, OutputArray responses); + + +/****************************************************************************************\ +* Simulated annealing solver * +\****************************************************************************************/ + +#ifdef CV_DOXYGEN +/** @brief This class declares example interface for system state used in simulated annealing optimization algorithm. + +@note This class is not defined in C++ code and can't be use directly - you need your own implementation with the same methods. +*/ +struct SimulatedAnnealingSolverSystem +{ + /** Give energy value for a state of system.*/ + double energy() const; + /** Function which change the state of system (random perturbation).*/ + void changeState(); + /** Function to reverse to the previous state. Can be called once only after changeState(). */ + void reverseState(); +}; +#endif // CV_DOXYGEN + +/** @brief The class implements simulated annealing for optimization. + +@cite Kirkpatrick83 for details + +@param solverSystem optimization system (see SimulatedAnnealingSolverSystem) +@param initialTemperature initial temperature +@param finalTemperature final temperature +@param coolingRatio temperature step multiplies +@param iterationsPerStep number of iterations per temperature changing step +@param lastTemperature optional output for last used temperature +@param rngEnergy specify custom random numbers generator (cv::theRNG() by default) +*/ +template +int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem, + double initialTemperature, double finalTemperature, double coolingRatio, + size_t iterationsPerStep, + CV_OUT double* lastTemperature = NULL, + cv::RNG& rngEnergy = cv::theRNG() +); + +//! @} ml + +} +} + +#include + +#endif // __cplusplus +#endif // OPENCV_ML_HPP + +/* End of file. */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml/ml.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml/ml.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f6f9cd8f89329832d7424a9910f67ae2314598f5 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml/ml.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/ml.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml/ml.inl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml/ml.inl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dc9c78393a5a85be32b0fe187a447a01ce95e39b --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/ml/ml.inl.hpp @@ -0,0 +1,60 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_ML_INL_HPP +#define OPENCV_ML_INL_HPP + +namespace cv { namespace ml { + +// declared in ml.hpp +template +int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem, + double initialTemperature, double finalTemperature, double coolingRatio, + size_t iterationsPerStep, + CV_OUT double* lastTemperature, + cv::RNG& rngEnergy +) +{ + CV_Assert(finalTemperature > 0); + CV_Assert(initialTemperature > finalTemperature); + CV_Assert(iterationsPerStep > 0); + CV_Assert(coolingRatio < 1.0f); + double Ti = initialTemperature; + double previousEnergy = solverSystem.energy(); + int exchange = 0; + while (Ti > finalTemperature) + { + for (size_t i = 0; i < iterationsPerStep; i++) + { + solverSystem.changeState(); + double newEnergy = solverSystem.energy(); + if (newEnergy < previousEnergy) + { + previousEnergy = newEnergy; + exchange++; + } + else + { + double r = rngEnergy.uniform(0.0, 1.0); + if (r < std::exp(-(newEnergy - previousEnergy) / Ti)) + { + previousEnergy = newEnergy; + exchange++; + } + else + { + solverSystem.reverseState(); + } + } + } + Ti *= coolingRatio; + } + if (lastTemperature) + *lastTemperature = Ti; + return exchange; +} + +}} //namespace + +#endif // OPENCV_ML_INL_HPP diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1cbbf8456fff420f883bd624cbd214c11b680477 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect.hpp @@ -0,0 +1,720 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_OBJDETECT_HPP +#define OPENCV_OBJDETECT_HPP + +#include "opencv2/core.hpp" + +/** +@defgroup objdetect Object Detection + +Haar Feature-based Cascade Classifier for Object Detection +---------------------------------------------------------- + +The object detector described below has been initially proposed by Paul Viola @cite Viola01 and +improved by Rainer Lienhart @cite Lienhart02 . + +First, a classifier (namely a *cascade of boosted classifiers working with haar-like features*) is +trained with a few hundred sample views of a particular object (i.e., a face or a car), called +positive examples, that are scaled to the same size (say, 20x20), and negative examples - arbitrary +images of the same size. + +After a classifier is trained, it can be applied to a region of interest (of the same size as used +during the training) in an input image. The classifier outputs a "1" if the region is likely to show +the object (i.e., face/car), and "0" otherwise. To search for the object in the whole image one can +move the search window across the image and check every location using the classifier. The +classifier is designed so that it can be easily "resized" in order to be able to find the objects of +interest at different sizes, which is more efficient than resizing the image itself. So, to find an +object of an unknown size in the image the scan procedure should be done several times at different +scales. + +The word "cascade" in the classifier name means that the resultant classifier consists of several +simpler classifiers (*stages*) that are applied subsequently to a region of interest until at some +stage the candidate is rejected or all the stages are passed. The word "boosted" means that the +classifiers at every stage of the cascade are complex themselves and they are built out of basic +classifiers using one of four different boosting techniques (weighted voting). Currently Discrete +Adaboost, Real Adaboost, Gentle Adaboost and Logitboost are supported. The basic classifiers are +decision-tree classifiers with at least 2 leaves. Haar-like features are the input to the basic +classifiers, and are calculated as described below. The current algorithm uses the following +Haar-like features: + +![image](pics/haarfeatures.png) + +The feature used in a particular classifier is specified by its shape (1a, 2b etc.), position within +the region of interest and the scale (this scale is not the same as the scale used at the detection +stage, though these two scales are multiplied). For example, in the case of the third line feature +(2c) the response is calculated as the difference between the sum of image pixels under the +rectangle covering the whole feature (including the two white stripes and the black stripe in the +middle) and the sum of the image pixels under the black stripe multiplied by 3 in order to +compensate for the differences in the size of areas. The sums of pixel values over a rectangular +regions are calculated rapidly using integral images (see below and the integral description). + +To see the object detector at work, have a look at the facedetect demo: + + +The following reference is for the detection part only. There is a separate application called +opencv_traincascade that can train a cascade of boosted classifiers from a set of samples. + +@note In the new C++ interface it is also possible to use LBP (local binary pattern) features in +addition to Haar-like features. .. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection +using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at + + +@{ + @defgroup objdetect_c C API +@} + */ + +typedef struct CvHaarClassifierCascade CvHaarClassifierCascade; + +namespace cv +{ + +//! @addtogroup objdetect +//! @{ + +///////////////////////////// Object Detection //////////////////////////// + +//! class for grouping object candidates, detected by Cascade Classifier, HOG etc. +//! instance of the class is to be passed to cv::partition (see cxoperations.hpp) +class CV_EXPORTS SimilarRects +{ +public: + SimilarRects(double _eps) : eps(_eps) {} + inline bool operator()(const Rect& r1, const Rect& r2) const + { + double delta = eps * ((std::min)(r1.width, r2.width) + (std::min)(r1.height, r2.height)) * 0.5; + return std::abs(r1.x - r2.x) <= delta && + std::abs(r1.y - r2.y) <= delta && + std::abs(r1.x + r1.width - r2.x - r2.width) <= delta && + std::abs(r1.y + r1.height - r2.y - r2.height) <= delta; + } + double eps; +}; + +/** @brief Groups the object candidate rectangles. + +@param rectList Input/output vector of rectangles. Output vector includes retained and grouped +rectangles. (The Python list is not modified in place.) +@param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a +group of rectangles to retain it. +@param eps Relative difference between sides of the rectangles to merge them into a group. + +The function is a wrapper for the generic function partition . It clusters all the input rectangles +using the rectangle equivalence criteria that combines rectangles with similar sizes and similar +locations. The similarity is defined by eps. When eps=0 , no clustering is done at all. If +\f$\texttt{eps}\rightarrow +\inf\f$ , all the rectangles are put in one cluster. Then, the small +clusters containing less than or equal to groupThreshold rectangles are rejected. In each other +cluster, the average rectangle is computed and put into the output rectangle list. + */ +CV_EXPORTS void groupRectangles(std::vector& rectList, int groupThreshold, double eps = 0.2); +/** @overload */ +CV_EXPORTS_W void groupRectangles(CV_IN_OUT std::vector& rectList, CV_OUT std::vector& weights, + int groupThreshold, double eps = 0.2); +/** @overload */ +CV_EXPORTS void groupRectangles(std::vector& rectList, int groupThreshold, + double eps, std::vector* weights, std::vector* levelWeights ); +/** @overload */ +CV_EXPORTS void groupRectangles(std::vector& rectList, std::vector& rejectLevels, + std::vector& levelWeights, int groupThreshold, double eps = 0.2); +/** @overload */ +CV_EXPORTS void groupRectangles_meanshift(std::vector& rectList, std::vector& foundWeights, + std::vector& foundScales, + double detectThreshold = 0.0, Size winDetSize = Size(64, 128)); + +template<> struct DefaultDeleter{ CV_EXPORTS void operator ()(CvHaarClassifierCascade* obj) const; }; + +enum { CASCADE_DO_CANNY_PRUNING = 1, + CASCADE_SCALE_IMAGE = 2, + CASCADE_FIND_BIGGEST_OBJECT = 4, + CASCADE_DO_ROUGH_SEARCH = 8 + }; + +class CV_EXPORTS_W BaseCascadeClassifier : public Algorithm +{ +public: + virtual ~BaseCascadeClassifier(); + virtual bool empty() const CV_OVERRIDE = 0; + virtual bool load( const String& filename ) = 0; + virtual void detectMultiScale( InputArray image, + CV_OUT std::vector& objects, + double scaleFactor, + int minNeighbors, int flags, + Size minSize, Size maxSize ) = 0; + + virtual void detectMultiScale( InputArray image, + CV_OUT std::vector& objects, + CV_OUT std::vector& numDetections, + double scaleFactor, + int minNeighbors, int flags, + Size minSize, Size maxSize ) = 0; + + virtual void detectMultiScale( InputArray image, + CV_OUT std::vector& objects, + CV_OUT std::vector& rejectLevels, + CV_OUT std::vector& levelWeights, + double scaleFactor, + int minNeighbors, int flags, + Size minSize, Size maxSize, + bool outputRejectLevels ) = 0; + + virtual bool isOldFormatCascade() const = 0; + virtual Size getOriginalWindowSize() const = 0; + virtual int getFeatureType() const = 0; + virtual void* getOldCascade() = 0; + + class CV_EXPORTS MaskGenerator + { + public: + virtual ~MaskGenerator() {} + virtual Mat generateMask(const Mat& src)=0; + virtual void initializeMask(const Mat& /*src*/) { } + }; + virtual void setMaskGenerator(const Ptr& maskGenerator) = 0; + virtual Ptr getMaskGenerator() = 0; +}; + +/** @example samples/cpp/facedetect.cpp +This program demonstrates usage of the Cascade classifier class +\image html Cascade_Classifier_Tutorial_Result_Haar.jpg "Sample screenshot" width=321 height=254 +*/ +/** @brief Cascade classifier class for object detection. + */ +class CV_EXPORTS_W CascadeClassifier +{ +public: + CV_WRAP CascadeClassifier(); + /** @brief Loads a classifier from a file. + + @param filename Name of the file from which the classifier is loaded. + */ + CV_WRAP CascadeClassifier(const String& filename); + ~CascadeClassifier(); + /** @brief Checks whether the classifier has been loaded. + */ + CV_WRAP bool empty() const; + /** @brief Loads a classifier from a file. + + @param filename Name of the file from which the classifier is loaded. The file may contain an old + HAAR classifier trained by the haartraining application or a new cascade classifier trained by the + traincascade application. + */ + CV_WRAP bool load( const String& filename ); + /** @brief Reads a classifier from a FileStorage node. + + @note The file may contain a new cascade classifier (trained traincascade application) only. + */ + CV_WRAP bool read( const FileNode& node ); + + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + + @param image Matrix of the type CV_8U containing an image where objects are detected. + @param objects Vector of rectangles where each rectangle contains the detected object, the + rectangles may be partially outside the original image. + @param scaleFactor Parameter specifying how much the image size is reduced at each image scale. + @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have + to retain it. + @param flags Parameter with the same meaning for an old cascade as in the function + cvHaarDetectObjects. It is not used for a new cascade. + @param minSize Minimum possible object size. Objects smaller than that are ignored. + @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. + + The function is parallelized with the TBB library. + + @note + - (Python) A face detection example using cascade classifiers can be found at + opencv_source_code/samples/python/facedetect.py + */ + CV_WRAP void detectMultiScale( InputArray image, + CV_OUT std::vector& objects, + double scaleFactor = 1.1, + int minNeighbors = 3, int flags = 0, + Size minSize = Size(), + Size maxSize = Size() ); + + /** @overload + @param image Matrix of the type CV_8U containing an image where objects are detected. + @param objects Vector of rectangles where each rectangle contains the detected object, the + rectangles may be partially outside the original image. + @param numDetections Vector of detection numbers for the corresponding objects. An object's number + of detections is the number of neighboring positively classified rectangles that were joined + together to form the object. + @param scaleFactor Parameter specifying how much the image size is reduced at each image scale. + @param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have + to retain it. + @param flags Parameter with the same meaning for an old cascade as in the function + cvHaarDetectObjects. It is not used for a new cascade. + @param minSize Minimum possible object size. Objects smaller than that are ignored. + @param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale. + */ + CV_WRAP_AS(detectMultiScale2) void detectMultiScale( InputArray image, + CV_OUT std::vector& objects, + CV_OUT std::vector& numDetections, + double scaleFactor=1.1, + int minNeighbors=3, int flags=0, + Size minSize=Size(), + Size maxSize=Size() ); + + /** @overload + This function allows you to retrieve the final stage decision certainty of classification. + For this, one needs to set `outputRejectLevels` on true and provide the `rejectLevels` and `levelWeights` parameter. + For each resulting detection, `levelWeights` will then contain the certainty of classification at the final stage. + This value can then be used to separate strong from weaker classifications. + + A code sample on how to use it efficiently can be found below: + @code + Mat img; + vector weights; + vector levels; + vector detections; + CascadeClassifier model("/path/to/your/model.xml"); + model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true); + cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl; + @endcode + */ + CV_WRAP_AS(detectMultiScale3) void detectMultiScale( InputArray image, + CV_OUT std::vector& objects, + CV_OUT std::vector& rejectLevels, + CV_OUT std::vector& levelWeights, + double scaleFactor = 1.1, + int minNeighbors = 3, int flags = 0, + Size minSize = Size(), + Size maxSize = Size(), + bool outputRejectLevels = false ); + + CV_WRAP bool isOldFormatCascade() const; + CV_WRAP Size getOriginalWindowSize() const; + CV_WRAP int getFeatureType() const; + void* getOldCascade(); + + CV_WRAP static bool convert(const String& oldcascade, const String& newcascade); + + void setMaskGenerator(const Ptr& maskGenerator); + Ptr getMaskGenerator(); + + Ptr cc; +}; + +CV_EXPORTS Ptr createFaceDetectionMaskGenerator(); + +//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// + +//! struct for detection region of interest (ROI) +struct DetectionROI +{ + //! scale(size) of the bounding box + double scale; + //! set of requested locations to be evaluated + std::vector locations; + //! vector that will contain confidence values for each location + std::vector confidences; +}; + +/**@brief Implementation of HOG (Histogram of Oriented Gradients) descriptor and object detector. + +the HOG descriptor algorithm introduced by Navneet Dalal and Bill Triggs @cite Dalal2005 . + +useful links: + +https://hal.inria.fr/inria-00548512/document/ + +https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients + +https://software.intel.com/en-us/ipp-dev-reference-histogram-of-oriented-gradients-hog-descriptor + +http://www.learnopencv.com/histogram-of-oriented-gradients + +http://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial + + */ +struct CV_EXPORTS_W HOGDescriptor +{ +public: + enum HistogramNormType { L2Hys = 0 //!< Default histogramNormType + }; + enum { DEFAULT_NLEVELS = 64 //!< Default nlevels value. + }; + enum DescriptorStorageFormat { DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW }; + + /**@brief Creates the HOG descriptor and detector with default params. + + aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9 ) + */ + CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8), + cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1), + histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true), + free_coef(-1.f), nlevels(HOGDescriptor::DEFAULT_NLEVELS), signedGradient(false) + {} + + /** @overload + @param _winSize sets winSize with given value. + @param _blockSize sets blockSize with given value. + @param _blockStride sets blockStride with given value. + @param _cellSize sets cellSize with given value. + @param _nbins sets nbins with given value. + @param _derivAperture sets derivAperture with given value. + @param _winSigma sets winSigma with given value. + @param _histogramNormType sets histogramNormType with given value. + @param _L2HysThreshold sets L2HysThreshold with given value. + @param _gammaCorrection sets gammaCorrection with given value. + @param _nlevels sets nlevels with given value. + @param _signedGradient sets signedGradient with given value. + */ + CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride, + Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1, + HOGDescriptor::HistogramNormType _histogramNormType=HOGDescriptor::L2Hys, + double _L2HysThreshold=0.2, bool _gammaCorrection=false, + int _nlevels=HOGDescriptor::DEFAULT_NLEVELS, bool _signedGradient=false) + : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize), + nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma), + histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold), + gammaCorrection(_gammaCorrection), free_coef(-1.f), nlevels(_nlevels), signedGradient(_signedGradient) + {} + + /** @overload + @param filename The file name containing HOGDescriptor properties and coefficients for the linear SVM classifier. + */ + CV_WRAP HOGDescriptor(const String& filename) + { + load(filename); + } + + /** @overload + @param d the HOGDescriptor which cloned to create a new one. + */ + HOGDescriptor(const HOGDescriptor& d) + { + d.copyTo(*this); + } + + /**@brief Default destructor. + */ + virtual ~HOGDescriptor() {} + + /**@brief Returns the number of coefficients required for the classification. + */ + CV_WRAP size_t getDescriptorSize() const; + + /** @brief Checks if detector size equal to descriptor size. + */ + CV_WRAP bool checkDetectorSize() const; + + /** @brief Returns winSigma value + */ + CV_WRAP double getWinSigma() const; + + /**@example samples/cpp/peopledetect.cpp + */ + /**@brief Sets coefficients for the linear SVM classifier. + @param svmdetector coefficients for the linear SVM classifier. + */ + CV_WRAP virtual void setSVMDetector(InputArray svmdetector); + + /** @brief Reads HOGDescriptor parameters from a cv::FileNode. + @param fn File node + */ + virtual bool read(FileNode& fn); + + /** @brief Stores HOGDescriptor parameters in a cv::FileStorage. + @param fs File storage + @param objname Object name + */ + virtual void write(FileStorage& fs, const String& objname) const; + + /** @brief loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file. + @param filename Path of the file to read. + @param objname The optional name of the node to read (if empty, the first top-level node will be used). + */ + CV_WRAP virtual bool load(const String& filename, const String& objname = String()); + + /** @brief saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file + @param filename File name + @param objname Object name + */ + CV_WRAP virtual void save(const String& filename, const String& objname = String()) const; + + /** @brief clones the HOGDescriptor + @param c cloned HOGDescriptor + */ + virtual void copyTo(HOGDescriptor& c) const; + + /**@example samples/cpp/train_HOG.cpp + */ + /** @brief Computes HOG descriptors of given image. + @param img Matrix of the type CV_8U containing an image where HOG features will be calculated. + @param descriptors Matrix of the type CV_32F + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param locations Vector of Point + */ + CV_WRAP virtual void compute(InputArray img, + CV_OUT std::vector& descriptors, + Size winStride = Size(), Size padding = Size(), + const std::vector& locations = std::vector()) const; + + /** @brief Performs object detection without a multi-scale window. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. + @param weights Vector that will contain confidence values for each detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param searchLocations Vector of Point includes set of requested locations to be evaluated. + */ + CV_WRAP virtual void detect(InputArray img, CV_OUT std::vector& foundLocations, + CV_OUT std::vector& weights, + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), + const std::vector& searchLocations = std::vector()) const; + + /** @brief Performs object detection without a multi-scale window. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of point where each point contains left-top corner point of detected object boundaries. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param searchLocations Vector of Point includes locations to search. + */ + virtual void detect(InputArray img, CV_OUT std::vector& foundLocations, + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), + const std::vector& searchLocations=std::vector()) const; + + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param foundWeights Vector that will contain confidence values for each detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param scale Coefficient of the detection window increase. + @param finalThreshold Final threshold + @param useMeanshiftGrouping indicates grouping algorithm + */ + CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector& foundLocations, + CV_OUT std::vector& foundWeights, double hitThreshold = 0, + Size winStride = Size(), Size padding = Size(), double scale = 1.05, + double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const; + + /** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list + of rectangles. + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param hitThreshold Threshold for the distance between features and SVM classifying plane. + Usually it is 0 and should be specified in the detector coefficients (as the last free coefficient). + But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param winStride Window stride. It must be a multiple of block stride. + @param padding Padding + @param scale Coefficient of the detection window increase. + @param finalThreshold Final threshold + @param useMeanshiftGrouping indicates grouping algorithm + */ + virtual void detectMultiScale(InputArray img, CV_OUT std::vector& foundLocations, + double hitThreshold = 0, Size winStride = Size(), + Size padding = Size(), double scale = 1.05, + double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const; + + /** @brief Computes gradients and quantized gradient orientations. + @param img Matrix contains the image to be computed + @param grad Matrix of type CV_32FC2 contains computed gradients + @param angleOfs Matrix of type CV_8UC2 contains quantized gradient orientations + @param paddingTL Padding from top-left + @param paddingBR Padding from bottom-right + */ + CV_WRAP virtual void computeGradient(InputArray img, InputOutputArray grad, InputOutputArray angleOfs, + Size paddingTL = Size(), Size paddingBR = Size()) const; + + /** @brief Returns coefficients of the classifier trained for people detection (for 64x128 windows). + */ + CV_WRAP static std::vector getDefaultPeopleDetector(); + + /**@example samples/tapi/hog.cpp + */ + /** @brief Returns coefficients of the classifier trained for people detection (for 48x96 windows). + */ + CV_WRAP static std::vector getDaimlerPeopleDetector(); + + //! Detection window size. Align to block size and block stride. Default value is Size(64,128). + CV_PROP Size winSize; + + //! Block size in pixels. Align to cell size. Default value is Size(16,16). + CV_PROP Size blockSize; + + //! Block stride. It must be a multiple of cell size. Default value is Size(8,8). + CV_PROP Size blockStride; + + //! Cell size. Default value is Size(8,8). + CV_PROP Size cellSize; + + //! Number of bins used in the calculation of histogram of gradients. Default value is 9. + CV_PROP int nbins; + + //! not documented + CV_PROP int derivAperture; + + //! Gaussian smoothing window parameter. + CV_PROP double winSigma; + + //! histogramNormType + CV_PROP HOGDescriptor::HistogramNormType histogramNormType; + + //! L2-Hys normalization method shrinkage. + CV_PROP double L2HysThreshold; + + //! Flag to specify whether the gamma correction preprocessing is required or not. + CV_PROP bool gammaCorrection; + + //! coefficients for the linear SVM classifier. + CV_PROP std::vector svmDetector; + + //! coefficients for the linear SVM classifier used when OpenCL is enabled + UMat oclSvmDetector; + + //! not documented + float free_coef; + + //! Maximum number of detection window increases. Default value is 64 + CV_PROP int nlevels; + + //! Indicates signed gradient will be used or not + CV_PROP bool signedGradient; + + /** @brief evaluate specified ROI and return confidence value for each location + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param locations Vector of Point + @param foundLocations Vector of Point where each Point is detected object's top-left point. + @param confidences confidences + @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually + it is 0 and should be specified in the detector coefficients (as the last free coefficient). But if + the free coefficient is omitted (which is allowed), you can specify it manually here + @param winStride winStride + @param padding padding + */ + virtual void detectROI(InputArray img, const std::vector &locations, + CV_OUT std::vector& foundLocations, CV_OUT std::vector& confidences, + double hitThreshold = 0, cv::Size winStride = Size(), + cv::Size padding = Size()) const; + + /** @brief evaluate specified ROI and return confidence value for each location in multiple scales + @param img Matrix of the type CV_8U or CV_8UC3 containing an image where objects are detected. + @param foundLocations Vector of rectangles where each rectangle contains the detected object. + @param locations Vector of DetectionROI + @param hitThreshold Threshold for the distance between features and SVM classifying plane. Usually it is 0 and should be specified + in the detector coefficients (as the last free coefficient). But if the free coefficient is omitted (which is allowed), you can specify it manually here. + @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. + */ + virtual void detectMultiScaleROI(InputArray img, + CV_OUT std::vector& foundLocations, + std::vector& locations, + double hitThreshold = 0, + int groupThreshold = 0) const; + + /** @brief Groups the object candidate rectangles. + @param rectList Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.) + @param weights Input/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.) + @param groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it. + @param eps Relative difference between sides of the rectangles to merge them into a group. + */ + void groupRectangles(std::vector& rectList, std::vector& weights, int groupThreshold, double eps) const; +}; + +class CV_EXPORTS_W QRCodeDetector +{ +public: + CV_WRAP QRCodeDetector(); + ~QRCodeDetector(); + + /** @brief sets the epsilon used during the horizontal scan of QR code stop marker detection. + @param epsX Epsilon neighborhood, which allows you to determine the horizontal pattern + of the scheme 1:1:3:1:1 according to QR code standard. + */ + CV_WRAP void setEpsX(double epsX); + /** @brief sets the epsilon used during the vertical scan of QR code stop marker detection. + @param epsY Epsilon neighborhood, which allows you to determine the vertical pattern + of the scheme 1:1:3:1:1 according to QR code standard. + */ + CV_WRAP void setEpsY(double epsY); + + /** @brief Detects QR code in image and returns the quadrangle containing the code. + @param img grayscale or color (BGR) image containing (or not) QR code. + @param points Output vector of vertices of the minimum-area quadrangle containing the code. + */ + CV_WRAP bool detect(InputArray img, OutputArray points) const; + + /** @brief Decodes QR code in image once it's found by the detect() method. + Returns UTF8-encoded output string or empty string if the code cannot be decoded. + + @param img grayscale or color (BGR) image containing QR code. + @param points Quadrangle vertices found by detect() method (or some other algorithm). + @param straight_qrcode The optional output image containing rectified and binarized QR code + */ + CV_WRAP std::string decode(InputArray img, InputArray points, OutputArray straight_qrcode = noArray()); + + /** @brief Both detects and decodes QR code + + @param img grayscale or color (BGR) image containing QR code. + @param points opiotnal output array of vertices of the found QR code quadrangle. Will be empty if not found. + @param straight_qrcode The optional output image containing rectified and binarized QR code + */ + CV_WRAP std::string detectAndDecode(InputArray img, OutputArray points=noArray(), + OutputArray straight_qrcode = noArray()); +protected: + struct Impl; + Ptr p; +}; + +//! @} objdetect +} + +#include "opencv2/objdetect/detection_based_tracker.hpp" + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect/detection_based_tracker.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect/detection_based_tracker.hpp new file mode 100644 index 0000000000000000000000000000000000000000..18cde13eabe7c7471e2dc881c8cf728c5cc877aa --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect/detection_based_tracker.hpp @@ -0,0 +1,222 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_OBJDETECT_DBT_HPP +#define OPENCV_OBJDETECT_DBT_HPP + +#include + +#include + +namespace cv +{ + +//! @addtogroup objdetect +//! @{ + +class CV_EXPORTS DetectionBasedTracker +{ + public: + struct CV_EXPORTS Parameters + { + int maxTrackLifetime; + int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0 + + Parameters(); + }; + + class IDetector + { + public: + IDetector(): + minObjSize(96, 96), + maxObjSize(INT_MAX, INT_MAX), + minNeighbours(2), + scaleFactor(1.1f) + {} + + virtual void detect(const cv::Mat& image, std::vector& objects) = 0; + + void setMinObjectSize(const cv::Size& min) + { + minObjSize = min; + } + void setMaxObjectSize(const cv::Size& max) + { + maxObjSize = max; + } + cv::Size getMinObjectSize() const + { + return minObjSize; + } + cv::Size getMaxObjectSize() const + { + return maxObjSize; + } + float getScaleFactor() + { + return scaleFactor; + } + void setScaleFactor(float value) + { + scaleFactor = value; + } + int getMinNeighbours() + { + return minNeighbours; + } + void setMinNeighbours(int value) + { + minNeighbours = value; + } + virtual ~IDetector() {} + + protected: + cv::Size minObjSize; + cv::Size maxObjSize; + int minNeighbours; + float scaleFactor; + }; + + DetectionBasedTracker(cv::Ptr mainDetector, cv::Ptr trackingDetector, const Parameters& params); + virtual ~DetectionBasedTracker(); + + virtual bool run(); + virtual void stop(); + virtual void resetTracking(); + + virtual void process(const cv::Mat& imageGray); + + bool setParameters(const Parameters& params); + const Parameters& getParameters() const; + + + typedef std::pair Object; + virtual void getObjects(std::vector& result) const; + virtual void getObjects(std::vector& result) const; + + enum ObjectStatus + { + DETECTED_NOT_SHOWN_YET, + DETECTED, + DETECTED_TEMPORARY_LOST, + WRONG_OBJECT + }; + struct ExtObject + { + int id; + cv::Rect location; + ObjectStatus status; + ExtObject(int _id, cv::Rect _location, ObjectStatus _status) + :id(_id), location(_location), status(_status) + { + } + }; + virtual void getObjects(std::vector& result) const; + + + virtual int addObject(const cv::Rect& location); //returns id of the new object + + protected: + class SeparateDetectionWork; + cv::Ptr separateDetectionWork; + friend void* workcycleObjectDetectorFunction(void* p); + + struct InnerParameters + { + int numLastPositionsToTrack; + int numStepsToWaitBeforeFirstShow; + int numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown; + int numStepsToShowWithoutDetecting; + + float coeffTrackingWindowSize; + float coeffObjectSizeToTrack; + float coeffObjectSpeedUsingInPrediction; + + InnerParameters(); + }; + Parameters parameters; + InnerParameters innerParameters; + + struct TrackedObject + { + typedef std::vector PositionsVector; + + PositionsVector lastPositions; + + int numDetectedFrames; + int numFramesNotDetected; + int id; + + TrackedObject(const cv::Rect& rect):numDetectedFrames(1), numFramesNotDetected(0) + { + lastPositions.push_back(rect); + id=getNextId(); + }; + + static int getNextId() + { + static int _id=0; + return _id++; + } + }; + + int numTrackedSteps; + std::vector trackedObjects; + + std::vector weightsPositionsSmoothing; + std::vector weightsSizesSmoothing; + + cv::Ptr cascadeForTracking; + + void updateTrackedObjects(const std::vector& detectedObjects); + cv::Rect calcTrackedObjectPositionToShow(int i) const; + cv::Rect calcTrackedObjectPositionToShow(int i, ObjectStatus& status) const; + void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector& detectedObjectsInRegions); +}; + +//! @} objdetect + +} //end of cv namespace + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect/objdetect.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect/objdetect.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3ee284f4275e3ec013df5c6c1b6b55cd7effe6de --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/objdetect/objdetect.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/objdetect.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/opencv.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/opencv.hpp new file mode 100644 index 0000000000000000000000000000000000000000..40481587f05782ae97989657dec822276096a48c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/opencv.hpp @@ -0,0 +1,139 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_ALL_HPP +#define OPENCV_ALL_HPP + +// File that defines what modules where included during the build of OpenCV +// These are purely the defines of the correct HAVE_OPENCV_modulename values +#include "opencv2/opencv_modules.hpp" + +// Then the list of defines is checked to include the correct headers +// Core library is always included --> without no OpenCV functionality available +#include "opencv2/core.hpp" + +// Then the optional modules are checked +#ifdef HAVE_OPENCV_CALIB3D +#include "opencv2/calib3d.hpp" +#endif +#ifdef HAVE_OPENCV_FEATURES2D +#include "opencv2/features2d.hpp" +#endif +#ifdef HAVE_OPENCV_DNN +#include "opencv2/dnn.hpp" +#endif +#ifdef HAVE_OPENCV_FLANN +#include "opencv2/flann.hpp" +#endif +#ifdef HAVE_OPENCV_HIGHGUI +#include "opencv2/highgui.hpp" +#endif +#ifdef HAVE_OPENCV_IMGCODECS +#include "opencv2/imgcodecs.hpp" +#endif +#ifdef HAVE_OPENCV_IMGPROC +#include "opencv2/imgproc.hpp" +#endif +#ifdef HAVE_OPENCV_ML +#include "opencv2/ml.hpp" +#endif +#ifdef HAVE_OPENCV_OBJDETECT +#include "opencv2/objdetect.hpp" +#endif +#ifdef HAVE_OPENCV_PHOTO +#include "opencv2/photo.hpp" +#endif +#ifdef HAVE_OPENCV_SHAPE +#include "opencv2/shape.hpp" +#endif +#ifdef HAVE_OPENCV_STITCHING +#include "opencv2/stitching.hpp" +#endif +#ifdef HAVE_OPENCV_SUPERRES +#include "opencv2/superres.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEO +#include "opencv2/video.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOIO +#include "opencv2/videoio.hpp" +#endif +#ifdef HAVE_OPENCV_VIDEOSTAB +#include "opencv2/videostab.hpp" +#endif +#ifdef HAVE_OPENCV_VIZ +#include "opencv2/viz.hpp" +#endif + +// Finally CUDA specific entries are checked and added +#ifdef HAVE_OPENCV_CUDAARITHM +#include "opencv2/cudaarithm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDABGSEGM +#include "opencv2/cudabgsegm.hpp" +#endif +#ifdef HAVE_OPENCV_CUDACODEC +#include "opencv2/cudacodec.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFEATURES2D +#include "opencv2/cudafeatures2d.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAFILTERS +#include "opencv2/cudafilters.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAIMGPROC +#include "opencv2/cudaimgproc.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOBJDETECT +#include "opencv2/cudaobjdetect.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAOPTFLOW +#include "opencv2/cudaoptflow.hpp" +#endif +#ifdef HAVE_OPENCV_CUDASTEREO +#include "opencv2/cudastereo.hpp" +#endif +#ifdef HAVE_OPENCV_CUDAWARPING +#include "opencv2/cudawarping.hpp" +#endif + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/opencv_modules.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/opencv_modules.hpp new file mode 100644 index 0000000000000000000000000000000000000000..59444db418dd02ab6775e34eee56065d3366d109 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/opencv_modules.hpp @@ -0,0 +1,66 @@ +/* + * ** File generated automatically, do not modify ** + * + * This file defines the list of modules available in current build configuration + * + * +*/ + +// This definition means that OpenCV is built with enabled non-free code. +// For example, patented algorithms for non-profit/non-commercial use only. +/* #undef OPENCV_ENABLE_NONFREE */ + +#define HAVE_OPENCV_ARUCO +#define HAVE_OPENCV_BGSEGM +#define HAVE_OPENCV_BIOINSPIRED +#define HAVE_OPENCV_CALIB3D +#define HAVE_OPENCV_CCALIB +#define HAVE_OPENCV_CORE +#define HAVE_OPENCV_CVV +#define HAVE_OPENCV_DATASETS +#define HAVE_OPENCV_DNN +#define HAVE_OPENCV_DNN_OBJDETECT +#define HAVE_OPENCV_DNN_SUPERRES +#define HAVE_OPENCV_DPM +#define HAVE_OPENCV_FACE +#define HAVE_OPENCV_FEATURES2D +#define HAVE_OPENCV_FLANN +#define HAVE_OPENCV_FREETYPE +#define HAVE_OPENCV_FUZZY +#define HAVE_OPENCV_GAPI +#define HAVE_OPENCV_HDF +#define HAVE_OPENCV_HFS +#define HAVE_OPENCV_HIGHGUI +#define HAVE_OPENCV_IMG_HASH +#define HAVE_OPENCV_IMGCODECS +#define HAVE_OPENCV_IMGPROC +#define HAVE_OPENCV_LINE_DESCRIPTOR +#define HAVE_OPENCV_ML +#define HAVE_OPENCV_OBJDETECT +#define HAVE_OPENCV_OPTFLOW +#define HAVE_OPENCV_PHASE_UNWRAPPING +#define HAVE_OPENCV_PHOTO +#define HAVE_OPENCV_PLOT +#define HAVE_OPENCV_QUALITY +#define HAVE_OPENCV_REG +#define HAVE_OPENCV_RGBD +#define HAVE_OPENCV_SALIENCY +#define HAVE_OPENCV_SFM +#define HAVE_OPENCV_SHAPE +#define HAVE_OPENCV_STEREO +#define HAVE_OPENCV_STITCHING +#define HAVE_OPENCV_STRUCTURED_LIGHT +#define HAVE_OPENCV_SUPERRES +#define HAVE_OPENCV_SURFACE_MATCHING +#define HAVE_OPENCV_TEXT +#define HAVE_OPENCV_TRACKING +#define HAVE_OPENCV_VIDEO +#define HAVE_OPENCV_VIDEOIO +#define HAVE_OPENCV_VIDEOSTAB +#define HAVE_OPENCV_VIZ +#define HAVE_OPENCV_XFEATURES2D +#define HAVE_OPENCV_XIMGPROC +#define HAVE_OPENCV_XOBJDETECT +#define HAVE_OPENCV_XPHOTO + + diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..093b5fe2c7facb60fbf919425ed57d1a0424f350 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow.hpp @@ -0,0 +1,309 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_OPTFLOW_HPP__ +#define __OPENCV_OPTFLOW_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/video.hpp" + +/** +@defgroup optflow Optical Flow Algorithms + +Dense optical flow algorithms compute motion for each point: + +- cv::optflow::calcOpticalFlowSF +- cv::optflow::createOptFlow_DeepFlow + +Motion templates is alternative technique for detecting motion and computing its direction. +See samples/motempl.py. + +- cv::motempl::updateMotionHistory +- cv::motempl::calcMotionGradient +- cv::motempl::calcGlobalOrientation +- cv::motempl::segmentMotion + +Functions reading and writing .flo files in "Middlebury" format, see: + +- cv::optflow::readOpticalFlow +- cv::optflow::writeOpticalFlow + + */ + +#include "opencv2/optflow/pcaflow.hpp" +#include "opencv2/optflow/sparse_matching_gpc.hpp" +#include "opencv2/optflow/rlofflow.hpp" +namespace cv +{ +namespace optflow +{ + +//! @addtogroup optflow +//! @{ + +/** @overload */ +CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, + int layers, int averaging_block_size, int max_flow); + +/** @brief Calculate an optical flow using "SimpleFlow" algorithm. + +@param from First 8-bit 3-channel image. +@param to Second 8-bit 3-channel image of the same size as prev +@param flow computed flow image that has the same size as prev and type CV_32FC2 +@param layers Number of layers +@param averaging_block_size Size of block through which we sum up when calculate cost function +for pixel +@param max_flow maximal flow that we search at each level +@param sigma_dist vector smooth spatial sigma parameter +@param sigma_color vector smooth color sigma parameter +@param postprocess_window window size for postprocess cross bilateral filter +@param sigma_dist_fix spatial sigma for postprocess cross bilateralf filter +@param sigma_color_fix color sigma for postprocess cross bilateral filter +@param occ_thr threshold for detecting occlusions +@param upscale_averaging_radius window size for bilateral upscale operation +@param upscale_sigma_dist spatial sigma for bilateral upscale operation +@param upscale_sigma_color color sigma for bilateral upscale operation +@param speed_up_thr threshold to detect point with irregular flow - where flow should be +recalculated after upscale + +See @cite Tao2012 . And site of project - . + +@note + - An example using the simpleFlow algorithm can be found at samples/simpleflow_demo.cpp + */ +CV_EXPORTS_W void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, int layers, + int averaging_block_size, int max_flow, + double sigma_dist, double sigma_color, int postprocess_window, + double sigma_dist_fix, double sigma_color_fix, double occ_thr, + int upscale_averaging_radius, double upscale_sigma_dist, + double upscale_sigma_color, double speed_up_thr ); + +/** @brief Fast dense optical flow based on PyrLK sparse matches interpolation. + +@param from first 8-bit 3-channel or 1-channel image. +@param to second 8-bit 3-channel or 1-channel image of the same size as from +@param flow computed flow image that has the same size as from and CV_32FC2 type +@param grid_step stride used in sparse match computation. Lower values usually + result in higher quality but slow down the algorithm. +@param k number of nearest-neighbor matches considered, when fitting a locally affine + model. Lower values can make the algorithm noticeably faster at the cost of + some quality degradation. +@param sigma parameter defining how fast the weights decrease in the locally-weighted affine + fitting. Higher values can help preserve fine details, lower values can help to get rid + of the noise in the output flow. +@param use_post_proc defines whether the ximgproc::fastGlobalSmootherFilter() is used + for post-processing after interpolation +@param fgs_lambda see the respective parameter of the ximgproc::fastGlobalSmootherFilter() +@param fgs_sigma see the respective parameter of the ximgproc::fastGlobalSmootherFilter() + */ +CV_EXPORTS_W void calcOpticalFlowSparseToDense ( InputArray from, InputArray to, OutputArray flow, + int grid_step = 8, int k = 128, float sigma = 0.05f, + bool use_post_proc = true, float fgs_lambda = 500.0f, + float fgs_sigma = 1.5f ); + +/** @brief DeepFlow optical flow algorithm implementation. + +The class implements the DeepFlow optical flow algorithm described in @cite Weinzaepfel2013 . See +also . +Parameters - class fields - that may be modified after creating a class instance: +- member float alpha +Smoothness assumption weight +- member float delta +Color constancy assumption weight +- member float gamma +Gradient constancy weight +- member float sigma +Gaussian smoothing parameter +- member int minSize +Minimal dimension of an image in the pyramid (next, smaller images in the pyramid are generated +until one of the dimensions reaches this size) +- member float downscaleFactor +Scaling factor in the image pyramid (must be \< 1) +- member int fixedPointIterations +How many iterations on each level of the pyramid +- member int sorIterations +Iterations of Succesive Over-Relaxation (solver) +- member float omega +Relaxation factor in SOR + */ +CV_EXPORTS_W Ptr createOptFlow_DeepFlow(); + +//! Additional interface to the SimpleFlow algorithm - calcOpticalFlowSF() +CV_EXPORTS_W Ptr createOptFlow_SimpleFlow(); + +//! Additional interface to the Farneback's algorithm - calcOpticalFlowFarneback() +CV_EXPORTS_W Ptr createOptFlow_Farneback(); + +//! Additional interface to the SparseToDenseFlow algorithm - calcOpticalFlowSparseToDense() +CV_EXPORTS_W Ptr createOptFlow_SparseToDense(); + +/** @brief "Dual TV L1" Optical Flow Algorithm. + +The class implements the "Dual TV L1" optical flow algorithm described in @cite Zach2007 and +@cite Javier2012 . +Here are important members of the class that control the algorithm, which you can set after +constructing the class instance: + +- member double tau + Time step of the numerical scheme. + +- member double lambda + Weight parameter for the data term, attachment parameter. This is the most relevant + parameter, which determines the smoothness of the output. The smaller this parameter is, + the smoother the solutions we obtain. It depends on the range of motions of the images, so + its value should be adapted to each image sequence. + +- member double theta + Weight parameter for (u - v)\^2, tightness parameter. It serves as a link between the + attachment and the regularization terms. In theory, it should have a small value in order + to maintain both parts in correspondence. The method is stable for a large range of values + of this parameter. + +- member int nscales + Number of scales used to create the pyramid of images. + +- member int warps + Number of warpings per scale. Represents the number of times that I1(x+u0) and grad( + I1(x+u0) ) are computed per scale. This is a parameter that assures the stability of the + method. It also affects the running time, so it is a compromise between speed and + accuracy. + +- member double epsilon + Stopping criterion threshold used in the numerical scheme, which is a trade-off between + precision and running time. A small value will yield more accurate solutions at the + expense of a slower convergence. + +- member int iterations + Stopping criterion iterations number used in the numerical scheme. + +C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". +Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation". +*/ +class CV_EXPORTS_W DualTVL1OpticalFlow : public DenseOpticalFlow +{ +public: + //! @brief Time step of the numerical scheme + /** @see setTau */ + CV_WRAP virtual double getTau() const = 0; + /** @copybrief getTau @see getTau */ + CV_WRAP virtual void setTau(double val) = 0; + //! @brief Weight parameter for the data term, attachment parameter + /** @see setLambda */ + CV_WRAP virtual double getLambda() const = 0; + /** @copybrief getLambda @see getLambda */ + CV_WRAP virtual void setLambda(double val) = 0; + //! @brief Weight parameter for (u - v)^2, tightness parameter + /** @see setTheta */ + CV_WRAP virtual double getTheta() const = 0; + /** @copybrief getTheta @see getTheta */ + CV_WRAP virtual void setTheta(double val) = 0; + //! @brief coefficient for additional illumination variation term + /** @see setGamma */ + CV_WRAP virtual double getGamma() const = 0; + /** @copybrief getGamma @see getGamma */ + CV_WRAP virtual void setGamma(double val) = 0; + //! @brief Number of scales used to create the pyramid of images + /** @see setScalesNumber */ + CV_WRAP virtual int getScalesNumber() const = 0; + /** @copybrief getScalesNumber @see getScalesNumber */ + CV_WRAP virtual void setScalesNumber(int val) = 0; + //! @brief Number of warpings per scale + /** @see setWarpingsNumber */ + CV_WRAP virtual int getWarpingsNumber() const = 0; + /** @copybrief getWarpingsNumber @see getWarpingsNumber */ + CV_WRAP virtual void setWarpingsNumber(int val) = 0; + //! @brief Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time + /** @see setEpsilon */ + CV_WRAP virtual double getEpsilon() const = 0; + /** @copybrief getEpsilon @see getEpsilon */ + CV_WRAP virtual void setEpsilon(double val) = 0; + //! @brief Inner iterations (between outlier filtering) used in the numerical scheme + /** @see setInnerIterations */ + CV_WRAP virtual int getInnerIterations() const = 0; + /** @copybrief getInnerIterations @see getInnerIterations */ + CV_WRAP virtual void setInnerIterations(int val) = 0; + //! @brief Outer iterations (number of inner loops) used in the numerical scheme + /** @see setOuterIterations */ + CV_WRAP virtual int getOuterIterations() const = 0; + /** @copybrief getOuterIterations @see getOuterIterations */ + CV_WRAP virtual void setOuterIterations(int val) = 0; + //! @brief Use initial flow + /** @see setUseInitialFlow */ + CV_WRAP virtual bool getUseInitialFlow() const = 0; + /** @copybrief getUseInitialFlow @see getUseInitialFlow */ + CV_WRAP virtual void setUseInitialFlow(bool val) = 0; + //! @brief Step between scales (<1) + /** @see setScaleStep */ + CV_WRAP virtual double getScaleStep() const = 0; + /** @copybrief getScaleStep @see getScaleStep */ + CV_WRAP virtual void setScaleStep(double val) = 0; + //! @brief Median filter kernel size (1 = no filter) (3 or 5) + /** @see setMedianFiltering */ + CV_WRAP virtual int getMedianFiltering() const = 0; + /** @copybrief getMedianFiltering @see getMedianFiltering */ + CV_WRAP virtual void setMedianFiltering(int val) = 0; + + /** @brief Creates instance of cv::DualTVL1OpticalFlow*/ + CV_WRAP static Ptr create( + double tau = 0.25, + double lambda = 0.15, + double theta = 0.3, + int nscales = 5, + int warps = 5, + double epsilon = 0.01, + int innnerIterations = 30, + int outerIterations = 10, + double scaleStep = 0.8, + double gamma = 0.0, + int medianFiltering = 5, + bool useInitialFlow = false); +}; + +/** @brief Creates instance of cv::DenseOpticalFlow +*/ +CV_EXPORTS_W Ptr createOptFlow_DualTVL1(); + +//! @} + +} //optflow +} + +#include "opencv2/optflow/motempl.hpp" + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/motempl.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/motempl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..aeea9e8cd7cee61dddbe7df5564167afd4040271 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/motempl.hpp @@ -0,0 +1,147 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2013, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +#ifndef __OPENCV_OPTFLOW_MOTEMPL_HPP__ +#define __OPENCV_OPTFLOW_MOTEMPL_HPP__ + +#include "opencv2/core.hpp" + +namespace cv +{ +namespace motempl +{ + +//! @addtogroup optflow +//! @{ + +/** @brief Updates the motion history image by a moving silhouette. + +@param silhouette Silhouette mask that has non-zero pixels where the motion occurs. +@param mhi Motion history image that is updated by the function (single-channel, 32-bit +floating-point). +@param timestamp Current time in milliseconds or other units. +@param duration Maximal duration of the motion track in the same units as timestamp . + +The function updates the motion history image as follows: + +\f[\texttt{mhi} (x,y)= \forkthree{\texttt{timestamp}}{if \(\texttt{silhouette}(x,y) \ne 0\)}{0}{if \(\texttt{silhouette}(x,y) = 0\) and \(\texttt{mhi} < (\texttt{timestamp} - \texttt{duration})\)}{\texttt{mhi}(x,y)}{otherwise}\f] + +That is, MHI pixels where the motion occurs are set to the current timestamp , while the pixels +where the motion happened last time a long time ago are cleared. + +The function, together with calcMotionGradient and calcGlobalOrientation , implements a motion +templates technique described in @cite Davis97 and @cite Bradski00 . + */ +CV_EXPORTS_W void updateMotionHistory( InputArray silhouette, InputOutputArray mhi, + double timestamp, double duration ); + +/** @brief Calculates a gradient orientation of a motion history image. + +@param mhi Motion history single-channel floating-point image. +@param mask Output mask image that has the type CV_8UC1 and the same size as mhi . Its non-zero +elements mark pixels where the motion gradient data is correct. +@param orientation Output motion gradient orientation image that has the same type and the same +size as mhi . Each pixel of the image is a motion orientation, from 0 to 360 degrees. +@param delta1 Minimal (or maximal) allowed difference between mhi values within a pixel +neighborhood. +@param delta2 Maximal (or minimal) allowed difference between mhi values within a pixel +neighborhood. That is, the function finds the minimum ( \f$m(x,y)\f$ ) and maximum ( \f$M(x,y)\f$ ) mhi +values over \f$3 \times 3\f$ neighborhood of each pixel and marks the motion orientation at \f$(x, y)\f$ +as valid only if +\f[\min ( \texttt{delta1} , \texttt{delta2} ) \le M(x,y)-m(x,y) \le \max ( \texttt{delta1} , \texttt{delta2} ).\f] +@param apertureSize Aperture size of the Sobel operator. + +The function calculates a gradient orientation at each pixel \f$(x, y)\f$ as: + +\f[\texttt{orientation} (x,y)= \arctan{\frac{d\texttt{mhi}/dy}{d\texttt{mhi}/dx}}\f] + +In fact, fastAtan2 and phase are used so that the computed angle is measured in degrees and covers +the full range 0..360. Also, the mask is filled to indicate pixels where the computed angle is +valid. + +@note + - (Python) An example on how to perform a motion template technique can be found at + opencv_source_code/samples/python2/motempl.py + */ +CV_EXPORTS_W void calcMotionGradient( InputArray mhi, OutputArray mask, OutputArray orientation, + double delta1, double delta2, int apertureSize = 3 ); + +/** @brief Calculates a global motion orientation in a selected region. + +@param orientation Motion gradient orientation image calculated by the function calcMotionGradient +@param mask Mask image. It may be a conjunction of a valid gradient mask, also calculated by +calcMotionGradient , and the mask of a region whose direction needs to be calculated. +@param mhi Motion history image calculated by updateMotionHistory . +@param timestamp Timestamp passed to updateMotionHistory . +@param duration Maximum duration of a motion track in milliseconds, passed to updateMotionHistory + +The function calculates an average motion direction in the selected region and returns the angle +between 0 degrees and 360 degrees. The average direction is computed from the weighted orientation +histogram, where a recent motion has a larger weight and the motion occurred in the past has a +smaller weight, as recorded in mhi . + */ +CV_EXPORTS_W double calcGlobalOrientation( InputArray orientation, InputArray mask, InputArray mhi, + double timestamp, double duration ); + +/** @brief Splits a motion history image into a few parts corresponding to separate independent motions (for +example, left hand, right hand). + +@param mhi Motion history image. +@param segmask Image where the found mask should be stored, single-channel, 32-bit floating-point. +@param boundingRects Vector containing ROIs of motion connected components. +@param timestamp Current time in milliseconds or other units. +@param segThresh Segmentation threshold that is recommended to be equal to the interval between +motion history "steps" or greater. + +The function finds all of the motion segments and marks them in segmask with individual values +(1,2,...). It also computes a vector with ROIs of motion connected components. After that the motion +direction for every component can be calculated with calcGlobalOrientation using the extracted mask +of the particular component. + */ +CV_EXPORTS_W void segmentMotion( InputArray mhi, OutputArray segmask, + CV_OUT std::vector& boundingRects, + double timestamp, double segThresh ); + + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/pcaflow.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/pcaflow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..78946f69db0de610c2ad807b51da3f1764ddc76c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/pcaflow.hpp @@ -0,0 +1,149 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2016, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +/** + * @file pcaflow.hpp + * @author Vladislav Samsonov + * @brief Implementation of the PCAFlow algorithm from the following paper: + * http://files.is.tue.mpg.de/black/papers/cvpr2015_pcaflow.pdf + * + * @cite Wulff:CVPR:2015 + * + * There are some key differences which distinguish this algorithm from the original PCAFlow (see paper): + * - Discrete Cosine Transform basis is used instead of basis extracted with PCA. + * Reasoning: DCT basis has comparable performance and it doesn't require additional storage space. + * Also, this decision helps to avoid overloading the algorithm with a lot of external input. + * - Usage of built-in OpenCV feature tracking instead of libviso. +*/ + +#ifndef __OPENCV_OPTFLOW_PCAFLOW_HPP__ +#define __OPENCV_OPTFLOW_PCAFLOW_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/video.hpp" + +namespace cv +{ +namespace optflow +{ + +//! @addtogroup optflow +//! @{ + +/** @brief + * This class can be used for imposing a learned prior on the resulting optical flow. + * Solution will be regularized according to this prior. + * You need to generate appropriate prior file with "learn_prior.py" script beforehand. + */ +class CV_EXPORTS_W PCAPrior +{ +private: + Mat L1; + Mat L2; + Mat c1; + Mat c2; + +public: + PCAPrior( const char *pathToPrior ); + + int getPadding() const { return L1.size().height; } + + int getBasisSize() const { return L1.size().width; } + + void fillConstraints( float *A1, float *A2, float *b1, float *b2 ) const; +}; + +/** @brief PCAFlow algorithm. + */ +class CV_EXPORTS_W OpticalFlowPCAFlow : public DenseOpticalFlow +{ +protected: + const Ptr prior; + const Size basisSize; + const float sparseRate; // (0 .. 0.1) + const float retainedCornersFraction; // [0 .. 1] + const float occlusionsThreshold; + const float dampingFactor; + const float claheClip; + bool useOpenCL; + +public: + /** @brief Creates an instance of PCAFlow algorithm. + * @param _prior Learned prior or no prior (default). @see cv::optflow::PCAPrior + * @param _basisSize Number of basis vectors. + * @param _sparseRate Controls density of sparse matches. + * @param _retainedCornersFraction Retained corners fraction. + * @param _occlusionsThreshold Occlusion threshold. + * @param _dampingFactor Regularization term for solving least-squares. It is not related to the prior regularization. + * @param _claheClip Clip parameter for CLAHE. + */ + OpticalFlowPCAFlow( Ptr _prior = Ptr(), const Size _basisSize = Size( 18, 14 ), + float _sparseRate = 0.024, float _retainedCornersFraction = 0.2, + float _occlusionsThreshold = 0.0003, float _dampingFactor = 0.00002, float _claheClip = 14 ); + + void calc( InputArray I0, InputArray I1, InputOutputArray flow ) CV_OVERRIDE; + void collectGarbage() CV_OVERRIDE; + +private: + void findSparseFeatures( UMat &from, UMat &to, std::vector &features, + std::vector &predictedFeatures ) const; + + void removeOcclusions( UMat &from, UMat &to, std::vector &features, + std::vector &predictedFeatures ) const; + + void getSystem( OutputArray AOut, OutputArray b1Out, OutputArray b2Out, const std::vector &features, + const std::vector &predictedFeatures, const Size size ); + + void getSystem( OutputArray A1Out, OutputArray A2Out, OutputArray b1Out, OutputArray b2Out, + const std::vector &features, const std::vector &predictedFeatures, + const Size size ); + + OpticalFlowPCAFlow& operator=( const OpticalFlowPCAFlow& ); // make it non-assignable +}; + +/** @brief Creates an instance of PCAFlow +*/ +CV_EXPORTS_W Ptr createOptFlow_PCAFlow(); + +//! @} + +} +} + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/rlofflow.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/rlofflow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c4150cae6521c6d47a1c108a2787bf440dc151ca --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/rlofflow.hpp @@ -0,0 +1,544 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +#ifndef __OPENCV_OPTFLOW_RLOFFLOW_HPP__ +#define __OPENCV_OPTFLOW_RLOFFLOW_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/video.hpp" + +namespace cv +{ +namespace optflow +{ +//! @addtogroup optflow +//! @{ + +enum SupportRegionType { + SR_FIXED = 0, /**< Apply a constant support region */ + SR_CROSS = 1 /**< Apply a adaptive support region obtained by cross-based segmentation + * as described in @cite Senst2014 + */ +}; +enum SolverType { + ST_STANDART = 0, /**< Apply standard iterative refinement */ + ST_BILINEAR = 1 /**< Apply optimized iterative refinement based bilinear equation solutions + * as described in @cite Senst2013 + */ +}; + +enum InterpolationType +{ + INTERP_GEO = 0, /**< Fast geodesic interpolation, see @cite Geistert2016 */ + INTERP_EPIC = 1, /**< Edge-preserving interpolation using ximgproc::EdgeAwareInterpolator, see @cite Revaud2015,Geistert2016. */ + INTERP_RIC = 2, /**< SLIC based robust interpolation using ximgproc::RICInterpolator, see @cite Hu2017. */ +}; + +/** @brief This is used store and set up the parameters of the robust local optical flow (RLOF) algoritm. + * + * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014 + * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as + * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019. + * The implementation is derived from optflow::calcOpticalFlowPyrLK(). + * This RLOF implementation can be seen as an improved pyramidal iterative Lucas-Kanade and includes + * a set of improving modules. The main improvements in respect to the pyramidal iterative Lucas-Kanade + * are: + * - A more robust redecending M-estimator framework (see @cite Senst2012) to improve the accuracy at + * motion boundaries and appearing and disappearing pixels. + * - an adaptive support region strategies to improve the accuracy at motion boundaries to reduce the + * corona effect, i.e oversmoothing of the PLK at motion/object boundaries. The cross-based segementation + * strategy (SR_CROSS) proposed in @cite Senst2014 uses a simple segmenation approach to obtain the optimal + * shape of the support region. + * - To deal with illumination changes (outdoor sequences and shadow) the intensity constancy assumption + * based optical flow equation has been adopt with the Gennert and Negahdaripour illumination model + * (see @cite Senst2016). This model can be switched on/off with the useIlluminationModel variable. + * - By using a global motion prior initialization (see @cite Senst2016) of the iterative refinement + * the accuracy could be significantly improved for large displacements. This initialization can be + * switched on and of with useGlobalMotionPrior variable. + * + * The RLOF can be computed with the SparseOpticalFlow class or function interface to track a set of features + * or with the DenseOpticalFlow class or function interface to compute dense optical flow. + * + * @see optflow::DenseRLOFOpticalFlow, optflow::calcOpticalFlowDenseRLOF(), optflow::SparseRLOFOpticalFlow, optflow::calcOpticalFlowSparseRLOF() + */ +class CV_EXPORTS_W RLOFOpticalFlowParameter{ +public: + RLOFOpticalFlowParameter() + :solverType(ST_BILINEAR) + ,supportRegionType(SR_CROSS) + ,normSigma0(3.2f) + ,normSigma1(7.f) + ,smallWinSize(9) + ,largeWinSize(21) + ,crossSegmentationThreshold(25) + ,maxLevel(5) + ,useInitialFlow(false) + ,useIlluminationModel(true) + ,useGlobalMotionPrior(true) + ,maxIteration(30) + ,minEigenValue(0.0001f) + ,globalMotionRansacThreshold(10) + {} + + SolverType solverType; + /**< Variable specifies the iterative refinement strategy. Please consider citing @cite Senst2013 when + * using ST_BILINEAR. + */ + + SupportRegionType supportRegionType; + /**< Variable specifies the support region shape extraction or shrinking strategy. + */ + + float normSigma0; + /**< &sigma paramter of the shrinked Hampel norm introduced in @cite Senst2012. If + * &sigma = std::numeric_limist::max() the least-square estimator will be used + * instead of the M-estimator. Althoug M-estimator is more robust against outlier in the support + * region the least-square can be fast in computation. + */ + float normSigma1; + /**< &sigma paramter of the shrinked Hampel norm introduced in @cite Senst2012. If + * &sigma = std::numeric_limist::max() the least-square estimator will be used + * instead of the M-estimator. Althoug M-estimator is more robust against outlier in the support + * region the least-square can be fast in computation. + */ + int smallWinSize; + /**< Minimal window size of the support region. This parameter is only used if supportRegionType is SR_CROSS. + */ + int largeWinSize; + /**< Maximal window size of the support region. If supportRegionType is SR_FIXED this gives the exact support + * region size. The speed of the RLOF is related to the applied win sizes. The smaller the window size the lower is the runtime, + * but the more sensitive to noise is the method. + */ + int crossSegmentationThreshold; + /**< Color similarity threshold used by cross-based segmentation following @cite Senst2014 . + * (Only used if supportRegionType is SR_CROSS). With the cross-bassed segmentation + * motion boundaries can be computed more accurately. + */ + int maxLevel; + /**< Maximal number of pyramid level used. The large this value is the more likely it is + * to obtain accurate solutions for long-range motions. The runtime is linear related to + * this parameter. + */ + bool useInitialFlow; + /**< Use next point list as initial values. A good intialization can imporve the algortihm + * accuracy and reduce the runtime by a faster convergence of the iteration refinement. + */ + bool useIlluminationModel; + /**< Use the Gennert and Negahdaripour illumination model instead of the intensity brigthness + * constraint. (proposed in @cite Senst2016 ) This model is defined as follow: + * \f[ I(\mathbf{x},t) + m \cdot I(\mathbf{x},t) + c = I(\mathbf{x},t+1) \f] + * and contains with m and c a multiplicative and additive term which makes the estimate + * more robust against illumination changes. The computational complexity is increased by + * enabling the illumination model. + */ + bool useGlobalMotionPrior; + /**< Use global motion prior initialisation has been introduced in @cite Senst2016 . It + * allows to be more accurate for long-range motion. The computational complexity is + * slightly increased by enabling the global motion prior initialisation. + */ + int maxIteration; + /**< Number of maximal iterations used for the iterative refinement. Lower values can + * reduce the runtime but also the accuracy. + */ + float minEigenValue; + /**< Threshold for the minimal eigenvalue of the gradient matrix defines when to abort the + * iterative refinement. + */ + float globalMotionRansacThreshold; + /**< To apply the global motion prior motion vectors will be computed on a regulary sampled which + * are the basis for Homography estimation using RANSAC. The reprojection threshold is based on + * n-th percentil (given by this value [0 ... 100]) of the motion vectors magnitude. + * See @cite Senst2016 for more details. + */ + + CV_WRAP void setSolverType(SolverType val); + CV_WRAP SolverType getSolverType() const; + + CV_WRAP void setSupportRegionType(SupportRegionType val); + CV_WRAP SupportRegionType getSupportRegionType() const; + + CV_WRAP void setNormSigma0(float val); + CV_WRAP float getNormSigma0() const; + + CV_WRAP void setNormSigma1(float val); + CV_WRAP float getNormSigma1() const; + + CV_WRAP void setSmallWinSize(int val); + CV_WRAP int getSmallWinSize() const; + + CV_WRAP void setLargeWinSize(int val); + CV_WRAP int getLargeWinSize() const; + + CV_WRAP void setCrossSegmentationThreshold(int val); + CV_WRAP int getCrossSegmentationThreshold() const; + + CV_WRAP void setMaxLevel(int val); + CV_WRAP int getMaxLevel() const; + + CV_WRAP void setUseInitialFlow(bool val); + CV_WRAP bool getUseInitialFlow() const; + + CV_WRAP void setUseIlluminationModel(bool val); + CV_WRAP bool getUseIlluminationModel() const; + + CV_WRAP void setUseGlobalMotionPrior(bool val); + CV_WRAP bool getUseGlobalMotionPrior() const; + + CV_WRAP void setMaxIteration(int val); + CV_WRAP int getMaxIteration() const; + + CV_WRAP void setMinEigenValue(float val); + CV_WRAP float getMinEigenValue() const; + + CV_WRAP void setGlobalMotionRansacThreshold(float val); + CV_WRAP float getGlobalMotionRansacThreshold() const; + + //! @brief Creates instance of optflow::RLOFOpticalFlowParameter + CV_WRAP static Ptr create(); +}; + +/** @brief Fast dense optical flow computation based on robust local optical flow (RLOF) algorithms and sparse-to-dense interpolation + * scheme. + * + * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014 + * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as + * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019. + * The implementation is derived from optflow::calcOpticalFlowPyrLK(). + * + * The sparse-to-dense interpolation scheme allows for fast computation of dense optical flow using RLOF (see @cite Geistert2016). + * For this scheme the following steps are applied: + * -# motion vector seeded at a regular sampled grid are computed. The sparsity of this grid can be configured with setGridStep + * -# (optinally) errornous motion vectors are filter based on the forward backward confidence. The threshold can be configured + * with setForwardBackward. The filter is only applied if the threshold >0 but than the runtime is doubled due to the estimation + * of the backward flow. + * -# Vector field interpolation is applied to the motion vector set to obtain a dense vector field. + * + * For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details. + * Parameters have been described in @cite Senst2012 @cite Senst2013 @cite Senst2014 and @cite Senst2016. + * + * @note SIMD parallelization is only available when compiling with SSE4.1. If the grid size is set to (1,1) and the + * forward backward threshold <= 0 that the dense optical flow field is purely. + * computed with the RLOF. + * + * @see optflow::calcOpticalFlowDenseRLOF(), optflow::RLOFOpticalFlowParameter +*/ +class CV_EXPORTS_W DenseRLOFOpticalFlow : public DenseOpticalFlow +{ +public: + //! @brief Configuration of the RLOF alogrithm. + /** + @see optflow::RLOFOpticalFlowParameter, getRLOFOpticalFlowParameter + */ + CV_WRAP virtual void setRLOFOpticalFlowParameter(Ptr val) = 0; + /** @copybrief setRLOFOpticalFlowParameter + @see optflow::RLOFOpticalFlowParameter, setRLOFOpticalFlowParameter + */ + CV_WRAP virtual Ptr getRLOFOpticalFlowParameter() const = 0; + //! @brief Threshold for the forward backward confidence check + /**For each grid point \f$ \mathbf{x} \f$ a motion vector \f$ d_{I0,I1}(\mathbf{x}) \f$ is computed. + * If the forward backward error \f[ EP_{FB} = || d_{I0,I1} + d_{I1,I0} || \f] + * is larger than threshold given by this function then the motion vector will not be used by the following + * vector field interpolation. \f$ d_{I1,I0} \f$ denotes the backward flow. Note, the forward backward test + * will only be applied if the threshold > 0. This may results into a doubled runtime for the motion estimation. + * @see getForwardBackward, setGridStep + */ + CV_WRAP virtual void setForwardBackward(float val) = 0; + /** @copybrief setForwardBackward + @see setForwardBackward + */ + CV_WRAP virtual float getForwardBackward() const = 0; + //! @brief Size of the grid to spawn the motion vectors. + /** For each grid point a motion vector is computed. Some motion vectors will be removed due to the forwatd backward + * threshold (if set >0). The rest will be the base of the vector field interpolation. + * @see getForwardBackward, setGridStep + */ + CV_WRAP virtual Size getGridStep() const = 0; + /** @copybrief getGridStep + * @see getGridStep + */ + CV_WRAP virtual void setGridStep(Size val) = 0; + + //! @brief Interpolation used to compute the dense optical flow. + /** Two interpolation algorithms are supported + * - **INTERP_GEO** applies the fast geodesic interpolation, see @cite Geistert2016. + * - **INTERP_EPIC_RESIDUAL** applies the edge-preserving interpolation, see @cite Revaud2015,Geistert2016. + * @see ximgproc::EdgeAwareInterpolator, getInterpolation + */ + CV_WRAP virtual void setInterpolation(InterpolationType val) = 0; + /** @copybrief setInterpolation + * @see ximgproc::EdgeAwareInterpolator, setInterpolation + */ + CV_WRAP virtual InterpolationType getInterpolation() const = 0; + //! @brief see ximgproc::EdgeAwareInterpolator() K value. + /** K is a number of nearest-neighbor matches considered, when fitting a locally affine + * model. Usually it should be around 128. However, lower values would make the interpolation noticeably faster. + * @see ximgproc::EdgeAwareInterpolator, setEPICK + */ + CV_WRAP virtual int getEPICK() const = 0; + /** @copybrief getEPICK + * @see ximgproc::EdgeAwareInterpolator, getEPICK + */ + CV_WRAP virtual void setEPICK(int val) = 0; + //! @brief see ximgproc::EdgeAwareInterpolator() sigma value. + /** Sigma is a parameter defining how fast the weights decrease in the locally-weighted affine + * fitting. Higher values can help preserve fine details, lower values can help to get rid of noise in the + * output flow. + * @see ximgproc::EdgeAwareInterpolator, setEPICSigma + */ + CV_WRAP virtual float getEPICSigma() const = 0; + /** @copybrief getEPICSigma + * @see ximgproc::EdgeAwareInterpolator, getEPICSigma + */ + CV_WRAP virtual void setEPICSigma(float val) = 0; + //! @brief see ximgproc::EdgeAwareInterpolator() lambda value. + /** Lambda is a parameter defining the weight of the edge-aware term in geodesic distance, + * should be in the range of 0 to 1000. + * @see ximgproc::EdgeAwareInterpolator, setEPICSigma + */ + CV_WRAP virtual float getEPICLambda() const = 0; + /** @copybrief getEPICLambda + * @see ximgproc::EdgeAwareInterpolator, getEPICLambda + */ + CV_WRAP virtual void setEPICLambda(float val) = 0; + //! @brief see ximgproc::EdgeAwareInterpolator(). + /** Sets the respective fastGlobalSmootherFilter() parameter. + * @see ximgproc::EdgeAwareInterpolator, setFgsLambda + */ + CV_WRAP virtual float getFgsLambda() const = 0; + /** @copybrief getFgsLambda + * @see ximgproc::EdgeAwareInterpolator, ximgproc::fastGlobalSmootherFilter, getFgsLambda + */ + CV_WRAP virtual void setFgsLambda(float val) = 0; + //! @brief see ximgproc::EdgeAwareInterpolator(). + /** Sets the respective fastGlobalSmootherFilter() parameter. + * @see ximgproc::EdgeAwareInterpolator, ximgproc::fastGlobalSmootherFilter, setFgsSigma + */ + CV_WRAP virtual float getFgsSigma() const = 0; + /** @copybrief getFgsSigma + * @see ximgproc::EdgeAwareInterpolator, ximgproc::fastGlobalSmootherFilter, getFgsSigma + */ + CV_WRAP virtual void setFgsSigma(float val) = 0; + //! @brief enables ximgproc::fastGlobalSmootherFilter + /** + * @see getUsePostProc + */ + CV_WRAP virtual void setUsePostProc(bool val) = 0; + /** @copybrief setUsePostProc + * @see ximgproc::fastGlobalSmootherFilter, setUsePostProc + */ + CV_WRAP virtual bool getUsePostProc() const = 0; + //! @brief enables VariationalRefinement + /** + * @see getUseVariationalRefinement + */ + CV_WRAP virtual void setUseVariationalRefinement(bool val) = 0; + /** @copybrief setUseVariationalRefinement + * @see ximgproc::fastGlobalSmootherFilter, setUsePostProc + */ + CV_WRAP virtual bool getUseVariationalRefinement() const = 0; + //! @brief Parameter to tune the approximate size of the superpixel used for oversegmentation. + /** + * @see cv::ximgproc::createSuperpixelSLIC, cv::ximgproc::RICInterpolator + */ + CV_WRAP virtual void setRICSPSize(int val) = 0; + /** @copybrief setRICSPSize + * @see setRICSPSize + */ + CV_WRAP virtual int getRICSPSize() const = 0; + /** @brief Parameter to choose superpixel algorithm variant to use: + * - cv::ximgproc::SLICType SLIC segments image using a desired region_size (value: 100) + * - cv::ximgproc::SLICType SLICO will optimize using adaptive compactness factor (value: 101) + * - cv::ximgproc::SLICType MSLIC will optimize using manifold methods resulting in more content-sensitive superpixels (value: 102). + * @see cv::ximgproc::createSuperpixelSLIC, cv::ximgproc::RICInterpolator + */ + CV_WRAP virtual void setRICSLICType(int val) = 0; + /** @copybrief setRICSLICType + * @see setRICSLICType + */ + CV_WRAP virtual int getRICSLICType() const = 0; + //! @brief Creates instance of optflow::DenseRLOFOpticalFlow + /** + * @param rlofParam see optflow::RLOFOpticalFlowParameter + * @param forwardBackwardThreshold see setForwardBackward + * @param gridStep see setGridStep + * @param interp_type see setInterpolation + * @param epicK see setEPICK + * @param epicSigma see setEPICSigma + * @param epicLambda see setEPICLambda + * @param ricSPSize see setRICSPSize + * @param ricSLICType see setRICSLICType + * @param use_post_proc see setUsePostProc + * @param fgsLambda see setFgsLambda + * @param fgsSigma see setFgsSigma + * @param use_variational_refinement see setUseVariationalRefinement + */ + CV_WRAP static Ptr create( + Ptr rlofParam = Ptr(), + float forwardBackwardThreshold = 1.f, + Size gridStep = Size(6, 6), + InterpolationType interp_type = InterpolationType::INTERP_EPIC, + int epicK = 128, + float epicSigma = 0.05f, + float epicLambda = 999.0f, + int ricSPSize = 15, + int ricSLICType = 100, + bool use_post_proc = true, + float fgsLambda = 500.0f, + float fgsSigma = 1.5f, + bool use_variational_refinement = false); +}; + +/** @brief Class used for calculation sparse optical flow and feature tracking with robust local optical flow (RLOF) algorithms. +* +* The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014 + * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as +* proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019. +* The implementation is derived from optflow::calcOpticalFlowPyrLK(). +* +* For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details. +* Parameters have been described in @cite Senst2012, @cite Senst2013, @cite Senst2014 and @cite Senst2016. +* +* @note SIMD parallelization is only available when compiling with SSE4.1. +* @see optflow::calcOpticalFlowSparseRLOF(), optflow::RLOFOpticalFlowParameter +*/ +class CV_EXPORTS_W SparseRLOFOpticalFlow : public SparseOpticalFlow +{ +public: + /** @copydoc DenseRLOFOpticalFlow::setRLOFOpticalFlowParameter + */ + CV_WRAP virtual void setRLOFOpticalFlowParameter(Ptr val) = 0; + /** @copybrief setRLOFOpticalFlowParameter + * @see setRLOFOpticalFlowParameter + */ + CV_WRAP virtual Ptr getRLOFOpticalFlowParameter() const = 0; + //! @brief Threshold for the forward backward confidence check + /** For each feature point a motion vector \f$ d_{I0,I1}(\mathbf{x}) \f$ is computed. + * If the forward backward error \f[ EP_{FB} = || d_{I0,I1} + d_{I1,I0} || \f] + * is larger than threshold given by this function then the status will not be used by the following + * vector field interpolation. \f$ d_{I1,I0} \f$ denotes the backward flow. Note, the forward backward test + * will only be applied if the threshold > 0. This may results into a doubled runtime for the motion estimation. + * @see setForwardBackward + */ + CV_WRAP virtual void setForwardBackward(float val) = 0; + /** @copybrief setForwardBackward + * @see setForwardBackward + */ + CV_WRAP virtual float getForwardBackward() const = 0; + + //! @brief Creates instance of SparseRLOFOpticalFlow + /** + * @param rlofParam see setRLOFOpticalFlowParameter + * @param forwardBackwardThreshold see setForwardBackward + */ + CV_WRAP static Ptr create( + Ptr rlofParam = Ptr(), + float forwardBackwardThreshold = 1.f); + +}; + +/** @brief Fast dense optical flow computation based on robust local optical flow (RLOF) algorithms and sparse-to-dense interpolation scheme. + * + * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014 + * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as + * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019. + * The implementation is derived from optflow::calcOpticalFlowPyrLK(). + * + * The sparse-to-dense interpolation scheme allows for fast computation of dense optical flow using RLOF (see @cite Geistert2016). + * For this scheme the following steps are applied: + * -# motion vector seeded at a regular sampled grid are computed. The sparsity of this grid can be configured with setGridStep + * -# (optinally) errornous motion vectors are filter based on the forward backward confidence. The threshold can be configured + * with setForwardBackward. The filter is only applied if the threshold >0 but than the runtime is doubled due to the estimation + * of the backward flow. + * -# Vector field interpolation is applied to the motion vector set to obtain a dense vector field. + * + * @param I0 first 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType + * = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image. + * @param I1 second 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType + * = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image. + * @param flow computed flow image that has the same size as I0 and type CV_32FC2. + * @param rlofParam see optflow::RLOFOpticalFlowParameter + * @param forwardBackwardThreshold Threshold for the forward backward confidence check. + * For each grid point \f$ \mathbf{x} \f$ a motion vector \f$ d_{I0,I1}(\mathbf{x}) \f$ is computed. + * If the forward backward error \f[ EP_{FB} = || d_{I0,I1} + d_{I1,I0} || \f] + * is larger than threshold given by this function then the motion vector will not be used by the following + * vector field interpolation. \f$ d_{I1,I0} \f$ denotes the backward flow. Note, the forward backward test + * will only be applied if the threshold > 0. This may results into a doubled runtime for the motion estimation. + * @param gridStep Size of the grid to spawn the motion vectors. For each grid point a motion vector is computed. + * Some motion vectors will be removed due to the forwatd backward threshold (if set >0). The rest will be the + * base of the vector field interpolation. + * @param interp_type interpolation method used to compute the dense optical flow. Two interpolation algorithms are + * supported: + * - **INTERP_GEO** applies the fast geodesic interpolation, see @cite Geistert2016. + * - **INTERP_EPIC_RESIDUAL** applies the edge-preserving interpolation, see @cite Revaud2015,Geistert2016. + * @param epicK see ximgproc::EdgeAwareInterpolator sets the respective parameter. + * @param epicSigma see ximgproc::EdgeAwareInterpolator sets the respective parameter. + * @param epicLambda see ximgproc::EdgeAwareInterpolator sets the respective parameter. + * @param ricSPSize see ximgproc::RICInterpolator sets the respective parameter. + * @param ricSLICType see ximgproc::RICInterpolator sets the respective parameter. + * @param use_post_proc enables ximgproc::fastGlobalSmootherFilter() parameter. + * @param fgsLambda sets the respective ximgproc::fastGlobalSmootherFilter() parameter. + * @param fgsSigma sets the respective ximgproc::fastGlobalSmootherFilter() parameter. + * @param use_variational_refinement enables VariationalRefinement + * + * Parameters have been described in @cite Senst2012, @cite Senst2013, @cite Senst2014, @cite Senst2016. + * For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details. + * @note If the grid size is set to (1,1) and the forward backward threshold <= 0 that the dense optical flow field is purely + * computed with the RLOF. + * + * @note SIMD parallelization is only available when compiling with SSE4.1. + * + * @sa optflow::DenseRLOFOpticalFlow, optflow::RLOFOpticalFlowParameter +*/ +CV_EXPORTS_W void calcOpticalFlowDenseRLOF(InputArray I0, InputArray I1, InputOutputArray flow, + Ptr rlofParam = Ptr(), + float forwardBackwardThreshold = 0, Size gridStep = Size(6, 6), + InterpolationType interp_type = InterpolationType::INTERP_EPIC, + int epicK = 128, float epicSigma = 0.05f, float epicLambda = 100.f, + int ricSPSize = 15, int ricSLICType = 100, + bool use_post_proc = true, float fgsLambda = 500.0f, float fgsSigma = 1.5f, + bool use_variational_refinement = false); + +/** @brief Calculates fast optical flow for a sparse feature set using the robust local optical flow (RLOF) similar +* to optflow::calcOpticalFlowPyrLK(). +* +* The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014 + * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as +* proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019. +* The implementation is derived from optflow::calcOpticalFlowPyrLK(). +* +* @param prevImg first 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType +* = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image. +* @param nextImg second 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType +* = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image. +* @param prevPts vector of 2D points for which the flow needs to be found; point coordinates must be single-precision +* floating-point numbers. +* @param nextPts output vector of 2D points (with single-precision floating-point coordinates) containing the calculated +* new positions of input features in the second image; when optflow::RLOFOpticalFlowParameter::useInitialFlow variable is true the vector must +* have the same size as in the input and contain the initialization point correspondences. +* @param status output status vector (of unsigned chars); each element of the vector is set to 1 if the flow for the +* corresponding features has passed the forward backward check. +* @param err output vector of errors; each element of the vector is set to the forward backward error for the corresponding feature. +* @param rlofParam see optflow::RLOFOpticalFlowParameter +* @param forwardBackwardThreshold Threshold for the forward backward confidence check. If forewardBackwardThreshold <=0 the forward +* +* @note SIMD parallelization is only available when compiling with SSE4.1. +* +* Parameters have been described in @cite Senst2012, @cite Senst2013, @cite Senst2014 and @cite Senst2016. +* For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details. +*/ +CV_EXPORTS_W void calcOpticalFlowSparseRLOF(InputArray prevImg, InputArray nextImg, + InputArray prevPts, InputOutputArray nextPts, + OutputArray status, OutputArray err, + Ptr rlofParam = Ptr(), + float forwardBackwardThreshold = 0); + +//! Additional interface to the Dense RLOF algorithm - optflow::calcOpticalFlowDenseRLOF() +CV_EXPORTS_W Ptr createOptFlow_DenseRLOF(); + +//! Additional interface to the Sparse RLOF algorithm - optflow::calcOpticalFlowSparseRLOF() +CV_EXPORTS_W Ptr createOptFlow_SparseRLOF(); +//! @} + +} // namespace +} // namespace +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/sparse_matching_gpc.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/sparse_matching_gpc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5256534bb96684ff0d72dfdadbdba74e80910c04 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/optflow/sparse_matching_gpc.hpp @@ -0,0 +1,372 @@ +/* +By downloading, copying, installing or using the software you agree to this +license. If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Copyright (C) 2016, OpenCV Foundation, all rights reserved. +Third party copyrights are property of their respective owners. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are +disclaimed. In no event shall copyright holders or contributors be liable for +any direct, indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. +*/ + +/** + * @file sparse_matching_gpc.hpp + * @author Vladislav Samsonov + * @brief Implementation of the Global Patch Collider. + * + * Implementation of the Global Patch Collider algorithm from the following paper: + * http://research.microsoft.com/en-us/um/people/pkohli/papers/wfrik_cvpr2016.pdf + * + * @cite Wang_2016_CVPR + */ + +#ifndef __OPENCV_OPTFLOW_SPARSE_MATCHING_GPC_HPP__ +#define __OPENCV_OPTFLOW_SPARSE_MATCHING_GPC_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" + +namespace cv +{ +namespace optflow +{ + +//! @addtogroup optflow +//! @{ + +struct CV_EXPORTS_W GPCPatchDescriptor +{ + static const unsigned nFeatures = 18; //!< number of features in a patch descriptor + Vec< double, nFeatures > feature; + + double dot( const Vec< double, nFeatures > &coef ) const; + + void markAsSeparated() { feature[0] = std::numeric_limits< double >::quiet_NaN(); } + + bool isSeparated() const { return cvIsNaN( feature[0] ) != 0; } +}; + +struct CV_EXPORTS_W GPCPatchSample +{ + GPCPatchDescriptor ref; + GPCPatchDescriptor pos; + GPCPatchDescriptor neg; + + void getDirections( bool &refdir, bool &posdir, bool &negdir, const Vec< double, GPCPatchDescriptor::nFeatures > &coef, double rhs ) const; +}; + +typedef std::vector< GPCPatchSample > GPCSamplesVector; + +/** @brief Descriptor types for the Global Patch Collider. + */ +enum GPCDescType +{ + GPC_DESCRIPTOR_DCT = 0, //!< Better quality but slow + GPC_DESCRIPTOR_WHT //!< Worse quality but much faster +}; + +/** @brief Class encapsulating training samples. + */ +class CV_EXPORTS_W GPCTrainingSamples +{ +private: + GPCSamplesVector samples; + int descriptorType; + +public: + /** @brief This function can be used to extract samples from a pair of images and a ground truth flow. + * Sizes of all the provided vectors must be equal. + */ + static Ptr< GPCTrainingSamples > create( const std::vector< String > &imagesFrom, const std::vector< String > &imagesTo, + const std::vector< String > >, int descriptorType ); + + static Ptr< GPCTrainingSamples > create( InputArrayOfArrays imagesFrom, InputArrayOfArrays imagesTo, InputArrayOfArrays gt, + int descriptorType ); + + size_t size() const { return samples.size(); } + + int type() const { return descriptorType; } + + operator GPCSamplesVector &() { return samples; } +}; + +/** @brief Class encapsulating training parameters. + */ +struct GPCTrainingParams +{ + unsigned maxTreeDepth; //!< Maximum tree depth to stop partitioning. + int minNumberOfSamples; //!< Minimum number of samples in the node to stop partitioning. + int descriptorType; //!< Type of descriptors to use. + bool printProgress; //!< Print progress to stdout. + + GPCTrainingParams( unsigned _maxTreeDepth = 20, int _minNumberOfSamples = 3, GPCDescType _descriptorType = GPC_DESCRIPTOR_DCT, + bool _printProgress = true ) + : maxTreeDepth( _maxTreeDepth ), minNumberOfSamples( _minNumberOfSamples ), descriptorType( _descriptorType ), + printProgress( _printProgress ) + { + CV_Assert( check() ); + } + + bool check() const { return maxTreeDepth > 1 && minNumberOfSamples > 1; } +}; + +/** @brief Class encapsulating matching parameters. + */ +struct GPCMatchingParams +{ + bool useOpenCL; //!< Whether to use OpenCL to speed up the matching. + + GPCMatchingParams( bool _useOpenCL = false ) : useOpenCL( _useOpenCL ) {} + + GPCMatchingParams( const GPCMatchingParams ¶ms ) : useOpenCL( params.useOpenCL ) {} +}; + +/** @brief Class for individual tree. + */ +class CV_EXPORTS_W GPCTree : public Algorithm +{ +public: + struct Node + { + Vec< double, GPCPatchDescriptor::nFeatures > coef; //!< Hyperplane coefficients + double rhs; //!< Bias term of the hyperplane + unsigned left; + unsigned right; + + bool operator==( const Node &n ) const { return coef == n.coef && rhs == n.rhs && left == n.left && right == n.right; } + }; + +private: + typedef GPCSamplesVector::iterator SIter; + + std::vector< Node > nodes; + GPCTrainingParams params; + + bool trainNode( size_t nodeId, SIter begin, SIter end, unsigned depth ); + +public: + void train( GPCTrainingSamples &samples, const GPCTrainingParams params = GPCTrainingParams() ); + + void write( FileStorage &fs ) const CV_OVERRIDE; + + void read( const FileNode &fn ) CV_OVERRIDE; + + unsigned findLeafForPatch( const GPCPatchDescriptor &descr ) const; + + static Ptr< GPCTree > create() { return makePtr< GPCTree >(); } + + bool operator==( const GPCTree &t ) const { return nodes == t.nodes; } + + int getDescriptorType() const { return params.descriptorType; } +}; + +template < int T > class GPCForest : public Algorithm +{ +private: + struct Trail + { + unsigned leaf[T]; //!< Inside which leaf of the tree 0..T the patch fell? + Point2i coord; //!< Patch coordinates. + + bool operator==( const Trail &trail ) const { return memcmp( leaf, trail.leaf, sizeof( leaf ) ) == 0; } + + bool operator<( const Trail &trail ) const + { + for ( int i = 0; i < T - 1; ++i ) + if ( leaf[i] != trail.leaf[i] ) + return leaf[i] < trail.leaf[i]; + return leaf[T - 1] < trail.leaf[T - 1]; + } + }; + + class ParallelTrailsFilling : public ParallelLoopBody + { + private: + const GPCForest *forest; + const std::vector< GPCPatchDescriptor > *descr; + std::vector< Trail > *trails; + + ParallelTrailsFilling &operator=( const ParallelTrailsFilling & ); + + public: + ParallelTrailsFilling( const GPCForest *_forest, const std::vector< GPCPatchDescriptor > *_descr, std::vector< Trail > *_trails ) + : forest( _forest ), descr( _descr ), trails( _trails ){}; + + void operator()( const Range &range ) const CV_OVERRIDE + { + for ( int t = range.start; t < range.end; ++t ) + for ( size_t i = 0; i < descr->size(); ++i ) + trails->at( i ).leaf[t] = forest->tree[t].findLeafForPatch( descr->at( i ) ); + } + }; + + GPCTree tree[T]; + +public: + /** @brief Train the forest using one sample set for every tree. + * Please, consider using the next method instead of this one for better quality. + */ + void train( GPCTrainingSamples &samples, const GPCTrainingParams params = GPCTrainingParams() ) + { + for ( int i = 0; i < T; ++i ) + tree[i].train( samples, params ); + } + + /** @brief Train the forest using individual samples for each tree. + * It is generally better to use this instead of the first method. + */ + void train( const std::vector< String > &imagesFrom, const std::vector< String > &imagesTo, const std::vector< String > >, + const GPCTrainingParams params = GPCTrainingParams() ) + { + for ( int i = 0; i < T; ++i ) + { + Ptr< GPCTrainingSamples > samples = + GPCTrainingSamples::create( imagesFrom, imagesTo, gt, params.descriptorType ); // Create training set for the tree + tree[i].train( *samples, params ); + } + } + + void train( InputArrayOfArrays imagesFrom, InputArrayOfArrays imagesTo, InputArrayOfArrays gt, + const GPCTrainingParams params = GPCTrainingParams() ) + { + for ( int i = 0; i < T; ++i ) + { + Ptr< GPCTrainingSamples > samples = + GPCTrainingSamples::create( imagesFrom, imagesTo, gt, params.descriptorType ); // Create training set for the tree + tree[i].train( *samples, params ); + } + } + + void write( FileStorage &fs ) const CV_OVERRIDE + { + fs << "ntrees" << T << "trees" + << "["; + for ( int i = 0; i < T; ++i ) + { + fs << "{"; + tree[i].write( fs ); + fs << "}"; + } + fs << "]"; + } + + void read( const FileNode &fn ) CV_OVERRIDE + { + CV_Assert( T <= (int)fn["ntrees"] ); + FileNodeIterator it = fn["trees"].begin(); + for ( int i = 0; i < T; ++i, ++it ) + tree[i].read( *it ); + } + + /** @brief Find correspondences between two images. + * @param[in] imgFrom First image in a sequence. + * @param[in] imgTo Second image in a sequence. + * @param[out] corr Output vector with pairs of corresponding points. + * @param[in] params Additional matching parameters for fine-tuning. + */ + void findCorrespondences( InputArray imgFrom, InputArray imgTo, std::vector< std::pair< Point2i, Point2i > > &corr, + const GPCMatchingParams params = GPCMatchingParams() ) const; + + static Ptr< GPCForest > create() { return makePtr< GPCForest >(); } +}; + +class CV_EXPORTS_W GPCDetails +{ +public: + static void dropOutliers( std::vector< std::pair< Point2i, Point2i > > &corr ); + + static void getAllDescriptorsForImage( const Mat *imgCh, std::vector< GPCPatchDescriptor > &descr, const GPCMatchingParams &mp, + int type ); + + static void getCoordinatesFromIndex( size_t index, Size sz, int &x, int &y ); +}; + +template < int T > +void GPCForest< T >::findCorrespondences( InputArray imgFrom, InputArray imgTo, std::vector< std::pair< Point2i, Point2i > > &corr, + const GPCMatchingParams params ) const +{ + CV_Assert( imgFrom.channels() == 3 ); + CV_Assert( imgTo.channels() == 3 ); + + Mat from, to; + imgFrom.getMat().convertTo( from, CV_32FC3 ); + imgTo.getMat().convertTo( to, CV_32FC3 ); + cvtColor( from, from, COLOR_BGR2YCrCb ); + cvtColor( to, to, COLOR_BGR2YCrCb ); + + Mat fromCh[3], toCh[3]; + split( from, fromCh ); + split( to, toCh ); + + std::vector< GPCPatchDescriptor > descr; + GPCDetails::getAllDescriptorsForImage( fromCh, descr, params, tree[0].getDescriptorType() ); + std::vector< Trail > trailsFrom( descr.size() ), trailsTo( descr.size() ); + + for ( size_t i = 0; i < descr.size(); ++i ) + GPCDetails::getCoordinatesFromIndex( i, from.size(), trailsFrom[i].coord.x, trailsFrom[i].coord.y ); + parallel_for_( Range( 0, T ), ParallelTrailsFilling( this, &descr, &trailsFrom ) ); + + descr.clear(); + GPCDetails::getAllDescriptorsForImage( toCh, descr, params, tree[0].getDescriptorType() ); + + for ( size_t i = 0; i < descr.size(); ++i ) + GPCDetails::getCoordinatesFromIndex( i, to.size(), trailsTo[i].coord.x, trailsTo[i].coord.y ); + parallel_for_( Range( 0, T ), ParallelTrailsFilling( this, &descr, &trailsTo ) ); + + std::sort( trailsFrom.begin(), trailsFrom.end() ); + std::sort( trailsTo.begin(), trailsTo.end() ); + + for ( size_t i = 0; i < trailsFrom.size(); ++i ) + { + bool uniq = true; + while ( i + 1 < trailsFrom.size() && trailsFrom[i] == trailsFrom[i + 1] ) + ++i, uniq = false; + if ( uniq ) + { + typename std::vector< Trail >::const_iterator lb = std::lower_bound( trailsTo.begin(), trailsTo.end(), trailsFrom[i] ); + if ( lb != trailsTo.end() && *lb == trailsFrom[i] && ( ( lb + 1 ) == trailsTo.end() || !( *lb == *( lb + 1 ) ) ) ) + corr.push_back( std::make_pair( trailsFrom[i].coord, lb->coord ) ); + } + } + + GPCDetails::dropOutliers( corr ); +} + +//! @} + +} // namespace optflow + +CV_EXPORTS void write( FileStorage &fs, const String &name, const optflow::GPCTree::Node &node ); + +CV_EXPORTS void read( const FileNode &fn, optflow::GPCTree::Node &node, optflow::GPCTree::Node ); +} // namespace cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0e15e71ed67b902faa7f9367321c212ec98a85c5 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping.hpp @@ -0,0 +1,61 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#include "opencv2/phase_unwrapping/phase_unwrapping.hpp" +#include "opencv2/phase_unwrapping/histogramphaseunwrapping.hpp" + +/** @defgroup phase_unwrapping Phase Unwrapping API + +Two-dimensional phase unwrapping is found in different applications like terrain elevation estimation +in synthetic aperture radar (SAR), field mapping in magnetic resonance imaging or as a way of finding +corresponding pixels in structured light reconstruction with sinusoidal patterns. + +Given a phase map, wrapped between [-pi; pi], phase unwrapping aims at finding the "true" phase map +by adding the right number of 2*pi to each pixel. + +The problem is straightforward for perfect wrapped phase map, but real data are usually not noise-free. +Among the different algorithms that were developed, quality-guided phase unwrapping methods are fast +and efficient. They follow a path that unwraps high quality pixels first, +avoiding error propagation from the start. + +In this module, a quality-guided phase unwrapping is implemented following the approach described in @cite histogramUnwrapping . + +*/ \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e75d8896ddc2848ebcd95058d6d45d358fa87ab9 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping/histogramphaseunwrapping.hpp @@ -0,0 +1,107 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#ifndef __OPENCV_HISTOGRAM_PHASE_UNWRAPPING_HPP__ +#define __OPENCV_HISTOGRAM_PHASE_UNWRAPPING_HPP__ + +#include "opencv2/core.hpp" +#include +#include "opencv2/phase_unwrapping/phase_unwrapping.hpp" + +namespace cv { +namespace phase_unwrapping { +//! @addtogroup phase_unwrapping +//! @{ + + /** @brief Class implementing two-dimensional phase unwrapping based on @cite histogramUnwrapping + * This algorithm belongs to the quality-guided phase unwrapping methods. + * First, it computes a reliability map from second differences between a pixel and its eight neighbours. + * Reliability values lie between 0 and 16*pi*pi. Then, this reliability map is used to compute + * the reliabilities of "edges". An edge is an entity defined by two pixels that are connected + * horizontally or vertically. Its reliability is found by adding the the reliabilities of the + * two pixels connected through it. Edges are sorted in a histogram based on their reliability values. + * This histogram is then used to unwrap pixels, starting from the highest quality pixel. + + * The wrapped phase map and the unwrapped result are stored in CV_32FC1 Mat. + */ +class CV_EXPORTS_W HistogramPhaseUnwrapping : public PhaseUnwrapping +{ + +public: + /** + * @brief Parameters of phaseUnwrapping constructor. + + * @param width Phase map width. + * @param height Phase map height. + * @param histThresh Bins in the histogram are not of equal size. Default value is 3*pi*pi. The one before "histThresh" value are smaller. + * @param nbrOfSmallBins Number of bins between 0 and "histThresh". Default value is 10. + * @param nbrOfLargeBins Number of bins between "histThresh" and 32*pi*pi (highest edge reliability value). Default value is 5. + */ + struct CV_EXPORTS Params + { + Params(); + int width; + int height; + float histThresh; + int nbrOfSmallBins; + int nbrOfLargeBins; + }; + /** + * @brief Constructor + + * @param parameters HistogramPhaseUnwrapping parameters HistogramPhaseUnwrapping::Params: width,height of the phase map and histogram characteristics. + */ + static Ptr create( const HistogramPhaseUnwrapping::Params ¶meters = + HistogramPhaseUnwrapping::Params() ); + + /** + * @brief Get the reliability map computed from the wrapped phase map. + + * @param reliabilityMap Image where the reliability map is stored. + */ + CV_WRAP + virtual void getInverseReliabilityMap( OutputArray reliabilityMap ) = 0; +}; + +//! @} +} +} +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping/phase_unwrapping.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping/phase_unwrapping.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5b5cb5100bac9e92afac9e5f146033185b77c8ef --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/phase_unwrapping/phase_unwrapping.hpp @@ -0,0 +1,74 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// + // + // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2015, OpenCV Foundation, all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. + // + //M*/ + +#ifndef __OPENCV_PHASE_UNWRAPPING_HPP__ +#define __OPENCV_PHASE_UNWRAPPING_HPP__ + +#include "opencv2/core.hpp" + +namespace cv { +namespace phase_unwrapping { +//! @addtogroup phase_unwrapping +//! @{ + + /** + @brief Abstract base class for phase unwrapping. + */ +class CV_EXPORTS_W PhaseUnwrapping : public virtual Algorithm +{ +public: + /** + * @brief Unwraps a 2D phase map. + + * @param wrappedPhaseMap The wrapped phase map that needs to be unwrapped. + * @param unwrappedPhaseMap The unwrapped phase map. + * @param shadowMask Optional parameter used when some pixels do not hold any phase information in the wrapped phase map. + */ + CV_WRAP + virtual void unwrapPhaseMap( InputArray wrappedPhaseMap, OutputArray unwrappedPhaseMap, + InputArray shadowMask = noArray() ) = 0; + +}; + +//! @} +} +} +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c2e89a3858f060b28582b0944f5996e031d3b763 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo.hpp @@ -0,0 +1,858 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_PHOTO_HPP +#define OPENCV_PHOTO_HPP + +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" + +/** +@defgroup photo Computational Photography + +This module includes photo processing algorithms +@{ + @defgroup photo_inpaint Inpainting + @defgroup photo_denoise Denoising + @defgroup photo_hdr HDR imaging + +This section describes high dynamic range imaging algorithms namely tonemapping, exposure alignment, +camera calibration with multiple exposures and exposure fusion. + + @defgroup photo_decolor Contrast Preserving Decolorization + +Useful links: + +http://www.cse.cuhk.edu.hk/leojia/projects/color2gray/index.html + + @defgroup photo_clone Seamless Cloning + +Useful links: + +https://www.learnopencv.com/seamless-cloning-using-opencv-python-cpp + + @defgroup photo_render Non-Photorealistic Rendering + +Useful links: + +http://www.inf.ufrgs.br/~eslgastal/DomainTransform + +https://www.learnopencv.com/non-photorealistic-rendering-using-opencv-python-c/ + + @defgroup photo_c C API +@} + */ + +namespace cv +{ + +//! @addtogroup photo +//! @{ + +//! @addtogroup photo_inpaint +//! @{ +//! the inpainting algorithm +enum +{ + INPAINT_NS = 0, //!< Use Navier-Stokes based method + INPAINT_TELEA = 1 //!< Use the algorithm proposed by Alexandru Telea @cite Telea04 +}; + +/** @brief Restores the selected region in an image using the region neighborhood. + +@param src Input 8-bit, 16-bit unsigned or 32-bit float 1-channel or 8-bit 3-channel image. +@param inpaintMask Inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that +needs to be inpainted. +@param dst Output image with the same size and type as src . +@param inpaintRadius Radius of a circular neighborhood of each point inpainted that is considered +by the algorithm. +@param flags Inpainting method that could be cv::INPAINT_NS or cv::INPAINT_TELEA + +The function reconstructs the selected image area from the pixel near the area boundary. The +function may be used to remove dust and scratches from a scanned photo, or to remove undesirable +objects from still images or video. See for more details. + +@note + - An example using the inpainting technique can be found at + opencv_source_code/samples/cpp/inpaint.cpp + - (Python) An example using the inpainting technique can be found at + opencv_source_code/samples/python/inpaint.py + */ +CV_EXPORTS_W void inpaint( InputArray src, InputArray inpaintMask, + OutputArray dst, double inpaintRadius, int flags ); + +//! @} photo_inpaint + +//! @addtogroup photo_denoise +//! @{ + +/** @brief Perform image denoising using Non-local Means Denoising algorithm + with several computational +optimizations. Noise expected to be a gaussian white noise + +@param src Input 8-bit 1-channel, 2-channel, 3-channel or 4-channel image. +@param dst Output image with the same size and type as src . +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength. Big h value perfectly removes noise but also +removes image details, smaller h value preserves details but also preserves some noise + +This function expected to be applied to grayscale images. For colored images look at +fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored +image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting +image to CIELAB colorspace and then separately denoise L and AB components with different h +parameter. + */ +CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, float h = 3, + int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Perform image denoising using Non-local Means Denoising algorithm + with several computational +optimizations. Noise expected to be a gaussian white noise + +@param src Input 8-bit or 16-bit (only with NORM_L1) 1-channel, +2-channel, 3-channel or 4-channel image. +@param dst Output image with the same size and type as src . +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Array of parameters regulating filter strength, either one +parameter applied to all channels or one per channel in dst. Big h value +perfectly removes noise but also removes image details, smaller h +value preserves details but also preserves some noise +@param normType Type of norm used for weight calculation. Can be either NORM_L2 or NORM_L1 + +This function expected to be applied to grayscale images. For colored images look at +fastNlMeansDenoisingColored. Advanced usage of this functions can be manual denoising of colored +image in different colorspaces. Such approach is used in fastNlMeansDenoisingColored by converting +image to CIELAB colorspace and then separately denoise L and AB components with different h +parameter. + */ +CV_EXPORTS_W void fastNlMeansDenoising( InputArray src, OutputArray dst, + const std::vector& h, + int templateWindowSize = 7, int searchWindowSize = 21, + int normType = NORM_L2); + +/** @brief Modification of fastNlMeansDenoising function for colored images + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src . +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength for luminance component. Bigger h value perfectly +removes noise but also removes image details, smaller h value preserves details but also preserves +some noise +@param hColor The same as h but for color components. For most images value equals 10 +will be enough to remove colored noise and do not distort colors + +The function converts image to CIELAB colorspace and then separately denoise L and AB components +with given h parameters using fastNlMeansDenoising function. + */ +CV_EXPORTS_W void fastNlMeansDenoisingColored( InputArray src, OutputArray dst, + float h = 3, float hColor = 3, + int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Modification of fastNlMeansDenoising function for images sequence where consecutive images have been +captured in small period of time. For example video. This version of the function is for grayscale +images or for manual manipulation with colorspaces. For more details see + + +@param srcImgs Input 8-bit 1-channel, 2-channel, 3-channel or +4-channel images sequence. All images should have the same type and +size. +@param imgToDenoiseIndex Target image to denoise index in srcImgs sequence +@param temporalWindowSize Number of surrounding images to use for target image denoising. Should +be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to +imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise +srcImgs[imgToDenoiseIndex] image. +@param dst Output image with the same size and type as srcImgs images. +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength. Bigger h value +perfectly removes noise but also removes image details, smaller h +value preserves details but also preserves some noise + */ +CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst, + int imgToDenoiseIndex, int temporalWindowSize, + float h = 3, int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Modification of fastNlMeansDenoising function for images sequence where consecutive images have been +captured in small period of time. For example video. This version of the function is for grayscale +images or for manual manipulation with colorspaces. For more details see + + +@param srcImgs Input 8-bit or 16-bit (only with NORM_L1) 1-channel, +2-channel, 3-channel or 4-channel images sequence. All images should +have the same type and size. +@param imgToDenoiseIndex Target image to denoise index in srcImgs sequence +@param temporalWindowSize Number of surrounding images to use for target image denoising. Should +be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to +imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise +srcImgs[imgToDenoiseIndex] image. +@param dst Output image with the same size and type as srcImgs images. +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Array of parameters regulating filter strength, either one +parameter applied to all channels or one per channel in dst. Big h value +perfectly removes noise but also removes image details, smaller h +value preserves details but also preserves some noise +@param normType Type of norm used for weight calculation. Can be either NORM_L2 or NORM_L1 + */ +CV_EXPORTS_W void fastNlMeansDenoisingMulti( InputArrayOfArrays srcImgs, OutputArray dst, + int imgToDenoiseIndex, int temporalWindowSize, + const std::vector& h, + int templateWindowSize = 7, int searchWindowSize = 21, + int normType = NORM_L2); + +/** @brief Modification of fastNlMeansDenoisingMulti function for colored images sequences + +@param srcImgs Input 8-bit 3-channel images sequence. All images should have the same type and +size. +@param imgToDenoiseIndex Target image to denoise index in srcImgs sequence +@param temporalWindowSize Number of surrounding images to use for target image denoising. Should +be odd. Images from imgToDenoiseIndex - temporalWindowSize / 2 to +imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs will be used to denoise +srcImgs[imgToDenoiseIndex] image. +@param dst Output image with the same size and type as srcImgs images. +@param templateWindowSize Size in pixels of the template patch that is used to compute weights. +Should be odd. Recommended value 7 pixels +@param searchWindowSize Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater +denoising time. Recommended value 21 pixels +@param h Parameter regulating filter strength for luminance component. Bigger h value perfectly +removes noise but also removes image details, smaller h value preserves details but also preserves +some noise. +@param hColor The same as h but for color components. + +The function converts images to CIELAB colorspace and then separately denoise L and AB components +with given h parameters using fastNlMeansDenoisingMulti function. + */ +CV_EXPORTS_W void fastNlMeansDenoisingColoredMulti( InputArrayOfArrays srcImgs, OutputArray dst, + int imgToDenoiseIndex, int temporalWindowSize, + float h = 3, float hColor = 3, + int templateWindowSize = 7, int searchWindowSize = 21); + +/** @brief Primal-dual algorithm is an algorithm for solving special types of variational problems (that is, +finding a function to minimize some functional). As the image denoising, in particular, may be seen +as the variational problem, primal-dual algorithm then can be used to perform denoising and this is +exactly what is implemented. + +It should be noted, that this implementation was taken from the July 2013 blog entry +@cite MA13 , which also contained (slightly more general) ready-to-use source code on Python. +Subsequently, that code was rewritten on C++ with the usage of openCV by Vadim Pisarevsky at the end +of July 2013 and finally it was slightly adapted by later authors. + +Although the thorough discussion and justification of the algorithm involved may be found in +@cite ChambolleEtAl, it might make sense to skim over it here, following @cite MA13 . To begin +with, we consider the 1-byte gray-level images as the functions from the rectangular domain of +pixels (it may be seen as set +\f$\left\{(x,y)\in\mathbb{N}\times\mathbb{N}\mid 1\leq x\leq n,\;1\leq y\leq m\right\}\f$ for some +\f$m,\;n\in\mathbb{N}\f$) into \f$\{0,1,\dots,255\}\f$. We shall denote the noised images as \f$f_i\f$ and with +this view, given some image \f$x\f$ of the same size, we may measure how bad it is by the formula + +\f[\left\|\left\|\nabla x\right\|\right\| + \lambda\sum_i\left\|\left\|x-f_i\right\|\right\|\f] + +\f$\|\|\cdot\|\|\f$ here denotes \f$L_2\f$-norm and as you see, the first addend states that we want our +image to be smooth (ideally, having zero gradient, thus being constant) and the second states that +we want our result to be close to the observations we've got. If we treat \f$x\f$ as a function, this is +exactly the functional what we seek to minimize and here the Primal-Dual algorithm comes into play. + +@param observations This array should contain one or more noised versions of the image that is to +be restored. +@param result Here the denoised image will be stored. There is no need to do pre-allocation of +storage space, as it will be automatically allocated, if necessary. +@param lambda Corresponds to \f$\lambda\f$ in the formulas above. As it is enlarged, the smooth +(blurred) images are treated more favorably than detailed (but maybe more noised) ones. Roughly +speaking, as it becomes smaller, the result will be more blur but more sever outliers will be +removed. +@param niters Number of iterations that the algorithm will run. Of course, as more iterations as +better, but it is hard to quantitatively refine this statement, so just use the default and +increase it if the results are poor. + */ +CV_EXPORTS_W void denoise_TVL1(const std::vector& observations,Mat& result, double lambda=1.0, int niters=30); + +//! @} photo_denoise + +//! @addtogroup photo_hdr +//! @{ + +enum { LDR_SIZE = 256 }; + +/** @brief Base class for tonemapping algorithms - tools that are used to map HDR image to 8-bit range. + */ +class CV_EXPORTS_W Tonemap : public Algorithm +{ +public: + /** @brief Tonemaps image + + @param src source image - CV_32FC3 Mat (float 32 bits 3 channels) + @param dst destination image - CV_32FC3 Mat with values in [0, 1] range + */ + CV_WRAP virtual void process(InputArray src, OutputArray dst) = 0; + + CV_WRAP virtual float getGamma() const = 0; + CV_WRAP virtual void setGamma(float gamma) = 0; +}; + +/** @brief Creates simple linear mapper with gamma correction + +@param gamma positive value for gamma correction. Gamma value of 1.0 implies no correction, gamma +equal to 2.2f is suitable for most displays. +Generally gamma \> 1 brightens the image and gamma \< 1 darkens it. + */ +CV_EXPORTS_W Ptr createTonemap(float gamma = 1.0f); + +/** @brief Adaptive logarithmic mapping is a fast global tonemapping algorithm that scales the image in +logarithmic domain. + +Since it's a global operator the same function is applied to all the pixels, it is controlled by the +bias parameter. + +Optional saturation enhancement is possible as described in @cite FL02 . + +For more information see @cite DM03 . + */ +class CV_EXPORTS_W TonemapDrago : public Tonemap +{ +public: + + CV_WRAP virtual float getSaturation() const = 0; + CV_WRAP virtual void setSaturation(float saturation) = 0; + + CV_WRAP virtual float getBias() const = 0; + CV_WRAP virtual void setBias(float bias) = 0; +}; + +/** @brief Creates TonemapDrago object + +@param gamma gamma value for gamma correction. See createTonemap +@param saturation positive saturation enhancement value. 1.0 preserves saturation, values greater +than 1 increase saturation and values less than 1 decrease it. +@param bias value for bias function in [0, 1] range. Values from 0.7 to 0.9 usually give best +results, default value is 0.85. + */ +CV_EXPORTS_W Ptr createTonemapDrago(float gamma = 1.0f, float saturation = 1.0f, float bias = 0.85f); + + +/** @brief This is a global tonemapping operator that models human visual system. + +Mapping function is controlled by adaptation parameter, that is computed using light adaptation and +color adaptation. + +For more information see @cite RD05 . + */ +class CV_EXPORTS_W TonemapReinhard : public Tonemap +{ +public: + CV_WRAP virtual float getIntensity() const = 0; + CV_WRAP virtual void setIntensity(float intensity) = 0; + + CV_WRAP virtual float getLightAdaptation() const = 0; + CV_WRAP virtual void setLightAdaptation(float light_adapt) = 0; + + CV_WRAP virtual float getColorAdaptation() const = 0; + CV_WRAP virtual void setColorAdaptation(float color_adapt) = 0; +}; + +/** @brief Creates TonemapReinhard object + +@param gamma gamma value for gamma correction. See createTonemap +@param intensity result intensity in [-8, 8] range. Greater intensity produces brighter results. +@param light_adapt light adaptation in [0, 1] range. If 1 adaptation is based only on pixel +value, if 0 it's global, otherwise it's a weighted mean of this two cases. +@param color_adapt chromatic adaptation in [0, 1] range. If 1 channels are treated independently, +if 0 adaptation level is the same for each channel. + */ +CV_EXPORTS_W Ptr +createTonemapReinhard(float gamma = 1.0f, float intensity = 0.0f, float light_adapt = 1.0f, float color_adapt = 0.0f); + +/** @brief This algorithm transforms image to contrast using gradients on all levels of gaussian pyramid, +transforms contrast values to HVS response and scales the response. After this the image is +reconstructed from new contrast values. + +For more information see @cite MM06 . + */ +class CV_EXPORTS_W TonemapMantiuk : public Tonemap +{ +public: + CV_WRAP virtual float getScale() const = 0; + CV_WRAP virtual void setScale(float scale) = 0; + + CV_WRAP virtual float getSaturation() const = 0; + CV_WRAP virtual void setSaturation(float saturation) = 0; +}; + +/** @brief Creates TonemapMantiuk object + +@param gamma gamma value for gamma correction. See createTonemap +@param scale contrast scale factor. HVS response is multiplied by this parameter, thus compressing +dynamic range. Values from 0.6 to 0.9 produce best results. +@param saturation saturation enhancement value. See createTonemapDrago + */ +CV_EXPORTS_W Ptr +createTonemapMantiuk(float gamma = 1.0f, float scale = 0.7f, float saturation = 1.0f); + +/** @brief The base class for algorithms that align images of the same scene with different exposures + */ +class CV_EXPORTS_W AlignExposures : public Algorithm +{ +public: + /** @brief Aligns images + + @param src vector of input images + @param dst vector of aligned images + @param times vector of exposure time values for each image + @param response 256x1 matrix with inverse camera response function for each pixel value, it should + have the same number of channels as images. + */ + CV_WRAP virtual void process(InputArrayOfArrays src, std::vector& dst, + InputArray times, InputArray response) = 0; +}; + +/** @brief This algorithm converts images to median threshold bitmaps (1 for pixels brighter than median +luminance and 0 otherwise) and than aligns the resulting bitmaps using bit operations. + +It is invariant to exposure, so exposure values and camera response are not necessary. + +In this implementation new image regions are filled with zeros. + +For more information see @cite GW03 . + */ +class CV_EXPORTS_W AlignMTB : public AlignExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, std::vector& dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + + /** @brief Short version of process, that doesn't take extra arguments. + + @param src vector of input images + @param dst vector of aligned images + */ + CV_WRAP virtual void process(InputArrayOfArrays src, std::vector& dst) = 0; + + /** @brief Calculates shift between two images, i. e. how to shift the second image to correspond it with the + first. + + @param img0 first image + @param img1 second image + */ + CV_WRAP virtual Point calculateShift(InputArray img0, InputArray img1) = 0; + /** @brief Helper function, that shift Mat filling new regions with zeros. + + @param src input image + @param dst result image + @param shift shift value + */ + CV_WRAP virtual void shiftMat(InputArray src, OutputArray dst, const Point shift) = 0; + /** @brief Computes median threshold and exclude bitmaps of given image. + + @param img input image + @param tb median threshold bitmap + @param eb exclude bitmap + */ + CV_WRAP virtual void computeBitmaps(InputArray img, OutputArray tb, OutputArray eb) = 0; + + CV_WRAP virtual int getMaxBits() const = 0; + CV_WRAP virtual void setMaxBits(int max_bits) = 0; + + CV_WRAP virtual int getExcludeRange() const = 0; + CV_WRAP virtual void setExcludeRange(int exclude_range) = 0; + + CV_WRAP virtual bool getCut() const = 0; + CV_WRAP virtual void setCut(bool value) = 0; +}; + +/** @brief Creates AlignMTB object + +@param max_bits logarithm to the base 2 of maximal shift in each dimension. Values of 5 and 6 are +usually good enough (31 and 63 pixels shift respectively). +@param exclude_range range for exclusion bitmap that is constructed to suppress noise around the +median value. +@param cut if true cuts images, otherwise fills the new regions with zeros. + */ +CV_EXPORTS_W Ptr createAlignMTB(int max_bits = 6, int exclude_range = 4, bool cut = true); + +/** @brief The base class for camera response calibration algorithms. + */ +class CV_EXPORTS_W CalibrateCRF : public Algorithm +{ +public: + /** @brief Recovers inverse camera response. + + @param src vector of input images + @param dst 256x1 matrix with inverse camera response function + @param times vector of exposure time values for each image + */ + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0; +}; + +/** @brief Inverse camera response function is extracted for each brightness value by minimizing an objective +function as linear system. Objective function is constructed using pixel values on the same position +in all images, extra term is added to make the result smoother. + +For more information see @cite DM97 . + */ +class CV_EXPORTS_W CalibrateDebevec : public CalibrateCRF +{ +public: + CV_WRAP virtual float getLambda() const = 0; + CV_WRAP virtual void setLambda(float lambda) = 0; + + CV_WRAP virtual int getSamples() const = 0; + CV_WRAP virtual void setSamples(int samples) = 0; + + CV_WRAP virtual bool getRandom() const = 0; + CV_WRAP virtual void setRandom(bool random) = 0; +}; + +/** @brief Creates CalibrateDebevec object + +@param samples number of pixel locations to use +@param lambda smoothness term weight. Greater values produce smoother results, but can alter the +response. +@param random if true sample pixel locations are chosen at random, otherwise they form a +rectangular grid. + */ +CV_EXPORTS_W Ptr createCalibrateDebevec(int samples = 70, float lambda = 10.0f, bool random = false); + +/** @brief Inverse camera response function is extracted for each brightness value by minimizing an objective +function as linear system. This algorithm uses all image pixels. + +For more information see @cite RB99 . + */ +class CV_EXPORTS_W CalibrateRobertson : public CalibrateCRF +{ +public: + CV_WRAP virtual int getMaxIter() const = 0; + CV_WRAP virtual void setMaxIter(int max_iter) = 0; + + CV_WRAP virtual float getThreshold() const = 0; + CV_WRAP virtual void setThreshold(float threshold) = 0; + + CV_WRAP virtual Mat getRadiance() const = 0; +}; + +/** @brief Creates CalibrateRobertson object + +@param max_iter maximal number of Gauss-Seidel solver iterations. +@param threshold target difference between results of two successive steps of the minimization. + */ +CV_EXPORTS_W Ptr createCalibrateRobertson(int max_iter = 30, float threshold = 0.01f); + +/** @brief The base class algorithms that can merge exposure sequence to a single image. + */ +class CV_EXPORTS_W MergeExposures : public Algorithm +{ +public: + /** @brief Merges images. + + @param src vector of input images + @param dst result image + @param times vector of exposure time values for each image + @param response 256x1 matrix with inverse camera response function for each pixel value, it should + have the same number of channels as images. + */ + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) = 0; +}; + +/** @brief The resulting HDR image is calculated as weighted average of the exposures considering exposure +values and camera response. + +For more information see @cite DM97 . + */ +class CV_EXPORTS_W MergeDebevec : public MergeExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0; +}; + +/** @brief Creates MergeDebevec object + */ +CV_EXPORTS_W Ptr createMergeDebevec(); + +/** @brief Pixels are weighted using contrast, saturation and well-exposedness measures, than images are +combined using laplacian pyramids. + +The resulting image weight is constructed as weighted average of contrast, saturation and +well-exposedness measures. + +The resulting image doesn't require tonemapping and can be converted to 8-bit image by multiplying +by 255, but it's recommended to apply gamma correction and/or linear tonemapping. + +For more information see @cite MK07 . + */ +class CV_EXPORTS_W MergeMertens : public MergeExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + /** @brief Short version of process, that doesn't take extra arguments. + + @param src vector of input images + @param dst result image + */ + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst) = 0; + + CV_WRAP virtual float getContrastWeight() const = 0; + CV_WRAP virtual void setContrastWeight(float contrast_weiht) = 0; + + CV_WRAP virtual float getSaturationWeight() const = 0; + CV_WRAP virtual void setSaturationWeight(float saturation_weight) = 0; + + CV_WRAP virtual float getExposureWeight() const = 0; + CV_WRAP virtual void setExposureWeight(float exposure_weight) = 0; +}; + +/** @brief Creates MergeMertens object + +@param contrast_weight contrast measure weight. See MergeMertens. +@param saturation_weight saturation measure weight +@param exposure_weight well-exposedness measure weight + */ +CV_EXPORTS_W Ptr +createMergeMertens(float contrast_weight = 1.0f, float saturation_weight = 1.0f, float exposure_weight = 0.0f); + +/** @brief The resulting HDR image is calculated as weighted average of the exposures considering exposure +values and camera response. + +For more information see @cite RB99 . + */ +class CV_EXPORTS_W MergeRobertson : public MergeExposures +{ +public: + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, + InputArray times, InputArray response) CV_OVERRIDE = 0; + CV_WRAP virtual void process(InputArrayOfArrays src, OutputArray dst, InputArray times) = 0; +}; + +/** @brief Creates MergeRobertson object + */ +CV_EXPORTS_W Ptr createMergeRobertson(); + +//! @} photo_hdr + +//! @addtogroup photo_decolor +//! @{ + +/** @brief Transforms a color image to a grayscale image. It is a basic tool in digital printing, stylized +black-and-white photograph rendering, and in many single channel image processing applications +@cite CL12 . + +@param src Input 8-bit 3-channel image. +@param grayscale Output 8-bit 1-channel image. +@param color_boost Output 8-bit 3-channel image. + +This function is to be applied on color images. + */ +CV_EXPORTS_W void decolor( InputArray src, OutputArray grayscale, OutputArray color_boost); + +//! @} photo_decolor + +//! @addtogroup photo_clone +//! @{ + + +//! seamlessClone algorithm flags +enum +{ + /** The power of the method is fully expressed when inserting objects with complex outlines into a new background*/ + NORMAL_CLONE = 1, + /** The classic method, color-based selection and alpha masking might be time consuming and often leaves an undesirable + halo. Seamless cloning, even averaged with the original image, is not effective. Mixed seamless cloning based on a loose selection proves effective.*/ + MIXED_CLONE = 2, + /** Monochrome transfer allows the user to easily replace certain features of one object by alternative features.*/ + MONOCHROME_TRANSFER = 3}; + + +/** @example samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp +An example using seamlessClone function +*/ +/** @brief Image editing tasks concern either global changes (color/intensity corrections, filters, +deformations) or local changes concerned to a selection. Here we are interested in achieving local +changes, ones that are restricted to a region manually selected (ROI), in a seamless and effortless +manner. The extent of the changes ranges from slight distortions to complete replacement by novel +content @cite PM03 . + +@param src Input 8-bit 3-channel image. +@param dst Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param p Point in dst image where object is placed. +@param blend Output image with the same size and type as dst. +@param flags Cloning method that could be cv::NORMAL_CLONE, cv::MIXED_CLONE or cv::MONOCHROME_TRANSFER + */ +CV_EXPORTS_W void seamlessClone( InputArray src, InputArray dst, InputArray mask, Point p, + OutputArray blend, int flags); + +/** @brief Given an original color image, two differently colored versions of this image can be mixed +seamlessly. + +@param src Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param dst Output image with the same size and type as src . +@param red_mul R-channel multiply factor. +@param green_mul G-channel multiply factor. +@param blue_mul B-channel multiply factor. + +Multiplication factor is between .5 to 2.5. + */ +CV_EXPORTS_W void colorChange(InputArray src, InputArray mask, OutputArray dst, float red_mul = 1.0f, + float green_mul = 1.0f, float blue_mul = 1.0f); + +/** @brief Applying an appropriate non-linear transformation to the gradient field inside the selection and +then integrating back with a Poisson solver, modifies locally the apparent illumination of an image. + +@param src Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param dst Output image with the same size and type as src. +@param alpha Value ranges between 0-2. +@param beta Value ranges between 0-2. + +This is useful to highlight under-exposed foreground objects or to reduce specular reflections. + */ +CV_EXPORTS_W void illuminationChange(InputArray src, InputArray mask, OutputArray dst, + float alpha = 0.2f, float beta = 0.4f); + +/** @brief By retaining only the gradients at edge locations, before integrating with the Poisson solver, one +washes out the texture of the selected region, giving its contents a flat aspect. Here Canny Edge %Detector is used. + +@param src Input 8-bit 3-channel image. +@param mask Input 8-bit 1 or 3-channel image. +@param dst Output image with the same size and type as src. +@param low_threshold %Range from 0 to 100. +@param high_threshold Value \> 100. +@param kernel_size The size of the Sobel kernel to be used. + +@note +The algorithm assumes that the color of the source image is close to that of the destination. This +assumption means that when the colors don't match, the source image color gets tinted toward the +color of the destination image. + */ +CV_EXPORTS_W void textureFlattening(InputArray src, InputArray mask, OutputArray dst, + float low_threshold = 30, float high_threshold = 45, + int kernel_size = 3); + +//! @} photo_clone + +//! @addtogroup photo_render +//! @{ + +//! Edge preserving filters +enum +{ + RECURS_FILTER = 1, //!< Recursive Filtering + NORMCONV_FILTER = 2 //!< Normalized Convolution Filtering +}; + +/** @brief Filtering is the fundamental operation in image and video processing. Edge-preserving smoothing +filters are used in many different applications @cite EM11 . + +@param src Input 8-bit 3-channel image. +@param dst Output 8-bit 3-channel image. +@param flags Edge preserving filters: cv::RECURS_FILTER or cv::NORMCONV_FILTER +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. + */ +CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1, + float sigma_s = 60, float sigma_r = 0.4f); + +/** @brief This filter enhances the details of a particular image. + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src. +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. + */ +CV_EXPORTS_W void detailEnhance(InputArray src, OutputArray dst, float sigma_s = 10, + float sigma_r = 0.15f); + +/** @example samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp +An example using non-photorealistic line drawing functions +*/ +/** @brief Pencil-like non-photorealistic line drawing + +@param src Input 8-bit 3-channel image. +@param dst1 Output 8-bit 1-channel image. +@param dst2 Output image with the same size and type as src. +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. +@param shade_factor %Range between 0 to 0.1. + */ +CV_EXPORTS_W void pencilSketch(InputArray src, OutputArray dst1, OutputArray dst2, + float sigma_s = 60, float sigma_r = 0.07f, float shade_factor = 0.02f); + +/** @brief Stylization aims to produce digital imagery with a wide variety of effects not focused on +photorealism. Edge-aware filters are ideal for stylization, as they can abstract regions of low +contrast while preserving, or enhancing, high-contrast features. + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src. +@param sigma_s %Range between 0 to 200. +@param sigma_r %Range between 0 to 1. + */ +CV_EXPORTS_W void stylization(InputArray src, OutputArray dst, float sigma_s = 60, + float sigma_r = 0.45f); + +//! @} photo_render + +//! @} photo + +} // cv + +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/cuda.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/cuda.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a2f38167e640fcb91a43f97d3ea9d9305dc84dcf --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/cuda.hpp @@ -0,0 +1,132 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef OPENCV_PHOTO_CUDA_HPP +#define OPENCV_PHOTO_CUDA_HPP + +#include "opencv2/core/cuda.hpp" + +namespace cv { namespace cuda { + +//! @addtogroup photo_denoise +//! @{ + +/** @brief Performs pure non local means denoising without any simplification, and thus it is not fast. + +@param src Source image. Supports only CV_8UC1, CV_8UC2 and CV_8UC3. +@param dst Destination image. +@param h Filter sigma regulating filter strength for color. +@param search_window Size of search window. +@param block_size Size of block used for computing weights. +@param borderMode Border type. See borderInterpolate for details. BORDER_REFLECT101 , +BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now. +@param stream Stream for the asynchronous version. + +@sa + fastNlMeansDenoising + */ +CV_EXPORTS void nonLocalMeans(InputArray src, OutputArray dst, + float h, + int search_window = 21, + int block_size = 7, + int borderMode = BORDER_DEFAULT, + Stream& stream = Stream::Null()); + +/** @brief Perform image denoising using Non-local Means Denoising algorithm + with several computational +optimizations. Noise expected to be a gaussian white noise + +@param src Input 8-bit 1-channel, 2-channel or 3-channel image. +@param dst Output image with the same size and type as src . +@param h Parameter regulating filter strength. Big h value perfectly removes noise but also +removes image details, smaller h value preserves details but also preserves some noise +@param search_window Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater search_window - greater +denoising time. Recommended value 21 pixels +@param block_size Size in pixels of the template patch that is used to compute weights. Should be +odd. Recommended value 7 pixels +@param stream Stream for the asynchronous invocations. + +This function expected to be applied to grayscale images. For colored images look at +FastNonLocalMeansDenoising::labMethod. + +@sa + fastNlMeansDenoising + */ +CV_EXPORTS void fastNlMeansDenoising(InputArray src, OutputArray dst, + float h, + int search_window = 21, + int block_size = 7, + Stream& stream = Stream::Null()); + +/** @brief Modification of fastNlMeansDenoising function for colored images + +@param src Input 8-bit 3-channel image. +@param dst Output image with the same size and type as src . +@param h_luminance Parameter regulating filter strength. Big h value perfectly removes noise but +also removes image details, smaller h value preserves details but also preserves some noise +@param photo_render float The same as h but for color components. For most images value equals 10 will be +enough to remove colored noise and do not distort colors +@param search_window Size in pixels of the window that is used to compute weighted average for +given pixel. Should be odd. Affect performance linearly: greater search_window - greater +denoising time. Recommended value 21 pixels +@param block_size Size in pixels of the template patch that is used to compute weights. Should be +odd. Recommended value 7 pixels +@param stream Stream for the asynchronous invocations. + +The function converts image to CIELAB colorspace and then separately denoise L and AB components +with given h parameters using FastNonLocalMeansDenoising::simpleMethod function. + +@sa + fastNlMeansDenoisingColored + */ +CV_EXPORTS void fastNlMeansDenoisingColored(InputArray src, OutputArray dst, + float h_luminance, float photo_render, + int search_window = 21, + int block_size = 7, + Stream& stream = Stream::Null()); + +//! @} photo + +}} // namespace cv { namespace cuda { + +#endif /* OPENCV_PHOTO_CUDA_HPP */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/legacy/constants_c.h b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/legacy/constants_c.h new file mode 100644 index 0000000000000000000000000000000000000000..ec1d4403fde38c4894df7787ea45d28ffff3d9d3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/legacy/constants_c.h @@ -0,0 +1,14 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_PHOTO_LEGACY_CONSTANTS_H +#define OPENCV_PHOTO_LEGACY_CONSTANTS_H + +enum InpaintingModes +{ + CV_INPAINT_NS =0, + CV_INPAINT_TELEA =1 +}; + +#endif // OPENCV_PHOTO_LEGACY_CONSTANTS_H diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/photo.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/photo.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8af5e9f0fae26070fb49d931190b08cfa09e9419 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/photo/photo.hpp @@ -0,0 +1,48 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifdef __OPENCV_BUILD +#error this is a compatibility header which should not be used inside the OpenCV library +#endif + +#include "opencv2/photo.hpp" diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/plot.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/plot.hpp new file mode 100644 index 0000000000000000000000000000000000000000..06a12a1479ed2c30442ec936498cadfe9cb9419a --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/plot.hpp @@ -0,0 +1,120 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ +//################################################################################ +// +// Created by Nuno Moutinho +// +//################################################################################ + +#ifndef _OPENCV_PLOT_H_ +#define _OPENCV_PLOT_H_ +#ifdef __cplusplus + +#include + +/** +@defgroup plot Plot function for Mat data +*/ + +namespace cv +{ + namespace plot + { + //! @addtogroup plot + //! @{ + + class CV_EXPORTS_W Plot2d : public Algorithm + { + public: + + CV_WRAP virtual void setMinX(double _plotMinX) = 0; + CV_WRAP virtual void setMinY(double _plotMinY) = 0; + CV_WRAP virtual void setMaxX(double _plotMaxX) = 0; + CV_WRAP virtual void setMaxY(double _plotMaxY) = 0; + CV_WRAP virtual void setPlotLineWidth(int _plotLineWidth) = 0; + /** + * @brief Switches data visualization mode + * + * @param _needPlotLine if true then neighbour plot points will be connected by lines. + * In other case data will be plotted as a set of standalone points. + */ + CV_WRAP virtual void setNeedPlotLine(bool _needPlotLine) = 0; + CV_WRAP virtual void setPlotLineColor(Scalar _plotLineColor) = 0; + CV_WRAP virtual void setPlotBackgroundColor(Scalar _plotBackgroundColor) = 0; + CV_WRAP virtual void setPlotAxisColor(Scalar _plotAxisColor) = 0; + CV_WRAP virtual void setPlotGridColor(Scalar _plotGridColor) = 0; + CV_WRAP virtual void setPlotTextColor(Scalar _plotTextColor) = 0; + CV_WRAP virtual void setPlotSize(int _plotSizeWidth, int _plotSizeHeight) = 0; + CV_WRAP virtual void setShowGrid(bool needShowGrid) = 0; + CV_WRAP virtual void setShowText(bool needShowText) = 0; + CV_WRAP virtual void setGridLinesNumber(int gridLinesNumber) = 0; + CV_WRAP virtual void setInvertOrientation(bool _invertOrientation) = 0; + /** + * @brief Sets the index of a point which coordinates will be printed on the top left corner of the plot (if ShowText flag is true). + * + * @param pointIdx index of the required point in data array. + */ + CV_WRAP virtual void setPointIdxToPrint(int pointIdx) = 0; + CV_WRAP virtual void render(OutputArray _plotResult) = 0; + + /** + * @brief Creates Plot2d object + * + * @param data \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. \f$X\f$ values + * will be equal to indexes of correspondind elements in data matrix. + */ + CV_WRAP static Ptr create(InputArray data); + + /** + * @brief Creates Plot2d object + * + * @param dataX \f$1xN\f$ or \f$Nx1\f$ matrix \f$X\f$ values of points to plot. + * @param dataY \f$1xN\f$ or \f$Nx1\f$ matrix containing \f$Y\f$ values of points to plot. + */ + CV_WRAP static Ptr create(InputArray dataX, InputArray dataY); + }; + //! @} + } +} + +#endif +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8470f08fefc3ce8194391bbddbf8df7ea45baf04 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality.hpp @@ -0,0 +1,15 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITY_HPP +#define OPENCV_QUALITY_HPP + +#include "quality/qualitybase.hpp" +#include "quality/qualitymse.hpp" +#include "quality/qualitypsnr.hpp" +#include "quality/qualityssim.hpp" +#include "quality/qualitygmsd.hpp" +#include "quality/qualitybrisque.hpp" + +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/quality_utils.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/quality_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4b3df51a0c3b4a591043d05076a9508bf199fa22 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/quality_utils.hpp @@ -0,0 +1,109 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITY_QUALITY_UTILS_HPP +#define OPENCV_QUALITY_QUALITY_UTILS_HPP + +#include "qualitybase.hpp" + +namespace cv +{ +namespace quality +{ +namespace quality_utils +{ + +// default type of matrix to expand to +static CV_CONSTEXPR const int EXPANDED_MAT_DEFAULT_TYPE = CV_32F; + +// convert inputarray to specified mat type. set type == -1 to preserve existing type +template +inline R extract_mat(InputArray in, const int type = -1) +{ + R result = {}; + if ( in.isMat() ) + in.getMat().convertTo( result, (type != -1) ? type : in.getMat().type()); + else if ( in.isUMat() ) + in.getUMat().convertTo( result, (type != -1) ? type : in.getUMat().type()); + else + CV_Error(Error::StsNotImplemented, "Unsupported input type"); + + return result; +} + +// extract and expand matrix to target type +template +inline R expand_mat( InputArray src, int TYPE_DEFAULT = EXPANDED_MAT_DEFAULT_TYPE) +{ + auto result = extract_mat(src, -1); + + // by default, expand to 32F unless we already have >= 32 bits, then go to 64 + // if/when we can detect OpenCL CV_16F support, opt for that when input depth == 8 + // note that this may impact the precision of the algorithms and would need testing + int type = TYPE_DEFAULT; + + switch (result.depth()) + { + case CV_32F: + case CV_32S: + case CV_64F: + type = CV_64F; + }; // switch + + result.convertTo(result, type); + return result; +} + +// return mat of observed min/max pair per column +// row 0: min per column +// row 1: max per column +// template +inline cv::Mat get_column_range( const cv::Mat& data ) +{ + CV_Assert(data.channels() == 1); + CV_Assert(data.rows > 0); + + cv::Mat result( cv::Size( data.cols, 2 ), data.type() ); + + auto + row_min = result.row(0) + , row_max = result.row(1) + ; + + // set initial min/max + data.row(0).copyTo(row_min); + data.row(0).copyTo(row_max); + + for (int y = 1; y < data.rows; ++y) + { + auto row = data.row(y); + cv::min(row,row_min, row_min); + cv::max(row, row_max, row_max); + } + return result; +} // get_column_range + +// linear scale of each column from min to max +// range is column-wise pair of observed min/max. See get_column_range +template +inline void scale( cv::Mat& mat, const cv::Mat& range, const T min, const T max ) +{ + // value = lower + (upper - lower) * (value - feature_min[index]) / (feature_max[index] - feature_min[index]); + // where [lower] = lower bound, [upper] = upper bound + + for (int y = 0; y < mat.rows; ++y) + { + auto row = mat.row(y); + auto row_min = range.row(0); + auto row_max = range.row(1); + + for (int x = 0; x < mat.cols; ++x) + row.at(x) = min + (max - min) * (row.at(x) - row_min.at(x) ) / (row_max.at(x) - row_min.at(x)); + } +} + +} // quality_utils +} // quality +} // cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitybase.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitybase.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1f4887fcae11214dea8791ebf5157d84a5d91c01 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitybase.hpp @@ -0,0 +1,63 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITYBASE_HPP +#define OPENCV_QUALITYBASE_HPP + +#include + +/** +@defgroup quality Image Quality Analysis (IQA) API +*/ + +namespace cv +{ +namespace quality +{ + +//! @addtogroup quality +//! @{ + +/************************************ Quality Base Class ************************************/ +class CV_EXPORTS_W QualityBase + : public virtual Algorithm +{ +public: + + /** @brief Destructor */ + virtual ~QualityBase() = default; + + /** + @brief Compute quality score per channel with the per-channel score in each element of the resulting cv::Scalar. See specific algorithm for interpreting result scores + @param img comparison image, or image to evalute for no-reference quality algorithms + */ + virtual CV_WRAP cv::Scalar compute( InputArray img ) = 0; + + /** @brief Returns output quality map that was generated during computation, if supported by the algorithm */ + virtual CV_WRAP void getQualityMap(OutputArray dst) const + { + if (!dst.needed() || _qualityMap.empty() ) + return; + dst.assign(_qualityMap); + } + + /** @brief Implements Algorithm::clear() */ + CV_WRAP void clear() CV_OVERRIDE { _qualityMap = _mat_type(); Algorithm::clear(); } + + /** @brief Implements Algorithm::empty() */ + CV_WRAP bool empty() const CV_OVERRIDE { return _qualityMap.empty(); } + +protected: + + /** @brief internal mat type default */ + using _mat_type = cv::UMat; + + /** @brief Output quality maps if generated by algorithm */ + _mat_type _qualityMap; + +}; // QualityBase +//! @} +} // quality +} // cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitybrisque.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitybrisque.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9732f82d26b6a4bfd764a2d028339107f921d5f1 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitybrisque.hpp @@ -0,0 +1,82 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITY_QUALITYBRISQUE_HPP +#define OPENCV_QUALITY_QUALITYBRISQUE_HPP + +#include "qualitybase.hpp" +#include "opencv2/ml.hpp" + +namespace cv +{ +namespace quality +{ + +/** +@brief BRISQUE (Blind/Referenceless Image Spatial Quality Evaluator) is a No Reference Image Quality Assessment (NR-IQA) algorithm. + +BRISQUE computes a score based on extracting Natural Scene Statistics (https://en.wikipedia.org/wiki/Scene_statistics) +and calculating feature vectors. See Mittal et al. @cite Mittal2 for original paper and original implementation @cite Mittal2_software . + +A trained model is provided in the /samples/ directory and is trained on the LIVE-R2 database @cite Sheikh as in the original implementation. +When evaluated against the TID2008 database @cite Ponomarenko , the SROCC is -0.8424 versus the SROCC of -0.8354 in the original implementation. +C++ code for the BRISQUE LIVE-R2 trainer and TID2008 evaluator are also provided in the /samples/ directory. +*/ +class CV_EXPORTS_W QualityBRISQUE : public QualityBase { +public: + + /** @brief Computes BRISQUE quality score for input image + @param img Image for which to compute quality + @returns cv::Scalar with the score in the first element. The score ranges from 0 (best quality) to 100 (worst quality) + */ + CV_WRAP cv::Scalar compute( InputArray img ) CV_OVERRIDE; + + /** + @brief Create an object which calculates quality + @param model_file_path cv::String which contains a path to the BRISQUE model data, eg. /path/to/brisque_model_live.yml + @param range_file_path cv::String which contains a path to the BRISQUE range data, eg. /path/to/brisque_range_live.yml + */ + CV_WRAP static Ptr create( const cv::String& model_file_path, const cv::String& range_file_path ); + + /** + @brief Create an object which calculates quality + @param model cv::Ptr which contains a loaded BRISQUE model + @param range cv::Mat which contains BRISQUE range data + */ + CV_WRAP static Ptr create( const cv::Ptr& model, const cv::Mat& range ); + + /** + @brief static method for computing quality + @param img image for which to compute quality + @param model_file_path cv::String which contains a path to the BRISQUE model data, eg. /path/to/brisque_model_live.yml + @param range_file_path cv::String which contains a path to the BRISQUE range data, eg. /path/to/brisque_range_live.yml + @returns cv::Scalar with the score in the first element. The score ranges from 0 (best quality) to 100 (worst quality) + */ + CV_WRAP static cv::Scalar compute( InputArray img, const cv::String& model_file_path, const cv::String& range_file_path ); + + /** + @brief static method for computing image features used by the BRISQUE algorithm + @param img image (BGR(A) or grayscale) for which to compute features + @param features output row vector of features to cv::Mat or cv::UMat + */ + CV_WRAP static void computeFeatures(InputArray img, OutputArray features); + +protected: + + cv::Ptr _model = nullptr; + cv::Mat _range; + + /** @brief Internal constructor */ + QualityBRISQUE( const cv::String& model_file_path, const cv::String& range_file_path ); + + /** @brief Internal constructor */ + QualityBRISQUE(const cv::Ptr& model, const cv::Mat& range ) + : _model{ model } + , _range{ range } + {} + +}; // QualityBRISQUE +} // quality +} // cv +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitygmsd.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitygmsd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3a9cd0b694bab2c016154c3fc66db52a7ed162df --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitygmsd.hpp @@ -0,0 +1,92 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITY_QUALITYGMSD_HPP +#define OPENCV_QUALITY_QUALITYGMSD_HPP + +#include "qualitybase.hpp" + +namespace cv +{ +namespace quality +{ + +/** +@brief Full reference GMSD algorithm +http://www4.comp.polyu.edu.hk/~cslzhang/IQA/GMSD/GMSD.htm +*/ +class CV_EXPORTS_W QualityGMSD + : public QualityBase { +public: + + /** + @brief Compute GMSD + @param cmp comparison image + @returns cv::Scalar with per-channel quality value. Values range from 0 (worst) to 1 (best) + */ + CV_WRAP cv::Scalar compute( InputArray cmp ) CV_OVERRIDE; + + /** @brief Implements Algorithm::empty() */ + CV_WRAP bool empty() const CV_OVERRIDE { return _refImgData.empty() && QualityBase::empty(); } + + /** @brief Implements Algorithm::clear() */ + CV_WRAP void clear() CV_OVERRIDE { _refImgData = _mat_data(); QualityBase::clear(); } + + /** + @brief Create an object which calculates image quality + @param ref reference image + */ + CV_WRAP static Ptr create( InputArray ref ); + + /** + @brief static method for computing quality + @param ref reference image + @param cmp comparison image + @param qualityMap output quality map, or cv::noArray() + @returns cv::Scalar with per-channel quality value. Values range from 0 (worst) to 1 (best) + */ + CV_WRAP static cv::Scalar compute( InputArray ref, InputArray cmp, OutputArray qualityMap ); + +protected: + + // holds computed values for a mat + struct _mat_data + { + // internal mat type + using mat_type = QualityBase::_mat_type; + + mat_type + gradient_map + , gradient_map_squared + ; + + // allow default construction + _mat_data() = default; + + // construct from mat_type + _mat_data(const mat_type&); + + // construct from inputarray + _mat_data(InputArray); + + // returns flag if empty + bool empty() const { return this->gradient_map.empty() && this->gradient_map_squared.empty(); } + + // compute for a single frame + static std::pair compute(const _mat_data& lhs, const _mat_data& rhs); + + }; // mat_data + + /** @brief Reference image data */ + _mat_data _refImgData; + + // internal constructor + QualityGMSD(_mat_data refImgData) + : _refImgData(std::move(refImgData)) + {} + +}; // QualityGMSD +} // quality +} // cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitymse.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitymse.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7763a58b78659f03b3043775d9452434ad671d50 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitymse.hpp @@ -0,0 +1,64 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITY_QUALITYMSE_HPP +#define OPENCV_QUALITY_QUALITYMSE_HPP + +#include "qualitybase.hpp" + +namespace cv +{ +namespace quality +{ + +/** +@brief Full reference mean square error algorithm https://en.wikipedia.org/wiki/Mean_squared_error +*/ +class CV_EXPORTS_W QualityMSE : public QualityBase { +public: + + /** @brief Computes MSE for reference images supplied in class constructor and provided comparison images + @param cmpImgs Comparison image(s) + @returns cv::Scalar with per-channel quality values. Values range from 0 (best) to potentially max float (worst) + */ + CV_WRAP cv::Scalar compute( InputArrayOfArrays cmpImgs ) CV_OVERRIDE; + + /** @brief Implements Algorithm::empty() */ + CV_WRAP bool empty() const CV_OVERRIDE { return _ref.empty() && QualityBase::empty(); } + + /** @brief Implements Algorithm::clear() */ + CV_WRAP void clear() CV_OVERRIDE { _ref = _mat_type(); QualityBase::clear(); } + + /** + @brief Create an object which calculates quality + @param ref input image to use as the reference for comparison + */ + CV_WRAP static Ptr create(InputArray ref); + + /** + @brief static method for computing quality + @param ref reference image + @param cmp comparison image= + @param qualityMap output quality map, or cv::noArray() + @returns cv::Scalar with per-channel quality values. Values range from 0 (best) to max float (worst) + */ + CV_WRAP static cv::Scalar compute( InputArray ref, InputArray cmp, OutputArray qualityMap ); + +protected: + + /** @brief Reference image, converted to internal mat type */ + QualityBase::_mat_type _ref; + + /** + @brief Constructor + @param ref reference image, converted to internal type + */ + QualityMSE(QualityBase::_mat_type ref) + : _ref(std::move(ref)) + {} + +}; // QualityMSE +} // quality +} // cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitypsnr.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitypsnr.hpp new file mode 100644 index 0000000000000000000000000000000000000000..59b7325507d793671d2575967c2d44cfd34edc95 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualitypsnr.hpp @@ -0,0 +1,120 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITY_QUALITYPSNR_HPP +#define OPENCV_QUALITY_QUALITYPSNR_HPP + +#include // numeric_limits +#include "qualitybase.hpp" +#include "qualitymse.hpp" + +namespace cv +{ +namespace quality +{ + +/** +@brief Full reference peak signal to noise ratio (PSNR) algorithm https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio +*/ +class CV_EXPORTS_W QualityPSNR + : public QualityBase { + +public: + + /** @brief Default maximum pixel value */ +#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900/*MSVS 2015*/) + static constexpr double MAX_PIXEL_VALUE_DEFAULT = 255.; +#else + // support MSVS 2013 + static const int MAX_PIXEL_VALUE_DEFAULT = 255; +#endif + + /** + @brief Create an object which calculates quality + @param ref input image to use as the source for comparison + @param maxPixelValue maximum per-channel value for any individual pixel; eg 255 for uint8 image + */ + CV_WRAP static Ptr create( InputArray ref, double maxPixelValue = QualityPSNR::MAX_PIXEL_VALUE_DEFAULT ) + { + return Ptr(new QualityPSNR(QualityMSE::create(ref), maxPixelValue)); + } + + /** + @brief Compute the PSNR + @param cmp Comparison image + @returns Per-channel PSNR value, or std::numeric_limits::infinity() if the MSE between the two images == 0 + */ + CV_WRAP cv::Scalar compute( InputArray cmp ) CV_OVERRIDE + { + auto result = _qualityMSE->compute( cmp ); + _qualityMSE->getQualityMap(_qualityMap); // copy from internal obj to this obj + return _mse_to_psnr( + result + , _maxPixelValue + ); + } + + /** @brief Implements Algorithm::empty() */ + CV_WRAP bool empty() const CV_OVERRIDE { return _qualityMSE->empty() && QualityBase::empty(); } + + /** @brief Implements Algorithm::clear() */ + CV_WRAP void clear() CV_OVERRIDE { _qualityMSE->clear(); QualityBase::clear(); } + + /** + @brief static method for computing quality + @param ref reference image + @param cmp comparison image + @param qualityMap output quality map, or cv::noArray() + @param maxPixelValue maximum per-channel value for any individual pixel; eg 255 for uint8 image + @returns PSNR value, or std::numeric_limits::infinity() if the MSE between the two images == 0 + */ + CV_WRAP static cv::Scalar compute( InputArray ref, InputArray cmp, OutputArray qualityMap, double maxPixelValue = QualityPSNR::MAX_PIXEL_VALUE_DEFAULT) + { + return _mse_to_psnr( + QualityMSE::compute(ref, cmp, qualityMap) + , maxPixelValue + ); + } + + /** @brief return the maximum pixel value used for PSNR computation */ + CV_WRAP double getMaxPixelValue() const { return _maxPixelValue; } + + /** + @brief sets the maximum pixel value used for PSNR computation + @param val Maximum pixel value + */ + CV_WRAP void setMaxPixelValue(double val) { this->_maxPixelValue = val; } + +protected: + + Ptr _qualityMSE; + double _maxPixelValue = QualityPSNR::MAX_PIXEL_VALUE_DEFAULT; + + /** @brief Constructor */ + QualityPSNR( Ptr qualityMSE, double maxPixelValue ) + : _qualityMSE(std::move(qualityMSE)) + , _maxPixelValue(maxPixelValue) + {} + + // convert mse to psnr + static double _mse_to_psnr(double mse, double max_pixel_value) + { + return (mse == 0.) + ? std::numeric_limits::infinity() + : 10. * std::log10((max_pixel_value * max_pixel_value) / mse) + ; + } + + // convert scalar of mses to psnrs + static cv::Scalar _mse_to_psnr(cv::Scalar mse, double max_pixel_value) + { + for (int i = 0; i < mse.rows; ++i) + mse(i) = _mse_to_psnr(mse(i), max_pixel_value); + return mse; + } + +}; // QualityPSNR +} // quality +} // cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualityssim.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualityssim.hpp new file mode 100644 index 0000000000000000000000000000000000000000..edbd3ae6b523ab77369ff4225d93510bd51ebc6c --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/quality/qualityssim.hpp @@ -0,0 +1,97 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef OPENCV_QUALITY_QUALITYSSIM_HPP +#define OPENCV_QUALITY_QUALITYSSIM_HPP + +#include "qualitybase.hpp" + +namespace cv +{ +namespace quality +{ + +/** +@brief Full reference structural similarity algorithm https://en.wikipedia.org/wiki/Structural_similarity +*/ +class CV_EXPORTS_W QualitySSIM + : public QualityBase { +public: + + /** + @brief Computes SSIM + @param cmp Comparison image + @returns cv::Scalar with per-channel quality values. Values range from 0 (worst) to 1 (best) + */ + CV_WRAP cv::Scalar compute( InputArray cmp ) CV_OVERRIDE; + + /** @brief Implements Algorithm::empty() */ + CV_WRAP bool empty() const CV_OVERRIDE { return _refImgData.empty() && QualityBase::empty(); } + + /** @brief Implements Algorithm::clear() */ + CV_WRAP void clear() CV_OVERRIDE { _refImgData = _mat_data(); QualityBase::clear(); } + + /** + @brief Create an object which calculates quality + @param ref input image to use as the reference image for comparison + */ + CV_WRAP static Ptr create( InputArray ref ); + + /** + @brief static method for computing quality + @param ref reference image + @param cmp comparison image + @param qualityMap output quality map, or cv::noArray() + @returns cv::Scalar with per-channel quality values. Values range from 0 (worst) to 1 (best) + */ + CV_WRAP static cv::Scalar compute( InputArray ref, InputArray cmp, OutputArray qualityMap ); + +protected: + + // holds computed values for a mat + struct _mat_data + { + // internal mat type + using mat_type = QualityBase::_mat_type; + + mat_type + I + , I_2 + , mu + , mu_2 + , sigma_2 + ; + + // allow default construction + _mat_data() = default; + + // construct from mat_type + _mat_data(const mat_type&); + + // construct from inputarray + _mat_data(InputArray); + + // return flag if this is empty + bool empty() const { return I.empty() && I_2.empty() && mu.empty() && mu_2.empty() && sigma_2.empty(); } + + // computes ssim and quality map for single frame + static std::pair compute(const _mat_data& lhs, const _mat_data& rhs); + + }; // mat_data + + /** @brief Reference image data */ + _mat_data _refImgData; + + /** + @brief Constructor + @param refImgData reference image, converted to internal type + */ + QualitySSIM( _mat_data refImgData ) + : _refImgData( std::move(refImgData) ) + {} + +}; // QualitySSIM +} // quality +} // cv +#endif \ No newline at end of file diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/map.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/map.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a885a2844b1879e299b89fe05a621aa20b197d02 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/map.hpp @@ -0,0 +1,175 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAP_H_ +#define MAP_H_ + +#include // Basic OpenCV structures (cv::Mat, Scalar) + +/** @defgroup reg Image Registration + +The Registration module implements parametric image registration. The implemented method is direct +alignment, that is, it uses directly the pixel values for calculating the registration between a +pair of images, as opposed to feature-based registration. The implementation follows essentially the +corresponding part of @cite Szeliski06 . + +Feature based methods have some advantages over pixel based methods when we are trying to register +pictures that have been shoot under different lighting conditions or exposition times, or when the +images overlap only partially. On the other hand, the main advantage of pixel-based methods when +compared to feature based methods is their better precision for some pictures (those shoot under +similar lighting conditions and that have a significative overlap), due to the fact that we are +using all the information available in the image, which allows us to achieve subpixel accuracy. This +is particularly important for certain applications like multi-frame denoising or super-resolution. + +In fact, pixel and feature registration methods can complement each other: an application could +first obtain a coarse registration using features and then refine the registration using a pixel +based method on the overlapping area of the images. The code developed allows this use case. + +The module implements classes derived from the abstract classes cv::reg::Map or cv::reg::Mapper. The +former models a coordinate transformation between two reference frames, while the later encapsulates +a way of invoking a method that calculates a Map between two images. Although the objective has been +to implement pixel based methods, the module can be extended to support other methods that can +calculate transformations between images (feature methods, optical flow, etc.). + +Each class derived from Map implements a motion model, as follows: + +- MapShift: Models a simple translation +- MapAffine: Models an affine transformation +- MapProjec: Models a projective transformation + +MapProject can also be used to model affine motion or translations, but some operations on it are +more costly, and that is the reason for defining the other two classes. + +The classes derived from Mapper are + +- MapperGradShift: Gradient based alignment for calculating translations. It produces a MapShift + (two parameters that correspond to the shift vector). +- MapperGradEuclid: Gradient based alignment for euclidean motions, that is, rotations and + translations. It calculates three parameters (angle and shift vector), although the result is + stored in a MapAffine object for convenience. +- MapperGradSimilar: Gradient based alignment for calculating similarities, which adds scaling to + the euclidean motion. It calculates four parameters (two for the anti-symmetric matrix and two + for the shift vector), although the result is stored in a MapAffine object for better + convenience. +- MapperGradAffine: Gradient based alignment for an affine motion model. The number of parameters + is six and the result is stored in a MapAffine object. +- MapperGradProj: Gradient based alignment for calculating projective transformations. The number + of parameters is eight and the result is stored in a MapProject object. +- MapperPyramid: It implements hyerarchical motion estimation using a Gaussian pyramid. Its + constructor accepts as argument any other object that implements the Mapper interface, and it is + that mapper the one called by MapperPyramid for each scale of the pyramid. + +If the motion between the images is not very small, the normal way of using these classes is to +create a MapperGrad\* object and use it as input to create a MapperPyramid, which in turn is called +to perform the calculation. However, if the motion between the images is small enough, we can use +directly the MapperGrad\* classes. Another possibility is to use first a feature based method to +perform a coarse registration and then do a refinement through MapperPyramid or directly a +MapperGrad\* object. The "calculate" method of the mappers accepts an initial estimation of the +motion as input. + +When deciding which MapperGrad to use we must take into account that mappers with more parameters +can handle more complex motions, but involve more calculations and are therefore slower. Also, if we +are confident on the motion model that is followed by the sequence, increasing the number of +parameters beyond what we need will decrease the accuracy: it is better to use the least number of +degrees of freedom that we can. + +In the module tests there are examples that show how to register a pair of images using any of the +implemented mappers. +*/ + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/** @brief Base class for modelling a Map between two images. + +The class is only used to define the common interface for any possible map. + */ +class CV_EXPORTS_W Map +{ +public: + /*! + * Virtual destructor + */ + virtual ~Map(); + + /*! + * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T^{-1}(x)), as we + * have to apply the inverse transformation to the points to move them to were the values + * of img2 are. + * \param[in] img1 Original image + * \param[out] img2 Warped image + */ + CV_WRAP virtual void warp(InputArray img1, OutputArray img2) const; + + /*! + * Warps image to a new coordinate frame. The calculation is img2(x)=img1(T(x)), so in fact + * this is the inverse warping as we are taking the value of img1 with the forward + * transformation of the points. + * \param[in] img1 Original image + * \param[out] img2 Warped image + */ + CV_WRAP virtual void inverseWarp(InputArray img1, OutputArray img2) const = 0; + + /*! + * Calculates the inverse map + * \return Inverse map + */ + CV_WRAP virtual cv::Ptr inverseMap() const = 0; + + /*! + * Changes the map composing the current transformation with the one provided in the call. + * The order is first the current transformation, then the input argument. + * \param[in] map Transformation to compose with. + */ + CV_WRAP virtual void compose(cv::Ptr map) = 0; + + /*! + * Scales the map by a given factor as if the coordinates system is expanded/compressed + * by that factor. + * \param[in] factor Expansion if bigger than one, compression if smaller than one + */ + CV_WRAP virtual void scale(double factor) = 0; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAP_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapaffine.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapaffine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..52ab8d6b708e817c5568e631ca76cb08ac1c7f17 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapaffine.hpp @@ -0,0 +1,113 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPAFFINE_H_ +#define MAPAFFINE_H_ + +#include "map.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Defines an affine transformation + */ +class CV_EXPORTS_W MapAffine : public Map +{ +public: + /*! + * Default constructor builds an identity map + */ + CV_WRAP MapAffine(); + + /*! + * Constructor providing explicit values + * \param[in] linTr Linear part of the affine transformation + * \param[in] shift Displacement part of the affine transformation + */ + CV_WRAP MapAffine(InputArray linTr, InputArray shift); + + /*! + * Destructor + */ + ~MapAffine(); + + CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; + + CV_WRAP cv::Ptr inverseMap() const CV_OVERRIDE; + + CV_WRAP void compose(cv::Ptr map) CV_OVERRIDE; + + CV_WRAP void scale(double factor) CV_OVERRIDE; + + /*! + * Return linear part of the affine transformation + * \return Linear part of the affine transformation + */ + const cv::Matx& getLinTr() const { + return linTr_; + } + + CV_WRAP void getLinTr(OutputArray linTr) const { + Mat(linTr_).copyTo(linTr); + } + + /*! + * Return displacement part of the affine transformation + * \return Displacement part of the affine transformation + */ + const cv::Vec& getShift() const { + return shift_; + } + + CV_WRAP void getShift(OutputArray shift) const { + Mat(shift_).copyTo(shift); + } + +private: + cv::Matx linTr_; + cv::Vec shift_; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPAFFINE_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapper.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapper.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2c2862d49dc39cf6f5a8011faf7de0d7910b05e3 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapper.hpp @@ -0,0 +1,113 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPER_H_ +#define MAPPER_H_ + +#include // Basic OpenCV structures (cv::Mat, Scalar) +#include "map.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/** @brief Base class for modelling an algorithm for calculating a map + +The class is only used to define the common interface for any possible mapping algorithm. + */ +class CV_EXPORTS_W Mapper +{ +public: + virtual ~Mapper(void) {} + + /* + * Calculate mapping between two images + * \param[in] img1 Reference image + * \param[in] img2 Warped image + * \param[in] If present, it is an initial rough estimation that the mapper will try to refine. + * \return Map from img1 to img2, stored in a smart pointer. + */ + CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const = 0; + + /* + * Returns a map compatible with the Mapper class + * \return Pointer to identity Map + */ + CV_WRAP virtual cv::Ptr getMap() const = 0; + +protected: + /* + * Calculates gradient and difference between images + * \param[in] img1 Image one + * \param[in] img2 Image two + * \param[out] Ix Gradient x-coordinate + * \param[out] Iy Gradient y-coordinate + * \param[out] It Difference of images + */ + void gradient(const cv::Mat& img1, const cv::Mat& img2, + cv::Mat& Ix, cv::Mat& Iy, cv::Mat& It) const; + + /* + * Fills matrices with pixel coordinates of an image + * \param[in] img Image + * \param[out] grid_r Row (y-coordinate) + * \param[out] grid_c Column (x-coordinate) + */ + void grid(const Mat& img, Mat& grid_r, Mat& grid_c) const; + + /* + * Per-element square of a matrix + * \param[in] mat1 Input matrix + * \return mat1[i,j]^2 + */ + cv::Mat sqr(const cv::Mat& mat1) const + { + cv::Mat res; + res.create(mat1.size(), mat1.type()); + res = mat1.mul(mat1); + return res; + } +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPER_H_ + diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradaffine.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradaffine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..49b0bc7bcdfb4c1aad1868146bdc51c6e9789f8f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradaffine.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPERGRADAFFINE_H_ +#define MAPPERGRADAFFINE_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Mapper for affine motion + */ +class CV_EXPORTS_W MapperGradAffine: public Mapper +{ +public: + CV_WRAP MapperGradAffine(); + ~MapperGradAffine(void); + + CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADAFFINE_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradeuclid.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradeuclid.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4f6c5c8f18e60aeea927309b9224139595393bdd --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradeuclid.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPERGRADEUCLID_H_ +#define MAPPERGRADEUCLID_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Mapper for euclidean motion: rotation plus shift + */ +class CV_EXPORTS_W MapperGradEuclid: public Mapper +{ +public: + CV_WRAP MapperGradEuclid(); + ~MapperGradEuclid(); + + CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADEUCLID_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradproj.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradproj.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1e01c71bf65b34107048735f590582c7dbc5c3fe --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradproj.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPERGRADPROJ_H_ +#define MAPPERGRADPROJ_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Gradient mapper for a projective transformation + */ +class CV_EXPORTS_W MapperGradProj: public Mapper +{ +public: + CV_WRAP MapperGradProj(); + ~MapperGradProj(); + + CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADPROJ_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradshift.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradshift.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cd812d98683e2192ccdb7c91edd6529b08a04bbc --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradshift.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPERGRADSHIFT_H_ +#define MAPPERGRADSHIFT_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Gradient mapper for a translation + */ +class CV_EXPORTS_W MapperGradShift: public Mapper +{ +public: + CV_WRAP MapperGradShift(); + virtual ~MapperGradShift(); + + CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADSHIFT_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradsimilar.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradsimilar.hpp new file mode 100644 index 0000000000000000000000000000000000000000..07d64d9674a65a1e3e49fac893f35a2d6b63de7f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mappergradsimilar.hpp @@ -0,0 +1,67 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPERGRADSIMILAR_H_ +#define MAPPERGRADSIMILAR_H_ + +#include "mapper.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Calculates a similarity transformation between to images (scale, rotation, and shift) + */ +class CV_EXPORTS_W MapperGradSimilar: public Mapper +{ +public: + CV_WRAP MapperGradSimilar(); + ~MapperGradSimilar(); + + CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERGRADSIMILAR_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapperpyramid.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapperpyramid.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6106f49b98b3914bba72402872100499e9fd2f22 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapperpyramid.hpp @@ -0,0 +1,105 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPERPYRAMID_H_ +#define MAPPERPYRAMID_H_ + +#include "mapper.hpp" +#include "mapaffine.hpp" +#include "mapprojec.hpp" +#include "mapshift.hpp" + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Calculates a map using a gaussian pyramid + */ +class CV_EXPORTS_W MapperPyramid: public Mapper +{ +public: + /* + * Constructor + * \param[in] baseMapper Base mapper used for the refinements + */ + CV_WRAP MapperPyramid(Ptr baseMapper); + + CV_WRAP virtual cv::Ptr calculate(InputArray img1, InputArray img2, cv::Ptr init = cv::Ptr()) const CV_OVERRIDE; + + CV_WRAP cv::Ptr getMap() const CV_OVERRIDE; + + CV_PROP_RW int numLev_; /*!< Number of levels of the pyramid */ + CV_PROP_RW int numIterPerScale_; /*!< Number of iterations at a given scale of the pyramid */ + +private: + MapperPyramid& operator=(const MapperPyramid&); + const Mapper& baseMapper_; /*!< Mapper used in inner level */ +}; + +/*! + * Converts a pointer to a Map returned by MapperPyramid::calculate into the specified Map pointer type + */ +class CV_EXPORTS_W MapTypeCaster +{ +public: + CV_WRAP static Ptr toAffine(Ptr sourceMap) + { + MapAffine& affineMap = dynamic_cast(*sourceMap); + return Ptr(new MapAffine(affineMap)); + } + + CV_WRAP static Ptr toShift(Ptr sourceMap) + { + MapShift& shiftMap = dynamic_cast(*sourceMap); + return Ptr(new MapShift(shiftMap)); + } + + CV_WRAP static Ptr toProjec(Ptr sourceMap) + { + MapProjec& projecMap = dynamic_cast(*sourceMap); + return Ptr(new MapProjec(projecMap)); + } +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPERPYRAMID_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapprojec.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapprojec.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6d1e565e0b7411d62181d50e1c001c59b947407e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapprojec.hpp @@ -0,0 +1,109 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPPROJEC_H_ +#define MAPPROJEC_H_ + +#include "map.hpp" + + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Defines an transformation that consists on a projective transformation + */ +class CV_EXPORTS_W MapProjec : public Map +{ +public: + /*! + * Default constructor builds an identity map + */ + CV_WRAP MapProjec(); + + /*! + * Constructor providing explicit values + * \param[in] projTr Projective transformation + */ + CV_WRAP MapProjec(InputArray projTr); + + /*! + * Destructor + */ + ~MapProjec(); + + CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; + + CV_WRAP cv::Ptr inverseMap() const CV_OVERRIDE; + + CV_WRAP void compose(cv::Ptr map) CV_OVERRIDE; + + CV_WRAP void scale(double factor) CV_OVERRIDE; + + /*! + * Returns projection matrix + * \return Projection matrix + */ + const cv::Matx& getProjTr() const { + return projTr_; + } + + CV_WRAP void getProjTr(OutputArray projTr) const { + Mat(projTr_).copyTo(projTr); + } + + /*! + * Normalizes object's homography + */ + CV_WRAP void normalize() { + double z = 1./projTr_(2, 2); + for(size_t v_i = 0; v_i < sizeof(projTr_.val)/sizeof(projTr_.val[0]); ++v_i) + projTr_.val[v_i] *= z; + } + +private: + cv::Matx projTr_; /*< Projection matrix */ +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPPROJEC_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapshift.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapshift.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ada9545017118db404edeeee66d347ba4d724d8e --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/reg/mapshift.hpp @@ -0,0 +1,101 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// Copyright (C) 2013, Alfonso Sanchez-Beato, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef MAPSHIFT_H_ +#define MAPSHIFT_H_ + +#include "map.hpp" + + +namespace cv { +namespace reg { + +//! @addtogroup reg +//! @{ + +/*! + * Defines an transformation that consists on a simple displacement + */ +class CV_EXPORTS_W MapShift : public Map +{ +public: + /*! + * Default constructor builds an identity map + */ + CV_WRAP MapShift(); + + /*! + * Constructor providing explicit values + * \param[in] shift Displacement + */ + + CV_WRAP MapShift(InputArray shift); + + /*! + * Destructor + */ + ~MapShift(); + + CV_WRAP void inverseWarp(InputArray img1, OutputArray img2) const CV_OVERRIDE; + + CV_WRAP cv::Ptr inverseMap() const CV_OVERRIDE; + + CV_WRAP void compose(cv::Ptr map) CV_OVERRIDE; + + CV_WRAP void scale(double factor) CV_OVERRIDE; + + /*! + * Return displacement + * \return Displacement + */ + const cv::Vec& getShift() const { + return shift_; + } + + CV_WRAP void getShift(OutputArray shift) const { + Mat(shift_).copyTo(shift); + } + +private: + cv::Vec shift_; /*< Displacement */ +}; + +//! @} + +}} // namespace cv::reg + +#endif // MAPSHIFT_H_ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd.hpp new file mode 100644 index 0000000000000000000000000000000000000000..37b2927cdcff0320fff54961d1f2a1fe27a99038 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd.hpp @@ -0,0 +1,23 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This code is also subject to the license terms in the LICENSE_KinectFusion.md file found in this module's directory + +// This code is also subject to the license terms in the LICENSE_WillowGarage.md file found in this module's directory + +#ifndef __OPENCV_RGBD_HPP__ +#define __OPENCV_RGBD_HPP__ + +#include "opencv2/rgbd/linemod.hpp" +#include "opencv2/rgbd/depth.hpp" +#include "opencv2/rgbd/kinfu.hpp" +#include "opencv2/rgbd/dynafu.hpp" + + +/** @defgroup rgbd RGB-Depth Processing +*/ + +#endif + +/* End of file. */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/depth.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/depth.hpp new file mode 100644 index 0000000000000000000000000000000000000000..94fdca62036477fe1f517d8a171990ad8ad65315 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/depth.hpp @@ -0,0 +1,1192 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This code is also subject to the license terms in the LICENSE_WillowGarage.md file found in this module's directory + +#ifndef __OPENCV_RGBD_DEPTH_HPP__ +#define __OPENCV_RGBD_DEPTH_HPP__ + +#include +#include + +namespace cv +{ +namespace rgbd +{ + +//! @addtogroup rgbd +//! @{ + + /** Checks if the value is a valid depth. For CV_16U or CV_16S, the convention is to be invalid if it is + * a limit. For a float/double, we just check if it is a NaN + * @param depth the depth to check for validity + */ + CV_EXPORTS + inline bool + isValidDepth(const float & depth) + { + return !cvIsNaN(depth); + } + CV_EXPORTS + inline bool + isValidDepth(const double & depth) + { + return !cvIsNaN(depth); + } + CV_EXPORTS + inline bool + isValidDepth(const short int & depth) + { + return (depth != std::numeric_limits::min()) && (depth != std::numeric_limits::max()); + } + CV_EXPORTS + inline bool + isValidDepth(const unsigned short int & depth) + { + return (depth != std::numeric_limits::min()) + && (depth != std::numeric_limits::max()); + } + CV_EXPORTS + inline bool + isValidDepth(const int & depth) + { + return (depth != std::numeric_limits::min()) && (depth != std::numeric_limits::max()); + } + CV_EXPORTS + inline bool + isValidDepth(const unsigned int & depth) + { + return (depth != std::numeric_limits::min()) && (depth != std::numeric_limits::max()); + } + + /** Object that can compute the normals in an image. + * It is an object as it can cache data for speed efficiency + * The implemented methods are either: + * - FALS (the fastest) and SRI from + * ``Fast and Accurate Computation of Surface Normals from Range Images`` + * by H. Badino, D. Huber, Y. Park and T. Kanade + * - the normals with bilateral filtering on a depth image from + * ``Gradient Response Maps for Real-Time Detection of Texture-Less Objects`` + * by S. Hinterstoisser, C. Cagniart, S. Ilic, P. Sturm, N. Navab, P. Fua, and V. Lepetit + */ + class CV_EXPORTS_W RgbdNormals: public Algorithm + { + public: + enum RGBD_NORMALS_METHOD + { + RGBD_NORMALS_METHOD_FALS = 0, + RGBD_NORMALS_METHOD_LINEMOD = 1, + RGBD_NORMALS_METHOD_SRI = 2 + }; + + RgbdNormals() + : + rows_(0), + cols_(0), + depth_(0), + K_(Mat()), + window_size_(0), + method_(RGBD_NORMALS_METHOD_FALS), + rgbd_normals_impl_(0) + { + } + + /** Constructor + * @param rows the number of rows of the depth image normals will be computed on + * @param cols the number of cols of the depth image normals will be computed on + * @param depth the depth of the normals (only CV_32F or CV_64F) + * @param K the calibration matrix to use + * @param window_size the window size to compute the normals: can only be 1,3,5 or 7 + * @param method one of the methods to use: RGBD_NORMALS_METHOD_SRI, RGBD_NORMALS_METHOD_FALS + */ + RgbdNormals(int rows, int cols, int depth, InputArray K, int window_size = 5, int method = + RgbdNormals::RGBD_NORMALS_METHOD_FALS); + + ~RgbdNormals(); + + CV_WRAP static Ptr create(int rows, int cols, int depth, InputArray K, int window_size = 5, int method = + RgbdNormals::RGBD_NORMALS_METHOD_FALS); + + /** Given a set of 3d points in a depth image, compute the normals at each point. + * @param points a rows x cols x 3 matrix of CV_32F/CV64F or a rows x cols x 1 CV_U16S + * @param normals a rows x cols x 3 matrix + */ + CV_WRAP_AS(apply) void + operator()(InputArray points, OutputArray normals) const; + + /** Initializes some data that is cached for later computation + * If that function is not called, it will be called the first time normals are computed + */ + CV_WRAP void + initialize() const; + + CV_WRAP int getRows() const + { + return rows_; + } + CV_WRAP void setRows(int val) + { + rows_ = val; + } + CV_WRAP int getCols() const + { + return cols_; + } + CV_WRAP void setCols(int val) + { + cols_ = val; + } + CV_WRAP int getWindowSize() const + { + return window_size_; + } + CV_WRAP void setWindowSize(int val) + { + window_size_ = val; + } + CV_WRAP int getDepth() const + { + return depth_; + } + CV_WRAP void setDepth(int val) + { + depth_ = val; + } + CV_WRAP cv::Mat getK() const + { + return K_; + } + CV_WRAP void setK(const cv::Mat &val) + { + K_ = val; + } + CV_WRAP int getMethod() const + { + return method_; + } + CV_WRAP void setMethod(int val) + { + method_ = val; + } + + protected: + void + initialize_normals_impl(int rows, int cols, int depth, const Mat & K, int window_size, int method) const; + + int rows_, cols_, depth_; + Mat K_; + int window_size_; + int method_; + mutable void* rgbd_normals_impl_; + }; + + /** Object that can clean a noisy depth image + */ + class CV_EXPORTS_W DepthCleaner: public Algorithm + { + public: + /** NIL method is from + * ``Modeling Kinect Sensor Noise for Improved 3d Reconstruction and Tracking`` + * by C. Nguyen, S. Izadi, D. Lovel + */ + enum DEPTH_CLEANER_METHOD + { + DEPTH_CLEANER_NIL + }; + + DepthCleaner() + : + depth_(0), + window_size_(0), + method_(DEPTH_CLEANER_NIL), + depth_cleaner_impl_(0) + { + } + + /** Constructor + * @param depth the depth of the normals (only CV_32F or CV_64F) + * @param window_size the window size to compute the normals: can only be 1,3,5 or 7 + * @param method one of the methods to use: RGBD_NORMALS_METHOD_SRI, RGBD_NORMALS_METHOD_FALS + */ + DepthCleaner(int depth, int window_size = 5, int method = DepthCleaner::DEPTH_CLEANER_NIL); + + ~DepthCleaner(); + + CV_WRAP static Ptr create(int depth, int window_size = 5, int method = DepthCleaner::DEPTH_CLEANER_NIL); + + /** Given a set of 3d points in a depth image, compute the normals at each point. + * @param points a rows x cols x 3 matrix of CV_32F/CV64F or a rows x cols x 1 CV_U16S + * @param depth a rows x cols matrix of the cleaned up depth + */ + CV_WRAP_AS(apply) void + operator()(InputArray points, OutputArray depth) const; + + /** Initializes some data that is cached for later computation + * If that function is not called, it will be called the first time normals are computed + */ + CV_WRAP void + initialize() const; + + CV_WRAP int getWindowSize() const + { + return window_size_; + } + CV_WRAP void setWindowSize(int val) + { + window_size_ = val; + } + CV_WRAP int getDepth() const + { + return depth_; + } + CV_WRAP void setDepth(int val) + { + depth_ = val; + } + CV_WRAP int getMethod() const + { + return method_; + } + CV_WRAP void setMethod(int val) + { + method_ = val; + } + + protected: + void + initialize_cleaner_impl() const; + + int depth_; + int window_size_; + int method_; + mutable void* depth_cleaner_impl_; + }; + + + /** Registers depth data to an external camera + * Registration is performed by creating a depth cloud, transforming the cloud by + * the rigid body transformation between the cameras, and then projecting the + * transformed points into the RGB camera. + * + * uv_rgb = K_rgb * [R | t] * z * inv(K_ir) * uv_ir + * + * Currently does not check for negative depth values. + * + * @param unregisteredCameraMatrix the camera matrix of the depth camera + * @param registeredCameraMatrix the camera matrix of the external camera + * @param registeredDistCoeffs the distortion coefficients of the external camera + * @param Rt the rigid body transform between the cameras. Transforms points from depth camera frame to external camera frame. + * @param unregisteredDepth the input depth data + * @param outputImagePlaneSize the image plane dimensions of the external camera (width, height) + * @param registeredDepth the result of transforming the depth into the external camera + * @param depthDilation whether or not the depth is dilated to avoid holes and occlusion errors (optional) + */ + CV_EXPORTS_W + void + registerDepth(InputArray unregisteredCameraMatrix, InputArray registeredCameraMatrix, InputArray registeredDistCoeffs, + InputArray Rt, InputArray unregisteredDepth, const Size& outputImagePlaneSize, + OutputArray registeredDepth, bool depthDilation=false); + + /** + * @param depth the depth image + * @param in_K + * @param in_points the list of xy coordinates + * @param points3d the resulting 3d points + */ + CV_EXPORTS_W + void + depthTo3dSparse(InputArray depth, InputArray in_K, InputArray in_points, OutputArray points3d); + + /** Converts a depth image to an organized set of 3d points. + * The coordinate system is x pointing left, y down and z away from the camera + * @param depth the depth image (if given as short int CV_U, it is assumed to be the depth in millimeters + * (as done with the Microsoft Kinect), otherwise, if given as CV_32F or CV_64F, it is assumed in meters) + * @param K The calibration matrix + * @param points3d the resulting 3d points. They are of depth the same as `depth` if it is CV_32F or CV_64F, and the + * depth of `K` if `depth` is of depth CV_U + * @param mask the mask of the points to consider (can be empty) + */ + CV_EXPORTS_W + void + depthTo3d(InputArray depth, InputArray K, OutputArray points3d, InputArray mask = noArray()); + + /** If the input image is of type CV_16UC1 (like the Kinect one), the image is converted to floats, divided + * by 1000 to get a depth in meters, and the values 0 are converted to std::numeric_limits::quiet_NaN() + * Otherwise, the image is simply converted to floats + * @param in the depth image (if given as short int CV_U, it is assumed to be the depth in millimeters + * (as done with the Microsoft Kinect), it is assumed in meters) + * @param depth the desired output depth (floats or double) + * @param out The rescaled float depth image + */ + CV_EXPORTS_W + void + rescaleDepth(InputArray in, int depth, OutputArray out); + + /** Object that can compute planes in an image + */ + class CV_EXPORTS_W RgbdPlane: public Algorithm + { + public: + enum RGBD_PLANE_METHOD + { + RGBD_PLANE_METHOD_DEFAULT + }; + + RgbdPlane(int method = RgbdPlane::RGBD_PLANE_METHOD_DEFAULT) + : + method_(method), + block_size_(40), + min_size_(block_size_*block_size_), + threshold_(0.01), + sensor_error_a_(0), + sensor_error_b_(0), + sensor_error_c_(0) + { + } + + /** Constructor + * @param block_size The size of the blocks to look at for a stable MSE + * @param min_size The minimum size of a cluster to be considered a plane + * @param threshold The maximum distance of a point from a plane to belong to it (in meters) + * @param sensor_error_a coefficient of the sensor error. 0 by default, 0.0075 for a Kinect + * @param sensor_error_b coefficient of the sensor error. 0 by default + * @param sensor_error_c coefficient of the sensor error. 0 by default + * @param method The method to use to compute the planes. + */ + RgbdPlane(int method, int block_size, + int min_size, double threshold, double sensor_error_a = 0, + double sensor_error_b = 0, double sensor_error_c = 0); + + ~RgbdPlane(); + + CV_WRAP static Ptr create(int method, int block_size, int min_size, double threshold, + double sensor_error_a = 0, double sensor_error_b = 0, + double sensor_error_c = 0); + + /** Find The planes in a depth image + * @param points3d the 3d points organized like the depth image: rows x cols with 3 channels + * @param normals the normals for every point in the depth image + * @param mask An image where each pixel is labeled with the plane it belongs to + * and 255 if it does not belong to any plane + * @param plane_coefficients the coefficients of the corresponding planes (a,b,c,d) such that ax+by+cz+d=0, norm(a,b,c)=1 + * and c < 0 (so that the normal points towards the camera) + */ + CV_WRAP_AS(apply) void + operator()(InputArray points3d, InputArray normals, OutputArray mask, + OutputArray plane_coefficients); + + /** Find The planes in a depth image but without doing a normal check, which is faster but less accurate + * @param points3d the 3d points organized like the depth image: rows x cols with 3 channels + * @param mask An image where each pixel is labeled with the plane it belongs to + * and 255 if it does not belong to any plane + * @param plane_coefficients the coefficients of the corresponding planes (a,b,c,d) such that ax+by+cz+d=0 + */ + CV_WRAP_AS(apply) void + operator()(InputArray points3d, OutputArray mask, OutputArray plane_coefficients); + + CV_WRAP int getBlockSize() const + { + return block_size_; + } + CV_WRAP void setBlockSize(int val) + { + block_size_ = val; + } + CV_WRAP int getMinSize() const + { + return min_size_; + } + CV_WRAP void setMinSize(int val) + { + min_size_ = val; + } + CV_WRAP int getMethod() const + { + return method_; + } + CV_WRAP void setMethod(int val) + { + method_ = val; + } + CV_WRAP double getThreshold() const + { + return threshold_; + } + CV_WRAP void setThreshold(double val) + { + threshold_ = val; + } + CV_WRAP double getSensorErrorA() const + { + return sensor_error_a_; + } + CV_WRAP void setSensorErrorA(double val) + { + sensor_error_a_ = val; + } + CV_WRAP double getSensorErrorB() const + { + return sensor_error_b_; + } + CV_WRAP void setSensorErrorB(double val) + { + sensor_error_b_ = val; + } + CV_WRAP double getSensorErrorC() const + { + return sensor_error_c_; + } + CV_WRAP void setSensorErrorC(double val) + { + sensor_error_c_ = val; + } + + private: + /** The method to use to compute the planes */ + int method_; + /** The size of the blocks to look at for a stable MSE */ + int block_size_; + /** The minimum size of a cluster to be considered a plane */ + int min_size_; + /** How far a point can be from a plane to belong to it (in meters) */ + double threshold_; + /** coefficient of the sensor error with respect to the. All 0 by default but you want a=0.0075 for a Kinect */ + double sensor_error_a_, sensor_error_b_, sensor_error_c_; + }; + + /** Object that contains a frame data. + */ + struct CV_EXPORTS_W RgbdFrame + { + RgbdFrame(); + RgbdFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + virtual ~RgbdFrame(); + + CV_WRAP static Ptr create(const Mat& image=Mat(), const Mat& depth=Mat(), const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + + CV_WRAP virtual void + release(); + + CV_PROP int ID; + CV_PROP Mat image; + CV_PROP Mat depth; + CV_PROP Mat mask; + CV_PROP Mat normals; + }; + + /** Object that contains a frame data that is possibly needed for the Odometry. + * It's used for the efficiency (to pass precomputed/cached data of the frame that participates + * in the Odometry processing several times). + */ + struct CV_EXPORTS_W OdometryFrame : public RgbdFrame + { + /** These constants are used to set a type of cache which has to be prepared depending on the frame role: + * srcFrame or dstFrame (see compute method of the Odometry class). For the srcFrame and dstFrame different cache data may be required, + * some part of a cache may be common for both frame roles. + * @param CACHE_SRC The cache data for the srcFrame will be prepared. + * @param CACHE_DST The cache data for the dstFrame will be prepared. + * @param CACHE_ALL The cache data for both srcFrame and dstFrame roles will be computed. + */ + enum + { + CACHE_SRC = 1, CACHE_DST = 2, CACHE_ALL = CACHE_SRC + CACHE_DST + }; + + OdometryFrame(); + OdometryFrame(const Mat& image, const Mat& depth, const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + + CV_WRAP static Ptr create(const Mat& image=Mat(), const Mat& depth=Mat(), const Mat& mask=Mat(), const Mat& normals=Mat(), int ID=-1); + + CV_WRAP virtual void + release() CV_OVERRIDE; + + CV_WRAP void + releasePyramids(); + + CV_PROP std::vector pyramidImage; + CV_PROP std::vector pyramidDepth; + CV_PROP std::vector pyramidMask; + + CV_PROP std::vector pyramidCloud; + + CV_PROP std::vector pyramid_dI_dx; + CV_PROP std::vector pyramid_dI_dy; + CV_PROP std::vector pyramidTexturedMask; + + CV_PROP std::vector pyramidNormals; + CV_PROP std::vector pyramidNormalsMask; + }; + + /** Base class for computation of odometry. + */ + class CV_EXPORTS_W Odometry: public Algorithm + { + public: + + /** A class of transformation*/ + enum + { + ROTATION = 1, TRANSLATION = 2, RIGID_BODY_MOTION = 4 + }; + + CV_WRAP static inline float + DEFAULT_MIN_DEPTH() + { + return 0.f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_DEPTH() + { + return 4.f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_DEPTH_DIFF() + { + return 0.07f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_POINTS_PART() + { + return 0.07f; // in [0, 1] + } + CV_WRAP static inline float + DEFAULT_MAX_TRANSLATION() + { + return 0.15f; // in meters + } + CV_WRAP static inline float + DEFAULT_MAX_ROTATION() + { + return 15; // in degrees + } + + /** Method to compute a transformation from the source frame to the destination one. + * Some odometry algorithms do not used some data of frames (eg. ICP does not use images). + * In such case corresponding arguments can be set as empty Mat. + * The method returns true if all internal computions were possible (e.g. there were enough correspondences, + * system of equations has a solution, etc) and resulting transformation satisfies some test if it's provided + * by the Odometry inheritor implementation (e.g. thresholds for maximum translation and rotation). + * @param srcImage Image data of the source frame (CV_8UC1) + * @param srcDepth Depth data of the source frame (CV_32FC1, in meters) + * @param srcMask Mask that sets which pixels have to be used from the source frame (CV_8UC1) + * @param dstImage Image data of the destination frame (CV_8UC1) + * @param dstDepth Depth data of the destination frame (CV_32FC1, in meters) + * @param dstMask Mask that sets which pixels have to be used from the destination frame (CV_8UC1) + * @param Rt Resulting transformation from the source frame to the destination one (rigid body motion): + dst_p = Rt * src_p, where dst_p is a homogeneous point in the destination frame and src_p is + homogeneous point in the source frame, + Rt is 4x4 matrix of CV_64FC1 type. + * @param initRt Initial transformation from the source frame to the destination one (optional) + */ + CV_WRAP bool + compute(const Mat& srcImage, const Mat& srcDepth, const Mat& srcMask, const Mat& dstImage, const Mat& dstDepth, + const Mat& dstMask, OutputArray Rt, const Mat& initRt = Mat()) const; + + /** One more method to compute a transformation from the source frame to the destination one. + * It is designed to save on computing the frame data (image pyramids, normals, etc.). + */ + CV_WRAP_AS(compute2) bool + compute(Ptr& srcFrame, Ptr& dstFrame, OutputArray Rt, const Mat& initRt = Mat()) const; + + /** Prepare a cache for the frame. The function checks the precomputed/passed data (throws the error if this data + * does not satisfy) and computes all remaining cache data needed for the frame. Returned size is a resolution + * of the prepared frame. + * @param frame The odometry which will process the frame. + * @param cacheType The cache type: CACHE_SRC, CACHE_DST or CACHE_ALL. + */ + CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const; + + CV_WRAP static Ptr create(const String & odometryType); + + /** @see setCameraMatrix */ + CV_WRAP virtual cv::Mat getCameraMatrix() const = 0; + /** @copybrief getCameraMatrix @see getCameraMatrix */ + CV_WRAP virtual void setCameraMatrix(const cv::Mat &val) = 0; + /** @see setTransformType */ + CV_WRAP virtual int getTransformType() const = 0; + /** @copybrief getTransformType @see getTransformType */ + CV_WRAP virtual void setTransformType(int val) = 0; + + protected: + virtual void + checkParams() const = 0; + + virtual bool + computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, + const Mat& initRt) const = 0; + }; + + /** Odometry based on the paper "Real-Time Visual Odometry from Dense RGB-D Images", + * F. Steinbucker, J. Strum, D. Cremers, ICCV, 2011. + */ + class CV_EXPORTS_W RgbdOdometry: public Odometry + { + public: + RgbdOdometry(); + /** Constructor. + * @param cameraMatrix Camera matrix + * @param minDepth Pixels with depth less than minDepth will not be used (in meters) + * @param maxDepth Pixels with depth larger than maxDepth will not be used (in meters) + * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out + * if their depth difference is larger than maxDepthDiff (in meters) + * @param iterCounts Count of iterations on each pyramid level. + * @param minGradientMagnitudes For each pyramid level the pixels will be filtered out + * if they have gradient magnitude less than minGradientMagnitudes[level]. + * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart + * @param transformType Class of transformation + */ + RgbdOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), const std::vector& iterCounts = std::vector(), + const std::vector& minGradientMagnitudes = std::vector(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP static Ptr create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), const std::vector& iterCounts = std::vector(), + const std::vector& minGradientMagnitudes = std::vector(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const CV_OVERRIDE; + + CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE + { + return cameraMatrix; + } + CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE + { + cameraMatrix = val; + } + CV_WRAP double getMinDepth() const + { + return minDepth; + } + CV_WRAP void setMinDepth(double val) + { + minDepth = val; + } + CV_WRAP double getMaxDepth() const + { + return maxDepth; + } + CV_WRAP void setMaxDepth(double val) + { + maxDepth = val; + } + CV_WRAP double getMaxDepthDiff() const + { + return maxDepthDiff; + } + CV_WRAP void setMaxDepthDiff(double val) + { + maxDepthDiff = val; + } + CV_WRAP cv::Mat getIterationCounts() const + { + return iterCounts; + } + CV_WRAP void setIterationCounts(const cv::Mat &val) + { + iterCounts = val; + } + CV_WRAP cv::Mat getMinGradientMagnitudes() const + { + return minGradientMagnitudes; + } + CV_WRAP void setMinGradientMagnitudes(const cv::Mat &val) + { + minGradientMagnitudes = val; + } + CV_WRAP double getMaxPointsPart() const + { + return maxPointsPart; + } + CV_WRAP void setMaxPointsPart(double val) + { + maxPointsPart = val; + } + CV_WRAP int getTransformType() const CV_OVERRIDE + { + return transformType; + } + CV_WRAP void setTransformType(int val) CV_OVERRIDE + { + transformType = val; + } + CV_WRAP double getMaxTranslation() const + { + return maxTranslation; + } + CV_WRAP void setMaxTranslation(double val) + { + maxTranslation = val; + } + CV_WRAP double getMaxRotation() const + { + return maxRotation; + } + CV_WRAP void setMaxRotation(double val) + { + maxRotation = val; + } + + protected: + virtual void + checkParams() const CV_OVERRIDE; + + virtual bool + computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, + const Mat& initRt) const CV_OVERRIDE; + + // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. + /*float*/ + double minDepth, maxDepth, maxDepthDiff; + /*vector*/ + Mat iterCounts; + /*vector*/ + Mat minGradientMagnitudes; + double maxPointsPart; + + Mat cameraMatrix; + int transformType; + + double maxTranslation, maxRotation; + }; + + /** Odometry based on the paper "KinectFusion: Real-Time Dense Surface Mapping and Tracking", + * Richard A. Newcombe, Andrew Fitzgibbon, at al, SIGGRAPH, 2011. + */ + class CV_EXPORTS_W ICPOdometry: public Odometry + { + public: + ICPOdometry(); + /** Constructor. + * @param cameraMatrix Camera matrix + * @param minDepth Pixels with depth less than minDepth will not be used + * @param maxDepth Pixels with depth larger than maxDepth will not be used + * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out + * if their depth difference is larger than maxDepthDiff + * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart + * @param iterCounts Count of iterations on each pyramid level. + * @param transformType Class of trasformation + */ + ICPOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector& iterCounts = std::vector(), int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP static Ptr create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector& iterCounts = std::vector(), int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const CV_OVERRIDE; + + CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE + { + return cameraMatrix; + } + CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE + { + cameraMatrix = val; + } + CV_WRAP double getMinDepth() const + { + return minDepth; + } + CV_WRAP void setMinDepth(double val) + { + minDepth = val; + } + CV_WRAP double getMaxDepth() const + { + return maxDepth; + } + CV_WRAP void setMaxDepth(double val) + { + maxDepth = val; + } + CV_WRAP double getMaxDepthDiff() const + { + return maxDepthDiff; + } + CV_WRAP void setMaxDepthDiff(double val) + { + maxDepthDiff = val; + } + CV_WRAP cv::Mat getIterationCounts() const + { + return iterCounts; + } + CV_WRAP void setIterationCounts(const cv::Mat &val) + { + iterCounts = val; + } + CV_WRAP double getMaxPointsPart() const + { + return maxPointsPart; + } + CV_WRAP void setMaxPointsPart(double val) + { + maxPointsPart = val; + } + CV_WRAP int getTransformType() const CV_OVERRIDE + { + return transformType; + } + CV_WRAP void setTransformType(int val) CV_OVERRIDE + { + transformType = val; + } + CV_WRAP double getMaxTranslation() const + { + return maxTranslation; + } + CV_WRAP void setMaxTranslation(double val) + { + maxTranslation = val; + } + CV_WRAP double getMaxRotation() const + { + return maxRotation; + } + CV_WRAP void setMaxRotation(double val) + { + maxRotation = val; + } + CV_WRAP Ptr getNormalsComputer() const + { + return normalsComputer; + } + + protected: + virtual void + checkParams() const CV_OVERRIDE; + + virtual bool + computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, + const Mat& initRt) const CV_OVERRIDE; + + // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. + /*float*/ + double minDepth, maxDepth, maxDepthDiff; + /*float*/ + double maxPointsPart; + /*vector*/ + Mat iterCounts; + + Mat cameraMatrix; + int transformType; + + double maxTranslation, maxRotation; + + mutable Ptr normalsComputer; + }; + + /** Odometry that merges RgbdOdometry and ICPOdometry by minimize sum of their energy functions. + */ + + class CV_EXPORTS_W RgbdICPOdometry: public Odometry + { + public: + RgbdICPOdometry(); + /** Constructor. + * @param cameraMatrix Camera matrix + * @param minDepth Pixels with depth less than minDepth will not be used + * @param maxDepth Pixels with depth larger than maxDepth will not be used + * @param maxDepthDiff Correspondences between pixels of two given frames will be filtered out + * if their depth difference is larger than maxDepthDiff + * @param maxPointsPart The method uses a random pixels subset of size frameWidth x frameHeight x pointsPart + * @param iterCounts Count of iterations on each pyramid level. + * @param minGradientMagnitudes For each pyramid level the pixels will be filtered out + * if they have gradient magnitude less than minGradientMagnitudes[level]. + * @param transformType Class of trasformation + */ + RgbdICPOdometry(const Mat& cameraMatrix, float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector& iterCounts = std::vector(), + const std::vector& minGradientMagnitudes = std::vector(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP static Ptr create(const Mat& cameraMatrix = Mat(), float minDepth = Odometry::DEFAULT_MIN_DEPTH(), float maxDepth = Odometry::DEFAULT_MAX_DEPTH(), + float maxDepthDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), float maxPointsPart = Odometry::DEFAULT_MAX_POINTS_PART(), + const std::vector& iterCounts = std::vector(), + const std::vector& minGradientMagnitudes = std::vector(), + int transformType = Odometry::RIGID_BODY_MOTION); + + CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const CV_OVERRIDE; + + CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE + { + return cameraMatrix; + } + CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE + { + cameraMatrix = val; + } + CV_WRAP double getMinDepth() const + { + return minDepth; + } + CV_WRAP void setMinDepth(double val) + { + minDepth = val; + } + CV_WRAP double getMaxDepth() const + { + return maxDepth; + } + CV_WRAP void setMaxDepth(double val) + { + maxDepth = val; + } + CV_WRAP double getMaxDepthDiff() const + { + return maxDepthDiff; + } + CV_WRAP void setMaxDepthDiff(double val) + { + maxDepthDiff = val; + } + CV_WRAP double getMaxPointsPart() const + { + return maxPointsPart; + } + CV_WRAP void setMaxPointsPart(double val) + { + maxPointsPart = val; + } + CV_WRAP cv::Mat getIterationCounts() const + { + return iterCounts; + } + CV_WRAP void setIterationCounts(const cv::Mat &val) + { + iterCounts = val; + } + CV_WRAP cv::Mat getMinGradientMagnitudes() const + { + return minGradientMagnitudes; + } + CV_WRAP void setMinGradientMagnitudes(const cv::Mat &val) + { + minGradientMagnitudes = val; + } + CV_WRAP int getTransformType() const CV_OVERRIDE + { + return transformType; + } + CV_WRAP void setTransformType(int val) CV_OVERRIDE + { + transformType = val; + } + CV_WRAP double getMaxTranslation() const + { + return maxTranslation; + } + CV_WRAP void setMaxTranslation(double val) + { + maxTranslation = val; + } + CV_WRAP double getMaxRotation() const + { + return maxRotation; + } + CV_WRAP void setMaxRotation(double val) + { + maxRotation = val; + } + CV_WRAP Ptr getNormalsComputer() const + { + return normalsComputer; + } + + protected: + virtual void + checkParams() const CV_OVERRIDE; + + virtual bool + computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, + const Mat& initRt) const CV_OVERRIDE; + + // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. + /*float*/ + double minDepth, maxDepth, maxDepthDiff; + /*float*/ + double maxPointsPart; + /*vector*/ + Mat iterCounts; + /*vector*/ + Mat minGradientMagnitudes; + + Mat cameraMatrix; + int transformType; + + double maxTranslation, maxRotation; + + mutable Ptr normalsComputer; + }; + + /** A faster version of ICPOdometry which is used in KinectFusion implementation + * Partial list of differences: + * - Works in parallel + * - Written in universal intrinsics + * - Filters points by angle + * - Interpolates points and normals + * - Doesn't use masks or min/max depth filtering + * - Doesn't use random subsets of points + * - Supports only Rt transform type + * - Supports only 4-float vectors as input type + */ + class CV_EXPORTS_W FastICPOdometry: public Odometry + { + public: + FastICPOdometry(); + /** Constructor. + * @param cameraMatrix Camera matrix + * @param maxDistDiff Correspondences between pixels of two given frames will be filtered out + * if their depth difference is larger than maxDepthDiff + * @param angleThreshold Correspondence will be filtered out + * if an angle between their normals is bigger than threshold + * @param sigmaDepth Depth sigma in meters for bilateral smooth + * @param sigmaSpatial Spatial sigma in pixels for bilateral smooth + * @param kernelSize Kernel size in pixels for bilateral smooth + * @param iterCounts Count of iterations on each pyramid level + */ + FastICPOdometry(const Mat& cameraMatrix, + float maxDistDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), + float angleThreshold = (float)(30. * CV_PI / 180.), + float sigmaDepth = 0.04f, + float sigmaSpatial = 4.5f, + int kernelSize = 7, + const std::vector& iterCounts = std::vector()); + + CV_WRAP static Ptr create(const Mat& cameraMatrix, + float maxDistDiff = Odometry::DEFAULT_MAX_DEPTH_DIFF(), + float angleThreshold = (float)(30. * CV_PI / 180.), + float sigmaDepth = 0.04f, + float sigmaSpatial = 4.5f, + int kernelSize = 7, + const std::vector& iterCounts = std::vector()); + + CV_WRAP virtual Size prepareFrameCache(Ptr& frame, int cacheType) const CV_OVERRIDE; + + CV_WRAP cv::Mat getCameraMatrix() const CV_OVERRIDE + { + return cameraMatrix; + } + CV_WRAP void setCameraMatrix(const cv::Mat &val) CV_OVERRIDE + { + cameraMatrix = val; + } + CV_WRAP double getMaxDistDiff() const + { + return maxDistDiff; + } + CV_WRAP void setMaxDistDiff(float val) + { + maxDistDiff = val; + } + CV_WRAP float getAngleThreshold() const + { + return angleThreshold; + } + CV_WRAP void setAngleThreshold(float f) + { + angleThreshold = f; + } + CV_WRAP float getSigmaDepth() const + { + return sigmaDepth; + } + CV_WRAP void setSigmaDepth(float f) + { + sigmaDepth = f; + } + CV_WRAP float getSigmaSpatial() const + { + return sigmaSpatial; + } + CV_WRAP void setSigmaSpatial(float f) + { + sigmaSpatial = f; + } + CV_WRAP int getKernelSize() const + { + return kernelSize; + } + CV_WRAP void setKernelSize(int f) + { + kernelSize = f; + } + CV_WRAP cv::Mat getIterationCounts() const + { + return iterCounts; + } + CV_WRAP void setIterationCounts(const cv::Mat &val) + { + iterCounts = val; + } + CV_WRAP int getTransformType() const CV_OVERRIDE + { + return Odometry::RIGID_BODY_MOTION; + } + CV_WRAP void setTransformType(int val) CV_OVERRIDE + { + if(val != Odometry::RIGID_BODY_MOTION) + throw std::runtime_error("Rigid Body Motion is the only accepted transformation type" + " for this odometry method"); + } + + protected: + virtual void + checkParams() const CV_OVERRIDE; + + virtual bool + computeImpl(const Ptr& srcFrame, const Ptr& dstFrame, OutputArray Rt, + const Mat& initRt) const CV_OVERRIDE; + + // Some params have commented desired type. It's due to AlgorithmInfo::addParams does not support it now. + float maxDistDiff; + + float angleThreshold; + + float sigmaDepth; + + float sigmaSpatial; + + int kernelSize; + + /*vector*/ + Mat iterCounts; + + Mat cameraMatrix; + }; + + /** Warp the image: compute 3d points from the depth, transform them using given transformation, + * then project color point cloud to an image plane. + * This function can be used to visualize results of the Odometry algorithm. + * @param image The image (of CV_8UC1 or CV_8UC3 type) + * @param depth The depth (of type used in depthTo3d fuction) + * @param mask The mask of used pixels (of CV_8UC1), it can be empty + * @param Rt The transformation that will be applied to the 3d points computed from the depth + * @param cameraMatrix Camera matrix + * @param distCoeff Distortion coefficients + * @param warpedImage The warped image. + * @param warpedDepth The warped depth. + * @param warpedMask The warped mask. + */ + CV_EXPORTS_W + void + warpFrame(const Mat& image, const Mat& depth, const Mat& mask, const Mat& Rt, const Mat& cameraMatrix, + const Mat& distCoeff, OutputArray warpedImage, OutputArray warpedDepth = noArray(), OutputArray warpedMask = noArray()); + +// TODO Depth interpolation +// Curvature +// Get rescaleDepth return dubles if asked for + +//! @} + +} /* namespace rgbd */ +} /* namespace cv */ + +#endif + +/* End of file. */ diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/dynafu.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/dynafu.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d057ebe76c67ea52dde4bd0d445dce5f8ec3fd86 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/dynafu.hpp @@ -0,0 +1,206 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This code is also subject to the license terms in the LICENSE_KinectFusion.md file found in this module's directory + +#ifndef __OPENCV_RGBD_DYNAFU_HPP__ +#define __OPENCV_RGBD_DYNAFU_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/core/affine.hpp" + +namespace cv { +namespace dynafu { + +struct CV_EXPORTS_W Params +{ + /** @brief Default parameters + A set of parameters which provides better model quality, can be very slow. + */ + CV_WRAP static Ptr defaultParams(); + + /** @brief Coarse parameters + A set of parameters which provides better speed, can fail to match frames + in case of rapid sensor motion. + */ + CV_WRAP static Ptr coarseParams(); + + /** @brief frame size in pixels */ + CV_PROP_RW Size frameSize; + + /** @brief camera intrinsics */ + CV_PROP Matx33f intr; + + /** @brief pre-scale per 1 meter for input values + + Typical values are: + * 5000 per 1 meter for the 16-bit PNG files of TUM database + * 1000 per 1 meter for Kinect 2 device + * 1 per 1 meter for the 32-bit float images in the ROS bag files + */ + CV_PROP_RW float depthFactor; + + /** @brief Depth sigma in meters for bilateral smooth */ + CV_PROP_RW float bilateral_sigma_depth; + /** @brief Spatial sigma in pixels for bilateral smooth */ + CV_PROP_RW float bilateral_sigma_spatial; + /** @brief Kernel size in pixels for bilateral smooth */ + CV_PROP_RW int bilateral_kernel_size; + + /** @brief Number of pyramid levels for ICP */ + CV_PROP_RW int pyramidLevels; + + /** @brief Resolution of voxel space + + Number of voxels in each dimension. + */ + CV_PROP_RW Vec3i volumeDims; + /** @brief Size of voxel in meters */ + CV_PROP_RW float voxelSize; + + /** @brief Minimal camera movement in meters + + Integrate new depth frame only if camera movement exceeds this value. + */ + CV_PROP_RW float tsdf_min_camera_movement; + + /** @brief initial volume pose in meters */ + Affine3f volumePose; + + /** @brief distance to truncate in meters + + Distances to surface that exceed this value will be truncated to 1.0. + */ + CV_PROP_RW float tsdf_trunc_dist; + + /** @brief max number of frames per voxel + + Each voxel keeps running average of distances no longer than this value. + */ + CV_PROP_RW int tsdf_max_weight; + + /** @brief A length of one raycast step + + How much voxel sizes we skip each raycast step + */ + CV_PROP_RW float raycast_step_factor; + + // gradient delta in voxel sizes + // fixed at 1.0f + // float gradient_delta_factor; + + /** @brief light pose for rendering in meters */ + CV_PROP Vec3f lightPose; + + /** @brief distance theshold for ICP in meters */ + CV_PROP_RW float icpDistThresh; + /** angle threshold for ICP in radians */ + CV_PROP_RW float icpAngleThresh; + /** number of ICP iterations for each pyramid level */ + CV_PROP std::vector icpIterations; + + /** @brief Threshold for depth truncation in meters + + All depth values beyond this threshold will be set to zero + */ + CV_PROP_RW float truncateThreshold; +}; + +/** @brief DynamicFusion implementation + + This class implements a 3d reconstruction algorithm as described in @cite dynamicfusion. + + It takes a sequence of depth images taken from depth sensor + (or any depth images source such as stereo camera matching algorithm or even raymarching renderer). + The output can be obtained as a vector of points and their normals + or can be Phong-rendered from given camera pose. + + It extends the KinectFusion algorithm to handle non-rigidly deforming scenes by maintaining a sparse + set of nodes covering the geometry such that each node contains a warp to transform it from a canonical + space to the live frame. + + An internal representation of a model is a voxel cuboid that keeps TSDF values + which are a sort of distances to the surface (for details read the @cite kinectfusion article about TSDF). + There is no interface to that representation yet. + + Note that DynamicFusion is based on the KinectFusion algorithm which is patented and its use may be + restricted by the list of patents mentioned in README.md file in this module directory. + + That's why you need to set the OPENCV_ENABLE_NONFREE option in CMake to use DynamicFusion. +*/ +class CV_EXPORTS_W DynaFu +{ +public: + CV_WRAP static Ptr create(const Ptr& _params); + virtual ~DynaFu(); + + /** @brief Get current parameters */ + virtual const Params& getParams() const = 0; + + /** @brief Renders a volume into an image + + Renders a 0-surface of TSDF using Phong shading into a CV_8UC4 Mat. + Light pose is fixed in DynaFu params. + + @param image resulting image + @param cameraPose pose of camera to render from. If empty then render from current pose + which is a last frame camera pose. + */ + + CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose = Matx44f::eye()) const = 0; + + /** @brief Gets points and normals of current 3d mesh + + The order of normals corresponds to order of points. + The order of points is undefined. + + @param points vector of points which are 4-float vectors + @param normals vector of normals which are 4-float vectors + */ + CV_WRAP virtual void getCloud(OutputArray points, OutputArray normals) const = 0; + + /** @brief Gets points of current 3d mesh + + The order of points is undefined. + + @param points vector of points which are 4-float vectors + */ + CV_WRAP virtual void getPoints(OutputArray points) const = 0; + + /** @brief Calculates normals for given points + @param points input vector of points which are 4-float vectors + @param normals output vector of corresponding normals which are 4-float vectors + */ + CV_WRAP virtual void getNormals(InputArray points, OutputArray normals) const = 0; + + /** @brief Resets the algorithm + + Clears current model and resets a pose. + */ + CV_WRAP virtual void reset() = 0; + + /** @brief Get current pose in voxel space */ + virtual const Affine3f getPose() const = 0; + + /** @brief Process next depth frame + + Integrates depth into voxel space with respect to its ICP-calculated pose. + Input image is converted to CV_32F internally if has another type. + + @param depth one-channel image which size and depth scale is described in algorithm's parameters + @return true if succeeded to align new frame with current scene, false if opposite + */ + CV_WRAP virtual bool update(InputArray depth) = 0; + + virtual std::vector getNodesPos() const = 0; + + virtual void marchCubes(OutputArray vertices, OutputArray edges) const = 0; + + virtual void renderSurface(OutputArray depthImage, OutputArray vertImage, OutputArray normImage, bool warp=true) = 0; +}; + +//! @} +} +} +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/kinfu.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/kinfu.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b69cd3199c76c4bd31419d27a080ab9aed01ac2f --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/kinfu.hpp @@ -0,0 +1,204 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This code is also subject to the license terms in the LICENSE_KinectFusion.md file found in this module's directory + +#ifndef __OPENCV_RGBD_KINFU_HPP__ +#define __OPENCV_RGBD_KINFU_HPP__ + +#include "opencv2/core.hpp" +#include "opencv2/core/affine.hpp" + +namespace cv { +namespace kinfu { +//! @addtogroup kinect_fusion +//! @{ + +struct CV_EXPORTS_W Params +{ + /** @brief Default parameters + A set of parameters which provides better model quality, can be very slow. + */ + CV_WRAP static Ptr defaultParams(); + + /** @brief Coarse parameters + A set of parameters which provides better speed, can fail to match frames + in case of rapid sensor motion. + */ + CV_WRAP static Ptr coarseParams(); + + /** @brief frame size in pixels */ + CV_PROP_RW Size frameSize; + + /** @brief camera intrinsics */ + CV_PROP Matx33f intr; + + /** @brief pre-scale per 1 meter for input values + + Typical values are: + * 5000 per 1 meter for the 16-bit PNG files of TUM database + * 1000 per 1 meter for Kinect 2 device + * 1 per 1 meter for the 32-bit float images in the ROS bag files + */ + CV_PROP_RW float depthFactor; + + /** @brief Depth sigma in meters for bilateral smooth */ + CV_PROP_RW float bilateral_sigma_depth; + /** @brief Spatial sigma in pixels for bilateral smooth */ + CV_PROP_RW float bilateral_sigma_spatial; + /** @brief Kernel size in pixels for bilateral smooth */ + CV_PROP_RW int bilateral_kernel_size; + + /** @brief Number of pyramid levels for ICP */ + CV_PROP_RW int pyramidLevels; + + /** @brief Resolution of voxel space + + Number of voxels in each dimension. + */ + CV_PROP_RW Vec3i volumeDims; + /** @brief Size of voxel in meters */ + CV_PROP_RW float voxelSize; + + /** @brief Minimal camera movement in meters + + Integrate new depth frame only if camera movement exceeds this value. + */ + CV_PROP_RW float tsdf_min_camera_movement; + + /** @brief initial volume pose in meters */ + Affine3f volumePose; + + /** @brief distance to truncate in meters + + Distances to surface that exceed this value will be truncated to 1.0. + */ + CV_PROP_RW float tsdf_trunc_dist; + + /** @brief max number of frames per voxel + + Each voxel keeps running average of distances no longer than this value. + */ + CV_PROP_RW int tsdf_max_weight; + + /** @brief A length of one raycast step + + How much voxel sizes we skip each raycast step + */ + CV_PROP_RW float raycast_step_factor; + + // gradient delta in voxel sizes + // fixed at 1.0f + // float gradient_delta_factor; + + /** @brief light pose for rendering in meters */ + CV_PROP Vec3f lightPose; + + /** @brief distance theshold for ICP in meters */ + CV_PROP_RW float icpDistThresh; + /** angle threshold for ICP in radians */ + CV_PROP_RW float icpAngleThresh; + /** number of ICP iterations for each pyramid level */ + CV_PROP std::vector icpIterations; + + /** @brief Threshold for depth truncation in meters + + All depth values beyond this threshold will be set to zero + */ + CV_PROP_RW float truncateThreshold; +}; + +/** @brief KinectFusion implementation + + This class implements a 3d reconstruction algorithm described in + @cite kinectfusion paper. + + It takes a sequence of depth images taken from depth sensor + (or any depth images source such as stereo camera matching algorithm or even raymarching renderer). + The output can be obtained as a vector of points and their normals + or can be Phong-rendered from given camera pose. + + An internal representation of a model is a voxel cuboid that keeps TSDF values + which are a sort of distances to the surface (for details read the @cite kinectfusion article about TSDF). + There is no interface to that representation yet. + + KinFu uses OpenCL acceleration automatically if available. + To enable or disable it explicitly use cv::setUseOptimized() or cv::ocl::setUseOpenCL(). + + This implementation is based on [kinfu-remake](https://github.com/Nerei/kinfu_remake). + + Note that the KinectFusion algorithm was patented and its use may be restricted by + the list of patents mentioned in README.md file in this module directory. + + That's why you need to set the OPENCV_ENABLE_NONFREE option in CMake to use KinectFusion. +*/ +class CV_EXPORTS_W KinFu +{ +public: + CV_WRAP static Ptr create(const Ptr& _params); + virtual ~KinFu(); + + /** @brief Get current parameters */ + virtual const Params& getParams() const = 0; + + /** @brief Renders a volume into an image + + Renders a 0-surface of TSDF using Phong shading into a CV_8UC4 Mat. + Light pose is fixed in KinFu params. + + @param image resulting image + @param cameraPose pose of camera to render from. If empty then render from current pose + which is a last frame camera pose. + */ + + CV_WRAP virtual void render(OutputArray image, const Matx44f& cameraPose = Matx44f::eye()) const = 0; + + /** @brief Gets points and normals of current 3d mesh + + The order of normals corresponds to order of points. + The order of points is undefined. + + @param points vector of points which are 4-float vectors + @param normals vector of normals which are 4-float vectors + */ + CV_WRAP virtual void getCloud(OutputArray points, OutputArray normals) const = 0; + + /** @brief Gets points of current 3d mesh + + The order of points is undefined. + + @param points vector of points which are 4-float vectors + */ + CV_WRAP virtual void getPoints(OutputArray points) const = 0; + + /** @brief Calculates normals for given points + @param points input vector of points which are 4-float vectors + @param normals output vector of corresponding normals which are 4-float vectors + */ + CV_WRAP virtual void getNormals(InputArray points, OutputArray normals) const = 0; + + /** @brief Resets the algorithm + + Clears current model and resets a pose. + */ + CV_WRAP virtual void reset() = 0; + + /** @brief Get current pose in voxel space */ + virtual const Affine3f getPose() const = 0; + + /** @brief Process next depth frame + + Integrates depth into voxel space with respect to its ICP-calculated pose. + Input image is converted to CV_32F internally if has another type. + + @param depth one-channel image which size and depth scale is described in algorithm's parameters + @return true if succeeded to align new frame with current scene, false if opposite + */ + CV_WRAP virtual bool update(InputArray depth) = 0; +}; + +//! @} +} +} +#endif diff --git a/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/linemod.hpp b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/linemod.hpp new file mode 100644 index 0000000000000000000000000000000000000000..76b61bf7cd8e92acaef71dfb6fbcce1d5900e6e4 --- /dev/null +++ b/collector/tools/fayssense_depth_sdk/sdk/opencv/x86_64/include/opencv4/opencv2/rgbd/linemod.hpp @@ -0,0 +1,435 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html + +// This code is also subject to the license terms in the LICENSE_WillowGarage.md file found in this module's directory + +#ifndef __OPENCV_RGBD_LINEMOD_HPP__ +#define __OPENCV_RGBD_LINEMOD_HPP__ + +#include "opencv2/core.hpp" +#include + +/****************************************************************************************\ +* LINE-MOD * +\****************************************************************************************/ + +namespace cv { +namespace linemod { + +//! @addtogroup rgbd +//! @{ + +/** + * \brief Discriminant feature described by its location and label. + */ +struct CV_EXPORTS_W_SIMPLE Feature +{ + CV_PROP_RW int x; ///< x offset + CV_PROP_RW int y; ///< y offset + CV_PROP_RW int label; ///< Quantization + + CV_WRAP Feature() : x(0), y(0), label(0) {} + CV_WRAP Feature(int x, int y, int label); + + void read(const FileNode& fn); + void write(FileStorage& fs) const; +}; + +inline Feature::Feature(int _x, int _y, int _label) : x(_x), y(_y), label(_label) {} + +struct CV_EXPORTS_W_SIMPLE Template +{ + CV_PROP int width; + CV_PROP int height; + CV_PROP int pyramid_level; + CV_PROP std::vector features; + + void read(const FileNode& fn); + void write(FileStorage& fs) const; +}; + +/** + * \brief Represents a modality operating over an image pyramid. + */ +class CV_EXPORTS_W QuantizedPyramid +{ +public: + // Virtual destructor + virtual ~QuantizedPyramid() {} + + /** + * \brief Compute quantized image at current pyramid level for online detection. + * + * \param[out] dst The destination 8-bit image. For each pixel at most one bit is set, + * representing its classification. + */ + CV_WRAP virtual void quantize(CV_OUT Mat& dst) const =0; + + /** + * \brief Extract most discriminant features at current pyramid level to form a new template. + * + * \param[out] templ The new template. + */ + CV_WRAP virtual bool extractTemplate(CV_OUT Template& templ) const =0; + + /** + * \brief Go to the next pyramid level. + * + * \todo Allow pyramid scale factor other than 2 + */ + CV_WRAP virtual void pyrDown() =0; + +protected: + /// Candidate feature with a score + struct Candidate + { + Candidate(int x, int y, int label, float score); + + /// Sort candidates with high score to the front + bool operator<(const Candidate& rhs) const + { + return score > rhs.score; + } + + Feature f; + float score; + }; + + /** + * \brief Choose candidate features so that they are not bunched together. + * + * \param[in] candidates Candidate features sorted by score. + * \param[out] features Destination vector of selected features. + * \param[in] num_features Number of candidates to select. + * \param[in] distance Hint for desired distance between features. + */ + static void selectScatteredFeatures(const std::vector& candidates, + std::vector& features, + size_t num_features, float distance); +}; + +inline QuantizedPyramid::Candidate::Candidate(int x, int y, int label, float _score) : f(x, y, label), score(_score) {} + +/** + * \brief Interface for modalities that plug into the LINE template matching representation. + * + * \todo Max response, to allow optimization of summing (255/MAX) features as uint8 + */ +class CV_EXPORTS_W Modality +{ +public: + // Virtual destructor + virtual ~Modality() {} + + /** + * \brief Form a quantized image pyramid from a source image. + * + * \param[in] src The source image. Type depends on the modality. + * \param[in] mask Optional mask. If not empty, unmasked pixels are set to zero + * in quantized image and cannot be extracted as features. + */ + CV_WRAP Ptr process(const Mat& src, + const Mat& mask = Mat()) const + { + return processImpl(src, mask); + } + + CV_WRAP virtual String name() const =0; + + CV_WRAP virtual void read(const FileNode& fn) =0; + virtual void write(FileStorage& fs) const =0; + + /** + * \brief Create modality by name. + * + * The following modality types are supported: + * - "ColorGradient" + * - "DepthNormal" + */ + CV_WRAP static Ptr create(const String& modality_type); + + /** + * \brief Load a modality from file. + */ + CV_WRAP static Ptr create(const FileNode& fn); + +protected: + // Indirection is because process() has a default parameter. + virtual Ptr processImpl(const Mat& src, + const Mat& mask) const =0; +}; + +/** + * \brief Modality that computes quantized gradient orientations from a color image. + */ +class CV_EXPORTS_W ColorGradient : public Modality +{ +public: + /** + * \brief Default constructor. Uses reasonable default parameter values. + */ + ColorGradient(); + + /** + * \brief Constructor. + * + * \param weak_threshold When quantizing, discard gradients with magnitude less than this. + * \param num_features How many features a template must contain. + * \param strong_threshold Consider as candidate features only gradients whose norms are + * larger than this. + */ + ColorGradient(float weak_threshold, size_t num_features, float strong_threshold); + + CV_WRAP static Ptr create(float weak_threshold, size_t num_features, float strong_threshold); + + virtual String name() const CV_OVERRIDE; + + virtual void read(const FileNode& fn) CV_OVERRIDE; + virtual void write(FileStorage& fs) const CV_OVERRIDE; + + CV_PROP float weak_threshold; + CV_PROP size_t num_features; + CV_PROP float strong_threshold; + +protected: + virtual Ptr processImpl(const Mat& src, + const Mat& mask) const CV_OVERRIDE; +}; + +/** + * \brief Modality that computes quantized surface normals from a dense depth map. + */ +class CV_EXPORTS_W DepthNormal : public Modality +{ +public: + /** + * \brief Default constructor. Uses reasonable default parameter values. + */ + DepthNormal(); + + /** + * \brief Constructor. + * + * \param distance_threshold Ignore pixels beyond this distance. + * \param difference_threshold When computing normals, ignore contributions of pixels whose + * depth difference with the central pixel is above this threshold. + * \param num_features How many features a template must contain. + * \param extract_threshold Consider as candidate feature only if there are no differing + * orientations within a distance of extract_threshold. + */ + DepthNormal(int distance_threshold, int difference_threshold, size_t num_features, + int extract_threshold); + + CV_WRAP static Ptr create(int distance_threshold, int difference_threshold, + size_t num_features, int extract_threshold); + + virtual String name() const CV_OVERRIDE; + + virtual void read(const FileNode& fn) CV_OVERRIDE; + virtual void write(FileStorage& fs) const CV_OVERRIDE; + + CV_PROP int distance_threshold; + CV_PROP int difference_threshold; + CV_PROP size_t num_features; + CV_PROP int extract_threshold; + +protected: + virtual Ptr processImpl(const Mat& src, + const Mat& mask) const CV_OVERRIDE; +}; + +/** + * \brief Debug function to colormap a quantized image for viewing. + */ +CV_EXPORTS_W void colormap(const Mat& quantized, CV_OUT Mat& dst); + +/** + * \brief Debug function to draw linemod features + * @param img + * @param templates see @ref Detector::addTemplate + * @param tl template bbox top-left offset see @ref Detector::addTemplate + * @param size marker size see @ref cv::drawMarker + */ +CV_EXPORTS_W void drawFeatures(InputOutputArray img, const std::vector