(轉載)彩色相機和黑白相機數據轉Halcon格式(開源)

bool GrayDataToHalcon(HObject *ho_Image, int width, int height)

{
    unsigned char *GrayData = new unsigned char [width * height];
    for(int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            GrayData[width * (height - i - 1) + j] = ImageBuffer[width * i + j];
        }
    }
    GenImage1(ho_Image, "byte", width, height, (Hlong)(GrayData));
    return true;
}


BOOL CaiSeDataToHalcon(HObject *ho_Image, int width, int height)
{
    unsigned char *red = new unsigned char[width * height];
    unsigned char *green = new unsigned char[width * height];
    unsigned char *blue = new unsigned char[width * height];
    if (red == NULL || green == NULL || blue == NULL)
    {
        return false;
    }
    for (int r = 0; r < height; r++)
    {
        for (int c = 0 ; c < width; c++)
        {
            blue[(height - r - 1) * width + c] = ImageBuffer[r * width * 3 + 3 * c];
            green[(height - r - 1) * width + c] = ImageBuffer[r * width * 3 + 3 * c + 1];
            red[(height - r - 1) * width + c] = ImageBuffer[r * width*3 + 3 * c + 2];
         }
    }
    GenImage3(ho_Image, "byte", width, height, (Hlong)red, (Hlong)green, (Hlong)blue);
    delete [] red;
    delete [] green;
    delete [] blue;
    return true;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章