Retrieving Pixel Values Code Snippet¶
This code snippet shows the recommended method (fastest) to access the pixel values in a BW8 image.
C++¶
#include <eVision/Easy/EImageBW8.h>
using namespace eVision;
EImageBW8 img;
uint8_t* pixelPtr;
uint8_t* rowPtr;
uint8_t pixelValue;
uint32_t rowPitch;
int x, y;
int height(1080);
int width(1920);
rowPtr = reinterpret_cast <uint8_t*>(img.GetImagePtr());
rowPitch = img.GetRowPitch();
for (y = 0; y < height; y++)
{
pixelPtr = rowPtr;
for (x = 0; x < width; x++)
{
pixelValue = *pixelPtr;
// Add your pixel computation code here
*pixelPtr = pixelValue;
pixelPtr++;
}
rowPtr += rowPitch;
}
See also
C#¶
using System;
using System.Runtime.InteropServices;
using eVision;
IntPtr pixAddr;
byte pix;
EImageBW8 bw8Image = new EImageBW8();
int height = 1080;
int width = 1920;
//...
for (int y = 0; y < height; ++y)
{
pixAddr = bw8Image.GetImagePtr(0, y);
for (int x = 0; x < width; ++x)
pix = Marshal.ReadByte(pixAddr, x);
}
See also
Python¶
import eVision
import numpy as np
img = eVision.EImageBW8()
np_view = np.asarray(img.PixelView)
for row in np_view:
for pixel in row:
# Add your pixel computation code here
pass
See also