Call OpenCV from a C-File
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 ...
the error actually comes from the linker. you're not linking opencv_core XXX.lib correctly.
also, screenshots are useless here for various reasons. please replace them with a text version.
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.
sorry, typo, text, not test.
you specified a linker path, but no libraries
sidenote: i think, you wanted: