Exemple #1
0
        /// <summary>
        /// 画像上にテキストを描画する際に利用されるフォントを作成します.
        /// </summary>
        /// <param name="nameFont">フォント名. 指定のフォントが見つからなければ,デフォルトフォントが利用されます.</param>
        /// <param name="pointSize">ォントサイズ.これが,未指定,または0以下の値の場合,フォンとのポイントサイズはシステム依存のデフォルト値にセットされます.通常は,12ポイントです.</param>
        /// <param name="color">BGRA で表現されるフォントカラー.</param>
        /// <param name="weight">フォントの太さ</param>
        /// <param name="style">処理フラグ</param>
        /// <param name="spacing">文字間のスペース.正負の値が利用できます.</param>
#else
        /// <summary>
        /// Create the font to be used to draw text on an image
        /// </summary>
        /// <param name="nameFont">Name of the font. The name should match the name of a system font (such as ``Times’‘). If the font is not found, a default one will be used.</param>
        /// <param name="pointSize">Size of the font. If not specified, equal zero or negative, the point size of the font is set to a system-dependent default value. Generally, this is 12 points.</param>
        /// <param name="color">Color of the font in BGRA – A = 255 is fully transparent. Use the macro CV _ RGB for simplicity.</param>
        /// <param name="weight">The operation flags</param>
        /// <param name="style">The operation flags</param>
        /// <param name="spacing">Spacing between characters. Can be negative or positive.</param>
#endif
        public CvFontQt(string nameFont, int pointSize, CvScalar color, FontWeight weight, FontStyle style, int spacing)
        {
            if (nameFont == null)
                throw new ArgumentNullException("nameFont");

            ptr = base.AllocMemory(SizeOf);
            WCvFont font = CvInvoke.cvFontQt(nameFont, pointSize, color, weight, style, spacing);
            using (ScopedGCHandle gch = new ScopedGCHandle(font, GCHandleType.Pinned))
            {
                Util.CopyMemory(ptr, gch.AddrOfPinnedObject(), SizeOf);
            }
        }
Exemple #2
0
        /// <summary>
        /// ウィンドウ名と画像の表示モードと始めから表示しておく画像を指定して初期化
        /// </summary>
        /// <param name="name">ウィンドウの識別に用いられるウィンドウ名で,ウィンドウのタイトルバ ーに表示される.</param>
        /// <param name="flags">ウィンドウのフラグ</param>
        /// <param name="image">ウィンドウに表示する画像</param>
#else
        /// <summary>
        /// Creates a window
        /// </summary>
        /// <param name="name">Name of the window which is used as window identifier and appears in the window caption. </param>
        /// <param name="flags">Flags of the window. Currently the only supported flag is WindowMode.AutoSize. 
        /// If it is set, window size is automatically adjusted to fit the displayed image (see cvShowImage), while user can not change the window size manually. </param>
        /// <param name="image">Image to be shown.</param>
#endif
        public CvWindow(string name, WindowMode flags, CvArr image)
        {
            if (name == null)
            {
                throw new ArgumentNullException();
            }
            this.name = name;
            int status = NativeMethods.cvNamedWindow(name, flags);
            if (status == 0)
            {
                throw new OpenCvSharpException("Failed to create CvWindow");
            }
            this.image = image;
            ShowImage(image);
            trackbars = new Dictionary<string, CvTrackbar>();
            if (!Windows.ContainsKey(name))
            {
                Windows.Add(name, this);
            }
            callbackHandle = null;
        }
Exemple #3
0
        /// <summary>
        /// System.Runtime.InteropServices.GCHandle オブジェクトの内部整数表現を返します
        /// </summary>
        /// <param name="value">内部整数表現の取得元の System.Runtime.InteropServices.GCHandle オブジェクト</param>
        /// <returns>System.Runtime.InteropServices.GCHandle オブジェクトを表す System.IntPtr オブジェクト</returns>
#else
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
#endif
        public static IntPtr ToIntPtr(ScopedGCHandle value)
        {
            return GCHandle.ToIntPtr(value.Handle);
        }
Exemple #4
0
        /// <summary>
        /// ウィンドウ名と画像の表示モードと始めから表示しておく画像を指定して初期化
        /// </summary>
        /// <param name="name">ウィンドウの識別に用いられるウィンドウ名で,ウィンドウのタイトルバ ーに表示される.</param>
        /// <param name="flags">ウィンドウのフラグ</param>
        /// <param name="image">ウィンドウに表示する画像</param>
#else
        /// <summary>
        /// Creates a window
        /// </summary>
        /// <param name="name">Name of the window which is used as window identifier and appears in the window caption. </param>
        /// <param name="flags">Flags of the window. Currently the only supported flag is WindowMode.AutoSize. 
        /// If it is set, window size is automatically adjusted to fit the displayed image (see cvShowImage), while user can not change the window size manually. </param>
        /// <param name="image">Image to be shown.</param>
#endif
        public Window(string name, WindowMode flags, Mat image)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            
            this.name = name;
            NativeMethods.highgui_namedWindow(name, (int)flags);
            
            this.image = image;
            ShowImage(image);
            trackbars = new Dictionary<string, CvTrackbar>();
            if (!Windows.ContainsKey(name))
            {
                Windows.Add(name, this);
            }
            this.callbackHandle = null;
        }
Exemple #5
0
        /// <summary>
        /// System.Runtime.InteropServices.GCHandle オブジェクトの内部整数表現を返します
        /// </summary>
        /// <param name="value">内部整数表現の取得元の System.Runtime.InteropServices.GCHandle オブジェクト</param>
        /// <returns>System.Runtime.InteropServices.GCHandle オブジェクトを表す System.IntPtr オブジェクト</returns>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
#endif
        public static IntPtr ToIntPtr(ScopedGCHandle value)
        {
            return(GCHandle.ToIntPtr(value.Handle));
        }
Exemple #6
0
        private static unsafe void FillBitmapInfo(ref Win32API.BITMAPINFO bmi, int width, int height, int bpp, int origin)
        {
            Debug.Assert(width > 0 && height > 0 && (bpp == 8 || bpp == 24 || bpp == 32));

            Win32API.BITMAPINFOHEADER bmih = bmi.Header;
            using (ScopedGCHandle handle = new ScopedGCHandle(bmih, GCHandleType.Pinned))
            {
                //Win32API.FillMemory(handle.AddrOfPinnedObject(), Marshal.SizeOf(typeof(Win32API.BITMAPINFOHEADER)), 0);
                bmih.Size = (uint)sizeof(Win32API.BITMAPINFOHEADER);
                bmih.Width = width;
                bmih.Height = (origin != 0) ? Math.Abs(height) : -Math.Abs(height);
                bmih.Planes = 1;
                bmih.BitCount = (ushort)bpp;
                bmih.Compression = Win32API.BI_RGB;
                bmih.ClrImportant = 0;
                bmih.Compression = 0;
                bmih.SizeImage = 0;
                bmih.XPelsPerMeter = 0;
                bmih.YPelsPerMeter = 0;
                bmi.Header = bmih;
            }

            if (bpp == 8)
            {
                Win32API.RGBQUAD[] palette = bmi.Colors;
                for (int i = 0; i < palette.Length; i++)
                {
                    palette[i].Blue = palette[i].Green = palette[i].Red = (byte)i;
                    palette[i].Reserved = 0;
                }
                bmi.Colors = palette;
            }
        }