Ask Your Question
0

Call OpenCV from a C-File

asked 2016-08-27 12:14:43 -0600

Max1989 gravatar image

Hello Community,

I'm new here and have less programming experience. For a project work for my studies I want to implement an image processing code in an existing program. If this question is misplaced here, please let me know. During my search in the www I didn't find a solution or a similar post. If there is one existing, please let me know too. Additional I want to mention, that I didn't asked this question in another forums.

Im struggling with the task to implement the OpenCV libs. I have an existing programm. Included in this project there is a C-File (vds-client.c - see last picture in my post) which generates a picture (three channels with values for r,g and b) this picture I want to transfer to a c++-file (ImageProcessing_OpenCV.cpp - see last picture in my post) via an external function which I included to the project. In the c++-file, the image will be processed and if a specific object is detected, the flag should be set and returned to the c-file. Right now, I set the flag constantly to a value to not generate another error. Also the image processing code itself is not implemented so far. First I need a working platform.

In the C++-file I included the precompiled OpenCV Libraries which worked. E.g. I'm typing "MA" and the system offers me "MAT" as an OpenCV function.As well as the function call from the C-side to the C++-function works fine.

But the problem occurs in the .obj file from the c++-file. The error, unfortunately in German, is called:

Fehler 5 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPAX@Z)" in Funktion ""public: __thiscall cv::Mat::~Mat(void)" (??1Mat@cv@@QAE@XZ)". C:\CM_Projects\TestProject\src\ImageProcessing_OpenCV.obj CarMaker

My Code (extracted from vds-client.c) to receive the image from a simulation environment and to transmit it to the c++-file (ImageProcessing_OpenCV) is:

VDS_GetData(void){
int len = 0;
int res = 0;

/* Variables for Image Processing */
char    ImgType[64]; 
int     ImgWidth, ImgHeight, Channel;
float   SimTime;
int     ImgLen;
unsigned char *img;

extern int CV_Function(img, ImgHeight, ImgWidth);



if (sscanf(VDScfg.sbuf, "*VDS %d %s %f %dx%d %d", &Channel, 
           ImgType, &SimTime, &ImgWidth, &ImgHeight, &ImgLen) == 6) {
    if (0)
        Log("SimTime: %6.3f, Channel: %d: ImgType: %8s ImgSize: %dx%d, ImgLen:  %d\n", SimTime, Channel, ImgType, ImgWidth, ImgHeight, ImgLen);
    if (ImgLen > 0) {
        if (strcmp(ImgType, "rgb") == 0) {
            *img = (unsigned char *)malloc(ImgLen);
            for (len=0; len<ImgLen; len+=res) {
                if ((res=recv(VDScfg.sock, img+len, ImgLen-len, VDScfg.RecvFlags)) < 0) {
                    Log ("VDS: Socket Reading Failure\n");
                    break;
                }
            }
            Log("len: %d, ImgLen: %d", len, ImgLen);
            if (len == ImgLen) {

                VDSIF.Flag = CV_Function(*img, ImgHeight, ImgWidth);


                if (VDScfg.Verbose) {
                /* Print general image information */
                    //Log ("> %s\n", VDScfg.sbuf);

                    //Log ("Minimal distance: %6.3f m\n", VDSIF.MinDepth);
                    //Log ("Pixel position: x = %u, y = %u\n", MinDepthPixel%ImgWidth, MinDepthPixel/ImgWidth);
                    //Log ("\n");
                }
            }
            free (img);
        }
    }
    VDSIF.nImages ...
(more)
edit retag flag offensive close merge delete

Comments

1

the error actually comes from the linker. you're not linking opencv_core XXX.lib correctly.

berak gravatar imageberak ( 2016-08-27 12:42:53 -0600 )edit

also, screenshots are useless here for various reasons. please replace them with a text version.

berak gravatar imageberak ( 2016-08-27 12:47:37 -0600 )edit

Hello Berak, thank you a lot for your quick answer. I don't know how to create a test version quickly, due to the project is a licensed Software. I will do my very best. If you have any tip for me, I would appreciate it a lot.

Max1989 gravatar imageMax1989 ( 2016-08-27 14:53:26 -0600 )edit

sorry, typo, text, not test.

berak gravatar imageberak ( 2016-08-27 18:12:04 -0600 )edit

you specified a linker path, but no libraries

berak gravatar imageberak ( 2016-08-28 04:49:47 -0600 )edit

sidenote: i think, you wanted:

int CV_Function(unsigned char *img, int HEIGHT, int WIDTH) {
    Mat A = Mat(HEIGHT, WIDTH, CV_8UC3, img);
    //   A = *img; <-- this is for sure wrong !
berak gravatar imageberak ( 2016-08-28 09:01:46 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2016-08-28 04:55:12 -0600

Max1989 gravatar image

Hallo Berak,

I struggled to get what you mean, to get my screenshots into a text module. But then I decided to check your first hint with the linker, and now I found the mistake. In my version of OpenCV there was no core.lib so I downloaded an older version and now it works. At least I can build the project without an error now.

Thank you a lot for your help!

Max

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-08-27 12:14:43 -0600

Seen: 791 times

Last updated: Aug 27 '16