Closed Rombond closed 5 months ago
Thank you very much for reporting.
Could you try the attachment? FlannBasedMatcher_read_yml_ORB_Example.zip
This example is a C# conversion of the code on the following page, with Detector changed to ORB. https://docs.opencv.org/3.4/d5/d6f/tutorial_feature_flann_matcher.html
I assume that the error in your code is probably due to incorrectly set FlannBasedMatcher parameters.
python
# Parameters for FLANN
FLANN_INDEX_LSH = 6
index_params = dict(algorithm=FLANN_INDEX_LSH,
table_number=6, # 12
key_size=12, # 20
multi_probe_level=2) # 2
search_params = dict(checks=100)
flann = cv2.FlannBasedMatcher(index_params, search_params)
C#
var flann = FlannBasedMatcher.create();
flann.read(Utils.getFilePath("conf.yml"));
Regerds, EnoxSoftware
Oh yeah it was the missing yml Thank you for your help !
Sorry to disturb you again, but there is still a problem between the python version and the C#
Python:
C#:
Python script hasn't changes, C# script change a little bit, i used Thread to process frame, and i use LineRenderer to show my "square".
Here how i get each points:
pa = new Vector2((float)sceneCorners.get(1, 0)[0], (float)sceneCorners.get(1, 0)[1]);
pb = new Vector2((float)sceneCorners.get(2, 0)[0], (float)sceneCorners.get(2, 0)[1]);
pc = new Vector2((float)sceneCorners.get(3, 0)[0], (float)sceneCorners.get(3, 0)[1]);
pd = new Vector2((float)sceneCorners.get(0, 0)[0], (float)sceneCorners.get(0, 0)[1]);
If you used Imgproc.polylines in the c# code to draw squares on the image, did you get the same results as in the python code?
LineRenderer is a method for drawing lines in Untiy's world 3D coordinate system, so it is different from OpenCV's coordinate system, plus the camera position and perspective factors also affect it. It cannot be replaced as is.
I wan't able to use polylines, it askes a List<MatOfPoint>
but every times i create one, values are rounded.
Here how i did it in MatchPic.cs
:
Mat H = Calib3d.findHomography(obj, scene, Calib3d.RANSAC, 5);
if (!H.empty())
{
// Dessiner un rectangle autour de l'objet détecté
MatOfPoint2f templateCorners = new MatOfPoint2f(new Point(0, 0), new Point(0, 1023), new Point(1023, 1023), new Point(1023, 0));
MatOfPoint2f sceneCorners = new MatOfPoint2f();
Core.perspectiveTransform(templateCorners, sceneCorners, H);
MatOfPoint test = new MatOfPoint(new Point(sceneCorners.get(0, 0)[0], sceneCorners.get(0, 0)[1]), new Point(sceneCorners.get(1, 0)[0], sceneCorners.get(1, 0)[1]), new Point(sceneCorners.get(2, 0)[0], sceneCorners.get(2, 0)[1]), new Point(sceneCorners.get(3, 0)[0], sceneCorners.get(3, 0)[1]));
Debug.Log(sceneCorners.dump());
List<MatOfPoint> lst = new List<MatOfPoint>
{
new MatOfPoint(new Point(sceneCorners.get(0, 0)[0], sceneCorners.get(0, 0)[1])),
new MatOfPoint(new Point(sceneCorners.get(1, 0)[0], sceneCorners.get(1, 0)[1])),
new MatOfPoint(new Point(sceneCorners.get(2, 0)[0], sceneCorners.get(2, 0)[1])),
new MatOfPoint(new Point(sceneCorners.get(3, 0)[0], sceneCorners.get(3, 0)[1]))
};
Imgproc.polylines(img2Mat, lst, true, new Scalar(0, 255, 0), 10);
}
I also tried:
MatOfPoint test = new MatOfPoint(new Point(sceneCorners.get(0, 0)[0], sceneCorners.get(0, 0)[1]), new Point(sceneCorners.get(1, 0)[0], sceneCorners.get(1, 0)[1]), new Point(sceneCorners.get(2, 0)[0], sceneCorners.get(2, 0)[1]), new Point(sceneCorners.get(3, 0)[0], sceneCorners.get(3, 0)[1]));
List<MatOfPoint> lst = new List<MatOfPoint>
{
test
};
Imgproc.polylines(img2Mat, lst, true, new Scalar(0, 255, 0), 10);
And:
MatOfPoint test = new MatOfPoint();
test.fromArray(sceneCorners.toArray());
List<MatOfPoint> lst = new List<MatOfPoint>
{
test
};
Imgproc.polylines(img2Mat, lst, true, new Scalar(0, 255, 0), 10);
The MatOfPoint type that the Imgproc.polylines method takes as an argument holds a numeric value as an int type. And since Imgproc.polylines is a drawing function for image mat, it is not considered a problem to round the numeric value of the point cloud coordinates to an Int type. This is the specification of the Java version of OpenCV, from which our assets are derived.
It works with polylines, so i think it's just an issue with LineRenderer Thanks for you help !
Hi, i have this python script fully working, and i tried to implement it on Unity:
Actually i'm with this:
But when i run it, i always get errors at
flann.knnMatch(des2, matches, 2);
:Did i miss something ?