2016-02-09 09:55:36 -0600
| commented answer | Drawing bounding box in java Hi. Why do you multiply arcLength for 0.02? |
2016-02-07 01:16:01 -0600
| asked a question | Problem with homography Hi, i want this:
but i obtain this with my code:
and my code is: Bitmap Matches(){
Mat images1 = new Mat();
Mat images2 = new Mat();
images1 = immagine1.clone();
images2 = immagine2.clone();
// trovo i keypoint
final MatOfKeyPoint keypoint1 = new MatOfKeyPoint();
final MatOfKeyPoint keypoint2 = new MatOfKeyPoint();
final Mat descriptor1 = new Mat();
final Mat descriptor2 = new Mat();
final Mat out_put_image = new Mat();
Bitmap image;
final MatOfDMatch dMatch = new MatOfDMatch();
FeatureDetector detector = FeatureDetector.create(FeatureDetector.BRISK);
final DescriptorExtractor descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
final DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
detector.detect(images1, keypoint1);
detector.detect(images2, keypoint2);
// trovo i descrittori
descriptorExtractor.compute(images1, keypoint1, descriptor1);
descriptorExtractor.compute(images2, keypoint2, descriptor2);
// trovo i match
matcher.match(descriptor2, descriptor1, dMatch);
//calculate max and min distances between keypoints
double max_dist=0;double min_dist=99;
List<DMatch> matchesList = dMatch.toList();
for(int i=0;i<descriptor2.rows();i++)
{
double dist = matchesList.get(i).distance;
if (dist < min_dist && dist != 0)
{
min_dist = dist;
}
if (dist > max_dist)
{
max_dist = dist;
}
}
double threshold = 3 * min_dist;
double threshold2 = 2 * min_dist;
if (threshold2 >= max_dist)
{
threshold = min_dist * 1.1;
}
else if (threshold >= max_dist)
{
threshold = threshold2 * 1.4;
}
//set up good matches, add matches if close enough
LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
MatOfDMatch gm = new MatOfDMatch();
for (int i = 0; i < matchesList.size(); i++)
{
double dist = matchesList.get(i).distance;
if (dist < threshold)
{
good_matches.add(dMatch.toList().get(i));
}
}
gm.fromList(good_matches);
//put keypoints mats into lists
List<KeyPoint> keypoints1_List = keypoint1.toList();
List<KeyPoint> keypoints2_List = keypoint2.toList();
//put keypoints into point2f mats so calib3d can use them to find homography
LinkedList<Point> objList = new LinkedList<Point>();
LinkedList<KeyPoint> objK = new LinkedList<>();
LinkedList<Point> sceneList = new LinkedList<Point>();
LinkedList<KeyPoint> scnK = new LinkedList<>();
for(int i=0;i<good_matches.size();i++)
{
objList.addLast(keypoints1_List.get(good_matches.get(i).trainIdx).pt);
objK.add(keypoints1_List.get(good_matches.get(i).trainIdx));
sceneList.addLast(keypoints2_List.get(good_matches.get(i).queryIdx).pt);
scnK.addLast(keypoints2_List.get(good_matches.get(i).queryIdx));
}
MatOfPoint2f obj = new MatOfPoint2f();
MatOfPoint2f scene = new MatOfPoint2f();
obj.fromList(objList);
scene.fromList(sceneList);
//run homography on object and scene points
Mat H = Calib3d.findHomography(obj, scene, Calib3d.RANSAC, 0.001);
// Trovo i contorni:
Mat gray1 = new Mat();
Mat hierarchy = new Mat();
Mat cannyEdges = new Mat();
List<MatOfPoint> contourList = new ArrayList<>();
Imgproc.cvtColor(images1, gray1, Imgproc.COLOR_BGR2GRAY);
Imgproc.Canny(images1, cannyEdges, 10, 110);
Imgproc.findContours(cannyEdges, contourList, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
Mat obj_mat = Converters.vector_Point_to_Mat(contourList.get(0).toList(),CvType.CV_32F);
Mat destination = new Mat(obj_mat.rows(),obj_mat.cols(),CvType.CV_32F);
List<MatOfPoint> contourLists = new ArrayList<>();
//Creo l'immagine
Imgproc.cvtColor(images1, images1, Imgproc.COLOR_BGR2RGB);
Imgproc.cvtColor(images2, images2, Imgproc.COLOR_BGR2RGB);
MatOfPoint2f approxCurve = new MatOfPoint2f();
//For each contour found
for (int i=0; i<contourList.size(); i++)
{
//Convert contours(i) from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f( contourList.get(i).toArray() );
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);
//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint( approxCurve.toArray() );
// Get bounding rect of contour
Rect ... (more) |
2016-02-05 13:15:59 -0600
| commented answer | RANSAC inliers For me inliers is a matrix, in inliers.get(0,0) = 0 what does is means? |
2016-02-05 13:09:15 -0600
| commented answer | RANSAC inliers |
2016-02-05 11:59:39 -0600
| asked a question | RANSAC inliers With: Mat H = Calib3d.findHomography(oggetto,scena,Calib3d.RANSAC,50,inliers,25,0.90);
I have the inliers, but the matrix is a series of 0 and 1. I need to say if in the inliers.get(i,j) i and j indicate the index of point used to obtain the homography? |
2016-02-05 11:01:33 -0600
| asked a question | Contours with Homography Application Hi, I have founded the homography matrix H with Calib3d.findHomography() , and now i want to apply it on a point of contours and i use this: // trovo il contorno dell'oggetto
Mat edges = new Mat();
Mat hierarchy = new Mat();
// ogni contorno è una lista di punti
List<MatOfPoint> contourList = new ArrayList<MatOfPoint>(); // lista dei contorni
Imgproc.Canny(images1, edges, 10, 100);
//Trovo i contorni
Imgproc.findContours(edges, contourList, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
List<MatOfPoint> perspectiveMat = new ArrayList<>();
for (int i = 0; i < contourList.size() ; i++){
MatOfPoint matrix = contourList.get(i);
Mat M = Converters.vector_Point_to_Mat(matrix.toList());
Mat perspective = new Mat(M.cols(),M.rows(),CvType.CV_32FC2);
Imgproc.warpPerspective(M, perspective, H, new Size(M.cols(),M.rows()));
List<org.opencv.core.Point> perspectiveContours = new ArrayList<>();
Converters.Mat_to_vector_Point(perspective, perspectiveContours);
MatOfPoint perspectivepointmatrix = new MatOfPoint();
perspectivepointmatrix.fromList(perspectiveContours);
perspectiveMat.add(perspectivepointmatrix);
}
But I have this error: 02-05 17:52:17.900 29178-29178/com.opencv.users.brisk E/cv::error(): OpenCV Error: Assertion failed (ifunc != 0) in void cv::remap(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, int, int, const Scalar&), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/imgwarp.cpp, line 3247
02-05 17:52:17.912 29178-29178/com.opencv.usersproc: imgproc::warpPerspective_12() caught std::exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/imgwarp.cpp:3247: error: (-215) ifunc != 0 in function void cv::remap(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, int, int, const Scalar&)
02-05 17:52:17.913 29178-29178/com.opencv.users.brisk D/AndroidRuntime: Shutting down VM
02-05 17:52:17.924 29178-29178/com.opencv.userse: FATAL EXCEPTION: main
Process: com.opencv.users.brisk, PID: 29178
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.Exception: std::exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/imgwarp.cpp:3247: error: (-215) ifunc != 0 in function void cv::remap(cv::InputArray, cv::OutputArray, cv::InputArray, cv::InputArray, int, int, const Scalar&)
Pleas can you give me an hand to this error? |
2016-02-04 10:20:21 -0600
| received badge | ● Critic
(source)
|
2016-02-04 01:38:12 -0600
| received badge | ● Enthusiast
|
2016-02-03 15:18:18 -0600
| received badge | ● Editor
(source)
|
2016-02-03 15:12:22 -0600
| asked a question | BRISK Detector with RANSAC HI, I find the keypoint and the match between two images with BRISK ( I have to use it ) but now I need to use RANSAC to estimate the correspondence better than the only matcher function.
Can you help me? I think:
I take the position of keypoint in the object and in the scene and calculate Homography with it, but i don't now how to continue. Please help me. This is my code: Bitmap Matches(){
FeatureDetector detector;
MatOfKeyPoint keypoints1, keypoints2;
DescriptorExtractor descriptorExtractor;
Mat descriptors1, descriptors2;
DescriptorMatcher descriptorMatcher;
MatOfDMatch matches = new MatOfDMatch();
keypoints1 = new MatOfKeyPoint();
keypoints2 = new MatOfKeyPoint();
descriptors1 = new Mat();
descriptors2 = new Mat();
detector = FeatureDetector.create(FeatureDetector.BRISK);
descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
detector.detect(immagine1,keypoints1);
detector.detect(immagine2, keypoints2);
descriptorExtractor.compute(immagine1, keypoints1, descriptors1);
descriptorExtractor.compute(immagine2, keypoints2, descriptors2);
descriptorMatcher.match(descriptors2, descriptors1, matches);
//calculate max and min distances between keypoints
double max_dist=0;double min_dist=99;
List<DMatch> matchesList = matches.toList();
for(int i=0;i<descriptors2.rows();i++)
{
double dist = matchesList.get(i).distance;
if (dist<min_dist) min_dist = dist;
if (dist>max_dist) max_dist = dist;
}
//set up good matches, add matches if close enough
LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
MatOfDMatch gm = new MatOfDMatch();
for (int i=0;i<descriptors1.rows();i++)
{
if(matchesList.get(i).distance<max_dist)
{
good_matches.addLast(matchesList.get(i));
}
}
gm.fromList(good_matches);
//put keypoints mats into lists
List<KeyPoint> keypoints1_List = keypoints1.toList();
List<KeyPoint> keypoints2_List = keypoints2.toList();
//put keypoints into point2f mats so calib3d can use them to find homography
LinkedList<Point> objList = new LinkedList<Point>();
LinkedList<Point> sceneList = new LinkedList<Point>();
for(int i=0;i<good_matches.size();i++)
{
objList.addLast(keypoints1_List.get(good_matches.get(i).trainIdx).pt);
sceneList.addLast(keypoints2_List.get(good_matches.get(i).queryIdx).pt);
}
MatOfPoint2f obj = new MatOfPoint2f();
MatOfPoint2f scene = new MatOfPoint2f();
obj.fromList(objList);
scene.fromList(sceneList);
//output image
Mat outputImg = new Mat();
MatOfByte drawnMatches = new MatOfByte();
Features2d.drawMatches(immagine1, keypoints1, immagine2, keypoints2, gm, outputImg,
Scalar.all(-1), Scalar.all(-1), drawnMatches,Features2d.NOT_DRAW_SINGLE_POINTS);
//run homography on object and scene points
Mat H = Calib3d.findHomography(obj, scene,Calib3d.RANSAC, 10);
// trovo il contorno dell'oggetto
Mat edges = new Mat();
Mat hierarchy = new Mat();
// ogni contorno è una lista di punti
List<MatOfPoint> contourList = new ArrayList<MatOfPoint>(); // lista dei contorni
Imgproc.Canny(immagine1_grey, edges, 10, 100);
// Applico la trasformazione all'immagine
Mat bordi = new Mat(edges.cols(),edges.rows(),CvType.CV_32FC2);
//Trovo i contorni
Imgproc.findContours(edges,contourList,hierarchy,Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
MatOfPoint2f approxCurve = new MatOfPoint2f();
MatOfPoint points = null;
//For each contour found
for (int i=0; i<contourList.size(); i++)
{
//Convert contours(i) from MatOfPoint to MatOfPoint2f
MatOfPoint2f contour2f = new MatOfPoint2f( contourList.get(i).toArray() );
//Processing on mMOP2f1 which is in type MatOfPoint2f
double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);
//Convert back to MatOfPoint
points = new MatOfPoint( approxCurve.toArray() );
// Get bounding rect of contour
Rect rect = Imgproc.boundingRect(points);
// draw enclosing rectangle (all same color, but you could use variable i to make them ... (more) |
2016-01-30 07:06:05 -0600
| asked a question | Problema to compile the non free library SURF/SIFT I will do an app for android that contain the SURF e SIFT extractor but the idk give me this error: " make: Entering directory /Users/marcomameli/OneDrive/SURF'
jni/Android.mk:5: Users/marcomameli/AndroidStudioProject/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk: No such file or directory
make: *** No rule to make target Users/marcomameli/AndroidStudioProject/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk'. Stop.
make: Leaving directory `/Users/marcomameli/OneDrive/SURF' " How can i fix it? Please help me. |