# Replacing org.opencv by org.bytedeco.opencv

**URL:** <https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535>\
**Category:** Uncategorized\
**Created:** [May 18, 2020, 8:28am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535 "2020-05-18T08:28:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnaud22](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arnaud22/32/1405_2.png) [@arnaud22](https://community.konduit.ai/u/arnaud22)\
**Post date:** [May 18, 2020, 8:28am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/1 "2020-05-18T08:28:39Z")

</div>

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:

```auto
import org.bytedeco.opencv.global.opencv_imgproc;
// ...
opencv_imgproc.matchTemplate(grayImg1, grayImg2, result, opencv_imgproc.TM_CCOEFF_NORMED);

```

```auto
import static org.opencv.imgproc.ImgProc.*;
// ...
matchTemplate(grayImg1, grayImg2, result, TM_CCOEFF_NORMED);

```

```auto
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](https://docs.opencv.org/4.3.0/df/dfb/group __imgproc__ object.html#ga586ebfb0a7fb604b35a23d85391329be)"

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

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

```

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

Cheers,

Arnaud

---

<div class="post-metadata">

**Author:** ![saudet](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/saudet/32/69_2.png) [@saudet](https://community.konduit.ai/u/saudet)\
**Post date:** [May 19, 2020, 6:09am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/2 "2020-05-19T06:09:13Z")

</div>

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

> <https://github.com/bytedeco/javacv/blob/master/samples/CaffeGooglenet.java>

  

In the general case, it looks like this:

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

```

---

<div class="post-metadata">

**Author:** ![arnaud22](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arnaud22/32/1405_2.png) [@arnaud22](https://community.konduit.ai/u/arnaud22)\
**Post date:** [May 19, 2020, 6:57am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/3 "2020-05-19T06:57:05Z")

</div>

thx @saudet !

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

```java
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 ?

```

---

<div class="post-metadata">

**Author:** ![arnaud22](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arnaud22/32/1405_2.png) [@arnaud22](https://community.konduit.ai/u/arnaud22)\
**Post date:** [May 19, 2020, 7:02am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/4 "2020-05-19T07:02:21Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![saudet](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/saudet/32/69_2.png) [@saudet](https://community.konduit.ai/u/saudet)\
**Post date:** [May 19, 2020, 7:14am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/5 "2020-05-19T07:14:26Z")

</div>

We can access values efficiently using indexers:  
[http://bytedeco.org/news/2014/12/23/third-release/](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.

---

<div class="post-metadata">

**Author:** ![arnaud22](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arnaud22/32/1405_2.png) [@arnaud22](https://community.konduit.ai/u/arnaud22)\
**Post date:** [May 19, 2020, 7:20am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/6 "2020-05-19T07:20:18Z")

</div>

I can see :

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

```

and

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

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

```

there is also :

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

```

---

<div class="post-metadata">

**Author:** ![saudet](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/saudet/32/69_2.png) [@saudet](https://community.konduit.ai/u/saudet)\
**Post date:** [May 19, 2020, 7:32am UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/7 "2020-05-19T07:32:08Z")

</div>

There’s also `Size2d` if that’s what you’re looking for: [Size2d (JavaCPP Presets for OpenCV 4.5.5-1.5.7 API)](http://bytedeco.org/javacpp-presets/opencv/apidocs/org/bytedeco/opencv/opencv_core/Size2d.html)

---

<div class="post-metadata">

**Author:** ![arnaud22](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/arnaud22/32/1405_2.png) [@arnaud22](https://community.konduit.ai/u/arnaud22)\
**Post date:** [May 26, 2020, 2:25pm UTC](https://community.konduit.ai/t/replacing-org-opencv-by-org-bytedeco-opencv/535/8 "2020-05-26T14:25:29Z")

</div>

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

> **[javacpp-presets/opencv at master · bytedeco/javacpp-presets - Documentation](https://github.com/bytedeco/javacpp-presets/tree/master/opencv#documentation)**
>
> master/opencv
