0

I get the Error run-time check failure #3, and i have to initialize P and i know why but not how to do it.

Points is supposed to be a variable 2D array like float* points[3] for testing purposes its constant for now.

CVAPI(CvPOSITObject*)  lvCreatePOSITObject( float points[5][3], int point_count )
{
    CvPoint3D32f* P; //array of structs with int x,y,z 
    for(int i = 0; i< point_count; i++)
    {
        P[i].x = points[i][0];
        P[i].y = points[i][1];
        P[i].z = points[i][2];
    }
    return cvCreatePOSITObject(P,point_count);
}
9
  • What does cvCreatePOSITObject() do? This is essential to know, for deciding which solution to take, as there are multiple. Commented Nov 4, 2015 at 12:44
  • a value of type void* cannot be used to initialize an entity of type CvPoint3D32f, also is it possible to use malloc(point_count, sizeof(CVPoint3D32f))? it creates a opencv structure from points Commented Nov 4, 2015 at 12:45
  • malloc(point_count, sizeof(CVPoint3D32f)) should have read calloc(point_count, sizeof(CVPoint3D32f))? Commented Nov 4, 2015 at 12:49
  • same error as with malloc Commented Nov 4, 2015 at 12:50
  • Which compiler, which platform? Commented Nov 4, 2015 at 12:53

1 Answer 1

1

I don't know much about OpenCV, but I think you should allocate some memory to store the data.

#include <stdlib.h> // add this to the head of the file to use malloc

CVAPI(CvPOSITObject*)  lvCreatePOSITObject( float points[5][3], int point_count )
{
    CvPoint3D32f* P; //array of structs with int x,y,z
    P = malloc(sizeof(CvPoint3D32f) * point_count); // allocate some memory
    for(int i = 0; i< point_count; i++)
    {
        P[i].x = points[i][0];
        P[i].y = points[i][1];
        P[i].z = points[i][2];
    }
    return cvCreatePOSITObject(P,point_count);
}

This code may be bad because this may not free the allocated buffer.

Sign up to request clarification or add additional context in comments.

3 Comments

malloc says: a value of type void* cannot be used to initialize an entity of type CvPoint3D32f freeing the memory happens in another function
@Eumel: Mind the * in CvPoint3D32f* P;!
oh yes there should be a * there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.