This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LCDK C6748 OpenCV Error

Other Parts Discussed in Thread: SYSBIOS

TI Correspondent,

I am working with an LCDK C6748, and have started a bare metal (i.e. no RTSC or SYS/BIOS) application aimed at doing some simple image processing. Basing my project in part on the FaceDetect demo, given that I am familiar with OpenCV, I added "cv.lib" and "cxcore.lib" to my linker path, and the "cv*.h" and "cx*.h" headers to my compiler include path. I wrote a MWE program that simply tries to allocate an image handle object as follows:

// Hardware libraries
#include <cv.h>
#include <cvtypes.h>

static IplImage* cv = NULL;

void main(void) {
    
    // Allocate the Ipl Image structure
    cv = (IplImage *) cvAlloc(sizeof(IplImage));

    // Initialize the Ipl Image
    cvInitImageHeader(*cv, cvSize(1024, 768), IPL_DEPTH_8U, 3, IPL_ORIGIN_BL, 8);

}

This sequence of actions is the same that is seen at the start of the FaceDetect demo for the colorConvertTask() thread. The cvAlloc() function executes without issue, and allocates the IplImage structure to the heap as expected. The cvInitImageHeader() function, however, immediately fails and calls an abort, with the following error text seen over the debugger:

[C674X_0] Assertion failed, (0), file C:/opencv_dsp/cxcore/src/cxerror.cpp, line 373

The only other information available from the debug session is a (somewhat unhelpful) call stack (screenshot pasted below). All of the functions in the call stack are related to an abort operation, which makes sense given that an assertion failed.

Am I missing a required startup step to use the OpenCV libraries? Does it require the use of RSTC or SYS/BIOS? If there is some dependency on RSTC or SYS/BIOS, is there a means of emulating the required functionality in bare metal?

Thanks,

-Chris F.

  • Dear Chris,
    I'm not good at opencv apps.
    1) But I suggest you to use the facedetect code and use your lines of code in that project with commented out all the facedetect code part so that you would get all the RTSC/SYSBIOS project settings.

    2) I hope its not due to SYS/BIOS or RTSC project environment and its due to something else.
    You can debug the actual facedetect code and try to understand the APIs "cvInitImageHeader" "cvAlloc" , what we need to give as argument, i/p and return value etc.m.,
  • Titus,

    To your first point, I have tried to re-compile the FaceDetect demo, however I have not had any successes there. The target XDCtools components are from the CCS 5.x era, and no Platforms are present under "Project Properties" -> "CCS General" -> "RTSC" if I attempt to update it to a more recent version (i.e. the ones I've installed with CCS). At this moment, I don't have enough time in my schedule to re-create the FaceDetect demo project from scratch with the correct dependencies, etc.

    To your second point, I provided a minimum working example (MWE) that uses the same cvAlloc() and cvInitImageHeader() function calling scheme (arguments, input/output, etc.) as the FaceDetect demo. I was able to compile to an .out file, connect a debug session, and get the error with this MWE, so it should be easy to replicate on another board. I, too, hope that there is no dependency on SYS/BIOS, but after triple-checking that I'm not missing some earlier function call or mangling some argument in the two listed functions, there's not much else I can do.

    So, is there a more recent version of the FaceDetect demo project that I could compile without having to re-create it from scratch? Or can you try to re-create and help debug the issue with a development board on your side?

    Thanks,
    -Chris F.
  • Dear Chris,

    You don't want to create "facedetect" demo code from scratch.

    You can import and rebuild the project, it should work.

    I have attached my RTSC settings, I have simply used XDCtools and BIOS package.

    Any build issues ?

    What build error you are getting for facedetect code ?

  • Titus,

    I was able to get the FaceDetect demo to compile and run. As expected, I had to re-create the project in order for the XDCtools to work correctly. If I tried simply updating the tools version and re-compiling, the Windows permissions for the default install directory was keeping the project from compiling. Luckily I was able to copy-paste most of the directory and CCS settings and just update them after they were in my workspace. However, moving the project from this default install directory also involved setting absolute directories for all of the include and library paths.

    After compiling, I was able to run the demo on the board. I set a breakpoint before the cvAlloc() and cvInitImageHeader() functions, and was able to execute both of those functions as expected! So, I've learned that those functions can be executed, but I still am at a loss for why they can be executed in the facedetect demo, but not in a bare metal application. Even in the demo, the functions are calling a pre-compiled library, so I have no means of telling what the library functions are doing. My final application is not targeting SYS/BIOS, and so I can't just inject my project code into the FaceDetect demo.

    Can you provide any insight into with the cvAlloc() and cvInitImageHeader() functions are doing on the library side? Is there some dependency of this OpenCV build on SYS/BIOS?

    Thanks,

    Chris F.

  • Hi Chris,

    There is no SYSBIOS dependency to the OpenCV 1.0 libraries (cxcore and cv ) that we have cross compiled for the C6000 DSP. If any API fails, you should be able to check the status of the erorr in the same way as you would on an x86 machine.

    In the cxcore library in OpenCV 1.0, we have replaced all the p_cvAlloc calls with malloc calls to avoid using the OpenCV memory manager which we had noticed lead to some memory leak issues. For example, here is the modification we have made to the OpenCV 1.0 library when cross compiling it for the C6000 DSP.

    CV_IMPL  void*  cvAlloc( size_t size )

    {

       void* ptr = 0;

       CV_FUNCNAME( "cvAlloc" );

       __BEGIN__;

       if( (size_t)size > CV_MAX_ALLOC_SIZE )

           CV_ERROR( CV_StsOutOfRange,

                     "Negative or too large argument of cvAlloc function" );

    #ifndef OPENCV_C6X

       ptr = p_cvAlloc( size, p_cvAllocUserData );

    #else

    ptr = malloc(size);

    #endif

       if( !ptr )

           CV_ERROR( CV_StsNoMem, "Out of memory" );

       __END__;

       return ptr;

    }

    I have also checked the cvInitImageHeader, there is no memory allocation calls in the function so the function code is same as the OpenCV 1.0 source available to the community.


    Regards,
    Rahul

  • Rahul,

    I can't add any CV_ERROR checks after the calls to cvInitHeader, as the call to cvInitHeader is what causes the failed assertion.

    Given that the OpenCV code was not largely modified from it's original form, I tracked down a copy of the source for OpenCV 1.0 and manually inserted an in situ version of the cvInitHeader function (and related sub-functions) with the modifications you have listed. This compiled and the cvInitHeader function ran successfully, but of course the very next OpenCV function failed with with the same generic "assertion failed" message. This leads me to strongly believe that the TI-provided OpenCV library requires SYS/BIOS, especially given my earlier successes re-compiling the SYS/BIOS based demo.

    In the month since your most recent response, we have moved to a tablet PC approach to using OpenCV, which has been much more fruitful. If you plan on supporting OpenCV, or would prefer users to use one of the TI imaging libraries, I suggest maintaining a modern example of image processing on the TI wiki. Getting stuck just trying to do basic library setup has lowered our confidence in TI as a solution for our future image processing needs.

    Edit: I have rejected the previous answer, as it still does not answer the original question. I'm not going to find and edit a copy of the OpenCV 1.0 source by replacing all of the malloc functions to get this to work.


    Thanks,
    -Chris