BayerBG conversion in VVVV.Packs.Image (raw Gige camera)

Hello everybody and happy nevvvv year :)

I’m trying to modify VVVV.Packs.Image in order to add Debayer (BayerBG8 format) feature to decode raw data from my Mako camera. (but it could work with any gige cameras with Bayer filter)

I have some difficulties to add this feature to the existent cv image library.

Here’s how I proceeded: (just modifications of the code are displayed)

namespace VVVV.CV.Core
     {
 public enum TColorFormat {BGR,BAYERBG }; // ADDITION OF BAYERBG AND BGR (final destination of conversion) FORMAT TColor

[…]

public static COLOR_CONVERSION ConvertRoute(TColorFormat src, TColorFormat dst)
    {
        switch (src)
        {

            case TColorFormat.BAYERBG: //If I'm not wrong, if BAYERBG source format is detected, return a BGR image thanks to COLOR_CONVERSION.CV_BayerBG2BGR
                switch (dst)
                {
                    case TColorFormat.BGR:
                        return COLOR_CONVERSION.CV_BayerBG2BGR;
                }

[…]

public static IImage CreateImage(int width, int height, TColorFormat format)
    {
        switch (format)
        {
                     case TColorFormat.BGR:
                return new Image<Bgr, byte>(width, height);
            case TColorFormat.BAYERBG:                         // CREATE gray image and bgr image to handle source and destination format.
                return new Image<Gray, byte>(width, height);

[…]

public static TColorFormat GetFormat(IImage image)
    {

        var imageBAYER = image as Image<Gray, byte>; //should be source foramt
        if (imageBAYER != null)
            return TColorFormat.BAYERBG;
        var imageBGR = image as Image<Bgr, byte>; //should be dest format
        if (imageBGR != null)
            return TColorFormat.BGR;

[…]

public static TColorFormat GetFormat(PixelFormat format)
    {
        switch (format)
        { case PixelFormat.Format32bppRgb:
                return TColorFormat.RGBA8;
            case PixelFormat.Format24bppRgb: 		//DON'T KNOW IF I HAVE TO MODIFY THIS
                return TColorFormat.RGB8;

[…]

public static uint BytesPerPixel(TColorFormat format)
    {
        switch (format)
        {     case TColorFormat.BAYERBG:
                    return 1;

                case TColorFormat.BGR:
                    return 3;

[…]

public static int ChannelCount(TColorFormat format)
    {
        switch (format)
        {
            case TColorFormat.BAYERBG:
                return 1;

            case TColorFormat.BGR:
                return 3;

[…]

  public static TChannelFormat ChannelFormat(TColorFormat format)
    {
        switch (format)
        {
            case TColorFormat.BAYERBG:
            case TColorFormat.BGR:
                return TChannelFormat.Byte;

[…]

public static Format GetDXFormat(TColorFormat format)
    {
        switch (format)
        {
             case TColorFormat.BAYERBG:
                return Format.L8;
                								//NOT SURE AT ALL
            case TColorFormat.BGR:
                return Format.R8G8B8;

the class which handles camera:

   image = args.Image;
        if (image != null)
        {

            System.Drawing.Imaging.BitmapData bmpData1 = ((Bitmap)image).LockBits(new Rectangle(0, 0, ((Bitmap)image).Width, ((Bitmap)image).Height),
            System.Drawing.Imaging.ImageLockMode.ReadWrite, ((Bitmap)image).PixelFormat);
            
            
            if (!FOutput.Image.Allocated || image.Width != FOutput.Image.Width || image.Height != FOutput.Image.Height)
            {

                FOutput.Image.Initialise(new Size((int)image.Width, (int)image.Height), TColorFormat.BAYERBG); //IS IT DESTINATION FORMAT OR SOURCE FORMAT ?? I can't say...
            }

            ImageInUse = true;
            FOutput.Image.SetPixels((IntPtr)(bmpData1.Scan0));
            FOutput.Send();
            ((Bitmap)image).UnlockBits(bmpData1);
            Status = "Frame received";
            FCounter++;

        }
        else
        {

           Status = "no Frame present";
          
        }

It sends me “No Frame Present” .

Would it be something obvious that I’m missing ?
I can’t really understand how CV got the pixel format (BayerBG8) of my camera…
If you have some tips I’ll take them :)
tiouss and thanks in advance.

can not help you with cv image, but just want to let you know that i did a debayer shader once. dont know if its useful for your case but probably faster as a shader:

@elektromeier thanks !!
I will check it out and hope it can do the job !

But in order to learning how to opencv in vvvv I’ll keep in trying to make a bayerbg2bgr open cv filter.
I’ll post my results (and issues for sure ).
tiouss !

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.