Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay IplImage as Android Bitmap
    primarykey
    data
    text
    <p>I'm working on a facedetect Android application which uses the OpenCV 2.3.1 library. I've found some code which allow me to make a photo on my Samsung GT-P1000 and save it in the gallery. Then I want to select the image from the gallery which allows a .cpp file to use OpenCV functions. This requires a bitmap to IplImage conversion (the .java and .cpp code snippets are added below).</p> <p><strong>The java code looks like this:</strong></p> <pre><code>Bitmap bitmap = BitmapFactory.decodeFile(mCurrentImagePath); Log.i(TAG, mCurrentImagePath); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); opencv.setSourceImage(pixels, width, height); byte[] imageData = opencv.getSourceImage(); bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); mImageView.setImageBitmap(bitmap); </code></pre> <p><strong>The C++ code looks like this:</strong></p> <pre><code>IplImage * pImage = NULL; IplImage * loadpixels(int * pixels, int width, int height); IplImage * getIplImageFromIntArray (JNIEnv* env, jintArray array_data, jint width, jint height); JNIEXPORT jboolean JNICALL Java_org_opencv_example_pruts_Test1OpenCV_setSourceImage (JNIEnv * env, jobject thiz, jintArray photo_data, jint width, jint height) { if(pImage != NULL) { cvReleaseImage(&amp;pImage); pImage = NULL; } pImage = getIplImageFromIntArray(env, photo_data, width, height); if(pImage == 0) { return 0; } return 1; } </code></pre> <p>However I need another JNIEXPORT function which converts the IplImage to bitmap data. Therefor the last 4 lines of code will be used. imageData should be filled so BitmapFactory can decode it. I came across load of examples and these code snippets come from those as well. However I'm not able to find a solution for my problem. Does anyone has some suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload