Beaglebone: background_segm.hpp error: unknown type name 'namespace'

asked 2015-03-24 18:01:17 -0600

skipi4 gravatar image

I'm trying to compile a program which detects and tracks a coloured object, it all works fine in Visual Studio but it won't compile on my Beaglebone Black (running Angstrom), it gives this error:

root@beaglebone:~# gcc OpenCvTest.c -o OpenCvTest
In file included from /usr/include/opencv2/video/video.hpp:47:0,
from /usr/include/opencv2/opencv.hpp:52,
from OpenCvTest.c:3:
/usr/include/opencv2/video/background_segm.hpp:49:1: error: unknown type name 'n
/usr/include/opencv2/video/background_segm.hpp:50:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

I have a feeling this is because I'm being stubborn and programming in C rather than C++, but is there a way I can edit the background_segm.hpp file to let me compile with C? Or am I missing something and is it acually really easy to compile this C program?

All the open cv header files are in /usr/include and I have tried to make it so that there is no reference to video.hpp or background_segm.hpp but that gives even worse compiler errors.

Thanks in advance

Source Code:

/* Image Processing Program
Will detect and track Red LED */

#include <opencv2/opencv.hpp>
#include <opencv/cxcore.h>
#include <opencv/highgui.h>

#include <stdlib.h> 
#include <stdio.h>  

/* function main */ 
int main(int argc, char** argv) { 

CvCapture* capfromcam;
capfromcam = cvCaptureFromCAM(0);

CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));

IplImage* imgRaw;
IplImage* imgHSV;
IplImage* imgFiltered;

int minH = 145;
int maxH = 179;

int minS = 89;
int maxS = 210;

int minV = 68;
int maxV = 255;

CvScalar minHSV = CV_RGB(minH, minS, minV);
CvScalar maxHSV = CV_RGB(maxH, maxS, maxV);

int posX;
int posY;

double m00;
double m01;
double m10;

char EscKeyCheck;

while (1)
{

    /* Capture Image */

    imgRaw = cvQueryFrame(capfromcam);
    cvWaitKey(10);

    if (imgRaw == NULL)
        {
        printf("Null \n");
        return(-1);
        }

    imgHSV = cvCreateImage(cvGetSize(imgRaw), IPL_DEPTH_8U, 3);
    imgFiltered = cvCreateImage(cvGetSize(imgRaw), IPL_DEPTH_8U, 1);

    /* Filter Image */

    cvCvtColor(imgRaw, imgHSV, CV_BGR2HSV);
    cvInRangeS(imgHSV, minHSV, maxHSV, imgFiltered);

    cvErode(imgFiltered, imgFiltered, cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_ELLIPSE, 0), 1);
    cvDilate(imgFiltered, imgFiltered, cvCreateStructuringElementEx(5, 5, 1, 1, CV_SHAPE_ELLIPSE, 0), 2);

    cvDilate(imgFiltered, imgFiltered, cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_ELLIPSE, 0), 2);
    cvErode(imgFiltered, imgFiltered, cvCreateStructuringElementEx(3, 3, 1, 1, CV_SHAPE_ELLIPSE, 0), 1);

    /* Track Image */

    cvMoments(imgFiltered, moments, 0);

    m00 = cvGetSpatialMoment(moments, 0, 0);
    m01 = cvGetSpatialMoment(moments, 0, 1);
    m10 = cvGetSpatialMoment(moments, 1, 0);

    if (m00 > 500)   //if area > 500
    {
        posX = m10 / m00;
        posY = m01 / m00;

        cvCircle(imgRaw, cvPoint(cvRound(posX), cvRound(posY)), 3, CV_RGB(0, 0, 255), CV_FILLED, 8, 0);   /*draw circle on centre*/
        printf("Position x = %3.0d, y = %3.0d\r", posX, posY);   /*print co'ordinates of centre*/
    }

    cvReleaseImage(&imgHSV);   /*release images from memory*/
    cvReleaseImage(&imgFiltered);

    EscKeyCheck = cvWaitKey(10);
    if (EscKeyCheck == 27) break;
}

return 0; 
}
edit retag flag offensive close merge delete

Comments

using opencv's legacy c-api is no more a valid option in 2015. please move over to c++.. (this is not optional)

(c does not know, what a namespace is.)

berak gravatar imageberak ( 2015-03-25 02:33:31 -0600 )edit

Shame, thanks anyway, seems odd that nearly every header file has namespace in it somewhere but this is the only one causing an error

skipi4 gravatar imageskipi4 ( 2015-03-25 09:23:47 -0600 )edit

some modules have a *_c.h to support the legacy, but no such thing will ever get backported.

please understand, that using c (with opencv) is a thing of the past, a lost case. opencv moved to c++ half a decade ago.

the earlier you accept this, the less harm done.

berak gravatar imageberak ( 2015-03-25 09:36:23 -0600 )edit