Ask Your Question

Daniel Baggio's profile - activity

2016-06-22 10:51:15 -0600 commented answer Java OpenCV Tutorials?

Yes, it has. Please check: https://www.packtpub.com/application-...

2016-05-20 03:33:06 -0600 answered a question Facial feature detection

There's a nicetutorial here: http://www.learnopencv.com/facial-lan...

2014-11-12 17:19:24 -0600 commented answer Why isn't the OpenCV java libraries available via maven?

My idea is really to put this in the build process of OpenCV. Binaries should be generated with their version control. Could you please add another request for it in the issue thread ( http://code.opencv.org/issues/3097). Maybe if enough people comment, there could be more attention from OpenCV people.

2014-10-21 01:28:51 -0600 received badge  Necromancer (source)
2014-10-20 22:36:35 -0600 answered a question Why isn't the OpenCV java libraries available via maven?

We have an open ticket about this feature: http://code.opencv.org/issues/3097

I have a sample project that shows how to use OpenCV through Maven: https://github.com/JavaOpenCVBook/code/tree/master/chapter1/maven-sample (Notice: it requires adding a custom repository, so I would really like to see OpenCV supporting it instead of having to add another repository)

2014-02-18 04:32:58 -0600 received badge  Teacher (source)
2014-02-17 05:09:22 -0600 answered a question Java OpenCV Tutorials?

Hi,

there's one book coming from PacktPub as well, probably in a couple months.

Kind regards, Daniel

2014-02-11 21:58:42 -0600 answered a question OpenCV Java API to compare images

Hi,

you should look for Template Matching. There's a function in Imgproc, called Imgproc.matchTemplate. There's a good explanation for C++ API here: http://docs.opencv.org/doc/tutorials/imgproc/histograms/template_matching/template_matching.html

It should be easy to convert to Java.

Besides, there's some more explanation in chapter 7 of "Learning OpenCV Computer Vision with the OpenCV Library".

Best regards, Daniel

2014-02-09 20:06:55 -0600 answered a question Linker error (x86 - x64)

It seems you are pointing to x64 libraries and building it as x86. What is the content of OPENCV_DIR variable? Simply type

set OPENCV_DIR

on your terminal. If it points to 64 libs, something like this D:\OpenCV\Build\x64\vc10
You should change it to x86, with a command like this:

set OPENCV_DIR=D:\OpenCV\Build\x86\vc10

(this will only work for this session) or maybe

setx -m OPENCV_DIR D:\OpenCV\Build\x86\vc10

as super user (open command prompt with administrator capabilities).

I guess this should solve your problem.

Kind regards, Daniel

2014-02-01 12:23:46 -0600 answered a question OpenCV on OSX Mavericks in Xcode

Hi,

you are trying to load the file img.jpg. Make sure this file is in the same folder as the executable file.

Kind regards, Daniel

2014-01-27 10:38:51 -0600 answered a question Could anyone make OSX Java binaries available?

Hi, I've made them available here in case it interests anyone: https://github.com/JavaOpenCVBook/code/tree/maven2/org/javaopencvbook/opencvjar-runtime/2.4.8 Also, instructions on how to setup a maven project for opencv are here: https://github.com/JavaOpenCVBook/code/tree/master/chapter1/maven-sample

Kind regards, Daniel

2014-01-21 23:18:58 -0600 answered a question java code for smoothing image using openCV library functions

Hi,

you could use something as simple as:

public Mat blur(Mat input, int numberOfTimes){
        Mat sourceImage = new Mat();
        Mat destImage = input.clone();
        for(int i=0;i<numberOfTimes;i++){
            sourceImage = destImage.clone();
            Imgproc.blur(sourceImage, destImage, new Size(3.0, 3.0));
        }
        return destImage;
    }

which blurs an image using the normalized box filter, using a 3x3 grid around each pixel on the image. This method also let's you define the number of times you want to smooth it.

Kind regards, Daniel

2014-01-21 08:20:06 -0600 received badge  Editor (source)
2014-01-20 22:03:36 -0600 asked a question Could anyone make OSX Java binaries available?

I am looking for a way to setup Maven to get dependencies and I would like to make OSX binaries available but I don't own a Mac, so I thought if Mac guys could give me a hand.

Could anyone make OSX Java binaries, like opencv_java247.dylib (or something alike), publicly available, please?

Kind regards, may God be with you!

2014-01-18 21:56:10 -0600 commented question capture image to slow with java

Well, camera initialization does take a while, even in pure C/C++.

2014-01-18 21:23:51 -0600 received badge  Supporter (source)
2014-01-18 21:21:54 -0600 commented answer Opencv java - Load image to GUI

Hi Lucky,

I see. I believe there's an even faster way to do it in case we are able to point to native memory instead of copying it. But I also think this is fast enough for what most people will do, so I've delayed this solution (nor could I make it so far).

2014-01-17 03:34:13 -0600 received badge  Necromancer (source)
2014-01-15 03:01:31 -0600 received badge  Necromancer (source)
2014-01-14 22:43:28 -0600 received badge  Critic (source)
2014-01-14 22:40:33 -0600 commented answer which class can show an image in java?

Using System.arraycopy will give you 2 times speedup.

public Image toBufferedImageArrayCopy(Mat m){

    int type = BufferedImage.TYPE_BYTE_GRAY;

    if ( m.channels() &gt; 1 ) {

        type = BufferedImage.TYPE_3BYTE_BGR;

    }

    int bufferSize = m.channels()*m.cols()*m.rows();

    byte [] b = new byte[bufferSize];

    m.get(0,0,b); // get all the pixels

    BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);

    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();

    System.arraycopy(b, 0, targetPixels, 0, b.length);  

    return image;


}
2014-01-14 22:38:32 -0600 answered a question Opencv java - Load image to GUI

Hi,

using System.arraycopy is more than 2 times faster than using raster setDataElements method:

public Image toBufferedImage(Mat m){
        int type = BufferedImage.TYPE_BYTE_GRAY;
        if ( m.channels() > 1 ) {
            type = BufferedImage.TYPE_3BYTE_BGR;
        }
        int bufferSize = m.channels()*m.cols()*m.rows();
        byte [] b = new byte[bufferSize];
        m.get(0,0,b); // get all the pixels
        BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
        final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
        System.arraycopy(b, 0, targetPixels, 0, b.length);  
        return image;

    }
2014-01-14 22:34:59 -0600 answered a question Proper(fast) way to extract pixel data from Mat in Java

Using System.arraycopy is faster than my other answer:

public Image toBufferedImageArrayCopy(Mat m){
        int type = BufferedImage.TYPE_BYTE_GRAY;
        if ( m.channels() > 1 ) {
            type = BufferedImage.TYPE_3BYTE_BGR;
        }
        int bufferSize = m.channels()*m.cols()*m.rows();
        byte [] b = new byte[bufferSize];
        m.get(0,0,b); // get all the pixels
        BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
        final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
        System.arraycopy(b, 0, targetPixels, 0, b.length);  
        return image;

    }
2013-12-30 04:14:39 -0600 commented answer imshow equivalence in Java

You don't need to compress it to .jpg. You can do it like this:

public Image toBufferedImage(Mat m){
    int type = BufferedImage.TYPE_BYTE_GRAY;
    if ( m.channels() &gt; 1 ) {
        Mat m2 = new Mat();
        Imgproc.cvtColor(m,m2,Imgproc.COLOR_BGR2RGB);
        type = BufferedImage.TYPE_3BYTE_BGR;
        m = m2;
    }
    byte [] b = new byte[m.channels()*m.cols()*m.rows()];
    m.get(0,0,b); // get all the pixels
    BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
    image.getRaster().setDataElements(0, 0, m.cols(),m.rows(), b);
    return image;

}

Best regards,

2013-12-23 23:51:44 -0600 received badge  Necromancer (source)
2013-12-22 22:29:03 -0600 answered a question Proper(fast) way to extract pixel data from Mat in Java

Hi,

I can't assure you this is the fastest way to do it, but it takes around 2-3 ms per frame (640x480) on a similar computer. General idea is natively inverting BGR -> RGB and using BufferedImage setDataElements.

 public Image toBufferedImageNoEncode(Mat m){
        long time = System.currentTimeMillis();
        int type = BufferedImage.TYPE_BYTE_GRAY;
        if ( m.channels() > 1 ) {
            Mat m2 = new Mat();
            Imgproc.cvtColor(m,m2,Imgproc.COLOR_BGR2RGB);
            type = BufferedImage.TYPE_3BYTE_BGR;
            m = m2;
        }

        byte [] b = new byte[m.channels()*m.cols()*m.rows()];
        m.get(0,0,b); // get all the pixels
        BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
        image.getRaster().setDataElements(0, 0, m.cols(),m.rows(), b);
        System.out.println("To buffer: " + (System.currentTimeMillis() - time));

        return image;


    }