CvtColor() private method

private CvtColor ( IntPtr src, IntPtr dst, CvEnum code, IntPtr stream ) : void
src System.IntPtr
dst System.IntPtr
code CvEnum
stream System.IntPtr
return void
Beispiel #1
0
 private static void ConvertColor(IntPtr src, IntPtr dest, Type srcColor, Type destColor, Size size, Stream stream)
 {
     try
     {
         // if the direct conversion exist, apply the conversion
         GpuInvoke.CvtColor(src, dest, CvToolbox.GetColorCvtCode(srcColor, destColor), stream);
     } catch
     {
         try
         {
             //if a direct conversion doesn't exist, apply a two step conversion
             //in this case, needs to wait for the completion of the stream because a temporary local image buffer is used
             //we don't want the tmp image to be released before the operation is completed.
             using (GpuImage <Bgr, TDepth> tmp = new GpuImage <Bgr, TDepth>(size))
             {
                 GpuInvoke.CvtColor(src, tmp.Ptr, CvToolbox.GetColorCvtCode(srcColor, typeof(Bgr)), stream);
                 GpuInvoke.CvtColor(tmp.Ptr, dest, CvToolbox.GetColorCvtCode(typeof(Bgr), destColor), stream);
                 stream.WaitForCompletion();
             }
         } catch
         {
             throw new NotSupportedException(String.Format(
                                                 "Convertion from Image<{0}, {1}> to Image<{2}, {3}> is not supported by OpenCV",
                                                 srcColor.ToString(),
                                                 typeof(TDepth).ToString(),
                                                 destColor.ToString(),
                                                 typeof(TDepth).ToString()));
         }
     }
 }
 private static void ConvertColor(IntPtr src, IntPtr dest, Type srcColor, Type destColor, Size size, Stream stream)
 {
     try
     {
         // if the direct conversion exist, apply the conversion
         GpuInvoke.CvtColor(src, dest, CvToolbox.GetColorCvtCode(srcColor, destColor), stream);
     }
     catch
     {
         try
         {
             //if a direct conversion doesn't exist, apply a two step conversion
             using (GpuImage <Bgr, TDepth> tmp = new GpuImage <Bgr, TDepth>(size))
             {
                 GpuInvoke.CvtColor(src, tmp.Ptr, CvToolbox.GetColorCvtCode(srcColor, typeof(Bgr)), stream);
                 GpuInvoke.CvtColor(tmp.Ptr, dest, CvToolbox.GetColorCvtCode(typeof(Bgr), destColor), stream);
             }
         }
         catch
         {
             throw new NotSupportedException(String.Format(
                                                 "Convertion from Image<{0}, {1}> to Image<{2}, {3}> is not supported by OpenCV",
                                                 srcColor.ToString(),
                                                 typeof(TDepth).ToString(),
                                                 destColor.ToString(),
                                                 typeof(TDepth).ToString()));
         }
     }
 }