[Scilab-users] List API function error

Shamika Mohanan shamika.i.nair at gmail.com
Tue May 10 10:54:43 CEST 2016


I'm using Scilab API list function to access 2D/3D matrices from Scilab
environment in the C++ code. This list is then converted into a Mat object
and passed to OpenCV.

I'm having trouble accessing the child elements of the list.

int retrieveImage(Mat &image,int pos)
{

    SciErr sciErr;
    int iRows=0,iCols=0,i,j,k=0;
    int *piAddr = NULL;
    int *piAddrChild = NULL;
    int iPrec = 0,iItem = 0;

    //retrieving number of items in the list and type of data(integer/float)
    sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piAddrChild);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    if(isIntegerType(pvApiCtx, piAddrChild))
    {
      // Retrieve 2D/3D matrices of int type
    }
    else //for floating point/ double precision values
    {
        if(iItem==3)
        {

            double *pstDataR = NULL;
            double *pstDataG = NULL;
            double *pstDataB = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }

            //retrive the matrix of the R values
            sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows,
&iCols, &pstDataR);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }

            //retrive address of the list
            sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
            //retrive the matrix of the G values
            sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows,
&iCols, &pstDataG);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }

            //retrive address of the list
            sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
            //retrive the matrix of the B values
            sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows,
&iCols, &pstDataB);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }

            //creating an image matrix with the no. of rows and columns we
retrieved, and assigning it to be of the form 8-bit unsinged integers
            image = Mat(iRows,iCols,CV_64FC3);

            //Now that we have the 3 matrices(R,G,B), we need to assign
those values to the pixels. The following code does this
            k=0;
            for(i=0;i<iRows;i++)
            {
                for(j=0;j<iCols;j++)
                {
                    image.at<Vec3d>(i,j)[2]=pstDataR[i+iRows*j];
                    image.at<Vec3d>(i,j)[1]=pstDataG[i+iRows*j];
                    image.at<Vec3d>(i,j)[0]=pstDataB[i+iRows*j];
                }
            }
        }
        else
        {
            // Grayscale images
            double *pstDataR = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
            //retrive one 2D matrix of image
            sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows,
&iCols, &pstDataR);
            if(sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }

            image = Mat(iRows,iCols,CV_64FC1);

            //Assigning image matrix values to pixels
            k=0;
            for(i=0;i<iRows;i++)
                for(j=0;j<iCols;j++)
                    image.at<double>(i,j)=pstDataR[i+iRows*j];

        }
    }
    return 1;
}

When I use this function, I get the error-

API Error:
    in getMatrixOfDoubleInList: Unable to get address of item #2 in
argument #1
    in getMatrixOfDouble: Invalid argument type, double matrix expected


What is wrong with the code?

Shamika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160510/f9d078bb/attachment.htm>


More information about the users mailing list