EnoxSoftware / MarkerLessARExample

This asset is a Marker-Less Augmented Reality Example using the actual environment as input instead of printed square markers and display 3d model in WebCamTexture in real-time.
https://assetstore.unity.com/packages/templates/tutorials/markerless-ar-example-77560
25 stars 5 forks source link

Feature Description Data Persistence #10

Open gushenjie opened 3 years ago

gushenjie commented 3 years ago

p.savetxt(outputImgPath ,des , fmt='%.2f')

Python code saves image features and sample code. How does unityforopencv persist image features, including saving and reading? Do you give some suggestions and guidance?

EnoxSoftware commented 3 years ago

OpenCVForUnity does not have a way to directly save Mat values to a text file. However, it is possible to save the Mat as an image file.

            MatOfKeyPoint keypoints1 = new MatOfKeyPoint ();
            Mat descriptors1 = new Mat ();

            detector.detect (img1Mat, keypoints1);
            extractor.compute (img1Mat, keypoints1, descriptors1);

            Debug.Log("descriptors1.ToString() " + descriptors1.ToString());
            Debug.Log("descriptors1.dump() " + descriptors1.dump());

            Imgcodecs.imwrite("C:/Users/satoo/Desktop/des.png", descriptors1);

            Mat loadDes1 = Imgcodecs.imread("C:/Users/satoo/Desktop/des.png", Imgcodecs.IMREAD_GRAYSCALE);

            Debug.Log("loadDes1.ToString() " + loadDes1.ToString());
            Debug.Log("loadDes1.dump() " + loadDes1.dump());
gushenjie commented 3 years ago

Sorry, using the method you gave, the program feature point matching is always 0, but I used the MAT to JSON format to save the descriptors as a txt file, and the function is normal. Now I still want to save the keypoints data together, and I am still trying. Do you have any good suggestions?

gushenjie commented 3 years ago

OpenCVForUnity does not have a way to directly save Mat values to a text file. However, it is possible to save the Mat as an image file.

            MatOfKeyPoint keypoints1 = new MatOfKeyPoint ();
            Mat descriptors1 = new Mat ();

            detector.detect (img1Mat, keypoints1);
            extractor.compute (img1Mat, keypoints1, descriptors1);

            Debug.Log("descriptors1.ToString() " + descriptors1.ToString());
            Debug.Log("descriptors1.dump() " + descriptors1.dump());

            Imgcodecs.imwrite("C:/Users/satoo/Desktop/des.png", descriptors1);

            Mat loadDes1 = Imgcodecs.imread("C:/Users/satoo/Desktop/des.png", Imgcodecs.IMREAD_GRAYSCALE);

            Debug.Log("loadDes1.ToString() " + loadDes1.ToString());
            Debug.Log("loadDes1.dump() " + loadDes1.dump());

Sorry, using the method you gave, the program feature point matching is always 0, but I used the MAT to JSON format to save the descriptors as a txt file, and the function is normal. Now I still want to save the keypoints data together, and I am still trying. Do you have any good suggestions?