Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9202329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:13:51+00:00 2026-06-17T23:13:51+00:00

I am trying to process a bmp image obtained from Android’s camera intent through

  • 0

I am trying to process a bmp image obtained from Android’s camera intent through the following steps:

  1. Obtain bmp image from intent
  2. Convert bmp image to Mat object for OpenCV processing (problem starts here)
  3. Do needed OpenCV processing (through sending Mat object, obj, as obj.getNativeObjAddr() to native processing, or perform it locally in java).
  4. Convert Mat object back to bmp

The problem is indeed not novel. I have found countless similar questions online, none of which seem to resolve the situation however.

Results (problem)

The intention is to display the processed image (that undergoes the above 4 steps) in an ImageView object. After running, the ImageView however remains unchanged and logcat emits the following warning on reaching the line calling Utils.bitmapToMat()

 W/System.err(3872): java.lang.IllegalArgumentException: mat == null

Code

Below is the code’s outline that is used in the onActivityResult method (resultant_bmp is the acquired bmp from the camera intent. It displays successfully on its own).
filePath is the file path, name and extension included, of resultant_bmp.

The first 3 lines following the starting if condition are from here, where its use seems to work fine in the mentioned question.

Bitmap resultant_bmp /*image from camera*/,   
       bmp /*image after opencv processing*/;
Mat rgb_img, gray_img;      

if (OpenCVLoader.initDebug()) { 

     BitmapFactory.Options options = new BitmapFactory.Options();
     options.inPreferredConfig = Config.RGB_565;
     resultant_bmp= BitmapFactory.decodeFile(filePath, options);

     /****************** Problem starts HERE ******************
     Last point reachable before Logcat states:
       W/System.err(4460):java.lang.IllegalArgumentException: mat == null   

     After this point, the program doesn't crash, but expected results 
       in the imageView (last line of code) do not result.
     **********************************************************/  

     Utils.bitmapToMat(resultant_bmp, rgb_img);                                 
     Imgproc.cvtColor(rgb_img, gray_img, Imgproc.COLOR_RGBA2GRAY); 

     /*Do opencv processing (on gray_img) here*/

     Utils.matToBitmap(gray_img, bmp);

     imageView.setImageBitmap(bmp);

}

Previous attempts& research

  • I found a similar problem here and tried, as recommended, to push the file libopencv_java.so to system/lib on the device, using adb in command line and received the error:

failed to copy 'libopencv_java.so' to 'system/lib/libopencv_java.so': Read-only file system

  • This question considers the same problem domain in the current question; the code provided above follows a similar pattern as that suggested there, which still doesn’t work.

  • Based on this answer (as well as this aforementioned one), I added the following lines to the code:

System.loadLibrary("opencv_java");
System.loadLibrary("libopencv_java");

  • I have added the OpenCV library to the project properties; as well as the NDKROOT variable indicating where the NDK root path lies, as explained further here.

  • I’ve tried the image processing required (in step 3 above) in another working sample of OpenCV’s, so the problem definitely lies within step 2 (above); conversion of a bmp to a Mat object.

There should be a simple solution around this, but I cannot seem to find it. Help would be much appreciated if possible.

Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:13:52+00:00Added an answer on June 17, 2026 at 11:13 pm

    Have you initialized your mat variable ? I couldnt find it in provided code.

    Add this before you try to convert to mat.

    Mat rgb_img = new Mat();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to process data obtained from a run of diff to an instance
While trying to process and obtain data from an XML document, I want to
I'm trying to process recurring payments through Authorize.Net with the following requirements: Payment processing
I'm trying to process data obtained from a csv file using csv module in
I'm trying to process some imagedata which comes directly from the device camera. In
I am trying to process 114,000 rows in a dataset (populated from an oracle
I am trying to process the response from paypal on my page. I found
I'm trying to process an array from data posted from a textbox. I've written
I'm trying to process a directory of JPEG images (roughly 600+, ranging from 50k
I'm trying to convert a bitmap image into an uncompressed tif file for use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.