簡體   English   中英

Java、OpenCV:如何讀/寫 ORB FeatureDetection 參數

[英]Java, OpenCV: How to read/write ORB FeatureDetection parameters

在 OpenCV 中,我在 Android 應用程序中使用 ORB FeatureDetection。 它有參數,但不能直接在 Java 中設置。 設置它們的推薦方法是寫出帶有參數的 XML 或 YML 文件,然后將其讀回。

但是,似乎無法確定實際上我已正確寫入文件並應用了參數。 我想我可以使用 write() 方法來驗證我的新設置是否已采用。 但這似乎不起作用。 它確實編寫了一個正確的 YML 或 XML 文件,但這些文件沒有參數。

下面是寫文件的代碼:

_detector = FeatureDetector.create(FeatureDetector.ORB);

// write initial params. 
String fileName = myDir.getPath() + "/orb_params.yml";
_detector.write(fileName);
fileName = myDir.getPath() + "/orb_params.xml";
_detector.write(fileName);

// try setting some params. 
String tempFileName = writeToFile("tempFile", "%YAML:1.0\nscaleFactor: 1.1\nnLevels: 5\nfirstLevel: 0\nedgeThreshold: 31\npatchSize: 31\n");
_detector.read(tempFileName);

// write params again. 
String fileName = myDir.getPath() + "/orb_params2.yml";
_detector.write(fileName);
fileName = myDir.getPath() + "/orb_params2.xml";
_detector.write(fileName);

xml 文件如下所示:

<?xml version="1.0"?>
<opencv_storage>
</opencv_storage>

yml 文件如下所示:

%YAML:1.0

Java 中沒有實現 write 方法嗎? 我看到它是在 Algorithm.cpp 中實現的,並且我假設 ORB 特征檢測器只是使用該實現,我看不到代碼以其他方式表示。

我不知道這個問題是否僅限於 ORB 特征檢測,或者其他算法在嘗試從 Java 寫入參數時是否遇到這些問題。

附錄:我看到 write 方法似乎是在 JNI 代碼中實現的: https : //github.com/Itseez/opencv/blob/ddf82d0b154873510802ef75c53e628cd7b2cb13/modules/features2d/misc/java/src/cpp/features.hppd_

在 answers.opencv.org 上得到了一個回復,我把它張貼在這里,供將來遇到這個問題的人使用:

根據此答案,讀/寫功能未在 C++ 中實現,因此也不適用於 Android。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM