# How to use norm with Java?

I have a code that is written in both Python and C++ that I am now converting to Java. I use the norm function to compare 2 points of an RGB image. In Python and C++ getting these pixel values is simple, and you can just plug them into the norm function. In java, when getting these values the data type changes from Mat to double[] array. The norm function however takes Mat as its arguments. Is it possible to convert the double array to Mat, or to get the pixel values as a Mat?

This is the current methods I am using:

double[] right_pt = image_to_read.get(middlexint+radiint, middleyint); // get pixel value point1
double e_dist = Core.norm(right_pt, pti);  // calculate euclidean distance

edit retag close merge delete

Sort by » oldest newest most voted

well, the java wrappers are indeed somewhat clumsy here (compared to c++),

but you could either work around it with 1-pixel Mat's like:

Mat left  = img.submat(yleft,  yleft+1,  xleft,  xleft+1);
Mat right = img.submat(yright, yright+1, xright, xright+1);
double dist = Core.norm(left, right);


or just compute it manually:

double db = right_pt - pti;
double dg = right_pt - pti;
double dr = right_pt - pti;
double dist = Math.sqrt(db*db + dg*dg + dr*dr);

more

Official site

GitHub

Wiki

Documentation