We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everybody, I want that while there is a live webcam it is possible to adjust the brightness and contrast of color and gray images. This is my code:
import processing.video.*;
import g4p_controls.*;
import java.awt.Font;
import gab.opencv.*;
OpenCV opencv;
PFont f;
boolean filterT=false;
Capture cam;
GButton btnFilterT;
int n = 1;
void setup() {
size(1024, 768);
f = createFont("Arial", 48, true);
btnFilterT = new GButton(this, 740, 50, 140, 20);
btnFilterT.setText("On");
btnFilterT.setLocalColorScheme(GCScheme.GREEN_SCHEME);
cam = new Capture(this, 640, 480);
cam.start();
}
void draw() {
if (cam.available() == true) {
cam.read();
}
pushMatrix();
scale(-1, 1);
image(cam.get(), -width, 0, width, height);
popMatrix();
opencv = new OpenCV(this, cam);
opencv.loadImage(cam);
if (filterT==true) {
opencv.brightness((int)map(mouseX, 0, width, -255, 255));
image(opencv.getOutput(),0, 0, width, height);
}
}
public void handleButtonEvents(GButton button, GEvent event) {
if (button == btnFilterT) {
filterT=true;
}
}
I have two problems:
if I press the T button to start the brightness and contrast in gray, the screen flips over and becomes no mirror.
how can I have brightness and contrast with the mirror video?
how can I have the brightness and contrast of the webcam color?
thank you
Answers
To answer the first question: I think the reason why the the screen flips over is that you only perform push, scale and pop on cam.get() but not on openvc.getOutput().
Thanks Andreas_Ref, I have tried to change:
image(opencv.getOutput(), -width, 0, width, height);
but it does not work. Anyone have any ideas to suggest?
thanks
I was hoping somebody in the community would have answered this question by now. I tried myself but I failed.
Next I am assuming opencv.getOutput() returns a PImage object.
The code next is a dirty test suggestion, partial code and un-tested. Also explore previous post using scale: https://forum.processing.org/two/search?Search=scale
I am interested to know if this will work.
Kf
Thank you very much for your help kfrajer!
Your example works fine!
But then when I slightly changed it started to does not work Opencv.brightness ();
Where am I wrong?
thanks
That is very odd. from your previous code, i notice that inversion is observed only on the image that you draw in line 113 and it is shown only for a split second. I removed G4P and openCV thinking they were changing the object and my luck didn't change. Odd enough, the previous example did work so it seems....
I kinda gave up because I couldn't get it to work using scale at the end. It is like image ignore the scale parameter despite been called before. Very very odd.
I have a solution. Sketch below. Notice I assume the sketch and image have the same size.
Kf
Strange. I'm actually trying to understand -- should the previous issue be reported as a bug? Interesting solution, @kfrajer.
I re-tested all the code above and none works. I am not sure if it is a bug or if not being used properly. i think using the default imageMode leads to confusion. I came up with the following example. I create a copy of the current cam image and I display it twice, one inside the push/pop bloc and the second one outside in an untouched reference frame. Notice that I am using imageMode(CENTER). I conclude the one inside the block works.
Kf
This post also works for this case, related to horizontal flipping (Tested in Java but not using G4P... it should work nevertheless): https://forum.processing.org/two/discussion/22546/how-do-i-flip-video-in-canvas-horizontally-in-p5js#latest
Kf