Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCv in Android: keypoint detection in images from file
    text
    copied!<p>I'm new to both OpenCv and StackOverflow, and almost new to Android programming so please excuse me if my question is stupid.</p> <p>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.</p> <p>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).</p> <pre><code>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 &amp;&amp; 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&lt;KeyPoint&gt; getKp(Bitmap bm){ Mat image = Utils.bitmapToMat(bm); List&lt;KeyPoint&gt; kp = new ArrayList&lt;KeyPoint&gt;(); FeatureDetector fd = FeatureDetector.create(FeatureDetector.SURF); fd.detect(image, kp); return kp; } } </code></pre> <p>Thank you very much.</p> <p>Ale</p>
 

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