atduskgreg / opencv-processing

OpenCV for Processing. A creative coding computer vision library based on the official OpenCV Java API
Other
1.32k stars 464 forks source link

Any android camera support #103

Open dattasaurabh82 opened 6 years ago

dattasaurabh82 commented 6 years ago

So Ketai library does the heavy lifting for camera class, while processing's native video lib does't support android camera yet. Under those circumstances, How can I use, not face but object detection with specific object cascade files from android , using opencv-lib? can I?

elcraydo commented 4 years ago

Hi, I'd like to bump this issue. This library is great on windows/mac, but nearly two years later and it seems the same problems still exist with core Processing libraries in Android mode. Ketai works with the camera and wraps android's face detection, but openCV marker detection is what I'm looking for.

wisehackermonkey commented 4 years ago

im in the same boat right now, im trying to use Ketai camera and combine it with opencv's face detection but its currently giving me bugs.

if you just want face detection i ended up using Ketai's face tracking: NOTE: you have to have Ketai and android mode install within processing3 for this to work

import ketai.camera.*;

import ketai.cv.facedetector.*;

KetaiCamera cam;

PImage video;
int low = 30;
int high = 100;
int camWidth = 640;
int camHeight = 480;
int MAX_FACES = 20;
KetaiSimpleFace[] faces = new KetaiSimpleFace[MAX_FACES];

void setup() {
  orientation(LANDSCAPE);
  imageMode(CENTER);

  stroke(0, 255, 0);
  strokeWeight(2);
  noFill();
  rectMode(CENTER);

  cam = new KetaiCamera(this, camWidth, camHeight, 30);
  // 0: back camera; 1: front camera

  video = createImage(camWidth, camHeight, RGB);
}

void draw() {
  if (cam != null && cam.isStarted()) {
    cam.loadPixels();
    for (int y = 0; y < cam.height; y++) {
      for (int x = 0; x < cam.width; x++) {
        color pixelColor = cam.get(x, y);
        video.set(x, y, pixelColor);
      }
    }
    video.loadPixels(); 
    image(video, width/2, height/2, width, height);
    //scale(2);

    faces = KetaiFaceDetector.findFaces(video, MAX_FACES); 

    for (int i=0; i < faces.length; i++)
    {
      //We only get the distance between the eyes so we base our bounding box off of that 
      rect(faces[i].location.x, faces[i].location.y, 2.5*faces[i].distance, 3*faces[i].distance);
    }
  }
}

void mousePressed()
{
  if (cam.isStarted()) {
    cam.stop();
  } else {
    cam.setCameraID(1);
    cam.start();
  }
}

void onCameraPreviewEvent()
{
  cam.read();
}
elcraydo commented 4 years ago

Hey, I managed to get marker detection working great for AR on Android using Ketai and nyARToolkit. Here's a link to an older post: https://discourse.processing.org/t/augmented-reality-made-easy/12692/2 It's not the final working code, but it might give you some ideas.