Skip to content

Instantly share code, notes, and snippets.

@immengineer
Created August 9, 2017 04:38
Show Gist options
  • Save immengineer/c559d45ba754e925398fe31beb021f4a to your computer and use it in GitHub Desktop.
Save immengineer/c559d45ba754e925398fe31beb021f4a to your computer and use it in GitHub Desktop.
JAISDK 画像データ取得 実処理部分
void HandleImage(ref Jai_FactoryWrapper.ImageInfo ImageInfo)
{
Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success;
// Set Measurement area (100 x 100 Pixel)
m_MeasureRect.Left = 100;
m_MeasureRect.Top = 100;
m_MeasureRect.Right = 200;
m_MeasureRect.Bottom = 200;
// Get average value and calculate new control parameters:
Jai_FactoryWrapper.PixelValue Average = new Jai_FactoryWrapper.PixelValue();
// Allocate conversion buffer once
if (m_ConversionBuffer.ImageBuffer == IntPtr.Zero)
error = Jai_FactoryWrapper.J_Image_Malloc(ref ImageInfo, ref m_ConversionBuffer);
// Then we convert into 48bpp image format
error = Jai_FactoryWrapper.J_Image_FromRawToImage(ref ImageInfo, ref m_ConversionBuffer, Jai_FactoryWrapper.EColorInterpolationAlgorithm.BayerStandardMultiprocessor, 4096, 4096, 4096);
// .. and then we can calculate the average value for the measurement ROI
error = Jai_FactoryWrapper.J_Image_GetAverage(ref m_ConversionBuffer, ref m_MeasureRect, ref Average);
// PixelFormat 10 Bit Bayer GR, Get 10 bit data from BGR48
float red = (Average.BGR48_R & 0xFFC0) >> 6;
float green = (Average.BGR48_G & 0xFFC0) >> 6;
float blue = (Average.BGR48_B & 0xFFC0) >> 6;
// Update labelR,G,B
Invoke((MethodInvoker)delegate()
{
labelR.Text = red.ToString("F2");
labelG.Text = green.ToString("F2");
labelB.Text = blue.ToString("F2");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment