예제 #1
0
        private void InitializeComponent(MatND <float> matND, RangeF[] ranges)
        {
            _matND = matND;
            MCvMatND cvMatND = _matND.MCvMatND;

            Debug.Assert(
                ranges.Length == cvMatND.dims,
                "incompatible dimension");
            _ptr = Marshal.AllocHGlobal(StructSize.MCvHistogram);

            #region parse the ranges to appropriate format
            GCHandle rangesHandle = GCHandle.Alloc(ranges, GCHandleType.Pinned);
            IntPtr[] rangesPts    = new IntPtr[ranges.Length];
            Int64    address      = rangesHandle.AddrOfPinnedObject().ToInt64();
            for (int i = 0; i < rangesPts.Length; i++)
            {
                rangesPts[i] = new IntPtr(address + i * StructSize.RangF);
            }
            #endregion

            CvInvoke.cvMakeHistHeaderForArray(
                cvMatND.dims,
                Array.ConvertAll <MCvMatND.Dimension, int>(cvMatND.dim, delegate(MCvMatND.Dimension d) {
                return(d.Size);
            }),                //binSizes
                _ptr,
                _matND.MCvMatND.data,
                rangesPts,
                1);

            rangesHandle.Free();
        }
예제 #2
0
        private int[] GetDimension()
        {
            MCvMatND matND = MCvMatND;

            int[] dim = new int[matND.dims];
            for (int i = 0; i < dim.Length; i++)
            {
                dim[i] = matND.dim[i].Size;
            }
            return(dim);
        }
예제 #3
0
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            UnmanagedObject matND = objectProvider.GetObject() as UnmanagedObject;

            if (matND != null)
            {
                MCvMatND cvMatND = (MCvMatND)Marshal.PtrToStructure(matND.Ptr, typeof(MCvMatND));
                if (cvMatND.dims > 3 || (cvMatND.dims == 3 && cvMatND.dim[2].Size > 4))
                {
                    MessageBox.Show("MatND of dimension > 3 is not supported for debugger visualizer");
                    return;
                }

                UnmanagedObject matrix   = null;
                int             rows     = cvMatND.dim[0].Size;
                int             cols     = cvMatND.dims >= 2 ? cvMatND.dim[1].Size : 1;
                int             channels = cvMatND.dims >= 3 ? cvMatND.dim[2].Size : 1;
                if (matND is MatND <float> )
                {
                    matrix = new Matrix <float>(rows, cols, channels);
                }
                else if (matND is MatND <int> )
                {
                    matrix = new Matrix <int>(rows, cols, channels);
                }
                else if (matND is MatND <double> )
                {
                    matrix = new Matrix <double>(rows, cols, channels);
                }

                if (matrix == null)
                {
                    MessageBox.Show(String.Format("{0} is not supported", cvMatND.type.ToString()));
                    return;
                }

                CvInvoke.cvCopy(matND.Ptr, matrix.Ptr, IntPtr.Zero);

                using (MatrixViewer viewer = new MatrixViewer())
                {
                    viewer.Matrix = matrix;
                    windowService.ShowDialog(viewer);
                }
            }
        }