Leo 發問時間： 電腦與網際網路程式設計 · 8 年前

c# 影像處理求方法

ex: 第一張是一個天空的圖 第二張是有鳥在天上飛

3 個解答

• 最佳解答

一般使用C#的人，會採用

SetPixel的方法，程式碼如下：

Bitmap source = new Bitmap(3000, 2000, PixelFormat.Format32bppArgb);for (int h = 0; h < source.Height; h++){ for (int w = 0; w < source.Width; w++) { source.SetPixel(w, h, Color.White); }}

Image img = new Image(3000, 2000);for (int h = 0; h < img.Height; h++){ for (int w = 0; w < img.Width; w++) { img[h, w] = new Bgr(255, 255, 255); }}

Imageimg = new Image(3000, 2000);Parallel.For(0, img.Height, h =>{ Parallel.For(0, img.Width, w => { img[h, w] = new Bgr(255, 255, 255); });});

Bitmap source = new Bitmap(3000, 2000, PixelFormat.Format32bppArgb);MemoryStream memoryStream = new MemoryStream();source.Save(memoryStream, ImageFormat.Bmp);byte[] byteArray = memoryStream.ToArray();int totalPixels = source.Height * source.Width;for (int p = 0; p < totalPixels; p++){ byteArray[54 + p] = 255; } memoryStream = new MemoryStream(byteArray); source = new Bitmap(memoryStream);

Bitmap source = new Bitmap(3000, 2000,PixelFormat.Format32bppArgb);BitmapData sourceData = source.LockBits(new Rectangle(0, 0, source.Width, source.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);IntPtr source_scan = sourceData.Scan0;unsafe{ byte* source_p = (byte*)source_scan.ToPointer(); for (int height = 0; height < source.Height; ++height) { for (int width = 0; width < sourceData.Width; ++width) { source_p[0] = 255; //A source_p++; source_p[0] = 255; //R source_p++; source_p[0] = 155; //G source_p++; source_p[0] = 55; //B source_p++; } }}source.UnlockBits(sourceData);

• ?
Lv 7
8 年前

先跑一遍 canny，然後找 contour？

• Chen
Lv 6
8 年前

You want to find object without relation to colors and angle and intensity and size in picture.

If you want to learn image recognition, You must learn image segement( GABOR filter, CANNY, SIFT, SURF), and machine learning(PCA, ISOMAP, LLE , SVM ...etc), Maye you spend some hours in studying above statement.

below some pictures are tested by my coding program(c/c++) without any graphic library( GDI, OPENCV, DIRECTX ...etc)

test1: how to find one dime in coins. program finds result.

one dime coins

test2: how to find car plate in the picture(car02.jpg)

test result:

test3: how to find to recognite the people(picture1) in the picture(picture2)

picture1

picture2

test result: