0
votes

I am just started with processing.js.

The goal of my program is adept image filter(opencv) to video frame.

So I thought (However I found out it does not working in this way :<) :

  • get video steam from Capture object which in processing.video package.
  • Store current Image(I hope it can store as PImage Object).
  • adept OpenCV image Filter
  • call image method with filtered PImage Object.

I found out how to get video stream from cam, but do not know how to store this.

import processing.video.*;
import gab.opencv.*;

Capture cap;
OpenCV opencv;

public void setup(){
  //size(800, 600);
  size(640, 480);
  colorMode(RGB, 255, 255, 255, 100);

  cap = new Capture(this, width, height);
  opencv = new OpenCV(this, cap);
  cap.start();
  background(0);
}

public void draw(){
  if(cap.available()){
    //return void 
    cap.read();
  }

  image(cap, 0, 0);
}

this code get video stream and show what it gets. However, I can not store single frame since Capture.read() returns 'void'.

After Store current frame I would like to transform PImage s with OpenCV like :

 PImage gray = opencv.getSnapshot();

  opencv.threshold(80);
  thresh = opencv.getSnapshot();

  opencv.loadImage(gray);
  opencv.blur(12);  
  blur = opencv.getSnapshot();

  opencv.loadImage(gray);
  opencv.adaptiveThreshold(591, 1);
  adaptive = opencv.getSnapshot();

Is there any decent way to store and transform current frame? (I think my way - this means show frame after save current image and transform - uses lots of resources depend on frame rate)

Thanks for answer :D

2
just as a sidenote: processing.js is quite a bad way to use opencv, their bindings were never updated since 200x and cover only ~5% of opencv's functionality. - berak
@berak Thanks for advice. I also found it out there are not much example with processingjs(Mostly it uses with C++ code). However I have to figure this out with processing since I do not know much of C++ for now. Is there anyway to implement those specifications without using openCV? - Juneyoung Oh
opencv comes with java and python bindings, if that's any help ? - berak
@berak no. There is a restrict that I should use processing js. Anyway thanks for new clue to figure it out :D - Juneyoung Oh

2 Answers

0
votes

not sure what you want to do, I'm sure you solved it already, but this could be useful for someone anyway...

It seems you can just write the Capture object's name directly and it returns a PImage:

 cap = new Capture(this, width, height);

//Code starting and reading capture in here

PImage snapshot = cap;
//Then you can do whatever you wanted to do with the PImage
snapshot.save("snapshot.jpg");
//Actually this seems to work fine too
cap.save("snapshot.jpg");
0
votes

Use opencv.loadImage(cap). For example:

if (cap.available() == true) {
    cap.read();
}  

opencv.loadImage(cap);
opencv.blur(15);

image(opencv.getSnapshot(), 0, 0);

Hope this helps!