我对OpenCv和StackOverflow都不熟悉,对Android编程也几乎一无所知,所以请原谅我如果我的问题很愚蠢。 我正在尝试将从相机获取的图像与某些图像文件进行匹配,以查看哪个图像文件与相机图像更相似。因此,我使用DescriptorExtractor.compute在SURF中获取文件图像和相机图像的关键点(我还尝试了SIFT)以进行匹配,但是...应用于文件图像的方法总是返回一个空的关键点列表,而如果我在相机图像上使用它,我总是得到一个非空列表(平均有一百个点)。最让我困惑的是,即使是使用完全相同的图像,首先从相机加载,然后从文件加载,我也会得到这种行为。 你能帮我找出问题出在哪里吗?以下是一些测试代码(仅针对文件部分,但我也使用相同的getKp方法从相机中提取关键点)。
非常感谢您。 Ale
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;
}
}
非常感谢您。 Ale