Skip to content

An indexing error using the Mat.Row function? #1775

Open
@MikePelton

Description

@MikePelton

Hi - a repro below of an issue that causes an "attempt to read or write protected memory" access violation. It has all the hallmarks of a "one-off" bug, crashing when iRow is 200 and iCol is 363. The test image is a 364 pixels wide JPG, available here and the data row claims it is Mat with 364 entries.

using OpenCvSharp;

namespace CvSharpTest
{
    internal class Program
    {
        static int Main(string[] args)
        {
            string inputFilePath = @"D:\MikeP\Images\ATest\ColoursGrid_364x556.jpg";

            Mat pixels = Cv2.ImRead(inputFilePath, ImreadModes.Color);
            if (pixels == null)
            {
                Console.WriteLine($"!!! Couldn't open {inputFilePath}");
                return 1;
            }

            int nRows = pixels.Rows;
            int nCols = pixels.Cols;

            for (int iRow = 0; iRow < nRows; iRow++)
            {
                var dataRow = pixels.Row(iRow);

                for (int iCol = 0; iCol < nCols; iCol++)
                {
                    OpenCvSharp.Vec3b vec3B = dataRow.At<OpenCvSharp.Vec3b>(iCol);
                    byte r = vec3B.Item2;
                    byte g = vec3B.Item1;
                    byte b = vec3B.Item0;

                }
                dataRow.Dispose();
            }
            pixels.Dispose();
            return 0;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions