识别包含黑白框的位图文件上的黑盒子 [英] Identify a black box on a bitmap file that contains black and white boxes

查看:85
本文介绍了识别包含黑白框的位图文件上的黑盒子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。请问我正在开发一个位图项目。此位图文件具有黑色和白色框,并将其加载到图片框中。我希望能够识别位图上黑框中的像素,并将它们保存到数组中,以便进一步处理项目。我可以获得VB.net(最好)或C#中执行此操作的代码的帮助。谢谢



抱歉,这是我第一次来这里,对于图形编程来说相对较新。这就是我所做的,它只能在richtextbox上显示x,y坐标和像素。 Sub Getcoordinates()

错误GoTo刷新

CheckForIllegalCrossThreadCalls = False

Dim Bild As Bitmap = CType(Me.PictureBox1.Image.Clone,位图)

昏暗宽度As Integer = Bild.Width - 1

昏暗高度As Integer = Bild.Height - 1

x = 0宽度

对于y = 0到高度



Dim R,G,B,A作为整数

R = Bild.GetPixel(x,y).R

G = Bild.GetPixel(x,y).G

B = Bild.GetPixel(x,y) .B

A = Bild.GetPixel(x,y).A

RichTextBox1.AppendText(R& - &G& - &B& - &A&Cordinates&x&,&y&vbNewLine)

下一页

下一页

RichTextBox1.Text = RichTextBox1。 Text.Substring(0,RichTextBox1.Text.Length - 1)

RichTextBox1.AppendText( |&width&*&height)





刷新:

刷新()

结束Sub

Hello all. Please I am working on a bitmap project. This bitmap file has black and white boxes and it is loaded to the picturebox. I want to be able to identify the pixels in the black box on the bitmap and save them to an array for use in further processing of the project. Please can I get help with the codes that does this in VB.net (preferably) or C#. Thanks

sorry guys it's my first time here and am relatively new to Graphics programming. This is what I have done, it can only display the x, y cordinates and pixels on a richtextbox. Sub Getcoordinates()
On Error GoTo Refresh
CheckForIllegalCrossThreadCalls = False
Dim Bild As Bitmap = CType(Me.PictureBox1.Image.Clone, Bitmap)
Dim width As Integer = Bild.Width - 1
Dim height As Integer = Bild.Height - 1
For x = 0 To width
For y = 0 To height

Dim R, G, B, A As Integer
R = Bild.GetPixel(x, y).R
G = Bild.GetPixel(x, y).G
B = Bild.GetPixel(x, y).B
A = Bild.GetPixel(x, y).A
RichTextBox1.AppendText(R & "-" & G & "-" & B & "-" & A & " Cordinates " & x & "," & y & vbNewLine)
Next
Next
RichTextBox1.Text = RichTextBox1.Text.Substring(0, RichTextBox1.Text.Length - 1)
RichTextBox1.AppendText("|" & width & "*" & height)


Refresh:
Refresh()
End Sub

推荐答案

不仅使用 GetPixel 过于缓慢,它只是没有严重。如果您不知道如何自己开发图像识别(这根本不容易),您可以使用其中一个开源库。我推荐原生.NET库AForge.NET:

http://en.wikipedia.org /wiki/AForge.NET [ ^ ] ,

http://www.aforgenet.com/ [ ^ ]。



你需要的是 blob识别。这是带有源代码示例的基本AForge.NET手册,可用于查找所有文档页面: http://www.aforgenet .com / articles / shape_checker [ ^ ]。



这款软件的坚固性和特别是性能非常棒。对于一个公认的物体,它可以给你凸壳,它是描述你斑点主要属性的最具特色的物体。







要找到黑色和白色斑点,你需要找到白色斑点,然后反转图像并再次找到...白色斑点,这将被倒置黑人。另请参阅下面的评论:您可能需要首先对比源,使用其他AForge.NET转换(始终保留原始图像)。



请参阅我过去的答案相关建议:

如何过滤掉AForge.net中不需要的blob? [ ^ ],

ConvexHull2d .............. ................... [ ^ ],

c#中的斑点检测 [ ^ ],

简单的BLOB检测算法 [ ^ ],

使用Aforge.net进行图像处理>>我需要帮助 [ ^ ],



(很抱歉有些冗余的回答;我希望你明白我回答了不同的人。)



另请参阅: http://en.wikipedia.org/wiki/Blob_detection [ ^ ]。



-SA
Not only using GetPixel is prohibitively slow, it's just no serious. If you don't know how to develop image recognition by yourself (this is not easy at all), you can use one of the open-source libraries. I would recommend native .NET library AForge.NET:
http://en.wikipedia.org/wiki/AForge.NET[^],
http://www.aforgenet.com/[^].

What you need is the blob recognition. This is the basic AForge.NET manual with source code sample which you can use to find all the documentation pages: http://www.aforgenet.com/articles/shape_checker[^].

The robustness and especially performance of this software is wonderful. For a recognized object, it can give you the convex hull of it, which is the most characteristic object describing major properties of your blob.



To find black and white blobs, you need to find the white blobs, then invert the image and find… white blobs again, which will be inverted blacks. See also my comment below: you may need to contrast your source first, using other AForge.NET transformations (always keep your original image).

Please see my past answers with related advise:
How to filter out the unwanted blobs in AForge.net ?[^],
Convex "Hull" 2d.................................[^],
blob detection in c#[^],
Simple BLOB detection algorithm[^],
image processing using Aforge.net >> I need the help[^],

(Sorry for some redundancy in answer; I hope you understand that I answered to different people.)

See also: http://en.wikipedia.org/wiki/Blob_detection[^].

—SA


这篇关于识别包含黑白框的位图文件上的黑盒子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆