how to access each pixel from Mat in opencvsharp by vb.net? [closed]

asked 2020-02-24 18:05:06 -0500

Tshimo gravatar image

Dear all;

I am now tring to program image processing by using Opencvsharp and vb.net. but i did not know how to access each pixel from Mat format. ”img.Data" property occurs syntax(?) error .

Could you show me some example to how to access each pixel?

=== VB.net ===================

        Dim x As Integer
        Dim y As Integer

        y = 1
        Do While (y _
                        < (img.Rows - 1))
            x = 1
            Do While (x _
                            < (img.Cols - 1))
                Dim v9 As Integer
                Dim v2 As Integer
                Dim v3 As Integer
                Dim v8 As Integer
                Dim v1 As Integer
                Dim v4 As Integer
                Dim v7 As Integer
                Dim v6 As Integer
                Dim v5 As Integer

                v1 = img.Data(y * img.Step + x * img.ElemSize)
                v2 = img.Data((y - 1) * img.Step + (x * img.ElemSize))
                v3 = img.Data((((y - 1) * img.Step) + ((x + 1) * img.ElemSize)))
                v4 = img.Data(((y * img.Step) + ((x + 1) * img.ElemSize)))
                v5 = img.Data((((y + 1) * img.Step) + ((x + 1) * img.ElemSize)))
                v6 = img.Data((((y + 1) * img.Step) + (x * img.ElemSize)))
                v7 = img.Data((((y + 1) * img.Step) + ((x - 1) * img.ElemSize)))
                v8 = img.Data(((y * img.Step) + ((x - 1) * img.ElemSize)))
                v9 = img.Data((((y - 1) * img.Step) + ((x - 1) * img.ElemSize)))

========= C ++ =========================== int x, y;

for (y = 1; y < img.rows-1; ++y) {

    for (x = 1; x < img.cols-1; ++x) {

        int v9,v2,v3;
        int v8,v1,v4;
        int v7,v6,v5;

        v1=img.data[   y   * img.step +   x   * img.elemSize()];
        v2=img.data[ (y-1) * img.step +   x   * img.elemSize()];
        v3=img.data[ (y-1) * img.step + (x+1) * img.elemSize()];
        v4=img.data[   y   * img.step + (x+1) * img.elemSize()];
        v5=img.data[ (y+1) * img.step + (x+1) * img.elemSize()];
        v6=img.data[ (y+1) * img.step +   x   * img.elemSize()];
        v7=img.data[ (y+1) * img.step + (x-1) * img.elemSize()];
        v8=img.data[   y   * img.step + (x-1) * mg.elemSize()];
        v9=img.data[ (y-1) *img.step + (x-1) * img.elemSize()];
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by LBerger
close date 2020-02-24 20:22:37.314404

Comments

1

Sorry opencvsharp is off topic.try here

LBerger gravatar imageLBerger ( 2020-02-24 20:22:30 -0500 )edit