Exemplo n.º 1
0
        /// <summary>
        /// Load the Mat from file
        /// </summary>
        /// <param name="fileName">The name of the file</param>
        /// <param name="loadType">File loading method</param>
        public Mat(String fileName, CvEnum.ImreadModes loadType = ImreadModes.Color)
            : this(MatInvoke.cveMatCreate(), true, false)
        {
            using (CvString s = new CvString(fileName))
            {
                CvInvoke.cveImread(s, loadType, this);

                if (this.IsEmpty) //failed to load in the first attempt
                {
#if !(NETFX_CORE || UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE || UNITY_METRO || UNITY_EDITOR)
                    if (File.Exists(fileName))
                    {
                        //try again to see if this is a Unicode issue in the file name.
                        //Work around for Open CV ticket:
                        //https://github.com/Itseez/opencv/issues/4292
                        //https://github.com/Itseez/opencv/issues/4866

                        byte[] raw = File.ReadAllBytes(fileName);
                        CvInvoke.Imdecode(raw, loadType, this);

                        if (IsEmpty)
                        {
                            throw new ArgumentException(String.Format("Unable to decode file: {0}", fileName));
                        }
                    }
                    else
                    {
                        throw new ArgumentException(String.Format("File {0} do not exist", fileName));
                    }
#endif
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create an empty cv::Mat
 /// </summary>
 public Mat()
     : this(MatInvoke.cveMatCreate(), true, true)
 {
 }
Exemplo n.º 3
0
 /// <summary>
 /// Load the Mat from file
 /// </summary>
 /// <param name="fileName">The name of the file</param>
 /// <param name="loadType">File loading method</param>
 public Mat(String fileName, CvEnum.LoadImageType loadType)
     : this(MatInvoke.cveMatCreate(), true, false)
 {
     using (CvString s = new CvString(fileName))
         CvInvoke.cveImread(s, loadType, this);
 }