Mat to int[] and vice versa

asked 2015-02-20 10:19:25 -0600

updated 2015-02-20 10:20:26 -0600

I'm completely new to this library, so apologize for my simple question. I'm using OpenCV library in Android. So Java.

Given a homographyMatrix :

    Mat srcMat, dstMat;
    int[] srcPixels, dstPixels;

    //... srcPixels filled with int values of pixels

   srcPixels conversion to srcMat

   Imgproc.warpPerspective(srcMat, dstMat, homographyMatrix, dstMat.size())

   dstMat conversion to dstPixels

this because i use int[] objects in order to display images.

Yes, i've already seen this question, but the answer is in c++ and does not really answer.

edit retag flag offensive close merge delete

Comments

why are you using an int array for your src pixels ?

opencv holds its images in uchar arrays (3 or 4 bytes per pixel), so to use opencv functionality , you would have to re-pack your src array (which will be very expensive).

berak gravatar imageberak ( 2015-02-20 10:26:30 -0600 )edit

because all my operations and all my program (that is long) works with int[] arrays. Now i have to compute this warp, i'm using OpenCV only for : findHomography and warpPerspective, so the decisions are two : or I modify ALL my program to work with Mat (ofc no ;) or i try this solution. So i don't have solutions... by the way images are 800x600 so they aren't so expensive

psykomantisita gravatar imagepsykomantisita ( 2015-02-20 10:34:01 -0600 )edit
1

again, unfortunate decision. if you at least can make a Bitmap, or a BufferedImage from that, the transition will be easier, still tremendously expensive.

berak gravatar imageberak ( 2015-02-20 10:37:31 -0600 )edit

ok i will convert my display component to bitmap obj. How can i convert ;Mat to Bitmap and vice versa?

psykomantisita gravatar imagepsykomantisita ( 2015-02-20 10:50:19 -0600 )edit
2

opencv4android has Utility functions for this

berak gravatar imageberak ( 2015-02-20 10:54:34 -0600 )edit

oh thank you very much!!

psykomantisita gravatar imagepsykomantisita ( 2015-02-20 10:59:57 -0600 )edit