What's the ideal way to convert `opencv::cv::Mat` from rust to `numpy.ndarray` in python?
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
調査の方向性
Issue にある PyArray3::from_vec3 の呼び出しと opencv::imgcodecs::imread の例から始めてください。要求された Rust cv::Mat から numpy.ndarray への変換で、説明されている Vec のネストとコピーを回避できるか判断してください。完了条件は、具体的でサポートされている方法が文書化されること、または制限事項が明確化されることです。
索引モデルが issue の本文から書いたものです。
説明
I have a cv::Mat in Rust, but want to convey the data to Python, I have checked the doc and gone to PyArray3, but it requires a Vec<Vec<Vec<T>>>, which means I have to make up the Vec manually with one copy, and from PyArray3::from_vec3 it might clone another time, that's quite inefficient, what's the proper way to do that? Is there a way to prevent data clone?
#[test]
fn mat_2_numpy() -> PyResult<()> {
Python::with_gil(|py| {
println!("in gil");
let func: Py<PyAny> = PyModule::from_code(
py,
c_str!(
"import numpy as np
def call_np(arr):
print(\"Shape:\", arr.shape)
"
),
c_str!(""),
c_str!(""),
)?
.getattr("call_np")?
.into();
let img = opencv::imgcodecs::imread("/some/path/sample.jpg", 0).unwrap();
let shape = (img.rows(), img.cols(), img.channels());
// it requires Vec<Vec<Vec<T>>>
let array = PyArray3::from_vec3(py, v)?;
// pass object with Rust tuple of positional arguments
let args = (array,);
let engine_obj = func.call1(py, args)?;
Ok(())
})
- 主要言語
- Rust
- スター
- 1.4k
- フォーク
- 141
- 平均マージ
- 16分
- マージ済み PR(30日)
- 3
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PyO3/rust-numpy のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
PyO3/rust-numpy#565 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
PyO3/rust-numpy#563 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 56/100
PyO3/rust-numpy#557 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
PyO3/rust-numpy#547 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 20/100
PyO3/rust-numpy#535 ·
PyO3/rust-numpy の issue をすべて見る
似ている issue
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
n0-computer/iroh#4550 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
paritytech/zombienet-sdk#591 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
farion1231/cc-switch#7638 · コメント 1 件 ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100