5

I was trying to use opencv 3.4 within a plain C program using MinGW/Eclipse on a Wondows 10 PC. Compilation and installation of opencv worked nicely following the instructions here, but when I just include libs, headers etc. in my eclipse project settings, I get an

C:/opencv/MinGW_build/install/include/opencv2/imgproc/imgproc_c.h:1041: undefined reference to cvRound (with many warnings prior to it)

My compile command was gcc "-IC:\\opencv\\MinGW_build\\install\\include" "-IC:\\opencv\\MinGW_build\\install\\include\\opencv2" "-IC:\\opencv\\MinGW_build\\install\\include\\opencv" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\opencv_c_testproject.o" "..\\src\\opencv_c_testproject.c"

I used the sample code from here.

After digging through a few posts the problem might be dropped support for C in opencv 3? Or did I just mess up my configuration?

A simple c++ project works nicely using my build.

Any help is appreciated.

OBu
  • 4,977
  • 3
  • 29
  • 45
  • In OpenCV 3.X, modern C++ (C++11 or newer) is used on a large scale. Old C API maybe removed. And some fresh modules don't provide too. You should choose the official support C++ API when using OpenCV 3.X . Or endless compiling failed messages may occur. – Kinght 金 Jan 21 '18 at 11:11
  • 3
    it is just strange that the website states "It has C++, C, Python and Java interfaces" on the front page... – OBu Jan 21 '18 at 12:52
  • Different versions have different APIs(most of them are the same). – Kinght 金 Jan 21 '18 at 12:53

1 Answers1

7

The cvRound() problem was one of the first issues with this.

There is more. Plain .C files have an issue with the 3.x core_c.h include that comes with the install. It uses cv_def.h which appears to have #defines that allow it to use the "namespace" keyword, which is wrong in your C-file.

Why am I getting a namespace identifier error?

https://github.com/opencv/opencv/issues/10963

Some Github members discussing OpenCV suggest there is a fix for these issues, but the OpenCV project contributors insists that plain C API was discontinued somewhere before version 3.x !

So.. there are three options:

  • go back to OpenCV before release 3.x

  • use OpenCV 3.x, with older 2.4 header files. I've used it with 3.0.0.. but this is risky!

  • or.. kill your darlings.. For any other config, use C++ and a .CPP extension. I have recently tested the C-struct lpIImage with OpenCV 3.4 in C++ 64 bit with VS2017. Runs fine, see below. You won't have to rewrite things. Just embed your C-code, or declare it as C++ static functions. Both Mat and lpIImage interfaces will be available:

,

 //CVMain3.cpp
 #include <stdio.h>
 #include <iostream>
 #include <string>
 #include <opencv2/core.hpp>
 #include <opencv2/imgproc.hpp>
 #include <opencv2/highgui.hpp>

 using namespace cv;
 using namespace std;

 static IplImage *CVGreyImageFromFile(const char *FileName)
 {
    IplImage *img = cvLoadImage(FileName, CV_LOAD_IMAGE_GRAYSCALE);
    return img;
 }

 int mainTest()
 {   
    string filename = "c:/test/mytestimage.jpg";
    IplImage *im1 = CVGreyImageFromFile(filename.c_str());
    if (im1 != NULL)
    {
        cvShowImage("window showing lpIImage", im1);
        Mat AK = cv::cvarrToMat(im1, false, true, 0, 0);
        imshow("window showing Mat", AK);
        cvReleaseImage(&im1);
    }
    else cout << "No CVGreyImageFromFile.";
    cv::waitKey(10000);
    getchar();    
    return 0;
}
Goodies
  • 1,951
  • 21
  • 26