How can add weights and cfg path to Dnn.readNetFromDarknet(cfgPath, weightPath) at android studio?

Viewed 141
yolo = Dnn.readNetFromDarknet(cfgPath, weightPath);

At this point, i created an assets folder and uploaded cfg and weights files to here. But i could not run this line because i cannot give the correct path. How can i add paths from my assets folder to this line or is there another option to do this process.

Opencv version 3.4.5

1 Answers

You can access the Assets folder using these lines:

  AssetManager assetManager = getAsset();
  assetManager.open("filename");

But you can't actually get the path to Asset Folder and you need to give readNetFromDarknet function String arguments paths to the configuration files. Therefore, what you need to do is to create the files in the internal storage:

 getApplicationContext().getFilesDir().getAbsolutePath()
Related