# How to int array

**URL:** https://discourse.processing.org/t/how-to-int-array/41952
**Category:** Libraries
**Created:** [May 9, 2023, 2:06pm UTC](https://discourse.processing.org/t/how-to-int-array/41952 "2023-05-09T14:06:16Z")
**Posts on this page:** 13
**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 9, 2023, 2:06pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/1 "2023-05-09T14:06:16Z")

</div>

hi forum anyone could help me how to change following code

```auto
int lowerb = 100;
int upperb = 145;

```

into this

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

```

below is complete code

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

```

thank you.

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [May 9, 2023, 2:48pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/2 "2023-05-09T14:48:22Z")

</div>

Hi

[![](https://img.youtube.com/vi/5tSBbWySCC0/maxresdefault.jpg "Arrays in Processing 3 (Java)") ](https://www.youtube.com/watch?v=5tSBbWySCC0)

> **[Arrays](https://processing.org/tutorials/arrays/)**
>
> How to store and access data in array structures.

---

<div class="post-metadata">

### Author: ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)
#### Post date: [May 9, 2023, 2:53pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/3 "2023-05-09T14:53:34Z")

</div>

It looks like inRange() takes integers, not integer triples (or arrays). So you only want to pass it two single integer values.

---

<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 9, 2023, 3:02pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/4 "2023-05-09T15:02:29Z")

</div>

i know but in the source it receive scalar

```auto
public void inRange(int lowerBound, int upperBound){
		Core.inRange(getCurrentMat(), new Scalar(lowerBound), new Scalar(upperBound), getCurrentMat());
	}

```

as far as i know scalar could be written as follow

```auto
Scalar lowerb = new Scalar (0,0,0)

```

---

<div class="post-metadata">

### Author: ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)
#### Post date: [May 9, 2023, 3:55pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/5 "2023-05-09T15:55:34Z")

</div>

Looking at [https://docs.opencv.org/3.4/javadoc/org/opencv/core/Scalar.html](https://docs.opencv.org/3.4/javadoc/org/opencv/core/Scalar.html), it looks like their Scalar class takes `double`s in the constructor, so you could have

```auto
double[] lowerbnd = { 100, 0, 0 };
double[] upperbnd = { 255, 80, 255 };

Scalar lowerb;
Scalar upperb;

void setup() {

  lowerb = new Scalar( lowerbnd );
  upperb = new Scalar( upperbnd );
}

```

but recognize that you’ll have to call the `Core.inRange()` version of the function yourself. The `gab` wrapper only takes a single `int` and not a `Scalar`.

---

<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 9, 2023, 4:09pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/6 "2023-05-09T16:09:35Z")

</div>

its error with

Type mismatch: cannot convert from Scalar to double

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 9, 2023, 5:01pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/7 "2023-05-09T17:01:41Z")

</div>

Okay please show your code.

It’s

- lowerb
- upperb

btw.

---

<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 9, 2023, 5:02pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/8 "2023-05-09T17:02:56Z")

</div>

```auto
import org.opencv.core.Core;
import gab.opencv.*;
import processing.video.*;
PImage src, colorFilteredImage;
import org.opencv.core.Scalar;
import org.opencv.core.Mat;
OpenCV opencv;
Movie video;
//int lowerb = 100;//80,100
//int upperb = 145;//

double[] lowerbnd = { 100, 0, 0 };
double[] upperbnd = { 255, 80, 255 };
Histogram histogram;
void setup() {
  size(1136, 320);
  video = new Movie(this, "vid1.mp4");//1
   opencv = new OpenCV(this, 568, 320);
    lowerbnd = new Scalar( lowerbnd );
  upperbnd = new Scalar( upperbnd );
  
  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(lowerbnd, upperbnd);
            histogram = opencv.findHistogram(opencv.getH(), 255);
            //opencv.useColor(HSB);// this not work
            // translate(video.width, 0);
            image(opencv.getOutput(), video.width, 0);
}
void movieEvent(Movie m) 
  {
  m.read();
  }

```

---

<div class="post-metadata">

### Author: ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)
#### Post date: [May 9, 2023, 5:26pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/9 "2023-05-09T17:26:50Z")

</div>

opencv.inRange() takes two ints. You can’t give it anything other than two ints.

Its code, however, calls Core.inRange() which takes different parameters. You need to call that function if you want to pass it Scalar objects. I’m not sure how you would go about doing so though.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 9, 2023, 5:35pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/10 "2023-05-09T17:35:52Z")

</div>

just for completeness:

remember that scudly had

```auto
double[] lowerbnd = { 100, 0, 0 };
double[] upperbnd = { 255, 80, 255 };

Scalar lowerb;
Scalar upperb;

```

and

```auto
  lowerb = new Scalar( lowerbnd );
  upperb = new Scalar( upperbnd );

```

**Where you have**

```auto
  lowerbnd = new Scalar( lowerbnd );
  upperbnd = new Scalar( upperbnd );

```

can’t work this way.

You need lowerb and upperb.

---

<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 9, 2023, 5:36pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/11 "2023-05-09T17:36:05Z")

</div>

actually i succeed in android studio just to filter white image with this code, and just want to try in processing

```auto
public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2 {

    private static final String TAG = "OCVSample::Activity";
    private int w, h;
    private CameraBridgeViewBase mOpenCvCameraView;
    TextView tvName;
    Scalar sc1 = new Scalar(80, 0, 0);
    Scalar sc2 = new Scalar(250, 160, 250);
    int iLowH = 80;
    int iHighH = 255;
    int iLowS = 0;
    int iHighS = 160;
    int iLowV = 0;
    int iHighV = 255;

    Mat mRgba, imgHSV, imgThreshold, fit;
    Scalar sc1,sc2;

    static {
        if (!OpenCVLoader.initDebug())
            Log.d("ERROR", "Unable to load OpenCV");
        else
            Log.d("SUCCESS", "OpenCV loaded");
    }

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                }
                break;
                default: {
                    super.onManagerConnected(status);
                }
                break;
            }
        }
    };
    public void onCameraViewStopped() {
    }

    public void onCameraViewStarted(int width, int height) {
        imgHSV = new Mat(width,height, CvType.CV_16UC4);
        imgThreshold = new Mat(width,height, CvType.CV_16UC4);
    }

    public MainActivity() {

        Log.i(TAG, "Instantiated new " + this.getClass());
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        Log.i(TAG, "called onCreate");
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);
        mOpenCvCameraView = (CameraBridgeViewBase)findViewById(R.id.display);
        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
        mOpenCvCameraView.setCvCameraViewListener(this);
        mOpenCvCameraView.enableView();
        sc1 = new Scalar(iLowH,iLowS,iLowV);
        sc2 = new Scalar(iHighH,iHighS,iHighV);
    }
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        Imgproc.cvtColor(inputFrame.rgba(), imgHSV, Imgproc.COLOR_BGR2HSV);
        Core.inRange(imgHSV,sc1,sc2,imgThreshold);
        return imgThreshold;
    }
}

```

---

<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 9, 2023, 5:41pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/12 "2023-05-09T17:41:04Z")

</div>

i try this but still the opencv.inRange(); expects (int,int);

```auto
import org.opencv.core.Core;
import gab.opencv.*;
import processing.video.*;
PImage src, colorFilteredImage;
import org.opencv.core.Scalar;
import org.opencv.core.Mat;
OpenCV opencv;
Movie video;
//int lowerb = 100;//80,100
//int upperb = 145;//
Scalar lowerb;
Scalar upperb;

double[] lowerbnd = { 100, 0, 0 };
double[] upperbnd = { 255, 80, 255 };
Histogram histogram;
void setup() {
  size(1136, 320);
  video = new Movie(this, "vid1.mp4");//1
   opencv = new OpenCV(this, 568, 320);
    lowerb = new Scalar( lowerbnd );
  upperb = new Scalar( upperbnd );
  
  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);
}
void movieEvent(Movie m) 
  {
  m.read();
  }

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 9, 2023, 9:10pm UTC](https://discourse.processing.org/t/how-to-int-array/41952/13 "2023-05-09T21:10:17Z")

</div>

I can’t help you with this
