Я хочу использовать трекеры OpenCV. И я действительно достиг, чтобы использовать Trackermil
для установки OpenCV Я использую это в моем gradle/libs.versions.toml :
Код: Выделить всё
...
opencv-android = "4.10.0"
opencv-android = { module = "org.opencv:opencv", version.ref = "opencv-android" }
...
Код: Выделить всё
androidMain.dependencies {
implementation(libs.kotlinx.coroutines.play.services)
implementation(libs.opencv.android) // !
implementation(libs.mlkit.textRecognition)
implementation(libs.commons.text)
implementation(libs.litert)
implementation(libs.litert.support.api)
implementation(libs.litert.metadata)
}
< /code>
Как это я могу правильно: < /p>
import org.opencv.video.TrackerMIL
public typealias TrackerType = TrackerMIL
...
val tracker = TrackerType.create()
tracker.init(mat, rect)
...
val located = tracker.update(mat, rect)
...
Код: Выделить всё
import org.opencv.video.TrackerNano // ONNX
import org.opencv.video.TrackerVit // ONNX
public typealias TrackerType = TrackerVit
...
< /code>
Я получаю эту ошибку: < /p>
06-19 12:09:51.221 12721 12742 E TestRunner: ----- begin exception -----
06-19 12:09:51.221 12721 12742 E TestRunner: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.10.0) /home/ci/opencv/modules/dnn/src/onnx/onnx_importer.cpp:277: error: (-5:Bad argument) Can't read ONNX file: vitTracker.onnx in function 'ONNXImporter'
06-19 12:09:51.221 12721 12742 E TestRunner: ]
06-19 12:09:51.221 12721 12742 E TestRunner: at org.opencv.video.TrackerVit.create_1(Native Method)
06-19 12:09:51.221 12721 12742 E TestRunner: at org.opencv.video.TrackerVit.create(TrackerVit.java:43)
06-19 12:09:51.221 12721 12742 E TestRunner: at com.ltu.ibsa.analysis.MultiObjectTrackingModel$detectAndTrack$2.invokeSuspend(MultiObjectTrackingModel.kt:168)
06-19 12:09:51.221 12721 12742 E TestRunner: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
06-19 12:09:51.221 12721 12742 E TestRunner: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
06-19 12:09:51.221 12721 12742 E TestRunner: at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
06-19 12:09:51.221 12721 12742 E TestRunner: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829)
06-19 12:09:51.221 12721 12742 E TestRunner: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
06-19 12:09:51.221 12721 12742 E TestRunner: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
06-19 12:09:51.221 12721 12742 E TestRunner: ----- end exception -----
06-19 12:09:51.226 12721 12742 I TestRunner: finished: testMultiObjectTracking(com.ltu.ibsa.LiteRTIntegrationTest)
CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.10.0) /home/ci/opencv/modules/dnn/src/onnx/onnx_importer.cpp:277: error: (-5:Bad argument) Can't read ONNX file: vitTracker.onnx in function 'ONNXImporter'
]
at org.opencv.video.TrackerVit.create_1(Native Method)
at org.opencv.video.TrackerVit.create(TrackerVit.java:43)
at com.ltu.ibsa.analysis.MultiObjectTrackingModel$detectAndTrack$2.invokeSuspend(MultiObjectTrackingModel.kt:168)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:829)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
// Load the ONNX file from assets
val assetManager = context.assets
val inputStream = assetManager.open("vitTracker.onnx")
val file = File(context.cacheDir, "vitTracker.onnx")
file.outputStream().use { inputStream.copyTo(it) }
val filePath = file.absolutePath
val params = TrackerVit_Params()
params.set_net(filePath)
...
tracker.init(mat, rect)
< /code>
Но я получил такую же ошибку. У меня отсутствуют зависимости? Это правильный способ установить модель файла?
Подробнее здесь: https://stackoverflow.com/questions/796 ... cv-android
Мобильная версия