my code working when extracts keypoints, matches poorly 2 images. here can find code, don't know how draw matched in java android
descriptors = new mat(); keypoints = new matofkeypoint(); detector = featuredetector.create(featuredetector.orb); detector.detect(img1, keypoints); descriptor = descriptorextractor.create(descriptorextractor.orb); descriptor.compute(img1, keypoints, descriptors); matcher = descriptormatcher.create(descriptormatcher.bruteforce_hamming); colordetection.cvt_yuvtorgbtohsv(myuv,mgraysubmat); matofkeypoint mkeypoints = new matofkeypoint(); matofdmatch matches = new matofdmatch(); detector.detect(mgraysubmat, mkeypoints); descriptor.compute(mgraysubmat, mkeypoints, mintermediatemat); matcher.match(mintermediatemat,descriptors,matches); mintermediatemat2.create(resultsize, cvtype.cv_8uc1); features2d.drawmatches(img1, keypoints, mgraysubmat, mkeypoints, matches, mintermediatemat2,green, red, match_mask, features2d.not_draw_single_points); imgproc.resize(mintermediatemat2, mintermediatemat2, mrgba.size()); imgproc.cvtcolor(mintermediatemat2, mrgba, imgproc.color_rgba2bgra, 4); utils.mattobitmap(mrgba, bmp); dmatch dm[] = matches.toarray(); list<point> lp1 = new arraylist<point>(dm.length); list<point> lp2 = new arraylist<point>(dm.length); keypoint tkp[] = keypoints.toarray(); keypoint qkp[] = mkeypoints.toarray(); (int = 0; < dm.length; i++) { dmatch dma = dm[i]; lp1.add(tkp[dma.trainidx].pt); lp2.add(qkp[dma.queryidx].pt); } matofpoint2f pointsprev = new matofpoint2f(lp1.toarray(new point[0])); matofpoint2f pointsact = new matofpoint2f(lp2.toarray(new point[0])); log.i("pointsprev", pointsprev.size().tostring()); log.i("pointsact", pointsact.size().tostring()); fundamental_matrix.create(resultsize, cvtype.cv_8uc1); fundamental_matrix = calib3d.findfundamentalmat( pointsact, pointsprev, calib3d.fm_ransac, 3, 0.99);
any suggestion?
edit :
i can't convert matches list ! because feature2d.drawmatches()
need matofdmatch
, not list<dmatch>
matofdmatch matches, matches12, matches21; matcher.match( descriptors1, descriptors2, matches12 ); matcher.match( descriptors2, descriptors1, matches21 ); iterate matches12 dmatch forward = matches12[i]; dmatch backward = matches21[forward.trainidx]; if( backward.trainidx == forward.queryidx ) //add forward matches features2d.drawmatches(img1, keypoints, mgraysubmat, mkeypoints, matches,mintermediatemat2);
your code should this:
featuredetector detector = featuredetector.create(featuredetector.orb); descriptorextractor descriptor = descriptorextractor.create(descriptorextractor.orb);; descriptormatcher matcher = descriptormatcher.create(descriptormatcher.bruteforce_hamming); //first image mat img1 = highgui.imread("<image1 path>"); mat descriptors1 = new mat(); matofkeypoint keypoints1 = new matofkeypoint(); detector.detect(img1, keypoints1); descriptor.compute(img1, keypoints1, descriptors1); //second image mat img2 = highgui.imread("<image2 path>"); mat descriptors2 = new mat(); matofkeypoint keypoints2 = new matofkeypoint(); detector.detect(img2, keypoints2); descriptor.compute(img2, keypoints2, descriptors2); //matcher should include 2 different image's descriptors matofdmatch matches = new matofdmatch(); matcher.match(descriptors1,descriptors2,matches); //feature , connection colors scalar red = new scalar(255,0,0); scalar green = new scalar(0,255,0); //output image mat outputimg = new mat(); matofbyte drawnmatches = new matofbyte(); //this draw matches, works fine features2d.drawmatches(img1, keypoints1, img2, keypoints2, matches, outputimg, green, red, drawnmatches, features2d.not_draw_single_points);
also if want display features, can add code:
mat featuredimg = new mat(); scalar kpcolor = new scalar(255,159,10);//this color of keypoints //featuredimg output of first image features2d.drawkeypoints(img1, keypoints1, featuredimg , kpcolor, 0); //featuredimg output of first image features2d.drawkeypoints(img1, keypoints1, featuredimg , kpcolor, 0);
then can show matched points this:
bitmap imagematched = bitmap.createbitmap(outputimg.cols(), outputimg.rows(), bitmap.config.rgb_565);//need save bitmap utils.mattobitmap(outputimg, imagematched); imageview.setimagebitmap(imagematched);
eventually can implement matches. hope this thread helpful.
Comments
Post a Comment