我正在创建一个用于查找两个图像之间匹配的应用程序。我无法正确找到匹配结果。
匹配方法给出了与输入关键点相同数量的描述符,我也无法绘制此结果。我在工作区中使用OpenCV作为库。
这是我的代码。
Bitmap mBitmap1 = mimage1.copy(Bitmap.Config.ARGB_8888, false);
Bitmap mBitmap2 = mimage2.copy(Bitmap.Config.ARGB_8888, false);
Mat s_image1 = Utils.bitmapToMat(mBitmap1);
Mat s_image2 = Utils.bitmapToMat(mBitmap2);
Mat rgb1 = new Mat();
Mat rgb2 = new Mat();
Mat rgb3 = new Mat();
Mat temp = new Mat();
Mat o_image1 = new Mat();
Mat o_image2 = new Mat();
Mat o_image3 = new Mat();
List<KeyPoint> points1 = new ArrayList<KeyPoint>();
List<KeyPoint> points2 = new ArrayList<KeyPoint>();
List<DMatch> matches = new ArrayList<DMatch>();
FeatureDetector surf = FeatureDetector.create(FeatureDetector.SURF);
surf.detect(s_image1, points1);
surf.detect(s_image2, points2);
Scalar color1 = new Scalar(0,255,0);
Scalar color2 = new Scalar(255,0,0);
Imgproc.cvtColor(s_image1, rgb1, Imgproc.COLOR_RGBA2RGB);
Imgproc.cvtColor(s_image2, rgb2, Imgproc.COLOR_RGBA2RGB);
Mat descriptors1 = new Mat(), descriptors2 = new Mat();
Features2d.drawKeypoints(rgb1, points1, rgb1, color2);
Features2d.drawKeypoints(rgb2, points2, rgb2, color2);
DescriptorExtractor extracter = DescriptorExtractor.create(DescriptorExtractor.SURF);
extracter.compute(rgb1, points1, descriptors1);
extracter.compute(rgb2, points2, descriptors2);
int k = 5;
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
matcher.match(descriptors2, descriptors1, matches);
Features2d.drawMatches(rgb1, points1, rgb2, points2, matches, rgb3, color1, color2);
Imgproc.cvtColor(rgb1, o_image1, Imgproc.COLOR_RGB2RGBA);
Imgproc.cvtColor(rgb2, o_image2, Imgproc.COLOR_RGB2RGBA);
Utils.matToBitmap(o_image1, mBitmap1);
mimageview1.setImageBitmap(mBitmap1);
Utils.matToBitmap(o_image2, mBitmap2);
mimageview2.setImageBitmap(mBitmap2);
Utils.matToBitmap(o_image3, mBitmap3);
mimageview3.setImageBitmap(mBitmap3);
s_image1.release();
s_image2.release();
o_image1.release();
o_image2.release();
答案 0 :(得分:1)
如果是锁定解决方案,我建议您使用Android NDK和C ++本机代码。它工作正常。 This tutorial很好地解释了为android
执行jni-opencv项目的步骤