本文整理汇总了C#中IplImage.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# IplImage.Clone方法的具体用法?C# IplImage.Clone怎么用?C# IplImage.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IplImage
的用法示例。
在下文中一共展示了IplImage.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToWriteableBitmap
/// <summary>
/// IplImageをWriteableBitmapに変換する.
/// 返却値を新たに生成せず引数で指定したWriteableBitmapに格納するので、メモリ効率が良い。
/// </summary>
/// <param name="src">変換するIplImage</param>
/// <param name="dst">変換結果を設定するWriteableBitmap</param>
#else
/// <summary>
/// Converts IplImage to WriteableBitmap.
/// This method is more efficient because new instance of WriteableBitmap is not allocated.
/// </summary>
/// <param name="src">Input IplImage</param>
/// <param name="dst">Output WriteableBitmap</param>
#endif
public static void ToWriteableBitmap(IplImage src, WriteableBitmap dst)
{
if (src == null)
throw new ArgumentNullException("src");
if (dst == null)
throw new ArgumentNullException("dst");
if (src.Width != dst.PixelWidth || src.Height != dst.PixelHeight)
throw new ArgumentException("size of src must be equal to size of dst");
//if (src.Depth != BitDepth.U8)
//throw new ArgumentException("bit depth of src must be BitDepth.U8", "src");
int w = src.Width;
int h = src.Height;
int bpp = dst.Format.BitsPerPixel;
int channels = GetOptimumChannels(dst.Format);
if (src.NChannels != channels)
{
throw new ArgumentException("PixelFormat of dst is invalid", "dst");
}
// 左下原点の場合は上下反転する
IplImage ipl = null;
if (src.Origin == ImageOrigin.TopLeft)
{
ipl = src;
}
else
{
ipl = src.Clone();
Cv.Flip(src, ipl, FlipMode.X);
}
if (bpp == 1)
{
unsafe
{
// 手作業で移し替える
int stride = w / 8 + 1;
if (stride < 2)
{
stride = 2;
}
byte[] pixels = new byte[h * stride];
byte* p = (byte*)(ipl.ImageData.ToPointer());
int x = 0;
int y;
int byte_pos;
int offset;
byte b;
int i;
int widthStep = src.WidthStep;
for (y = 0; y < h; y++)
{
offset = y * stride;
for (byte_pos = 0; byte_pos < stride; byte_pos++)
{
if (x < w)
{
b = 0;
// 現在の位置から横8ピクセル分、ビットがそれぞれ立っているか調べ、1つのbyteにまとめる
for (i = 0; i < 8; i++)
{
b <<= 1;
if (x < w && p[widthStep * y + x] != 0)
{
b |= 1;
}
x++;
}
pixels[offset + byte_pos] = b;
}
}
x = 0;
}
dst.WritePixels(new Int32Rect(0, 0, w, h), pixels, stride, 0);
}
/*} else if(bpp == 8){
int stride = w;
array<Byte>^ pixels = gcnew array<Byte>(h * stride);
byte* p = (byte*)(void*)src->ImageData;
for (int y=0; y<h; y++) {
for(int x=0; x<w; x++){
pixels[y * stride + x] = p[src->WidthStep * y + x];
}
//.........这里部分代码省略.........
示例2: FindContours
/// <summary>
/// 輪郭を得る
/// </summary>
/// <param name="img"></param>
/// <param name="storage"></param>
/// <returns></returns>
private CvSeq<CvPoint> FindContours(IplImage img, CvMemStorage storage)
{
// 輪郭抽出
CvSeq<CvPoint> contours;
using (IplImage imgClone = img.Clone())
{
Cv.FindContours(imgClone, storage, out contours);
if (contours == null)
{
return null;
}
contours = Cv.ApproxPoly(contours, CvContour.SizeOf, storage, ApproxPolyMethod.DP, 3, true);
}
// 一番長そうな輪郭のみを得る
CvSeq<CvPoint> max = contours;
for (CvSeq<CvPoint> c = contours; c != null; c = c.HNext)
{
if (max.Total < c.Total)
{
max = c;
}
}
return max;
}