Mat inRange Color not working

448 views
Skip to first unread message

Ankur Dubey

unread,
Nov 11, 2015, 9:39:19 AM11/11/15
to javacv
Hi 

I am trying to do the following operation which I have implemented using opencv API and worked.

    Mat colormask = new Mat(),colormask1 = new Mat();
   
Scalar Colour = new Scalar(a.get((a.rows())/2-1,(a.cols())/2-1));
   
Core.inRange(b,new Scalar(0,0,0),Colour,colormask);
   
Core.inRange(b,new Scalar(0,0,0),new Scalar(a.get(0,0)),colormask1);




And I have implemented same in JavaCV as 

                Mat colormask = new Mat(),colormask1 = new Mat();
              opencv_core
.Mat Ub1 = new opencv_core.Mat(1,1,b.type(),a.arrayData().get((a.rows())/2-1));
             
//opencv_core.Scalar Colour = new opencv_core.Scalar(a.arrayData().get((a.rows())/2-1));
              opencv_core
.Mat Ub2 = new opencv_core.Mat(1,1,b.type(),a.arrayData().get(0));
              opencv_core
.inRange(b,new opencv_core.Mat(1, 1, b.type(), 0),Ub1,colormask);
              opencv_core
.inRange(b,new opencv_core.Mat(1, 1, b.type(), 0),Ub2,colormask1);



And then I am getting the error as 
Error: java.lang.RuntimeException: /bytedeco/javacpp-presets/opencv/cppbuild/linux-x86_64/opencv-3.0.0/modules/core/src/arithm.cpp:5696: error: (-209) The lower bounary is neither an array of the same size and same type as src, nor a scalar in function inRange



Am I doing something wrong in here? Help me.

Message has been deleted

Samuel Audet

unread,
Nov 14, 2015, 1:09:01 AM11/14/15
to jav...@googlegroups.com
On 11/11/2015 11:39 PM, Ankur Dubey wrote:
> Hi
>
> I am trying to do the following operation which I have implemented using
> opencv API and worked.
>
> Mat colormask = new Mat(),colormask1 = new Mat();
> Scalar Colour = new Scalar(a.get((a.rows())/2-1,(a.cols())/2-1));
> Core.inRange(b,new Scalar(0,0,0),Colour,colormask);
> Core.inRange(b,new Scalar(0,0,0),new Scalar(a.get(0,0)),colormask1);

Try something like this:

Mat colormask = new Mat(),colormask1 = new Mat();
Mat Colour = new Mat(new double[]
{a.createIndexer().get((a.rows())/2-1,(a.cols())/2-1)});
inRange(b,new Mat(new double[] {0, 0, 0, 0}),Colour,colormask);
inRange(b,new Mat(new double[] {0, 0, 0, 0}),new Mat(new double[]
{a.createIndexer().get(0,0)}),colormask1);

> I didn't understand why different work going on with same name ------one
> with OPENCV API and other one with bytecode opencv. And if there is any
> difference why there is no proper blog with full documentation of changes
> and how to use them. In this example only its visible when there is change
> in from OPENCV API but its not mentioned anywhere that how to use. No
> examples as well for new opencv Mat format.

JavaCPP tends to follow more closely the C++ API, so we should refer to
sample code in C++, not Java.

Of course, more documentation, samples, FAQ, etc are desirable. If you
would like to make a contribution, you could start a wiki article about
this particular issue. It's write accessible to all! Thanks

Samuel

Ankur Dubey

unread,
Nov 16, 2015, 4:20:18 AM11/16/15
to javacv
Thanks Samuel, Can you tell me how to change the opencv Mat into ByteArrayInputStream / FileInputStream?

Samuel Audet

unread,
Nov 22, 2015, 9:22:16 PM11/22/15
to jav...@googlegroups.com
On 11/16/2015 06:20 PM, Ankur Dubey wrote:
> Thanks Samuel, Can you tell me how to change the opencv Mat into
> ByteArrayInputStream / FileInputStream?

Sure, something like this:
byte[] array = new byte[Mat.arraySize()];
Mat.arrayData().get(array);
return new ByteArrayInputStream(array);


Samuel

Reply all
Reply to author
Forward
0 new messages