doni
May 7, 2023, 12:22pm
1
hi forum, i tried bellow code to display video and histogram result of saved video, the video succeed to display but the histogram shows black image. thank you for help
import gab.opencv.*;
import processing.video.*;
Movie img;
OpenCV opencv;
Histogram histogram;
int lowerb = 100;
int upperb = 145;
boolean useROI = true;
void setup() {
size(1024, 768);
img = new Movie(this, "vid1.mp4");
opencv = new OpenCV(this, 568, 320);
img.loop();
img.play();
opencv.useColor(HSB);
}
void draw() {
if (img.width == 0 || img.height == 0)
return;//1
opencv.loadImage(img);
image(img, 0, 0);
opencv.setGray(opencv.getH().clone());
opencv.inRange(lowerb, upperb);
histogram = opencv.findHistogram(opencv.getH(), 255);
image(opencv.getOutput(), width-400,0);
}
void movieEvent(Movie m) {//1
m.read();
}
doni
May 7, 2023, 4:11pm
2
i was able to display the histogram result by following code but strange image
import gab.opencv.*;
import processing.video.*;
PImage src, colorFilteredImage;
OpenCV opencv;
Movie video;
int lowerb = 100;//80,100
int upperb = 145;//148
Histogram histogram;
void setup() {
size(1136, 320);
video = new Movie(this, "vid1.mp4");//1
opencv = new OpenCV(this, 568, 320);
video.loop();
video.play();
}
void draw() {
if (video.width == 0 || video.height == 0)
return;
opencv.loadImage(video);
opencv.useColor(HSB);
image(video, 0, 0);
//opencv.useColor(HSB); able to display the result but strange image
opencv.setGray(opencv.getH().clone());
opencv.inRange(lowerb, upperb);
histogram = opencv.findHistogram(opencv.getH(), 255);
//opencv.useColor(HSB);// this not work
// translate(video.width, 0);
image(opencv.getOutput(), video.width, 0);
}
glv
May 7, 2023, 6:38pm
3
Hello @doni ,
Working example:
import gab.opencv.*;
import processing.video.*;
PImage src, colorFilteredImage;
OpenCV opencv;
Movie video;
int lowerb = 100;//80,100
int upperb = 145;//148
Histogram histogram;
// movie used:
// https://github.com/processing/processing-video/raw/main/examples/Movie/Speed/data/launch2.mp4
int count;
void setup()
{
size(1120, 406);
video = new Movie(this, "launch2.mp4");
println(video.width, video.height);
video.loop();
while(video.width <=0)
{
delay(1);
}
println(video.width, video.height);
opencv = new OpenCV(this, video.width, video.height);
while(opencv.width<=0)
{
delay(1);
}
println(opencv.width, opencv.height);
}
void draw()
{
image(video, 0, 0);
opencv.loadImage(video);
opencv.useColor(HSB);
opencv.setGray(opencv.getH().clone());
opencv.inRange(lowerb, upperb);
histogram = opencv.findHistogram(opencv.getH(), 255);
image(opencv.getOutput(), video.width, 0);
}
void movieEvent(Movie m)
{
m.read();
}
:)
1 Like
doni
May 7, 2023, 9:32pm
4
Hi it works thank you indeed. would you like to help me how to make it re run automaticaly after reach maximum frame.
if i read the this part code
opencv.setGray(opencv.getH().clone());
histogram = opencv.findHistogram(opencv.getH(), 255);
it seems the program only targetting the H (hue) value, i need it to be able to set hsv lowerb and upperb as following
int lowerb = ([100,0,0]);
int upperb = ([255,80,255]);
thank you