Ask Your Question

Revision history [back]

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

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; 
}