Problems with CV :: Rectangle OpenCV

1

I have a problem when drawing a rectangle in a cv :: mat. I am making a communication between Unity and C ++ to generate an Android application.

I use the unity Webcamtexture camera and I send the information to C ++ using the PInvoke method. Once in the C ++ code, I want to draw a rectangle but I get more than one in the image (see image) and I really do not understand why. I hope you can help me. I have attached the C ++ code and C #

C #

void Update()
{
    //texto.text = texto.text + " / "+ testo().ToString();
    imgData = null;
    imgData = new byte[width * height * 3];
    resultado = null;
    resultado = new byte[width * height * 3];
    color = webcam.GetPixels32();
    int bytesPerPixel = 3;
    const int indexR = 0;
    const int indexG = 1;
    const int indexB = 2;
    for (var i = 0; i < color.Length; i++)
    {
        imgData[(i * bytesPerPixel) + indexR] = color[i].r;
        imgData[(i * bytesPerPixel) + indexG] = color[i].g;
        imgData[(i * bytesPerPixel) + indexB] = color[i].b;
    }
    color = null;
    ProcessFrame(imgData, resultado, 0, 0, 0,0, nuevo);
    nuevo = false;
    textura2 = new Texture2D(width, height, TextureFormat.RGB24, false);
    textura2.LoadRawTextureData(resultado);
    textura2.Apply();
    renderer.material.mainTexture = textura2;
    textura2 = null;
    Resources.UnloadUnusedAssets();
}

C ++

void ProcessFrame(unsigned char* arr, unsigned char* resu,int posx, int posy, int poswidth, int posheight,bool nuevo) {
    Mat dst;//dst image
    trueRect.x = 150;
    trueRect.y = 150;
    trueRect.width = 100;
    trueRect.height = 100;
    wi = poswidth;
    he = posheight;
    mal = 20;
    dst = Mat(tamWid,tamHeid,CV_8UC3, arr);
    rectangle(dst, Point(50,50), Point(100,100), cv::Scalar(0, 255, 255));
    copy(dst.datastart, dst.dataend, resu);
}
    
asked by Urko Sanchez Ortiz 18.10.2017 в 10:24
source

0 answers