Conflicting libraries (YOLO comp vision)

Hi team, i seem not to be able to get YOLO working despite some step by step guidance stated on:


from mr MagicandLove. I removed libraries and replaced them to try get the error removed.
Is there a tip that can steer me in the correct direction?

I did import the required files in the locations as the site stated, the CVImage file seems to keep conflicting (i do restart pc to refresh )

help to tackle this last step would be helped

basic code from site:

import cvimage.*;
import ipcapture.*;
 
IPCapture cap;
import processing.video.*;
//import CVImage.*;
import org.opencv.core.*;
import org.opencv.core.Core;
import org.opencv.core.Core.MinMaxLocResult;
import org.opencv.dnn.*;
import org.opencv.core.MatOfDouble;
import java.util.*;

final int CAPW = 640, CAPH = 360;
final int W = 416, H = 416;
final float THRESH = 0.85;
private Net net;
//private Capture cap;
private CVImage cv;
private String [] labels;
private ArrayList<String> names;

public void settings() {
  size(CAPW, CAPH);
}

public void setup() {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  println(Core.VERSION);
  //  printArray(Capture.list());
 // cap = new Capture(this, CAPW, CAPH);
 cap = new IPCapture(this, "http://DESKTOP-1QTI31N:8080/cx","","");
  cap.start();
  cv = new CVImage(W, H);
  loadYOLO();
  getOutputsNames(net);
}

private void getOutputsNames(Net n) {
  int [] outLayers = n.getUnconnectedOutLayers().toArray();
  ArrayList<String> layers = (ArrayList)n.getLayerNames();
  names = new ArrayList<String>(outLayers.length);
  for (int i=0; i<outLayers.length; i++) {
    names.add(layers.get(outLayers[i]-1));
  }
  for (String s : names) {
    println(s);
  }
}

private void loadYOLO() {
  net = Dnn.readNetFromDarknet(dataPath("yolov3.cfg"), 
    dataPath("yolov3.weights"));

  //net.setPreferableBackend(Dnn.DNN_BACKEND_DEFAULT);
  //net.setPreferableTarget(Dnn.DNN_TARGET_OPENCL);
  String [] labelFile = loadStrings("object_detection_classes_yolov3.txt");
  labels = new String[labelFile.length];
  println("Class size: " + labelFile.length);
  for (int i=0; i<labelFile.length; i++) {
    labels[i] = trim(labelFile[i]);
    println(labels[i]);
  }
}

public void draw() {
  if (cap.available()) {
    return;
  cap.read();
  }
  background(0);
  cv.copy(cap, 0, 0, cap.width, cap.height, 
    0, 0, cv.width, cv.height);
  cv.copyTo();
  image(cap, 0, 0);
  Mat blob = Dnn.blobFromImage(cv.getBGR(), 1.0f/255.0f, 
    new Size(cv.width, cv.height), 
    new Scalar(0, 0, 0), true, false);
  net.setInput(blob);

  Mat result = net.forward(names.get(0));

  pushStyle();
  for (int i=0; i<result.rows(); i++) {
    Mat scores = result.row(i).colRange(5, result.cols());
    MinMaxLocResult mm = Core.minMaxLoc(scores);
    Point classIdPoint = mm.maxLoc;
    double confidence = mm.maxVal;
    if (confidence > THRESH) {
      int idx = (int)classIdPoint.x;
      int x = (int)(result.get(i, 0)[0]*cap.width);
      int y = (int)(result.get(i, 1)[0]*cap.height);
      int w = (int)(result.get(i, 2)[0]*cap.width);
      int h = (int)(result.get(i, 3)[0]*cap.height);
      noFill();
      stroke(255, 0, 0);
      rect(x-w/2.0, y-h/2.0, w, h);
      noStroke();
      fill(255, 0, 0, 200);
      rect(x-w/2.0, y-h/2.0, w, 18);
      fill(255, 255, 255);
      text(labels[idx], x+5-w/2.0, y+12-h/2.0);
    }
  }
  popStyle();
}

error:

2 Likes

The little popup box error seems to be telling you what you need. You have two library folders installed that both provide opencv – one is libraries/CVImage, the other is libraries\opencv_processing. It looks like you need to uninstall one of them – e.g. move one of those folders out of your libraries path – so that when you import org.opencv, there is only one match, not two matches.

`Jeremy,

thank you for taking time. I indeed removed one of them, in different orders and variants. each time restarting pc. no positive result, i do a new testround tomorrow , toady the pc beat me though, getting energy to fight it again and get it solved :slight_smile:

You should not need to restart your PC – and skipping that step will greatly speed up your testing. I’d suggest removing them both and restarting PDE. The sketch should fail with library not found. If it doesn’t you have a bigger problem.

Also note that you need to completely remove those folders from your library path. You can’t just rename them or put them in a subfolder – they will still be found and your problem won’t go away.

Thank you for pointing out only all P3 windows needs to be closed, not restarting helps indeed :slightly_smiling_face:
I completely removed one (in a few variants), it gets me in an error which marks

net = Dnn.readNetFromDarknet(dataPath("yolov3.cfg"),

also refers to a library still: No library found for org.opencv.core.Core

and gives the message that is above my understanding:

i am diving in the matter to see if i can make baby steps, if there is an obvious tip though, it would make my sunday real good.

I was able to reproduce your problem and then I fixed it. I guess you forgot to download files into data folder as written in readme https://github.com/chungbwc/Magicandlove/blob/master/ml20180808a/README.md

But be careful, 1st cfg file and 3rd txt files are not direct link to raw files, so you need to follow the link and then download raw files from Github. The 2nd weight file is a direct link.

3 Likes

Micuat, very grateful you point out that the yolov3.cfg was the issue, i indeed placed the file wrongly in the datafolder, putting a copied raw as replacement fixed that part.

it is running, very slow, now trying to get it to run smooth and correct, helped a lot

2 Likes

Hello, I have the same problem, but I don’t know how to solve it. Can you tell me how to solve it? T

hanks