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 6794123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:11:02+00:00 2026-05-26T18:11:02+00:00

I’m new to both OpenCv and StackOverflow, and almost new to Android programming so

  • 0

I’m new to both OpenCv and StackOverflow, and almost new to Android programming so please excuse me if my question is stupid.

I am trying to match an image acquired from camera against some image files, to see which image file is more similar to the camera image. So I use DescriptorExtractor.compute to get the keypoints of the file image and the camera image with SURF (I also tried SIFT) in order to match them but… the method applied to the file image always returns an empty keypoint list, while if I use it on the camera image, I always get a non empty list (a hundred of points on average). What puzzles me most is that the even using the very same image, loaded from the camera first, and then from file, I get this behavior.

Could you please help me figure out what I’m doing wrong? Here is some test code (only for the file part, but I use the same method getKp to extract keypoints from camera as well).

public class HelloOpenCvActivity extends Activity {
    private static final int FILE_REQUEST = 400;
    /** Called when the activity is first created. */

    ImageView img;
    TextView txt;
    Bitmap logo;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        img = (ImageView) findViewById(R.id.image);
        txt = (TextView) findViewById(R.id.kp);

        img.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                chooseFile();               
            }
        });
    }

    private void chooseFile(){
        Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
        fileIntent.addCategory(Intent.CATEGORY_OPENABLE);
        fileIntent.setType("image/*");
        startActivityForResult(Intent.createChooser(fileIntent,"prova"), FILE_REQUEST); 
    }

    /*Quando ho il risultato della chiamata al file explorer, viene invocata questa callback */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == FILE_REQUEST) {  
            // obtain the filename
            Uri uri = data.getData();
            String filePath = null;
            if (uri != null) {
                if (uri.toString().startsWith("file:")) {
                    filePath = uri.getPath();
                } else { // uri.startsWith("content:")
                    Cursor c = getContentResolver().query(uri, null, null, null, null);
                    if (c != null && c.moveToFirst()) {
                        int id = c.getColumnIndex(Images.Media.DATA);
                        if (id != -1) {
                            filePath = c.getString(id);
                        }
                    }
                }
            }
            if (filePath != null) {
                logo = BitmapFactory.decodeFile(filePath);
                img.setImageBitmap(logo);
                txt.setText(""+getKp(logo).size());
            }
        }  
    }

    private List<KeyPoint> getKp(Bitmap bm){
        Mat image = Utils.bitmapToMat(bm);

        List<KeyPoint> kp = new ArrayList<KeyPoint>();
        FeatureDetector fd = FeatureDetector.create(FeatureDetector.SURF);
        fd.detect(image, kp);


        return kp;
    }

}

Thank you very much.

Ale

  • 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-05-26T18:11:02+00:00Added an answer on May 26, 2026 at 6:11 pm

    After hours of research and headache 😉 I have found the problem. Images from camera and file can be both stored in bitmap objects, but their config (Bitmap.Config) is different: ARGB_8888 for camera images and RGB_565 for file ones. Changing bitmap configuration in file images to ARGB_8888 with Bitmap.copy method is the solution.

    private List<KeyPoint> getKp(Bitmap bm){
        //scale bitmap (otherwise the program crashes due to memory lack)
        int MAX_DIM = 300;
        int w, h;       
        if (bm.getWidth() >= bm.getHeight()){
            w = MAX_DIM;
            h = bm.getHeight()*MAX_DIM/bm.getWidth();
        }
        else{
            h = MAX_DIM;
            w = bm.getWidth()*MAX_DIM/bm.getHeight();
        }
        bm = Bitmap.createScaledBitmap(bm, w, h, false);
    
        //change bitmap config <- THAT'S THE POINT!
        Bitmap img = bm.copy(Bitmap.Config.ARGB_8888, false);           
    
        Mat image = Utils.bitmapToMat(img);
    
        List<KeyPoint> kp = new ArrayList<KeyPoint>();
        FeatureDetector fd = FeatureDetector.create(FeatureDetector.SURF);
        fd.detect(image, kp);
    
        return kp;
    }
    

    Hope this can help anybody who runs into the same issue. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post

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.