JavaCV 0.8 image stitcher

348 views
Skip to first unread message

Robin de Vries

unread,
Apr 29, 2014, 2:03:08 PM4/29/14
to jav...@googlegroups.com
Hi,

I'm (still) trying to use in image-stitcher on Android. The new api-call of the stitch-method in an org.bytedeco.javacpp.opencv_stitching.Stitcher instance has the signature stitch(Mat, Mat).  So all the input-images should be in 1 Mat? How should that be done?

Regards,

Robin

Samuel Audet

unread,
Apr 30, 2014, 8:50:49 AM4/30/14
to jav...@googlegroups.com
Hello,
I see, that module follows a different convention from the other
modules. I've fixed that in this revision:
https://github.com/bytedeco/javacpp-presets/commit/e5a63859aa11617374455d2528ee851d31d26b4f

And uploaded some snapshot binaries of that revision here:
https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacpp-presets/opencv/2.4.9-0.8-1-SNAPSHOT/

Thanks for reporting! :)

Samuel

Robin de Vries

unread,
May 4, 2014, 12:34:18 PM5/4/14
to jav...@googlegroups.com
Thanks, now i'm facing another error:

java.lang.UnsatisfiedLinkError: Native method not found: org.bytedeco.javacpp.opencv_core$Mat.allocate:()V
at org.bytedeco.javacpp.opencv_core$Mat.allocate(Native Method)

This occurs when doing an imread, am I doing something terribly wrong?

Robin





Samuel

--

--- You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Audet

unread,
May 6, 2014, 6:28:11 AM5/6/14
to jav...@googlegroups.com
Hi,

Yes, that's another issue that's been fixed:
https://github.com/bytedeco/javacpp/issues/1

Samuel

Robin de Vries

unread,
May 8, 2014, 4:08:18 AM5/8/14
to jav...@googlegroups.com
Hi,

That is another fixed error, but there are more :(

I'm still executing the following code:

 Mat image1 = imread("/sdcard/stitch/nachtwacht1.jpg");
 Mat image2 = imread("/sdcard/stitch/nachtwacht2.jpg");
       
 Stitcher stitcher = Stitcher.createDefault(false);
               
 MatVector input = new MatVector();
 input.put(image1);
 input.put(image2);
       
 Mat result = new Mat();
 int status = stitcher.stitch(input, result);
               
  if(status == Stitcher.OK)
  {
       System.out.println("Works");
   }

05-08 10:06:01.961: E/AndroidRuntime(6202): FATAL EXCEPTION: main
05-08 10:06:01.961: E/AndroidRuntime(6202): java.lang.RuntimeException: vector::_M_fill_insert
05-08 10:06:01.961: E/AndroidRuntime(6202):     at org.bytedeco.javacpp.opencv_stitching$Stitcher.stitch(Native Method)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at nl.uva.stitcher.MainActivity.onClick(MainActivity.java:91)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at android.view.View.performClick(View.java:4084)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at android.view.View$PerformClick.run(View.java:16966)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at android.os.Handler.handleCallback(Handler.java:615)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at android.os.Looper.loop(Looper.java:137)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at android.app.ActivityThread.main(ActivityThread.java:4745)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-08 10:06:01.961: E/AndroidRuntime(6202):     at dalvik.system.NativeStart.main(Native Method)

Robin


Samuel Audet

unread,
May 8, 2014, 7:57:44 AM5/8/14
to jav...@googlegroups.com
Hi,

On 05/08/2014 05:08 PM, Robin de Vries wrote:
> MatVector input = new MatVector();
> input.put(image1);
> input.put(image2);

We would need to initialize `input = new MatVector(2)` or call
`input.resize(2)` after construction.

Samuel

Robin de Vries

unread,
May 8, 2014, 2:52:37 PM5/8/14
to jav...@googlegroups.com
Hi,

Thanks for the improvement, but it still crashes..

05-08 20:51:25.675: E/AndroidRuntime(7567): FATAL EXCEPTION: main
05-08 20:51:25.675: E/AndroidRuntime(7567): java.lang.RuntimeException: vector::_M_fill_insert
05-08 20:51:25.675: E/AndroidRuntime(7567):     at org.bytedeco.javacpp.opencv_stitching$Stitcher.stitch(Native Method)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at nl.uva.stitcher.MainActivity.onClick(MainActivity.java:92)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at android.view.View.performClick(View.java:4084)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at android.view.View$PerformClick.run(View.java:16966)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at android.os.Handler.handleCallback(Handler.java:615)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at android.os.Looper.loop(Looper.java:137)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at android.app.ActivityThread.main(ActivityThread.java:4745)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at java.lang.reflect.Method.invokeNative(Native Method)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at java.lang.reflect.Method.invoke(Method.java:511)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-08 20:51:25.675: E/AndroidRuntime(7567):     at dalvik.system.NativeStart.main(Native Method)

Any idea?

Robin


Samuel Audet

unread,
May 9, 2014, 7:17:32 AM5/9/14
to jav...@googlegroups.com
On 05/09/2014 03:52 AM, Robin de Vries wrote:
> Thanks for the improvement, but it still crashes..

Well, you're probably not looking into overwriting the pointer to the
MatVector object, but to values in the vector, so we probably want to
provide an index to the put() method, i.e.:

MatVector input = new MatVector(2);
input.put(0, image1);
input.put(1, image2);

Samuel

Robin de Vries

unread,
May 9, 2014, 9:02:06 AM5/9/14
to jav...@googlegroups.com
Finally, thanks :)

Now as last step, I'm trying to convert a Mat to an Bitmap, but this isn't working:

Mat image1 = imread("/sdcard/stitch/nachtwacht1.jpg");
Bitmap im1 = Bitmap.createBitmap(image1.cols(), image1.rows(), Bitmap.Config.ARGB_8888);
im1.copyPixelsFromBuffer(image1.getByteBuffer());

05-09 14:55:22.759: E/AndroidRuntime(10082): java.lang.RuntimeException: Unable to start activity ComponentInfo{nl.uva.stitcher/nl.uva.stitcher.MainActivity}: java.lang.RuntimeException: Buffer not large enough for pixels

Robin




Samuel

Samuel Audet

unread,
May 9, 2014, 9:11:32 AM5/9/14
to jav...@googlegroups.com
On 05/09/2014 10:02 PM, Robin de Vries wrote:
> Now as last step, I'm trying to convert a Mat to an Bitmap, but this isn't working:
>
> Mat image1 = imread("/sdcard/stitch/nachtwacht1.jpg");
> Bitmap im1 = Bitmap.createBitmap(image1.cols(), image1.rows(), Bitmap.Config.ARGB_8888);
> im1.copyPixelsFromBuffer(image1.getByteBuffer());

Android has perfectly fine methods to read JPEG files:
http://developer.android.com/reference/android/graphics/BitmapFactory.html
If I were you, I'd use those.

Samuel

Robin de Vries

unread,
May 9, 2014, 9:13:18 AM5/9/14
to jav...@googlegroups.com
Well this was just an example, the final stitched image should be converted to a bitmap to show in an ImageView ;)

Robin




Samuel

Samuel Audet

unread,
May 9, 2014, 9:17:11 AM5/9/14
to jav...@googlegroups.com
On 05/09/2014 10:13 PM, Robin de Vries wrote:
> Well this was just an example, the final stitched image should be
> converted to a bitmap to show in an ImageView ;)

So it needs to be converted to RGBA, maybe with cvtColor():
http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor
Before copying it to a Bitmap, as required by Android. Please refer to
Android and OpenCV docs about all that.

Samuel

Robin de Vries

unread,
May 9, 2014, 10:07:49 AM5/9/14
to jav...@googlegroups.com
Ah, thanks, i'm now using the function below and it works flawlessly

    private Bitmap matToBitmap(Mat image)
    {
        Mat tmp = new Mat(image1.size(),CV_8U, new Scalar(4));
        cvtColor(image,tmp, COLOR_RGB2BGRA,4);
       
        Bitmap bitmap = Bitmap.createBitmap(image.cols(), image.rows(), Bitmap.Config.ARGB_8888);
        bitmap.copyPixelsFromBuffer(tmp.getByteBuffer());
       
        tmp._deallocate();
       
        return bitmap;
    }




Samuel

Reply all
Reply to author
Forward
0 new messages