Error loading OpenCV in Java for Image Processing

976 views Asked by At

I am facing a problem in loading OpenCV in Java(Eclipse, Mac OSX). I am new to Java and my main target is Image Processing.I have checked several examples online but....I have few queries actually:

0) Can you actually instruct me how to use OpenCV library for Java in Eclipse in Mac OS X? I have only downloaded the jar and done the import....

1) Below is a sample of my code

Mat A = Highgui.imread("/Users/.../Dropbox/ImageJSpace/Image_0001.jpg", 1);
    Mat B = null;
    Imgproc.cvtColor(A, B, Imgproc.COLOR_BGR2GRAY);

    Highgui.imwrite("/Users/.../Dropbox/ImageJSpace/Image_0001gray.jpg", B);

In this section, I am simply trying to read image, covert to matrix, to graysale and then save to image again. In the examples that I checked online, they have mentioned cvtColor but overtime i try to write it doesn't work. I have to write Highgui.cvtColor and for each keyword from this new library.

2) I get the following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
at org.opencv.highgui.Highgui.<clinit>(Highgui.java:416)
at Expertising.ImageModifications.Mat2Img(ImageModifications.java:382)
at Expertising.Main.main(Main.java:7)

I don't know how to get rid of this..

3) To be clear for my program, which is longer than this section, I have used the following imports:

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;

4) I want to process DICOM images using OpenCV. Is there a method to work with that?

5) I also have imported the ImageJ library to work with DICOM. I can open and display. Can I read and work with pixels?

6) I am mainly interested in studying structure tensor in DICOM images. How can I read individual pixels from DICOM?

7) I am working in studying directionality. Is there any method to better explore it?

8) Can I convert my DICOM Image to Matrix and then explore the pixels as Matrix by use of JAMA?

Please help,, thanks a lot....

2

There are 2 answers

0
Tolga DURAN On

Did you add OpenCV Core library to main method?

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
0
FrankyG On

I don't know anything about OpenCV but here is a tutorial on how to use OpenCV with Eclipse.

As for DICOM I found this:

OpenCV does not support DICOM images so that you will have to find a suitable libary (like http://dicom.offis.de/dcmtk.php.en ) and convert the loaded image to a cv::Mat.

I would suggest using the OpenCV Questions site for this question.