Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is mask detection. / 'Bad' condition does not appear. #3

Open
SeongJongKwak opened this issue Oct 28, 2021 · 0 comments
Open

This is mask detection. / 'Bad' condition does not appear. #3

SeongJongKwak opened this issue Oct 28, 2021 · 0 comments

Comments

@SeongJongKwak
Copy link

Dear cansik
This is mask detection.

import ch.bildspur.vision.*;
import ch.bildspur.vision.result.*;

import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PImage;
import processing.video.Capture;

import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.List;

// speed of the yolo algorithm (trained on 416)
int detectionSize = 128;

// size of the inferenced image 
// in relation to the original
float sizeFactor = 1.0;

// camera input width and height
int inputWidth = 640;
int inputHeight = 480;

Capture cam;
PImage inputImage;

DeepVision deepVision = new DeepVision(this);
YOLONetwork yolo;
List<ObjectDetectionResult> detections;

public void setup() {
  size(640, 480, FX2D);
  frameRate(30);
  colorMode(HSB, 360, 100, 100);

  println("creating model...");
  Path model = Paths.get(sketchPath("/models/mask-yolov4.cfg")).toAbsolutePath();
  Path weights = Paths.get(sketchPath("/models/mask-yolov4.weights")).toAbsolutePath();
  
  //Path model = Paths.get(sketchPath("/models/mask-yolov3-tiny-prn.cfg")).toAbsolutePath();
  //Path weights = Paths.get(sketchPath("/models/mask-yolov3-tiny-prn.weights")).toAbsolutePath();
  
  
  
  println(" model : " + model);
  println(" weights : " + weights);


  yolo = new YOLONetwork(model, weights, detectionSize, detectionSize);
  yolo.setLabels("good", "bad", "none");

  println("loading yolo model...");
  yolo.setup();

  String[] cams = Capture.list();
  println("Cameras: ");
  printArray(cams);

  //cam = new Capture(this, inputWidth, inputHeight, cams[0]);
  //cam.start();
  inputImage = new PImage(int(inputWidth * sizeFactor), int(inputHeight * sizeFactor), RGB);  
  inputImage = loadImage("victor-he-lf1ivjbtF2Q-unsplash.jpg");
  inputImage = loadImage("jeremy-stenuit-3mErKfgolzM-unsplash.jpg");  
  inputImage = loadImage("test2.jpg");  
  // inputImage = loadImage("test3.jpg");  
  inputImage.resize(width,height);
  
}

public void draw() {
  background(55);

  //if (cam.available()) {
  //  cam.read();
  //}
  //inputImage.copy(cam, 0, 0, cam.width, cam.height, 0, 0, inputImage.width, inputImage.height);



  yolo.setConfidenceThreshold(0.50f);
  detections = yolo.run(inputImage);
  image(inputImage, 0, 0);
  // cam.filter(GRAY);  image(cam, 0, 0);

  scale(1.0 / sizeFactor);
  for (ObjectDetectionResult detection : detections) {    
    noFill();
    strokeWeight(2f);

    switch(detection.getClassId()) {
    case 0:
      stroke(120, 80, 100);
      break;

    case 1:
      stroke(40, 80, 100);
      break;

    case 2:
      stroke(0, 80, 100);
      break;
    }
    noFill(); 
    rect(detection.getX(), detection.getY(), detection.getWidth(), detection.getHeight());


    fill(0,250); noStroke();
    String label = detection.getClassName();
    rect(detection.getX()-50, detection.getY()-25, 100, 20);
    fill(255); textAlign(CENTER);
    text(label + " " + nf(detection.getConfidence(), 0, 2), detection.getX(), detection.getY()-10);
    
  }

  surface.setTitle("Mask YOLO Test - FPS: " + Math.round(frameRate));
}

[result image]
https://drive.google.com/file/d/1sSd4qRMXRbAwwkpTXC8PIB2IRILEFB2s/view?usp=sharing

  1. 'Bad' condition does not appear.
  2. I used the yolo-v4 you trained.
    Why not? help me.

result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant