cvCreateImage in Java on Android

Skip to first unread message


May 15, 2012, 1:43:27 PM5/15/12

Dear OpenCV Android users,

Is it possible to use cvCreateImage in .java source?  I have been unsuccessful in finding the right way to use such an API in Java for OpenCV Android.

I am trying to execute this code in inside the Tutorial 1 (Basic) - Add OpenCV sample :

            /* Copy mask into a grayscale image */
            IplImage *hough_in = cvCreateImage(size, 8, 1);
            cvCopy(mask, hough_in, NULL);
                cvSmooth(hough_in, hough_in, CV_GAUSSIAN, 15, 15, 0, 0);

            /* Run the Hough function */
            CvMemStorage *storage = cvCreateMemStorage(0);
            CvSeq *circles = cvHoughCircles(hough_in, storage,
                CV_HOUGH_GRADIENT, 4, size.height/10, 100, 40, 0, 0);

Thank you very much for your insights, time, and direction.  It truly is appreciated.  I will not be surprised to find out I cannot do this.  The native samples ("Advanced") are not executing for me on a Samsung Galaxy S2.

Rui Marques

May 15, 2012, 5:25:02 PM5/15/12
The java version does not use IplImage. I also think that IplImage is deprecated with C++ version as it is replaced by the Mat data structure.

In java you use:

Mat  hough_in = new Mat();

There are several Mat() construtors, besides this empty one, consult the docs or opencv4android source code to know more.

Rui Marques

May 15, 2012, 5:56:56 PM5/15/12
A very rough translation would be like this, you can find better Hough circles samples in this usergroup.
Be aware that this is just indicative, I cannot test it right now.

/* Copy mask into a grayscale image */
Mat hough_in = new Mat();


Imgproc.smooth(hough_in, hough_in, Imgproc.CV_GAUSSIAN, 15, 15, 0, 0);

/* Run the Hough function */
Mat storage = new Mat();
Imgproc.HoughCircles(hough_in, storage, Imgproc.CV_HOUGH_GRADIENT, 4, size.height/10, 100, 40, 0, 0);



May 17, 2012, 4:18:26 AM5/17/12

The Android way is writing all your code in Java.
But somethimes it is not enough and you need to go to a native level and write part of your application in C/C++. This is important when you already have some computer vision functionality which is written in C++ and uses OpenCV, and you want to use it in your Android application, but do not want to rewrite the C++ code to Java. In this case the only way is to use JNI mechanism. It means, that you should add a class with native methods wrapping your C++ functionality into the Java part of your Android application.

If you want write code using C++ you need to use the jni mechanism (Java native interface)
Reply all
Reply to author
0 new messages