Replacing org.opencv by org.bytedeco.opencv

Hello everyone,

I am replacing the opencv library with the bytedeco library in my project.
Thx to @saudet for his first tips here :

" The official Java API is loosely based on the C++ API, so typically it’s quite straightforward. For example, any other the following works just fine:

import org.bytedeco.opencv.global.opencv_imgproc;
// ...
opencv_imgproc.matchTemplate(grayImg1, grayImg2, result, opencv_imgproc.TM_CCOEFF_NORMED);
import static org.opencv.imgproc.ImgProc.*;
// ...
matchTemplate(grayImg1, grayImg2, result, TM_CCOEFF_NORMED);
import static org.bytedeco.opencv.global.opencv_imgproc.*;
// ...
matchTemplate(grayImg1, grayImg2, result, TM_CCOEFF_NORMED);

There is no official guides, but the API exposed by JavaCPP is very close to the C++ API, so we can refer to the official documentation here, for example:
OpenCV: Object Detection"

I have some problems trying to use the concept of Pointer :
with openCV I have :

MinMaxLocResult mmr = Core.minMaxLoc(mat);
double score = mmr.maxVal;

How can I do with opencv_core.minMaxLoc(Mat, ?) : Buffer/Pointer ?

Cheers,

Arnaud

There’s a few of examples of that around, for example, in this sample code:


In the general case, it looks like this:

DoublePointer minVal = new DoublePointer(1);
DoublePointer maxVal = new DoublePointer(1);
Point minLoc = new Point(1);
Point maxLoc = new Point(1);
minMaxLoc(mat, minVal, maxVal, minLoc, maxLoc, null);
// use minVal.get(), maxVal.get(), minLoc.x(), minLoc.y(), maxLoc.x(), maxLoc.y() here
2 Likes

thx @saudet !

An other interrogation.
Any equivalent to get value from a matrice ?

Size srcSize = srcImg.size();
Point2f center = new Point2f(srcSize.width() / 2, srcSize.height() / 2);
Mat transformation2DMat = opencv_imgproc.getRotationMatrix2D(center, angle, 1);
Float cos = Math.abs(transformation2DMat.get(0, 0)[0]); // Any equivalent for this line ?

An other interrogation :
is there a trick to using the zeros function with a kernel defined with float ? Size2f ?

Mat srcImg = ...
Float targetWidt = ...
Float targetHeight = ...
Mat targetMat = Mat.zeros(new Size(targetWidth, targetHeight), srcImg.type()).asMat();

We can access values efficiently using indexers:
http://bytedeco.org/news/2014/12/23/third-release/

What do you mean by “kernel defined with float”?
The widths and heights of images are always integers.

1 Like

I can see :

package org.opencv.core;
public class Size {
  public double width;
  public double height;

and

package org.bytedeco.opencv.opencv_core;
[...]
public class Size extends IntPointer {
[...]

  public Size(int _width, int _height) {
  [...]

there is also :

package org.bytedeco.opencv.opencv_core;
[...]
public class Size2f extends FloatPointer {
[...]
 public Size2f(float _width, float _height) {
[...]

There’s also Size2d if that’s what you’re looking for: Size2d (JavaCPP Presets for OpenCV 4.5.5-1.5.7 API)

Thx you so much @saudet

I was able to remove the external opencv installation by adding this line of code as you suggested…
Loader.load(opencv_java.class)

1 Like