Пример #1
0
      /// <summary>
      /// Saves the image to the specified file. The image format is chosen depending on the filename extension, see cvLoadImage. Only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. If the format, depth or channel order is different, use cvCvtScale and cvCvtColor to convert it before saving, or use universal cvSave to save the image to XML or YAML format
      /// </summary>
      /// <param name="filename">The name of the file to be saved to</param>
      /// <param name="image">The image to be saved</param>
      /// <param name="parameters">The parameters</param>
      /// <returns>true if success</returns>
      public static bool Imwrite(String filename, IInputArray image, params int[] parameters)
      {
         using (Util.VectorOfInt vec = new Util.VectorOfInt())
         {
            if (parameters.Length > 0)
               vec.Push(parameters);
            using (CvString s = new CvString(filename))
            using (InputArray iaImage = image.GetInputArray())
            {
#if !(__IOS__ || __ANDROID__ || NETFX_CORE)
               bool containsUnicode = (s.Length != filename.Length);
               if (containsUnicode &&
                   (Emgu.Util.Platform.OperationSystem != OS.MacOSX) &&
                   (Emgu.Util.Platform.OperationSystem != OS.Linux))
               {
                  //Handle unicode in Windows platform
                  //Work around for Open CV ticket:
                  //https://github.com/Itseez/opencv/issues/4292
                  //https://github.com/Itseez/opencv/issues/4866     
                  System.IO.FileInfo fi = new System.IO.FileInfo(filename);

                  using (VectorOfByte vb = new VectorOfByte())
                  {
                     CvInvoke.Imencode(fi.Extension, image, vb, parameters);
                     byte[] arr = vb.ToArray();
                     System.IO.File.WriteAllBytes(filename, arr);
                     return true;
                  }
               }
               else
#endif
                  return cveImwrite(s, iaImage, vec);
            }
         }
      }
Пример #2
0
 /// <summary>
 /// Saves the image to the specified file. The image format is chosen depending on the filename extension, see cvLoadImage. Only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. If the format, depth or channel order is different, use cvCvtScale and cvCvtColor to convert it before saving, or use universal cvSave to save the image to XML or YAML format
 /// </summary>
 /// <param name="filename">The name of the file to be saved to</param>
 /// <param name="image">The image to be saved</param>
 /// <param name="parameters">The parameters</param>
 /// <returns>true if success</returns>
 public static bool Imwrite(String filename, IInputArray image, params int[] parameters)
 {
    using (Util.VectorOfInt vec = new Util.VectorOfInt())
    {
       if (parameters.Length > 0)
          vec.Push(parameters);
       using (CvString s = new CvString(filename))
       using (InputArray iaImage = image.GetInputArray())
          return cveImwrite(s, iaImage, vec);
    }
 }
Пример #3
0
 /// <summary>
 /// Perform detection on the image
 /// </summary>
 /// <param name="mat">The image for detection.</param>
 /// <returns>The detection result</returns>
 public ObjectDetection[] Detect(Mat mat)
 {
     using (Util.VectorOfRect rects = new Util.VectorOfRect())
         using (Util.VectorOfFloat scores = new Util.VectorOfFloat())
             using (Util.VectorOfInt classIds = new Util.VectorOfInt())
             {
                 DpmInvoke.cveDPMDetectorDetect(_ptr, mat, rects, scores, classIds);
                 ObjectDetection[] detections = new ObjectDetection[rects.Size];
                 for (var i = 0; i < detections.Length; i++)
                 {
                     detections[i] = new ObjectDetection(rects[i], scores[i], classIds[i]);
                 }
                 return(detections);
             }
 }