# OpenCV - Unable to display histogram result of saved video

**URL:** <https://discourse.processing.org/t/opencv-unable-to-display-histogram-result-of-saved-video/41934>\
**Category:** Libraries\
**Created:** [May 7, 2023, 12:22pm UTC](https://discourse.processing.org/t/opencv-unable-to-display-histogram-result-of-saved-video/41934 "2023-05-07T12:22:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![doni](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@doni](https://discourse.processing.org/u/doni)\
**Post date:** [May 7, 2023, 12:22pm UTC](https://discourse.processing.org/t/opencv-unable-to-display-histogram-result-of-saved-video/41934/1 "2023-05-07T12:22:49Z")

</div>

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

```auto
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();
}

```

---

<div class="post-metadata">

**Author:** ![doni](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@doni](https://discourse.processing.org/u/doni)\
**Post date:** [May 7, 2023, 4:11pm UTC](https://discourse.processing.org/t/opencv-unable-to-display-histogram-result-of-saved-video/41934/2 "2023-05-07T16:11:51Z")

</div>

i was able to display the histogram result by following code but strange image

```auto
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);
}

```

 ![Screenshot1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/6/863e77948e1e84f397cde317d2fe087b67c034ee.png)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 7, 2023, 6:38pm UTC](https://discourse.processing.org/t/opencv-unable-to-display-histogram-result-of-saved-video/41934/3 "2023-05-07T18:38:02Z")

</div>

Hello @doni,

Working example:

```auto
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();
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/5/65ae9adf5b3088a164947d874b6dc4c6f4156f08.jpeg)

`:)`

---

<div class="post-metadata">

**Author:** ![doni](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@doni](https://discourse.processing.org/u/doni)\
**Post date:** [May 7, 2023, 9:32pm UTC](https://discourse.processing.org/t/opencv-unable-to-display-histogram-result-of-saved-video/41934/4 "2023-05-07T21:32:40Z")

</div>

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

```auto
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

```auto
int lowerb = ([100,0,0]);
int upperb = ([255,80,255]);

```

thank you
