Ask Your Question

Primoz's profile - activity

2018-02-22 07:48:03 -0600 asked a question Rotated rectangle (RotatedRect) vertices

Rotated rectangle (RotatedRect) vertices Hello to everyone! I need to do some operations on a rotated rectangle and bec

2016-02-04 02:10:29 -0600 asked a question Imdecode input array

Hello!

I'm using OpenCV in C# through EmguCV wrapper. I'm asking on this forum because I think that my problem is more related to OpenCV than EmguCV.

I have an grayscale image from the camera and I want to pass it to the Imdecode function to create Mat object. Because of wrapper I can not pass the pointer to it so I create an array of pixels in direction from top to bottom and left to right, so actually copy pixel by pixel. There are no problems when compiling and running but, if I pass the image (Mat) to an ImageBox it's just black. ImageBox works fine if I load the image from a file on a disc.

What I'm doing wrong, should input array consist from more than just pixel values?

Please see the main part of the code below.

    Mat image_1 = new Mat(icImagingControl1.ImageHeight, icImagingControl1.ImageWidth, DepthType.Cv8U, 1);
int lines;
int columns;
byte[] image_bytes;
int counter = 0;

icImagingControl1.MemorySnapImage();

lines = icImagingControl1.ImageActiveBuffer.Lines;
columns = icImagingControl1.ImageActiveBuffer.BytesPerLine;

Console.WriteLine(lines);
Console.WriteLine(columns);

image_bytes = new byte[lines * columns];
for (int i = 0; i < lines; i++)
{
    for (int j = 0; j < columns; j++)
    {
        image_bytes[counter] = icImagingControl1.ImageActiveBuffer.GetByteData(j, i);
        counter = counter + 1;
    }
}

CvInvoke.Imdecode(image_bytes, LoadImageType.Grayscale, image_1);
imageBox1L.Image = image_1;