Visionpro Notes: Color distinction

Source: Internet
Author: User

VisionPro: Color Distinction

From: blog.sina.com.cn/yangchao168

The use of color to distinguish objects such items have not been done, always find it difficult, especially when it comes to RGB and HSI and so on. It is interesting to see this example in Visionpro.

1) DECLARE variables:

Private Mtool as Cogcolorsegmentertool

Private Mimagefiletool as Cogimagefiletool

Private mcolorrangesinitialized as Boolean

2) After instantiating Mtool and mimagefiletool, loading the image and displaying it, the next step is to initialize the color range and add them to the Colorcollection tool.

It's hard to actually distinguish all the colors here, using Cogsimplecolor

Dim DefaultColor as Cogsimplecolor

Defaultcolor=new Cogsimplecolor (COGIMAGECOLORSPACECONSTANTS.RGB)

Define two kinds of yellow

Dim ColorRangeYellow1 as Cogcolorrangeitem

Original image

Colorrangeywllow1=new Cogcolorrangeitem (DefaultColor)

Use Norminal,low/high tolerance and softness to populate each plane

ColorRangeYellow1.PlaneRange0.Update (229,-81, 26, 0)

ColorRangeYellow1.PlaneRange1.Update (227,-100.2, 28, 0)

ColorRangeYellow1.PlaneRange2.Update (49,-33.3, 36.7, 0)

Add this color to the segment tool

MTOOL.RUNPARAMS.COLORRANGECOLLECTION.ADD (COLORRANGEYELLOW1)

Next is the second kind of yellow

Dim ColorRangeYellow2 as Cogcolorrangeitem colorRangeYellow2 = New Cogcolorrangeitem (defaultcolor) ColorRangeYellow2.PlaneRange0.Update ( -29.8, 23.7, 0) colorRangeYellow2.PlaneRange1.Update (122,-28.1, 32.7, 0) ColorRangeYellow2.PlaneRange2.Update ( -11.8, 11.8, 0) MTool.RunParams.ColorRangeCollection.Add ( COLORRANGEYELLOW2)

Results with a yellow distinction

Define 3 kinds of yellow

Dim colorRangeRed1 as Cogcolorrangeitem colorRangeRed1 = New Cogcolorrangeitem (defaultcolor) ColorRangeRed1.PlaneRange0.Update (109, -28.4, 33.8, 0) ColorRangeRed1.PlaneRange1.Update (34,-20.8, 17.8, 0) ColorRangeRed1.PlaneRange2.Update (one, -8.7, 10.2, 0) colorrangered1.selected = False MTOOL.RUNPARAMS.COLORRANGECOLLECTION.ADD (colorRangeRed1)

Yellow is selected by default, so the selected property for red is set to false.

。。。

After all the colors have been initialized

mcolorrangesinitialized =true ' can be used as a follow-up judgment condition

3) Color selection

If you choose Yellow

MTool.RunParams.ColorRangeCollection.Item (0). Selected=true

Results with a red distinction

MTool.RunParams.ColorRangeCollection.Item (1). Selected=true

If you choose red, you can set the item (2), (3), and (4) to selected.

4) Distinguishing

Mtool.inputimage=inputimage

Mtool.run ()

Output result image

If (MTool.RunStatus.Result.Equals (cogtoolresultconstants.accept)) Then Cogdisplaysegmentimage.image = Mtool.result c1> ' Display image

Else cogdisplaysegmentimage.image = Nothing ' result incorrect end If

Results using the yellow-red distinction

Visionpro Notes: Color distinction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.