/// <summary>
 /// The constructor.
 /// </summary>
 /// <param name="dextractor">Descriptor extractor that is used to compute descriptors for an input image and its keypoints.</param>
 /// <param name="dmatcher">Descriptor matcher that is used to find the nearest word of the trained vocabulary for each keypoint descriptor of the image.</param>
 public BOWImgDescriptorExtractor(Feature2D dextractor, DescriptorMatcher dmatcher)
 {
     if (dextractor == null)
         throw new ArgumentNullException(nameof(dextractor));
     if (dmatcher == null)
         throw new ArgumentNullException(nameof(dmatcher));
     ptr = NativeMethods.features2d_BOWImgDescriptorExtractor_new1(dextractor.PtrObj, dmatcher.PtrObj);
 }
 /// <summary>
 /// The constructor.
 /// </summary>
 /// <param name="dmatcher">Descriptor matcher that is used to find the nearest word of the trained vocabulary for each keypoint descriptor of the image.</param>
 public BOWImgDescriptorExtractor(DescriptorMatcher dmatcher)
 {
     if (dmatcher == null)
     {
         throw new ArgumentNullException(nameof(dmatcher));
     }
     ptr = NativeMethods.features2d_BOWImgDescriptorExtractor_new2(dmatcher.PtrObj);
 }
 /// <summary>
 /// The constructor.
 /// </summary>
 /// <param name="dmatcher">Descriptor matcher that is used to find the nearest word of the trained vocabulary for each keypoint descriptor of the image.</param>
 public BOWImgDescriptorExtractor(DescriptorMatcher dmatcher)
 {
     if (dmatcher == null)
     {
         throw new ArgumentNullException(nameof(dmatcher));
     }
     ptr = NativeMethods.features2d_BOWImgDescriptorExtractor_new2_RawPtr(dmatcher.CvPtr);
     GC.KeepAlive(dmatcher);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates instance from raw pointer T*
 /// </summary>
 /// <param name="ptr"></param>
 internal static DescriptorMatcher FromRawPtr(IntPtr ptr)
 {
     if (ptr == IntPtr.Zero)
         throw new OpenCvSharpException("Invalid DescriptorMatcher pointer");
     var detector = new DescriptorMatcher
     {
         detectorPtr = null,
         ptr = ptr
     };
     return detector;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates instance from cv::Ptr&lt;T&gt; .
 /// ptr is disposed when the wrapper disposes. 
 /// </summary>
 /// <param name="ptr"></param>
 internal static DescriptorMatcher FromPtr(IntPtr ptr)
 {
     if (ptr == IntPtr.Zero)
         throw new OpenCvSharpException("Invalid cv::Ptr<DescriptorMatcher> pointer");
     var ptrObj = new Ptr(ptr);
     var detector = new DescriptorMatcher
     {
         detectorPtr = ptrObj,
         ptr = ptrObj.Get()
     };
     return detector;
 }
Exemplo n.º 6
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="dextractor">Descriptor extractor that is used to compute descriptors for an input image and its keypoints.</param>
        /// <param name="dmatcher">Descriptor matcher that is used to find the nearest word of the trained vocabulary for each keypoint descriptor of the image.</param>
        public BOWImgDescriptorExtractor(Feature2D dextractor, DescriptorMatcher dmatcher)
        {
            if (dextractor == null)
            {
                throw new ArgumentNullException(nameof(dextractor));
            }
            if (dmatcher == null)
            {
                throw new ArgumentNullException(nameof(dmatcher));
            }

            NativeMethods.HandleException(
                NativeMethods.features2d_BOWImgDescriptorExtractor_new1_RawPtr(dextractor.CvPtr, dmatcher.CvPtr, out ptr));

            GC.KeepAlive(dextractor);
            GC.KeepAlive(dmatcher);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates instance from cv::Ptr&lt;T&gt; .
 /// ptr is disposed when the wrapper disposes. 
 /// </summary>
 /// <param name="ptr"></param>
 internal static DescriptorMatcher FromPtr(IntPtr ptr)
 {
     if (ptr == IntPtr.Zero)
         throw new OpenCvSharpException("Invalid cv::Ptr<DescriptorMatcher> pointer");
     var ptrObj = new Ptr<DescriptorMatcher>(ptr);
     var detector = new DescriptorMatcher
     {
         detectorPtr = ptrObj,
         ptr = ptrObj.Get()
     };
     return detector;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Creates instance from raw pointer T*
 /// </summary>
 /// <param name="ptr"></param>
 internal static DescriptorMatcher FromRawPtr(IntPtr ptr)
 {
     if (ptr == IntPtr.Zero)
         throw new OpenCvSharpException("Invalid DescriptorMatcher pointer");
     var detector = new DescriptorMatcher
     {
         detectorPtr = null,
         ptr = ptr
     };
     return detector;
 }
    void Start()
    {
        //thread = new Thread(new ThreadStart(ThreadMainFunc));
        //thread = new Thread(ThreadMainFunc);
        //thread.IsBackground = true;
        //thread = Loom.RunAsync(ThreadMainFunc);
        //thread.Start();
        //textTex = Resources.Load<Texture2D>("test-IMG_0204-text");
        //rawImageRI.texture = textTex;

        //TextAsset binary = (TextAsset)AssetDatabase.LoadAssetAtPath("Assets/img1.bytes", typeof(TextAsset));

        //inputTex = Resources.Load<Texture2D>("test-IMG_0204");
        //rawImageRI.texture = inputTex;
        //Debug.Log("inputTex.width: "+inputTex.width);
        //Debug.Log("inputTex.height: "+inputTex.height);

        //tex.LoadImage(binary.bytes);
        //Texture2D tex = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/img.PNG", typeof(Texture2D));

        //StartCoroutine(GetTextImg());

        //Size texSize = new Size(tex.width, tex.height);
        //Mat mat = new Mat(texSize, CvType.CV_8UC4);
        //Utils.texture2DToMat(tex, mat);

        //inputImg = Cv2.ImRead(imgPath);
        //Cv2.ImShow("inputImg", inputImg);

        //tex = Unity.MatToTexture(inputImg);
        //rawImageRI.texture = tex;

        /*inputTex = new Texture2D(2,2);
         * string imgPath = "../signboard-rectangle/test-IMG_0204.PNG";
         * byte [] binaryImageData = File.ReadAllBytes(imgPath);
         * inputTex.LoadImage(binaryImageData);*/

        //inputTex = Resources.Load<Texture2D>("forAddText");

        //必要 防止記憶體爆炸
        Texture2D inputTex1 = TextureGray.ToGray("1");
        Texture2D inputTex2 = TextureGray.ToGray("2");

        //Texture2D inputTex3 = TextureGray.ToGray("3");
        //Debug.Log("inputTex.width: "+inputTex.width);
        //Debug.Log("inputTex.height: "+inputTex.height);

        //rawImageRI.texture = inputTex;

        OpenCvSharp.Mat inputImg1 = Unity.TextureToMat(inputTex1);
        OpenCvSharp.Mat inputImg2 = Unity.TextureToMat(inputTex2);
        //OpenCvSharp.Mat inputImg3 = Unity.TextureToMat(inputTex3);
        //OpenCvSharp.Mat inputImg2 = Unity.TextureToMat(inputTex);
        //Cv2.ImShow("img", inputImg);

        InputArray img1 = InputArray.Create(inputImg1);
        InputArray img2 = InputArray.Create(inputImg2);

        //InputArray img3 = InputArray.Create(inputImg3);
        //Debug.Log("inputImg: "+inputImg.ToString());
        //InputArray mask = null;
        //OpenCvSharp.KeyPoint[] kp1 = null;
        des1 = OutputArray.Create(inputImg1);
        des2 = OutputArray.Create(inputImg2);
        //des3 = OutputArray.Create(inputImg3);
        //Debug.Log("des1: "+des1);

        //Initiate SIFT detector and extractor
        //siftDetect = FeatureDetector.create(3);
        //siftExtract = DescriptorExtractor.create(1);

        sift = SIFT.Create();
        //surf = SURF.Create((double)100);
        //orb = OpenCvSharp.ORB.Create();
        //brief = OpenCvSharp.XFeatures2D.BriefDescriptorExtractor.Create();

        //if image too large will cause app Terminated due to memory error
        kp1 = sift.Detect(inputImg1);
        kp2 = sift.Detect(inputImg2);
        //kp3 = sift.Detect(inputImg3);
        //kp1 = surf.Detect(inputImg);
        //kp1 = orb.Detect(inputImg);
        //kp1 = brief.Detect(inputImg);

        //Cv2.ImShow("img", inputImg); ok

        sift.Compute(img1, ref kp1, des1);
        sift.Compute(img2, ref kp2, des2);
        //sift.Compute(img3, ref kp3, des3);
        //surf.Compute(img1, ref kp1, des1);
        //orb.Compute(img1, ref kp1, des1);
        //brief.Compute(img1, ref kp1, des1);

        //Cv2.ImShow("img", inputImg); 亂碼圖
        //Cv2.ImShow("img", inputImg2); ok

        //foreach (OpenCvSharp.KeyPoint kp in kp1)
        // Debug.Log("kp: "+kp.ToString());

        //用flannbased的話unity會掛掉
        descriptorMatcher = OpenCvSharp.DescriptorMatcher.Create("BruteForce");

        //sift.DetectAndCompute(img1, mask, out kp1, des1);

        //MatOfKeyPoint kp1 = new MatOfKeyPoint();
        //Mat des1 = new Mat();
        //siftDetect.detect(inputImg, kp1);
        //siftExtract.compute(inputImg, kp1, des1);

        //StartCoroutine(OpenCamera());//開啟攝影機鏡頭
        //StartCoroutine(CalculateHomography());

        /*Texture2D sourceTex = ScreenCapture.CaptureScreenshotAsTexture();
         * Color[] pix = sourceTex.GetPixels((int)rectBotLeft.x, (int)rectBotLeft.y, width, height);
         * tex = new Texture2D(width, height);
         * tex.SetPixels(pix);
         * tex.Apply();
         *
         * tex = TextureGray.ToGray(tex);
         *
         * mat = Unity.TextureToMat(tex);
         *
         * InputArray img2 = InputArray.Create(mat);
         * desCam = OutputArray.Create(mat);
         *
         * kpCam = sift.Detect(mat);*/
    }