Search Unity

OpenCVSharp >> Cv.CvtColor Error:Incorrect number of channels for this conversion code

Discussion in 'Scripting' started by F_Riffel, Mar 1, 2015.

  1. F_Riffel

    F_Riffel

    Joined:
    Feb 27, 2015
    Posts:
    1
    Hey,
    i´m new using OpenCvSharp, following many tutorials i´m starting to create my faceRecognition project, but i´m stopped because this damn error on CvtColor.
    I´m create all images with the same number of Channels but this error insists on appear.

    Here´s the part of code when a use the CvtColor, to convert one image to Gray:

    Code (CSharp):
    1.  using (IplImage img = Texture2DtoIplImage(finalImage))
    2.             using (IplImage smallImg = new IplImage(new CvSize(Cv.Round(img.Width / Scale), Cv.Round(img.Height / Scale)), BitDepth.U8, 1))
    3.             {
    4.                 using (IplImage gray = new IplImage(img.Size, BitDepth.U8, 1))
    5.                 {                
    6.                     Cv.CvtColor(img, gray, ColorConversion.BgrToGray);
    7.                     Cv.Resize(gray, smallImg, Interpolation.Linear);
    8.                     Cv.EqualizeHist(smallImg, smallImg);
    9.                 }
    and here the code to convert Texture2D to IplImage:

    Code (CSharp):
    1. IplImage Texture2DtoIplImage(Texture2D texture)
    2.     {
    3.         IplImage ipl =  new IplImage(new CvSize(CAPTURE_WIDTH, CAPTURE_HEIGHT), BitDepth.U8, 1);
    4.         int jBackwards = CAPTURE_HEIGHT;
    5.  
    6.         for (int v = 0; v < CAPTURE_HEIGHT; ++v)
    7.         {
    8.             for (int u = 0; u < CAPTURE_WIDTH; ++u)
    9.             {
    10.  
    11.                 CvScalar col = new CvScalar();
    12.                 col.Val0 = (double)texture.GetPixel(u, v).b * 255;
    13.                 col.Val1 = (double)texture.GetPixel(u, v).g * 255;
    14.                 col.Val2 = (double)texture.GetPixel(u, v).r * 255;
    15.  
    16.                 jBackwards = CAPTURE_HEIGHT - v - 1;
    17.  
    18.                 ipl.Set2D(jBackwards, u, col);
    19.             }
    20.         }
    21.         return ipl;
    22.     }
    Thanks for the help. :)