public static bool CV_IS_IMAGE(__IplImagePtr img) { unsafe { return (CV_IS_IMAGE_HDR(img) && img.ToPointer()->imageData != null); } }
public static bool CV_IS_IMAGE_HDR(__IplImagePtr img) { unsafe { return ((img.ptr != IntPtr.Zero) && img.ToPointer()->nSize == sizeof(__IplImage)); } }
public CVHistogram CalcHistogram(int[] binSizes, CVPair[] binRanges, CVImage mask) { CVHistogram h = new CVHistogram(binSizes, binRanges); __IplImagePtr[] images = new __IplImagePtr[this.Channels]; if (this.Channels == 1) { images[0] = this.Internal; } else { CVImage[] planes = this.Split(); for (int i = 0; i < planes.Length; ++i) { images[i] = planes[i].Internal; } } __CvArrPtr maskArr = IntPtr.Zero; if (mask != null) { maskArr = mask.Array; } PInvoke.cvCalcHist(images, h.Internal, 0, maskArr); CVUtils.CheckLastError(); return(h); }
public CVImage CalcBackProject(CVHistogram histogram) { CVImage[] planes = Split(); CVImage backProjection = new CVImage( planes[0].RegionOfInterest.Width, planes[0].RegionOfInterest.Height, planes[0].Depth, planes[0].Channels); __IplImagePtr[] iplImages = new __IplImagePtr[planes.Length]; for (int i = 0; i < planes.Length; ++i) { iplImages[i] = planes[i].Internal; } PInvoke.cvCalcBackProject(iplImages, backProjection.Internal, histogram.Internal); CVUtils.CheckLastError(); for (int i = 0; i < planes.Length; ++i) { planes[i].Release(); } return(backProjection); }
public void Merge(CVImage blue, CVImage green, CVImage red) { __IplImagePtr c0 = blue != null ? blue.image : IntPtr.Zero; __IplImagePtr c1 = green != null ? green.image : IntPtr.Zero; __IplImagePtr c2 = red != null ? red.image : IntPtr.Zero; PInvoke.cvMerge(c0, c1, c2, IntPtr.Zero, image); CVUtils.CheckLastError(); }
public void Split(CVImage ch0, CVImage ch1, CVImage ch2, CVImage ch3) { __IplImagePtr d0 = ch0 != null ? ch0.image : IntPtr.Zero; __IplImagePtr d1 = ch1 != null ? ch1.image : IntPtr.Zero; __IplImagePtr d2 = ch2 != null ? ch2.image : IntPtr.Zero; __IplImagePtr d3 = ch3 != null ? ch3.image : IntPtr.Zero; PInvoke.cvSplit(image, d0, d1, d2, d3); CVUtils.CheckLastError(); }
public void Resize(int newWidth, int newHeight, CVInterpolation interpolation) { CVImage newImage = new CVImage(newWidth, newHeight, Depth, Channels); PInvoke.cvResize(this.image, newImage.image, (int)interpolation); CVUtils.CheckLastError(); Release(); this.image = newImage.image; newImage.created = false; }
public void LoadImage(String filename, bool isColor) { if (!System.IO.File.Exists(filename)) { throw new System.IO.FileNotFoundException(filename); } Release(); image = PInvoke.cvLoadImage(filename, isColor ? 1 : 0); CVUtils.CheckLastError(); created = true; }
public void Release() { if (!created) { return; } //created = false; __IplImagePtr ptr = image; if (ptr.ptr != IntPtr.Zero) { IntPtr ptrAux = ptr.ptr; PInvoke.cvReleaseImage(ref ptrAux); CVUtils.CheckLastError(); image = new __IplImagePtr(); } }
public CVImage QueryFrame() { if (asImage != null) { return(asImage.Clone()); } __IplImagePtr frame = PInvoke.cvQueryFrame(capture); CVUtils.CheckLastError(); if (frame.ptr == IntPtr.Zero) { return(null); } CVImage newImage = new CVImage(new CVImage(frame)); return(newImage); }
public static extern void cvSetImageROI(__IplImagePtr image, __CvRect rect);
public static extern void cvResetImageROI(__IplImagePtr image);
public static extern int cvWriteFrame(__CvVideoWriterPtr writer, __IplImagePtr image);
public static extern void cvCreateImage(out __IplImagePtr image);
public static void cvCalcHist(__IplImagePtr[] image, IntPtr hist, int accumulate, __CvArrPtr mask) { __CvArrPtr[] arrs = new __CvArrPtr[image.Length]; for (int i = 0; i < image.Length; ++i) arrs[i] = image[i]; cvCalcArrHist(arrs, hist, accumulate, mask); }
public static void cvCalcBackProject(__IplImagePtr[] image, __CvArrPtr dst, IntPtr hist) { __CvArrPtr[] arrs = new __CvArrPtr[image.Length]; for (int i = 0; i < image.Length; ++i) arrs[i] = image[i]; cvCalcArrBackProject(arrs, dst, hist); }
public unsafe CVImage(System.Drawing.Bitmap sourceImage) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); rect.X = 0 ; rect.Y = 0 ; rect.Width = sourceImage.Width; rect.Height = sourceImage.Height; System.Drawing.Imaging.BitmapData bData = sourceImage.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); // New implementation: int pixelSizeInBytes = 8; int numberOfChannels = 3; this.image = PInvoke.cvCreateImage( new __CvSize(sourceImage.Width, sourceImage.Height), pixelSizeInBytes, numberOfChannels); CVUtils.CheckLastError(); unsafe { int height = sourceImage.Height; int width = sourceImage.Width; byte* pRead = (byte*)bData.Scan0.ToPointer(); byte* pWrite = this.Internal.ToPointer()->imageData; int nReadStride = bData.Stride - width * numberOfChannels; int nWriteStride = this.Internal.ToPointer()->widthStep - width * numberOfChannels; for (int row = 0; row < height; ++row, pRead += nReadStride, pWrite += nWriteStride) { for (int col = 0; col < width; ++col, pRead += numberOfChannels, pWrite += numberOfChannels) { pWrite[0] = pRead[0]; // Blue pWrite[1] = pRead[1]; // Green pWrite[2] = pRead[2]; // Red } } } #region Old Implementation //__IplImagePtr tempImage = PInvoke.cvCreateImageHeader(new __CvSize(sourceImage.Width, sourceImage.Height), 8, Bitmap.GetPixelFormatSize(sourceImage.PixelFormat) / 8); //tempImage.ToPointer()->imageData = (byte*)bData.Scan0.ToPointer(); //__IplImagePtr[] dst = new __IplImagePtr[4]; //for (int i = 0; i < 4; ++i) //{ // dst[i] = IntPtr.Zero; //} //for (int i = 0; i < tempImage.ToPointer()->nChannels; i++) //{ // dst[i] = PInvoke.cvCreateImage(new __CvSize(sourceImage.Width, sourceImage.Height), 8, 1); //} //PInvoke.cvSplit( // tempImage, // dst[0], // dst[1], // dst[2], // dst[3]); //image = PInvoke.cvCreateImage(new __CvSize(sourceImage.Width, sourceImage.Height), 8, 3); //PInvoke.cvMerge(dst[0], dst[1], dst[2], IntPtr.Zero, image) ; //for (int i = 0; i < tempImage.ToPointer()->nChannels; i++) //{ // PInvoke.cvReleaseImage(ref dst[i]); //} #endregion created = true; sourceImage.UnlockBits(bData); }
internal CVImage(__IplImagePtr internal_image) { image = internal_image; created = false; }
public void Release() { if (!created) return; //created = false; __IplImagePtr ptr = image; if (ptr.ptr != IntPtr.Zero) { IntPtr ptrAux = ptr.ptr; PInvoke.cvReleaseImage(ref ptrAux); CVUtils.CheckLastError(); image = new __IplImagePtr(); } }
public void Resize(int newWidth, int newHeight, CVInterpolation interpolation) { CVImage newImage = new CVImage(newWidth, newHeight, Depth, Channels); PInvoke.cvResize(this.image, newImage.image, (int) interpolation); CVUtils.CheckLastError(); Release(); this.image = newImage.image; newImage.created = false; }
public static extern __IplImagePtr cvCloneImage(__IplImagePtr image);
public unsafe CVImage(System.Drawing.Bitmap sourceImage) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(); rect.X = 0; rect.Y = 0; rect.Width = sourceImage.Width; rect.Height = sourceImage.Height; System.Drawing.Imaging.BitmapData bData = sourceImage.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); // New implementation: int pixelSizeInBytes = 8; int numberOfChannels = 3; this.image = PInvoke.cvCreateImage( new __CvSize(sourceImage.Width, sourceImage.Height), pixelSizeInBytes, numberOfChannels); CVUtils.CheckLastError(); unsafe { int height = sourceImage.Height; int width = sourceImage.Width; byte *pRead = (byte *)bData.Scan0.ToPointer(); byte *pWrite = this.Internal.ToPointer()->imageData; int nReadStride = bData.Stride - width * numberOfChannels; int nWriteStride = this.Internal.ToPointer()->widthStep - width * numberOfChannels; for (int row = 0; row < height; ++row, pRead += nReadStride, pWrite += nWriteStride) { for (int col = 0; col < width; ++col, pRead += numberOfChannels, pWrite += numberOfChannels) { pWrite[0] = pRead[0]; // Blue pWrite[1] = pRead[1]; // Green pWrite[2] = pRead[2]; // Red } } } #region Old Implementation //__IplImagePtr tempImage = PInvoke.cvCreateImageHeader(new __CvSize(sourceImage.Width, sourceImage.Height), 8, Bitmap.GetPixelFormatSize(sourceImage.PixelFormat) / 8); //tempImage.ToPointer()->imageData = (byte*)bData.Scan0.ToPointer(); //__IplImagePtr[] dst = new __IplImagePtr[4]; //for (int i = 0; i < 4; ++i) //{ // dst[i] = IntPtr.Zero; //} //for (int i = 0; i < tempImage.ToPointer()->nChannels; i++) //{ // dst[i] = PInvoke.cvCreateImage(new __CvSize(sourceImage.Width, sourceImage.Height), 8, 1); //} //PInvoke.cvSplit( // tempImage, // dst[0], // dst[1], // dst[2], // dst[3]); //image = PInvoke.cvCreateImage(new __CvSize(sourceImage.Width, sourceImage.Height), 8, 3); //PInvoke.cvMerge(dst[0], dst[1], dst[2], IntPtr.Zero, image) ; //for (int i = 0; i < tempImage.ToPointer()->nChannels; i++) //{ // PInvoke.cvReleaseImage(ref dst[i]); //} #endregion created = true; sourceImage.UnlockBits(bData); }
public CVImage CalcBackProject(CVHistogram histogram) { CVImage[] planes = Split(); CVImage backProjection = new CVImage( planes[0].RegionOfInterest.Width, planes[0].RegionOfInterest.Height, planes[0].Depth, planes[0].Channels); __IplImagePtr[] iplImages = new __IplImagePtr[planes.Length]; for (int i = 0; i < planes.Length; ++i) iplImages[i] = planes[i].Internal; PInvoke.cvCalcBackProject(iplImages, backProjection.Internal, histogram.Internal); CVUtils.CheckLastError(); for (int i = 0; i < planes.Length; ++i) planes[i].Release(); return backProjection; }
private void Create(int width, int height, CVDepth depth, int channels) { image = PInvoke.cvCreateImage(new __CvSize(width, height), (int) depth, channels); CVUtils.CheckLastError(); created = true; }
public CVHistogram CalcHistogram(int[] binSizes, CVPair[] binRanges, CVImage mask) { CVHistogram h = new CVHistogram(binSizes, binRanges); __IplImagePtr[] images = new __IplImagePtr[this.Channels]; if (this.Channels == 1) { images[0] = this.Internal; } else { CVImage[] planes = this.Split(); for (int i = 0; i < planes.Length; ++i) { images[i] = planes[i].Internal; } } __CvArrPtr maskArr = IntPtr.Zero; if (mask != null) maskArr = mask.Array; PInvoke.cvCalcHist(images, h.Internal, 0, maskArr); CVUtils.CheckLastError(); return h; }
public static void cvCalcHist(__IplImagePtr[] image, IntPtr hist) { __CvArrPtr[] arrs = new __CvArrPtr[image.Length]; for (int i = 0; i < image.Length; ++i) arrs[i] = image[i]; cvCalcArrHist(arrs, hist, 0, IntPtr.Zero); }
private void Create(int width, int height, CVDepth depth, int channels) { image = PInvoke.cvCreateImage(new __CvSize(width, height), (int)depth, channels); CVUtils.CheckLastError(); created = true; }